Search in sources :

Example 1 with DDMTreeList

use of com.emc.storageos.datadomain.restapi.model.DDMTreeList in project coprhd-controller by CoprHD.

the class DataDomainCommunicationInterface method discoverUnManagedFileSystems.

private void discoverUnManagedFileSystems(DataDomainClient ddClient, StorageSystem storageSystem) throws DataDomainApiException {
    String detailedStatusMessage = "Discovery of DataDomain Unmanaged FileSystem started";
    List<UnManagedFileSystem> newUnManagedFileSystems = new ArrayList<UnManagedFileSystem>();
    List<UnManagedFileSystem> existingUnManagedFileSystems = new ArrayList<UnManagedFileSystem>();
    Set<URI> allDiscoveredUnManagedFileSystems = new HashSet<URI>();
    StoragePool pool = getPoolFromDB(storageSystem);
    StringSet matchedVPools = DiscoveryUtils.getMatchedVirtualPoolsForPool(_dbClient, pool.getId());
    DDMTreeInfoDetail mtree = null;
    try {
        DDMTreeList mtreeList = ddClient.getMTreeList(storageSystem.getNativeGuid());
        for (DDMTreeInfo mtreeInfo : mtreeList.mtree) {
            mtree = ddClient.getMTree(storageSystem.getNativeGuid(), mtreeInfo.getId());
            if (mtree == null || mtree.delStatus == DataDomainApiConstants.FILE_DELETED) {
                continue;
            }
            // Filtering mtrees that are not supporting either of NFS & CIFS
            if ((mtree.protocolName == null) || (mtree.protocolName.isEmpty())) {
                _log.info("Mtree: {} doesn't contain any protocol defined so ignoring it", mtree.name);
                continue;
            } else {
                if ((mtree.protocolName.contains(DataDomainApiConstants.NFS_PROTOCOL)) || (mtree.protocolName.contains(DataDomainApiConstants.CIFS_PROTOCOL))) {
                    _log.info("Mtree: {} contains supported protocol:{} so discovering it", mtree.name, mtree.protocolName.toArray());
                } else {
                    _log.info("Mtree: {} contains unsupported protocol:{} so ignoring it", mtree.name, mtree.protocolName.toArray());
                    continue;
                }
            }
            String fsNativeGuid = NativeGUIDGenerator.generateNativeGuid(storageSystem.getSystemType(), storageSystem.getSerialNumber().toUpperCase(), mtreeInfo.getId());
            // If the filesystem already exists in db..just continue.
            // No Need to create an UnManaged Filesystems.
            URIQueryResultList result = new URIQueryResultList();
            _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getFileSystemNativeGUIdConstraint(fsNativeGuid), result);
            if (result.iterator().hasNext()) {
                continue;
            }
            String fsUnManagedFsNativeGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingFileSystem(storageSystem.getSystemType(), storageSystem.getSerialNumber().toUpperCase(), mtreeInfo.getId());
            UnManagedFileSystem unManagedFS = getUnManagedFileSystemFromDB(fsUnManagedFsNativeGuid);
            boolean alreadyExist = unManagedFS == null ? false : true;
            unManagedFS = createUnManagedFileSystem(unManagedFS, fsUnManagedFsNativeGuid, mtree, storageSystem, pool, matchedVPools);
            if (alreadyExist) {
                existingUnManagedFileSystems.add(unManagedFS);
            } else {
                newUnManagedFileSystems.add(unManagedFS);
            }
            allDiscoveredUnManagedFileSystems.add(unManagedFS.getId());
        }
        // Process those active unmanaged fs objects available in database but not in newly discovered items, to mark them inactive.
        markUnManagedFSObjectsInActive(storageSystem, allDiscoveredUnManagedFileSystems);
        if (newUnManagedFileSystems != null && !newUnManagedFileSystems.isEmpty()) {
            // Add UnManagedFileSystem
            _dbClient.createObject(newUnManagedFileSystems);
            _log.info("{} {} Records inserted to DB", newUnManagedFileSystems.size(), UNMANAGED_FILESYSTEM);
        }
        if (existingUnManagedFileSystems != null && !existingUnManagedFileSystems.isEmpty()) {
            _dbClient.updateAndReindexObject(existingUnManagedFileSystems);
            _log.info("{} {} Records updated to DB", existingUnManagedFileSystems.size(), UNMANAGED_FILESYSTEM);
        }
        storageSystem.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.COMPLETE.toString());
        // discovery succeeds
        detailedStatusMessage = String.format("Discovery completed successfully for DataDomain system: %s", storageSystem.getId().toString());
    } catch (DataDomainApiException dde) {
        detailedStatusMessage = "DiscoverStorage failed" + dde.getMessage();
        _log.error("discoverStorage failed.  Storage system: " + storageSystem.getId().toString());
        throw dde;
    } catch (Exception e) {
        detailedStatusMessage = "DiscoverStorage failed" + e.getMessage();
        _log.error("discoverStorage failed. Storage system: " + storageSystem.getId().toString(), e);
        throw DataDomainApiException.exceptions.failedDataDomainDiscover(storageSystem.getNativeGuid(), e);
    } finally {
        if (storageSystem != null) {
            try {
                // set detailed message
                storageSystem.setLastDiscoveryStatusMessage(detailedStatusMessage);
                _dbClient.persistObject(storageSystem);
            } catch (Exception ex) {
                _log.error("Error while persisting object to DB", ex);
            }
        }
    }
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) DDMTreeList(com.emc.storageos.datadomain.restapi.model.DDMTreeList) ArrayList(java.util.ArrayList) DDMTreeInfoDetail(com.emc.storageos.datadomain.restapi.model.DDMTreeInfoDetail) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DataDomainApiException(com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) DataDomainResourceNotFoundException(com.emc.storageos.datadomain.restapi.errorhandling.DataDomainResourceNotFoundException) IOException(java.io.IOException) DataDomainApiException(com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException) DDMTreeInfo(com.emc.storageos.datadomain.restapi.model.DDMTreeInfo) StringSet(com.emc.storageos.db.client.model.StringSet) UnManagedFileSystem(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileSystem) HashSet(java.util.HashSet)

Example 2 with DDMTreeList

use of com.emc.storageos.datadomain.restapi.model.DDMTreeList in project coprhd-controller by CoprHD.

the class DataDomainCommunicationInterface method discoverPool.

private void discoverPool(DataDomainClient ddClient, StorageSystem storageSystem) {
    boolean newPool = false;
    boolean match = false;
    StoragePool storagePool = getPoolFromDB(storageSystem);
    if (storagePool == null) {
        // New storage pool
        storagePool = new StoragePool();
        storagePool.setId(URIUtil.createId(StoragePool.class));
        String nativeGid = NativeGUIDGenerator.generateNativeGuid(storageSystem, storageSystem.getNativeGuid(), NativeGUIDGenerator.POOL);
        storagePool.setNativeGuid(nativeGid);
        storagePool.setLabel(storageSystem.getLabel());
        storagePool.setPoolName(storageSystem.getLabel());
        storagePool.setPoolClassName(POOL_TYPE);
        storagePool.setPoolServiceType(StoragePool.PoolServiceType.file.toString());
        storagePool.setStorageDevice(storageSystem.getId());
        StringSet protocols = new StringSet();
        protocols.add(StorageProtocol.File.NFS.name());
        protocols.add(StorageProtocol.File.CIFS.name());
        storagePool.setProtocols(protocols);
        storagePool.setLongTermRetention(true);
        storagePool.setSupportedResourceTypes(StoragePool.SupportedResourceTypes.THIN_ONLY.toString());
        storagePool.setRegistrationStatus(DiscoveredDataObject.RegistrationStatus.REGISTERED.toString());
        newPool = true;
        _log.info("Creating new storage pool for system : {} ", storageSystem.getNativeGuid());
    }
    storagePool.setOperationalStatus(StoragePool.PoolOperationalStatus.READY.toString());
    storagePool.setDiscoveryStatus(DiscoveryStatus.VISIBLE.name());
    DDSystem ddSystem = ddClient.getDDSystem(storageSystem.getNativeGuid());
    storagePool.setNativeId(ddSystem.id);
    storagePool.setTotalCapacity(ddSystem.logicalCapacity.getTotal() >> DataDomainApiConstants.B_TO_KB_SHIFT);
    storagePool.setFreeCapacity(ddSystem.logicalCapacity.getAvailable() >> DataDomainApiConstants.B_TO_KB_SHIFT);
    storagePool.setSubscribedCapacity(ddSystem.logicalCapacity.getUsed() >> DataDomainApiConstants.B_TO_KB_SHIFT);
    StringMap capacityProp = storagePool.getCustomProperties();
    capacityProp.put(DataDomainApiConstants.TOTAL_PHYSICAL_CAPACITY, Long.valueOf(ddSystem.physicalCapacity.getTotal() >> DataDomainApiConstants.B_TO_KB_SHIFT).toString());
    capacityProp.put(DataDomainApiConstants.AVAILABLE_PHYSICAL_CAPACITY, Long.valueOf(ddSystem.physicalCapacity.getAvailable() >> DataDomainApiConstants.B_TO_KB_SHIFT).toString());
    capacityProp.put(DataDomainApiConstants.USED_PHYSICAL_CAPACITY, Long.valueOf(ddSystem.physicalCapacity.getUsed() >> DataDomainApiConstants.B_TO_KB_SHIFT).toString());
    capacityProp.put(DataDomainApiConstants.SYSTEM_QUOTA, Long.valueOf(ddSystem.subscribedCapacity >> DataDomainApiConstants.B_TO_KB_SHIFT).toString());
    capacityProp.put(DataDomainApiConstants.COMPRESSION_FACTOR, Double.valueOf(ddSystem.compressionFactor).toString());
    DDMTreeList list = ddClient.getMTreeList(storageSystem.getNativeGuid());
    capacityProp.put(DataDomainApiConstants.NUMBER_MTREES, Long.valueOf(list.mtree.size()).toString());
    // Temporarily fix until DD fixes logical capacity computation
    if (ddSystem.compressionFactor < 0.5) {
        capacityProp.put(DataDomainApiConstants.COMPRESSION_FACTOR, "1.0");
        storagePool.setTotalCapacity(Long.valueOf(capacityProp.get(DataDomainApiConstants.TOTAL_PHYSICAL_CAPACITY)));
        storagePool.setFreeCapacity(Long.valueOf(capacityProp.get(DataDomainApiConstants.AVAILABLE_PHYSICAL_CAPACITY)));
        storagePool.setSubscribedCapacity(Long.valueOf(capacityProp.get(DataDomainApiConstants.USED_PHYSICAL_CAPACITY)));
    }
    if ((DiscoveredDataObject.DataCollectionJobStatus.ERROR.name().equals(storageSystem.getDiscoveryStatus())) || (DiscoveredDataObject.CompatibilityStatus.INCOMPATIBLE.name().equals(storageSystem.getCompatibilityStatus()))) {
        storagePool.setDiscoveryStatus(DiscoveryStatus.NOTVISIBLE.name());
        storagePool.setCompatibilityStatus(DiscoveredDataObject.CompatibilityStatus.INCOMPATIBLE.name());
    } else {
        storagePool.setDiscoveryStatus(DiscoveryStatus.VISIBLE.name());
        storagePool.setCompatibilityStatus(DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.name());
    }
    if (ImplicitPoolMatcher.checkPoolPropertiesChanged(storagePool.getCompatibilityStatus(), DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.name())) {
        match = true;
    }
    if (newPool) {
        _dbClient.createObject(storagePool);
    } else {
        _dbClient.persistObject(storagePool);
    }
    if (match) {
        StringBuffer errorMessage = new StringBuffer();
        ImplicitPoolMatcher.matchModifiedStoragePoolsWithAllVpool(Arrays.asList(storagePool), _dbClient, _coordinator, storageSystem.getId(), errorMessage);
    }
    _log.info("discoverPools for storage system {} - complete", storageSystem.getId());
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) StoragePool(com.emc.storageos.db.client.model.StoragePool) DDMTreeList(com.emc.storageos.datadomain.restapi.model.DDMTreeList) DDSystem(com.emc.storageos.datadomain.restapi.model.DDSystem) StringSet(com.emc.storageos.db.client.model.StringSet)

Aggregations

DDMTreeList (com.emc.storageos.datadomain.restapi.model.DDMTreeList)2 StoragePool (com.emc.storageos.db.client.model.StoragePool)2 StringSet (com.emc.storageos.db.client.model.StringSet)2 DataDomainApiException (com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException)1 DataDomainResourceNotFoundException (com.emc.storageos.datadomain.restapi.errorhandling.DataDomainResourceNotFoundException)1 DDMTreeInfo (com.emc.storageos.datadomain.restapi.model.DDMTreeInfo)1 DDMTreeInfoDetail (com.emc.storageos.datadomain.restapi.model.DDMTreeInfoDetail)1 DDSystem (com.emc.storageos.datadomain.restapi.model.DDSystem)1 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 StringMap (com.emc.storageos.db.client.model.StringMap)1 UnManagedFileSystem (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileSystem)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)1 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)1 IOException (java.io.IOException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1