use of javax.cim.CIMProperty 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.cim.CIMProperty in project coprhd-controller by CoprHD.
the class SmisReplicaCreationJobs method getProvisionedCapacityInformation.
protected long getProvisionedCapacityInformation(WBEMClient client, CIMInstance syncVolumeInstance) {
Long provisionedCapacity = 0L;
try {
if (syncVolumeInstance != null) {
CIMProperty consumableBlocks = syncVolumeInstance.getProperty(SmisConstants.CP_CONSUMABLE_BLOCKS);
CIMProperty blockSize = syncVolumeInstance.getProperty(SmisConstants.CP_BLOCK_SIZE);
// calculate provisionedCapacity = consumableBlocks * block size
provisionedCapacity = Long.valueOf(consumableBlocks.getValue().toString()) * Long.valueOf(blockSize.getValue().toString());
}
} catch (Exception e) {
_log.error("Updating ProvisionedCapacity failed for Volume {}", syncVolumeInstance.getObjectPath(), e);
}
return provisionedCapacity;
}
use of javax.cim.CIMProperty in project coprhd-controller by CoprHD.
the class SmisReplicaCreationJobs method getAllocatedCapacityInformation.
protected long getAllocatedCapacityInformation(WBEMClient client, CIMInstance syncVolumeInstance) {
Long allocatedCapacity = 0L;
try {
if (syncVolumeInstance != null) {
CloseableIterator<CIMInstance> iterator = client.referenceInstances(syncVolumeInstance.getObjectPath(), SmisConstants.CIM_ALLOCATED_FROM_STORAGEPOOL, null, false, SmisConstants.PS_SPACE_CONSUMED);
if (iterator.hasNext()) {
CIMInstance allocatedFromStoragePoolPath = iterator.next();
CIMProperty spaceConsumed = allocatedFromStoragePoolPath.getProperty(SmisConstants.CP_SPACE_CONSUMED);
allocatedCapacity = Long.valueOf(spaceConsumed.getValue().toString());
}
}
} catch (Exception e) {
_log.error("Updating Allocated Capacity failed for Volume {}", syncVolumeInstance.getObjectPath(), e);
}
return allocatedCapacity;
}
use of javax.cim.CIMProperty in project coprhd-controller by CoprHD.
the class Util method modifyCimObjectPathProperties.
/**
* Generic routine that will take a cimObjectPath and examine it. It will look through the keys and check their
* values for the specified 'delimiter'. If it exists, then all instances of 'searchRegex' will be changed to
* 'replaceWith'.
*
* If there was a modification, keyMap will have a Constants.USING_SMIS80_DELIMITERS set to true.
*
* @param keyMap [in/out] Map of String to Objects. Context used for scanning and discovery. Can pass null if
* this is not necessary to use.
* @param cimObjectPath [in] - CIMObjectPath
* @param delimiter [in] - Check if any key values contain this delimiter
* @param searchRegex [in] - Substring search string
* @param replaceWith [in] - Replacement string
* @return CIMObjectPath, that may have been modified.
*/
private static Object modifyCimObjectPathProperties(Map<String, Object> keyMap, CIMObjectPath cimObjectPath, String delimiter, String searchRegex, String replaceWith) {
CIMObjectPath result = cimObjectPath;
boolean isModified = false;
CIMProperty<?>[] properties = cimObjectPath.getKeys();
CIMProperty<?>[] changedProperties = new CIMProperty<?>[properties.length];
for (int index = 0; index < properties.length; index++) {
CIMProperty property = properties[index];
Object value = cimObjectPath.getKeyValue(property.getName());
if (value instanceof String) {
String string = (String) value;
changedProperties[index] = property;
if (string.contains(delimiter)) {
String modified = string.replaceAll(searchRegex, replaceWith);
CIMProperty changed = new CIMProperty<>(property.getName(), CIMDataType.STRING_T, modified, true, false, null);
changedProperties[index] = changed;
isModified = true;
if (keyMap != null) {
keyMap.put(Constants.USING_SMIS80_DELIMITERS, Boolean.TRUE);
}
}
}
}
if (isModified) {
result = CimObjectPathCreator.createInstance(cimObjectPath.getObjectName(), cimObjectPath.getNamespace(), changedProperties);
}
return result;
}
use of javax.cim.CIMProperty in project coprhd-controller by CoprHD.
the class CimSubscriptionManager method createSubscription.
/**
* Creates an indication subscription in the CIMOM for the given filter.
*
* @param filterInfo the filter information.
*
* @return the CIM object path of the subscription
*
* @throws WBEMException, ConnectionManagerException
*/
protected CIMObjectPath createSubscription(CimFilterInfo filterInfo) throws WBEMException, ConnectionManagerException {
CIMObjectPath filterPath;
if (filterInfo instanceof CimManagedFilterInfo) {
filterPath = createFilter((CimManagedFilterInfo) filterInfo);
} else {
filterPath = getInstance(CimConstants.CIM_FILTER_NAME, filterInfo.getName()).getObjectPath();
}
s_logger.trace("filterPath :{}", filterPath);
CIMProperty<?> filterProp = new CIMProperty<CIMObjectPath>(CimConstants.SUBSCRIPTION_PROP_FILTER, new CIMDataType(CimConstants.CIM_FILTER_NAME), filterPath);
CIMProperty<?> handlerProp = new CIMProperty<CIMObjectPath>(CimConstants.SUBSCRIPTION_PROP_HANDLER, new CIMDataType(CimConstants.CIM_HANDLER_NAME), getHandler());
s_logger.trace("filterProp :{}", filterProp);
s_logger.trace("handlerProp :{}", handlerProp);
CIMProperty<?>[] subscriptionProperties = new CIMProperty[] { filterProp, handlerProp };
CIMObjectPath subscriptionPath = createInstance(CimConstants.CIM_SUBSCRIPTION_NAME, subscriptionProperties);
_subscriptionPaths.add(subscriptionPath);
s_logger.trace("subscriptionPath :{}", subscriptionPath);
return subscriptionPath;
}
Aggregations