-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
572843c
commit 41a447d
Showing
6 changed files
with
218 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
fn main() { | ||
tonic_build::compile_protos("proto/instance.proto").unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
syntax = "proto3"; | ||
|
||
package instance; | ||
|
||
// Message definitions | ||
message Instance { | ||
string name = 1; | ||
string engine = 2; | ||
} | ||
|
||
message CreateInstanceRequest { | ||
string engine_type = 1; | ||
string root_path = 2; | ||
} | ||
|
||
message CreateInstanceResponse { | ||
string instance = 1; | ||
} | ||
|
||
message GetInstanceRequest { | ||
string instance_name = 1; | ||
} | ||
|
||
message GetInstanceResponse { | ||
string instance = 1; // Returning the instance | ||
} | ||
|
||
message GetAllInstancesRequest { | ||
string message = 1; | ||
} | ||
|
||
message GetAllInstancesResponse { | ||
repeated Instance instances = 1; | ||
} | ||
|
||
service InstanceService { | ||
rpc CreateInstance(CreateInstanceRequest) returns (CreateInstanceResponse); | ||
rpc GetInstance(GetInstanceRequest) returns (GetInstanceResponse); | ||
rpc GetAllInstances(GetAllInstancesRequest) returns (GetAllInstancesResponse); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use tonic::{transport::Server, Request, Response, Status}; | ||
use uuid::Uuid; | ||
use std::path::PathBuf; | ||
use std::sync::{Arc, Mutex}; | ||
|
||
// Import generated gRPC code | ||
pub mod instance { | ||
tonic::include_proto!("instance"); | ||
} | ||
|
||
use instance::{InstanceService, CreateInstanceRequest, CreateInstanceResponse, | ||
GetInstanceRequest, GetInstanceResponse, Instance}; | ||
|
||
// Engines enum represents the types of engines | ||
#[derive(Debug, Clone)] | ||
pub enum Engines { | ||
JSONEngine(JSONEngine), | ||
} | ||
|
||
// Your JSONEngine structure | ||
#[derive(Debug, Clone)] | ||
pub struct JSONEngine { | ||
// Add fields necessary for your JSON engine | ||
} | ||
|
||
impl JSONEngine { | ||
pub fn new(_root_path: &PathBuf) -> Self { | ||
// Initialize your JSONEngine as needed | ||
Self {} | ||
} | ||
} | ||
|
||
// Instance structure | ||
#[derive(Debug, Clone, Default)] | ||
pub struct Instance { | ||
pub name: String, | ||
pub engine: Engines, | ||
} | ||
|
||
// InstanceManager struct to manage instances | ||
#[derive(Debug, Default)] | ||
pub struct InstanceManager { | ||
pub name: String, | ||
pub instances: Vec<Instance>, | ||
} | ||
|
||
impl InstanceManager { | ||
pub fn new() -> Self { | ||
let name = Uuid::new_v4().to_string(); | ||
let instances: Vec<Instance> = vec![]; | ||
Self { name, instances } | ||
} | ||
|
||
pub fn create_instance(&mut self, engine_type: &str, root_path: &PathBuf) -> String { | ||
let instance_name: String = Uuid::new_v4().to_string(); | ||
|
||
let engine = match engine_type { | ||
"json_engine" => Engines::JSONEngine(JSONEngine::new(root_path)), | ||
_ => panic!("Engine not found"), | ||
}; | ||
|
||
let instance = Instance { engine, name: instance_name.clone() }; | ||
self.instances.push(instance); | ||
instance_name | ||
} | ||
|
||
pub fn get_instance(&self, instance_name: &str) -> Option<&Instance> { | ||
self.instances.iter().find(|i| i.name == instance_name) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters