blob: d2964a28982e0c7d7bdf6d99789bc231791ffcd1 [file] [log] [blame]
Jian Lifc55e422019-01-21 14:39:34 +09001/*
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 */
16package org.onosproject.k8snetworking.api;
17
Jian Li7e8f57e2019-01-24 18:31:03 +090018import org.onlab.util.Tools;
Jian Lifc55e422019-01-21 14:39:34 +090019import org.onosproject.event.AbstractEvent;
20
Jian Li7e8f57e2019-01-24 18:31:03 +090021import static com.google.common.base.MoreObjects.toStringHelper;
22
Jian Lifc55e422019-01-21 14:39:34 +090023/**
24 * Describes kubernetes network service event.
25 */
26public class K8sNetworkEvent extends AbstractEvent<K8sNetworkEvent.Type, K8sNetwork> {
27
Jian Li7e8f57e2019-01-24 18:31:03 +090028 private final K8sPort port;
Jian Lifc55e422019-01-21 14:39:34 +090029
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 Li7e8f57e2019-01-24 18:31:03 +090049
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,
Jian Li4aa17642019-01-30 00:01:11 +090064
65 /**
66 * Signifies that the kubernetes port is activated.
67 */
68 K8S_PORT_ACTIVATED,
69
70 /**
71 * Signifies that the kubernetes port is inactivated.
72 */
73 K8S_PORT_INACTIVATED,
Jian Li7e8f57e2019-01-24 18:31:03 +090074 }
75
76 /**
77 * Creates an event of a given type for the specified network.
78 *
79 * @param type kubernetes network event type
80 * @param network kubernetes network
81 */
82 public K8sNetworkEvent(Type type, K8sNetwork network) {
83 super(type, network);
84 this.port = null;
85 }
86
87 /**
88 * Creates an event of a given type for the specified network and port.
89 *
90 * @param type kubernetes network event type
91 * @param network kubernetes network
92 * @param port kubernetes port
93 */
94 public K8sNetworkEvent(Type type, K8sNetwork network, K8sPort port) {
95 super(type, network);
96 this.port = port;
97 }
98
99 /**
100 * Returns the kubernetes port of the network event.
101 *
102 * @return kubernetes port; null if the event is not port specific
103 */
104 public K8sPort port() {
105 return port;
106 }
107
108 @Override
109 public String toString() {
110 if (port == null) {
111 return super.toString();
112 }
113 return toStringHelper(this)
114 .add("time", Tools.defaultOffsetDataTime(time()))
115 .add("port", port)
116 .add("network", subject())
117 .toString();
Jian Lifc55e422019-01-21 14:39:34 +0900118 }
119}