Search in sources :

Example 21 with QuotaDirectory

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

the class VNXFileStorageDeviceXML method doDeleteQuotaDirectory.

@Override
public BiosCommandResult doDeleteQuotaDirectory(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    BiosCommandResult result = new BiosCommandResult();
    ApplicationContext context = null;
    XMLApiResult apiResult = null;
    try {
        _log.info("VNXFileStorageDeviceXML doDeleteQuotaDirectory - start");
        String fsName = args.getFsName();
        String quotaTreetreeName = args.getQuotaDirectoryName();
        QuotaDirectory quotaDir = args.getQuotaDirectory();
        if (null == fsName) {
            _log.error("VNXFileStorageDeviceXML::doDeleteQuotaDirectory failed:  Filesystem name is either missing or empty");
            ServiceError serviceError = DeviceControllerErrors.vnx.unableToDeleteQuotaDir();
            serviceError.setMessage(FileSystemConstants.FS_ERR_FS_NAME_MISSING_OR_EMPTY);
            result = BiosCommandResult.createErrorResult(serviceError);
            return result;
        }
        if (null == quotaTreetreeName) {
            _log.error("VNXFileStorageDeviceXML::doDeleteQuotaDirectory failed:  Quota Tree name is either missing or empty");
            ServiceError serviceError = DeviceControllerErrors.vnx.unableToDeleteQuotaDir();
            serviceError.setMessage(FileSystemConstants.FS_ERR_QUOTADIR_NAME_MISSING_OR_EMPTY);
            result = BiosCommandResult.createErrorResult(serviceError);
            return result;
        }
        _log.info("FSName: {}", args.getFsName());
        _log.info("Quota tree name: {}", args.getQuotaDirectoryName());
        boolean isMountRequired = !(args.isFileShareMounted());
        _log.info("Mount required or not, to delete quota dir requested {}", isMountRequired);
        // Load the context
        context = loadContext();
        VNXFileCommApi vnxComm = loadVNXFileCommunicationAPIs(context);
        if (null == vnxComm) {
            throw VNXException.exceptions.communicationFailed(VNXCOMM_ERR_MSG);
        }
        // we can't delete quota, if the filsystem is not mount, We should changes quota cmd
        apiResult = vnxComm.deleteQuotaDirectory(storage, args.getFsName(), quotaTreetreeName, true, isMountRequired);
        if (apiResult.isCommandSuccess()) {
            result = BiosCommandResult.createSuccessfulResult();
        }
        _log.info("doDeleteQuotaDirectory call result : {}", apiResult.isCommandSuccess());
    } catch (VNXException e) {
        throw new DeviceControllerException(e);
    } finally {
        clearContext(context);
    }
    BiosCommandResult cmdResult = null;
    if (result.isCommandSuccess()) {
        cmdResult = BiosCommandResult.createSuccessfulResult();
    } else {
        cmdResult = BiosCommandResult.createErrorResult(DeviceControllerErrors.vnx.unableToDeleteQuotaDir());
    }
    return cmdResult;
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) VNXException(com.emc.storageos.vnx.xmlapi.VNXException) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) VNXFileCommApi(com.emc.storageos.volumecontroller.impl.plugins.provisioning.VNXFileCommApi) QuotaDirectory(com.emc.storageos.db.client.model.QuotaDirectory) XMLApiResult(com.emc.storageos.vnx.xmlapi.XMLApiResult) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 22 with QuotaDirectory

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

the class IsilonFileStorageDevice method isiDeleteQuotaDirs.

/**
 * Deleting Quota dirs: - deletes quota dirs of a file system
 *
 * @param isi
 *            IsilonApi object
 * @param args
 *            FileDeviceInputOutput
 * @throws IsilonException
 */
private void isiDeleteQuotaDirs(IsilonApi isi, FileDeviceInputOutput args) throws IsilonException {
    List<URI> quotaDirURIList = _dbClient.queryByConstraint(ContainmentConstraint.Factory.getQuotaDirectoryConstraint(args.getFsId()));
    for (URI quotaDirURI : quotaDirURIList) {
        QuotaDirectory quotaDir = _dbClient.queryObject(QuotaDirectory.class, quotaDirURI);
        if (quotaDir != null && (!quotaDir.getInactive())) {
            if (quotaDir.getExtensions() != null && quotaDir.getExtensions().containsKey(QUOTA)) {
                String quotaDirPath = args.getFsMountPath() + "/" + quotaDir.getName();
                // if the quota directory has some data in it.
                if (isi.fsDirHasData(quotaDirPath)) {
                    // Fail to delete file system quota directory which has data in it!!!
                    _log.error("Quota directory deletion failed as it's directory path {} has content in it", quotaDirPath);
                    throw DeviceControllerException.exceptions.failToDeleteQuotaDirectory(quotaDirPath);
                }
                String quotaId = quotaDir.getExtensions().get(QUOTA);
                _log.info("IsilonFileStorageDevice isiDeleteQuotaDirs , Delete Quota {}", quotaId);
                isi.deleteQuota(quotaId);
                // delete from quota extensions
                quotaDir.getExtensions().remove(QUOTA);
                // delete directory for the Quota Directory
                isi.deleteDir(quotaDirPath);
            }
        }
    }
}
Also used : QuotaDirectory(com.emc.storageos.db.client.model.QuotaDirectory) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 23 with QuotaDirectory

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

the class VNXFileCommApi method getVNXFSDependencies.

/*
     * Check the dependencies on file share or on snap shot.
     * input :
     * fs: File share object
     * considerSnapshots: consider the snap shot dependencies.
     * return: this function will check and return the number of dependencies like
     * exports, shares, snapshot and quota directories on the given file share.
     */
private int getVNXFSDependencies(FileShare fs, Boolean considerSnapshots) {
    FSExportMap exports = null;
    SMBShareMap shares = null;
    int totalDependencies = 0;
    // FileShare operation
    if (fs.getFsExports() != null) {
        exports = fs.getFsExports();
    }
    if (fs.getSMBFileShares() != null) {
        shares = fs.getSMBFileShares();
    }
    if (exports != null) {
        totalDependencies += exports.size();
    }
    if (shares != null) {
        totalDependencies += shares.size();
    }
    List<Snapshot> snapshots = getFSSnapshots(fs);
    if (snapshots != null && !snapshots.isEmpty()) {
        totalDependencies += snapshots.size();
    }
    List<QuotaDirectory> quotaDirs = getFSQuotaDirs(fs);
    if (quotaDirs != null && !quotaDirs.isEmpty()) {
        totalDependencies += quotaDirs.size();
    }
    if (considerSnapshots && snapshots != null) {
        totalDependencies = snapshots.size();
        for (Snapshot snap : snapshots) {
            exports = snap.getFsExports();
            shares = snap.getSMBFileShares();
            if (exports != null) {
                totalDependencies += exports.size();
            }
            if (shares != null) {
                totalDependencies += shares.size();
            }
        }
    }
    _log.info("FileShare : total dependencies {} ", totalDependencies);
    return totalDependencies;
}
Also used : Snapshot(com.emc.storageos.db.client.model.Snapshot) VNXSnapshot(com.emc.storageos.vnx.xmlapi.VNXSnapshot) SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) QuotaDirectory(com.emc.storageos.db.client.model.QuotaDirectory) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) Checkpoint(com.emc.nas.vnxfile.xmlapi.Checkpoint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint)

Example 24 with QuotaDirectory

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

the class UnManagedFilesystemService method ingestFileQuotaDirectories.

private void ingestFileQuotaDirectories(FileShare parentFS) throws IOException {
    String parentFsNativeGUID = parentFS.getNativeGuid();
    URIQueryResultList result = new URIQueryResultList();
    List<QuotaDirectory> quotaDirectories = new ArrayList<>();
    _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getUnManagedFileQuotaDirectoryInfoParentNativeGUIdConstraint(parentFsNativeGUID), result);
    List<UnManagedFileQuotaDirectory> unManagedFileQuotaDirectories = _dbClient.queryObject(UnManagedFileQuotaDirectory.class, result);
    _logger.info("found {} quota directories for fs {}", unManagedFileQuotaDirectories.size(), parentFS.getId());
    for (UnManagedFileQuotaDirectory unManagedFileQuotaDirectory : unManagedFileQuotaDirectories) {
        QuotaDirectory quotaDirectory = new QuotaDirectory();
        quotaDirectory.setId(URIUtil.createId(QuotaDirectory.class));
        quotaDirectory.setParent(new NamedURI(parentFS.getId(), unManagedFileQuotaDirectory.getLabel()));
        quotaDirectory.setNativeId(unManagedFileQuotaDirectory.getNativeId());
        quotaDirectory.setLabel(unManagedFileQuotaDirectory.getLabel());
        quotaDirectory.setOpStatus(new OpStatusMap());
        quotaDirectory.setProject(new NamedURI(parentFS.getProject().getURI(), unManagedFileQuotaDirectory.getLabel()));
        quotaDirectory.setTenant(new NamedURI(parentFS.getTenant().getURI(), unManagedFileQuotaDirectory.getLabel()));
        quotaDirectory.setInactive(false);
        quotaDirectory.setSoftLimit(unManagedFileQuotaDirectory.getSoftLimit() != null && unManagedFileQuotaDirectory.getSoftLimit() != 0 ? unManagedFileQuotaDirectory.getSoftLimit() : parentFS.getSoftLimit() != null ? parentFS.getSoftLimit().intValue() : 0);
        quotaDirectory.setSoftGrace(unManagedFileQuotaDirectory.getSoftGrace() != null && unManagedFileQuotaDirectory.getSoftGrace() != 0 ? unManagedFileQuotaDirectory.getSoftGrace() : parentFS.getSoftGracePeriod() != null ? parentFS.getSoftGracePeriod() : 0);
        quotaDirectory.setNotificationLimit(unManagedFileQuotaDirectory.getNotificationLimit() != null && unManagedFileQuotaDirectory.getNotificationLimit() != 0 ? unManagedFileQuotaDirectory.getNotificationLimit() : parentFS.getNotificationLimit() != null ? parentFS.getNotificationLimit().intValue() : 0);
        String convertedName = unManagedFileQuotaDirectory.getLabel().replaceAll("[^\\dA-Za-z_]", "");
        _logger.info("FileService::QuotaDirectory Original name {} and converted name {}", unManagedFileQuotaDirectory.getLabel(), convertedName);
        quotaDirectory.setName(convertedName);
        if (unManagedFileQuotaDirectory.getOpLock() != null) {
            quotaDirectory.setOpLock(unManagedFileQuotaDirectory.getOpLock());
        } else {
            quotaDirectory.setOpLock(true);
        }
        quotaDirectory.setSize(unManagedFileQuotaDirectory.getSize());
        quotaDirectory.setSecurityStyle(unManagedFileQuotaDirectory.getSecurityStyle());
        quotaDirectory.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(_dbClient, quotaDirectory, parentFS.getName()));
        // check for file extensions
        if (null != unManagedFileQuotaDirectory.getExtensions() && !unManagedFileQuotaDirectory.getExtensions().isEmpty()) {
            StringMap extensions = new StringMap();
            if (null != unManagedFileQuotaDirectory.getExtensions().get(QUOTA)) {
                extensions.put(QUOTA, unManagedFileQuotaDirectory.getExtensions().get(QUOTA));
                quotaDirectory.setExtensions(extensions);
            }
        }
        quotaDirectories.add(quotaDirectory);
    }
    if (!quotaDirectories.isEmpty()) {
        _dbClient.updateObject(quotaDirectories);
    }
    if (!unManagedFileQuotaDirectories.isEmpty()) {
        unManagedFileQuotaDirectories.forEach(unManagedFileQuotaDir -> unManagedFileQuotaDir.setInactive(true));
        _dbClient.updateObject(unManagedFileQuotaDirectories);
        _logger.info("ingested {} quota directories for fs {}", unManagedFileQuotaDirectories.size(), parentFS.getId());
    }
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) NamedURI(com.emc.storageos.db.client.model.NamedURI) ArrayList(java.util.ArrayList) UnManagedFileQuotaDirectory(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileQuotaDirectory) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) QuotaDirectory(com.emc.storageos.db.client.model.QuotaDirectory) UnManagedFileQuotaDirectory(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileQuotaDirectory) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 25 with QuotaDirectory

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

the class FileService 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) QuotaDirectory(com.emc.storageos.db.client.model.QuotaDirectory) FileShareQuotaDirectory(com.emc.storageos.volumecontroller.FileShareQuotaDirectory) 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) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

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