use of com.emc.storageos.db.client.model.StringSet in project coprhd-controller by CoprHD.
the class BlockSnapshotSessionCreateCompleter method complete.
/**
* {@inheritDoc}
*/
@Override
protected void complete(DbClient dbClient, Status status, ServiceCoded coded) throws DeviceControllerException {
try {
BlockSnapshotSession snapSession = dbClient.queryObject(BlockSnapshotSession.class, getId());
// Update the status map of the snapshot session.
switch(status) {
case error:
// Mark any linked targets inactive. This would not
// normally case when failing to create a snapshot
// session as targets are not linked when a new
// snapshot session is prepared in ViPR. However,
// it could be the case when restoring a source volume
// form a linked target.
StringSet linkedTargets = snapSession.getLinkedTargets();
if ((linkedTargets != null) && (!linkedTargets.isEmpty())) {
for (String linkedTarget : linkedTargets) {
BlockSnapshot target = dbClient.queryObject(BlockSnapshot.class, URI.create(linkedTarget));
if (target != null) {
target.setInactive(true);
dbClient.updateObject(target);
}
}
}
// Mark ViPR snapshot session inactive on error.
snapSession.setInactive(true);
dbClient.updateObject(snapSession);
break;
case ready:
break;
default:
String errMsg = String.format("Unexpected status %s for completer for step %s", status.name(), getOpId());
s_logger.info(errMsg);
throw DeviceControllerException.exceptions.unexpectedCondition(errMsg);
}
s_logger.info("Done snapshot session create step {} with status: {}", getOpId(), status.name());
} catch (Exception e) {
s_logger.error("Failed updating status for snapshot session create step {}", getOpId(), e);
} finally {
super.complete(dbClient, status, coded);
}
}
use of com.emc.storageos.db.client.model.StringSet in project coprhd-controller by CoprHD.
the class VPlexBlockServiceApiImpl method createVPlexVolumeDescriptors.
/**
* Create the necessary volume descriptors for Vplex volumes, including the backend
* volume descriptors and the virtual volume descriptors.
*
* @param param
* - the VolumeCreate parameters
* @param project
* -- user's project
* @param vArray
* -- virtual array volumes are created in
* @param vPool
* -- virtual pool (ROOT) used to create the volumes
* @param recommendations
* -- recommendations received from placement
* @param task
* -- a task identifier
* @param vPoolCapabilities
* - VirtualPoolCapabilitiesWrapper
* @param blockConsistencyGroupURI
* - the block consistency group URI
* @param taskList
* - OUTPUT list of tasks created
* @param allVolumes
* - OUTPUT - list of volumes created
* @param createTask
* -- boolean flag indicating to create tasks
* @return
*/
public List<VolumeDescriptor> createVPlexVolumeDescriptors(VolumeCreate param, Project project, final VirtualArray vArray, final VirtualPool vPool, List<Recommendation> recommendations, String task, VirtualPoolCapabilityValuesWrapper vPoolCapabilities, URI blockConsistencyGroupURI, TaskList taskList, List<URI> allVolumes, boolean createTask) {
s_logger.info("Request to create {} VPlex virtual volume(s)", vPoolCapabilities.getResourceCount());
// Determine if we're processing an SRDF copy so we can set appropriate name.
boolean srdfCopy = false;
if (recommendations.get(0).getRecommendation() != null && recommendations.get(0).getRecommendation() instanceof SRDFCopyRecommendation) {
srdfCopy = true;
}
// Sort the recommendations by VirtualArray. There can be up to two
// VirtualArrays, the requested VirtualArray and the HA VirtualArray
// either passed or determined by the placement when HA virtual volumes
// are being created. We also set the VPlex storage system, which
// should be the same for all recommendations.
URI vplexStorageSystemURI = null;
URI[] vplexSystemURIOut = new URI[1];
Map<String, List<VPlexRecommendation>> varrayRecommendationsMap = sortRecommendationsByVarray(recommendations, vplexSystemURIOut);
vplexStorageSystemURI = vplexSystemURIOut[0];
// for the srdf copies, since they are already pre-created.
if (!srdfCopy) {
validateVolumeLabels(param.getName(), project, vPoolCapabilities, varrayRecommendationsMap);
}
// Determine the project to be used for the VPlex's artifacts
StorageSystem vplexStorageSystem = _dbClient.queryObject(StorageSystem.class, vplexStorageSystemURI);
Project vplexProject = getVplexProject(vplexStorageSystem, _dbClient, _tenantsService);
// The volume size.
long size = SizeUtil.translateSize(param.getSize());
// The consistency group or null when not specified.
final BlockConsistencyGroup consistencyGroup = blockConsistencyGroupURI == null ? null : _dbClient.queryObject(BlockConsistencyGroup.class, blockConsistencyGroupURI);
// Find all volumes assigned to the group
boolean cgContainsVolumes = false;
if (consistencyGroup != null) {
final List<Volume> activeCGVolumes = getActiveCGVolumes(consistencyGroup);
cgContainsVolumes = (activeCGVolumes != null && !activeCGVolumes.isEmpty());
}
// If the consistency group is created but does not specify the LOCAL
// type, the CG must be a CG created prior to 2.2 or an ingested CG. In
// this case, we don't want a volume creation to result in backend CGs.
// The only exception is if the CG does not reference any volumes. In
// this case, if the LOCAL type isn't specified, we can create backend
// CGs.
BlockConsistencyGroup backendCG = null;
if (consistencyGroup != null && (!consistencyGroup.created() || !cgContainsVolumes || consistencyGroup.getTypes().contains(Types.LOCAL.toString()))) {
backendCG = consistencyGroup;
}
// Prepare Bourne volumes to represent the backend volumes for the
// recommendations in each VirtualArray.
int varrayCount = 0;
String volumeLabel = param.getName();
List<VolumeDescriptor> descriptors = new ArrayList<VolumeDescriptor>();
URI[][] varrayVolumeURIs = new URI[2][vPoolCapabilities.getResourceCount()];
Iterator<String> varrayIter = varrayRecommendationsMap.keySet().iterator();
while (varrayIter.hasNext()) {
String varrayId = varrayIter.next();
s_logger.info("Processing backend recommendations for Virtual Array {}", varrayId);
List<VPlexRecommendation> vplexRecommendations = varrayRecommendationsMap.get(varrayId);
List<VolumeDescriptor> varrayDescriptors = makeBackendVolumeDescriptors(vplexRecommendations, project, vplexProject, vPool, volumeLabel, varrayCount, size, backendCG, vPoolCapabilities, createTask, task);
descriptors.addAll(varrayDescriptors);
List<URI> varrayURIs = VolumeDescriptor.getVolumeURIs(varrayDescriptors);
allVolumes.addAll(varrayURIs);
for (int i = 0; i < varrayURIs.size(); i++) {
varrayVolumeURIs[varrayCount][i] = varrayURIs.get(i);
}
varrayCount++;
}
// Prepare Bourne volumes to represent the highly available virtual
// volumes and associate the virtual volumes with their associated
// backend volumes.
s_logger.info("Preparing virtual volumes");
List<URI> virtualVolumeURIs = new ArrayList<URI>();
URI nullPoolURI = NullColumnValueGetter.getNullURI();
vPoolCapabilities.put(VirtualPoolCapabilityValuesWrapper.AUTO_TIER__POLICY_NAME, null);
for (int i = 0; i < vPoolCapabilities.getResourceCount(); i++) {
// Compute the volume label based on the label of the underlying volume
String volumeLabelBuilt = null;
Volume associatedVolume = _dbClient.queryObject(Volume.class, varrayVolumeURIs[0][i]);
// Get the virtual volume backing replication group instance name, if available.
String backingReplicationGroupInstance = null;
if (associatedVolume != null) {
volumeLabelBuilt = generateLabelFromAssociatedVolume(volumeLabel, associatedVolume);
backingReplicationGroupInstance = NullColumnValueGetter.isNotNullValue(associatedVolume.getReplicationGroupInstance()) ? associatedVolume.getReplicationGroupInstance() : NullColumnValueGetter.getNullStr();
} else {
volumeLabelBuilt = AbstractBlockServiceApiImpl.generateDefaultVolumeLabel(volumeLabel, i, vPoolCapabilities.getResourceCount());
}
s_logger.info("Volume label is {}", volumeLabelBuilt);
Volume volume = StorageScheduler.getPrecreatedVolume(_dbClient, taskList, volumeLabelBuilt);
boolean volumePrecreated = false;
if (volume != null) {
volumePrecreated = true;
}
long thinVolumePreAllocationSize = 0;
if (null != vPool.getThinVolumePreAllocationPercentage()) {
thinVolumePreAllocationSize = VirtualPoolUtil.getThinVolumePreAllocationSize(vPool.getThinVolumePreAllocationPercentage(), size);
}
volume = prepareVolume(VolumeType.VPLEX_VIRTUAL_VOLUME, volume, size, thinVolumePreAllocationSize, project, vArray, vPool, vplexStorageSystemURI, nullPoolURI, volumeLabelBuilt, consistencyGroup, vPoolCapabilities);
StringSet associatedVolumes = new StringSet();
associatedVolumes.add(varrayVolumeURIs[0][i].toString());
s_logger.info("Associating volume {}", varrayVolumeURIs[0][i].toString());
// associated with the virtual volume.
if (varrayCount > 1) {
associatedVolumes.add(varrayVolumeURIs[1][i].toString());
s_logger.info("Associating volume {}", varrayVolumeURIs[1][i].toString());
}
volume.setAssociatedVolumes(associatedVolumes);
if (null != backingReplicationGroupInstance) {
s_logger.info("Setting virtual volume backingReplicationGroupInstance to {}", backingReplicationGroupInstance);
volume.setBackingReplicationGroupInstance(backingReplicationGroupInstance);
}
_dbClient.updateObject(volume);
URI volumeId = volume.getId();
s_logger.info("Prepared virtual volume {}", volumeId);
virtualVolumeURIs.add(volumeId);
allVolumes.add(volumeId);
if (createTask && !volumePrecreated) {
Operation op = _dbClient.createTaskOpStatus(Volume.class, volume.getId(), task, ResourceOperationTypeEnum.CREATE_BLOCK_VOLUME);
TaskResourceRep volumeTask = toTask(volume, task, op);
taskList.getTaskList().add(volumeTask);
}
VolumeDescriptor descriptor = new VolumeDescriptor(VolumeDescriptor.Type.VPLEX_VIRT_VOLUME, vplexStorageSystemURI, volumeId, null, consistencyGroup == null ? null : consistencyGroup.getId(), vPoolCapabilities, volume.getCapacity());
// Set the compute resource in the descriptor if the volume to be created will be exported
// to a host/cluster after it has been created so that the compute resource name can be
// included in the volume name if the custom volume naming is so configured. Do not set the
// compute resource if the descriptor is for an SRDF target as the target is not exported
// to the compute resource.
URI computeResourceURI = param.getComputeResource();
if ((computeResourceURI != null) && (!srdfCopy)) {
s_logger.info(String.format("Volume %s - will be exported to Host/Cluster: %s", volume.getLabel(), computeResourceURI.toString()));
descriptor.setComputeResource(computeResourceURI);
}
descriptors.add(descriptor);
}
return descriptors;
}
use of com.emc.storageos.db.client.model.StringSet in project coprhd-controller by CoprHD.
the class VPlexBlockServiceApiImpl method addVplexMirrorToVolume.
/**
* Adds a VplexMirror structure to a Volume's mirror set.
*/
private static void addVplexMirrorToVolume(Volume volume, VplexMirror mirror, DbClient dbClient) {
StringSet mirrors = volume.getMirrors();
if (mirrors == null) {
mirrors = new StringSet();
}
mirrors.add(mirror.getId().toString());
volume.setMirrors(mirrors);
// Persist changes
dbClient.updateObject(volume);
}
use of com.emc.storageos.db.client.model.StringSet in project coprhd-controller by CoprHD.
the class VirtualPoolService method refreshMatchedPools.
/**
* Refresh the matching pools by running implicit pool matcher algorithm and
* find if there are any new matched pools exists in the environment.
* Returns the new matched pools to user.
*
* @param id the URN of a ViPR VirtualPool.
* @return : list of pools.
*/
protected StoragePoolList refreshMatchedPools(VirtualPool.Type type, URI id) {
ArgValidator.checkUri(id);
StoragePoolList poolList = new StoragePoolList();
VirtualPool vpool = queryResource(id);
ArgValidator.checkEntityNotNull(vpool, id, isIdEmbeddedInURL(id));
if (!vpool.getType().equals(type.name())) {
throw APIException.badRequests.providedVirtualPoolNotCorrectType();
}
StringBuffer errorMessage = new StringBuffer();
ImplicitPoolMatcher.matchVirtualPoolWithAllStoragePools(vpool, _dbClient, _coordinator, errorMessage);
_dbClient.updateAndReindexObject(vpool);
StringSet matchedPools = vpool.getMatchedStoragePools();
if (null != matchedPools && !matchedPools.isEmpty()) {
Iterator<String> vpoolItr = matchedPools.iterator();
while (vpoolItr.hasNext()) {
URI poolURI = URI.create(vpoolItr.next());
StoragePool pool = _dbClient.queryObject(StoragePool.class, poolURI);
if (pool == null) {
continue;
}
poolList.getPools().add(toNamedRelatedResource(pool));
}
}
return poolList;
}
use of com.emc.storageos.db.client.model.StringSet in project coprhd-controller by CoprHD.
the class VirtualPoolService method getPoolsWithVPoolResources.
/**
* Calculate the storage pools which have the vpool resources.
* 1) Get list of vpool resources
* 2) For each of the vpool's matched pool, get the pool resources
* 3) If there is resource in storage pool which is also in the vpool resource list, add to the pool list
*
* @param vpool
* @param dbClient
* @return List of storage pools with vpool resources.
*/
public static Set<String> getPoolsWithVPoolResources(VirtualPool vpool, Set<String> pools, DbClient dbClient) {
Set<String> resourcePools = new StringSet();
_log.debug("Getting the storage pools with resources of virtual pool {}.", vpool.getLabel());
if (null != pools && !pools.isEmpty()) {
Iterator<String> poolItr = pools.iterator();
while (poolItr.hasNext()) {
String matchedPool = poolItr.next();
URI poolURI = URI.create(matchedPool);
URIQueryResultList poolResourcesResultList = new URIQueryResultList();
URIQueryResultList vpoolResourcesResultList = new URIQueryResultList();
if (VirtualPool.Type.block.name().equals(vpool.getType())) {
dbClient.queryByConstraint(ContainmentConstraint.Factory.getStoragePoolVolumeConstraint(poolURI), poolResourcesResultList);
dbClient.queryByConstraint(ContainmentConstraint.Factory.getVirtualPoolVolumeConstraint(vpool.getId()), vpoolResourcesResultList);
} else if (VirtualPool.Type.file.name().equals(vpool.getType())) {
dbClient.queryByConstraint(ContainmentConstraint.Factory.getStoragePoolFileshareConstraint(poolURI), poolResourcesResultList);
dbClient.queryByConstraint(ContainmentConstraint.Factory.getVirtualPoolFileshareConstraint(vpool.getId()), vpoolResourcesResultList);
} else if (VirtualPool.Type.object.name().equals(vpool.getType())) {
dbClient.queryByConstraint(ContainmentConstraint.Factory.getStoragePoolBucketConstraint(poolURI), poolResourcesResultList);
dbClient.queryByConstraint(ContainmentConstraint.Factory.getVirtualPoolBucketConstraint(vpool.getId()), vpoolResourcesResultList);
}
// Create a set of vpoolResourcesResultList
HashSet<URI> vpoolResourceSet = new HashSet<URI>();
for (URI vpoolResource : vpoolResourcesResultList) {
vpoolResourceSet.add(vpoolResource);
}
// Now look up if there are pool resources in the vpool resources set.
for (URI poolResource : poolResourcesResultList) {
if (vpoolResourceSet.contains(poolResource)) {
boolean inactive = false;
if (VirtualPool.Type.block.name().equals(vpool.getType())) {
Volume resource = dbClient.queryObject(Volume.class, poolResource);
inactive = resource.getInactive();
} else if (VirtualPool.Type.file.name().equals(vpool.getType())) {
FileShare resource = dbClient.queryObject(FileShare.class, poolResource);
inactive = resource.getInactive();
}
if (!inactive) {
_log.info("Found vpool resource {} in the storage pool {}", poolResource, matchedPool);
resourcePools.add(matchedPool);
break;
}
}
}
}
}
return resourcePools;
}
Aggregations