Search in sources :

Example 6 with Bucket

use of com.emc.storageos.db.client.model.Bucket in project coprhd-controller by CoprHD.

the class BucketService method getBucket.

/**
 * Get info for Bucket
 *
 * @param id the URN of a ViPR Bucket
 * @brief Show details for a specified bucket
 * @return Bucket details
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public BucketRestRep getBucket(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, Bucket.class, "id");
    Bucket fs = queryResource(id);
    return map(fs);
}
Also used : Bucket(com.emc.storageos.db.client.model.Bucket) MapBucket(com.emc.storageos.api.mapper.functions.MapBucket) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 7 with Bucket

use of com.emc.storageos.db.client.model.Bucket in project coprhd-controller by CoprHD.

the class BucketService method updateBucketACL.

/**
 * Add/Update the ACL settings for bucket
 *
 * @param id
 * @param param
 * @brief Change a bucket ACL
 * @return TaskResponse
 * @throws InternalException
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/acl")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep updateBucketACL(@PathParam("id") URI id, ObjectBucketACLUpdateParams param) throws InternalException {
    _log.info("Update bucket acl request received. BucketId: {}", id.toString());
    _log.info("Request body: {}", param.toString());
    Bucket bucket = null;
    ArgValidator.checkFieldUriType(id, Bucket.class, "id");
    bucket = _dbClient.queryObject(Bucket.class, id);
    ArgValidator.checkEntity(bucket, id, isIdEmbeddedInURL(id));
    if (bucket.getVersion() == null) {
        syncBucketACL(bucket);
    }
    // Verify the Bucket ACL Settings
    BucketACLUtility bucketACLUtil = new BucketACLUtility(_dbClient, bucket.getName(), bucket.getId());
    bucketACLUtil.verifyBucketACL(param);
    _log.info("Request payload verified. No errors found.");
    StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, bucket.getStorageDevice());
    ObjectController controller = getController(ObjectController.class, storageSystem.getSystemType());
    String task = UUID.randomUUID().toString();
    _log.info(String.format("Bucket ACL Update --- Bucket id: %1$s, Task: %2$s", id, task));
    Operation op = _dbClient.createTaskOpStatus(Bucket.class, bucket.getId(), task, ResourceOperationTypeEnum.UPDATE_BUCKET_ACL);
    op.setDescription("Bucket ACL update");
    controller.updateBucketACL(bucket.getStorageDevice(), id, param, task);
    auditOp(OperationTypeEnum.UPDATE_BUCKET_ACL, true, AuditLogManager.AUDITOP_BEGIN, bucket.getId().toString(), bucket.getStorageDevice().toString());
    return toTask(bucket, task, op);
}
Also used : BucketACLUtility(com.emc.storageos.api.service.impl.resource.utils.BucketACLUtility) Bucket(com.emc.storageos.db.client.model.Bucket) MapBucket(com.emc.storageos.api.mapper.functions.MapBucket) ObjectController(com.emc.storageos.volumecontroller.ObjectController) Operation(com.emc.storageos.db.client.model.Operation) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 8 with Bucket

use of com.emc.storageos.db.client.model.Bucket in project coprhd-controller by CoprHD.

the class BucketService method deactivateBucket.

/**
 * Deactivate Bucket, this will move the Bucket to a "marked-for-delete" state
 *
 * <p>
 * NOTE: This is an asynchronous operation.
 *
 * @param id the URN of a ViPR Bucket
 * @param param Bucket delete param for optional force delete
 * @brief Delete bucket
 * @return Task resource representation
 * @throws InternalException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/deactivate")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep deactivateBucket(@PathParam("id") URI id, BucketDeleteParam param) throws InternalException {
    String task = UUID.randomUUID().toString();
    _log.info(String.format("BucketDelete --- Bucket id: %1$s, Task: %2$s, ForceDelete: %3$s", id, task, param.getForceDelete()));
    ArgValidator.checkFieldUriType(id, Bucket.class, "id");
    Bucket bucket = queryResource(id);
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, bucket.getStorageDevice());
    Operation op = _dbClient.createTaskOpStatus(Bucket.class, bucket.getId(), task, ResourceOperationTypeEnum.DELETE_BUCKET);
    op.setDescription("Bucket deactivate");
    ObjectController controller = getController(ObjectController.class, device.getSystemType());
    controller.deleteBucket(bucket.getStorageDevice(), id, param.getDeleteType(), task);
    auditOp(OperationTypeEnum.DELETE_BUCKET, true, AuditLogManager.AUDITOP_BEGIN, bucket.getId().toString(), device.getId().toString());
    return toTask(bucket, task, op);
}
Also used : Bucket(com.emc.storageos.db.client.model.Bucket) MapBucket(com.emc.storageos.api.mapper.functions.MapBucket) ObjectController(com.emc.storageos.volumecontroller.ObjectController) Operation(com.emc.storageos.db.client.model.Operation) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 9 with Bucket

use of com.emc.storageos.db.client.model.Bucket in project coprhd-controller by CoprHD.

the class BucketService method initiateBucketCreation.

private TaskResourceRep initiateBucketCreation(BucketParam param, Project project, TenantOrg tenant, DataObject.Flag[] flags) throws InternalException {
    ArgValidator.checkFieldUriType(param.getVpool(), VirtualPool.class, "vpool");
    ArgValidator.checkFieldUriType(param.getVarray(), VirtualArray.class, "varray");
    Long softQuota = SizeUtil.translateSize(param.getSoftQuota());
    Long hardQuota = SizeUtil.translateSize(param.getHardQuota());
    Integer retention = Integer.valueOf(param.getRetention());
    // Hard Quota should be more than SoftQuota
    verifyQuotaValues(softQuota, hardQuota, param.getLabel());
    // check varray
    VirtualArray neighborhood = _dbClient.queryObject(VirtualArray.class, param.getVarray());
    ArgValidator.checkEntity(neighborhood, param.getVarray(), false);
    _permissionsHelper.checkTenantHasAccessToVirtualArray(tenant.getId(), neighborhood);
    // check vpool reference
    VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, param.getVpool());
    _permissionsHelper.checkTenantHasAccessToVirtualPool(tenant.getId(), vpool);
    ArgValidator.checkEntity(vpool, param.getVpool(), false);
    if (!VirtualPool.Type.object.name().equals(vpool.getType())) {
        throw APIException.badRequests.virtualPoolNotForObjectStorage(VirtualPool.Type.object.name());
    }
    // verify retention. Its validated only if Retention is configured.
    if (retention != 0 && vpool.getMaxRetention() != 0 && retention > vpool.getMaxRetention()) {
        throw APIException.badRequests.insufficientRetentionForVirtualPool(vpool.getLabel(), "bucket");
    }
    VirtualPoolCapabilityValuesWrapper capabilities = new VirtualPoolCapabilityValuesWrapper();
    capabilities.put(VirtualPoolCapabilityValuesWrapper.RESOURCE_COUNT, Integer.valueOf(1));
    capabilities.put(VirtualPoolCapabilityValuesWrapper.THIN_PROVISIONING, Boolean.FALSE);
    capabilities.put(VirtualPoolCapabilityValuesWrapper.QUOTA, hardQuota.toString());
    Map<String, Object> attributeMap = new HashMap<String, Object>();
    List<BucketRecommendation> placement = _bucketScheduler.placeBucket(neighborhood, vpool, capabilities, attributeMap);
    if (placement.isEmpty()) {
        StringBuffer errorMessage = new StringBuffer();
        if (attributeMap.get(AttributeMatcher.ERROR_MESSAGE) != null) {
            errorMessage = (StringBuffer) attributeMap.get(AttributeMatcher.ERROR_MESSAGE);
        }
        throw APIException.badRequests.noStoragePools(neighborhood.getLabel(), vpool.getLabel(), errorMessage.toString());
    }
    // Randomly select a recommended pool
    Collections.shuffle(placement);
    BucketRecommendation recommendation = placement.get(0);
    String task = UUID.randomUUID().toString();
    Bucket bucket = prepareBucket(param, project, tenant, neighborhood, vpool, flags, recommendation);
    _log.info(String.format("createBucket --- Bucket: %1$s, StoragePool: %2$s, StorageSystem: %3$s", bucket.getId(), recommendation.getSourceStoragePool(), recommendation.getSourceStorageSystem()));
    Operation op = _dbClient.createTaskOpStatus(Bucket.class, bucket.getId(), task, ResourceOperationTypeEnum.CREATE_BUCKET);
    op.setDescription("Bucket Create");
    // Controller invocation
    StorageSystem system = _dbClient.queryObject(StorageSystem.class, recommendation.getSourceStorageSystem());
    ObjectController controller = getController(ObjectController.class, system.getSystemType());
    controller.createBucket(recommendation.getSourceStorageSystem(), recommendation.getSourceStoragePool(), bucket.getId(), bucket.getName(), bucket.getNamespace(), bucket.getRetention(), bucket.getHardQuota(), bucket.getSoftQuota(), bucket.getOwner(), task);
    auditOp(OperationTypeEnum.CREATE_BUCKET, true, AuditLogManager.AUDITOP_BEGIN, param.getLabel(), param.getHardQuota(), neighborhood.getId().toString(), project == null ? null : project.getId().toString());
    return toTask(bucket, task, op);
}
Also used : VirtualPoolCapabilityValuesWrapper(com.emc.storageos.volumecontroller.impl.utils.VirtualPoolCapabilityValuesWrapper) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) HashMap(java.util.HashMap) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) Operation(com.emc.storageos.db.client.model.Operation) BucketRecommendation(com.emc.storageos.api.service.impl.placement.BucketRecommendation) Bucket(com.emc.storageos.db.client.model.Bucket) MapBucket(com.emc.storageos.api.mapper.functions.MapBucket) ObjectController(com.emc.storageos.volumecontroller.ObjectController) DataObject(com.emc.storageos.db.client.model.DataObject) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 10 with Bucket

use of com.emc.storageos.db.client.model.Bucket in project coprhd-controller by CoprHD.

the class VirtualPoolService method getVArraysWithVPoolResources.

/**
 * Calculate the virtual arrays which have the vpool resources.
 * 1) Get list of vpool resources
 * 2) Get the resources for each of the passed in virtual array
 * 3) If there is resource in virtual array which is also in the vpool resource list, add to the virtual array list
 *
 * @param vpool
 * @param varrays
 * @param dbClient
 * @return List of virtual arrays with vpool resources.
 */
public static Set<String> getVArraysWithVPoolResources(VirtualPool vpool, Set<String> varrays, DbClient dbClient) {
    Set<String> resourcePools = new StringSet();
    _log.debug("Getting the virtual arrays with resources of virtual pool {}.", vpool.getLabel());
    if (null != varrays && !varrays.isEmpty()) {
        Iterator<String> varrayItr = varrays.iterator();
        while (varrayItr.hasNext()) {
            String varray = varrayItr.next();
            URI varrayURI = URI.create(varray);
            URIQueryResultList varrayResourcesResultList = new URIQueryResultList();
            URIQueryResultList vpoolResourcesResultList = new URIQueryResultList();
            if (VirtualPool.Type.block.name().equals(vpool.getType())) {
                dbClient.queryByConstraint(ContainmentConstraint.Factory.getVirtualArrayVolumeConstraint(varrayURI), varrayResourcesResultList);
                dbClient.queryByConstraint(ContainmentConstraint.Factory.getVirtualPoolVolumeConstraint(vpool.getId()), vpoolResourcesResultList);
            } else if (VirtualPool.Type.file.name().equals(vpool.getType())) {
                dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVirtualArrayFileSharesConstraint(varrayURI.toString()), varrayResourcesResultList);
                dbClient.queryByConstraint(ContainmentConstraint.Factory.getVirtualPoolFileshareConstraint(vpool.getId()), vpoolResourcesResultList);
            } else if (VirtualPool.Type.object.name().equals(vpool.getType())) {
                dbClient.queryByConstraint(ContainmentConstraint.Factory.getVirtualArrayBucketsConstraint(varrayURI), varrayResourcesResultList);
                dbClient.queryByConstraint(ContainmentConstraint.Factory.getVirtualPoolBucketConstraint(vpool.getId()), vpoolResourcesResultList);
            }
            // Create a set of vpoolResourcesResultList
            HashSet<URI> vpoolResourceSet = new HashSet<URI>();
            for (URI vpoolResource : vpoolResourcesResultList) {
                vpoolResourceSet.add(vpoolResource);
            }
            // Now look up if there are varray resources in the vpool resources set.
            for (URI varrayResource : varrayResourcesResultList) {
                if (vpoolResourceSet.contains(varrayResource)) {
                    boolean inactive = false;
                    if (VirtualPool.Type.block.name().equals(vpool.getType())) {
                        Volume resource = dbClient.queryObject(Volume.class, varrayResource);
                        inactive = resource.getInactive();
                    } else if (VirtualPool.Type.file.name().equals(vpool.getType())) {
                        FileShare resource = dbClient.queryObject(FileShare.class, varrayResource);
                        inactive = resource.getInactive();
                    } else if (VirtualPool.Type.object.name().equals(vpool.getType())) {
                        Bucket resource = dbClient.queryObject(Bucket.class, varrayResource);
                        inactive = resource.getInactive();
                    }
                    if (!inactive) {
                        _log.info("Found vpool resource {} in the varray {}", varrayResource, varray);
                        resourcePools.add(varray);
                        break;
                    }
                }
            }
        }
    }
    return resourcePools;
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) Bucket(com.emc.storageos.db.client.model.Bucket) StringSet(com.emc.storageos.db.client.model.StringSet) URI(java.net.URI) FileShare(com.emc.storageos.db.client.model.FileShare) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) HashSet(java.util.HashSet)

Aggregations

Bucket (com.emc.storageos.db.client.model.Bucket)16 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)11 MapBucket (com.emc.storageos.api.mapper.functions.MapBucket)9 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 Operation (com.emc.storageos.db.client.model.Operation)5 ObjectController (com.emc.storageos.volumecontroller.ObjectController)5 ObjectDeviceInputOutput (com.emc.storageos.volumecontroller.ObjectDeviceInputOutput)4 Consumes (javax.ws.rs.Consumes)3 BucketACLUtility (com.emc.storageos.api.service.impl.resource.utils.BucketACLUtility)2 StoragePool (com.emc.storageos.db.client.model.StoragePool)2 StringSet (com.emc.storageos.db.client.model.StringSet)2 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)2 GET (javax.ws.rs.GET)2 PUT (javax.ws.rs.PUT)2 BucketRecommendation (com.emc.storageos.api.service.impl.placement.BucketRecommendation)1 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 DataObject (com.emc.storageos.db.client.model.DataObject)1 FileShare (com.emc.storageos.db.client.model.FileShare)1