Search in sources :

Example 1 with DataDomainApiException

use of com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException in project coprhd-controller by CoprHD.

the class DataDomainFileStorageDevice method doUnexport.

@Override
public BiosCommandResult doUnexport(StorageSystem storage, FileDeviceInputOutput args, List<FileExport> exportList) throws ControllerException {
    try {
        _log.info("DataDomainFileStorageDevice doUnexport {} - start", args.getFsId());
        DataDomainClient ddClient = getDataDomainClient(storage);
        if (ddClient == null) {
            _log.error("doUnexport failed, provider unreachable");
            String op = "FS unexport";
            return BiosCommandResult.createErrorResult(DeviceControllerErrors.datadomain.operationFailedProviderInaccessible(op));
        }
        URI storagePoolId = args.getFs().getPool();
        StoragePool storagePool = _dbClient.queryObject(StoragePool.class, storagePoolId);
        FSExportMap currentExports = args.getFsExports();
        ddDeleteExports(ddClient, storagePool.getNativeId(), currentExports, exportList);
        _log.info("DataDomainFileStorageDevice doUnexport {} - complete", args.getFsId());
        return BiosCommandResult.createSuccessfulResult();
    } catch (DataDomainApiException e) {
        _log.error("doUnexport failed, device error.", e);
        return BiosCommandResult.createErrorResult(e);
    }
}
Also used : DataDomainApiException(com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException) StoragePool(com.emc.storageos.db.client.model.StoragePool) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) DataDomainClient(com.emc.storageos.datadomain.restapi.DataDomainClient) URI(java.net.URI)

Example 2 with DataDomainApiException

use of com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException in project coprhd-controller by CoprHD.

the class DataDomainFileStorageDevice method doExpandFS.

@Override
public BiosCommandResult doExpandFS(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    try {
        _log.info("DataDomainFileStorageDevice doExpandFS {} - start", args.getFsId());
        DataDomainClient ddClient = getDataDomainClient(storage);
        if (ddClient == null) {
            _log.error("doExpandFS failed, provider unreachable");
            String op = "FS expand";
            return BiosCommandResult.createErrorResult(DeviceControllerErrors.datadomain.operationFailedProviderInaccessible(op));
        }
        Long newSize = args.getNewFSCapacity();
        Long currSize;
        if ((args.getFsCapacity() != null) && (args.getFsCapacity() > 0)) {
            currSize = args.getFsCapacity();
        } else {
            ServiceError serviceError = DeviceControllerErrors.datadomain.doFailedToGetCurrSize();
            return BiosCommandResult.createErrorResult(serviceError);
        }
        if (currSize >= newSize) {
            ServiceError serviceError = DeviceControllerErrors.datadomain.doShrinkFSFailed(currSize, newSize);
            return BiosCommandResult.createErrorResult(serviceError);
        }
        // Modify mtree
        // Data Domain expects capacity in Bytes
        DDMTreeInfo ddMtreeInfo = ddClient.expandMTree(args.getStoragePool().getNativeId(), args.getFs().getNativeId(), newSize);
        if (args.getFsExtensions() == null) {
            args.initFsExtensions();
        }
        args.getFsExtensions().put(DataDomainApiConstants.TOTAL_PHYSICAL_CAPACITY, String.valueOf(newSize));
        _log.info("DataDomainFileStorageDevice doExpandFS {} - complete", args.getFsId());
        return BiosCommandResult.createSuccessfulResult();
    } catch (DataDomainApiException e) {
        _log.error("doExpandFS failed, device error.", e);
        return BiosCommandResult.createErrorResult(e);
    } catch (Exception e) {
        _log.error("doExpandFS failed.", e);
        ServiceError serviceError = DeviceControllerErrors.datadomain.doExpandFSFailed(e.getMessage());
        return BiosCommandResult.createErrorResult(serviceError);
    }
}
Also used : DataDomainApiException(com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) DDMTreeInfo(com.emc.storageos.datadomain.restapi.model.DDMTreeInfo) DataDomainClient(com.emc.storageos.datadomain.restapi.DataDomainClient) DataDomainResourceNotFoundException(com.emc.storageos.datadomain.restapi.errorhandling.DataDomainResourceNotFoundException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) DataDomainApiException(com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException)

Example 3 with DataDomainApiException

use of com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException in project coprhd-controller by CoprHD.

the class DataDomainFileStorageDevice method doDeleteShare.

@Override
public BiosCommandResult doDeleteShare(StorageSystem storage, FileDeviceInputOutput args, SMBFileShare smbFileShare) throws ControllerException {
    try {
        _log.info("DataDomainFileStorageDevice doDeleteShare: {} - start");
        DataDomainClient ddClient = getDataDomainClient(storage);
        if (ddClient == null) {
            _log.error("doDeleteShare failed, provider unreachable");
            String op = "FS share delete";
            return BiosCommandResult.createErrorResult(DeviceControllerErrors.datadomain.operationFailedProviderInaccessible(op));
        }
        URI storagePoolId = args.getFs().getPool();
        StoragePool storagePool = _dbClient.queryObject(StoragePool.class, storagePoolId);
        SMBShareMap currentShares = args.getFileObjShares();
        List<SMBFileShare> sharesToDelete = new ArrayList<SMBFileShare>();
        sharesToDelete.add(smbFileShare);
        ddDeleteShares(ddClient, storagePool.getNativeId(), currentShares, sharesToDelete);
        _log.info("DataDomainFileStorageDevice doDeleteShare {} - complete");
        return BiosCommandResult.createSuccessfulResult();
    } catch (DataDomainApiException e) {
        _log.error("doDeleteShare failed, device error.", e);
        return BiosCommandResult.createErrorResult(e);
    }
}
Also used : DataDomainApiException(com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException) StoragePool(com.emc.storageos.db.client.model.StoragePool) SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) ArrayList(java.util.ArrayList) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) DataDomainClient(com.emc.storageos.datadomain.restapi.DataDomainClient) URI(java.net.URI)

Example 4 with DataDomainApiException

use of com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException 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)

Example 5 with DataDomainApiException

use of com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException in project coprhd-controller by CoprHD.

the class DataDomainCommunicationInterface method discoverUnManagedNewExports.

private void discoverUnManagedNewExports(DataDomainClient ddClient, StorageSystem storageSystem) throws DataDomainApiException {
    storageSystem.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.IN_PROGRESS.toString());
    String detailedStatusMessage = "Discovery of Data Domain Unmanaged Exports started";
    storageSystem.setLastDiscoveryStatusMessage(detailedStatusMessage);
    // Used to cache UMFS once retrieved from DB
    Map<String, UnManagedFileSystem> existingUnManagedFileSystems = new HashMap<String, UnManagedFileSystem>();
    // Used to Save the rules to DB
    List<UnManagedFileExportRule> newUnManagedExportRules = new ArrayList<UnManagedFileExportRule>();
    try {
        // Get exports on the array and loop through each export.
        DDExportList exportList = ddClient.getExports(storageSystem.getNativeGuid());
        // Verification Utility
        UnManagedExportVerificationUtility validationUtility = new UnManagedExportVerificationUtility(_dbClient);
        for (DDExportInfo exp : exportList.getExports()) {
            DDExportInfoDetail export = ddClient.getExport(storageSystem.getNativeGuid(), exp.getId());
            if (export.getPathStatus() != DataDomainApiConstants.PATH_EXISTS) {
                continue;
            }
            String fsUnManagedFsNativeGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingFileSystem(storageSystem.getSystemType(), storageSystem.getSerialNumber().toUpperCase(), export.getMtreeID());
            // Get UMFS from cache if possible, otherwise try to retrieve from DB
            UnManagedFileSystem unManagedFS = existingUnManagedFileSystems.get(fsUnManagedFsNativeGuid);
            if (unManagedFS == null) {
                unManagedFS = getUnManagedFileSystemFromDB(fsUnManagedFsNativeGuid);
            }
            // Used for rules validation
            List<UnManagedFileExportRule> unManagedExportRules = new ArrayList<UnManagedFileExportRule>();
            if (unManagedFS != null) {
                // Add UMFS to cache
                existingUnManagedFileSystems.put(fsUnManagedFsNativeGuid, unManagedFS);
                // Build ViPR export rules from the export retrieved from the array
                List<UnManagedFileExportRule> exportRules = applyAllSecurityRules(export, unManagedFS.getId());
                _log.info("Number of exports discovered for file system {} is {}", unManagedFS.getId(), exportRules.size());
                for (UnManagedFileExportRule dbExportRule : exportRules) {
                    _log.info("Un Managed File Export Rule : {}", dbExportRule);
                    String fsExportRulenativeId = dbExportRule.getFsExportIndex();
                    _log.info("Native Id using to build Native Guid {}", fsExportRulenativeId);
                    String fsUnManagedFileExportRuleNativeGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingFileExportRule(storageSystem, fsExportRulenativeId);
                    _log.info("Native GUID {}", fsUnManagedFileExportRuleNativeGuid);
                    dbExportRule.setNativeGuid(fsUnManagedFileExportRuleNativeGuid);
                    dbExportRule.setId(URIUtil.createId(UnManagedFileExportRule.class));
                    // Build all export rules list.
                    unManagedExportRules.add(dbExportRule);
                }
                // apply as per API SVC Validations.
                if (!unManagedExportRules.isEmpty()) {
                    boolean isAllRulesValid = validationUtility.validateUnManagedExportRules(unManagedExportRules, false);
                    if (isAllRulesValid) {
                        _log.info("Validating rules success for export {}", export.getPath());
                        for (UnManagedFileExportRule exportRule : unManagedExportRules) {
                            UnManagedFileExportRule existingRule = checkUnManagedFsExportRuleExistsInDB(_dbClient, exportRule.getNativeGuid());
                            if (existingRule == null) {
                                newUnManagedExportRules.add(exportRule);
                            } else {
                                // Remove the existing rule.
                                existingRule.setInactive(true);
                                _dbClient.persistObject(existingRule);
                                newUnManagedExportRules.add(exportRule);
                            }
                        }
                        unManagedFS.setHasExports(true);
                        unManagedFS.putFileSystemCharacterstics(UnManagedFileSystem.SupportedFileSystemCharacterstics.IS_FILESYSTEM_EXPORTED.toString(), TRUE);
                        _dbClient.persistObject(unManagedFS);
                        _log.info("File System {} has Exports and their size is {}", unManagedFS.getId(), newUnManagedExportRules.size());
                    } else {
                        _log.warn("Validating rules failed for export {}. Ignroing to import these rules into ViPR DB", export.getPath());
                        // Don't consider the file system with invalid exports!!!
                        unManagedFS.setInactive(true);
                    }
                }
                // Adding this additional logic to avoid OOM
                if (newUnManagedExportRules.size() == MAX_UMFS_RECORD_SIZE) {
                    _log.info("Saving Number of UnManagedFileExportRule(s) {}", newUnManagedExportRules.size());
                    _dbClient.persistObject(newUnManagedExportRules);
                    newUnManagedExportRules.clear();
                }
            } else {
                _log.info("FileSystem " + fsUnManagedFsNativeGuid + " is not present in ViPR DB. Hence ignoring " + export + " export");
            }
        }
        if (!newUnManagedExportRules.isEmpty()) {
            // Update UnManagedFilesystem
            _dbClient.persistObject(newUnManagedExportRules);
            _log.info("Saving Number of UnManagedFileExportRule(s) {}", newUnManagedExportRules.size());
        }
        if (!existingUnManagedFileSystems.isEmpty()) {
            // Update UnManagedFilesystem
            _dbClient.persistObject(existingUnManagedFileSystems.values());
            _log.info("{} {} Records updated to DB", existingUnManagedFileSystems.size(), UNMANAGED_FILESYSTEM);
        }
        storageSystem.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.COMPLETE.toString());
        // discovery succeeded
        detailedStatusMessage = String.format("Discovery completed successfully for Data Domain: %s", storageSystem.getId().toString());
        storageSystem.setLastDiscoveryStatusMessage(detailedStatusMessage);
    } catch (DataDomainApiException dde) {
        _log.error("discoverStorage failed.  Storage system: " + storageSystem.getId());
    } catch (Exception e) {
        _log.error("discoverStorage failed. Storage system: " + storageSystem.getId(), e);
    } finally {
        if (storageSystem != null) {
            try {
                _dbClient.persistObject(storageSystem);
            } catch (Exception ex) {
                _log.error("Error while persisting object to DB", ex);
            }
        }
    }
}
Also used : UnManagedExportVerificationUtility(com.emc.storageos.volumecontroller.impl.utils.UnManagedExportVerificationUtility) DDExportInfoDetail(com.emc.storageos.datadomain.restapi.model.DDExportInfoDetail) UnManagedFileExportRule(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileExportRule) HashMap(java.util.HashMap) DDExportList(com.emc.storageos.datadomain.restapi.model.DDExportList) ArrayList(java.util.ArrayList) 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) DDExportInfo(com.emc.storageos.datadomain.restapi.model.DDExportInfo) UnManagedFileSystem(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileSystem)

Aggregations

DataDomainApiException (com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException)20 DataDomainClient (com.emc.storageos.datadomain.restapi.DataDomainClient)13 DataDomainResourceNotFoundException (com.emc.storageos.datadomain.restapi.errorhandling.DataDomainResourceNotFoundException)10 URI (java.net.URI)10 ArrayList (java.util.ArrayList)9 StoragePool (com.emc.storageos.db.client.model.StoragePool)8 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)5 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)5 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)5 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)5 IOException (java.io.IOException)5 SMBShareMap (com.emc.storageos.db.client.model.SMBShareMap)4 UnManagedFileSystem (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileSystem)4 DDMTreeInfo (com.emc.storageos.datadomain.restapi.model.DDMTreeInfo)3 FSExportMap (com.emc.storageos.db.client.model.FSExportMap)3 FileExport (com.emc.storageos.db.client.model.FileExport)3 FileShare (com.emc.storageos.db.client.model.FileShare)3 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)3 HashMap (java.util.HashMap)3 DDExportInfo (com.emc.storageos.datadomain.restapi.model.DDExportInfo)2