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 javax.mail.Quota.Resource
27 import org.apache.commons.lang3.StringUtils
28 import org.apache.http.HttpResponse
29 import org.camunda.bpm.engine.delegate.DelegateExecution
30 import org.codehaus.groovy.runtime.ArrayUtil
31 import org.codehaus.groovy.runtime.ScriptBytecodeAdapter
32 import org.codehaus.groovy.runtime.callsite.CallSite
33 import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation
34 import org.codehaus.groovy.runtime.typehandling.ShortTypeHandling
35 import org.json.JSONArray
36 import org.json.JSONObject
37 import org.openecomp.mso.bpmn.common.recipe.BpmnRestClient
38 import org.openecomp.mso.bpmn.common.recipe.ResourceInput
39 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
40 import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils
41 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
42 import org.openecomp.mso.bpmn.core.domain.AllottedResource
43 import org.openecomp.mso.bpmn.core.domain.NetworkResource
44 import org.openecomp.mso.bpmn.core.domain.VnfResource
45 import org.openecomp.mso.bpmn.core.json.JsonUtils
48 * This groovy class supports the <class>DoCreateResources.bpmn</class> process.
51 * @param - msoRequestId
52 * @param - globalSubscriberId - O
53 * @param - subscriptionServiceType - O
54 * @param - serviceInstanceId
55 * @param - serviceInstanceName - O
56 * @param - serviceInputParams (should contain aic_zone for serviceTypes TRANSPORT,ATM)
57 * @param - sdncVersion
58 * @param - failNotFound - TODO
59 * @param - serviceInputParams - TODO
61 * @param - addResourceList
64 * @param - WorkflowException
68 public class DoCreateResources extends AbstractServiceTaskProcessor
70 ExceptionUtil exceptionUtil = new ExceptionUtil()
71 JsonUtils jsonUtil = new JsonUtils()
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 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(Object execution)
96 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
97 utils.log("INFO", "======== Start sequenceResoure Process ======== ", isDebugEnabled)
98 String serviceModelUUID = execution.getVariable("modelUuid")
99 JSONArray networks = cutils.getAllNetworksByServiceModelUuid(execution, serviceModelUUID)
100 utils.log("DEBUG", "obtained Network list: "+ networks, isDebugEnabled)
101 if (networks == null) {
102 utils.log("INFO", "No matching networks in Catalog DB for serviceModelUUID=" + serviceModelUUID, isDebugEnabled)
106 List<Resource> addResourceList = execution.getVariable("addResourceList")
108 //we use VF to define a network service
109 List<VnfResource> vnfResourceList = new ArrayList<VnfResource>()
110 //here wan is defined as a network resource
111 List<NetworkResource> networkResourceList = new ArrayList<NetworkResource>()
113 List<AllottedResource> arResourceList = new ArrayList<AllottedResource>()
115 //define sequenced resource list, we deploy vf first and then network and then ar
116 //this is defaule sequence
117 List<Resource> sequencedResourceList = new ArrayList<Resource>()
118 for (Resource rc : addResourceList){
119 if (rc instanceof VnfResource) {
120 vnfResourceList.add(rc)
121 } else if (rc instanceof NetworkResource) {
122 NetworkResource.add(rc)
123 } else if (rc instanceof AllottedResource) {
124 AllottedResource.add(rc)
127 sequencedResourceList.addAll(vnfResourceList)
128 sequencedResourceList.addAll(networkResourceList)
129 sequencedResourceList.addAll(arResourceList)
131 String isContainsWanResource = networkResourceList.isEmpty() ? "false" : "true"
132 execution.setVariable("isContainsWanResource", isContainsWanResource)
133 execution.setVariable("currentResourceIndex", 0)
134 execution.setVariable("sequencedResourceList", sequencedResourceList)
135 utils.log("INFO", "sequencedResourceList: " + sequencedResourceList, isDebugEnabled)
136 utils.log("INFO", "======== COMPLETED sequenceResoure Process ======== ", isDebugEnabled)
139 public void getCurrentResoure(execution){
140 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
141 utils.log("INFO", "======== Start getCurrentResoure Process ======== ", isDebugEnabled)
142 def currentIndex = execution.getVariable("currentResourceIndex")
143 List<Resource> sequencedResourceList = execution.getVariable("sequencedResourceList")
144 Resource currentResource = sequencedResourceList.get(currentIndex)
145 utils.log("INFO", "Now we deal with resouce:" + currentResource.getModelInfo().getModelName(), isDebugEnabled)
146 utils.log("INFO", "======== COMPLETED getCurrentResoure Process ======== ", isDebugEnabled)
149 public void parseNextResource(execution){
150 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
151 utils.log("INFO", "======== Start parseNextResource Process ======== ", isDebugEnabled)
152 def currentIndex = execution.getVariable("currentResourceIndex")
153 def nextIndex = currentIndex + 1
154 execution.setVariable("currentResourceIndex", nextIndex)
155 List<String> sequencedResourceList = execution.getVariable("sequencedResourceList")
156 if(nextIndex >= sequencedResourceList.size()){
157 execution.setVariable("allResourceFinished", "true")
159 execution.setVariable("allResourceFinished", "false")
161 utils.log("INFO", "======== COMPLETED parseNextResource Process ======== ", isDebugEnabled)
164 public void prepareResourceRecipeRequest(execution){
165 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
166 utils.log("INFO", "======== Start prepareResourceRecipeRequest Process ======== ", isDebugEnabled)
167 ResourceInput resourceInput = new ResourceInput()
168 String serviceInstanceName = execution.getVariable("serviceInstanceName")
169 String resourceInstanceName = resourceType + "_" + serviceInstanceName
170 resourceInput.setResourceInstanceName(resourceInstanceName)
171 utils.log("INFO", "Prepare Resource Request resourceInstanceName:" + resourceInstanceName, isDebugEnabled)
172 String globalSubscriberId = execution.getVariable("globalSubscriberId")
173 String serviceType = execution.getVariable("serviceType")
174 String serviceInstanceId = execution.getVariable("serviceInstanceId")
175 String operationId = execution.getVariable("operationId")
176 String operationType = execution.getVariable("operationType")
177 resourceInput.setGlobalSubscriberId(globalSubscriberId)
178 resourceInput.setServiceType(serviceType)
179 resourceInput.setServiceInstanceId(serviceInstanceId)
180 resourceInput.setOperationId(operationId)
181 resourceInput.setOperationType(operationType);
182 def currentIndex = execution.getVariable("currentResourceIndex")
183 List<Resource> sequencedResourceList = execution.getVariable("sequencedResourceList")
184 Resource currentResource = sequencedResourceList.get(currentIndex)
185 String resourceCustomizationUuid = currentResource.getModelInfo().getModelCustomizationUuid()
186 resourceInput.setResourceCustomizationUuid(resourceCustomizationUuid);
187 String resourceInvariantUuid = currentResource.getModelInfo().getModelInvariantUuid()
188 resourceInput.setResourceInvariantUuid(resourceInvariantUuid)
189 String resourceUuid = currentResource.getModelInfo().getModelUuid()
190 resourceInput.setResourceUuid(resourceUuid)
192 String incomingRequest = execution.getVariable("uuiRequest")
193 //set the requestInputs from tempalte To Be Done
194 String serviceModelUuid = execution.getVariable("modelUuid")
195 String serviceParameters = jsonUtil.getJsonValue(incomingRequest, "service.parameters")
196 String resourceParameters = ResourceRequestBuilder.buildResourceRequestParameters(execution, serviceModelUuid, resourceCustomizationUuid, serviceParameters)
197 resourceInput.setResourceParameters(resourceParameters)
198 execution.setVariable("resourceInput", resourceInput)
199 utils.log("INFO", "======== COMPLETED prepareResourceRecipeRequest Process ======== ", isDebugEnabled)
202 public void executeResourceRecipe(execution){
203 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
204 utils.log("INFO", "======== Start executeResourceRecipe Process ======== ", isDebugEnabled)
205 String requestId = execution.getVariable("msoRequestId")
206 String serviceInstanceId = execution.getVariable("serviceInstanceId")
207 String serviceType = execution.getVariable("serviceType")
208 ResourceInput resourceInput = execution.getVariable("resourceInput")
209 String requestAction = resourceInput.getOperationType()
210 JSONObject resourceRecipe = cutils.getResourceRecipe(execution, resourceInput.getResourceUuid(), requestAction)
211 String recipeUri = resourceRecipe.getString("orchestrationUri")
212 String recipeTimeOut = resourceRecipe.getString("recipeTimeout")
213 String recipeParamXsd = resourceRecipe.get("paramXSD")
214 HttpResponse resp = BpmnRestClient.post(recipeUri, requestId, recipeTimeout, requestAction, serviceInstanceId, serviceType, resourceInput.toString(), recipeParamXsd)
218 public void postConfigRequest(execution){