Search in sources :

Example 61 with URIQueryResultList

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;
}
Also used : VirtualNASList(com.emc.storageos.model.vnas.VirtualNASList) VirtualNAS(com.emc.storageos.db.client.model.VirtualNAS) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 62 with URIQueryResultList

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;
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) ProjectList(com.emc.storageos.model.project.ProjectList) StringSet(com.emc.storageos.db.client.model.StringSet) VolumeGroupList(com.emc.storageos.model.application.VolumeGroupList) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 63 with URIQueryResultList

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;
}
Also used : OSTenantRestRep(com.emc.storageos.model.keystone.OSTenantRestRep) ArrayList(java.util.ArrayList) OSTenantListRestRep(com.emc.storageos.model.keystone.OSTenantListRestRep) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 64 with URIQueryResultList

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;
}
Also used : AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) Volume(com.emc.storageos.db.client.model.Volume) ProtectionSet(com.emc.storageos.db.client.model.ProtectionSet) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 65 with URIQueryResultList

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();
}
Also used : RPSiteArray(com.emc.storageos.db.client.model.RPSiteArray) ProtectionSet(com.emc.storageos.db.client.model.ProtectionSet) ArrayList(java.util.ArrayList) MapProtectionSystem(com.emc.storageos.api.mapper.functions.MapProtectionSystem) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)664 URI (java.net.URI)497 ArrayList (java.util.ArrayList)258 HashMap (java.util.HashMap)107 Volume (com.emc.storageos.db.client.model.Volume)97 NamedURI (com.emc.storageos.db.client.model.NamedURI)96 HashSet (java.util.HashSet)92 StoragePort (com.emc.storageos.db.client.model.StoragePort)91 StringSet (com.emc.storageos.db.client.model.StringSet)83 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)64 Produces (javax.ws.rs.Produces)55 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)54 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)54 Path (javax.ws.rs.Path)54 List (java.util.List)53 StoragePool (com.emc.storageos.db.client.model.StoragePool)49 Initiator (com.emc.storageos.db.client.model.Initiator)47 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)45 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)39 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)38