Search in sources :

Example 1 with DriverTask

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

the class ExternalBlockStorageDevice method createGroupSnapshots.

private void createGroupSnapshots(StorageSystem storageSystem, List<BlockSnapshot> snapshots, Boolean createInactive, Boolean readOnly, TaskCompleter taskCompleter) {
    _log.info("Creating snapshot of consistency group .....");
    List<VolumeSnapshot> driverSnapshots = new ArrayList<>();
    Map<VolumeSnapshot, BlockSnapshot> driverSnapshotToSnapshotMap = new HashMap<>();
    URI cgUri = snapshots.get(0).getConsistencyGroup();
    BlockConsistencyGroup consistencyGroup = dbClient.queryObject(BlockConsistencyGroup.class, cgUri);
    // Prepare driver snapshots
    String storageSystemNativeId = storageSystem.getNativeId();
    for (BlockSnapshot snapshot : snapshots) {
        Volume parent = dbClient.queryObject(Volume.class, snapshot.getParent().getURI());
        VolumeSnapshot driverSnapshot = new VolumeSnapshot();
        driverSnapshot.setParentId(parent.getNativeId());
        driverSnapshot.setStorageSystemId(storageSystemNativeId);
        driverSnapshot.setDisplayName(snapshot.getLabel());
        if (readOnly) {
            driverSnapshot.setAccessStatus(StorageObject.AccessStatus.READ_ONLY);
        } else {
            driverSnapshot.setAccessStatus(StorageObject.AccessStatus.READ_WRITE);
        }
        driverSnapshotToSnapshotMap.put(driverSnapshot, snapshot);
        driverSnapshots.add(driverSnapshot);
    }
    // Prepare driver consistency group of the parent volume
    VolumeConsistencyGroup driverCG = new VolumeConsistencyGroup();
    driverCG.setNativeId(consistencyGroup.getNativeId());
    driverCG.setDisplayName(consistencyGroup.getLabel());
    driverCG.setStorageSystemId(storageSystem.getNativeId());
    // call driver
    BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
    DriverTask task = driver.createConsistencyGroupSnapshot(driverCG, Collections.unmodifiableList(driverSnapshots), null);
    // todo: need to implement support for async case.
    if (task.getStatus() == DriverTask.TaskStatus.READY) {
        // update snapshots
        for (VolumeSnapshot driverSnapshot : driverSnapshotToSnapshotMap.keySet()) {
            BlockSnapshot snapshot = driverSnapshotToSnapshotMap.get(driverSnapshot);
            snapshot.setNativeId(driverSnapshot.getNativeId());
            snapshot.setDeviceLabel(driverSnapshot.getDeviceLabel());
            snapshot.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(storageSystem, snapshot));
            snapshot.setIsSyncActive(true);
            // we use driver snapshot consistency group id as replication group label for group snapshots
            snapshot.setReplicationGroupInstance(driverSnapshot.getConsistencyGroup());
            if (driverSnapshot.getProvisionedCapacity() > 0) {
                snapshot.setProvisionedCapacity(driverSnapshot.getProvisionedCapacity());
            }
            if (driverSnapshot.getAllocatedCapacity() > 0) {
                snapshot.setAllocatedCapacity(driverSnapshot.getAllocatedCapacity());
            }
        }
        dbClient.updateObject(driverSnapshotToSnapshotMap.values());
        String msg = String.format("createGroupSnapshots -- Created snapshots: %s .", task.getMessage());
        _log.info(msg);
        taskCompleter.ready(dbClient);
    } else {
        for (BlockSnapshot snapshot : snapshots) {
            snapshot.setInactive(true);
        }
        dbClient.updateObject(snapshots);
        String errorMsg = String.format("doCreateSnapshot -- Failed to create snapshots: %s .", task.getMessage());
        _log.error(errorMsg);
        ServiceError serviceError = ExternalDeviceException.errors.createSnapshotsFailed("doCreateSnapshot", errorMsg);
        taskCompleter.error(dbClient, serviceError);
    }
}
Also used : VolumeConsistencyGroup(com.emc.storageos.storagedriver.model.VolumeConsistencyGroup) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) URI(java.net.URI) 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) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver)

Example 2 with DriverTask

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

the class ExternalBlockStorageDevice method doRestoreFromGroupClone.

@Override
public void doRestoreFromGroupClone(StorageSystem storageSystem, List<URI> cloneVolumes, TaskCompleter taskCompleter) {
    BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
    DriverTask task = null;
    List<Volume> clones = dbClient.queryObject(Volume.class, cloneVolumes);
    _log.info("Restore from group clone on storage system {}, clones: {} .", storageSystem.getNativeId(), clones.toString());
    try {
        Map<VolumeClone, Volume> driverCloneToCloneMap = new HashMap<>();
        List<VolumeClone> driverClones = new ArrayList<>();
        for (Volume clone : clones) {
            BlockObject sourceVolume = BlockObject.fetch(dbClient, clone.getAssociatedSourceVolume());
            VolumeClone driverClone = new VolumeClone();
            driverClone.setStorageSystemId(storageSystem.getNativeId());
            driverClone.setNativeId(clone.getNativeId());
            driverClone.setParentId(sourceVolume.getNativeId());
            driverClone.setConsistencyGroup(clone.getReplicationGroupInstance());
            driverClones.add(driverClone);
            driverCloneToCloneMap.put(driverClone, clone);
        }
        // Call driver
        task = driver.restoreFromClone(Collections.unmodifiableList(driverClones));
        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 update the clone
            // volume replica state and call the completer as appropriate based on the result
            // of the request.
            RestoreFromGroupCloneExternalDeviceJob job = new RestoreFromGroupCloneExternalDeviceJob(storageSystem.getId(), cloneVolumes, task.getTaskId(), taskCompleter);
            ControllerServiceImpl.enqueueJob(new QueueJob(job));
        } else if (task.getStatus() == DriverTask.TaskStatus.READY) {
            for (Map.Entry<VolumeClone, Volume> entry : driverCloneToCloneMap.entrySet()) {
                VolumeClone driverClone = entry.getKey();
                Volume clone = entry.getValue();
                ExternalDeviceUtils.updateRestoredClone(clone, driverClone, dbClient, false);
            }
            String msg = String.format("doRestoreFromGroupClone -- Restore from group clone: %s .", task.getMessage());
            _log.info(msg);
            dbClient.updateObject(clones);
            taskCompleter.ready(dbClient);
        } else {
            String msg = String.format("Failed to restore from group clone on storage system %s, clones: %s .", storageSystem.getNativeId(), clones.toString());
            _log.error(msg);
            ServiceError serviceError = ExternalDeviceException.errors.restoreVolumesFromClonesFailed("doRestoreFromGroupClone", msg);
            taskCompleter.error(dbClient, serviceError);
        }
    } catch (Exception e) {
        String msg = String.format("Failed to restore from group clone on storage system %s, clones: %s .", storageSystem.getNativeId(), clones.toString());
        _log.error(msg, e);
        ServiceError serviceError = ExternalDeviceException.errors.restoreVolumesFromClonesFailed("doRestoreFromGroupClone", msg);
        taskCompleter.error(dbClient, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RestoreFromGroupCloneExternalDeviceJob(com.emc.storageos.volumecontroller.impl.externaldevice.job.RestoreFromGroupCloneExternalDeviceJob) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) IOException(java.io.IOException) DriverTask(com.emc.storageos.storagedriver.DriverTask) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) Volume(com.emc.storageos.db.client.model.Volume) VolumeClone(com.emc.storageos.storagedriver.model.VolumeClone) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver) BlockObject(com.emc.storageos.db.client.model.BlockObject) StorageBlockObject(com.emc.storageos.storagedriver.model.StorageBlockObject)

Example 3 with DriverTask

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

the class ExternalDeviceExportOperations method removeVolumes.

@Override
public void removeVolumes(StorageSystem storage, URI exportMaskUri, List<URI> volumeUris, List<com.emc.storageos.db.client.model.Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
    log.info("{} removeVolumes START...", storage.getSerialNumber());
    try {
        log.info("removeVolumes: Export mask id: {}", exportMaskUri);
        log.info("removeVolumes: volumes: {}", Joiner.on(',').join(volumeUris));
        if (initiatorList != null) {
            log.info("removeVolumes: impacted initiators: {}", Joiner.on(",").join(initiatorList));
        }
        BlockStorageDriver driver = externalDevice.getDriver(storage.getSystemType());
        ExportMask exportMask = (ExportMask) dbClient.queryObject(exportMaskUri);
        StringSet maskInitiators = exportMask.getInitiators();
        List<String> maskInitiatorList = new ArrayList<>();
        for (String initiatorUri : maskInitiators) {
            maskInitiatorList.add(initiatorUri);
        }
        log.info("Export mask existing initiators: {} ", Joiner.on(",").join(maskInitiatorList));
        // Prepare volumes. We send to driver only new volumes for the export mask.
        List<StorageVolume> driverVolumes = new ArrayList<>();
        prepareVolumes(storage, volumeUris, driverVolumes);
        // Prepare initiators
        Set<com.emc.storageos.db.client.model.Initiator> initiators = ExportMaskUtils.getInitiatorsForExportMask(dbClient, exportMask, null);
        List<Initiator> driverInitiators = new ArrayList<>();
        // Get export group uri from task completer
        URI exportGroupUri = taskCompleter.getId();
        ExportGroup exportGroup = (ExportGroup) dbClient.queryObject(exportGroupUri);
        prepareInitiators(initiators, exportGroup.forCluster(), driverInitiators);
        // Ready to call driver
        DriverTask task = driver.unexportVolumesFromInitiators(driverInitiators, driverVolumes);
        // todo: need to implement support for async case.
        if (task.getStatus() == DriverTask.TaskStatus.READY) {
            String msg = String.format("Removed volumes from export: %s.", task.getMessage());
            log.info(msg);
            taskCompleter.ready(dbClient);
        } else {
            String errorMsg = String.format("Failed to remove volumes from export mask: %s .", task.getMessage());
            log.error(errorMsg);
            ServiceError serviceError = ExternalDeviceException.errors.deleteVolumesFromExportMaskFailed("removeVolumes", errorMsg);
            taskCompleter.error(dbClient, serviceError);
        }
    } catch (Exception ex) {
        log.error("Problem in removeVolumes: ", ex);
        String errorMsg = String.format("Failed to remove volumes from export mask: %s .", ex.getMessage());
        log.error(errorMsg);
        ServiceError serviceError = ExternalDeviceException.errors.deleteVolumesFromExportMaskFailed("removeVolumes", errorMsg);
        taskCompleter.error(dbClient, serviceError);
    }
    log.info("{} removeVolumes END...", storage.getSerialNumber());
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) URI(java.net.URI) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) DriverTask(com.emc.storageos.storagedriver.DriverTask) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) Initiator(com.emc.storageos.storagedriver.model.Initiator) StringSet(com.emc.storageos.db.client.model.StringSet) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver)

Example 4 with DriverTask

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

the class ExternalDeviceJob method poll.

/**
 * {@inheritDoc}
 */
public JobPollResult poll(JobContext jobContext, long trackingPeriodInMillis) {
    s_logger.info("Polled external device job for driver task {} on storage system {}", _driverTaskId, _storageSystemURI);
    DriverTask driverTask = null;
    DbClient dbClient = jobContext.getDbClient();
    try {
        // Update the job info.
        _pollResult.setJobName(_driverTaskId);
        _pollResult.setJobId(_driverTaskId);
        _pollResult.setJobPercentComplete(0);
        // Get the external storage system on which the driver task is running.
        StorageSystem storageSystem = dbClient.queryObject(StorageSystem.class, _storageSystemURI);
        if (storageSystem == null) {
            s_logger.error("Could not find external storage system {}", _storageSystemURI);
            throw ExternalDeviceException.exceptions.cantFindStorageSystemForDriverTask(_storageSystemURI.toString(), _driverTaskId);
        }
        String systemType = storageSystem.getSystemType();
        // Get the external storage driver for the system on which the task is executing.
        BlockStorageDriver driver = ExternalBlockStorageDevice.getBlockStorageDriver(systemType);
        if (driver == null) {
            s_logger.error("Could not find storage driver for system type {}", systemType);
            throw ExternalDeviceException.exceptions.noDriverDefinedForDevice(systemType);
        }
        // Get the storage driver task.
        driverTask = driver.getTask(_driverTaskId);
        if (driverTask == null) {
            s_logger.error("Could not find storage driver task {} for storage system {}", _driverTaskId, _storageSystemURI.toString());
            throw ExternalDeviceException.exceptions.cantFindDriverTaskOnSystem(_driverTaskId, _storageSystemURI.toString());
        }
        TaskStatus taskStatus = driverTask.getStatus();
        String taskStatusMsg = driverTask.getMessage();
        if (isTaskSuccessful(taskStatus)) {
            // Completed successfully
            s_logger.info(String.format("Task %s completed successfully with status %s:%s", _driverTaskId, taskStatus, taskStatusMsg));
            doTaskSucceeded(driverTask, dbClient);
            _pollResult.setJobPercentComplete(100);
            _status = JobStatus.SUCCESS;
        } else if (isTaskFailed(taskStatus)) {
            // Failed.
            s_logger.info(String.format("Task %s failed with status %s:%s", _driverTaskId, taskStatus, taskStatusMsg));
            doTaskFailed(driverTask, dbClient);
            _pollResult.setJobPercentComplete(100);
            _errorDescription = taskStatusMsg;
            _status = JobStatus.FAILED;
        }
    } catch (Exception e) {
        _errorDescription = e.getMessage();
        s_logger.error(String.format("Unexpected error getting external driver task status for task %s on storage system %s: %s", _driverTaskId, _storageSystemURI.toString(), _errorDescription), e);
        try {
            doTaskFailed(driverTask, dbClient);
        } catch (Exception dtfe) {
            s_logger.error("Unexpected error handling task failed", e);
        }
        _status = JobStatus.FAILED;
    } finally {
        updateStatus(dbClient);
    }
    _pollResult.setJobStatus(_status);
    _pollResult.setErrorDescription(_errorDescription);
    return _pollResult;
}
Also used : DriverTask(com.emc.storageos.storagedriver.DriverTask) DbClient(com.emc.storageos.db.client.DbClient) TaskStatus(com.emc.storageos.storagedriver.DriverTask.TaskStatus) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver) ExternalDeviceException(com.emc.storageos.volumecontroller.impl.externaldevice.ExternalDeviceException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 5 with DriverTask

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

the class ExternalBlockStorageDevice method doRemoveFromConsistencyGroup.

@Override
public void doRemoveFromConsistencyGroup(StorageSystem storageSystem, URI consistencyGroupId, List<URI> blockObjects, TaskCompleter taskCompleter) throws DeviceControllerException {
    BlockConsistencyGroup consistencyGroup = null;
    try {
        _log.info("{} doRemoveVolumesFromConsistencyGroup START ...", storageSystem.getSerialNumber());
        BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
        List<Volume> volumes = dbClient.queryObject(Volume.class, blockObjects);
        List<StorageVolume> driverVolumes = new ArrayList<>();
        consistencyGroup = dbClient.queryObject(BlockConsistencyGroup.class, consistencyGroupId);
        for (Volume volume : volumes) {
            StorageVolume driverVolume = new StorageVolume();
            driverVolume.setStorageSystemId(storageSystem.getNativeId());
            driverVolume.setNativeId(volume.getNativeId());
            driverVolume.setRequestedCapacity(volume.getCapacity());
            driverVolume.setThinlyProvisioned(volume.getThinlyProvisioned());
            driverVolume.setConsistencyGroup(consistencyGroup.getNativeId());
            driverVolume.setDisplayName(volume.getLabel());
            // add them to StorageVolumes list
            driverVolumes.add(driverVolume);
        }
        DriverTask task = driver.removeVolumesFromConsistencyGroup(driverVolumes, null);
        _log.info("doRemoveVolumesFromConsistencyGroup -- removing volumes {} from consistency Group: {}", volumes.toString(), consistencyGroupId);
        if (task.getStatus() == DriverTask.TaskStatus.READY) {
            for (Volume volume : volumes) {
                volume.setConsistencyGroup(NullColumnValueGetter.getNullURI());
            }
            dbClient.updateObject(volumes);
            taskCompleter.ready(dbClient);
        } else {
            _log.error(String.format("Remove volumes from Consistency Group operation failed %s", task.getMessage()));
            taskCompleter.error(dbClient, DeviceControllerException.exceptions.failedToRemoveMembersToConsistencyGroup(consistencyGroup.getLabel(), consistencyGroup.getLabel(), task.getMessage()));
        }
        _log.info("{} doRemoveVolumesFromConsistencyGroup END ...", storageSystem.getSerialNumber());
    } catch (Exception e) {
        _log.error(String.format("Remove volumes from Consistency Group operation failed %s", e.getMessage()));
        taskCompleter.error(dbClient, DeviceControllerException.exceptions.failedToRemoveMembersToConsistencyGroup(consistencyGroup.getLabel(), consistencyGroup.getLabel(), e.getMessage()));
    }
}
Also used : DriverTask(com.emc.storageos.storagedriver.DriverTask) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) Volume(com.emc.storageos.db.client.model.Volume) ArrayList(java.util.ArrayList) 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)

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