]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Bulk updates to the common-agent (CAF) code.
authorOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:22:46 +0000 (11:22 -0700)
committerOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:22:46 +0000 (11:22 -0700)
16 files changed:
open-vm-tools/common-agent/Cpp/Communication/amqpListener/src/AmqpListenerWorker.cpp
open-vm-tools/common-agent/Cpp/Framework/Framework/include/Doc/PersistenceDoc/CPersistenceProtocolDoc.h
open-vm-tools/common-agent/Cpp/Framework/Framework/src/Common/CPersistenceUtils.cpp
open-vm-tools/common-agent/Cpp/Framework/Framework/src/Doc/DocXml/PersistenceXml/PersistenceProtocolXml.cpp
open-vm-tools/common-agent/Cpp/Framework/Framework/src/Integration/Caf/CCafMessageCreator.cpp
open-vm-tools/common-agent/Cpp/Framework/Framework/src/Integration/Core/CSourcePollingChannelAdapter.cpp
open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CConfigEnv.cpp
open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CConfigEnv.h
open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CConfigEnvMerge.cpp
open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CConfigEnvMerge.h
open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CMonitorReadingMessageSource.cpp
open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CMonitorReadingMessageSource.h
open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CPersistenceMerge.cpp
open-vm-tools/common-agent/etc/install/caf-dbg.sh
open-vm-tools/common-agent/etc/install/postinstallInstall.sh
open-vm-tools/common-agent/etc/install/postinstallUpgrade.sh

index 1c4a2f079f9ba86fe03736536aea2c24b7ce57e1..63f98df7285ff5d4cdc089fbb2d07da17b679dc2 100644 (file)
@@ -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<uint32>(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<uint32>(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<uint32>(5000));
+                       uint32 intStartupTimeout = AppConfigUtils::getOptionalUint32(
+                                       "communication_amqp",
+                                       "startup_timeout");
+                       intStartupTimeout = std::max(intStartupTimeout, static_cast<uint32>(5000));
 
-               uint32 connectionRetryInterval = AppConfigUtils::getOptionalUint32(
-                               "communication_amqp",
-                               "connection_retry_interval");
-               connectionRetryInterval = std::max(connectionRetryInterval, static_cast<uint32>(5000));
+                       uint32 connectionRetryInterval = AppConfigUtils::getOptionalUint32(
+                                       "communication_amqp",
+                                       "connection_retry_interval");
+                       connectionRetryInterval = std::max(connectionRetryInterval, static_cast<uint32>(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() {
index 8e01b72edcbaaffb95d5c7d5f678edba44fddbd1..659a68a5d172fcb63d8d3a8d87a7f85919e308d4 100644 (file)
@@ -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;
 
index 58f41b9ba1aeb3a96e35b3b41b87252e0bd4186a..0115b249350e3b7ef99cff9e0d777b2b78a2b766 100644 (file)
@@ -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);
 
index 4b819af6a116e6b049522e7d76af4e1cd2885dca..99df3845f79fb3c3839ae7da6891ec00c342aa0d 100644 (file)
@@ -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);
 
index 26a7387a6511156779fef9aff4c7ccbc2e474119..709979108c2b953e91c168f8d626aeaa9e3e61c8 100644 (file)
@@ -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<SmartPtrCAttachmentDoc> 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<SmartPtrCAttachmentDoc> 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;
 }
index 7b701982d1fbba78d82bc759deada6b9a4eed0b0..267cb14271fa7b1e05852793ffed68d4c51cad57 100644 (file)
@@ -68,6 +68,7 @@ void CSourcePollingChannelAdapter::run() {
        SmartPtrIIntMessage message;
        while (! getIsCancelled()) {
                try {
+                       message = NULL;
                        if (_isTimeoutSet) {
                                message = _inputPollableChannel->receive(_timeout);
                        } else {
index a61d67c1c1955e65f62eaaefab0f23aa7b094f71..3981bdb27d5984e2889cac2dd9537012e7d83a93 100644 (file)
@@ -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);
 }
index 94b850cb6248b456170ca4b0520824e7710f2916..509a679ebfa4cb661f759c668c40a523f833b23c 100644 (file)
@@ -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;
 
index 545dd5061c093cd06c12c97d6c79af150d1b42a2..958ae90347e21dce28b865bef68ee811fa4161bc 100644 (file)
@@ -105,6 +105,8 @@ std::deque<SmartPtrCPersistenceProtocolDoc> CConfigEnvMerge::mergePersistencePro
        CAF_CM_VALIDATE_BOOL(persistenceProtocolCollectionInner.size() == 1);
        CAF_CM_VALIDATE_STRING(localId);
 
+       const bool isTunnelEnabled = isTunnelEnabledFunc();
+
        std::deque<SmartPtrCPersistenceProtocolDoc> rc;
        std::deque<SmartPtrCPersistenceProtocolDoc> persistenceProtocolCollectionInnerDiff;
        std::deque<SmartPtrCPersistenceProtocolDoc> persistenceProtocolCollectionInnerAll;
@@ -112,11 +114,7 @@ std::deque<SmartPtrCPersistenceProtocolDoc> 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<SmartPtrCPersistenceProtocolDoc> 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<SmartPtrCPersistenceProtocolDoc> 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)) {
index 083baf8596b4e4cf4ca5c2ea7fbe1ee573ec0dab..f4d84355f05aa8218219524c59a9ebd32ceb39f4 100644 (file)
@@ -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,
index d5d5a8fc6c795fe71686d8eefa89bb2dfa6c29c6..3b6a2c6e67b40a09b52fd304df8133bf324778ab 100644 (file)
@@ -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);
index 4e58d3964492eb1b334aeda99df29259e6513753..481cfb9024be34fd37f2c7ee05c81148c954cbe9 100644 (file)
@@ -63,7 +63,7 @@ private:
 
        std::string _monitorDir;
        std::string _restartListenerPath;
-       std::string _listenerConfiguredPath;
+       std::string _listenerConfiguredStage2Path;
 
        std::string _scriptOutputDir;
        std::string _stopListenerScript;
index ac329af0540041c226e1526fbde0453215079709..e72a873b63b7dd97d831932ec373a8b11edbd73c 100644 (file)
@@ -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());
                        }
index c0d6b4532659341172f3cc351d6f2411fc356ee1..96e283b425d528663509bca9439bd2c60a0a287d 100644 (file)
@@ -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"
    ;;
index 02744c5c67e93fb761b2b60f903f31ab3d1bbcaa..974c5de2875ceed2a610cf97fddc97493baf1cfe 100644 (file)
@@ -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.
index f5449b277a60ccf138f161e5e3b4ee423248103f..42a3aa8a4ed34cb8b5325143028096f6633c578a 100644 (file)
@@ -5,4 +5,3 @@ scriptsDir=$installDir/../scripts
 
 $installDir/upgrade.sh
 $scriptsDir/start-ma
-$scriptsDir/start-listener