diff options
author | Jakub Dudycz <jakub.dudycz@nokia.com> | 2018-01-25 17:03:54 +0100 |
---|---|---|
committer | Patrick Brady <pb071s@att.com> | 2018-01-25 18:25:07 -0500 |
commit | 9c2071e0b5281635753d137ba50eb1e05df2f900 (patch) | |
tree | a99f886bd10690ee677734c3b856e382529c81bb | |
parent | 3b69b59e624ffdedf72c92fc84fcb1cd915db58a (diff) |
DetachVolumeServer fixes
Change-Id: I8f57e962583914467a748648303f90319fcfa58d
Issue-ID: APPC-524
Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com>
-rw-r--r-- | appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/DettachVolumeServer.java | 76 |
1 files changed, 40 insertions, 36 deletions
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 28b15b561..6f0ab87be 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,6 +25,17 @@ 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; +import com.att.cdp.zones.VolumeService; +import com.att.cdp.zones.model.ModelObject; +import com.att.cdp.zones.model.Server; +import com.att.cdp.zones.model.Volume; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.att.eelf.i18n.EELFResourceManager; import java.util.List; import java.util.Map; import org.glassfish.grizzly.http.util.HttpStatus; @@ -39,23 +50,14 @@ import org.onap.appc.adapter.iaas.provider.operation.impl.base.ProviderServerOpe import org.onap.appc.exceptions.APPCException; import org.onap.appc.i18n.Msg; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import com.att.cdp.exceptions.ZoneException; -import com.att.cdp.zones.ComputeService; -import com.att.cdp.zones.Context; -import com.att.cdp.zones.VolumeService; -import com.att.cdp.zones.model.ModelObject; -import com.att.cdp.zones.model.Server; -import com.att.cdp.zones.model.Volume; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.att.eelf.i18n.EELFResourceManager; 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); @@ -66,42 +68,43 @@ public class DettachVolumeServer extends ProviderServerOperation { RequestContext rc = new RequestContext(ctx); rc.isAlive(); String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME); - String vm_url = params.get(ProviderAdapter.PROPERTY_INSTANCE_URL); - String volumeid = params.get(ProviderAdapter.VOLUME_ID); - VMURL vm = VMURL.parseURL(vm_url); - Context context = null; - String tenantName = "Unknown";// to be used also in case of exception + 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 try { - if (validateVM(rc, appName, vm_url, vm)) + if (validateVM(rc, appName, vmUrl, vm)) { return null; + } IdentityURL ident = IdentityURL.parseURL(params.get(ProviderAdapter.PROPERTY_IDENTITY_URL)); String identStr = (ident == null) ? null : ident.toString(); - String vol_id = (volumeid == null) ? null : volumeid.toString(); - context = getContext(rc, vm_url, identStr); + context = getContext(rc, vmUrl, identStr); if (context != null) { - tenantName = context.getTenantName();// this varaible also is used in case of exception + tenantName = context.getTenantName();//this variable 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()); + logger.debug(Msg.SERVER_FOUND, vmUrl, context.getTenantName(), server.getStatus().toString()); Context contx = server.getContext(); ComputeService service = contx.getComputeService(); VolumeService vs = contx.getVolumeService(); - logger.info("collecting volume status for volume -id:" + vol_id); + logger.info("collecting volume status for volume -id: " + volumeId); List<Volume> volList = vs.getVolumes(); - logger.info("Size of volume list :" + volList.size()); - if (volList != null && !volList.isEmpty()) { + 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(vol_id)) { - v.setId(vol_id); - logger.info("Ready to Detach Volume from the server:" + Volume.Status.DETACHING); + 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, vol_id)) { + logger.info("Volume status after performing detach: " + v.getStatus()); + if (validateDetach(vs, volumeId)) { doSuccess(rc); } } else { - String msg = "Volume with volume id " + vol_id + " cannot be detached as it doesnot exists"; + String msg = + "Volume with volume id " + volumeId + " cannot be detached as it doesn't exists"; doFailure(rc, HttpStatus.NOT_IMPLEMENTED_501, msg); } } @@ -113,15 +116,16 @@ public class DettachVolumeServer extends ProviderServerOperation { ctx.setAttribute("VOLUME_STATUS", "CONTEXT_NOT_FOUND"); } } catch (ZoneException e) { - String msg = EELFResourceManager.format(Msg.SERVER_NOT_FOUND, e, vm_url); + String msg = EELFResourceManager.format(Msg.SERVER_NOT_FOUND, e, vmUrl); logger.error(msg); doFailure(rc, HttpStatus.NOT_FOUND_404, msg); } catch (RequestFailedException e) { + logger.error("An error occurred when processing the request", e); doFailure(rc, e.getStatus(), e.getMessage()); - } catch (Exception ex) { - String msg = EELFResourceManager.format(Msg.SERVER_OPERATION_EXCEPTION, ex, ex.getClass().getSimpleName(), - ATTACHVOLUME_SERVICE.toString(), vm_url, tenantName); - logger.error(msg, ex); + } catch (Exception e) { + String msg = EELFResourceManager.format(Msg.SERVER_OPERATION_EXCEPTION, e, e.getClass().getSimpleName(), + ATTACHVOLUME_SERVICE.toString(), vmUrl, tenantName); + logger.error(msg, e); doFailure(rc, HttpStatus.INTERNAL_SERVER_ERROR_500, msg); } return server; |