Search in sources :

Example 21 with CIMConnectionFactory

use of com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory in project coprhd-controller by CoprHD.

the class SmisBlockSnapshotSessionLinkTargetJob method updateStatus.

/**
 * {@inheritDoc}
 */
@Override
public void updateStatus(JobContext jobContext) throws Exception {
    JobStatus jobStatus = getJobStatus();
    CloseableIterator<CIMObjectPath> volumeIter = null;
    try {
        DbClient dbClient = jobContext.getDbClient();
        TaskCompleter completer = getTaskCompleter();
        BlockSnapshot snapshot = dbClient.queryObject(BlockSnapshot.class, _snapshotURI);
        if (jobStatus == JobStatus.IN_PROGRESS) {
            return;
        }
        if (jobStatus == JobStatus.SUCCESS) {
            s_logger.info("Post-processing successful link snapshot session target {} for task {}", snapshot.getId(), completer.getOpId());
            // Get the snapshot session to which the target is being linked.
            BlockSnapshotSession snapSession = dbClient.queryObject(BlockSnapshotSession.class, completer.getId());
            // Get the snapshot device ID and set it against the BlockSnapshot object.
            BlockObject sourceObj = BlockObject.fetch(dbClient, snapshot.getParent().getURI());
            CIMConnectionFactory cimConnectionFactory = jobContext.getCimConnectionFactory();
            WBEMClient client = getWBEMClient(dbClient, cimConnectionFactory);
            volumeIter = client.associatorNames(getCimJob(), null, SmisConstants.CIM_STORAGE_VOLUME, null, null);
            while (volumeIter.hasNext()) {
                // Get the sync volume native device id
                CIMObjectPath volumePath = volumeIter.next();
                s_logger.info("volumePath: {}", volumePath.toString());
                CIMInstance volume = client.getInstance(volumePath, false, false, null);
                String volumeDeviceId = volumePath.getKey(SmisConstants.CP_DEVICE_ID).getValue().toString();
                s_logger.info("volumeDeviceId: {}", volumeDeviceId);
                if (volumeDeviceId.equals(sourceObj.getNativeId())) {
                    // Don't want the source, we want the linked target.
                    continue;
                }
                String volumeElementName = CIMPropertyFactory.getPropertyValue(volume, SmisConstants.CP_ELEMENT_NAME);
                s_logger.info("volumeElementName: {}", volumeElementName);
                String volumeWWN = CIMPropertyFactory.getPropertyValue(volume, SmisConstants.CP_WWN_NAME);
                s_logger.info("volumeWWN: {}", volumeWWN);
                String volumeAltName = CIMPropertyFactory.getPropertyValue(volume, SmisConstants.CP_NAME);
                s_logger.info("volumeAltName: {}", volumeAltName);
                StorageSystem system = dbClient.queryObject(StorageSystem.class, getStorageSystemURI());
                snapshot.setNativeId(volumeDeviceId);
                snapshot.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(system, snapshot));
                snapshot.setDeviceLabel(volumeElementName);
                snapshot.setInactive(false);
                snapshot.setIsSyncActive(Boolean.TRUE);
                snapshot.setCreationTime(Calendar.getInstance());
                snapshot.setWWN(volumeWWN.toUpperCase());
                snapshot.setAlternateName(volumeAltName);
                snapshot.setSettingsInstance(snapSession.getSessionInstance());
                commonSnapshotUpdate(snapshot, volume, client, system, sourceObj.getNativeId(), volumeDeviceId, false, dbClient);
                s_logger.info(String.format("For target volume path %1$s, going to set blocksnapshot %2$s nativeId to %3$s (%4$s). Associated volume is %5$s (%6$s)", volumePath.toString(), snapshot.getId().toString(), volumeDeviceId, volumeElementName, sourceObj.getNativeId(), sourceObj.getDeviceLabel()));
                dbClient.updateObject(snapshot);
            }
        } else if (jobStatus == JobStatus.FAILED || jobStatus == JobStatus.FATAL_ERROR) {
            s_logger.info("Failed to link snapshot session target {} for task {}", snapshot.getId(), completer.getOpId());
            snapshot.setInactive(true);
            dbClient.updateObject(snapshot);
        }
    } catch (Exception e) {
        setPostProcessingErrorStatus("Encountered an internal error in link snapshot session target job status processing: " + e.getMessage());
        s_logger.error("Encountered an internal error in link snapshot session target job status processing", e);
    } finally {
        if (volumeIter != null) {
            volumeIter.close();
        }
        super.updateStatus(jobContext);
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) CIMObjectPath(javax.cim.CIMObjectPath) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) CIMInstance(javax.cim.CIMInstance) CIMConnectionFactory(com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) WBEMClient(javax.wbem.client.WBEMClient) BlockObject(com.emc.storageos.db.client.model.BlockObject) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 22 with CIMConnectionFactory

use of com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory in project coprhd-controller by CoprHD.

the class SmisCreateListReplicaJob method updateStatus.

public void updateStatus(JobContext jobContext) throws Exception {
    CloseableIterator<CIMInstance> syncVolumeIter = null;
    DbClient dbClient = jobContext.getDbClient();
    JobStatus jobStatus = getJobStatus();
    try {
        if (jobStatus == JobStatus.IN_PROGRESS) {
            return;
        }
        List<? extends BlockObject> replicas = BlockObject.fetch(dbClient, getTaskCompleter().getIds());
        if (jobStatus == JobStatus.SUCCESS) {
            CIMConnectionFactory cimConnectionFactory = jobContext.getCimConnectionFactory();
            WBEMClient client = getWBEMClient(dbClient, cimConnectionFactory);
            if (_syncType == SmisConstants.MIRROR_VALUE || _syncType == SmisConstants.CLONE_VALUE) {
                updatePools(client, dbClient, (List<? extends Volume>) replicas);
            }
            syncVolumeIter = client.associatorInstances(getCimJob(), null, SmisConstants.CIM_STORAGE_VOLUME, null, null, false, _volumeProps);
            StorageSystem storage = dbClient.queryObject(StorageSystem.class, getStorageSystemURI());
            processListReplica(syncVolumeIter, client, dbClient, jobContext.getSmisCommandHelper(), storage, replicas, _syncType, _isSyncActive);
        } else if (jobStatus == JobStatus.FAILED || jobStatus == JobStatus.FATAL_ERROR) {
            _log.info("Failed to create list relica");
            for (BlockObject replica : replicas) {
                replica.setInactive(true);
            }
            dbClient.persistObject(replicas);
        }
    } catch (Exception e) {
        setPostProcessingErrorStatus("Encountered an internal error during create list replica job status processing: " + e.getMessage());
        _log.error("Caught an exception while trying to updateStatus for SmisCreateListReplicaJob", e);
    } finally {
        if (syncVolumeIter != null) {
            syncVolumeIter.close();
        }
        super.updateStatus(jobContext);
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) CIMConnectionFactory(com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory) WBEMClient(javax.wbem.client.WBEMClient) CIMInstance(javax.cim.CIMInstance) BlockObject(com.emc.storageos.db.client.model.BlockObject) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 23 with CIMConnectionFactory

use of com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory in project coprhd-controller by CoprHD.

the class SmisCreateMetaVolumeHeadJob method updateStatus.

/**
 * Called to update the job status when the create meta volume head job completes.
 * Sets native device ID to meta head volume.
 *
 * @param jobContext The job context.
 */
public void updateStatus(JobContext jobContext) throws Exception {
    CloseableIterator<CIMObjectPath> iterator = null;
    DbClient dbClient = jobContext.getDbClient();
    JobStatus jobStatus = getJobStatus();
    try {
        if (jobStatus == Job.JobStatus.IN_PROGRESS) {
            return;
        }
        String opId = getTaskCompleter().getOpId();
        StringBuilder logMsgBuilder = new StringBuilder(String.format("Updating post processing status of job %s to %s, task: %s", this.getJobName(), jobStatus.name(), opId));
        CIMConnectionFactory cimConnectionFactory = jobContext.getCimConnectionFactory();
        WBEMClient client = getWBEMClient(dbClient, cimConnectionFactory);
        iterator = client.associatorNames(getCimJob(), null, SmisConstants.CIM_STORAGE_VOLUME, null, null);
        Calendar now = Calendar.getInstance();
        Volume metaHead = dbClient.queryObject(Volume.class, _metaHeadId);
        if (jobStatus == Job.JobStatus.SUCCESS) {
            CIMObjectPath volumePath = iterator.next();
            CIMProperty<String> deviceID = (CIMProperty<String>) volumePath.getKey(SmisConstants.CP_DEVICE_ID);
            String headNativeID = deviceID.getValue();
            metaHead.setCreationTime(now);
            metaHead.setNativeId(headNativeID);
            metaHead.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(dbClient, metaHead));
            dbClient.persistObject(metaHead);
            logMsgBuilder.append("\n");
            logMsgBuilder.append(String.format("%n   Task %s created meta head volume: %s with device ID: %s", opId, metaHead.getLabel(), headNativeID));
            _log.info(logMsgBuilder.toString());
        } else if (jobStatus == JobStatus.FAILED || jobStatus == JobStatus.FATAL_ERROR) {
            logMsgBuilder.append("\n");
            logMsgBuilder.append(String.format("Task %s failed to create meta head volume: %s caused by: %s", opId, metaHead.getLabel(), _errorDescription));
            Volume volume = dbClient.queryObject(Volume.class, _metaHeadId);
            volume.setInactive(true);
            dbClient.persistObject(volume);
            _log.error(logMsgBuilder.toString());
            setFailedStatus(logMsgBuilder.toString());
        }
    } catch (Exception e) {
        _log.error("Caught an exception while trying to process status for " + this.getJobName(), e);
        setPostProcessingErrorStatus("Encountered an internal error during " + this.getJobName() + " job status processing : " + e.getMessage());
    } finally {
        if (iterator != null) {
            iterator.close();
        }
        _metaVolumeTaskCompleter.setLastStepStatus(jobStatus);
        if (isJobInTerminalFailedState()) {
            super.updateStatus(jobContext);
        }
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) Calendar(java.util.Calendar) CIMObjectPath(javax.cim.CIMObjectPath) CIMConnectionFactory(com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory) Volume(com.emc.storageos.db.client.model.Volume) CIMProperty(javax.cim.CIMProperty) WBEMClient(javax.wbem.client.WBEMClient)

Example 24 with CIMConnectionFactory

use of com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory in project coprhd-controller by CoprHD.

the class SmisCreateMetaVolumeMembersJob method updateStatus.

/**
 * Called to update the job status when the create meta members job completes.
 *
 * @param jobContext The job context.
 */
public void updateStatus(JobContext jobContext) throws Exception {
    CloseableIterator<CIMObjectPath> iterator = null;
    DbClient dbClient = jobContext.getDbClient();
    JobStatus jobStatus = getJobStatus();
    try {
        if (jobStatus == JobStatus.IN_PROGRESS) {
            return;
        }
        String opId = getTaskCompleter().getOpId();
        StringBuilder logMsgBuilder = new StringBuilder(String.format("Updating status of job %s to %s, task: %s", this.getJobName(), jobStatus.name(), opId));
        CIMConnectionFactory cimConnectionFactory = jobContext.getCimConnectionFactory();
        WBEMClient client = getWBEMClient(dbClient, cimConnectionFactory);
        iterator = client.associatorNames(getCimJob(), null, SmisConstants.CIM_STORAGE_VOLUME, null, null);
        if (jobStatus == JobStatus.SUCCESS) {
            // verify that all meta members have been created
            List<CIMObjectPath> volumePaths = new ArrayList<CIMObjectPath>();
            while (iterator.hasNext()) {
                volumePaths.add(iterator.next());
            }
            if (volumePaths.size() != _count) {
                logMsgBuilder.append("\n");
                logMsgBuilder.append(String.format("   Failed to create required number %s of meta members for meta head %s caused by %s: , task: %s.", _count, _metaHead.getLabel(), _errorDescription, opId));
                _log.error(logMsgBuilder.toString());
                setFailedStatus(logMsgBuilder.toString());
            } else {
                // Process meta members
                logMsgBuilder.append("\n");
                logMsgBuilder.append(String.format("   Created required number %s of meta members for meta head %s, task: %s .", _count, _metaHead.getLabel(), opId));
                Iterator<CIMObjectPath> volumePathsIterator = volumePaths.iterator();
                while (volumePathsIterator.hasNext()) {
                    CIMObjectPath volumePath = volumePathsIterator.next();
                    CIMProperty<String> deviceID = (CIMProperty<String>) volumePath.getKey(SmisConstants.CP_DEVICE_ID);
                    String nativeID = deviceID.getValue();
                    _metaMembers.add(nativeID);
                    logMsgBuilder.append(String.format("%n   Meta member device ID: %s", nativeID));
                }
                _log.info(logMsgBuilder.toString());
            }
        } else if (jobStatus == JobStatus.FAILED || jobStatus == JobStatus.FATAL_ERROR) {
            logMsgBuilder.append("\n");
            logMsgBuilder.append(String.format("Task %s failed to create meta members for meta head volume: %s caused by: %s", opId, _metaHead.getLabel(), _errorDescription));
            _log.error(logMsgBuilder.toString());
            setFailedStatus(logMsgBuilder.toString());
        }
    } catch (Exception e) {
        _log.error("Caught an exception while trying to updateStatus for " + this.getJobName(), e);
        setPostProcessingErrorStatus("Encountered an internal error during " + this.getJobName() + " job status processing : " + e.getMessage());
    } finally {
        if (iterator != null) {
            iterator.close();
        }
        _metaVolumeTaskCompleter.setLastStepStatus(jobStatus);
        if (jobStatus != JobStatus.IN_PROGRESS) {
            // set meta members native ids in step data in WF
            String opId = _metaVolumeTaskCompleter.getVolumeTaskCompleter().getOpId();
            WorkflowService.getInstance().storeStepData(opId, _metaMembers);
            _log.debug("Set meta members for meta volume in WF. Members: {}", _metaMembers);
            // Also set meta members in volume itself. Can be used to do cleanup at delete time
            // (in case rollback fails).
            StringSet metaMembersSet = new StringSet(_metaMembers);
            _metaHead.setMetaVolumeMembers(metaMembersSet);
            dbClient.persistObject(_metaHead);
            _log.info("Set meta members for meta volume in metaHead. Members: {}", _metaMembers);
        // TEMPER USED for negative testing.
        // jobStatus = Job.JobStatus.FAILED;
        // TEMPER
        }
        // operation.
        if (isJobInTerminalFailedState()) {
            super.updateStatus(jobContext);
        }
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) CIMObjectPath(javax.cim.CIMObjectPath) ArrayList(java.util.ArrayList) CIMConnectionFactory(com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory) CIMProperty(javax.cim.CIMProperty) StringSet(com.emc.storageos.db.client.model.StringSet) WBEMClient(javax.wbem.client.WBEMClient)

Example 25 with CIMConnectionFactory

use of com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory in project coprhd-controller by CoprHD.

the class SmisDeleteVolumeJob method updateStatus.

/**
 * Called to update the job status when the volume delete job completes.
 *
 * @param jobContext The job context.
 */
public void updateStatus(JobContext jobContext) throws Exception {
    DbClient dbClient = jobContext.getDbClient();
    JobStatus jobStatus = getJobStatus();
    try {
        if (jobStatus == JobStatus.IN_PROGRESS) {
            return;
        }
        CIMConnectionFactory cimConnectionFactory = jobContext.getCimConnectionFactory();
        WBEMClient client = getWBEMClient(dbClient, cimConnectionFactory);
        // Get list of volumes; get set of storage pool ids to which they belong.
        List<Volume> volumes = new ArrayList<Volume>();
        Set<URI> poolURIs = new HashSet<URI>();
        for (URI id : getTaskCompleter().getIds()) {
            Volume volume = dbClient.queryObject(Volume.class, id);
            if (volume != null && !volume.getInactive()) {
                volumes.add(volume);
                poolURIs.add(volume.getPool());
            }
        }
        // If terminal job state update storage pool capacity
        if (jobStatus == JobStatus.SUCCESS || jobStatus == JobStatus.FAILED || jobStatus == JobStatus.FATAL_ERROR) {
            // Update capacity of storage pools.
            for (URI poolURI : poolURIs) {
                SmisUtils.updateStoragePoolCapacity(dbClient, client, poolURI);
            }
        }
        StringBuilder logMsgBuilder = new StringBuilder();
        if (jobStatus == JobStatus.SUCCESS) {
            for (Volume volume : volumes) {
                if (logMsgBuilder.length() != 0) {
                    logMsgBuilder.append("\n");
                }
                logMsgBuilder.append(String.format("Successfully deleted volume %s", volume.getId()));
            }
        } else if (jobStatus == JobStatus.FAILED || jobStatus == JobStatus.FATAL_ERROR) {
            for (URI id : getTaskCompleter().getIds()) {
                if (logMsgBuilder.length() != 0) {
                    logMsgBuilder.append("\n");
                }
                logMsgBuilder.append(String.format("Failed to delete volume: %s", id));
            }
            // This fix, converts a RDF device to non-rdf device in ViPr, so that this volume is exposed to UI for deletion again.
            for (Volume volume : volumes) {
                if (volume.checkForSRDF()) {
                    volume.setPersonality(NullColumnValueGetter.getNullStr());
                    volume.setAccessState(Volume.VolumeAccessState.READWRITE.name());
                    volume.setLinkStatus(NullColumnValueGetter.getNullStr());
                    if (!NullColumnValueGetter.isNullNamedURI(volume.getSrdfParent())) {
                        volume.setSrdfParent(new NamedURI(NullColumnValueGetter.getNullURI(), NullColumnValueGetter.getNullStr()));
                        volume.setSrdfCopyMode(NullColumnValueGetter.getNullStr());
                        volume.setSrdfGroup(NullColumnValueGetter.getNullURI());
                    } else if (null != volume.getSrdfTargets()) {
                        volume.getSrdfTargets().clear();
                    }
                }
            }
            dbClient.updateObject(volumes);
        }
        if (logMsgBuilder.length() > 0) {
            _log.info(logMsgBuilder.toString());
        }
    } catch (Exception e) {
        setPostProcessingErrorStatus("Encountered an internal error during delete volume job status processing: " + e.getMessage());
        _log.error("Caught exception while handling updateStatus for delete volume job.", e);
    } finally {
        super.updateStatus(jobContext);
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) NamedURI(com.emc.storageos.db.client.model.NamedURI) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) CIMConnectionFactory(com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory) Volume(com.emc.storageos.db.client.model.Volume) WBEMClient(javax.wbem.client.WBEMClient) HashSet(java.util.HashSet)

Aggregations

CIMConnectionFactory (com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory)32 DbClient (com.emc.storageos.db.client.DbClient)28 WBEMClient (javax.wbem.client.WBEMClient)27 CIMObjectPath (javax.cim.CIMObjectPath)18 Volume (com.emc.storageos.db.client.model.Volume)14 CIMInstance (javax.cim.CIMInstance)14 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)13 URI (java.net.URI)11 BlockMirror (com.emc.storageos.db.client.model.BlockMirror)5 BlockObject (com.emc.storageos.db.client.model.BlockObject)5 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)5 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)5 CIMProperty (javax.cim.CIMProperty)5 StoragePool (com.emc.storageos.db.client.model.StoragePool)4 StringMap (com.emc.storageos.db.client.model.StringMap)4 ArrayList (java.util.ArrayList)4 CimConnection (com.emc.storageos.cimadapter.connections.cim.CimConnection)3 BlockSnapshotSession (com.emc.storageos.db.client.model.BlockSnapshotSession)3 SMIPluginException (com.emc.storageos.plugins.metering.smis.SMIPluginException)3 TaskCompleter (com.emc.storageos.volumecontroller.TaskCompleter)3