* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/
package org.onap.so.bpmn.common.scripts
+import javax.ws.rs.core.UriBuilder
+
import org.camunda.bpm.engine.delegate.DelegateExecution
-import org.onap.so.bpmn.core.UrnPropertiesReader
-import org.onap.so.rest.APIResponse
+import org.onap.aai.domain.yang.VolumeGroup
+import org.onap.so.client.aai.AAIObjectType
+import org.onap.so.client.aai.entities.uri.AAIResourceUri
+import org.onap.so.client.aai.entities.uri.AAIUriFactory
+import org.onap.so.constants.Defaults
import org.onap.so.logger.MessageEnum
import org.onap.so.logger.MsoLogger
public class ConfirmVolumeGroupName extends AbstractServiceTaskProcessor{
private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, ConfirmVolumeGroupName.class);
-
+
def Prefix="CVGN_"
ExceptionUtil exceptionUtil = new ExceptionUtil()
execution.setVariable("CVGN_volumeGroupName",null)
execution.setVariable("CVGN_aicCloudRegion", null)
execution.setVariable("CVGN_volumeGroupGetEndpoint",null)
-
+
// ConfirmVolumeGroupName workflow response variable placeholders
execution.setVariable("CVGN_volumeGroupNameMatches", false)
execution.setVariable("CVGN_queryVolumeGroupResponseCode",null)
def volumeGroupId = execution.getVariable("ConfirmVolumeGroupName_volumeGroupId")
def volumeGroupName= execution.getVariable("ConfirmVolumeGroupName_volumeGroupName")
def aicCloudRegion = execution.getVariable("ConfirmVolumeGroupName_aicCloudRegion")
-
+
initProcessVariables(execution)
execution.setVariable("CVGN_volumeGroupId", volumeGroupId)
execution.setVariable("CVGN_volumeGroupName", volumeGroupName)
execution.setVariable("CVGN_aicCloudRegion", aicCloudRegion)
-
- AaiUtil aaiUriUtil = new AaiUtil(this)
- def aai_uri = aaiUriUtil.getCloudInfrastructureCloudRegionUri(execution)
- msoLogger.debug('AAI URI is: ' + aai_uri)
- msoLogger.debug("AAI URI: " + aai_uri)
- execution.setVariable("CVGN_volumeGroupGetEndpoint","${aai_uri}/${aicCloudRegion}/volume-groups/volume-group/" +
- volumeGroupId)
+
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VOLUME_GROUP, Defaults.CLOUD_OWNER.toString(), aicCloudRegion, volumeGroupId)
+ execution.setVariable("CVGN_volumeGroupGetEndpoint", uri)
}
-
+
// send a GET request to AA&I to retrieve the Volume information based on volume-group-id
// expect a 200 response with the information in the response body or a 404 if the volume group id does not exist
public void queryAAIForVolumeGroupId(DelegateExecution execution) {
- def endPoint = UrnPropertiesReader.getVariable("aai.endpoint", execution) + execution.getVariable("CVGN_volumeGroupGetEndpoint")
-
+ AAIResourceUri resourceUri = execution.getVariable("CVGN_volumeGroupGetEndpoint")
+
try {
- msoLogger.debug("invoking GET call to AAI endpoint :"+System.lineSeparator()+endPoint)
- msoLogger.debug("queryAAIForVolumeGroupId() endpoint-" + endPoint)
- msoLogger.debug("ConfirmVolumeGroup sending GET call to AAI Endpoint: " + endPoint)
-
- AaiUtil aaiUtil = new AaiUtil(this)
- APIResponse response = aaiUtil.executeAAIGetCall(execution, endPoint)
- def responseData = response.getResponseBodyAsString()
- def responseStatusCode = response.getStatusCode()
- execution.setVariable("CVGN_queryVolumeGroupResponseCode", responseStatusCode)
- execution.setVariable("CVGN_queryVolumeGroupResponse", responseData)
-
- msoLogger.debug("Response code:" + responseStatusCode)
- msoLogger.debug("Response:" + responseData)
- msoLogger.debug("Response code:" + responseStatusCode)
- msoLogger.debug("Response:" + System.lineSeparator()+responseData)
+ Optional<VolumeGroup> volumeGroupOp = getAAIClient().get(VolumeGroup.class, resourceUri)
+ if(volumeGroupOp.isPresent()){
+ execution.setVariable("CVGN_queryVolumeGroupResponseCode", 200)
+ execution.setVariable("CVGN_queryVolumeGroupResponse", volumeGroupOp.get())
+ }else{
+ execution.setVariable("CVGN_queryVolumeGroupResponseCode", 404)
+ execution.setVariable("CVGN_queryVolumeGroupResponse", "Volume Group not Found!")
+ }
} catch (Exception ex) {
- // ex.printStackTrace()
msoLogger.debug("Exception occurred while executing AAI GET:" + ex.getMessage())
execution.setVariable("CVGN_queryVolumeGroupResponseCode", 500)
execution.setVariable("CVGN_queryVolumeGroupResponse", "AAI GET Failed:" + ex.getMessage())
public void checkAAIQueryResult(DelegateExecution execution) {
def result = execution.getVariable("CVGN_queryVolumeGroupResponse")
- if (execution.getVariable("CVGN_queryVolumeGroupResponseCode") == 404) {
+ def actualVolumeGroupName = ""
+ if (execution.getVariable("CVGN_queryVolumeGroupResponseCode") == 404) {
msoLogger.debug('volumeGroupId does not exist in AAI')
}
else if (execution.getVariable("CVGN_queryVolumeGroupResponseCode") == 200) {
+ VolumeGroup volumeGroup = execution.getVariable("CVGN_queryVolumeGroupResponse")
+ if(volumeGroup.getVolumeGroupName()!=null){
+ actualVolumeGroupName = volumeGroup.getVolumeGroupName()
+ }
msoLogger.debug("volumeGroupId exists in AAI")
}
- def xml = execution.getVariable("CVGN_queryVolumeGroupResponse")
- def actualVolumeGroupName = ""
- if (utils.nodeExists(xml, "volume-group-name")) {
- actualVolumeGroupName = utils.getNodeText(xml, "volume-group-name")
- }
execution.setVariable("CVGN_volumeGroupNameMatches", false)
def volumeGroupName = execution.getVariable("CVGN_volumeGroupName")
exceptionUtil.buildAndThrowWorkflowException(execution, 1002, errorNotAssociated)
}
-}
\ No newline at end of file
+ // sends a successful WorkflowResponse
+ public void reportSuccess(DelegateExecution execution) {
+ msoLogger.debug("Sending 200 back to the caller")
+ def responseXML = ""
+ execution.setVariable("WorkflowResponse", responseXML)
+ }
+}