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.mso.bpmn.infrastructure.workflow.serviceTask.client.builder;
23 import org.apache.commons.lang3.StringUtils;
24 import org.camunda.bpm.engine.delegate.DelegateExecution;
25 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.entity.OnapModelInformationEntity;
26 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.entity.ParamEntity;
27 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.entity.RequestInformationEntity;
28 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.entity.ServiceInformationEntity;
29 import org.openecomp.mso.requestsdb.RequestsDbConstant;
31 import java.util.ArrayList;
32 import java.util.List;
34 import java.util.UUID;
36 //import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.request.information.RequestInformation;
37 //import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.sdnc.request.header.SdncRequestHeader;
40 * Created by 10112215 on 2017/9/20.
42 public abstract class AbstractBuilder<IN, OUT> {
44 public static final String OPERATION_TYPE = "operationType";
45 public static final String RESOURCE_TYPE = "resourceType";
47 public static enum RequestAction {
48 CreateNetworkInstance(0, "CreateNetworkInstance"),
49 ActivateNetworkInstance(1, "ActivateNetworkInstance"),
50 CreateServiceInstance(2, "CreateServiceInstance"),
51 DeleteServiceInstance(3, "DeleteServiceInstance"),
52 DeleteNetworkInstance(4, "DeleteNetworkInstance"),
53 CreateVnfInstance(5, "CreateVnfInstance"),
54 ActivateVnfInstance(6, "ActivateVnfInstance"),
55 DeleteVnfInstance(7, "DeleteVnfInstance"),
56 CreateVfModuleInstance(8, "CreateVfModuleInstance"),
57 ActivateVfModuleInstance(9, "ActivateVfModuleInstance"),
58 DeleteVfModuleInstance(10, "DeleteVfModuleInstance"),
59 CreateContrailRouteInstance(11, "CreateContrailRouteInstance"),
60 DeleteContrailRouteInstance(12, "DeleteContrailRouteInstance"),
61 CreateSecurityZoneInstance(13, "CreateSecurityZoneInstance"),
62 DeleteSecurityZoneInstance(14, "DeleteSecurityZoneInstance"),
63 ActivateDCINetworkInstance(15, "ActivateDCINetworkInstance"),
64 DeActivateDCINetworkInstance(16, "DeActivateDCINetworkInstance");
69 private RequestAction(int value, String name) {
74 public String getName() {
78 public int getIntValue() {
83 public enum SvcAction {
84 Reserve(0, "reserve"),
86 Activate(2, "activate"),
88 Changeassign(4, "changeassign"),
89 Changedelete(5, "changedelete"),
90 Rollback(6, "rollback"),
91 Deactivate(7, "deactivate"),
92 Unassign(8, "unassign"),
98 private SvcAction(int value, String name) {
103 public String getName() {
107 public int getIntValue() {
112 protected String requestId = null;
114 abstract OUT build(DelegateExecution execution, IN input) throws Exception;
116 protected String getRequestActoin(DelegateExecution execution) {
117 String action = /*RequestInformation.*/RequestAction.CreateNetworkInstance.getName();
118 String operType = (String) execution.getVariable(OPERATION_TYPE);
119 String resourceType = ((String) execution.getVariable(RESOURCE_TYPE)).toLowerCase();
120 if (!StringUtils.isBlank(operType)) {
121 if (RequestsDbConstant.OperationType.DELETE.equalsIgnoreCase(operType)) {
122 if (isOverlay(resourceType)) {
123 action = /*RequestInformation.*/RequestAction.DeActivateDCINetworkInstance.getName();
124 } else if (isUnderlay(resourceType)) {
125 action = /*RequestInformation.*/RequestAction.DeleteNetworkInstance.getName();
127 action = /*RequestInformation.*/RequestAction.DeleteServiceInstance.getName();
129 } else if (RequestsDbConstant.OperationType.CREATE.equalsIgnoreCase(operType)) {
130 if (isOverlay(resourceType)) {
131 action = /*RequestInformation.*/RequestAction.ActivateDCINetworkInstance.getName();
132 } else if (isUnderlay(resourceType)) {
133 action = /*RequestInformation.*/RequestAction.CreateNetworkInstance.getName();
135 action = /*RequestInformation.*/RequestAction.CreateServiceInstance.getName();
142 private boolean isOverlay(String resourceType) {
143 return !StringUtils.isBlank(resourceType) && resourceType.contains("overlay");
146 private boolean isUnderlay(String resourceType) {
147 return !StringUtils.isBlank(resourceType) && resourceType.contains("underlay");
150 protected String getSvcAction(DelegateExecution execution) {
151 String action = /*SdncRequestHeader.*/SvcAction.Create.getName();
152 String operType = (String) execution.getVariable(OPERATION_TYPE);
153 String resourceType = ((String) execution.getVariable(RESOURCE_TYPE)).toLowerCase();
154 if (!StringUtils.isBlank(operType)) {
155 if (RequestsDbConstant.OperationType.DELETE.equalsIgnoreCase(operType)) {
156 if (isOverlay(resourceType)) {
157 action = /*SdncRequestHeader.*/SvcAction.Deactivate.getName();
158 } else if (isUnderlay(resourceType)) {
159 action = /*SdncRequestHeader.*/SvcAction.Delete.getName();
161 action = /*SdncRequestHeader.*/SvcAction.Unassign.getName();
163 } else if (RequestsDbConstant.OperationType.CREATE.equalsIgnoreCase(operType)) {
164 if (isOverlay(resourceType)) {
165 action = /*SdncRequestHeader.*/SvcAction.Activate.getName();
166 } else if (isUnderlay(resourceType)) {
167 action = /*SdncRequestHeader.*/SvcAction.Create.getName();
169 action = /*SdncRequestHeader.*/SvcAction.Assign.getName();
176 protected synchronized String getRequestId(DelegateExecution execution) {
177 if (StringUtils.isBlank(requestId)) {
178 requestId = (String) execution.getVariable("msoRequestId");
179 if (StringUtils.isBlank(requestId)) {
180 requestId = UUID.randomUUID().toString();
186 protected OnapModelInformationEntity getOnapServiceModelInformationEntity(DelegateExecution execution) {
187 OnapModelInformationEntity onapModelInformationEntity = new OnapModelInformationEntity();
189 String modelInvariantUuid = (String) execution.getVariable("modelInvariantUuid");
190 String modelVersion = (String) execution.getVariable("modelVersion");
191 String modelUuid = (String) execution.getVariable("modelUuid");
192 String modelName = (String) execution.getVariable("serviceModelName");
193 onapModelInformationEntity.setModelInvariantUuid(modelInvariantUuid);
194 onapModelInformationEntity.setModelVersion(modelVersion);
195 onapModelInformationEntity.setModelUuid(modelUuid);
196 onapModelInformationEntity.setModelName(modelName);
198 return onapModelInformationEntity;
201 protected OnapModelInformationEntity getOnapNetworkModelInformationEntity(DelegateExecution execution) {
202 OnapModelInformationEntity onapModelInformationEntity = new OnapModelInformationEntity();
204 String modelInvariantUuid = (String) execution.getVariable("resourceInvariantUUID");
205 String modelVersion = (String) execution.getVariable("modelVersion");
206 String modelUuid = (String) execution.getVariable("resourceUUID");
207 String modelName = (String) execution.getVariable("resourceType");
208 onapModelInformationEntity.setModelInvariantUuid(modelInvariantUuid);
209 onapModelInformationEntity.setModelVersion(modelVersion);
210 onapModelInformationEntity.setModelUuid(modelUuid);
211 onapModelInformationEntity.setModelName(modelName);
213 return onapModelInformationEntity;
216 protected List<ParamEntity> getParamEntities(Map<String, String> inputs) {
217 List<ParamEntity> paramEntityList = new ArrayList<>();
218 if (inputs != null && !inputs.isEmpty()) {
219 inputs.keySet().forEach(key -> {
220 ParamEntity paramEntity = new ParamEntity();
221 paramEntity.setName(key);
222 paramEntity.setValue(inputs.get(key));
223 paramEntityList.add(paramEntity);
226 return paramEntityList;
229 protected RequestInformationEntity getRequestInformationEntity(DelegateExecution execution) {
230 RequestInformationEntity requestInformationEntity = new RequestInformationEntity();
232 requestInformationEntity.setRequestId(getRequestId(execution));
233 requestInformationEntity.setRequestAction(getRequestActoin(execution));
235 return requestInformationEntity;
238 protected ServiceInformationEntity getServiceInformationEntity(DelegateExecution execution) {
239 ServiceInformationEntity serviceInformationEntity = new ServiceInformationEntity();
240 serviceInformationEntity.setServiceId("VOLTE_SERVICE_ID");
241 serviceInformationEntity.setSubscriptionServiceType((String) execution.getVariable("serviceType"));
242 serviceInformationEntity.setOnapModelInformation(getOnapServiceModelInformationEntity(execution));
243 serviceInformationEntity.setServiceInstanceId((String) execution.getVariable("serviceInstanceId"));
244 serviceInformationEntity.setGlobalCustomerId((String) execution.getVariable("globalSubscriberId"));
245 return serviceInformationEntity;
248 protected String getServiceInstanceName(DelegateExecution execution) {
249 return (String) execution.getVariable("serviceInstanceName");