Search in sources :

Example 1 with QuotaDirectory

use of com.emc.storageos.db.client.model.QuotaDirectory in project coprhd-controller by CoprHD.

the class FileDeviceController method deleteQuotaDirectory.

@Override
public void deleteQuotaDirectory(URI storage, URI quotaDir, URI fs, String task) throws ControllerException {
    FileShare fsObj = null;
    QuotaDirectory quotaDirObj = null;
    try {
        String[] params = { storage.toString(), quotaDir.toString(), fs.toString() };
        _log.info("FileDeviceController::deleteQuotaDirectory: storage : {}, quotadir : {}, fs : {}", params);
        StorageSystem storageObj = _dbClient.queryObject(StorageSystem.class, storage);
        fsObj = _dbClient.queryObject(FileShare.class, fs);
        quotaDirObj = _dbClient.queryObject(QuotaDirectory.class, quotaDir);
        FileDeviceInputOutput args = new FileDeviceInputOutput();
        args.addFSFileObject(fsObj);
        args.addQuotaDirectory(quotaDirObj);
        args.setOpId(task);
        FileStorageDevice nasDevice = getDevice(storageObj.getSystemType());
        BiosCommandResult result = nasDevice.doDeleteQuotaDirectory(storageObj, args);
        if (result.getCommandPending()) {
            return;
        }
        fsObj.getOpStatus().updateTaskStatus(task, result.toOperation());
        quotaDirObj.getOpStatus().updateTaskStatus(task, result.toOperation());
        String fsName = fsObj.getName();
        quotaDirObj.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(_dbClient, quotaDirObj, fsName));
        if (!result.isCommandSuccess()) {
            _log.error("FileDeviceController::deleteQuotaDirectory: command is not successfull");
        } else {
            // If delete operation is successful, then remove obj from ViPR db by setting inactive=true
            quotaDirObj.setInactive(true);
        }
        // save the task status in db
        _dbClient.updateObject(quotaDirObj);
        _dbClient.updateObject(fsObj);
        fsObj = _dbClient.queryObject(FileShare.class, fs);
        _log.debug("FileDeviceController::deleteQuotaDirectory: After deleteQuotaDirectory created and fs persisted, Task Stauts {} -- Operation Details : {}", fsObj.getOpStatus().get(task).getStatus(), result.toOperation());
        String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
        recordFileDeviceOperation(_dbClient, OperationTypeEnum.DELETE_FILE_SYSTEM_QUOTA_DIR, result.isCommandSuccess(), eventMsg, "", quotaDirObj, fsObj);
    } catch (Exception e) {
        String[] params = { storage.toString(), fs.toString(), quotaDir.toString(), e.getMessage() };
        _log.error("FileDeviceController::deleteQuotaDirectory: Unable to create file system quota dir: storage {}, FS {}, quotadir {}: {}", params);
        updateTaskStatus(task, fsObj, e);
        updateTaskStatus(task, quotaDirObj, e);
        if ((fsObj != null) && (quotaDirObj != null)) {
            recordFileDeviceOperation(_dbClient, OperationTypeEnum.DELETE_FILE_SYSTEM_QUOTA_DIR, false, e.getMessage(), "", quotaDirObj, fsObj);
        }
    }
}
Also used : QuotaDirectory(com.emc.storageos.db.client.model.QuotaDirectory) FileShareQuotaDirectory(com.emc.storageos.volumecontroller.FileShareQuotaDirectory) FileStorageDevice(com.emc.storageos.volumecontroller.FileStorageDevice) FileDeviceInputOutput(com.emc.storageos.volumecontroller.FileDeviceInputOutput) 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) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 2 with QuotaDirectory

use of com.emc.storageos.db.client.model.QuotaDirectory in project coprhd-controller by CoprHD.

the class FileDeviceController method createQuotaDirectory.

@Override
public void createQuotaDirectory(URI storage, FileShareQuotaDirectory quotaDir, URI fs, String task) throws ControllerException {
    ControllerUtils.setThreadLocalLogData(fs, task);
    FileShare fsObj = null;
    QuotaDirectory quotaDirObj = null;
    try {
        String[] params = { storage.toString(), fs.toString(), quotaDir.toString() };
        _log.info("FileDeviceController::createQtree: create QuotaDirectory: storage : {}, quotaDir : {}, fs : {}", params);
        StorageSystem storageObj = _dbClient.queryObject(StorageSystem.class, storage);
        fsObj = _dbClient.queryObject(FileShare.class, fs);
        URI qtreeURI = quotaDir.getId();
        quotaDirObj = _dbClient.queryObject(QuotaDirectory.class, qtreeURI);
        FileDeviceInputOutput args = new FileDeviceInputOutput();
        // Set up args
        args.addFileShare(fsObj);
        args.addQuotaDirectory(quotaDirObj);
        args.setOpId(task);
        FileStorageDevice nasDevice = getDevice(storageObj.getSystemType());
        BiosCommandResult result = nasDevice.doCreateQuotaDirectory(storageObj, args, quotaDirObj);
        if (result.getCommandPending()) {
            return;
        }
        fsObj.getOpStatus().updateTaskStatus(task, result.toOperation());
        quotaDirObj.getOpStatus().updateTaskStatus(task, result.toOperation());
        String fsName = fsObj.getName();
        quotaDirObj.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(_dbClient, quotaDirObj, fsName));
        // In case of an error, set the quotaDir to an 'inactive' state.
        if (!result.isCommandSuccess()) {
            quotaDirObj.setInactive(true);
            _log.error("FileDeviceController::createQtree: QuotaDirectory create command is not successfull");
        }
        _dbClient.updateObject(quotaDirObj);
        _dbClient.updateObject(fsObj);
        fsObj = _dbClient.queryObject(FileShare.class, fs);
        _log.debug("FileDeviceController::createQtree: After QuotaDirectory created and fs persisted, Task Stauts {} -- Operation Details : {}", fsObj.getOpStatus().get(task).getStatus(), result.toOperation());
        String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
        recordFileDeviceOperation(_dbClient, OperationTypeEnum.CREATE_FILE_SYSTEM_QUOTA_DIR, result.isCommandSuccess(), eventMsg, "", quotaDirObj, fsObj);
    } catch (Exception e) {
        String[] params = { storage.toString(), fs.toString(), quotaDir.toString(), e.getMessage() };
        _log.error("FileDeviceController::createQtree: Unable to create file system quotaDir: storage {}, FS {}, snapshot {}: {}", params);
        // remove from DB
        if (quotaDirObj != null) {
            quotaDirObj.setInactive(true);
            _dbClient.updateObject(quotaDirObj);
        }
        updateTaskStatus(task, fsObj, e);
        updateTaskStatus(task, quotaDirObj, e);
        if ((fsObj != null) && (quotaDirObj != null)) {
            recordFileDeviceOperation(_dbClient, OperationTypeEnum.CREATE_FILE_SYSTEM_QUOTA_DIR, false, e.getMessage(), "", quotaDirObj, fsObj);
        }
    }
}
Also used : QuotaDirectory(com.emc.storageos.db.client.model.QuotaDirectory) FileShareQuotaDirectory(com.emc.storageos.volumecontroller.FileShareQuotaDirectory) FileStorageDevice(com.emc.storageos.volumecontroller.FileStorageDevice) FileDeviceInputOutput(com.emc.storageos.volumecontroller.FileDeviceInputOutput) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) URI(java.net.URI) 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) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 3 with QuotaDirectory

use of com.emc.storageos.db.client.model.QuotaDirectory in project coprhd-controller by CoprHD.

the class FileDeviceController method quotaDirectoriesExistsOnFS.

private boolean quotaDirectoriesExistsOnFS(FileShare fs) {
    _log.info(" Setting Snapshots to InActive with Force Delete ");
    URIQueryResultList qdIDList = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getQuotaDirectoryConstraint(fs.getId()), qdIDList);
    _log.info("getQuotaDirectories : FS {}: {} ", fs.getId().toString(), qdIDList.toString());
    List<QuotaDirectory> qdList = _dbClient.queryObject(QuotaDirectory.class, qdIDList);
    if (qdList != null) {
        for (QuotaDirectory qd : qdList) {
            if (!qd.getInactive()) {
                return true;
            }
        }
    }
    return false;
}
Also used : QuotaDirectory(com.emc.storageos.db.client.model.QuotaDirectory) FileShareQuotaDirectory(com.emc.storageos.volumecontroller.FileShareQuotaDirectory) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 4 with QuotaDirectory

use of com.emc.storageos.db.client.model.QuotaDirectory in project coprhd-controller by CoprHD.

the class FileDeviceController method updateQuotaDirectory.

@Override
public void updateQuotaDirectory(URI storage, FileShareQuotaDirectory quotaDir, URI fs, String task) throws ControllerException {
    ControllerUtils.setThreadLocalLogData(fs, task);
    FileShare fsObj = null;
    StorageSystem storageObj = null;
    QuotaDirectory quotaDirObj = null;
    FileDeviceInputOutput args = new FileDeviceInputOutput();
    try {
        String[] params = { storage.toString(), fs.toString(), quotaDir.toString() };
        _log.info("FileDeviceController::updateQtree:  storage : {}, fs : {}, quotaDir : {}", params);
        fsObj = _dbClient.queryObject(FileShare.class, fs);
        storageObj = _dbClient.queryObject(StorageSystem.class, storage);
        quotaDirObj = _dbClient.queryObject(QuotaDirectory.class, quotaDir.getId());
        if (null != quotaDir.getSize()) {
            quotaDirObj.setSize(quotaDir.getSize());
        }
        quotaDirObj.setSoftLimit(quotaDir.getSoftLimit());
        quotaDirObj.setSoftGrace(quotaDir.getSoftGrace());
        quotaDirObj.setNotificationLimit(quotaDir.getNotificationLimit());
        if (null != quotaDir.getOpLock()) {
            quotaDirObj.setOpLock(quotaDir.getOpLock());
        }
        if (null != quotaDir.getSecurityStyle()) {
            quotaDirObj.setSecurityStyle(quotaDir.getSecurityStyle());
        }
        // Set up args
        args.addFileShare(fsObj);
        args.addQuotaDirectory(quotaDirObj);
        args.setOpId(task);
        FileStorageDevice nasDevice = getDevice(storageObj.getSystemType());
        BiosCommandResult result = nasDevice.doUpdateQuotaDirectory(storageObj, args, quotaDirObj);
        if (result.getCommandPending()) {
            return;
        }
        if (!result.isCommandSuccess() && !result.getCommandPending()) {
            _log.error("FileDeviceController::updateQtree: QuotaDirectory update command is not successful");
            // The quota object was already modified with changes.
            // if it fail to update the quota directory,
            // restore the object with the original quota directory!!!
            quotaDirObj = _dbClient.queryObject(QuotaDirectory.class, quotaDir.getId());
        }
        quotaDirObj.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(_dbClient, quotaDirObj, fsObj.getName()));
        fsObj.getOpStatus().updateTaskStatus(task, result.toOperation());
        quotaDirObj.getOpStatus().updateTaskStatus(task, result.toOperation());
        // save the task status into db
        _dbClient.updateObject(quotaDirObj);
        _dbClient.updateObject(fsObj);
        fsObj = _dbClient.queryObject(FileShare.class, fs);
        _log.debug("FileDeviceController::updateQtree: After QuotaDirectory updated and fs persisted, Task Stauts {} -- Operation Details : {}", fsObj.getOpStatus().get(task).getStatus(), result.toOperation());
        String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
        recordFileDeviceOperation(_dbClient, OperationTypeEnum.UPDATE_FILE_SYSTEM_QUOTA_DIR, result.isCommandSuccess(), eventMsg, "", quotaDirObj, fsObj);
    } catch (Exception e) {
        String[] params = { storage.toString(), fs.toString(), quotaDir.toString(), e.getMessage() };
        _log.error("FileDeviceController::updateQtree: Unable to update file system quotaDir: storage {}, FS {}, snapshot {}: {}", params);
        updateTaskStatus(task, fsObj, e);
        updateTaskStatus(task, quotaDirObj, e);
        if ((fsObj != null) && (quotaDirObj != null)) {
            recordFileDeviceOperation(_dbClient, OperationTypeEnum.CREATE_FILE_SYSTEM_QUOTA_DIR, false, e.getMessage(), "", quotaDirObj, fsObj);
        }
    }
}
Also used : QuotaDirectory(com.emc.storageos.db.client.model.QuotaDirectory) FileShareQuotaDirectory(com.emc.storageos.volumecontroller.FileShareQuotaDirectory) FileStorageDevice(com.emc.storageos.volumecontroller.FileStorageDevice) FileDeviceInputOutput(com.emc.storageos.volumecontroller.FileDeviceInputOutput) 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) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 5 with QuotaDirectory

use of com.emc.storageos.db.client.model.QuotaDirectory in project coprhd-controller by CoprHD.

the class FileService method createQuotaDirectory.

/**
 * Create Quota directory for a file system
 * <p>
 * NOTE: This is an asynchronous operation.
 *
 * @param id
 *            the URN of a ViPR File system
 * @param param
 *            File system Quota directory parameters
 * @brief Create file system Quota directory
 * @return Task resource representation
 * @throws InternalException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/quota-directories")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep createQuotaDirectory(@PathParam("id") URI id, QuotaDirectoryCreateParam param) throws InternalException {
    _log.info("FileService::createQtree Request recieved {}", id);
    String origQtreeName = param.getQuotaDirName();
    ArgValidator.checkQuotaDirName(origQtreeName, "name");
    ArgValidator.checkFieldMaximum(param.getSoftLimit(), 100, "softLimit");
    ArgValidator.checkFieldMaximum(param.getNotificationLimit(), 100, "notificationLimit");
    if (param.getSoftLimit() != 0L) {
        ArgValidator.checkFieldMinimum(param.getSoftGrace(), 1L, "softGrace");
    }
    // check duplicate QuotaDirectory names for this fileshare
    checkForDuplicateName(origQtreeName, QuotaDirectory.class, id, "parent", _dbClient);
    String task = UUID.randomUUID().toString();
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    if (param.getSecurityStyle() != null) {
        ArgValidator.checkFieldValueFromEnum(param.getSecurityStyle(), "security_style", EnumSet.allOf(QuotaDirectory.SecurityStyles.class));
    }
    // Get the FileSystem object from the URN
    FileShare fs = queryResource(id);
    ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
    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();
    }
    // Create the QuotaDirectory object for the DB
    QuotaDirectory quotaDirectory = new QuotaDirectory();
    quotaDirectory.setId(URIUtil.createId(QuotaDirectory.class));
    // ICICIC - Curious !
    quotaDirectory.setParent(new NamedURI(id, origQtreeName));
    quotaDirectory.setLabel(origQtreeName);
    quotaDirectory.setOpStatus(new OpStatusMap());
    quotaDirectory.setProject(new NamedURI(fs.getProject().getURI(), origQtreeName));
    quotaDirectory.setTenant(new NamedURI(fs.getTenant().getURI(), origQtreeName));
    quotaDirectory.setSoftLimit(param.getSoftLimit() > 0 ? param.getSoftLimit() : fsSoftLimit > 0 ? fsSoftLimit : 0);
    quotaDirectory.setSoftGrace(param.getSoftGrace() > 0 ? param.getSoftGrace() : fsGraceLimit > 0 ? fsGraceLimit : 0);
    quotaDirectory.setNotificationLimit(param.getNotificationLimit() > 0 ? param.getNotificationLimit() : fsNotifiLimit > 0 ? fsNotifiLimit : 0);
    String convertedName = origQtreeName.replaceAll("[^\\dA-Za-z_]", "");
    _log.info("FileService::QuotaDirectory Original name {} and converted name {}", origQtreeName, convertedName);
    quotaDirectory.setName(convertedName);
    if (param.getOpLock() != null) {
        quotaDirectory.setOpLock(param.getOpLock());
    } else {
        quotaDirectory.setOpLock(true);
    }
    if (param.getSecurityStyle() != null) {
        quotaDirectory.setSecurityStyle(param.getSecurityStyle());
    } else {
        quotaDirectory.setSecurityStyle(SecurityStyles.parent.toString());
    }
    if (param.getSize() != null) {
        // converts the input string in format "<value>GB"
        Long quotaSize = SizeUtil.translateSize(param.getSize());
        // to bytes
        ArgValidator.checkFieldMaximum(quotaSize, fs.getCapacity(), SizeUtil.SIZE_B, "size", true);
        quotaDirectory.setSize(quotaSize);
    } else {
        quotaDirectory.setSize((long) 0);
    }
    fs.setOpStatus(new OpStatusMap());
    Operation op = new Operation();
    op.setResourceType(ResourceOperationTypeEnum.CREATE_FILE_SYSTEM_QUOTA_DIR);
    quotaDirectory.getOpStatus().createTaskStatus(task, op);
    fs.getOpStatus().createTaskStatus(task, op);
    _dbClient.createObject(quotaDirectory);
    _dbClient.persistObject(fs);
    // Create an object of type "FileShareQuotaDirectory" to be passed into the south-bound layers.
    FileShareQuotaDirectory qt = new FileShareQuotaDirectory(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.createQuotaDirectory(device.getId(), qt, fs.getId(), task);
    } catch (InternalException e) {
        quotaDirectory.setInactive(true);
        _dbClient.persistObject(quotaDirectory);
        // should discriminate between validation problems vs. internal errors
        throw e;
    }
    auditOp(OperationTypeEnum.CREATE_FILE_SYSTEM_QUOTA_DIR, true, AuditLogManager.AUDITOP_BEGIN, quotaDirectory.getLabel(), quotaDirectory.getId().toString(), fs.getId().toString());
    fs = _dbClient.queryObject(FileShare.class, id);
    _log.debug("FileService::QuotaDirectory Before sending response, FS ID : {}, Tasks : {} ; Status {}", fs.getOpStatus().get(task), fs.getOpStatus().get(task).getStatus());
    return toTask(quotaDirectory, task, op);
}
Also used : NamedURI(com.emc.storageos.db.client.model.NamedURI) FileController(com.emc.storageos.volumecontroller.FileController) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) 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) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) SecurityStyles(com.emc.storageos.db.client.model.QuotaDirectory.SecurityStyles) FileShareQuotaDirectory(com.emc.storageos.volumecontroller.FileShareQuotaDirectory) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) 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