Search in sources :

Example 16 with ScaleIORestClient

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

the class ScaleIOStorageDevice method doDeleteVolumes.

@Override
public void doDeleteVolumes(StorageSystem storageSystem, String opId, List<Volume> volumes, TaskCompleter completer) throws DeviceControllerException {
    try {
        ScaleIORestClient scaleIOHandle = scaleIOHandleFactory.using(dbClient).getClientHandle(storageSystem);
        Set<URI> poolsToUpdate = new HashSet<>();
        for (Volume volume : volumes) {
            scaleIOHandle.removeVolume(volume.getNativeId());
            volume.setInactive(true);
            poolsToUpdate.add(volume.getPool());
            if (!NullColumnValueGetter.isNullURI(volume.getConsistencyGroup())) {
                volume.setConsistencyGroup(NullColumnValueGetter.getNullURI());
            }
        }
        dbClient.persistObject(volumes);
        List<StoragePool> pools = dbClient.queryObject(StoragePool.class, Lists.newArrayList(poolsToUpdate));
        for (StoragePool pool : pools) {
            ScaleIOHelper.updateStoragePoolCapacity(dbClient, scaleIOHandle, pool, storageSystem);
        }
        completer.ready(dbClient);
    } catch (Exception e) {
        log.error("Encountered an exception", e);
        ServiceCoded code = DeviceControllerErrors.scaleio.encounteredAnExceptionFromScaleIOOperation("deleteVolume", e.getMessage());
        completer.error(dbClient, code);
    }
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) Volume(com.emc.storageos.db.client.model.Volume) ScaleIOVolume(com.emc.storageos.scaleio.api.restapi.response.ScaleIOVolume) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) ScaleIORestClient(com.emc.storageos.scaleio.api.restapi.ScaleIORestClient) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ScaleIOException(com.emc.storageos.scaleio.ScaleIOException) HashSet(java.util.HashSet)

Example 17 with ScaleIORestClient

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

the class ScaleIOStorageDevice method mapVolumes.

/**
 * Given a mapping of volumes and initiators, make the ScaleIO API calls to map the volume
 * to the specified ScaleIO initiators
 *
 * @param storage
 *            [in] - StorageSystem object (ScaleIO array abstraction)
 * @param volumeMap
 *            [in] - Volume URI to Integer LUN map
 * @param initiators
 *            [in] - Collection of Initiator objects
 * @param completer
 *            [in] - TaskCompleter
 */
private void mapVolumes(StorageSystem storage, Map<URI, Integer> volumeMap, Collection<Initiator> initiators, TaskCompleter completer) {
    try {
        ScaleIORestClient scaleIOHandle = scaleIOHandleFactory.using(dbClient).getClientHandle(storage);
        for (Map.Entry<URI, Integer> volMapEntry : volumeMap.entrySet()) {
            BlockObject blockObject = BlockObject.fetch(dbClient, volMapEntry.getKey());
            String nativeId = blockObject.getNativeId();
            for (Initiator initiator : initiators) {
                String port = initiator.getInitiatorPort();
                boolean wasMapped = false;
                if (initiator.getProtocol().equals(HostInterface.Protocol.ScaleIO.name())) {
                    wasMapped = mapToSDC(scaleIOHandle, nativeId, port, completer);
                } else if (initiator.getProtocol().equals(HostInterface.Protocol.iSCSI.name())) {
                    wasMapped = mapToSCSI(scaleIOHandle, nativeId, port, initiator.getLabel(), completer);
                } else {
                    ServiceCoded code = DeviceControllerErrors.scaleio.mapVolumeToClientFailed(nativeId, port, String.format("Unexpected initiator type %s", initiator.getProtocol()));
                    completer.error(dbClient, code);
                }
                if (!wasMapped) {
                    // Failed to map the volume
                    return;
                }
            }
        }
        completer.ready(dbClient);
    } catch (Exception e) {
        log.error("Encountered an exception", e);
        ServiceCoded code = DeviceControllerErrors.scaleio.encounteredAnExceptionFromScaleIOOperation("mapVolume", e.getMessage());
        completer.error(dbClient, code);
    }
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) ScaleIORestClient(com.emc.storageos.scaleio.api.restapi.ScaleIORestClient) Map(java.util.Map) HashMap(java.util.HashMap) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ScaleIOException(com.emc.storageos.scaleio.ScaleIOException)

Example 18 with ScaleIORestClient

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

the class ScaleIOStorageDevice method doCreateVolumes.

@Override
public void doCreateVolumes(StorageSystem storage, StoragePool storagePool, String opId, List<Volume> volumes, VirtualPoolCapabilityValuesWrapper capabilities, TaskCompleter taskCompleter) throws DeviceControllerException {
    int index = 1;
    try {
        ScaleIORestClient scaleIOHandle = scaleIOHandleFactory.using(dbClient).getClientHandle(storage);
        String protectionDomainName = storage.getSerialNumber();
        Long volumeSize = capabilities.getSize() / ScaleIOHelper.BYTES_IN_GB;
        int count = volumes.size();
        Set<URI> poolsToUpdate = new HashSet<>();
        boolean thinlyProvisioned = capabilities.getThinProvisioning();
        Set<URI> consistencyGroups = new HashSet<>();
        Multimap<URI, String> poolToVolumesMap = ArrayListMultimap.create();
        String systemId = scaleIOHandle.getSystemId();
        for (; index <= count; index++) {
            Volume volume = volumes.get(index - 1);
            Long size = capabilities.getSize();
            String poolId = storagePool.getNativeId();
            ScaleIOVolume result = scaleIOHandle.addVolume(protectionDomainName, poolId, volume.getLabel(), size.toString(), thinlyProvisioned);
            ScaleIOHelper.updateVolumeWithAddVolumeInfo(dbClient, volume, systemId, volumeSize, result);
            poolsToUpdate.add(volume.getPool());
            if (!NullColumnValueGetter.isNullURI(volume.getConsistencyGroup())) {
                consistencyGroups.add(volume.getConsistencyGroup());
            }
            poolToVolumesMap.put(volume.getPool(), volume.getId().toString());
        }
        updateConsistencyGroupsWithStorageSystem(consistencyGroups, storage);
        List<StoragePool> pools = dbClient.queryObject(StoragePool.class, Lists.newArrayList(poolsToUpdate));
        for (StoragePool pool : pools) {
            pool.removeReservedCapacityForVolumes(poolToVolumesMap.get(pool.getId()));
            ScaleIOHelper.updateStoragePoolCapacity(dbClient, scaleIOHandle, pool, storage);
        }
        dbClient.persistObject(volumes);
        taskCompleter.ready(dbClient);
    } catch (Exception e) {
        log.error("Encountered an exception", e);
        for (int cleanup = index; cleanup <= volumes.size(); cleanup++) {
            volumes.get(cleanup - 1).setInactive(true);
        }
        dbClient.persistObject(volumes);
        ServiceCoded code = DeviceControllerErrors.scaleio.encounteredAnExceptionFromScaleIOOperation("addVolume", e.getMessage());
        taskCompleter.error(dbClient, code);
    }
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) ScaleIOVolume(com.emc.storageos.scaleio.api.restapi.response.ScaleIOVolume) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ScaleIOException(com.emc.storageos.scaleio.ScaleIOException) Volume(com.emc.storageos.db.client.model.Volume) ScaleIOVolume(com.emc.storageos.scaleio.api.restapi.response.ScaleIOVolume) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) ScaleIORestClient(com.emc.storageos.scaleio.api.restapi.ScaleIORestClient) HashSet(java.util.HashSet)

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