aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorModaboina, Kusumakumari (km583p) <km583p@us.att.com>2018-03-20 13:17:00 -0400
committerTakamune Cho <tc012c@att.com>2018-03-22 13:12:58 +0000
commitf1bd95884be20932a3ab7a92440e9e306902c1a0 (patch)
treeba2153416913fb4dfe407a0dfd200aa19a5fbffe
parent4b612bc977e1c8bf6a98fabf4efdac08d40a6552 (diff)
Bugfixes for error handling while attaching volume
Change-Id: I103709186eff4fc9e42038b2e1113b010b822528 Issue-ID: APPC-761 Signed-off-by: Modaboina, Kusumakumari (km583p) <km583p@us.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.java117
-rw-r--r--appc-common/src/main/resources/org/onap/appc/i18n/MessageResources.properties3
-rw-r--r--appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/conv/Converter.java11
3 files changed, 99 insertions, 32 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 e27b1594d..358831786 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
@@ -18,7 +18,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
* ============LICENSE_END=========================================================
*/
package org.onap.appc.adapter.iaas.provider.operation.impl;
@@ -37,15 +36,22 @@ import com.att.eelf.configuration.EELFManager;
import com.att.eelf.i18n.EELFResourceManager;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import org.glassfish.grizzly.http.util.HttpStatus;
import org.onap.appc.Constants;
import org.onap.appc.adapter.iaas.ProviderAdapter;
import org.onap.appc.adapter.iaas.impl.IdentityURL;
import org.onap.appc.adapter.iaas.impl.RequestContext;
import org.onap.appc.adapter.iaas.impl.RequestFailedException;
+import com.att.cdp.exceptions.TimeoutException;
import org.onap.appc.adapter.iaas.impl.VMURL;
import org.onap.appc.adapter.iaas.provider.operation.common.enums.Operation;
import org.onap.appc.adapter.iaas.provider.operation.impl.base.ProviderServerOperation;
+import com.woorea.openstack.base.client.OpenStackBaseException;
+import com.att.cdp.openstack.util.ExceptionMapper;
+import org.onap.appc.configuration.Configuration;
+import org.onap.appc.configuration.ConfigurationFactory;
+import java.util.Iterator;
import org.onap.appc.exceptions.APPCException;
import org.onap.appc.i18n.Msg;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
@@ -53,6 +59,7 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
public class AttachVolumeServer extends ProviderServerOperation {
private final EELFLogger logger = EELFManager.getInstance().getLogger(AttachVolumeServer.class);
+ private static final Configuration config = ConfigurationFactory.getConfiguration();
private Server attachVolume(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
Server server = null;
@@ -85,27 +92,28 @@ public class AttachVolumeServer extends ProviderServerOperation {
logger.info("collecting volume status for volume -id:" + volumeId);
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 Attach Volume to the server:");
- service.attachVolume(server, volume, device);
- 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);
- }
+ boolean isAttached = false;
+ if (validateAttach(service, vm.getServerId(), volumeId, device)) {
+ String msg = "Volume with volume id " + volumeId + " cannot be attached as it already exists";
+ logger.info("Already volumes exists:");
+ ctx.setAttribute("VOLUME_STATUS", "FAILURE");
+ doFailure(requestContext, HttpStatus.METHOD_NOT_ALLOWED_405, msg);
+ isAttached = false;
+ } else {
+ volume.setId(volumeId);
+ logger.info("Ready to Attach Volume to the server:");
+ service.attachVolume(server, volume, device);
+ isAttached = true;
+ }
+ if (isAttached) {
+ if (validateAttach(requestContext, service, vm.getServerId(), volumeId, device)) {
+ ctx.setAttribute("VOLUME_STATUS", "SUCCESS");
+ doSuccess(requestContext);
} else {
- String msg = "Volume with volume id " + volumeId + " cannot be attached as it already exists";
- logger.info("Alreday volumes exists:");
+ String msg = "Volume with " + volumeId + " unable to attach";
+ logger.info("Volume with " + volumeId + " unable to attach");
ctx.setAttribute("VOLUME_STATUS", "FAILURE");
- doFailure(requestContext, HttpStatus.NOT_IMPLEMENTED_501, msg);
+ doFailure(requestContext, HttpStatus.CONFLICT_409, msg);
}
}
context.close();
@@ -124,6 +132,11 @@ public class AttachVolumeServer extends ProviderServerOperation {
String msg = EELFResourceManager.format(Msg.SERVER_OPERATION_EXCEPTION, ex, ex.getClass().getSimpleName(),
ATTACHVOLUME_SERVICE.toString(), vmUrl, tenantName);
ctx.setAttribute("VOLUME_STATUS", "FAILURE");
+ try {
+ ExceptionMapper.mapException((OpenStackBaseException) ex);
+ } catch (ZoneException e1) {
+ logger.error(e1.getMessage());
+ }
doFailure(requestContext, HttpStatus.INTERNAL_SERVER_ERROR_500, msg);
}
return server;
@@ -137,16 +150,62 @@ public class AttachVolumeServer extends ProviderServerOperation {
return attachVolume(params, context);
}
- protected boolean validateAttach(VolumeService volumeService, String volumeId)
+ protected boolean validateAttach(ComputeService ser, String vm, String volumeId, String device)
+ throws RequestFailedException, ZoneException {
+ boolean isValid = false;
+ Map<String, String> map = ser.getAttachments(vm);
+ Iterator<Entry<String, String>> it = map.entrySet().iterator();
+ while (it.hasNext()) {
+ Map.Entry volumes = (Map.Entry) it.next();
+ if (map != null && !(map.isEmpty())) {
+ logger.info("volumes available before attach");
+ logger.info("device" + volumes.getKey() + "Values" + volumes.getValue());
+ if (volumes.getKey().equals(device) && (volumes.getValue().equals(volumeId))) {
+ logger.info("Device " + volumes.getKey() + "Volumes" + volumes.getValue());
+ isValid = true;
+ }
+ }
+ }
+ logger.info("AttachVolumeFlag" + isValid);
+ return isValid;
+ }
+
+ protected boolean validateAttach(RequestContext rc, ComputeService ser, String vm, String volumeId, String device)
throws RequestFailedException, ZoneException {
- boolean flag = false;
- List<Volume> volumeList = volumeService.getVolumes();
- if (volumeList.contains(volumeId)) {
- flag = true;
- } else {
- flag = false;
+ boolean isValid = false;
+ String msg = null;
+ config.setProperty(Constants.PROPERTY_RETRY_DELAY, "10");
+ config.setProperty(Constants.PROPERTY_RETRY_LIMIT, "30");
+ while (rc.attempt()) {
+ Map<String, String> map = ser.getAttachments(vm);
+ if (map != null && !(map.isEmpty())) {
+ Iterator<Entry<String, String>> it = map.entrySet().iterator();
+ logger.info("volumes available after attach ");
+ while (it.hasNext()) {
+ Map.Entry volumes = (Map.Entry) it.next();
+ logger.info(" devices " + volumes.getKey() + "volumes" + volumes.getValue());
+ if (volumes.getKey().equals(device) && (volumes.getValue().equals(volumeId))) {
+ logger.info("Device" + volumes.getKey() + "Volume" + volumes.getValue());
+ isValid = true;
+ break;
+ }
+ }
+ if (isValid) {
+ logger.info("AttachVolume" + rc.getAttempts() + "No.of attempts");
+ break;
+ } else {
+ rc.delay();
+ }
+ }
+ }
+ if ((rc.getAttempts() == 30) && (!isValid)) {
+
+ msg = EELFResourceManager.format(Msg.CONNECTION_FAILED_RETRY, Long.toString(rc.getRetryDelay()),
+ Integer.toString(rc.getAttempts()), Integer.toString(rc.getRetryLimit()));
+ logger.error(msg);
+ throw new TimeoutException(msg);
}
- logger.info("validateAttach flag-->" + flag);
- return flag;
+ logger.info("AttachVolume Flag -->" + isValid);
+ return isValid;
}
}
diff --git a/appc-common/src/main/resources/org/onap/appc/i18n/MessageResources.properties b/appc-common/src/main/resources/org/onap/appc/i18n/MessageResources.properties
index 85598c734..49999c563 100644
--- a/appc-common/src/main/resources/org/onap/appc/i18n/MessageResources.properties
+++ b/appc-common/src/main/resources/org/onap/appc/i18n/MessageResources.properties
@@ -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
# =============================================================================
@@ -18,7 +18,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-# ECOMP is a trademark and service mark of AT&T Intellectual Property.
# ============LICENSE_END=========================================================
###
diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/conv/Converter.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/conv/Converter.java
index 68352c1b1..5aac95a42 100644
--- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/conv/Converter.java
+++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/conv/Converter.java
@@ -18,7 +18,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
* ============LICENSE_END=========================================================
*/
@@ -254,6 +253,16 @@ public class Converter {
((UpgradePreCheckOutputBuilder)outObj).setCommonHeader(commonHeader);
((UpgradePreCheckOutputBuilder)outObj).setStatus(status);
return outObj;
+ case AttachVolume:
+ outObj = new AttachVolumeOutputBuilder();
+ ((AttachVolumeOutputBuilder)outObj).setCommonHeader(commonHeader);
+ ((AttachVolumeOutputBuilder)outObj).setStatus(status);
+ return outObj;
+ case DetachVolume:
+ outObj = new DetachVolumeOutputBuilder();
+ ((DetachVolumeOutputBuilder)outObj).setCommonHeader(commonHeader);
+ ((DetachVolumeOutputBuilder)outObj).setStatus(status);
+ return outObj;
default:
throw new IllegalArgumentException(action+" action is not supported");
}