Search in sources :

Example 11 with QuotaDirectory

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

the class IsilonFileStorageDevice method doUpdateQuotaDirectory.

@Override
public BiosCommandResult doUpdateQuotaDirectory(StorageSystem storage, FileDeviceInputOutput args, QuotaDirectory quotaDir) throws ControllerException {
    // Get Parent FS mount path
    // Get Quota Directory Name
    // Get Quota Size
    // Call Update Quota (Aways use that quota for updating the size)
    QuotaDirectory quotaDirObj = null;
    String fsMountPath = args.getFsMountPath();
    Long qDirSize = quotaDir.getSize();
    String qDirPath = fsMountPath + "/" + quotaDir.getName();
    _log.info("IsilonFileStorageDevice doUpdateQuotaDirectory {} with size {} - start", qDirPath, qDirSize);
    try {
        IsilonApi isi = getIsilonDevice(storage);
        URI qtreeURI = quotaDir.getId();
        quotaDirObj = _dbClient.queryObject(QuotaDirectory.class, qtreeURI);
        String quotaId = null;
        if (quotaDirObj.getExtensions() != null) {
            quotaId = quotaDirObj.getExtensions().get(QUOTA);
        }
        if (quotaId != null) {
            // Isilon does not allow to update quota directory to zero.
            IsilonSmartQuota isiCurrentSmartQuota = isi.getQuota(quotaId);
            long quotaUsageSpace = isiCurrentSmartQuota.getUsagePhysical();
            if (qDirSize > 0 && qDirSize.compareTo(quotaUsageSpace) > 0) {
                _log.info("IsilonFileStorageDevice doUpdateQuotaDirectory , Update Quota {} with Capacity {}", quotaId, qDirSize);
                IsilonSmartQuota expandedQuota = getQuotaDirectoryExpandedSmartQuota(quotaDir, qDirSize, args.getFsCapacity(), isi);
                isi.modifyQuota(quotaId, expandedQuota);
            } else {
                Double dUsage = SizeUtil.translateSize(quotaUsageSpace, SizeUtil.SIZE_GB);
                Double dQuotaSize = SizeUtil.translateSize(qDirSize, SizeUtil.SIZE_GB);
                String msg = String.format("as requested reduced size [%.1fGB] is smaller than used capacity [%.1fGB] for filesystem %s", dQuotaSize, dUsage, args.getFs().getName());
                _log.error("doUpdateQuotaDirectory : " + msg);
                ServiceError error = DeviceControllerErrors.isilon.unableUpdateQuotaDirectory(msg);
                return BiosCommandResult.createErrorResult(error);
            }
        } else {
            // Create a new Quota
            String qid = checkThresholdAndcreateQuota(quotaDir, qDirSize, qDirPath, null, isi);
            if (args.getQuotaDirExtensions() == null) {
                args.initQuotaDirExtensions();
            }
            args.getQuotaDirExtensions().put(QUOTA, qid);
        }
        _log.info("IsilonFileStorageDevice doUpdateQuotaDirectory {} with size {} - complete", qDirPath, qDirSize);
        return BiosCommandResult.createSuccessfulResult();
    } catch (IsilonException e) {
        _log.error("doUpdateQuotaDirectory failed.", e);
        return BiosCommandResult.createErrorResult(e);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) IsilonSmartQuota(com.emc.storageos.isilon.restapi.IsilonSmartQuota) QuotaDirectory(com.emc.storageos.db.client.model.QuotaDirectory) IsilonApi(com.emc.storageos.isilon.restapi.IsilonApi) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) IsilonException(com.emc.storageos.isilon.restapi.IsilonException)

Example 12 with QuotaDirectory

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

the class IsilonFileStorageDevice method doDeleteQuotaDirectory.

@Override
public BiosCommandResult doDeleteQuotaDirectory(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    // Get Parent FS Mount Path
    // Get Quota Directory Name
    // Get Quota Size
    // Call Delete Quota
    // Call Delete Directory recursively
    QuotaDirectory quotaDir = args.getQuotaDirectory();
    String fsMountPath = args.getFsMountPath();
    Long qDirSize = quotaDir.getSize();
    String qDirPath = fsMountPath + "/" + quotaDir.getName();
    _log.info("IsilonFileStorageDevice doDeleteQuotaDirectory {} with size {} - start", qDirPath, qDirSize);
    try {
        IsilonApi isi = getIsilonDevice(storage);
        // if the quota directory has some data in it.
        if (isi.fsDirHasData(qDirPath)) {
            // Fail to delete quota directory which has data in it!!!
            _log.error("Quota directory deletion failed as it's directory path {} has content in it", qDirPath);
            throw DeviceControllerException.exceptions.failToDeleteQuotaDirectory(qDirPath);
        }
        String quotaId = null;
        if (quotaDir.getExtensions() != null) {
            quotaId = quotaDir.getExtensions().get(QUOTA);
        }
        if (quotaId != null) {
            _log.info("IsilonFileStorageDevice doDeleteQuotaDirectory , Delete Quota {}", quotaId);
            isi.deleteQuota(quotaId);
        }
        // delete directory for the Quota Directory
        isi.deleteDir(qDirPath);
        _log.info("IsilonFileStorageDevice doDeleteQuotaDirectory {} with size {} - complete", qDirPath, qDirSize);
        return BiosCommandResult.createSuccessfulResult();
    } catch (IsilonException e) {
        _log.error("doDeleteQuotaDirectory failed.", e);
        return BiosCommandResult.createErrorResult(e);
    }
}
Also used : QuotaDirectory(com.emc.storageos.db.client.model.QuotaDirectory) IsilonApi(com.emc.storageos.isilon.restapi.IsilonApi) IsilonException(com.emc.storageos.isilon.restapi.IsilonException)

Example 13 with QuotaDirectory

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

the class VNXFileCommApi method getFSQuotaDirs.

private List<QuotaDirectory> getFSQuotaDirs(FileShare fs) {
    URI fsId = fs.getId();
    List<QuotaDirectory> quotaDirs = new ArrayList<QuotaDirectory>();
    URIQueryResultList qdIDList = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getQuotaDirectoryConstraint(fsId), qdIDList);
    while (qdIDList.iterator().hasNext()) {
        URI uri = qdIDList.iterator().next();
        QuotaDirectory quotaDir = _dbClient.queryObject(QuotaDirectory.class, uri);
        if (!quotaDir.getInactive()) {
            quotaDirs.add(quotaDir);
        }
    }
    return quotaDirs;
}
Also used : ArrayList(java.util.ArrayList) QuotaDirectory(com.emc.storageos.db.client.model.QuotaDirectory) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 14 with QuotaDirectory

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

the class VNXUnityFileStorageDevice method doCreateQuotaDirectory.

@Override
public BiosCommandResult doCreateQuotaDirectory(StorageSystem storage, FileDeviceInputOutput args, QuotaDirectory qd) throws ControllerException {
    _logger.info("creating Quota Directory: ", args.getQuotaDirectoryName());
    VNXUnityQuotaDirectoryTaskCompleter completer = null;
    VNXeApiClient apiClient = getVnxUnityClient(storage);
    VNXeCommandJob job = null;
    try {
        Long softLimit = 0L;
        Long softGrace = 0L;
        Long size = 0L;
        if (qd.getSize() == 0) {
            // If quota directory has no size specified, inherit it from the parent fs
            size = args.getFsCapacity();
        // for the calculation of limit sizes
        } else {
            size = qd.getSize();
        }
        // conversion from percentage to bytes
        softLimit = Long.valueOf(qd.getSoftLimit() * size / 100);
        // using hard limit
        // conversion from days to seconds
        softGrace = Long.valueOf(qd.getSoftGrace() * 24 * 60 * 60);
        job = apiClient.createQuotaDirectory(args.getFsNativeId(), qd.getName(), qd.getSize(), softLimit, softGrace);
        if (job != null) {
            _logger.info("opid:" + args.getOpId());
            completer = new VNXUnityQuotaDirectoryTaskCompleter(QuotaDirectory.class, args.getQuotaDirectory().getId(), args.getOpId());
            if (args.getQuotaDirectory() == null) {
                _logger.error("Could not find the quota object");
            }
            VNXUnityCreateFileSystemQuotaDirectoryJob createQuotaJob = new VNXUnityCreateFileSystemQuotaDirectoryJob(job.getId(), storage.getId(), completer);
            ControllerServiceImpl.enqueueJob(new QueueJob(createQuotaJob));
        } else {
            _logger.error("No job returned from createQuotaDirectory");
            ServiceError error = DeviceControllerErrors.vnxe.jobFailed("No Job returned from createQuotaDirectory");
            return BiosCommandResult.createErrorResult(error);
        }
    } catch (VNXeException e) {
        _logger.error("Create Quota Directory got an exception", e);
        if (completer != null) {
            completer.error(dbClient, e);
        }
        return BiosCommandResult.createErrorResult(e);
    } catch (Exception ex) {
        _logger.error("Create Quota Directory got an exception", ex);
        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("CreateQuotaDirectory", ex.getMessage());
        if (completer != null) {
            completer.error(dbClient, error);
        }
        return BiosCommandResult.createErrorResult(error);
    }
    StringBuilder logMsgBuilder = new StringBuilder(String.format("Create filesystem job submitted - Array:%s, fileSystem: %s", storage.getSerialNumber(), args.getFsName()));
    _logger.info(logMsgBuilder.toString());
    return BiosCommandResult.createPendingResult();
}
Also used : VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) VNXeException(com.emc.storageos.vnxe.VNXeException) QuotaDirectory(com.emc.storageos.db.client.model.QuotaDirectory) VNXUnityQuotaDirectoryTaskCompleter(com.emc.storageos.volumecontroller.impl.vnxunity.job.VNXUnityQuotaDirectoryTaskCompleter) VNXUnityCreateFileSystemQuotaDirectoryJob(com.emc.storageos.volumecontroller.impl.vnxunity.job.VNXUnityCreateFileSystemQuotaDirectoryJob) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) VNXeException(com.emc.storageos.vnxe.VNXeException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException)

Example 15 with QuotaDirectory

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

the class VNXUnityFileStorageDevice method doUpdateQuotaDirectory.

@Override
public BiosCommandResult doUpdateQuotaDirectory(StorageSystem storage, FileDeviceInputOutput args, QuotaDirectory qd) throws ControllerException {
    _logger.info("updating Quota Directory: ", args.getQuotaDirectoryName());
    VNXUnityQuotaDirectoryTaskCompleter completer = null;
    VNXeApiClient apiClient = getVnxUnityClient(storage);
    VNXeCommandJob job = null;
    try {
        Long softLimit = 0L;
        Long softGrace = 0L;
        Long size = 0L;
        if (qd.getSize() == 0) {
            // If quota directory has no size specified, inherit it from the parent fs
            size = args.getFsCapacity();
        // for the calculation of limit sizes
        } else {
            size = qd.getSize();
        }
        // conversion from percentage to bytes
        softLimit = Long.valueOf(qd.getSoftLimit() * size / 100);
        // using hard limit
        // conversion from days to seconds
        softGrace = Long.valueOf(qd.getSoftGrace() * 24 * 60 * 60);
        job = apiClient.updateQuotaDirectory(qd.getNativeId(), qd.getSize(), softLimit, softGrace);
        if (job != null) {
            _logger.info("opid:" + args.getOpId());
            completer = new VNXUnityQuotaDirectoryTaskCompleter(QuotaDirectory.class, args.getQuotaDirectory().getId(), args.getOpId());
            if (args.getQuotaDirectory() == null) {
                _logger.error("Could not find the quota object");
            }
            VNXUnityUpdateFileSystemQuotaDirectoryJob createQuotaJob = new VNXUnityUpdateFileSystemQuotaDirectoryJob(job.getId(), storage.getId(), completer);
            ControllerServiceImpl.enqueueJob(new QueueJob(createQuotaJob));
        } else {
            _logger.error("No job returned from createQuotaDirectory");
            ServiceError error = DeviceControllerErrors.vnxe.jobFailed("No Job returned from createQuotaDirectory");
            return BiosCommandResult.createErrorResult(error);
        }
    } catch (VNXeException e) {
        _logger.error("update Quota Directory got an exception", e);
        if (completer != null) {
            completer.error(dbClient, e);
        }
        return BiosCommandResult.createErrorResult(e);
    } catch (Exception ex) {
        _logger.error("update Quota Directory got an exception", ex);
        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("UpdateQuotaDirectory", ex.getMessage());
        if (completer != null) {
            completer.error(dbClient, error);
        }
        return BiosCommandResult.createErrorResult(error);
    }
    StringBuilder logMsgBuilder = new StringBuilder(String.format("update quota directory job submitted - Array:%s, fileSystem: %s, Quota Directory: %s", storage.getSerialNumber(), args.getFsName(), args.getQuotaDirectoryName()));
    _logger.info(logMsgBuilder.toString());
    return BiosCommandResult.createPendingResult();
}
Also used : VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) VNXeException(com.emc.storageos.vnxe.VNXeException) QuotaDirectory(com.emc.storageos.db.client.model.QuotaDirectory) VNXUnityQuotaDirectoryTaskCompleter(com.emc.storageos.volumecontroller.impl.vnxunity.job.VNXUnityQuotaDirectoryTaskCompleter) VNXUnityUpdateFileSystemQuotaDirectoryJob(com.emc.storageos.volumecontroller.impl.vnxunity.job.VNXUnityUpdateFileSystemQuotaDirectoryJob) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) VNXeException(com.emc.storageos.vnxe.VNXeException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException)

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