aboutsummaryrefslogtreecommitdiffstats
path: root/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main
diff options
context:
space:
mode:
authorkusuma kumari M <km583p@att.com>2018-01-22 12:36:00 -0500
committerTakamune Cho <tc012c@att.com>2018-01-24 15:14:28 +0000
commit15926e89c324b3b4ca2ac3252af204548adc371b (patch)
tree61f624a84ea908141fa2ae7e6e2ad374f591a708 /appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main
parent361d34f4d15040b2262a7c9c1ac3082c29ad633e (diff)
code fix for OS attach volumes and dettach volumes
Issue-ID: APPC-448 Change-Id: I348108a8fb49a42c79039975e8470442a0f80dd2 Signed-off-by: kusuma kumari M <km583p@att.com>
Diffstat (limited to 'appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main')
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/AttachVolumeServer.java47
-rw-r--r--appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/main/java/org/onap/appc/adapter/iaas/provider/operation/impl/DettachVolumeServer.java46
2 files changed, 54 insertions, 39 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 3d3b9b767..b62062d08 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
@@ -22,8 +22,11 @@
* ============LICENSE_END=========================================================
*/
package org.onap.appc.adapter.iaas.provider.operation.impl;
+
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 org.glassfish.grizzly.http.util.HttpStatus;
import org.onap.appc.Constants;
import org.onap.appc.adapter.iaas.ProviderAdapter;
@@ -49,6 +52,7 @@ import static org.onap.appc.adapter.iaas.provider.operation.common.enums.Operati
public class AttachVolumeServer extends ProviderServerOperation {
private final EELFLogger logger = EELFManager.getInstance().getLogger(AttachVolumeServer.class);
+
private Server attachVolume(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
Server server = null;
RequestContext rc = new RequestContext(ctx);
@@ -66,32 +70,34 @@ public class AttachVolumeServer extends ProviderServerOperation {
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();
- String msg;
context = getContext(rc, vm_url, identStr);
if (context != null) {
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, tenantName, server.getStatus().toString());
- VolumeService vs = context.getVolumeService();
- vs.getVolumes(server);;
- Volume vol = new Volume();
- vol.setId(vol_id);
- logger.info("Server status: "+server.getStatus());
- Map volms = server.getVolumes();
- logger.info("list of attachments");
- logger.info(volms.size()+"initial volumes");
- logger.info(vol.getId());
- if(server.getVolumes().containsValue(vol_id))
- {
- logger.info("Alreday volumes exists:");
- logger.info( volms.size()+"volumes size if exists");
- }
- else
- {
- server.attachVolume(vol, device);
- logger.info( volms.size()+"volumes size after attaching volume");
+ logger.debug(Msg.SERVER_FOUND, vm_url, 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);
+ List<Volume> volList = vs.getVolumes();
+ logger.info("Size of volume list :" + volList.size());
+ if (volList != null && !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 Attach Volume to the server:" + Volume.Status.ATTACHING);
+ service.attachVolume(server, v, device);
+ logger.info("Volume status after performing attach:" + v.getStatus());
+ doSuccess(rc);
+ } else {
+ String msg = "Volume with volume id " + vol_id + " cannot be attached as it already exists";
+ logger.info("Alreday volumes exists:");
+ doFailure(rc, HttpStatus.NOT_IMPLEMENTED_501, msg);
+ }
}
+ }
context.close();
doSuccess(rc);
ctx.setAttribute("VOLUME_STATUS", "SUCCESS");
@@ -112,6 +118,7 @@ public class AttachVolumeServer extends ProviderServerOperation {
}
return server;
}
+
@Override
protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context)
throws APPCException {
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 3dd843b67..091edf2bc 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
@@ -10,7 +10,7 @@
* 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
+ * 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,
@@ -26,6 +26,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 org.glassfish.grizzly.http.util.HttpStatus;
import org.onap.appc.Constants;
import org.onap.appc.adapter.iaas.ProviderAdapter;
@@ -49,8 +51,9 @@ import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.att.eelf.i18n.EELFResourceManager;
-public class DettachVolumeServer extends ProviderServerOperation{
+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 {
@@ -58,6 +61,7 @@ public class DettachVolumeServer extends ProviderServerOperation{
logOperation(Msg.DETTACHINGVOLUME_SERVER, params, context);
return dettachVolume(params, context);
}
+
private Server dettachVolume(Map<String, String> params, SvcLogicContext ctx) {
Server server = null;
RequestContext rc = new RequestContext(ctx);
@@ -75,29 +79,33 @@ public class DettachVolumeServer extends ProviderServerOperation{
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();
- String msg;
context = getContext(rc, vm_url, identStr);
if (context != null) {
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, tenantName, server.getStatus().toString());
- Volume vol = new Volume();
- vol.setId(vol_id);
- Map volms = server.getVolumes();
- ComputeService cs = context.getComputeService();
- if(server.getVolumes().containsValue(vol_id))
- {
- logger.info("Alreday volumes exists:");
- logger.info( volms.size()+"volumes size if exists");
- cs.detachVolume(server, vol);
- server.detachVolume(device);
- }
- else
- {
- logger.info("volume is not available to detach");
- logger.info("Server status: RUNNING");
+ logger.debug(Msg.SERVER_FOUND, vm_url, 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);
+ List<Volume> volList = vs.getVolumes();
+ logger.info("Size of volume list :" + volList.size());
+ if (volList != null && !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);
+ service.detachVolume(server, v);
+ logger.info("Volume status after performing detach:" + v.getStatus());
+ 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);
+ }
}
+ }
context.close();
doSuccess(rc);
ctx.setAttribute("VOLUME_STATUS", "SUCCESS");