Jian Li | caa0392 | 2021-02-26 18:15:20 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.kubevirtnetworking.api; |
| 17 | |
| 18 | import org.onosproject.event.AbstractEvent; |
| 19 | |
Jian Li | 073f1ba | 2021-02-28 03:50:15 +0900 | [diff] [blame] | 20 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 21 | |
Jian Li | caa0392 | 2021-02-26 18:15:20 +0900 | [diff] [blame] | 22 | /** |
| 23 | * Kubevirt router event class. |
| 24 | */ |
| 25 | public class KubevirtRouterEvent extends AbstractEvent<KubevirtRouterEvent.Type, KubevirtRouter> { |
| 26 | |
Jian Li | 073f1ba | 2021-02-28 03:50:15 +0900 | [diff] [blame] | 27 | private final KubevirtFloatingIp floatingIp; |
| 28 | private final String podName; |
| 29 | |
Jian Li | caa0392 | 2021-02-26 18:15:20 +0900 | [diff] [blame] | 30 | /** |
| 31 | * Creates an event of a given type for the specified kubevirt router. |
| 32 | * |
| 33 | * @param type kubevirt router event type |
| 34 | * @param subject kubevirt router |
| 35 | */ |
Jian Li | 810f58c | 2021-02-27 01:10:50 +0900 | [diff] [blame] | 36 | public KubevirtRouterEvent(Type type, KubevirtRouter subject) { |
Jian Li | caa0392 | 2021-02-26 18:15:20 +0900 | [diff] [blame] | 37 | super(type, subject); |
Jian Li | 073f1ba | 2021-02-28 03:50:15 +0900 | [diff] [blame] | 38 | this.floatingIp = null; |
| 39 | this.podName = null; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Creates an event of a given type for the specified kubevirt router. |
| 44 | * |
| 45 | * @param type kubevirt router event type |
| 46 | * @param subject kubevirt router |
| 47 | * @param floatingIp kubevirt floating IP |
| 48 | */ |
| 49 | public KubevirtRouterEvent(Type type, KubevirtRouter subject, KubevirtFloatingIp floatingIp) { |
| 50 | super(type, subject); |
| 51 | this.floatingIp = floatingIp; |
| 52 | this.podName = null; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Creates an event of a given type for the specified kubevirt router. |
| 57 | * |
| 58 | * @param type kubevirt router event type |
| 59 | * @param subject kubevirt router |
| 60 | * @param floatingIp kubevirt floating IP |
| 61 | * @param podName kubevirt POD name |
| 62 | */ |
| 63 | public KubevirtRouterEvent(Type type, KubevirtRouter subject, KubevirtFloatingIp floatingIp, String podName) { |
| 64 | super(type, subject); |
| 65 | this.floatingIp = floatingIp; |
| 66 | this.podName = podName; |
Jian Li | caa0392 | 2021-02-26 18:15:20 +0900 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | public enum Type { |
| 70 | /** |
| 71 | * Signifies that a new kubevirt router is created. |
| 72 | */ |
| 73 | KUBEVIRT_ROUTER_CREATED, |
| 74 | |
| 75 | /** |
| 76 | * Signifies that the kubevirt router is updated. |
| 77 | */ |
| 78 | KUBEVIRT_ROUTER_UPDATED, |
| 79 | |
| 80 | /** |
| 81 | * Signifies that the kubevirt router is removed. |
| 82 | */ |
| 83 | KUBEVIRT_ROUTER_REMOVED, |
Jian Li | 073f1ba | 2021-02-28 03:50:15 +0900 | [diff] [blame] | 84 | |
| 85 | /** |
| 86 | * Signifies that a new kubevirt floating IP is created. |
| 87 | */ |
| 88 | KUBEVIRT_FLOATING_IP_CREATED, |
| 89 | |
| 90 | /** |
| 91 | * Signifies that the kubevirt floating IP is updated. |
| 92 | */ |
| 93 | KUBEVIRT_FLOATING_IP_UPDATED, |
| 94 | |
| 95 | /** |
| 96 | * Signifies that the kubevirt floating IP is removed. |
| 97 | */ |
| 98 | KUBEVIRT_FLOATING_IP_REMOVED, |
| 99 | |
| 100 | /** |
| 101 | * Signifies that the floating IP is associated to a fixed IP. |
| 102 | */ |
| 103 | KUBEVIRT_FLOATING_IP_ASSOCIATED, |
| 104 | |
| 105 | /** |
| 106 | * Signifies that the floating IP disassociated from the fixed IP. |
| 107 | */ |
| 108 | KUBEVIRT_FLOATING_IP_DISASSOCIATED |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Returns the floating IP of the router event. |
| 113 | * |
| 114 | * @return kubevirt floating IP; null if the event is not relevant to the floating IP |
| 115 | */ |
| 116 | public KubevirtFloatingIp floatingIp() { |
| 117 | return floatingIp; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Returns the pod name of the router event. |
| 122 | * |
| 123 | * @return kubevirt pod name; null if the event is not relevant to the pod name |
| 124 | */ |
| 125 | public String podName() { |
| 126 | return podName; |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public String toString() { |
| 131 | if (floatingIp == null) { |
| 132 | return super.toString(); |
| 133 | } |
| 134 | return toStringHelper(this) |
| 135 | .add("type", type()) |
| 136 | .add("router", subject()) |
| 137 | .add("floatingIp", floatingIp) |
| 138 | .add("podName", podName) |
| 139 | .toString(); |
Jian Li | caa0392 | 2021-02-26 18:15:20 +0900 | [diff] [blame] | 140 | } |
| 141 | } |