use of com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext.ExportOperationContextOperation 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.volumecontroller.impl.utils.ExportOperationContext.ExportOperationContextOperation in project coprhd-controller by CoprHD.
the class VnxExportOperations method removeInitiators.
/*
* (non-Javadoc)
*
* @see
* com.emc.storageos.volumecontroller.impl.smis.ExportMaskOperations#removeInitiator(com.emc.storageos.db.client.
* model.StorageSystem, java.net.URI, java.util.List, java.util.List,
* com.emc.storageos.volumecontroller.TaskCompleter)
*
*/
@Override
public void removeInitiators(StorageSystem storage, URI exportMaskURI, List<URI> volumeURIList, List<Initiator> initiatorList, List<URI> targets, TaskCompleter taskCompleter) throws DeviceControllerException {
_log.info("{} removeInitiators START...", storage.getSerialNumber());
try {
_log.info("removeInitiators: Export mask id: {}", exportMaskURI);
if (volumeURIList != null) {
_log.info("removeInitiators: volumes : {}", Joiner.on(',').join(volumeURIList));
}
_log.info("removeInitiators: initiators : {}", Joiner.on(',').join(initiatorList));
if (targets != null) {
_log.info("removeInitiators: targets : {}", Joiner.on(',').join(targets));
}
boolean isRollback = WorkflowService.getInstance().isStepInRollbackState(taskCompleter.getOpId());
if (isRollback) {
_log.info("Handling removeInitiators as a result of rollback");
List<Initiator> addedInitiators = new ArrayList<Initiator>();
// Get the context from the task completer as 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()) {
ExportOperationContextOperation operation = (ExportOperationContextOperation) li.previous();
if (operation != null && VnxExportOperationContext.OPERATION_ADD_INITIATORS_TO_STORAGE_GROUP.equals(operation.getOperation())) {
addedInitiators = (List<Initiator>) operation.getArgs().get(0);
_log.info("Removing initiators {} as part of rollback", Joiner.on(',').join(addedInitiators));
}
}
}
initiatorList = addedInitiators;
if (initiatorList == null || initiatorList.isEmpty()) {
_log.info("There was no context found for add initiator. So there is nothing to rollback.");
taskCompleter.ready(_dbClient);
return;
}
}
ExportMask exportMask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
ExportMaskValidationContext ctx = new ExportMaskValidationContext();
ctx.setStorage(storage);
ctx.setExportMask(exportMask);
ctx.setBlockObjects(volumeURIList, _dbClient);
ctx.setAllowExceptions(!isRollback);
validator.removeInitiators(ctx).validate();
deleteStorageHWIDs(storage, initiatorList);
taskCompleter.ready(_dbClient);
} catch (Exception e) {
_log.error("Unexpected error: removeInitiators failed.", e);
ServiceError error = DeviceControllerErrors.smis.methodFailed("removeInitiators", e.getMessage());
taskCompleter.error(_dbClient, error);
}
_log.info("{} removeInitiators END...", storage.getSerialNumber());
}
use of com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext.ExportOperationContextOperation in project coprhd-controller by CoprHD.
the class XtremIOExportOperations method deleteExportMask.
@Override
public void deleteExportMask(StorageSystem storage, URI exportMaskURI, List<URI> volumeURIList, List<URI> targetURIList, List<Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
_log.info("{} deleteExportMask START...", storage.getSerialNumber());
try {
_log.info("Export mask id: {}", exportMaskURI);
if (volumeURIList != null) {
_log.info("deleteExportMask: volumes: {}", Joiner.on(',').join(volumeURIList));
}
if (targetURIList != null) {
_log.info("deleteExportMask: assignments: {}", Joiner.on(',').join(targetURIList));
}
if (initiatorList != null) {
_log.info("deleteExportMask: initiators: {}", Joiner.on(',').join(initiatorList));
}
List<URI> volumesToBeUnmapped = new ArrayList<URI>();
boolean isRollback = WorkflowService.getInstance().isStepInRollbackState(taskCompleter.getOpId());
if (isRollback) {
_log.info("Handling deleteExportMask as a result of rollback");
List<URI> addedVolumes = new ArrayList<URI>();
// Get the context from the task completer
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()) {
ExportOperationContextOperation operation = (ExportOperationContextOperation) li.previous();
if (operation != null && XtremIOExportOperationContext.OPERATION_ADD_VOLUMES_TO_INITIATOR_GROUP.equals(operation.getOperation())) {
addedVolumes = (List<URI>) operation.getArgs().get(0);
_log.info("Removing volumes {} as part of rollback", Joiner.on(',').join(addedVolumes));
}
}
}
volumesToBeUnmapped = addedVolumes;
if (volumesToBeUnmapped == null || volumesToBeUnmapped.isEmpty()) {
_log.info("There was no context found for add volumes. So there is nothing to rollback.");
taskCompleter.ready(dbClient);
return;
}
} else {
if (volumeURIList != null) {
volumesToBeUnmapped = volumeURIList;
}
}
ExportMask exportMask = dbClient.queryObject(ExportMask.class, exportMaskURI);
if (exportMask == null || exportMask.getInactive()) {
throw new DeviceControllerException("Invalid ExportMask URI: " + exportMaskURI);
}
runLunMapDeletionOrRemoveInitiatorAlgorithm(storage, exportMask, volumesToBeUnmapped, initiatorList, taskCompleter);
} catch (final Exception ex) {
_log.error("Problem in deleteExportMask: ", ex);
ServiceError serviceError = DeviceControllerErrors.xtremio.operationFailed("deleteExportMask", ex.getMessage());
taskCompleter.error(dbClient, serviceError);
}
_log.info("{} deleteExportMask END...", storage.getSerialNumber());
}
use of com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext.ExportOperationContextOperation in project coprhd-controller by CoprHD.
the class VmaxExportOperations method exportMaskRollback.
/**
* Export mask operation rollback method.
*
* @param storage
* storage device
* @param taskCompleter
* task completer
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
private void exportMaskRollback(StorageSystem storage, ExportOperationContext context, TaskCompleter taskCompleter) throws Exception {
// Go through each operation and roll it back.
if (context != null && context.getOperations() != null) {
WBEMClient client = _helper.getConnection(storage).getCimClient();
ListIterator li = context.getOperations().listIterator(context.getOperations().size());
while (li.hasPrevious()) {
ExportOperationContextOperation operation = (ExportOperationContextOperation) li.previous();
// Flag to indicate whether or not we need to use the EMCForce flag on this operation.
// We currently use this flag when dealing with RP Volumes as they are tagged for RP and the
// operation on these volumes would fail otherwise.
//
// IMPORTANT NOTE: Default is FALSE, each rollback method will need to determine if it should be set to
// true if it is needed.
boolean forceFlag = false;
try {
switch(operation.getOperation()) {
case VmaxExportOperationContext.OPERATION_ADD_INITIATORS_TO_INITIATOR_GROUP:
// remove initiators from the initiator group
List<Initiator> initiatorList = (List<Initiator>) operation.getArgs().get(0);
CIMObjectPath initiatorGroupPath = (CIMObjectPath) operation.getArgs().get(1);
CIMArgument[] inArgs = _helper.getRemoveInitiatorsFromMaskingGroupInputArguments(storage, initiatorGroupPath, initiatorList);
CIMArgument[] outArgs = new CIMArgument[5];
_helper.invokeMethodSynchronously(storage, _cimPath.getControllerConfigSvcPath(storage), "RemoveMembers", inArgs, outArgs, null);
break;
case VmaxExportOperationContext.OPERATION_ADD_INITIATOR_GROUPS_TO_INITIATOR_GROUP:
// remove initiator groups from cascaded initiator group
CIMObjectPath childInitiatorGroup = (CIMObjectPath) operation.getArgs().get(0);
CIMObjectPath parentInitiatorGroup = (CIMObjectPath) operation.getArgs().get(1);
inArgs = _helper.getRemoveIGFromCIG(childInitiatorGroup, parentInitiatorGroup);
outArgs = new CIMArgument[5];
_helper.invokeMethodSynchronously(storage, _cimPath.getControllerConfigSvcPath(storage), "RemoveMembers", inArgs, outArgs, null);
break;
case VmaxExportOperationContext.OPERATION_CREATE_CASCADING_STORAGE_GROUP:
case VmaxExportOperationContext.OPERATION_CREATE_STORAGE_GROUP:
// Delete storage group
String groupName = (String) operation.getArgs().get(0);
// .get(2) arg is different depending on the operation, but for now we don't need it so we
// won't get it.
_helper.deleteMaskingGroup(storage, groupName, SmisCommandHelper.MASKING_GROUP_TYPE.SE_DeviceMaskingGroup);
break;
case VmaxExportOperationContext.OPERATION_CREATE_PORT_GROUP:
// Delete port group
groupName = (String) operation.getArgs().get(0);
_helper.deleteMaskingGroup(storage, groupName, SmisCommandHelper.MASKING_GROUP_TYPE.SE_TargetMaskingGroup);
break;
case VmaxExportOperationContext.OPERATION_ADD_TIER_TO_STORAGE_GROUP:
// Remove tier policy from storage group
String policyName = (String) operation.getArgs().get(0);
CIMObjectPath[] volumeGroupPaths = (CIMObjectPath[]) operation.getArgs().get(1);
for (CIMObjectPath volumeGroupPath : volumeGroupPaths) {
_helper.removeVolumeGroupFromPolicyAndLimitsAssociation(client, storage, volumeGroupPath);
}
break;
case VmaxExportOperationContext.OPERATION_ADD_STORAGE_GROUP_TO_CASCADING_STORAGE_GROUP:
// Remove storage group from cascading storage group
groupName = (String) operation.getArgs().get(0);
forceFlag = (boolean) operation.getArgs().get(2);
CIMObjectPath[] volumeGroupPathList = (CIMObjectPath[]) operation.getArgs().get(1);
inArgs = _helper.modifyCascadedStorageGroupInputArguments(storage, groupName, volumeGroupPathList, forceFlag);
outArgs = new CIMArgument[5];
_helper.invokeMethodSynchronously(storage, _cimPath.getControllerConfigSvcPath(storage), "RemoveMembers", inArgs, outArgs, null);
break;
case VmaxExportOperationContext.OPERATION_CREATE_CASCADED_INITIATOR_GROUP:
case VmaxExportOperationContext.OPERATION_CREATE_INITIATOR_GROUP:
// Remove initiator group
groupName = (String) operation.getArgs().get(0);
_helper.deleteMaskingGroup(storage, groupName, SmisCommandHelper.MASKING_GROUP_TYPE.SE_InitiatorMaskingGroup);
break;
case VmaxExportOperationContext.OPERATION_CREATE_MASKING_VIEW:
// Remove masking view
String maskName = (String) operation.getArgs().get(0);
// Find the mask using the name
boolean foundMaskInDb = false;
ExportMask exportMask = null;
URIQueryResultList uriQueryList = new URIQueryResultList();
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getExportMaskByNameConstraint(maskName), uriQueryList);
while (uriQueryList.iterator().hasNext()) {
URI uri = uriQueryList.iterator().next();
exportMask = _dbClient.queryObject(ExportMask.class, uri);
if (exportMask != null && !exportMask.getInactive() && exportMask.getStorageDevice().equals(storage.getId())) {
foundMaskInDb = true;
// given name for any storage array.
break;
}
}
// If we have the mask, check to see if we need to use the force flag
if (foundMaskInDb) {
for (String volURI : exportMask.getUserAddedVolumes().values()) {
forceFlag = ExportUtils.useEMCForceFlag(_dbClient, URI.create(volURI));
if (forceFlag) {
break;
}
}
}
inArgs = _helper.getDeleteMaskingViewInputArguments(storage, maskName, forceFlag);
outArgs = new CIMArgument[5];
_helper.invokeMethodSynchronously(storage, _cimPath.getControllerConfigSvcPath(storage), "DeleteMaskingView", inArgs, outArgs, null);
break;
case VmaxExportOperationContext.OPERATION_ADD_PORTS_TO_PORT_GROUP:
// Remove ports from port group
groupName = (String) operation.getArgs().get(0);
List<URI> targetURIList = (List<URI>) operation.getArgs().get(1);
inArgs = _helper.getRemoveTargetPortsFromMaskingGroupInputArguments(storage, groupName, targetURIList);
outArgs = new CIMArgument[5];
_helper.invokeMethodSynchronously(storage, _cimPath.getControllerConfigSvcPath(storage), "RemoveMembers", inArgs, outArgs, null);
break;
case VmaxExportOperationContext.OPERATION_ADD_VOLUMES_TO_STORAGE_GROUP:
// Remove volumes from storage group
groupName = (String) operation.getArgs().get(0);
forceFlag = (boolean) operation.getArgs().get(2);
VolumeURIHLU[] volumeList = (VolumeURIHLU[]) operation.getArgs().get(1);
List<URI> volumesInSG = new ArrayList<>();
for (VolumeURIHLU volumeUriHlu : volumeList) {
volumesInSG.add(volumeUriHlu.getVolumeURI());
}
inArgs = _helper.getRemoveVolumesFromMaskingGroupInputArguments(storage, groupName, volumesInSG, forceFlag);
outArgs = new CIMArgument[5];
_helper.invokeMethodSynchronously(storage, _cimPath.getControllerConfigSvcPath(storage), "RemoveMembers", inArgs, outArgs, null);
break;
case VmaxExportOperationContext.OPERATION_ADD_EXISTING_INITIATOR_TO_EXPORT_GROUP:
URI initiator = (URI) operation.getArgs().get(0);
_log.info("Not removing initiator: {} because it already existed in the masking view", initiator);
// Ensure the task completer does not remove it from ViPR ExportMask/Group.
((ExportMaskRemoveInitiatorCompleter) taskCompleter).removeInitiator(initiator);
break;
default:
}
} catch (Exception e) {
_log.error("Exception caught while running rollback", e);
throw e;
}
}
}
}
use of com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext.ExportOperationContextOperation in project coprhd-controller by CoprHD.
the class VNXeExportOperations method removeInitiators.
@Override
public void removeInitiators(StorageSystem storage, URI exportMask, List<URI> volumeURIList, List<Initiator> initiators, List<URI> targets, TaskCompleter taskCompleter) throws DeviceControllerException {
_logger.info("{} removeInitiators START...", storage.getSerialNumber());
ExportMask mask = _dbClient.queryObject(ExportMask.class, exportMask);
if (mask == null || mask.getInactive()) {
_logger.error(String.format("The exportMask %s is invalid.", exportMask));
throw DeviceControllerException.exceptions.invalidObjectNull();
}
boolean isRollback = WorkflowService.getInstance().isStepInRollbackState(taskCompleter.getOpId());
if (isRollback) {
List<Initiator> addedInitiators = 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) {
_logger.info("Handling removeInitiators as a result of rollback");
ListIterator li = context.getOperations().listIterator(context.getOperations().size());
while (li.hasPrevious()) {
ExportOperationContextOperation operation = (ExportOperationContextOperation) li.previous();
if (operation != null && VNXeExportOperationContext.OPERATION_ADD_INITIATORS_TO_HOST.equals(operation.getOperation())) {
addedInitiators = (List<Initiator>) operation.getArgs().get(0);
_logger.info("Removing initiators {} as part of rollback", Joiner.on(',').join(addedInitiators));
}
}
}
// Update the initiators in the task completer such that we update the export mask/group correctly
for (Initiator initiator : initiators) {
if (addedInitiators == null || !addedInitiators.contains(initiator)) {
((ExportMaskRemoveInitiatorCompleter) taskCompleter).removeInitiator(initiator.getId());
}
}
initiators = addedInitiators;
if (initiators == null || initiators.isEmpty()) {
_logger.info("There was no context found for add initiator. So there is nothing to rollback.");
taskCompleter.ready(_dbClient);
return;
}
}
StringSet initiatorsInMask = mask.getInitiators();
List<Initiator> initiatorToBeRemoved = new ArrayList<>();
for (Initiator initiator : initiators) {
if (initiatorsInMask.contains(initiator.getId().toString())) {
initiatorToBeRemoved.add(initiator);
}
}
try {
VNXeApiClient apiClient = getVnxeClient(storage);
List<Initiator> allInitiators = ExportUtils.getExportMaskInitiators(exportMask, _dbClient);
String vnxeHostId = getHostIdFromInitiators(allInitiators, apiClient);
if (vnxeHostId != null) {
List<VNXeHostInitiator> vnxeInitiators = apiClient.getInitiatorsByHostId(vnxeHostId);
// initiators is a subset of allInitiators
Map<Initiator, VNXeHostInitiator> vnxeInitiatorsToBeRemoved = prepareInitiators(initiatorToBeRemoved);
Set<String> initiatorIds = new HashSet<String>();
for (VNXeHostInitiator vnxeInit : vnxeInitiators) {
initiatorIds.add(vnxeInit.getInitiatorId());
}
Set<String> initiatorsToBeRemoved = new HashSet<String>();
for (VNXeHostInitiator vnxeInit : vnxeInitiatorsToBeRemoved.values()) {
String initiatorId = vnxeInit.getId();
if (initiatorIds.remove(initiatorId)) {
initiatorsToBeRemoved.add(initiatorId);
}
}
ExportMaskValidationContext ctx = new ExportMaskValidationContext();
ctx.setStorage(storage);
ctx.setExportMask(mask);
ctx.setBlockObjects(volumeURIList, _dbClient);
// Allow exceptions to be thrown when not rolling back
ctx.setAllowExceptions(!isRollback);
AbstractVNXeValidator removeInitiatorsValidator = (AbstractVNXeValidator) validator.removeInitiators(ctx);
removeInitiatorsValidator.setHostId(vnxeHostId);
removeInitiatorsValidator.validate();
// 3. shared initiators, but all export masks have same set of initiators
if (!isRollback) {
boolean hasSharedInitiator = false;
for (Initiator initiator : initiatorToBeRemoved) {
if (ExportUtils.isInitiatorSharedByMasks(_dbClient, mask, initiator.getId())) {
hasSharedInitiator = true;
break;
}
}
if (hasSharedInitiator) {
validateAllMasks(_dbClient, mask, apiClient, vnxeHostId);
}
}
}
List<String> initiatorIdList = new ArrayList<>();
for (Initiator initiator : initiatorToBeRemoved) {
_logger.info("Processing initiator {}", initiator.getLabel());
if (vnxeHostId != null) {
String initiatorId = initiator.getInitiatorPort();
if (Protocol.FC.name().equals(initiator.getProtocol())) {
initiatorId = initiator.getInitiatorNode() + ":" + initiatorId;
}
initiatorIdList.add(initiatorId);
}
mask.removeFromExistingInitiators(initiator);
mask.removeFromUserCreatedInitiators(initiator);
}
if (!initiatorIdList.isEmpty()) {
apiClient.deleteInitiators(initiatorIdList);
}
_dbClient.updateObject(mask);
taskCompleter.ready(_dbClient);
} catch (Exception e) {
_logger.error("Problem in removeInitiators: ", e);
ServiceError serviceError = DeviceControllerErrors.vnxe.jobFailed("removeInitiator", e.getMessage());
taskCompleter.error(_dbClient, serviceError);
}
_logger.info("{} removeInitiators END...", storage.getSerialNumber());
}
Aggregations