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
40 import org.onap.so.client.aai.AAIObjectType
41 import org.onap.so.client.aai.entities.uri.AAIResourceUri
42 import org.onap.so.client.aai.entities.uri.AAIUriFactory
43 import org.onap.so.constants.Defaults
46 * Vnf Module Subflow for confirming the volume group belongs
50 * @param volumeGroupId
53 class ConfirmVolumeGroupTenant extends AbstractServiceTaskProcessor{
54 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, ConfirmVolumeGroupTenant.class);
57 ExceptionUtil exceptionUtil = new ExceptionUtil()
59 public void preProcessRequest(DelegateExecution execution){
60 execution.setVariable("prefix", Prefix)
61 msoLogger.trace("STARTED Confirm Volume Group Tenant Subflow ")
62 String processKey = getProcessKey(execution);
64 msoLogger.trace("Started QueryAAIForVolumeGroup Process ")
66 String volumeGroupId = execution.getVariable("volumeGroupId")
67 String incomingGroupName = execution.getVariable("volumeGroupName")
68 String incomingTenantId = execution.getVariable("tenantId")
69 def aicCloudRegion = execution.getVariable("aicCloudRegion")
71 AaiUtil aaiUriUtil = new AaiUtil(this)
72 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VOLUME_GROUP, Defaults.CLOUD_OWNER.toString(), aicCloudRegion, volumeGroupId)
73 String path = aaiUriUtil.createAaiUri(uri)
75 APIResponse queryAAIForVolumeGroupResponse = aaiUriUtil.executeAAIGetCall(execution, path)
77 def responseCode = queryAAIForVolumeGroupResponse.getStatusCode()
78 execution.setVariable("queryVolumeGroupResponseCode", responseCode)
79 String response = queryAAIForVolumeGroupResponse.getResponseBodyAsString()
81 msoLogger.debug("ConfirmVolumeGroup Response: " + response)
82 msoLogger.debug("ConfirmVolumeGroup Response Code: " + responseCode)
84 if(responseCode == 200 && response != null){
85 execution.setVariable("queryAAIVolumeGroupResponse", response)
86 msoLogger.debug("QueryAAIForVolumeGroup Received a Good REST Response is: \n" + response)
88 String volumeGroupTenantId = ""
89 InputSource source = new InputSource(new StringReader(response));
90 DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
91 docFactory.setNamespaceAware(true)
92 DocumentBuilder docBuilder = docFactory.newDocumentBuilder()
93 Document createVCERequestXml = docBuilder.parse(source)
94 NodeList nodeList = createVCERequestXml.getElementsByTagNameNS("*", "relationship")
95 for (int x = 0; x < nodeList.getLength(); x++) {
96 Node node = nodeList.item(x)
97 if (node.getNodeType() == Node.ELEMENT_NODE) {
98 Element eElement = (Element) node
99 String e = eElement.getElementsByTagNameNS("*", "related-to").item(0).getTextContent()
100 if(e.equals("tenant")){
101 NodeList relationDataList = eElement.getElementsByTagNameNS("*", "relationship-data")
102 for (int d = 0; d < relationDataList.getLength(); d++) {
103 Node dataNode = relationDataList.item(d)
104 if (dataNode.getNodeType() == Node.ELEMENT_NODE) {
105 Element dElement = (Element) dataNode
106 String key = dElement.getElementsByTagNameNS("*", "relationship-key").item(0).getTextContent()
107 if(key.equals("tenant.tenant-id")){
108 volumeGroupTenantId = dElement.getElementsByTagNameNS("*", "relationship-value").item(0).getTextContent()
116 //Determine if Tenant Ids match
117 if(incomingTenantId.equals(volumeGroupTenantId)){
118 msoLogger.debug("Tenant Ids Match")
119 execution.setVariable("tenantIdsMatch", true)
121 msoLogger.debug("Tenant Ids DO NOT Match")
122 execution.setVariable("tenantIdsMatch", false)
125 //Determine if Volume Group Names match
126 String volumeGroupName = utils.getNodeText(response, "volume-group-name")
127 if(incomingGroupName == null || incomingGroupName.length() < 1){
128 msoLogger.debug("Incoming Volume Group Name is NOT Provided.")
129 execution.setVariable("groupNamesMatch", true)
131 msoLogger.debug("Incoming Volume Group Name is: " + incomingGroupName)
132 if(volumeGroupName.equals(incomingGroupName)){
133 msoLogger.debug("Volume Group Names Match.")
134 execution.setVariable("groupNamesMatch", true)
136 msoLogger.debug("Volume Group Names DO NOT Match.")
137 execution.setVariable("groupNamesMatch", false)
141 msoLogger.debug("QueryAAIForVolumeGroup Bad REST Response!")
142 exceptionUtil.buildAndThrowWorkflowException(execution, 1, "Error Searching AAI for Volume Group. Received a Bad Response.")
148 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing queryAAIForVolumeGroup.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
149 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, "Internal Error - Occured in preProcessRequest.")
151 msoLogger.trace("COMPLETED queryAAIForVolumeGroup Process ")
154 public void assignVolumeHeatId(DelegateExecution execution){
155 execution.setVariable("prefix", Prefix)
157 msoLogger.trace("Started assignVolumeHeatId Process ")
159 String response = execution.getVariable("queryAAIVolumeGroupResponse")
160 String heatStackId = utils.getNodeText(response, "heat-stack-id")
161 execution.setVariable("volumeHeatStackId", heatStackId)
162 execution.setVariable("ConfirmVolumeGroupTenantResponse", heatStackId)
163 // TODO: Should deprecate use of processKey+Response variable for the response. Will use "WorkflowResponse" instead
164 execution.setVariable("WorkflowResponse", heatStackId)
165 msoLogger.debug("Volume Heat Stack Id is: " + heatStackId)
168 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing assignVolumeHeatId.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
169 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, "Internal Error - Occured in assignVolumeHeatId.")
171 msoLogger.trace("COMPLETED assignVolumeHeatId Process ")
172 msoLogger.trace("COMPLETED Confirm Volume Group Tenant Subflow ")
175 public void assignWorkflowException(DelegateExecution execution, String message){
176 execution.setVariable("prefix", Prefix)
177 String processKey = getProcessKey(execution);
178 msoLogger.trace("STARTED Assign Workflow Exception ")
180 String volumeGroupId = execution.getVariable("volumeGroupId")
182 String errorMessage = "Volume Group " + volumeGroupId + " " + message
184 exceptionUtil.buildWorkflowException(execution, errorCode, errorMessage)
186 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, "Exception Occured Processing assignWorkflowException.", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, e);
188 msoLogger.trace("COMPLETED Assign Workflow Exception =")