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=========================================================
23 package org.onap.so.bpmn.infrastructure.scripts
25 import org.json.JSONArray
26 import org.json.JSONObject
28 import org.onap.so.bpmn.common.scripts.ExternalAPIUtilFactory
30 import static org.apache.commons.lang3.StringUtils.*
31 import groovy.xml.XmlUtil
32 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
33 import org.onap.so.bpmn.common.scripts.ExceptionUtil
34 import org.onap.so.bpmn.common.scripts.ExternalAPIUtil
35 import org.onap.so.bpmn.common.scripts.MsoUtils
36 import org.onap.aai.domain.yang.SpPartner
37 import org.onap.so.bpmn.common.recipe.ResourceInput
38 import org.onap.so.bpmn.common.resource.ResourceRequestBuilder
39 import org.onap.so.bpmn.core.WorkflowException
40 import org.onap.so.bpmn.core.json.JsonUtils
41 import org.onap.so.bpmn.core.UrnPropertiesReader
42 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.builder.AbstractBuilder
43 import org.onap.so.client.aai.AAIObjectType
44 import org.onap.so.client.aai.AAIResourcesClient
45 import org.onap.so.client.aai.entities.uri.AAIResourceUri
46 import org.onap.so.client.aai.entities.uri.AAIUriFactory
47 import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils
48 import org.onap.so.bpmn.infrastructure.workflow.service.ServicePluginFactory
51 import javax.ws.rs.core.Response
52 import org.slf4j.Logger
53 import org.slf4j.LoggerFactory
55 import org.camunda.bpm.engine.runtime.Execution
56 import org.camunda.bpm.engine.delegate.BpmnError
57 import org.camunda.bpm.engine.delegate.DelegateExecution
58 import org.apache.commons.lang3.*
59 import org.apache.commons.codec.binary.Base64
63 * This groovy class supports the <class>Create3rdONAPE2EServiceInstance.bpmn</class> process.
64 * flow for Create E2EServiceInstance in 3rdONAP
66 public class Create3rdONAPE2EServiceInstance extends AbstractServiceTaskProcessor {
68 String Prefix = "CRE3rdONAPESI_"
70 ExceptionUtil exceptionUtil = new ExceptionUtil()
72 JsonUtils jsonUtil = new JsonUtils()
74 private static final Logger logger = LoggerFactory.getLogger( Create3rdONAPE2EServiceInstance.class);
76 public void checkSPPartnerInfo (DelegateExecution execution) {
77 logger.info(" ***** Started checkSPPartnerInfo *****")
79 //get bpmn inputs from resource request.
80 String requestId = execution.getVariable("mso-request-id")
81 String requestAction = execution.getVariable("requestAction")
82 logger.info("The requestAction is: " + requestAction)
83 String recipeParamsFromRequest = execution.getVariable("recipeParams")
84 logger.info("The recipeParams is: " + recipeParamsFromRequest)
85 String resourceInput = execution.getVariable("resourceInput")
86 logger.info("The resourceInput is: " + resourceInput)
87 //Get ResourceInput Object
88 ResourceInput resourceInputObj = ResourceRequestBuilder.getJsonObject(resourceInput, ResourceInput.class)
89 String resourceInputPrameters = resourceInputObj.getResourceParameters()
90 String inputParametersJson = JsonUtils.getJsonValue(resourceInputPrameters, "requestInputs")
91 JSONObject inputParameters = new JSONObject(inputParametersJson)
93 // set local resourceInput
94 execution.setVariable(Prefix + "ResourceInput", resourceInputObj)
96 boolean is3rdONAPExist = false
98 if(inputParameters.has("sppartner_url"))
100 String sppartnerUrl = inputParameters.get("sppartner_url")
101 if(!isBlank(sppartnerUrl)) {
102 execution.setVariable(Prefix + "SppartnerUrl", sppartnerUrl)
103 is3rdONAPExist = true
106 is3rdONAPExist = false
107 String msg = "sppartner Url is blank."
111 if(inputParameters.has("sppartner_providingServiceUuid"))
113 String sppartnerUUID= inputParameters.get("sppartner_providingServiceUuid")
114 execution.setVariable(Prefix + "SppartnerUUID", sppartnerUUID)
115 is3rdONAPExist = true
118 is3rdONAPExist = false
119 String msg = "sppartner providingServiceUuid is blank."
122 if(inputParameters.has("sppartner_providingServiceInvariantUuid"))
124 String sppartnerInvarianteUUID = inputParameters.get("sppartner_providingServiceInvariantUuid")
125 execution.setVariable(Prefix + "SppartnerInvarianteUUID", sppartnerInvarianteUUID)
126 is3rdONAPExist = true
129 is3rdONAPExist = false
130 String msg = "sppartner providingServiceInvarianteUuid is blank."
134 if(inputParameters.has("sppartner_handoverMode"))
136 String handoverMode = inputParameters.get("sppartner_handoverMode")
137 execution.setVariable(Prefix + "HandoverMode", handoverMode)
138 is3rdONAPExist = true
141 is3rdONAPExist = false
142 String msg = "sppartner handoverMode is blank."
146 execution.setVariable("Is3rdONAPExist", is3rdONAPExist)
147 execution.setVariable(Prefix + "ServiceInstanceId", resourceInputObj.getServiceInstanceId())
148 execution.setVariable("mso-request-id", requestId)
149 execution.setVariable("mso-service-instance-id", resourceInputObj.getServiceInstanceId())
151 } catch (Exception ex){
152 String msg = "Exception in checkSPPartnerInfo " + ex.getMessage()
154 // exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
158 public void checkLocallCall (DelegateExecution execution) {
159 logger.info(" ***** Started checkLocallCall *****")
162 //Get ResourceInput Object
163 ResourceInput resourceInputObj = execution.getVariable(Prefix + "ResourceInput")
166 String incomingRequest = resourceInputObj.getRequestsInputs()
167 String serviceParameters = JsonUtils.getJsonValue(incomingRequest, "service.parameters")
168 String requestInputs = JsonUtils.getJsonValue(serviceParameters, "requestInputs")
169 JSONObject inputParameters = new JSONObject(requestInputs)
170 execution.setVariable(Prefix + "ServiceParameters", inputParameters)
172 // CallSource is added only when ONAP SO calling 3rdONAP(External API) SO(Remote call)
173 boolean isLocalCall = true
174 String callSource = "UUI"
175 if(inputParameters.has("CallSource"))
177 callSource = inputParameters.get("CallSource")
178 if("ExternalAPI".equalsIgnoreCase(callSource)) {
179 String sppartnerId = inputParameters.get("SppartnerServiceId")
180 execution.setVariable(Prefix + "SppartnerServiceId", sppartnerId)
184 execution.setVariable(Prefix + "CallSource", callSource)
185 logger.debug("callSource is: " + callSource )
187 execution.setVariable("IsLocalCall", isLocalCall)
189 } catch (Exception ex){
190 String msg = "Exception in checkLocallCall " + ex.getMessage()
192 // exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
196 public void preProcessRequest(DelegateExecution execution){
197 logger.info(" ***** Started preProcessRequest *****")
201 ResourceInput resourceInputObj = execution.getVariable(Prefix + "ResourceInput")
203 String globalSubscriberId = resourceInputObj.getGlobalSubscriberId()
204 if (isBlank(globalSubscriberId)) {
205 msg = "Input globalSubscriberId is null"
209 execution.setVariable("globalSubscriberId", globalSubscriberId)
210 logger.info("globalSubscriberId:" + globalSubscriberId)
212 String serviceType = resourceInputObj.getServiceType()
213 if (isBlank(serviceType)) {
214 msg = "Input serviceType is null"
217 execution.setVariable("serviceType", serviceType)
218 logger.info("serviceType:" + serviceType)
220 String resourceName = resourceInputObj.getResourceInstanceName()
221 if (isBlank(resourceName)) {
222 msg = "Input resourceName is null"
225 execution.setVariable("resourceName", resourceName)
226 logger.info("resourceName:" + resourceName)
228 int beginIndex = resourceName.indexOf("_") + 1
229 String serviceInstanceName = resourceName.substring(beginIndex)
230 execution.setVariable("serviceInstanceName", serviceInstanceName)
232 String serviceInstanceId = resourceInputObj.getServiceInstanceId()
233 if (isBlank(serviceInstanceId)) {
234 msg = "Input serviceInstanceId is null"
237 execution.setVariable(Prefix + "ServiceInstanceId", serviceInstanceId)
238 logger.info("serviceInstanceId:" + serviceInstanceId)
240 String resourceModelInvariantUuid = resourceInputObj.getResourceModelInfo().getModelInvariantUuid()
241 if (isBlank(resourceModelInvariantUuid)) {
242 msg = "Input resourceModelInvariantUuid is null"
245 execution.setVariable(Prefix + "ResourceModelInvariantUuid", resourceModelInvariantUuid)
246 logger.info("resourceModelInvariantUuid:" + resourceModelInvariantUuid)
248 String resourceModelUuid = resourceInputObj.getResourceModelInfo().getModelUuid()
249 if (isBlank(resourceModelUuid)) {
250 msg = "Input resourceModelUuid is null"
253 execution.setVariable(Prefix + "ResourceModelUuid", resourceModelUuid)
254 logger.info("resourceModelUuid:" + resourceModelUuid)
256 String resourceModelCustomizationUuid = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid()
257 if (isBlank(resourceModelCustomizationUuid)) {
258 msg = "Input resourceModelCustomizationUuid is null"
261 execution.setVariable(Prefix + "ResourceModelCustomizationUuid", resourceModelCustomizationUuid)
262 logger.info("resourceModelCustomizationUuid:" + resourceModelCustomizationUuid)
264 } catch (Exception ex){
265 msg = "Exception in preProcessRequest " + ex.getMessage()
267 // exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
271 public void prepareUpdateProgress(DelegateExecution execution) {
272 logger.info(" ***** Started prepareUpdateProgress *****")
273 ResourceInput resourceInputObj = execution.getVariable(Prefix + "ResourceInput")
274 String operType = resourceInputObj.getOperationType()
275 String resourceCustomizationUuid = resourceInputObj.getResourceModelInfo().getModelCustomizationUuid()
276 String ServiceInstanceId = resourceInputObj.getServiceInstanceId()
277 String modelName = resourceInputObj.getResourceModelInfo().getModelName()
278 String operationId = resourceInputObj.getOperationId()
279 String progress = execution.getVariable("progress")
280 String status = execution.getVariable("status")
281 String statusDescription = execution.getVariable("statusDescription")
284 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
285 xmlns:ns="http://org.onap.so/requestsdb">
288 <ns:updateResourceOperationStatus>
289 <operType>${operType}</operType>
290 <operationId>${operationId}</operationId>
291 <progress>${progress}</progress>
292 <resourceTemplateUUID>${resourceCustomizationUuid}</resourceTemplateUUID>
293 <serviceId>${ServiceInstanceId}</serviceId>
294 <status>${status}</status>
295 <statusDescription>${statusDescription}</statusDescription>
296 </ns:updateResourceOperationStatus>
298 </soapenv:Envelope>"""
300 setProgressUpdateVariables(execution, body)
301 logger.info(" ***** Exit prepareUpdateProgress *****")
304 public void allocateCrossONAPResource(DelegateExecution execution) {
305 logger.info(" ***** Started allocateCrossONAPResource *****")
307 //get TP links from AAI for SOTN handoverMode only
308 String handoverMode = execution.getVariable(Prefix + "HandoverMode")
309 if("SOTN".equalsIgnoreCase(handoverMode)) {
310 // Put TP Link info into serviceParameters
311 JSONObject inputParameters = execution.getVariable(Prefix + "ServiceParameters")
312 if(inputParameters.has("remote-access-provider-id")) {
313 Map<String, Object> crossTPs = new HashMap<String, Object>();
314 crossTPs.put("local-access-provider-id", inputParameters.get("remote-access-provider-id"));
315 crossTPs.put("local-access-client-id", inputParameters.get("remote-access-client-id"));
316 crossTPs.put("local-access-topology-id", inputParameters.get("remote-access-topology-id"));
317 crossTPs.put("local-access-node-id", inputParameters.get("remote-access-node-id"));
318 crossTPs.put("local-access-ltp-id", inputParameters.get("remote-access-ltp-id"));
319 crossTPs.put("remote-access-provider-id", inputParameters.get("local-access-provider-id"));
320 crossTPs.put("remote-access-client-id", inputParameters.get("local-access-client-id"));
321 crossTPs.put("remote-access-topology-id", inputParameters.get("local-access-topology-id"));
322 crossTPs.put("remote-access-node-id", inputParameters.get("local-access-node-id"));
323 crossTPs.put("remote-access-ltp-id", inputParameters.get("local-access-ltp-id"));
325 inputParameters.put("local-access-provider-id", crossTPs.get("local-access-provider-id"));
326 inputParameters.put("local-access-client-id", crossTPs.get("local-access-client-id"));
327 inputParameters.put("local-access-topology-id", crossTPs.get("local-access-topology-id"));
328 inputParameters.put("local-access-node-id", crossTPs.get("local-access-node-id"));
329 inputParameters.put("local-access-ltp-id", crossTPs.get("local-access-ltp-id"));
330 inputParameters.put("remote-access-provider-id", crossTPs.get("remote-access-provider-id"));
331 inputParameters.put("remote-access-client-id", crossTPs.get("remote-access-client-id"));
332 inputParameters.put("remote-access-topology-id", crossTPs.get("remote-access-topology-id"));
333 inputParameters.put("remote-access-node-id", crossTPs.get("remote-access-node-id"));
334 inputParameters.put("remote-access-ltp-id", crossTPs.get("remote-access-ltp-id"));
336 execution.setVariable(Prefix + "ServiceParameters", inputParameters)
339 logger.error("No allocated CrossONAPResource found in ServiceParameters")
343 logger.info("Exit " + allocateCrossONAPResource)
346 public void prepare3rdONAPRequest(DelegateExecution execution) {
347 logger.info(" ***** Started prepare3rdONAPRequest *****")
349 String sppartnerUrl = execution.getVariable(Prefix + "SppartnerUrl")
350 String extAPIPath = sppartnerUrl + '/serviceOrder'
351 execution.setVariable("ExternalAPIURL", extAPIPath)
353 // ExternalAPI message format
354 String externalId = execution.getVariable("resourceName")
355 String category = "E2E Service"
356 String description = "Service Order from SPPartner"
357 String requestedStartDate = utils.generateCurrentTimeInUtc()
358 String requestedCompletionDate = utils.generateCurrentTimeInUtc()
359 String priority = "1" // 0-4 0:highest
360 String subscriberId = execution.getVariable("globalSubscriberId")
361 String customerRole = "ONAPcustomer"
362 String subscriberName = subscriberId
363 String referredType = "Consumer"
364 String orderItemId = "1"
365 String action = "add" //for create
366 String serviceState = "active"
367 String serviceName = execution.getVariable("serviceInstanceName")
368 String serviceUuId = execution.getVariable(Prefix + "SppartnerUUID")
370 Map<String, String> valueMap = new HashMap<>()
371 valueMap.put("externalId", '"' + externalId + '"')
372 valueMap.put("category", '"' + category + '"')
373 valueMap.put("description", '"' + description + '"')
374 valueMap.put("requestedStartDate", '"' + requestedStartDate + '"')
375 valueMap.put("requestedCompletionDate", '"' + requestedCompletionDate + '"')
376 valueMap.put("priority", '"'+ priority + '"')
377 valueMap.put("subscriberId", '"' + subscriberId + '"')
378 valueMap.put("customerRole", '"' + customerRole + '"')
379 valueMap.put("subscriberName", '"' + subscriberName + '"')
380 valueMap.put("referredType", '"' + referredType + '"')
381 valueMap.put("orderItemId", '"' + orderItemId + '"')
382 valueMap.put("action", '"' + action + '"')
383 valueMap.put("serviceState", '"' + serviceState + '"')
384 valueMap.put("serviceId", "null") //null for add
385 valueMap.put("serviceName", '"' + serviceName + '"')
386 valueMap.put("serviceUuId", '"' + serviceUuId + '"')
388 ExternalAPIUtil externalAPIUtil = new ExternalAPIUtilFactory().create()
390 // insert CallSource='ExternalAPI' to uuiRequest
391 Map<String, String> requestInputsMap = new HashMap<>()
392 requestInputsMap.put("inputName", '"CallSource"')
393 requestInputsMap.put("inputValue", '"ExternalAPI"')
394 String _requestInputs_ = externalAPIUtil.setTemplate(ExternalAPIUtil.RequestInputsTemplate, requestInputsMap)
396 requestInputsMap.clear()
397 String serviceInstanceId = execution.getVariable(Prefix + "ServiceInstanceId")
398 requestInputsMap.put("inputName", '"SppartnerServiceId"')
399 requestInputsMap.put("inputValue", '"' + serviceInstanceId + '"')
400 _requestInputs_ += ",\n" + externalAPIUtil.setTemplate(ExternalAPIUtil.RequestInputsTemplate, requestInputsMap)
402 requestInputsMap.clear()
403 String serviceType = execution.getVariable("serviceType")
404 requestInputsMap.put("inputName", '"serviceType"')
405 requestInputsMap.put("inputValue", '"' + serviceType + '"')
406 _requestInputs_ += ",\n" + externalAPIUtil.setTemplate(ExternalAPIUtil.RequestInputsTemplate, requestInputsMap)
408 // Transfer all uuiRequest incomeParameters to ExternalAPI format
409 JSONObject inputParameters = execution.getVariable(Prefix + "ServiceParameters")
410 for(String key : inputParameters.keySet()) {
411 String inputName = key
412 String inputValue = inputParameters.opt(key)
413 requestInputsMap.clear()
414 requestInputsMap.put("inputName", '"' + inputName+ '"')
415 requestInputsMap.put("inputValue", '"' + inputValue + '"')
416 _requestInputs_ += ",\n" + externalAPIUtil.setTemplate(ExternalAPIUtil.RequestInputsTemplate, requestInputsMap)
418 valueMap.put("_requestInputs_", _requestInputs_)
420 String payload = externalAPIUtil.setTemplate(ExternalAPIUtil.PostServiceOrderRequestsTemplate, valueMap)
421 execution.setVariable(Prefix + "Payload", payload)
422 logger.info("Exit " + prepare3rdONAPRequest)
425 public void doCreateE2ESIin3rdONAP(DelegateExecution execution) {
426 logger.info(" ***** Started doCreateE2ESIin3rdONAP *****")
428 String extAPIPath = execution.getVariable("ExternalAPIURL")
429 String payload = execution.getVariable(Prefix + "Payload")
430 logger.debug("doCreateE2ESIin3rdONAP externalAPIURL is: " + extAPIPath)
431 logger.debug("doCreateE2ESIin3rdONAP payload is: " + payload)
433 ExternalAPIUtil externalAPIUtil = new ExternalAPIUtilFactory().create()
434 execution.setVariable("ServiceOrderId", "")
436 Response response = externalAPIUtil.executeExternalAPIPostCall(execution, extAPIPath, payload)
438 int responseCode = response.getStatus()
439 execution.setVariable(Prefix + "PostServiceOrderResponseCode", responseCode)
440 logger.debug("Post ServiceOrder response code is: " + responseCode)
442 String extApiResponse = response.readEntity(String.class)
443 JSONObject responseObj = new JSONObject(extApiResponse)
444 execution.setVariable(Prefix + "PostServiceOrderResponse", extApiResponse)
446 logger.debug("doCreateE2ESIin3rdONAP response body is: " + extApiResponse)
449 if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
450 //200 OK 201 CREATED 202 ACCEPTED
452 logger.debug("Post ServiceOrder Received a Good Response")
453 String serviceOrderId = responseObj.get("id")
454 execution.setVariable(Prefix + "SuccessIndicator", true)
455 execution.setVariable("ServiceOrderId", serviceOrderId)
456 logger.info("Post ServiceOrderid is: " + serviceOrderId)
459 logger.error("Post ServiceOrder Received a Bad Response Code. Response Code is: " + responseCode)
460 // exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Post ServiceOrder Received a bad response from 3rdONAP External API")
463 logger.error("doCreateE2ESIin3rdONAP exception:" + e.getMessage())
466 logger.info("Exit " + doCreateE2ESIin3rdONAP)
470 public void getE2ESIProgressin3rdONAP(DelegateExecution execution) {
471 logger.info(" ***** Started getE2ESIProgressin3rdONAP *****")
474 String extAPIPath = execution.getVariable("ExternalAPIURL")
475 extAPIPath += "/" + execution.getVariable("ServiceOrderId")
476 logger.debug("getE2ESIProgressin3rdONAP create externalAPIURL is: " + extAPIPath)
478 ExternalAPIUtil externalAPIUtil = new ExternalAPIUtilFactory().create()
480 Response response = externalAPIUtil.executeExternalAPIGetCall(execution, extAPIPath)
482 int responseCode = response.getStatus()
483 execution.setVariable(Prefix + "GetServiceOrderResponseCode", responseCode)
484 logger.debug("Get ServiceOrder response code is: " + responseCode)
486 String extApiResponse = response.readEntity(String.class)
487 JSONObject responseObj = new JSONObject(extApiResponse)
488 execution.setVariable(Prefix + "GetServiceOrderResponse", extApiResponse)
490 logger.debug("getE2ESIProgressin3rdONAP create response body is: " + extApiResponse)
492 //Process Response //200 OK 201 CREATED 202 ACCEPTED
493 if(responseCode == 200 || responseCode == 201 || responseCode == 202 )
495 logger.debug("Get Create ServiceOrder Received a Good Response")
497 String orderState = responseObj.get("state")
498 if("REJECTED".equalsIgnoreCase(orderState)) {
499 execution.setVariable("progress", 100)
500 execution.setVariable("status", "error")
501 execution.setVariable("statusDescription", "Create Service Order Status is REJECTED")
505 JSONArray items = responseObj.getJSONArray("orderItem")
506 JSONObject item = items[0]
507 JSONObject service = item.get("service")
508 String sppartnerServiceId = service.get("id")
509 if(sppartnerServiceId == null || sppartnerServiceId.equals("null")) {
510 execution.setVariable("progress", 100)
511 execution.setVariable("status", "error")
512 execution.setVariable("statusDescription", "Create Service Order Status get null sppartnerServiceId")
513 logger.error("null sppartnerServiceId while getting progress from externalAPI")
517 execution.setVariable(Prefix + "SppartnerServiceId", sppartnerServiceId)
519 String serviceOrderState = item.get("state")
520 execution.setVariable(Prefix + "SuccessIndicator", true)
521 execution.setVariable("ServiceOrderState", serviceOrderState)
523 // Get serviceOrder State and process progress
524 if("ACKNOWLEDGED".equalsIgnoreCase(serviceOrderState)) {
525 execution.setVariable("progress", 15)
526 execution.setVariable("status", "processing")
527 execution.setVariable("statusDescription", "Create Service Order Status is " + serviceOrderState)
529 else if("INPROGRESS".equalsIgnoreCase(serviceOrderState)) {
530 execution.setVariable("progress", 40)
531 execution.setVariable("status", "processing")
532 execution.setVariable("statusDescription", "Create Service Order Status is " + serviceOrderState)
534 else if("COMPLETED".equalsIgnoreCase(serviceOrderState)) {
535 execution.setVariable("progress", 100)
536 execution.setVariable("status", "finished")
537 execution.setVariable("statusDescription", "Create Service Order Status is " + serviceOrderState)
539 else if("FAILED".equalsIgnoreCase(serviceOrderState)) {
540 execution.setVariable("progress", 100)
541 execution.setVariable("status", "error")
542 execution.setVariable("statusDescription", "Create Service Order Status is " + serviceOrderState)
545 execution.setVariable("progress", 100)
546 execution.setVariable("status", "error")
547 execution.setVariable("statusDescription", "Create Service Order Status is unknown")
551 logger.debug("Get ServiceOrder Received a Bad Response Code. Response Code is: " + responseCode)
552 execution.setVariable("progress", 100)
553 execution.setVariable("status", "error")
554 execution.setVariable("statusDescription", "Get Create ServiceOrder Received a bad response")
555 // exceptionUtil.buildAndThrowWorkflowException(execution, 500, "Get Create ServiceOrder Received a bad response from 3rdONAP External API")
559 execution.setVariable("progress", 100)
560 execution.setVariable("status", "error")
561 execution.setVariable("statusDescription", "Get Create ServiceOrder Exception")
562 logger.error("getE2ESIProgressin3rdONAP exception:" + e.getMessage())
564 logger.info("Exit " + getE2ESIProgressin3rdONAP)
570 public void timeDelay(DelegateExecution execution) {
573 } catch(InterruptedException e) {
574 logger.error("Time Delay exception" + e)
578 public void saveSPPartnerInAAI(DelegateExecution execution) {
579 logger.info(" ***** Started saveSPPartnerInAAI *****")
581 String sppartnerId = execution.getVariable(Prefix + "SppartnerServiceId")
582 String sppartnerUrl = execution.getVariable(Prefix + "SppartnerUrl")
583 String callSource = execution.getVariable(Prefix + "CallSource")
584 String serviceInstanceId = execution.getVariable(Prefix + "ServiceInstanceId")
585 String globalSubscriberId = execution.getVariable("globalSubscriberId")
586 String serviceType = execution.getVariable("serviceType")
587 String resourceModelInvariantUuid = execution.getVariable(Prefix + "ResourceModelInvariantUuid")
588 String resourceModelUuid = execution.getVariable(Prefix + "ResourceModelUuid")
589 String resourceModelCustomizationUuid = execution.getVariable(Prefix + "ResourceModelCustomizationUuid")
591 SpPartner partner = new SpPartner()
592 partner.setSpPartnerId(sppartnerId)
593 partner.setUrl(sppartnerUrl)
594 partner.setCallsource(callSource)
595 partner.setModelInvariantId(resourceModelInvariantUuid)
596 partner.setModelVersionId(resourceModelUuid)
597 partner.setModelCustomizationId(resourceModelCustomizationUuid)
599 AAIResourcesClient client = new AAIResourcesClient()
600 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SP_PARTNER, sppartnerId)
601 client.create(uri, partner)
603 AAIResourceUri siUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, serviceInstanceId)
604 client.connect(uri, siUri)
605 } catch (Exception ex) {
606 String msg = "Exception in Create3rdONAPE2EServiceInstance.saveSPPartnerInAAI. " + ex.getMessage()
608 // throw new BpmnError("MSOWorkflowException")
610 logger.info("Exit " + saveSPPartnerInAAI)
613 private void setProgressUpdateVariables(DelegateExecution execution, String body) {
614 def dbAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.openecomp.db.endpoint", execution)
615 execution.setVariable("CVFMI_dbAdapterEndpoint", dbAdapterEndpoint)
616 execution.setVariable("CVFMI_updateResOperStatusRequest", body)
619 public void postProcess(DelegateExecution execution){
620 logger.info(" ***** Started postProcess *****")
621 String responseCode = execution.getVariable(Prefix + "PutSppartnerResponseCode")
622 String responseObj = execution.getVariable(Prefix + "PutSppartnerResponse")
624 logger.info("response from AAI for put sppartner, response code :" + responseCode + " response object :" + responseObj)
625 logger.info(" ***** Exit postProcess *****")
628 public void sendSyncResponse (DelegateExecution execution) {
629 logger.debug(" *** sendSyncResponse *** ")
632 String operationStatus = "finished"
633 // RESTResponse for main flow
634 String resourceOperationResp = """{"operationStatus":"${operationStatus}"}""".trim()
635 logger.debug(" sendSyncResponse to APIH:" + "\n" + resourceOperationResp)
636 sendWorkflowResponse(execution, 202, resourceOperationResp)
637 execution.setVariable("sentSyncResponse", true)
639 } catch (Exception ex) {
640 String msg = "Exceptuion in sendSyncResponse:" + ex.getMessage()
642 // exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
644 logger.debug(" ***** Exit sendSyncResopnse *****")