features: app engine #1
| @ -94,7 +94,7 @@ impl NewAppReq { | |||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Serialize, Deserialize)] | #[derive(Debug, Serialize, Deserialize, Clone)] | ||||||
| pub struct AppNodeWithReports { | pub struct AppNodeWithReports { | ||||||
|     pub id: RecordId, |     pub id: RecordId, | ||||||
|     pub operator: RecordId, |     pub operator: RecordId, | ||||||
| @ -116,6 +116,7 @@ impl AppNodeWithReports { | |||||||
|     pub async fn find_by_filters( |     pub async fn find_by_filters( | ||||||
|         db: &Surreal<Client>, |         db: &Surreal<Client>, | ||||||
|         filters: app_proto::AppNodeFilters, |         filters: app_proto::AppNodeFilters, | ||||||
|  |         limit_one: bool, | ||||||
|     ) -> Result<Vec<Self>, Error> { |     ) -> Result<Vec<Self>, Error> { | ||||||
|         let mut filter_query = format!( |         let mut filter_query = format!( | ||||||
|             "select *, <-report.* from {APP_NODE} where
 |             "select *, <-report.* from {APP_NODE} where
 | ||||||
| @ -123,7 +124,7 @@ impl AppNodeWithReports { | |||||||
|             max_ports_per_app >= {} && |             max_ports_per_app >= {} && | ||||||
|             avail_vcpus >= {} && |             avail_vcpus >= {} && | ||||||
|             avail_mem_mb >= {} && |             avail_mem_mb >= {} && | ||||||
|             avail_storage_gbs >= {}\n",
 |             avail_storage_gbs >= {} ",
 | ||||||
|             filters.free_ports, |             filters.free_ports, | ||||||
|             filters.free_ports, |             filters.free_ports, | ||||||
|             filters.vcpus, |             filters.vcpus, | ||||||
| @ -143,8 +144,12 @@ impl AppNodeWithReports { | |||||||
|         if !filters.ip.is_empty() { |         if !filters.ip.is_empty() { | ||||||
|             filter_query += &format!("&& ip = '{}' ", filters.ip); |             filter_query += &format!("&& ip = '{}' ", filters.ip); | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|  |         if limit_one { | ||||||
|  |             filter_query += "limit 1"; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         filter_query += ";"; |         filter_query += ";"; | ||||||
|         dbg!(&filter_query); |  | ||||||
|         let mut query_resp = db.query(filter_query).await?; |         let mut query_resp = db.query(filter_query).await?; | ||||||
|         let app_nodes: Vec<Self> = query_resp.take(0)?; |         let app_nodes: Vec<Self> = query_resp.take(0)?; | ||||||
|         Ok(app_nodes) |         Ok(app_nodes) | ||||||
|  | |||||||
| @ -113,7 +113,7 @@ pub struct Kick { | |||||||
|     contract: RecordId, |     contract: RecordId, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Serialize, Deserialize)] | #[derive(Debug, Serialize, Deserialize, Clone)] | ||||||
| pub struct Report { | pub struct Report { | ||||||
|     #[serde(rename = "in")] |     #[serde(rename = "in")] | ||||||
|     from_account: RecordId, |     from_account: RecordId, | ||||||
|  | |||||||
| @ -219,7 +219,7 @@ impl BrainAppCli for AppCliServer { | |||||||
|     ) -> Result<tonic::Response<<Self as BrainAppCli>::ListAppNodesStream>, tonic::Status> { |     ) -> Result<tonic::Response<<Self as BrainAppCli>::ListAppNodesStream>, tonic::Status> { | ||||||
|         let req = check_sig_from_req(req)?; |         let req = check_sig_from_req(req)?; | ||||||
|         info!("list_app_nodes process starting for {:?}", req); |         info!("list_app_nodes process starting for {:?}", req); | ||||||
|         let app_nodes = db::AppNodeWithReports::find_by_filters(&self.db, req).await?; |         let app_nodes = db::AppNodeWithReports::find_by_filters(&self.db, req, false).await?; | ||||||
|         let (tx, rx) = mpsc::channel(6); |         let (tx, rx) = mpsc::channel(6); | ||||||
|         tokio::spawn(async move { |         tokio::spawn(async move { | ||||||
|             for app_node in app_nodes { |             for app_node in app_nodes { | ||||||
| @ -236,7 +236,12 @@ impl BrainAppCli for AppCliServer { | |||||||
|     ) -> Result<tonic::Response<AppNodeListResp>, tonic::Status> { |     ) -> Result<tonic::Response<AppNodeListResp>, tonic::Status> { | ||||||
|         let req = check_sig_from_req(req)?; |         let req = check_sig_from_req(req)?; | ||||||
|         info!("get_one_app_node process starting for {:?}", req); |         info!("get_one_app_node process starting for {:?}", req); | ||||||
|  |         let app_node = db::AppNodeWithReports::find_by_filters(&self.db, req, true) | ||||||
|  |             .await? | ||||||
|  |             .first() | ||||||
|  |             .ok_or(Status::not_found("No app node found"))? | ||||||
|  |             .clone(); | ||||||
| 
 | 
 | ||||||
|         todo!() |         Ok(Response::new(app_node.into())) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user