Search in sources :

Example 11 with ScaleIORestClient

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

the class ScaleIOHandleFactory method getClientHandle.

public ScaleIORestClient getClientHandle(StorageProvider provider) throws Exception {
    ScaleIORestClient handle = null;
    synchronized (syncObject) {
        String providerId = provider.getProviderID();
        handle = ScaleIORestClientMap.get(providerId);
        handle = getHandle(handle, provider);
    }
    return handle;
}
Also used : ScaleIORestClient(com.emc.storageos.scaleio.api.restapi.ScaleIORestClient)

Example 12 with ScaleIORestClient

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

the class ScaleIOHandleFactory method getHandle.

private ScaleIORestClient getHandle(ScaleIORestClient handle, StorageProvider provider) throws Exception {
    if (StorageProvider.InterfaceType.scaleioapi.name().equals(provider.getInterfaceType())) {
        if (handle == null) {
            URI baseURI = URI.create(ScaleIOConstants.getAPIBaseURI(provider.getIPAddress(), provider.getPortNumber()));
            handle = (ScaleIORestClient) scaleIORestClientFactory.getRESTClient(baseURI, provider.getUserName(), provider.getPassword(), true);
            ScaleIORestClient client = (ScaleIORestClient) handle;
            ScaleIORestClientMap.put(provider.getProviderID(), client);
        }
        ScaleIORestClient client = (ScaleIORestClient) handle;
        if (!Strings.isNullOrEmpty(provider.getUserName())) {
            client.setUsername(provider.getUserName());
        }
        if (!Strings.isNullOrEmpty(provider.getPassword())) {
            client.setPassword(provider.getPassword());
        }
    } else {
        log.info("The storage provider interface type is not supported: {} ", provider.getInterfaceType());
        // not supported
        handle = null;
    }
    return handle;
}
Also used : ScaleIORestClient(com.emc.storageos.scaleio.api.restapi.ScaleIORestClient) URI(java.net.URI)

Example 13 with ScaleIORestClient

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

the class ScaleIOSnapshotOperations method deleteSingleVolumeSnapshot.

@Override
public void deleteSingleVolumeSnapshot(StorageSystem storage, URI snapshot, TaskCompleter taskCompleter) throws DeviceControllerException {
    try {
        ScaleIORestClient scaleIOHandle = scaleIOHandleFactory.using(dbClient).getClientHandle(storage);
        BlockSnapshot blockSnapshot = dbClient.queryObject(BlockSnapshot.class, snapshot);
        if (blockSnapshot != null && !blockSnapshot.getInactive() && // state against the BlockSnapshot object can be set.
        !Strings.isNullOrEmpty(blockSnapshot.getNativeId())) {
            scaleIOHandle.removeVolume(blockSnapshot.getNativeId());
        }
        if (blockSnapshot != null) {
            blockSnapshot.setInactive(true);
            dbClient.updateObject(blockSnapshot);
            ScaleIOHelper.updateStoragePoolCapacity(dbClient, scaleIOHandle, blockSnapshot);
        }
        taskCompleter.ready(dbClient);
    } catch (Exception e) {
        log.error("Encountered an exception", e);
        ServiceCoded code = DeviceControllerErrors.scaleio.encounteredAnExceptionFromScaleIOOperation("deleteSingleVolumeSnapshot", e.getMessage());
        taskCompleter.error(dbClient, code);
    }
}
Also used : 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 14 with ScaleIORestClient

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

the class ScaleIOStorageDevice method unmapVolumes.

/**
 * Given a mapping of volumes and initiators, make the ScaleIO API calls to un-map the volume
 * to the specified ScaleIO initiators
 *
 * @param storage
 *            [in] - StorageSystem object (ScaleIO array abstraction)
 * @param volumeURIs
 *            [in] - Collection of Volume URIs
 * @param initiators
 *            [in] - Collection of Initiator objects
 * @param completer
 *            [in] - TaskCompleter
 */
private void unmapVolumes(StorageSystem storage, Collection<URI> volumeURIs, Collection<Initiator> initiators, TaskCompleter completer) {
    try {
        ScaleIORestClient scaleIOHandle = scaleIOHandleFactory.using(dbClient).getClientHandle(storage);
        for (URI volumeURI : volumeURIs) {
            BlockObject blockObject = BlockObject.fetch(dbClient, volumeURI);
            if (blockObject == null || blockObject.getInactive()) {
                log.warn(String.format("Attempted to unmap BlockObject %s, which was either not found in the DB or was inactive", volumeURI.toString()));
                continue;
            }
            String nativeId = blockObject.getNativeId();
            for (Initiator initiator : initiators) {
                String port = initiator.getInitiatorPort();
                boolean wasUnMapped = false;
                if (initiator.getProtocol().equals(HostInterface.Protocol.ScaleIO.name())) {
                    wasUnMapped = unmapFromSDC(scaleIOHandle, nativeId, port, completer);
                } else if (initiator.getProtocol().equals(HostInterface.Protocol.iSCSI.name())) {
                    wasUnMapped = unmapFromSCSI(scaleIOHandle, nativeId, port, initiator.getLabel(), completer);
                } else {
                    ServiceCoded code = DeviceControllerErrors.scaleio.unmapVolumeToClientFailed(nativeId, port, String.format("Unexpected initiator type %s", initiator.getProtocol()));
                    completer.error(dbClient, code);
                }
                if (!wasUnMapped) {
                    // Failed to map the volume
                    return;
                }
            }
        }
        completer.ready(dbClient);
    } catch (Exception e) {
        log.error("Encountered an exception", e);
        ServiceCoded code = DeviceControllerErrors.scaleio.encounteredAnExceptionFromScaleIOOperation("unmapVolume", 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) 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 15 with ScaleIORestClient

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

the class ScaleIOStorageDevice method doExpandVolume.

@Override
public void doExpandVolume(StorageSystem storage, StoragePool pool, Volume volume, Long size, TaskCompleter taskCompleter) throws DeviceControllerException {
    Long volumeSize = size / ScaleIOHelper.BYTES_IN_GB;
    Long expandSize = volumeSize;
    // ScaleIO volume size has to be granularity of 8
    long remainder = volumeSize % 8;
    if (remainder != 0) {
        expandSize += (8 - remainder);
        log.info("The requested size is {} GB, increase it to {} GB, so that it is granularity of 8", volumeSize, expandSize);
    }
    try {
        ScaleIORestClient scaleIOHandle = scaleIOHandleFactory.using(dbClient).getClientHandle(storage);
        ScaleIOVolume result = scaleIOHandle.modifyVolumeCapacity(volume.getNativeId(), expandSize.toString());
        long newSize = Long.parseLong(result.getSizeInKb()) * 1024L;
        volume.setProvisionedCapacity(newSize);
        volume.setAllocatedCapacity(newSize);
        volume.setCapacity(size);
        dbClient.persistObject(volume);
        ScaleIOHelper.updateStoragePoolCapacity(dbClient, scaleIOHandle, pool, storage);
        pool.removeReservedCapacityForVolumes(Arrays.asList(volume.getId().toString()));
        taskCompleter.ready(dbClient);
    } catch (Exception e) {
        log.error("Encountered an exception", e);
        ServiceCoded code = DeviceControllerErrors.scaleio.encounteredAnExceptionFromScaleIOOperation("expandVolume", e.getMessage());
        taskCompleter.error(dbClient, code);
    }
}
Also used : ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) ScaleIOVolume(com.emc.storageos.scaleio.api.restapi.response.ScaleIOVolume) ScaleIORestClient(com.emc.storageos.scaleio.api.restapi.ScaleIORestClient) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ScaleIOException(com.emc.storageos.scaleio.ScaleIOException)

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