use of com.emc.storageos.xtremio.restapi.XtremIOClient in project coprhd-controller by CoprHD.
the class XtremIOSnapshotOperations method deleteSingleVolumeSnapshot.
@Override
public void deleteSingleVolumeSnapshot(StorageSystem storage, URI snapshot, TaskCompleter taskCompleter) throws DeviceControllerException {
try {
XtremIOClient client = XtremIOProvUtils.getXtremIOClient(dbClient, storage, xtremioRestClientFactory);
BlockSnapshot snapshotObj = dbClient.queryObject(BlockSnapshot.class, snapshot);
String clusterName = client.getClusterDetails(storage.getSerialNumber()).getName();
if (null != XtremIOProvUtils.isSnapAvailableInArray(client, snapshotObj.getDeviceLabel(), clusterName)) {
client.deleteSnapshot(snapshotObj.getDeviceLabel(), clusterName);
}
snapshotObj.setIsSyncActive(false);
snapshotObj.setInactive(true);
dbClient.updateObject(snapshotObj);
taskCompleter.ready(dbClient);
} catch (Exception e) {
_log.error("Snapshot deletion failed", e);
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
taskCompleter.error(dbClient, serviceError);
}
}
use of com.emc.storageos.xtremio.restapi.XtremIOClient in project coprhd-controller by CoprHD.
the class XtremIOArrayAffinityDiscoverer method getPreferredPoolMapForHost.
/**
* Gets the preferred pool map for the given host.
*/
private Map<String, String> getPreferredPoolMapForHost(StorageSystem system, Host host, DbClient dbClient) throws Exception {
/**
* Group host's initiators by IG,
* For each IG:
* - Get list of volume maps [List all volume maps and see which ones have mapping for this IG],
* - Get pool detail for each volume,
* - Find the mask type for the pool.
*/
Map<String, String> preferredPoolMap = new HashMap<String, String>();
XtremIOClient xtremIOClient = XtremIOProvUtils.getXtremIOClient(dbClient, system, xtremioRestClientFactory);
String xioClusterName = xtremIOClient.getClusterDetails(system.getSerialNumber()).getName();
List<Initiator> hostInitiators = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, Initiator.class, ContainmentConstraint.Factory.getContainedObjectsConstraint(host.getId(), Initiator.class, Constants.HOST));
ArrayListMultimap<String, Initiator> groupInitiatorsByIG = ArrayListMultimap.create();
for (Initiator initiator : hostInitiators) {
log.info("Processing host initiator {}", initiator.getLabel());
String igName = XtremIOProvUtils.getIGNameForInitiator(initiator, system.getSerialNumber(), xtremIOClient, xioClusterName);
if (igName != null && !igName.isEmpty()) {
groupInitiatorsByIG.put(igName, initiator);
}
}
log.info("List of IGs found {}", Joiner.on(",").join(groupInitiatorsByIG.asMap().entrySet()));
Set<String> igNames = groupInitiatorsByIG.keySet();
if (!igNames.isEmpty()) {
// map of IG name to Volume names mapped
Map<String, Set<String>> igToVolumesMap = getIgToVolumesMap(xtremIOClient, xioClusterName);
Set<String> volumeNames = getVolumesForHost(igNames, igToVolumesMap);
// consider only unmanaged volumes
filterKnownVolumes(system, dbClient, xtremIOClient, xioClusterName, volumeNames);
// get storage pool for matching volumes
if (!volumeNames.isEmpty()) {
log.info("UnManaged Volumes found for this Host: {}", volumeNames);
// As XtremIO array has only one storage pool, add the pool directly.
// get the storage pool associated with the XtremIO system
StoragePool storagePool = XtremIOProvUtils.getXtremIOStoragePool(system.getId(), dbClient);
if (storagePool != null) {
String maskType = getMaskTypeForHost(xtremIOClient, xioClusterName, groupInitiatorsByIG, null, igNames, volumeNames);
ArrayAffinityDiscoveryUtils.addPoolToPreferredPoolMap(preferredPoolMap, storagePool.getId().toString(), maskType);
}
} else {
log.info("No UnManaged Volumes found for this Host");
}
}
return preferredPoolMap;
}
use of com.emc.storageos.xtremio.restapi.XtremIOClient in project coprhd-controller by CoprHD.
the class XtremIOExportOperations method removeInitiators.
@Override
public void removeInitiators(StorageSystem storage, URI exportMaskURI, List<URI> volumeURIList, List<Initiator> initiators, List<URI> targets, TaskCompleter taskCompleter) throws DeviceControllerException {
_log.info("{} removeInitiators START...", storage.getSerialNumber());
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.
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_INITIATORS_TO_INITIATOR_GROUP.equals(operation.getOperation())) {
addedInitiators = (List<Initiator>) operation.getArgs().get(0);
_log.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()) {
_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);
if (exportMask == null || exportMask.getInactive()) {
throw new DeviceControllerException("Invalid ExportMask URI: " + exportMaskURI);
}
XtremIOClient client = null;
// if host Name is not available in at least one of the initiator, then set it to
// Default_IG;
List<String> failedIGs = new ArrayList<String>();
ArrayListMultimap<String, Initiator> groupInitiatorsByIG = ArrayListMultimap.create();
try {
String hostName = null;
String clusterName = null;
client = XtremIOProvUtils.getXtremIOClient(dbClient, storage, xtremioRestClientFactory);
String xioClusterName = client.getClusterDetails(storage.getSerialNumber()).getName();
Iterator<Initiator> iniItr = initiators.iterator();
while (iniItr.hasNext()) {
Initiator initiator = iniItr.next();
String igName = null;
if (null != initiator.getHostName()) {
// initiators already grouped by Host
hostName = initiator.getHostName();
clusterName = initiator.getClusterName();
}
igName = XtremIOProvUtils.getIGNameForInitiator(initiator, storage.getSerialNumber(), client, xioClusterName);
if (igName != null && !igName.isEmpty()) {
groupInitiatorsByIG.put(igName, initiator);
} else {
// initiator not found in Array, remove from DB
exportMask.removeFromExistingInitiators(initiator);
exportMask.removeFromUserCreatedInitiators(initiator);
iniItr.remove();
}
}
// We need to look at all related initiators from the affected EM. We can use this list
// to then find all related volumes across all EMs. This will allow us to properly
// perform our validations.
List<Initiator> relatedInitiators = new ArrayList<Initiator>();
if (exportMask.getInitiators() != null && !exportMask.getInitiators().isEmpty()) {
Collection<URI> relatedInitiatorURIs = Collections2.transform(exportMask.getInitiators(), CommonTransformerFunctions.FCTN_STRING_TO_URI);
relatedInitiators.addAll(dbClient.queryObject(Initiator.class, relatedInitiatorURIs));
} else {
relatedInitiators.addAll(initiators);
}
Set<URI> allRelatedVolumes = new HashSet<URI>();
allRelatedVolumes.addAll(findAllRelatedExportMaskVolumesForInitiator(relatedInitiators, exportMask.getStorageDevice()));
_log.info("removeInitiators: Export mask id: {}", exportMaskURI);
if (!CollectionUtils.isEmpty(allRelatedVolumes)) {
_log.info("removeInitiators: volumes : {}", Joiner.on(',').join(allRelatedVolumes));
}
_log.info("removeInitiators: initiators : {}", Joiner.on(',').join(initiators));
_log.info("removeInitiators: targets : {}", Joiner.on(',').join(targets));
_log.info("List of IGs found {} with size : {}", Joiner.on(",").join(groupInitiatorsByIG.asMap().entrySet()), groupInitiatorsByIG.size());
ExportMaskValidationContext ctx = new ExportMaskValidationContext();
ctx.setStorage(storage);
ctx.setExportMask(exportMask);
ctx.setBlockObjects(allRelatedVolumes, dbClient);
ctx.setAllowExceptions(!isRollback);
XtremIOExportMaskVolumesValidator volumeValidator = (XtremIOExportMaskVolumesValidator) validator.removeInitiators(ctx);
volumeValidator.setIgNames(groupInitiatorsByIG.keySet());
volumeValidator.validate();
// lun map
for (Initiator initiator : initiators) {
try {
client.deleteInitiator(initiator.getMappedInitiatorName(storage.getSerialNumber()), xioClusterName);
exportMask.removeFromExistingInitiators(initiator);
exportMask.removeFromUserCreatedInitiators(initiator);
} catch (Exception e) {
failedIGs.add(initiator.getLabel().concat(XtremIOConstants.DASH).concat(e.getMessage()));
_log.warn("Removal of Initiator {} failed", initiator.getLabel(), e);
}
}
dbClient.updateObject(exportMask);
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 ex) {
_log.error("Problem in removeInitiators: ", ex);
ServiceError serviceError = DeviceControllerErrors.xtremio.operationFailed("removeInitiators", ex.getMessage());
taskCompleter.error(dbClient, serviceError);
return;
}
_log.info("{} removeInitiators END...", storage.getSerialNumber());
}
use of com.emc.storageos.xtremio.restapi.XtremIOClient in project coprhd-controller by CoprHD.
the class XtremIOExportOperations 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());
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));
}
ExportOperationContext context = new XtremIOExportOperationContext();
// Prime the context object
taskCompleter.updateWorkflowStepContext(context);
ExportMask exportMask = dbClient.queryObject(ExportMask.class, exportMaskURI);
if (exportMask == null || exportMask.getInactive()) {
throw new DeviceControllerException("Invalid ExportMask URI: " + exportMaskURI);
}
XtremIOClient client = XtremIOProvUtils.getXtremIOClient(dbClient, storage, xtremioRestClientFactory);
String xioClusterName = client.getClusterDetails(storage.getSerialNumber()).getName();
ArrayListMultimap<String, Initiator> initiatorToIGMap = XtremIOProvUtils.mapInitiatorToInitiatorGroup(storage.getSerialNumber(), initiatorList, null, xioClusterName, client);
XtremIOExportMaskInitiatorsValidator initiatorsValidator = (XtremIOExportMaskInitiatorsValidator) validator.addVolumes(storage, exportMaskURI, initiatorList);
initiatorsValidator.setInitiatorToIGMap(initiatorToIGMap);
initiatorsValidator.validate();
runLunMapCreationAlgorithm(storage, exportMask, volumeURIHLUs, initiatorList, null, client, xioClusterName, initiatorToIGMap, null, taskCompleter);
} catch (final Exception ex) {
_log.error("Problem in addVolumes: ", ex);
ServiceError serviceError = DeviceControllerErrors.xtremio.operationFailed("addVolumes", ex.getMessage());
taskCompleter.error(dbClient, serviceError);
}
_log.info("{} addVolumes END...", storage.getSerialNumber());
}
use of com.emc.storageos.xtremio.restapi.XtremIOClient in project coprhd-controller by CoprHD.
the class XtremIOExportOperations method refreshExportMask.
/*
* Refresh all export masks, not only the one passed in
* @see com.emc.storageos.volumecontroller.impl.smis.ExportMaskOperations#refreshExportMask(com.emc.storageos.db.client.model.StorageSystem, com.emc.storageos.db.client.model.ExportMask)
*/
@Override
public ExportMask refreshExportMask(StorageSystem storage, ExportMask mask) throws DeviceControllerException {
ExportMask maskToReturn = null;
try {
_log.info("Refreshing volumes and initiator labels in ViPR.. ");
XtremIOClient client = XtremIOProvUtils.getXtremIOClient(dbClient, storage, xtremioRestClientFactory);
Set<String> igNameSet = new HashSet<>();
Map<URI, Set<String>> maskToIGNameMap = new HashMap<>();
String xioClusterName = client.getClusterDetails(storage.getSerialNumber()).getName();
List<XtremIOInitiator> initiators = client.getXtremIOInitiatorsInfo(xioClusterName);
List<Initiator> initiatorObjs = new ArrayList<Initiator>();
for (XtremIOInitiator initiator : initiators) {
URIQueryResultList initiatorResult = new URIQueryResultList();
dbClient.queryByConstraint(AlternateIdConstraint.Factory.getInitiatorPortInitiatorConstraint(initiator.getPortAddress()), initiatorResult);
if (initiatorResult.iterator().hasNext()) {
Initiator initiatorObj = dbClient.queryObject(Initiator.class, initiatorResult.iterator().next());
_log.info("Updating Initiator label from {} to {} in ViPR DB", initiatorObj.getLabel(), initiator.getName());
initiatorObj.setLabel(initiator.getName());
initiatorObj.mapInitiatorName(storage.getSerialNumber(), initiator.getName());
initiatorObjs.add(initiatorObj);
List<ExportMask> results = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, ExportMask.class, ContainmentConstraint.Factory.getConstraint(ExportMask.class, "initiators", initiatorObj.getId()));
String igName = initiator.getInitiatorGroup().get(1);
for (ExportMask exportMask : results) {
if (exportMask != null && storage.getId().equals(exportMask.getStorageDevice())) {
igNameSet.add(igName);
// update export mask to IG name map
URI maskId = exportMask.getId();
Set<String> igNames = maskToIGNameMap.get(maskId);
if (igNames == null) {
igNames = new HashSet<String>();
maskToIGNameMap.put(maskId, igNames);
}
igNames.add(igName);
}
}
} else {
_log.info("No initiator objects in vipr db for port address {}", initiator.getPortAddress());
}
}
if (!initiatorObjs.isEmpty()) {
dbClient.updateObject(initiatorObjs);
}
// get volumes for each IG
Map<String, Map<String, Integer>> igNameToVolMap = new HashMap<>();
boolean bulkApiCallFlag = Boolean.valueOf(ControllerUtils.getPropertyValueFromCoordinator(coordinator, XTREMIO_BULK_API_CALL));
Map<String, List<XtremIOVolume>> igNameToVolumesMap = new HashMap<>();
_log.debug("Bulk API Flag", bulkApiCallFlag);
_log.debug("XtremIO Firmware Version", storage.getFirmwareVersion());
if (client.isVersion2() && XtremIOProvUtils.isBulkAPISupported(storage.getFirmwareVersion(), client) && bulkApiCallFlag) {
long starttime = System.nanoTime();
if (!igNameSet.isEmpty())
igNameToVolumesMap = XtremIOProvUtils.getLunMapAndVolumes(igNameSet, xioClusterName, client, igNameToVolumesMap);
_log.debug("Time taken for Bulk API Call : " + "total time = " + String.format("%2.6f", (System.nanoTime() - starttime) / 1000000000.0) + " seconds");
for (Map.Entry<String, List<XtremIOVolume>> entry : igNameToVolumesMap.entrySet()) {
Map<String, Integer> discoveredVolumesMap = new HashMap<String, Integer>();
for (XtremIOVolume volume : entry.getValue()) {
for (List<Object> lunMapEntries : volume.getLunMaps()) {
@SuppressWarnings("unchecked") List<Object> // This can't be null
igDetails = (List<Object>) lunMapEntries.get(0);
if (null == igDetails.get(1) || null == lunMapEntries.get(2)) {
continue;
}
String igNameToProcess = (String) igDetails.get(1);
if (!entry.getKey().equalsIgnoreCase(igNameToProcess)) {
continue;
}
Double hluNumber = (Double) lunMapEntries.get(2);
_log.info("Found HLU {} for volume {}", hluNumber, volume.getVolInfo().get(1));
discoveredVolumesMap.put(volume.getWwn(), Integer.valueOf(hluNumber.intValue()));
}
}
igNameToVolMap.put(entry.getKey(), discoveredVolumesMap);
}
_log.debug("Time taken for All iteration in BulK API : " + "total time = " + String.format("%2.6f", (System.nanoTime() - starttime) / 1000000000.0) + " seconds");
} else {
long totaltime = System.nanoTime();
for (String igName : igNameSet) {
Map<String, Integer> discoveredVolumes = new HashMap<String, Integer>();
long starttime1 = System.nanoTime();
List<XtremIOVolume> igVolumes = XtremIOProvUtils.getInitiatorGroupVolumes(igName, xioClusterName, client);
_log.debug("Time taken for each ig name normal API Call : " + "total time = " + String.format("%2.6f", (System.nanoTime() - starttime1) / 1000000000.0) + " seconds");
for (XtremIOVolume igVolume : igVolumes) {
for (List<Object> lunMapEntries : igVolume.getLunMaps()) {
@SuppressWarnings("unchecked") List<Object> // This can't be null
igDetails = (List<Object>) lunMapEntries.get(0);
if (null == igDetails.get(1) || null == lunMapEntries.get(2)) {
_log.warn("IG Name or hlu is null in returned lun map response for volume {}", igVolume.toString());
continue;
}
String igNameToProcess = (String) igDetails.get(1);
if (!igName.equalsIgnoreCase(igNameToProcess)) {
continue;
}
Double hluNumber = (Double) lunMapEntries.get(2);
_log.info("Found HLU {} for volume {}", hluNumber, igVolume.getVolInfo().get(1));
// for each IG involved, the same volume is visible through different HLUs.
// TODO we might need a list of HLU for each Volume URI
discoveredVolumes.put(BlockObject.normalizeWWN(igVolume.getWwn()), Integer.valueOf(hluNumber.intValue()));
}
}
igNameToVolMap.put(igName, discoveredVolumes);
}
_log.debug("Time taken for all ig name normal API Call : " + "total time = " + String.format("%2.6f", (System.nanoTime() - totaltime) / 1000000000.0) + " seconds");
}
// update each mask
for (Entry<URI, Set<String>> entry : maskToIGNameMap.entrySet()) {
URI maskId = entry.getKey();
ExportMask exportMask = dbClient.queryObject(ExportMask.class, maskId);
if (exportMask == null || exportMask.getInactive()) {
continue;
}
Map<String, Integer> discoveredVolumes = new HashMap<String, Integer>();
for (String igName : entry.getValue()) {
discoveredVolumes.putAll(igNameToVolMap.get(igName));
}
// Clear the existing volumes to update with the latest info
if (exportMask.getExistingVolumes() != null && !exportMask.getExistingVolumes().isEmpty()) {
exportMask.getExistingVolumes().clear();
}
// COP-27296 fix
if (null == exportMask.getUserAddedVolumes()) {
exportMask.setUserAddedVolumes(new StringMap());
}
// We need to look at all related initiators from the affected EM. We can use this list
// to then find all related volumes across all EMs. This will allow us to properly
// perform our validations.
List<Initiator> relatedInitiators = new ArrayList<Initiator>();
if (exportMask.getInitiators() != null && !exportMask.getInitiators().isEmpty()) {
Collection<URI> relatedInitiatorURIs = Collections2.transform(exportMask.getInitiators(), CommonTransformerFunctions.FCTN_STRING_TO_URI);
relatedInitiators.addAll(dbClient.queryObject(Initiator.class, relatedInitiatorURIs));
}
Set<URI> allRelatedVolumes = new HashSet<URI>();
allRelatedVolumes.addAll(findAllRelatedExportMaskVolumesForInitiator(relatedInitiators, exportMask.getStorageDevice()));
// If there are related volumes found, get the WWNs so we can diff against what has
// been discovered on the array.
Set<String> allRelatedVolumesWWN = new HashSet<String>();
for (URI relatedVolumeURI : allRelatedVolumes) {
BlockObject relatedObj = BlockObject.fetch(dbClient, relatedVolumeURI);
if (relatedObj != null) {
allRelatedVolumesWWN.add(relatedObj.getWWN());
}
}
Set<String> existingVolumes = Sets.difference(discoveredVolumes.keySet(), allRelatedVolumesWWN);
_log.info(String.format("XtremIO discovered volumes: {%s}%n", Joiner.on(',').join(discoveredVolumes.keySet())));
_log.info(String.format("%nXtremIO mask existing volumes: {%s}%n", Joiner.on(',').join(existingVolumes)));
for (String wwn : existingVolumes) {
exportMask.addToExistingVolumesIfAbsent(wwn, discoveredVolumes.get(wwn).toString());
}
// Update user added volume's HLU information in ExportMask and ExportGroup
ExportMaskUtils.updateHLUsInExportMask(exportMask, discoveredVolumes, dbClient);
dbClient.updateObject(exportMask);
if (mask != null && maskId.equals(mask.getId())) {
maskToReturn = exportMask;
}
}
} catch (Exception e) {
if (null != e.getMessage() && !e.getMessage().contains(XtremIOConstants.OBJECT_NOT_FOUND)) {
String msg = String.format("Error when refreshing export masks for the system %s, details: %s", storage.forDisplay(), e.getMessage());
throw XtremIOApiException.exceptions.refreshExistingMaskFailure(msg, e);
} else {
_log.warn("Error refreshing export masks for the system {}", storage.forDisplay());
}
}
return maskToReturn;
}
Aggregations