use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.
the class StoragePortAssociationHelper method getVArraysWithChangedConnectivityToStorageSystem.
/**
* This method finds varrays which change connection (either are newly connected or lost old connection) to storage
* system of the passed port parameter.
*
* @param port storage port for which varrays were added/removed
* @param varraysToAddIds set of added varrays to port
* @param varraysToRemoveIds set of removed varrays from port
* @param dbClient
* @return set of varrays which changed connection to port's storage system
*/
private static Set<String> getVArraysWithChangedConnectivityToStorageSystem(StoragePort port, Set<String> varraysToAddIds, Set<String> varraysToRemoveIds, DbClient dbClient) {
// This is our storage system.
URI storageSystemURI = port.getStorageDevice();
_log.info("Port {} belongs to storage system {}", port.getId(), storageSystemURI);
// Set of varrays which changed connection to the storage system.
Set<String> varraysWithChangedConnectivity = new HashSet<>();
// For these varrays there is no connection change to the storage system.
if (varraysToAddIds != null && !varraysToAddIds.isEmpty()) {
_log.info("New varrays {} added to the port {}", varraysToAddIds, port.getId());
Set<String> varraysToAddWithChangedConnectivity = new HashSet<>(varraysToAddIds);
for (String varrayId : varraysToAddIds) {
URIQueryResultList storagePortURIs = new URIQueryResultList();
dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVirtualArrayStoragePortsConstraint(varrayId), storagePortURIs);
for (URI portURI : storagePortURIs) {
// If this is the same port as was added to varray in the change request, skip and continue
if (port.getId().equals(portURI)) {
continue;
}
StoragePort varrayPort = (StoragePort) dbClient.queryObject(portURI);
if (!NullColumnValueGetter.isNullURI(varrayPort.getStorageDevice()) && storageSystemURI.equals(varrayPort.getStorageDevice())) {
// This varray port belongs to our storage system
// At least one other port from our storage system belongs to varray.
// Addition of a new port to this varray does not change connection between our storage
// system and varray.
// We can stop here processing varray ports.
varraysToAddWithChangedConnectivity.remove(varrayId);
_log.info("Varray {} already has connection to storage system {} through port {}", varrayId, storageSystemURI, portURI);
break;
}
}
}
_log.info("New varrays connected to storage system {} are {}", storageSystemURI, varraysToAddWithChangedConnectivity);
varraysWithChangedConnectivity.addAll(varraysToAddWithChangedConnectivity);
}
// the varray.
if (varraysToRemoveIds != null && !varraysToRemoveIds.isEmpty()) {
_log.info("Varrays {} are removed from the port {}", varraysToRemoveIds, port.getId());
Set<String> varraysToRemoveWithChangedConnectivity = new HashSet<>(varraysToRemoveIds);
for (String varrayId : varraysToRemoveIds) {
URIQueryResultList storagePortURIs = new URIQueryResultList();
dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVirtualArrayStoragePortsConstraint(varrayId), storagePortURIs);
for (URI portURI : storagePortURIs) {
StoragePort varrayPort = (StoragePort) dbClient.queryObject(portURI);
if (!NullColumnValueGetter.isNullURI(varrayPort.getStorageDevice()) && storageSystemURI.equals(varrayPort.getStorageDevice())) {
// This varray port belongs to our storage system
_log.info("Varray {} has connection to storage system {} through port {}", varrayId, storageSystemURI, portURI);
// There is other port from our storage system which belongs to varray.
// We can stop here processing varray ports.
varraysToRemoveWithChangedConnectivity.remove(varrayId);
break;
}
}
}
_log.info("Varrays which lost connection to storage system {} are {}", storageSystemURI, varraysToRemoveWithChangedConnectivity);
varraysWithChangedConnectivity.addAll(varraysToRemoveWithChangedConnectivity);
}
_log.info("Varrays with changed connection to storage system {} are {}", storageSystemURI, varraysWithChangedConnectivity);
return varraysWithChangedConnectivity;
}
use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.
the class StoragePortAssociationHelper method findvNasByNativeId.
/**
* it return VirtualNAS from database using NativeId
*
* @param nativeId
* @param dbClient
* @return VirtualNAS based on nativeId
*/
private static VirtualNAS findvNasByNativeId(String nativeId, DbClient dbClient) {
URIQueryResultList results = new URIQueryResultList();
VirtualNAS vNas = null;
dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVirtualNASByNativeGuidConstraint(nativeId), results);
Iterator<URI> iter = results.iterator();
while (iter.hasNext()) {
VirtualNAS tmpVnas = dbClient.queryObject(VirtualNAS.class, iter.next());
if (tmpVnas != null && !tmpVnas.getInactive()) {
vNas = tmpVnas;
_log.info("found virtual NAS {}", tmpVnas.getNativeGuid() + ":" + tmpVnas.getNasName());
break;
}
}
return vNas;
}
use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.
the class StoragePortAssociationHelper method getVpoolsForVarrays.
/**
* This method return list of VirtualPoll URIs defined in the past set of VirtualArray(s)
*
* @param varrayIDs set of virtual arrays URIs
* @param dbClient
*
* @return list of virtual pool URIs
*/
public static List<URI> getVpoolsForVarrays(Set<String> varrayIDs, DbClient dbClient) {
List<URI> vpoolURIs = new ArrayList<>();
for (String varrayID : varrayIDs) {
URI varrayURI = URI.create(varrayID);
URIQueryResultList resultList = new URIQueryResultList();
dbClient.queryByConstraint(ContainmentConstraint.Factory.getVirtualArrayVirtualPoolConstraint(varrayURI), resultList);
Iterator<URI> iterator = resultList.iterator();
while (iterator.hasNext()) {
URI vpoolId = iterator.next();
if (vpoolURIs.contains(vpoolId)) {
// already added, ignore
continue;
}
vpoolURIs.add(vpoolId);
}
}
return vpoolURIs;
}
use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.
the class AbstractDefaultMaskingOrchestrator method determineInitiatorToExportMaskPlacements.
/**
* Routine will examine the ExportGroup object's ExportMask and the passed in map of
* compute-resource-to-initiators map to produce a mapping of the ExportMasks'
* initiator port name to a list of ExportMask URIs.
*
* @param exportGroup
* [in] - ExportGroup object to examine
* @param storage
* @param computeResourceToInitiators
* [in] - Mapping of compute resource string key to
* list of Initiator URIs. @return Map of String to set of URIs. The key will be
* Initiator.normalizePort(initiator.portName).
* @param partialMasks
* [out] - list of masks that were found to be "partial" masks, where there are multiple masks that make
* up one
* compute resource
* Value will be set of ExportMask URIs.
*/
protected Map<String, Set<URI>> determineInitiatorToExportMaskPlacements(ExportGroup exportGroup, URI storage, Map<String, List<URI>> computeResourceToInitiators, Map<String, Set<URI>> initiatorToExportMapOnArray, Map<String, URI> portNameToInitiatorURI, Set<URI> partialMasks) {
Map<String, Set<URI>> initiatorToExportMaskURIMap = new HashMap<String, Set<URI>>();
Map<String, Set<URI>> computeResourceToExportMaskMap = ExportMaskUtils.mapComputeResourceToExportMask(_dbClient, exportGroup, storage);
Set<URI> allExportMaskURIs = new HashSet<>();
// associated with the ExportGroup
for (Map.Entry<String, List<URI>> entry : computeResourceToInitiators.entrySet()) {
String computeResource = entry.getKey();
List<URI> initiatorSet = entry.getValue();
if (computeResourceToExportMaskMap.get(computeResource) != null) {
for (URI exportMaskURI : computeResourceToExportMaskMap.get(computeResource)) {
if (exportMaskURI == null) {
_log.info(String.format("determineInitiatorToExportMaskPlacements - No ExportMask for compute resource %s in ExportGroup %s", computeResource, exportGroup.getLabel()));
continue;
}
for (URI initiatorURI : initiatorSet) {
Initiator initiator = _dbClient.queryObject(Initiator.class, initiatorURI);
if (initiator == null) {
continue;
}
String normalizedName = Initiator.normalizePort(initiator.getInitiatorPort());
Set<URI> exportMaskURIs = initiatorToExportMaskURIMap.get(normalizedName);
if (exportMaskURIs == null) {
exportMaskURIs = new TreeSet<URI>();
initiatorToExportMaskURIMap.put(normalizedName, exportMaskURIs);
}
exportMaskURIs.add(exportMaskURI);
}
}
}
}
// when combined, make up a cluster masking view
for (Map.Entry<String, Set<URI>> entry : initiatorToExportMapOnArray.entrySet()) {
allExportMaskURIs.addAll(entry.getValue());
}
Collection<URI> volumes = new HashSet<URI>();
if (exportGroup.getVolumes() != null) {
volumes = Collections2.transform(exportGroup.getVolumes().keySet(), CommonTransformerFunctions.FCTN_STRING_TO_URI);
}
ExportPathParams exportPathParams = _blockScheduler.calculateExportPathParamForVolumes(volumes, 0, storage, exportGroup.getId());
_log.info(String.format("determineInitiatorToExportMaskPlacements - ExportGroup=%s, exportPathParams=%s", exportGroup.getId().toString(), exportPathParams));
URI portGroup = exportPathParams.getPortGroup();
_log.info(String.format("Port group: %s", portGroup));
// Update mapping based on what is seen on the array
for (Map.Entry<String, Set<URI>> entry : initiatorToExportMapOnArray.entrySet()) {
String portName = entry.getKey();
// Validate this initiator and determine if it exists in the database
URI initiatorURI = portNameToInitiatorURI.get(portName);
if (initiatorURI == null) {
URIQueryResultList uris = new URIQueryResultList();
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getInitiatorPortInitiatorConstraint(portName), uris);
if (!uris.iterator().hasNext()) {
// There is no such initiator
_log.info(String.format("determineInitiatorToExportMaskPlacements - Could not find initiator port %s in DB", portName));
continue;
}
initiatorURI = uris.iterator().next();
}
// We should have a non-null initiator URI at this point
Initiator initiator = _dbClient.queryObject(Initiator.class, initiatorURI);
if (initiator == null) {
_log.info(String.format("determineInitiatorToExportMaskPlacements - Initiator %s does not exist in DB", initiatorURI.toString()));
continue;
}
_log.info(String.format("determineInitiatorToExportMaskPlacements - Scanning masks that contain initiator %s to see if those masks qualify for consideration for re-use", initiator.getInitiatorPort()));
// This container is for capturing those ExportMasks that we find to
// be matching based on the initiators, but unusable based on the
// StoragePorts that the mask has. Basically, in order for a mask to
// be considered a match, the initiators have to match, but the
// StoragePorts have to be in the same Network as the ExportGroup's
// VArray Network.
Map<URI, Map<String, String>> masksWithUnmatchedStoragePorts = new HashMap<URI, Map<String, String>>();
// Take a look at the ExportMask's initiators to see what compute resource that they support.
String computeResource = ExportUtils.computeResourceForInitiator(exportGroup, initiator);
List<URI> uriList = computeResourceToInitiators.get(computeResource);
List<String> portsForComputeResource = new ArrayList<String>();
Iterator<Initiator> iterator = _dbClient.queryIterativeObjects(Initiator.class, uriList);
while (iterator.hasNext()) {
portsForComputeResource.add(iterator.next().getInitiatorPort());
}
// At this point we have a non-null initiator object that we can use in the mapping
Map<URI, Integer> maskToTotalMatchingPorts = new HashMap<URI, Integer>();
int totalPorts = 0;
Set<URI> candidateExportMaskURIs = new HashSet<URI>();
Set<URI> exportMaskURIs = entry.getValue();
for (URI exportMaskURI : exportMaskURIs) {
ExportMask mask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
if (mask == null || mask.getInactive()) {
continue;
}
_log.info(String.format("determineInitiatorToExportMaskPlacements - Checking to see if we can consider mask %s, given its initiators, storage ports, and volumes", mask.getMaskName()));
// Check for NO_VIPR. If found, avoid this mask.
if (mask.getMaskName() != null && mask.getMaskName().toUpperCase().contains(ExportUtils.NO_VIPR)) {
_log.info(String.format("ExportMask %s disqualified because the name contains %s (in upper or lower case) to exclude it", mask.getMaskName(), ExportUtils.NO_VIPR));
continue;
}
Map<String, String> storagePortToNetworkName = new HashMap<String, String>();
if (mask.getCreatedBySystem()) {
if (mask.getResource().equals(computeResource)) {
if (maskHasPortGroup(mask, portGroup) && maskHasStoragePortsInExportVarray(exportGroup, mask, initiator, storagePortToNetworkName)) {
_log.info(String.format("determineInitiatorToExportMaskPlacements - ViPR-created mask %s qualifies for consideration for re-use", mask.getMaskName()));
candidateExportMaskURIs.add(exportMaskURI);
totalPorts += storagePortToNetworkName.keySet().size();
maskToTotalMatchingPorts.put(exportMaskURI, totalPorts);
// Ingest Fix : In ingest case, more than 1 export mask with createdBySystem flag set to
// true is possible
// remove the break statement
// break; First ViPR-created ExportMask associated with the resource, we will use
} else {
masksWithUnmatchedStoragePorts.put(exportMaskURI, storagePortToNetworkName);
_log.info(String.format("determineInitiatorToExportMaskPlacements - ViPR-created mask %s does not qualify for consideration for re-use due to storage ports mismatch with varray.", mask.getMaskName()));
}
} else {
_log.info(String.format("determineInitiatorToExportMaskPlacements - ViPR-created mask %s does not qualify for consideration for re-use due to compute resource mismatch.", mask.getMaskName()));
}
} else if (maskHasInitiatorsBasedOnExportType(exportGroup, mask, initiator, portsForComputeResource) || maskHasInitiatorsBasedOnExportType(exportGroup, mask, allExportMaskURIs, portsForComputeResource, partialMasks)) {
if (maskHasPortGroup(mask, portGroup) && maskHasStoragePortsInExportVarray(exportGroup, mask, initiator, storagePortToNetworkName)) {
_log.info(String.format("determineInitiatorToExportMaskPlacements - Pre-existing mask %s qualifies for consideration for re-use", mask.getMaskName()));
// This is a non-ViPR create ExportMask and it has the initiator
// as an existing initiator. Add it this as a matching candidate
candidateExportMaskURIs.add(exportMaskURI);
// We don't have zone ingest information for pre-existing masks, so for the purpose of
// matching more coexistence masks, we assume there are zones from every port to every
// initiator in the mask.
// Existing Initiators - initiators which are not userAdded.
int existingInitiators = mask.getExistingInitiators() == null ? 0 : mask.getExistingInitiators().size();
int userAddedInitators = mask.getUserAddedInitiators() == null ? 0 : mask.getUserAddedInitiators().size();
int totalInitiators = existingInitiators + userAddedInitators;
totalPorts += storagePortToNetworkName.keySet().size() * totalInitiators;
maskToTotalMatchingPorts.put(exportMaskURI, totalPorts);
} else {
masksWithUnmatchedStoragePorts.put(exportMaskURI, storagePortToNetworkName);
_log.info(String.format("determineInitiatorToExportMaskPlacements - Pre-existing mask %s does not qualify for consideration for re-use due to storage ports mismatch with varray.", mask.getMaskName()));
}
} else {
_log.info(String.format("determineInitiatorToExportMaskPlacements - Pre-existing mask %s does not qualify for consideration for re-use due to initiators not suitable for export group type.", mask.getMaskName()));
}
}
if (!candidateExportMaskURIs.isEmpty()) {
if (validateCandidateMasksAgainstExportPathParams(exportPathParams, maskToTotalMatchingPorts)) {
_log.info(String.format("determineInitiatorToExportMaskPlacements - Initiator %s (%s) will be mapped to these ExportMask URIs: %s", portName, initiatorURI.toString(), Joiner.on(',').join(exportMaskURIs)));
initiatorToExportMaskURIMap.put(portName, candidateExportMaskURIs);
}
} else {
if (masksWithUnmatchedStoragePorts.isEmpty()) {
_log.info(String.format("determineInitiatorToExportMaskPlacements - Could not find ExportMask to which %s can be associated", portName));
} else {
// We found matching exports on the array, but they were not viable due to
// the StoragePorts used (they were pointing to a different VArray), so we should
// warn the user in this case. We will likely still attempt to make a new mask,
// so if the user doesn't prefer that, this message will tell them why we took that
// path.
StringBuilder exportMaskInfo = new StringBuilder();
for (Map.Entry<URI, Map<String, String>> maskToStoragePortsEntry : masksWithUnmatchedStoragePorts.entrySet()) {
URI exportMaskURI = maskToStoragePortsEntry.getKey();
Map<String, String> storagePortToNetworks = maskToStoragePortsEntry.getValue();
ExportMask mask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
exportMaskInfo.append(String.format("MaskingView=%s StoragePorts [ %s ]%n", mask.getMaskName(), Joiner.on(',').join(storagePortToNetworks.entrySet())));
}
VirtualArray virtualArray = _dbClient.queryObject(VirtualArray.class, exportGroup.getVirtualArray());
Exception e = DeviceControllerException.exceptions.existingExportFoundButWithSPsInDifferentNetwork(virtualArray.getLabel(), exportMaskInfo.toString());
_log.warn(e.getMessage());
}
}
}
_log.info(String.format("determineInitiatorToExportMaskPlacements - initiatorToExportMaskURIMap: %s", Joiner.on(',').join(initiatorToExportMaskURIMap.entrySet())));
return initiatorToExportMaskURIMap;
}
use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.
the class StoragePoolService method getStoragePoolResources.
/**
* Retrieves the id, name, and type of the resources in the registered
* storage pool. with the passed id.
*
* @param id the URN of a ViPR storage pool.
*
* @brief List storage pool resources
* @return A list of the resources in the storage pool.
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/resources")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public StoragePoolResources getStoragePoolResources(@PathParam("id") URI id) {
// Make sure the storage pool is registered.
ArgValidator.checkFieldUriType(id, StoragePool.class, "id");
queryRegisteredResource(id);
// Create the storage pools resources to be returned.
StoragePoolResources resources = new StoragePoolResources();
// Get the active volumes in the storage pool and add them to
// the storage pool resources
URIQueryResultList volumeURIList = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getStoragePoolVolumeConstraint(id), volumeURIList);
Iterator<URI> volumeURIIter = volumeURIList.iterator();
while (volumeURIIter.hasNext()) {
URI volumeURI = volumeURIIter.next();
Volume volume = _dbClient.queryObject(Volume.class, volumeURI);
if ((volume != null) && (!volume.getInactive())) {
TypedRelatedResourceRep resource = toTypedRelatedResource(volume);
resources.getResources().add(resource);
}
}
// Get the active file shares in the storage pool and add them to the
// storage pools resources.
URIQueryResultList fsURIList = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getStoragePoolFileshareConstraint(id), fsURIList);
Iterator<URI> fsURIIter = fsURIList.iterator();
while (fsURIIter.hasNext()) {
URI fsURI = fsURIIter.next();
FileShare fs = _dbClient.queryObject(FileShare.class, fsURI);
if ((fs != null) && (!fs.getInactive())) {
TypedRelatedResourceRep resource = toTypedRelatedResource(fs);
resources.getResources().add(resource);
}
}
return resources;
}
Aggregations