Search in sources :

Example 1 with TypedRelatedResourceRep

use of com.emc.storageos.model.TypedRelatedResourceRep in project coprhd-controller by CoprHD.

the class StoragePoolService method getStoragePoolResources.

/**
 * Retrieves the id, name, and type of the resources in the registered
 * storage pool. with the passed id.
 *
 * @param id the URN of a ViPR storage pool.
 *
 * @brief List storage pool resources
 * @return A list of the resources in the storage pool.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/resources")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public StoragePoolResources getStoragePoolResources(@PathParam("id") URI id) {
    // Make sure the storage pool is registered.
    ArgValidator.checkFieldUriType(id, StoragePool.class, "id");
    queryRegisteredResource(id);
    // Create the storage pools resources to be returned.
    StoragePoolResources resources = new StoragePoolResources();
    // Get the active volumes in the storage pool and add them to
    // the storage pool resources
    URIQueryResultList volumeURIList = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getStoragePoolVolumeConstraint(id), volumeURIList);
    Iterator<URI> volumeURIIter = volumeURIList.iterator();
    while (volumeURIIter.hasNext()) {
        URI volumeURI = volumeURIIter.next();
        Volume volume = _dbClient.queryObject(Volume.class, volumeURI);
        if ((volume != null) && (!volume.getInactive())) {
            TypedRelatedResourceRep resource = toTypedRelatedResource(volume);
            resources.getResources().add(resource);
        }
    }
    // Get the active file shares in the storage pool and add them to the
    // storage pools resources.
    URIQueryResultList fsURIList = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getStoragePoolFileshareConstraint(id), fsURIList);
    Iterator<URI> fsURIIter = fsURIList.iterator();
    while (fsURIIter.hasNext()) {
        URI fsURI = fsURIIter.next();
        FileShare fs = _dbClient.queryObject(FileShare.class, fsURI);
        if ((fs != null) && (!fs.getInactive())) {
            TypedRelatedResourceRep resource = toTypedRelatedResource(fs);
            resources.getResources().add(resource);
        }
    }
    return resources;
}
Also used : TypedRelatedResourceRep(com.emc.storageos.model.TypedRelatedResourceRep) StoragePoolResources(com.emc.storageos.model.pools.StoragePoolResources) Volume(com.emc.storageos.db.client.model.Volume) URI(java.net.URI) FileShare(com.emc.storageos.db.client.model.FileShare) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 2 with TypedRelatedResourceRep

use of com.emc.storageos.model.TypedRelatedResourceRep in project coprhd-controller by CoprHD.

the class ProjectService method getResourceList.

/**
 * List resources in project
 *
 * @param id the URN of a ViPR Project
 * @prereq none
 * @brief List project resources
 * @return List of resources
 */
@SuppressWarnings("unchecked")
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/resources")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public ResourceList getResourceList(@PathParam("id") URI id) {
    Project project = getProjectById(id, false);
    QueryResultList<TypedRelatedResourceRep> file = new QueryResultList<TypedRelatedResourceRep>() {

        @Override
        public TypedRelatedResourceRep createQueryHit(URI uri) {
            TypedRelatedResourceRep resource = new TypedRelatedResourceRep();
            resource.setId(uri);
            resource.setType(ResourceTypeEnum.FILE);
            return resource;
        }

        @Override
        public TypedRelatedResourceRep createQueryHit(URI uri, String name, UUID timestamp) {
            TypedRelatedResourceRep resource = new TypedRelatedResourceRep();
            resource.setId(uri);
            resource.setType(ResourceTypeEnum.FILE);
            resource.setName(name);
            return resource;
        }

        @Override
        public TypedRelatedResourceRep createQueryHit(URI uri, Object entry) {
            return createQueryHit(uri);
        }
    };
    QueryResultList<TypedRelatedResourceRep> volume = new QueryResultList<TypedRelatedResourceRep>() {

        @Override
        public TypedRelatedResourceRep createQueryHit(URI uri) {
            TypedRelatedResourceRep resource = new TypedRelatedResourceRep();
            resource.setId(uri);
            resource.setType(ResourceTypeEnum.VOLUME);
            return resource;
        }

        @Override
        public TypedRelatedResourceRep createQueryHit(URI uri, String name, UUID timestamp) {
            TypedRelatedResourceRep resource = new TypedRelatedResourceRep();
            resource.setId(uri);
            resource.setType(ResourceTypeEnum.VOLUME);
            resource.setName(name);
            return resource;
        }

        @Override
        public TypedRelatedResourceRep createQueryHit(URI uri, Object entry) {
            return createQueryHit(uri);
        }
    };
    QueryResultList<TypedRelatedResourceRep> bucket = new QueryResultList<TypedRelatedResourceRep>() {

        @Override
        public TypedRelatedResourceRep createQueryHit(URI uri) {
            TypedRelatedResourceRep resource = new TypedRelatedResourceRep();
            resource.setId(uri);
            resource.setType(ResourceTypeEnum.BUCKET);
            return resource;
        }

        @Override
        public TypedRelatedResourceRep createQueryHit(URI uri, String name, UUID timestamp) {
            TypedRelatedResourceRep resource = new TypedRelatedResourceRep();
            resource.setId(uri);
            resource.setType(ResourceTypeEnum.BUCKET);
            resource.setName(name);
            return resource;
        }

        @Override
        public TypedRelatedResourceRep createQueryHit(URI uri, Object entry) {
            return createQueryHit(uri);
        }
    };
    QueryResultList<TypedRelatedResourceRep> exportgroup = new QueryResultList<TypedRelatedResourceRep>() {

        @Override
        public TypedRelatedResourceRep createQueryHit(URI uri) {
            TypedRelatedResourceRep resource = new TypedRelatedResourceRep();
            resource.setId(uri);
            resource.setType(ResourceTypeEnum.EXPORT_GROUP);
            return resource;
        }

        @Override
        public TypedRelatedResourceRep createQueryHit(URI uri, String name, UUID timestamp) {
            TypedRelatedResourceRep resource = new TypedRelatedResourceRep();
            resource.setId(uri);
            resource.setType(ResourceTypeEnum.EXPORT_GROUP);
            resource.setName(name);
            return resource;
        }

        @Override
        public TypedRelatedResourceRep createQueryHit(URI uri, Object entry) {
            return createQueryHit(uri);
        }
    };
    QueryResultList<TypedRelatedResourceRep> blockSnapshot = new QueryResultList<TypedRelatedResourceRep>() {

        @Override
        public TypedRelatedResourceRep createQueryHit(URI uri) {
            TypedRelatedResourceRep resource = new TypedRelatedResourceRep();
            resource.setId(uri);
            resource.setType(ResourceTypeEnum.BLOCK_SNAPSHOT);
            return resource;
        }

        @Override
        public TypedRelatedResourceRep createQueryHit(URI uri, String name, UUID timestamp) {
            TypedRelatedResourceRep resource = new TypedRelatedResourceRep();
            resource.setId(uri);
            resource.setType(ResourceTypeEnum.BLOCK_SNAPSHOT);
            resource.setName(name);
            return resource;
        }

        @Override
        public TypedRelatedResourceRep createQueryHit(URI uri, Object entry) {
            return createQueryHit(uri);
        }
    };
    QueryResultList<TypedRelatedResourceRep> fileSnapshot = new QueryResultList<TypedRelatedResourceRep>() {

        @Override
        public TypedRelatedResourceRep createQueryHit(URI uri) {
            TypedRelatedResourceRep resource = new TypedRelatedResourceRep();
            resource.setId(uri);
            resource.setType(ResourceTypeEnum.FILE_SNAPSHOT);
            return resource;
        }

        @Override
        public TypedRelatedResourceRep createQueryHit(URI uri, String name, UUID timestamp) {
            TypedRelatedResourceRep resource = new TypedRelatedResourceRep();
            resource.setId(uri);
            resource.setType(ResourceTypeEnum.FILE_SNAPSHOT);
            resource.setName(name);
            return resource;
        }

        @Override
        public TypedRelatedResourceRep createQueryHit(URI uri, Object entry) {
            return createQueryHit(uri);
        }
    };
    QueryResultList<TypedRelatedResourceRep> protectionSet = new QueryResultList<TypedRelatedResourceRep>() {

        @Override
        public TypedRelatedResourceRep createQueryHit(URI uri) {
            TypedRelatedResourceRep resource = new TypedRelatedResourceRep();
            resource.setId(uri);
            resource.setType(ResourceTypeEnum.PROTECTION_SET);
            return resource;
        }

        @Override
        public TypedRelatedResourceRep createQueryHit(URI uri, String name, UUID timestamp) {
            TypedRelatedResourceRep resource = new TypedRelatedResourceRep();
            resource.setId(uri);
            resource.setType(ResourceTypeEnum.PROTECTION_SET);
            resource.setName(name);
            return resource;
        }

        @Override
        public TypedRelatedResourceRep createQueryHit(URI uri, Object entry) {
            return createQueryHit(uri);
        }
    };
    QueryResultList<TypedRelatedResourceRep> blockConsistencySet = new QueryResultList<TypedRelatedResourceRep>() {

        @Override
        public TypedRelatedResourceRep createQueryHit(URI uri) {
            TypedRelatedResourceRep resource = new TypedRelatedResourceRep();
            resource.setId(uri);
            resource.setType(ResourceTypeEnum.BLOCK_CONSISTENCY_GROUP);
            return resource;
        }

        @Override
        public TypedRelatedResourceRep createQueryHit(URI uri, String name, UUID timestamp) {
            TypedRelatedResourceRep resource = new TypedRelatedResourceRep();
            resource.setId(uri);
            resource.setType(ResourceTypeEnum.BLOCK_CONSISTENCY_GROUP);
            resource.setName(name);
            return resource;
        }

        @Override
        public TypedRelatedResourceRep createQueryHit(URI uri, Object entry) {
            return createQueryHit(uri);
        }
    };
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getProjectVolumeConstraint(project.getId()), volume);
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getProjectFileshareConstraint(project.getId()), file);
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getProjectBucketConstraint(project.getId()), bucket);
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getProjectExportGroupConstraint(project.getId()), exportgroup);
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getProjectBlockSnapshotConstraint(project.getId()), blockSnapshot);
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getProjectFileSnapshotConstraint(project.getId()), fileSnapshot);
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getProjectProtectionSetConstraint(project.getId()), protectionSet);
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getProjectBlockConsistencyGroupConstraint(project.getId()), blockConsistencySet);
    ResourceList list = new ResourceList();
    list.setResources(new ChainedList<TypedRelatedResourceRep>(file.iterator(), volume.iterator(), bucket.iterator(), exportgroup.iterator(), blockSnapshot.iterator(), fileSnapshot.iterator(), file.iterator(), volume.iterator(), exportgroup.iterator(), protectionSet.iterator(), blockConsistencySet.iterator()));
    return list;
}
Also used : MapProject(com.emc.storageos.api.mapper.functions.MapProject) Project(com.emc.storageos.db.client.model.Project) TypedRelatedResourceRep(com.emc.storageos.model.TypedRelatedResourceRep) ResourceList(com.emc.storageos.model.project.ResourceList) QueryResultList(com.emc.storageos.db.client.constraint.QueryResultList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) UUID(java.util.UUID) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)2 TypedRelatedResourceRep (com.emc.storageos.model.TypedRelatedResourceRep)2 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)2 URI (java.net.URI)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 MapProject (com.emc.storageos.api.mapper.functions.MapProject)1 QueryResultList (com.emc.storageos.db.client.constraint.QueryResultList)1 FileShare (com.emc.storageos.db.client.model.FileShare)1 NamedURI (com.emc.storageos.db.client.model.NamedURI)1 Project (com.emc.storageos.db.client.model.Project)1 Volume (com.emc.storageos.db.client.model.Volume)1 StoragePoolResources (com.emc.storageos.model.pools.StoragePoolResources)1 ResourceList (com.emc.storageos.model.project.ResourceList)1 UUID (java.util.UUID)1