Search in sources :

Example 26 with NetAppException

use of com.emc.storageos.netapp.NetAppException 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)

Example 27 with NetAppException

use of com.emc.storageos.netapp.NetAppException in project coprhd-controller by CoprHD.

the class NetAppFileCommunicationInterface method discoverUmanagedFileSystems.

private void discoverUmanagedFileSystems(AccessProfile profile) {
    URI storageSystemId = profile.getSystemId();
    StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storageSystemId);
    if (null == storageSystem) {
        return;
    }
    String detailedStatusMessage = "Discovery of NetApp Unmanaged FileSystem started";
    List<UnManagedFileSystem> unManagedFileSystems = new ArrayList<UnManagedFileSystem>();
    List<UnManagedFileSystem> existingUnManagedFileSystems = new ArrayList<UnManagedFileSystem>();
    int newFileSystemsCount = 0;
    int existingFileSystemsCount = 0;
    Set<URI> allDiscoveredUnManagedFileSystems = new HashSet<URI>();
    NetAppApi netAppApi = new NetAppApi.Builder(storageSystem.getIpAddress(), storageSystem.getPortNumber(), storageSystem.getUsername(), storageSystem.getPassword()).https(true).build();
    Collection<String> attrs = new ArrayList<String>();
    for (String property : ntpPropertiesList) {
        attrs.add(SupportedNtpFileSystemInformation.getFileSystemInformation(property));
    }
    try {
        StoragePort storagePort = getStoragePortPool(storageSystem);
        URIQueryResultList storagePoolURIs = new URIQueryResultList();
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getStorageDeviceStoragePoolConstraint(storageSystem.getId()), storagePoolURIs);
        HashMap<String, StoragePool> pools = new HashMap();
        Iterator<URI> poolsItr = storagePoolURIs.iterator();
        while (poolsItr.hasNext()) {
            URI storagePoolURI = poolsItr.next();
            StoragePool storagePool = _dbClient.queryObject(StoragePool.class, storagePoolURI);
            pools.put(storagePool.getNativeGuid(), storagePool);
        }
        // Retrieve all the file system and vFiler info.
        List<Map<String, String>> fileSystemInfo = netAppApi.listVolumeInfo(null, attrs);
        List<VFilerInfo> vFilers = netAppApi.listVFilers(null);
        for (Map<String, String> fileSystemChar : fileSystemInfo) {
            String poolName = fileSystemChar.get(SupportedNtpFileSystemInformation.getFileSystemInformation(SupportedNtpFileSystemInformation.STORAGE_POOL.toString()));
            String filesystem = fileSystemChar.get(SupportedNtpFileSystemInformation.getFileSystemInformation(SupportedNtpFileSystemInformation.NAME.toString()));
            String poolNativeGuid = NativeGUIDGenerator.generateNativeGuid(storageSystem, poolName, NativeGUIDGenerator.POOL);
            StoragePool pool = pools.get(poolNativeGuid);
            String nativeId;
            if (filesystem.startsWith(VOL_ROOT)) {
                nativeId = filesystem;
            } else {
                nativeId = VOL_ROOT + filesystem;
            }
            String fsNativeGuid = NativeGUIDGenerator.generateNativeGuid(storageSystem.getSystemType(), storageSystem.getSerialNumber(), nativeId);
            // Ignore export for root volume and don't pull it into ViPR db.
            if (nativeId.contains(ROOT_VOL)) {
                _logger.info("Ignore and not discover root filesystem on NTP array");
                continue;
            }
            // to create an UnManaged Filesystems.
            if (checkStorageFileSystemExistsInDB(fsNativeGuid)) {
                continue;
            }
            _logger.debug("retrieve info for file system: " + filesystem);
            String vFiler = getOwningVfiler(filesystem, fileSystemInfo);
            if (vFiler != null && !vFiler.equalsIgnoreCase(DEFAULT_FILER)) {
                _logger.info("Ignoring {} because it is owned by {}", filesystem, vFiler);
                continue;
            }
            String address = getVfilerAddress(vFiler, vFilers);
            if (vFiler != null && !vFiler.isEmpty()) {
                // Need to use storage port for vFiler.
                String portNativeGuid = NativeGUIDGenerator.generateNativeGuid(storageSystem, address, NativeGUIDGenerator.PORT);
                storagePort = getVfilerStoragePort(storageSystem, portNativeGuid, vFiler);
            }
            String fsUnManagedFsNativeGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingFileSystem(storageSystem.getSystemType(), storageSystem.getSerialNumber().toUpperCase(), nativeId);
            UnManagedFileSystem unManagedFs = checkUnManagedFileSystemExistsInDB(fsUnManagedFsNativeGuid);
            boolean alreadyExist = unManagedFs == null ? false : true;
            unManagedFs = createUnManagedFileSystem(unManagedFs, profile, fsUnManagedFsNativeGuid, nativeId, storageSystem, pool, filesystem, storagePort, fileSystemChar);
            if (alreadyExist) {
                existingUnManagedFileSystems.add(unManagedFs);
                existingFileSystemsCount++;
            } else {
                unManagedFileSystems.add(unManagedFs);
                newFileSystemsCount++;
            }
            allDiscoveredUnManagedFileSystems.add(unManagedFs.getId());
            /**
             * Persist 200 objects and clear them to avoid memory issue
             */
            validateListSizeLimitAndPersist(unManagedFileSystems, existingUnManagedFileSystems, Constants.DEFAULT_PARTITION_SIZE * 2);
        }
        // Process those active unmanaged fs objects available in database but not in newly discovered items, to
        // mark them inactive.
        markUnManagedFSObjectsInActive(storageSystem, allDiscoveredUnManagedFileSystems);
        _logger.info("New unmanaged Netapp file systems count: {}", newFileSystemsCount);
        _logger.info("Update unmanaged Netapp file systems count: {}", existingFileSystemsCount);
        if (!unManagedFileSystems.isEmpty()) {
            // Add UnManagedFileSystem
            _partitionManager.insertInBatches(unManagedFileSystems, Constants.DEFAULT_PARTITION_SIZE, _dbClient, UNMANAGED_FILESYSTEM);
        }
        if (!existingUnManagedFileSystems.isEmpty()) {
            // Update UnManagedFilesystem
            _partitionManager.updateAndReIndexInBatches(existingUnManagedFileSystems, Constants.DEFAULT_PARTITION_SIZE, _dbClient, UNMANAGED_FILESYSTEM);
        }
        // discovery succeeds
        detailedStatusMessage = String.format("Discovery completed successfully for NetApp: %s", storageSystemId.toString());
    } 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);
    } finally {
        if (storageSystem != null) {
            try {
                // set detailed message
                storageSystem.setLastDiscoveryStatusMessage(detailedStatusMessage);
                _dbClient.persistObject(storageSystem);
            } catch (Exception ex) {
                _logger.error("Error while persisting object to DB", ex);
            }
        }
    }
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) NetAppException(com.emc.storageos.netapp.NetAppException) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) NetAppApi(com.emc.storageos.netapp.NetAppApi) UnManagedFileSystem(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileSystem) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) HashSet(java.util.HashSet) StoragePort(com.emc.storageos.db.client.model.StoragePort) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) 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) UnManagedFSExportMap(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFSExportMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) UnManagedSMBShareMap(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedSMBShareMap) StringMap(com.emc.storageos.db.client.model.StringMap)

Aggregations

NetAppException (com.emc.storageos.netapp.NetAppException)27 NetAppApi (com.emc.storageos.netapp.NetAppApi)23 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)16 BiosCommandResult (com.emc.storageos.volumecontroller.impl.BiosCommandResult)16 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)12 ControllerException (com.emc.storageos.volumecontroller.ControllerException)12 URI (java.net.URI)11 ArrayList (java.util.ArrayList)10 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)9 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)9 IOException (java.io.IOException)9 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)8 NetAppFileCollectionException (com.emc.storageos.plugins.metering.netapp.NetAppFileCollectionException)8 HashMap (java.util.HashMap)8 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)7 FileShare (com.emc.storageos.db.client.model.FileShare)6 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)6 VFilerInfo (com.iwave.ext.netapp.VFilerInfo)6 StoragePort (com.emc.storageos.db.client.model.StoragePort)5 StringMap (com.emc.storageos.db.client.model.StringMap)5