Implement App functionality #11

Open
noormohammedb wants to merge 30 commits from noormohammedb/brain-mock:app_brain into main
2 changed files with 8 additions and 18 deletions
Showing only changes of commit 41352f2c33 - Show all commits

2
Cargo.lock generated

@ -420,7 +420,7 @@ dependencies = [
[[package]]
name = "detee-shared"
version = "0.1.0"
source = "git+ssh://git@gitea.detee.cloud/noormohammedb/detee-shared?branch=stable_01#dc1e2dd0cd70f0915245fe3cae0863eab838fe5a"
source = "git+ssh://git@gitea.detee.cloud/noormohammedb/detee-shared?branch=stable_01#a734b392b7dba31693337b5a806d30cc9b8cd967"
dependencies = [
"base64",
"prost",

@ -195,20 +195,16 @@ pub struct AppContract {
}
impl AppContract {
fn total_units(&self) -> u64 {
fn total_units(&self) -> f64 {
// TODO: Optimize this based on price of hardware.
(self.vcpus as u64 * 10)
+ (self.memory_mb as u64 / 200)
+ (self.disk_size_mb as u64 / 10000)
}
pub fn price_estimate(vcpus: u32, memory_mb: u32, disk_size_mb: u32) -> u64 {
(vcpus as u64 * 10) + (memory_mb as u64 / 200) + (disk_size_mb as u64 / 10000)
(self.vcpus as f64 * 10f64)
+ (self.memory_mb as f64 / 200f64)
+ (self.disk_size_mb as f64 / 10000f64)
}
/// Returns price per minute in nanoLP
fn price_per_minute(&self) -> u64 {
self.total_units() * self.price_per_unit
(self.total_units() * self.price_per_unit as f64) as u64
}
}
@ -221,6 +217,7 @@ impl From<AppContract> for AppContractPB {
.map(MappedPort::from)
.collect();
let nano_per_minute = value.price_per_minute();
let resource = Some(AppResourcePB {
memory_mb: value.memory_mb,
disk_mb: value.disk_size_mb,
@ -238,7 +235,7 @@ impl From<AppContract> for AppContractPB {
created_at: value.created_at.to_rfc3339(),
updated_at: value.updated_at.to_rfc3339(),
// TODO: check while implementing pricing
nano_per_minute: value.price_per_unit,
nano_per_minute,
locked_nano: value.locked_nano,
collected_at: value.collected_at.to_rfc3339(),
hratls_pubkey: value.hratls_pubkey,
@ -1311,13 +1308,6 @@ impl BrainData {
}
pub async fn send_new_container_req(&self, mut req: NewAppReq, tx: OneshotSender<NewAppRes>) {
// TODO: make sure locked_nano in cli
if req.locked_nano == 0 {
let resource = req.resource.clone().unwrap_or_default();
req.locked_nano =
AppContract::price_estimate(resource.vcpu, resource.memory_mb, resource.disk_mb)
}
if let Err(e) = self.lock_nanotockens(&req.admin_pubkey, req.locked_nano) {
let _ = tx.send(NewAppRes {
uuid: String::new(),