Search in sources :

Example 6 with DriverTask

use of com.emc.storageos.storagedriver.DriverTask in project coprhd-controller by CoprHD.

the class ExternalBlockStorageDevice method doCreateVolumes.

@Override
public void doCreateVolumes(StorageSystem storageSystem, StoragePool storagePool, String opId, List<Volume> volumes, VirtualPoolCapabilityValuesWrapper capabilities, TaskCompleter taskCompleter) throws DeviceControllerException {
    List<StorageVolume> driverVolumes = new ArrayList<>();
    Map<StorageVolume, Volume> driverVolumeToVolumeMap = new HashMap<>();
    Set<URI> consistencyGroups = new HashSet<>();
    StorageCapabilities storageCapabilities = null;
    DriverTask task = null;
    BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
    try {
        for (Volume volume : volumes) {
            if (storageCapabilities == null) {
                // All volumes created in a request will have the same capabilities.
                storageCapabilities = new StorageCapabilities();
                addAutoTieringPolicyCapability(storageCapabilities, volume.getAutoTieringPolicyUri());
                addDeduplicationCapability(storageCapabilities, volume.getIsDeduplicated());
            }
            StorageVolume driverVolume = new StorageVolume();
            driverVolume.setStorageSystemId(storageSystem.getNativeId());
            driverVolume.setStoragePoolId(storagePool.getNativeId());
            driverVolume.setRequestedCapacity(volume.getCapacity());
            driverVolume.setThinlyProvisioned(volume.getThinlyProvisioned());
            driverVolume.setDisplayName(volume.getLabel());
            if (!NullColumnValueGetter.isNullURI(volume.getConsistencyGroup())) {
                BlockConsistencyGroup cg = dbClient.queryObject(BlockConsistencyGroup.class, volume.getConsistencyGroup());
                driverVolume.setConsistencyGroup(cg.getNativeId());
            }
            driverVolumes.add(driverVolume);
            driverVolumeToVolumeMap.put(driverVolume, volume);
        }
        // Call driver
        task = driver.createVolumes(Collections.unmodifiableList(driverVolumes), storageCapabilities);
        // todo: need to implement support for async case.
        if (task.getStatus() == DriverTask.TaskStatus.READY || task.getStatus() == DriverTask.TaskStatus.PARTIALLY_FAILED) {
            updateVolumesWithDriverVolumeInfo(dbClient, driverVolumeToVolumeMap, consistencyGroups);
            dbClient.updateObject(driverVolumeToVolumeMap.values());
            updateConsistencyGroupsWithStorageSystem(consistencyGroups, storageSystem);
            String msg = String.format("doCreateVolumes -- Created volumes: %s .", task.getMessage());
            _log.info(msg);
            taskCompleter.ready(dbClient);
        } else {
            // Set volumes to inactive state
            for (Volume volume : volumes) {
                volume.setInactive(true);
            }
            dbClient.updateObject(volumes);
            String errorMsg = String.format("doCreateVolumes -- Failed to create volumes: %s .", task.getMessage());
            _log.error(errorMsg);
            ServiceError serviceError = ExternalDeviceException.errors.createVolumesFailed("doCreateVolumes", errorMsg);
            taskCompleter.error(dbClient, serviceError);
        }
    } catch (Exception e) {
        _log.error("doCreateVolumes -- Failed to create volumes. ", e);
        ServiceError serviceError = ExternalDeviceException.errors.createVolumesFailed("doCreateVolumes", e.getMessage());
        taskCompleter.error(dbClient, serviceError);
    } finally {
        try {
            if (task == null || isTaskInTerminalState(task.getStatus())) {
                updateStoragePoolCapacity(storagePool, storageSystem, URIUtil.toUris(volumes), dbClient);
            }
        } catch (Exception ex) {
            _log.error("Failed to update storage pool {} after create volumes operation completion.", storagePool.getId(), ex);
        }
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) IOException(java.io.IOException) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) DriverTask(com.emc.storageos.storagedriver.DriverTask) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) StorageCapabilities(com.emc.storageos.storagedriver.storagecapabilities.StorageCapabilities) CommonStorageCapabilities(com.emc.storageos.storagedriver.storagecapabilities.CommonStorageCapabilities) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) Volume(com.emc.storageos.db.client.model.Volume) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver) HashSet(java.util.HashSet)

Example 7 with DriverTask

use of com.emc.storageos.storagedriver.DriverTask in project coprhd-controller by CoprHD.

the class ExternalBlockStorageDevice method doRestoreFromSnapshot.

@Override
public void doRestoreFromSnapshot(StorageSystem storageSystem, URI volume, URI snapshot, TaskCompleter taskCompleter) throws DeviceControllerException {
    String storageSystemNativeId = storageSystem.getNativeId();
    _log.info("Snapshot Restore..... Started");
    BlockConsistencyGroup parentVolumeConsistencyGroup = null;
    try {
        List<BlockSnapshot> snapshotsToRestore = new ArrayList<>();
        BlockSnapshot blockSnapshot = dbClient.queryObject(BlockSnapshot.class, snapshot);
        List<BlockSnapshot> groupSnapshots = ControllerUtils.getSnapshotsPartOfReplicationGroup(blockSnapshot, dbClient);
        if (groupSnapshots.size() > 1 && ControllerUtils.checkSnapshotsInConsistencyGroup(Arrays.asList(blockSnapshot), dbClient, taskCompleter)) {
            // make sure we restore only snapshots from the same consistency group
            for (BlockSnapshot snap : groupSnapshots) {
                if (snap.getConsistencyGroup().equals(blockSnapshot.getConsistencyGroup())) {
                    snapshotsToRestore.add(snap);
                }
            }
            URI cgUri = blockSnapshot.getConsistencyGroup();
            parentVolumeConsistencyGroup = dbClient.queryObject(BlockConsistencyGroup.class, cgUri);
            _log.info("Restore group snapshot: group {}, snapshot set: {}, snapshots to restore: " + Joiner.on("\t").join(snapshotsToRestore), parentVolumeConsistencyGroup.getNativeId(), blockSnapshot.getReplicationGroupInstance());
        } else {
            Volume sourceVolume = getSnapshotParentVolume(blockSnapshot);
            snapshotsToRestore.add(blockSnapshot);
            _log.info("Restore single volume snapshot: volume {}, snapshot: {}", sourceVolume.getNativeId(), blockSnapshot.getNativeId());
        }
        // Prepare driver snapshots
        List<VolumeSnapshot> driverSnapshots = new ArrayList<>();
        for (BlockSnapshot snap : snapshotsToRestore) {
            VolumeSnapshot driverSnapshot = new VolumeSnapshot();
            Volume sourceVolume = getSnapshotParentVolume(snap);
            driverSnapshot.setParentId(sourceVolume.getNativeId());
            driverSnapshot.setNativeId(snap.getNativeId());
            driverSnapshot.setStorageSystemId(storageSystemNativeId);
            driverSnapshot.setDisplayName(snap.getLabel());
            if (parentVolumeConsistencyGroup != null) {
                driverSnapshot.setConsistencyGroup(snap.getReplicationGroupInstance());
            }
            driverSnapshots.add(driverSnapshot);
        }
        // Call driver to execute this request
        BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
        DriverTask task = driver.restoreSnapshot(driverSnapshots);
        if (!isTaskInTerminalState(task.getStatus())) {
            // If the task is not in a terminal state and will be completed asynchronously
            // create a job to monitor the progress of the request and call the completer as
            // appropriate based on the result of the request.
            RestoreFromSnapshotExternalDeviceJob job = new RestoreFromSnapshotExternalDeviceJob(storageSystem.getId(), snapshot, task.getTaskId(), taskCompleter);
            ControllerServiceImpl.enqueueJob(new QueueJob(job));
        } else if (task.getStatus() == DriverTask.TaskStatus.READY) {
            String msg = String.format("doRestoreFromSnapshot -- Restored snapshots: %s .", task.getMessage());
            _log.info(msg);
            taskCompleter.ready(dbClient);
        } else {
            String errorMsg = String.format("doRestoreFromSnapshot -- Failed to restore from snapshots: %s .", task.getMessage());
            _log.error(errorMsg);
            ServiceError serviceError = ExternalDeviceException.errors.restoreFromSnapshotFailed("doRestoreFromSnapshot", errorMsg);
            taskCompleter.error(dbClient, serviceError);
        }
    } catch (Exception e) {
        String message = String.format("IO exception when trying to restore from snapshots on array %s", storageSystem.getSerialNumber());
        _log.error(message, e);
        ServiceError error = ExternalDeviceException.errors.restoreFromSnapshotFailed("doRestoreFromSnapshot", e.getMessage());
        taskCompleter.error(dbClient, error);
    }
    _log.info("Snapshot Restore..... End");
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) RestoreFromSnapshotExternalDeviceJob(com.emc.storageos.volumecontroller.impl.externaldevice.job.RestoreFromSnapshotExternalDeviceJob) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ArrayList(java.util.ArrayList) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) IOException(java.io.IOException) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) DriverTask(com.emc.storageos.storagedriver.DriverTask) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) Volume(com.emc.storageos.db.client.model.Volume) VolumeSnapshot(com.emc.storageos.storagedriver.model.VolumeSnapshot) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver)

Example 8 with DriverTask

use of com.emc.storageos.storagedriver.DriverTask in project coprhd-controller by CoprHD.

the class ExternalBlockStorageDevice method doDeleteConsistencyGroup.

@Override
public void doDeleteConsistencyGroup(StorageSystem storageSystem, URI consistencyGroupId, String replicationGroupName, Boolean keepRGName, Boolean markInactive, TaskCompleter taskCompleter) throws DeviceControllerException {
    _log.info("Delete consistency group: STARTED...");
    BlockConsistencyGroup consistencyGroup = null;
    String groupNativeId = null;
    String groupDisplayName = null;
    boolean isDeleteForBlockCG = true;
    try {
        if (!NullColumnValueGetter.isNullURI(consistencyGroupId)) {
            consistencyGroup = dbClient.queryObject(BlockConsistencyGroup.class, consistencyGroupId);
            groupDisplayName = consistencyGroup != null ? consistencyGroup.getLabel() : replicationGroupName;
            groupNativeId = consistencyGroup != null ? consistencyGroup.getNativeId() : replicationGroupName;
            if (consistencyGroup == null) {
                isDeleteForBlockCG = false;
            }
        } else {
            groupDisplayName = replicationGroupName;
            groupNativeId = replicationGroupName;
            isDeleteForBlockCG = false;
        }
        if (groupNativeId == null || groupNativeId.isEmpty()) {
            String msg = String.format("doDeleteConsistencyGroup -- There is no consistency group or replication group to delete.");
            _log.info(msg);
            taskCompleter.ready(dbClient);
            return;
        }
        if (isDeleteForBlockCG) {
            _log.info("Deleting consistency group: storage system {}, group {}", storageSystem.getNativeId(), groupDisplayName);
        } else {
            _log.info("Deleting system replication group: storage system {}, group {}", storageSystem.getNativeId(), groupDisplayName);
            _log.info("Replication groups are not supported for external devices. Do not call driver.");
            taskCompleter.ready(dbClient);
            return;
        }
        // prepare driver consistency group
        VolumeConsistencyGroup driverCG = new VolumeConsistencyGroup();
        driverCG.setDisplayName(groupDisplayName);
        driverCG.setNativeId(groupNativeId);
        driverCG.setStorageSystemId(storageSystem.getNativeId());
        // call driver
        BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
        DriverTask task = driver.deleteConsistencyGroup(driverCG);
        // todo: need to implement support for async case.
        if (task.getStatus() == DriverTask.TaskStatus.READY) {
            if (consistencyGroup != null) {
                // I followed xtremio pattern to implement this logic.
                consistencyGroup.removeSystemConsistencyGroup(URIUtil.asString(storageSystem.getId()), groupDisplayName);
                dbClient.updateObject(consistencyGroup);
                // have to read again to get updated systemConsistencyGroup map
                consistencyGroup = dbClient.queryObject(BlockConsistencyGroup.class, consistencyGroupId);
                /*
                     * Verify if the BlockConsistencyGroup references any LOCAL arrays.
                     * If we no longer have any references we can remove the 'LOCAL' type from the BlockConsistencyGroup.
                     */
                List<URI> referencedArrays = BlockConsistencyGroupUtils.getLocalSystems(consistencyGroup, dbClient);
                boolean cgReferenced = referencedArrays != null && !referencedArrays.isEmpty();
                if (!cgReferenced) {
                    // Remove the LOCAL type
                    StringSet cgTypes = consistencyGroup.getTypes();
                    cgTypes.remove(BlockConsistencyGroup.Types.LOCAL.name());
                    consistencyGroup.setTypes(cgTypes);
                    // of storage systems associated with the CG.
                    if (!BlockConsistencyGroupUtils.referencesNonLocalCgs(consistencyGroup, dbClient)) {
                        consistencyGroup.setStorageController(NullColumnValueGetter.getNullURI());
                        // Update the consistency group model
                        consistencyGroup.setInactive(markInactive);
                    }
                } else {
                    _log.info("*** Referenced arrays {}", referencedArrays.toString());
                }
                dbClient.updateObject(consistencyGroup);
            }
            String msg = String.format("doDeleteConsistencyGroup -- Delete consistency group: %s .", task.getMessage());
            _log.info(msg);
            taskCompleter.ready(dbClient);
        } else {
            String errorMsg = String.format("doDeleteConsistencyGroup -- Failed to delete Consistency Group: %s .", task.getMessage());
            _log.error(errorMsg);
            ServiceError serviceError = ExternalDeviceException.errors.deleteConsistencyGroupFailed("doDeleteConsistencyGroup", errorMsg);
            taskCompleter.error(dbClient, serviceError);
        }
    } catch (Exception e) {
        String errorMsg = String.format("doDeleteConsistencyGroup -- Failed to delete Consistency Group: %s .", e.getMessage());
        _log.error(errorMsg, e);
        ServiceError serviceError = ExternalDeviceException.errors.deleteConsistencyGroupFailed("doDeleteConsistencyGroup", errorMsg);
        taskCompleter.error(dbClient, serviceError);
    } finally {
        _log.info("Delete consistency group: END...");
    }
}
Also used : VolumeConsistencyGroup(com.emc.storageos.storagedriver.model.VolumeConsistencyGroup) DriverTask(com.emc.storageos.storagedriver.DriverTask) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) StringSet(com.emc.storageos.db.client.model.StringSet) URI(java.net.URI) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) IOException(java.io.IOException) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup)

Example 9 with DriverTask

use of com.emc.storageos.storagedriver.DriverTask in project coprhd-controller by CoprHD.

the class ExternalBlockStorageDevice method deleteGroupSnapshots.

private void deleteGroupSnapshots(StorageSystem storageSystem, List<BlockSnapshot> groupSnapshots, TaskCompleter taskCompleter) {
    _log.info("Deleting snapshot of consistency group. Snapshots: " + Joiner.on("\t").join(groupSnapshots));
    URI cgUri = groupSnapshots.get(0).getConsistencyGroup();
    BlockConsistencyGroup consistencyGroup = dbClient.queryObject(BlockConsistencyGroup.class, cgUri);
    List<VolumeSnapshot> driverSnapshots = new ArrayList<>();
    for (BlockSnapshot blockSnapshot : groupSnapshots) {
        VolumeSnapshot driverSnapshot = new VolumeSnapshot();
        driverSnapshot.setStorageSystemId(storageSystem.getNativeId());
        driverSnapshot.setNativeId(blockSnapshot.getNativeId());
        driverSnapshot.setConsistencyGroup(blockSnapshot.getReplicationGroupInstance());
        Volume parent = dbClient.queryObject(Volume.class, blockSnapshot.getParent().getURI());
        driverSnapshot.setParentId(parent.getNativeId());
        driverSnapshots.add(driverSnapshot);
    }
    // call driver
    BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
    DriverTask task = driver.deleteConsistencyGroupSnapshot(Collections.unmodifiableList(driverSnapshots));
    // todo: need to implement support for async case.
    if (task.getStatus() == DriverTask.TaskStatus.READY) {
        // update snapshots
        for (BlockSnapshot blockSnapshot : groupSnapshots) {
            blockSnapshot.setInactive(true);
        }
        dbClient.updateObject(groupSnapshots);
        String msg = String.format("deleteGroupSnapshots -- Deleted group snapshot: %s .", task.getMessage());
        _log.info(msg);
        taskCompleter.ready(dbClient);
    } else {
        String errorMsg = String.format("doDeleteSnapshot -- Failed to delete group snapshot: %s .", task.getMessage());
        _log.error(errorMsg);
        ServiceError serviceError = ExternalDeviceException.errors.deleteGroupSnapshotFailed("doDeleteSnapshot", errorMsg);
        taskCompleter.error(dbClient, serviceError);
    }
}
Also used : DriverTask(com.emc.storageos.storagedriver.DriverTask) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) Volume(com.emc.storageos.db.client.model.Volume) ArrayList(java.util.ArrayList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) URI(java.net.URI) VolumeSnapshot(com.emc.storageos.storagedriver.model.VolumeSnapshot) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup)

Example 10 with DriverTask

use of com.emc.storageos.storagedriver.DriverTask in project coprhd-controller by CoprHD.

the class ExternalBlockStorageDevice method deleteVolumeSnapshot.

private void deleteVolumeSnapshot(StorageSystem storageSystem, URI snapshot, TaskCompleter taskCompleter) {
    BlockSnapshot blockSnapshot = dbClient.queryObject(BlockSnapshot.class, snapshot);
    if (blockSnapshot != null && !blockSnapshot.getInactive() && // state against the BlockSnapshot object can be set.
    !Strings.isNullOrEmpty(blockSnapshot.getNativeId())) {
        _log.info("Deleting snapshot of a volume. Snapshot: {}", snapshot);
        Volume parent = dbClient.queryObject(Volume.class, blockSnapshot.getParent().getURI());
        VolumeSnapshot driverSnapshot = new VolumeSnapshot();
        driverSnapshot.setStorageSystemId(storageSystem.getNativeId());
        driverSnapshot.setNativeId(blockSnapshot.getNativeId());
        driverSnapshot.setParentId(parent.getNativeId());
        driverSnapshot.setConsistencyGroup(blockSnapshot.getReplicationGroupInstance());
        // call driver
        BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
        DriverTask task = driver.deleteVolumeSnapshot(driverSnapshot);
        // todo: need to implement support for async case.
        if (task.getStatus() == DriverTask.TaskStatus.READY) {
            // update snapshots
            blockSnapshot.setInactive(true);
            dbClient.updateObject(blockSnapshot);
            String msg = String.format("deleteVolumeSnapshot -- Deleted snapshot: %s .", task.getMessage());
            _log.info(msg);
            taskCompleter.ready(dbClient);
        } else {
            String errorMsg = String.format("doDeleteSnapshot -- Failed to delete snapshot: %s .", task.getMessage());
            _log.error(errorMsg);
            ServiceError serviceError = ExternalDeviceException.errors.deleteSnapshotFailed("doDeleteSnapshot", errorMsg);
            taskCompleter.error(dbClient, serviceError);
        }
    } else if (blockSnapshot != null) {
        blockSnapshot.setInactive(true);
        dbClient.updateObject(blockSnapshot);
        String msg = String.format("deleteVolumeSnapshot -- Deleted snapshot: %s .", blockSnapshot.getId());
        _log.info(msg);
        taskCompleter.ready(dbClient);
    }
}
Also used : DriverTask(com.emc.storageos.storagedriver.DriverTask) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) Volume(com.emc.storageos.db.client.model.Volume) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) VolumeSnapshot(com.emc.storageos.storagedriver.model.VolumeSnapshot) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver)

Aggregations

DriverTask (com.emc.storageos.storagedriver.DriverTask)80 BlockStorageDriver (com.emc.storageos.storagedriver.BlockStorageDriver)26 StorageVolume (com.emc.storageos.storagedriver.model.StorageVolume)26 ArrayList (java.util.ArrayList)26 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)22 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)21 Volume (com.emc.storageos.db.client.model.Volume)15 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)15 IOException (java.io.IOException)15 URI (java.net.URI)15 HashMap (java.util.HashMap)13 DellSCDriverTask (com.emc.storageos.driver.dellsc.DellSCDriverTask)10 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)9 HashSet (java.util.HashSet)9 VolumeClone (com.emc.storageos.storagedriver.model.VolumeClone)7 VolumeSnapshot (com.emc.storageos.storagedriver.model.VolumeSnapshot)7 BlockObject (com.emc.storageos.db.client.model.BlockObject)6 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)6 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)6 ExportMask (com.emc.storageos.db.client.model.ExportMask)6