5c371316edacbadf74abaceba672601a930e89a8
[policy/drools-applications.git] / vfwsim / src / main / java / org / openecomp / policy / sim / vfw / OnsetEvent.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * vFW simulator
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.policy.sim.vfw;
22
23 import java.io.Serializable;
24 import java.time.Instant;
25 import java.util.HashMap;
26 import java.util.UUID;
27
28 import org.openecomp.policy.controlloop.ControlLoopEventStatus;
29 import org.openecomp.policy.controlloop.ControlLoopTargetType;
30 import org.openecomp.policy.controlloop.VirtualControlLoopEvent;
31
32 public class OnsetEvent implements Serializable {
33         
34         private static final long serialVersionUID = -7904064194557621526L;
35         
36         public static String DEFAULT_CLOSEDLOOP_CONTROL_NAME = "CL-FRWL-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8";
37         public static String DEFAULT_CLOSEDLOOP_EVENT_CLIENT = "tca.instance00001";
38         public static String DEFAULT_REQUEST_ID = "664be3d2-6c12-4f4b-a3e7-c349acced200";
39         public static String DEFAULT_TARGET = "generic-vnf.vnf-id";
40         public static String DEFAULT_TARGET_TYPE = "VF";
41         public static String DEFAULT_FROM = "DCAE";
42
43         public static String DEFAULT_AAI_VNF_ID_NAME = DEFAULT_TARGET;
44         public static String DEFAULT_AAI_VNF_ID_VALUE = "fw0001vm001fw001";
45         
46         public static String DEFAULT_AAI_VSERVER_NAME = "vserver.vserver-name";
47         public static String DEFAULT_AAI_VSERVER_VALUE = "vserver-name-16102016-aai3255-data-11-1";
48
49         public String closedLoopControlName = DEFAULT_CLOSEDLOOP_CONTROL_NAME;
50         public String closedLoopEventClient = DEFAULT_CLOSEDLOOP_EVENT_CLIENT;
51         public String requestID = UUID.randomUUID().toString();
52         public String target = DEFAULT_TARGET;
53         public String targetType = DEFAULT_TARGET_TYPE;
54         public String aaIVnfId = DEFAULT_AAI_VNF_ID_VALUE;
55         public String aaIServerName = DEFAULT_AAI_VSERVER_VALUE;
56         public String from = "DCAE";
57         
58         public String dcaeTopic = "DCAE-CL-EVENT";
59         public String appcTopic = "APPC-CL";
60         public int appcResponseCode = 100;
61         
62         public OnsetEvent() {
63                 super();
64         }
65         
66         public OnsetEvent(String closedLoopControlName) {
67                 super();
68                 
69                 if (closedLoopControlName != null && !closedLoopControlName.isEmpty())
70                         this.closedLoopControlName = closedLoopControlName;
71         }
72         
73         public OnsetEvent(String closedLoopControlName, String dcaeTopic, String appcTopic, int code) {
74                 super();
75                 
76                 if (closedLoopControlName != null && !closedLoopControlName.isEmpty())
77                         this.closedLoopControlName = closedLoopControlName;
78                 
79                 if (dcaeTopic != null && !dcaeTopic.isEmpty())
80                         this.dcaeTopic = dcaeTopic;
81                 
82                 if (appcTopic != null && !appcTopic.isEmpty())
83                         this.appcTopic = appcTopic;
84                 
85                 this.appcResponseCode = code;
86         }
87         
88         public OnsetEvent(String closedLoopControlName, String requestID, String dcaeTopic, String appcTopic, int code) {
89                 super();
90                 
91                 if (closedLoopControlName != null && !closedLoopControlName.isEmpty())
92                         this.closedLoopControlName = closedLoopControlName;
93                 
94                 if (requestID != null)
95                         this.requestID = requestID;
96                 
97                 if (dcaeTopic != null && !dcaeTopic.isEmpty())
98                         this.dcaeTopic = dcaeTopic;
99                 
100                 if (appcTopic != null && !appcTopic.isEmpty())
101                         this.appcTopic = appcTopic;
102                 
103                 this.appcResponseCode = code;
104         }
105
106         public OnsetEvent(String closedLoopControlName, String closedLoopEventClient, 
107                                     String requestID, String target,
108                                     String targetType, String aaIVnfId, 
109                                     String aaIServerName, String from,
110                                     String dcaeTopic, String appcTopic,
111                                     int code) {
112                 super();
113                 
114                 if (closedLoopControlName != null && !closedLoopControlName.isEmpty())
115                         this.closedLoopControlName = closedLoopControlName;
116                 
117                 if (closedLoopEventClient != null && !closedLoopEventClient.isEmpty())
118                         this.closedLoopEventClient = closedLoopEventClient;
119                 
120                 if (requestID != null)
121                         this.requestID = requestID;
122                 
123                 if (target != null && !target.isEmpty())
124                         this.target = target;
125                 
126                 if (targetType != null && !targetType.isEmpty())
127                         this.targetType = targetType;
128                 
129                 if (aaIVnfId != null && !aaIVnfId.isEmpty())
130                         this.aaIVnfId = aaIVnfId;
131                 
132                 if (aaIServerName != null && !aaIServerName.isEmpty())
133                         this.aaIServerName = aaIServerName;
134                 
135                 if (from != null && !from.isEmpty())
136                         this.from = from;
137                 
138                 if (dcaeTopic != null && !dcaeTopic.isEmpty())
139                         this.dcaeTopic = dcaeTopic;
140                 
141                 if (appcTopic != null && !appcTopic.isEmpty())
142                         this.appcTopic = appcTopic;
143                 
144                 this.appcResponseCode = code;
145         }
146         
147         public VirtualControlLoopEvent toDcaeOnset() {
148                 
149                 VirtualControlLoopEvent onsetEvent = new VirtualControlLoopEvent();
150                 
151                 onsetEvent.closedLoopControlName = this.closedLoopControlName;
152                 onsetEvent.requestID = UUID.fromString(this.requestID);
153                 onsetEvent.closedLoopEventClient = this.closedLoopEventClient;
154                 onsetEvent.target_type = ControlLoopTargetType.valueOf(this.targetType);
155                 onsetEvent.target = this.target;
156                 onsetEvent.from = this.from;
157                 onsetEvent.closedLoopAlarmStart = Instant.now();
158                 onsetEvent.AAI = new HashMap<String, String>();
159                 onsetEvent.AAI.put(this.target, this.aaIVnfId);
160                 onsetEvent.AAI.put(DEFAULT_AAI_VSERVER_NAME, "vserver-name-16102016-aai3255-data-11-1");
161                 onsetEvent.closedLoopEventStatus = ControlLoopEventStatus.ONSET;
162                 
163                 return onsetEvent;
164         }
165
166         @Override
167         public int hashCode() {
168                 final int prime = 31;
169                 int result = 1;
170                 result = prime * result + ((aaIServerName == null) ? 0 : aaIServerName.hashCode());
171                 result = prime * result + ((aaIVnfId == null) ? 0 : aaIVnfId.hashCode());
172                 result = prime * result + appcResponseCode;
173                 result = prime * result + ((appcTopic == null) ? 0 : appcTopic.hashCode());
174                 result = prime * result + ((closedLoopControlName == null) ? 0 : closedLoopControlName.hashCode());
175                 result = prime * result + ((closedLoopEventClient == null) ? 0 : closedLoopEventClient.hashCode());
176                 result = prime * result + ((dcaeTopic == null) ? 0 : dcaeTopic.hashCode());
177                 result = prime * result + ((from == null) ? 0 : from.hashCode());
178                 result = prime * result + ((requestID == null) ? 0 : requestID.hashCode());
179                 result = prime * result + ((target == null) ? 0 : target.hashCode());
180                 result = prime * result + ((targetType == null) ? 0 : targetType.hashCode());
181                 return result;
182         }
183
184         @Override
185         public boolean equals(Object obj) {
186                 if (this == obj)
187                         return true;
188                 if (obj == null)
189                         return false;
190                 if (getClass() != obj.getClass())
191                         return false;
192                 OnsetEvent other = (OnsetEvent) obj;
193                 if (aaIServerName == null) {
194                         if (other.aaIServerName != null)
195                                 return false;
196                 } else if (!aaIServerName.equals(other.aaIServerName))
197                         return false;
198                 if (aaIVnfId == null) {
199                         if (other.aaIVnfId != null)
200                                 return false;
201                 } else if (!aaIVnfId.equals(other.aaIVnfId))
202                         return false;
203                 if (appcResponseCode != other.appcResponseCode)
204                         return false;
205                 if (appcTopic == null) {
206                         if (other.appcTopic != null)
207                                 return false;
208                 } else if (!appcTopic.equals(other.appcTopic))
209                         return false;
210                 if (closedLoopControlName == null) {
211                         if (other.closedLoopControlName != null)
212                                 return false;
213                 } else if (!closedLoopControlName.equals(other.closedLoopControlName))
214                         return false;
215                 if (closedLoopEventClient == null) {
216                         if (other.closedLoopEventClient != null)
217                                 return false;
218                 } else if (!closedLoopEventClient.equals(other.closedLoopEventClient))
219                         return false;
220                 if (dcaeTopic == null) {
221                         if (other.dcaeTopic != null)
222                                 return false;
223                 } else if (!dcaeTopic.equals(other.dcaeTopic))
224                         return false;
225                 if (from == null) {
226                         if (other.from != null)
227                                 return false;
228                 } else if (!from.equals(other.from))
229                         return false;
230                 if (requestID == null) {
231                         if (other.requestID != null)
232                                 return false;
233                 } else if (!requestID.equals(other.requestID))
234                         return false;
235                 if (target == null) {
236                         if (other.target != null)
237                                 return false;
238                 } else if (!target.equals(other.target))
239                         return false;
240                 if (targetType == null) {
241                         if (other.targetType != null)
242                                 return false;
243                 } else if (!targetType.equals(other.targetType))
244                         return false;
245                 return true;
246         }
247
248         @Override
249         public String toString() {
250                 return "OnsetEvent [closedLoopControlName=" + closedLoopControlName + ", closedLoopEventClient="
251                                 + closedLoopEventClient + ", requestID=" + requestID + ", target=" + target + ", targetType="
252                                 + targetType + ", aaIVnfId=" + aaIVnfId + ", aaIServerName=" + aaIServerName + ", from=" + from
253                                 + ", dcaeTopic=" + dcaeTopic + ", appcTopic=" + appcTopic + ", appcResponseCode=" + appcResponseCode
254                                 + "]";
255         }
256         
257 }