use of com.emc.storageos.api.service.impl.placement.BucketRecommendation 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);
}
Aggregations