aboutsummaryrefslogtreecommitdiffstats
path: root/appc-adapters
diff options
context:
space:
mode:
authorPatrick Brady <pb071s@att.com>2018-02-23 12:35:46 -0500
committerRanda Maher <rx196w@att.com>2018-02-28 00:14:50 +0000
commite3bd404d65b45afd4fdbe5a6da1a73b8ad934e2a (patch)
treee270666d315e7ac16d03f9dfbd13570107f28ecf /appc-adapters
parentff286ea030490eef3d57df78eb5c92c1ea7b8ea6 (diff)
Code fix for attach and detach volumes
Cherry-picked to split up commit https://gerrit.onap.org/r/#/c/31149/ into individual jira tickets. open stack consumes cdp-pal openstack jars to connect to cinder, this fix retrives set of volumes from volumeservice provider and performs attach or detach through compute service. Change-Id: I59bce60d9f79ba9285f284fe1f56945e63d0bcba Signed-off-by: Patrick Brady <pb071s@att.com> Signed-off-by: kusuma kumari M <km583p@att.com> Issue-ID: APPC-448
Diffstat (limited to 'appc-adapters')
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/AttachVolumeServer.java70
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/DettachVolumeServer.java92
2 files changed, 84 insertions, 78 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 fe42076f3..e27b1594d 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP : APPC
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
* =============================================================================
@@ -25,7 +25,6 @@ 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 com.att.cdp.exceptions.ZoneException;
import com.att.cdp.zones.ComputeService;
import com.att.cdp.zones.Context;
@@ -74,48 +73,57 @@ public class AttachVolumeServer extends ProviderServerOperation {
String identStr = (ident == null) ? null : ident.toString();
context = getContext(requestContext, vmUrl, identStr);
if (context != null) {
- tenantName = context.getTenantName();// this variable also is used in case of exception
+ tenantName = context.getTenantName();// this variable also is
+ // used in case of
+ // exception
requestContext.reset();
server = lookupServer(requestContext, context, vm.getServerId());
logger.debug(Msg.SERVER_FOUND, vmUrl, context.getTenantName(), server.getStatus().toString());
Context contx = server.getContext();
ComputeService service = contx.getComputeService();
VolumeService volumeService = contx.getVolumeService();
- logger.info("Collecting volume status for volume id: " + volumeId);
+ logger.info("collecting volume status for volume -id:" + volumeId);
List<Volume> volumes = volumeService.getVolumes();
- logger.info("Size of volume list: " + volumes.size());
- for (Volume volume : volumes) {
- logger.info("Processing volume with id: " + volume.getId());
- if (!volume.getId().equals(volumeId)) {
+ Volume volume = new Volume();
+ logger.info("Size of volume list :" + volumes.size());
+ if (volumes != null && !volumes.isEmpty()) {
+ if (!(volumes.contains(volumeId))) {
volume.setId(volumeId);
- logger.info("Ready to Attach Volume to the server: " + Volume.Status.ATTACHING);
+ logger.info("Ready to Attach Volume to the server:");
service.attachVolume(server, volume, device);
- logger.info("Volume status after performing attach: " + volume.getStatus());
-
- validateAttach(volumeService, volumeId, requestContext);
+ logger.info("Volume status after performing attach:" + volume.getStatus());
+ if (validateAttach(volumeService, volumeId)) {
+ ctx.setAttribute("VOLUME_STATUS", "SUCCESS");
+ doSuccess(requestContext);
+ } else {
+ String msg = "Failed to attach Volume";
+ logger.info("Volume with " + volumeId + " unable to attach");
+ ctx.setAttribute("VOLUME_STATUS", "FAILURE");
+ doFailure(requestContext, HttpStatus.NOT_IMPLEMENTED_501, msg);
+ }
} else {
- String msg = "Volume with id: " + volumeId + " cannot be attached as it already exists";
- logger.info(msg);
+ String msg = "Volume with volume id " + volumeId + " cannot be attached as it already exists";
+ logger.info("Alreday volumes exists:");
+ ctx.setAttribute("VOLUME_STATUS", "FAILURE");
doFailure(requestContext, HttpStatus.NOT_IMPLEMENTED_501, msg);
}
}
context.close();
- doSuccess(requestContext);
- ctx.setAttribute("VOLUME_STATUS", "SUCCESS");
} else {
ctx.setAttribute("VOLUME_STATUS", "CONTEXT_NOT_FOUND");
}
} catch (ZoneException e) {
String msg = EELFResourceManager.format(Msg.SERVER_NOT_FOUND, e, vmUrl);
logger.error(msg);
+ ctx.setAttribute("VOLUME_STATUS", "FAILURE");
doFailure(requestContext, HttpStatus.NOT_FOUND_404, msg);
} catch (RequestFailedException e) {
- logger.error("An error occurred in attachVolume", e);
+ ctx.setAttribute("VOLUME_STATUS", "FAILURE");
doFailure(requestContext, e.getStatus(), e.getMessage());
} catch (Exception ex) {
String msg = EELFResourceManager.format(Msg.SERVER_OPERATION_EXCEPTION, ex, ex.getClass().getSimpleName(),
- ATTACHVOLUME_SERVICE.toString(), vmUrl, tenantName);
- logger.error(msg, ex);
+ ATTACHVOLUME_SERVICE.toString(), vmUrl, tenantName);
+ ctx.setAttribute("VOLUME_STATUS", "FAILURE");
doFailure(requestContext, HttpStatus.INTERNAL_SERVER_ERROR_500, msg);
}
return server;
@@ -123,24 +131,22 @@ public class AttachVolumeServer extends ProviderServerOperation {
@Override
protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context)
- throws APPCException {
+ throws APPCException {
setMDC(Operation.ATTACHVOLUME_SERVICE.toString(), "App-C IaaS Adapter:attachVolume", ADAPTER_NAME);
logOperation(Msg.ATTACHINGVOLUME_SERVER, params, context);
return attachVolume(params, context);
}
- private void validateAttach(VolumeService vs, String volId, RequestContext requestContext)
- throws RequestFailedException, ZoneException {
-
- List<Volume> volList = vs.getVolumes();
- for (Volume v : volList) {
- if (v.getId().equals(volId)) {
- logger.info("Volume with id: " + volId + " attached successfully");
- doSuccess(requestContext);
- } else {
- logger.info("Failed to attach volume with id: " + volId);
- }
+ protected boolean validateAttach(VolumeService volumeService, String volumeId)
+ throws RequestFailedException, ZoneException {
+ boolean flag = false;
+ List<Volume> volumeList = volumeService.getVolumes();
+ if (volumeList.contains(volumeId)) {
+ flag = true;
+ } else {
+ flag = false;
}
+ logger.info("validateAttach flag-->" + flag);
+ 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 6f0ab87be..d9b30cbb8 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP : APPC
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
* =============================================================================
@@ -23,9 +23,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.iaas.provider.operation.common.enums.Operation.DETACHVOLUME_SERVICE;
import static org.onap.appc.adapter.utils.Constants.ADAPTER_NAME;
-
import com.att.cdp.exceptions.ZoneException;
import com.att.cdp.zones.ComputeService;
import com.att.cdp.zones.Context;
@@ -52,12 +51,11 @@ import org.onap.appc.i18n.Msg;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
public class DettachVolumeServer extends ProviderServerOperation {
-
private final EELFLogger logger = EELFManager.getInstance().getLogger(DettachVolumeServer.class);
@Override
protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context)
- throws APPCException {
+ throws APPCException {
setMDC(Operation.DETACHVOLUME_SERVICE.toString(), "App-C IaaS Adapter:dettachVolume", ADAPTER_NAME);
logOperation(Msg.DETTACHINGVOLUME_SERVER, params, context);
return dettachVolume(params, context);
@@ -65,84 +63,86 @@ public class DettachVolumeServer extends ProviderServerOperation {
private Server dettachVolume(Map<String, String> params, SvcLogicContext ctx) {
Server server = null;
- RequestContext rc = new RequestContext(ctx);
- rc.isAlive();
+ RequestContext requestContext = new RequestContext(ctx);
+ requestContext.isAlive();
String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
String vmUrl = params.get(ProviderAdapter.PROPERTY_INSTANCE_URL);
String volumeId = params.get(ProviderAdapter.VOLUME_ID);
VMURL vm = VMURL.parseURL(vmUrl);
Context context;
- 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, vmUrl, vm)) {
+ if (validateVM(requestContext, appName, vmUrl, vm)) {
return null;
}
IdentityURL ident = IdentityURL.parseURL(params.get(ProviderAdapter.PROPERTY_IDENTITY_URL));
String identStr = (ident == null) ? null : ident.toString();
- context = getContext(rc, vmUrl, identStr);
+ context = getContext(requestContext, vmUrl, identStr);
if (context != null) {
- tenantName = context.getTenantName();//this variable also is used in case of exception
- rc.reset();
- server = lookupServer(rc, context, vm.getServerId());
+ tenantName = context.getTenantName();// this variable also is
+ // used in case of
+ // exception
+ requestContext.reset();
+ server = lookupServer(requestContext, context, vm.getServerId());
logger.debug(Msg.SERVER_FOUND, vmUrl, context.getTenantName(), server.getStatus().toString());
Context contx = server.getContext();
ComputeService service = contx.getComputeService();
- VolumeService vs = contx.getVolumeService();
+ VolumeService volumeService = contx.getVolumeService();
logger.info("collecting volume status for volume -id: " + volumeId);
- List<Volume> volList = vs.getVolumes();
- logger.info("Size of volume list: " + volList.size());
- if (!volList.isEmpty()) {
- for (Volume v : volList) {
- logger.info("list of volumesif exists: " + v.getId());
- if (v.getId().equals(volumeId)) {
- v.setId(volumeId);
- 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());
- if (validateDetach(vs, volumeId)) {
- doSuccess(rc);
- }
+ List<Volume> volumes = volumeService.getVolumes();
+ Volume volume = new Volume();
+ logger.info("Size of volume list: " + volumes.size());
+ if (volumes != null && !volumes.isEmpty()) {
+ if (volumes.contains(volumeId)) {
+ volume.setId(volumeId);
+ logger.info("Ready to Detach Volume from the server: " + Volume.Status.DETACHING);
+ service.detachVolume(server, volume);
+ logger.info("Volume status after performing detach: " + volume.getStatus());
+ if (validateDetach(volumeService, volumeId)) {
+ doSuccess(requestContext);
} else {
- String msg =
- "Volume with volume id " + volumeId + " cannot be detached as it doesn't exists";
- doFailure(rc, HttpStatus.NOT_IMPLEMENTED_501, msg);
+ String msg = "Volume with volume id " + volumeId + " cannot be detached ";
+ ctx.setAttribute("VOLUME_STATUS", "FAILURE");
+ doFailure(requestContext, HttpStatus.NOT_IMPLEMENTED_501, msg);
+ logger.info("unable to detach volume from the server");
}
+ } else {
+ String msg = "Volume with volume id " + volumeId + " cannot be detached as it doesn't exists";
+ ctx.setAttribute("VOLUME_STATUS", "FAILURE");
+ doFailure(requestContext, HttpStatus.NOT_IMPLEMENTED_501, msg);
}
+ logger.info("volumestatus:" + ctx.getAttribute("VOLUME_STATUS"));
}
context.close();
- doSuccess(rc);
- ctx.setAttribute("VOLUME_STATUS", "SUCCESS");
} else {
ctx.setAttribute("VOLUME_STATUS", "CONTEXT_NOT_FOUND");
}
} catch (ZoneException e) {
String msg = EELFResourceManager.format(Msg.SERVER_NOT_FOUND, e, vmUrl);
logger.error(msg);
- doFailure(rc, HttpStatus.NOT_FOUND_404, msg);
+ doFailure(requestContext, HttpStatus.NOT_FOUND_404, msg);
} catch (RequestFailedException e) {
logger.error("An error occurred when processing the request", e);
- doFailure(rc, e.getStatus(), e.getMessage());
+ doFailure(requestContext, e.getStatus(), e.getMessage());
} catch (Exception e) {
String msg = EELFResourceManager.format(Msg.SERVER_OPERATION_EXCEPTION, e, e.getClass().getSimpleName(),
- ATTACHVOLUME_SERVICE.toString(), vmUrl, tenantName);
+ DETACHVOLUME_SERVICE.toString(), vmUrl, tenantName);
logger.error(msg, e);
- doFailure(rc, HttpStatus.INTERNAL_SERVER_ERROR_500, msg);
+ doFailure(requestContext, HttpStatus.INTERNAL_SERVER_ERROR_500, msg);
}
return server;
}
- protected boolean validateDetach(VolumeService vs, String volId) throws RequestFailedException, ZoneException {
+ protected boolean validateDetach(VolumeService volumeService, 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;
- }
+ List<Volume> volumes = volumeService.getVolumes();
+ if (!volumes.contains(volId)) {
+ flag = true;
+ } else {
+ flag = false;
}
+ logger.info("validateDetach flag-->" + flag);
return flag;
}
}