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 | b636f70 | 2021-03-03 14:46:50 +0900 | [diff] [blame] | 20 | import java.util.Set; |
| 21 | |
Jian Li | 073f1ba | 2021-02-28 03:50:15 +0900 | [diff] [blame] | 22 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 23 | |
Jian Li | caa0392 | 2021-02-26 18:15:20 +0900 | [diff] [blame] | 24 | /** |
| 25 | * Kubevirt router event class. |
| 26 | */ |
| 27 | public class KubevirtRouterEvent extends AbstractEvent<KubevirtRouterEvent.Type, KubevirtRouter> { |
| 28 | |
Jian Li | 073f1ba | 2021-02-28 03:50:15 +0900 | [diff] [blame] | 29 | private final KubevirtFloatingIp floatingIp; |
| 30 | private final String podName; |
Jian Li | b636f70 | 2021-03-03 14:46:50 +0900 | [diff] [blame] | 31 | private final Set<String> internal; |
| 32 | private final String externalIp; |
| 33 | private final String externalNet; |
| 34 | private final String peerRouterIp; |
Daniel Park | 2884b23 | 2021-03-04 18:58:47 +0900 | [diff] [blame^] | 35 | private final String gateway; |
Jian Li | 073f1ba | 2021-02-28 03:50:15 +0900 | [diff] [blame] | 36 | |
Jian Li | caa0392 | 2021-02-26 18:15:20 +0900 | [diff] [blame] | 37 | /** |
| 38 | * Creates an event of a given type for the specified kubevirt router. |
| 39 | * |
| 40 | * @param type kubevirt router event type |
| 41 | * @param subject kubevirt router |
| 42 | */ |
Jian Li | 810f58c | 2021-02-27 01:10:50 +0900 | [diff] [blame] | 43 | public KubevirtRouterEvent(Type type, KubevirtRouter subject) { |
Jian Li | caa0392 | 2021-02-26 18:15:20 +0900 | [diff] [blame] | 44 | super(type, subject); |
Jian Li | 073f1ba | 2021-02-28 03:50:15 +0900 | [diff] [blame] | 45 | this.floatingIp = null; |
| 46 | this.podName = null; |
Jian Li | b636f70 | 2021-03-03 14:46:50 +0900 | [diff] [blame] | 47 | this.internal = null; |
| 48 | this.externalIp = null; |
| 49 | this.externalNet = null; |
| 50 | this.peerRouterIp = null; |
Daniel Park | 2884b23 | 2021-03-04 18:58:47 +0900 | [diff] [blame^] | 51 | this.gateway = null; |
Jian Li | 073f1ba | 2021-02-28 03:50:15 +0900 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Creates an event of a given type for the specified kubevirt router. |
| 56 | * |
| 57 | * @param type kubevirt router event type |
| 58 | * @param subject kubevirt router |
| 59 | * @param floatingIp kubevirt floating IP |
| 60 | */ |
| 61 | public KubevirtRouterEvent(Type type, KubevirtRouter subject, KubevirtFloatingIp floatingIp) { |
| 62 | super(type, subject); |
| 63 | this.floatingIp = floatingIp; |
| 64 | this.podName = null; |
Jian Li | b636f70 | 2021-03-03 14:46:50 +0900 | [diff] [blame] | 65 | this.internal = null; |
| 66 | this.externalIp = null; |
| 67 | this.externalNet = null; |
| 68 | this.peerRouterIp = null; |
Daniel Park | 2884b23 | 2021-03-04 18:58:47 +0900 | [diff] [blame^] | 69 | this.gateway = null; |
| 70 | |
Jian Li | 073f1ba | 2021-02-28 03:50:15 +0900 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Creates an event of a given type for the specified kubevirt router. |
| 75 | * |
| 76 | * @param type kubevirt router event type |
| 77 | * @param subject kubevirt router |
| 78 | * @param floatingIp kubevirt floating IP |
| 79 | * @param podName kubevirt POD name |
| 80 | */ |
| 81 | public KubevirtRouterEvent(Type type, KubevirtRouter subject, KubevirtFloatingIp floatingIp, String podName) { |
| 82 | super(type, subject); |
| 83 | this.floatingIp = floatingIp; |
| 84 | this.podName = podName; |
Jian Li | b636f70 | 2021-03-03 14:46:50 +0900 | [diff] [blame] | 85 | this.internal = null; |
| 86 | this.externalIp = null; |
| 87 | this.externalNet = null; |
| 88 | this.peerRouterIp = null; |
Daniel Park | 2884b23 | 2021-03-04 18:58:47 +0900 | [diff] [blame^] | 89 | this.gateway = null; |
Jian Li | b636f70 | 2021-03-03 14:46:50 +0900 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Creates an event of a given type for the specified kubevirt router. |
| 94 | * |
| 95 | * @param type kubevirt router event type |
| 96 | * @param subject kubevirt router |
| 97 | * @param internal internal networks attached to the router |
| 98 | */ |
| 99 | public KubevirtRouterEvent(Type type, KubevirtRouter subject, Set<String> internal) { |
| 100 | super(type, subject); |
| 101 | this.internal = internal; |
| 102 | this.podName = null; |
| 103 | this.floatingIp = null; |
| 104 | this.externalIp = null; |
| 105 | this.externalNet = null; |
| 106 | this.peerRouterIp = null; |
Daniel Park | 2884b23 | 2021-03-04 18:58:47 +0900 | [diff] [blame^] | 107 | this.gateway = null; |
Jian Li | b636f70 | 2021-03-03 14:46:50 +0900 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Creates an event of a given type for the specified kubevirt router. |
| 112 | * |
| 113 | * @param type kubevirt router event type |
| 114 | * @param subject kubevirt router |
| 115 | * @param externalIp virtual router's IP address included in external network |
| 116 | * @param externalNet external network name |
| 117 | * @param peerRouterIp external peer router IP address |
| 118 | */ |
| 119 | public KubevirtRouterEvent(Type type, KubevirtRouter subject, |
| 120 | String externalIp, String externalNet, |
| 121 | String peerRouterIp) { |
| 122 | super(type, subject); |
| 123 | this.internal = null; |
| 124 | this.podName = null; |
| 125 | this.floatingIp = null; |
| 126 | this.externalIp = externalIp; |
| 127 | this.externalNet = externalNet; |
| 128 | this.peerRouterIp = peerRouterIp; |
Daniel Park | 2884b23 | 2021-03-04 18:58:47 +0900 | [diff] [blame^] | 129 | this.gateway = null; |
| 130 | } |
| 131 | |
| 132 | public KubevirtRouterEvent(Type type, KubevirtRouter subject, |
| 133 | String gateway) { |
| 134 | super(type, subject); |
| 135 | this.gateway = gateway; |
| 136 | this.floatingIp = null; |
| 137 | this.podName = null; |
| 138 | this.internal = null; |
| 139 | this.externalIp = null; |
| 140 | this.externalNet = null; |
| 141 | this.peerRouterIp = null; |
Jian Li | caa0392 | 2021-02-26 18:15:20 +0900 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | public enum Type { |
| 145 | /** |
| 146 | * Signifies that a new kubevirt router is created. |
| 147 | */ |
| 148 | KUBEVIRT_ROUTER_CREATED, |
| 149 | |
| 150 | /** |
| 151 | * Signifies that the kubevirt router is updated. |
| 152 | */ |
| 153 | KUBEVIRT_ROUTER_UPDATED, |
| 154 | |
| 155 | /** |
| 156 | * Signifies that the kubevirt router is removed. |
| 157 | */ |
| 158 | KUBEVIRT_ROUTER_REMOVED, |
Jian Li | 073f1ba | 2021-02-28 03:50:15 +0900 | [diff] [blame] | 159 | |
| 160 | /** |
Jian Li | b636f70 | 2021-03-03 14:46:50 +0900 | [diff] [blame] | 161 | * Signifies that a new external network is added to the router. |
| 162 | */ |
| 163 | KUBEVIRT_ROUTER_EXTERNAL_NETWORK_ATTACHED, |
| 164 | |
| 165 | /** |
| 166 | * Signifies that the existing external network is removed from the router. |
| 167 | */ |
| 168 | KUBEVIRT_ROUTER_EXTERNAL_NETWORK_DETACHED, |
| 169 | |
| 170 | /** |
| 171 | * Signifies that a new internal network is added to the router. |
| 172 | */ |
| 173 | KUBEVIRT_ROUTER_INTERNAL_NETWORKS_ATTACHED, |
| 174 | |
| 175 | /** |
| 176 | * Signifies that the existing internal network is removed from the router. |
| 177 | */ |
| 178 | KUBEVIRT_ROUTER_INTERNAL_NETWORKS_DETACHED, |
| 179 | |
| 180 | /** |
Jian Li | 073f1ba | 2021-02-28 03:50:15 +0900 | [diff] [blame] | 181 | * Signifies that a new kubevirt floating IP is created. |
| 182 | */ |
| 183 | KUBEVIRT_FLOATING_IP_CREATED, |
| 184 | |
| 185 | /** |
| 186 | * Signifies that the kubevirt floating IP is updated. |
| 187 | */ |
| 188 | KUBEVIRT_FLOATING_IP_UPDATED, |
| 189 | |
| 190 | /** |
| 191 | * Signifies that the kubevirt floating IP is removed. |
| 192 | */ |
| 193 | KUBEVIRT_FLOATING_IP_REMOVED, |
| 194 | |
| 195 | /** |
| 196 | * Signifies that the floating IP is associated to a fixed IP. |
| 197 | */ |
| 198 | KUBEVIRT_FLOATING_IP_ASSOCIATED, |
| 199 | |
| 200 | /** |
| 201 | * Signifies that the floating IP disassociated from the fixed IP. |
| 202 | */ |
Daniel Park | 2884b23 | 2021-03-04 18:58:47 +0900 | [diff] [blame^] | 203 | KUBEVIRT_FLOATING_IP_DISASSOCIATED, |
| 204 | |
| 205 | /** |
| 206 | * Signified that the gateway node associated for this router. |
| 207 | */ |
| 208 | KUBEVIRT_GATEWAY_NODE_ATTACHED, |
| 209 | /** |
| 210 | * Signified that the gateway node disassociated for this router. |
| 211 | */ |
| 212 | KUBEVIRT_GATEWAY_NODE_DETACHED, |
| 213 | /** |
| 214 | * Signified that the gateway node changed for this router. |
| 215 | */ |
| 216 | KUBEVIRT_GATEWAY_NODE_CHANGED |
Jian Li | 073f1ba | 2021-02-28 03:50:15 +0900 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Returns the floating IP of the router event. |
| 221 | * |
| 222 | * @return kubevirt floating IP; null if the event is not relevant to the floating IP |
| 223 | */ |
| 224 | public KubevirtFloatingIp floatingIp() { |
| 225 | return floatingIp; |
| 226 | } |
| 227 | |
| 228 | /** |
| 229 | * Returns the pod name of the router event. |
| 230 | * |
| 231 | * @return kubevirt pod name; null if the event is not relevant to the pod name |
| 232 | */ |
| 233 | public String podName() { |
| 234 | return podName; |
| 235 | } |
| 236 | |
Jian Li | da7ec15 | 2021-03-05 12:21:50 +0900 | [diff] [blame] | 237 | /** |
| 238 | * Returns the internal of the router event. |
| 239 | * |
| 240 | * @return kubevirt internal network set, null if the event is not relevant to the internal |
| 241 | */ |
| 242 | public Set<String> internal() { |
| 243 | return internal; |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * Returns the external IP address of the router event. |
| 248 | * |
| 249 | * @return external IP address, null if the event is not relevant to the external |
| 250 | */ |
| 251 | public String externalIp() { |
| 252 | return externalIp; |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * Returns the external network of the router event. |
| 257 | * |
| 258 | * @return external network, null if the event is not relevant ot the external |
| 259 | */ |
| 260 | public String externalNet() { |
| 261 | return externalNet; |
| 262 | } |
| 263 | |
Daniel Park | 2884b23 | 2021-03-04 18:58:47 +0900 | [diff] [blame^] | 264 | /** |
| 265 | * Returns the gateway of the router event. |
| 266 | * |
| 267 | * @return gateway if exists, null otherwise |
| 268 | */ |
| 269 | public String gateway() { |
| 270 | return gateway; |
| 271 | } |
| 272 | |
Jian Li | 073f1ba | 2021-02-28 03:50:15 +0900 | [diff] [blame] | 273 | @Override |
| 274 | public String toString() { |
| 275 | if (floatingIp == null) { |
| 276 | return super.toString(); |
| 277 | } |
| 278 | return toStringHelper(this) |
| 279 | .add("type", type()) |
| 280 | .add("router", subject()) |
| 281 | .add("floatingIp", floatingIp) |
| 282 | .add("podName", podName) |
Jian Li | b636f70 | 2021-03-03 14:46:50 +0900 | [diff] [blame] | 283 | .add("internal", internal) |
| 284 | .add("externalIp", externalIp) |
| 285 | .add("externalNet", externalNet) |
| 286 | .add("peerRouterIp", peerRouterIp) |
Daniel Park | 2884b23 | 2021-03-04 18:58:47 +0900 | [diff] [blame^] | 287 | .add("gatewayNodeHostName", gateway) |
Jian Li | 073f1ba | 2021-02-28 03:50:15 +0900 | [diff] [blame] | 288 | .toString(); |
Jian Li | caa0392 | 2021-02-26 18:15:20 +0900 | [diff] [blame] | 289 | } |
| 290 | } |