From: Oliver Kurth Date: Fri, 15 Sep 2017 18:22:46 +0000 (-0700) Subject: Bulk updates to the common-agent (CAF) code. X-Git-Tag: stable-10.2.0~686 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6d9a970fe99f6f9deeb4adcb742ee9a16a8a2072;p=thirdparty%2Fopen-vm-tools.git Bulk updates to the common-agent (CAF) code. --- diff --git a/open-vm-tools/common-agent/Cpp/Communication/amqpListener/src/AmqpListenerWorker.cpp b/open-vm-tools/common-agent/Cpp/Communication/amqpListener/src/AmqpListenerWorker.cpp index 1c4a2f079..63f98df72 100644 --- a/open-vm-tools/common-agent/Cpp/Communication/amqpListener/src/AmqpListenerWorker.cpp +++ b/open-vm-tools/common-agent/Cpp/Communication/amqpListener/src/AmqpListenerWorker.cpp @@ -26,70 +26,77 @@ AmqpListenerWorker::~AmqpListenerWorker() { void AmqpListenerWorker::doWork() { CAF_CM_FUNCNAME("run"); - uint32 intShutdownTimeout = AppConfigUtils::getOptionalUint32( - "communication_amqp", - "shutdown_timeout"); - intShutdownTimeout = std::max(intShutdownTimeout, static_cast(5000)); + const std::string monitorDir = AppConfigUtils::getRequiredString("monitor_dir"); + const std::string listenerConfiguredStage2Path = FileSystemUtils::buildPath( + monitorDir, "listenerConfiguredStage2.txt"); + if (FileSystemUtils::doesFileExist(listenerConfiguredStage2Path)) { + uint32 intShutdownTimeout = AppConfigUtils::getOptionalUint32( + "communication_amqp", + "shutdown_timeout"); + intShutdownTimeout = std::max(intShutdownTimeout, static_cast(5000)); - SmartPtrCIntegrationAppContext intAppContext; - try { - CLoggingUtils::setStartupConfigFile( - AppConfigUtils::getRequiredString(_sAppConfigGlobalParamLogConfigFile), - AppConfigUtils::getRequiredString(_sAppConfigGlobalParamLogDir)); + SmartPtrCIntegrationAppContext intAppContext; + try { + CLoggingUtils::setStartupConfigFile( + AppConfigUtils::getRequiredString(_sAppConfigGlobalParamLogConfigFile), + AppConfigUtils::getRequiredString(_sAppConfigGlobalParamLogDir)); - uint32 intStartupTimeout = AppConfigUtils::getOptionalUint32( - "communication_amqp", - "startup_timeout"); - intStartupTimeout = std::max(intStartupTimeout, static_cast(5000)); + uint32 intStartupTimeout = AppConfigUtils::getOptionalUint32( + "communication_amqp", + "startup_timeout"); + intStartupTimeout = std::max(intStartupTimeout, static_cast(5000)); - uint32 connectionRetryInterval = AppConfigUtils::getOptionalUint32( - "communication_amqp", - "connection_retry_interval"); - connectionRetryInterval = std::max(connectionRetryInterval, static_cast(5000)); + uint32 connectionRetryInterval = AppConfigUtils::getOptionalUint32( + "communication_amqp", + "connection_retry_interval"); + connectionRetryInterval = std::max(connectionRetryInterval, static_cast(5000)); - bool isSignaled = false; - do { - try { - CAF_CM_LOG_DEBUG_VA0("***** Initializing context"); - intAppContext.CreateInstance(); - intAppContext->initialize( - intStartupTimeout, - AppConfigUtils::getRequiredString("communication_amqp", "context_file")); - CAF_CM_LOG_DEBUG_VA0("***** Started. Waiting for stop signal."); + bool isSignaled = false; + do { + try { + CAF_CM_LOG_DEBUG_VA0("***** Initializing context"); + intAppContext.CreateInstance(); + intAppContext->initialize( + intStartupTimeout, + AppConfigUtils::getRequiredString("communication_amqp", "context_file")); + CAF_CM_LOG_DEBUG_VA0("***** Started. Waiting for stop signal."); + { + CAF_THREADSIGNAL_LOCK_UNLOCK; + _stopSignal.wait(CAF_THREADSIGNAL_MUTEX, 0); + } + CAF_CM_LOG_DEBUG_VA0("***** Received stop signal."); + break; + } catch (AmqpClient::AmqpExceptions::AmqpTimeoutException *ex) { + _logger.log( + log4cpp::Priority::WARN, + _cm_funcName_, + __LINE__, + ex); + ex->Release(); + CThreadUtils::sleep(connectionRetryInterval); + } + CAF_CM_CATCH_ALL; + CAF_CM_THROWEXCEPTION; { CAF_THREADSIGNAL_LOCK_UNLOCK; - _stopSignal.wait(CAF_THREADSIGNAL_MUTEX, 0); + isSignaled = _stopSignal.waitOrTimeout(CAF_THREADSIGNAL_MUTEX, 100); } - CAF_CM_LOG_DEBUG_VA0("***** Received stop signal."); - break; - } catch (AmqpClient::AmqpExceptions::AmqpTimeoutException *ex) { - _logger.log( - log4cpp::Priority::WARN, - _cm_funcName_, - __LINE__, - ex); - ex->Release(); - CThreadUtils::sleep(connectionRetryInterval); - } - CAF_CM_CATCH_ALL; - CAF_CM_THROWEXCEPTION; - { - CAF_THREADSIGNAL_LOCK_UNLOCK; - isSignaled = _stopSignal.waitOrTimeout(CAF_THREADSIGNAL_MUTEX, 100); - } - } while (!isSignaled); - } - CAF_CM_CATCH_ALL; - CAF_CM_LOG_CRIT_CAFEXCEPTION; + } while (!isSignaled); + } + CAF_CM_CATCH_ALL; + CAF_CM_LOG_CRIT_CAFEXCEPTION; - try { - if (intAppContext) { - intAppContext->terminate(intShutdownTimeout); + try { + if (intAppContext) { + intAppContext->terminate(intShutdownTimeout); + } } + CAF_CM_CATCH_ALL; + CAF_CM_LOG_CRIT_CAFEXCEPTION; + CAF_CM_THROWEXCEPTION; + } else { + CAF_CM_LOG_WARN_VA0("Listener not configured"); } - CAF_CM_CATCH_ALL; - CAF_CM_LOG_CRIT_CAFEXCEPTION; - CAF_CM_THROWEXCEPTION; } void AmqpListenerWorker::stopWork() { diff --git a/open-vm-tools/common-agent/Cpp/Framework/Framework/include/Doc/PersistenceDoc/CPersistenceProtocolDoc.h b/open-vm-tools/common-agent/Cpp/Framework/Framework/include/Doc/PersistenceDoc/CPersistenceProtocolDoc.h index 8e01b72ed..659a68a5d 100644 --- a/open-vm-tools/common-agent/Cpp/Framework/Framework/include/Doc/PersistenceDoc/CPersistenceProtocolDoc.h +++ b/open-vm-tools/common-agent/Cpp/Framework/Framework/include/Doc/PersistenceDoc/CPersistenceProtocolDoc.h @@ -32,6 +32,8 @@ public: const std::string& tlsProtocol = std::string(), const Cdeqstr& tlsCipherCollection = Cdeqstr(), const SmartPtrCCertCollectionDoc& tlsCertCollection = SmartPtrCCertCollectionDoc(), + const std::string& uriAmqpPath = std::string(), + const std::string& uriTunnelPath = std::string(), const std::string& tlsCertPath = std::string(), const SmartPtrCCertPathCollectionDoc& tlsCertPathCollection = SmartPtrCCertPathCollectionDoc()) { if (! _isInitialized) { @@ -44,6 +46,8 @@ public: _tlsCipherCollection = tlsCipherCollection; _tlsCertCollection = tlsCertCollection; + _uriAmqpPath = uriAmqpPath; + _uriTunnelPath = uriTunnelPath; _tlsCertPath = tlsCertPath; _tlsCertPathCollection = tlsCertPathCollection; @@ -92,6 +96,16 @@ public: return _tlsCertCollection; } + /// Accessor for the UriAmqpPath + std::string getUriAmqpPath() const { + return _uriAmqpPath; + } + + /// Accessor for the UriTunnelPath + std::string getUriTunnelPath() const { + return _uriTunnelPath; + } + /// Accessor for the TlsCertPath std::string getTlsCertPath() const { return _tlsCertPath; @@ -112,6 +126,8 @@ private: Cdeqstr _tlsCipherCollection; SmartPtrCCertCollectionDoc _tlsCertCollection; + std::string _uriAmqpPath; + std::string _uriTunnelPath; std::string _tlsCertPath; SmartPtrCCertPathCollectionDoc _tlsCertPathCollection; diff --git a/open-vm-tools/common-agent/Cpp/Framework/Framework/src/Common/CPersistenceUtils.cpp b/open-vm-tools/common-agent/Cpp/Framework/Framework/src/Common/CPersistenceUtils.cpp index 58f41b9ba..0115b2493 100644 --- a/open-vm-tools/common-agent/Cpp/Framework/Framework/src/Common/CPersistenceUtils.cpp +++ b/open-vm-tools/common-agent/Cpp/Framework/Framework/src/Common/CPersistenceUtils.cpp @@ -164,6 +164,8 @@ SmartPtrCPersistenceProtocolCollectionDoc CPersistenceUtils::loadPersistenceProt loadTextFile(protocolIdDir, "tlsProtocol.txt"), tlsCipherCollection, tlsCertCollection, + FileSystemUtils::buildPath(protocolIdDir, "uri_amqp.txt"), + FileSystemUtils::buildPath(protocolIdDir, "uri_tunnel.txt"), FileSystemUtils::buildPath(protocolIdDir, "tlsCert.pem"), tlsCertPathCollection); diff --git a/open-vm-tools/common-agent/Cpp/Framework/Framework/src/Doc/DocXml/PersistenceXml/PersistenceProtocolXml.cpp b/open-vm-tools/common-agent/Cpp/Framework/Framework/src/Doc/DocXml/PersistenceXml/PersistenceProtocolXml.cpp index 4b819af6a..99df3845f 100644 --- a/open-vm-tools/common-agent/Cpp/Framework/Framework/src/Doc/DocXml/PersistenceXml/PersistenceProtocolXml.cpp +++ b/open-vm-tools/common-agent/Cpp/Framework/Framework/src/Doc/DocXml/PersistenceXml/PersistenceProtocolXml.cpp @@ -70,6 +70,16 @@ void PersistenceProtocolXml::add( CertCollectionXml::add(tlsCertCollectionVal, tlsCertCollectionXml); } + const std::string uriAmqpPathVal = persistenceProtocolDoc->getUriAmqpPath(); + if (! uriAmqpPathVal.empty()) { + thisXml->addAttribute("uriAmqpPath", uriAmqpPathVal); + } + + const std::string uriTunnelPathVal = persistenceProtocolDoc->getUriTunnelPath(); + if (! uriTunnelPathVal.empty()) { + thisXml->addAttribute("uriTunnelPath", uriTunnelPathVal); + } + const std::string tlsCertPathVal = persistenceProtocolDoc->getTlsCertPath(); if (! tlsCertPathVal.empty()) { thisXml->addAttribute("tlsCertPath", tlsCertPathVal); @@ -133,6 +143,12 @@ SmartPtrCPersistenceProtocolDoc PersistenceProtocolXml::parse( tlsCertCollectionVal = CertCollectionXml::parse(tlsCertCollectionXml); } + const std::string uriAmqpPathVal = + thisXml->findOptionalAttribute("uriAmqpPath"); + + const std::string uriTunnelPathVal = + thisXml->findOptionalAttribute("uriTunnelPath"); + const std::string tlsCertPathVal = thisXml->findOptionalAttribute("tlsCertPath"); @@ -154,6 +170,8 @@ SmartPtrCPersistenceProtocolDoc PersistenceProtocolXml::parse( tlsProtocolVal, tlsCipherCollectionVal, tlsCertCollectionVal, + uriAmqpPathVal, + uriTunnelPathVal, tlsCertPathVal, tlsCertPathCollectionVal); diff --git a/open-vm-tools/common-agent/Cpp/Framework/Framework/src/Integration/Caf/CCafMessageCreator.cpp b/open-vm-tools/common-agent/Cpp/Framework/Framework/src/Integration/Caf/CCafMessageCreator.cpp index 26a7387a6..709979108 100644 --- a/open-vm-tools/common-agent/Cpp/Framework/Framework/src/Integration/Caf/CCafMessageCreator.cpp +++ b/open-vm-tools/common-agent/Cpp/Framework/Framework/src/Integration/Caf/CCafMessageCreator.cpp @@ -360,72 +360,76 @@ SmartPtrIIntMessage CCafMessageCreator::createPayloadEnvelope( const SmartPtrCAttachmentCollectionDoc& attachmentCollection, const SmartPtrCProtocolCollectionDoc& protocolCollection) { CAF_CM_STATIC_FUNC_LOG_VALIDATE("CCafMessageCreator", "createPayloadEnvelope"); + CAF_CM_VALIDATE_STRING(payloadType); CAF_CM_VALIDATE_STRING(payloadStr); // clientId is optional - CAF_CM_VALIDATE_GUID(requestId); + // requestId is optional // pmeId is optional - CAF_CM_VALIDATE_STRING(payloadType); CAF_CM_VALIDATE_STRING(payloadVersion); - const std::string outputDir = - AppConfigUtils::getRequiredString(_sAppConfigGlobalParamOutputDir); - - const std::string destAttachmentFilename = - BasePlatform::UuidToString(requestId) + "-EnvelopePayload.xml"; - const std::string destAttachmentPath = FileSystemUtils::buildPath( - outputDir, "att", destAttachmentFilename); - const std::string destAttachmentUri = - "file:///" + destAttachmentPath + "?relPath=" + destAttachmentFilename; - - const SmartPtrCDynamicByteArray payload = - CCafMessagePayload::createBufferFromStr(payloadStr); - FileSystemUtils::saveByteFile(destAttachmentPath, payload); - - const std::string cmsPolicyStr = AppConfigUtils::getRequiredString( - "security", "cms_policy"); - const CMS_POLICY cmsPolicy = - EnumConvertersXml::convertStringToCmsPolicy(cmsPolicyStr); - - SmartPtrCAttachmentDoc envelopePayloadAttachment; - envelopePayloadAttachment.CreateInstance(); - envelopePayloadAttachment->initialize("_EnvelopePayload_", "EnvelopePayload", - destAttachmentUri, false, cmsPolicy); - - std::deque attachmentCollectionNew; - if (! attachmentCollection.IsNull()) { - attachmentCollectionNew = attachmentCollection->getAttachment(); - } - attachmentCollectionNew.push_back(envelopePayloadAttachment); - - SmartPtrCAttachmentCollectionDoc attachmentCollectionDocNew; - attachmentCollectionDocNew.CreateInstance(); - attachmentCollectionDocNew->initialize(attachmentCollectionNew); - - SmartPtrCPayloadEnvelopeDoc payloadEnvelope; - payloadEnvelope.CreateInstance(); - payloadEnvelope->initialize( - clientId, - requestId, - pmeId, - payloadType, - payloadVersion, - attachmentCollectionDocNew, - protocolCollection); - - const std::string payloadEnvelopeStr = - XmlRoots::savePayloadEnvelopeToString(payloadEnvelope); - - const CIntMessage::SmartPtrCHeaders mergedHeaders = - CIntMessage::mergeHeaders(newHeaders, origHeaders); - - SmartPtrCCafMessageHeadersWriter messageHeadersWriter = - CCafMessageHeadersWriter::create(); - messageHeadersWriter->setPayloadType(payloadType); - SmartPtrCIntMessage messageImpl; - messageImpl.CreateInstance(); - messageImpl->initializeStr( - payloadEnvelopeStr, messageHeadersWriter->getHeaders(), mergedHeaders); + if (::IsEqualGUID(requestId, CAFCOMMON_GUID_NULL)) { + CAF_CM_LOG_WARN_VA1("Message is not associated with a request - %s", payloadStr.c_str()); + } else { + const std::string outputDir = + AppConfigUtils::getRequiredString(_sAppConfigGlobalParamOutputDir); + + const std::string destAttachmentFilename = + BasePlatform::UuidToString(requestId) + "-EnvelopePayload.xml"; + const std::string destAttachmentPath = FileSystemUtils::buildPath( + outputDir, "att", destAttachmentFilename); + const std::string destAttachmentUri = + "file:///" + destAttachmentPath + "?relPath=" + destAttachmentFilename; + + const SmartPtrCDynamicByteArray payload = + CCafMessagePayload::createBufferFromStr(payloadStr); + FileSystemUtils::saveByteFile(destAttachmentPath, payload); + + const std::string cmsPolicyStr = AppConfigUtils::getRequiredString( + "security", "cms_policy"); + const CMS_POLICY cmsPolicy = + EnumConvertersXml::convertStringToCmsPolicy(cmsPolicyStr); + + SmartPtrCAttachmentDoc envelopePayloadAttachment; + envelopePayloadAttachment.CreateInstance(); + envelopePayloadAttachment->initialize("_EnvelopePayload_", "EnvelopePayload", + destAttachmentUri, false, cmsPolicy); + + std::deque attachmentCollectionNew; + if (! attachmentCollection.IsNull()) { + attachmentCollectionNew = attachmentCollection->getAttachment(); + } + attachmentCollectionNew.push_back(envelopePayloadAttachment); + + SmartPtrCAttachmentCollectionDoc attachmentCollectionDocNew; + attachmentCollectionDocNew.CreateInstance(); + attachmentCollectionDocNew->initialize(attachmentCollectionNew); + + SmartPtrCPayloadEnvelopeDoc payloadEnvelope; + payloadEnvelope.CreateInstance(); + payloadEnvelope->initialize( + clientId, + requestId, + pmeId, + payloadType, + payloadVersion, + attachmentCollectionDocNew, + protocolCollection); + + const std::string payloadEnvelopeStr = + XmlRoots::savePayloadEnvelopeToString(payloadEnvelope); + + const CIntMessage::SmartPtrCHeaders mergedHeaders = + CIntMessage::mergeHeaders(newHeaders, origHeaders); + + SmartPtrCCafMessageHeadersWriter messageHeadersWriter = + CCafMessageHeadersWriter::create(); + messageHeadersWriter->setPayloadType(payloadType); + + messageImpl.CreateInstance(); + messageImpl->initializeStr( + payloadEnvelopeStr, messageHeadersWriter->getHeaders(), mergedHeaders); + } return messageImpl; } diff --git a/open-vm-tools/common-agent/Cpp/Framework/Framework/src/Integration/Core/CSourcePollingChannelAdapter.cpp b/open-vm-tools/common-agent/Cpp/Framework/Framework/src/Integration/Core/CSourcePollingChannelAdapter.cpp index 7b701982d..267cb1427 100644 --- a/open-vm-tools/common-agent/Cpp/Framework/Framework/src/Integration/Core/CSourcePollingChannelAdapter.cpp +++ b/open-vm-tools/common-agent/Cpp/Framework/Framework/src/Integration/Core/CSourcePollingChannelAdapter.cpp @@ -68,6 +68,7 @@ void CSourcePollingChannelAdapter::run() { SmartPtrIIntMessage message; while (! getIsCancelled()) { try { + message = NULL; if (_isTimeoutSet) { message = _inputPollableChannel->receive(_timeout); } else { diff --git a/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CConfigEnv.cpp b/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CConfigEnv.cpp index a61d67c1c..3981bdb27 100644 --- a/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CConfigEnv.cpp +++ b/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CConfigEnv.cpp @@ -46,7 +46,10 @@ void CConfigEnv::initialize( _monitorDir = AppConfigUtils::getRequiredString("monitor_dir"); _restartListenerPath = FileSystemUtils::buildPath(_monitorDir, "restartListener.txt"); - _listenerConfiguredPath = FileSystemUtils::buildPath(_monitorDir, "listenerConfigured.txt"); + _listenerConfiguredStage1Path = FileSystemUtils::buildPath( + _monitorDir, "listenerConfiguredStage1.txt"); + _listenerConfiguredStage2Path = FileSystemUtils::buildPath( + _monitorDir, "listenerConfiguredStage2.txt"); std::string guestProxyDir; #ifdef _WIN32 @@ -60,10 +63,6 @@ void CConfigEnv::initialize( _vcidPath = FileSystemUtils::buildPath(guestProxyDir, "VmVcUuid", "vm.vc.uuid"); _cacertPath = FileSystemUtils::buildPath(guestProxyDir, "server", "cert.pem"); - _persistence = CPersistenceUtils::loadPersistence(_persistenceDir); - _persistenceUpdated = _persistence; - savePersistenceAppconfig(_persistence, _configDir); - _isInitialized = true; } } @@ -74,15 +73,24 @@ SmartPtrCPersistenceDoc CConfigEnv::getUpdated( CAF_CM_LOCK_UNLOCK; CAF_CM_PRECOND_ISINITIALIZED(_isInitialized); - const SmartPtrCPersistenceDoc persistenceTmp = - CConfigEnvMerge::mergePersistence(_persistence, _cacertPath, _vcidPath); - if (! persistenceTmp.IsNull()) { - _persistence = persistenceTmp; - _persistenceUpdated = _persistence; + if (FileSystemUtils::doesFileExist(_listenerConfiguredStage1Path)) { + if (_persistence.IsNull()) { + _persistence = CPersistenceUtils::loadPersistence(_persistenceDir); + } - savePersistenceAppconfig(_persistence, _configDir); - CPersistenceUtils::savePersistence(_persistence, _persistenceDir); - restartListener("Info changed on disk"); + const SmartPtrCPersistenceDoc persistenceTmp = + CConfigEnvMerge::mergePersistence(_persistence, _cacertPath, _vcidPath); + if (! persistenceTmp.IsNull()) { + _persistence = persistenceTmp; + _persistenceUpdated = _persistence; + + savePersistenceAppconfig(_persistence, _configDir); + CPersistenceUtils::savePersistence(_persistence, _persistenceDir); + + const std::string reason = "Info changed in env"; + listenerConfiguredStage2(reason); + restartListener(reason); + } } SmartPtrCPersistenceDoc rc; @@ -109,11 +117,12 @@ void CConfigEnv::update( savePersistenceAppconfig(_persistence, _configDir); CPersistenceUtils::savePersistence(_persistence, _persistenceDir); + removePrivateKey(_persistence, _persistenceRemove); const std::string reason = "Info changed at source"; - listenerConfigured(reason); + listenerConfiguredStage1(reason); + listenerConfiguredStage2(reason); restartListener(reason); - removePrivateKey(_persistence, _persistenceRemove); } else { CAF_CM_LOG_DEBUG_VA0("Persistence info did not change"); } @@ -206,7 +215,12 @@ void CConfigEnv::restartListener( FileSystemUtils::saveTextFile(_restartListenerPath, reason); } -void CConfigEnv::listenerConfigured( +void CConfigEnv::listenerConfiguredStage1( + const std::string& reason) const { + FileSystemUtils::saveTextFile(_listenerConfiguredStage1Path, reason); +} + +void CConfigEnv::listenerConfiguredStage2( const std::string& reason) const { - FileSystemUtils::saveTextFile(_listenerConfiguredPath, reason); + FileSystemUtils::saveTextFile(_listenerConfiguredStage2Path, reason); } diff --git a/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CConfigEnv.h b/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CConfigEnv.h index 94b850cb6..509a679eb 100644 --- a/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CConfigEnv.h +++ b/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CConfigEnv.h @@ -64,7 +64,10 @@ private: void restartListener( const std::string& reason) const; - void listenerConfigured( + void listenerConfiguredStage1( + const std::string& reason) const; + + void listenerConfiguredStage2( const std::string& reason) const; private: @@ -74,7 +77,8 @@ private: std::string _persistenceAppconfigPath; std::string _monitorDir; std::string _restartListenerPath; - std::string _listenerConfiguredPath; + std::string _listenerConfiguredStage1Path; + std::string _listenerConfiguredStage2Path; std::string _vcidPath; std::string _cacertPath; 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 545dd5061..958ae9034 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 @@ -105,6 +105,8 @@ std::deque CConfigEnvMerge::mergePersistencePro CAF_CM_VALIDATE_BOOL(persistenceProtocolCollectionInner.size() == 1); CAF_CM_VALIDATE_STRING(localId); + const bool isTunnelEnabled = isTunnelEnabledFunc(); + std::deque rc; std::deque persistenceProtocolCollectionInnerDiff; std::deque persistenceProtocolCollectionInnerAll; @@ -112,11 +114,7 @@ std::deque CConfigEnvMerge::mergePersistencePro persistenceProtocolIter; persistenceProtocolIter++) { const SmartPtrCPersistenceProtocolDoc persistenceProtocol = *persistenceProtocolIter; - const std::string uriDiff = mergeUri( - persistenceProtocol->getUri(), - persistenceProtocol->getUriAmqp(), - persistenceProtocol->getUriTunnel(), - localId); + const std::string uriDiff = mergeUri(persistenceProtocol, localId, isTunnelEnabled); const SmartPtrCCertCollectionDoc tlsCertCollectionDiff = mergeTlsCertCollection(persistenceProtocol->getTlsCertCollection(), cacert); @@ -124,13 +122,15 @@ std::deque CConfigEnvMerge::mergePersistencePro persistenceProtocolDiff.CreateInstance(); persistenceProtocolDiff->initialize( persistenceProtocol->getProtocolName(), - uriDiff.empty() ? persistenceProtocol->getUri() : uriDiff, - persistenceProtocol->getUriAmqp(), - persistenceProtocol->getUriTunnel(), + ! uriDiff.empty() ? uriDiff : persistenceProtocol->getUri(), + ! uriDiff.empty() && ! isTunnelEnabled ? uriDiff : persistenceProtocol->getUriAmqp(), + ! uriDiff.empty() && isTunnelEnabled ? uriDiff : persistenceProtocol->getUriTunnel(), persistenceProtocol->getTlsCert(), persistenceProtocol->getTlsProtocol(), persistenceProtocol->getTlsCipherCollection(), tlsCertCollectionDiff.IsNull() ? persistenceProtocol->getTlsCertCollection() : tlsCertCollectionDiff, + persistenceProtocol->getUriAmqpPath(), + persistenceProtocol->getUriTunnelPath(), persistenceProtocol->getTlsCertPath(), persistenceProtocol->getTlsCertPathCollection()); persistenceProtocolCollectionInnerAll.push_back(persistenceProtocolDiff); @@ -148,43 +148,37 @@ std::deque CConfigEnvMerge::mergePersistencePro } std::string CConfigEnvMerge::mergeUri( - const std::string& uri, - const std::string& uriAmqp, - const std::string& uriTunnel, - const std::string& localId) { + const SmartPtrCPersistenceProtocolDoc& persistenceProtocol, + const std::string& localId, + const bool isTunnelEnabled) { CAF_CM_STATIC_FUNC_LOG_VALIDATE("CConfigEnvMerge", "mergeUri"); - CAF_CM_VALIDATE_STRING(uriAmqp); - CAF_CM_VALIDATE_STRING(uriTunnel); + CAF_CM_VALIDATE_SMARTPTR(persistenceProtocol); CAF_CM_VALIDATE_STRING(localId); - UriUtils::SUriRecord uriData; - if (! uri.empty()) { - UriUtils::parseUriString(uri, uriData); - } - - const bool isTunnelEnabled = isTunnelEnabledFunc(); - const std::string uriProtocol = isTunnelEnabled ? "tunnel" : "amqp"; - - bool isUriChanged = false; - if (uriData.protocol.compare(uriProtocol) != 0) { - const std::string uriTmp = isTunnelEnabled ? uriTunnel : uriAmqp; - UriUtils::parseUriString(uriTmp, uriData); - isUriChanged = true; - } + const std::string uri = persistenceProtocol->getUri(); - std::string amqpQueueId = localId; + std::string uriNew; if (isTunnelEnabled) { - amqpQueueId += "-agentId1"; + uriNew = loadTextFile(persistenceProtocol->getUriTunnelPath()); + } else { + uriNew = loadTextFile(persistenceProtocol->getUriAmqpPath()); } + CAF_CM_VALIDATE_STRING(uriNew); - if (uriData.path.compare(amqpQueueId) != 0) { - uriData.path = amqpQueueId; - isUriChanged = true; - } + CAF_CM_LOG_DEBUG_VA3("uri: %s, uriNew: %s, localId: %s", + uri.c_str(), uriNew.c_str(), localId.c_str()); + + UriUtils::SUriRecord uriDataNew; + UriUtils::parseUriString(uriNew, uriDataNew); std::string rc; - if (isUriChanged) { - rc = UriUtils::buildUriString(uriData); + if ((uri.compare(uriNew) != 0) || (uriDataNew.path.compare(localId) != 0)) { + uriDataNew.path = localId; + if (isTunnelEnabled) { + uriDataNew.path += "-agentId1"; + } + + rc = UriUtils::buildUriString(uriDataNew); CAF_CM_LOG_DEBUG_VA2("uri changed - %s != %s", uri.c_str(), rc.c_str()); } @@ -286,6 +280,8 @@ bool CConfigEnvMerge::isTunnelEnabledFunc() { std::string CConfigEnvMerge::loadTextFile( const std::string& path) { + CAF_CM_STATIC_FUNC_VALIDATE("CConfigEnvMerge", "loadTextFile"); + CAF_CM_VALIDATE_STRING(path); std::string rc; if (FileSystemUtils::doesFileExist(path)) { diff --git a/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CConfigEnvMerge.h b/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CConfigEnvMerge.h index 083baf859..f4d84355f 100644 --- a/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CConfigEnvMerge.h +++ b/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CConfigEnvMerge.h @@ -30,10 +30,9 @@ private: const std::string& vcidPath); static std::string mergeUri( - const std::string& uri, - const std::string& uriAmqp, - const std::string& uriTunnel, - const std::string& localId); + const SmartPtrCPersistenceProtocolDoc& persistenceProtocol, + const std::string& localId, + const bool isTunnelEnabled); static SmartPtrCCertCollectionDoc mergeTlsCertCollection( const SmartPtrCCertCollectionDoc& tlsCertCollection, diff --git a/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CMonitorReadingMessageSource.cpp b/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CMonitorReadingMessageSource.cpp index d5d5a8fc6..3b6a2c6e6 100644 --- a/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CMonitorReadingMessageSource.cpp +++ b/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CMonitorReadingMessageSource.cpp @@ -36,7 +36,7 @@ void CMonitorReadingMessageSource::initialize( _monitorDir = AppConfigUtils::getRequiredString("monitor_dir"); _restartListenerPath = FileSystemUtils::buildPath(_monitorDir, "restartListener.txt"); - _listenerConfiguredPath = FileSystemUtils::buildPath(_monitorDir, "listenerConfigured.txt"); + _listenerConfiguredStage2Path = FileSystemUtils::buildPath(_monitorDir, "listenerConfiguredStage2.txt"); _scriptOutputDir = AppConfigUtils::getRequiredString(_sConfigTmpDir); _listenerStartupType = AppConfigUtils::getRequiredString("monitor", "listener_startup_type"); @@ -85,7 +85,7 @@ SmartPtrIIntMessage CMonitorReadingMessageSource::doReceive( } std::string reason; - if (FileSystemUtils::doesFileExist(_listenerConfiguredPath)) { + if (FileSystemUtils::doesFileExist(_listenerConfiguredStage2Path)) { if (FileSystemUtils::doesFileExist(_restartListenerPath)) { reason = FileSystemUtils::loadTextFile(_restartListenerPath); FileSystemUtils::removeFile(_restartListenerPath); diff --git a/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CMonitorReadingMessageSource.h b/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CMonitorReadingMessageSource.h index 4e58d3964..481cfb902 100644 --- a/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CMonitorReadingMessageSource.h +++ b/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CMonitorReadingMessageSource.h @@ -63,7 +63,7 @@ private: std::string _monitorDir; std::string _restartListenerPath; - std::string _listenerConfiguredPath; + std::string _listenerConfiguredStage2Path; std::string _scriptOutputDir; std::string _stopListenerScript; diff --git a/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CPersistenceMerge.cpp b/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CPersistenceMerge.cpp index ac329af05..e72a873b6 100644 --- a/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CPersistenceMerge.cpp +++ b/open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CPersistenceMerge.cpp @@ -197,6 +197,8 @@ SmartPtrCPersistenceProtocolDoc CPersistenceMerge::mergePersistenceProtocol( tlsProtocol.empty() ? persistenceProtocolIn->getTlsProtocol() : tlsProtocol, tlsCipherCollection.empty() ? persistenceProtocolIn->getTlsCipherCollection() : tlsCipherCollection, tlsCertCollection.IsNull() ? persistenceProtocolIn->getTlsCertCollection() : tlsCertCollection, + persistenceProtocolLoaded->getUriAmqpPath(), + persistenceProtocolLoaded->getUriTunnelPath(), persistenceProtocolLoaded->getTlsCertPath(), persistenceProtocolLoaded->getTlsCertPathCollection()); } diff --git a/open-vm-tools/common-agent/etc/install/caf-dbg.sh b/open-vm-tools/common-agent/etc/install/caf-dbg.sh index c0d6b4532..96e283b42 100644 --- a/open-vm-tools/common-agent/etc/install/caf-dbg.sh +++ b/open-vm-tools/common-agent/etc/install/caf-dbg.sh @@ -20,33 +20,39 @@ function validateNotEmpty() { fi } +function configAmqp() { + local username="$1" + local password="$2" + local brokerAddr="$3" + validateNotEmpty "$username" "username" + validateNotEmpty "$password" "password" + validateNotEmpty "$brokerAddr" "brokerAddr" + + local uriAmqpFile="$CAF_INPUT_DIR/persistence/protocol/amqpBroker_default/uri_amqp.txt" + sed -i -e "s/#amqpUsername#/${username}/g" -e "s/#amqpPassword#/${password}/g" -e "s/#brokerAddr#/$brokerAddr/g" "$uriAmqpFile" +} + function enableCaf() { local username="$1" local password="$2" validateNotEmpty "$username" "username" validateNotEmpty "$password" "password" - local uriFile="$CAF_INPUT_DIR/persistence/protocol/amqpBroker_default/uri.txt" local uriAmqpFile="$CAF_INPUT_DIR/persistence/protocol/amqpBroker_default/uri_amqp.txt" - sed -i "s/#amqpUsername#/${username}/g" "$uriFile" - sed -i "s/#amqpPassword#/${password}/g" "$uriFile" - sed -i "s/#amqpUsername#/${username}/g" "$uriAmqpFile" - sed -i "s/#amqpPassword#/${password}/g" "$uriAmqpFile" + sed -i -e "s/#amqpUsername#/${username}/g" -e "s/#amqpPassword#/${password}/g" "$uriAmqpFile" } function setBroker() { local brokerAddr="$1" validateNotEmpty "$brokerAddr" "brokerAddr" - local uriFile="$CAF_INPUT_DIR/persistence/protocol/amqpBroker_default/uri.txt" local uriAmqpFile="$CAF_INPUT_DIR/persistence/protocol/amqpBroker_default/uri_amqp.txt" - sed -i "s/#brokerAddr#/$brokerAddr/g" "$uriFile" sed -i "s/#brokerAddr#/$brokerAddr/g" "$uriAmqpFile" } function setListenerConfigured() { mkdir -p "$CAF_INPUT_DIR/monitor" - echo "Manual" > "$CAF_INPUT_DIR/monitor/listenerConfigured.txt" + echo "Manual" > "$CAF_INPUT_DIR/monitor/listenerConfiguredStage1.txt" } function setListenerStartupType() { @@ -59,23 +65,24 @@ function setListenerStartupType() { function prtHelp() { echo "*** $(basename $0) cmd - Runs commands that help with debugging CAF" - echo " * enableCaf brokerUsername brokerPassword Enables CAF" - echo " * setBroker brokerAddress Sets the Broker into the CAF config file" - echo " * setListenerConfigured Indicates that the Listener is configured" - echo " * setListenerStartupType startupType Sets the startup type used by the Listener (Manual, Automatic)" + echo " * configAmqp brokerUsername brokerPassword brokerAddress Configures AMQP" + echo " * enableCaf brokerUsername brokerPassword Enables CAF" + echo " * setBroker brokerAddress Sets the Broker into the CAF config file" + echo " * setListenerConfigured Indicates that the Listener is configured" + echo " * setListenerStartupType startupType Sets the startup type used by the Listener (Manual, Automatic)" echo "" - echo " * getAmqpQueueName Gets the AMQP Queue Name" + echo " * getAmqpQueueName Gets the AMQP Queue Name" echo "" - echo " * checkTunnel Checks the AMQP Tunnel " - echo " * checkCerts Checks the certificates" - echo " * prtCerts Prints the certificates" - echo " * checkVmwTools Checks VMware Tools" + echo " * checkTunnel Checks the AMQP Tunnel " + echo " * checkCerts Checks the certificates" + echo " * prtCerts Prints the certificates" + echo " * checkVmwTools Checks VMware Tools" echo "" - echo " * validateXml Validates the XML files against the published schema" - echo " * validateInstall Validates that the files are in the right locations and have the right permissions" - echo " * validateOVTInstall Validates that the files are in the right locations for OVT and have the right permissions" + echo " * validateXml Validates the XML files against the published schema" + echo " * validateInstall Validates that the files are in the right locations and have the right permissions" + echo " * validateOVTInstall Validates that the files are in the right locations for OVT and have the right permissions" echo "" - echo " * clearCaches Clears the CAF caches" + echo " * clearCaches Clears the CAF caches" } function validateXml() { @@ -503,6 +510,9 @@ case "$cmd" in "clearCaches") clearCaches ;; + "configAmqp") + configAmqp "$1" "$2" "$3" + ;; "enableCaf") enableCaf "$1" "$2" ;; diff --git a/open-vm-tools/common-agent/etc/install/postinstallInstall.sh b/open-vm-tools/common-agent/etc/install/postinstallInstall.sh index 02744c5c6..974c5de28 100644 --- a/open-vm-tools/common-agent/etc/install/postinstallInstall.sh +++ b/open-vm-tools/common-agent/etc/install/postinstallInstall.sh @@ -5,5 +5,3 @@ scriptsDir=$installDir/../scripts $installDir/install.sh -l /usr/lib -i /var/lib -o /var/lib $scriptsDir/start-ma - -# Start Communication once we've removed the amqp_username/password requirement. diff --git a/open-vm-tools/common-agent/etc/install/postinstallUpgrade.sh b/open-vm-tools/common-agent/etc/install/postinstallUpgrade.sh index f5449b277..42a3aa8a4 100644 --- a/open-vm-tools/common-agent/etc/install/postinstallUpgrade.sh +++ b/open-vm-tools/common-agent/etc/install/postinstallUpgrade.sh @@ -5,4 +5,3 @@ scriptsDir=$installDir/../scripts $installDir/upgrade.sh $scriptsDir/start-ma -$scriptsDir/start-listener