use of com.emc.storageos.db.client.model.VirtualArray in project coprhd-controller by CoprHD.
the class SRDFScheduler method findDestPoolsForSourcePool.
/**
* Generate a list of storage pools for each varray that can provide a valid target path. The
* seed data is the recommendedPool; the storage pool must have SRDF capability to the
* destination pool.
*
* @param targetVarrays
* target virtual arrays to cycle through
* @param srcDestPoolsList
* src/dest pool list
* @param recommendedPool
* current recommended pool to check
* @return a map of storage pools that can be protected by recommendedPool
*/
private Map<VirtualArray, List<StoragePool>> findDestPoolsForSourcePool(final List<VirtualArray> targetVarrays, final Set<SRDFPoolMapping> srcDestPoolsList, final StoragePool recommendedPool, VirtualPool vpool) {
// Create a return map
Map<VirtualArray, List<StoragePool>> targetVarrayPoolMap = new HashMap<VirtualArray, List<StoragePool>>();
// For each target Varray, see if you have any src/dest entries that have the same pool.
for (VirtualArray targetVarray : targetVarrays) {
Set<StoragePool> uniquePools = new HashSet<StoragePool>();
_log.info("Phase 1: Target Pool mapping for varray: " + targetVarray.getLabel());
for (SRDFPoolMapping srdfPoolMapping : srcDestPoolsList) {
if (srdfPoolMapping.destVarray.getId().equals(targetVarray.getId()) && srdfPoolMapping.sourceStoragePool.equals(recommendedPool)) {
_log.info("Phase 1: Target Pool mapping adding: " + srdfPoolMapping.destStoragePool.getLabel());
uniquePools.add(srdfPoolMapping.destStoragePool);
}
}
List<StoragePool> uniquePoolList = new ArrayList<StoragePool>();
uniquePoolList.addAll(uniquePools);
uniquePoolList = filterPoolsForSupportedActiveModeProvider(uniquePoolList, vpool);
targetVarrayPoolMap.put(targetVarray, uniquePoolList);
}
return targetVarrayPoolMap;
}
use of com.emc.storageos.db.client.model.VirtualArray in project coprhd-controller by CoprHD.
the class SRDFScheduler method scheduleStorageSourcePoolConstraint.
/**
* Schedule storage based on the incoming storage pools for source volumes. Find a source
* storage pool that can provide a source volume that satisfies the vpool's criteria for all
* targets varrays required and build a recommendation structure to describe the findings.
*
* Strategy:
*
* 0. When we come into method, we already have a list of candidate source pools, which may be
* in multiple arrays 1. Get matching pools for each of the target virtual arrays based on the
* target virtual pool. 2. Make a map of virtual array to potential pools in step 1. 3. Find a
* pool from each entry in the map that belongs to a storage system that is connected via SRDF
* (with the same policy) to the specific candidate pool we're looking at. 4. Generate an SRDF
* Recommendation object that reflects the combination we found.
*
* @param varray
* varray requested for source
* @param srdfVarrays
* Varray to protect this volume to.
* @param vpool
* vpool requested
* @param capabilities
* parameters
* @param candidatePools
* candidate pools to use for source
* @param vpoolChangeVolume
* vpool change volume, if applicable
* @return list of Recommendation objects to satisfy the request
*/
private List<Recommendation> scheduleStorageSourcePoolConstraint(final VirtualArray varray, final Project project, final VirtualPool vpool, final VirtualPoolCapabilityValuesWrapper capabilities, final List<StoragePool> candidatePools, final Volume vpoolChangeVolume, final URI consistencyGroupUri) {
// Initialize a list of recommendations to be returned.
List<Recommendation> recommendations = new ArrayList<Recommendation>();
if (capabilities.getResourceCount() == 1) {
// For single resource request, select storage pool randomly from all candidate pools
// (to minimize collisions).
Collections.shuffle(candidatePools);
} else {
// Sort all pools in descending order by free capacity (first order) and in ascending
// order by ratio
// of pool's subscribed capacity to total capacity(suborder). This order is kept through
// the selection procedure.
_blockScheduler.sortPools(candidatePools);
}
List<VirtualArray> targetVarrays = getTargetVirtualArraysForVirtualPool(project, vpool, _dbClient, _permissionsHelper);
// Attempt to use these pools for selection based on target
StringBuffer sb = new StringBuffer("Determining if SRDF is possible from " + varray.getId() + " to: ");
for (VirtualArray targetVarray : targetVarrays) {
sb.append(targetVarray.getId()).append(" ");
}
_log.info(sb.toString());
// The port group provided is belongs to SRDF source storage system.
// If port group set in capabilities, ViPR looks storage pools from given PG's storage system only
// Need to remove PORT_GROUP entry from capabilities for SRDF target volume,
// so that ViPR picks SRDF target storage pools from right storage system.
//
capabilities.removeCapabilityEntry(VirtualPoolCapabilityValuesWrapper.PORT_GROUP);
Map<String, Object> attributeMap = new HashMap<String, Object>();
Map<VirtualArray, List<StoragePool>> varrayPoolMap = getMatchingPools(targetVarrays, vpool, capabilities, attributeMap);
if (varrayPoolMap == null || varrayPoolMap.isEmpty()) {
// No matching storage pools found for any of the target varrays. There are no target
// storage pools that match the passed vpool parameters and protocols and/or there are
// no pools that have enough
// capacity to hold at least one resource of the requested size.
Set<String> tmpTargetVarrays = new HashSet<String>();
sb = new StringBuffer("No matching storage pools found for any of the target varrays: [ ");
for (VirtualArray targetVarray : targetVarrays) {
sb.append(targetVarray.getId()).append(" ");
tmpTargetVarrays.add(targetVarray.getLabel());
}
sb.append("]. There are no storage pools that match the passed vpool parameters and protocols and/or " + "there are no pools that have enough capacity to hold at least one resource of the requested size.");
StringBuffer errorMessage = new StringBuffer();
if (attributeMap.get(AttributeMatcher.ERROR_MESSAGE) != null) {
errorMessage = (StringBuffer) attributeMap.get(AttributeMatcher.ERROR_MESSAGE);
}
_log.error(sb.toString());
throw APIException.badRequests.noMatchingRecoverPointStoragePoolsForVpoolAndVarrays(vpool.getLabel(), tmpTargetVarrays, errorMessage.toString());
}
// Reduce the source and target pool down to the pools available via target.
Set<SRDFPoolMapping> tmpDestPoolsList = getSRDFPoolMappings(varray, candidatePools, varrayPoolMap, vpool, vpoolChangeVolume, capabilities.getSize());
if (tmpDestPoolsList == null || tmpDestPoolsList.isEmpty()) {
// There are no target pools from any of the target varrays that share the
// same SRDF connectivity as any of the source varray pools. Placement cannot
// be achieved.
Set<String> tmpSRDFVarrays = new HashSet<String>();
sb = new StringBuffer("No matching target pool found for varray: ");
sb.append(varray.getId());
sb.append(" and vpool: ");
sb.append(vpool.getId());
sb.append(" to varrays: ");
for (VirtualArray targetVarray : targetVarrays) {
sb.append(targetVarray.getId()).append(" ");
tmpSRDFVarrays.add(targetVarray.getLabel());
}
// No matching target pool found for varray so throw an exception
// indicating a placement error.
_log.error(sb.toString());
throw APIException.badRequests.noMatchingSRDFPools(varray.getLabel(), vpool.getLabel(), tmpSRDFVarrays);
}
// Fire business rules to determine which SRDFPoolMappings can be eliminated
// from consideration for placement.
Set<SRDFPoolMapping> srcDestPoolsList = fireSRDFPlacementRules(tmpDestPoolsList, capabilities.getResourceCount());
// the volume request configuration throw an exception.
if (srcDestPoolsList == null || srcDestPoolsList.isEmpty()) {
throw APIException.badRequests.srdfNoSolutionsFoundError();
}
// Get a new source pool list for pool selection
Set<StoragePool> sourceCandidatePoolList = new HashSet<StoragePool>();
for (SRDFPoolMapping srdfPoolMapping : srcDestPoolsList) {
sourceCandidatePoolList.add(srdfPoolMapping.sourceStoragePool);
}
// Try with the storagePoolList as it currently is.
// If we get through the process and couldn't achieve full target, we should
// take out the matched pool from the storagePoolList and try again.
List<StoragePool> sourcePoolList = new ArrayList<StoragePool>();
sourcePoolList.addAll(sourceCandidatePoolList);
// We need to create recommendations for one or more pools
// that can accommodate the number of requested resources.
// We start by trying to place all resources in a single
// pool if one exists that can accommodate all requested
// resources and work our way down as necessary trying to
// minimize the number of pools used to satisfy the request.
int recommendedCount = 0;
int currentCount = capabilities.getResourceCount();
// satisfied all of the requests.
while (!sourcePoolList.isEmpty() && recommendedCount < capabilities.getResourceCount()) {
// This request will either decrement the count OR shrink the sourcePoolList
// In the case of decrementing the count, it's because it was successful at
// placing volume(s). If it wasn't, that source pool goes in the trash and we
// try the next one.
long resourceSize = capabilities.getSize();
int resourceCount = capabilities.getResourceCount();
// We need to find a pool that matches the capacity for all the source/target luns
long requiredPoolCapacity = resourceSize * currentCount;
_log.info("Required pool capacity: " + requiredPoolCapacity);
StoragePool poolWithRequiredCapacity = _blockScheduler.getPoolMatchingCapacity(requiredPoolCapacity, resourceSize, currentCount, sourcePoolList, VirtualPool.ProvisioningType.Thin.toString().equalsIgnoreCase(vpool.getSupportedProvisioningType()), null);
// pool, setting the resource count for that recommendation.
if (poolWithRequiredCapacity != null) {
StoragePool recommendedPool = poolWithRequiredCapacity;
_log.debug("Recommending storage pool {} for {} resources.", recommendedPool.getId(), currentCount);
// Now we know what pool was selected, we can grab the target pools that jive with that
// source
Map<VirtualArray, List<StoragePool>> targetVarrayPoolMap = findDestPoolsForSourcePool(targetVarrays, srcDestPoolsList, recommendedPool, vpool);
if (targetVarrayPoolMap == null || targetVarrayPoolMap.isEmpty()) {
// A valid source pool was found but there are no pools from any of the
// target varrays that can protect it.
_log.info("There are no pools from any of the target varrays that can protect the source " + "varray pool {}. Will try using another source varray pool.", recommendedPool.getLabel());
// Remove the source pool and try the next one.
sourcePoolList.remove(poolWithRequiredCapacity);
} else {
// A single recommendation object will create a set of volumes for an SRDF pair.
SRDFRecommendation rec = new SRDFRecommendation();
// For each target varray, we start the process of matching source and destination
// pools to one storage system.
Map<VirtualArray, Set<StorageSystem>> varrayTargetDeviceMap = new HashMap<VirtualArray, Set<StorageSystem>>();
for (VirtualArray targetVarray1 : targetVarrayPoolMap.keySet()) {
if (rec.getSourceStoragePool() == null) {
rec.setVirtualArray(varray.getId());
rec.setVirtualPool(vpool);
rec.setSourceStoragePool(recommendedPool.getId());
rec.setResourceCount(currentCount);
rec.setSourceStorageSystem(recommendedPool.getStorageDevice());
rec.setVirtualArrayTargetMap(new HashMap<URI, Target>());
rec.setVpoolChangeVolume(vpoolChangeVolume != null ? vpoolChangeVolume.getId() : null);
rec.setVpoolChangeVpool(vpoolChangeVolume != null ? vpool.getId() : null);
}
if (targetVarrayPoolMap.get(targetVarray1) == null || targetVarrayPoolMap.get(targetVarray1).isEmpty()) {
_log.error("Could not find any suitable storage pool for target varray: " + targetVarray1.getLabel());
throw APIException.badRequests.unableToFindSuitablePoolForTargetVArray(targetVarray1.getLabel());
}
// Select the destination pool based on what was selected as source
StoragePool destinationPool = _blockScheduler.selectPool(targetVarrayPoolMap.get(targetVarray1));
_log.info("Destination target for varray " + targetVarray1.getLabel() + " was determined to be in pool: " + destinationPool.getLabel());
Target target = new Target();
target.setTargetPool(destinationPool.getId());
target.setTargetStorageDevice(destinationPool.getStorageDevice());
// Set the copy mode
Map<URI, VpoolRemoteCopyProtectionSettings> settingsMap = VirtualPool.getRemoteProtectionSettings(vpool, _dbClient);
target.setCopyMode(settingsMap.get(targetVarray1.getId()).getCopyMode());
if (target.getCopyMode() == null) {
// Set the default if not set
target.setCopyMode(RemoteDirectorGroup.SupportedCopyModes.ASYNCHRONOUS.toString());
}
// Generate a list of storage systems that match the src and dest pools lists.
Set<StorageSystem> targetDeviceList = findMatchingSRDFPools(targetVarray1, srcDestPoolsList, recommendedPool, destinationPool);
if (targetDeviceList.isEmpty()) {
_log.error("Could not find a Storage pool for target varray: " + targetVarray1.getLabel());
throw APIException.badRequests.unableToFindSuitablePoolForTargetVArray(targetVarray1.getLabel());
}
rec.getVirtualArrayTargetMap().put(targetVarray1.getId(), target);
// Add this potential solution to the map.
varrayTargetDeviceMap.put(targetVarray1, targetDeviceList);
}
// Grab any element since all varrays need to have the same SRDF connectivity.
VirtualArray firstVarray = null;
for (VirtualArray baseVarray : varrayTargetDeviceMap.keySet()) {
firstVarray = baseVarray;
break;
}
_log.info("Chose the first varray for SRDF comparison: " + firstVarray.getLabel());
// Now go through each storage system in this varray and see if it matches up
findInsertRecommendation(rec, firstVarray, recommendations, candidatePools, recommendedPool, varrayTargetDeviceMap, project, consistencyGroupUri);
// Update the count of resources for which we have created
// a recommendation.
recommendedCount += currentCount;
// Update the current count. The conditional prevents
// unnecessary attempts to look for pools of a given
// free capacity that we already know don't exist. For
// example, say we want 100 resources and the first pool
// we find that can hold multiple resources can hold only
// 10. We don't want to continue looking for pools that
// can hold 90,89,88,...11 resources. We just want to
// see if there is another pool that can hold 10 resources,
// then 9,8, and so on.
currentCount = resourceCount - recommendedCount < currentCount ? resourceCount - recommendedCount : currentCount;
}
} else {
// If we can't find a pool that can hold the current
// count of resources, decrease the count so that we look
// for pools that can hold the next smaller number.
currentCount--;
// Clear out the source pool list (which will cause failure)
sourcePoolList.clear();
}
// log an error and clear the list of recommendations.
if (recommendedCount != resourceCount) {
_log.error("Could not find matching pools for varray {} & vpool {}", varray.getId(), vpool.getId());
recommendations.clear();
// Remove the pool we chose from the list so we can try again.
sourcePoolList.remove(poolWithRequiredCapacity);
}
}
return recommendations;
}
use of com.emc.storageos.db.client.model.VirtualArray in project coprhd-controller by CoprHD.
the class SRDFScheduler method getMatchingPools.
/**
* Gather matching pools for a collection of varrays
*
* @param varrays
* The target varrays
* @param vpool
* the requested vpool that must be satisfied by the storage pool
* @param capabilities
* capabilities
* @param attributeMap
* attributeMap
* @return A list of matching storage pools and varray mapping
*/
private Map<VirtualArray, List<StoragePool>> getMatchingPools(final List<VirtualArray> varrays, final VirtualPool vpool, final VirtualPoolCapabilityValuesWrapper capabilities, Map<String, Object> attributeMap) {
Map<VirtualArray, List<StoragePool>> varrayStoragePoolMap = new HashMap<VirtualArray, List<StoragePool>>();
Map<URI, VpoolRemoteCopyProtectionSettings> settingsMap = VirtualPool.getRemoteProtectionSettings(vpool, _dbClient);
for (VirtualArray varray : varrays) {
// If there was no vpool specified with the target settings, use the base vpool for this
// varray.
VirtualPool targetVpool = vpool;
VpoolRemoteCopyProtectionSettings settings = settingsMap.get(varray.getId());
if (settings != null && settings.getVirtualPool() != null) {
targetVpool = _dbClient.queryObject(VirtualPool.class, settings.getVirtualPool());
}
capabilities.put(VirtualPoolCapabilityValuesWrapper.PERSONALITY, VirtualPoolCapabilityValuesWrapper.SRDF_TARGET);
// Find a matching pool for the target vpool
varrayStoragePoolMap.put(varray, _blockScheduler.getMatchingPools(varray, targetVpool, capabilities, attributeMap));
}
return varrayStoragePoolMap;
}
use of com.emc.storageos.db.client.model.VirtualArray in project coprhd-controller by CoprHD.
the class SRDFScheduler method getTargetVirtualArraysForVirtualPool.
/**
* Gets and verifies that the target varrays passed in the request are accessible to the tenant.
*
* @param project
* A reference to the project.
* @param vpool
* class of service, contains target varrays
* @return A reference to the varrays
* @throws java.net.URISyntaxException
* @throws com.emc.storageos.db.exceptions.DatabaseException
*/
public static List<VirtualArray> getTargetVirtualArraysForVirtualPool(final Project project, final VirtualPool vpool, final DbClient dbClient, final PermissionsHelper permissionHelper) {
List<VirtualArray> targetVirtualArrays = new ArrayList<VirtualArray>();
if (VirtualPool.getRemoteProtectionSettings(vpool, dbClient) != null) {
for (URI targetVirtualArray : VirtualPool.getRemoteProtectionSettings(vpool, dbClient).keySet()) {
VirtualArray nh = dbClient.queryObject(VirtualArray.class, targetVirtualArray);
targetVirtualArrays.add(nh);
permissionHelper.checkTenantHasAccessToVirtualArray(project.getTenantOrg().getURI(), nh);
}
}
return targetVirtualArrays;
}
use of com.emc.storageos.db.client.model.VirtualArray in project coprhd-controller by CoprHD.
the class StorageScheduler method prepareFullCopyVolumeFromVolume.
private static Volume prepareFullCopyVolumeFromVolume(DbClient dbClient, String name, Volume sourceVolume, VolumeRecommendation recommendation, int volumeCounter, VirtualPoolCapabilityValuesWrapper capabilities, Boolean createInactive) {
long size = sourceVolume.getCapacity();
long preAllocateSize = 0;
if (null != sourceVolume.getThinVolumePreAllocationSize()) {
preAllocateSize = sourceVolume.getThinVolumePreAllocationSize();
}
NamedURI projectUri = sourceVolume.getProject();
Project project = dbClient.queryObject(Project.class, projectUri);
URI vArrayUri = sourceVolume.getVirtualArray();
VirtualArray vArray = dbClient.queryObject(VirtualArray.class, vArrayUri);
URI vPoolUri = sourceVolume.getVirtualPool();
VirtualPool vPool = dbClient.queryObject(VirtualPool.class, vPoolUri);
String label = name + (volumeCounter > 0 ? ("-" + volumeCounter) : "");
Volume volume = prepareVolume(dbClient, null, size, preAllocateSize, project, vArray, vPool, recommendation, label, null, capabilities, createInactive);
// Since this is a full copy, update it with URI of the source volume
volume.setAssociatedSourceVolume(sourceVolume.getId());
StringSet associatedFullCopies = sourceVolume.getFullCopies();
if (associatedFullCopies == null) {
associatedFullCopies = new StringSet();
sourceVolume.setFullCopies(associatedFullCopies);
}
associatedFullCopies.add(volume.getId().toString());
dbClient.persistObject(volume);
dbClient.persistObject(sourceVolume);
addVolumeCapacityToReservedCapacityMap(dbClient, volume);
return volume;
}
Aggregations