Search in sources :

Example 1 with XtremIOApiException

use of com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException in project coprhd-controller by CoprHD.

the class XtremIOStorageDevice method doDeleteVolumes.

@Override
public void doDeleteVolumes(StorageSystem storageSystem, String opId, List<Volume> volumes, TaskCompleter completer) throws DeviceControllerException {
    Map<String, String> failedVolumes = new HashMap<String, String>();
    try {
        XtremIOClient client = XtremIOProvUtils.getXtremIOClient(dbClient, storageSystem, xtremioRestClientFactory);
        String clusterName = client.getClusterDetails(storageSystem.getSerialNumber()).getName();
        URI projectUri = volumes.get(0).getProject().getURI();
        URI poolUri = volumes.get(0).getPool();
        for (Volume volume : volumes) {
            String volumeName = volume.getDeviceLabel() != null ? volume.getDeviceLabel() : volume.getLabel();
            try {
                if (null != XtremIOProvUtils.isVolumeAvailableInArray(client, volumeName, clusterName)) {
                    // Remove the volume from the consistency group
                    if (client.isVersion2() && !NullColumnValueGetter.isNullURI(volume.getConsistencyGroup()) && NullColumnValueGetter.isNotNullValue(volume.getReplicationGroupInstance())) {
                        BlockConsistencyGroup consistencyGroupObj = dbClient.queryObject(BlockConsistencyGroup.class, volume.getConsistencyGroup());
                        String cgName = volume.getReplicationGroupInstance();
                        XtremIOConsistencyGroup xioCG = XtremIOProvUtils.isCGAvailableInArray(client, cgName, clusterName);
                        // Check if CG has volumes
                        if (null != xioCG && null != xioCG.getVolList() && !xioCG.getVolList().isEmpty()) {
                            boolean isVolRemovedFromCG = false;
                            // Verify if the volumes is part of the CG or not. If Exists always remove from CG
                            if (checkIfVolumeExistsInCG(xioCG.getVolList(), volumeName)) {
                                _log.info("Removing volume {} from consistency group {}", volumeName, cgName);
                                InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_038);
                                client.removeVolumeFromConsistencyGroup(volumeName, cgName, clusterName);
                                InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_039);
                                isVolRemovedFromCG = true;
                            } else {
                                _log.info("Volume {} doesn't exist on CG {}", volumeName, cgName);
                            }
                            // Perform remove CG only when we removed the volume from CG.
                            if (isVolRemovedFromCG) {
                                // Query the CG to reflect the latest data on array.
                                xioCG = XtremIOProvUtils.isCGAvailableInArray(client, cgName, clusterName);
                                if (null == xioCG.getVolList() || xioCG.getVolList().isEmpty()) {
                                    InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_038);
                                    client.removeConsistencyGroup(cgName, clusterName);
                                    InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_039);
                                    _log.info("CG is empty on array. Remove array association from the CG");
                                    consistencyGroupObj.removeSystemConsistencyGroup(storageSystem.getId().toString(), cgName);
                                    // clear the LOCAL type
                                    StringSet types = consistencyGroupObj.getTypes();
                                    if (types != null) {
                                        types.remove(Types.LOCAL.name());
                                        consistencyGroupObj.setTypes(types);
                                    }
                                    dbClient.updateObject(consistencyGroupObj);
                                }
                            }
                        }
                    }
                    // backing volume).
                    if (volume.checkForRp() || RPHelper.isAssociatedToAnyRpVplexTypes(volume, dbClient)) {
                        int attempt = 0;
                        while (attempt++ <= MAX_RP_RETRIES) {
                            try {
                                _log.info(String.format("Deleting RecoverPoint volume %s (attempt %s/%s)", volumeName, attempt, MAX_RP_RETRIES));
                                InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_040);
                                client.deleteVolume(volumeName, clusterName);
                                InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_041);
                                break;
                            } catch (XtremIOApiException e) {
                                // volume removed from the consistency group.
                                if (attempt != MAX_RP_RETRIES && e.getMessage().contains("cannot_remove_volume_that_is_in_consistency_group")) {
                                    _log.warn(String.format("Encountered exception attempting delete RP volume %s.  Waiting %s milliseconds before trying again.  Error: %s", volumeName, RP_WAIT_FOR_RETRY, e.getMessage()));
                                    try {
                                        Thread.sleep(RP_WAIT_FOR_RETRY);
                                    } catch (InterruptedException e1) {
                                        Thread.currentThread().interrupt();
                                    }
                                } else {
                                    // re-throw the exception if this is not the one we care about
                                    throw e;
                                }
                            }
                        }
                    } else {
                        _log.info("Deleting the volume {}", volumeName);
                        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_040);
                        client.deleteVolume(volumeName, clusterName);
                        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_041);
                    }
                }
            } catch (Exception e) {
                _log.error("Error during volume {} delete.", volumeName, e);
                failedVolumes.put(volumeName, ControllerUtils.getMessage(e));
            }
        }
        if (!failedVolumes.isEmpty()) {
            StringBuffer errMsg = new StringBuffer("Failed to delete volumes: ");
            for (String failedVolume : failedVolumes.keySet()) {
                errMsg.append(failedVolume).append(":").append(failedVolumes.get(failedVolume));
            }
            ServiceError error = DeviceControllerErrors.xtremio.deleteVolumeFailure(errMsg.toString());
            completer.error(dbClient, error);
        } else {
            String volumeFolderName = getVolumeFolderName(projectUri, storageSystem);
            XtremIOProvUtils.cleanupVolumeFoldersIfNeeded(client, clusterName, volumeFolderName, storageSystem);
            completer.ready(dbClient);
        }
        // update StoragePool capacity for pools changed
        StoragePool pool = dbClient.queryObject(StoragePool.class, poolUri);
        try {
            _log.info("Updating Pool {} Capacity", pool.getNativeGuid());
            XtremIOProvUtils.updateStoragePoolCapacity(client, dbClient, pool);
        } catch (Exception e) {
            _log.warn("Error while updating pool capacity for pool {} ", poolUri, e);
        }
    } catch (Exception e) {
        _log.error("Error while deleting volumes", e);
        ServiceError error = DeviceControllerErrors.xtremio.deleteVolumeFailure(e.getMessage());
        completer.error(dbClient, error);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) XtremIOConsistencyGroup(com.emc.storageos.xtremio.restapi.model.response.XtremIOConsistencyGroup) StoragePool(com.emc.storageos.db.client.model.StoragePool) HashMap(java.util.HashMap) URI(java.net.URI) XtremIOApiException(com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) XtremIOVolume(com.emc.storageos.xtremio.restapi.model.response.XtremIOVolume) Volume(com.emc.storageos.db.client.model.Volume) XtremIOClient(com.emc.storageos.xtremio.restapi.XtremIOClient) StringSet(com.emc.storageos.db.client.model.StringSet) XtremIOApiException(com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException)

Example 2 with XtremIOApiException

use of com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException in project coprhd-controller by CoprHD.

the class XtremIOSnapshotOperations method resyncSingleVolumeSnapshot.

@Override
public void resyncSingleVolumeSnapshot(StorageSystem storage, URI volume, URI snapshot, TaskCompleter taskCompleter) throws DeviceControllerException {
    Volume sourceVol = null;
    try {
        XtremIOClient client = XtremIOProvUtils.getXtremIOClient(dbClient, storage, xtremioRestClientFactory);
        BlockSnapshot snapshotObj = dbClient.queryObject(BlockSnapshot.class, snapshot);
        sourceVol = dbClient.queryObject(Volume.class, snapshotObj.getParent());
        String clusterName = client.getClusterDetails(storage.getSerialNumber()).getName();
        client.refreshSnapshotFromVolume(clusterName, sourceVol.getDeviceLabel(), snapshotObj.getDeviceLabel());
        taskCompleter.ready(dbClient);
    } catch (Exception e) {
        _log.error("Snapshot resync failed", e);
        ServiceError serviceError = null;
        if (e instanceof XtremIOApiException) {
            XtremIOApiException xioException = (XtremIOApiException) e;
            // check for specific error key for snapshot size mismatch with source volume.
            if (null != xioException.getMessage() && xioException.getMessage().contains(XtremIOConstants.SNAP_SIZE_MISMATCH_ERROR_KEY)) {
                String restoreFailureMsg = String.format("snapshot size mismatch with the source volume size %s. Use expand snapshot feature to increase the snapshot size.", sourceVol.getProvisionedCapacity());
                serviceError = DeviceControllerErrors.xtremio.resyncSnapshotFailureSourceSizeMismatch(restoreFailureMsg);
            }
        } else {
            serviceError = DeviceControllerException.errors.jobFailed(e);
        }
        taskCompleter.error(dbClient, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) Volume(com.emc.storageos.db.client.model.Volume) XtremIOVolume(com.emc.storageos.xtremio.restapi.model.response.XtremIOVolume) XtremIOClient(com.emc.storageos.xtremio.restapi.XtremIOClient) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) XtremIOApiException(com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException) XtremIOApiException(com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 3 with XtremIOApiException

use of com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException in project coprhd-controller by CoprHD.

the class XtremIOSnapshotOperations method restoreSingleVolumeSnapshot.

@Override
public void restoreSingleVolumeSnapshot(StorageSystem storage, URI volume, URI snapshot, TaskCompleter taskCompleter) throws DeviceControllerException {
    Volume sourceVol = null;
    try {
        XtremIOClient client = XtremIOProvUtils.getXtremIOClient(dbClient, storage, xtremioRestClientFactory);
        BlockSnapshot snapshotObj = dbClient.queryObject(BlockSnapshot.class, snapshot);
        sourceVol = dbClient.queryObject(Volume.class, snapshotObj.getParent());
        String clusterName = client.getClusterDetails(storage.getSerialNumber()).getName();
        client.restoreVolumeFromSnapshot(clusterName, sourceVol.getDeviceLabel(), snapshotObj.getDeviceLabel());
        taskCompleter.ready(dbClient);
    } catch (Exception e) {
        _log.error("Snapshot restore failed", e);
        ServiceError serviceError = null;
        if (e instanceof XtremIOApiException) {
            XtremIOApiException xioException = (XtremIOApiException) e;
            // check for specific error key for snapshot size mismatch with source volume.
            if (null != xioException.getMessage() && xioException.getMessage().contains(XtremIOConstants.SNAP_SIZE_MISMATCH_ERROR_KEY)) {
                String restoreFailureMsg = String.format("snapshot size mismatch with the source volume size %s. Use expand snapshot feature to increase the snapshot size.", sourceVol.getProvisionedCapacity());
                serviceError = DeviceControllerErrors.xtremio.restoreSnapshotFailureSourceSizeMismatch(restoreFailureMsg);
            }
        } else {
            serviceError = DeviceControllerException.errors.jobFailed(e);
        }
        taskCompleter.error(dbClient, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) Volume(com.emc.storageos.db.client.model.Volume) XtremIOVolume(com.emc.storageos.xtremio.restapi.model.response.XtremIOVolume) XtremIOClient(com.emc.storageos.xtremio.restapi.XtremIOClient) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) XtremIOApiException(com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException) XtremIOApiException(com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 4 with XtremIOApiException

use of com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException in project coprhd-controller by CoprHD.

the class XtremIOClient method checkResponse.

@Override
protected int checkResponse(URI uri, ClientResponse response) throws XtremIOApiException {
    ClientResponse.Status status = response.getClientResponseStatus();
    int errorCode = status.getStatusCode();
    if (errorCode >= 300) {
        JSONObject obj = null;
        String extraExceptionInfo = null;
        int xtremIOCode = 0;
        try {
            obj = response.getEntity(JSONObject.class);
            xtremIOCode = obj.getInt(XtremIOConstants.ERROR_CODE);
        } catch (Exception e) {
            extraExceptionInfo = e.getMessage();
            log.error("Parsing the failure response object failed", e);
        }
        if (xtremIOCode == 404 || xtremIOCode == 410) {
            throw XtremIOApiException.exceptions.resourceNotFound(uri.toString());
        } else if (xtremIOCode == 401) {
            throw XtremIOApiException.exceptions.authenticationFailure(uri.toString());
        } else {
            // Sometimes the response object can be null, just set it to empty when it is null.
            String objStr = (obj == null) ? "" : obj.toString();
            // Append extra exception info if present
            if (extraExceptionInfo != null) {
                objStr = String.format("%s%s", (objStr.isEmpty()) ? objStr : objStr + " | ", extraExceptionInfo);
            }
            throw XtremIOApiException.exceptions.internalError(uri.toString(), objStr);
        }
    } else {
        return errorCode;
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) JSONObject(org.codehaus.jettison.json.JSONObject) XtremIOApiException(com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException)

Example 5 with XtremIOApiException

use of com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException in project coprhd-controller by CoprHD.

the class XtremIOClient method authenticate.

@Override
protected void authenticate() throws XtremIOApiException {
    ClientResponse response = null;
    try {
        XtremIOAuthInfo authInfo = new XtremIOAuthInfo();
        authInfo.setPassword(_password);
        authInfo.setUsername(_username);
        String body = getJsonForEntity(authInfo);
        URI requestURI = _base.resolve(URI.create(XtremIOConstants.XTREMIO_BASE_STR));
        response = _client.resource(requestURI).type(MediaType.APPLICATION_JSON).post(ClientResponse.class, body);
        if (response.getClientResponseStatus() != ClientResponse.Status.OK && response.getClientResponseStatus() != ClientResponse.Status.CREATED) {
            throw XtremIOApiException.exceptions.authenticationFailure(_base.toString());
        }
        _authToken = response.getHeaders().getFirst(XtremIOConstants.AUTH_TOKEN_HEADER);
    } catch (Exception e) {
        throw XtremIOApiException.exceptions.authenticationFailure(_base.toString());
    } finally {
        closeResponse(response);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) XtremIOAuthInfo(com.emc.storageos.xtremio.restapi.model.XtremIOAuthInfo) URI(java.net.URI) XtremIOApiException(com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException)

Aggregations

XtremIOApiException (com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException)7 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)5 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)5 XtremIOClient (com.emc.storageos.xtremio.restapi.XtremIOClient)5 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)4 XtremIOVolume (com.emc.storageos.xtremio.restapi.model.response.XtremIOVolume)4 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)3 Volume (com.emc.storageos.db.client.model.Volume)3 XtremIOConsistencyGroup (com.emc.storageos.xtremio.restapi.model.response.XtremIOConsistencyGroup)3 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)2 ClientResponse (com.sun.jersey.api.client.ClientResponse)2 URI (java.net.URI)2 BlockObject (com.emc.storageos.db.client.model.BlockObject)1 StoragePool (com.emc.storageos.db.client.model.StoragePool)1 StringSet (com.emc.storageos.db.client.model.StringSet)1 XtremIOAuthInfo (com.emc.storageos.xtremio.restapi.model.XtremIOAuthInfo)1 HashMap (java.util.HashMap)1 JSONObject (org.codehaus.jettison.json.JSONObject)1