use of com.emc.storageos.db.client.model.VolumeGroup in project coprhd-controller by CoprHD.
the class ControllerUtils method getApplicationForCG.
/**
* gets the application volume group for this CG and group name if it exists
*
* @param dbClient
* dbClient to query objects from db
* @param consistencyGroup
* consistency group object
* @param cgNameOnArray
* cg name to check
* @return a VolumeGroup object or null if this CG and group name are not associated with an application
*/
public static VolumeGroup getApplicationForCG(DbClient dbClient, BlockConsistencyGroup consistencyGroup, String cgNameOnArray) {
VolumeGroup volumeGroup = null;
URIQueryResultList uriQueryResultList = new URIQueryResultList();
dbClient.queryByConstraint(getVolumesByConsistencyGroup(consistencyGroup.getId()), uriQueryResultList);
Iterator<Volume> volumeIterator = dbClient.queryIterativeObjects(Volume.class, uriQueryResultList);
while (volumeIterator.hasNext()) {
Volume volume = volumeIterator.next();
if (NullColumnValueGetter.isNotNullValue(volume.getReplicationGroupInstance()) && volume.getReplicationGroupInstance().equals(cgNameOnArray)) {
volumeGroup = volume.getApplication(dbClient);
if (volumeGroup != null) {
break;
}
}
}
return volumeGroup;
}
use of com.emc.storageos.db.client.model.VolumeGroup in project coprhd-controller by CoprHD.
the class ControllerUtils method getApplicationsForFullCopies.
/**
* get the list of applications for a list of full copy volumes
*
* @param fcVolumeIds full copy volume ids
* @param dbClient
* @return
*/
public static List<URI> getApplicationsForFullCopies(List<URI> fcVolumeIds, DbClient dbClient) {
Set<URI> volumeGroupIds = new HashSet<URI>();
Iterator<Volume> fcVolumes = dbClient.queryIterativeObjects(Volume.class, fcVolumeIds);
while (fcVolumes.hasNext()) {
Volume fcVolume = fcVolumes.next();
if (!NullColumnValueGetter.isNullURI(fcVolume.getAssociatedSourceVolume())) {
BlockObject sourceObj = BlockObject.fetch(dbClient, fcVolume.getAssociatedSourceVolume());
if (sourceObj instanceof Volume) {
for (String appId : ((Volume) sourceObj).getVolumeGroupIds()) {
volumeGroupIds.add(URI.create(appId));
}
}
}
}
Iterator<VolumeGroup> volumeGroups = dbClient.queryIterativeObjects(VolumeGroup.class, volumeGroupIds);
List<URI> applicationIds = new ArrayList<URI>();
while (volumeGroups.hasNext()) {
VolumeGroup app = volumeGroups.next();
if (app.getRoles().contains(VolumeGroup.VolumeGroupRole.COPY.toString())) {
applicationIds.add(app.getId());
}
}
return applicationIds;
}
use of com.emc.storageos.db.client.model.VolumeGroup in project coprhd-controller by CoprHD.
the class TenantsService method listVolumeGroups.
/**
* List volume groups the user is authorized to see
*
* @param id the URN of a ViPR Tenant/Subtenant
* @prereq none
* @brief List volume groups
* @return List of volume groups
*/
@GET
@Path("/{id}/volume-groups")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public VolumeGroupList listVolumeGroups(@PathParam("id") URI id) {
// tenant id and user permission will get validated in listProjects()
ProjectList projectList = listProjects(id);
Set<URI> projects = new HashSet<URI>();
for (NamedRelatedResourceRep projectRep : projectList.getProjects()) {
projects.add(projectRep.getId());
}
// for each project, get all volumes. Collect volume group ids for all volumes
StringSet volumeGroups = new StringSet();
for (URI project : projects) {
URIQueryResultList list = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getProjectVolumeConstraint(project), list);
Iterator<Volume> resultsIt = _dbClient.queryIterativeObjects(Volume.class, list);
while (resultsIt.hasNext()) {
volumeGroups.addAll(resultsIt.next().getVolumeGroupIds());
}
}
// form Volume Group list response
VolumeGroupList volumeGroupList = new VolumeGroupList();
for (String vg : volumeGroups) {
VolumeGroup volumeGroup = _dbClient.queryObject(VolumeGroup.class, URI.create(vg));
volumeGroupList.getVolumeGroups().add(toNamedRelatedResource(volumeGroup));
}
return volumeGroupList;
}
use of com.emc.storageos.db.client.model.VolumeGroup in project coprhd-controller by CoprHD.
the class RPBlockServiceApiImpl method updateVolumesInVolumeGroup.
/**
* {@inheritDoc}
*/
@Override
public void updateVolumesInVolumeGroup(VolumeGroupVolumeList addVolumes, List<Volume> removeVolumes, URI applicationId, String taskId) {
VolumeGroup volumeGroup = _dbClient.queryObject(VolumeGroup.class, applicationId);
ApplicationAddVolumeList addVolumeList = null;
List<URI> removeVolumesURI = null;
RPController controller = null;
URI protSystemUri = null;
Volume firstVolume = null;
if (addVolumes != null && addVolumes.getVolumes() != null && !addVolumes.getVolumes().isEmpty()) {
addVolumeList = addVolumesToApplication(addVolumes, volumeGroup);
List<URI> vols = addVolumeList.getVolumes();
if (vols != null && !vols.isEmpty()) {
firstVolume = _dbClient.queryObject(Volume.class, vols.get(0));
}
}
if (removeVolumes != null && !removeVolumes.isEmpty()) {
removeVolumesURI = getValidVolumesToRemoveFromCG(removeVolumes);
if (firstVolume == null) {
firstVolume = removeVolumes.get(0);
}
}
if ((addVolumeList != null && !addVolumeList.getVolumes().isEmpty()) || (removeVolumesURI != null && !removeVolumesURI.isEmpty())) {
protSystemUri = firstVolume.getProtectionController();
ProtectionSystem system = _dbClient.queryObject(ProtectionSystem.class, protSystemUri);
controller = getController(RPController.class, system.getSystemType());
controller.updateApplication(protSystemUri, addVolumeList, removeVolumesURI, volumeGroup.getId(), taskId);
} else {
// No need to call to controller. update the application task
Operation op = volumeGroup.getOpStatus().get(taskId);
op.ready();
volumeGroup.getOpStatus().updateTaskStatus(taskId, op);
_dbClient.updateObject(volumeGroup);
}
}
use of com.emc.storageos.db.client.model.VolumeGroup in project coprhd-controller by CoprHD.
the class AbstractBlockServiceApiImpl method prepareSnapshots.
/**
* Prepares the snapshots for a snapshot request.
*
* @param volumes
* The volumes for which snapshots are to be created.
* @param snapshotType
* The snapshot technology type.
* @param snapshotName
* The snapshot name.
* @param snapshotURIs
* [OUT] The URIs for the prepared snapshots.
* @param taskId
* The unique task identifier
*
* @return The list of snapshots
*/
@Override
public List<BlockSnapshot> prepareSnapshots(List<Volume> volumes, String snapshotType, String snapshotName, List<URI> snapshotURIs, String taskId) {
List<BlockSnapshot> snapshots = new ArrayList<BlockSnapshot>();
int count = 1;
for (Volume volume : volumes) {
// Attempt to create distinct labels here when creating >1 volumes (ScaleIO requirement)
String rgName = volume.getReplicationGroupInstance();
VolumeGroup application = volume.getApplication(_dbClient);
if (volume.isVPlexVolume(_dbClient)) {
Volume backendVol = VPlexUtil.getVPLEXBackendVolume(volumes.get(0), true, _dbClient);
if (backendVol != null && !backendVol.getInactive()) {
rgName = backendVol.getReplicationGroupInstance();
}
}
String label = snapshotName;
if (NullColumnValueGetter.isNotNullValue(rgName) && application != null) {
// There can be multiple RGs in a CG, in such cases generate unique name
if (volumes.size() > 1) {
label = String.format("%s-%s-%s", snapshotName, rgName, count++);
} else {
label = String.format("%s-%s", snapshotName, rgName);
}
} else if (volumes.size() > 1) {
label = String.format("%s-%s", snapshotName, count++);
}
BlockSnapshot snapshot = prepareSnapshotFromVolume(volume, snapshotName, label);
snapshot.setTechnologyType(snapshotType);
snapshot.setOpStatus(new OpStatusMap());
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.CREATE_VOLUME_SNAPSHOT);
snapshot.getOpStatus().createTaskStatus(taskId, op);
snapshotURIs.add(snapshot.getId());
snapshots.add(snapshot);
}
_dbClient.createObject(snapshots);
return snapshots;
}
Aggregations