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.ErrorCode
26 import static org.apache.commons.lang3.StringUtils.*;
28 import org.camunda.bpm.engine.delegate.BpmnError
29 import org.camunda.bpm.engine.delegate.DelegateExecution
30 import org.json.JSONArray;
31 import org.json.JSONObject;
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.MsoUtils
35 import org.onap.so.bpmn.core.json.JsonUtils
36 import org.onap.so.logger.MessageEnum
37 import org.slf4j.Logger
38 import org.slf4j.LoggerFactory
39 import org.springframework.web.util.UriUtils;
44 * This groovy class supports the <class>DoScaleServiceInstance.bpmn</class> process.
47 public class DoScaleE2EServiceInstance extends AbstractServiceTaskProcessor {
48 private static final Logger logger = LoggerFactory.getLogger( DoScaleE2EServiceInstance.class);
51 String Prefix = "DCRESI_"
52 ExceptionUtil exceptionUtil = new ExceptionUtil()
53 JsonUtils jsonUtil = new JsonUtils()
55 public void preProcessRequest(DelegateExecution execution) {
57 logger.trace("preProcessRequest ")
60 String requestId = execution.getVariable("msoRequestId")
61 execution.setVariable("prefix", Prefix)
64 String globalSubscriberId = execution.getVariable("globalSubscriberId")
66 String serviceType = execution.getVariable("serviceType")
67 String serviceInstanceName = execution.getVariable("serviceInstanceName")
68 String serviceInstanceId = execution.getVariable("serviceInstanceId")
70 execution.setVariable("serviceType", serviceType)
72 String resourceTemplateUUIDs = ""
73 String scaleNsRequest = execution.getVariable("bpmnRequest")
74 JSONObject jsonObject = new JSONObject(scaleNsRequest).getJSONObject("service")
75 JSONArray jsonArray = jsonObject.getJSONArray("resources")
77 for (int i = 0; i < jsonArray.size(); i++) {
78 JSONObject reqBodyJsonObj = jsonArray.getJSONObject(i)
79 String nsInstanceId = reqBodyJsonObj.getString("resourceInstanceId")
80 resourceTemplateUUIDs = resourceTemplateUUIDs + nsInstanceId + ":"
83 execution.setVariable("resourceTemplateUUIDs", resourceTemplateUUIDs)
85 if (serviceInstanceName == null) {
86 execution.setVariable("serviceInstanceName", "")
88 if (isBlank(serviceInstanceId)) {
89 msg = "Input serviceInstanceId is null"
91 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
93 } catch (BpmnError e) {
95 } catch (Exception ex) {
96 msg = "Exception in preProcessRequest " + ex.getMessage()
98 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
100 logger.trace("Exit preProcessRequest ")
104 public void preInitResourcesOperStatus(DelegateExecution execution){
105 logger.trace("STARTED preInitResourcesOperStatus Process ")
107 String serviceId = execution.getVariable("serviceInstanceId")
108 String operationId = execution.getVariable("operationId")
109 String operationType = "SCALE"
111 // resourceTemplateUUIDs should be created ??
112 String resourceTemplateUUIDs = execution.getVariable("resourceTemplateUUIDs")
113 logger.info("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType)
114 serviceId = UriUtils.encode(serviceId,"UTF-8")
115 execution.setVariable("serviceInstanceId", serviceId)
116 execution.setVariable("operationId", operationId)
117 execution.setVariable("operationType", operationType)
119 execution.setVariable("URN_mso_openecomp_adapters_db_endpoint","http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")
122 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
123 xmlns:ns="http://org.onap.so/requestsdb">
126 <ns:initResourceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
127 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
128 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
129 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
130 <resourceTemplateUUIDs>${MsoUtils.xmlEscape(resourceTemplateUUIDs)}</resourceTemplateUUIDs>
131 </ns:initResourceOperationStatus>
133 </soapenv:Envelope>"""
135 payload = utils.formatXml(payload)
136 execution.setVariable("CVFMI_initResOperStatusRequest", payload)
137 logger.info("Outgoing initResourceOperationStatus: \n" + payload)
138 logger.debug("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)
141 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
142 "Exception Occured Processing preInitResourcesOperStatus.", "BPMN",
143 ErrorCode.UnknownError.getValue(), e);
144 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
146 logger.trace("COMPLETED preInitResourcesOperStatus Process ")