Search in sources :

Example 11 with BlockSnapshotCreateCompleter

use of com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotCreateCompleter in project coprhd-controller by CoprHD.

the class SmisBlockCreateCGSnapshotJob method updateStatus.

@Override
public void updateStatus(JobContext jobContext) throws Exception {
    CloseableIterator<CIMObjectPath> syncVolumeIter = null;
    DbClient dbClient = jobContext.getDbClient();
    JobStatus jobStatus = getJobStatus();
    try {
        if (jobStatus == 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 (jobStatus == JobStatus.SUCCESS) {
            // 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);
            }
            // Iterate through the snapshot elements that were created by the
            // Job and try to match them up with the appropriate BlockSnapshot
            CIMConnectionFactory cimConnectionFactory = jobContext.getCimConnectionFactory();
            WBEMClient client = getWBEMClient(dbClient, cimConnectionFactory);
            CIMObjectPath replicationGroupPath = client.associatorNames(getCimJob(), null, SmisConstants.SE_REPLICATION_GROUP, null, null).next();
            String replicationGroupInstance = (String) replicationGroupPath.getKey(SmisConstants.CP_INSTANCE_ID).getValue();
            replicationGroupInstance = SmisUtils.getTargetGroupName(replicationGroupInstance, storage.getUsingSmis80());
            String relationshipName = getRelationShipName(client, replicationGroupPath, replicationGroupInstance);
            syncVolumeIter = client.associatorNames(replicationGroupPath, null, SmisConstants.CIM_STORAGE_VOLUME, null, null);
            Calendar now = Calendar.getInstance();
            while (syncVolumeIter.hasNext()) {
                // Get the sync volume native device id
                CIMObjectPath syncVolumePath = syncVolumeIter.next();
                CIMInstance syncVolume = client.getInstance(syncVolumePath, false, false, null);
                String syncDeviceID = syncVolumePath.getKey(SmisConstants.CP_DEVICE_ID).getValue().toString();
                String elementName = CIMPropertyFactory.getPropertyValue(syncVolume, SmisConstants.CP_ELEMENT_NAME);
                // Get the associated volume for this sync volume
                CIMObjectPath volumePath = null;
                CloseableIterator<CIMObjectPath> volumeIter = client.associatorNames(syncVolumePath, null, SmisConstants.CIM_STORAGE_VOLUME, null, null);
                volumePath = volumeIter.next();
                volumeIter.close();
                String volumeDeviceID = volumePath.getKey(SmisConstants.CP_DEVICE_ID).getValue().toString();
                String wwn = CIMPropertyFactory.getPropertyValue(syncVolume, SmisConstants.CP_WWN_NAME);
                String alternativeName = CIMPropertyFactory.getPropertyValue(syncVolume, SmisConstants.CP_NAME);
                // Lookup the associated snapshot based on the volume native device id
                BlockSnapshot snapshot = volumeToSnapMap.get(volumeDeviceID);
                // we need to perform this null check to avoid a NPE.
                if (snapshot != null) {
                    snapshot.setNativeId(syncDeviceID);
                    snapshot.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(storage, snapshot));
                    snapshot.setReplicationGroupInstance(replicationGroupInstance);
                    snapshot.setDeviceLabel(elementName);
                    snapshot.setInactive(false);
                    snapshot.setIsSyncActive(_wantSyncActive);
                    snapshot.setCreationTime(now);
                    snapshot.setWWN(wwn.toUpperCase());
                    snapshot.setAlternateName(alternativeName);
                    commonSnapshotUpdate(snapshot, syncVolume, client, storage, _sourceGroupId, relationshipName, true, dbClient);
                    _log.info(String.format("For sync volume path %1$s, going to set blocksnapshot %2$s nativeId to %3$s (%4$s). " + "Replication Group instance is %5$s. Associated volume is %6$s", syncVolumePath.toString(), snapshot.getId().toString(), syncDeviceID, elementName, replicationGroupInstance, volumePath.toString()));
                    dbClient.updateObject(snapshot);
                }
            }
        } else if (jobStatus == JobStatus.FAILED || jobStatus == JobStatus.FATAL_ERROR) {
            _log.info("Failed to create snapshot");
            for (BlockSnapshot snapshot : snapshots) {
                snapshot.setInactive(true);
            }
            dbClient.updateObject(snapshots);
        }
    } catch (Exception e) {
        setPostProcessingErrorStatus("Encountered an internal error during create CG snapshot job status processing: " + e.getMessage());
        _log.error("Caught an exception while trying to updateStatus for SmisBlockCreateCGSnapshotJob", e);
    } finally {
        if (syncVolumeIter != null) {
            syncVolumeIter.close();
        }
        super.updateStatus(jobContext);
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) HashMap(java.util.HashMap) Calendar(java.util.Calendar) CIMObjectPath(javax.cim.CIMObjectPath) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) BlockSnapshotCreateCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotCreateCompleter) CIMInstance(javax.cim.CIMInstance) Volume(com.emc.storageos.db.client.model.Volume) CIMConnectionFactory(com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory) WBEMClient(javax.wbem.client.WBEMClient) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 12 with BlockSnapshotCreateCompleter

use of com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotCreateCompleter 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)

Example 13 with BlockSnapshotCreateCompleter

use of com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotCreateCompleter 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

BlockSnapshotCreateCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotCreateCompleter)13 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)10 Volume (com.emc.storageos.db.client.model.Volume)9 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)8 TaskCompleter (com.emc.storageos.volumecontroller.TaskCompleter)6 DbClient (com.emc.storageos.db.client.DbClient)5 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)5 WorkflowException (com.emc.storageos.workflow.WorkflowException)5 URI (java.net.URI)5 NamedURI (com.emc.storageos.db.client.model.NamedURI)4 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)4 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)4 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)4 ControllerException (com.emc.storageos.volumecontroller.ControllerException)4 MultiVolumeTaskCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.MultiVolumeTaskCompleter)4 VolumeTaskCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.VolumeTaskCompleter)4 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)3 ApplicationTaskCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.ApplicationTaskCompleter)3 BlockMirrorTaskCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockMirrorTaskCompleter)3 BlockSnapshotEstablishGroupTaskCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotEstablishGroupTaskCompleter)3