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.onap.so.bpmn.infrastructure.workflow.serviceTask.client.builder;
23 import java.util.ArrayList;
24 import java.util.List;
26 import java.util.UUID;
28 import org.apache.commons.lang3.StringUtils;
29 import org.camunda.bpm.engine.delegate.DelegateExecution;
30 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.entity.OnapModelInformationEntity;
31 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.entity.ParamEntity;
32 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.entity.RequestInformationEntity;
33 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.entity.ServiceInformationEntity;
34 import org.onap.so.requestsdb.RequestsDbConstant;
36 public abstract class AbstractBuilder<I, O> {
38 public static final String OPERATION_TYPE = "operationType";
39 public static final String RESOURCE_TYPE = "resourceType";
41 public enum RequestAction {
42 CREATE_NETWORK_INSTANCE(0, "CreateNetworkInstance"),
43 ACTIVATE_NETWORK_INSTANCE(1, "ActivateNetworkInstance"),
44 CREATE_SERVICE_INSTANCE(2, "CreateServiceInstance"),
45 DELETE_SERVICE_INSTANCE(3, "DeleteServiceInstance"),
46 DELETE_NETWORK_INSTANCE(4, "DeleteNetworkInstance"),
47 CREATE_VNF_INSTANCE(5, "CreateVnfInstance"),
48 ACTIVATE_VNF_INSTANCE(6, "ActivateVnfInstance"),
49 DELETE_VNF_INSTANCE(7, "DeleteVnfInstance"),
50 CREATE_VF_MODULE_INSTANCE(8, "CreateVfModuleInstance"),
51 ACTIVATE_VF_MODULE_INSTANCE(9, "ActivateVfModuleInstance"),
52 DELETE_VF_MODULE_INSTANCE(10, "DeleteVfModuleInstance"),
53 CREATE_CONTRAIL_ROUTE_INSTANCE(11, "CreateContrailRouteInstance"),
54 DELETE_CONTRAIL_ROUTE_INSTANCE(12, "DeleteContrailRouteInstance"),
55 CREATE_SECURITY_ZONE_INSTANCE(13, "CreateSecurityZoneInstance"),
56 DELETE_SECURITY_ZONE_INSTANCE(14, "DeleteSecurityZoneInstance"),
57 ACTIVATE_DCI_NETWORK_INSTANCE(15, "ActivateDCINetworkInstance"),
58 DEACTIVATE_DCI_NETWORK_INSTANCE(16, "DeActivateDCINetworkInstance");
63 private RequestAction(int value, String name) {
68 public String getName() {
72 public int getIntValue() {
77 public enum SvcAction {
78 RESERVE(0, "reserve"),
80 ACTIVATE(2, "activate"),
82 CHANGEASSIGN(4, "changeassign"),
83 CHANGEDELETE(5, "changedelete"),
84 ROLLBACK(6, "rollback"),
85 DEACTIVATE(7, "deactivate"),
86 UNASSIGN(8, "unassign"),
92 private SvcAction(int value, String name) {
97 public String getName() {
101 public int getIntValue() {
106 protected String requestId = null;
108 abstract O build(DelegateExecution execution, I input) throws Exception;
110 protected String getRequestAction(DelegateExecution execution) {
111 String action = /*RequestInformation.*/RequestAction.CREATE_NETWORK_INSTANCE.getName();
112 String operType = (String) execution.getVariable(OPERATION_TYPE);
113 String resourceType = (String)execution.getVariable(RESOURCE_TYPE);
114 if (!StringUtils.isBlank(operType)) {
115 if (RequestsDbConstant.OperationType.DELETE.equalsIgnoreCase(operType)) {
116 if (isOverlay(resourceType)) {
117 action = /*RequestInformation.*/RequestAction.DEACTIVATE_DCI_NETWORK_INSTANCE.getName();
118 } else if (isUnderlay(resourceType)) {
119 action = /*RequestInformation.*/RequestAction.DELETE_NETWORK_INSTANCE.getName();
121 action = /*RequestInformation.*/RequestAction.DELETE_SERVICE_INSTANCE.getName();
123 } else if (RequestsDbConstant.OperationType.CREATE.equalsIgnoreCase(operType)) {
124 if (isOverlay(resourceType)) {
125 action = /*RequestInformation.*/RequestAction.ACTIVATE_DCI_NETWORK_INSTANCE.getName();
126 } else if (isUnderlay(resourceType)) {
127 action = /*RequestInformation.*/RequestAction.CREATE_NETWORK_INSTANCE.getName();
129 action = /*RequestInformation.*/RequestAction.CREATE_SERVICE_INSTANCE.getName();
136 private boolean isOverlay(String resourceType) {
137 return !StringUtils.isBlank(resourceType) && resourceType.toLowerCase().contains("overlay");
140 private boolean isUnderlay(String resourceType) {
141 return !StringUtils.isBlank(resourceType) && resourceType.toLowerCase().contains("underlay");
144 protected String getSvcAction(DelegateExecution execution) {
145 String action = /*SdncRequestHeader.*/SvcAction.CREATE.getName();
146 String operType = (String) execution.getVariable(OPERATION_TYPE);
147 String resourceType = (String)execution.getVariable(RESOURCE_TYPE);
148 if (!StringUtils.isBlank(operType)) {
149 if (RequestsDbConstant.OperationType.DELETE.equalsIgnoreCase(operType)) {
150 if (isOverlay(resourceType)) {
151 action = /*SdncRequestHeader.*/SvcAction.DEACTIVATE.getName();
152 } else if (isUnderlay(resourceType)) {
153 action = /*SdncRequestHeader.*/SvcAction.DELETE.getName();
155 action = /*SdncRequestHeader.*/SvcAction.UNASSIGN.getName();
157 } else if (RequestsDbConstant.OperationType.CREATE.equalsIgnoreCase(operType)) {
158 if (isOverlay(resourceType)) {
159 action = /*SdncRequestHeader.*/SvcAction.ACTIVATE.getName();
160 } else if (isUnderlay(resourceType)) {
161 action = /*SdncRequestHeader.*/SvcAction.CREATE.getName();
163 action = /*SdncRequestHeader.*/SvcAction.ASSIGN.getName();
170 protected synchronized String getRequestId(DelegateExecution execution) {
171 if (StringUtils.isBlank(requestId)) {
172 requestId = (String) execution.getVariable("msoRequestId");
173 if (StringUtils.isBlank(requestId)) {
174 requestId = UUID.randomUUID().toString();
180 protected OnapModelInformationEntity getOnapServiceModelInformationEntity(DelegateExecution execution) {
181 OnapModelInformationEntity onapModelInformationEntity = new OnapModelInformationEntity();
182 String modelInvariantUuid = (String) execution.getVariable("modelInvariantUuid");
183 String modelVersion = (String) execution.getVariable("modelVersion");
184 String modelUuid = (String) execution.getVariable("modelUuid");
185 String modelName = (String) execution.getVariable("serviceModelName");
186 onapModelInformationEntity.setModelInvariantUuid(modelInvariantUuid);
187 onapModelInformationEntity.setModelVersion(modelVersion);
188 onapModelInformationEntity.setModelUuid(modelUuid);
189 onapModelInformationEntity.setModelName(modelName);
190 return onapModelInformationEntity;
193 protected OnapModelInformationEntity getOnapNetworkModelInformationEntity(DelegateExecution execution) {
194 OnapModelInformationEntity onapModelInformationEntity = new OnapModelInformationEntity();
195 String modelInvariantUuid = (String) execution.getVariable("resourceInvariantUUID");
196 String modelVersion = (String) execution.getVariable("modelVersion");
197 String modelUuid = (String) execution.getVariable("resourceUUID");
198 String modelName = (String) execution.getVariable(RESOURCE_TYPE);
199 onapModelInformationEntity.setModelInvariantUuid(modelInvariantUuid);
200 onapModelInformationEntity.setModelVersion(modelVersion);
201 onapModelInformationEntity.setModelUuid(modelUuid);
202 onapModelInformationEntity.setModelName(modelName);
203 return onapModelInformationEntity;
206 protected List<ParamEntity> getParamEntities(Map<String, String> inputs) {
207 List<ParamEntity> paramEntityList = new ArrayList<>();
208 if (inputs != null && !inputs.isEmpty()) {
209 inputs.keySet().forEach(key -> {
210 ParamEntity paramEntity = new ParamEntity();
211 paramEntity.setName(key);
212 paramEntity.setValue(inputs.get(key));
213 paramEntityList.add(paramEntity);
216 return paramEntityList;
219 protected RequestInformationEntity getRequestInformationEntity(DelegateExecution execution) {
220 RequestInformationEntity requestInformationEntity = new RequestInformationEntity();
221 requestInformationEntity.setRequestId(getRequestId(execution));
222 requestInformationEntity.setRequestAction(getRequestAction(execution));
223 return requestInformationEntity;
226 protected ServiceInformationEntity getServiceInformationEntity(DelegateExecution execution) {
227 ServiceInformationEntity serviceInformationEntity = new ServiceInformationEntity();
228 serviceInformationEntity.setServiceId((String) execution.getVariable("serviceInstanceId"));
229 serviceInformationEntity.setSubscriptionServiceType((String) execution.getVariable("serviceType"));
230 serviceInformationEntity.setOnapModelInformation(getOnapServiceModelInformationEntity(execution));
231 serviceInformationEntity.setServiceInstanceId((String) execution.getVariable("serviceInstanceId"));
232 serviceInformationEntity.setGlobalCustomerId((String) execution.getVariable("globalSubscriberId"));
233 return serviceInformationEntity;
236 protected String getServiceInstanceName(DelegateExecution execution) {
237 return (String) execution.getVariable("serviceInstanceName");