2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. 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=========================================================
21 package org.onap.so.bpmn.common.scripts
23 import org.onap.so.bpmn.core.UrnPropertiesReader
25 import javax.xml.parsers.DocumentBuilder
26 import javax.xml.parsers.DocumentBuilderFactory
28 import org.apache.commons.lang3.*
29 import org.camunda.bpm.engine.delegate.BpmnError
30 import org.camunda.bpm.engine.delegate.DelegateExecution
31 import org.onap.so.bpmn.core.WorkflowException
32 import org.onap.so.rest.APIResponse
33 import org.w3c.dom.Document
34 import org.w3c.dom.Element
35 import org.w3c.dom.Node
36 import org.w3c.dom.NodeList
37 import org.xml.sax.InputSource
38 import org.onap.so.logger.MessageEnum
39 import org.onap.so.logger.MsoLogger
42 * Vnf Module Subflow for confirming the volume group belongs
46 * @param volumeGroupId
49 class ConfirmVolumeGroupTenant extends AbstractServiceTaskProcessor{
50 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, ConfirmVolumeGroupTenant.class);
53 ExceptionUtil exceptionUtil = new ExceptionUtil()
55 public void preProcessRequest(DelegateExecution execution){
56 execution.setVariable("prefix", Prefix)
57 msoLogger.trace("STARTED Confirm Volume Group Tenant Subflow ")
58 String processKey = getProcessKey(execution);
60 msoLogger.trace("Started QueryAAIForVolumeGroup Process ")
62 String volumeGroupId = execution.getVariable("volumeGroupId")
63 String incomingGroupName = execution.getVariable("volumeGroupName")
64 String incomingTenantId = execution.getVariable("tenantId")
65 def aicCloudRegion = execution.getVariable("aicCloudRegion")
66 String aai = UrnPropertiesReader.getVariable("aai.endpoint", execution)
68 AaiUtil aaiUriUtil = new AaiUtil(this)
69 def aai_uri = aaiUriUtil.getCloudInfrastructureCloudRegionUri(execution)
70 msoLogger.debug('AAI URI is: ' + aai_uri)
72 String path = aai + "${aai_uri}/${aicCloudRegion}/volume-groups/volume-group/" + volumeGroupId
74 APIResponse queryAAIForVolumeGroupResponse = aaiUriUtil.executeAAIGetCall(execution, path)
76 def responseCode = queryAAIForVolumeGroupResponse.getStatusCode()
77 execution.setVariable("queryVolumeGroupResponseCode", responseCode)
78 String response = queryAAIForVolumeGroupResponse.getResponseBodyAsString()
80 msoLogger.debug("ConfirmVolumeGroup Response: " + response)
81 msoLogger.debug("ConfirmVolumeGroup Response Code: " + responseCode)
83 if(responseCode == 200 && response != null){
84 execution.setVariable("queryAAIVolumeGroupResponse", response)
85 msoLogger.debug("QueryAAIForVolumeGroup Received a Good REST Response is: \n" + response)
87 String volumeGroupTenantId = ""
88 InputSource source = new InputSource(new StringReader(response));
89 DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
90 docFactory.setNamespaceAware(true)
91 DocumentBuilder docBuilder = docFactory.newDocumentBuilder()
92 Document createVCERequestXml = docBuilder.parse(source)
93 NodeList nodeList = createVCERequestXml.getElementsByTagNameNS("*", "relationship")
94 for (int x = 0; x < nodeList.getLength(); x++) {
95 Node node = nodeList.item(x)
96 if (node.getNodeType() == Node.ELEMENT_NODE) {
97 Element eElement = (Element) node
98 String e = eElement.getElementsByTagNameNS("*", "related-to").item(0).getTextContent()
99 if(e.equals("tenant")){
100 NodeList relationDataList = eElement.getElementsByTagNameNS("*", "relationship-data")
101 for (int d = 0; d < relationDataList.getLength(); d++) {
102 Node dataNode = relationDataList.item(d)
103 if (dataNode.getNodeType() == Node.ELEMENT_NODE) {
104 Element dElement = (Element) dataNode
105 String key = dElement.getElementsByTagNameNS("*", "relationship-key").item(0).getTextContent()
106 if(key.equals("tenant.tenant-id")){
107 volumeGroupTenantId = dElement.getElementsByTagNameNS("*", "relationship-value").item(0).getTextContent()
115 //Determine if Tenant Ids match
116 if(incomingTenantId.equals(volumeGroupTenantId)){
117 msoLogger.debug("Tenant Ids Match")
118 execution.setVariable("tenantIdsMatch", true)
120 msoLogger.debug("Tenant Ids DO NOT Match")
121 execution.setVariable("tenantIdsMatch", false)
124 //Determine if Volume Group Names match
125 String volumeGroupName = utils.getNodeText(response, "volume-group-name")
126 if(incomingGroupName == null || incomingGroupName.length() < 1){
127 msoLogger.debug("Incoming Volume Group Name is NOT Provided.")
128 execution.setVariable("groupNamesMatch", true)
130 msoLogger.debug("Incoming Volume Group Name is: " + incomingGroupName)
131 if(volumeGroupName.equals(incomingGroupName)){
132 msoLogger.debug("Volume Group Names Match.")
133 execution.setVariable("groupNamesMatch", true)
135 msoLogger.debug("Volume Group Names DO NOT Match.")
136 execution.setVariable("groupNamesMatch", false)
140 msoLogger.debug("QueryAAIForVolumeGroup Bad REST Response!")
141 exceptionUtil.buildAndThrowWorkflowException(execution, 1, "Error Searching AAI for Volume Group. Received a Bad Response.")
147 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing queryAAIForVolumeGroup.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
148 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, "Internal Error - Occured in preProcessRequest.")
150 msoLogger.trace("COMPLETED queryAAIForVolumeGroup Process ")
153 public void assignVolumeHeatId(DelegateExecution execution){
154 execution.setVariable("prefix", Prefix)
156 msoLogger.trace("Started assignVolumeHeatId Process ")
158 String response = execution.getVariable("queryAAIVolumeGroupResponse")
159 String heatStackId = utils.getNodeText(response, "heat-stack-id")
160 execution.setVariable("volumeHeatStackId", heatStackId)
161 execution.setVariable("ConfirmVolumeGroupTenantResponse", heatStackId)
162 // TODO: Should deprecate use of processKey+Response variable for the response. Will use "WorkflowResponse" instead
163 execution.setVariable("WorkflowResponse", heatStackId)
164 msoLogger.debug("Volume Heat Stack Id is: " + heatStackId)
167 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing assignVolumeHeatId.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
168 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, "Internal Error - Occured in assignVolumeHeatId.")
170 msoLogger.trace("COMPLETED assignVolumeHeatId Process ")
171 msoLogger.trace("COMPLETED Confirm Volume Group Tenant Subflow ")
174 public void assignWorkflowException(DelegateExecution execution, String message){
175 execution.setVariable("prefix", Prefix)
176 String processKey = getProcessKey(execution);
177 msoLogger.trace("STARTED Assign Workflow Exception ")
179 String volumeGroupId = execution.getVariable("volumeGroupId")
181 String errorMessage = "Volume Group " + volumeGroupId + " " + message
183 exceptionUtil.buildWorkflowException(execution, errorCode, errorMessage)
185 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing assignWorkflowException.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
187 msoLogger.trace("COMPLETED Assign Workflow Exception =")