Search in sources :

Example 31 with BlockSnapshotSession

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

the class BlockSnapshotCleanup method process.

/**
 * Cleans up instances of {@link BlockSnapshot} that failed to be created. Also, any stale entries in
 * {@link BlockSnapshotSession#getLinkedTargets()} will be cleaned up.
 *
 * @param volume        Volume URI to process.
 * @param itemsToUpdate Items to be updated.
 * @param itemsToDelete Items to be deleted.
 */
@Override
public void process(URI volume, Collection<DataObject> itemsToUpdate, Collection<DataObject> itemsToDelete) {
    List<BlockSnapshot> snapshots = CustomQueryUtility.queryActiveResourcesByConstraint(getDbClient(), BlockSnapshot.class, ContainmentConstraint.Factory.getVolumeSnapshotConstraint(volume));
    List<BlockSnapshot> failedSnapshots = new ArrayList<>();
    List<BlockSnapshotSession> updateSessions = new ArrayList<>();
    failedSnapshots.addAll(Collections2.filter(snapshots, new Predicate<BlockSnapshot>() {

        @Override
        public boolean apply(BlockSnapshot snapshot) {
            return Strings.isNullOrEmpty(snapshot.getNativeId());
        }
    }));
    // Removed failed snapshots from any existing sessions
    for (BlockSnapshot failedSnapshot : failedSnapshots) {
        log.info("Removing failed snapshot: {}", failedSnapshot.getLabel());
        List<BlockSnapshotSession> sessions = CustomQueryUtility.queryActiveResourcesByConstraint(getDbClient(), BlockSnapshotSession.class, ContainmentConstraint.Factory.getLinkedTargetSnapshotSessionConstraint(failedSnapshot.getId()));
        for (BlockSnapshotSession session : sessions) {
            log.info("Updating existing session: {}", session.getSessionLabel());
            StringSet linkedTargets = session.getLinkedTargets();
            linkedTargets.remove(failedSnapshot.getId().toString());
            updateSessions.add(session);
        }
    }
    itemsToUpdate.addAll(updateSessions);
    itemsToDelete.addAll(failedSnapshots);
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ArrayList(java.util.ArrayList) StringSet(com.emc.storageos.db.client.model.StringSet) Predicate(com.google.common.base.Predicate)

Example 32 with BlockSnapshotSession

use of com.emc.storageos.db.client.model.BlockSnapshotSession 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)

Example 33 with BlockSnapshotSession

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

the class BlockSnapshotSessionDeleteWorkflowCompleter method complete.

/**
 * {@inheritDoc}
 */
@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
    URI snapSessionURI = getId();
    try {
        BlockSnapshotSession snapSession = dbClient.queryObject(BlockSnapshotSession.class, snapSessionURI);
        List<BlockObject> allSources = getAllSources(snapSession, dbClient);
        BlockObject sourceObj = allSources.get(0);
        // Record the results.
        recordBlockSnapshotSessionOperation(dbClient, OperationTypeEnum.DELETE_SNAPSHOT_SESSION, status, snapSession, sourceObj);
        // Update the status map of the snapshot session.
        switch(status) {
            case error:
                setErrorOnDataObject(dbClient, BlockSnapshotSession.class, snapSessionURI, coded);
                break;
            case suspended_error:
                setSuspendedErrorOnDataObject(dbClient, BlockSnapshotSession.class, snapSessionURI, coded);
                break;
            case suspended_no_error:
                setSuspendedNoErrorOnDataObject(dbClient, BlockSnapshotSession.class, snapSessionURI);
                break;
            case ready:
                setReadyOnDataObject(dbClient, BlockSnapshotSession.class, snapSessionURI);
                // Mark snapshot session inactive.
                snapSession.setInactive(true);
                dbClient.updateObject(snapSession);
                break;
            default:
                String errMsg = String.format("Unexpected status %s for completer for task %s", status.name(), getOpId());
                s_logger.info(errMsg);
                throw DeviceControllerException.exceptions.unexpectedCondition(errMsg);
        }
        s_logger.info("Done delete snapshot session task {} with status: {}", getOpId(), status.name());
    } catch (Exception e) {
        s_logger.error("Failed updating status for delete snapshot session task {}", getOpId(), e);
    } finally {
        super.complete(dbClient, status, coded);
    }
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 34 with BlockSnapshotSession

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

the class BlockSnapshotSessionRelinkTargetCompleter method complete.

/**
 * {@inheritDoc}
 */
@Override
protected void complete(DbClient dbClient, Status status, ServiceCoded coded) throws DeviceControllerException {
    try {
        switch(status) {
            case error:
                break;
            case ready:
                // Remove the linked targets from the linked targets list for their
                // current snapshot session and add them to the linked targets for
                // the target session.
                BlockSnapshotSession tgtSnapSession = dbClient.queryObject(BlockSnapshotSession.class, getId());
                StringSet tgtSnapSessionTargets = tgtSnapSession.getLinkedTargets();
                List<BlockSnapshotSession> snaphotSessionsList = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, BlockSnapshotSession.class, ContainmentConstraint.Factory.getLinkedTargetSnapshotSessionConstraint(_snapshotURI));
                if (snaphotSessionsList.isEmpty()) {
                    // The target is not linked to an active snapshot session.
                    throw DeviceControllerException.exceptions.unexpectedCondition(String.format("Cound not find active snapshot session for linked target %s", _snapshotURI));
                }
                // A target can only be linked to a single session.
                BlockSnapshotSession currentSnapSession = snaphotSessionsList.get(0);
                BlockSnapshot snapshot = dbClient.queryObject(BlockSnapshot.class, _snapshotURI);
                List<BlockSnapshot> relatedSnapshots = getRelatedSnapshots(snapshot, dbClient);
                for (BlockSnapshot relatedSnapshot : relatedSnapshots) {
                    // snapshot sessions.
                    if (!currentSnapSession.getId().equals(getId())) {
                        String snapshotId = relatedSnapshot.getId().toString();
                        // Remove from the current snapshot session.
                        StringSet currentSnapSessionTargets = currentSnapSession.getLinkedTargets();
                        currentSnapSessionTargets.remove(snapshotId);
                        dbClient.updateObject(currentSnapSession);
                        // Add to the target snapshot session.
                        if (tgtSnapSessionTargets == null) {
                            tgtSnapSessionTargets = new StringSet();
                            tgtSnapSession.setLinkedTargets(tgtSnapSessionTargets);
                        }
                        tgtSnapSessionTargets.add(snapshotId);
                        dbClient.updateObject(tgtSnapSession);
                    }
                }
                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 re-link target volume step {} with status: {}", getOpId(), status.name());
    } catch (Exception e) {
        s_logger.error("Failed updating status for re-link target volume 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)

Example 35 with BlockSnapshotSession

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

the class BlockSnapshotSessionRestoreWorkflowCompleter method complete.

/**
 * {@inheritDoc}
 */
@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
    URI snapSessionURI = getId();
    try {
        if (_updateOpStatus) {
            BlockSnapshotSession snapSession = dbClient.queryObject(BlockSnapshotSession.class, snapSessionURI);
            List<BlockObject> allSources = getAllSources(snapSession, dbClient);
            BlockObject sourceObj = allSources.get(0);
            // Record the results.
            recordBlockSnapshotSessionOperation(dbClient, OperationTypeEnum.RESTORE_SNAPSHOT_SESSION, status, snapSession, sourceObj);
            // Update the status map of the snapshot session.
            switch(status) {
                case error:
                    setErrorOnDataObject(dbClient, BlockSnapshotSession.class, snapSession.getId(), coded);
                    break;
                case ready:
                    setReadyOnDataObject(dbClient, BlockSnapshotSession.class, snapSession.getId());
                    break;
                case suspended_error:
                    setSuspendedErrorOnDataObject(dbClient, BlockSnapshotSession.class, snapSession.getId(), coded);
                    break;
                case suspended_no_error:
                    setSuspendedNoErrorOnDataObject(dbClient, BlockSnapshotSession.class, snapSession.getId());
                    break;
                default:
                    String errMsg = String.format("Unexpected status %s for completer for task %s", status.name(), getOpId());
                    s_logger.info(errMsg);
                    throw DeviceControllerException.exceptions.unexpectedCondition(errMsg);
            }
        }
        s_logger.info("Done restore snapshot session task {} with status: {}", getOpId(), status.name());
    } catch (Exception e) {
        s_logger.error("Failed updating status for restore snapshot session task {}", getOpId(), e);
    } finally {
        super.complete(dbClient, status, coded);
    }
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Aggregations

BlockSnapshotSession (com.emc.storageos.db.client.model.BlockSnapshotSession)112 URI (java.net.URI)64 Volume (com.emc.storageos.db.client.model.Volume)43 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)41 NamedURI (com.emc.storageos.db.client.model.NamedURI)38 ArrayList (java.util.ArrayList)33 BlockObject (com.emc.storageos.db.client.model.BlockObject)29 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)27 StringSet (com.emc.storageos.db.client.model.StringSet)25 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)17 HashMap (java.util.HashMap)17 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)16 CIMObjectPath (javax.cim.CIMObjectPath)13 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)12 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)11 NullColumnValueGetter.isNullURI (com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI)11 ServiceCoded (com.emc.storageos.svcs.errorhandling.model.ServiceCoded)11 DataObject (com.emc.storageos.db.client.model.DataObject)10 Project (com.emc.storageos.db.client.model.Project)10 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)10