void ConfigurationPersistenceManager::onConfigurationUpdated(const KaaRootConfiguration& configuration)
{
    if (ignoreConfigurationUpdate_) {
        ignoreConfigurationUpdate_ = false;
        return;
    }

    KAA_LOG_INFO("Configuration updated.");

    AvroByteArrayConverter<KaaRootConfiguration> converter;
    SharedDataBuffer buffer = converter.toByteArray(configuration);

    KAA_LOG_INFO(boost::format("Going to store configuration using configuration storage %1%") % storage_);

    KAA_MUTEX_LOCKING("confPersistenceGuard_");
    KAA_MUTEX_UNIQUE_DECLARE(confPersistenceGuardLock, confPersistenceGuard_);
    KAA_MUTEX_LOCKED("confPersistenceGuard_");

    if (storage_) {
        storage_->saveConfiguration(std::vector<std::uint8_t>(buffer.first.get(), buffer.first.get() + buffer.second));
    }

    KAA_MUTEX_UNLOCKING("confPersistenceGuard_");
    KAA_UNLOCK(confPersistenceGuardLock);
    KAA_MUTEX_UNLOCKED("confPersistenceGuard_");

    configurationHash_ = EndpointObjectHash(buffer);

    KAA_LOG_INFO(boost::format("Calculated configuration hash: %1%") % LoggingUtils::ByteArrayToString(configurationHash_.getHashDigest()));
}
void ConfigurationManager::updateConfiguration(const std::uint8_t* data, const std::uint32_t dataSize)
{
    static AvroByteArrayConverter<KaaRootConfiguration> converter;

    converter.fromByteArray(data, dataSize, configuration_);
    configurationHash_ = EndpointObjectHash(data, dataSize);

    KAA_LOG_TRACE(boost::format("Calculated configuration hash: %1%") %
                  LoggingUtils::ByteArrayToString(configurationHash_.getHashDigest()));
}
Example #3
0
HashDigest getPropertiesHash()
{
    std::ostringstream ss;

    ss << SDK_TOKEN;
    ss << POLLING_PERIOD_SECONDS;
    ss << CLIENT_PUB_KEY_LOCATION;
    ss << CLIENT_PRIV_KEY_LOCATION;
    ss << CLIENT_STATUS_FILE_LOCATION;

    for (const auto& server : getBootstrapServers()) {
        const auto& connectionInfo = server->getConnectionInfo();
        ss.write(reinterpret_cast<const char*>(connectionInfo.data()), connectionInfo.size());
    }

    ss.write(reinterpret_cast<const char*>(
            getDefaultConfigData().data()), getDefaultConfigData().size());

    return EndpointObjectHash(ss.str()).getHashDigest();
}
void ConfigurationPersistenceManager::readStoredConfiguration()
{
    if (state_->isSDKPropertiesUpdated()) {
        KAA_LOG_INFO("Ignore loading configuration from storage: configuration version updated");
        return;
    }

    auto hash = configurationHash_.getHashDigest();
    if (hash.empty()) {
        KAA_LOG_DEBUG("Going to read stored configuration.");

        auto bytes = storage_->loadConfiguration();

        if (!bytes.empty()) {
            if (processor_) {
                ignoreConfigurationUpdate_ = true;
                processor_->processConfigurationData(bytes.data(), bytes.size(), true);
            }

            configurationHash_ = EndpointObjectHash(bytes.data(), bytes.size());
            KAA_LOG_INFO(boost::format("Calculated configuration hash: %1%") % LoggingUtils::ByteArrayToString(configurationHash_.getHashDigest()));
        }
    }
}