OW_RemoteInstanceProvider.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 
00035 #include "OW_config.h"
00036 #include "OW_RemoteInstanceProvider.hpp"
00037 #include "OW_RemoteProviderUtils.hpp"
00038 #include "OW_CIMInstance.hpp"
00039 #include "OW_CIMObjectPath.hpp"
00040 #include "OW_Format.hpp"
00041 #include "OW_CIMException.hpp"
00042 #include "OW_Logger.hpp"
00043 #include "OW_ProviderEnvironmentIFC.hpp"
00044 #include "OW_ClientCIMOMHandle.hpp"
00045 
00046 namespace OW_NAMESPACE
00047 {
00048 
00049 namespace
00050 {
00051    const String COMPONENT_NAME("ow.provider.remote.ifc");
00052 }
00053 
00055 RemoteInstanceProvider::RemoteInstanceProvider(const ProviderEnvironmentIFCRef& env, const String& url, const ClientCIMOMHandleConnectionPoolRef& pool,
00056    bool alwaysSendCredentials, bool useConnectionCredentials)
00057    : m_pool(pool)
00058    , m_url(url)
00059    , m_alwaysSendCredentials(alwaysSendCredentials)
00060    , m_useConnectionCredentials(useConnectionCredentials)
00061 {
00062 }
00063 
00065 RemoteInstanceProvider::~RemoteInstanceProvider()
00066 {
00067 }
00068    
00070 void
00071 RemoteInstanceProvider::enumInstanceNames(
00072       const ProviderEnvironmentIFCRef& env,
00073       const String& ns,
00074       const String& className,
00075       CIMObjectPathResultHandlerIFC& result,
00076       const CIMClass& cimClass )
00077 {
00078    LoggerRef lgr = env->getLogger(COMPONENT_NAME);
00079    OW_LOG_DEBUG(lgr, Format("RemoteInstanceProvider::enumInstanceNames ns = %1, className = %2", ns, className));
00080    String lUrl(m_url);
00081    ClientCIMOMHandleRef hdl = RemoteProviderUtils::getRemoteClientCIMOMHandle(lUrl, m_useConnectionCredentials, env, m_pool, m_alwaysSendCredentials);
00082    OW_LOG_DEBUG(lgr, Format("RemoteInstanceProvider::enumInstanceNames got ClientCIMOMHandleRef for url: %1", lUrl));
00083 
00084    ClientCIMOMHandleConnectionPool::HandleReturner returner(hdl, m_pool, lUrl);
00085 
00086    OW_LOG_DEBUG(lgr, "RemoteInstanceProvider::enumInstanceNames calling remote WBEM server");
00087 
00088    try
00089    {
00090       hdl->enumInstanceNames(ns, className, result);
00091    }
00092    catch (CIMException& e)
00093    {
00094       if (e.getErrNo() == CIMException::NOT_SUPPORTED)
00095       {
00096          e.setErrNo(CIMException::FAILED); // providers shouldn't ever throw NOT_SUPPORTED
00097       }
00098       OW_LOG_INFO(lgr, Format("RemoteInstanceProvider::enumInstanceNames remote WBEM server threw: %1", e));
00099       throw;
00100    }
00101    catch (const Exception& e)
00102    {
00103       String msg = Format("RemoteInstanceProvider::enumInstanceNames failed calling remote WBEM server: %1", e);
00104       OW_LOG_ERROR(lgr, msg);
00105       OW_THROWCIMMSG_SUBEX(CIMException::FAILED, msg.c_str(), e);
00106    }
00107 }
00108 
00110 void
00111 RemoteInstanceProvider::enumInstances(
00112       const ProviderEnvironmentIFCRef& env,
00113       const String& ns,
00114       const String& className,
00115       CIMInstanceResultHandlerIFC& result,
00116       WBEMFlags::ELocalOnlyFlag localOnly,
00117       WBEMFlags::EDeepFlag deep,
00118       WBEMFlags::EIncludeQualifiersFlag includeQualifiers,
00119       WBEMFlags::EIncludeClassOriginFlag includeClassOrigin,
00120       const StringArray* propertyList,
00121       const CIMClass& requestedClass,
00122       const CIMClass& cimClass )
00123 {
00124    LoggerRef lgr = env->getLogger(COMPONENT_NAME);
00125    OW_LOG_DEBUG(lgr, Format("RemoteInstanceProvider::enumInstances ns = %1, className = %2", ns, className));
00126    String lUrl(m_url);
00127    ClientCIMOMHandleRef hdl = RemoteProviderUtils::getRemoteClientCIMOMHandle(lUrl, m_useConnectionCredentials, env, m_pool, m_alwaysSendCredentials);
00128    OW_LOG_DEBUG(lgr, Format("RemoteInstanceProvider::enumInstances got ClientCIMOMHandleRef for url: %1", lUrl));
00129 
00130    ClientCIMOMHandleConnectionPool::HandleReturner returner(hdl, m_pool, lUrl);
00131 
00132    OW_LOG_DEBUG(lgr, "RemoteInstanceProvider::enumInstances calling remote WBEM server");
00133 
00134    try
00135    {
00136       hdl->enumInstances(ns, className, result, deep, localOnly, includeQualifiers, includeClassOrigin, propertyList);
00137    }
00138    catch (CIMException& e)
00139    {
00140       if (e.getErrNo() == CIMException::NOT_SUPPORTED)
00141       {
00142          e.setErrNo(CIMException::FAILED); // providers shouldn't ever throw NOT_SUPPORTED
00143       }
00144       OW_LOG_INFO(lgr, Format("RemoteInstanceProvider::enumInstances remote WBEM server threw: %1", e));
00145       throw;
00146    }
00147    catch (const Exception& e)
00148    {
00149       String msg = Format("RemoteInstanceProvider::enumInstances failed calling remote WBEM server: %1", e);
00150       OW_LOG_ERROR(lgr, msg);
00151       OW_THROWCIMMSG_SUBEX(CIMException::FAILED, msg.c_str(), e);
00152    }
00153 }
00154 
00156 CIMInstance
00157 RemoteInstanceProvider::getInstance(
00158       const ProviderEnvironmentIFCRef& env,
00159       const String& ns,
00160       const CIMObjectPath& instanceName,
00161       WBEMFlags::ELocalOnlyFlag localOnly,
00162       WBEMFlags::EIncludeQualifiersFlag includeQualifiers,
00163       WBEMFlags::EIncludeClassOriginFlag includeClassOrigin,
00164       const StringArray* propertyList,
00165       const CIMClass& cimClass )
00166 {
00167    LoggerRef lgr = env->getLogger(COMPONENT_NAME);
00168    OW_LOG_DEBUG(lgr, Format("RemoteInstanceProvider::getInstance ns = %1, instanceName = %2", ns, instanceName));
00169    String lUrl(m_url);
00170    ClientCIMOMHandleRef hdl = RemoteProviderUtils::getRemoteClientCIMOMHandle(lUrl, m_useConnectionCredentials, env, m_pool, m_alwaysSendCredentials);
00171    OW_LOG_DEBUG(lgr, Format("RemoteInstanceProvider::getInstance got ClientCIMOMHandleRef for url: %1", lUrl));
00172 
00173    ClientCIMOMHandleConnectionPool::HandleReturner returner(hdl, m_pool, lUrl);
00174 
00175    OW_LOG_DEBUG(lgr, "RemoteInstanceProvider::getInstance calling remote WBEM server");
00176 
00177    CIMInstance rval(CIMNULL);
00178    try
00179    {
00180       rval = hdl->getInstance(ns, instanceName, localOnly, includeQualifiers, includeClassOrigin, propertyList);
00181    }
00182    catch (CIMException& e)
00183    {
00184       if (e.getErrNo() == CIMException::NOT_SUPPORTED)
00185       {
00186          e.setErrNo(CIMException::FAILED); // providers shouldn't ever throw NOT_SUPPORTED
00187       }
00188       OW_LOG_INFO(lgr, Format("RemoteInstanceProvider::getInstance remote WBEM server threw: %1", e));
00189       throw;
00190    }
00191    catch (const Exception& e)
00192    {
00193       String msg = Format("RemoteInstanceProvider::getInstance failed calling remote WBEM server: %1", e);
00194       OW_LOG_ERROR(lgr, msg);
00195       OW_THROWCIMMSG_SUBEX(CIMException::FAILED, msg.c_str(), e);
00196    }
00197    return rval;
00198 }
00199 
00200 #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00201 
00202 CIMObjectPath
00203 RemoteInstanceProvider::createInstance(
00204       const ProviderEnvironmentIFCRef& env,
00205       const String& ns,
00206       const CIMInstance& cimInstance )
00207 {
00208    LoggerRef lgr = env->getLogger(COMPONENT_NAME);
00209    OW_LOG_DEBUG(lgr, Format("RemoteInstanceProvider::createInstance ns = %1", ns));
00210    String lUrl(m_url);
00211    ClientCIMOMHandleRef hdl = RemoteProviderUtils::getRemoteClientCIMOMHandle(lUrl, m_useConnectionCredentials, env, m_pool, m_alwaysSendCredentials);
00212    OW_LOG_DEBUG(lgr, Format("RemoteInstanceProvider::createInstance got ClientCIMOMHandleRef for url: %1", lUrl));
00213 
00214    ClientCIMOMHandleConnectionPool::HandleReturner returner(hdl, m_pool, lUrl);
00215 
00216    OW_LOG_DEBUG(lgr, "RemoteInstanceProvider::createInstance calling remote WBEM server");
00217 
00218    CIMObjectPath rval(CIMNULL);
00219    try
00220    {
00221       rval = hdl->createInstance(ns, cimInstance);
00222    }
00223    catch (CIMException& e)
00224    {
00225       if (e.getErrNo() == CIMException::NOT_SUPPORTED)
00226       {
00227          e.setErrNo(CIMException::FAILED); // providers shouldn't ever throw NOT_SUPPORTED
00228       }
00229       OW_LOG_INFO(lgr, Format("RemoteInstanceProvider::createInstance remote WBEM server threw: %1", e));
00230       throw;
00231    }
00232    catch (const Exception& e)
00233    {
00234       String msg = Format("RemoteInstanceProvider::createInstance failed calling remote WBEM server: %1", e);
00235       OW_LOG_ERROR(lgr, msg);
00236       OW_THROWCIMMSG_SUBEX(CIMException::FAILED, msg.c_str(), e);
00237    }
00238    return rval;
00239 }
00240 
00242 void
00243 RemoteInstanceProvider::modifyInstance(
00244       const ProviderEnvironmentIFCRef& env,
00245       const String& ns,
00246       const CIMInstance& modifiedInstance,
00247       const CIMInstance& previousInstance,
00248       WBEMFlags::EIncludeQualifiersFlag includeQualifiers,
00249       const StringArray* propertyList,
00250       const CIMClass& theClass)
00251 {
00252    LoggerRef lgr = env->getLogger(COMPONENT_NAME);
00253    OW_LOG_DEBUG(lgr, Format("RemoteInstanceProvider::modifyInstance ns = %1", ns));
00254    String lUrl(m_url);
00255    ClientCIMOMHandleRef hdl = RemoteProviderUtils::getRemoteClientCIMOMHandle(lUrl, m_useConnectionCredentials, env, m_pool, m_alwaysSendCredentials);
00256    OW_LOG_DEBUG(lgr, Format("RemoteInstanceProvider::modifyInstance got ClientCIMOMHandleRef for url: %1", lUrl));
00257 
00258    ClientCIMOMHandleConnectionPool::HandleReturner returner(hdl, m_pool, lUrl);
00259 
00260    OW_LOG_DEBUG(lgr, "RemoteInstanceProvider::modifyInstance calling remote WBEM server");
00261 
00262    try
00263    {
00264       hdl->modifyInstance(ns, modifiedInstance, includeQualifiers, propertyList);
00265    }
00266    catch (CIMException& e)
00267    {
00268       if (e.getErrNo() == CIMException::NOT_SUPPORTED)
00269       {
00270          e.setErrNo(CIMException::FAILED); // providers shouldn't ever throw NOT_SUPPORTED
00271       }
00272       OW_LOG_INFO(lgr, Format("RemoteInstanceProvider::modifyInstance remote WBEM server threw: %1", e));
00273       throw;
00274    }
00275    catch (const Exception& e)
00276    {
00277       String msg = Format("RemoteInstanceProvider::modifyInstance failed calling remote WBEM server: %1", e);
00278       OW_LOG_ERROR(lgr, msg);
00279       OW_THROWCIMMSG_SUBEX(CIMException::FAILED, msg.c_str(), e);
00280    }
00281 }
00282 
00284 void
00285 RemoteInstanceProvider::deleteInstance(
00286       const ProviderEnvironmentIFCRef& env,
00287       const String& ns,
00288       const CIMObjectPath& cop)
00289 {
00290    LoggerRef lgr = env->getLogger(COMPONENT_NAME);
00291    OW_LOG_DEBUG(lgr, Format("RemoteInstanceProvider::deleteInstance ns = %1, cop = %2", ns, cop));
00292    String lUrl(m_url);
00293    ClientCIMOMHandleRef hdl = RemoteProviderUtils::getRemoteClientCIMOMHandle(lUrl, m_useConnectionCredentials, env, m_pool, m_alwaysSendCredentials);
00294    OW_LOG_DEBUG(lgr, Format("RemoteInstanceProvider::deleteInstance got ClientCIMOMHandleRef for url: %1", lUrl));
00295 
00296    ClientCIMOMHandleConnectionPool::HandleReturner returner(hdl, m_pool, lUrl);
00297 
00298    OW_LOG_DEBUG(lgr, "RemoteInstanceProvider::deleteInstance calling remote WBEM server");
00299 
00300    try
00301    {
00302       hdl->deleteInstance(ns, cop);
00303    }
00304    catch (CIMException& e)
00305    {
00306       if (e.getErrNo() == CIMException::NOT_SUPPORTED)
00307       {
00308          e.setErrNo(CIMException::FAILED); // providers shouldn't ever throw NOT_SUPPORTED
00309       }
00310       OW_LOG_INFO(lgr, Format("RemoteInstanceProvider::deleteInstance remote WBEM server threw: %1", e));
00311       throw;
00312    }
00313    catch (const Exception& e)
00314    {
00315       String msg = Format("RemoteInstanceProvider::deleteInstance failed calling remote WBEM server: %1", e);
00316       OW_LOG_ERROR(lgr, msg);
00317       OW_THROWCIMMSG_SUBEX(CIMException::FAILED, msg.c_str(), e);
00318    }
00319 }
00320 
00321 #endif // #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00322 
00323 
00324 
00325 } // end namespace OW_NAMESPACE
00326 
00327 
00328 

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