Search in sources :

Example 11 with UnManagedFileQuotaDirectory

use of com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileQuotaDirectory 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 12 with UnManagedFileQuotaDirectory

use of com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileQuotaDirectory 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

UnManagedFileQuotaDirectory (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileQuotaDirectory)12 URI (java.net.URI)9 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)6 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)5 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)5 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)5 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)4 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)4 HashMap (java.util.HashMap)4 DiscoveredDataObject (com.emc.storageos.db.client.model.DiscoveredDataObject)3 URISyntaxException (java.net.URISyntaxException)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 DataObject (com.emc.storageos.db.client.model.DataObject)2 FileShare (com.emc.storageos.db.client.model.FileShare)2 StringMap (com.emc.storageos.db.client.model.StringMap)2 UnManagedSMBFileShare (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedSMBFileShare)2 IsilonAccessZone (com.emc.storageos.isilon.restapi.IsilonAccessZone)2 IsilonApi (com.emc.storageos.isilon.restapi.IsilonApi)2