Exemplo n.º 1
0
/*
 * Retrieve a specific instance given an object path
 */
wbem::framework::Instance* wbem::performance::PerformanceMetricFactory::getInstance(
	framework::ObjectPath &path, framework::attribute_names_t &attributes)
throw (wbem::framework::Exception)
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);

	// Verify attributes
	checkAttributes(attributes);

	framework::Instance *pInstance = NULL;
	try
	{
		pInstance = new framework::Instance(path);

		framework::Attribute instanceIdAttr = path.getKeyValue(INSTANCEID_KEY);

		std::string deviceUid;
		metric_type metric;
		if (!splitInstanceID(instanceIdAttr, deviceUid, metric))
		{
			throw framework::ExceptionBadParameter(instanceIdAttr.asStr().c_str());
		}

		NVM_UID nvmUid;
		uid_copy(deviceUid.c_str(), nvmUid);

		// serialNumberStr is used in more than 1 attribute so getting here.
		std::string serialNumberStr = getDeviceSerialNumber(nvmUid);

		std::string metricName = getMetricElementNameFromType(metric) + " " + serialNumberStr;
		framework::Attribute elementNameAttr(metricName, false);
		(*pInstance).setAttribute(wbem::ELEMENTNAME_KEY, elementNameAttr, attributes);

		const std::string metricDefId
			= PerformanceMetricDefinitionFactory::getMetricId(metric);
		framework::Attribute metricDefinitionAttr(metricDefId, false);
		(*pInstance).setAttribute(wbem::METRICDEFINITION_ID_KEY, metricDefinitionAttr, attributes);

		std::string metricDimm = METRIC_DIMM_STR + serialNumberStr;
		framework::Attribute measuredElementNameAttr(metricDimm, false);
		(*pInstance).setAttribute(wbem::MEASUREDELEMENTNAME_KEY, measuredElementNameAttr, attributes);

		NVM_UINT64 metricValue = getValueForDeviceMetric(nvmUid, metric);
		std::ostringstream stream;
		stream << metricValue;
		framework::Attribute metricValueAttr(stream.str(), false);
		(*pInstance).setAttribute(wbem::METRICVALUE_KEY, metricValueAttr, attributes);
	}
	catch (framework::Exception) // clean up and re-throw
	{
		if (pInstance != NULL)
		{
			delete pInstance;
			pInstance = NULL;
		}
		throw;
	}
	return pInstance;
}
Exemplo n.º 2
0
/*
 * Retrieve a specific instance given an object path
 */
wbem::framework::Instance* wbem::support::DiagnosticLogFactory::getInstance(
		framework::ObjectPath &path, framework::attribute_names_t &attributes)
throw (wbem::framework::Exception)
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);

	// create the instance, initialize with attributes from the path
	framework::Instance *pInstance = new framework::Instance(path);
	try
	{
		checkAttributes(attributes);

		// get the host server name
		std::string hostName = wbem::server::getHostName();

		// make sure the instance ID passed in matches this host
		framework::Attribute instanceID = path.getKeyValue(INSTANCEID_KEY);
		if (instanceID.stringValue() == std::string(DIAGNOSTICLOG_NAME + hostName))
		{
			// ElementName - "NVDIMM Diagnostic Log"
			if (containsAttribute(ELEMENTNAME_KEY, attributes))
			{
				framework::Attribute elementNameAttr(DIAGNOSTICLOG_NAME, false);
				pInstance->setAttribute(ELEMENTNAME_KEY, elementNameAttr, attributes);
			}

			// CurrentNumberOfRecords - One per test type per dimm
			if (containsAttribute(CURRENTNUMBEROFRECORDS_KEY, attributes))
			{
				diagnosticResults_t results;
				int count = gatherDiagnosticResults(&results);
				framework::Attribute recordCntAttr((NVM_UINT64)count, false);
				pInstance->setAttribute(CURRENTNUMBEROFRECORDS_KEY, recordCntAttr, attributes);
			}
		}
		else
		{
			throw framework::ExceptionBadParameter(INSTANCEID_KEY.c_str());
		}
	}
	catch (framework::Exception &) // clean up and re-throw
	{
		delete pInstance;
		throw;
	}

	return pInstance;
}