use of com.emc.storageos.db.client.model.QuotaDirectory in project coprhd-controller by CoprHD.
the class FileService method reduce.
/**
* Reduce file system quota -- supported only on Isilon
*
* @param id - the URN of a ViPR File system
* @param param - File system reduction parameters
* @return Task resource representation
* @throws InternalException
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/reduce")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep reduce(@PathParam("id") URI id, FileSystemReduceParam param) throws InternalException {
_log.info(String.format("FileShareReduce --- FileShare id: %1$s, New Quota: %2$s", id, param.getNewSize()));
// check file system
ArgValidator.checkFieldUriType(id, FileShare.class, "id");
FileShare fs = queryResource(id);
ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
if (!device.deviceIsType(DiscoveredDataObject.Type.isilon)) {
String msg = String.format("reducing filesystem is not supported for storage system %s", device.getSystemType());
throw APIException.badRequests.reduceFileSystemNotSupported(msg);
}
Long newFSsize = SizeUtil.translateSize(param.getNewSize());
long quotaFsSize = newFSsize - fs.getCapacity();
final long MIN_EXPAND_SIZE = SizeUtil.translateSize("1MB") + 1;
if (newFSsize <= 0) {
throw APIException.badRequests.parameterMustBeGreaterThan("new_size", 0);
} else {
if (quotaFsSize < MIN_EXPAND_SIZE) {
List<QuotaDirectory> quotaDirs = queryDBQuotaDirectories(fs);
if (null != quotaDirs && !quotaDirs.isEmpty()) {
long qdsize = 0;
// that new size should not be less than any of the sub quota.
for (QuotaDirectory quotaDir : quotaDirs) {
qdsize = newFSsize - quotaDir.getSize();
Double quotasize = SizeUtil.translateSize(quotaDir.getSize(), SizeUtil.SIZE_GB);
Double newFScapacity = SizeUtil.translateSize(newFSsize, SizeUtil.SIZE_GB);
if (qdsize < MIN_EXPAND_SIZE) {
String msg = String.format("as requested reduced size [%.1fGB] is smaller than its quota size [%.1fGB] for filesystem %s", newFScapacity, quotasize, fs.getName());
throw APIException.badRequests.reduceFileSystemNotSupported(msg);
}
}
}
} else {
throw APIException.badRequests.parameterMustBeLessThan("new_size", fs.getCapacity());
}
}
String task = UUID.randomUUID().toString();
Operation op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.REDUCE_FILE_SYSTEM);
op.setDescription("Filesystem reduce quota");
FileServiceApi fileServiceApi = getFileShareServiceImpl(fs, _dbClient);
try {
fileServiceApi.reduceFileShareQuota(fs, newFSsize, task);
} catch (InternalException e) {
if (_log.isErrorEnabled()) {
_log.error("Reduce File Quota error", e);
}
fs = _dbClient.queryObject(FileShare.class, fs.getId());
op = fs.getOpStatus().get(task);
op.error(e);
fs.getOpStatus().updateTaskStatus(task, op);
_dbClient.updateObject(fs);
throw e;
}
return toTask(fs, task, op);
}
use of com.emc.storageos.db.client.model.QuotaDirectory in project coprhd-controller by CoprHD.
the class FileService method getQuotaDirectoryList.
/**
* Get list of quota directories for the specified file system.
*
* @param id
* the URN of a ViPR File system
* @brief List file system quota directories
* @return List of file system quota directories.
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/quota-directories")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public QuotaDirectoryList getQuotaDirectoryList(@PathParam("id") URI id) {
_log.info(String.format("Get list of quota directories for file system: %1$s", id));
ArgValidator.checkFieldUriType(id, FileShare.class, "id");
FileShare fileShare = queryResource(id);
QuotaDirectoryList quotaDirList = new QuotaDirectoryList();
if (fileShare.getInactive()) {
return quotaDirList;
}
// Get SMB share map from file system
List<QuotaDirectory> quotaDirs = queryDBQuotaDirectories(fileShare);
// Process each share from the map and add its data to shares in response list.
for (QuotaDirectory quotaDir : quotaDirs) {
quotaDirList.getQuotaDirs().add(toNamedRelatedResource(quotaDir));
}
return quotaDirList;
}
use of com.emc.storageos.db.client.model.QuotaDirectory in project coprhd-controller by CoprHD.
the class FileQuotaDirectoryService method queryDBQuotaDirectories.
private List<QuotaDirectory> queryDBQuotaDirectories(FileShare fs) {
_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 FileQuotaDirectoryService method getTenantOwner.
@Override
protected URI getTenantOwner(URI id) {
QuotaDirectory qd = queryResource(id);
FileShare fs = queryFileShareResource(qd.getParent().getURI());
return fs.getTenant().getURI();
}
use of com.emc.storageos.db.client.model.QuotaDirectory in project coprhd-controller by CoprHD.
the class FileQuotaDirectoryService method deactivateQuotaDirectory.
/**
* Deactivate Quota directory of file system, this will move the
* Quota directory to a "marked-for-delete" state
* <p>
* NOTE: This is an asynchronous operation.
*
* @param id
* the URN of the QuotaDirectory
* @param param
* QuotaDirectory delete param for optional force delete
* @brief Delete 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}/deactivate")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep deactivateQuotaDirectory(@PathParam("id") URI id, QuotaDirectoryDeleteParam param) throws InternalException {
_log.info("FileService::deactivateQtree Request recieved {}", id);
String task = UUID.randomUUID().toString();
ArgValidator.checkFieldUriType(id, QuotaDirectory.class, "id");
QuotaDirectory quotaDirectory = queryResource(id);
FileShare fs = queryFileShareResource(quotaDirectory.getParent().getURI());
ArgValidator.checkFieldNotNull(fs, "filesystem");
// if the delete request is with force flag!!!
if (param.getForceDelete()) {
_log.error("Quota directory delete operation is not supported with force delete {}", param.getForceDelete());
throw APIException.badRequests.quotaDirectoryDeleteNotSupported(param.getForceDelete());
} else {
// Fail to delete quota directory, if there are any dependency objects like exports, shares
if (quotaDirectoryHasExportsOrShares(fs, quotaDirectory.getName())) {
throw APIException.badRequests.resourceCannotBeDeleted("Quota directory " + quotaDirectory.getName() + " has exports/shares ");
}
}
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.DELETE_FILE_SYSTEM_QUOTA_DIR);
quotaDirectory.getOpStatus().createTaskStatus(task, op);
fs.setOpStatus(new OpStatusMap());
fs.getOpStatus().createTaskStatus(task, op);
_dbClient.persistObject(fs);
_dbClient.persistObject(quotaDirectory);
// 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.deleteQuotaDirectory(device.getId(), quotaDirectory.getId(), fs.getId(), task);
} catch (InternalException e) {
throw e;
}
auditOp(OperationTypeEnum.DELETE_FILE_SYSTEM_QUOTA_DIR, true, AuditLogManager.AUDITOP_BEGIN, quotaDirectory.getLabel(), quotaDirectory.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(quotaDirectory, task, op);
}
Aggregations