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.*;
24 import javax.ws.rs.NotFoundException
26 import org.apache.commons.lang3.*
27 import org.camunda.bpm.engine.delegate.BpmnError
28 import org.camunda.bpm.engine.delegate.DelegateExecution
29 import org.onap.aai.domain.yang.ServiceInstance
30 import org.onap.so.bpmn.common.resource.ResourceRequestBuilder
31 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
32 import org.onap.so.bpmn.common.scripts.ExceptionUtil
33 import org.onap.so.bpmn.core.domain.CompareModelsResult
34 import org.onap.so.bpmn.core.domain.ModelInfo
35 import org.onap.so.bpmn.core.domain.Resource
36 import org.onap.so.bpmn.core.domain.ResourceModelInfo
37 import org.onap.so.bpmn.core.json.JsonUtils
38 import org.onap.so.client.aai.AAIObjectType
39 import org.onap.so.client.aai.AAIResourcesClient
40 import org.onap.so.client.aai.entities.AAIResultWrapper
41 import org.onap.so.client.aai.entities.uri.AAIResourceUri
42 import org.onap.so.client.aai.entities.uri.AAIUriFactory
47 * This groovy class supports the <class>DoCompareModelofE2EServiceInstance.bpmn</class> process.
50 * @param - msoRequestId
51 * @param - globalSubscriberId
52 * @param - subscriptionServiceType
53 * @param - serviceInstanceId
54 * @param - modelInvariantIdTarget
55 * @param - modelVersionIdTarget
58 * @param - compareModelsResult CompareModelsResult
61 public class DoCompareModelofE2EServiceInstance extends AbstractServiceTaskProcessor {
63 String Prefix="DCMPMDSI_"
64 private static final String DebugFlag = "isDebugEnabled"
66 ExceptionUtil exceptionUtil = new ExceptionUtil()
67 JsonUtils jsonUtil = new JsonUtils()
69 public void preProcessRequest (DelegateExecution execution) {
71 def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'
72 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
73 utils.log("INFO","Entered " + method, isDebugEnabled)
75 utils.log("INFO"," ***** Enter DoCompareModelofE2EServiceInstance preProcessRequest *****", isDebugEnabled)
77 execution.setVariable("prefix", Prefix)
80 //subscriberInfo. for AAI GET
81 String globalSubscriberId = execution.getVariable("globalSubscriberId")
82 utils.log("INFO"," ***** globalSubscriberId *****" + globalSubscriberId, isDebugEnabled)
84 String serviceType = execution.getVariable("serviceType")
85 utils.log("INFO"," ***** serviceType *****" + serviceType, isDebugEnabled)
87 if (isBlank(globalSubscriberId)) {
88 msg = "Input globalSubscriberId is null"
89 utils.log("INFO", msg, isDebugEnabled)
90 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
93 if (isBlank(serviceType)) {
94 msg = "Input serviceType is null"
95 utils.log("INFO", msg, isDebugEnabled)
96 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
99 String serviceInstanceId = execution.getVariable("serviceInstanceId")
100 if (isBlank(serviceInstanceId)){
101 msg = "Input serviceInstanceId is null"
102 utils.log("INFO", msg, isDebugEnabled)
103 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
106 String modelInvariantUuid = execution.getVariable("modelInvariantIdTarget")
107 if (isBlank(modelInvariantUuid)){
108 msg = "Input modelInvariantUuid is null"
109 utils.log("INFO", msg, isDebugEnabled)
110 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
113 String modelUuid = execution.getVariable("modelVersionIdTarget")
114 if (isBlank(modelUuid)){
115 msg = "Input modelUuid is null"
116 utils.log("INFO", msg, isDebugEnabled)
117 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
120 // Set Target Template info
121 execution.setVariable("model-invariant-id-target", modelInvariantUuid)
122 execution.setVariable("model-version-id-target", modelUuid)
125 utils.log("INFO", "Exited " + method, isDebugEnabled)
129 * Gets the service instance from aai
133 public void getServiceInstance(DelegateExecution execution) {
135 String serviceInstanceId = execution.getVariable('serviceInstanceId')
136 String globalSubscriberId = execution.getVariable('globalSubscriberId')
137 String serviceType = execution.getVariable('serviceType')
139 AAIResourcesClient resourceClient = new AAIResourcesClient()
140 AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, serviceInstanceId)
141 AAIResultWrapper wrapper = resourceClient.get(serviceInstanceUri, NotFoundException.class)
143 Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
144 execution.setVariable("model-invariant-id-original", si.get().getModelInvariantId())
145 execution.setVariable("model-version-id-original", si.get().getModelVersionId())
147 }catch(BpmnError e) {
149 }catch(NotFoundException e) {
150 exceptionUtil.buildAndThrowWorkflowException(execution, 404, "Service-instance does not exist AAI")
151 }catch(Exception ex) {
152 String msg = "Internal Error in getServiceInstance: " + ex.getMessage()
153 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
157 public void postCompareModelVersions(DelegateExecution execution) {
158 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
161 List<Resource> addResourceList = execution.getVariable("addResourceList")
162 List<Resource> delResourceList = execution.getVariable("delResourceList")
164 CompareModelsResult cmpResult = new CompareModelsResult()
165 List<ResourceModelInfo> addedResourceList = new ArrayList<ResourceModelInfo>()
166 List<ResourceModelInfo> deletedResourceList = new ArrayList<ResourceModelInfo>()
169 String serviceModelUuid = execution.getVariable("model-version-id-target")
170 List<String> requestInputs = new ArrayList<String>()
172 for(Resource rc : addResourceList) {
173 mi = rc.getModelInfo()
174 String resourceCustomizationUuid = mi.getModelCustomizationUuid()
175 ResourceModelInfo rmodel = new ResourceModelInfo()
176 rmodel.setResourceName(mi.getModelName())
177 rmodel.setResourceInvariantUuid(mi.getModelInvariantUuid())
178 rmodel.setResourceUuid(mi.getModelUuid())
179 rmodel.setResourceCustomizationUuid(resourceCustomizationUuid)
180 addedResourceList.add(rmodel)
182 Map<String, Object> resourceParameters = ResourceRequestBuilder.buildResouceRequest(serviceModelUuid, resourceCustomizationUuid, null)
183 requestInputs.addAll(resourceParameters.keySet())
186 for(Resource rc : delResourceList) {
187 mi = rc.getModelInfo()
188 String resourceCustomizationUuid = mi.getModelCustomizationUuid()
189 ResourceModelInfo rmodel = new ResourceModelInfo()
190 rmodel.setResourceName(mi.getModelName())
191 rmodel.setResourceInvariantUuid(mi.getModelInvariantUuid())
192 rmodel.setResourceUuid(mi.getModelUuid())
193 rmodel.setResourceCustomizationUuid(resourceCustomizationUuid)
194 deletedResourceList.add(rmodel)
197 cmpResult.setAddedResourceList(addedResourceList)
198 cmpResult.setDeletedResourceList(deletedResourceList)
199 cmpResult.setRequestInputs(requestInputs)
201 execution.setVariable("compareModelsResult", cmpResult)