Search in sources :

Example 26 with QuotaDirectory

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

Example 27 with QuotaDirectory

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);
}
Also used : FileShareQuotaDirectory(com.emc.storageos.volumecontroller.FileShareQuotaDirectory) 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) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) 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 28 with QuotaDirectory

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

Example 29 with QuotaDirectory

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;
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) 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) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 30 with QuotaDirectory

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

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