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);
}
}
}
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);
}
}
}
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);
}
}
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);
}
}
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;
}
Aggregations