2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
20 package org.openecomp.mso.bpmn.infrastructure.scripts;
\r
22 import static org.apache.commons.lang3.StringUtils.*;
\r
23 import groovy.xml.XmlUtil
\r
24 import groovy.json.*
\r
26 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition
\r
27 import org.openecomp.mso.bpmn.core.domain.ServiceInstance
\r
28 import org.openecomp.mso.bpmn.core.domain.ModelInfo
\r
29 import org.openecomp.mso.bpmn.core.domain.Resource
\r
30 import org.openecomp.mso.bpmn.core.domain.AllottedResource
\r
31 import org.openecomp.mso.bpmn.core.domain.NetworkResource
\r
32 import org.openecomp.mso.bpmn.core.domain.VnfResource
\r
33 import org.openecomp.mso.bpmn.common.recipe.ResourceInput
\r
34 import org.openecomp.mso.bpmn.common.recipe.BpmnRestClient
\r
35 import org.openecomp.mso.bpmn.core.json.JsonUtils
\r
36 import org.openecomp.mso.bpmn.common.scripts.AaiUtil
\r
37 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
\r
38 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
\r
39 import org.openecomp.mso.bpmn.common.scripts.SDNCAdapterUtils
\r
40 import org.openecomp.mso.bpmn.common.scripts.CatalogDbUtils;
\r
41 import org.openecomp.mso.bpmn.core.RollbackData
\r
42 import org.openecomp.mso.bpmn.core.WorkflowException
\r
43 import org.openecomp.mso.rest.APIResponse;
\r
44 import org.openecomp.mso.rest.RESTClient
\r
45 import org.openecomp.mso.rest.RESTConfig
\r
47 import java.util.List;
\r
48 import java.util.UUID;
\r
50 import org.camunda.bpm.engine.delegate.BpmnError
\r
51 import org.camunda.bpm.engine.runtime.Execution
\r
52 import org.camunda.bpm.engine.delegate.DelegateExecution
\r
53 import org.json.JSONObject;
\r
54 import org.json.JSONArray;
\r
55 import org.apache.commons.lang3.*
\r
56 import org.apache.commons.codec.binary.Base64;
\r
57 import org.springframework.web.util.UriUtils;
\r
60 * This groovy class supports the <class>DoCompareModelVersions.bpmn</class> process.
\r
63 * @param - model-invariant-id-target
\r
64 * @param - model-version-id-target
\r
65 * @param - model-invariant-id-original
\r
66 * @param - model-version-id-original
\r
69 * @param - addResourceList
\r
70 * @param - delResourceList
\r
73 public class DoCompareModelVersions extends AbstractServiceTaskProcessor {
\r
75 String Prefix="DCMPMDV_"
\r
76 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
77 JsonUtils jsonUtil = new JsonUtils()
\r
78 CatalogDbUtils cutils = new CatalogDbUtils()
\r
80 public void preProcessRequest (DelegateExecution execution) {
\r
81 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
\r
83 utils.log("INFO"," ***** preProcessRequest *****", isDebugEnabled)
\r
86 execution.setVariable("prefix", Prefix)
\r
89 String modelInvariantUuid_target = execution.getVariable("model-invariant-id-target")
\r
90 if (isBlank(modelInvariantUuid_target)) {
\r
91 msg = "Input model-invariant-id-target is null"
\r
92 utils.log("INFO", msg, isDebugEnabled)
\r
93 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
\r
96 String modelUuid_target = execution.getVariable("model-version-id-target")
\r
97 if (isBlank(modelUuid_target)) {
\r
98 msg = "Input model-version-id-target is null"
\r
99 utils.log("INFO", msg, isDebugEnabled)
\r
100 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
\r
103 String modelInvariantUuid_original = execution.getVariable("model-invariant-id-original")
\r
104 if (isBlank(modelInvariantUuid_original)) {
\r
105 msg = "Input model-invariant-id-original is null"
\r
106 utils.log("INFO", msg, isDebugEnabled)
\r
107 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
\r
110 String modelUuid_original = execution.getVariable("model-version-id-original")
\r
111 if (isBlank(modelUuid_original)) {
\r
112 msg = "Input model-version-id-original is null"
\r
113 utils.log("INFO", msg, isDebugEnabled)
\r
114 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
\r
117 // Target and original modelInvariantUuid must to be the same
\r
118 if(modelInvariantUuid_target != modelInvariantUuid_original){
\r
119 msg = "Input model-invariant-id-target and model-invariant-id-original must to be the same"
\r
120 utils.log("INFO", msg, isDebugEnabled)
\r
121 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
\r
124 // Target and original modelUuid must not to be the same
\r
125 if(modelUuid_target == modelUuid_original){
\r
126 msg = "Input model-version-id-target and model-version-id-original must not to be the same"
\r
127 utils.log("INFO", msg, isDebugEnabled)
\r
128 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
\r
131 } catch (Exception ex){
\r
132 msg = "Exception in preProcessRequest " + ex.getMessage()
\r
133 utils.log("INFO", msg, isDebugEnabled)
\r
134 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
\r
136 utils.log("INFO"," ***** Exit preProcessRequest *****", isDebugEnabled)
\r
139 public void prepareDecomposeService_Target(DelegateExecution execution) {
\r
140 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
143 utils.log("DEBUG", " ***** Inside prepareDecomposeService_Target of update generic e2e service ***** ", isDebugEnabled)
\r
144 String modelInvariantUuid = execution.getVariable("model-invariant-id-target")
\r
145 String modelUuid = execution.getVariable("model-version-id-target")
\r
146 //here modelVersion is not set, we use modelUuid to decompose the service.
\r
147 String serviceModelInfo = """{
\r
148 "modelInvariantUuid":"${modelInvariantUuid}",
\r
149 "modelUuid":"${modelUuid}",
\r
153 execution.setVariable("serviceModelInfo_Target", serviceModelInfo)
\r
155 utils.log("DEBUG", " ***** Completed prepareDecomposeService_Target of update generic e2e service ***** ", isDebugEnabled)
\r
156 } catch (Exception ex) {
\r
157 // try error in method block
\r
158 String exceptionMessage = "Bpmn error encountered in update generic e2e service flow. Unexpected Error from method prepareDecomposeService_Target() - " + ex.getMessage()
\r
159 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
163 public void processDecomposition_Target(DelegateExecution execution) {
\r
164 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
166 utils.log("DEBUG", " ***** Inside processDecomposition_Target() of update generic e2e service flow ***** ", isDebugEnabled)
\r
168 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
\r
169 execution.setVariable("serviceDecomposition_Target", serviceDecomposition)
\r
170 } catch (Exception ex) {
\r
171 String exceptionMessage = "Bpmn error encountered in update generic e2e service flow. Unexpected Error from method processDecomposition_Target() - " + ex.getMessage()
\r
172 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
\r
173 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
177 public void prepareDecomposeService_Original(DelegateExecution execution) {
\r
178 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
181 utils.log("DEBUG", " ***** Inside prepareDecomposeService_Original of update generic e2e service ***** ", isDebugEnabled)
\r
182 String modelInvariantUuid = execution.getVariable("model-invariant-id-original")
\r
183 String modelUuid = execution.getVariable("model-version-id-original")
\r
184 //here modelVersion is not set, we use modelUuid to decompose the service.
\r
185 String serviceModelInfo = """{
\r
186 "modelInvariantUuid":"${modelInvariantUuid}",
\r
187 "modelUuid":"${modelUuid}",
\r
191 execution.setVariable("serviceModelInfo_Original", serviceModelInfo)
\r
193 utils.log("DEBUG", " ***** Completed prepareDecomposeService_Original of update generic e2e service ***** ", isDebugEnabled)
\r
194 } catch (Exception ex) {
\r
195 // try error in method block
\r
196 String exceptionMessage = "Bpmn error encountered in update generic e2e service flow. Unexpected Error from method prepareDecomposeService_Original() - " + ex.getMessage()
\r
197 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
201 public void processDecomposition_Original(DelegateExecution execution) {
\r
202 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
204 utils.log("DEBUG", " ***** Inside processDecomposition_Original() of update generic e2e service flow ***** ", isDebugEnabled)
\r
206 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
\r
207 execution.setVariable("serviceDecomposition_Original", serviceDecomposition)
\r
208 } catch (Exception ex) {
\r
209 String exceptionMessage = "Bpmn error encountered in update generic e2e service flow. processDecomposition_Original() - " + ex.getMessage()
\r
210 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
\r
211 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
\r
215 public void doCompareModelVersions(DelegateExecution execution){
\r
216 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
217 utils.log("INFO", "======== Start doCompareModelVersions Process ======== ", isDebugEnabled)
\r
219 ServiceDecomposition serviceDecomposition_Target = execution.getVariable("serviceDecomposition_Target")
\r
220 ServiceDecomposition serviceDecomposition_Original = execution.getVariable("serviceDecomposition_Original")
\r
222 List<Resource> allSR_target = serviceDecomposition_Target.getServiceResources();
\r
223 List<Resource> allSR_original = serviceDecomposition_Original.getServiceResources();
\r
225 List<Resource> addResourceList = new ArrayList<String>()
\r
226 List<Resource> delResourceList = new ArrayList<String>()
\r
228 addResourceList.addAll(allSR_target)
\r
229 delResourceList.addAll(allSR_original)
\r
232 for (Resource rc_t : allSR_target){
\r
233 String muuid = rc_t.getModelInfo().getModelUuid()
\r
234 String mIuuid = rc_t.getModelInfo().getModelInvariantUuid()
\r
235 String mCuuid = rc_t.getModelInfo().getModelCustomizationUuid()
\r
236 for (Resource rc_o : allSR_original){
\r
237 if(rc_o.getModelInfo().getModelUuid() == muuid
\r
238 && rc_o.getModelInfo().getModelInvariantUuid() == mIuuid
\r
239 && rc_o.getModelInfo().getModelCustomizationUuid() == mCuuid) {
\r
240 addResourceList.remove(rc_t);
\r
241 delResourceList.remove(rc_o);
\r
246 execution.setVariable("addResourceList", addResourceList)
\r
247 execution.setVariable("delResourceList", delResourceList)
\r
248 utils.log("INFO", "addResourceList: " + addResourceList, isDebugEnabled)
\r
249 utils.log("INFO", "delResourceList: " + delResourceList, isDebugEnabled)
\r
251 utils.log("INFO", "======== COMPLETED doCompareModelVersions Process ======== ", isDebugEnabled)
\r