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.name();
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.equals(operType)) {
122 if (isOverlay(resourceType)) {
123 action = /*RequestInformation.*/RequestAction.DeActivateDCINetworkInstance.name();
124 } else if (isUnderlay(resourceType)) {
125 action = /*RequestInformation.*/RequestAction.DeleteNetworkInstance.name();
127 action = /*RequestInformation.*/RequestAction.DeleteServiceInstance.name();
129 } else if (RequestsDbConstant.OperationType.CREATE.equals(operType)) {
130 if (isOverlay(resourceType)) {
131 action = /*RequestInformation.*/RequestAction.ActivateDCINetworkInstance.name();
132 } else if (isUnderlay(resourceType)) {
133 action = /*RequestInformation.*/RequestAction.CreateNetworkInstance.name();
135 action = /*RequestInformation.*/RequestAction.CreateServiceInstance.name();
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.name();
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.equals(operType)) {
156 if (isOverlay(resourceType)) {
157 action = /*SdncRequestHeader.*/SvcAction.Deactivate.name();
159 action = /*SdncRequestHeader.*/SvcAction.Delete.name();
161 } else if (RequestsDbConstant.OperationType.CREATE.equals(operType)) {
162 if (isOverlay(resourceType)) {
163 action = /*SdncRequestHeader.*/SvcAction.Activate.name();
165 action = /*SdncRequestHeader.*/SvcAction.Create.name();
172 protected synchronized String getRequestId(DelegateExecution execution) {
173 if (StringUtils.isBlank(requestId)) {
174 requestId = (String) execution.getVariable("msoRequestId");
175 if (StringUtils.isBlank(requestId)) {
176 requestId = UUID.randomUUID().toString();
182 protected OnapModelInformationEntity getOnapModelInformationEntity(DelegateExecution execution) {
183 OnapModelInformationEntity onapModelInformationEntity = new OnapModelInformationEntity();
185 String modelInvariantUuid = (String) execution.getVariable("modelInvariantUuid");
186 String modelVersion = (String) execution.getVariable("modelVersion");
187 String modelUuid = (String) execution.getVariable("modelUuid");
188 String modelName = (String) execution.getVariable("modelName");
189 onapModelInformationEntity.setModelInvariantUuid(modelInvariantUuid);
190 onapModelInformationEntity.setModelVersion(modelVersion);
191 onapModelInformationEntity.setModelUuid(modelUuid);
192 onapModelInformationEntity.setModelName(modelName);
194 return onapModelInformationEntity;
197 protected List<ParamEntity> getParamEntities(Map<String, String> inputs) {
198 List<ParamEntity> paramEntityList = new ArrayList<>();
199 if (inputs != null && !inputs.isEmpty()) {
200 inputs.keySet().forEach(key -> {
201 ParamEntity paramEntity = new ParamEntity();
202 paramEntity.setName(key);
203 paramEntity.setValue(inputs.get(key));
204 paramEntityList.add(paramEntity);
207 return paramEntityList;
210 protected RequestInformationEntity getRequestInformationEntity(DelegateExecution execution) {
211 RequestInformationEntity requestInformationEntity = new RequestInformationEntity();
213 requestInformationEntity.setRequestId(getRequestId(execution));
214 requestInformationEntity.setRequestAction(getRequestActoin(execution));
216 return requestInformationEntity;
219 protected ServiceInformationEntity getServiceInformationEntity(DelegateExecution execution) {
220 ServiceInformationEntity serviceInformationEntity = new ServiceInformationEntity();
221 serviceInformationEntity.setServiceId((String) execution.getVariable("productFamilyId"));
222 serviceInformationEntity.setSubscriptionServiceType((String) execution.getVariable("subscriptionServiceType"));
223 serviceInformationEntity.setOnapModelInformation(getOnapModelInformationEntity(execution));
224 serviceInformationEntity.setServiceInstanceId((String) execution.getVariable("serviceInstanceId"));
225 serviceInformationEntity.setGlobalCustomerId((String) execution.getVariable("globalSubscriberId"));
226 return serviceInformationEntity;
229 protected String getServiceInstanceName(DelegateExecution execution) {
230 return (String) execution.getVariable("serviceInstanceName");