Search in sources :

Example 6 with Qtree

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

the class NetAppApi method deleteAllQTrees.

public Boolean deleteAllQTrees(String volName) throws NetAppException {
    String qtreeName = null;
    try {
        netAppFacade = new NetAppFacade(_ipAddress, _portNumber, _userName, _password, _https);
        List<Qtree> qtrees = netAppFacade.listQtrees(volName);
        if (qtrees != null && !qtrees.isEmpty()) {
            for (Qtree qtree : qtrees) {
                qtreeName = qtree.getQtree();
                // Skip the unnamed Qtree.
                if (qtreeName != null && !qtreeName.isEmpty()) {
                    deleteQtree(qtreeName, volName, _vFilerName);
                }
            }
        }
        return true;
    } catch (Exception e) {
        _logger.error("Deleting the qtree {} of filesystem {} failed ", qtreeName, volName);
        throw NetAppException.exceptions.deleteQtreeFailed(qtreeName, e.getMessage());
    }
}
Also used : Qtree(com.iwave.ext.netapp.model.Qtree) NetAppFacade(com.iwave.ext.netapp.NetAppFacade)

Example 7 with Qtree

use of com.iwave.ext.netapp.model.Qtree 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)

Example 8 with Qtree

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

the class NetAppFileCommunicationInterface method discoverUmanagedFileQuotaDirectory.

private void discoverUmanagedFileQuotaDirectory(AccessProfile profile) {
    URI storageSystemId = profile.getSystemId();
    StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storageSystemId);
    if (null == storageSystem) {
        return;
    }
    NetAppApi netAppApi = new NetAppApi.Builder(storageSystem.getIpAddress(), storageSystem.getPortNumber(), storageSystem.getUsername(), storageSystem.getPassword()).https(true).build();
    try {
        // Retrive vFilers
        List<VFilerInfo> vFilers = netAppApi.listVFilers(null);
        List<Qtree> qtrees;
        List<Quota> quotas;
        NetAppApi vFilerNetAppApi;
        // Retrieve all the qtree info for all vFilers
        for (VFilerInfo tempVFiler : vFilers) {
            try {
                vFilerNetAppApi = new NetAppApi.Builder(storageSystem.getIpAddress(), storageSystem.getPortNumber(), storageSystem.getUsername(), storageSystem.getPassword()).https(true).vFiler(tempVFiler.getName()).build();
                qtrees = vFilerNetAppApi.listQtrees();
                quotas = vFilerNetAppApi.listQuotas();
            } catch (Exception e) {
                _logger.error("Error while fetching quotas for vFiler:: " + tempVFiler.getName(), e.getMessage());
                return;
            }
            if (quotas != null) {
                Map<String, Qtree> qTreeNameQTreeMap = new HashMap<>();
                qtrees.forEach(qtree -> {
                    if (!StringUtils.isEmpty(qtree.getQtree())) {
                        qTreeNameQTreeMap.put(qtree.getVolume() + qtree.getQtree(), qtree);
                    }
                });
                List<UnManagedFileQuotaDirectory> unManagedFileQuotaDirectories = new ArrayList<>();
                List<UnManagedFileQuotaDirectory> existingUnManagedFileQuotaDirectories = new ArrayList<>();
                for (Quota quota : quotas) {
                    if (quota == null) {
                        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());
                    UnManagedFileQuotaDirectory tempUnManagedFileQuotaDirectory = checkUnManagedQuotaDirectoryExistsInDB(nativeUnmanagedGUID);
                    boolean unManagedFileQuotaDirectoryExists = tempUnManagedFileQuotaDirectory == null ? false : true;
                    if (checkStorageQuotaDirectoryExistsInDB(nativeGUID)) {
                        continue;
                    }
                    UnManagedFileQuotaDirectory unManagedFileQuotaDirectory;
                    if (!unManagedFileQuotaDirectoryExists) {
                        unManagedFileQuotaDirectory = new UnManagedFileQuotaDirectory();
                        unManagedFileQuotaDirectory.setId(URIUtil.createId(UnManagedFileQuotaDirectory.class));
                    } else {
                        unManagedFileQuotaDirectory = tempUnManagedFileQuotaDirectory;
                    }
                    unManagedFileQuotaDirectory.setLabel(quota.getQtree());
                    unManagedFileQuotaDirectory.setNativeGuid(nativeUnmanagedGUID);
                    unManagedFileQuotaDirectory.setParentFSNativeGuid(fsNativeGUID);
                    unManagedFileQuotaDirectory.setNativeId("/vol/" + quota.getVolume() + "/" + quota.getQtree());
                    String tempVolume = quota.getVolume();
                    String tempQTreeName = quota.getQtree();
                    Qtree tempQtree = qTreeNameQTreeMap.get(tempVolume + tempQTreeName);
                    if (tempQtree == null) {
                        continue;
                    }
                    _logger.info(" Volume Name::" + tempVolume + " QtreeName::" + tempQTreeName + " Qtree::" + tempQtree.getQtree());
                    if ("enabled".equals(qTreeNameQTreeMap.get(quota.getVolume() + quota.getQtree()).getOplocks())) {
                        unManagedFileQuotaDirectory.setOpLock(true);
                    }
                    // Converting KB to Bytes
                    unManagedFileQuotaDirectory.setSize(Long.valueOf(quota.getDiskLimit()) * BYTESCONVERTER);
                    if (!unManagedFileQuotaDirectoryExists) {
                        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 : Qtree(com.iwave.ext.netapp.model.Qtree) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) 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) NetAppFileCollectionException(com.emc.storageos.plugins.metering.netapp.NetAppFileCollectionException) IOException(java.io.IOException) VFilerInfo(com.iwave.ext.netapp.VFilerInfo) Quota(com.iwave.ext.netapp.model.Quota) NetAppApi(com.emc.storageos.netapp.NetAppApi) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

Qtree (com.iwave.ext.netapp.model.Qtree)8 ArrayList (java.util.ArrayList)3 List (java.util.List)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 Quota (com.iwave.ext.netapp.model.Quota)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 NetAppFacade (com.iwave.ext.netapp.NetAppFacade)1 VFilerInfo (com.iwave.ext.netapp.VFilerInfo)1