blob: c022c2949a50ed4e7c5f949f5d910172b8485514 [file] [log] [blame]
Hyunsun Moon44aac662017-02-18 02:07:01 +09001/*
2 * Copyright 2017-present Open Networking Laboratory
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.openstacknetworking.api;
17
18import org.joda.time.LocalDateTime;
19import org.onosproject.event.AbstractEvent;
20import org.openstack4j.model.network.Network;
21import org.openstack4j.model.network.Port;
22import org.openstack4j.model.network.Subnet;
23
24import static com.google.common.base.MoreObjects.toStringHelper;
25
26/**
27 * Describes OpenStack network service event.
28 */
29public class OpenstackNetworkEvent extends AbstractEvent<OpenstackNetworkEvent.Type, Network> {
30
31 private final Port port;
32 private final Subnet subnet;
33
34 public enum Type {
35 /**
36 * Signifies that a new OpenStack network is created.
37 */
38 OPENSTACK_NETWORK_CREATED,
39
40 /**
41 * Signifies that the OpenStack network is updated.
42 */
43 OPENSTACK_NETWORK_UPDATED,
44
45 /**
46 * Signifies that the OpenStack network is removed.
47 */
48 OPENSTACK_NETWORK_REMOVED,
49
50 /**
51 * Signifies that a new OpenStack subnet is created.
52 */
53 OPENSTACK_SUBNET_CREATED,
54
55 /**
56 * Signifies that the OpenStack subnet is updated.
57 */
58 OPENSTACK_SUBNET_UPDATED,
59
60 /**
61 * Signifies that the OpenStack subnet is removed.
62 */
63 OPENSTACK_SUBNET_REMOVED,
64
65 /**
66 * Signifies that a new OpenStack port is created.
67 */
68 OPENSTACK_PORT_CREATED,
69
70 /**
71 * Signifies that the OpenStack port is updated.
72 */
73 OPENSTACK_PORT_UPDATED,
74
75 /**
76 * Signifies that the OpenStack port is removed.
77 */
78 OPENSTACK_PORT_REMOVED
79 }
80
81 /**
82 * Creates an event of a given type for the specified network and the current time.
83 * @param type openstack network event type
84 * @param network openstack network
85 */
86 public OpenstackNetworkEvent(Type type, Network network) {
87 super(type, network);
88 this.port = null;
89 this.subnet = null;
90 }
91
92 /**
93 * Creates an event of a given type for the specified network, port and the
94 * current time.
95 *
96 * @param type openstack network event type
97 * @param network openstack network
98 * @param port openstack port
99 */
100 public OpenstackNetworkEvent(Type type, Network network, Port port) {
101 super(type, network);
102 this.port = port;
103 this.subnet = null;
104 }
105
106 /**
107 * Creates an event of a given type for the specified network, subnet and the
108 * current time.
109 *
110 * @param type openstack network event type
111 * @param network openstack network
112 * @param subnet openstack subnet
113 */
114 public OpenstackNetworkEvent(Type type, Network network, Subnet subnet) {
115 super(type, network);
116 this.port = null;
117 this.subnet = subnet;
118 }
119
120 /**
121 * Returns the port of the network event.
122 *
123 * @return openstack port; null if the event is not port specific
124 */
125 public Port port() {
126 return port;
127 }
128
129 /**
130 * Returns the subnet of the network event.
131 *
132 * @return openstack subnet; null if the event is not subnet specific
133 */
134 public Subnet subnet() {
135 return subnet;
136 }
137
138 @Override
139 public String toString() {
140 if (port == null && subnet == null) {
141 return super.toString();
142 }
143 return toStringHelper(this)
144 .add("time", new LocalDateTime(time()))
145 .add("type", type())
146 .add("network", subject())
147 .add("port", port)
148 .add("subnet", subnet)
149 .toString();
150 }
151}