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 org.openecomp.mso.bpmn.infrastructure.properties.BPMNProperties
25 import java.util.ArrayList
26 import java.util.Iterator
28 import org.apache.commons.lang3.StringUtils
29 import org.apache.http.HttpResponse
30 import org.camunda.bpm.engine.delegate.DelegateExecution
31 import org.codehaus.groovy.runtime.ArrayUtil
32 import org.codehaus.groovy.runtime.ScriptBytecodeAdapter
33 import org.codehaus.groovy.runtime.callsite.CallSite
34 import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation
35 import org.codehaus.groovy.runtime.typehandling.ShortTypeHandling
36 import org.json.JSONArray
37 import org.json.JSONObject
38 import org.openecomp.mso.bpmn.common.recipe.BpmnRestClient
39 import org.openecomp.mso.bpmn.common.recipe.ResourceInput
40 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
41 import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils
42 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
43 import org.openecomp.mso.bpmn.core.domain.AllottedResource
44 import org.openecomp.mso.bpmn.core.domain.NetworkResource
45 import org.openecomp.mso.bpmn.core.domain.Resource
46 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition
47 import org.openecomp.mso.bpmn.core.domain.VnfResource
48 import org.openecomp.mso.bpmn.core.json.JsonUtils
49 import org.openecomp.mso.bpmn.common.resource.ResourceRequestBuilder
52 * This groovy class supports the <class>DoCreateResources.bpmn</class> process.
55 * @param - msoRequestId
56 * @param - globalSubscriberId - O
57 * @param - subscriptionServiceType - O
58 * @param - serviceInstanceId
59 * @param - serviceInstanceName - O
60 * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)
61 * @param - sdncVersion
63 * @param - addResourceList
66 * @param - WorkflowException
69 public class DoCreateResources extends AbstractServiceTaskProcessor
71 ExceptionUtil exceptionUtil = new ExceptionUtil()
72 JsonUtils jsonUtil = new JsonUtils()
73 CatalogDbUtils cutils = new CatalogDbUtils()
75 public void preProcessRequest(DelegateExecution execution)
77 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
78 utils.log("INFO"," ***** preProcessRequest *****", isDebugEnabled)
81 List addResourceList = execution.getVariable("addResourceList")
82 if (addResourceList == null)
84 msg = "Input addResourceList is null"
85 utils.log("INFO", msg, isDebugEnabled)
86 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
88 else if (addResourceList.size() == 0)
90 msg = "No resource in addResourceList"
91 utils.log("INFO", msg, isDebugEnabled)
93 utils.log("INFO", " ***** Exit preProcessRequest *****", isDebugEnabled)
96 public void sequenceResoure(DelegateExecution execution)
98 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
99 utils.log("INFO", "======== Start sequenceResoure Process ======== ", isDebugEnabled)
101 String serviceModelUUID = execution.getVariable("modelUuid")
103 List<Resource> addResourceList = execution.getVariable("addResourceList")
104 List<NetworkResource> networkResourceList = new ArrayList<NetworkResource>()
106 List<Resource> sequencedResourceList = new ArrayList<Resource>()
107 def resourceSequence = BPMNProperties.getResourceSequenceProp()
109 if(resourceSequence != null) {
110 // sequence is defined in config file
111 for (resourceType in resourceSequence) {
112 for (resource in addResourceList) {
113 if (StringUtils.containsIgnoreCase(resource.getModelInfo().getModelName(), resourceType)) {
114 sequencedResourceList.add(resource)
116 if (resource instanceof NetworkResource) {
117 networkResourceList.add(resource)
124 //define sequenced resource list, we deploy vf first and then network and then ar
125 //this is defaule sequence
126 List<VnfResource> vnfResourceList = new ArrayList<VnfResource>()
127 List<AllottedResource> arResourceList = new ArrayList<AllottedResource>()
129 for (Resource rc : addResourceList){
130 if (rc instanceof VnfResource) {
131 vnfResourceList.add(rc)
132 } else if (rc instanceof NetworkResource) {
133 networkResourceList.add(rc)
134 } else if (rc instanceof AllottedResource) {
135 arResourceList.add(rc)
138 sequencedResourceList.addAll(vnfResourceList)
139 sequencedResourceList.addAll(networkResourceList)
140 sequencedResourceList.addAll(arResourceList)
143 String isContainsWanResource = networkResourceList.isEmpty() ? "false" : "true"
144 execution.setVariable("isContainsWanResource", isContainsWanResource)
145 execution.setVariable("currentResourceIndex", 0)
146 execution.setVariable("sequencedResourceList", sequencedResourceList)
147 utils.log("INFO", "sequencedResourceList: " + sequencedResourceList, isDebugEnabled)
148 utils.log("INFO", "======== COMPLETED sequenceResoure Process ======== ", isDebugEnabled)
151 public void getCurrentResoure(DelegateExecution execution){
152 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
153 utils.log("INFO", "======== Start getCurrentResoure Process ======== ", isDebugEnabled)
154 def currentIndex = execution.getVariable("currentResourceIndex")
155 List<Resource> sequencedResourceList = execution.getVariable("sequencedResourceList")
156 Resource currentResource = sequencedResourceList.get(currentIndex)
157 execution.setVariable("resourceType", currentResource.getModelInfo().getModelName())
158 utils.log("INFO", "Now we deal with resouce:" + currentResource.getModelInfo().getModelName(), isDebugEnabled)
159 utils.log("INFO", "======== COMPLETED getCurrentResoure Process ======== ", isDebugEnabled)
162 public void parseNextResource(DelegateExecution execution){
163 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
164 utils.log("INFO", "======== Start parseNextResource Process ======== ", isDebugEnabled)
165 def currentIndex = execution.getVariable("currentResourceIndex")
166 def nextIndex = currentIndex + 1
167 execution.setVariable("currentResourceIndex", nextIndex)
168 List<String> sequencedResourceList = execution.getVariable("sequencedResourceList")
169 if(nextIndex >= sequencedResourceList.size()){
170 execution.setVariable("allResourceFinished", "true")
172 execution.setVariable("allResourceFinished", "false")
174 utils.log("INFO", "======== COMPLETED parseNextResource Process ======== ", isDebugEnabled)
177 public void prepareResourceRecipeRequest(DelegateExecution execution){
178 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
179 utils.log("INFO", "======== Start prepareResourceRecipeRequest Process ======== ", isDebugEnabled)
180 ResourceInput resourceInput = new ResourceInput()
181 String serviceInstanceName = execution.getVariable("serviceInstanceName")
182 String resourceType = execution.getVariable("resourceType")
183 String resourceInstanceName = resourceType + "_" + serviceInstanceName
184 resourceInput.setResourceInstanceName(resourceInstanceName)
185 utils.log("INFO", "Prepare Resource Request resourceInstanceName:" + resourceInstanceName, isDebugEnabled)
186 String globalSubscriberId = execution.getVariable("globalSubscriberId")
187 String serviceType = execution.getVariable("serviceType")
188 String serviceInstanceId = execution.getVariable("serviceInstanceId")
189 String operationId = execution.getVariable("operationId")
190 String operationType = execution.getVariable("operationType")
191 resourceInput.setGlobalSubscriberId(globalSubscriberId)
192 resourceInput.setServiceType(serviceType)
193 resourceInput.setServiceInstanceId(serviceInstanceId)
194 resourceInput.setOperationId(operationId)
195 resourceInput.setOperationType(operationType);
196 def currentIndex = execution.getVariable("currentResourceIndex")
197 List<Resource> sequencedResourceList = execution.getVariable("sequencedResourceList")
198 Resource currentResource = sequencedResourceList.get(currentIndex)
199 resourceInput.setResourceModelInfo(currentResource.getModelInfo());
200 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
201 resourceInput.setServiceModelInfo(serviceDecomposition.getModelInfo());
202 def String resourceCustomizationUuid = currentResource.getModelInfo().getModelCustomizationUuid();
204 String incomingRequest = execution.getVariable("uuiRequest")
205 //set the requestInputs from tempalte To Be Done
206 String serviceModelUuid = jsonUtil.getJsonValue(incomingRequest,"service.serviceUuid")
207 String serviceParameters = jsonUtil.getJsonValue(incomingRequest, "service.parameters")
208 String resourceParameters = ResourceRequestBuilder.buildResourceRequestParameters(execution, serviceModelUuid, resourceCustomizationUuid, serviceParameters)
209 resourceInput.setResourceParameters(resourceParameters)
210 execution.setVariable("resourceInput", resourceInput)
211 utils.log("INFO", "======== COMPLETED prepareResourceRecipeRequest Process ======== ", isDebugEnabled)
214 public void executeResourceRecipe(DelegateExecution execution){
215 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
216 utils.log("INFO", "======== Start executeResourceRecipe Process ======== ", isDebugEnabled)
217 String requestId = execution.getVariable("msoRequestId")
218 String serviceInstanceId = execution.getVariable("serviceInstanceId")
219 String serviceType = execution.getVariable("serviceType")
220 ResourceInput resourceInput = execution.getVariable("resourceInput")
222 // requestAction is action, not opertiontype
223 //String requestAction = resourceInput.getOperationType()
224 String requestAction = "createInstance"
225 JSONObject resourceRecipe = cutils.getResourceRecipe(execution, resourceInput.getResourceModelInfo().getModelUuid(), requestAction)
226 String recipeURL = BPMNProperties.getProperty("bpelURL", "http://mso:8080") + resourceRecipe.getString("orchestrationUri")
227 int recipeTimeOut = resourceRecipe.getInt("recipeTimeout")
228 String recipeParamXsd = resourceRecipe.get("paramXSD")
229 HttpResponse resp = BpmnRestClient.post(recipeURL, requestId, recipeTimeOut, requestAction, serviceInstanceId, serviceType, resourceInput.toString(), recipeParamXsd)
230 utils.log("INFO", "======== end executeResourceRecipe Process ======== ", isDebugEnabled)
233 public void postConfigRequest(DelegateExecution execution){