use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.
the class StorageSystemService method getVnasServers.
/**
* Gets all virtual NAS for the registered storage system with the passed
* id.
*
* @param id the URN of a ViPR storage system.
*
* @brief List storage system virtual nas servers
* @return A reference to a StoragePooList specifying the id and self link
* for each storage pool.
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/vnasservers")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public VirtualNASList getVnasServers(@PathParam("id") URI id) {
// Make sure storage system is registered.
ArgValidator.checkFieldUriType(id, StorageSystem.class, "id");
StorageSystem system = queryResource(id);
ArgValidator.checkEntity(system, id, isIdEmbeddedInURL(id));
VirtualNASList vNasList = new VirtualNASList();
URIQueryResultList vNasURIs = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getStorageDeviceVirtualNasConstraint(id), vNasURIs);
Iterator<URI> vNasIter = vNasURIs.iterator();
while (vNasIter.hasNext()) {
URI vNasURI = vNasIter.next();
VirtualNAS vNas = _dbClient.queryObject(VirtualNAS.class, vNasURI);
if (vNas != null && !vNas.getInactive()) {
vNasList.getVNASServers().add(toNamedRelatedResource(vNas, vNas.getNativeGuid()));
}
}
return vNasList;
}
use of com.emc.storageos.db.client.constraint.URIQueryResultList 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.constraint.URIQueryResultList in project coprhd-controller by CoprHD.
the class KeystoneService method updateOpenstackTenants.
/**
* Updates representation of OpenStack Tenants in CoprHD.
* Creates Tenants and Projects for new Tenants and deletes them for excluded Tenants.
*
* @param param OpenStackTenantListParam OpenStack Tenants representation with all necessary elements for update.
* @brief Updates representation of OpenStack Tenants in CoprHD.
* @return Updated Tenants.
* @see
*/
@PUT
@Path("/ostenants")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SECURITY_ADMIN })
public OSTenantListRestRep updateOpenstackTenants(OSTenantListRestRep param) {
_log.debug("Keystone Service - updateOpenstackTenants");
if (param.getOSTenantsRestRep() == null || param.getOSTenantsRestRep().isEmpty()) {
throw APIException.internalServerErrors.targetIsNullOrEmpty("Tenant list param");
}
OSTenantListRestRep resp = new OSTenantListRestRep();
List<OSTenant> tenantsToUpdate = new ArrayList<>();
List<OSTenant> tenantsToDelete = new ArrayList<>();
OSTenant osTenant;
for (OSTenantRestRep tenant : param.getOSTenantsRestRep()) {
osTenant = _dbClient.queryObject(OSTenant.class, tenant.getId());
if (!osTenant.getExcluded().equals(tenant.getExcluded())) {
// Tenant changed from included to excluded. Mark for deletion related Tenant and Project.
if (!osTenant.getExcluded()) {
tenantsToDelete.add(osTenant);
} else {
tenantsToUpdate.add(osTenant);
}
osTenant.setExcluded(tenant.getExcluded());
resp.getOSTenantsRestRep().add(mapToCoprhdOsTenant(osTenant));
}
}
if (!tenantsToUpdate.isEmpty()) {
// Create Tenant and Project for included Tenants.
for (OSTenant tenant : tenantsToUpdate) {
if (_keystoneUtils.getCoprhdTenantWithOpenstackId(tenant.getOsId()) == null) {
_authService.createTenantAndProjectForOpenstackTenant(tenant);
}
}
}
tenantsToUpdate.addAll(tenantsToDelete);
if (!tenantsToUpdate.isEmpty()) {
_dbClient.updateObject(tenantsToUpdate);
}
if (!tenantsToDelete.isEmpty()) {
for (OSTenant tenant : tenantsToDelete) {
TenantOrg tenantOrg = _keystoneUtils.getCoprhdTenantWithOpenstackId(tenant.getOsId());
if (tenantOrg != null && !TenantOrg.isRootTenant(tenantOrg)) {
URIQueryResultList uris = new URIQueryResultList();
_dbClient.queryByConstraint(PrefixConstraint.Factory.getTagsPrefixConstraint(Project.class, tenant.getOsId(), tenantOrg.getId()), uris);
for (URI projectUri : uris) {
Project project = _dbClient.queryObject(Project.class, projectUri);
ArgValidator.checkReference(Project.class, project.getId(), checkForDelete(project));
_dbClient.markForDeletion(project);
}
ArgValidator.checkReference(TenantOrg.class, tenantOrg.getId(), checkForDelete(tenantOrg));
_dbClient.markForDeletion(tenantOrg);
}
}
}
return resp;
}
use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.
the class ProtectionSystemService method checkForVolumes.
/**
* checks for the existence of any volumes associated with a protection sysem
* also compiles a list of empty protection sets associated with the protection system that can be deleted
*
* @param system protection system
* @param protectionSetsToDelete (return) empty list to be populated by this method
* @return true if volumes exist; else false
*/
private boolean checkForVolumes(URI id, List<ProtectionSet> protectionSetsToDelete) {
boolean volumesExist = false;
URIQueryResultList list = new URIQueryResultList();
Constraint constraint = ContainmentConstraint.Factory.getProtectionSystemProtectionSetConstraint(id);
_dbClient.queryByConstraint(constraint, list);
Iterator<URI> it = list.iterator();
while (it.hasNext()) {
URI protectionSetId = it.next();
ProtectionSet protectionSet = _dbClient.queryObject(ProtectionSet.class, protectionSetId);
if (protectionSet != null && !protectionSet.getInactive()) {
if (protectionSet.getVolumes() != null && !protectionSet.getVolumes().isEmpty()) {
for (String volId : protectionSet.getVolumes()) {
Volume vol = _dbClient.queryObject(Volume.class, URI.create(volId));
if (vol != null && !vol.getInactive()) {
volumesExist = true;
break;
}
}
}
if (!volumesExist) {
// there are no volumes in this protection set, we can delete it
protectionSetsToDelete.add(protectionSet);
}
}
}
return volumesExist;
}
use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.
the class ProtectionSystemService method deleteProtectionSystem.
/**
* Deactivate protection system, this will move it to a "marked-for-delete" state.
* It will be deleted in the next iteration of garbage collector
*
* @param id the URN of a ViPR protection system
* @brief Delete protection system
* @return No data returned in response body
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/deactivate")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public Response deleteProtectionSystem(@PathParam("id") URI id) {
ArgValidator.checkFieldUriType(id, ProtectionSystem.class, "id");
ProtectionSystem system = _dbClient.queryObject(ProtectionSystem.class, id);
ArgValidator.checkEntityNotNull(system, id, isIdEmbeddedInURL(id));
// Check to make sure there are no volumes associated with this protection system
List<ProtectionSet> protectionSetsToDelete = new ArrayList<ProtectionSet>();
if (checkForVolumes(id, protectionSetsToDelete)) {
// don't allow the delete protection system if there are volumes
throw APIException.badRequests.unableToDeactivateDueToDependencies(id);
}
// delete any empty protection sets
_dbClient.markForDeletion(protectionSetsToDelete);
// Side-effect: RPSiteArray entries need to be cleaned up so placement and connectivity feeds are correct
// Mark all of the RPSiteArray entries associated with this protection system for deletion
URIQueryResultList sitelist = new URIQueryResultList();
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getRPSiteArrayProtectionSystemConstraint(id.toString()), sitelist);
Iterator<URI> it = sitelist.iterator();
while (it.hasNext()) {
URI rpSiteArrayId = it.next();
RPSiteArray siteArray = _dbClient.queryObject(RPSiteArray.class, rpSiteArrayId);
if (siteArray != null) {
_dbClient.markForDeletion(siteArray);
}
}
_dbClient.markForDeletion(system);
auditOp(OperationTypeEnum.DELETE_PROTECTION_SYSTEM, true, null, system.getId().toString());
return Response.ok().build();
}
Aggregations