Search in sources :

Example 6 with Quota

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

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