Search in sources :

Example 91 with BlockSnapshot

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

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

the class ExternalDeviceUnManagedVolumeDiscoverer method processUnManagedSnapshots.

/**
 * Process snapshots of unManaged volume.
 * Check if unManaged snapshot should be created and create unManaged volume instance for a snapshot in such a case.
 * Add unManaged snapshot to parent volume CG if needed and update the snap with parent volume CG information.
 * Gets export information for snapshots and stores it in the provided map.
 *
 * @param driverVolume              driver volume for snap parent volume. [IN]
 * @param unManagedParentVolume     unManaged parent volume [IN/OUT]
 * @param storageSystem             storage system [IN]
 * @param storagePool               storage pool [IN]
 * @param unManagedVolumesToCreate  list of unmanaged volumes to create [OUT]
 * @param unManagedVolumesToUpdate  list of unmanaged volumes to update [OUT]
 * @param allCurrentUnManagedCgURIs set of unManaged CG uris found in the current discovery [OUT]
 * @param unManagedCGToUpdateMap    map of unManaged CG GUID to unManaged CG instance [IN/OUT]
 * @param unManagedVolumeNativeIdToUriMap map of unmanaged volumes nativeId to their uri [OUT]
 * @param hostToUnManagedVolumeExportInfoMap map  with export data for unmanaged volumes (including snaps and clones)
 * @param driver                    storage driver [IN]
 * @param dbClient                  reference to db client [IN]
 * @return                          set of URIs for unmanaged snapshots
 * @throws Exception
 */
private Set<URI> processUnManagedSnapshots(StorageVolume driverVolume, UnManagedVolume unManagedParentVolume, com.emc.storageos.db.client.model.StorageSystem storageSystem, com.emc.storageos.db.client.model.StoragePool storagePool, List<UnManagedVolume> unManagedVolumesToCreate, List<UnManagedVolume> unManagedVolumesToUpdate, Set<URI> allCurrentUnManagedCgURIs, Map<String, UnManagedConsistencyGroup> unManagedCGToUpdateMap, Map<String, URI> unManagedVolumeNativeIdToUriMap, Map<String, List<HostExportInfo>> hostToUnManagedVolumeExportInfoMap, BlockStorageDriver driver, DbClient dbClient) throws Exception {
    log.info("Processing snapshots for volume {} ", unManagedParentVolume.getNativeGuid());
    Set<URI> snapshotUris = new HashSet<>();
    List<VolumeSnapshot> driverSnapshots = driver.getVolumeSnapshots(driverVolume);
    if (driverSnapshots == null || driverSnapshots.isEmpty()) {
        log.info("There are no snapshots for volume {} ", unManagedParentVolume.getNativeGuid());
    } else {
        log.info("Snapshots for unManaged volume {}:" + Joiner.on("\t").join(driverSnapshots), unManagedParentVolume.getNativeGuid());
        StringSet unManagedSnaps = new StringSet();
        for (VolumeSnapshot driverSnapshot : driverSnapshots) {
            String managedSnapNativeGuid = NativeGUIDGenerator.generateNativeGuidForVolumeOrBlockSnapShot(storageSystem.getNativeGuid(), driverSnapshot.getNativeId());
            BlockSnapshot systemSnap = DiscoveryUtils.checkBlockSnapshotExistsInDB(dbClient, managedSnapNativeGuid);
            if (null != systemSnap) {
                log.info("Skipping snapshot {} as it is already managed by the system.", managedSnapNativeGuid);
                continue;
            }
            String unManagedSnapNatvieGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingVolume(storageSystem.getNativeGuid(), driverSnapshot.getNativeId());
            UnManagedVolume unManagedSnap = createUnManagedSnapshot(driverSnapshot, unManagedParentVolume, storageSystem, storagePool, unManagedVolumesToCreate, unManagedVolumesToUpdate, dbClient);
            snapshotUris.add(unManagedSnap.getId());
            unManagedSnaps.add(unManagedSnapNatvieGuid);
            // Check if this snap is for a volume in consistency group on device.
            String isParentVolumeInCG = unManagedParentVolume.getVolumeCharacterstics().get(UnManagedVolume.SupportedVolumeCharacterstics.IS_VOLUME_ADDED_TO_CONSISTENCYGROUP.toString());
            if (isParentVolumeInCG.equals(Boolean.TRUE.toString())) {
                // add snapshot to parent volume unManaged consistency group, update snapshot with parent volume CG information.
                addObjectToUnManagedConsistencyGroup(storageSystem, driverVolume.getConsistencyGroup(), unManagedSnap, allCurrentUnManagedCgURIs, unManagedCGToUpdateMap, driver, dbClient);
            }
            // get export data for the snapshot
            unManagedVolumeNativeIdToUriMap.put(driverSnapshot.getNativeId(), unManagedSnap.getId());
            getSnapshotExportInfo(driver, driverSnapshot, hostToUnManagedVolumeExportInfoMap);
        }
        if (!unManagedSnaps.isEmpty()) {
            // set the HAS_REPLICAS property
            unManagedParentVolume.getVolumeCharacterstics().put(UnManagedVolume.SupportedVolumeCharacterstics.HAS_REPLICAS.toString(), TRUE);
            StringSetMap unManagedVolumeInformation = unManagedParentVolume.getVolumeInformation();
            log.info("New unManaged snaps for unManaged volume {}:" + Joiner.on("\t").join(unManagedSnaps), unManagedParentVolume.getNativeGuid());
            if (unManagedVolumeInformation.containsKey(UnManagedVolume.SupportedVolumeInformation.SNAPSHOTS.toString())) {
                log.info("Old unManaged snaps for unManaged volume {}:" + Joiner.on("\t").join(unManagedVolumeInformation.get(UnManagedVolume.SupportedVolumeInformation.SNAPSHOTS.toString())), unManagedParentVolume.getNativeGuid());
                // replace with new StringSet
                unManagedParentVolume.putVolumeInfo(UnManagedVolume.SupportedVolumeInformation.SNAPSHOTS.toString(), unManagedSnaps);
                log.info("Replaced snaps :" + Joiner.on("\t").join(unManagedVolumeInformation.get(UnManagedVolume.SupportedVolumeInformation.SNAPSHOTS.toString())));
            } else {
                unManagedParentVolume.putVolumeInfo(UnManagedVolume.SupportedVolumeInformation.SNAPSHOTS.toString(), unManagedSnaps);
            }
        } else {
            log.info("All snapshots for volume {} are already managed.", unManagedParentVolume.getNativeGuid());
        }
    }
    return snapshotUris;
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) StringSet(com.emc.storageos.db.client.model.StringSet) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) URI(java.net.URI) VolumeSnapshot(com.emc.storageos.storagedriver.model.VolumeSnapshot) HashSet(java.util.HashSet)

Example 93 with BlockSnapshot

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

the class ExternalDeviceUnManagedVolumeDiscoverer method getExportInfoForManagedVolumeReplicas.

/**
 * Get export info for replicas (snaps and clones) of managed volume.
 * We expect that all replicas of managed volume should be managed (known to the system) ---
 * enforced by  ingest framework, plus we do not support coexistence .
 * Warning log message is generated for each replica which is unmanaged.
 *
 * @param managedVolumeNativeIdToUriMap    [OUT], map: key --- managed volume native id, value: volume uri.
 * @param hostToManagedVolumeExportInfoMap [OUT], map: key --- host name, value: list of export infos for volumes exported
 *                                         to this host.
 * @param dbClient                         reference to db client [IN]
 * @param storageSystem                    storage system [IN]
 * @param systemVolume                     system volume  [IN]
 * @param driverVolume                     native volume [IN]
 * @param driver                           reference to driver [IN]
 * @throws Exception
 */
private void getExportInfoForManagedVolumeReplicas(Map<String, URI> managedVolumeNativeIdToUriMap, Map<String, List<HostExportInfo>> hostToManagedVolumeExportInfoMap, DbClient dbClient, com.emc.storageos.db.client.model.StorageSystem storageSystem, Volume systemVolume, StorageVolume driverVolume, BlockStorageDriver driver) throws Exception {
    // get export info for managed volume  snapshots
    log.info("Processing snapshots for managed volume {} ", systemVolume.getNativeGuid());
    List<VolumeSnapshot> driverSnapshots = driver.getVolumeSnapshots(driverVolume);
    if (driverSnapshots == null || driverSnapshots.isEmpty()) {
        log.info("There are no snapshots for volume {} ", systemVolume.getNativeGuid());
    } else {
        log.info("Snapshots for managed volume {}:" + Joiner.on("\t").join(driverSnapshots), systemVolume.getNativeGuid());
        for (VolumeSnapshot driverSnapshot : driverSnapshots) {
            String managedSnapNativeGuid = NativeGUIDGenerator.generateNativeGuidForVolumeOrBlockSnapShot(storageSystem.getNativeGuid(), driverSnapshot.getNativeId());
            BlockSnapshot systemSnap = DiscoveryUtils.checkBlockSnapshotExistsInDB(dbClient, managedSnapNativeGuid);
            if (systemSnap == null) {
                log.warn("Found unmanaged snapshot of managed volume --- this is unexpected! Skipping this snapshot {}.", driverSnapshot.getNativeId());
                continue;
            } else {
                log.info("Processing managed {} snapshot of managed volume ().", systemSnap.getNativeId(), systemVolume.getNativeGuid());
            }
            // get export data for the snapshot
            managedVolumeNativeIdToUriMap.put(driverSnapshot.getNativeId(), systemSnap.getId());
            getSnapshotExportInfo(driver, driverSnapshot, hostToManagedVolumeExportInfoMap);
        }
    }
    // get export info for managed volume  clones
    log.info("Processing clones for managed volume {} ", systemVolume.getNativeGuid());
    List<VolumeClone> driverClones = driver.getVolumeClones(driverVolume);
    if (driverClones == null || driverClones.isEmpty()) {
        log.info("There are no clones for volume {} ", systemVolume.getNativeGuid());
    } else {
        log.info("Clones for managed volume {}:" + Joiner.on("\t").join(driverClones), systemVolume.getNativeGuid());
        for (VolumeClone driverClone : driverClones) {
            String managedCloneNativeGuid = NativeGUIDGenerator.generateNativeGuidForVolumeOrBlockSnapShot(storageSystem.getNativeGuid(), driverClone.getNativeId());
            Volume systemClone = DiscoveryUtils.checkStorageVolumeExistsInDB(dbClient, managedCloneNativeGuid);
            if (systemClone == null) {
                log.warn("Found unmanaged clone of managed volume --- this is unexpected! Skipping this clone {}.", driverClone.getNativeId());
                continue;
            } else {
                log.info("Processing managed {} clone of managed volume ().", systemClone.getNativeId(), systemVolume.getNativeGuid());
            }
            // get export data for the clone
            managedVolumeNativeIdToUriMap.put(driverClone.getNativeId(), systemClone.getId());
            getCloneExportInfo(driver, driverClone, hostToManagedVolumeExportInfoMap);
        }
    }
}
Also used : StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) Volume(com.emc.storageos.db.client.model.Volume) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) VolumeClone(com.emc.storageos.storagedriver.model.VolumeClone) VolumeSnapshot(com.emc.storageos.storagedriver.model.VolumeSnapshot)

Example 94 with BlockSnapshot

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

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

the class BlockSnapshotDeactivateCompleter method complete.

@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
    try {
        List<BlockSnapshot> snapshots = dbClient.queryObject(BlockSnapshot.class, snapshotURIs);
        for (BlockSnapshot snapshot : snapshots) {
            Volume volume = dbClient.queryObject(Volume.class, snapshot.getParent());
            switch(status) {
                case error:
                    setErrorOnDataObject(dbClient, BlockSnapshot.class, snapshot, coded);
                    setErrorOnDataObject(dbClient, Volume.class, volume.getId(), coded);
                    break;
                case ready:
                    // Only execute the following logic if the snapshot has been deactivated and is tied to a bookmark
                    if (deactivatedSnapshots.contains(snapshot.getId()) && RPHelper.hasRpBookmark(snapshot)) {
                        // Note regarding the syncActive field:
                        // If we are performing a disable image access as part of a snapshot create for an array snapshot + RP bookmark,
                        // we want to set the syncActive field to true. This will enable us to perform snapshot exports and remove
                        // snapshots from exports.
                        // Update the snapshot/volume fields
                        RPHelper.updateRPSnapshotPostImageAccessChange(snapshot, volume, Volume.VolumeAccessState.NOT_READY, setSnapshotSyncActive, dbClient);
                    }
                default:
                    setReadyOnDataObject(dbClient, BlockSnapshot.class, snapshot);
                    setReadyOnDataObject(dbClient, Volume.class, volume.getId());
                    break;
            }
            recordBlockSnapshotOperation(dbClient, OperationTypeEnum.DEACTIVATE_VOLUME_SNAPSHOT, status, eventMessage(status, volume, snapshot), snapshot);
        }
        super.complete(dbClient, status, coded);
        _log.info("Done deactivate {}, with Status: {}", getOpId(), status.name());
    } catch (Exception e) {
        _log.error("Failed updating status. SnapshotDeactivate {}, for task " + getOpId(), getId(), e);
    }
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) 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