00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00035 #include "OW_config.h"
00036 #include "OW_CppProviderIncludes.hpp"
00037 #include "OW_ConfigOpts.hpp"
00038 #include "OW_UUID.hpp"
00039 #include "OW_Thread.hpp"
00040
00041 namespace OW_NAMESPACE
00042 {
00043
00044 namespace
00045 {
00046 const String COMPONENT_NAME("ow.provider.OpenWBEM_ObjectManager");
00047 const String CLASS_OpenWBEM_ObjectManager("OpenWBEM_ObjectManager");
00048 const String CLASS_OpenWBEM_InternalData("OpenWBEM_InternalData");
00049 const String Class_OpenWBEM_ComputerSystem("OpenWBEM_UnitaryComputerSystem");
00050 const String dataKey("OpenWBEM_ObjectManager.Name");
00051 const String CLASS_CIM_InstModification("CIM_InstModification");
00052 const String CLASS_OpenWBEM_HostedObjectManager("OpenWBEM_HostedObjectManager");
00053 const CIMName PROP_Antecedent("Antecedent");
00054 const CIMName PROP_Dependent("Dependent");
00055 const CIMName PROP_SystemCreationClassName("SystemCreationClassName");
00056 const CIMName PROP_CreationClassName("CreationClassName");
00057 const CIMName PROP_Name("Name");
00058 const CIMName PROP_SystemName("SystemName");
00059 }
00060
00061 using namespace WBEMFlags;
00062 class OpenWBEM_ObjectManagerInstProv
00063 : public CppReadOnlyInstanceProviderIFC
00064 , public CppSimpleInstanceProviderIFC
00065 , public CppIndicationProviderIFC
00066 #ifndef OW_DISABLE_ASSOCIATION_TRAVERSAL
00067 , public CppSimpleAssociatorProviderIFC
00068 #endif
00069 {
00070 private:
00071
00072 CIMInstance m_inst;
00073 bool m_haveSubscriptions;
00074
00075 public:
00077 OpenWBEM_ObjectManagerInstProv()
00078 : m_inst(CIMNULL)
00079 , m_haveSubscriptions(false)
00080 {
00081 }
00082
00084 virtual void getInstanceProviderInfo(InstanceProviderInfo& info)
00085 {
00086 info.addInstrumentedClass(CLASS_OpenWBEM_ObjectManager);
00087 info.addInstrumentedClass(CLASS_OpenWBEM_HostedObjectManager);
00088 }
00089
00090 #ifndef OW_DISABLE_ASSOCIATION_TRAVERSAL
00091
00092 virtual void getAssociatorProviderInfo(AssociatorProviderInfo& info)
00093 {
00094 info.addInstrumentedClass(CLASS_OpenWBEM_HostedObjectManager);
00095 }
00096 #endif // #ifndef OW_DISABLE_ASSOCIATION_TRAVERSAL
00097
00099 virtual void getIndicationProviderInfo(IndicationProviderInfo& info)
00100 {
00101
00102 const char* theMonitoredClasses[] =
00103 {
00104 "OpenWBEM_ObjectManager",
00105 0
00106 };
00107
00108
00109 const char* instanceLifeCycleIndicationClassNames[] =
00110 {
00111 "CIM_InstModification",
00112 "CIM_InstIndication",
00113 "CIM_Indication",
00114 0
00115 };
00116
00117 for (const char** pIndicationClassName = instanceLifeCycleIndicationClassNames;
00118 *pIndicationClassName != 0;
00119 ++pIndicationClassName)
00120 {
00121 const char* indicationClassName = *pIndicationClassName;
00122 IndicationProviderInfoEntry e(indicationClassName);
00123 for (const char** pClassName = theMonitoredClasses;
00124 *pClassName != 0;
00125 ++pClassName)
00126 {
00127 const char* className = *pClassName;
00128 e.classes.push_back(className);
00129 }
00130 info.addInstrumentedClass(e);
00131
00132 }
00133 }
00134
00135 void activateFilter(
00136 const ProviderEnvironmentIFCRef& env,
00137 const WQLSelectStatement& filter,
00138 const String& eventType,
00139 const String& nameSpace,
00140 const StringArray& classes,
00141 bool firstActivation
00142 )
00143 {
00144 m_haveSubscriptions = true;
00145 }
00146
00147 void deActivateFilter(
00148 const ProviderEnvironmentIFCRef& env,
00149 const WQLSelectStatement& filter,
00150 const String& eventType,
00151 const String& nameSpace,
00152 const StringArray& classes,
00153 bool lastActivation
00154 )
00155 {
00156 if (lastActivation)
00157 {
00158 m_haveSubscriptions = false;
00159 }
00160 }
00161
00163 virtual void initialize(const ProviderEnvironmentIFCRef &env)
00164 {
00165
00166 String interopNS = env->getConfigItem(ConfigOpts::INTEROP_SCHEMA_NAMESPACE_opt, OW_DEFAULT_INTEROP_SCHEMA_NAMESPACE);
00167 CIMOMHandleIFCRef rephdl(env->getRepositoryCIMOMHandle());
00168
00169 String omName;
00170 try
00171 {
00172
00173 CIMObjectPath omNamePath(CLASS_OpenWBEM_InternalData, interopNS);
00174 omNamePath.setKeyValue(PROP_Name, CIMValue(dataKey));
00175 CIMInstance nameInst(rephdl->getInstance(interopNS, omNamePath));
00176 omName = nameInst.getPropertyValue("Value").toString();
00177 }
00178 catch (CIMException& e)
00179 {
00180 if (e.getErrNo() == CIMException::NOT_FOUND)
00181 {
00182 #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00183 omName = OW_PACKAGE_PREFIX ":";
00184 if (omName == ":")
00185 {
00186
00187 omName = "OpenWBEM:";
00188 }
00189 omName += UUID().toString();
00190
00191
00192 CIMClass OpenWBEM_InternalData(rephdl->getClass(interopNS, CLASS_OpenWBEM_InternalData));
00193 CIMInstance newData(OpenWBEM_InternalData.newInstance());
00194 newData.updatePropertyValue(PROP_Name, CIMValue(dataKey));
00195 newData.updatePropertyValue("Value", CIMValue(omName));
00196 rephdl->createInstance(interopNS, newData);
00197 #else
00198 throw;
00199 #endif
00200 }
00201 else
00202 {
00203 throw;
00204 }
00205 }
00206
00207 m_inst = createTheInstance(env, omName);
00208 }
00209
00211 virtual void shuttingDown(const ProviderEnvironmentIFCRef &env)
00212 {
00213 if (m_haveSubscriptions)
00214 {
00215
00216 String interopNS = env->getConfigItem(ConfigOpts::INTEROP_SCHEMA_NAMESPACE_opt, OW_DEFAULT_INTEROP_SCHEMA_NAMESPACE);
00217 CIMOMHandleIFCRef hdl(env->getCIMOMHandle());
00218 try
00219 {
00220 CIMClass CIM_InstModification(hdl->getClass(interopNS, CLASS_CIM_InstModification));
00221 CIMInstance indicationInst(CIM_InstModification.newInstance());
00222 indicationInst.updatePropertyValue("PreviousInstance", CIMValue(m_inst));
00223
00224 m_inst.updatePropertyValue("Started", CIMValue(false));
00225 indicationInst.updatePropertyValue("SourceInstance", CIMValue(m_inst));
00226 indicationInst.setProperty("IndicationTime", CIMValue(CIMDateTime(DateTime::getCurrent())));
00227 hdl->exportIndication(indicationInst, interopNS);
00228
00229
00230
00231
00232 Thread::sleep(1000);
00233 }
00234 catch (Exception& e)
00235 {
00236 OW_LOG_ERROR(env->getLogger(COMPONENT_NAME), Format("OpenWBEM_ObjectManager caught exception while exporting indication in shuttingDown(): %1", e));
00237 }
00238
00239 }
00240 }
00241
00243 static CIMInstance createTheInstance(const ProviderEnvironmentIFCRef &env, const String& omName)
00244 {
00245 String interopNS = env->getConfigItem(ConfigOpts::INTEROP_SCHEMA_NAMESPACE_opt, OW_DEFAULT_INTEROP_SCHEMA_NAMESPACE);
00246 CIMOMHandleIFCRef hdl(env->getCIMOMHandle());
00247
00248 CIMClass OpenWBEM_ObjectManager(hdl->getClass(interopNS, CLASS_OpenWBEM_ObjectManager));
00249
00250 CIMInstance newInst(OpenWBEM_ObjectManager.newInstance());
00251
00252
00253 CIMObjectPathArray computerSystems(hdl->enumInstanceNamesA(interopNS, Class_OpenWBEM_ComputerSystem));
00254 if (computerSystems.size() != 1)
00255 {
00256 OW_THROWCIMMSG(CIMException::FAILED, Format("Expected 1 instance of %1, got %2",
00257 Class_OpenWBEM_ComputerSystem, computerSystems.size()).c_str());
00258 }
00259
00260 CIMObjectPath& computerSystem(computerSystems[0]);
00261
00262 newInst.updatePropertyValue("Version", CIMValue(OW_VERSION));
00263
00264
00265 newInst.updatePropertyValue(PROP_SystemCreationClassName, computerSystem.getKeyValue(PROP_CreationClassName));
00266
00267 newInst.updatePropertyValue(PROP_SystemName, computerSystem.getKeyValue(PROP_Name));
00268
00269 newInst.updatePropertyValue(PROP_CreationClassName, CIMValue(newInst.getClassName()));
00270
00271
00272 newInst.updatePropertyValue(PROP_Name, CIMValue(omName));
00273
00274 newInst.updatePropertyValue("Started", CIMValue(true));
00275 newInst.updatePropertyValue("EnabledState", CIMValue(UInt16(2)));
00276 newInst.updatePropertyValue("Caption", CIMValue("owcimomd"));
00277 newInst.updatePropertyValue("Description", CIMValue("owcimomd"));
00278
00279 return newInst;
00280 }
00281
00283 void doSimpleEnumInstances(
00284 const ProviderEnvironmentIFCRef &env,
00285 const String &ns,
00286 const CIMClass &cimClass,
00287 CIMInstanceResultHandlerIFC &result,
00288 EPropertiesFlag propertiesFlag)
00289 {
00290 if (cimClass.getName() == CLASS_OpenWBEM_ObjectManager)
00291 {
00292 result.handle(m_inst);
00293 }
00294 else if (cimClass.getName() == CLASS_OpenWBEM_HostedObjectManager)
00295 {
00296 CIMInstance ci(cimClass.newInstance());
00297 ci.updatePropertyValue(PROP_Dependent, CIMValue(CIMObjectPath(ns, m_inst)));
00298
00299 String systemCreationClassName(m_inst.getPropertyValue(PROP_SystemCreationClassName).toString());
00300 CIMObjectPath csPath(systemCreationClassName, ns);
00301 csPath.setKeyValue(PROP_CreationClassName, CIMValue(systemCreationClassName));
00302 csPath.setKeyValue(PROP_Name, m_inst.getPropertyValue(PROP_SystemName));
00303
00304 ci.updatePropertyValue(PROP_Antecedent, CIMValue(csPath));
00305 result.handle(ci);
00306 }
00307 }
00308
00309 #ifndef OW_DISABLE_ASSOCIATION_TRAVERSAL
00310
00311 void doReferences(const ProviderEnvironmentIFCRef &env,
00312 CIMInstanceResultHandlerIFC &result,
00313 const String &ns,
00314 const CIMObjectPath &objectName,
00315 const CIMClass &assocClass,
00316 const String &resultClass,
00317 const String &role,
00318 const String &resultRole)
00319 {
00320 doSimpleEnumInstances(env, ns, assocClass, result, E_ALL_PROPERTIES);
00321 }
00322 #endif // #ifndef OW_DISABLE_ASSOCIATION_TRAVERSAL
00323 };
00324
00325 }
00326
00327 OW_PROVIDERFACTORY(OpenWBEM::OpenWBEM_ObjectManagerInstProv, owprovinstOpenWBEM_ObjectManager)
00328