use of com.emc.storageos.xtremio.restapi.XtremIOClient in project coprhd-controller by CoprHD.
the class XtremIOExportOperations method runLunMapDeletionOrRemoveInitiatorAlgorithm.
/**
* It deletes the LunMap if the IG contains no other initiators than the requested ones.
* Else it removes the requested initiators from the IG
*/
private void runLunMapDeletionOrRemoveInitiatorAlgorithm(StorageSystem storage, ExportMask exportMask, List<URI> volumes, List<Initiator> initiators, TaskCompleter taskCompleter) throws DeviceControllerException {
// find LunMap associated with Volume
// Then find initiatorGroup associated with this lun map
XtremIOClient client = null;
// Default_IG;
try {
String hostName = null;
String clusterName = null;
client = XtremIOProvUtils.getXtremIOClient(dbClient, storage, xtremioRestClientFactory);
String xioClusterName = client.getClusterDetails(storage.getSerialNumber()).getName();
boolean initiatorsOfRP = ExportUtils.checkIfInitiatorsForRP(initiators);
for (Initiator initiator : initiators) {
if (null != initiator.getHostName()) {
// initiators already grouped by Host
hostName = initiator.getHostName();
clusterName = initiator.getClusterName();
break;
}
}
ArrayListMultimap<String, Initiator> groupInitiatorsByIG = XtremIOProvUtils.mapInitiatorToInitiatorGroup(storage.getSerialNumber(), initiators, null, xioClusterName, client);
ArrayListMultimap<String, Initiator> knownInitiatorsToIGMap = ArrayListMultimap.create();
// DU validations for removing volumes from IG.
ExportMaskValidationContext ctx = new ExportMaskValidationContext();
ctx.setStorage(storage);
ctx.setExportMask(exportMask);
ctx.setInitiators(initiators);
ctx.setAllowExceptions(!WorkflowService.getInstance().isStepInRollbackState(taskCompleter.getOpId()));
XtremIOExportMaskInitiatorsValidator initiatorsValidator = (XtremIOExportMaskInitiatorsValidator) validator.removeVolumes(ctx);
initiatorsValidator.setInitiatorToIGMap(groupInitiatorsByIG);
initiatorsValidator.setKnownInitiatorToIGMap(knownInitiatorsToIGMap);
initiatorsValidator.validate();
Set<String> igNames = groupInitiatorsByIG.keySet();
List<String> failedVolumes = new ArrayList<String>();
List<String> failedIGs = new ArrayList<String>();
for (URI volumeUri : volumes) {
BlockObject blockObj = BlockObject.fetch(dbClient, volumeUri);
_log.info("Block Obj {} , wwn {}", blockObj.getId(), blockObj.getWWN());
XtremIOVolume xtremIOVolume = null;
if (URIUtil.isType(volumeUri, Volume.class)) {
xtremIOVolume = XtremIOProvUtils.isVolumeAvailableInArray(client, blockObj.getDeviceLabel(), xioClusterName);
} else {
if (URIUtil.isType(volumeUri, BlockSnapshot.class) && BlockObject.checkForRP(dbClient, volumeUri)) {
// If the BlockObject is a BlockSnapshot of type RP (bookmark), there will be no exported
// snapshot. In this case, a target volume will have been exported and the deviceLabel of
// the BlockSnapshot reflects the name of that target.
_log.info(String.format("Dealing with a RecoverPoint bookmark lun mapping. Checking to see if volume %s is available on array.", blockObj.getDeviceLabel()));
xtremIOVolume = XtremIOProvUtils.isVolumeAvailableInArray(client, blockObj.getDeviceLabel(), xioClusterName);
} else {
xtremIOVolume = XtremIOProvUtils.isSnapAvailableInArray(client, blockObj.getDeviceLabel(), xioClusterName);
}
}
if (null != xtremIOVolume) {
// I need lun map id and igName
// if iGName is available in the above group:
_log.info("Volume Details {}", xtremIOVolume.toString());
_log.info("Volume lunMap details {}", xtremIOVolume.getLunMaps().toString());
// Lun Maps to delete
Set<String> lunMaps = new HashSet<String>();
boolean removeInitiator = false;
String volId = xtremIOVolume.getVolInfo().get(2);
if (xtremIOVolume.getLunMaps().isEmpty()) {
// handle scenarios where volumes gets unexported already
_log.info("Volume {} doesn't have any existing export available on Array, unexported already.", xtremIOVolume.toString());
exportMask.removeFromUserCreatedVolumes(blockObj);
exportMask.removeVolume(blockObj.getId());
continue;
}
for (List<Object> lunMapEntries : xtremIOVolume.getLunMaps()) {
@SuppressWarnings("unchecked") List<Object> igDetails = (List<Object>) lunMapEntries.get(0);
String igName = (String) igDetails.get(1);
// IG details is actually transforming to a double by default, even though
// its modeled as List<String>
// hence this logic
Double IgIdDouble = (Double) igDetails.get(2);
String igId = String.valueOf(IgIdDouble.intValue());
_log.info("IG Name: {} Id: {} found in Lun Map", igName, igId);
if (!igNames.contains(igName)) {
_log.info("Volume is associated with IG {} which is not in the removal list requested, ignoring..", igName);
continue;
}
/**
* i) If Cluster export:
* If there are additional initiators other than the requested ones (Single IG with all cluster
* initiators)
* - - - remove initiator from IG,
* - - - Note: If initiators are of RP (CTRL-13622), always delete LunMap.
* - ii) Host export:
* - - -- delete LunMap
*/
boolean igHasOtherHostInitiatorsOfSameCluster = knownInitiatorsToIGMap.get(igName).size() > groupInitiatorsByIG.get(igName).size();
if (!initiatorsOfRP && clusterName != null && igHasOtherHostInitiatorsOfSameCluster) {
removeInitiator = true;
}
if (!removeInitiator) {
// delete LunMap
@SuppressWarnings("unchecked") List<Object> tgtGroupDetails = (List<Object>) lunMapEntries.get(1);
Double tgIdDouble = (Double) tgtGroupDetails.get(2);
String tgtid = String.valueOf(tgIdDouble.intValue());
String lunMapId = volId.concat(XtremIOConstants.UNDERSCORE).concat(igId).concat(XtremIOConstants.UNDERSCORE).concat(tgtid);
_log.info("LunMap Id {} Found associated with Volume {}", lunMapId, blockObj.getDeviceLabel());
lunMaps.add(lunMapId);
}
}
// there will be only one lun map always
for (String lunMap : lunMaps) {
try {
client.deleteLunMap(lunMap, xioClusterName);
} catch (Exception e) {
failedVolumes.add(volumeUri.toString().concat(XtremIOConstants.DASH).concat(e.getMessage()));
_log.warn("Deletion of Lun Map {} failed}", lunMap, e);
}
}
// remove initiator from IG
if (removeInitiator) {
_log.info("Removing requested intiators from IG instead of deleting LunMap" + " as the IG contains other Host's initiators belonging to same Cluster.");
ctx = new ExportMaskValidationContext();
ctx.setStorage(storage);
ctx.setExportMask(exportMask);
ctx.setBlockObjects(volumes, dbClient);
ctx.setAllowExceptions(!WorkflowService.getInstance().isStepInRollbackState(taskCompleter.getOpId()));
// DU validation when removing initiators
XtremIOExportMaskVolumesValidator volumeValidator = (XtremIOExportMaskVolumesValidator) validator.removeInitiators(ctx);
volumeValidator.setIgNames(groupInitiatorsByIG.keySet());
volumeValidator.validate();
List<Initiator> initiatorsToBeRemoved = new ArrayList<Initiator>();
// Get the context from the task completer, in case this is a rollback.
ExportOperationContext context = (ExportOperationContext) WorkflowService.getInstance().loadStepData(taskCompleter.getOpId());
if (context != null && context.getOperations() != null) {
ListIterator li = context.getOperations().listIterator(context.getOperations().size());
while (li.hasPrevious()) {
_log.info("Handling deleteExportMask as a result of rollback");
ExportOperationContextOperation operation = (ExportOperationContextOperation) li.previous();
if (operation != null && XtremIOExportOperationContext.OPERATION_ADD_INITIATORS_TO_INITIATOR_GROUP.equals(operation.getOperation())) {
initiatorsToBeRemoved = (List<Initiator>) operation.getArgs().get(0);
_log.info("Removing initiators {} as part of rollback", Joiner.on(',').join(initiatorsToBeRemoved));
}
}
} else {
initiatorsToBeRemoved = initiators;
}
// Deleting the initiator automatically removes the initiator from lun map
for (Initiator initiator : initiatorsToBeRemoved) {
try {
// check if Initiator has already been deleted during previous volume processing
String initiatorName = initiator.getMappedInitiatorName(storage.getSerialNumber());
XtremIOInitiator initiatorObj = client.getInitiator(initiatorName, xioClusterName);
if (null != initiatorObj) {
client.deleteInitiator(initiatorName, xioClusterName);
} else {
_log.info("Initiator {} already deleted", initiatorName);
}
} catch (Exception e) {
failedIGs.add(initiator.getLabel().concat(XtremIOConstants.DASH).concat(e.getMessage()));
_log.warn("Removal of Initiator {} from IG failed", initiator.getLabel(), e);
}
}
}
} else {
exportMask.removeFromUserCreatedVolumes(blockObj);
exportMask.removeVolume(blockObj.getId());
}
}
dbClient.updateObject(exportMask);
if (!failedVolumes.isEmpty()) {
String errMsg = "Export Operations failed for these volumes: ".concat(Joiner.on(", ").join(failedVolumes));
ServiceError serviceError = DeviceControllerException.errors.jobFailedMsg(errMsg, null);
taskCompleter.error(dbClient, serviceError);
return;
}
if (!failedIGs.isEmpty()) {
String errMsg = "Export Operations failed deleting these initiators: ".concat(Joiner.on(", ").join(failedIGs));
ServiceError serviceError = DeviceControllerException.errors.jobFailedMsg(errMsg, null);
taskCompleter.error(dbClient, serviceError);
return;
}
// Clean IGs if empty
deleteInitiatorGroup(groupInitiatorsByIG, client, xioClusterName);
// delete IG Folder as well if IGs are empty
deleteInitiatorGroupFolder(client, xioClusterName, clusterName, hostName, storage);
taskCompleter.ready(dbClient);
} catch (Exception e) {
_log.error(String.format("Export Operations failed - maskName: %s", exportMask.getId().toString()), e);
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
taskCompleter.error(dbClient, serviceError);
}
}
use of com.emc.storageos.xtremio.restapi.XtremIOClient 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.XtremIOClient 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.XtremIOClient in project coprhd-controller by CoprHD.
the class XtremIOSnapshotOperations method createSingleVolumeSnapshot.
@Override
public void createSingleVolumeSnapshot(StorageSystem storage, URI snapshot, Boolean createInactive, Boolean readOnly, TaskCompleter taskCompleter) throws DeviceControllerException {
BlockSnapshot snap = dbClient.queryObject(BlockSnapshot.class, snapshot);
try {
XtremIOClient client = XtremIOProvUtils.getXtremIOClient(dbClient, storage, xtremioRestClientFactory);
String xioClusterName = client.getClusterDetails(storage.getSerialNumber()).getName();
String generatedLabel = nameGenerator.generate("", snap.getLabel(), "", '_', XtremIOConstants.XTREMIO_MAX_VOL_LENGTH);
snap.setLabel(generatedLabel);
XtremIOVolume createdSnap;
if (client.isVersion2()) {
createdSnap = createV2Snapshot(client, storage, xioClusterName, snap, generatedLabel, readOnly, taskCompleter);
} else {
createdSnap = createV1Snapshot(client, storage, snap, generatedLabel, readOnly, taskCompleter);
}
if (createdSnap != null) {
processSnapshot(createdSnap, snap, storage);
}
dbClient.updateObject(snap);
taskCompleter.ready(dbClient);
} catch (Exception e) {
_log.error("Snapshot creation failed", e);
snap.setInactive(true);
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
taskCompleter.error(dbClient, serviceError);
}
}
use of com.emc.storageos.xtremio.restapi.XtremIOClient in project coprhd-controller by CoprHD.
the class XtremIOSnapshotOperations method deleteGroupSnapshots.
@Override
public void deleteGroupSnapshots(StorageSystem storage, URI snapshot, TaskCompleter taskCompleter) throws DeviceControllerException {
try {
XtremIOClient client = XtremIOProvUtils.getXtremIOClient(dbClient, storage, xtremioRestClientFactory);
BlockSnapshot snapshotObj = dbClient.queryObject(BlockSnapshot.class, snapshot);
String clusterName = client.getClusterDetails(storage.getSerialNumber()).getName();
String rgName = snapshotObj.getReplicationGroupInstance();
if (NullColumnValueGetter.isNotNullValue(rgName) && null != XtremIOProvUtils.isSnapsetAvailableInArray(client, rgName, clusterName)) {
client.deleteSnapshotSet(rgName, clusterName);
}
// Set inactive=true for all snapshots in the snap
List<BlockSnapshot> snapshots = ControllerUtils.getSnapshotsPartOfReplicationGroup(snapshotObj, dbClient);
for (BlockSnapshot snap : snapshots) {
snap.setIsSyncActive(false);
snap.setInactive(true);
dbClient.updateObject(snap);
}
taskCompleter.ready(dbClient);
} catch (Exception e) {
_log.error("Snapshot deletion failed", e);
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
taskCompleter.error(dbClient, serviceError);
}
}
Aggregations