use of com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportRemoveInitiatorCompleter in project coprhd-controller by CoprHD.
the class BlockStorageDeviceTest method testExportRemoveInitiators.
@Test
public void testExportRemoveInitiators() {
ExportGroup exportGroup = getExportGroup();
ExportMask exportMask = getExportMask();
List<Initiator> initiators = getInitiators();
List<URI> initiatorURIs = new ArrayList<URI>();
List<Initiator> initiatorArgs = new ArrayList<Initiator>();
for (Initiator initiator : initiators) {
if (initiator.getInitiatorPort().endsWith("1")) {
initiatorURIs.add(initiator.getId());
initiatorArgs.add(initiator);
}
}
String token = UUID.randomUUID().toString() + UUID.randomUUID().toString();
ExportTaskCompleter taskCompleter = new ExportRemoveInitiatorCompleter(exportGroup.getId(), initiatorURIs, token);
_deviceController.doExportRemoveInitiators(_storageSystem, exportMask, null, initiators, null, taskCompleter);
}
use of com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportRemoveInitiatorCompleter in project coprhd-controller by CoprHD.
the class VPlexDeviceController method exportGroupRemoveInitiators.
/*
* (non-Javadoc)
*
* @see com.emc.storageos.volumecontroller.impl.vplex.VplexController#exportRemoveInitiator(java.net.URI,
* java.net.URI, java.net.URI,
* java.lang.String)
*/
@Override
public void exportGroupRemoveInitiators(URI vplexURI, URI exportURI, List<URI> initiatorURIs, String opId) throws ControllerException {
try {
StorageSystem vplex = getDataObject(StorageSystem.class, vplexURI, _dbClient);
ExportGroup exportGroup = getDataObject(ExportGroup.class, exportURI, _dbClient);
ExportRemoveInitiatorCompleter completer = new ExportRemoveInitiatorCompleter(exportURI, initiatorURIs, opId);
Workflow workflow = _workflowService.getNewWorkflow(this, "exportRemoveInitiator", true, opId);
// true if Workflow has a Step
boolean hasStep = false;
Initiator firstInitiator = _dbClient.queryObject(Initiator.class, initiatorURIs.get(0));
StringBuffer errorMessages = new StringBuffer();
boolean isValidationNeeded = validatorConfig.isValidationEnabled() && !ExportUtils.checkIfInitiatorsForRP(Arrays.asList(firstInitiator));
_log.info("Orchestration level validation needed : {}", isValidationNeeded);
_log.info("starting remove initiators for export group: " + exportGroup.toString());
_log.info("request is to remove these initiators: " + initiatorURIs);
initiatorURIs = VPlexUtil.filterInitiatorsForVplex(_dbClient, initiatorURIs);
// get a map of host URI to a list of Initiators in that Host
Map<URI, List<Initiator>> hostInitiatorsMap = VPlexUtil.makeHostInitiatorsMap(initiatorURIs, _dbClient);
VPlexApiClient client = getVPlexAPIClient(_vplexApiFactory, vplex, _dbClient);
// Loop, processing each host separately.
for (URI hostURI : hostInitiatorsMap.keySet()) {
_log.info("setting up initiator removal for host " + hostURI);
// Get the initiators (and initiator URIs) for this host
List<Initiator> initiators = hostInitiatorsMap.get(hostURI);
// Find the ExportMask for my host.
List<ExportMask> exportMasks = getExportMaskForHost(exportGroup, hostURI, vplexURI);
if (exportMasks == null || exportMasks.isEmpty()) {
// If there is no ExportMask for this host, there is nothing to do.
_log.info("No export mask found for hostURI: " + hostURI);
continue;
}
String lastStep = null;
List<URI> initiatorsAlreadyRemovedFromExportGroup = new ArrayList<URI>();
for (ExportMask exportMask : exportMasks) {
_log.info("adding remove initiators steps for " + "export mask / storage view: " + exportMask.getMaskName());
String vplexClusterName = VPlexUtil.getVplexClusterName(exportMask, vplexURI, client, _dbClient);
Map<String, String> targetPortToPwwnMap = VPlexControllerUtils.getTargetPortToPwwnMap(client, vplexClusterName);
VPlexStorageViewInfo storageView = client.getStorageView(vplexClusterName, exportMask.getMaskName());
_log.info("Refreshing ExportMask {}", exportMask.getMaskName());
VPlexControllerUtils.refreshExportMask(_dbClient, storageView, exportMask, targetPortToPwwnMap, _networkDeviceController);
// initiator filter logic is move inside addStepsForRemoveInitiators and addStepsForInitiatorRemoval as
// it is not required for zone related operation.
// validate the remove initiator operation against the export mask volumes
List<URI> volumeURIList = (exportMask.getUserAddedVolumes() != null) ? URIUtil.toURIList(exportMask.getUserAddedVolumes().values()) : new ArrayList<URI>();
if (volumeURIList.isEmpty()) {
_log.warn("volume URI list for validating remove initiators is empty...");
}
ExportMaskValidationContext ctx = new ExportMaskValidationContext();
ctx.setStorage(vplex);
ctx.setExportMask(exportMask);
ctx.setBlockObjects(volumeURIList, _dbClient);
ctx.setAllowExceptions(!WorkflowService.getInstance().isStepInRollbackState(opId));
validator.removeInitiators(ctx).validate();
lastStep = addStepsForRemoveInitiators(vplex, workflow, completer, exportGroup, exportMask, initiators, hostURI, initiatorsAlreadyRemovedFromExportGroup, errorMessages, lastStep);
if (lastStep != null) {
hasStep = true;
}
}
}
String message = errorMessages.toString();
if (isValidationNeeded && !message.isEmpty()) {
_log.error("Error Message {}", errorMessages);
List<String> initiatorNames = new ArrayList<String>();
for (URI initiatorURI : initiatorURIs) {
Initiator initiator = _dbClient.queryObject(Initiator.class, initiatorURI);
if (initiator != null) {
String normalizedName = Initiator.normalizePort(initiator.getInitiatorPort());
initiatorNames.add(normalizedName);
} else {
_log.warn("no initiator found for URI {}", initiatorURI);
}
}
throw DeviceControllerException.exceptions.removeInitiatorValidationError(Joiner.on(", ").join(initiatorNames), vplex.getLabel(), message);
}
// Fire off the workflow if there were initiators to delete. Otherwise just fire completer.
if (hasStep) {
workflow.executePlan(completer, "Successfully removed initiators: " + initiatorURIs.toString());
} else {
_log.info(String.format("No updates to ExportMasks needed... complete"));
completer.ready(_dbClient);
}
} catch (VPlexApiException vae) {
_log.error("Exception in exportRemoveInitiators: " + initiatorURIs.toString(), vae);
WorkflowStepCompleter.stepFailed(opId, vae);
} catch (Exception ex) {
_log.error("Exception in exportRemoveInitiators: " + initiatorURIs.toString(), ex);
String opName = ResourceOperationTypeEnum.DELETE_EXPORT_INITIATOR.getName();
ServiceError serviceError = VPlexApiException.errors.exportGroupRemoveInitiatorsFailed(opName, ex);
WorkflowStepCompleter.stepFailed(opId, serviceError);
}
}
use of com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportRemoveInitiatorCompleter in project coprhd-controller by CoprHD.
the class BlockStorageDeviceTest method testExportRemoveInitiator.
@Test
public void testExportRemoveInitiator() {
ExportGroup exportGroup = getExportGroup();
ExportMask exportMask = getExportMask();
Initiator initiator = getInitiators().get(0);
;
List<URI> initiatorURIs = new ArrayList<URI>(1);
initiatorURIs.add(initiator.getId());
String token = UUID.randomUUID().toString() + UUID.randomUUID().toString();
ExportTaskCompleter taskCompleter = new ExportRemoveInitiatorCompleter(exportGroup.getId(), initiatorURIs, token);
_deviceController.doExportRemoveInitiator(_storageSystem, exportMask, null, initiator, null, taskCompleter);
}
Aggregations