Search in sources :

Example 56 with ServiceCoded

use of com.emc.storageos.svcs.errorhandling.model.ServiceCoded 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)

Example 57 with ServiceCoded

use of com.emc.storageos.svcs.errorhandling.model.ServiceCoded 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 58 with ServiceCoded

use of com.emc.storageos.svcs.errorhandling.model.ServiceCoded 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 59 with ServiceCoded

use of com.emc.storageos.svcs.errorhandling.model.ServiceCoded 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)

Example 60 with ServiceCoded

use of com.emc.storageos.svcs.errorhandling.model.ServiceCoded in project coprhd-controller by CoprHD.

the class ScaleIOStorageDevice method completeTaskAsUnsupported.

/**
 * Method calls the completer with error message indicating that the caller's method is unsupported
 *
 * @param completer
 *            [in] - TaskCompleter
 */
private void completeTaskAsUnsupported(TaskCompleter completer) {
    StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
    String methodName = stackTrace[2].getMethodName();
    ServiceCoded code = DeviceControllerErrors.scaleio.operationIsUnsupported(methodName);
    completer.error(dbClient, code);
}
Also used : ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded)

Aggregations

ServiceCoded (com.emc.storageos.svcs.errorhandling.model.ServiceCoded)94 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)48 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)44 URI (java.net.URI)41 Volume (com.emc.storageos.db.client.model.Volume)31 ControllerException (com.emc.storageos.volumecontroller.ControllerException)27 NamedURI (com.emc.storageos.db.client.model.NamedURI)26 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)22 WorkflowException (com.emc.storageos.workflow.WorkflowException)22 ArrayList (java.util.ArrayList)22 BlockObject (com.emc.storageos.db.client.model.BlockObject)18 Operation (com.emc.storageos.db.client.model.Operation)17 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)17 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)16 TaskCompleter (com.emc.storageos.volumecontroller.TaskCompleter)15 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)14 HashMap (java.util.HashMap)14 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)13 URISyntaxException (java.net.URISyntaxException)13 Host (com.emc.storageos.db.client.model.Host)12