2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package org.openecomp.mso.bpmn.infrastructure.scripts
\r
23 import org.openecomp.mso.bpmn.common.scripts.AaiUtil;
\r
24 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor;
\r
25 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil;
\r
26 import org.openecomp.mso.bpmn.common.scripts.VidUtils;
\r
27 import org.openecomp.mso.bpmn.core.WorkflowException
\r
28 import org.openecomp.mso.rest.APIResponse
\r
30 import groovy.json.JsonSlurper
\r
32 import org.camunda.bpm.engine.delegate.BpmnError
\r
33 import org.camunda.bpm.engine.runtime.Execution;
\r
34 import org.apache.commons.lang3.*
\r
36 class CreateVfModuleVolumeInfraV1 extends AbstractServiceTaskProcessor {
\r
38 public static final String prefix='CVMVINFRAV1_'
\r
41 * Perform initial processing, such as request validation, initialization of variables, etc.
\r
42 * * @param execution
\r
44 public void preProcessRequest (Execution execution) {
\r
45 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
\r
46 preProcessRequest(execution, isDebugEnabled)
\r
51 * Perform initial processing, such as request validation, initialization of variables, etc.
\r
53 * @param isDebugEnabled
\r
55 public void preProcessRequest (Execution execution, isDebugEnabled) {
\r
57 execution.setVariable("prefix",prefix)
\r
58 setSuccessIndicator(execution, false)
\r
59 execution.setVariable(prefix+'syncResponseSent', false)
\r
61 String createVolumeIncoming = validateRequest(execution, 'vnfId')
\r
62 utils.logAudit(createVolumeIncoming)
\r
65 def jsonSlurper = new JsonSlurper()
\r
66 Map reqMap = jsonSlurper.parseText(createVolumeIncoming)
\r
68 def serviceInstanceId = execution.getVariable('serviceInstanceId')
\r
69 def vnfId = execution.getVariable('vnfId')
\r
71 def vidUtils = new VidUtils(this)
\r
72 createVolumeIncoming = vidUtils.createXmlVolumeRequest(reqMap, 'CREATE_VF_MODULE_VOL', serviceInstanceId)
\r
74 execution.setVariable(prefix+'Request', createVolumeIncoming)
\r
75 execution.setVariable(prefix+'vnfId', vnfId)
\r
76 execution.setVariable(prefix+'isVidRequest', true)
\r
78 utils.log("DEBUG", "XML request:\n" + createVolumeIncoming, isDebugEnabled)
\r
81 catch(groovy.json.JsonException je) {
\r
82 (new ExceptionUtil()).buildAndThrowWorkflowException(execution, 2500, 'Request is not a valid JSON document')
\r
85 execution.setVariable(prefix+'source', utils.getNodeText1(createVolumeIncoming, "source"))
\r
86 execution.setVariable(prefix+'volumeGroupName', utils.getNodeText1(createVolumeIncoming, 'volume-group-name'))
\r
87 execution.setVariable(prefix+'volumeOutputs', utils.getNodeXml(createVolumeIncoming, 'volume-outputs', false))
\r
89 execution.setVariable(prefix+'serviceType', 'service-instance')
\r
90 execution.setVariable(prefix+'serviceInstanceId', utils.getNodeText1(createVolumeIncoming, "service-instance-id"))
\r
92 // Generate volume group id
\r
93 String volumeGroupId = UUID.randomUUID()
\r
94 utils.log("DEBUG", "Generated volume group id: " + volumeGroupId, isDebugEnabled)
\r
96 def testGroupId = execution.getVariable('test-volume-group-id')
\r
97 if (testGroupId != null && testGroupId.trim() != '') {
\r
98 volumeGroupId = testGroupId
\r
101 execution.setVariable(prefix+'volumeGroupId', volumeGroupId)
\r
106 public void sendSyncResponse (Execution execution, isDebugEnabled) {
\r
107 def volumeGroupId = execution.getVariable(prefix+'volumeGroupId')
\r
108 def requestId = execution.getVariable("mso-request-id")
\r
109 def serviceInstanceId = execution.getVariable("serviceInstanceId")
\r
111 String syncResponse = """{"requestReferences":{"instanceId":"${volumeGroupId}","requestId":"${requestId}"}}""".trim()
\r
113 utils.log("DEBUG", "Sync Response: " + "\n" + syncResponse, isDebugEnabled)
\r
114 sendWorkflowResponse(execution, 200, syncResponse)
\r
116 execution.setVariable(prefix+'syncResponseSent', true)
\r
120 public void sendSyncError (Execution execution, isDebugEnabled) {
\r
121 WorkflowException we = execution.getVariable('WorkflowException')
\r
122 def errorCode = we?.getErrorCode()
\r
123 def errorMessage = we?.getErrorMessage()
\r
124 //default to 400 since only invalid request will trigger this method
\r
125 sendWorkflowResponse(execution, 400, errorMessage)
\r
130 * Create a WorkflowException
\r
132 * @param isDebugEnabled
\r
134 public void buildWorkflowException(Execution execution, int errorCode, errorMessage, isDebugEnabled) {
\r
135 utils.log("DEBUG", errorMessage, isDebugEnabled)
\r
136 (new ExceptionUtil()).buildWorkflowException(execution, 2500, errorMessage)
\r
140 public void prepareDbInfraSuccessRequest(Execution execution, isDebugEnabled) {
\r
141 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
142 def dbVnfOutputs = execution.getVariable(prefix+'volumeOutputs')
\r
143 def requestId = execution.getVariable('mso-request-id')
\r
144 def statusMessage = "VolumeGroup successfully created."
\r
145 def requestStatus = "COMPLETED"
\r
146 def progress = "100"
\r
149 String basicAuthValueDB = execution.getVariable("URN_mso_adapters_db_auth")
\r
150 utils.log("DEBUG", " Obtained BasicAuth userid password for Catalog DB adapter: " + basicAuthValueDB, isDebugEnabled)
\r
152 def encodedString = utils.getBasicAuth(basicAuthValueDB, execution.getVariable("URN_mso_msoKey"))
\r
153 execution.setVariable("BasicAuthHeaderValueDB",encodedString)
\r
154 } catch (IOException ex) {
\r
155 String dataErrorMessage = " Unable to encode Catalog DB user/password string - " + ex.getMessage()
\r
156 utils.log("DEBUG", dataErrorMessage, isDebugEnabled)
\r
157 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, dataErrorMessage)
\r
161 from: $gVolumeGroup/aai:volume-group-id/text()
\r
162 to: vnfreq:volume-outputs/vnfreq:volume-group-id
\r
164 // for now assume, generated volumeGroupId is accepted
\r
165 def volumeGroupId = execution.getVariable(prefix+'volumeGroupId')
\r
168 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
\r
171 <ns:updateInfraRequest xmlns:ns="http://org.openecomp.mso/requestsdb">
\r
172 <requestId>${requestId}</requestId>
\r
173 <lastModifiedBy>BPMN</lastModifiedBy>
\r
174 <statusMessage>${statusMessage}</statusMessage>
\r
175 <responseBody></responseBody>
\r
176 <requestStatus>${requestStatus}</requestStatus>
\r
177 <progress>${progress}</progress>
\r
178 <vnfOutputs>${dbVnfOutputs}</vnfOutputs>
\r
179 <volumeGroupId>${volumeGroupId}</volumeGroupId>
\r
180 </ns:updateInfraRequest>
\r
182 </soapenv:Envelope>"""
\r
184 String buildDeleteDBRequestAsString = utils.formatXml(dbRequest)
\r
185 execution.setVariable(prefix+"createDBRequest", buildDeleteDBRequestAsString)
\r
187 utils.logAudit(buildDeleteDBRequestAsString)
\r
194 public void postProcessResponse (Execution execution, isDebugEnabled) {
\r
196 def dbReturnCode = execution.getVariable(prefix+'dbReturnCode')
\r
197 def createDBResponse = execution.getVariable(prefix+'createDBResponse')
\r
199 utils.logAudit('DB return code: ' + dbReturnCode)
\r
200 utils.logAudit('DB response: ' + createDBResponse)
\r
202 def requestId = execution.getVariable("mso-request-id")
\r
203 def source = execution.getVariable(prefix+'source')
\r
205 String msoCompletionRequest =
\r
206 """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
207 xmlns:ns="http://org.openecomp/mso/request/types/v1">
\r
208 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
209 <request-id>${requestId}</request-id>
\r
210 <action>CREATE</action>
\r
211 <source>${source}</source>
\r
213 <aetgt:status-message>Volume Group has been created successfully.</aetgt:status-message>
\r
214 <aetgt:mso-bpel-name>BPMN VF Module Volume action: CREATE</aetgt:mso-bpel-name>
\r
215 </aetgt:MsoCompletionRequest>"""
\r
217 String xmlMsoCompletionRequest = utils.formatXml(msoCompletionRequest)
\r
219 utils.logAudit(createDBResponse)
\r
220 utils.logAudit(xmlMsoCompletionRequest)
\r
221 execution.setVariable(prefix+'Success', true)
\r
222 execution.setVariable(prefix+'CompleteMsoProcessRequest', xmlMsoCompletionRequest)
\r
223 utils.log("DEBUG", " Overall SUCCESS Response going to CompleteMsoProcess - " + "\n" + xmlMsoCompletionRequest, isDebugEnabled)
\r
227 public void prepareFalloutHandlerRequest(Execution execution, isDebugEnabled) {
\r
229 WorkflowException we = execution.getVariable('WorkflowException')
\r
230 def errorCode = we?.getErrorCode()
\r
231 def errorMessage = we?.getErrorMessage()
\r
233 def requestId = execution.getVariable("mso-request-id")
\r
234 def source = execution.getVariable(prefix+'source')
\r
236 String falloutHandlerRequest =
\r
237 """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
\r
238 xmlns:ns="http://org.openecomp/mso/request/types/v1"
\r
239 xmlns:wfsch="http://org.openecomp/mso/workflow/schema/v1">
\r
240 <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
\r
241 <request-id>${requestId}</request-id>
\r
242 <action>CREATE</action>
\r
243 <source>${source}</source>
\r
245 <aetgt:WorkflowException>
\r
246 <aetgt:ErrorMessage>${errorMessage}</aetgt:ErrorMessage>
\r
247 <aetgt:ErrorCode>${errorCode}</aetgt:ErrorCode>
\r
248 </aetgt:WorkflowException>
\r
250 </aetgt:FalloutHandlerRequest>"""
\r
253 String xmlHandlerRequest = utils.formatXml(falloutHandlerRequest)
\r
254 utils.logAudit(xmlHandlerRequest)
\r
256 execution.setVariable(prefix+'FalloutHandlerRequest', xmlHandlerRequest)
\r
257 utils.log("ERROR", "Overall Error Response going to FalloutHandler: " + "\n" + xmlHandlerRequest, isDebugEnabled)
\r
262 * Query AAI service instance
\r
264 * @param isDebugEnabled
\r
266 public void callRESTQueryAAIServiceInstance(Execution execution, isDebugEnabled) {
\r
268 def request = execution.getVariable(prefix+"Request")
\r
269 def serviceInstanceId = utils.getNodeText1(request, "service-instance-id")
\r
271 AaiUtil aaiUtil = new AaiUtil(this)
\r
272 String aaiEndpoint = aaiUtil.getSearchNodesQueryEndpoint(execution)
\r
274 def String queryAAIRequest = aaiEndpoint + "?search-node-type=service-instance&filter=service-instance-id:EQUALS:" + serviceInstanceId
\r
275 utils.logAudit("AAI query service instance request: " + queryAAIRequest)
\r
277 APIResponse response = aaiUtil.executeAAIGetCall(execution, queryAAIRequest)
\r
279 String returnCode = response.getStatusCode()
\r
280 String aaiResponseAsString = response.getResponseBodyAsString()
\r
281 aaiResponseAsString = StringEscapeUtils.unescapeXml(aaiResponseAsString)
\r
283 utils.logAudit("AAI query service instance return code: " + returnCode)
\r
284 utils.logAudit("AAI query service instance response: " + aaiResponseAsString)
\r
286 utils.log("DEBUG", "AAI query service instance return code: " + returnCode, isDebugEnabled)
\r
287 utils.log("DEBUG", "AAI query service instance response: " + aaiResponseAsString, isDebugEnabled)
\r
289 ExceptionUtil exceptionUtil = new ExceptionUtil()
\r
291 if (returnCode=='200') {
\r
292 utils.log("DEBUG", 'Service instance ' + serviceInstanceId + ' found in AAI.', isDebugEnabled)
\r
294 if (returnCode=='404') {
\r
295 def message = 'Service instance ' + serviceInstanceId + ' was not found in AAI. Return code: 404.'
\r
296 utils.log("DEBUG", message, isDebugEnabled)
\r
297 exceptionUtil.buildAndThrowWorkflowException(execution, 2500, message)
\r
299 WorkflowException aWorkflowException = exceptionUtil.MapAAIExceptionToWorkflowException(aaiResponseAsString, execution)
\r
300 throw new BpmnError("MSOWorkflowException")
\r