Search in sources :

Example 96 with BlockSnapshot

use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.

the class BlockSnapshotDeleteCompleter method createCompleter.

/**
 * This method is for creating the BlockSnapshotDeleteCompleter. This a bit unique from
 * the other completers because of the way that we need to complete the task. For the
 * case of CG snapshots, there will be multiple BlockSnapshots associated, even though
 * the request to delete the snapshot was against only one of the CG snaps. Here we will
 * make sure that the task completer has references to all the CG snaps, so that they
 * can be referred to in the completer. Main reason is that if a BlockSnapshot is marked
 * inactive, it can no longer be retrieved using AltIndex queries.
 *
 * @param dbClient [in] - DbClient for querying ViPR DB
 * @param snapshot [in] - BlockSnapshot object
 * @param task [in] - Task UUID for the snapshot delete operation
 * @return a new BlockSnapshotDeleteCompleter object
 */
public static BlockSnapshotDeleteCompleter createCompleter(DbClient dbClient, BlockSnapshot snapshot, String task) {
    BlockSnapshotDeleteCompleter completer = new BlockSnapshotDeleteCompleter(snapshot, task);
    if (snapshot.getConsistencyGroup() != null) {
        // For snapshot based on a consistency group, set status and send
        // events for all related snaps
        List<URI> snapIds = new ArrayList<URI>();
        List<BlockSnapshot> snaps = ControllerUtils.getSnapshotsPartOfReplicationGroup(snapshot, dbClient);
        for (BlockSnapshot snap : snaps) {
            snapIds.add(snap.getId());
        }
        completer.addIds(snapIds);
    }
    return completer;
}
Also used : ArrayList(java.util.ArrayList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) URI(java.net.URI)

Example 97 with BlockSnapshot

use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.

the class BlockSnapshotRestoreCompleter method complete.

@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
    try {
        BlockSnapshot snapshot = dbClient.queryObject(BlockSnapshot.class, getId());
        Volume volume = dbClient.queryObject(Volume.class, snapshot.getParent());
        if (_updateAndRecordOp) {
            if (snapshot.getConsistencyGroup() != null) {
                // For snapshot based on a consistency group, set status and send
                // events for all related snaps
                List<BlockSnapshot> snaps = ControllerUtils.getSnapshotsPartOfReplicationGroup(snapshot, dbClient);
                for (BlockSnapshot snap : snaps) {
                    URI uri = snap.getId();
                    BlockSnapshot it = dbClient.queryObject(BlockSnapshot.class, uri);
                    switch(status) {
                        case error:
                            dbClient.error(BlockSnapshot.class, uri, getOpId(), coded);
                            break;
                        default:
                            dbClient.ready(BlockSnapshot.class, uri, getOpId());
                    }
                    recordBlockSnapshotOperation(dbClient, OperationTypeEnum.RESTORE_VOLUME_SNAPSHOT, status, eventMessage(status, volume, it), it, volume);
                    _log.info(String.format("Completed CG snapshot restore of snap %s (%s), with status %s", it.getLabel(), uri.toString(), status.name()));
                }
            } else {
                switch(status) {
                    case error:
                        dbClient.error(BlockSnapshot.class, getId(), getOpId(), coded);
                        break;
                    default:
                        dbClient.ready(BlockSnapshot.class, getId(), getOpId());
                }
                recordBlockSnapshotOperation(dbClient, OperationTypeEnum.RESTORE_VOLUME_SNAPSHOT, status, eventMessage(status, volume, snapshot), snapshot, volume);
            }
        }
        _log.info("Done SnapshotRestore {}, with Status: {}", getOpId(), status.name());
        super.complete(dbClient, status, coded);
    } catch (Exception e) {
        _log.error("Failed updating status. SnapshotRestore {}, for task " + getOpId(), getId(), e);
    }
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) URI(java.net.URI) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 98 with BlockSnapshot

use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.

the class BlockSnapshotResyncCompleter method complete.

@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
    try {
        BlockSnapshot snapshot = dbClient.queryObject(BlockSnapshot.class, getId());
        Volume volume = dbClient.queryObject(Volume.class, snapshot.getParent());
        if (_updateAndRecordOp) {
            if (snapshot.getConsistencyGroup() != null) {
                // For snapshot based on a consistency group, set status and send
                // events for all related snaps
                List<BlockSnapshot> snaps = ControllerUtils.getSnapshotsPartOfReplicationGroup(snapshot, dbClient);
                for (BlockSnapshot snap : snaps) {
                    URI uri = snap.getId();
                    BlockSnapshot it = dbClient.queryObject(BlockSnapshot.class, uri);
                    switch(status) {
                        case error:
                            dbClient.error(BlockSnapshot.class, uri, getOpId(), coded);
                            break;
                        default:
                            dbClient.ready(BlockSnapshot.class, uri, getOpId());
                    }
                    recordBlockSnapshotOperation(dbClient, OperationTypeEnum.RESYNCHRONIZE_VOLUME_SNAPSHOT, status, eventMessage(status, volume, it), it, volume);
                    _log.info(String.format("Completed CG snapshot resynchronization of snap %s (%s), with status %s", it.getLabel(), uri.toString(), status.name()));
                }
            } else {
                switch(status) {
                    case error:
                        dbClient.error(BlockSnapshot.class, getId(), getOpId(), coded);
                        break;
                    default:
                        dbClient.ready(BlockSnapshot.class, getId(), getOpId());
                }
                recordBlockSnapshotOperation(dbClient, OperationTypeEnum.RESYNCHRONIZE_VOLUME_SNAPSHOT, status, eventMessage(status, volume, snapshot), snapshot, volume);
            }
        }
        _log.info("Done Resync Snapshot {}, with Status: {}", getOpId(), status.name());
        super.complete(dbClient, status, coded);
    } catch (Exception e) {
        _log.error("Failed updating status. SnapshotResync {}, for task " + getOpId(), getId(), e);
    }
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) URI(java.net.URI) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 99 with BlockSnapshot

use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.

the class BlockSnapshotSessionCompleter method getAllSnapshots.

/**
 * When this completer is handling multiple snapshots from different replication groups,
 * this method gathers all related snapshots for each snapshot and returns them in a list.
 *
 * @param dbClient  Database client.
 * @return          List of all snapshots, including each of their related snapshots.
 */
public List<BlockSnapshot> getAllSnapshots(DbClient dbClient) {
    List<BlockSnapshot> result = new ArrayList<>();
    Iterator<BlockSnapshot> iterator = dbClient.queryIterativeObjects(BlockSnapshot.class, _snapshotURIs);
    while (iterator.hasNext()) {
        BlockSnapshot snapshot = iterator.next();
        result.addAll(getRelatedSnapshots(snapshot, dbClient));
    }
    return result;
}
Also used : BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ArrayList(java.util.ArrayList)

Example 100 with BlockSnapshot

use of com.emc.storageos.db.client.model.BlockSnapshot in project coprhd-controller by CoprHD.

the class BlockSnapshotSessionCreateCompleter method complete.

/**
 * {@inheritDoc}
 */
@Override
protected void complete(DbClient dbClient, Status status, ServiceCoded coded) throws DeviceControllerException {
    try {
        BlockSnapshotSession snapSession = dbClient.queryObject(BlockSnapshotSession.class, getId());
        // Update the status map of the snapshot session.
        switch(status) {
            case error:
                // Mark any linked targets inactive. This would not
                // normally case when failing to create a snapshot
                // session as targets are not linked when a new
                // snapshot session is prepared in ViPR. However,
                // it could be the case when restoring a source volume
                // form a linked target.
                StringSet linkedTargets = snapSession.getLinkedTargets();
                if ((linkedTargets != null) && (!linkedTargets.isEmpty())) {
                    for (String linkedTarget : linkedTargets) {
                        BlockSnapshot target = dbClient.queryObject(BlockSnapshot.class, URI.create(linkedTarget));
                        if (target != null) {
                            target.setInactive(true);
                            dbClient.updateObject(target);
                        }
                    }
                }
                // Mark ViPR snapshot session inactive on error.
                snapSession.setInactive(true);
                dbClient.updateObject(snapSession);
                break;
            case ready:
                break;
            default:
                String errMsg = String.format("Unexpected status %s for completer for step %s", status.name(), getOpId());
                s_logger.info(errMsg);
                throw DeviceControllerException.exceptions.unexpectedCondition(errMsg);
        }
        s_logger.info("Done snapshot session create step {} with status: {}", getOpId(), status.name());
    } catch (Exception e) {
        s_logger.error("Failed updating status for snapshot session create step {}", getOpId(), e);
    } finally {
        super.complete(dbClient, status, coded);
    }
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) StringSet(com.emc.storageos.db.client.model.StringSet) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Aggregations

BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)401 Volume (com.emc.storageos.db.client.model.Volume)215 URI (java.net.URI)209 ArrayList (java.util.ArrayList)112 NamedURI (com.emc.storageos.db.client.model.NamedURI)110 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)106 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)91 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)63 BlockObject (com.emc.storageos.db.client.model.BlockObject)63 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)55 CIMObjectPath (javax.cim.CIMObjectPath)51 StringSet (com.emc.storageos.db.client.model.StringSet)49 HashMap (java.util.HashMap)48 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)46 BlockSnapshotSession (com.emc.storageos.db.client.model.BlockSnapshotSession)41 WBEMException (javax.wbem.WBEMException)38 Produces (javax.ws.rs.Produces)36 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)35 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)33 Path (javax.ws.rs.Path)33