Search in sources :

Example 81 with WBEMClient

use of javax.wbem.client.WBEMClient 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 82 with WBEMClient

use of javax.wbem.client.WBEMClient 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 83 with WBEMClient

use of javax.wbem.client.WBEMClient 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)

Example 84 with WBEMClient

use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.

the class SmisVnxCreateCGCloneJob 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;
        }
        CloneCreateCompleter completer = (CloneCreateCompleter) getTaskCompleter();
        List<Volume> clones = dbClient.queryObject(Volume.class, completer.getIds());
        if (jobStatus == JobStatus.SUCCESS) {
            CIMConnectionFactory cimConnectionFactory = jobContext.getCimConnectionFactory();
            WBEMClient client = getWBEMClient(dbClient, cimConnectionFactory);
            // generate a UUID for the set of clones
            String setId = UUID.randomUUID().toString();
            syncVolumeIter = client.associatorInstances(getCimJob(), null, SmisConstants.CIM_STORAGE_VOLUME, null, null, false, _volumeProps);
            processCGClones(syncVolumeIter, client, dbClient, clones, setId, isSyncActive);
        } else if (jobStatus == JobStatus.FAILED || jobStatus == JobStatus.FATAL_ERROR) {
            _log.info("Failed to create clone");
            for (Volume clone : clones) {
                clone.setInactive(true);
            }
            dbClient.persistObject(clones);
        }
    } catch (Exception e) {
        setPostProcessingErrorStatus("Encountered an internal error during create CG clone job status processing: " + e.getMessage());
        _log.error("Caught an exception while trying to updateStatus for SmisVnxCreateCGCloneJob", e);
    } finally {
        if (syncVolumeIter != null) {
            syncVolumeIter.close();
        }
        super.updateStatus(jobContext);
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) Volume(com.emc.storageos.db.client.model.Volume) CIMConnectionFactory(com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory) CloneCreateCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.CloneCreateCompleter) WBEMClient(javax.wbem.client.WBEMClient) CIMInstance(javax.cim.CIMInstance)

Example 85 with WBEMClient

use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.

the class SmisWaitForGroupSynchronizedJob method poll.

@Override
public JobPollResult poll(JobContext jobContext, long trackingPeriodInMillis) {
    JobPollResult pollResult = new JobPollResult();
    DbClient dbClient = jobContext.getDbClient();
    CIMConnectionFactory factory = jobContext.getCimConnectionFactory();
    WBEMClient client = getWBEMClient(dbClient, factory);
    TaskCompleter completer = getTaskCompleter();
    List<Volume> clones = dbClient.queryObject(Volume.class, completer.getIds());
    try {
        pollResult.setJobName(getJobName());
        pollResult.setJobId(SmisConstants.CP_PERCENT_SYNCED);
        pollResult.setJobStatus(JobStatus.IN_PROGRESS);
        CIMObjectPath path = getGroupSyncPath();
        // no corresponding sync obj, set to complete
        if (SmisConstants.NULL_IBM_CIM_OBJECT_PATH.equals(path)) {
            log.info("Sync complete");
            pollResult.setJobPercentComplete(100);
            pollResult.setJobStatus(JobStatus.SUCCESS);
            completer.ready(dbClient);
            return pollResult;
        }
        String[] propertyKeys = { SmisConstants.CP_SYNC_STATE, SmisConstants.CP_SYNC_TYPE, SmisConstants.CP_PERCENT_SYNCED, SmisConstants.CP_PROGRESS_STATUS };
        CIMInstance syncInstance = client.getInstance(path, false, false, propertyKeys);
        if (syncInstance != null) {
            String state = CIMPropertyFactory.getPropertyValue(syncInstance, SmisConstants.CP_SYNC_STATE);
            String type = CIMPropertyFactory.getPropertyValue(syncInstance, SmisConstants.CP_SYNC_TYPE);
            String percent = CIMPropertyFactory.getPropertyValue(syncInstance, SmisConstants.CP_PERCENT_SYNCED);
            String status = CIMPropertyFactory.getPropertyValue(syncInstance, SmisConstants.CP_PROGRESS_STATUS);
            String msg = String.format("Target=%s, State=%s, Type=%s, Percent=%s, Status=%s", clones.get(0).getId(), state, type, percent, status);
            log.info(msg);
            pollResult.setJobPercentComplete(Integer.parseInt(percent));
            if (COMPLETE.equals(percent)) {
                pollResult.setJobStatus(JobStatus.SUCCESS);
                completer.ready(dbClient);
            }
        } else {
            pollResult.setJobStatus(JobStatus.FAILED);
        }
    } catch (Exception e) {
        log.error("Failed to update synchronization", e);
        pollResult.setJobStatus(JobStatus.FAILED);
        completer.error(dbClient, DeviceControllerException.errors.jobFailed(e));
    }
    return pollResult;
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) CIMConnectionFactory(com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory) Volume(com.emc.storageos.db.client.model.Volume) CIMObjectPath(javax.cim.CIMObjectPath) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) JobPollResult(com.emc.storageos.volumecontroller.impl.JobPollResult) WBEMClient(javax.wbem.client.WBEMClient) CIMInstance(javax.cim.CIMInstance) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Aggregations

WBEMClient (javax.wbem.client.WBEMClient)110 CIMObjectPath (javax.cim.CIMObjectPath)75 CIMInstance (javax.cim.CIMInstance)69 WBEMException (javax.wbem.WBEMException)42 ArrayList (java.util.ArrayList)39 URI (java.net.URI)35 DbClient (com.emc.storageos.db.client.DbClient)29 Volume (com.emc.storageos.db.client.model.Volume)29 CIMConnectionFactory (com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory)27 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)25 HashSet (java.util.HashSet)25 CimConnection (com.emc.storageos.cimadapter.connections.cim.CimConnection)24 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)18 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)18 HashMap (java.util.HashMap)17 ExportMask (com.emc.storageos.db.client.model.ExportMask)16 SmisException (com.emc.storageos.volumecontroller.impl.smis.SmisException)16 CIMProperty (javax.cim.CIMProperty)14 UnsignedInteger32 (javax.cim.UnsignedInteger32)14 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)13