CAF_CM_VALIDATE_SMARTPTR(persistence);
CAF_CM_VALIDATE_STRING(persistenceDir);
- const SmartPtrCLocalSecurityDoc localSecurity = persistence->getLocalSecurity();
- const SmartPtrCRemoteSecurityCollectionDoc remoteSecurityCollection =
- persistence->getRemoteSecurityCollection();
- const SmartPtrCPersistenceProtocolCollectionDoc persistenceProtocolCollection =
- persistence->getPersistenceProtocolCollection();
+ const std::string protocolDir = FileSystemUtils::buildPath(persistenceDir, "protocol", "amqpBroker_default");
+ const std::string uriAmqp = loadTextFile(protocolDir, "uri_amqp.txt");
+ const std::string uriTunnel = loadTextFile(protocolDir, "uri_tunnel.txt");
if (FileSystemUtils::doesDirectoryExist(persistenceDir)) {
CAF_CM_LOG_DEBUG_VA1("Removing directory - %s", persistenceDir.c_str());
FileSystemUtils::recursiveRemoveDirectory(persistenceDir);
}
+ const SmartPtrCLocalSecurityDoc localSecurity = persistence->getLocalSecurity();
+ const SmartPtrCRemoteSecurityCollectionDoc remoteSecurityCollection =
+ persistence->getRemoteSecurityCollection();
+ const SmartPtrCPersistenceProtocolCollectionDoc persistenceProtocolCollection =
+ persistence->getPersistenceProtocolCollection();
+
saveLocalSecurity(localSecurity, persistenceDir);
saveRemoteSecurityCollection(remoteSecurityCollection, persistenceDir);
- savePersistenceProtocolCollection(persistenceProtocolCollection, persistenceDir);
+ savePersistenceProtocolCollection(persistenceProtocolCollection, persistenceDir,
+ uriAmqp, uriTunnel);
FileSystemUtils::saveTextFile(persistenceDir, "version.txt", persistence->getVersion());
}
void CPersistenceUtils::savePersistenceProtocolCollection(
const SmartPtrCPersistenceProtocolCollectionDoc& persistenceProtocolCollection,
- const std::string& persistenceDir) {
+ const std::string& persistenceDir,
+ const std::string& uriAmqp,
+ const std::string& uriTunnel) {
CAF_CM_STATIC_FUNC_VALIDATE("CPersistenceUtils", "savePersistenceProtocolCollection");
CAF_CM_VALIDATE_STRING(persistenceDir);
amqpQueueDir, "uri.txt", persistenceProtocol->getUri());
}
- if (! persistenceProtocol->getUriAmqp().empty()) {
+ const std::string uriAmqpTmp = persistenceProtocol->getUriAmqp().empty() ?
+ uriAmqp : persistenceProtocol->getUriAmqp();
+ if (! uriAmqpTmp.empty()) {
FileSystemUtils::saveTextFile(
- amqpQueueDir, "uri_amqp.txt", persistenceProtocol->getUriAmqp());
+ amqpQueueDir, "uri_amqp.txt", uriAmqpTmp);
}
- if (! persistenceProtocol->getUriTunnel().empty()) {
+ const std::string uriTunnelTmp = persistenceProtocol->getUriTunnel().empty() ?
+ uriTunnel : persistenceProtocol->getUriTunnel();
+ if (! uriTunnelTmp.empty()) {
FileSystemUtils::saveTextFile(
- amqpQueueDir, "uri_tunnel.txt", persistenceProtocol->getUriTunnel());
+ amqpQueueDir, "uri_tunnel.txt", uriTunnelTmp);
}
if (! persistenceProtocol->getTlsCert().empty()) {
const std::string& file,
const std::string& defaultVal,
const bool isTrimRight) {
- CAF_CM_STATIC_FUNC_VALIDATE("CPersistenceUtils", "loadTextFile");
+ CAF_CM_STATIC_FUNC_LOG_VALIDATE("CPersistenceUtils", "loadTextFile");
CAF_CM_VALIDATE_STRING(dir);
CAF_CM_VALIDATE_STRING(file);
rc = CStringUtils::trimRight(rc);
}
} else {
+ CAF_CM_LOG_DEBUG_VA1("File not found - %s", path.c_str());
rc = defaultVal;
}
static void savePersistenceProtocolCollection(
const SmartPtrCPersistenceProtocolCollectionDoc& persistenceProtocolCollection,
- const std::string& persistenceDir);
+ const std::string& persistenceDir,
+ const std::string& uriAmqp,
+ const std::string& uriTunnel);
private:
static std::string loadTextFile(
const SmartPtrCPersistenceDoc persistenceTmp =
CConfigEnvMerge::mergePersistence(_persistence, _cacertPath, _vcidPath);
if (! persistenceTmp.IsNull()) {
- _persistence = persistenceTmp;
+ CPersistenceUtils::savePersistence(persistenceTmp, _persistenceDir);
+ _persistence = CPersistenceUtils::loadPersistence(_persistenceDir);
_persistenceUpdated = _persistence;
savePersistenceAppconfig(_persistence, _configDir);
- CPersistenceUtils::savePersistence(_persistence, _persistenceDir);
const std::string reason = "Info changed in env";
listenerConfiguredStage2(reason);
CAF_CM_LOCK_UNLOCK;
CAF_CM_PRECOND_ISINITIALIZED(_isInitialized);
- const SmartPtrCPersistenceDoc persistenceTmp =
+ const SmartPtrCPersistenceDoc persistenceTmp1 =
CPersistenceMerge::mergePersistence(_persistence, persistence);
+
+ const SmartPtrCPersistenceDoc persistenceIn = persistenceTmp1.IsNull() ? _persistence : persistenceTmp1;
+ const SmartPtrCPersistenceDoc persistenceTmp2 =
+ CConfigEnvMerge::mergePersistence(persistenceIn, _cacertPath, _vcidPath);
+
+ const SmartPtrCPersistenceDoc persistenceTmp = persistenceTmp2.IsNull() ? persistenceTmp1 : persistenceTmp2;
+
if (! persistenceTmp.IsNull()) {
- _persistence = persistenceTmp;
+ CPersistenceUtils::savePersistence(persistenceTmp, _persistenceDir);
+ _persistence = CPersistenceUtils::loadPersistence(_persistenceDir);
_persistenceUpdated = _persistence;
savePersistenceAppconfig(_persistence, _configDir);
- CPersistenceUtils::savePersistence(_persistence, _persistenceDir);
removePrivateKey(_persistence, _persistenceRemove);
const std::string reason = "Info changed at source";
listenerConfiguredStage1(reason);
listenerConfiguredStage2(reason);
restartListener(reason);
- } else {
- CAF_CM_LOG_DEBUG_VA0("Persistence info did not change");
}
}
CAF_CM_VALIDATE_STRING(localId);
const std::string uri = persistenceProtocol->getUri();
-
- std::string uriNew;
- if (isTunnelEnabled) {
- uriNew = loadTextFile(persistenceProtocol->getUriTunnelPath());
- } else {
- uriNew = loadTextFile(persistenceProtocol->getUriAmqpPath());
- }
+ const std::string uriNew = isTunnelEnabled ?
+ persistenceProtocol->getUriTunnel() :
+ persistenceProtocol->getUriAmqp();
CAF_CM_VALIDATE_STRING(uriNew);
CAF_CM_LOG_DEBUG_VA3("uri: %s, uriNew: %s, localId: %s",
std::string CConfigEnvMerge::loadTextFile(
const std::string& path) {
- CAF_CM_STATIC_FUNC_VALIDATE("CConfigEnvMerge", "loadTextFile");
+ CAF_CM_STATIC_FUNC_LOG_VALIDATE("CConfigEnvMerge", "loadTextFile");
CAF_CM_VALIDATE_STRING(path);
std::string rc;
if (FileSystemUtils::doesFileExist(path)) {
rc = FileSystemUtils::loadTextFile(path);
rc = CStringUtils::trimRight(rc);
+ } else {
+ CAF_CM_LOG_DEBUG_VA1("File does not exist - %s", path.c_str());
}
return rc;
SmartPtrCPersistenceDoc rc;
if (isReady()) {
- //If nothing has been updated, skip all of the unneeded work
- const std::string updates = getValue("updates");
- if (!updates.empty()) {
+ const std::string updatesCur = getValue("updates");
+ if (_updates.compare(updatesCur) != 0) {
+ _updates = updatesCur;
const std::string version = getValue("version");
//EP Doc
//For now, we only support one broker.
const std::string protocolName = getValue(protocolKey + ".protocol_name");
+ const std::string tlsCert = getValue(protocolKey + ".tls.cert");
+ const std::string tlsProtocol = getValue(protocolKey + ".tls.protocol");
const std::string uri = getValue(protocolKey + ".uri");
const std::string uriAmqp = getValue(protocolKey + ".uri.amqp");
const std::string uriTunnel = getValue(protocolKey + ".uri.tunnel");
- const std::string tlsCert = getValue(protocolKey + ".tls.cert");
- const std::string tlsProtocol = getValue(protocolKey + ".tls.protocol");
SmartPtrCPersistenceProtocolDoc persistenceProtocol;
persistenceProtocol.CreateInstance();
}
return value;
}
-
+
void CPersistenceNamespaceDb::setValue(
const std::string& key,
const std::string& value) {
CAF_CM_FUNCNAME("setValue");
CAF_CM_VALIDATE_STRING(key);
- if (value.empty()) {
- return;
- }
+ if (_removedKeys.find(key) == _removedKeys.end()) {
+ if (value.empty()) {
+ CAF_CM_LOG_DEBUG_VA1("Cannot set empty value: %s", key.c_str());
+ return;
+ }
- std::string stdoutContent;
- std::string stderrContent;
- Cdeqstr argv;
- std::string tmpFile;
+ std::string stdoutContent;
+ std::string stderrContent;
+ Cdeqstr argv;
+ std::string tmpFile;
- try {
- //TODO: generate hash of value
- //TODO: prepend delimitted hash to value
-
- tmpFile = FileSystemUtils::saveTempTextFile("caf_nsdb_XXXXXX", value);
- CAF_CM_LOG_DEBUG_VA2("Setting %s to %s", key.c_str(), value.c_str());
- argv.push_back(_nsdbCmdPath);
- argv.push_back("set-key");
- argv.push_back(_nsdbNamespace);
- argv.push_back("-k");
- argv.push_back(key);
- argv.push_back("-f");
- argv.push_back(tmpFile);
-
- ProcessUtils::runSync(argv, stdoutContent, stderrContent);
- //Add to key+hash _cache
- //TODO: generate a hash of the value std::string
- _cache[key] = value; //As a temporary hack use the entire value as the "hash"
- }
- catch(ProcessFailedException* ex){
- CAF_CM_LOG_DEBUG_VA1("exception: %s", ex->getMsg().c_str());
- CAF_CM_EXCEPTION_VA3(E_UNEXPECTED,
- "NamespaceDB command failed - %s: %s: %s",
- ex->getMsg().c_str(),
- stdoutContent.c_str(),
- stderrContent.c_str());
- }
- if ( !tmpFile.empty() && FileSystemUtils::doesFileExist(tmpFile)) {
- FileSystemUtils::removeFile(tmpFile);
+ try {
+ tmpFile = FileSystemUtils::saveTempTextFile("caf_nsdb_XXXXXX", value);
+ CAF_CM_LOG_DEBUG_VA2("Setting %s to %s", key.c_str(), value.c_str());
+ argv.push_back(_nsdbCmdPath);
+ argv.push_back("set-key");
+ argv.push_back(_nsdbNamespace);
+ argv.push_back("-k");
+ argv.push_back(key);
+ argv.push_back("-f");
+ argv.push_back(tmpFile);
+
+ ProcessUtils::runSync(argv, stdoutContent, stderrContent);
+ }
+ catch(ProcessFailedException* ex){
+ CAF_CM_LOG_DEBUG_VA1("exception: %s", ex->getMsg().c_str());
+ CAF_CM_EXCEPTION_VA3(E_UNEXPECTED,
+ "NamespaceDB command failed - %s: %s: %s",
+ ex->getMsg().c_str(),
+ stdoutContent.c_str(),
+ stderrContent.c_str());
+ }
+ if ( !tmpFile.empty() && FileSystemUtils::doesFileExist(tmpFile)) {
+ FileSystemUtils::removeFile(tmpFile);
+ }
+ } else {
+ CAF_CM_LOG_DEBUG_VA1("Cannot set a removed key: %s", key.c_str());
}
}
CAF_CM_FUNCNAME("removeKey");
CAF_CM_VALIDATE_STRING(key);
- std::string stdoutContent;
- std::string stderrContent;
- Cdeqstr argv;
+ if (_removedKeys.find(key) == _removedKeys.end()) {
+ std::string stdoutContent;
+ std::string stderrContent;
+ Cdeqstr argv;
- try {
- argv.push_back(_nsdbCmdPath);
- argv.push_back("delete-key");
- argv.push_back(_nsdbNamespace);
- argv.push_back("-k");
- argv.push_back(key);
-
- ProcessUtils::runSync(argv, stdoutContent, stderrContent);
-
- //Remove from _cache
- Cmapstrstr::iterator it = _cache.find(key);
- if (it != _cache.end()) {
- _cache.erase(it);
+ try {
+ argv.push_back(_nsdbCmdPath);
+ argv.push_back("delete-key");
+ argv.push_back(_nsdbNamespace);
+ argv.push_back("-k");
+ argv.push_back(key);
+
+ ProcessUtils::runSync(argv, stdoutContent, stderrContent);
+ _removedKeys.insert(key);
}
- }
- catch(ProcessFailedException* ex){
- CAF_CM_LOG_DEBUG_VA1("exception: %s", ex->getMsg().c_str());
- CAF_CM_EXCEPTION_VA3(E_UNEXPECTED,
- "NamespaceDB command failed - %s: %s: %s",
- ex->getMsg().c_str(),
- stdoutContent.c_str(),
- stderrContent.c_str());
+ catch(ProcessFailedException* ex){
+ CAF_CM_LOG_DEBUG_VA1("exception: %s", ex->getMsg().c_str());
+ CAF_CM_EXCEPTION_VA3(E_UNEXPECTED,
+ "NamespaceDB command failed - %s: %s: %s",
+ ex->getMsg().c_str(),
+ stdoutContent.c_str(),
+ stderrContent.c_str());
+ }
+ } else {
+ CAF_CM_LOG_DEBUG_VA1("Key already removed: %s", key.c_str());
}
}
if (value[value.length()-1] == '"')
value.erase(value.length()-1,1);
}
- //TODO: parse hash from nsdb value
- std::string hash = value; //As a temporary hack, use the entire value as the "hash"
- //if hash has not changed, return empty
- if (_cache[key] == hash) {
- CAF_CM_LOG_DEBUG_VA1("Value for %s has not changed", key.c_str());
- value = "";
- }
- else {
- //if hash has changed, update key+hash _cache and return value
- CAF_CM_LOG_DEBUG_VA1("Value for %s has changed", key.c_str());
- _cache[key] = hash;
- }
return value;
}
std::string _nsdbCmdPath;
std::string _nsdbNamespace;
- Cmapstrstr _cache;
+ Csetstr _removedKeys;
+ std::string _updates;
SmartPtrCPersistenceDoc _persistenceUpdate;
SmartPtrCPersistenceDoc _persistenceRemove;