Search in sources :

Example 1 with VNXeLunGroupSnap

use of com.emc.storageos.vnxe.models.VNXeLunGroupSnap 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 2 with VNXeLunGroupSnap

use of com.emc.storageos.vnxe.models.VNXeLunGroupSnap in project coprhd-controller by CoprHD.

the class VNXeSnapshotOperation method deleteGroupSnapshots.

@Override
public void deleteGroupSnapshots(StorageSystem storage, URI snapshot, TaskCompleter taskCompleter) throws DeviceControllerException {
    try {
        List<BlockSnapshot> snapshots = _dbClient.queryObject(BlockSnapshot.class, Arrays.asList(snapshot));
        BlockSnapshot snapshotObj = snapshots.get(0);
        VNXeApiClient apiClient = getVnxeClient(storage);
        VNXeLunGroupSnap lunGroupSnap = apiClient.getLunGroupSnapshot(snapshotObj.getReplicationGroupInstance());
        if (lunGroupSnap != null) {
            VNXeCommandJob job = apiClient.deleteLunGroupSnap(lunGroupSnap.getId());
            if (job != null) {
                ControllerServiceImpl.enqueueJob(new QueueJob(new VNXeBlockDeleteSnapshotJob(job.getId(), storage.getId(), taskCompleter)));
            } else {
                // Should not take this path, but treat as an error if we do
                // happen to get a null job due to some error in the client.
                _log.error("Unexpected null job from VNXe client call to delete group snapshot.");
                ServiceCoded sc = DeviceControllerExceptions.vnxe.nullJobForDeleteGroupSnapshot(snapshotObj.forDisplay(), snapshotObj.getReplicationGroupInstance());
                taskCompleter.error(_dbClient, sc);
            }
        } else {
            // Treat as in the single volume snapshot case and presume
            // the group snapshot has already been deleted.
            List<BlockSnapshot> grpSnapshots = ControllerUtils.getSnapshotsPartOfReplicationGroup(snapshotObj, _dbClient);
            for (BlockSnapshot grpSnapshot : grpSnapshots) {
                grpSnapshot.setInactive(true);
                grpSnapshot.setIsSyncActive(false);
            }
            _dbClient.updateObject(grpSnapshots);
            taskCompleter.ready(_dbClient);
        }
    } catch (VNXeException e) {
        _log.error("Delete group snapshot got the exception", e);
        taskCompleter.error(_dbClient, e);
    } catch (Exception ex) {
        _log.error("Delete group snapshot got the exception", ex);
        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("DeletGroupSnapshot", ex.getMessage());
        taskCompleter.error(_dbClient, error);
    }
}
Also used : VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) VNXeLunGroupSnap(com.emc.storageos.vnxe.models.VNXeLunGroupSnap) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) VNXeException(com.emc.storageos.vnxe.VNXeException) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) VNXeBlockDeleteSnapshotJob(com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeBlockDeleteSnapshotJob) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) VNXeException(com.emc.storageos.vnxe.VNXeException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 3 with VNXeLunGroupSnap

use of com.emc.storageos.vnxe.models.VNXeLunGroupSnap in project coprhd-controller by CoprHD.

the class LunGroupSnapRequests method getLunGroupSnapByName.

/**
 * Get snapshot details by its name
 *
 * @param name
 * @return
 */
public VNXeLunGroupSnap getLunGroupSnapByName(String name) {
    setFilter(VNXeConstants.NAME_FILTER + name);
    VNXeLunGroupSnap result = null;
    List<VNXeLunGroupSnap> snapList = getDataForObjects(VNXeLunGroupSnap.class);
    // it should just return 1
    if (snapList != null && !snapList.isEmpty()) {
        result = snapList.get(0);
    } else {
        _logger.info("No lun group snapshot found using the name: " + name);
    }
    return result;
}
Also used : VNXeLunGroupSnap(com.emc.storageos.vnxe.models.VNXeLunGroupSnap)

Example 4 with VNXeLunGroupSnap

use of com.emc.storageos.vnxe.models.VNXeLunGroupSnap in project coprhd-controller by CoprHD.

the class VNXeSnapshotOperation method restoreGroupSnapshots.

@Override
public void restoreGroupSnapshots(StorageSystem storage, URI volume, URI snapshot, TaskCompleter taskCompleter) throws DeviceControllerException {
    try {
        BlockSnapshot snapshotObj = _dbClient.queryObject(BlockSnapshot.class, snapshot);
        VNXeApiClient apiClient = getVnxeClient(storage);
        VNXeLunGroupSnap lunGroupSnap = apiClient.getLunGroupSnapshot(snapshotObj.getReplicationGroupInstance());
        // Error out if the snapshot is attached
        if (lunGroupSnap.getIsAttached()) {
            _log.error("Snapshot {})is attached and cannot be used for restore", snapshotObj.getLabel());
            ServiceError error = DeviceControllerErrors.vnxe.cannotRestoreAttachedSnapshot(snapshot.toString());
            taskCompleter.error(_dbClient, error);
        }
        VNXeCommandJob job = apiClient.restoreLunGroupSnap(lunGroupSnap.getId());
        if (job != null) {
            ControllerServiceImpl.enqueueJob(new QueueJob(new VNXeBlockRestoreSnapshotJob(job.getId(), storage.getId(), taskCompleter)));
        }
    } catch (VNXeException e) {
        _log.error("Restore group snapshot got the exception", e);
        taskCompleter.error(_dbClient, e);
    } catch (Exception ex) {
        _log.error("Restore group snapshot got the exception", ex);
        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("RestoreSnapshotJob", ex.getMessage());
        taskCompleter.error(_dbClient, error);
    }
}
Also used : VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) VNXeLunGroupSnap(com.emc.storageos.vnxe.models.VNXeLunGroupSnap) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) VNXeBlockRestoreSnapshotJob(com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeBlockRestoreSnapshotJob) VNXeException(com.emc.storageos.vnxe.VNXeException) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) VNXeException(com.emc.storageos.vnxe.VNXeException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 5 with VNXeLunGroupSnap

use of com.emc.storageos.vnxe.models.VNXeLunGroupSnap in project coprhd-controller by CoprHD.

the class VNXeBlockCreateCGSnapshotJob method updateStatus.

public void updateStatus(JobContext jobContext) throws Exception {
    DbClient dbClient = jobContext.getDbClient();
    try {
        if (_status == JobStatus.IN_PROGRESS) {
            return;
        }
        BlockSnapshotCreateCompleter completer = (BlockSnapshotCreateCompleter) getTaskCompleter();
        List<BlockSnapshot> snapshots = dbClient.queryObject(BlockSnapshot.class, completer.getSnapshotURIs());
        StorageSystem storage = dbClient.queryObject(StorageSystem.class, getStorageSystemUri());
        if (_status == JobStatus.SUCCESS) {
            VNXeApiClient vnxeApiClient = getVNXeClient(jobContext);
            VNXeCommandJob vnxeJob = vnxeApiClient.getJob(getJobIds().get(0));
            ParametersOut output = vnxeJob.getParametersOut();
            // get the luns belonging to the lun group
            String lunGroupSnapId = output.getId();
            VNXeLunGroupSnap groupSnap = vnxeApiClient.getLunGroupSnapshot(lunGroupSnapId);
            List<VNXeLun> groupLuns = vnxeApiClient.getLunByStorageResourceId(groupSnap.getStorageResource().getId());
            // Create mapping of volume.nativeDeviceId to BlockSnapshot object
            Map<String, BlockSnapshot> volumeToSnapMap = new HashMap<String, BlockSnapshot>();
            for (BlockSnapshot snapshot : snapshots) {
                Volume volume = dbClient.queryObject(Volume.class, snapshot.getParent());
                volumeToSnapMap.put(volume.getNativeId(), snapshot);
            }
            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(output.getId());
                snapshot.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(storage, snapshot));
                snapshot.setDeviceLabel(groupLun.getName());
                snapshot.setReplicationGroupInstance(lunGroupSnapId);
                snapshot.setIsSyncActive(true);
                snapshot.setInactive(false);
                snapshot.setCreationTime(Calendar.getInstance());
                snapshot.setWWN(groupLun.getSnapWwn());
                snapshot.setAllocatedCapacity(groupLun.getSnapsSizeAllocated());
                snapshot.setProvisionedCapacity(groupLun.getSnapsSize());
                _logger.info(String.format("Going to set blocksnapshot %1$s nativeId to %2$s (%3$s). Associated lun is %4$s (%5$s)", snapshot.getId().toString(), output.getId(), snapshot.getLabel(), groupLun.getId(), groupLun.getName()));
                dbClient.persistObject(snapshot);
            }
        } else if (_status == JobStatus.FAILED) {
            _logger.info("Failed to create snapshot");
            for (BlockSnapshot snapshot : snapshots) {
                snapshot.setInactive(true);
            }
            dbClient.persistObject(snapshots);
        }
    } catch (Exception e) {
        _logger.error("Caught an exception while trying to updateStatus for VNXeBlockCreateCGSnapshotJob", e);
        setErrorStatus("Encountered an internal error during group snapshot create 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) ParametersOut(com.emc.storageos.vnxe.models.ParametersOut) BlockSnapshotCreateCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotCreateCompleter) 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)

Aggregations

VNXeLunGroupSnap (com.emc.storageos.vnxe.models.VNXeLunGroupSnap)5 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)4 VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)4 VNXeCommandJob (com.emc.storageos.vnxe.models.VNXeCommandJob)4 DbClient (com.emc.storageos.db.client.DbClient)2 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)2 Volume (com.emc.storageos.db.client.model.Volume)2 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)2 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)2 VNXeException (com.emc.storageos.vnxe.VNXeException)2 ParametersOut (com.emc.storageos.vnxe.models.ParametersOut)2 VNXeLun (com.emc.storageos.vnxe.models.VNXeLun)2 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)2 HashMap (java.util.HashMap)2 NamedURI (com.emc.storageos.db.client.model.NamedURI)1 OpStatusMap (com.emc.storageos.db.client.model.OpStatusMap)1 ServiceCoded (com.emc.storageos.svcs.errorhandling.model.ServiceCoded)1 VNXeLunSnap (com.emc.storageos.vnxe.models.VNXeLunSnap)1 BlockSnapshotCreateCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotCreateCompleter)1 VNXeBlockDeleteSnapshotJob (com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeBlockDeleteSnapshotJob)1