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;
27 import org.apache.commons.lang3.StringUtils;
28 import org.camunda.bpm.engine.delegate.DelegateExecution;
29 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.entity.OnapModelInformationEntity;
30 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.entity.ParamEntity;
31 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.entity.RequestInformationEntity;
32 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.entity.ServiceInformationEntity;
33 import org.onap.so.requestsdb.RequestsDbConstant;
35 public abstract class AbstractBuilder<I, O> {
37 public static final String OPERATION_TYPE = "operationType";
38 public static final String RESOURCE_TYPE = "resourceType";
40 public enum RequestAction {
41 CREATE_NETWORK_INSTANCE(0, "CreateNetworkInstance"), ACTIVATE_NETWORK_INSTANCE(1,
42 "ActivateNetworkInstance"), CREATE_SERVICE_INSTANCE(2,
43 "CreateServiceInstance"), DELETE_SERVICE_INSTANCE(3,
44 "DeleteServiceInstance"), DELETE_NETWORK_INSTANCE(4,
45 "DeleteNetworkInstance"), CREATE_VNF_INSTANCE(5,
46 "CreateVnfInstance"), ACTIVATE_VNF_INSTANCE(6,
47 "ActivateVnfInstance"), DELETE_VNF_INSTANCE(7,
48 "DeleteVnfInstance"), CREATE_VF_MODULE_INSTANCE(8,
49 "CreateVfModuleInstance"), ACTIVATE_VF_MODULE_INSTANCE(
51 "ActivateVfModuleInstance"), DELETE_VF_MODULE_INSTANCE(
53 "DeleteVfModuleInstance"), CREATE_CONTRAIL_ROUTE_INSTANCE(
55 "CreateContrailRouteInstance"), DELETE_CONTRAIL_ROUTE_INSTANCE(
57 "DeleteContrailRouteInstance"), CREATE_SECURITY_ZONE_INSTANCE(
59 "CreateSecurityZoneInstance"), DELETE_SECURITY_ZONE_INSTANCE(
61 "DeleteSecurityZoneInstance"), ACTIVATE_DCI_NETWORK_INSTANCE(
63 "ActivateDCINetworkInstance"), DEACTIVATE_DCI_NETWORK_INSTANCE(
65 "DeActivateDCINetworkInstance");
70 private RequestAction(int value, String name) {
75 public String getName() {
79 public int getIntValue() {
84 public enum SvcAction {
85 RESERVE(0, "reserve"), ASSIGN(1, "assign"), ACTIVATE(2, "activate"), DELETE(3, "delete"), CHANGEASSIGN(4,
86 "changeassign"), CHANGEDELETE(5, "changedelete"), ROLLBACK(6,
87 "rollback"), DEACTIVATE(7, "deactivate"), UNASSIGN(8, "unassign"), CREATE(9, "create");
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");