Search in sources :

Example 1 with ParametersOut

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

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

the class VNXeBlockSnapshotCreateJob 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());
        if (_status == JobStatus.SUCCESS) {
            _logger.info(String.format("Post-processing successful snap creation task:%s. Expected: snapshot.size() = 1; Actual: snapshots.size() = %d", getTaskCompleter().getOpId(), snapshots.size()));
            StorageSystem storage = dbClient.queryObject(StorageSystem.class, getStorageSystemUri());
            VNXeApiClient vnxeApiClient = getVNXeClient(jobContext);
            VNXeCommandJob vnxeJob = vnxeApiClient.getJob(getJobIds().get(0));
            ParametersOut output = vnxeJob.getParametersOut();
            BlockSnapshot snapshot = snapshots.get(0);
            Volume volume = dbClient.queryObject(Volume.class, snapshot.getParent().getURI());
            snapshot.setNativeId(output.getId());
            snapshot.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(storage, snapshot));
            snapshot.setIsSyncActive(true);
            snapshot.setInactive(false);
            snapshot.setCreationTime(Calendar.getInstance());
            if (vnxeApiClient.isUnityClient()) {
                Snap snap = vnxeApiClient.getSnapshot(output.getId());
                snapshot.setDeviceLabel(snap.getName());
                snapshot.setAllocatedCapacity(snap.getSize());
                snapshot.setProvisionedCapacity(snap.getSize());
            } else {
                VNXeLunSnap vnxeLunSnap = vnxeApiClient.getLunSnapshot(output.getId());
                VNXeLun lun = vnxeApiClient.getLun(vnxeLunSnap.getLun().getId());
                snapshot.setDeviceLabel(vnxeLunSnap.getName());
                snapshot.setAllocatedCapacity(lun.getSnapsSizeAllocated());
                snapshot.setProvisionedCapacity(lun.getSnapsSize());
            }
            _logger.info(String.format("Going to set blocksnapshot %1$s nativeId to %2$s. Associated volume is %3$s (%4$s)", snapshot.getId().toString(), output.getId(), volume.getNativeId(), volume.getLabel()));
            dbClient.updateObject(snapshot);
            getTaskCompleter().ready(dbClient);
        } else if (_status == JobStatus.FAILED) {
            _logger.info("Failed to create snapshot");
            BlockSnapshot snapshot = snapshots.get(0);
            snapshot.setInactive(true);
            dbClient.updateObject(snapshot);
        }
    } catch (Exception e) {
        _logger.error("Caught an exception while trying to updateStatus for VNXeBlockSnapshotCreateJob", e);
        setErrorStatus("Encountered an internal error during volume snapshot create job status processing : " + e.getMessage());
    } finally {
        super.updateStatus(jobContext);
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ParametersOut(com.emc.storageos.vnxe.models.ParametersOut) BlockSnapshotCreateCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotCreateCompleter) Snap(com.emc.storageos.vnxe.models.Snap) VNXeLunSnap(com.emc.storageos.vnxe.models.VNXeLunSnap) 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 3 with ParametersOut

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

the class VNXeCreateVolumesJob method updateStatus.

/**
 * Called to update the job status when the volumes create job completes.
 *
 * @param jobContext The job context.
 */
@Override
public void updateStatus(JobContext jobContext) throws Exception {
    DbClient dbClient = jobContext.getDbClient();
    try {
        if (_status == JobStatus.IN_PROGRESS) {
            return;
        }
        String opId = getTaskCompleter().getOpId();
        StringBuilder logMsgBuilder = new StringBuilder(String.format("Updating status of job %s to %s", opId, _status.name()));
        VNXeApiClient vnxeApiClient = getVNXeClient(jobContext);
        // If terminal state update storage pool capacity
        if (_status == JobStatus.SUCCESS || _status == JobStatus.FAILED) {
            List<URI> volUris = getTaskCompleter().getIds();
            List<String> volsInPool = new ArrayList<String>();
            for (URI voluri : volUris) {
                volsInPool.add(voluri.toString());
            }
            VNXeJob.updateStoragePoolCapacity(dbClient, vnxeApiClient, storagePool, volsInPool);
        }
        Calendar now = Calendar.getInstance();
        int volumeCount = 0;
        if (_status == JobStatus.SUCCESS) {
            if (!isConsistencyGroup) {
                for (String jobId : getJobIds()) {
                    VNXeCommandJob vnxeJob = vnxeApiClient.getJob(jobId);
                    ParametersOut output = vnxeJob.getParametersOut();
                    String nativeId = null;
                    URI volumeId = getTaskCompleter().getId(volumeCount);
                    if (output != null) {
                        VNXeBase storageResource = output.getStorageResource();
                        if (storageResource != null) {
                            nativeId = storageResource.getId();
                        }
                    }
                    processVolume(vnxeApiClient, nativeId, volumeId, dbClient, logMsgBuilder, now);
                    volumeCount++;
                }
            } else {
                List<URI> volIds = getTaskCompleter().getIds();
                processVolumesinConsistencyGroup(vnxeApiClient, volIds, dbClient, logMsgBuilder, now);
            }
        } else if (_status == JobStatus.FAILED) {
            List<URI> volIds = getTaskCompleter().getIds();
            for (URI volId : volIds) {
                Volume volume = dbClient.queryObject(Volume.class, volId);
                volume.setInactive(true);
                dbClient.updateObject(volume);
                if (logMsgBuilder.length() != 0) {
                    logMsgBuilder.append("\n");
                }
                logMsgBuilder.append(String.format("Task %s failed to create volume: %s", opId, volId));
            }
        }
        _logger.info(logMsgBuilder.toString());
    } catch (Exception e) {
        _logger.error("Caught an exception while trying to updateStatus for VNXeCreateVolumesJob", e);
        setErrorStatus("Encountered an internal error during volume create job status processing : " + e.getMessage());
    } finally {
        super.updateStatus(jobContext);
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) ParametersOut(com.emc.storageos.vnxe.models.ParametersOut) URI(java.net.URI) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) IOException(java.io.IOException) VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) Volume(com.emc.storageos.db.client.model.Volume) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with ParametersOut

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

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

the class VNXUnityCreateCGSnapshotJob 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();
            String snapGroupId = output.getId();
            List<Snap> snaps = vnxeApiClient.getSnapshotsBySnapGroup(snapGroupId);
            // 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 (Snap snap : snaps) {
                String lunId = snap.getLun().getId();
                BlockSnapshot snapshot = volumeToSnapMap.get(lunId);
                snapshot.setNativeId(snap.getId());
                snapshot.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(storage, snapshot));
                snapshot.setDeviceLabel(snap.getName());
                snapshot.setReplicationGroupInstance(snapGroupId);
                snapshot.setIsSyncActive(true);
                snapshot.setInactive(false);
                snapshot.setCreationTime(Calendar.getInstance());
                snapshot.setWWN(snap.getAttachedWWN());
                snapshot.setAllocatedCapacity(snap.getSize());
                snapshot.setProvisionedCapacity(snap.getSize());
                if (readOnly) {
                    snapshot.setIsReadOnly(readOnly);
                }
                _logger.info(String.format("Going to set blocksnapshot %1$s nativeId to %2$s (%3$s). Associated lun is %4$s", snapshot.getId().toString(), snap.getId(), snapshot.getLabel(), lunId));
                dbClient.updateObject(snapshot);
            }
        } else if (_status == JobStatus.FAILED) {
            _logger.info("Failed to create snapshot");
            for (BlockSnapshot snapshot : snapshots) {
                snapshot.setInactive(true);
            }
            dbClient.updateObject(snapshots);
        }
    } catch (Exception e) {
        _logger.error("Caught an exception while trying to updateStatus for VNXUntiyCreateCGSnapshotJob", e);
        setErrorStatus("Encountered an internal error during group snapshot create 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) ParametersOut(com.emc.storageos.vnxe.models.ParametersOut) BlockSnapshotCreateCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotCreateCompleter) Snap(com.emc.storageos.vnxe.models.Snap) VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) Volume(com.emc.storageos.db.client.model.Volume) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

DbClient (com.emc.storageos.db.client.DbClient)6 Volume (com.emc.storageos.db.client.model.Volume)6 VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)6 ParametersOut (com.emc.storageos.vnxe.models.ParametersOut)6 VNXeCommandJob (com.emc.storageos.vnxe.models.VNXeCommandJob)6 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)5 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)5 HashMap (java.util.HashMap)4 Snap (com.emc.storageos.vnxe.models.Snap)3 VNXeLun (com.emc.storageos.vnxe.models.VNXeLun)3 BlockSnapshotCreateCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotCreateCompleter)3 URI (java.net.URI)3 ArrayList (java.util.ArrayList)3 NamedURI (com.emc.storageos.db.client.model.NamedURI)2 OpStatusMap (com.emc.storageos.db.client.model.OpStatusMap)2 VNXeLunGroupSnap (com.emc.storageos.vnxe.models.VNXeLunGroupSnap)2 VNXeLunSnap (com.emc.storageos.vnxe.models.VNXeLunSnap)2 BlockObject (com.emc.storageos.db.client.model.BlockObject)1 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)1 VNXeBase (com.emc.storageos.vnxe.models.VNXeBase)1