OW_RemoteSecondaryInstanceProvider.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2004 Vintela, Inc. All rights reserved.
00003 *
00004 * Redistribution and use in source and binary forms, with or without
00005 * modification, are permitted provided that the following conditions are met:
00006 *
00007 *  - Redistributions of source code must retain the above copyright notice,
00008 *    this list of conditions and the following disclaimer.
00009 *
00010 *  - Redistributions in binary form must reproduce the above copyright notice,
00011 *    this list of conditions and the following disclaimer in the documentation
00012 *    and/or other materials provided with the distribution.
00013 *
00014 *  - Neither the name of Vintela, Inc. nor the names of its
00015 *    contributors may be used to endorse or promote products derived from this
00016 *    software without specific prior written permission.
00017 *
00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc. OR THE CONTRIBUTORS
00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 * POSSIBILITY OF SUCH DAMAGE.
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       // dont: throw;
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       // dont: OW_THROWCIMMSG(CIMException::FAILED, msg.c_str());
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       // dont: throw;
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       // dont: OW_THROWCIMMSG(CIMException::FAILED, msg.c_str());
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          // now go through the properties and set any that aren't keys or the default
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             // if it's not the default value
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); // providers shouldn't ever throw NOT_SUPPORTED
00197          }
00198          OW_LOG_INFO(lgr, Format("RemoteSecondaryInstanceProvider::filterInstances remote WBEM server threw: %1", e));
00199          // we do want to throw here if something went wrong
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          // we do want to throw here if something went wrong
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       // dont: throw;
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       // dont: OW_THROWCIMMSG(CIMException::FAILED, msg.c_str());
00241    }
00242 }
00243 #endif // #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00244 
00245 
00246 } // end namespace OW_NAMESPACE
00247 
00248 

Generated on Thu Feb 9 08:48:10 2006 for openwbem by  doxygen 1.4.6