Skip to content

Commit

Permalink
composeappmanager: Add update reason for each app in getAppsToUpdate
Browse files Browse the repository at this point in the history
Signed-off-by: Andre Detsch <[email protected]>
  • Loading branch information
detsch committed Aug 29, 2024
1 parent 7feae70 commit 4ce9c58
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 19 deletions.
6 changes: 4 additions & 2 deletions src/aklite_client_ext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@ GetTargetToInstallResult AkliteClientExt::GetTargetToInstall(const CheckInResult
<< res.selected_target.Name();

res.status = GetTargetToInstallResult::Status::UpdateSyncApps;
res.reason =
"Syncing Active Target Apps\nApps requiring update:\n" + boost::algorithm::join(apps_to_update, "\n");
res.reason = "Syncing Active Target Apps\n";
for (const auto& app_to_update : apps_to_update) {
res.reason += "- " + app_to_update.first + ": " + app_to_update.second + "\n";
}
} else {
// No targets to install
res.selected_target = TufTarget();
Expand Down
37 changes: 24 additions & 13 deletions src/composeappmanager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <boost/format.hpp>
#include <boost/process.hpp>
#include <boost/range/iterator_range_core.hpp>
#include <unordered_map>

#include "bootloader/bootloaderlite.h"
#include "docker/restorableappengine.h"
Expand Down Expand Up @@ -193,7 +194,8 @@ ComposeAppManager::AppsContainer ComposeAppManager::getApps(const Uptane::Target
return apps;
}

ComposeAppManager::AppsContainer ComposeAppManager::getAppsToUpdate(const Uptane::Target& t) const {
ComposeAppManager::AppsContainer ComposeAppManager::getAppsToUpdate(
const Uptane::Target& t, std::unordered_map<std::string, std::string>& apps_and_reasons) const {
AppsContainer apps_to_update;

auto currently_installed_target_apps = Target::appsJson(OstreeManager::getCurrent());
Expand All @@ -206,13 +208,15 @@ ComposeAppManager::AppsContainer ComposeAppManager::getAppsToUpdate(const Uptane
if (app_data.empty()) {
// new app in Target
apps_to_update.insert(app_pair);
apps_and_reasons[app_pair.first] = "new app in target";
LOG_INFO << app_name << " will be installed";
continue;
}

if (app_pair.second != app_data["uri"].asString()) {
// an existing App update
apps_to_update.insert(app_pair);
apps_and_reasons[app_pair.first] = "new version in target";
LOG_INFO << app_name << " will be updated";
continue;
}
Expand All @@ -221,38 +225,45 @@ ComposeAppManager::AppsContainer ComposeAppManager::getAppsToUpdate(const Uptane
!boost::filesystem::exists(cfg_.apps_root / app_name / Docker::ComposeAppEngine::ComposeFile)) {
// an App that is supposed to be installed has been removed somehow, let's install it again
apps_to_update.insert(app_pair);
apps_and_reasons[app_pair.first] = "missing installation";
LOG_INFO << app_name << " will be re-installed";
continue;
}

LOG_DEBUG << app_name << " performing full status check";
if (!app_engine_->isFetched({app_name, app_pair.second}) || !app_engine_->isRunning({app_name, app_pair.second})) {
// an App that is supposed to be installed and running is not fully installed or running
if (!app_engine_->isFetched({app_name, app_pair.second})) {
// an App that is supposed to be installed is not fully installed
apps_to_update.insert(app_pair);
LOG_INFO << app_name << " update will be re-installed or completed";
apps_and_reasons[app_pair.first] = "not fetched";
LOG_INFO << app_name << " is not fully installed. Will be re-installed or have update completed";
continue;
}
if (!app_engine_->isRunning({app_name, app_pair.second})) {
// an App that is supposed to running is not running
apps_to_update.insert(app_pair);
apps_and_reasons[app_pair.first] = "not running";
LOG_INFO << app_name << " is not running. Will be re-installed or have update completed";
continue;
}
}

return apps_to_update;
}

std::vector<std::string> ComposeAppManager::checkForAppsToUpdate(const Uptane::Target& target) {
cur_apps_to_fetch_and_update_ = getAppsToUpdate(target);
// true if the vector contains any string starting with the given prefix
std::unordered_map<std::string, std::string> ComposeAppManager::checkForAppsToUpdate(const Uptane::Target& target) {
std::unordered_map<std::string, std::string> apps_and_reasons;
cur_apps_to_fetch_and_update_ = getAppsToUpdate(target, apps_and_reasons);
if (!!cfg_.reset_apps) {
cur_apps_to_fetch_ = getAppsToFetch(target);
}
are_apps_checked_ = true;
std::vector<std::string> ret;
for (const auto& app : cur_apps_to_fetch_and_update_) {
ret.push_back(app.first);
}
for (const auto& app : cur_apps_to_fetch_) {
if (std::find(ret.begin(), ret.end(), app.first) == ret.end()) {
ret.push_back(app.first);
if (apps_and_reasons.count(app.first) == 0) {
apps_and_reasons[app.first] = "not fetched (reset apps)";
}
}
return ret;
return apps_and_reasons;
}

DownloadResult ComposeAppManager::Download(const TufTarget& target) {
Expand Down
5 changes: 3 additions & 2 deletions src/composeappmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ class ComposeAppManager : public RootfsTreeManager {
// Returns an intersection of Target's Apps and Apps listed in the config (sota.toml:compose_apps)
// If Apps are not specified in the config then all Target's Apps are returned
AppsContainer getApps(const Uptane::Target& t) const;
AppsContainer getAppsToUpdate(const Uptane::Target& t) const;
std::vector<std::string> checkForAppsToUpdate(const Uptane::Target& target);
AppsContainer getAppsToUpdate(const Uptane::Target& t,
std::unordered_map<std::string, std::string>& apps_and_reasons) const;
std::unordered_map<std::string, std::string> checkForAppsToUpdate(const Uptane::Target& target);
void setAppsNotChecked() { are_apps_checked_ = false; }
void handleRemovedApps(const Uptane::Target& target) const;
Json::Value getAppsState() const;
Expand Down
2 changes: 1 addition & 1 deletion src/liteclient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ bool LiteClient::isTargetActive(const Uptane::Target& target) const {

bool LiteClient::appsInSync(const Uptane::Target& target) const { return appsToUpdate(target).empty(); }

std::vector<std::string> LiteClient::appsToUpdate(const Uptane::Target& target) const {
std::unordered_map<std::string, std::string> LiteClient::appsToUpdate(const Uptane::Target& target) const {
if (package_manager_->name() == ComposeAppManager::Name) {
auto* compose_pacman = dynamic_cast<ComposeAppManager*>(package_manager_.get());
if (compose_pacman == nullptr) {
Expand Down
2 changes: 1 addition & 1 deletion src/liteclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class LiteClient {
void reportAppsState();
bool isTargetActive(const Uptane::Target& target) const;
bool appsInSync(const Uptane::Target& target) const;
std::vector<std::string> appsToUpdate(const Uptane::Target& target) const;
std::unordered_map<std::string, std::string> appsToUpdate(const Uptane::Target& target) const;
void setAppsNotChecked();
std::string getDeviceID() const;
static void update_request_headers(std::shared_ptr<HttpClient>& http_client, const Uptane::Target& target,
Expand Down

0 comments on commit 4ce9c58

Please sign in to comment.