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_RemoteProviderInterface.hpp"
00037 #include "OW_RemoteInstanceProvider.hpp"
00038 #include "OW_RemoteSecondaryInstanceProvider.hpp"
00039 #include "OW_RemoteMethodProvider.hpp"
00040 #ifndef OW_DISABLE_ASSOCIATION_TRAVERSAL
00041 #include "OW_RemoteAssociatorProvider.hpp"
00042 #endif
00043 #include "OW_ConfigOpts.hpp"
00044 #include "OW_CIMInstance.hpp"
00045 #include "OW_CIMException.hpp"
00046 #include "OW_Format.hpp"
00047 #include "OW_CIMProperty.hpp"
00048 #include "OW_CIMValue.hpp"
00049 #include "OW_NoSuchPropertyException.hpp"
00050 #include "OW_NULLValueException.hpp"
00051 #include "OW_Logger.hpp"
00052
00053 namespace OW_NAMESPACE
00054 {
00055
00056 namespace
00057 {
00058 const String COMPONENT_NAME("ow.provider.remote.ifc");
00059 }
00060
00062 RemoteProviderInterface::RemoteProviderInterface()
00063 {
00064 }
00065
00067 RemoteProviderInterface::~RemoteProviderInterface()
00068 {
00069 }
00070
00072 const char*
00073 RemoteProviderInterface::getName() const
00074 {
00075 return "remote";
00076 }
00077
00079 void
00080 RemoteProviderInterface::doInit(const ProviderEnvironmentIFCRef& env,
00081 InstanceProviderInfoArray& ipia,
00082 SecondaryInstanceProviderInfoArray& sipia,
00083 #ifndef OW_DISABLE_ASSOCIATION_TRAVERSAL
00084 AssociatorProviderInfoArray& apia,
00085 #endif
00086 MethodProviderInfoArray& mpia,
00087 IndicationProviderInfoArray& indpia)
00088 {
00089 unsigned maxConnectionsPerUrl = 5;
00090 try
00091 {
00092 maxConnectionsPerUrl = env->getConfigItem(ConfigOpts::REMOTEPROVIFC_MAX_CONNECTIONS_PER_URL_opt, OW_DEFAULT_REMOTEPROVIFC_MAX_CONNECTIONS_PER_URL).toUInt32();
00093 }
00094 catch (StringConversionException& e)
00095 {
00096 }
00097 m_connectionPool = ClientCIMOMHandleConnectionPoolRef(new ClientCIMOMHandleConnectionPool(maxConnectionsPerUrl));
00098
00099 LoggerRef lgr = env->getLogger(COMPONENT_NAME);
00100 String interopNs = env->getConfigItem(ConfigOpts::INTEROP_SCHEMA_NAMESPACE_opt, OW_DEFAULT_INTEROP_SCHEMA_NAMESPACE);
00101 CIMInstanceArray registrations;
00102 try
00103 {
00104 registrations = env->getCIMOMHandle()->enumInstancesA(interopNs, "OpenWBEM_RemoteProviderRegistration");
00105 }
00106 catch (CIMException& e)
00107 {
00108 OW_LOG_DEBUG(lgr, Format("RemoteProviderInterface::doInit() caught exception (%1) while enumerating instances of "
00109 "OpenWBEM_RemoteProviderRegistration in namespace %2", e, interopNs));
00110 }
00111 OW_LOG_DEBUG(lgr, Format("RemoteProviderInterface::doInit() found %1 registrations", registrations.size()));
00112 for (size_t i = 0; i < registrations.size(); ++i)
00113 {
00114 CIMInstance& curReg = registrations[i];
00115 OW_LOG_DEBUG(lgr, Format("RemoteProviderInterface::doInit() processing registration %1: %2", i, curReg.toString()));
00116 try
00117 {
00118 String instanceID = curReg.getPropertyT("InstanceID").getValueT().toString();
00119 ProvRegInfo info;
00120 info.namespaceName = curReg.propertyHasValue("NamespaceName") ? curReg.getPropertyT("NamespaceName").getValueT().toString() : String();
00121 info.className = curReg.getPropertyT("ClassName").getValueT().toString();
00122 UInt16Array providerTypes = curReg.getPropertyT("ProviderTypes").getValueT().toUInt16Array();
00123 info.url = curReg.getPropertyT("Url").getValueT().toString();
00124 info.alwaysSendCredentials = curReg.getPropertyT("AlwaysSendCredentials").getValueT().toBool();
00125 info.useConnectionCredentials = curReg.getPropertyT("UseConnectionCredentials").getValueT().toBool();
00126
00127 if (providerTypes.empty())
00128 {
00129 OW_LOG_ERROR(lgr, "ProviderTypes property value has no entries");
00130 }
00131 for (size_t j = 0; j < providerTypes.size(); ++j)
00132 {
00133 switch (providerTypes[j])
00134 {
00135 case E_INSTANCE:
00136 {
00137
00138 m_instanceProvReg[instanceID] = info;
00139
00140 InstanceProviderInfo ipi;
00141 ipi.setProviderName(instanceID);
00142 StringArray namespaces;
00143 if (!info.namespaceName.empty())
00144 {
00145 namespaces.push_back(info.namespaceName);
00146 }
00147 InstanceProviderInfo::ClassInfo classInfo(info.className, namespaces);
00148 ipi.addInstrumentedClass(classInfo);
00149 ipia.push_back(ipi);
00150 }
00151 break;
00152 case E_SECONDARY_INSTANCE:
00153 {
00154
00155 m_secondaryInstanceProvReg[instanceID] = info;
00156
00157 SecondaryInstanceProviderInfo sipi;
00158 sipi.setProviderName(instanceID);
00159 StringArray namespaces;
00160 if (!info.namespaceName.empty())
00161 {
00162 namespaces.push_back(info.namespaceName);
00163 }
00164 SecondaryInstanceProviderInfo::ClassInfo classInfo(info.className, namespaces);
00165 sipi.addInstrumentedClass(classInfo);
00166 sipia.push_back(sipi);
00167 }
00168 break;
00169 case E_ASSOCIATION:
00170 {
00171 #ifndef OW_DISABLE_ASSOCIATION_TRAVERSAL
00172
00173 m_associatorProvReg[instanceID] = info;
00174
00175 AssociatorProviderInfo api;
00176 api.setProviderName(instanceID);
00177 StringArray namespaces;
00178 if (!info.namespaceName.empty())
00179 {
00180 namespaces.push_back(info.namespaceName);
00181 }
00182 AssociatorProviderInfo::ClassInfo classInfo(info.className, namespaces);
00183 api.addInstrumentedClass(classInfo);
00184 apia.push_back(api);
00185 #else
00186 OW_LOG_ERROR(lgr, "Remote associator providers not supported");
00187 #endif // #ifndef OW_DISABLE_ASSOCIATION_TRAVERSAL
00188 }
00189 break;
00190 case E_INDICATION:
00191 {
00192 OW_LOG_ERROR(lgr, "Remote indication providers not supported");
00193 }
00194 break;
00195 case E_METHOD:
00196 {
00197
00198 m_methodProvReg[instanceID] = info;
00199
00200 MethodProviderInfo mpi;
00201 mpi.setProviderName(instanceID);
00202 StringArray namespaces;
00203 if (!info.namespaceName.empty())
00204 {
00205 namespaces.push_back(info.namespaceName);
00206 }
00207 StringArray methods;
00208 MethodProviderInfo::ClassInfo classInfo(info.className, namespaces, methods);
00209 mpi.addInstrumentedClass(classInfo);
00210 mpia.push_back(mpi);
00211 }
00212 break;
00213 default:
00214 OW_LOG_ERROR(lgr, Format("Invalid value (%1) in ProviderTypes", providerTypes[j]));
00215 break;
00216 }
00217 }
00218 }
00219 catch (NoSuchPropertyException& e)
00220 {
00221 OW_LOG_ERROR(lgr, Format("Registration instance %1 has no property: %2", curReg.toString(), e));
00222 }
00223 catch (NULLValueException& e)
00224 {
00225 OW_LOG_ERROR(lgr, Format("Registration instance %1 property has null value: %2", curReg.toString(), e));
00226 }
00227 }
00228
00229 }
00230
00232 InstanceProviderIFCRef
00233 RemoteProviderInterface::doGetInstanceProvider(const ProviderEnvironmentIFCRef& env, const char* provIdString)
00234 {
00235 ProvRegMap_t::const_iterator iter = m_instanceProvReg.find(provIdString);
00236 if (iter == m_instanceProvReg.end())
00237 {
00238
00239 return InstanceProviderIFCRef(new RemoteInstanceProvider(env, provIdString, m_connectionPool, false, false));
00240 }
00241 else
00242 {
00243 return InstanceProviderIFCRef(new RemoteInstanceProvider(env, iter->second.url, m_connectionPool,
00244 iter->second.alwaysSendCredentials, iter->second.useConnectionCredentials));
00245 }
00246 }
00247
00249 SecondaryInstanceProviderIFCRef
00250 RemoteProviderInterface::doGetSecondaryInstanceProvider(const ProviderEnvironmentIFCRef& env, const char* provIdString)
00251 {
00252 ProvRegMap_t::const_iterator iter = m_secondaryInstanceProvReg.find(provIdString);
00253 if (iter == m_secondaryInstanceProvReg.end())
00254 {
00255
00256 return SecondaryInstanceProviderIFCRef(new RemoteSecondaryInstanceProvider(env, provIdString, m_connectionPool, false, false));
00257 }
00258 else
00259 {
00260 return SecondaryInstanceProviderIFCRef(new RemoteSecondaryInstanceProvider(env, iter->second.url, m_connectionPool,
00261 iter->second.alwaysSendCredentials, iter->second.useConnectionCredentials));
00262 }
00263 }
00264
00266 MethodProviderIFCRef
00267 RemoteProviderInterface::doGetMethodProvider(const ProviderEnvironmentIFCRef& env, const char* provIdString)
00268 {
00269 ProvRegMap_t::const_iterator iter = m_methodProvReg.find(provIdString);
00270 if (iter == m_methodProvReg.end())
00271 {
00272
00273 return MethodProviderIFCRef(new RemoteMethodProvider(env, provIdString, m_connectionPool, false, false));
00274 }
00275 else
00276 {
00277 return MethodProviderIFCRef(new RemoteMethodProvider(env, iter->second.url, m_connectionPool,
00278 iter->second.alwaysSendCredentials, iter->second.useConnectionCredentials));
00279 }
00280 }
00281
00282 #ifndef OW_DISABLE_ASSOCIATION_TRAVERSAL
00283
00284 AssociatorProviderIFCRef
00285 RemoteProviderInterface::doGetAssociatorProvider(const ProviderEnvironmentIFCRef& env, const char* provIdString)
00286 {
00287 ProvRegMap_t::const_iterator iter = m_associatorProvReg.find(provIdString);
00288 if (iter == m_associatorProvReg.end())
00289 {
00290
00291 return AssociatorProviderIFCRef(new RemoteAssociatorProvider(env, provIdString, m_connectionPool, false, false));
00292 }
00293 else
00294 {
00295 return AssociatorProviderIFCRef(new RemoteAssociatorProvider(env, iter->second.url, m_connectionPool,
00296 iter->second.alwaysSendCredentials, iter->second.useConnectionCredentials));
00297 }
00298 }
00299 #endif
00300
00301
00302 }
00303
00304 OW_PROVIDERIFCFACTORY(OpenWBEM::RemoteProviderInterface, owremoteprovifc)
00305