Skip to content

Commit

Permalink
[daemon] process adapted delete request and add snapshot delete place…
Browse files Browse the repository at this point in the history
…holder code
  • Loading branch information
sharder996 committed May 23, 2023
1 parent e568a2b commit 4c1c183
Showing 1 changed file with 38 additions and 9 deletions.
47 changes: 38 additions & 9 deletions src/daemon/daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,23 @@ bool is_ipv4_valid(const std::string& ipv4)
return true;
}

template <typename Instances>
std::unordered_map<std::string, std::unordered_set<std::string>> map_snapshots_to_instances(const Instances& instances)
{
std::unordered_map<std::string, std::unordered_set<std::string>> instance_snapshots_map;

for (const auto& it : instances)
{
if (it.snapshot_name().empty())
instance_snapshots_map[it.instance_name()] = {};
else if (auto entry = instance_snapshots_map.find(it.instance_name());
entry != instance_snapshots_map.end() && !entry->second.empty())
instance_snapshots_map[it.instance_name()].emplace(it.snapshot_name());
}

return instance_snapshots_map;
}

void add_aliases(google::protobuf::RepeatedPtrField<mp::FindReply_ImageInfo>* container, const std::string& remote_name,
const mp::VMImageInfo& info, const std::string& default_remote)
{
Expand Down Expand Up @@ -1755,14 +1772,7 @@ try // clang-format on

if (status.ok())
{
for (const auto& it : request->instances_snapshots())
{
if (it.snapshot_name().empty())
instance_snapshots_map[it.instance_name()] = {};
else if (const auto& entry = instance_snapshots_map.find(it.instance_name());
entry != instance_snapshots_map.end() && !entry->second.empty())
instance_snapshots_map[it.instance_name()].insert(it.snapshot_name());
}
instance_snapshots_map = map_snapshots_to_instances(request->instances_snapshots());

// TODO@snapshots change cmd logic after all info logic paths are added
auto cmd =
Expand Down Expand Up @@ -2231,12 +2241,13 @@ try // clang-format on
DeleteReply response;

auto [instance_selection, status] =
select_instances_and_react(operative_instances, deleted_instances, request->instance_names().instance_name(),
select_instances_and_react(operative_instances, deleted_instances, request->instances_snapshots(),
InstanceGroup::All, require_existing_instances_reaction);

if (status.ok())
{
const bool purge = request->purge();
auto instance_snapshots_map = map_snapshots_to_instances(request->instances_snapshots());

for (const auto& vm_it : instance_selection.operative_selection)
{
Expand All @@ -2252,6 +2263,24 @@ try // clang-format on

if (purge)
{
// TODO@snapshots call method to delete snapshots
/*
if (const auto& it = instance_snapshots_map.find(name);
it == instance_snapshots_map.end() || it.second.empty())
{
// Delete instance and snapshots
// release_resources(name);
// response.add_purged_instances(name);
}
else
{
for (const auto& snapshot_name : instance_snapshots_map[name])
{
// Delete snapshot
}
}
*/

release_resources(name);
response.add_purged_instances(name);
}
Expand Down

0 comments on commit 4c1c183

Please sign in to comment.