2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.policy.sim.vfw;
23 import java.io.Serializable;
24 import java.time.Instant;
25 import java.util.HashMap;
26 import java.util.UUID;
28 import org.openecomp.policy.controlloop.ControlLoopEventStatus;
29 import org.openecomp.policy.controlloop.ControlLoopTargetType;
30 import org.openecomp.policy.controlloop.VirtualControlLoopEvent;
32 public class OnsetEvent implements Serializable {
34 private static final long serialVersionUID = -7904064194557621526L;
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";
43 public static String DEFAULT_AAI_VNF_ID_NAME = DEFAULT_TARGET;
44 public static String DEFAULT_AAI_VNF_ID_VALUE = "fw0001vm001fw001";
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";
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";
58 public String dcaeTopic = "DCAE-CL-EVENT";
59 public String appcTopic = "APPC-CL";
60 public int appcResponseCode = 100;
66 public OnsetEvent(String closedLoopControlName) {
69 if (closedLoopControlName != null && !closedLoopControlName.isEmpty())
70 this.closedLoopControlName = closedLoopControlName;
73 public OnsetEvent(String closedLoopControlName, String dcaeTopic, String appcTopic, int code) {
76 if (closedLoopControlName != null && !closedLoopControlName.isEmpty())
77 this.closedLoopControlName = closedLoopControlName;
79 if (dcaeTopic != null && !dcaeTopic.isEmpty())
80 this.dcaeTopic = dcaeTopic;
82 if (appcTopic != null && !appcTopic.isEmpty())
83 this.appcTopic = appcTopic;
85 this.appcResponseCode = code;
88 public OnsetEvent(String closedLoopControlName, String requestID, String dcaeTopic, String appcTopic, int code) {
91 if (closedLoopControlName != null && !closedLoopControlName.isEmpty())
92 this.closedLoopControlName = closedLoopControlName;
94 if (requestID != null)
95 this.requestID = requestID;
97 if (dcaeTopic != null && !dcaeTopic.isEmpty())
98 this.dcaeTopic = dcaeTopic;
100 if (appcTopic != null && !appcTopic.isEmpty())
101 this.appcTopic = appcTopic;
103 this.appcResponseCode = code;
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,
114 if (closedLoopControlName != null && !closedLoopControlName.isEmpty())
115 this.closedLoopControlName = closedLoopControlName;
117 if (closedLoopEventClient != null && !closedLoopEventClient.isEmpty())
118 this.closedLoopEventClient = closedLoopEventClient;
120 if (requestID != null)
121 this.requestID = requestID;
123 if (target != null && !target.isEmpty())
124 this.target = target;
126 if (targetType != null && !targetType.isEmpty())
127 this.targetType = targetType;
129 if (aaIVnfId != null && !aaIVnfId.isEmpty())
130 this.aaIVnfId = aaIVnfId;
132 if (aaIServerName != null && !aaIServerName.isEmpty())
133 this.aaIServerName = aaIServerName;
135 if (from != null && !from.isEmpty())
138 if (dcaeTopic != null && !dcaeTopic.isEmpty())
139 this.dcaeTopic = dcaeTopic;
141 if (appcTopic != null && !appcTopic.isEmpty())
142 this.appcTopic = appcTopic;
144 this.appcResponseCode = code;
147 public VirtualControlLoopEvent toDcaeOnset() {
149 VirtualControlLoopEvent onsetEvent = new VirtualControlLoopEvent();
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;
167 public int hashCode() {
168 final int prime = 31;
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());
185 public boolean equals(Object obj) {
190 if (getClass() != obj.getClass())
192 OnsetEvent other = (OnsetEvent) obj;
193 if (aaIServerName == null) {
194 if (other.aaIServerName != null)
196 } else if (!aaIServerName.equals(other.aaIServerName))
198 if (aaIVnfId == null) {
199 if (other.aaIVnfId != null)
201 } else if (!aaIVnfId.equals(other.aaIVnfId))
203 if (appcResponseCode != other.appcResponseCode)
205 if (appcTopic == null) {
206 if (other.appcTopic != null)
208 } else if (!appcTopic.equals(other.appcTopic))
210 if (closedLoopControlName == null) {
211 if (other.closedLoopControlName != null)
213 } else if (!closedLoopControlName.equals(other.closedLoopControlName))
215 if (closedLoopEventClient == null) {
216 if (other.closedLoopEventClient != null)
218 } else if (!closedLoopEventClient.equals(other.closedLoopEventClient))
220 if (dcaeTopic == null) {
221 if (other.dcaeTopic != null)
223 } else if (!dcaeTopic.equals(other.dcaeTopic))
226 if (other.from != null)
228 } else if (!from.equals(other.from))
230 if (requestID == null) {
231 if (other.requestID != null)
233 } else if (!requestID.equals(other.requestID))
235 if (target == null) {
236 if (other.target != null)
238 } else if (!target.equals(other.target))
240 if (targetType == null) {
241 if (other.targetType != null)
243 } else if (!targetType.equals(other.targetType))
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