use of com.emc.storageos.hds.api.HDSApiExportManager in project coprhd-controller by CoprHD.
the class HDSExportOperations method refreshExportMask.
@Override
public ExportMask refreshExportMask(StorageSystem storage, ExportMask mask) throws DeviceControllerException {
try {
HDSApiClient client = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storage), storage.getSmisUserName(), storage.getSmisPassword());
HDSApiExportManager exportManager = client.getHDSApiExportManager();
String systemObjectID = HDSUtils.getSystemObjectID(storage);
if (null != mask.getDeviceDataMap() && !mask.getDeviceDataMap().isEmpty()) {
Set<String> hsdList = mask.getDeviceDataMap().keySet();
StringBuilder builder = new StringBuilder();
Set<String> discoveredInitiators = new HashSet<String>();
String maskName = null;
Map<String, Integer> discoveredVolumes = new HashMap<String, Integer>();
for (String hsdObjectIdFromDb : hsdList) {
HostStorageDomain hsd = exportManager.getHostStorageDomain(systemObjectID, hsdObjectIdFromDb);
if (null == hsd) {
// If the HSD is removed using non-ViPR, update ViPR DB.
mask.getDeviceDataMap().remove(hsdObjectIdFromDb);
continue;
}
maskName = (null == hsd.getName()) ? hsd.getNickname() : hsd.getName();
// Get volumes and initiators for the masking instance
discoveredVolumes.putAll(HDSUtils.getVolumesFromHSD(hsd, storage));
discoveredInitiators.addAll(HDSUtils.getInitiatorsFromHSD(hsd));
}
Set existingInitiators = (mask.getExistingInitiators() != null) ? mask.getExistingInitiators() : Collections.emptySet();
Set existingVolumes = (mask.getExistingVolumes() != null) ? mask.getExistingVolumes().keySet() : Collections.emptySet();
builder.append(String.format("%nXM object: %s I{%s} V:{%s}%n", maskName, Joiner.on(',').join(existingInitiators), Joiner.on(',').join(existingVolumes)));
builder.append(String.format("XM discovered: %s I:{%s} V:{%s}%n", maskName, Joiner.on(',').join(discoveredInitiators), Joiner.on(',').join(discoveredVolumes.keySet())));
List<Initiator> initiatorList = new ArrayList<>();
if (!CollectionUtils.isEmpty(discoveredInitiators)) {
for (String port : discoveredInitiators) {
Initiator existingInitiator = ExportUtils.getInitiator(Initiator.toPortNetworkId(port), dbClient);
if (existingInitiator != null && !existingInitiator.getInactive()) {
initiatorList.add(existingInitiator);
}
}
}
mask.addInitiators(initiatorList);
dbClient.updateObject(mask);
List<String> initiatorsToAddToExisting = new ArrayList<String>();
List<Initiator> initiatorsToAddToUserAddedAndInitiatorList = new ArrayList<Initiator>();
/**
* For the newly discovered initiators, if they are ViPR discovered ports and belong to same resource
* add them to user added and initiators list, otherwise add to existing list.
*/
for (String port : discoveredInitiators) {
String normalizedPort = Initiator.normalizePort(port);
if (!mask.hasExistingInitiator(normalizedPort) && !mask.hasUserInitiator(normalizedPort)) {
Initiator existingInitiator = ExportUtils.getInitiator(Initiator.toPortNetworkId(port), dbClient);
// Don't add additional initiator to initiators list if it belongs to different host/cluster
if (existingInitiator != null && !ExportMaskUtils.checkIfDifferentResource(mask, existingInitiator)) {
log.info("Initiator {}->{} belonging to same compute, adding to userAdded and initiator list.", normalizedPort, existingInitiator.getId());
initiatorsToAddToUserAddedAndInitiatorList.add(existingInitiator);
} else {
initiatorsToAddToExisting.add(normalizedPort);
}
}
}
/**
* Get the existing initiators from the mask and remove the non-discovered ports because
* they are not discovered and are stale.
*
* If the mask has existing initiators but if they are discovered and belongs to same compute resource, then the
* initiators has to get added to user Added and initiators list, and removed from existing list.
*/
List<String> initiatorsToRemoveFromExistingList = new ArrayList<String>();
if (mask.getExistingInitiators() != null && !mask.getExistingInitiators().isEmpty()) {
for (String existingInitiatorStr : mask.getExistingInitiators()) {
if (!discoveredInitiators.contains(existingInitiatorStr)) {
initiatorsToRemoveFromExistingList.add(existingInitiatorStr);
} else {
Initiator existingInitiator = ExportUtils.getInitiator(Initiator.toPortNetworkId(existingInitiatorStr), dbClient);
if (existingInitiator != null && !ExportMaskUtils.checkIfDifferentResource(mask, existingInitiator)) {
log.info("Initiator {}->{} belonging to same compute, removing from existing," + " and adding to userAdded and initiator list", existingInitiatorStr, existingInitiator.getId());
initiatorsToAddToUserAddedAndInitiatorList.add(existingInitiator);
initiatorsToRemoveFromExistingList.add(existingInitiatorStr);
}
}
}
}
/**
* Get all the initiators from the mask and remove all the ViPR discovered ports.
* The remaining list has to be removed from user Added and initiator list, because they are not available in ViPR
* but has to be moved to existing list.
*/
List<URI> initiatorsToRemoveFromUserAddedAndInitiatorList = new ArrayList<URI>();
if (mask.getInitiators() != null && !mask.getInitiators().isEmpty()) {
initiatorsToRemoveFromUserAddedAndInitiatorList.addAll(transform(mask.getInitiators(), CommonTransformerFunctions.FCTN_STRING_TO_URI));
for (String port : discoveredInitiators) {
String normalizedPort = Initiator.normalizePort(port);
Initiator initiatorDiscoveredInViPR = ExportUtils.getInitiator(Initiator.toPortNetworkId(port), dbClient);
if (initiatorDiscoveredInViPR != null) {
initiatorsToRemoveFromUserAddedAndInitiatorList.remove(initiatorDiscoveredInViPR.getId());
} else if (!mask.hasExistingInitiator(normalizedPort)) {
log.info("Initiator {} not found in database, removing from user Added and initiator list," + " and adding to existing list.", port);
initiatorsToAddToExisting.add(normalizedPort);
}
}
}
boolean removeInitiators = !initiatorsToRemoveFromExistingList.isEmpty() || !initiatorsToRemoveFromUserAddedAndInitiatorList.isEmpty();
boolean addInitiators = !initiatorsToAddToUserAddedAndInitiatorList.isEmpty() || !initiatorsToAddToExisting.isEmpty();
// Check the volumes and update the lists as necessary
Map<String, Integer> volumesToAdd = ExportMaskUtils.diffAndFindNewVolumes(mask, discoveredVolumes);
boolean addVolumes = !volumesToAdd.isEmpty();
boolean removeVolumes = false;
List<String> volumesToRemove = new ArrayList<String>();
// if the volume is in export mask's user added volumes and also in the existing volumes, remove from existing volumes
for (String wwn : discoveredVolumes.keySet()) {
if (mask.hasExistingVolume(wwn)) {
URIQueryResultList volumeList = new URIQueryResultList();
dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVolumeWwnConstraint(wwn), volumeList);
if (volumeList.iterator().hasNext()) {
URI volumeURI = volumeList.iterator().next();
if (mask.hasUserCreatedVolume(volumeURI)) {
builder.append(String.format("\texisting volumes contain wwn %s, but it is also in the " + "export mask's user added volumes, so removing from existing volumes", wwn));
volumesToRemove.add(wwn);
}
}
}
}
if (mask.getExistingVolumes() != null && !mask.getExistingVolumes().isEmpty()) {
volumesToRemove.addAll(mask.getExistingVolumes().keySet());
volumesToRemove.removeAll(discoveredVolumes.keySet());
removeVolumes = !volumesToRemove.isEmpty();
}
// Update user added volume's HLU information in ExportMask and ExportGroup
ExportMaskUtils.updateHLUsInExportMask(mask, discoveredVolumes, dbClient);
builder.append(String.format("XM refresh: %s existing initiators; add:{%s} remove:{%s}%n", maskName, Joiner.on(',').join(initiatorsToAddToExisting), Joiner.on(',').join(initiatorsToRemoveFromExistingList)));
builder.append(String.format("XM refresh: %s user added and initiator list; add:{%s} remove:{%s}%n", maskName, Joiner.on(',').join(initiatorsToAddToUserAddedAndInitiatorList), Joiner.on(',').join(initiatorsToRemoveFromUserAddedAndInitiatorList)));
builder.append(String.format("XM refresh: %s volumes; add:{%s} remove:{%s}%n", maskName, Joiner.on(',').join(volumesToAdd.keySet()), Joiner.on(',').join(volumesToRemove)));
// Any changes indicated, then update the mask and persist it
if (addInitiators || removeInitiators || addVolumes || removeVolumes) {
builder.append("XM refresh: There are changes to mask, " + "updating it...\n");
if (!initiatorsToRemoveFromUserAddedAndInitiatorList.isEmpty()) {
mask.removeInitiatorURIs(initiatorsToRemoveFromUserAddedAndInitiatorList);
mask.removeFromUserAddedInitiatorsByURI(initiatorsToRemoveFromUserAddedAndInitiatorList);
}
List<Initiator> userAddedInitiators = ExportMaskUtils.findIfInitiatorsAreUserAddedInAnotherMask(mask, initiatorsToAddToUserAddedAndInitiatorList, dbClient);
mask.addToUserCreatedInitiators(userAddedInitiators);
builder.append(String.format("XM refresh: %s user added initiators; add:{%s} remove:{%s}%n", maskName, Joiner.on(',').join(userAddedInitiators), Joiner.on(',').join(initiatorsToRemoveFromUserAddedAndInitiatorList)));
mask.addInitiators(initiatorsToAddToUserAddedAndInitiatorList);
mask.addToUserCreatedInitiators(initiatorsToAddToUserAddedAndInitiatorList);
mask.addToExistingInitiatorsIfAbsent(initiatorsToAddToExisting);
mask.removeFromExistingInitiators(initiatorsToRemoveFromExistingList);
mask.removeFromExistingVolumes(volumesToRemove);
mask.addToExistingVolumesIfAbsent(volumesToAdd);
ExportMaskUtils.sanitizeExportMaskContainers(dbClient, mask);
builder.append("XM refresh: There are changes to mask, " + "updating it...\n");
dbClient.updateObject(mask);
} else {
builder.append("XM refresh: There are no changes to the mask\n");
}
_networkDeviceController.refreshZoningMap(mask, transform(initiatorsToRemoveFromUserAddedAndInitiatorList, CommonTransformerFunctions.FCTN_URI_TO_STRING), Collections.EMPTY_LIST, (addInitiators || removeInitiators), true);
log.info(builder.toString());
}
} catch (Exception e) {
log.error("Error when attempting to query HostStorageDomain information", e);
throw HDSException.exceptions.refreshExistingMaskFailure(mask.getLabel());
}
return mask;
}
use of com.emc.storageos.hds.api.HDSApiExportManager in project coprhd-controller by CoprHD.
the class HDSExportOperations 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());
List<HostStorageDomain> hsdToDeleteList = new ArrayList<HostStorageDomain>();
try {
log.info("deleteExportMask: 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));
}
// Get the context from the task completer, in case this is a rollback.
boolean isRollback = WorkflowService.getInstance().isStepInRollbackState(taskCompleter.getOpId());
ExportMask exportMask = dbClient.queryObject(ExportMask.class, exportMaskURI);
ExportMaskValidationContext ctx = new ExportMaskValidationContext();
ctx.setStorage(storage);
ctx.setExportMask(exportMask);
ctx.setBlockObjects(volumeURIList, dbClient);
ctx.setInitiators(initiatorList);
// Allow exceptions to be thrown when not rolling back
ctx.setAllowExceptions(!isRollback);
AbstractHDSValidator deleteMaskValidator = (AbstractHDSValidator) validator.exportMaskDelete(ctx);
deleteMaskValidator.validate();
HDSApiClient hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storage), storage.getSmisUserName(), storage.getSmisPassword());
HDSApiExportManager exportMgr = hdsApiClient.getHDSApiExportManager();
String systemObjectId = HDSUtils.getSystemObjectID(storage);
StringSetMap deviceDataMap = exportMask.getDeviceDataMap();
if (null != deviceDataMap && !deviceDataMap.isEmpty()) {
Set<String> hsdObjectIdList = deviceDataMap.keySet();
for (String hsdObjectIdFromDb : hsdObjectIdList) {
HostStorageDomain hsdObj = exportMgr.getHostStorageDomain(systemObjectId, hsdObjectIdFromDb);
if (null != hsdObj) {
hsdToDeleteList.add(hsdObj);
}
}
if (!hsdToDeleteList.isEmpty()) {
hdsApiClient.getHDSBatchApiExportManager().deleteBatchHostStorageDomains(systemObjectId, hsdToDeleteList, storage.getModel());
}
// By this time, we have removed all HSD's created in this mask.
taskCompleter.ready(dbClient);
} else {
String message = String.format("ExportMask %s does not have a configured HSD's, " + "indicating that this export may not have been created " + "successfully. Marking the delete operation ready.", exportMaskURI.toString());
log.info(message);
taskCompleter.ready(dbClient);
return;
}
} catch (Exception e) {
log.error("Unexpected error: deleteExportMask failed.", e);
ServiceError error = DeviceControllerErrors.hds.methodFailed("deleteExportMask", e.getMessage());
taskCompleter.error(dbClient, error);
}
log.info("{} deleteExportMask END...", storage.getSerialNumber());
}
use of com.emc.storageos.hds.api.HDSApiExportManager in project coprhd-controller by CoprHD.
the class HDSExportOperations method addVolumes.
@Override
public void addVolumes(StorageSystem storage, URI exportMaskURI, VolumeURIHLU[] volumeURIHLUs, List<Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
log.info("{} addVolumes START...", storage.getSerialNumber());
HDSApiClient hdsApiClient = null;
String systemObjectID = null;
try {
log.info("addVolumes: Export mask id: {}", exportMaskURI);
log.info("addVolumes: volume-HLU pairs: {}", Joiner.on(',').join(volumeURIHLUs));
if (initiatorList != null) {
log.info("addVolumes: initiators impacted: {}", Joiner.on(',').join(initiatorList));
}
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);
StringSetMap deviceDataMap = exportMask.getDeviceDataMap();
Set<String> hsdList = deviceDataMap.keySet();
if (null == hsdList || hsdList.isEmpty()) {
throw HDSException.exceptions.notAbleToFindHostStorageDomain(systemObjectID);
}
if (null != exportMask && !exportMask.getInactive() && !hsdList.isEmpty()) {
List<Path> pathList = new ArrayList<Path>();
for (String hsdObjectID : hsdList) {
// Query the provider to see whether the HSD exists or not.
HostStorageDomain hsd = exportMgr.getHostStorageDomain(systemObjectID, hsdObjectID);
if (null != hsd) {
Map<String, String> volumeLunMap = getVolumeLunMap(systemObjectID, hsd.getObjectID(), volumeURIHLUs, exportMgr);
for (Map.Entry<String, String> entry : volumeLunMap.entrySet()) {
if (!checkIfVolumeAlreadyExistsOnHSD(entry.getKey(), hsd)) {
Path path = new Path(hsd.getPortID(), hsd.getDomainID(), null, entry.getValue(), entry.getKey());
pathList.add(path);
}
}
}
}
if (!pathList.isEmpty()) {
List<Path> pathResponseList = hdsApiClient.getHDSBatchApiExportManager().addLUNPathsToHSDs(systemObjectID, pathList, storage.getModel());
if (null != pathResponseList && !pathResponseList.isEmpty()) {
// update volume-lun relationship to exportmask.
updateVolumeHLUInfo(volumeURIHLUs, pathResponseList, exportMask);
dbClient.updateObject(exportMask);
} else {
log.error(String.format("addVolumes failed - maskURI: %s", exportMaskURI.toString()), new Exception("Not able to parse the response of addLUN from server"));
ServiceError serviceError = DeviceControllerException.errors.jobFailedOpMsg(ResourceOperationTypeEnum.ADD_EXPORT_VOLUME.getName(), "Not able to parse the response of addLUN from server");
taskCompleter.error(dbClient, serviceError);
return;
}
} else {
log.info("All the volumes are already part of the HSDs.");
}
taskCompleter.ready(dbClient);
}
} catch (Exception e) {
log.error(String.format("addVolumes failed - maskURI: %s", exportMaskURI.toString()), e);
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
taskCompleter.error(dbClient, serviceError);
}
log.info("{} addVolumes END...", storage.getSerialNumber());
}
use of com.emc.storageos.hds.api.HDSApiExportManager in project coprhd-controller by CoprHD.
the class HDSExportMaskInitiatorsValidator method validate.
@Override
public boolean validate() throws Exception {
log.info("Initiating initiators validation of HDS ExportMask: {}", id);
try {
ExportMask exportMask = getExportMask();
StorageSystem system = getStorage();
if (exportMask != null && !CollectionUtils.isEmpty(exportMask.getDeviceDataMap())) {
Set<String> hsdList = exportMask.getDeviceDataMap().keySet();
HDSApiClient client = getClientFactory().getClient(HDSUtils.getHDSServerManagementServerInfo(system), system.getSmisUserName(), system.getSmisPassword());
HDSApiExportManager exportManager = client.getHDSApiExportManager();
String maskName = null;
String systemObjectID = HDSUtils.getSystemObjectID(system);
Set<String> volumesInExportMask = new HashSet<>();
Set<String> initiatorsInExportMask = new HashSet<>();
if (!CollectionUtils.isEmpty(exportMask.getUserAddedVolumes())) {
volumesInExportMask.addAll(exportMask.getUserAddedVolumes().keySet());
}
if (!CollectionUtils.isEmpty(exportMask.getUserAddedInitiators())) {
initiatorsInExportMask.addAll(exportMask.getUserAddedInitiators().keySet());
}
log.info("Volumes {} in Export Mask {}", volumesInExportMask, exportMask.forDisplay());
log.info("Initiators {} in Export Mask {}", initiatorsInExportMask, exportMask.forDisplay());
for (String hsdObjectIdFromDb : hsdList) {
Set<String> discoveredVolumes = new HashSet<>();
HostStorageDomain hsd = exportManager.getHostStorageDomain(systemObjectID, hsdObjectIdFromDb);
if (null == hsd) {
continue;
}
maskName = (null == hsd.getName()) ? hsd.getNickname() : hsd.getName();
// Get volumes and initiators from storage system
discoveredVolumes.addAll(HDSUtils.getVolumesFromHSD(hsd, system).keySet());
log.info("Volumes {} discovered from array for the HSD {}", discoveredVolumes, maskName);
Set<String> additionalVolumesOnArray = Sets.difference(discoveredVolumes, volumesInExportMask);
if (!CollectionUtils.isEmpty(additionalVolumesOnArray)) {
getValidatorLogger().logDiff(String.format("%s - %s", id, maskName), "volumes", ValidatorLogger.NO_MATCHING_ENTRY, Joiner.on("\t").join(additionalVolumesOnArray));
}
}
checkForErrors();
}
} catch (Exception ex) {
log.error("Unexpected exception validating ExportMask initiators: " + ex.getMessage(), ex);
if (getValidatorConfig().isValidationEnabled()) {
throw DeviceControllerException.exceptions.unexpectedCondition("Unexpected exception validating ExportMask initiators: " + ex.getMessage());
}
}
return true;
}
use of com.emc.storageos.hds.api.HDSApiExportManager in project coprhd-controller by CoprHD.
the class HDSExportMaskValidator method validate.
@Override
public boolean validate() throws Exception {
log.info("Initiating validation of HDS ExportMask: {}", id);
try {
ExportMask exportMask = getExportMask();
StorageSystem system = getStorage();
if (exportMask != null && !CollectionUtils.isEmpty(exportMask.getDeviceDataMap())) {
Set<String> hsdList = exportMask.getDeviceDataMap().keySet();
HDSApiClient client = getClientFactory().getClient(HDSUtils.getHDSServerManagementServerInfo(system), system.getSmisUserName(), system.getSmisPassword());
HDSApiExportManager exportManager = client.getHDSApiExportManager();
String maskName = null;
String systemObjectID = HDSUtils.getSystemObjectID(system);
Set<String> volumesInExportMask = new HashSet<>();
Set<String> initiatorsInExportMask = new HashSet<>();
if (!CollectionUtils.isEmpty(exportMask.getUserAddedVolumes())) {
volumesInExportMask.addAll(exportMask.getUserAddedVolumes().keySet());
}
if (!CollectionUtils.isEmpty(exportMask.getUserAddedInitiators())) {
initiatorsInExportMask.addAll(exportMask.getUserAddedInitiators().keySet());
}
log.info("Volumes {} in Export Mask {}", volumesInExportMask, exportMask.forDisplay());
log.info("Initiators {} in Export Mask {}", initiatorsInExportMask, exportMask.forDisplay());
for (String hsdObjectIdFromDb : hsdList) {
Set<String> discoveredInitiators = new HashSet<>();
Set<String> discoveredVolumes = new HashSet<>();
HostStorageDomain hsd = exportManager.getHostStorageDomain(systemObjectID, hsdObjectIdFromDb);
if (null == hsd) {
continue;
}
maskName = (null == hsd.getName()) ? hsd.getNickname() : hsd.getName();
// Get volumes and initiators from storage system
discoveredVolumes.addAll(HDSUtils.getVolumesFromHSD(hsd, system).keySet());
discoveredInitiators.addAll(HDSUtils.getInitiatorsFromHSD(hsd));
log.info("Volumes {} discovered from array for the HSD {}", discoveredVolumes, maskName);
log.info("Initiators {} discovered from array for the HSD {}", discoveredInitiators, maskName);
Set<String> additionalVolumesOnArray = Sets.difference(discoveredVolumes, volumesInExportMask);
Set<String> additionalInitiatorsOnArray = Sets.difference(discoveredInitiators, initiatorsInExportMask);
if (!CollectionUtils.isEmpty(additionalVolumesOnArray)) {
getValidatorLogger().logDiff(String.format("%s - %s", id, maskName), "volumes", ValidatorLogger.NO_MATCHING_ENTRY, Joiner.on("\t").join(additionalVolumesOnArray));
}
if (!CollectionUtils.isEmpty(additionalInitiatorsOnArray)) {
getValidatorLogger().logDiff(String.format("%s - %s", id, maskName), "initiators", ValidatorLogger.NO_MATCHING_ENTRY, Joiner.on("\t").join(additionalInitiatorsOnArray));
}
}
checkForErrors();
}
} catch (Exception ex) {
log.error("Unexpected exception validating ExportMask initiators: " + ex.getMessage(), ex);
if (getValidatorConfig().isValidationEnabled()) {
throw DeviceControllerException.exceptions.unexpectedCondition("Unexpected exception validating ExportMask initiators: " + ex.getMessage());
}
}
return true;
}
Aggregations