Jian Li | fc55e42 | 2019-01-21 14:39:34 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019-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.k8snetworking.api; |
| 17 | |
Jian Li | 7e8f57e | 2019-01-24 18:31:03 +0900 | [diff] [blame^] | 18 | import org.onlab.util.Tools; |
Jian Li | fc55e42 | 2019-01-21 14:39:34 +0900 | [diff] [blame] | 19 | import org.onosproject.event.AbstractEvent; |
| 20 | |
Jian Li | 7e8f57e | 2019-01-24 18:31:03 +0900 | [diff] [blame^] | 21 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 22 | |
Jian Li | fc55e42 | 2019-01-21 14:39:34 +0900 | [diff] [blame] | 23 | /** |
| 24 | * Describes kubernetes network service event. |
| 25 | */ |
| 26 | public class K8sNetworkEvent extends AbstractEvent<K8sNetworkEvent.Type, K8sNetwork> { |
| 27 | |
Jian Li | 7e8f57e | 2019-01-24 18:31:03 +0900 | [diff] [blame^] | 28 | private final K8sPort port; |
Jian Li | fc55e42 | 2019-01-21 14:39:34 +0900 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * Kubernetes network events. |
| 32 | */ |
| 33 | public enum Type { |
| 34 | |
| 35 | /** |
| 36 | * Signifies that a new kubernetes network is created. |
| 37 | */ |
| 38 | K8S_NETWORK_CREATED, |
| 39 | |
| 40 | /** |
| 41 | * Signifies that the kubernetes network is updated. |
| 42 | */ |
| 43 | K8S_NETWORK_UPDATED, |
| 44 | |
| 45 | /** |
| 46 | * Signifies that the kubernetes network is removed. |
| 47 | */ |
| 48 | K8S_NETWORK_REMOVED, |
Jian Li | 7e8f57e | 2019-01-24 18:31:03 +0900 | [diff] [blame^] | 49 | |
| 50 | /** |
| 51 | * Signifies that a new kubernetes port is created. |
| 52 | */ |
| 53 | K8S_PORT_CREATED, |
| 54 | |
| 55 | /** |
| 56 | * Signifies that the kubernetes port is updated. |
| 57 | */ |
| 58 | K8S_PORT_UPDATED, |
| 59 | |
| 60 | /** |
| 61 | * Signifies that the kubernetes port is removed. |
| 62 | */ |
| 63 | K8S_PORT_REMOVED, |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Creates an event of a given type for the specified network. |
| 68 | * |
| 69 | * @param type kubernetes network event type |
| 70 | * @param network kubernetes network |
| 71 | */ |
| 72 | public K8sNetworkEvent(Type type, K8sNetwork network) { |
| 73 | super(type, network); |
| 74 | this.port = null; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Creates an event of a given type for the specified network and port. |
| 79 | * |
| 80 | * @param type kubernetes network event type |
| 81 | * @param network kubernetes network |
| 82 | * @param port kubernetes port |
| 83 | */ |
| 84 | public K8sNetworkEvent(Type type, K8sNetwork network, K8sPort port) { |
| 85 | super(type, network); |
| 86 | this.port = port; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Returns the kubernetes port of the network event. |
| 91 | * |
| 92 | * @return kubernetes port; null if the event is not port specific |
| 93 | */ |
| 94 | public K8sPort port() { |
| 95 | return port; |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public String toString() { |
| 100 | if (port == null) { |
| 101 | return super.toString(); |
| 102 | } |
| 103 | return toStringHelper(this) |
| 104 | .add("time", Tools.defaultOffsetDataTime(time())) |
| 105 | .add("port", port) |
| 106 | .add("network", subject()) |
| 107 | .toString(); |
Jian Li | fc55e42 | 2019-01-21 14:39:34 +0900 | [diff] [blame] | 108 | } |
| 109 | } |