2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 CMCC 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 org.camunda.bpm.engine.delegate.BpmnError
27 import org.camunda.bpm.engine.delegate.DelegateExecution
28 import org.json.JSONArray;
29 import org.json.JSONObject;
30 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
31 import org.onap.so.bpmn.common.scripts.ExceptionUtil
32 import org.onap.so.bpmn.common.scripts.MsoUtils
33 import org.onap.so.bpmn.core.json.JsonUtils
34 import org.onap.so.logger.MessageEnum
35 import org.onap.so.logger.MsoLogger
36 import org.slf4j.Logger
37 import org.slf4j.LoggerFactory
38 import org.springframework.web.util.UriUtils;
43 * This groovy class supports the <class>DoScaleServiceInstance.bpmn</class> process.
46 public class DoScaleE2EServiceInstance extends AbstractServiceTaskProcessor {
47 private static final Logger logger = LoggerFactory.getLogger( DoScaleE2EServiceInstance.class);
50 String Prefix = "DCRESI_"
51 ExceptionUtil exceptionUtil = new ExceptionUtil()
52 JsonUtils jsonUtil = new JsonUtils()
54 public void preProcessRequest(DelegateExecution execution) {
56 logger.trace("preProcessRequest ")
59 String requestId = execution.getVariable("msoRequestId")
60 execution.setVariable("prefix", Prefix)
63 String globalSubscriberId = execution.getVariable("globalSubscriberId")
65 String serviceType = execution.getVariable("serviceType")
66 String serviceInstanceName = execution.getVariable("serviceInstanceName")
67 String serviceInstanceId = execution.getVariable("serviceInstanceId")
69 execution.setVariable("serviceType", serviceType)
71 String resourceTemplateUUIDs = ""
72 String scaleNsRequest = execution.getVariable("bpmnRequest")
73 JSONObject jsonObject = new JSONObject(scaleNsRequest).getJSONObject("service")
74 JSONArray jsonArray = jsonObject.getJSONArray("resources")
76 for (int i = 0; i < jsonArray.size(); i++) {
77 JSONObject reqBodyJsonObj = jsonArray.getJSONObject(i)
78 String nsInstanceId = reqBodyJsonObj.getString("resourceInstanceId")
79 resourceTemplateUUIDs = resourceTemplateUUIDs + nsInstanceId + ":"
82 execution.setVariable("resourceTemplateUUIDs", resourceTemplateUUIDs)
84 if (serviceInstanceName == null) {
85 execution.setVariable("serviceInstanceName", "")
87 if (isBlank(serviceInstanceId)) {
88 msg = "Input serviceInstanceId is null"
90 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
92 } catch (BpmnError e) {
94 } catch (Exception ex) {
95 msg = "Exception in preProcessRequest " + ex.getMessage()
97 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
99 logger.trace("Exit preProcessRequest ")
103 public void preInitResourcesOperStatus(DelegateExecution execution){
104 logger.trace("STARTED preInitResourcesOperStatus Process ")
106 String serviceId = execution.getVariable("serviceInstanceId")
107 String operationId = execution.getVariable("operationId")
108 String operationType = "SCALE"
110 // resourceTemplateUUIDs should be created ??
111 String resourceTemplateUUIDs = execution.getVariable("resourceTemplateUUIDs")
112 logger.info("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType)
113 serviceId = UriUtils.encode(serviceId,"UTF-8")
114 execution.setVariable("serviceInstanceId", serviceId)
115 execution.setVariable("operationId", operationId)
116 execution.setVariable("operationType", operationType)
118 execution.setVariable("URN_mso_openecomp_adapters_db_endpoint","http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")
121 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
122 xmlns:ns="http://org.onap.so/requestsdb">
125 <ns:initResourceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
126 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
127 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
128 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
129 <resourceTemplateUUIDs>${MsoUtils.xmlEscape(resourceTemplateUUIDs)}</resourceTemplateUUIDs>
130 </ns:initResourceOperationStatus>
132 </soapenv:Envelope>"""
134 payload = utils.formatXml(payload)
135 execution.setVariable("CVFMI_initResOperStatusRequest", payload)
136 logger.info("Outgoing initResourceOperationStatus: \n" + payload)
137 logger.debug("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)
140 logger.error("{} {} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
141 "Exception Occured Processing preInitResourcesOperStatus.", "BPMN", MsoLogger.getServiceName(),
142 MsoLogger.ErrorCode.UnknownError.getValue(), e);
143 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
145 logger.trace("COMPLETED preInitResourcesOperStatus Process ")