use of com.emc.storageos.db.joiner.Joiner in project coprhd-controller by CoprHD.
the class NetworkDeviceController method getZoneReferences.
/**
* Given the zoning map, find all the instances of FCZoneReference for each initiator-port pair.
*
* @param refreshMap the zoning map
* @param initiators the initiators
* @param ports the storage ports
* @return a map of zone key to a list of zone reference objects for the key.
*/
private Map<String, List<FCZoneReference>> getZoneReferences(StringSetMap refreshMap, Collection<Initiator> initiators, Collection<StoragePort> ports) {
Map<String, List<FCZoneReference>> map = new HashMap<String, List<FCZoneReference>>();
Initiator initiator = null;
StoragePort port = null;
Set<String> portsKey = null;
for (String initKey : refreshMap.keySet()) {
portsKey = refreshMap.get(initKey);
initiator = DataObjectUtils.findInCollection(initiators, initKey);
if (initiator == null) {
continue;
}
if (portsKey == null || portsKey.isEmpty()) {
continue;
}
for (String portkey : portsKey) {
port = DataObjectUtils.findInCollection(ports, portkey);
if (port == null) {
continue;
}
String key = FCZoneReference.makeEndpointsKey(initiator.getInitiatorPort(), port.getPortNetworkId());
Joiner joiner = dbModelClient.join(FCZoneReference.class, "refs", "pwwnKey", key).go();
List<FCZoneReference> list = joiner.list("refs");
if (list != null && !list.isEmpty()) {
map.put(key, list);
}
}
}
return map;
}
use of com.emc.storageos.db.joiner.Joiner in project coprhd-controller by CoprHD.
the class ManagedCapacityImpl method getManagedCapacity.
public static ManagedResourcesCapacity getManagedCapacity(DbClient dbClient) throws InterruptedException {
ManagedResourcesCapacity resourcesCapacity = new ManagedResourcesCapacity();
ManagedResourcesCapacity.ManagedResourceCapacity manCap;
CustomQueryUtility.AggregatedValue aggr = null;
if (Thread.currentThread().interrupted()) {
throw new InterruptedException();
}
manCap = new ManagedResourcesCapacity.ManagedResourceCapacity();
manCap.setType(ManagedResourcesCapacity.CapacityResourceType.VOLUME);
aggr = CustomQueryUtility.aggregatedPrimitiveField(dbClient, Volume.class, "allocatedCapacity");
manCap.setNumResources(aggr.getCount());
manCap.setResourceCapacity(aggr.getValue());
resourcesCapacity.getResourceCapacityList().add(manCap);
if (Thread.currentThread().interrupted()) {
throw new InterruptedException();
}
manCap = new ManagedResourcesCapacity.ManagedResourceCapacity();
manCap.setType(ManagedResourcesCapacity.CapacityResourceType.FILESHARE);
aggr = CustomQueryUtility.aggregatedPrimitiveField(dbClient, FileShare.class, "usedCapacity");
manCap.setNumResources(aggr.getCount());
manCap.setResourceCapacity(aggr.getValue());
resourcesCapacity.getResourceCapacityList().add(manCap);
if (Thread.currentThread().interrupted()) {
throw new InterruptedException();
}
manCap = new ManagedResourcesCapacity.ManagedResourceCapacity();
manCap.setType(ManagedResourcesCapacity.CapacityResourceType.POOL);
aggr = CustomQueryUtility.aggregatedPrimitiveField(dbClient, StoragePool.class, "freeCapacity");
manCap.setNumResources(aggr.getCount());
double capacity = aggr.getValue();
// We must consider storage systems with sharedStorageCapacity == true (e.g. Ceph),
// because each their pool reports total storage free capacity.
// We get all such systems and subtract its pool size multiplied by (pools count - 1) from total capacity.
// Get all StoragePools where storageDevice is a StorageSystem where sharedStorageCapacity is true
Joiner j = new Joiner(dbClient).join(StorageSystem.class, "ss").match("sharedStorageCapacity", true).join("ss", StoragePool.class, "sp", "storageDevice").go();
Map<StorageSystem, Collection<URI>> ssToPoolMap = j.pushList("ss").pushUris("sp").map();
// From the joiner, get the StorageSystems (which is a small amount of objects) and the SPs (which is large, so get URIs and use query)
for (Entry<StorageSystem, Collection<URI>> ssToPoolEntry : ssToPoolMap.entrySet()) {
Collection<URI> poolURIs = ssToPoolEntry.getValue();
int extraPoolCount = poolURIs.size() - 1;
if (extraPoolCount <= 0) {
// Do nothing if none of the only pool belongs to Storage System
continue;
}
StoragePool pool = dbClient.queryObject(StoragePool.class, poolURIs.iterator().next());
capacity -= extraPoolCount * pool.getFreeCapacity();
}
manCap.setResourceCapacity(capacity * KB);
resourcesCapacity.getResourceCapacityList().add(manCap);
if (Thread.currentThread().interrupted()) {
throw new InterruptedException();
}
manCap = new ManagedResourcesCapacity.ManagedResourceCapacity();
manCap.setType(ManagedResourcesCapacity.CapacityResourceType.BUCKET);
aggr = CustomQueryUtility.aggregatedPrimitiveField(dbClient, Bucket.class, "hardQuota");
manCap.setNumResources(aggr.getCount());
manCap.setResourceCapacity(aggr.getValue());
resourcesCapacity.getResourceCapacityList().add(manCap);
if (Thread.currentThread().interrupted()) {
throw new InterruptedException();
}
return resourcesCapacity;
}
use of com.emc.storageos.db.joiner.Joiner in project coprhd-controller by CoprHD.
the class ExportMaskUtils method removeMaskCoexistInitiators.
/**
* When a co-exist initiator is delete in ViPR, no action will be taken on the storage array
* but the ExportMask and FCZoneReferences in ViPR need to be updated. Note that the only
* time a co-exist initiator can be removed is by actually deleting this initiator in ViPR.
* This means all references will need to be deleted.
*
* @param dbModelClient an instance of DbModelClient
* @param exportMaskUri the export mask being updates
* @param initiatorsUris the ids of the initiators being removed.
*/
public static void removeMaskCoexistInitiators(DbModelClient dbModelClient, URI exportMaskUri, List<URI> initiatorsUris) {
_log.info("removeMaskEoexistInitiators - Removing FCZoneReferences for initiators {}", initiatorsUris);
ExportMask mask = dbModelClient.find(ExportMask.class, exportMaskUri);
if (mask == null || mask.getInactive() || initiatorsUris == null) {
return;
}
// Get the initiators that are removed and all ports in the mask. Generate all possible keys.
List<Initiator> initiators = DataObjectUtils.iteratorToList(dbModelClient.find(Initiator.class, initiatorsUris));
List<StoragePort> ports = DataObjectUtils.iteratorToList(dbModelClient.find(StoragePort.class, StringSetUtil.stringSetToUriList(mask.getStoragePorts())));
List<String> keys = new ArrayList<String>();
for (Initiator initiator : initiators) {
for (StoragePort port : ports) {
keys.add(FCZoneReference.makeEndpointsKey(initiator.getInitiatorPort(), port.getPortNetworkId()));
}
}
if (!keys.isEmpty()) {
_log.info("removeMaskEoexistInitiators - Removing FCZoneReferences for keys {}", keys);
Joiner joiner = dbModelClient.join(FCZoneReference.class, "refs", "pwwnKey", keys).go();
List<FCZoneReference> list = joiner.list("refs");
if (list != null && !list.isEmpty()) {
_log.info("removeMaskEoexistInitiators - found {} FCZoneReferences for keys {}", list.size(), keys);
dbModelClient.remove(list);
}
}
// now clean the export mask
mask.removeInitiators(initiators);
for (URI uri : initiatorsUris) {
mask.removeZoningMapEntry(uri.toString());
}
_log.info("removeMaskEoexistInitiators - removed initiators {} from mask {}", initiatorsUris, mask.getMaskName());
dbModelClient.update(mask);
}
use of com.emc.storageos.db.joiner.Joiner in project coprhd-controller by CoprHD.
the class ExportMaskUtils method getExportMasksWithInitiatorPorts.
/**
* Find a set of ExportMasks to which the given Initiators belong.
*
* @param dbClient [IN] - For accessing DB
* @param initiatorPorts [IN] - List of initiator ports to search for among the ExportMasks found in the DB.
* @return HashMap of ExportMask URI to ExportMask object (Using HashMap, since URI is Comparable)
*/
public static HashMap<URI, ExportMask> getExportMasksWithInitiatorPorts(DbClient dbClient, List<String> initiatorPorts) {
final String initiatorAliasStr = "initiator";
final String portNameAliasStr = "iniport";
final String exportMaskAliasStr = "em";
final String initiatorStr = "initiators";
// Find all the ExportMasks that contain the 'initiators'
HashMap<URI, ExportMask> exportMasksWithInitiator = new HashMap<>();
for (String initiatorPort : initiatorPorts) {
Joiner joiner = new Joiner(dbClient);
Joiner query = joiner.join(Initiator.class, initiatorAliasStr).match(portNameAliasStr, initiatorPort).join(initiatorAliasStr, ExportMask.class, exportMaskAliasStr, initiatorStr).go();
Set<ExportMask> matchedMasks = query.set(exportMaskAliasStr);
for (ExportMask exportMask : matchedMasks) {
exportMasksWithInitiator.put(exportMask.getId(), exportMask);
}
}
return exportMasksWithInitiator;
}
use of com.emc.storageos.db.joiner.Joiner in project coprhd-controller by CoprHD.
the class ImplicitUnManagedObjectsMatcher method matchVirtualPoolWithUnManagedVolumeVPLEX.
/**
* Match virtual pool with unmanaged VPLEX volumes. Uses a different criteria than straight block matchers.
* Currently this method will only add virtual pools to an unmanaged volume. It will not remove them.
* This code is loosely based on VPlexCommunicationInterface.updateUnmanagedVolume() content, but is changed
* to suit this specific case where a single virtual pool is getting added/updated.
*
* @param modifiedUnManagedVolumes list of volumes to add to
* @param vpool virtual pool (new or updated)
* @param dbClient dbclient
*/
private static void matchVirtualPoolWithUnManagedVolumeVPLEX(List<UnManagedVolume> modifiedUnManagedVolumes, VirtualPool vpool, DbClient dbClient) {
// This method only applies to VPLEX vpools
if (!VirtualPool.vPoolSpecifiesHighAvailability(vpool)) {
return;
}
_log.info("START: matching virtual pool with unmanaged volume for VPLEX");
// Get all UnManagedVolumes where storageDevice is a StorageSystem where type = VPLEX
Joiner j = new Joiner(dbClient).join(StorageSystem.class, "ss").match("systemType", "vplex").join("ss", UnManagedVolume.class, "umv", "storageDevice").go();
// From the joiner, get the StorageSystems (which is a small amount of objects) and the UMVs (which is large, so get URIs and use iter)
Map<StorageSystem, List<URI>> ssToUmvMap = j.pushList("ss").pushUris("umv").map();
for (Entry<StorageSystem, List<URI>> ssToUmvEntry : ssToUmvMap.entrySet()) {
StorageSystem vplex = ssToUmvEntry.getKey();
// fetch the current mapping of VPLEX cluster ids to cluster names (e.g., "1"=>"cluster-1";"2"=>"cluster-2")
// the cluster names can be changed by the VPLEX admin, so we cannot rely on the default cluster-1 or cluster-2
Map<String, String> clusterIdToNameMap = null;
try {
VPlexApiClient client = VPlexControllerUtils.getVPlexAPIClient(VPlexApiFactory.getInstance(), vplex, dbClient);
clusterIdToNameMap = client.getClusterIdToNameMap();
} catch (Exception ex) {
_log.warn("Exception caught while getting cluster name info from VPLEX {}", vplex.forDisplay());
}
if (null == clusterIdToNameMap || clusterIdToNameMap.isEmpty()) {
_log.warn("Could not update virtual pool matches for VPLEX {} because cluster name info couldn't be retrieved", vplex.forDisplay());
continue;
}
// Create a map of virtual arrays to their respective VPLEX cluster (a varray is not allowed to have both VPLEX clusters)
Map<String, String> varrayToClusterIdMap = new HashMap<String, String>();
// Since there may be a lot of unmanaged volumes to process, we use the iterative query
Iterator<UnManagedVolume> volumeIter = dbClient.queryIterativeObjects(UnManagedVolume.class, ssToUmvEntry.getValue());
while (volumeIter.hasNext()) {
UnManagedVolume volume = volumeIter.next();
String highAvailability = null;
if (volume.getVolumeInformation().get(SupportedVolumeInformation.VPLEX_LOCALITY.toString()) != null) {
String haFound = volume.getVolumeInformation().get(SupportedVolumeInformation.VPLEX_LOCALITY.toString()).iterator().next();
if (haFound.equalsIgnoreCase(LOCAL)) {
highAvailability = VirtualPool.HighAvailabilityType.vplex_local.name();
} else {
highAvailability = VirtualPool.HighAvailabilityType.vplex_distributed.name();
}
}
_log.debug("finding valid virtual pools for UnManagedVolume {}", volume.getLabel());
// - The vpool is RPVPLEX and this is a VPLEX local volume (likely a journal)
if (!vpool.getHighAvailability().equals(highAvailability) && !(VirtualPool.vPoolSpecifiesRPVPlex(vpool) && highAvailability.equals(VirtualPool.HighAvailabilityType.vplex_local.name()))) {
_log.info(String.format(" virtual pool %s is not valid because " + "its high availability setting does not match the unmanaged volume %s", vpool.getLabel(), volume.forDisplay()));
continue;
}
// If the volume is in a CG, the vpool must specify multi-volume consistency.
Boolean mvConsistency = vpool.getMultivolumeConsistency();
if ((TRUE.equals(volume.getVolumeCharacterstics().get(SupportedVolumeCharacterstics.IS_VOLUME_ADDED_TO_CONSISTENCYGROUP.toString()))) && ((mvConsistency == null) || (mvConsistency == Boolean.FALSE))) {
_log.info(String.format(" virtual pool %s is not valid because it does not have the " + "multi-volume consistency flag set, and the unmanaged volume %s is in a consistency group", vpool.getLabel(), volume.forDisplay()));
continue;
}
StringSet volumeClusters = new StringSet();
if (volume.getVolumeInformation().get(SupportedVolumeInformation.VPLEX_CLUSTER_IDS.toString()) != null) {
volumeClusters.addAll(volume.getVolumeInformation().get(SupportedVolumeInformation.VPLEX_CLUSTER_IDS.toString()));
}
// VPool must be assigned to a varray corresponding to volume's clusters.
StringSet varraysForVpool = vpool.getVirtualArrays();
for (String varrayId : varraysForVpool) {
String varrayClusterId = varrayToClusterIdMap.get(varrayId);
if (null == varrayClusterId) {
varrayClusterId = ConnectivityUtil.getVplexClusterForVarray(URI.create(varrayId), vplex.getId(), dbClient);
varrayToClusterIdMap.put(varrayId, varrayClusterId);
}
if (!ConnectivityUtil.CLUSTER_UNKNOWN.equals(varrayClusterId)) {
String varrayClusterName = clusterIdToNameMap.get(varrayClusterId);
if (volumeClusters.contains(varrayClusterName)) {
if (volume.getSupportedVpoolUris() == null) {
volume.setSupportedVpoolUris(new StringSet());
}
volume.getSupportedVpoolUris().add(vpool.getId().toString());
List<UnManagedVolume> backendVols = VplexBackendIngestionContext.findBackendUnManagedVolumes(volume, dbClient);
if (backendVols != null) {
for (UnManagedVolume backendVol : backendVols) {
if (backendVol.getSupportedVpoolUris() == null) {
backendVol.setSupportedVpoolUris(new StringSet());
}
backendVol.getSupportedVpoolUris().add(vpool.getId().toString());
modifiedUnManagedVolumes.add(backendVol);
}
}
modifiedUnManagedVolumes.add(volume);
break;
}
}
}
if (!modifiedUnManagedVolumes.contains(volume)) {
_log.info(String.format(" virtual pool %s is not valid because " + "volume %s resides on a cluster that does not match the varray(s) associated with the vpool", vpool.getLabel(), volume.forDisplay()));
}
}
}
_log.info("END: matching virtual pool with unmanaged volume for VPLEX");
}
Aggregations