Search in sources :

Example 6 with VolumeSnapshot

use of com.emc.storageos.storagedriver.model.VolumeSnapshot 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)

Example 7 with VolumeSnapshot

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

the class ExternalBlockStorageDevice method createVolumeSnapshots.

private void createVolumeSnapshots(StorageSystem storageSystem, List<BlockSnapshot> snapshots, Boolean createInactive, Boolean readOnly, TaskCompleter taskCompleter) {
    _log.info("Creating snapshots for volumes.....");
    List<VolumeSnapshot> driverSnapshots = new ArrayList<>();
    Map<VolumeSnapshot, BlockSnapshot> driverSnapshotToSnapshotMap = new HashMap<>();
    // 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);
    }
    // call driver
    BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
    DriverTask task = driver.createVolumeSnapshot(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);
            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("createVolumeSnapshots -- 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 : DriverTask(com.emc.storageos.storagedriver.DriverTask) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) HashMap(java.util.HashMap) 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) VolumeSnapshot(com.emc.storageos.storagedriver.model.VolumeSnapshot) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver)

Example 8 with VolumeSnapshot

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

the class DellSCStorageDriver method deleteConsistencyGroupSnapshot.

/**
 * Delete a consistency group snapshot set.
 *
 * @param snapshots The snapshots to delete.
 * @return The delete task.
 */
@Override
public DriverTask deleteConsistencyGroupSnapshot(List<VolumeSnapshot> snapshots) {
    LOG.info("Deleting consistency group snapshot");
    DellSCDriverTask task = new DellSCDriverTask("deleteConsistencyGroupSnapshot");
    StringBuilder errBuffer = new StringBuilder();
    int deletedCount = 0;
    for (VolumeSnapshot snapshot : snapshots) {
        DriverTask subTask = snapshotHelper.deleteVolumeSnapshot(snapshot);
        if (subTask.getStatus() == TaskStatus.FAILED) {
            errBuffer.append(String.format("%s%n", subTask.getMessage()));
        } else {
            deletedCount++;
        }
    }
    task.setMessage(errBuffer.toString());
    if (deletedCount == snapshots.size()) {
        task.setStatus(TaskStatus.READY);
    } else if (deletedCount == 0) {
        task.setStatus(TaskStatus.FAILED);
    } else {
        task.setStatus(TaskStatus.PARTIALLY_FAILED);
    }
    return task;
}
Also used : DriverTask(com.emc.storageos.storagedriver.DriverTask) VolumeSnapshot(com.emc.storageos.storagedriver.model.VolumeSnapshot)

Example 9 with VolumeSnapshot

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

the class DellSCConsistencyGroups method populateCgSnapshotInfo.

/**
 * Populates VolumeSnapshot info from CG created replays.
 *
 * @param snapshots The expected VolumeSnapshot objects.
 * @param replays The created replays.
 * @return True if successful, false if errors encountered.
 */
private boolean populateCgSnapshotInfo(List<VolumeSnapshot> snapshots, ScReplay[] replays) {
    boolean complete = true;
    for (VolumeSnapshot snapshot : snapshots) {
        boolean found = false;
        for (ScReplay replay : replays) {
            if (replay.instanceId.startsWith(snapshot.getParentId())) {
                // Found match, populate the info
                util.getVolumeSnapshotFromReplay(replay, snapshot);
                found = true;
                break;
            }
        }
        if (!found) {
            complete = false;
            LOG.warn("Unable to find snapshot for {}", snapshot.getDisplayName());
        }
    }
    return complete;
}
Also used : ScReplay(com.emc.storageos.driver.dellsc.scapi.objects.ScReplay) VolumeSnapshot(com.emc.storageos.storagedriver.model.VolumeSnapshot)

Example 10 with VolumeSnapshot

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

the class DellSCDiscovery method getVolumeSnapshots.

/**
 * Gets all snapshots for a volume.
 *
 * @param storageVolume The volume.
 * @return The snapshots.
 */
public List<VolumeSnapshot> getVolumeSnapshots(StorageVolume storageVolume) {
    LOG.info("Getting snapshots for {}", storageVolume.getNativeId());
    List<VolumeSnapshot> result = new ArrayList<>();
    try {
        StorageCenterAPI api = connectionManager.getConnection(storageVolume.getStorageSystemId());
        ScReplay[] replays = api.getVolumeSnapshots(storageVolume.getNativeId());
        for (ScReplay replay : replays) {
            VolumeSnapshot snap = util.getVolumeSnapshotFromReplay(replay, null);
            result.add(snap);
        }
    } catch (DellSCDriverException e) {
        String msg = String.format("Error getting volume info: %s", e);
        LOG.warn(msg);
    }
    return result;
}
Also used : StorageCenterAPI(com.emc.storageos.driver.dellsc.scapi.StorageCenterAPI) DellSCDriverException(com.emc.storageos.driver.dellsc.DellSCDriverException) ArrayList(java.util.ArrayList) ScReplay(com.emc.storageos.driver.dellsc.scapi.objects.ScReplay) VolumeSnapshot(com.emc.storageos.storagedriver.model.VolumeSnapshot)

Aggregations

VolumeSnapshot (com.emc.storageos.storagedriver.model.VolumeSnapshot)22 DriverTask (com.emc.storageos.storagedriver.DriverTask)8 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)7 StorageVolume (com.emc.storageos.storagedriver.model.StorageVolume)7 ArrayList (java.util.ArrayList)7 Volume (com.emc.storageos.db.client.model.Volume)6 BlockStorageDriver (com.emc.storageos.storagedriver.BlockStorageDriver)5 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)5 URI (java.net.URI)4 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)3 ScReplay (com.emc.storageos.driver.dellsc.scapi.objects.ScReplay)3 VolumeDetailsCommandResult (com.emc.storageos.hp3par.command.VolumeDetailsCommandResult)3 UnManagedVolume (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume)2 DellSCDriverException (com.emc.storageos.driver.dellsc.DellSCDriverException)2 StorageCenterAPI (com.emc.storageos.driver.dellsc.scapi.StorageCenterAPI)2 VolumeClone (com.emc.storageos.storagedriver.model.VolumeClone)2 HashMap (java.util.HashMap)2 StringSet (com.emc.storageos.db.client.model.StringSet)1 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1