2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 package org.onap.so.bpmn.infrastructure.scripts;
24 import static org.apache.commons.lang3.StringUtils.*;
26 import javax.ws.rs.NotFoundException
28 import org.apache.commons.lang3.*
29 import org.camunda.bpm.engine.delegate.BpmnError
30 import org.camunda.bpm.engine.delegate.DelegateExecution
31 import org.onap.aai.domain.yang.ServiceInstance
32 import org.onap.so.bpmn.common.resource.ResourceRequestBuilder
33 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
34 import org.onap.so.bpmn.common.scripts.ExceptionUtil
35 import org.onap.so.bpmn.core.domain.CompareModelsResult
36 import org.onap.so.bpmn.core.domain.ModelInfo
37 import org.onap.so.bpmn.core.domain.Resource
38 import org.onap.so.bpmn.core.domain.ResourceModelInfo
39 import org.onap.so.bpmn.core.json.JsonUtils
40 import org.onap.aaiclient.client.aai.AAIObjectType
41 import org.onap.aaiclient.client.aai.AAIResourcesClient
42 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
43 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
44 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
45 import org.slf4j.Logger
46 import org.slf4j.LoggerFactory
51 * This groovy class supports the <class>DoCompareModelofE2EServiceInstance.bpmn</class> process.
54 * @param - msoRequestId
55 * @param - globalSubscriberId
56 * @param - subscriptionServiceType
57 * @param - serviceInstanceId
58 * @param - modelInvariantIdTarget
59 * @param - modelVersionIdTarget
62 * @param - compareModelsResult CompareModelsResult
65 public class DoCompareModelofE2EServiceInstance extends AbstractServiceTaskProcessor {
67 String Prefix="DCMPMDSI_"
68 private static final String DebugFlag = "isDebugEnabled"
69 private static final Logger logger = LoggerFactory.getLogger( DeleteNetworkInstance.class);
71 ExceptionUtil exceptionUtil = new ExceptionUtil()
72 JsonUtils jsonUtil = new JsonUtils()
74 public void preProcessRequest (DelegateExecution execution) {
76 def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'
77 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
78 logger.info("Entered " + method)
80 logger.info(" ***** Enter DoCompareModelofE2EServiceInstance preProcessRequest *****")
82 execution.setVariable("prefix", Prefix)
85 //subscriberInfo. for AAI GET
86 String globalSubscriberId = execution.getVariable("globalSubscriberId")
87 logger.info(" ***** globalSubscriberId *****" + globalSubscriberId)
89 String serviceType = execution.getVariable("serviceType")
90 logger.info(" ***** serviceType *****" + serviceType)
92 if (isBlank(globalSubscriberId)) {
93 msg = "Input globalSubscriberId is null"
95 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
98 if (isBlank(serviceType)) {
99 msg = "Input serviceType is null"
101 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
104 String serviceInstanceId = execution.getVariable("serviceInstanceId")
105 if (isBlank(serviceInstanceId)){
106 msg = "Input serviceInstanceId is null"
108 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
111 String modelInvariantUuid = execution.getVariable("modelInvariantIdTarget")
112 if (isBlank(modelInvariantUuid)){
113 msg = "Input modelInvariantUuid is null"
115 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
118 String modelUuid = execution.getVariable("modelVersionIdTarget")
119 if (isBlank(modelUuid)){
120 msg = "Input modelUuid is null"
122 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
125 // Set Target Template info
126 execution.setVariable("model-invariant-id-target", modelInvariantUuid)
127 execution.setVariable("model-version-id-target", modelUuid)
130 logger.info( "Exited " + method)
134 * Gets the service instance from aai
138 public void getServiceInstance(DelegateExecution execution) {
140 String serviceInstanceId = execution.getVariable('serviceInstanceId')
141 String globalSubscriberId = execution.getVariable('globalSubscriberId')
142 String serviceType = execution.getVariable('serviceType')
144 AAIResourcesClient resourceClient = new AAIResourcesClient()
145 AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, serviceInstanceId)
146 AAIResultWrapper wrapper = resourceClient.get(serviceInstanceUri, NotFoundException.class)
148 Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
149 execution.setVariable("model-invariant-id-original", si.get().getModelInvariantId())
150 execution.setVariable("model-version-id-original", si.get().getModelVersionId())
152 }catch(BpmnError e) {
154 }catch(NotFoundException e) {
155 exceptionUtil.buildAndThrowWorkflowException(execution, 404, "Service-instance does not exist AAI")
156 }catch(Exception ex) {
157 String msg = "Internal Error in getServiceInstance: " + ex.getMessage()
158 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
162 public void postCompareModelVersions(DelegateExecution execution) {
163 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
166 List<Resource> addResourceList = execution.getVariable("addResourceList")
167 List<Resource> delResourceList = execution.getVariable("delResourceList")
169 CompareModelsResult cmpResult = new CompareModelsResult()
170 List<ResourceModelInfo> addedResourceList = new ArrayList<ResourceModelInfo>()
171 List<ResourceModelInfo> deletedResourceList = new ArrayList<ResourceModelInfo>()
174 String serviceModelUuid = execution.getVariable("model-version-id-target")
175 List<String> requestInputs = new ArrayList<String>()
177 for(Resource rc : addResourceList) {
178 mi = rc.getModelInfo()
179 String resourceCustomizationUuid = mi.getModelCustomizationUuid()
180 ResourceModelInfo rmodel = new ResourceModelInfo()
181 rmodel.setResourceName(mi.getModelName())
182 rmodel.setResourceInvariantUuid(mi.getModelInvariantUuid())
183 rmodel.setResourceUuid(mi.getModelUuid())
184 rmodel.setResourceCustomizationUuid(resourceCustomizationUuid)
185 addedResourceList.add(rmodel)
187 Map<String, Object> resourceParameters = ResourceRequestBuilder.buildResouceRequest(rc, null, null)
188 requestInputs.addAll(resourceParameters.keySet())
191 for(Resource rc : delResourceList) {
192 mi = rc.getModelInfo()
193 String resourceCustomizationUuid = mi.getModelCustomizationUuid()
194 ResourceModelInfo rmodel = new ResourceModelInfo()
195 rmodel.setResourceName(mi.getModelName())
196 rmodel.setResourceInvariantUuid(mi.getModelInvariantUuid())
197 rmodel.setResourceUuid(mi.getModelUuid())
198 rmodel.setResourceCustomizationUuid(resourceCustomizationUuid)
199 deletedResourceList.add(rmodel)
202 cmpResult.setAddedResourceList(addedResourceList)
203 cmpResult.setDeletedResourceList(deletedResourceList)
204 cmpResult.setRequestInputs(requestInputs)
206 execution.setVariable("compareModelsResult", cmpResult)