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);
}
}
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);
}
}
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);
}
}
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;
}
}
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);
}
}
Aggregations