validation fix for OS attach volumes & detach vols 11/29211/4
authorkusuma kumari M <km583p@att.com>
Thu, 25 Jan 2018 19:34:00 +0000 (14:34 -0500)
committerPatrick Brady <pb071s@att.com>
Thu, 25 Jan 2018 22:38:17 +0000 (22:38 +0000)
Issue-ID: APPC-448
Change-Id: Icdf6c63a09e82b494c0de25c9d4ed2cb0d2312d1
Signed-off-by: kusuma kumari M <km583p@att.com>
appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/AttachVolumeServer.java
appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/DettachVolumeServer.java

index b62062d..0a35373 100644 (file)
@@ -63,7 +63,7 @@ public class AttachVolumeServer extends ProviderServerOperation {
         String device = params.get(ProviderAdapter.DEVICE);
         VMURL vm = VMURL.parseURL(vm_url);
         Context context = null;
-        String tenantName = "Unknown";//to be used also in case of exception
+        String tenantName = "Unknown";// to be used also in case of exception
         try {
             if (validateVM(rc, appName, vm_url, vm))
                 return null;
@@ -72,7 +72,7 @@ public class AttachVolumeServer extends ProviderServerOperation {
             String vol_id = (volumeid == null) ? null : volumeid.toString();
             context = getContext(rc, vm_url, identStr);
             if (context != null) {
-                tenantName = context.getTenantName();//this varaible also is used in case of exception
+                tenantName = context.getTenantName();// this varaible also is used in case of exception
                 rc.reset();
                 server = lookupServer(rc, context, vm.getServerId());
                 logger.debug(Msg.SERVER_FOUND, vm_url, context.getTenantName(), server.getStatus().toString());
@@ -90,7 +90,9 @@ public class AttachVolumeServer extends ProviderServerOperation {
                             logger.info("Ready to Attach Volume to the server:" + Volume.Status.ATTACHING);
                             service.attachVolume(server, v, device);
                             logger.info("Volume status after performing attach:" + v.getStatus());
-                            doSuccess(rc);
+                            if (validateAttach(vs, vol_id)) {
+                                doSuccess(rc);
+                            }
                         } else {
                             String msg = "Volume with volume id " + vol_id + " cannot be attached as it already exists";
                             logger.info("Alreday volumes exists:");
@@ -126,4 +128,20 @@ public class AttachVolumeServer extends ProviderServerOperation {
         logOperation(Msg.ATTACHINGVOLUME_SERVER, params, context);
         return attachVolume(params, context);
     }
+
+    protected boolean validateAttach(VolumeService vs, String volId) throws RequestFailedException, ZoneException {
+        boolean flag = false;
+        List<Volume> volList = vs.getVolumes();
+        for (Volume v : volList) {
+            if (v.getId().equals(volId)) {
+                logger.info("Volume with " + volId + "attached successsfully");
+                flag = true;
+            } else {
+                logger.info("failed to attach volume with id" + volId);
+                flag = false;
+            }
+        }
+        return flag;
+    }
+
 }
index 091edf2..28b15b5 100644 (file)
@@ -25,9 +25,8 @@ package org.onap.appc.adapter.iaas.provider.operation.impl;
 
 import static org.onap.appc.adapter.iaas.provider.operation.common.enums.Operation.ATTACHVOLUME_SERVICE;
 import static org.onap.appc.adapter.utils.Constants.ADAPTER_NAME;
-import java.util.Map;
 import java.util.List;
-import com.att.cdp.zones.ComputeService;
+import java.util.Map;
 import org.glassfish.grizzly.http.util.HttpStatus;
 import org.onap.appc.Constants;
 import org.onap.appc.adapter.iaas.ProviderAdapter;
@@ -69,10 +68,9 @@ public class DettachVolumeServer extends ProviderServerOperation {
         String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
         String vm_url = params.get(ProviderAdapter.PROPERTY_INSTANCE_URL);
         String volumeid = params.get(ProviderAdapter.VOLUME_ID);
-        String device = params.get(ProviderAdapter.DEVICE);
         VMURL vm = VMURL.parseURL(vm_url);
         Context context = null;
-        String tenantName = "Unknown";//to be used also in case of exception
+        String tenantName = "Unknown";// to be used also in case of exception
         try {
             if (validateVM(rc, appName, vm_url, vm))
                 return null;
@@ -81,7 +79,7 @@ public class DettachVolumeServer extends ProviderServerOperation {
             String vol_id = (volumeid == null) ? null : volumeid.toString();
             context = getContext(rc, vm_url, identStr);
             if (context != null) {
-                tenantName = context.getTenantName();//this varaible also is used in case of exception
+                tenantName = context.getTenantName();// this varaible also is used in case of exception
                 rc.reset();
                 server = lookupServer(rc, context, vm.getServerId());
                 logger.debug(Msg.SERVER_FOUND, vm_url, context.getTenantName(), server.getStatus().toString());
@@ -99,7 +97,9 @@ public class DettachVolumeServer extends ProviderServerOperation {
                             logger.info("Ready to Detach Volume from the server:" + Volume.Status.DETACHING);
                             service.detachVolume(server, v);
                             logger.info("Volume status after performing detach:" + v.getStatus());
-                            doSuccess(rc);
+                            if (validateDetach(vs, vol_id)) {
+                                doSuccess(rc);
+                            }
                         } else {
                             String msg = "Volume with volume id " + vol_id + " cannot be detached as it doesnot exists";
                             doFailure(rc, HttpStatus.NOT_IMPLEMENTED_501, msg);
@@ -127,4 +127,18 @@ public class DettachVolumeServer extends ProviderServerOperation {
         return server;
     }
 
+    protected boolean validateDetach(VolumeService vs, String volId) throws RequestFailedException, ZoneException {
+        boolean flag = false;
+        List<Volume> volList = vs.getVolumes();
+        for (Volume v : volList) {
+            if (!v.getId().equals(volId)) {
+                logger.info("Volume with " + volId + "detached successsfully");
+                flag = true;
+            } else {
+                logger.info("failed to detach volume with id" + volId);
+                flag = false;
+            }
+        }
+        return flag;
+    }
 }