use of com.emc.storageos.model.application.VolumeGroupList 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.model.application.VolumeGroupList in project coprhd-controller by CoprHD.
the class BlockProvider method getApplicationSourceVolumes.
@Asset("sourceBlockVolumeForAddToApplication")
@AssetDependencies({ "consistencyGroupAll" })
public List<AssetOption> getApplicationSourceVolumes(AssetOptionsContext ctx, URI cg) {
final ViPRCoreClient client = api(ctx);
VolumeGroupList applications = client.application().getApplications();
List<URI> applicationIds = new ArrayList<URI>();
for (NamedRelatedResourceRep volumeGroup : applications.getVolumeGroups()) {
VolumeGroupRestRep vg = client.application().getApplication(volumeGroup.getId());
if (vg.getRoles().contains("COPY")) {
applicationIds.add(volumeGroup.getId());
}
}
ResourceFilter<VolumeRestRep> cgFilter = new BlockVolumeConsistencyGroupFilter(cg, false);
List<ProjectRestRep> projects = api(ctx).projects().getByTenant(ctx.getTenant());
List<VolumeRestRep> volumes = new ArrayList<VolumeRestRep>();
for (ProjectRestRep project : projects) {
volumes.addAll(listSourceVolumes(api(ctx), project.getId(), cgFilter));
}
List<VolumeRestRep> volumesNotInApplication = new ArrayList<VolumeRestRep>();
for (VolumeRestRep volume : volumes) {
if (volume.getVolumeGroups() != null && !volume.getVolumeGroups().isEmpty()) {
boolean volumeIsInApplication = false;
for (RelatedResourceRep rep : volume.getVolumeGroups()) {
if (applicationIds.contains(rep.getId())) {
volumeIsInApplication = true;
break;
}
}
if (!volumeIsInApplication) {
volumesNotInApplication.add(volume);
}
} else {
volumesNotInApplication.add(volume);
}
}
return createVolumeOptions(null, volumesNotInApplication);
}
use of com.emc.storageos.model.application.VolumeGroupList in project coprhd-controller by CoprHD.
the class VolumeGroupService method getVolumeGroups.
/**
* List volume groups.
*
* @brief List all volume groups
* @return A reference to VolumeGroupList.
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public VolumeGroupList getVolumeGroups() {
VolumeGroupList volumeGroupList = new VolumeGroupList();
List<URI> ids = _dbClient.queryByType(VolumeGroup.class, true);
Iterator<VolumeGroup> iter = _dbClient.queryIterativeObjects(VolumeGroup.class, ids);
StorageOSUser user = getUserFromContext();
if (_permissionsHelper.userHasGivenRole(user, null, Role.SYSTEM_MONITOR, Role.TENANT_ADMIN, Role.SECURITY_ADMIN)) {
while (iter.hasNext()) {
VolumeGroup vg = iter.next();
volumeGroupList.getVolumeGroups().add(toNamedRelatedResource(vg));
}
} else {
log.info("checking tenant");
// otherwise, filter by only authorized to use
URI tenant = URI.create(user.getTenantId());
while (iter.hasNext()) {
VolumeGroup vg = iter.next();
List<Volume> volumes = ControllerUtils.getVolumeGroupVolumes(_dbClient, vg);
if (volumes == null || volumes.isEmpty()) {
// if no volume in the application yet, the application is visible to all tenants
volumeGroupList.getVolumeGroups().add(toNamedRelatedResource(vg));
} else {
Volume firstVol = volumes.get(0);
URI volTenant = firstVol.getTenant().getURI();
if (volTenant.equals(tenant)) {
volumeGroupList.getVolumeGroups().add(toNamedRelatedResource(vg));
}
}
}
}
return volumeGroupList;
}
Aggregations