Search in sources :

Example 76 with StringSet

use of com.emc.storageos.db.client.model.StringSet 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 77 with StringSet

use of com.emc.storageos.db.client.model.StringSet 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 78 with StringSet

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

the class BlockSnapshotSessionUnlinkTargetCompleter method processSnapshot.

private void processSnapshot(URI snapshotURI, DbClient dbClient) {
    BlockSnapshot snapshotObj = dbClient.queryObject(BlockSnapshot.class, snapshotURI);
    BlockSnapshotSession snapSession = dbClient.queryObject(BlockSnapshotSession.class, getId());
    StringSet linkedTargets = snapSession.getLinkedTargets();
    List<BlockSnapshot> snapshots = getRelatedSnapshots(snapshotObj, dbClient);
    for (BlockSnapshot snapshot : snapshots) {
        snapshot.setInactive(true);
        if ((linkedTargets != null) && (linkedTargets.contains(snapshot.getId().toString()))) {
            linkedTargets.remove(snapshot.getId().toString());
        }
    }
    // Note that even if the target is not deleted, mark the associated
    // BlockSnapshot inactive. Since the target is no longer associated
    // with an array snapshot, it is really no longer a BlockSnapshot
    // instance in ViPR. In the unlink job we have created a ViPR Volume
    // to represent the former snapshot target volume. So here we mark the
    // BlockSnapshot inactive so it is garbage collected.
    dbClient.updateObject(snapshots);
    dbClient.updateObject(snapSession);
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) StringSet(com.emc.storageos.db.client.model.StringSet)

Example 79 with StringSet

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

the class ApplicationTaskCompleter method removeApplicationFromVolume.

/**
 * Remove application from the volume applicationIds attribute
 * @param voluri The volumes that will be updated
 * @param dbClient
 */
protected void removeApplicationFromVolume(URI voluri, DbClient dbClient) {
    Volume volume = dbClient.queryObject(Volume.class, voluri);
    String appId = getId().toString();
    StringSet appIds = volume.getVolumeGroupIds();
    if (appIds != null) {
        appIds.remove(appId);
    }
    dbClient.updateObject(volume);
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) StringSet(com.emc.storageos.db.client.model.StringSet)

Example 80 with StringSet

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

the class BlockMirrorCreateCompleter method removeMirrorFromVolume.

private void removeMirrorFromVolume(URI mirrorId, Volume volume, DbClient dbClient) {
    StringSet mirrors = volume.getMirrors();
    if (mirrors == null) {
        _log.warn("Removing mirror {} from volume {} which had no mirrors", mirrorId, volume);
        return;
    }
    mirrors.remove(mirrorId.toString());
    volume.setMirrors(mirrors);
    // Persist changes
    dbClient.persistObject(volume);
}
Also used : StringSet(com.emc.storageos.db.client.model.StringSet)

Aggregations

StringSet (com.emc.storageos.db.client.model.StringSet)760 URI (java.net.URI)371 ArrayList (java.util.ArrayList)278 Volume (com.emc.storageos.db.client.model.Volume)189 NamedURI (com.emc.storageos.db.client.model.NamedURI)176 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)137 HashMap (java.util.HashMap)132 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)124 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)116 List (java.util.List)108 HashSet (java.util.HashSet)106 StoragePort (com.emc.storageos.db.client.model.StoragePort)90 StoragePool (com.emc.storageos.db.client.model.StoragePool)75 StringMap (com.emc.storageos.db.client.model.StringMap)74 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)71 UnManagedVolume (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume)70 Initiator (com.emc.storageos.db.client.model.Initiator)60 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)60 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)50 Map (java.util.Map)48