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.openecomp.mso.bpmn.infrastructure.scripts
22 import org.camunda.bpm.engine.delegate.DelegateExecution
23 import org.json.JSONArray;
24 import static org.apache.commons.lang3.StringUtils.*;
25 import org.openecomp.mso.bpmn.core.json.JsonUtils
26 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
27 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
28 import org.camunda.bpm.engine.delegate.BpmnError
29 import org.camunda.bpm.engine.runtime.Execution
30 import org.json.JSONObject;
31 import org.springframework.web.util.UriUtils;
34 * This groovy class supports the <class>DoScaleServiceInstance.bpmn</class> process.
37 public class DoScaleE2EServiceInstance extends AbstractServiceTaskProcessor {
39 String Prefix = "DCRESI_"
40 ExceptionUtil exceptionUtil = new ExceptionUtil()
41 JsonUtils jsonUtil = new JsonUtils()
43 public void preProcessRequest(DelegateExecution execution) {
44 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
46 utils.log("DEBUG", " ***** preProcessRequest *****", isDebugEnabled)
49 String requestId = execution.getVariable("msoRequestId")
50 execution.setVariable("prefix", Prefix)
53 String globalSubscriberId = execution.getVariable("globalSubscriberId")
55 String serviceType = execution.getVariable("serviceType")
56 String serviceInstanceName = execution.getVariable("serviceInstanceName")
57 String serviceInstanceId = execution.getVariable("serviceInstanceId")
59 execution.setVariable("serviceType", serviceType)
61 String resourceTemplateUUIDs = ""
62 String scaleNsRequest = execution.getVariable("bpmnRequest")
63 JSONObject jsonObject = new JSONObject(scaleNsRequest).getJSONObject("service")
64 JSONArray jsonArray = jsonObject.getJSONArray("resources")
66 for (int i = 0; i < jsonArray.size(); i++) {
67 JSONObject reqBodyJsonObj = jsonArray.getJSONObject(i)
68 String nsInstanceId = reqBodyJsonObj.getString("resourceInstanceId")
69 resourceTemplateUUIDs = resourceTemplateUUIDs + nsInstanceId + ":"
72 execution.setVariable("resourceTemplateUUIDs", resourceTemplateUUIDs)
74 if (serviceInstanceName == null) {
75 execution.setVariable("serviceInstanceName", "")
77 if (isBlank(serviceInstanceId)) {
78 msg = "Input serviceInstanceId is null"
79 utils.log("DEBUG", msg, isDebugEnabled)
80 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
82 } catch (BpmnError e) {
84 } catch (Exception ex) {
85 msg = "Exception in preProcessRequest " + ex.getMessage()
86 utils.log("DEBUG", msg, isDebugEnabled)
87 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
89 utils.log("DEBUG", " ***** Exit preProcessRequest *****", isDebugEnabled)
93 public void preInitResourcesOperStatus(DelegateExecution execution){
94 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
96 utils.log("INFO", " ======== STARTED preInitResourcesOperStatus Process ======== ", isDebugEnabled)
98 String serviceId = execution.getVariable("serviceInstanceId")
99 String operationId = execution.getVariable("operationId")
100 String operationType = "SCALE"
102 // resourceTemplateUUIDs should be created ??
103 String resourceTemplateUUIDs = execution.getVariable("resourceTemplateUUIDs")
104 utils.log("INFO", "Generated new operation for Service Instance serviceId:" + serviceId + " operationId:" + operationId + " operationType:" + operationType, isDebugEnabled)
105 serviceId = UriUtils.encode(serviceId,"UTF-8")
106 execution.setVariable("serviceInstanceId", serviceId)
107 execution.setVariable("operationId", operationId)
108 execution.setVariable("operationType", operationType)
110 execution.setVariable("URN_mso_openecomp_adapters_db_endpoint","http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")
113 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
114 xmlns:ns="http://org.openecomp.mso/requestsdb">
117 <ns:initResourceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">
118 <serviceId>${serviceId}</serviceId>
119 <operationId>${operationId}</operationId>
120 <operationType>${operationType}</operationType>
121 <resourceTemplateUUIDs>${resourceTemplateUUIDs}</resourceTemplateUUIDs>
122 </ns:initResourceOperationStatus>
124 </soapenv:Envelope>"""
126 payload = utils.formatXml(payload)
127 execution.setVariable("CVFMI_initResOperStatusRequest", payload)
128 utils.log("INFO", "Outgoing initResourceOperationStatus: \n" + payload, isDebugEnabled)
129 utils.logAudit("CreateVfModuleInfra Outgoing initResourceOperationStatus Request: " + payload)
132 utils.log("ERROR", "Exception Occured Processing preInitResourcesOperStatus. Exception is:\n" + e, isDebugEnabled)
133 execution.setVariable("CVFMI_ErrorResponse", "Error Occurred during preInitResourcesOperStatus Method:\n" + e.getMessage())
135 utils.log("INFO", "======== COMPLETED preInitResourcesOperStatus Process ======== ", isDebugEnabled)