Search in sources :

Example 21 with OpStatusMap

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

the class VPlexDeviceController method findPromotedVolumeForMirror.

private Volume findPromotedVolumeForMirror(URI vplexMirrorURI, List<URI> promotees) {
    VplexMirror mirror = _dbClient.queryObject(VplexMirror.class, vplexMirrorURI);
    List<Volume> promotedVolumes = _dbClient.queryObject(Volume.class, promotees);
    for (Volume promotee : promotedVolumes) {
        OpStatusMap statusMap = promotee.getOpStatus();
        for (Map.Entry<String, Operation> entry : statusMap.entrySet()) {
            Operation operation = entry.getValue();
            if (operation.getAssociatedResourcesField().contains(mirror.getId().toString())) {
                return promotee;
            }
        }
    }
    throw new IllegalStateException("No volume available for the promotion of mirror " + mirror.getId());
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) Operation(com.emc.storageos.db.client.model.Operation) ExportOperationContextOperation(com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext.ExportOperationContextOperation) VplexMirror(com.emc.storageos.db.client.model.VplexMirror) Map(java.util.Map) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) HashMap(java.util.HashMap) StringMap(com.emc.storageos.db.client.model.StringMap)

Example 22 with OpStatusMap

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

the class VNXeBlockRestoreSnapshotJob method updateStatus.

public void updateStatus(JobContext jobContext) throws Exception {
    DbClient dbClient = jobContext.getDbClient();
    try {
        if (_status == JobStatus.IN_PROGRESS) {
            return;
        }
        String opId = getTaskCompleter().getOpId();
        _logger.info(String.format("Updating status of job %s to %s", opId, _status.name()));
        URI snapId = getTaskCompleter().getId();
        BlockSnapshot snapshotObj = dbClient.queryObject(BlockSnapshot.class, snapId);
        StorageSystem storage = dbClient.queryObject(StorageSystem.class, getStorageSystemUri());
        if (_status == JobStatus.SUCCESS && snapshotObj != null) {
            VNXeApiClient vnxeApiClient = getVNXeClient(jobContext);
            VNXeCommandJob vnxeJob = vnxeApiClient.getJob(getJobIds().get(0));
            ParametersOut output = vnxeJob.getParametersOut();
            // get the id of the backup snapshot created before restore operation
            String backUpSnapId = output.getBackup().getId();
            if (snapshotObj.getConsistencyGroup() != null) {
                VNXeLunGroupSnap backupSnap = vnxeApiClient.getLunGroupSnapshot(backUpSnapId);
                List<VNXeLun> groupLuns = vnxeApiClient.getLunByStorageResourceId(backupSnap.getStorageResource().getId());
                // Create a snapshot corresponding to the backup snap for each volume in the consistency group
                URI cgID = snapshotObj.getConsistencyGroup();
                List<Volume> cgVolumes = getCGVolumes(cgID.toString(), dbClient);
                final List<BlockSnapshot> snapshotList = new ArrayList<BlockSnapshot>();
                Map<String, BlockSnapshot> volumeToSnapMap = new HashMap<String, BlockSnapshot>();
                for (Volume vol : cgVolumes) {
                    final BlockSnapshot newSnap = getSnapshotFromVol(vol, backupSnap.getName());
                    newSnap.setOpStatus(new OpStatusMap());
                    snapshotList.add(newSnap);
                    volumeToSnapMap.put(vol.getNativeId(), newSnap);
                }
                // Add vnxe information to the new snapshots
                for (VNXeLun groupLun : groupLuns) {
                    BlockSnapshot snapshot = volumeToSnapMap.get(groupLun.getId());
                    if (snapshot == null) {
                        _logger.info("No snapshot found for the vnxe lun - ", groupLun.getId());
                        continue;
                    }
                    snapshot.setNativeId(backUpSnapId);
                    snapshot.setReplicationGroupInstance(backUpSnapId);
                    processSnapshot(snapshot, storage, groupLun, dbClient);
                }
                dbClient.createObject(snapshotList);
            } else {
                VNXeLunSnap backupSnap = vnxeApiClient.getLunSnapshot(backUpSnapId);
                VNXeLun lun = vnxeApiClient.getLun(backupSnap.getLun().getId());
                Volume vol = dbClient.queryObject(Volume.class, snapshotObj.getParent());
                final BlockSnapshot newSnap = getSnapshotFromVol(vol, backupSnap.getName());
                newSnap.setNativeId(backUpSnapId);
                processSnapshot(newSnap, storage, lun, dbClient);
            }
            getTaskCompleter().ready(dbClient);
        } else if (_status == JobStatus.FAILED && snapshotObj != null) {
            _logger.info(String.format("Task %s failed to restore volume snapshot: %s", opId, snapshotObj.getLabel()));
        }
    } catch (Exception e) {
        _logger.error("Caught an exception while trying to updateStatus for VNXeBlockRestoreSnapshotJob", e);
        setErrorStatus("Encountered an internal error during snapshot restore job status processing : " + e.getMessage());
    } finally {
        super.updateStatus(jobContext);
    }
}
Also used : VNXeLunGroupSnap(com.emc.storageos.vnxe.models.VNXeLunGroupSnap) DbClient(com.emc.storageos.db.client.DbClient) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) HashMap(java.util.HashMap) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ArrayList(java.util.ArrayList) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) ParametersOut(com.emc.storageos.vnxe.models.ParametersOut) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) VNXeLunSnap(com.emc.storageos.vnxe.models.VNXeLunSnap) VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) Volume(com.emc.storageos.db.client.model.Volume) VNXeLun(com.emc.storageos.vnxe.models.VNXeLun) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 23 with OpStatusMap

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

the class VNXeRestoreFileSystemSnapshotJob method syncSnapshots.

private void syncSnapshots(DbClient dbClient, FileShare fsObj, VNXeApiClient vnxeApiClient) {
    // Retrieve all snapshots from DB that belong to this file system
    URIQueryResultList results = new URIQueryResultList();
    dbClient.queryByConstraint(ContainmentConstraint.Factory.getFileshareSnapshotConstraint(fsObj.getId()), results);
    // Setup snapshot name-object map
    Map<String, Snapshot> snapshotsInDB = new ConcurrentHashMap<String, Snapshot>();
    while (results.iterator().hasNext()) {
        URI uri = results.iterator().next();
        Snapshot snap = dbClient.queryObject(Snapshot.class, uri);
        String nativeId = snap.getNativeId();
        if (nativeId == null || nativeId.isEmpty()) {
            // no nativeId set in the snap, remove it from db.
            snap.setInactive(true);
            dbClient.persistObject(snap);
            _logger.info("No nativeId, removing the snapshot: {}", snap.getId());
            continue;
        } else {
            snapshotsInDB.put(nativeId, snap);
        }
    }
    // Retrieve list of valid snapshot names from the device
    List<VNXeFileSystemSnap> snapshots = vnxeApiClient.getFileSystemSnaps(fsObj.getNativeId());
    List<String> snapIdsOnDevice = new ArrayList<String>();
    for (VNXeFileSystemSnap snap : snapshots) {
        snapIdsOnDevice.add(snap.getId());
    }
    // Iterate through the snapshots in the DB and if name not found in
    // the list returned by the device, mark snapshot in DB as inactive
    Set<String> snapshotNativeIds = snapshotsInDB.keySet();
    for (String snapshotId : snapshotNativeIds) {
        if (!snapIdsOnDevice.contains(snapshotId)) {
            _logger.info("Removing the snapshot: {}", snapshotId);
            snapshotsInDB.get(snapshotId).setInactive(true);
            dbClient.persistObject(snapshotsInDB.get(snapshotId));
        }
    }
    // newly discovered snapshot to the DB.
    for (VNXeFileSystemSnap snap : snapshots) {
        if (!snapshotNativeIds.contains(snap.getId())) {
            _logger.info("adding the snapshot: {}", snap.getId());
            Snapshot newSnap = new Snapshot();
            newSnap.setCreationTime(Calendar.getInstance());
            newSnap.setId(URIUtil.createId(Snapshot.class));
            newSnap.setParent(new NamedURI(fsObj.getId(), fsObj.getLabel()));
            newSnap.setLabel(snap.getName());
            newSnap.setOpStatus(new OpStatusMap());
            newSnap.setProject(new NamedURI(fsObj.getProject().getURI(), fsObj.getProject().getName()));
            newSnap.setNativeId(snap.getId());
            try {
                newSnap.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(dbClient, newSnap));
            } catch (IOException e) {
                _logger.info("Exception while setting snap's nativeGUID");
            }
        }
    }
}
Also used : NamedURI(com.emc.storageos.db.client.model.NamedURI) ArrayList(java.util.ArrayList) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) IOException(java.io.IOException) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) VNXeFileSystemSnap(com.emc.storageos.vnxe.models.VNXeFileSystemSnap) Snapshot(com.emc.storageos.db.client.model.Snapshot) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 24 with OpStatusMap

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

the class VNXUnityRestoreSnapshotJob method updateStatus.

public void updateStatus(JobContext jobContext) throws Exception {
    DbClient dbClient = jobContext.getDbClient();
    try {
        if (_status == JobStatus.IN_PROGRESS) {
            return;
        }
        String opId = getTaskCompleter().getOpId();
        _logger.info(String.format("Updating status of job %s to %s", opId, _status.name()));
        URI snapId = getTaskCompleter().getId();
        BlockSnapshot snapshotObj = dbClient.queryObject(BlockSnapshot.class, snapId);
        URI projectUri = snapshotObj.getProject().getURI();
        StorageSystem storage = dbClient.queryObject(StorageSystem.class, getStorageSystemUri());
        if (_status == JobStatus.SUCCESS && snapshotObj != null) {
            VNXeApiClient vnxeApiClient = getVNXeClient(jobContext);
            VNXeCommandJob vnxeJob = vnxeApiClient.getJob(getJobIds().get(0));
            ParametersOut output = vnxeJob.getParametersOut();
            // get the id of the backup snapshot created before restore operation
            String backUpSnapId = output.getBackup().getId();
            Snap backupSnap = vnxeApiClient.getSnapshot(backUpSnapId);
            if (NullColumnValueGetter.isNotNullValue(snapshotObj.getReplicationGroupInstance())) {
                List<BlockSnapshot> snapshots = ControllerUtils.getSnapshotsPartOfReplicationGroup(snapshotObj, dbClient);
                // Create a snapshot corresponding to the backup snap for each volume in the consistency group
                final List<BlockSnapshot> snapshotList = new ArrayList<BlockSnapshot>();
                Map<String, BlockSnapshot> volumeToSnapMap = new HashMap<String, BlockSnapshot>();
                int count = 1;
                String setLabel = backupSnap.getName();
                for (BlockSnapshot snapshot : snapshots) {
                    BlockObject parent = BlockObject.fetch(dbClient, snapshot.getParent().getURI());
                    String label = String.format("%s-%s", setLabel, count++);
                    final BlockSnapshot newSnap = initSnapshot(parent, label, setLabel, projectUri);
                    newSnap.setOpStatus(new OpStatusMap());
                    snapshotList.add(newSnap);
                    volumeToSnapMap.put(parent.getNativeId(), newSnap);
                }
                List<Snap> snaps = vnxeApiClient.getSnapshotsBySnapGroup(backUpSnapId);
                for (Snap snap : snaps) {
                    String lunId = snap.getLun().getId();
                    BlockSnapshot snapshot = volumeToSnapMap.get(lunId);
                    snapshot.setReplicationGroupInstance(backUpSnapId);
                    createSnapshot(snapshot, snap, storage, dbClient);
                }
            } else {
                Volume vol = dbClient.queryObject(Volume.class, snapshotObj.getParent());
                final BlockSnapshot newSnap = initSnapshot(vol, backupSnap.getName(), backupSnap.getName(), projectUri);
                createSnapshot(newSnap, backupSnap, storage, dbClient);
            }
            getTaskCompleter().ready(dbClient);
        } else if (_status == JobStatus.FAILED && snapshotObj != null) {
            _logger.info(String.format("Task %s failed to restore volume snapshot: %s", opId, snapshotObj.getLabel()));
        }
    } catch (Exception e) {
        _logger.error("Caught an exception while trying to updateStatus for VNXeBlockRestoreSnapshotJob", e);
        setErrorStatus("Encountered an internal error during snapshot restore job status processing : " + e.getMessage());
    } finally {
        super.updateStatus(jobContext);
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) HashMap(java.util.HashMap) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ArrayList(java.util.ArrayList) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) ParametersOut(com.emc.storageos.vnxe.models.ParametersOut) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Snap(com.emc.storageos.vnxe.models.Snap) VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) Volume(com.emc.storageos.db.client.model.Volume) BlockObject(com.emc.storageos.db.client.model.BlockObject) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 25 with OpStatusMap

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

the class SmisBlockSnapshotSessionUnlinkTargetJob method promoteSnapshotsToVolume.

/**
 * Promotes a list of BlockSnapshot instances to their Volume equivalents. For BlockSnapshot
 * instances that are part of a target ReplicationGroup, a BlockConsistencyGroup shall be created
 * as part of the promotion.
 *
 * @param snapshots List of BlockSnapshot instances.
 * @param dbClient Database client.
 */
private void promoteSnapshotsToVolume(List<BlockSnapshot> snapshots, DbClient dbClient) {
    Map<String, BlockConsistencyGroup> groupCache = new HashMap<>();
    for (BlockSnapshot snapshot : snapshots) {
        // We check to make sure there is not already a volume with the
        // native GUID of the snapshot. This could be the case if we are
        // unlinking a target after restoring a source volume from a
        // linked target volume. In that case, a linked target was created
        // to represent the source volume and now we are unlinking that
        // linked target. The volume in this case already exists.
        List<Volume> volumesWithNativeId = CustomQueryUtility.getActiveVolumeByNativeGuid(dbClient, snapshot.getNativeGuid());
        if (volumesWithNativeId.isEmpty()) {
            URI cgId = getBlockConsistencyGroupForPromotedSnapshot(snapshot, groupCache, dbClient);
            URI sourceObjURI = snapshot.getParent().getURI();
            if (URIUtil.isType(sourceObjURI, Volume.class)) {
                Volume sourceVolume = dbClient.queryObject(Volume.class, sourceObjURI);
                // Create a new volume to represent the former snapshot target.
                // We get what we can from the snapshot and for what is not
                // available in the snapshot, we get from the source.
                Volume volume = new Volume();
                volume.setId(URIUtil.createId(Volume.class));
                volume.setCreationTime(snapshot.getCreationTime());
                volume.setWWN(snapshot.getWWN());
                volume.setNativeGuid(snapshot.getNativeGuid());
                volume.setNativeId(snapshot.getNativeId());
                volume.setLabel(snapshot.getLabel());
                volume.setDeviceLabel(snapshot.getDeviceLabel());
                volume.setAlternateName(snapshot.getAlternateName());
                volume.setSyncActive(true);
                volume.setAccessState(sourceVolume.getAccessState());
                volume.setCapacity(sourceVolume.getCapacity());
                volume.setProvisionedCapacity(snapshot.getProvisionedCapacity());
                volume.setAllocatedCapacity(snapshot.getAllocatedCapacity());
                volume.setThinlyProvisioned(sourceVolume.getThinlyProvisioned());
                // It is understood that this is not necessary true.
                volume.setVirtualPool(sourceVolume.getVirtualPool());
                volume.setVirtualArray(snapshot.getVirtualArray());
                volume.setProject(snapshot.getProject());
                volume.setTenant(sourceVolume.getTenant());
                volume.setStorageController(snapshot.getStorageController());
                volume.setSystemType(snapshot.getSystemType());
                // It is understood that this is not necessarily true.
                volume.setPool(sourceVolume.getPool());
                StringSet protocols = new StringSet();
                protocols.addAll(snapshot.getProtocol());
                volume.setProtocol(protocols);
                volume.setOpStatus(new OpStatusMap());
                volume.setConsistencyGroup(cgId);
                String repGrpInstance = snapshot.getReplicationGroupInstance();
                if (!NullColumnValueGetter.isNullValue(repGrpInstance)) {
                    volume.setReplicationGroupInstance(repGrpInstance.substring(repGrpInstance.indexOf("+") + 1));
                }
                dbClient.createObject(volume);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) Volume(com.emc.storageos.db.client.model.Volume) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) StringSet(com.emc.storageos.db.client.model.StringSet) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup)

Aggregations

OpStatusMap (com.emc.storageos.db.client.model.OpStatusMap)48 Operation (com.emc.storageos.db.client.model.Operation)29 NamedURI (com.emc.storageos.db.client.model.NamedURI)28 Volume (com.emc.storageos.db.client.model.Volume)15 URI (java.net.URI)15 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)13 StringSet (com.emc.storageos.db.client.model.StringSet)13 FileShare (com.emc.storageos.db.client.model.FileShare)12 ArrayList (java.util.ArrayList)10 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)9 StringMap (com.emc.storageos.db.client.model.StringMap)9 HashMap (java.util.HashMap)9 StoragePool (com.emc.storageos.db.client.model.StoragePool)8 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)7 MapFileShare (com.emc.storageos.api.mapper.functions.MapFileShare)6 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)6 DataObject (com.emc.storageos.db.client.model.DataObject)6 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)6 Consumes (javax.ws.rs.Consumes)6 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)5