2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 CMCC All rights reserved. *
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.so.bpmn.infrastructure.scripts
22 import static org.apache.commons.lang3.StringUtils.*;
24 import org.camunda.bpm.engine.delegate.BpmnError
25 import org.camunda.bpm.engine.delegate.DelegateExecution
26 import org.json.JSONArray;
27 import org.json.JSONObject;
28 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
29 import org.onap.so.bpmn.common.scripts.ExceptionUtil
30 import org.onap.so.bpmn.common.scripts.MsoUtils
31 import org.onap.so.bpmn.core.json.JsonUtils
32 import org.onap.so.logger.MessageEnum
33 import org.onap.so.logger.MsoLogger
34 import org.springframework.web.util.UriUtils;
39 * This groovy class supports the <class>DoScaleServiceInstance.bpmn</class> process.
42 public class DoScaleE2EServiceInstance extends AbstractServiceTaskProcessor {
43 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, DoScaleE2EServiceInstance.class);
46 String Prefix = "DCRESI_"
47 ExceptionUtil exceptionUtil = new ExceptionUtil()
48 JsonUtils jsonUtil = new JsonUtils()
50 public void preProcessRequest(DelegateExecution execution) {
52 msoLogger.trace("preProcessRequest ")
55 String requestId = execution.getVariable("msoRequestId")
56 execution.setVariable("prefix", Prefix)
59 String globalSubscriberId = execution.getVariable("globalSubscriberId")
61 String serviceType = execution.getVariable("serviceType")
62 String serviceInstanceName = execution.getVariable("serviceInstanceName")
63 String serviceInstanceId = execution.getVariable("serviceInstanceId")
65 execution.setVariable("serviceType", serviceType)
67 String resourceTemplateUUIDs = ""
68 String scaleNsRequest = execution.getVariable("bpmnRequest")
69 JSONObject jsonObject = new JSONObject(scaleNsRequest).getJSONObject("service")
70 JSONArray jsonArray = jsonObject.getJSONArray("resources")
72 for (int i = 0; i < jsonArray.size(); i++) {
73 JSONObject reqBodyJsonObj = jsonArray.getJSONObject(i)
74 String nsInstanceId = reqBodyJsonObj.getString("resourceInstanceId")
75 resourceTemplateUUIDs = resourceTemplateUUIDs + nsInstanceId + ":"
78 execution.setVariable("resourceTemplateUUIDs", resourceTemplateUUIDs)
80 if (serviceInstanceName == null) {
81 execution.setVariable("serviceInstanceName", "")
83 if (isBlank(serviceInstanceId)) {
84 msg = "Input serviceInstanceId is null"
86 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
88 } catch (BpmnError e) {
90 } catch (Exception ex) {
91 msg = "Exception in preProcessRequest " + ex.getMessage()
93 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
95 msoLogger.trace("Exit preProcessRequest ")
99 public void preInitResourcesOperStatus(DelegateExecution execution){
100 msoLogger.trace("STARTED preInitResourcesOperStatus Process ")
102 String serviceId = execution.getVariable("serviceInstanceId")
103 String operationId = execution.getVariable("operationId")
104 String operationType = "SCALE"
106 // resourceTemplateUUIDs should be created ??
107 String resourceTemplateUUIDs = execution.getVariable("resourceTemplateUUIDs")
108 msoLogger.info("Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType)
109 serviceId = UriUtils.encode(serviceId,"UTF-8")
110 execution.setVariable("serviceInstanceId", serviceId)
111 execution.setVariable("operationId", operationId)
112 execution.setVariable("operationType", operationType)
114 execution.setVariable("URN_mso_openecomp_adapters_db_endpoint","http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")
117 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
118 xmlns:ns="http://org.onap.so/requestsdb">
121 <ns:initResourceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
122 <serviceId>${MsoUtils.xmlEscape(serviceId)}</serviceId>
123 <operationId>${MsoUtils.xmlEscape(operationId)}</operationId>
124 <operationType>${MsoUtils.xmlEscape(operationType)}</operationType>
125 <resourceTemplateUUIDs>${MsoUtils.xmlEscape(resourceTemplateUUIDs)}</resourceTemplateUUIDs>
126 </ns:initResourceOperationStatus>
128 </soapenv:Envelope>"""
130 payload = utils.formatXml(payload)
131 execution.setVariable("CVFMI_initResOperStatusRequest", payload)
132 msoLogger.info("Outgoing initResourceOperationStatus: \n" + payload)
133 msoLogger.debug("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)
136 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing preInitResourcesOperStatus.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
137 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
139 msoLogger.trace("COMPLETED preInitResourcesOperStatus Process ")