Search in sources :

Example 26 with StorageProvider

use of com.emc.storageos.db.client.model.StorageProvider in project coprhd-controller by CoprHD.

the class ScanTaskCompleter method setNextRunTime.

@Override
public final void setNextRunTime(DbClient dbClient, long time) {
    Class type = getType();
    if (StorageProvider.class.isAssignableFrom(type)) {
        try {
            StorageProvider dbObject = (StorageProvider) DataObject.createInstance(type, getId());
            dbObject.trackChanges();
            dbObject.setNextScanTime(time);
            dbClient.persistObject(dbObject);
        } catch (InstantiationException ex) {
            DatabaseException.fatals.queryFailed(ex);
        } catch (IllegalAccessException ex) {
            DatabaseException.fatals.queryFailed(ex);
        }
    } else {
        throw DeviceControllerException.exceptions.invalidSystemType(type.toString());
    }
}
Also used : StorageProvider(com.emc.storageos.db.client.model.StorageProvider)

Example 27 with StorageProvider

use of com.emc.storageos.db.client.model.StorageProvider in project coprhd-controller by CoprHD.

the class SoftwareIdentityProcessor method processResult.

/**
 * {@inheritDoc}
 */
@Override
public void processResult(Operation operation, Object resultObj, Map<String, Object> keyMap) throws BaseCollectionException {
    AccessProfile profile = null;
    try {
        _dbClient = (DbClient) keyMap.get(Constants.dbClient);
        coordinator = (CoordinatorClient) keyMap.get(Constants.COORDINATOR_CLIENT);
        profile = (AccessProfile) keyMap.get(Constants.ACCESSPROFILE);
        @SuppressWarnings("unchecked") final Iterator<CIMInstance> it = (Iterator<CIMInstance>) resultObj;
        if (it.hasNext()) {
            CIMInstance softwareInstance = it.next();
            String providerId = profile.getIpAddress() + "-" + profile.getProviderPort();
            List<StorageProvider> providers = CustomQueryUtility.getActiveStorageProvidersByProviderId(_dbClient, providerId);
            if (!providers.isEmpty()) {
                checkProviderVersion(softwareInstance, providers.get(0));
            }
        } else {
            String errMsg = String.format("No information obtained from Provider %s for Provider version", profile.getIpAddress());
            throw new SMIPluginException(errMsg, SMIPluginException.ERRORCODE_OPERATIONFAILED);
        }
    } catch (SMIPluginException e) {
        throw e;
    } catch (Exception e) {
        String errMsg = String.format("An error occurred while verifying Provider version: %s", e.getMessage());
        throw new SMIPluginException(SMIPluginException.ERRORCODE_OPERATIONFAILED, e, errMsg);
    }
}
Also used : Iterator(java.util.Iterator) SMIPluginException(com.emc.storageos.plugins.metering.smis.SMIPluginException) AccessProfile(com.emc.storageos.plugins.AccessProfile) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) CIMInstance(javax.cim.CIMInstance) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) SMIPluginException(com.emc.storageos.plugins.metering.smis.SMIPluginException)

Example 28 with StorageProvider

use of com.emc.storageos.db.client.model.StorageProvider in project coprhd-controller by CoprHD.

the class BlockMonitoringImpl method stopMonitoringStaleSystem.

/**
 * 1.Find stale SMIS Provider from DB
 * 2. Un-subscribe cimconnection to avoid indications.
 * 3. Remove stale smisprovider URI from local CACHE
 */
@Override
public void stopMonitoringStaleSystem() {
    _logger.debug("Entering {}", Thread.currentThread().getStackTrace()[1].getMethodName());
    Iterator<Map.Entry<String, DistributedQueueItemProcessedCallback>> iter = SMIS_PROVIDERS_CACHE.entrySet().iterator();
    StorageProvider smisprovider = null;
    while (iter.hasNext()) {
        Map.Entry<String, DistributedQueueItemProcessedCallback> entry = iter.next();
        String smisProvoiderURI = entry.getKey();
        _logger.debug("smisProvoiderURI :{}", smisProvoiderURI);
        try {
            smisprovider = _dbClient.queryObject(StorageProvider.class, URI.create(smisProvoiderURI));
        } catch (final DatabaseException e) {
            _logger.error(e.getMessage(), e);
        }
        if (null == smisprovider || smisprovider.getInactive()) {
            _logger.info("Stale SMIS Provider {} has been removed from monitoring", smisProvoiderURI);
            _connectionFactory.unsubscribeSMIProviderConnection(smisProvoiderURI);
            try {
                // Removes monitorinJob token from queue
                entry.getValue().itemProcessed();
            } catch (Exception e) {
                _logger.error("Exception occurred while removing monitoringJob token from ZooKeeper queue", e);
            } finally {
                // Removes from CACHE
                iter.remove();
                ACTIVE_SMIS_PROVIDERS_CACHE.remove(smisProvoiderURI);
            }
        }
    }
    _logger.debug("Exiting {}", Thread.currentThread().getStackTrace()[1].getMethodName());
}
Also used : DistributedQueueItemProcessedCallback(com.emc.storageos.coordinator.client.service.DistributedQueueItemProcessedCallback) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) IOException(java.io.IOException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Example 29 with StorageProvider

use of com.emc.storageos.db.client.model.StorageProvider in project coprhd-controller by CoprHD.

the class CephCommunicationInterface method scan.

@Override
public void scan(AccessProfile accessProfile) throws BaseCollectionException {
    _log.info("Starting scan of Ceph StorageProvider. IP={}", accessProfile.getIpAddress());
    StorageProvider provider = _dbClient.queryObject(StorageProvider.class, accessProfile.getSystemId());
    StorageProvider.ConnectionStatus status = StorageProvider.ConnectionStatus.NOTCONNECTED;
    Map<String, StorageSystemViewObject> storageSystemsCache = accessProfile.getCache();
    String cephType = StorageSystem.Type.ceph.name();
    try (CephClient cephClient = CephUtils.connectToCeph(_cephClientFactory, provider)) {
        ClusterInfo clusterInfo = cephClient.getClusterInfo();
        String systemNativeGUID = NativeGUIDGenerator.generateNativeGuid(cephType, clusterInfo.getFsid());
        StorageSystemViewObject viewObject = storageSystemsCache.get(systemNativeGUID);
        if (viewObject == null) {
            viewObject = new StorageSystemViewObject();
        }
        viewObject.setDeviceType(cephType);
        viewObject.addprovider(accessProfile.getSystemId().toString());
        viewObject.setProperty(StorageSystemViewObject.SERIAL_NUMBER, clusterInfo.getFsid());
        viewObject.setProperty(StorageSystemViewObject.STORAGE_NAME, systemNativeGUID);
        viewObject.setProperty(StorageSystemViewObject.MODEL, "Ceph Storage Cluster");
        // TODO It is possible to figure out more Ceph cluster details (version, alternative IPs, etc),
        // but neither Java client, nor pure librados provide this info. Since Ceph (with clien libraries)
        // is an open source project it is possible to extend its functionality, and then use it here
        storageSystemsCache.put(systemNativeGUID, viewObject);
        status = StorageProvider.ConnectionStatus.CONNECTED;
    } catch (Exception e) {
        _log.error(String.format("Exception was encountered when attempting to scan Ceph Instance %s", accessProfile.getIpAddress()), e);
        throw CephException.exceptions.operationException(e);
    } finally {
        provider.setConnectionStatus(status.name());
        _dbClient.updateObject(provider);
    }
}
Also used : ClusterInfo(com.emc.storageos.ceph.model.ClusterInfo) StorageSystemViewObject(com.emc.storageos.plugins.StorageSystemViewObject) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) CephClient(com.emc.storageos.ceph.CephClient) CephException(com.emc.storageos.ceph.CephException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException)

Example 30 with StorageProvider

use of com.emc.storageos.db.client.model.StorageProvider in project coprhd-controller by CoprHD.

the class DataDomainCommunicationInterface method collectStatisticsInformation.

@Override
public void collectStatisticsInformation(AccessProfile accessProfile) throws BaseCollectionException, DataDomainApiException {
    long statsCount = 0;
    URI storageSystemId = null;
    StorageSystem storageSystem = null;
    try {
        _log.info("Stats collection for {} using ip {}", accessProfile.getSystemId(), accessProfile.getIpAddress());
        storageSystemId = accessProfile.getSystemId();
        storageSystem = _dbClient.queryObject(StorageSystem.class, storageSystemId);
        initializeKeyMap(accessProfile);
        DataDomainClient ddClient = getDataDomainClient(accessProfile);
        URI providerId = storageSystem.getActiveProviderURI();
        StorageProvider provider = _dbClient.queryObject(StorageProvider.class, providerId);
        ZeroRecordGenerator zeroRecordGenerator = new FileZeroRecordGenerator();
        CassandraInsertion statsColumnInjector = new FileDBInsertion();
        DataDomainStatsRecorder recorder = new DataDomainStatsRecorder(zeroRecordGenerator, statsColumnInjector);
        // Stats collection start time
        long statsCollectionStartTime = storageSystem.getLastMeteringRunTime();
        // start time to the time the storage system was successfully discovered.
        if (statsCollectionStartTime == 0) {
            statsCollectionStartTime = storageSystem.getSuccessDiscoveryTime();
        }
        // Stats collection end time
        long statsCollectionEndTime = accessProfile.getCurrentSampleTime();
        _keyMap.put(Constants._TimeCollected, statsCollectionEndTime);
        // Get list of file systems on the device that are in the DB
        List<URI> fsUris = zeroRecordGenerator.extractVolumesOrFileSharesFromDB(storageSystemId, _dbClient, FileShare.class);
        List<FileShare> fsObjs = _dbClient.queryObject(FileShare.class, fsUris, true);
        // Get capacity usage info on individual mtrees
        List<Stat> stats = new ArrayList<>();
        for (FileShare fileSystem : fsObjs) {
            String fsNativeId = fileSystem.getNativeId();
            String fsNativeGuid = fileSystem.getNativeGuid();
            // Retrieve the last 2 data points only
            int entriesRetrieved = 0;
            List<DDStatsCapacityInfo> statsCapInfos = new ArrayList<>();
            // Default
            DDStatsIntervalQuery granularity = DDStatsIntervalQuery.hour;
            // Retrieve hourly data - lowest resolution supported by DD arrays.
            try {
                DDMtreeCapacityInfos mtreeCapInfo = ddClient.getMTreeCapacityInfo(storageSystem.getNativeGuid(), fsNativeId, DataDomainApiConstants.STATS_FIRST_PAGE, DataDomainApiConstants.STATS_PAGE_SIZE, DDStatsDataViewQuery.absolute, DDStatsIntervalQuery.hour, true, DataDomainApiConstants.DESCENDING_SORT);
                entriesRetrieved += mtreeCapInfo.getPagingInfo().getPageEntries();
                // Collect stats
                List<DDStatsCapacityInfo> capacityInfos = mtreeCapInfo.getStatsCapacityInfo();
                if (capacityInfos != null) {
                    statsCapInfos.addAll(capacityInfos);
                }
                statsCount += entriesRetrieved;
            } catch (Exception e) {
                _log.info("Stats collection info not found for fileNativeGuid ", fsNativeGuid);
                continue;
            }
            // Retrieved all pages, now save in DB if info changed in the latest data point
            long usedCapacity = 0;
            if (fileSystem.getUsedCapacity() != null) {
                usedCapacity = fileSystem.getUsedCapacity();
            }
            DDStatsCapacityInfo statsCapInfo = null;
            Stat stat = null;
            if (statsCapInfos != null && !statsCapInfos.isEmpty()) {
                statsCapInfo = statsCapInfos.get(0);
                _keyMap.put(Constants._Granularity, granularity);
                stat = recorder.addUsageInfo(statsCapInfo, _keyMap, fsNativeGuid, ddClient);
            }
            // Persist FileShare capacity stats only if usage info has changed
            long allocatedCapacity = 0;
            if (stat != null) {
                allocatedCapacity = stat.getAllocatedCapacity();
            }
            // TODO: a method to detect changes in stats will be useful
            boolean statsChanged = (usedCapacity != allocatedCapacity) ? true : false;
            if ((stat != null) && (!fileSystem.getInactive()) && (statsChanged)) {
                stats.add(stat);
                fileSystem.setUsedCapacity(allocatedCapacity);
                fileSystem.setCapacity(stat.getProvisionedCapacity());
                _dbClient.persistObject(fileSystem);
            }
        }
        // Determine if a filesystems were deleted from this device and write zero records for deleted ones
        zeroRecordGenerator.identifyRecordstobeZeroed(_keyMap, stats, FileShare.class);
        persistStatsInDB(stats);
        // TODO: Metering task completer will overwrite currTime below with a new
        // time as the last collection time. To avoid this, setLastTime in
        // MeteringTaskCompleter should be modified to set last metering run time
        // only if it
        storageSystem.setLastMeteringRunTime(statsCollectionEndTime);
        _log.info("Done metering device {}, processed {} file system stats ", storageSystemId, statsCount);
        _log.info("End collecting statistics for ip address {}", accessProfile.getIpAddress());
    } catch (Exception e) {
        _log.error("CollectStatisticsInformation failed. Storage system: " + storageSystemId, e);
        throw DataDomainApiException.exceptions.statsCollectionFailed(e.getMessage());
    }
}
Also used : DDStatsCapacityInfo(com.emc.storageos.datadomain.restapi.model.DDStatsCapacityInfo) ArrayList(java.util.ArrayList) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) FileZeroRecordGenerator(com.emc.storageos.volumecontroller.impl.plugins.metering.file.FileZeroRecordGenerator) URI(java.net.URI) DataDomainClient(com.emc.storageos.datadomain.restapi.DataDomainClient) FileShare(com.emc.storageos.db.client.model.FileShare) UnManagedSMBFileShare(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedSMBFileShare) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) 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) DataDomainStatsRecorder(com.emc.storageos.volumecontroller.impl.plugins.metering.datadomain.DataDomainStatsRecorder) Stat(com.emc.storageos.db.client.model.Stat) DDMtreeCapacityInfos(com.emc.storageos.datadomain.restapi.model.DDMtreeCapacityInfos) CassandraInsertion(com.emc.storageos.volumecontroller.impl.plugins.metering.CassandraInsertion) FileZeroRecordGenerator(com.emc.storageos.volumecontroller.impl.plugins.metering.file.FileZeroRecordGenerator) ZeroRecordGenerator(com.emc.storageos.volumecontroller.impl.plugins.metering.ZeroRecordGenerator) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) FileDBInsertion(com.emc.storageos.volumecontroller.impl.plugins.metering.file.FileDBInsertion) DDStatsIntervalQuery(com.emc.storageos.datadomain.restapi.model.DDStatsIntervalQuery)

Aggregations

StorageProvider (com.emc.storageos.db.client.model.StorageProvider)97 URI (java.net.URI)44 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)26 ArrayList (java.util.ArrayList)24 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)23 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)19 Produces (javax.ws.rs.Produces)19 IOException (java.io.IOException)18 StringSet (com.emc.storageos.db.client.model.StringSet)17 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)15 Path (javax.ws.rs.Path)15 Consumes (javax.ws.rs.Consumes)11 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)10 MapStorageProvider (com.emc.storageos.api.mapper.functions.MapStorageProvider)8 StorageSystemViewObject (com.emc.storageos.plugins.StorageSystemViewObject)8 GET (javax.ws.rs.GET)8 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)7 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)7 AsyncTask (com.emc.storageos.volumecontroller.AsyncTask)7 BlockController (com.emc.storageos.volumecontroller.BlockController)7