This is an automated email from the ASF dual-hosted git repository.

saipranav pushed a commit to branch ResViewCrow
in repository https://gitbox.apache.org/repos/asf/incubator-resilientdb.git


The following commit(s) were added to refs/heads/ResViewCrow by this push:
     new 8f4386f0 "Added 2 new apis in same thread to save resources"
8f4386f0 is described below

commit 8f4386f0cd8fd848f6eac5aad1a51625aeb2ff96
Author: Saipranav Kotamreddy <[email protected]>
AuthorDate: Sun Mar 24 18:53:07 2024 -0700

    "Added 2 new apis in same thread to save resources"
---
 platform/statistic/stats.cpp | 35 +++++++++++++++++++++++++++++------
 platform/statistic/stats.h   |  2 +-
 2 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/platform/statistic/stats.cpp b/platform/statistic/stats.cpp
index 3a975cf6..74c1fcbc 100644
--- a/platform/statistic/stats.cpp
+++ b/platform/statistic/stats.cpp
@@ -88,12 +88,12 @@ Stats::~Stats() {
     global_thread_.join();
   }
   if(enable_resview && summary_thread_.joinable()){
-    summary_thread_.join();
+    //summary_thread_.join();
     crow_thread_.join();
   }
-  if(enable_faulty_switch && faulty_thread_.joinable()){
+  /*if(enable_faulty_switch && faulty_thread_.joinable()){
     faulty_thread_.join();
-  }
+  }*/
 }
 
 void Stats::SocketManagementWrite(){
@@ -162,6 +162,29 @@ void Stats::CrowRoute(){
         res.end();
         //return consensus_history_.dump();
       });
+      CROW_ROUTE(app, "/get_status").methods("GET"_method)([this](const 
crow::request& req, crow::response& res){
+        LOG(ERROR)<<"API";
+        res.set_header("Access-Control-Allow-Origin", "*"); // Allow requests 
from any origin
+        res.set_header("Access-Control-Allow-Methods", "GET, POST, OPTIONS"); 
// Specify allowed methods
+        res.set_header("Access-Control-Allow-Headers", "Content-Type, 
Authorization"); // Specify allowed headers
+
+        // Send your response
+        res.body= IsFaulty() ? "Faulty" : "Not Faulty";
+        res.end();
+      });
+      CROW_ROUTE(app, "/make_faulty").methods("POST"_method)([this](const 
crow::request& req, crow::response& res){
+        LOG(ERROR)<<"API";
+        res.set_header("Access-Control-Allow-Origin", "*"); // Allow requests 
from any origin
+        res.set_header("Access-Control-Allow-Methods", "GET, POST, OPTIONS"); 
// Specify allowed methods
+        res.set_header("Access-Control-Allow-Headers", "Content-Type, 
Authorization"); // Specify allowed headers
+
+        // Send your response
+        if(enable_faulty_switch_){
+          make_faulty_.store(!make_faulty_.load());
+        }
+        res.body= "Success";
+        res.end();
+      });
       app.port(8500+transaction_summary_.port).multithreaded().run();
       sleep(1);
     }
@@ -184,14 +207,14 @@ void Stats::SetProps(int replica_id, std::string ip, int 
port, bool resview_flag
   transaction_summary_.ip=ip;
   transaction_summary_.port=port;
   enable_resview=resview_flag;
-  enable_faulty_switch=faulty_flag;
+  enable_faulty_switch_=faulty_flag;
   if(resview_flag){
     //summary_thread_ = std::thread(&Stats::SocketManagementWrite, this);
     crow_thread_ = std::thread(&Stats::CrowRoute, this);
   }
-  if(faulty_flag){
+  /*if(faulty_flag){
     faulty_thread_ = std::thread(&Stats::SocketManagementRead, this);
-  }
+  }*/
 }
 
 void Stats::SetPrimaryId(int primary_id){
diff --git a/platform/statistic/stats.h b/platform/statistic/stats.h
index 8a7968c2..69111c79 100644
--- a/platform/statistic/stats.h
+++ b/platform/statistic/stats.h
@@ -146,7 +146,7 @@ class Stats{
   std::thread faulty_thread_;
   std::thread crow_thread_;
   bool enable_resview;
-  bool enable_faulty_switch;
+  bool enable_faulty_switch_;
   VisualData transaction_summary_;
   std::atomic<bool> send_summary_;
   std::atomic<bool> make_faulty_;

Reply via email to