From 894eb0d2929527b22be62ce612e4826ea93444a4 Mon Sep 17 00:00:00 2001
From: Philippe Virouleau <philippe.virouleau@inria.fr>
Date: Fri, 21 Jun 2024 10:28:37 +0200
Subject: [PATCH] refapi: add a global json file for RE

---
 lib/refrepo/gen/reference-api.rb | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/lib/refrepo/gen/reference-api.rb b/lib/refrepo/gen/reference-api.rb
index 9e3afb715a4..985651d655f 100644
--- a/lib/refrepo/gen/reference-api.rb
+++ b/lib/refrepo/gen/reference-api.rb
@@ -172,15 +172,26 @@ def generate_reference_api
   )
 
 
-  #
-  # Write the all-in-one json file
-  #
-
-  # rename entry for the all-in-on json file
-  global_hash["sites"].each do |_site_uid, site|
-    site["network_equipments"] = site.delete("networks")
-  end
+  # Generate the all-in-one json with just enough information for resources-explorer.
+  all_in_one_hash = {
+    "sites" => global_hash["sites"].to_h do |site_uid, site|
+      [site_uid, {
+        "uid" => site_uid,
+        "clusters" => site["clusters"].to_h do |cluster_uid, cluster|
+          [cluster_uid, {
+            "uid" => cluster_uid,
+            "queues" => cluster["queues"],
+            "nodes" => cluster["nodes"].to_h do |node_uid, node|
+              [node_uid, node.select { |key| %w[uid nodeset gpu_devices processor architecture].include?(key) }]
+            end
+          }]
+        end
+      }]
+    end
+  }
 
-  # Write global json file - Disable this for now, see https://www.grid5000.fr/w/TechTeam:CT-220
-  #write_json(grid_path.join(File.expand_path("../../#{global_hash['uid']}-all.json", File.dirname(__FILE__))), global_hash)
+  # Write the global json file.
+  # Writing the file at the root of the repository makes the full refrepo show
+  # up when GET-ing "/" in g5k-api, which we don't want; arbitrarily put it in accesses.
+  write_json(Pathname.new(refapi_path).join("accesses", "refrepo.json"), all_in_one_hash)
 end
-- 
GitLab