From 2f875fa129a7726fb92d3361b5478bc84e501e55 Mon Sep 17 00:00:00 2001
From: KyleKlenk <kyle.c.klenk@gmail.com>
Date: Wed, 5 Oct 2022 23:39:51 +0000
Subject: [PATCH] started added class defintion for batch_manager

---
 build/includes/summa_actor/batch_manager.hpp  | 72 +++++++++++++++++++
 build/includes/summa_actor/summa_client.hpp   |  1 +
 build/source/actors/summa_actor/client.cpp    |  2 +
 .../source/actors/summa_actor/summa_actor.cpp |  1 +
 .../actors/summa_actor/summa_client.cpp       |  2 +
 .../actors/summa_actor/summa_server.cpp       |  2 +
 6 files changed, 80 insertions(+)

diff --git a/build/includes/summa_actor/batch_manager.hpp b/build/includes/summa_actor/batch_manager.hpp
index 062cd06..cca0837 100644
--- a/build/includes/summa_actor/batch_manager.hpp
+++ b/build/includes/summa_actor/batch_manager.hpp
@@ -11,14 +11,43 @@ enum batch_status {
     failed
 };
 
+struct Batch_Struct {
+    int batch_id;
+    int start_hru;
+    int num_hru;
+
+    double run_time;
+    double read_time;
+    double write_time;
+    
+    std::string assigned_host;
+    caf::actor assigned_actor;
+    bool assigned;
+};
+
+template<class Inspector>
+bool inspect(Inspector& inspector, Batch_Struct& batch) {
+    return inspector.object(batch).fields(
+                inspector.field("batch_id", batch.batch_id),
+                inspector.field("start_hru",batch.start_hru),
+                inspector.field("num_hru",   batch.num_hru),
+                inspector.field("run_time",  batch.run_time),
+                inspector.field("write_time",batch.write_time),
+                inspector.field("assigned_host", batch.assigned_host),
+                inspector.field("assigned_actor", batch.assigned_actor),
+                inspector.field("assigned", batch.assigned));
+}
+
 class Batch {
     private:
         int batch_id;
         int start_hru;
         int num_hru;
+
         double run_time;
         double read_time;
         double write_time;
+        
         std::string assigned_host;
         caf::actor assigned_actor;
         batch_status status;
@@ -52,6 +81,49 @@ class Batch_Manager {
         std::vector<Batch> batch_list;
         std::vector<Batch> solved_batches;
         std::vector<Batch> failed_batches;        
+    
+    
     public:
+        /**
+         * Assemble the total number of HRUs given by the user into batches.
+         * The total number of hrus and the sizes of the batches are parameters
+         * provided by the user.
+         */
+        void assembleBatches(int total_hru_count, int num_hru_per_batch);
+
+
+        /**
+         * Assign a batch to be solved by a client.
+         * The hostname and the actor_ref of the client solving this batch
+         * are added to the client for the servers awareness
+         * The batch is then returned by this method and sent to the respective client
+         */
+        Batch assignBatch(std::string hostname, caf::actor actor_ref);
+
+
+        /**
+         * On a successful batch we take the batch given to us by the client 
+         * and add it to our solved_batches list.
+         *  
+         * We can then remove the batch from the global batch list.
+         */
+        void batchSuccess(Batch successful_batch, std::string output_csv);
+
+
+        /**
+         * A batch failure is returned to us by the client
+         * This is for when a client failed to solve the batch.
+         */
+        void batchFailure(Batch failed_batch);
+
+
+        /**
+         * A client has found to be disconnected. Unassign all batches
+         * that were assigned to the disconnected client. The client id 
+         * is passed in as a parameter
+         */
+        void disconnected_client(int client_id);
+
+
 
 };
\ No newline at end of file
diff --git a/build/includes/summa_actor/summa_client.hpp b/build/includes/summa_actor/summa_client.hpp
index 37f171d..496429d 100644
--- a/build/includes/summa_actor/summa_client.hpp
+++ b/build/includes/summa_actor/summa_client.hpp
@@ -3,6 +3,7 @@
 #include "caf/all.hpp"
 #include "caf/io/all.hpp"
 #include "settings_functions.hpp"
+#include "batch_manager.hpp"
 
 #include <string>
 #include <optional>
diff --git a/build/source/actors/summa_actor/client.cpp b/build/source/actors/summa_actor/client.cpp
index bc5faa1..b2e868a 100644
--- a/build/source/actors/summa_actor/client.cpp
+++ b/build/source/actors/summa_actor/client.cpp
@@ -2,6 +2,8 @@
 #include "client.hpp"
 
 
+
+
 Client::Client(int id, caf::actor client_actor, std::string hostname) {
     this->id = id;
     this->client_actor = client_actor;
diff --git a/build/source/actors/summa_actor/summa_actor.cpp b/build/source/actors/summa_actor/summa_actor.cpp
index 6793392..88d8ade 100644
--- a/build/source/actors/summa_actor/summa_actor.cpp
+++ b/build/source/actors/summa_actor/summa_actor.cpp
@@ -109,4 +109,5 @@ void spawnJob(stateful_actor<summa_actor_state>* self) {
 		self->state.numGRU = 0;
 	}
 }
+
 } // end namespace
diff --git a/build/source/actors/summa_actor/summa_client.cpp b/build/source/actors/summa_actor/summa_client.cpp
index 89606b3..e8dfa83 100644
--- a/build/source/actors/summa_actor/summa_client.cpp
+++ b/build/source/actors/summa_actor/summa_client.cpp
@@ -87,6 +87,8 @@ behavior running(stateful_actor<summa_client_state>* self, const actor& server_a
             
         },
 
+        // [=](compute_batch) {}
+
 
         [=](batch, int client_id, int batch_id, int start_hru, int num_hru, std::string config_path) {
             aout(self) << "\nReceived batch to compute" << "\n";
diff --git a/build/source/actors/summa_actor/summa_server.cpp b/build/source/actors/summa_actor/summa_server.cpp
index abd6176..68389ea 100644
--- a/build/source/actors/summa_actor/summa_server.cpp
+++ b/build/source/actors/summa_actor/summa_server.cpp
@@ -176,4 +176,6 @@ void initializeCSVOutput(std::string csv_output_name) {
     csv_output.close();
 }
 
+
+
 } // end namespace
-- 
GitLab