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 
00040 #include "OW_config.h"
00041 #include "OW_RemoteSecondaryInstanceProvider.hpp"
00042 #include "OW_RemoteProviderUtils.hpp"
00043 #include "OW_CIMInstance.hpp"
00044 #include "OW_Format.hpp"
00045 #include "OW_CIMException.hpp"
00046 #include "OW_CIMObjectPath.hpp"
00047 #include "OW_CIMClass.hpp"
00048 #include "OW_CIMProperty.hpp"
00049 #include "OW_CIMValue.hpp"
00050 #include "OW_Logger.hpp"
00051 #include "OW_ProviderEnvironmentIFC.hpp"
00052 #include "OW_ClientCIMOMHandle.hpp"
00053 
00054 namespace OW_NAMESPACE
00055 {
00056 
00057 using namespace WBEMFlags;
00058 
00059 namespace
00060 {
00061    const String COMPONENT_NAME("ow.provider.remote.ifc");
00062 }
00063 
00065 RemoteSecondaryInstanceProvider::RemoteSecondaryInstanceProvider(const ProviderEnvironmentIFCRef& env, const String& url, const ClientCIMOMHandleConnectionPoolRef& pool,
00066    bool alwaysSendCredentials, bool useConnectionCredentials)
00067    : m_pool(pool)
00068    , m_url(url)
00069    , m_alwaysSendCredentials(alwaysSendCredentials)
00070    , m_useConnectionCredentials(useConnectionCredentials)
00071 {
00072 }
00073 
00075 RemoteSecondaryInstanceProvider::~RemoteSecondaryInstanceProvider()
00076 {
00077 }
00078 
00079 #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00080 
00081 void
00082 RemoteSecondaryInstanceProvider::modifyInstance(const ProviderEnvironmentIFCRef &env, const String &ns, const CIMInstance &modifiedInstance,
00083    const CIMInstance &previousInstance, EIncludeQualifiersFlag includeQualifiers, const StringArray *propertyList, const CIMClass &theClass)
00084 {
00085    LoggerRef lgr = env->getLogger(COMPONENT_NAME);
00086    OW_LOG_DEBUG(lgr, Format("RemoteSecondaryInstanceProvider::modifyInstance ns = %1, modifiedInstance = %2", ns, modifiedInstance));
00087    String lUrl(m_url);
00088    ClientCIMOMHandleRef hdl = RemoteProviderUtils::getRemoteClientCIMOMHandle(lUrl, m_useConnectionCredentials, env, m_pool, m_alwaysSendCredentials);
00089    OW_LOG_DEBUG(lgr, Format("RemoteSecondaryInstanceProvider::modifyInstance got ClientCIMOMHandleRef for url: %1", lUrl));
00090 
00091    ClientCIMOMHandleConnectionPool::HandleReturner returner(hdl, m_pool, lUrl);
00092 
00093    OW_LOG_DEBUG(lgr, "RemoteSecondaryInstanceProvider::modifyInstance calling remote WBEM server");
00094 
00095    try
00096    {
00097       hdl->modifyInstance(ns, modifiedInstance, includeQualifiers, propertyList);
00098    }
00099    catch (CIMException& e)
00100    {
00101       OW_LOG_INFO(lgr, Format("RemoteSecondaryInstanceProvider::modifyInstance remote WBEM server threw: %1", e));
00102       
00103    }
00104    catch (const Exception& e)
00105    {
00106       String msg = Format("RemoteSecondaryInstanceProvider::modifyInstance failed calling remote WBEM server: %1", e);
00107       OW_LOG_ERROR(lgr, msg);
00108       
00109    }
00110 }
00111 
00113 void
00114 RemoteSecondaryInstanceProvider::deleteInstance(const ProviderEnvironmentIFCRef &env, const String &ns, const CIMObjectPath &cop)
00115 {
00116    LoggerRef lgr = env->getLogger(COMPONENT_NAME);
00117    OW_LOG_DEBUG(lgr, Format("RemoteSecondaryInstanceProvider::deleteInstance ns = %1, cop = %2", ns, cop));
00118    String lUrl(m_url);
00119    ClientCIMOMHandleRef hdl = RemoteProviderUtils::getRemoteClientCIMOMHandle(lUrl, m_useConnectionCredentials, env, m_pool, m_alwaysSendCredentials);
00120    OW_LOG_DEBUG(lgr, Format("RemoteSecondaryInstanceProvider::deleteInstance got ClientCIMOMHandleRef for url: %1", lUrl));
00121 
00122    ClientCIMOMHandleConnectionPool::HandleReturner returner(hdl, m_pool, lUrl);
00123 
00124    OW_LOG_DEBUG(lgr, "RemoteSecondaryInstanceProvider::deleteInstance calling remote WBEM server");
00125 
00126    try
00127    {
00128       hdl->deleteInstance(ns, cop);
00129    }
00130    catch (CIMException& e)
00131    {
00132       OW_LOG_INFO(lgr, Format("RemoteSecondaryInstanceProvider::deleteInstance remote WBEM server threw: %1", e));
00133       
00134    }
00135    catch (const Exception& e)
00136    {
00137       String msg = Format("RemoteSecondaryInstanceProvider::deleteInstance failed calling remote WBEM server: %1", e);
00138       OW_LOG_ERROR(lgr, msg);
00139       
00140    }
00141 }
00142 #endif // #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00143 
00145 void
00146 RemoteSecondaryInstanceProvider::filterInstances(const ProviderEnvironmentIFCRef &env, const String &ns, const String &className, CIMInstanceArray &instances,
00147    ELocalOnlyFlag localOnly,
00148    EDeepFlag deep,
00149    EIncludeQualifiersFlag includeQualifiers,
00150    EIncludeClassOriginFlag includeClassOrigin,
00151    const StringArray *propertyList, const CIMClass &requestedClass, const CIMClass &cimClass)
00152 {
00153    LoggerRef lgr = env->getLogger(COMPONENT_NAME);
00154    OW_LOG_DEBUG(lgr, Format("RemoteSecondaryInstanceProvider::filterInstances ns = %1, className = %2", ns, className));
00155    String lUrl(m_url);
00156    ClientCIMOMHandleRef hdl = RemoteProviderUtils::getRemoteClientCIMOMHandle(lUrl, m_useConnectionCredentials, env, m_pool, m_alwaysSendCredentials);
00157    OW_LOG_DEBUG(lgr, Format("RemoteSecondaryInstanceProvider::filterInstances got ClientCIMOMHandleRef for url: %1", lUrl));
00158 
00159    ClientCIMOMHandleConnectionPool::HandleReturner returner(hdl, m_pool, lUrl);
00160 
00161    OW_LOG_DEBUG(lgr, "RemoteSecondaryInstanceProvider::filterInstances calling remote WBEM server");
00162 
00163    for (size_t i = 0; i < instances.size(); ++i)
00164    {
00165       CIMInstance& curInst = instances[i];
00166       try
00167       {
00168          CIMObjectPath instPath(ns, curInst);
00169          CIMInstance tmp = hdl->getInstance(ns, instPath, localOnly, includeQualifiers, includeClassOrigin, propertyList);
00170          
00171          CIMPropertyArray classProps = cimClass.getAllProperties();
00172          for (size_t j = 0; j < classProps.size(); ++j)
00173          {
00174             CIMProperty& curProp = classProps[i];
00175             if (curProp.isKey())
00176             {
00177                continue;
00178             }
00179             CIMProperty p = tmp.getProperty(curProp.getName());
00180             if (!p)
00181             {
00182                continue;
00183             }
00184             CIMValue v = p.getValue();
00185             
00186             if (v != curProp.getValue())
00187             {
00188                curInst.setProperty(curProp.getName(), v);
00189             }
00190          }
00191       }
00192       catch (CIMException& e)
00193       {
00194          if (e.getErrNo() == CIMException::NOT_SUPPORTED)
00195          {
00196             e.setErrNo(CIMException::FAILED); 
00197          }
00198          OW_LOG_INFO(lgr, Format("RemoteSecondaryInstanceProvider::filterInstances remote WBEM server threw: %1", e));
00199          
00200          throw;
00201       }
00202       catch (const Exception& e)
00203       {
00204          String msg = Format("RemoteSecondaryInstanceProvider::filterInstances failed calling remote WBEM server: %1", e);
00205          OW_LOG_ERROR(lgr, msg);
00206          
00207          OW_THROWCIMMSG_SUBEX(CIMException::FAILED, msg.c_str(), e);
00208       }
00209    }
00210 }
00211 
00212 #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00213 
00214 void
00215 RemoteSecondaryInstanceProvider::createInstance(const ProviderEnvironmentIFCRef &env, const String &ns, const CIMInstance &cimInstance)
00216 {
00217    LoggerRef lgr = env->getLogger(COMPONENT_NAME);
00218    OW_LOG_DEBUG(lgr, Format("RemoteSecondaryInstanceProvider::createInstance ns = %1, cimInstance = %2", ns, cimInstance));
00219    String lUrl(m_url);
00220    ClientCIMOMHandleRef hdl = RemoteProviderUtils::getRemoteClientCIMOMHandle(lUrl, m_useConnectionCredentials, env, m_pool, m_alwaysSendCredentials);
00221    OW_LOG_DEBUG(lgr, Format("RemoteSecondaryInstanceProvider::createInstance got ClientCIMOMHandleRef for url: %1", lUrl));
00222 
00223    ClientCIMOMHandleConnectionPool::HandleReturner returner(hdl, m_pool, lUrl);
00224 
00225    OW_LOG_DEBUG(lgr, "RemoteSecondaryInstanceProvider::createInstance calling remote WBEM server");
00226 
00227    try
00228    {
00229       hdl->createInstance(ns, cimInstance);
00230    }
00231    catch (CIMException& e)
00232    {
00233       OW_LOG_INFO(lgr, Format("RemoteSecondaryInstanceProvider::createInstance remote WBEM server threw: %1", e));
00234       
00235    }
00236    catch (const Exception& e)
00237    {
00238       String msg = Format("RemoteSecondaryInstanceProvider::createInstance failed calling remote WBEM server: %1", e);
00239       OW_LOG_ERROR(lgr, msg);
00240       
00241    }
00242 }
00243 #endif // #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00244 
00245 
00246 } 
00247 
00248