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.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
46 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
47 import org.slf4j.Logger
48 import org.slf4j.LoggerFactory
53 * This groovy class supports the <class>DoCompareModelofE2EServiceInstance.bpmn</class> process.
56 * @param - msoRequestId
57 * @param - globalSubscriberId
58 * @param - subscriptionServiceType
59 * @param - serviceInstanceId
60 * @param - modelInvariantIdTarget
61 * @param - modelVersionIdTarget
64 * @param - compareModelsResult CompareModelsResult
67 public class DoCompareModelofE2EServiceInstance extends AbstractServiceTaskProcessor {
69 String Prefix="DCMPMDSI_"
70 private static final String DebugFlag = "isDebugEnabled"
71 private static final Logger logger = LoggerFactory.getLogger( DeleteNetworkInstance.class);
73 ExceptionUtil exceptionUtil = new ExceptionUtil()
74 JsonUtils jsonUtil = new JsonUtils()
76 public void preProcessRequest (DelegateExecution execution) {
78 def method = getClass().getSimpleName() + '.preProcessRequest(' +'execution=' + execution.getId() +')'
79 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
80 logger.info("Entered " + method)
82 logger.info(" ***** Enter DoCompareModelofE2EServiceInstance preProcessRequest *****")
84 execution.setVariable("prefix", Prefix)
87 //subscriberInfo. for AAI GET
88 String globalSubscriberId = execution.getVariable("globalSubscriberId")
89 logger.info(" ***** globalSubscriberId *****" + globalSubscriberId)
91 String serviceType = execution.getVariable("serviceType")
92 logger.info(" ***** serviceType *****" + serviceType)
94 if (isBlank(globalSubscriberId)) {
95 msg = "Input globalSubscriberId is null"
97 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
100 if (isBlank(serviceType)) {
101 msg = "Input serviceType is null"
103 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
106 String serviceInstanceId = execution.getVariable("serviceInstanceId")
107 if (isBlank(serviceInstanceId)){
108 msg = "Input serviceInstanceId is null"
110 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
113 String modelInvariantUuid = execution.getVariable("modelInvariantIdTarget")
114 if (isBlank(modelInvariantUuid)){
115 msg = "Input modelInvariantUuid is null"
117 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
120 String modelUuid = execution.getVariable("modelVersionIdTarget")
121 if (isBlank(modelUuid)){
122 msg = "Input modelUuid is null"
124 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
127 // Set Target Template info
128 execution.setVariable("model-invariant-id-target", modelInvariantUuid)
129 execution.setVariable("model-version-id-target", modelUuid)
132 logger.info( "Exited " + method)
136 * Gets the service instance from aai
140 public void getServiceInstance(DelegateExecution execution) {
142 String serviceInstanceId = execution.getVariable('serviceInstanceId')
143 String globalSubscriberId = execution.getVariable('globalSubscriberId')
144 String serviceType = execution.getVariable('serviceType')
146 AAIResourcesClient resourceClient = new AAIResourcesClient()
147 AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(serviceType).serviceInstance(serviceInstanceId))
148 AAIResultWrapper wrapper = resourceClient.get(serviceInstanceUri, NotFoundException.class)
150 Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
151 execution.setVariable("model-invariant-id-original", si.get().getModelInvariantId())
152 execution.setVariable("model-version-id-original", si.get().getModelVersionId())
154 }catch(BpmnError e) {
156 }catch(NotFoundException e) {
157 exceptionUtil.buildAndThrowWorkflowException(execution, 404, "Service-instance does not exist AAI")
158 }catch(Exception ex) {
159 String msg = "Internal Error in getServiceInstance: " + ex.getMessage()
160 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
164 public void postCompareModelVersions(DelegateExecution execution) {
165 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
168 List<Resource> addResourceList = execution.getVariable("addResourceList")
169 List<Resource> delResourceList = execution.getVariable("delResourceList")
171 CompareModelsResult cmpResult = new CompareModelsResult()
172 List<ResourceModelInfo> addedResourceList = new ArrayList<ResourceModelInfo>()
173 List<ResourceModelInfo> deletedResourceList = new ArrayList<ResourceModelInfo>()
176 String serviceModelUuid = execution.getVariable("model-version-id-target")
177 List<String> requestInputs = new ArrayList<String>()
179 for(Resource rc : addResourceList) {
180 mi = rc.getModelInfo()
181 String resourceCustomizationUuid = mi.getModelCustomizationUuid()
182 ResourceModelInfo rmodel = new ResourceModelInfo()
183 rmodel.setResourceName(mi.getModelName())
184 rmodel.setResourceInvariantUuid(mi.getModelInvariantUuid())
185 rmodel.setResourceUuid(mi.getModelUuid())
186 rmodel.setResourceCustomizationUuid(resourceCustomizationUuid)
187 addedResourceList.add(rmodel)
189 Map<String, Object> resourceParameters = ResourceRequestBuilder.buildResouceRequest(rc, null, null)
190 requestInputs.addAll(resourceParameters.keySet())
193 for(Resource rc : delResourceList) {
194 mi = rc.getModelInfo()
195 String resourceCustomizationUuid = mi.getModelCustomizationUuid()
196 ResourceModelInfo rmodel = new ResourceModelInfo()
197 rmodel.setResourceName(mi.getModelName())
198 rmodel.setResourceInvariantUuid(mi.getModelInvariantUuid())
199 rmodel.setResourceUuid(mi.getModelUuid())
200 rmodel.setResourceCustomizationUuid(resourceCustomizationUuid)
201 deletedResourceList.add(rmodel)
204 cmpResult.setAddedResourceList(addedResourceList)
205 cmpResult.setDeletedResourceList(deletedResourceList)
206 cmpResult.setRequestInputs(requestInputs)
208 execution.setVariable("compareModelsResult", cmpResult)