Skip to content

Commit

Permalink
Add some allocator details to /allocators endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
kacperzuk-neti committed Jul 12, 2024
1 parent 75097fa commit 6c3bd72
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 0 deletions.
40 changes: 40 additions & 0 deletions fplus-database/src/database/allocators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ pub async fn get_allocator(
* @param verifiers_gh_handles: Option<String> - The GitHub handles of the verifiers
* @param address: Option<String> - Address of the Allocator
* @param tooling: Option<String> - Supported tooling
* @param data_types: Option<Vec<String>> - Supported data_types
* @param required_sps: Option<String> - Required number of SPs
* @param required_replicas: Option<String> - Required number of replicas
* @param registry_file_path: Option<String> - Path to JSON file specifying the allocator in registry repo
*
* # Returns
* @return Result<AllocatorModel, sea_orm::DbErr> - The result of the operation
Expand All @@ -63,6 +67,10 @@ pub async fn create_or_update_allocator(
allocation_amount_type: Option<String>,
address: Option<String>,
tooling: Option<String>,
data_types: Option<Vec<String>>,
required_sps: Option<String>,
required_replicas: Option<String>,
registry_file_path: Option<String>,
) -> Result<AllocatorModel, sea_orm::DbErr> {
let existing_allocator = get_allocator(&owner, &repo).await?;
if let Some(allocator_model) = existing_allocator {
Expand Down Expand Up @@ -100,6 +108,22 @@ pub async fn create_or_update_allocator(
allocator_active_model.tooling = Set(tooling);
}

if data_types.is_some() {
allocator_active_model.data_types = Set(data_types);
}

if required_sps.is_some() {
allocator_active_model.required_sps = Set(required_sps);
}

if required_replicas.is_some() {
allocator_active_model.required_replicas = Set(required_replicas);
}

if registry_file_path.is_some() {
allocator_active_model.registry_file_path = Set(registry_file_path);
}

let updated_model = allocator_active_model.update(&conn).await?;

Ok(updated_model)
Expand Down Expand Up @@ -140,6 +164,22 @@ pub async fn create_or_update_allocator(
new_allocator.tooling = Set(tooling);
}

if data_types.is_some() {
new_allocator.data_types = Set(data_types);
}

if required_sps.is_some() {
new_allocator.required_sps = Set(required_sps);
}

if required_replicas.is_some() {
new_allocator.required_replicas = Set(required_replicas);
}

if registry_file_path.is_some() {
new_allocator.registry_file_path = Set(registry_file_path);
}

let conn = get_database_connection()
.await
.expect("Failed to get DB connection");
Expand Down
22 changes: 22 additions & 0 deletions fplus-database/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ mod tests {
let amount_type = Some("Fixed".to_string());
let address = Some("0x1234567890".to_string());
let tooling = Some("common_ui, smart_contract_allocator".to_string());
let data_types = Some(vec![
"Public Open Dataset (Research/Non-Profit)".to_string(),
"Public Open Commercial/Enterprise".to_string(),
]);
let required_sps = Some("5+".to_string());
let required_replicas = Some("5+".to_string());
let registry_file_path = Some("Allocators/123.json".to_string());

let result = database::allocators::create_or_update_allocator(
owner,
Expand All @@ -121,6 +128,10 @@ mod tests {
amount_type,
address,
tooling,
data_types,
required_sps,
required_replicas,
registry_file_path,
)
.await;
assert!(result.is_ok());
Expand Down Expand Up @@ -191,6 +202,13 @@ mod tests {
let amount_type = Some("Fixed".to_string());
let address = Some("0x1234567890".to_string());
let tooling = Some("common_ui, smart_contract_allocator".to_string());
let data_types = Some(vec![
"Public Open Dataset (Research/Non-Profit)".to_string(),
"Public Open Commercial/Enterprise".to_string(),
]);
let required_sps = Some("5+".to_string());
let required_replicas = Some("5+".to_string());
let registry_file_path = Some("Allocators/123.json".to_string());

let result = database::allocators::create_or_update_allocator(
owner.clone(),
Expand All @@ -202,6 +220,10 @@ mod tests {
amount_type,
address,
tooling,
data_types,
required_sps,
required_replicas,
registry_file_path,
)
.await;

Expand Down
4 changes: 4 additions & 0 deletions fplus-database/src/models/allocators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ pub struct Model {
pub allocation_amount_type: Option<String>,
pub address: Option<String>,
pub tooling: Option<String>,
pub data_types: Option<Vec<String>>,
pub required_sps: Option<String>,
pub required_replicas: Option<String>,
pub registry_file_path: Option<String>,
}

#[derive(Copy, Clone, Debug, EnumIter)]
Expand Down
4 changes: 4 additions & 0 deletions fplus-http-server/src/router/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ pub async fn create_from_json(
.and_then(|a| a.amount_type.clone()),
model.address,
tooling,
Some(model.application.data_types),
Some(model.application.required_sps),
Some(model.application.required_replicas),
Some(file_name.to_owned()),
)
.await;

Expand Down
3 changes: 3 additions & 0 deletions fplus-lib/src/core/allocator/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ pub struct Application {
pub allocation_bookkeeping: String,
pub allocation_amount: Option<AllocationAmount>,
pub tooling: Vec<String>,
pub data_types: Vec<String>,
pub required_sps: String,
pub required_replicas: String,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
Expand Down
4 changes: 4 additions & 0 deletions fplus-lib/src/core/allocator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,10 @@ pub async fn update_installation_ids_in_db(installation: InstallationRepositorie
None,
None,
None,
None,
None,
None,
None,
)
.await;
}
Expand Down
5 changes: 5 additions & 0 deletions manual-migrations/2024-07-12.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
alter table allocators
add column data_types text[],
add column required_sps text,
add column required_replicas text,
add column registry_file_path text;

0 comments on commit 6c3bd72

Please sign in to comment.