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=========================================================
20 package org.onap.so.bpmn.infrastructure.scripts;
22 import static org.apache.commons.lang3.StringUtils.*;
23 import groovy.xml.XmlUtil
26 import org.onap.so.bpmn.core.domain.ServiceDecomposition
27 import org.onap.so.bpmn.core.domain.ServiceInstance
28 import org.onap.so.bpmn.core.domain.ModelInfo
29 import org.onap.so.bpmn.core.domain.Resource
30 import org.onap.so.bpmn.core.domain.CompareModelsResult
31 import org.onap.so.bpmn.core.domain.ResourceModelInfo
32 import org.onap.so.bpmn.core.json.JsonUtils
33 import org.onap.so.bpmn.common.scripts.AaiUtil
34 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
35 import org.onap.so.bpmn.common.scripts.ExceptionUtil
36 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
37 import org.onap.so.bpmn.common.resource.ResourceRequestBuilder
38 import org.onap.so.bpmn.core.RollbackData
39 import org.onap.so.bpmn.core.WorkflowException
40 import org.onap.so.rest.APIResponse;
41 import org.onap.so.rest.RESTClient
42 import org.onap.so.rest.RESTConfig
47 import java.util.UUID;
48 import javax.xml.parsers.DocumentBuilder
49 import javax.xml.parsers.DocumentBuilderFactory
51 import org.camunda.bpm.engine.delegate.BpmnError
52 import org.camunda.bpm.engine.delegate.DelegateExecution
53 import org.json.JSONObject;
54 import org.json.JSONArray;
55 import org.apache.commons.lang3.*
56 import org.apache.commons.codec.binary.Base64;
57 import org.springframework.web.util.UriUtils;
59 import org.w3c.dom.Document
60 import org.w3c.dom.Element
61 import org.w3c.dom.Node
62 import org.w3c.dom.NodeList
63 import org.xml.sax.InputSource
65 * This groovy class supports the <class>DoCompareModelofE2EServiceInstance.bpmn</class> process.
68 * @param - msoRequestId
69 * @param - globalSubscriberId
70 * @param - subscriptionServiceType
71 * @param - serviceInstanceId
72 * @param - modelInvariantIdTarget
73 * @param - modelVersionIdTarget
76 * @param - compareModelsResult CompareModelsResult
79 public class DoCompareModelofE2EServiceInstance extends AbstractServiceTaskProcessor {
81 String Prefix="DCMPMDSI_"
82 private static final String DebugFlag = "isDebugEnabled"
84 ExceptionUtil exceptionUtil = new ExceptionUtil()
85 JsonUtils jsonUtil = new JsonUtils()
87 public void preProcessRequest (DelegateExecution execution) {
89 def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'
90 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
91 utils.log("INFO","Entered " + method, isDebugEnabled)
93 utils.log("INFO"," ***** Enter DoCompareModelofE2EServiceInstance preProcessRequest *****", isDebugEnabled)
95 execution.setVariable("prefix", Prefix)
98 //subscriberInfo. for AAI GET
99 String globalSubscriberId = execution.getVariable("globalSubscriberId")
100 utils.log("INFO"," ***** globalSubscriberId *****" + globalSubscriberId, isDebugEnabled)
102 String serviceType = execution.getVariable("serviceType")
103 utils.log("INFO"," ***** serviceType *****" + serviceType, isDebugEnabled)
105 if (isBlank(globalSubscriberId)) {
106 msg = "Input globalSubscriberId is null"
107 utils.log("INFO", msg, isDebugEnabled)
108 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
111 if (isBlank(serviceType)) {
112 msg = "Input serviceType is null"
113 utils.log("INFO", msg, isDebugEnabled)
114 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
117 String serviceInstanceId = execution.getVariable("serviceInstanceId")
118 if (isBlank(serviceInstanceId)){
119 msg = "Input serviceInstanceId is null"
120 utils.log("INFO", msg, isDebugEnabled)
121 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
124 String modelInvariantUuid = execution.getVariable("modelInvariantIdTarget")
125 if (isBlank(modelInvariantUuid)){
126 msg = "Input modelInvariantUuid is null"
127 utils.log("INFO", msg, isDebugEnabled)
128 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
131 String modelUuid = execution.getVariable("modelVersionIdTarget")
132 if (isBlank(modelUuid)){
133 msg = "Input modelUuid is null"
134 utils.log("INFO", msg, isDebugEnabled)
135 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
138 // Set Target Template info
139 execution.setVariable("model-invariant-id-target", modelInvariantUuid)
140 execution.setVariable("model-version-id-target", modelUuid)
143 utils.log("INFO", "Exited " + method, isDebugEnabled)
146 public void postProcessAAIGET(DelegateExecution execution) {
147 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
148 utils.log("INFO"," ***** postProcessAAIGET ***** ", isDebugEnabled)
152 String serviceInstanceId = execution.getVariable("serviceInstanceId")
153 boolean foundInAAI = execution.getVariable("GENGS_FoundIndicator")
154 String serviceType = ""
157 utils.log("INFO","Found Service-instance in AAI", isDebugEnabled)
159 String siData = execution.getVariable("GENGS_service")
160 utils.log("INFO", "SI Data", isDebugEnabled)
163 msg = "Could not retrive ServiceInstance data from AAI, Id:" + serviceInstanceId
164 utils.log("INFO", msg, isDebugEnabled)
165 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
169 utils.log("INFO", "SI Data" + siData, isDebugEnabled)
171 // Get Template uuid and version
172 if (utils.nodeExists(siData, "model-invariant-id") && utils.nodeExists(siData, "model-version-id") ) {
173 utils.log("INFO", "SI Data model-invariant-id and model-version-id exist", isDebugEnabled)
175 def modelInvariantId = utils.getNodeText(siData, "model-invariant-id")
176 def modelVersionId = utils.getNodeText(siData, "model-version-id")
178 // Set Original Template info
179 execution.setVariable("model-invariant-id-original", modelInvariantId)
180 execution.setVariable("model-version-id-original", modelVersionId)
184 boolean succInAAI = execution.getVariable("GENGS_SuccessIndicator")
186 utils.log("INFO","Error getting Service-instance from AAI", + serviceInstanceId, isDebugEnabled)
187 WorkflowException workflowException = execution.getVariable("WorkflowException")
188 utils.logAudit("workflowException: " + workflowException)
189 if(workflowException != null){
190 exceptionUtil.buildAndThrowWorkflowException(execution, workflowException.getErrorCode(), workflowException.getErrorMessage())
194 msg = "Failure in postProcessAAIGET GENGS_SuccessIndicator:" + succInAAI
195 utils.log("INFO", msg, isDebugEnabled)
196 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, msg)
200 utils.log("INFO","Service-instance NOT found in AAI. Silent Success", isDebugEnabled)
202 }catch (BpmnError e) {
204 } catch (Exception ex) {
205 msg = "Exception in DoDeleteE2EServiceInstance.postProcessAAIGET. " + ex.getMessage()
206 utils.log("INFO", msg, isDebugEnabled)
207 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
209 msoLogger.trace("Exit postProcessAAIGET ")
212 public void postCompareModelVersions(DelegateExecution execution) {
213 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
216 List<Resource> addResourceList = execution.getVariable("addResourceList")
217 List<Resource> delResourceList = execution.getVariable("delResourceList")
219 CompareModelsResult cmpResult = new CompareModelsResult()
220 List<ResourceModelInfo> addedResourceList = new ArrayList<ResourceModelInfo>()
221 List<ResourceModelInfo> deletedResourceList = new ArrayList<ResourceModelInfo>()
224 String serviceModelUuid = execution.getVariable("model-version-id-target")
225 List<String> requestInputs = new ArrayList<String>()
227 for(Resource rc : addResourceList) {
228 mi = rc.getModelInfo()
229 String resourceCustomizationUuid = mi.getModelCustomizationUuid()
230 ResourceModelInfo rmodel = new ResourceModelInfo()
231 rmodel.setResourceName(mi.getModelName())
232 rmodel.setResourceInvariantUuid(mi.getModelInvariantUuid())
233 rmodel.setResourceUuid(mi.getModelUuid())
234 rmodel.setResourceCustomizationUuid(resourceCustomizationUuid)
235 addedResourceList.add(rmodel)
237 Map<String, Object> resourceParameters = ResourceRequestBuilder.buildResouceRequest(serviceModelUuid, resourceCustomizationUuid, null)
238 requestInputs.addAll(resourceParameters.keySet())
241 for(Resource rc : delResourceList) {
242 mi = rc.getModelInfo()
243 String resourceCustomizationUuid = mi.getModelCustomizationUuid()
244 ResourceModelInfo rmodel = new ResourceModelInfo()
245 rmodel.setResourceName(mi.getModelName())
246 rmodel.setResourceInvariantUuid(mi.getModelInvariantUuid())
247 rmodel.setResourceUuid(mi.getModelUuid())
248 rmodel.setResourceCustomizationUuid(resourceCustomizationUuid)
249 deletedResourceList.add(rmodel)
252 cmpResult.setAddedResourceList(addedResourceList)
253 cmpResult.setDeletedResourceList(deletedResourceList)
254 cmpResult.setRequestInputs(requestInputs)
256 execution.setVariable("compareModelsResult", cmpResult)