summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkusuma kumari M <km583p@att.com>2018-01-25 14:34:00 -0500
committerPatrick Brady <pb071s@att.com>2018-01-25 22:38:17 +0000
commite25f6e20ef365b81cb82cee2e91f6d6e0df2a364 (patch)
treece6235d8e19c2e4d4a8049345ae49a899af8937a
parent629fdcadfa911e29856f9e14852604ea6307cca7 (diff)
validation fix for OS attach volumes & detach vols
Issue-ID: APPC-448 Change-Id: Icdf6c63a09e82b494c0de25c9d4ed2cb0d2312d1 Signed-off-by: kusuma kumari M <km583p@att.com>
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/AttachVolumeServer.java24
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/DettachVolumeServer.java26
2 files changed, 41 insertions, 9 deletions
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/AttachVolumeServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/AttachVolumeServer.java
index b62062d08..0a3537326 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/AttachVolumeServer.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/AttachVolumeServer.java
@@ -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;
+ }
+
}
diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/DettachVolumeServer.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/DettachVolumeServer.java
index 091edf2bc..28b15b561 100644
--- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/DettachVolumeServer.java
+++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/DettachVolumeServer.java
@@ -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;
+ }
}