use of com.emc.storageos.exceptions.DeviceControllerException in project coprhd-controller by CoprHD.
the class HDSExportOperations method removeVolumes.
@Override
public void removeVolumes(StorageSystem storage, URI exportMaskURI, List<URI> volumes, List<Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
log.info("{} removeVolumes START...", storage.getSerialNumber());
try {
log.info("removeVolumes: Export mask id: {}", exportMaskURI);
log.info("removeVolumes: volumes: {}", Joiner.on(',').join(volumes));
if (initiatorList != null) {
log.info("removeVolumes: impacted initiators: {}", Joiner.on(",").join(initiatorList));
}
HDSApiClient hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storage), storage.getSmisUserName(), storage.getSmisPassword());
HDSApiExportManager exportMgr = hdsApiClient.getHDSApiExportManager();
String systemObjectID = HDSUtils.getSystemObjectID(storage);
ExportMask exportMask = dbClient.queryObject(ExportMask.class, exportMaskURI);
if (CollectionUtils.isEmpty(exportMask.getDeviceDataMap())) {
log.info("HSD's are not found in the exportMask {} device DataMap.", exportMask.getId());
taskCompleter.ready(dbClient);
}
// Get the context from the task completer, in case this is a rollback.
boolean isRollback = WorkflowService.getInstance().isStepInRollbackState(taskCompleter.getOpId());
ExportMaskValidationContext ctx = new ExportMaskValidationContext();
ctx.setStorage(storage);
ctx.setExportMask(exportMask);
ctx.setBlockObjects(volumes, dbClient);
ctx.setInitiators(initiatorList);
// Allow exceptions to be thrown when not rolling back
ctx.setAllowExceptions(!isRollback);
AbstractHDSValidator removeVolumeFromMaskValidator = (AbstractHDSValidator) validator.removeVolumes(ctx);
removeVolumeFromMaskValidator.validate();
StringSetMap deviceDataMap = exportMask.getDeviceDataMap();
Set<String> hsdList = deviceDataMap.keySet();
List<Path> pathObjectIdList = new ArrayList<Path>();
if (null == hsdList || hsdList.isEmpty()) {
throw HDSException.exceptions.notAbleToFindHostStorageDomain(systemObjectID);
}
if (null != exportMask && !exportMask.getInactive()) {
for (String hsdObjectId : hsdList) {
HostStorageDomain hsd = exportMgr.getHostStorageDomain(systemObjectID, hsdObjectId);
if (null == hsd) {
log.warn("Couldn't find the HSD {} to remove volume from ExportMask", hsdObjectId);
continue;
}
if (null != hsd.getPathList() && !hsd.getPathList().isEmpty()) {
pathObjectIdList.addAll(getPathObjectIdsFromHsd(hsd, volumes));
}
}
if (!pathObjectIdList.isEmpty()) {
hdsApiClient.getHDSBatchApiExportManager().deleteLUNPathsFromStorageSystem(systemObjectID, pathObjectIdList, storage.getModel());
} else {
log.info("No volumes found on system: {}", systemObjectID);
}
}
// Update the status after deleting the volume from all HSD's.
taskCompleter.ready(dbClient);
} catch (Exception e) {
log.error(String.format("removeVolume failed - maskURI: %s", exportMaskURI.toString()), e);
ServiceError serviceError = DeviceControllerException.errors.jobFailedMsg(e.getMessage(), e);
taskCompleter.error(dbClient, serviceError);
}
log.info("{} removeVolumes END...", storage.getSerialNumber());
}
use of com.emc.storageos.exceptions.DeviceControllerException in project coprhd-controller by CoprHD.
the class HDSExportOperations method findExportMasks.
@Override
public Map<String, Set<URI>> findExportMasks(StorageSystem storage, List<String> initiatorNames, boolean mustHaveAllPorts) throws DeviceControllerException {
Map<String, Set<URI>> matchingMasks = new HashMap<String, Set<URI>>();
log.info("finding export masks for storage {}", storage.getId());
String systemObjectID = HDSUtils.getSystemObjectID(storage);
Map<URI, Set<HostStorageDomain>> matchedHostHSDsMap = new HashMap<URI, Set<HostStorageDomain>>();
Map<URI, Set<URI>> hostToInitiatorMap = new HashMap<URI, Set<URI>>();
Map<URI, Set<String>> matchedHostInitiators = new HashMap<URI, Set<String>>();
try {
HDSApiClient client = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storage), storage.getSmisUserName(), storage.getSmisPassword());
HDSApiExportManager exportManager = client.getHDSApiExportManager();
List<HostStorageDomain> hsdList = exportManager.getHostStorageDomains(systemObjectID);
for (HostStorageDomain hsd : hsdList) {
List<String> initiatorsExistsOnHSD = getInitiatorsExistsOnHSD(hsd.getWwnList(), hsd.getIscsiList());
// Find out if the port is in this masking container
for (String initiatorName : initiatorNames) {
String normalizedName = initiatorName.replace(HDSConstants.COLON, HDSConstants.DOT_OPERATOR);
if (initiatorsExistsOnHSD.contains(normalizedName)) {
log.info("Found a matching HSD for {}", initiatorName);
Initiator initiator = fetchInitiatorByName(initiatorName);
Set<HostStorageDomain> matchedHSDs = matchedHostHSDsMap.get(initiator.getHost());
if (matchedHSDs == null) {
matchedHSDs = new HashSet<HostStorageDomain>();
matchedHostHSDsMap.put(initiator.getHost(), matchedHSDs);
}
matchedHSDs.add(hsd);
Set<String> matchedInitiators = matchedHostInitiators.get(initiator.getHost());
if (null == matchedInitiators) {
matchedInitiators = new HashSet<String>();
matchedHostInitiators.put(initiator.getHost(), matchedInitiators);
}
matchedInitiators.add(initiatorName);
}
}
}
hsdList.clear();
log.info("matchedHSDs: {}", matchedHostHSDsMap);
log.info("initiatorURIToNameMap: {}", matchedHostInitiators);
processInitiators(initiatorNames, hostToInitiatorMap);
List<URI> activeMaskIdsInDb = dbClient.queryByType(ExportMask.class, true);
List<ExportMask> activeMasks = dbClient.queryObject(ExportMask.class, activeMaskIdsInDb);
if (null != matchedHostHSDsMap && !matchedHostHSDsMap.isEmpty()) {
// Iterate through each host
for (URI hostURI : hostToInitiatorMap.keySet()) {
Set<URI> hostInitiators = hostToInitiatorMap.get(hostURI);
boolean isNewExportMask = false;
// Create single ExportMask for each host-varray combination
List<ExportMask> exportMaskWithHostInitiators = fetchExportMasksFromDB(activeMasks, hostInitiators, storage);
Set<HostStorageDomain> hsds = matchedHostHSDsMap.get(hostURI);
if (!CollectionUtils.isEmpty(hsds)) {
for (HostStorageDomain hsd : hsds) {
String storagePortOFHDSURI = getStoragePortURIs(Arrays.asList(hsd.getPortID()), storage).get(0);
ExportMask maskForHSD = null;
for (ExportMask exportMaskhavingInitiators : exportMaskWithHostInitiators) {
if (exportMaskhavingInitiators.getStoragePorts().contains(storagePortOFHDSURI)) {
maskForHSD = exportMaskhavingInitiators;
break;
}
}
if (null == maskForHSD) {
// first get the varrays associated with the storage port of the HSD and then check if
// any of the export masks have storage ports, which have virtual arrays overlapping with the virtual
// arrays of the HSD storage port
// NOTE: If the storageport is assigned to multiple varrays, then maintaining one
// export mask per varray is not possible. Proper seggregation has to be done.
StringSet varraysAssociatedWithHSDStoragePort = getTaggedVarrays(storagePortOFHDSURI);
if (!varraysAssociatedWithHSDStoragePort.isEmpty()) {
boolean bMaskFound = false;
for (ExportMask exportMaskhavingInitiators : exportMaskWithHostInitiators) {
for (String storagePortUriIter : exportMaskhavingInitiators.getStoragePorts()) {
// get the storage port entity
StringSet varraysOfStoragePort = getTaggedVarrays(storagePortUriIter);
if (StringSetUtil.hasIntersection(varraysOfStoragePort, varraysAssociatedWithHSDStoragePort)) {
maskForHSD = exportMaskhavingInitiators;
// Ingest the foreign HSD into a matching export mask with same host and varray combination
bMaskFound = true;
break;
}
}
if (bMaskFound) {
break;
}
}
} else {
// Since this HSD port is not tagged to any varray, we will not ingest it
continue;
}
if (null == maskForHSD) {
// No matching export mask found for the same host and varray combination. Creating a new export mask.
isNewExportMask = true;
maskForHSD = new ExportMask();
maskForHSD.setId(URIUtil.createId(ExportMask.class));
maskForHSD.setStorageDevice(storage.getId());
maskForHSD.setCreatedBySystem(false);
}
}
Set<HostStorageDomain> hsdSet = new HashSet<>();
hsdSet.add(hsd);
updateHSDInfoInExportMask(maskForHSD, hostInitiators, hsdSet, storage, matchingMasks);
if (isNewExportMask) {
dbClient.createObject(maskForHSD);
exportMaskWithHostInitiators.add(maskForHSD);
} else {
ExportMaskUtils.sanitizeExportMaskContainers(dbClient, maskForHSD);
dbClient.updateObject(maskForHSD);
}
updateMatchingMasksForHost(matchedHostInitiators.get(hostURI), maskForHSD, matchingMasks);
}
}
}
}
} catch (Exception e) {
log.error("Error when attempting to query LUN masking information", e);
throw HDSException.exceptions.queryExistingMasksFailure(e.getMessage());
}
log.info("Found matching masks: {}", matchingMasks);
return matchingMasks;
}
use of com.emc.storageos.exceptions.DeviceControllerException in project coprhd-controller by CoprHD.
the class HDSExportOperations method addInitiators.
@Override
public void addInitiators(StorageSystem storage, URI exportMaskURI, List<URI> volumeURIs, List<Initiator> initiators, List<URI> targetURIList, TaskCompleter taskCompleter) throws DeviceControllerException {
log.info("{} addInitiator START...", storage.getSerialNumber());
HDSApiClient hdsApiClient = null;
String systemObjectID = null;
List<HostStorageDomain> hsdsToCreate = null;
List<HostStorageDomain> hsdsWithInitiators = null;
try {
log.info("addInitiator: Export mask id: {}", exportMaskURI);
if (volumeURIs != null) {
log.info("addInitiator: volumes : {}", Joiner.on(',').join(volumeURIs));
}
log.info("addInitiator: initiators : {}", Joiner.on(',').join(initiators));
log.info("addInitiator: targets : {}", Joiner.on(",").join(targetURIList));
hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storage), storage.getSmisUserName(), storage.getSmisPassword());
HDSApiExportManager exportMgr = hdsApiClient.getHDSApiExportManager();
systemObjectID = HDSUtils.getSystemObjectID(storage);
ExportMask exportMask = dbClient.queryObject(ExportMask.class, exportMaskURI);
List<StoragePort> ports = dbClient.queryObject(StoragePort.class, targetURIList, true);
if (checkIfMixedTargetPortTypeSelected(ports)) {
log.error("Unsupported Host as it has both FC & iSCSI Initiators");
throw HDSException.exceptions.unsupportedConfigurationFoundInHost();
}
// @TODO register new initiators by adding them to host on HiCommand DM.
// Currently, HiCommand is not supporting this. Need to see how we can handle.
String hostName = getHostNameForInitiators(initiators);
String hostMode = null, hostModeOption = null;
Pair<String, String> hostModeInfo = getHostModeInfo(storage, initiators);
if (hostModeInfo != null) {
hostMode = hostModeInfo.first;
hostModeOption = hostModeInfo.second;
}
if (targetURIList != null && !targetURIList.isEmpty()) {
Set<URI> newTargetPorts = new HashSet<>(targetURIList);
Set<URI> existingTargetPortsInMask = new HashSet<>();
if (exportMask.getStoragePorts() != null) {
existingTargetPortsInMask = new HashSet<>(targetURIList);
Collection<URI> targetPorts = Collections2.transform(exportMask.getStoragePorts(), CommonTransformerFunctions.FCTN_STRING_TO_URI);
existingTargetPortsInMask.retainAll(targetPorts);
}
newTargetPorts.removeAll(existingTargetPortsInMask);
log.info("list of new storage target ports {}", newTargetPorts);
log.info("list of existing storage target ports available in export masks {}", existingTargetPortsInMask);
// Case 1 is handled here for the new initiators & new target ports.
if (!newTargetPorts.isEmpty()) {
// If the HLU's are already configured on this target port, then an exception is thrown.
// User should make sure that all volumes should have same HLU across all target HSD's.
VolumeURIHLU[] volumeURIHLUs = getVolumeURIHLUFromExportMask(exportMask);
if (0 < volumeURIHLUs.length) {
List<URI> portList = new ArrayList<>(newTargetPorts);
hsdsToCreate = processTargetPortsToFormHSDs(hdsApiClient, storage, portList, hostName, exportMask, hostModeInfo, systemObjectID);
// Step 1: Create all HSD's using batch operation.
List<HostStorageDomain> hsdResponseList = hdsApiClient.getHDSBatchApiExportManager().addHostStorageDomains(systemObjectID, hsdsToCreate, storage.getModel());
if (null == hsdResponseList || hsdResponseList.isEmpty()) {
log.error("Batch HSD creation failed to add new initiators. Aborting operation...");
throw HDSException.exceptions.notAbleToAddHSD(storage.getSerialNumber());
}
// Step 2: Add initiators to all HSD's.
Iterator<StoragePort> storagePortIterator = dbClient.queryIterativeObjects(StoragePort.class, newTargetPorts);
List<StoragePort> stPortList = new ArrayList<>();
while (storagePortIterator.hasNext()) {
StoragePort stPort = storagePortIterator.next();
if (stPort != null && !stPort.getInactive()) {
stPortList.add(stPort);
}
}
hsdsWithInitiators = executeBatchHSDAddInitiatorsCommand(hdsApiClient, systemObjectID, hsdResponseList, stPortList, initiators, storage.getModel());
// Step 3: Add volumes to all HSD's.
List<Path> allHSDPaths = executeBatchHSDAddVolumesCommand(hdsApiClient, systemObjectID, hsdsWithInitiators, volumeURIHLUs, storage.getModel());
if (null != allHSDPaths && !allHSDPaths.isEmpty()) {
updateExportMaskDetailInDB(hsdsWithInitiators, allHSDPaths, exportMask, storage, volumeURIHLUs);
}
} else {
log.info("There are no volumes on this exportmask: {} to add to new initiator", exportMaskURI);
}
}
// existing HSD to access the volumes already exported in the exportmask.
if (!existingTargetPortsInMask.isEmpty()) {
// Step 1: Collect all HSDs from export mask
StringSetMap deviceDataMap = exportMask.getDeviceDataMap();
if (null != deviceDataMap && !deviceDataMap.isEmpty()) {
List<HostStorageDomain> hsdResponseList = new ArrayList<>();
Set<String> hsdObjectIdSet = deviceDataMap.keySet();
for (String hsdObjectId : hsdObjectIdSet) {
HostStorageDomain hsd = exportMgr.getHostStorageDomain(systemObjectID, hsdObjectId);
if (null == hsd) {
throw HDSException.exceptions.notAbleToFindHostStorageDomain(hsdObjectId);
}
hsdResponseList.add(hsd);
}
// Step 2: Add initiators to all HSD's.
Iterator<StoragePort> storagePortIterator = dbClient.queryIterativeObjects(StoragePort.class, existingTargetPortsInMask, true);
List<StoragePort> stPortList = new ArrayList<>();
while (storagePortIterator.hasNext()) {
StoragePort stPort = storagePortIterator.next();
if (stPort != null) {
stPortList.add(stPort);
}
}
hsdsWithInitiators = executeBatchHSDAddInitiatorsCommand(hdsApiClient, systemObjectID, hsdResponseList, stPortList, initiators, storage.getModel());
} else {
log.info("There are no hsd information in exportMask to add initiators");
}
}
}
taskCompleter.ready(dbClient);
} catch (Exception ex) {
try {
log.info("Exception occurred while adding new initiators: {}", ex.getMessage());
if (null != hsdsWithInitiators && !hsdsWithInitiators.isEmpty()) {
hdsApiClient.getHDSBatchApiExportManager().deleteBatchHostStorageDomains(systemObjectID, hsdsWithInitiators, storage.getModel());
} else {
if (null != hsdsToCreate && !hsdsToCreate.isEmpty()) {
List<HostStorageDomain> allHSDs = hdsApiClient.getHDSApiExportManager().getHostStorageDomains(systemObjectID);
List<HostStorageDomain> partialHSDListToRemove = getPartialHSDListToDelete(allHSDs, hsdsToCreate);
hdsApiClient.getHDSBatchApiExportManager().deleteBatchHostStorageDomains(systemObjectID, partialHSDListToRemove, storage.getModel());
}
}
log.error(String.format("addInitiator failed - maskURI: %s", exportMaskURI.toString()), ex);
} catch (Exception ex1) {
log.error("Exception occurred while deleting unsuccessful HSDs on system: {}", systemObjectID, ex1.getMessage());
} finally {
ServiceError serviceError = DeviceControllerException.errors.jobFailedOpMsg(ResourceOperationTypeEnum.ADD_EXPORT_INITIATOR.getName(), ex.getMessage());
taskCompleter.error(dbClient, serviceError);
}
}
log.info("{} addInitiator END...", storage.getSerialNumber());
}
use of com.emc.storageos.exceptions.DeviceControllerException in project coprhd-controller by CoprHD.
the class VnxMaskingOrchestrator method exportGroupCreate.
/**
* Create storage level masking components to support the requested
* ExportGroup object. This operation will be flexible enough to take into
* account initiators that are in some already existent in some
* StorageGroup. In such a case, the underlying masking component will be
* "adopted" by the ExportGroup. Further operations against the "adopted"
* mask will only allow for addition and removal of those initiators/volumes
* that were added by a Bourne request. Existing initiators/volumes will be
* maintained.
*
* @param storageURI
* - URI referencing underlying storage array
* @param exportGroupURI
* - URI referencing Bourne-level masking, ExportGroup
* @param initiatorURIs
* - List of Initiator URIs
* @param volumeMap
* - Map of Volume URIs to requested Integer URI
* @param token
* - Identifier for operation
* @throws Exception
*/
@Override
public void exportGroupCreate(URI storageURI, URI exportGroupURI, List<URI> initiatorURIs, Map<URI, Integer> volumeMap, String token) throws Exception {
ExportOrchestrationTask taskCompleter = null;
try {
BlockStorageDevice device = getDevice();
ExportGroup exportGroup = _dbClient.queryObject(ExportGroup.class, exportGroupURI);
StorageSystem storage = _dbClient.queryObject(StorageSystem.class, storageURI);
taskCompleter = new ExportOrchestrationTask(exportGroupURI, token);
logExportGroup(exportGroup, storageURI);
if (initiatorURIs != null && !initiatorURIs.isEmpty()) {
_log.info("export_create: initiator list non-empty");
// Set up workflow steps.
Workflow workflow = _workflowService.getNewWorkflow(MaskingWorkflowEntryPoints.getInstance(), "exportGroupCreate", true, token);
boolean createdSteps = determineExportGroupCreateSteps(workflow, null, device, storage, exportGroup, initiatorURIs, volumeMap, false, token);
String zoningStep = generateDeviceSpecificZoningCreateWorkflow(workflow, EXPORT_GROUP_MASKING_TASK, exportGroup, null, volumeMap);
if (createdSteps && null != zoningStep) {
// Execute the plan and allow the WorkflowExecutor to fire the
// taskCompleter.
String successMessage = String.format("ExportGroup successfully applied for StorageArray %s", storage.getLabel());
workflow.executePlan(taskCompleter, successMessage);
} else {
_log.info("export_create: no steps created.");
taskCompleter.ready(_dbClient);
}
} else {
_log.info("export_create: initiator list");
taskCompleter.ready(_dbClient);
}
} catch (DeviceControllerException dex) {
if (taskCompleter != null) {
taskCompleter.error(_dbClient, DeviceControllerException.errors.vmaxExportGroupCreateError(dex.getMessage()));
}
} catch (Exception ex) {
_log.error("ExportGroup Orchestration failed.", ex);
// TODO add service code here
if (taskCompleter != null) {
ServiceError serviceError = DeviceControllerException.errors.jobFailedMsg(ex.getMessage(), ex);
taskCompleter.error(_dbClient, serviceError);
}
}
}
use of com.emc.storageos.exceptions.DeviceControllerException in project coprhd-controller by CoprHD.
the class BlockConsistencyGroupAddVolumeCompleter method complete.
@Override
protected void complete(DbClient dbClient, Status status, ServiceCoded coded) throws DeviceControllerException {
log.info("Updating add volume replicationGroupInstance");
try {
super.complete(dbClient, status, coded);
if (status == Status.ready) {
BlockConsistencyGroup cg = dbClient.queryObject(BlockConsistencyGroup.class, getId());
if (groupName == null) {
groupName = (cg.getAlternateLabel() != null) ? cg.getAlternateLabel() : cg.getLabel();
}
VolumeGroup volumeGroup = ControllerUtils.getApplicationForCG(dbClient, cg, groupName);
for (URI voluri : addVolumeList) {
Volume volume = dbClient.queryObject(Volume.class, voluri);
if (volume != null && !volume.getInactive()) {
boolean isFullCopy = ControllerUtils.isVolumeFullCopy(volume, dbClient);
if (!isFullCopy) {
volume.setReplicationGroupInstance(groupName);
volume.setConsistencyGroup(this.getConsistencyGroupURI());
boolean isVplexBackendVolume = Volume.checkForVplexBackEndVolume(dbClient, volume);
if (volumeGroup != null && !isVplexBackendVolume) {
// do not set Application Id on VPLEX backend volume
volume.getVolumeGroupIds().add(volumeGroup.getId().toString());
}
// instance on the parent virtual volume
if (isVplexBackendVolume) {
Volume virtualVolume = Volume.fetchVplexVolume(dbClient, volume);
if (null != virtualVolume) {
if (!groupName.equals(virtualVolume.getBackingReplicationGroupInstance())) {
virtualVolume.setBackingReplicationGroupInstance(groupName);
dbClient.updateObject(virtualVolume);
}
}
}
dbClient.updateObject(volume);
}
}
}
}
} catch (Exception e) {
log.error("Failed updating status. BlockConsistencyGroupRemoveVolume {}, for task " + getOpId(), getId(), e);
}
}
Aggregations