Search in sources :

Example 6 with ScaleIORestClient

use of com.emc.storageos.scaleio.api.restapi.ScaleIORestClient in project coprhd-controller by CoprHD.

the class ScaleIOSnapshotOperations method createGroupSnapshots.

@Override
public void createGroupSnapshots(StorageSystem storage, List<URI> snapshotList, Boolean createInactive, Boolean readOnly, TaskCompleter taskCompleter) throws DeviceControllerException {
    try {
        ScaleIORestClient scaleIOHandle = scaleIOHandleFactory.using(dbClient).getClientHandle(storage);
        List<BlockSnapshot> blockSnapshots = dbClient.queryObject(BlockSnapshot.class, snapshotList);
        Map<String, String> parent2snap = new HashMap<>();
        Set<URI> poolsToUpdate = new HashSet<>();
        for (BlockSnapshot blockSnapshot : blockSnapshots) {
            Volume parent = dbClient.queryObject(Volume.class, blockSnapshot.getParent().getURI());
            parent2snap.put(parent.getNativeId(), blockSnapshot.getLabel());
            poolsToUpdate.add(parent.getPool());
        }
        String systemId = scaleIOHandle.getSystemId();
        ScaleIOSnapshotVolumeResponse result = scaleIOHandle.snapshotMultiVolume(parent2snap, systemId);
        List<String> nativeIds = result.getVolumeIdList();
        Map<String, String> snapNameIdMap = scaleIOHandle.getVolumes(nativeIds);
        ScaleIOHelper.updateSnapshotsWithSnapshotMultiVolumeResult(dbClient, blockSnapshots, systemId, snapNameIdMap, result.getSnapshotGroupId(), storage);
        dbClient.persistObject(blockSnapshots);
        List<StoragePool> pools = dbClient.queryObject(StoragePool.class, Lists.newArrayList(poolsToUpdate));
        for (StoragePool pool : pools) {
            ScaleIOHelper.updateStoragePoolCapacity(dbClient, scaleIOHandle, pool, storage);
        }
        taskCompleter.ready(dbClient);
    } catch (Exception e) {
        log.error("Encountered an exception", e);
        ServiceCoded code = DeviceControllerErrors.scaleio.encounteredAnExceptionFromScaleIOOperation("createGroupVolumeSnapshot", e.getMessage());
        taskCompleter.error(dbClient, code);
    }
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) HashMap(java.util.HashMap) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) URI(java.net.URI) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) Volume(com.emc.storageos.db.client.model.Volume) ScaleIOSnapshotVolumeResponse(com.emc.storageos.scaleio.api.restapi.response.ScaleIOSnapshotVolumeResponse) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) ScaleIORestClient(com.emc.storageos.scaleio.api.restapi.ScaleIORestClient) HashSet(java.util.HashSet)

Example 7 with ScaleIORestClient

use of com.emc.storageos.scaleio.api.restapi.ScaleIORestClient in project coprhd-controller by CoprHD.

the class ScaleIOSnapshotOperations method deleteGroupSnapshots.

@Override
public void deleteGroupSnapshots(StorageSystem storage, URI snapshot, TaskCompleter taskCompleter) throws DeviceControllerException {
    try {
        ScaleIORestClient scaleIOHandle = scaleIOHandleFactory.using(dbClient).getClientHandle(storage);
        BlockSnapshot blockSnapshot = dbClient.queryObject(BlockSnapshot.class, snapshot);
        Set<URI> poolsToUpdate = new HashSet<>();
        scaleIOHandle.removeConsistencyGroupSnapshot(blockSnapshot.getSnapsetLabel());
        List<BlockSnapshot> groupSnapshots = ControllerUtils.getSnapshotsPartOfReplicationGroup(blockSnapshot, dbClient);
        for (BlockSnapshot groupSnapshot : groupSnapshots) {
            Volume parent = dbClient.queryObject(Volume.class, groupSnapshot.getParent().getURI());
            poolsToUpdate.add(parent.getPool());
            groupSnapshot.setInactive(true);
        }
        dbClient.updateObject(groupSnapshots);
        List<StoragePool> pools = dbClient.queryObject(StoragePool.class, Lists.newArrayList(poolsToUpdate));
        for (StoragePool pool : pools) {
            ScaleIOHelper.updateStoragePoolCapacity(dbClient, scaleIOHandle, pool, storage);
        }
        taskCompleter.ready(dbClient);
    } catch (Exception e) {
        log.error("Encountered an exception", e);
        ServiceCoded code = DeviceControllerErrors.scaleio.encounteredAnExceptionFromScaleIOOperation("deleteGroupSnapshots", e.getMessage());
        taskCompleter.error(dbClient, code);
    }
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) Volume(com.emc.storageos.db.client.model.Volume) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ScaleIORestClient(com.emc.storageos.scaleio.api.restapi.ScaleIORestClient) URI(java.net.URI) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) HashSet(java.util.HashSet)

Example 8 with ScaleIORestClient

use of com.emc.storageos.scaleio.api.restapi.ScaleIORestClient in project coprhd-controller by CoprHD.

the class ScaleIOSnapshotOperations method createSingleVolumeSnapshot.

@Override
public void createSingleVolumeSnapshot(StorageSystem storage, URI snapshot, Boolean createInactive, Boolean readOnly, TaskCompleter taskCompleter) throws DeviceControllerException {
    try {
        ScaleIORestClient scaleIOHandle = scaleIOHandleFactory.using(dbClient).getClientHandle(storage);
        BlockSnapshot blockSnapshot = dbClient.queryObject(BlockSnapshot.class, snapshot);
        Volume parent = dbClient.queryObject(Volume.class, blockSnapshot.getParent().getURI());
        String systemId = scaleIOHandle.getSystemId();
        ScaleIOSnapshotVolumeResponse result = scaleIOHandle.snapshotVolume(parent.getNativeId(), blockSnapshot.getLabel(), systemId);
        String nativeId = result.getVolumeIdList().get(0);
        ScaleIOHelper.updateSnapshotWithSnapshotVolumeResult(dbClient, blockSnapshot, systemId, nativeId, storage);
        dbClient.persistObject(blockSnapshot);
        ScaleIOHelper.updateStoragePoolCapacity(dbClient, scaleIOHandle, blockSnapshot);
        taskCompleter.ready(dbClient);
    } catch (Exception e) {
        log.error("Encountered an exception", e);
        ServiceCoded code = DeviceControllerErrors.scaleio.encounteredAnExceptionFromScaleIOOperation("createSingleVolumeSnapshot", e.getMessage());
        taskCompleter.error(dbClient, code);
    }
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) ScaleIOSnapshotVolumeResponse(com.emc.storageos.scaleio.api.restapi.response.ScaleIOSnapshotVolumeResponse) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ScaleIORestClient(com.emc.storageos.scaleio.api.restapi.ScaleIORestClient) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 9 with ScaleIORestClient

use of com.emc.storageos.scaleio.api.restapi.ScaleIORestClient in project coprhd-controller by CoprHD.

the class ScaleIOStorageDevice method refreshConnectionStatusForAllSIOProviders.

/**
 * Refresh connection status for all ScaleIO providers.
 *
 * @return A list of providers whose connections were successful.
 */
public List<URI> refreshConnectionStatusForAllSIOProviders() {
    log.info("Refreshing connection statuses for ScaleIO providers");
    List<URI> activeProviders = Lists.newArrayList();
    List<StorageProvider> providers = CustomQueryUtility.getActiveStorageProvidersByInterfaceType(dbClient, StorageProvider.InterfaceType.scaleioapi.name());
    for (StorageProvider provider : providers) {
        try {
            // Flag for success/failure
            boolean success = false;
            // Prepare to try secondary IPs if necessary
            StringSet secondaryIps = provider.getSecondaryIps();
            Iterator<String> iterator = secondaryIps.iterator();
            // Cache the current IP address
            String currentIPAddress = provider.getIPAddress();
            String nextIp = null;
            do {
                try {
                    ScaleIORestClient handle = scaleIOHandleFactory.using(dbClient).getClientHandle(provider);
                    // Ignore the result on success, otherwise catch the exception
                    handle.getSystem();
                    log.info("Successfully connected to ScaleIO MDM {}: {}", provider.getIPAddress(), provider.getId());
                    success = true;
                    break;
                } catch (Exception e) {
                    log.error(String.format("Failed to connect to ScaleIO MDM %s: %s", provider.getIPAddress(), provider.getId()), e);
                    if (iterator.hasNext()) {
                        nextIp = iterator.next();
                        log.info("Attempting connection to potential new Primary MDM {}: {}", nextIp, provider.getId());
                        provider.setIPAddress(nextIp);
                    } else {
                        log.warn("Exhausted list of secondary IPs for ScaleIO provider: {}", provider.getId());
                        nextIp = null;
                    }
                }
            } while (// while we have more IPs to try
            nextIp != null);
            if (success) {
                // Update secondary IP addresses if we switched over
                if (!provider.getIPAddress().equalsIgnoreCase(currentIPAddress)) {
                    StringSet newSecondaryIps = new StringSet();
                    // Copy old secondary list
                    newSecondaryIps.addAll(secondaryIps);
                    // Remove the new primary IP
                    newSecondaryIps.remove(provider.getIPAddress());
                    // Add the old primary IP
                    newSecondaryIps.add(currentIPAddress);
                    // TODO Improve how we update the StringSet based on infra team suggestions
                    provider.setSecondaryIps(newSecondaryIps);
                }
                activeProviders.add(provider.getId());
                provider.setConnectionStatus(StorageProvider.ConnectionStatus.CONNECTED.toString());
            } else {
                provider.setIPAddress(currentIPAddress);
                provider.setConnectionStatus(StorageProvider.ConnectionStatus.NOTCONNECTED.toString());
            }
        } finally {
            dbClient.persistObject(provider);
        }
    }
    return activeProviders;
}
Also used : StringSet(com.emc.storageos.db.client.model.StringSet) ScaleIORestClient(com.emc.storageos.scaleio.api.restapi.ScaleIORestClient) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ScaleIOException(com.emc.storageos.scaleio.ScaleIOException)

Example 10 with ScaleIORestClient

use of com.emc.storageos.scaleio.api.restapi.ScaleIORestClient in project coprhd-controller by CoprHD.

the class ScaleIOCommunicationInterface method discover.

@Override
public void discover(AccessProfile accessProfile) throws BaseCollectionException {
    StorageSystem.CompatibilityStatus compatibilityStatus = StorageSystem.CompatibilityStatus.COMPATIBLE;
    StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, accessProfile.getSystemId());
    _locker.acquireLock(accessProfile.getIpAddress(), LOCK_WAIT_SECONDS);
    log.info("Starting discovery of ScaleIO StorageProvider. IP={} StorageSystem {}", accessProfile.getIpAddress(), storageSystem.getNativeGuid());
    String statusMsg = "";
    try {
        ScaleIORestClient scaleIOHandle = scaleIOHandleFactory.using(_dbClient).getClientHandle(storageSystem);
        if (scaleIOHandle != null) {
            ScaleIOSystem sioSystem = scaleIOHandle.getSystem();
            List<ScaleIOProtectionDomain> protectionDomains = scaleIOHandle.getProtectionDomains();
            List<ScaleIOSDC> allSDCs = scaleIOHandle.queryAllSDC();
            List<ScaleIOSDS> allSDSs = scaleIOHandle.queryAllSDS();
            List<ScaleIOScsiInitiator> allSCSIInitiators = scaleIOHandle.queryAllSCSIInitiators();
            List<StoragePort> ports = new ArrayList<>();
            List<StoragePool> newPools = new ArrayList<StoragePool>();
            List<StoragePool> updatePools = new ArrayList<StoragePool>();
            List<StoragePool> allPools = new ArrayList<StoragePool>();
            String scaleIOType = StorageSystem.Type.scaleio.name();
            String installationId = sioSystem.getInstallId();
            String version = sioSystem.getVersion().replaceAll("_", ".");
            String minimumSupported = VersionChecker.getMinimumSupportedVersion(StorageSystem.Type.scaleio);
            compatibilityStatus = (VersionChecker.verifyVersionDetails(minimumSupported, version) < 0) ? StorageSystem.CompatibilityStatus.INCOMPATIBLE : StorageSystem.CompatibilityStatus.COMPATIBLE;
            storageSystem.setFirmwareVersion(version);
            storageSystem.setCompatibilityStatus(compatibilityStatus.name());
            storageSystem.setReachableStatus(true);
            storageSystem.setLabel(storageSystem.getNativeGuid());
            for (ScaleIOProtectionDomain protectionDomain : protectionDomains) {
                String domainName = protectionDomain.getName();
                String id = String.format("%s+%s", installationId, domainName);
                String storageSystemNativeGUID = generateNativeGuid(scaleIOType, id);
                if (!storageSystemNativeGUID.equals(storageSystem.getNativeGuid())) {
                    // This is not the ProtectionDomain that we're looking for
                    continue;
                }
                String protectionDomainId = protectionDomain.getId();
                storageSystem.setSerialNumber(protectionDomainId);
                Network network = createNetwork(installationId);
                List<ScaleIOSDS> sdsList = new ArrayList<ScaleIOSDS>();
                for (ScaleIOSDS sds : allSDSs) {
                    String pdId = sds.getProtectionDomainId();
                    if (pdId.equals(protectionDomainId)) {
                        sdsList.add(sds);
                    }
                }
                List<StoragePort> thesePorts = createStoragePorts(storageSystem, compatibilityStatus.name(), network, sdsList, domainName);
                ports.addAll(thesePorts);
                createHost(network, allSDCs);
                boolean hasSCSIInitiators = createSCSIInitiatorsAndStoragePorts(storageSystem, domainName, compatibilityStatus, installationId, allSCSIInitiators, allSDCs, ports);
                List<StoragePort> notVisiblePorts = DiscoveryUtils.checkStoragePortsNotVisible(ports, _dbClient, storageSystem.getId());
                if (notVisiblePorts != null && !notVisiblePorts.isEmpty()) {
                    ports.addAll(notVisiblePorts);
                }
                Set<String> supportedProtocols = (hasSCSIInitiators) ? SCALEIO_AND_ISCSI : SCALEIO_ONLY;
                List<ScaleIOStoragePool> storagePools = scaleIOHandle.getProtectionDomainStoragePools(protectionDomainId);
                for (ScaleIOStoragePool storagePool : storagePools) {
                    String poolName = storagePool.getName();
                    String nativeGuid = String.format("%s-%s-%s", installationId, domainName, poolName);
                    log.info("Attempting to discover pool {} for ProtectionDomain {}", poolName, domainName);
                    List<StoragePool> pools = queryActiveResourcesByAltId(_dbClient, StoragePool.class, "nativeGuid", nativeGuid);
                    StoragePool pool = null;
                    if (pools.isEmpty()) {
                        log.info("Pool {} is new", poolName);
                        pool = new StoragePool();
                        pool.setId(URIUtil.createId(StoragePool.class));
                        pool.setStorageDevice(accessProfile.getSystemId());
                        pool.setPoolServiceType(StoragePool.PoolServiceType.block.toString());
                        pool.setOperationalStatus(StoragePool.PoolOperationalStatus.READY.name());
                        pool.setCompatibilityStatus(compatibilityStatus.name());
                        pool.setThinVolumePreAllocationSupported(false);
                        pool.addDriveTypes(Collections.singleton(StoragePool.SupportedDriveTypeValues.SATA.name()));
                        StringSet copyTypes = new StringSet();
                        copyTypes.add(StoragePool.CopyTypes.ASYNC.name());
                        copyTypes.add(StoragePool.CopyTypes.UNSYNC_UNASSOC.name());
                        pool.setSupportedCopyTypes(copyTypes);
                        pool.setMaximumThickVolumeSize(1048576L);
                        pool.setMinimumThickVolumeSize(1L);
                        newPools.add(pool);
                    } else if (pools.size() == 1) {
                        log.info("Pool {} was previously discovered", storagePool);
                        pool = pools.get(0);
                        updatePools.add(pool);
                    } else {
                        log.warn(String.format("There are %d StoragePools with nativeGuid = %s", pools.size(), nativeGuid));
                        continue;
                    }
                    pool.setPoolName(poolName);
                    pool.setNativeId(storagePool.getId());
                    pool.setNativeGuid(nativeGuid);
                    String availableCapacityString = storagePool.getCapacityAvailableForVolumeAllocationInKb();
                    pool.setFreeCapacity(Long.parseLong(availableCapacityString));
                    String totalCapacityString = storagePool.getMaxCapacityInKb();
                    pool.setTotalCapacity(Long.parseLong(totalCapacityString));
                    pool.addProtocols(supportedProtocols);
                    pool.setSupportedResourceTypes(StoragePool.SupportedResourceTypes.THIN_AND_THICK.name());
                    Long maxThinSize = 1048576L;
                    Long minThinSize = 1L;
                    pool.setMaximumThinVolumeSize(maxThinSize);
                    pool.setMinimumThinVolumeSize(minThinSize);
                    pool.setInactive(false);
                    pool.setDiscoveryStatus(DiscoveryStatus.VISIBLE.name());
                }
            }
            log.info(String.format("For StorageSystem %s, discovered %d new pools and %d pools to update", storageSystem.getNativeGuid(), newPools.size(), updatePools.size()));
            StoragePoolAssociationHelper.setStoragePoolVarrays(storageSystem.getId(), newPools, _dbClient);
            allPools.addAll(newPools);
            allPools.addAll(updatePools);
            _dbClient.createObject(newPools);
            _dbClient.updateAndReindexObject(updatePools);
            List<StoragePool> notVisiblePools = DiscoveryUtils.checkStoragePoolsNotVisible(allPools, _dbClient, storageSystem.getId());
            if (notVisiblePools != null && !notVisiblePools.isEmpty()) {
                allPools.addAll(notVisiblePools);
            }
            StoragePortAssociationHelper.runUpdatePortAssociationsProcess(ports, null, _dbClient, _coordinator, allPools);
            statusMsg = String.format("Discovery completed successfully for Storage System: %s", storageSystem.getNativeGuid());
        }
    } catch (Exception e) {
        storageSystem.setReachableStatus(false);
        log.error(String.format("Exception was encountered when attempting to discover ScaleIO Instance %s", accessProfile.getIpAddress()), e);
        statusMsg = String.format("Discovery failed because %s", e.getLocalizedMessage());
        throw ScaleIOException.exceptions.discoveryFailed(e);
    } finally {
        _locker.releaseLock(accessProfile.getIpAddress());
        if (storageSystem != null) {
            storageSystem.setLastDiscoveryStatusMessage(statusMsg);
        }
    }
    _dbClient.updateAndReindexObject(storageSystem);
    log.info("Completed of ScaleIO StorageProvider. IP={} StorageSystem {}", accessProfile.getIpAddress(), storageSystem.getNativeGuid());
}
Also used : ScaleIOStoragePool(com.emc.storageos.scaleio.api.restapi.response.ScaleIOStoragePool) ArrayList(java.util.ArrayList) ScaleIOSystem(com.emc.storageos.scaleio.api.restapi.response.ScaleIOSystem) ScaleIOProtectionDomain(com.emc.storageos.scaleio.api.restapi.response.ScaleIOProtectionDomain) ScaleIOStoragePool(com.emc.storageos.scaleio.api.restapi.response.ScaleIOStoragePool) ScaleIOSDS(com.emc.storageos.scaleio.api.restapi.response.ScaleIOSDS) IOException(java.io.IOException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) ScaleIOException(com.emc.storageos.scaleio.ScaleIOException) ScaleIOScsiInitiator(com.emc.storageos.scaleio.api.restapi.response.ScaleIOScsiInitiator) ScaleIORestClient(com.emc.storageos.scaleio.api.restapi.ScaleIORestClient) ScaleIOSDC(com.emc.storageos.scaleio.api.restapi.response.ScaleIOSDC)

Aggregations

ScaleIORestClient (com.emc.storageos.scaleio.api.restapi.ScaleIORestClient)18 ServiceCoded (com.emc.storageos.svcs.errorhandling.model.ServiceCoded)11 URI (java.net.URI)11 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)10 ScaleIOException (com.emc.storageos.scaleio.ScaleIOException)9 Volume (com.emc.storageos.db.client.model.Volume)7 StoragePool (com.emc.storageos.db.client.model.StoragePool)6 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)6 ScaleIOVolume (com.emc.storageos.scaleio.api.restapi.response.ScaleIOVolume)6 HashSet (java.util.HashSet)5 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)4 ScaleIOSnapshotVolumeResponse (com.emc.storageos.scaleio.api.restapi.response.ScaleIOSnapshotVolumeResponse)4 BlockObject (com.emc.storageos.db.client.model.BlockObject)3 ScaleIOProtectionDomain (com.emc.storageos.scaleio.api.restapi.response.ScaleIOProtectionDomain)3 ScaleIOSystem (com.emc.storageos.scaleio.api.restapi.response.ScaleIOSystem)3 HashMap (java.util.HashMap)3 Initiator (com.emc.storageos.db.client.model.Initiator)2 StorageProvider (com.emc.storageos.db.client.model.StorageProvider)2 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)2 ScaleIOSDC (com.emc.storageos.scaleio.api.restapi.response.ScaleIOSDC)2