Search in sources :

Example 31 with DbClient

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

the class SmisBlockCreateCGMirrorJob method updateStatus.

public void updateStatus(JobContext jobContext) throws Exception {
    CloseableIterator<CIMInstance> syncVolumeIter = null;
    CloseableIterator<CIMObjectPath> repGroupPathIter = null;
    DbClient dbClient = jobContext.getDbClient();
    BlockMirrorCreateCompleter completer = (BlockMirrorCreateCompleter) getTaskCompleter();
    ;
    JobStatus jobStatus = getJobStatus();
    try {
        if (jobStatus == JobStatus.IN_PROGRESS) {
            return;
        }
        CIMConnectionFactory cimConnectionFactory = jobContext.getCimConnectionFactory();
        WBEMClient client = getWBEMClient(dbClient, cimConnectionFactory);
        List<BlockMirror> mirrors = dbClient.queryObject(BlockMirror.class, completer.getIds());
        if (jobStatus == JobStatus.SUCCESS || jobStatus == JobStatus.FAILED || jobStatus == JobStatus.FATAL_ERROR) {
            updatePools(client, dbClient, mirrors);
        }
        if (jobStatus == JobStatus.SUCCESS) {
            _log.info("Group mirror creation success");
            repGroupPathIter = client.associatorNames(getCimJob(), null, SmisConstants.SE_REPLICATION_GROUP, null, null);
            CIMObjectPath repGroupPath = repGroupPathIter.next();
            StorageSystem storage = dbClient.queryObject(StorageSystem.class, getStorageSystemURI());
            String repGroupID = (String) repGroupPath.getKey(SmisConstants.CP_INSTANCE_ID).getValue();
            repGroupID = SmisUtils.getTargetGroupName(repGroupID, storage.getUsingSmis80());
            CIMInstance syncInst = getSynchronizedInstance(client, repGroupPath);
            String syncType = CIMPropertyFactory.getPropertyValue(syncInst, SmisConstants.CP_SYNC_TYPE);
            syncVolumeIter = client.associatorInstances(repGroupPath, null, SmisConstants.CIM_STORAGE_VOLUME, null, null, false, _volumeProps);
            processCGMirrors(syncVolumeIter, client, dbClient, jobContext.getSmisCommandHelper(), storage, mirrors, repGroupID, syncInst.getObjectPath().toString(), syncType);
        } else if (isJobInTerminalFailedState()) {
            _log.info("Failed to create group mirrors");
            completer.error(dbClient, DeviceControllerException.exceptions.attachVolumeMirrorFailed(getMessage()));
            for (BlockMirror mirror : mirrors) {
                mirror.setInactive(true);
            }
            dbClient.persistObject(mirrors);
        }
    } catch (Exception e) {
        setPostProcessingErrorStatus("Encountered an internal error during block create CG mirror job status processing: " + e.getMessage());
        _log.error("Caught an exception while trying to updateStatus for SmisBlockCreateCGMirrorJob", e);
    } finally {
        if (syncVolumeIter != null) {
            syncVolumeIter.close();
        }
        if (repGroupPathIter != null) {
            repGroupPathIter.close();
        }
        super.updateStatus(jobContext);
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) BlockMirror(com.emc.storageos.db.client.model.BlockMirror) CIMObjectPath(javax.cim.CIMObjectPath) BlockMirrorCreateCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockMirrorCreateCompleter) CIMInstance(javax.cim.CIMInstance) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) CIMConnectionFactory(com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory) WBEMClient(javax.wbem.client.WBEMClient) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 32 with DbClient

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

the class SmisBlockCreateSnapshotJob 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) {
            _log.info(String.format("Post-processing successful snap creation task:%s. Expected: snapshot.size() = 1; Actual: snapshots.size() = %d", getTaskCompleter().getOpId(), snapshots.size()));
            // Get the snapshot device ID and set it against the BlockSnapshot object
            CIMConnectionFactory cimConnectionFactory = jobContext.getCimConnectionFactory();
            WBEMClient client = getWBEMClient(dbClient, cimConnectionFactory);
            syncVolumeIter = client.associatorNames(getCimJob(), null, SmisConstants.CIM_STORAGE_VOLUME, null, null);
            if (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);
                String wwn = CIMPropertyFactory.getPropertyValue(syncVolume, SmisConstants.CP_WWN_NAME);
                String alternateName = CIMPropertyFactory.getPropertyValue(syncVolume, SmisConstants.CP_NAME);
                // Lookup the associated snapshot based on the volume native device id
                BlockSnapshot snapshot = snapshots.get(0);
                Volume volume = dbClient.queryObject(Volume.class, snapshot.getParent().getURI());
                snapshot.setNativeId(syncDeviceID);
                snapshot.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(storage, snapshot));
                snapshot.setDeviceLabel(elementName);
                snapshot.setInactive(false);
                snapshot.setIsSyncActive(_wantSyncActive);
                snapshot.setCreationTime(Calendar.getInstance());
                snapshot.setWWN(wwn.toUpperCase());
                snapshot.setAlternateName(alternateName);
                commonSnapshotUpdate(snapshot, syncVolume, client, storage, volume.getNativeId(), syncDeviceID, true, dbClient);
                _log.info(String.format("For sync volume path %1$s, going to set blocksnapshot %2$s nativeId to %3$s (%4$s). Associated volume is %5$s (%6$s)", syncVolumePath.toString(), snapshot.getId().toString(), syncDeviceID, elementName, volume.getNativeId(), volume.getDeviceLabel()));
                dbClient.persistObject(snapshot);
            }
        } else if (jobStatus == JobStatus.FAILED || jobStatus == JobStatus.FATAL_ERROR) {
            _log.info("Failed to create snapshot");
            BlockSnapshot snapshot = snapshots.get(0);
            snapshot.setInactive(true);
            dbClient.persistObject(snapshot);
        }
    } catch (Exception e) {
        setPostProcessingErrorStatus("Encountered an internal error during block create snapshot job status processing: " + e.getMessage());
        _log.error("Caught an exception while trying to updateStatus for SmisBlockCreateSnapshotJob", e);
    } finally {
        if (syncVolumeIter != null) {
            syncVolumeIter.close();
        }
        super.updateStatus(jobContext);
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) 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) CIMConnectionFactory(com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory) Volume(com.emc.storageos.db.client.model.Volume) WBEMClient(javax.wbem.client.WBEMClient) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 33 with DbClient

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

the class SmisBlockDeleteMirrorJob method updateStatus.

@Override
public void updateStatus(JobContext jobContext) throws Exception {
    DbClient dbClient = jobContext.getDbClient();
    JobStatus jobStatus = getJobStatus();
    try {
        if (jobStatus == JobStatus.IN_PROGRESS) {
            return;
        }
        BlockMirrorDeleteCompleter completer = (BlockMirrorDeleteCompleter) getTaskCompleter();
        BlockMirror mirror = dbClient.queryObject(BlockMirror.class, completer.getMirrorURI());
        // If terminal state update storage pool capacity
        if (jobStatus == JobStatus.SUCCESS || jobStatus == JobStatus.FAILED || jobStatus == JobStatus.FATAL_ERROR) {
            CIMConnectionFactory cimConnectionFactory = jobContext.getCimConnectionFactory();
            WBEMClient client = getWBEMClient(dbClient, cimConnectionFactory);
            URI poolURI = mirror.getPool();
            // Update capacity of storage pools.
            SmisUtils.updateStoragePoolCapacity(dbClient, client, poolURI);
        }
        if (jobStatus == JobStatus.SUCCESS) {
            _log.info("Mirror delete success");
            Volume volume = dbClient.queryObject(Volume.class, mirror.getSource().getURI());
            dbClient.markForDeletion(mirror);
            _log.info(String.format("Deleted BlockMirror %s on Volume %s", mirror, volume));
        } else if (jobStatus == JobStatus.FATAL_ERROR || jobStatus == JobStatus.FAILED) {
            String msg = String.format("Failed to delete mirror %s", mirror.getId());
            _log.error(msg);
            getTaskCompleter().error(dbClient, DeviceControllerErrors.smis.jobFailed(msg));
        }
    } catch (Exception e) {
        setFatalErrorStatus("Encountered an internal error during block delete mirror job status processing: " + e.getMessage());
        _log.error("Caught an exception while trying to updateStatus for SmisBlockDeleteMirrorJob", e);
        getTaskCompleter().error(dbClient, DeviceControllerErrors.smis.jobFailed(e.getMessage()));
    } finally {
        super.updateStatus(jobContext);
    }
}
Also used : BlockMirrorDeleteCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockMirrorDeleteCompleter) DbClient(com.emc.storageos.db.client.DbClient) BlockMirror(com.emc.storageos.db.client.model.BlockMirror) CIMConnectionFactory(com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory) Volume(com.emc.storageos.db.client.model.Volume) WBEMClient(javax.wbem.client.WBEMClient) URI(java.net.URI)

Example 34 with DbClient

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

the class SmisBlockDetachCloneJob method updateStatus.

@Override
public void updateStatus(JobContext jobContext) throws Exception {
    _log.info("START updateStatus for clone detach");
    JobStatus jobStatus = getJobStatus();
    super.updateStatus(jobContext);
    if (jobStatus == JobStatus.IN_PROGRESS) {
        return;
    }
    DbClient dbClient = jobContext.getDbClient();
    VolumeDetachCloneCompleter taskCompleter = (VolumeDetachCloneCompleter) getTaskCompleter();
    Volume cloneVolume = dbClient.queryObject(Volume.class, taskCompleter.getId());
    Operation.Status op = Operation.Status.pending;
    String message = "Detaching volume clone";
    if (jobStatus == JobStatus.SUCCESS) {
        op = Operation.Status.ready;
        message = "Successfully detached volume clone";
    } else if (jobStatus == JobStatus.ERROR || jobStatus == JobStatus.FAILED || jobStatus == JobStatus.FATAL_ERROR) {
        op = Operation.Status.error;
        message = "Failed to detached volume clone";
    }
    // set to terminal status to stop polling job
    if (jobStatus == JobStatus.ERROR) {
        setFatalErrorStatus(message);
    }
    dbClient.updateTaskOpStatus(Volume.class, cloneVolume.getId(), taskCompleter.getOpId(), new Operation(op.name(), message));
    WorkflowStepCompleter.updateState(taskCompleter.getOpId(), op, message);
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) Volume(com.emc.storageos.db.client.model.Volume) VolumeDetachCloneCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.VolumeDetachCloneCompleter) Operation(com.emc.storageos.db.client.model.Operation)

Example 35 with DbClient

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

the class SmisBlockResumeMirrorJob method updateStatus.

@Override
public void updateStatus(JobContext jobContext) throws Exception {
    log.info("START updateStatus for resuming {}", getTaskCompleter().getId());
    DbClient dbClient = jobContext.getDbClient();
    JobStatus jobStatus = getJobStatus();
    try {
        if (jobStatus == JobStatus.IN_PROGRESS) {
            return;
        }
        BlockMirrorResumeCompleter taskCompleter = (BlockMirrorResumeCompleter) getTaskCompleter();
        if (jobStatus == JobStatus.SUCCESS) {
            log.info("Mirror resume success");
            BlockMirror mirror = dbClient.queryObject(BlockMirror.class, taskCompleter.getMirrorURI());
            log.info("Updating sync details for mirror {}", mirror.getId());
            WBEMClient client = getWBEMClient(dbClient, jobContext.getCimConnectionFactory());
            updateSynchronizationAspects(client, mirror);
            dbClient.persistObject(mirror);
            getTaskCompleter().ready(dbClient);
        } else if (jobStatus == JobStatus.ERROR) {
            log.info("Mirror resume failed");
        }
    } catch (Exception e) {
        String errorMsg = "Failed job to resume mirror: " + e.getMessage();
        log.error(errorMsg, e);
        setPostProcessingErrorStatus(errorMsg);
    } finally {
        super.updateStatus(jobContext);
        log.info("FINISH updateStatus for resuming {}", getTaskCompleter().getId());
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) BlockMirror(com.emc.storageos.db.client.model.BlockMirror) WBEMClient(javax.wbem.client.WBEMClient) BlockMirrorResumeCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockMirrorResumeCompleter)

Aggregations

DbClient (com.emc.storageos.db.client.DbClient)253 URI (java.net.URI)155 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)73 Volume (com.emc.storageos.db.client.model.Volume)67 ArrayList (java.util.ArrayList)58 Test (org.junit.Test)42 FileShare (com.emc.storageos.db.client.model.FileShare)34 NamedURI (com.emc.storageos.db.client.model.NamedURI)31 CIMObjectPath (javax.cim.CIMObjectPath)31 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)29 WBEMClient (javax.wbem.client.WBEMClient)29 StringSet (com.emc.storageos.db.client.model.StringSet)28 CIMConnectionFactory (com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory)28 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)26 MigrationCallbackException (com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException)25 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)22 InternalDbClient (com.emc.storageos.db.client.upgrade.InternalDbClient)22 VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)21 CIMInstance (javax.cim.CIMInstance)21 BlockObject (com.emc.storageos.db.client.model.BlockObject)20