Search in sources :

Example 6 with QuotaDirectory

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);
}
Also used : QuotaDirectory(com.emc.storageos.db.client.model.QuotaDirectory) FileShareQuotaDirectory(com.emc.storageos.volumecontroller.FileShareQuotaDirectory) Operation(com.emc.storageos.db.client.model.Operation) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) 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 7 with QuotaDirectory

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;
}
Also used : QuotaDirectoryList(com.emc.storageos.model.file.QuotaDirectoryList) QuotaDirectory(com.emc.storageos.db.client.model.QuotaDirectory) FileShareQuotaDirectory(com.emc.storageos.volumecontroller.FileShareQuotaDirectory) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 8 with QuotaDirectory

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;
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) MapQuotaDirectory(com.emc.storageos.api.mapper.functions.MapQuotaDirectory) FileShareQuotaDirectory(com.emc.storageos.volumecontroller.FileShareQuotaDirectory) QuotaDirectory(com.emc.storageos.db.client.model.QuotaDirectory) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException)

Example 9 with QuotaDirectory

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();
}
Also used : MapQuotaDirectory(com.emc.storageos.api.mapper.functions.MapQuotaDirectory) FileShareQuotaDirectory(com.emc.storageos.volumecontroller.FileShareQuotaDirectory) QuotaDirectory(com.emc.storageos.db.client.model.QuotaDirectory) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare)

Example 10 with QuotaDirectory

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);
}
Also used : FileController(com.emc.storageos.volumecontroller.FileController) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) MapQuotaDirectory(com.emc.storageos.api.mapper.functions.MapQuotaDirectory) FileShareQuotaDirectory(com.emc.storageos.volumecontroller.FileShareQuotaDirectory) QuotaDirectory(com.emc.storageos.db.client.model.QuotaDirectory) Operation(com.emc.storageos.db.client.model.Operation) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) 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)

Aggregations

QuotaDirectory (com.emc.storageos.db.client.model.QuotaDirectory)31 FileShareQuotaDirectory (com.emc.storageos.volumecontroller.FileShareQuotaDirectory)17 FileShare (com.emc.storageos.db.client.model.FileShare)15 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)11 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)10 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)9 URI (java.net.URI)9 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)7 ControllerException (com.emc.storageos.volumecontroller.ControllerException)7 MapQuotaDirectory (com.emc.storageos.api.mapper.functions.MapQuotaDirectory)6 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)6 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)6 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)6 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 URISyntaxException (java.net.URISyntaxException)5 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)4 NamedURI (com.emc.storageos.db.client.model.NamedURI)4 OpStatusMap (com.emc.storageos.db.client.model.OpStatusMap)4