Search in sources :

Example 1 with Quota

use of com.iwave.ext.netapp.model.Quota in project coprhd-controller by CoprHD.

the class QuotaCommands method getQuotas.

public List<Quota> getQuotas() {
    NaElement elem = new NaElement("quota-list-entries-iter");
    try {
        List<Quota> quotas = Lists.newArrayList();
        NaElement result = server.invokeElem(elem);
        List<NaElement> quotaElems = new ArrayList<NaElement>();
        // Add the Quotas for first call
        quotaElems.addAll((List<NaElement>) result.getChildByName("attributes-list").getChildren());
        // Make further server invokes if more quotas are present
        while (result.getChildByName("next-tag") != null) {
            NaElement tempElem = new NaElement("quota-list-entries-iter");
            tempElem.addNewChild("tag", result.getChildContent("next-tag"));
            result = server.invokeElem(tempElem);
            quotaElems.addAll((List<NaElement>) result.getChildByName("attributes-list").getChildren());
        }
        for (NaElement quotaElem : quotaElems) {
            Quota quota = new Quota();
            quota.setVolume(quotaElem.getChildContent("volume"));
            quota.setQuotaTarget(quotaElem.getChildContent("quota-target"));
            quota.setQuotaType(quotaElem.getChildContent("quota-type"));
            quota.setQtree(quotaElem.getChildContent("qtree"));
            quota.setDiskLimit(quotaElem.getChildContent("disk-limit"));
            quota.setFileLimit(quotaElem.getChildContent("file-limit"));
            quota.setSoftDiskLimit(quotaElem.getChildContent("soft-disk-limit"));
            quota.setSoftFileLimit(quotaElem.getChildContent("soft-file-limit"));
            quota.setThreshold(quotaElem.getChildContent("threshold"));
            quotas.add(quota);
        }
        return quotas;
    } catch (NaAPIFailedException e) {
        if (e.getErrno() == NaErrno.EQUOTADOESNOTEXIST) {
            return null;
        }
        throw createError(elem, e);
    } catch (Exception e) {
        throw createError(elem, e);
    }
}
Also used : NaAPIFailedException(netapp.manage.NaAPIFailedException) Quota(com.iwave.ext.netapp.model.Quota) ArrayList(java.util.ArrayList) NaElement(netapp.manage.NaElement) NaAPIFailedException(netapp.manage.NaAPIFailedException)

Example 2 with Quota

use of com.iwave.ext.netapp.model.Quota in project coprhd-controller by CoprHD.

the class QuotaCommands method getQuota.

public Quota getQuota(String volume, String quotaTarget, String quotaType, String qtree) {
    NaElement elem = new NaElement("quota-get-entry");
    elem.addNewChild("volume", volume);
    elem.addNewChild("quota-target", quotaTarget);
    elem.addNewChild("quota-type", quotaType);
    elem.addNewChild("qtree", qtree);
    try {
        NaElement result = server.invokeElem(elem);
        Quota quota = new Quota();
        quota.setVolume(volume);
        quota.setQuotaTarget(quotaTarget);
        quota.setQuotaType(quotaType);
        quota.setQtree(qtree);
        quota.setDiskLimit(result.getChildContent("disk-limit"));
        quota.setFileLimit(result.getChildContent("file-limit"));
        quota.setSoftDiskLimit(result.getChildContent("soft-disk-limit"));
        quota.setSoftFileLimit(result.getChildContent("soft-file-limit"));
        quota.setThreshold(result.getChildContent("threshold"));
        return quota;
    } catch (NaAPIFailedException e) {
        if (e.getErrno() == NaErrno.EQUOTADOESNOTEXIST) {
            return null;
        }
        throw createError(elem, e);
    } catch (Exception e) {
        throw createError(elem, e);
    }
}
Also used : NaAPIFailedException(netapp.manage.NaAPIFailedException) Quota(com.iwave.ext.netapp.model.Quota) NaElement(netapp.manage.NaElement) NaAPIFailedException(netapp.manage.NaAPIFailedException)

Example 3 with Quota

use of com.iwave.ext.netapp.model.Quota in project coprhd-controller by CoprHD.

the class MiscTests method test8.

@Test
public void test8() {
    List<Quota> quotas = netAppFacade.listQuotas();
    for (Quota quota : quotas) {
        System.out.println("Quota:");
        System.out.println("  quotaTarget: " + quota.getQuotaTarget());
        System.out.println("  quotaType: " + quota.getQuotaType());
        System.out.println("  volume: " + quota.getVolume());
        System.out.println("  qtree: " + quota.getQtree());
        System.out.println("  diskUsed: " + quota.getDiskUsed());
        System.out.println("  diskLimit: " + quota.getDiskLimit());
        System.out.println("  softDiskLimit: " + quota.getSoftDiskLimit());
        System.out.println("  threshold: " + quota.getThreshold());
        System.out.println("  filesUsed: " + quota.getFilesUsed());
        System.out.println("  fileLimit: " + quota.getFileLimit());
        System.out.println("  softFileLimit: " + quota.getSoftFileLimit());
        System.out.println("  vfiler: " + quota.getVfiler());
    }
}
Also used : Quota(com.iwave.ext.netapp.model.Quota) Test(org.junit.Test)

Example 4 with Quota

use of com.iwave.ext.netapp.model.Quota in project coprhd-controller by CoprHD.

the class QuotaCommands method quotaReport.

public List<Quota> quotaReport(String path, String volume) {
    NaElement elem = new NaElement("quota-report");
    if (StringUtils.isNotBlank(path)) {
        elem.addNewChild("path", path);
    }
    if (StringUtils.isNotBlank(volume)) {
        elem.addNewChild("volume", volume);
    }
    NaElement resultElem = null;
    try {
        resultElem = server.invokeElem(elem);
    } catch (Exception e) {
        throw createError(elem, e);
    }
    List<Quota> quotas = Lists.newArrayList();
    for (NaElement e : (List<NaElement>) resultElem.getChildren()) {
        if ("error".equalsIgnoreCase(e.getName())) {
            String errno = e.getChildContent("errno");
            String reason = e.getChildContent("reason");
            String message = String.format("%s: %s", errno, reason);
            throw new NetAppException(message);
        } else if ("quotas".equalsIgnoreCase(e.getName())) {
            for (NaElement quotaElem : (List<NaElement>) e.getChildren()) {
                Quota quota = new Quota();
                quota.setQtree(quotaElem.getChildContent("tree"));
                quota.setDiskLimit(quotaElem.getChildContent("disk-limit"));
                quota.setDiskUsed(quotaElem.getChildContent("disk-used"));
                quota.setFileLimit(quotaElem.getChildContent("file-limit"));
                quota.setFilesUsed(quotaElem.getChildContent("files-used"));
                quota.setQuotaTarget(quotaElem.getChildContent("quota-target"));
                quota.setQuotaType(quotaElem.getChildContent("quota-type"));
                quota.setSoftDiskLimit(quotaElem.getChildContent("soft-disk-limit"));
                quota.setSoftFileLimit(quotaElem.getChildContent("soft-file-limit"));
                quota.setThreshold(quotaElem.getChildContent("threshold"));
                quota.setVfiler(quotaElem.getChildContent("vfiler"));
                quota.setVolume(quotaElem.getChildContent("volume"));
                // users
                NaElement quotaUsersElem = (NaElement) quotaElem.getChildByName("quota-users");
                if (quotaUsersElem != null) {
                    for (NaElement quotaUserElem : (List<NaElement>) quotaUsersElem.getChildren()) {
                        QuotaUser quotaUser = new QuotaUser();
                        quotaUser.setUserId(quotaUserElem.getChildContent("quota-user-id"));
                        quotaUser.setUserName(quotaUserElem.getChildContent("quota-user-name"));
                        quotaUser.setUserType(quotaUserElem.getChildContent("quota-user-type"));
                        quota.getQuotaUsers().add(quotaUser);
                    }
                }
                quotas.add(quota);
            }
        }
    }
    return quotas;
}
Also used : Quota(com.iwave.ext.netapp.model.Quota) QuotaUser(com.iwave.ext.netapp.model.QuotaUser) List(java.util.List) ArrayList(java.util.ArrayList) NaElement(netapp.manage.NaElement) NaAPIFailedException(netapp.manage.NaAPIFailedException)

Example 5 with Quota

use of com.iwave.ext.netapp.model.Quota in project coprhd-controller by CoprHD.

the class NetAppClusterModeCommIntf method discoverUmanagedFileQuotaDirectory.

private void discoverUmanagedFileQuotaDirectory(AccessProfile profile) {
    URI storageSystemId = profile.getSystemId();
    StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storageSystemId);
    if (null == storageSystem) {
        return;
    }
    NetAppClusterApi netAppCApi = new NetAppClusterApi.Builder(storageSystem.getIpAddress(), storageSystem.getPortNumber(), storageSystem.getUsername(), storageSystem.getPassword()).https(true).build();
    try {
        // Retrieve all the qtree info.
        List<Qtree> qtrees = netAppCApi.listQtrees();
        List<Quota> quotas;
        try {
            // Currently there are no API's available to check the quota status in general
            // TODO check weather quota is on before doing this call
            quotas = netAppCApi.listQuotas();
        } catch (Exception e) {
            _logger.error("Error while fetching quotas", e.getMessage());
            return;
        }
        if (quotas != null) {
            Map<String, Qtree> qTreeNameQTreeMap = new HashMap<>();
            qtrees.forEach(qtree -> {
                if (qtree.getQtree() != null && !qtree.getQtree().equals("")) {
                    qTreeNameQTreeMap.put(qtree.getVolume() + qtree.getQtree(), qtree);
                }
            });
            List<UnManagedFileQuotaDirectory> unManagedFileQuotaDirectories = new ArrayList<>();
            List<UnManagedFileQuotaDirectory> existingUnManagedFileQuotaDirectories = new ArrayList<>();
            String tempVolume = null;
            String tempQuotaTree = null;
            String tempQuotaTarget = null;
            for (Quota quota : quotas) {
                /* Temporary fix TODO 
                     * Fix for situations where QuotaTree is null
                     * Extracting QuotaTree id from quotaTarget.
                     */
                if ("".equals(quota.getQtree())) {
                    tempQuotaTarget = quota.getQuotaTarget();
                    tempVolume = quota.getVolume();
                    if (!"".equals(tempVolume)) {
                        Pattern pattern = Pattern.compile(tempVolume + "/(.*$)");
                        Matcher matcher = pattern.matcher(tempQuotaTarget);
                        if (matcher.find()) {
                            tempQuotaTree = matcher.group(1);
                        }
                        if ("".equals(tempQuotaTree)) {
                            continue;
                        }
                        quota.setQtree(tempQuotaTree);
                    } else {
                        continue;
                    }
                }
                String fsNativeId;
                if (quota.getVolume().startsWith(VOL_ROOT)) {
                    fsNativeId = quota.getVolume();
                } else {
                    fsNativeId = VOL_ROOT + quota.getVolume();
                }
                if (fsNativeId.contains(ROOT_VOL)) {
                    _logger.info("Ignore and not discover root filesystem on NTP array");
                    continue;
                }
                String fsNativeGUID = NativeGUIDGenerator.generateNativeGuid(storageSystem.getSystemType(), storageSystem.getSerialNumber(), fsNativeId);
                String nativeGUID = NativeGUIDGenerator.generateNativeGuidForQuotaDir(storageSystem.getSystemType(), storageSystem.getSerialNumber(), quota.getQtree(), quota.getVolume());
                String nativeUnmanagedGUID = NativeGUIDGenerator.generateNativeGuidForUnManagedQuotaDir(storageSystem.getSystemType(), storageSystem.getSerialNumber(), quota.getQtree(), quota.getVolume());
                if (checkStorageQuotaDirectoryExistsInDB(nativeGUID)) {
                    continue;
                }
                UnManagedFileQuotaDirectory unManagedFileQuotaDirectory = new UnManagedFileQuotaDirectory();
                unManagedFileQuotaDirectory.setId(URIUtil.createId(UnManagedFileQuotaDirectory.class));
                unManagedFileQuotaDirectory.setLabel(quota.getQtree());
                unManagedFileQuotaDirectory.setNativeGuid(nativeUnmanagedGUID);
                unManagedFileQuotaDirectory.setParentFSNativeGuid(fsNativeGUID);
                unManagedFileQuotaDirectory.setNativeId("/vol/" + quota.getVolume() + "/" + quota.getQtree());
                if ("enabled".equals(qTreeNameQTreeMap.get(quota.getVolume() + quota.getQtree()).getOplocks())) {
                    unManagedFileQuotaDirectory.setOpLock(true);
                }
                unManagedFileQuotaDirectory.setSize(Long.valueOf(quota.getDiskLimit()));
                if (!checkUnManagedQuotaDirectoryExistsInDB(nativeUnmanagedGUID)) {
                    unManagedFileQuotaDirectories.add(unManagedFileQuotaDirectory);
                } else {
                    existingUnManagedFileQuotaDirectories.add(unManagedFileQuotaDirectory);
                }
            }
            if (!unManagedFileQuotaDirectories.isEmpty()) {
                _partitionManager.insertInBatches(unManagedFileQuotaDirectories, Constants.DEFAULT_PARTITION_SIZE, _dbClient, UNMANAGED_FILEQUOTADIR);
            }
            if (!existingUnManagedFileQuotaDirectories.isEmpty()) {
                _partitionManager.updateAndReIndexInBatches(existingUnManagedFileQuotaDirectories, Constants.DEFAULT_PARTITION_SIZE, _dbClient, UNMANAGED_FILEQUOTADIR);
            }
        }
    } catch (NetAppException ve) {
        if (null != storageSystem) {
            cleanupDiscovery(storageSystem);
        }
        _logger.error("discoverStorage failed.  Storage system: " + storageSystemId);
        throw ve;
    } catch (Exception e) {
        if (null != storageSystem) {
            cleanupDiscovery(storageSystem);
        }
        _logger.error("discoverStorage failed. Storage system: " + storageSystemId, e);
        throw NetAppException.exceptions.discoveryFailed(storageSystemId.toString(), e);
    }
}
Also used : Pattern(java.util.regex.Pattern) Qtree(com.iwave.ext.netapp.model.Qtree) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) ImplicitPoolMatcher(com.emc.storageos.volumecontroller.impl.utils.ImplicitPoolMatcher) UnManagedFileQuotaDirectory(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileQuotaDirectory) ArrayList(java.util.ArrayList) URI(java.net.URI) NetAppException(com.emc.storageos.netapp.NetAppException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) NetAppException(com.emc.storageos.netapp.NetAppException) NetAppCException(com.emc.storageos.netappc.NetAppCException) IOException(java.io.IOException) NetAppClusterApi(com.emc.storageos.netappc.NetAppClusterApi) Quota(com.iwave.ext.netapp.model.Quota) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

Quota (com.iwave.ext.netapp.model.Quota)6 ArrayList (java.util.ArrayList)4 NaAPIFailedException (netapp.manage.NaAPIFailedException)3 NaElement (netapp.manage.NaElement)3 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)2 UnManagedFileQuotaDirectory (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileQuotaDirectory)2 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)2 NetAppException (com.emc.storageos.netapp.NetAppException)2 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)2 Qtree (com.iwave.ext.netapp.model.Qtree)2 IOException (java.io.IOException)2 URI (java.net.URI)2 HashMap (java.util.HashMap)2 NetAppApi (com.emc.storageos.netapp.NetAppApi)1 NetAppCException (com.emc.storageos.netappc.NetAppCException)1 NetAppClusterApi (com.emc.storageos.netappc.NetAppClusterApi)1 NetAppFileCollectionException (com.emc.storageos.plugins.metering.netapp.NetAppFileCollectionException)1 ImplicitPoolMatcher (com.emc.storageos.volumecontroller.impl.utils.ImplicitPoolMatcher)1 VFilerInfo (com.iwave.ext.netapp.VFilerInfo)1 QuotaUser (com.iwave.ext.netapp.model.QuotaUser)1