use of com.emc.storageos.db.client.model.QuotaDirectory in project coprhd-controller by CoprHD.
the class FileQuotaDirectoryService method queryResource.
@Override
protected QuotaDirectory queryResource(URI id) {
ArgValidator.checkUri(id);
QuotaDirectory qd = _permissionsHelper.getObjectById(id, QuotaDirectory.class);
ArgValidator.checkEntityNotNull(qd, id, isIdEmbeddedInURL(id));
return qd;
}
use of com.emc.storageos.db.client.model.QuotaDirectory in project coprhd-controller by CoprHD.
the class FileQuotaDirectoryService method updateQuotaDirectory.
/**
* Update Quota Directory for a file share
* <p>
* NOTE: This is an asynchronous operation.
*
* @param id
* the URN of a ViPR Quota directory
* @param param
* File system Quota directory update parameters
* @brief Update file system quota directory
* @return Task resource representation
* @throws com.emc.storageos.svcs.errorhandling.resources.InternalException
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep updateQuotaDirectory(@PathParam("id") URI id, QuotaDirectoryUpdateParam param) throws InternalException {
_log.info("FileService::Update Quota directory Request recieved {}", id);
QuotaDirectory quotaDirNew = new QuotaDirectory();
if (param.getSecurityStyle() != null) {
ArgValidator.checkFieldValueFromEnum(param.getSecurityStyle(), "security_style", EnumSet.allOf(QuotaDirectory.SecurityStyles.class));
}
// Get the FileSystem object
QuotaDirectory quotaDir = queryResource(id);
FileShare fs = queryFileShareResource(quotaDir.getParent().getURI());
ArgValidator.checkFieldNotNull(fs, "filesystem");
// Set all other optional parameters too.
quotaDirNew.setName(quotaDir.getName());
quotaDirNew.setId(id);
quotaDirNew.setNativeGuid(quotaDir.getNativeGuid());
if (param.getOpLock() != null) {
quotaDirNew.setOpLock(param.getOpLock());
}
if (param.getSecurityStyle() != null) {
quotaDirNew.setSecurityStyle(param.getSecurityStyle());
}
if (param.getSize() != null) {
// converts the input string in format "<value>GB" to Bytes
Long quotaSize = SizeUtil.translateSize(param.getSize());
if (quotaSize > 0) {
ArgValidator.checkFieldMaximum(quotaSize, fs.getCapacity(), SizeUtil.SIZE_B, "size", true);
quotaDirNew.setSize(quotaSize);
}
}
ArgValidator.checkFieldMaximum(param.getSoftLimit(), 100, "softLimit");
ArgValidator.checkFieldMaximum(param.getNotificationLimit(), 100, "notificationLimit");
if (param.getSoftLimit() != 0L) {
ArgValidator.checkFieldMinimum(param.getSoftGrace(), 1L, "softGrace");
}
int fsSoftLimit = -1;
if (null != fs.getSoftLimit()) {
fsSoftLimit = fs.getSoftLimit().intValue();
}
int fsNotifiLimit = -1;
if (null != fs.getNotificationLimit()) {
fsNotifiLimit = fs.getNotificationLimit().intValue();
}
int fsGraceLimit = -1;
if (null != fs.getSoftGracePeriod()) {
fsGraceLimit = fs.getSoftGracePeriod().intValue();
}
String task = UUID.randomUUID().toString();
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.UPDATE_FILE_SYSTEM_QUOTA_DIR);
// Update the quota directory object to store in ViPR database
quotaDir.setOpStatus(new OpStatusMap());
quotaDir.getOpStatus().createTaskStatus(task, op);
fs.setOpStatus(new OpStatusMap());
fs.getOpStatus().createTaskStatus(task, op);
_dbClient.updateObject(fs);
_dbClient.updateObject(quotaDir);
quotaDirNew.setSoftLimit(param.getSoftLimit() > 0 ? param.getSoftLimit() : quotaDir.getSoftLimit() > 0 ? quotaDir.getSoftLimit() : fsSoftLimit > 0 ? fsSoftLimit : 0);
quotaDirNew.setSoftGrace(param.getSoftGrace() > 0 ? param.getSoftGrace() : quotaDir.getSoftGrace() > 0 ? quotaDir.getSoftGrace() : fsGraceLimit > 0 ? fsGraceLimit : 0);
quotaDirNew.setNotificationLimit(param.getNotificationLimit() > 0 ? param.getNotificationLimit() : quotaDir.getNotificationLimit() > 0 ? quotaDir.getNotificationLimit() : fsNotifiLimit > 0 ? fsNotifiLimit : 0);
// Create an object of type "FileShareQtree" to be passed into the
// south-bound layers.
FileShareQuotaDirectory qt = new FileShareQuotaDirectory(quotaDirNew);
// Now get ready to make calls into the controller
StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
FileController controller = getController(FileController.class, device.getSystemType());
try {
controller.updateQuotaDirectory(device.getId(), qt, fs.getId(), task);
} catch (InternalException e) {
_log.error("Error during update of Quota Directory {}", e);
// errors
throw e;
}
auditOp(OperationTypeEnum.UPDATE_FILE_SYSTEM_QUOTA_DIR, true, AuditLogManager.AUDITOP_BEGIN, quotaDirNew.getLabel(), quotaDirNew.getId().toString(), fs.getId().toString());
fs = _dbClient.queryObject(FileShare.class, fs.getId());
_log.debug("FileService::Quota directory Before sending response, FS ID : {}, Taks : {} ; Status {}", fs.getOpStatus().get(task), fs.getOpStatus().get(task).getStatus());
return toTask(quotaDir, task, op);
}
use of com.emc.storageos.db.client.model.QuotaDirectory in project coprhd-controller by CoprHD.
the class FileQuotaDirectoryService method getQuotaDirectory.
/**
* Get info for file system quota directory
*
* @param id
* the URN of a ViPR Quota directory
* @brief Show file system quota directory
* @return File system quota directory details
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public QuotaDirectoryRestRep getQuotaDirectory(@PathParam("id") URI id) {
ArgValidator.checkFieldUriType(id, QuotaDirectory.class, "id");
QuotaDirectory quotaDir = queryResource(id);
return map(quotaDir);
}
use of com.emc.storageos.db.client.model.QuotaDirectory in project coprhd-controller by CoprHD.
the class FileDeviceController method queryFileQuotaDirs.
private List<QuotaDirectory> queryFileQuotaDirs(FileDeviceInputOutput args) {
if (args.getFileOperation()) {
FileShare fs = args.getFs();
_log.info("Querying all quota directories Using FsId {}", fs.getId());
try {
ContainmentConstraint containmentConstraint = ContainmentConstraint.Factory.getQuotaDirectoryConstraint(fs.getId());
List<QuotaDirectory> fsQuotaDirs = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, QuotaDirectory.class, containmentConstraint);
return fsQuotaDirs;
} catch (Exception e) {
_log.error("Error while querying {}", e);
}
}
return null;
}
use of com.emc.storageos.db.client.model.QuotaDirectory in project coprhd-controller by CoprHD.
the class FileDeviceController method doFSDeleteQuotaDirsFromDB.
private void doFSDeleteQuotaDirsFromDB(FileDeviceInputOutput args) throws Exception {
List<QuotaDirectory> quotaDirs = queryFileQuotaDirs(args);
if (quotaDirs != null && !quotaDirs.isEmpty()) {
_log.info("Doing CRUD Operations on all DB QuotaDirectory for requested fs");
for (QuotaDirectory dir : quotaDirs) {
_log.info("Deleting quota dir from DB - Dir :{}", dir);
dir.setInactive(true);
_dbClient.updateObject(dir);
}
}
}
Aggregations