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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations