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 org.onap.so.logger.LoggingAnchor
25 import org.onap.so.logger.ErrorCode
27 import static org.apache.commons.lang3.StringUtils.*;
29 import org.camunda.bpm.engine.delegate.BpmnError
30 import org.camunda.bpm.engine.delegate.DelegateExecution
31 import org.json.JSONArray;
32 import org.json.JSONObject;
33 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
34 import org.onap.so.bpmn.common.scripts.ExceptionUtil
35 import org.onap.so.bpmn.common.scripts.MsoUtils
36 import org.onap.so.bpmn.core.json.JsonUtils
37 import org.onap.so.logger.MessageEnum
38 import org.slf4j.Logger
39 import org.slf4j.LoggerFactory
40 import org.springframework.web.util.UriUtils;
45 * This groovy class supports the <class>DoScaleServiceInstance.bpmn</class> process.
48 public class DoScaleE2EServiceInstance extends AbstractServiceTaskProcessor {
49 private static final Logger logger = LoggerFactory.getLogger( DoScaleE2EServiceInstance.class);
52 String Prefix = "DCRESI_"
53 ExceptionUtil exceptionUtil = new ExceptionUtil()
54 JsonUtils jsonUtil = new JsonUtils()
56 public void preProcessRequest(DelegateExecution execution) {
58 logger.trace("preProcessRequest ")
61 String requestId = execution.getVariable("msoRequestId")
62 execution.setVariable("prefix", Prefix)
65 String globalSubscriberId = execution.getVariable("globalSubscriberId")
67 String serviceType = execution.getVariable("serviceType")
68 String serviceInstanceName = execution.getVariable("serviceInstanceName")
69 String serviceInstanceId = execution.getVariable("serviceInstanceId")
71 execution.setVariable("serviceType", serviceType)
73 String resourceTemplateUUIDs = ""
74 String scaleNsRequest = execution.getVariable("bpmnRequest")
75 JSONObject jsonObject = new JSONObject(scaleNsRequest).getJSONObject("service")
76 JSONArray jsonArray = jsonObject.getJSONArray("resources")
78 for (int i = 0; i < jsonArray.size(); i++) {
79 JSONObject reqBodyJsonObj = jsonArray.getJSONObject(i)
80 String nsInstanceId = reqBodyJsonObj.getString("resourceInstanceId")
81 resourceTemplateUUIDs = resourceTemplateUUIDs + nsInstanceId + ":"
84 execution.setVariable("resourceTemplateUUIDs", resourceTemplateUUIDs)
86 if (serviceInstanceName == null) {
87 execution.setVariable("serviceInstanceName", "")
89 if (isBlank(serviceInstanceId)) {
90 msg = "Input serviceInstanceId is null"
92 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
94 } catch (BpmnError e) {
96 } catch (Exception ex) {
97 msg = "Exception in preProcessRequest " + ex.getMessage()
99 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
101 logger.trace("Exit preProcessRequest ")
105 public void preInitResourcesOperStatus(DelegateExecution execution){
106 logger.trace("STARTED preInitResourcesOperStatus Process ")
108 String serviceId = execution.getVariable("serviceInstanceId")
109 String operationId = execution.getVariable("operationId")
110 String operationType = "SCALE"
112 // resourceTemplateUUIDs should be created ??
113 String resourceTemplateUUIDs = execution.getVariable("resourceTemplateUUIDs")
114 logger.info("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType)
115 serviceId = UriUtils.encode(serviceId,"UTF-8")
116 execution.setVariable("serviceInstanceId", serviceId)
117 execution.setVariable("operationId", operationId)
118 execution.setVariable("operationType", operationType)
120 execution.setVariable("URN_mso_openecomp_adapters_db_endpoint","http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")
123 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
124 xmlns:ns="http://org.onap.so/requestsdb">
127 <ns:initResourceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
128 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
129 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
130 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
131 <resourceTemplateUUIDs>${MsoUtils.xmlEscape(resourceTemplateUUIDs)}</resourceTemplateUUIDs>
132 </ns:initResourceOperationStatus>
134 </soapenv:Envelope>"""
136 payload = utils.formatXml(payload)
137 execution.setVariable("CVFMI_initResOperStatusRequest", payload)
138 logger.info("Outgoing initResourceOperationStatus: \n" + payload)
139 logger.debug("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)
142 logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
143 "Exception Occured Processing preInitResourcesOperStatus.", "BPMN",
144 ErrorCode.UnknownError.getValue(), e);
145 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
147 logger.trace("COMPLETED preInitResourcesOperStatus Process ")