From: Oliver Kurth Date: Fri, 15 Sep 2017 18:22:53 +0000 (-0700) Subject: Bulk updates to the common-agent (CAF) source. X-Git-Tag: stable-10.2.0~637 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8a9529e714141ab425b09ea9e0a4bf702f9cae1b;p=thirdparty%2Fopen-vm-tools.git Bulk updates to the common-agent (CAF) source. --- diff --git a/open-vm-tools/common-agent/Cpp/Communication/Subsystems/commIntegration/src/CReplyToResolverInstance.cpp b/open-vm-tools/common-agent/Cpp/Communication/Subsystems/commIntegration/src/CReplyToResolverInstance.cpp index ea1adaaf1..5a5ad6c9f 100644 --- a/open-vm-tools/common-agent/Cpp/Communication/Subsystems/commIntegration/src/CReplyToResolverInstance.cpp +++ b/open-vm-tools/common-agent/Cpp/Communication/Subsystems/commIntegration/src/CReplyToResolverInstance.cpp @@ -34,10 +34,15 @@ void CReplyToResolverInstance::initializeBean( CAF_CM_FUNCNAME_VALIDATE("initializeBean"); CAF_CM_LOCK_UNLOCK; CAF_CM_PRECOND_ISNOTINITIALIZED(_isInitialized); + + // Read cache map into memory + loadCache(); + _isInitialized = true; } void CReplyToResolverInstance::terminateBean() { + persistCache(); } std::string CReplyToResolverInstance::cacheReplyTo( @@ -106,7 +111,7 @@ SmartPtrIVariant CReplyToResolverInstance::invokeExpression( const std::string& methodName, const Cdeqstr& methodParams, const SmartPtrIIntMessage& message) { - CAF_CM_FUNCNAME("lookupReplyTo"); + CAF_CM_FUNCNAME("invokeExpression"); CAF_CM_LOCK_UNLOCK; CAF_CM_PRECOND_ISINITIALIZED(_isInitialized); CAF_CM_ASSERT(!methodParams.size()); @@ -123,3 +128,70 @@ SmartPtrIVariant CReplyToResolverInstance::invokeExpression( } return result; } + +inline std::string CReplyToResolverInstance::getResolverCacheFilePath() +{ + return AppConfigUtils::getRequiredString("communication_amqp", "resolver_cache_file"); +} + +/* + * private methods + * + */ +void CReplyToResolverInstance::loadCache() { + CAF_CM_FUNCNAME_VALIDATE("loadCache"); + CAF_CM_LOCK_UNLOCK; + + //const std::string cacheFilePath = AppConfigUtils::getRequiredString("communication_amqp", "resolver_cache_file"); + const std::string cacheFilePath = getResolverCacheFilePath(); + const std::string cacheDirPath = FileSystemUtils::getDirname(cacheFilePath); + if (! FileSystemUtils::doesDirectoryExist(cacheDirPath)) { + FileSystemUtils::createDirectory(cacheDirPath); + } + if (FileSystemUtils::doesFileExist(cacheFilePath)) { + + const std::deque fileContents = FileSystemUtils::loadTextFileIntoColl(cacheFilePath); + for(TConstIterator > fileLineIter(fileContents); fileLineIter; fileLineIter++) { + //const std::string fileLine = *fileLineIter; + const Cdeqstr fileLineTokens = CStringUtils::split(*fileLineIter, ' '); + + CAF_CM_LOG_DEBUG_VA2("cache entry - reqId: %s, addr: %s", + fileLineTokens[0].c_str(), fileLineTokens[1].c_str()); + if (fileLineTokens.size() == 2) { + UUID reqId; + BasePlatform::UuidFromString(fileLineTokens[0].c_str(), reqId); + _replyToAddresses.insert(std::make_pair(reqId, fileLineTokens[1])); + } + } + + } else { + CAF_CM_LOG_DEBUG_VA1("resolver cache is not available - resolverCache: %s", cacheFilePath.c_str()); + } + +} + +void CReplyToResolverInstance::persistCache() { + CAF_CM_FUNCNAME_VALIDATE("persistCache"); + CAF_CM_LOCK_UNLOCK; + CAF_CM_PRECOND_ISINITIALIZED(_isInitialized); + + //const std::string cacheFilePath = AppConfigUtils::getRequiredString("communication_amqp", "resolver_cache_file"); + const std::string cacheFilePath = getResolverCacheFilePath(); + std::stringstream contents; + //contents.str(""); + for (AddressMap::const_iterator replyToIter = _replyToAddresses.begin(); + replyToIter != _replyToAddresses.end(); ++replyToIter) { + + std::string reqIdStr = BasePlatform::UuidToString(replyToIter->first); + contents << reqIdStr << " " << replyToIter->second << std::endl; + CAF_CM_LOG_DEBUG_VA2("caching entry - reqId: %s, addr: %s", + reqIdStr.c_str(), replyToIter->second.c_str()); + } + if (contents.str().length() > 0) { + CAF_CM_LOG_DEBUG_VA0("Caching resolver map."); + FileSystemUtils::saveTextFile(cacheFilePath, contents.str()); + } + + +} + diff --git a/open-vm-tools/common-agent/Cpp/Communication/Subsystems/commIntegration/src/CReplyToResolverInstance.h b/open-vm-tools/common-agent/Cpp/Communication/Subsystems/commIntegration/src/CReplyToResolverInstance.h index 6251efcb9..e82158b27 100644 --- a/open-vm-tools/common-agent/Cpp/Communication/Subsystems/commIntegration/src/CReplyToResolverInstance.h +++ b/open-vm-tools/common-agent/Cpp/Communication/Subsystems/commIntegration/src/CReplyToResolverInstance.h @@ -46,6 +46,12 @@ public: // ReplyToResolver std::string lookupReplyTo(const SmartPtrIIntMessage& message); + static std::string getResolverCacheFilePath(); + +private: // ReplyToResolver + void loadCache(); + void persistCache(); + public: // IExpressionInvoker SmartPtrIVariant invokeExpression( const std::string& methodName, diff --git a/open-vm-tools/common-agent/Cpp/Communication/amqpCore/src/amqpClient/CAmqpConnection.cpp b/open-vm-tools/common-agent/Cpp/Communication/amqpCore/src/amqpClient/CAmqpConnection.cpp index eabd8defd..99272c293 100644 --- a/open-vm-tools/common-agent/Cpp/Communication/amqpCore/src/amqpClient/CAmqpConnection.cpp +++ b/open-vm-tools/common-agent/Cpp/Communication/amqpCore/src/amqpClient/CAmqpConnection.cpp @@ -287,6 +287,17 @@ AMQPStatus CAmqpConnection::receive( } break; + case AMQP_STATUS_SOCKET_ERROR: { // Enhance the logic to restart listener after certain number of errors. + if (! _isConnectionLost) { + CAF_CM_LOG_ERROR_VA1("SOCKET_ERROR... restarting listener - %s", + amqp_error_string2(status)); + _isConnectionLost = true; + restartListener(amqp_error_string2(status)); + } + rc = AMQP_ERROR_IO_INTERRUPTED; + } + break; + default: { CAF_CM_LOG_ERROR_VA1("Received error status - %s", amqp_error_string2(status)); diff --git a/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CConfigEnvMerge.cpp b/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CConfigEnvMerge.cpp index 1cf49c51d..86fc0f2b9 100644 --- a/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CConfigEnvMerge.cpp +++ b/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CConfigEnvMerge.cpp @@ -142,6 +142,8 @@ std::deque CConfigEnvMerge::mergePersistencePro persistenceProtocol->getTlsCertPathCollection()); persistenceProtocolCollectionInnerAll.push_back(persistenceProtocolDiff); + CAF_CM_LOG_DEBUG_VA2("uriDiff=%s, isTunnelEnabled=%s", uriDiff.c_str(), isTunnelEnabled?"true":"false" ); + if (! uriDiff.empty() || ! tlsCertCollectionDiff.IsNull()) { persistenceProtocolCollectionInnerDiff.push_back(persistenceProtocolDiff); } @@ -175,15 +177,17 @@ std::string CConfigEnvMerge::mergeUri( UriUtils::parseUriString(uriNew, uriDataNew); std::string rc; - if ((uri.compare(uriNew) != 0) || (uriDataNew.path.compare(localId) != 0)) { - uriDataNew.path = localId; - if (isTunnelEnabled) { - uriDataNew.path += "-agentId1"; - } - + std::string pathNew(localId); + if (isTunnelEnabled) { + pathNew += "-agentId1"; + } + if ((uri.compare(uriNew) != 0) || (uriDataNew.path.compare(pathNew) != 0)) { + uriDataNew.path = pathNew; rc = UriUtils::buildUriString(uriDataNew); - CAF_CM_LOG_DEBUG_VA2("uri changed - %s != %s", uri.c_str(), rc.c_str()); + CAF_CM_LOG_DEBUG_VA4("uri changed - %s != %s || %s != %s", + uri.c_str(), rc.c_str(), pathNew.c_str(), uriDataNew.path.c_str()); } + CAF_CM_LOG_DEBUG_VA1("rc: %s", rc.c_str()); return rc; } diff --git a/open-vm-tools/common-agent/etc/config/CommAmqpListener-appconfig b/open-vm-tools/common-agent/etc/config/CommAmqpListener-appconfig index 2102ac59e..34445d321 100644 --- a/open-vm-tools/common-agent/etc/config/CommAmqpListener-appconfig +++ b/open-vm-tools/common-agent/etc/config/CommAmqpListener-appconfig @@ -17,6 +17,7 @@ remap_logging_location=false [communication_amqp] working_dir=${output_dir}/comm-wrk context_file=${comm_amqp_listener_context} +resolver_cache_file=${output_dir}/cache/commAmqpResolver-cache reactive_request_queue_id=${reactive_request_amqp_queue_id} diff --git a/open-vm-tools/common-agent/etc/config/ma-context.xml b/open-vm-tools/common-agent/etc/config/ma-context.xml index 374d524e3..b32dfdbe0 100644 --- a/open-vm-tools/common-agent/etc/config/ma-context.xml +++ b/open-vm-tools/common-agent/etc/config/ma-context.xml @@ -309,7 +309,7 @@ id="persistenceInboundChannelAdapterId" channel="configenvOutboundChannel" ref="persistenceNsdbBean"> - +