2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Huawei Technologies Co., Ltd. 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.scripts
23 import java.util.ArrayList
24 import java.util.Iterator
26 import org.apache.commons.lang3.StringUtils
27 import org.apache.http.HttpResponse
28 import org.camunda.bpm.engine.delegate.DelegateExecution
29 import org.codehaus.groovy.runtime.ArrayUtil
30 import org.codehaus.groovy.runtime.ScriptBytecodeAdapter
31 import org.codehaus.groovy.runtime.callsite.CallSite
32 import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation
33 import org.codehaus.groovy.runtime.typehandling.ShortTypeHandling
34 import org.json.JSONArray
35 import org.json.JSONObject
36 import org.openecomp.mso.bpmn.common.recipe.BpmnRestClient
37 import org.openecomp.mso.bpmn.common.recipe.ResourceInput
38 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
39 import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils
40 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
41 import org.openecomp.mso.bpmn.core.domain.AllottedResource
42 import org.openecomp.mso.bpmn.core.domain.NetworkResource
43 import org.openecomp.mso.bpmn.core.domain.Resource
44 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition
45 import org.openecomp.mso.bpmn.core.domain.VnfResource
46 import org.openecomp.mso.bpmn.core.json.JsonUtils
47 import org.openecomp.mso.bpmn.common.resource.ResourceRequestBuilder
50 * This groovy class supports the <class>DoCreateResources.bpmn</class> process.
53 * @param - msoRequestId
54 * @param - globalSubscriberId - O
55 * @param - subscriptionServiceType - O
56 * @param - serviceInstanceId
57 * @param - serviceInstanceName - O
58 * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)
59 * @param - sdncVersion
61 * @param - addResourceList
64 * @param - WorkflowException
67 public class DoCreateResources extends AbstractServiceTaskProcessor
69 ExceptionUtil exceptionUtil = new ExceptionUtil()
70 JsonUtils jsonUtil = new JsonUtils()
71 CatalogDbUtils cutils = new CatalogDbUtils()
73 public void preProcessRequest(DelegateExecution execution)
75 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
76 utils.log("INFO"," ***** preProcessRequest *****", isDebugEnabled)
79 List addResourceList = execution.getVariable("addResourceList")
80 if (addResourceList == null)
82 msg = "Input addResourceList is null"
83 utils.log("INFO", msg, isDebugEnabled)
84 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
86 else if (addResourceList.size() == 0)
88 msg = "No resource in addResourceList"
89 utils.log("INFO", msg, isDebugEnabled)
91 utils.log("INFO", " ***** Exit preProcessRequest *****", isDebugEnabled)
94 public void sequenceResoure(DelegateExecution execution)
96 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
97 utils.log("INFO", "======== Start sequenceResoure Process ======== ", isDebugEnabled)
99 String serviceModelUUID = execution.getVariable("modelUuid")
101 List<Resource> addResourceList = execution.getVariable("addResourceList")
103 //we use VF to define a network service
104 List<VnfResource> vnfResourceList = new ArrayList<VnfResource>()
105 //here wan is defined as a network resource
106 List<NetworkResource> networkResourceList = new ArrayList<NetworkResource>()
108 List<AllottedResource> arResourceList = new ArrayList<AllottedResource>()
110 //define sequenced resource list, we deploy vf first and then network and then ar
111 //this is defaule sequence
112 List<Resource> sequencedResourceList = new ArrayList<Resource>()
113 for (Resource rc : addResourceList){
114 if (rc instanceof VnfResource) {
115 vnfResourceList.add(rc)
116 } else if (rc instanceof NetworkResource) {
117 networkResourceList.add(rc)
118 } else if (rc instanceof AllottedResource) {
119 arResourceList.add(rc)
122 sequencedResourceList.addAll(vnfResourceList)
123 sequencedResourceList.addAll(networkResourceList)
124 sequencedResourceList.addAll(arResourceList)
126 String isContainsWanResource = networkResourceList.isEmpty() ? "false" : "true"
127 execution.setVariable("isContainsWanResource", isContainsWanResource)
128 execution.setVariable("currentResourceIndex", 0)
129 execution.setVariable("sequencedResourceList", sequencedResourceList)
130 utils.log("INFO", "sequencedResourceList: " + sequencedResourceList, isDebugEnabled)
131 utils.log("INFO", "======== COMPLETED sequenceResoure Process ======== ", isDebugEnabled)
134 public void getCurrentResoure(DelegateExecution execution){
135 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
136 utils.log("INFO", "======== Start getCurrentResoure Process ======== ", isDebugEnabled)
137 def currentIndex = execution.getVariable("currentResourceIndex")
138 List<Resource> sequencedResourceList = execution.getVariable("sequencedResourceList")
139 Resource currentResource = sequencedResourceList.get(currentIndex)
140 execution.setVariable("resourceType", currentResource.getModelInfo().getModelName())
141 utils.log("INFO", "Now we deal with resouce:" + currentResource.getModelInfo().getModelName(), isDebugEnabled)
142 utils.log("INFO", "======== COMPLETED getCurrentResoure Process ======== ", isDebugEnabled)
145 public void parseNextResource(DelegateExecution execution){
146 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
147 utils.log("INFO", "======== Start parseNextResource Process ======== ", isDebugEnabled)
148 def currentIndex = execution.getVariable("currentResourceIndex")
149 def nextIndex = currentIndex + 1
150 execution.setVariable("currentResourceIndex", nextIndex)
151 List<String> sequencedResourceList = execution.getVariable("sequencedResourceList")
152 if(nextIndex >= sequencedResourceList.size()){
153 execution.setVariable("allResourceFinished", "true")
155 execution.setVariable("allResourceFinished", "false")
157 utils.log("INFO", "======== COMPLETED parseNextResource Process ======== ", isDebugEnabled)
160 public void prepareResourceRecipeRequest(DelegateExecution execution){
161 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
162 utils.log("INFO", "======== Start prepareResourceRecipeRequest Process ======== ", isDebugEnabled)
163 ResourceInput resourceInput = new ResourceInput()
164 String serviceInstanceName = execution.getVariable("serviceInstanceName")
165 String resourceType = execution.getVariable("resourceType")
166 String resourceInstanceName = resourceType + "_" + serviceInstanceName
167 resourceInput.setResourceInstanceName(resourceInstanceName)
168 utils.log("INFO", "Prepare Resource Request resourceInstanceName:" + resourceInstanceName, isDebugEnabled)
169 String globalSubscriberId = execution.getVariable("globalSubscriberId")
170 String serviceType = execution.getVariable("serviceType")
171 String serviceInstanceId = execution.getVariable("serviceInstanceId")
172 String operationId = execution.getVariable("operationId")
173 String operationType = execution.getVariable("operationType")
174 resourceInput.setGlobalSubscriberId(globalSubscriberId)
175 resourceInput.setServiceType(serviceType)
176 resourceInput.setServiceInstanceId(serviceInstanceId)
177 resourceInput.setOperationId(operationId)
178 resourceInput.setOperationType(operationType);
179 def currentIndex = execution.getVariable("currentResourceIndex")
180 List<Resource> sequencedResourceList = execution.getVariable("sequencedResourceList")
181 Resource currentResource = sequencedResourceList.get(currentIndex)
182 resourceInput.setResourceModelInfo(currentResource.getModelInfo());
183 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
184 resourceInput.setServiceModelInfo(serviceDecomposition.getModelInfo());
186 String incomingRequest = execution.getVariable("uuiRequest")
187 //set the requestInputs from tempalte To Be Done
188 String serviceModelUuid = jsonUtil.getJsonValue(incomingRequest,"service.serviceUuid")
189 String serviceParameters = jsonUtil.getJsonValue(incomingRequest, "service.parameters")
190 String resourceParameters = ResourceRequestBuilder.buildResourceRequestParameters(execution, serviceModelUuid, resourceCustomizationUuid, serviceParameters)
191 resourceInput.setResourceParameters(resourceParameters)
192 execution.setVariable("resourceInput", resourceInput)
193 utils.log("INFO", "======== COMPLETED prepareResourceRecipeRequest Process ======== ", isDebugEnabled)
196 public void executeResourceRecipe(DelegateExecution execution){
197 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
198 utils.log("INFO", "======== Start executeResourceRecipe Process ======== ", isDebugEnabled)
199 String requestId = execution.getVariable("msoRequestId")
200 String serviceInstanceId = execution.getVariable("serviceInstanceId")
201 String serviceType = execution.getVariable("serviceType")
202 ResourceInput resourceInput = execution.getVariable("resourceInput")
203 String requestAction = resourceInput.getOperationType()
204 JSONObject resourceRecipe = cutils.getResourceRecipe(execution, resourceInput.getResourceModelInfo().getModelUuid(), requestAction)
205 String recipeUri = resourceRecipe.getString("orchestrationUri")
206 String recipeTimeOut = resourceRecipe.getString("recipeTimeout")
207 String recipeParamXsd = resourceRecipe.get("paramXSD")
208 HttpResponse resp = BpmnRestClient.post(recipeUri, requestId, recipeTimeOut, requestAction, serviceInstanceId, serviceType, resourceInput.toString(), recipeParamXsd)
212 public void postConfigRequest(DelegateExecution execution){