use of com.emc.storageos.db.client.model.StringSetMap 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.db.client.model.StringSetMap 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.db.client.model.StringSetMap in project coprhd-controller by CoprHD.
the class ExportMaskUtils method getZoneMapFromAssignments.
/**
* Returns a StringSetMap containing the Initiator to StoragePort URIs from zoning assignments.
*
* @param assignments Map<URI, List<URI>> of zoning assignments.
* @return StringSetMap with same information encoded as
*/
public static StringSetMap getZoneMapFromAssignments(Map<URI, List<URI>> assignments) {
StringSetMap zoneMap = new StringSetMap();
for (URI initiatorURI : assignments.keySet()) {
StringSet portIds = new StringSet();
List<URI> portURIs = assignments.get(initiatorURI);
for (URI portURI : portURIs) {
portIds.add(portURI.toString());
}
zoneMap.put(initiatorURI.toString(), portIds);
}
return zoneMap;
}
use of com.emc.storageos.db.client.model.StringSetMap in project coprhd-controller by CoprHD.
the class ExportMaskUtils method getRemovePathsForExportMask.
/**
* Get the remove path list for the exportMask in the given removedPaths.
* The given removedPaths could be paths from all the exportMasks belonging to one export group.
*
* @param exportMask
* @param removedPaths - The list paths. some of them may not belong to the export mask.
* @return - The list of paths are going to be removed from the export mask.
*/
public static Map<URI, List<URI>> getRemovePathsForExportMask(ExportMask exportMask, Map<URI, List<URI>> removedPaths) {
Map<URI, List<URI>> result = new HashMap<URI, List<URI>>();
StringSetMap zoningMap = exportMask.getZoningMap();
StringSet maskInitiators = exportMask.getInitiators();
if (removedPaths == null || removedPaths.isEmpty()) {
return result;
}
for (Map.Entry<URI, List<URI>> entry : removedPaths.entrySet()) {
URI initiator = entry.getKey();
if (!maskInitiators.contains(initiator.toString())) {
continue;
}
List<URI> ports = entry.getValue();
List<URI> removePorts = new ArrayList<URI>();
StringSet targets = zoningMap.get(initiator.toString());
if (targets != null && !targets.isEmpty()) {
for (URI port : ports) {
if (targets.contains(port.toString())) {
removePorts.add(port);
}
}
if (!removePorts.isEmpty()) {
result.put(initiator, removePorts);
}
}
}
return result;
}
use of com.emc.storageos.db.client.model.StringSetMap in project coprhd-controller by CoprHD.
the class ExportMaskUtils method buildZoningMapFromInitiatorsAndPorts.
/**
* Builds a default zoneMap from the initiators and ports.
*
* For the targets in the mask, they are paired with the initiators they can service,
* i.e. that are on the same or a route-able network, and are usable in the varray,
* and the corresponding zones are put in the zoning map.
*
* @param mask -- The ExportMask being manipulated
* @param varray -- The Virtual Array (normally from the ExportGroup)
* @param dbClient -- DbClient
* @return - The zoning map represented as a string set map that is constructed from the
* cross product of mask initiators and mask storage ports. Initiators are only paired
* with ports on the same network.
*
* Assumption: the export mask has up to date initiators and storage ports
*/
public static StringSetMap buildZoningMapFromInitiatorsAndPorts(ExportMask mask, URI varray, DbClient dbClient) {
_log.info(String.format("Creating zoning map for ExportMask %s (%s) from the initiator and port sets", mask.getMaskName(), mask.getId()));
StringSetMap zoningMap = new StringSetMap();
// corresponding to the Initiator.
for (String initiatorURIStr : mask.getInitiators()) {
Initiator initiator = dbClient.queryObject(Initiator.class, URI.create(initiatorURIStr));
if (initiator == null || initiator.getInactive()) {
continue;
}
List<URI> storagePortList = ExportUtils.getPortsInInitiatorNetwork(mask, initiator, dbClient);
if (storagePortList.isEmpty()) {
continue;
}
StringSet storagePorts = new StringSet();
for (URI portURI : storagePortList) {
StoragePort port = dbClient.queryObject(StoragePort.class, portURI);
if (!port.isUsable()) {
_log.debug("Storage port {} is not selected because it is inactive, is not compatible, is not visible, not on a network, " + "is not registered, or is not a frontend port", port.getLabel());
continue;
}
// Network connectivity was checked in getInitiatorPortsInMask()
if (port.getTaggedVirtualArrays().contains(varray.toString())) {
storagePorts.add(portURI.toString());
} else {
_log.debug("Storage port {} is not selected because it is not in the specified varray {}", port.getLabel(), varray.toString());
}
}
if (!storagePorts.isEmpty()) {
zoningMap.put(initiatorURIStr, storagePorts);
}
}
_log.info("Constructed zoningMap -" + zoningMap.toString());
return zoningMap;
}
Aggregations