Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(builtins): impl srv.info, dist.get_blueprint #1468

Merged
merged 7 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions particle-builtins/src/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ use std::time::{Duration, Instant};

use derivative::Derivative;
use fluence_keypair::{KeyPair, Signature};
use futures::stream::FuturesUnordered;
use futures::StreamExt;
use humantime_serde::re::humantime::format_duration as pretty;
use libp2p::{core::Multiaddr, kad::kbucket::Key, kad::K_VALUE, PeerId};
use multihash::{Code, MultihashDigest, MultihashGeneric};
Expand Down Expand Up @@ -175,6 +173,7 @@ where
// TODO: get rid of all blocking methods (std::fs and such)
pub async fn builtins_call(&self, args: Args, particle: ParticleParams) -> FunctionOutcome {
use Result as R;

#[rustfmt::skip]
match (args.service_id.as_str(), args.function_name.as_str()) {
("peer", "identify") => ok(json!(self.node_info)),
Expand All @@ -195,6 +194,7 @@ where
("srv", "resolve_alias") => wrap(self.resolve_alias(args, particle)),
("srv", "add_alias") => wrap_unit(self.add_alias(args, particle)),
("srv", "remove") => wrap_unit(self.remove_service(args, particle)),
("srv", "info") => wrap(self.get_service_info(args, particle)),

("dist", "add_module_from_vault") => wrap(self.add_module_from_vault(args, particle)),
("dist", "add_module") => wrap(self.add_module(args)),
Expand All @@ -207,6 +207,7 @@ where
("dist", "list_modules") => wrap(self.list_modules()),
("dist", "get_module_interface") => wrap(self.get_module_interface(args)),
("dist", "list_blueprints") => wrap(self.get_blueprints()),
("dist", "get_blueprint") => wrap(self.get_blueprint(args)),

("script", "add") => wrap(self.add_script_from_arg(args, particle)),
("script", "add_from_vault") => wrap(self.add_script_from_vault(args, particle)),
Expand Down Expand Up @@ -303,6 +304,9 @@ where
}

async fn neighborhood_with_addresses(&self, args: Args) -> Result<JValue, JError> {
use futures::stream::FuturesUnordered;
use futures::StreamExt;

let neighbors = self.neighbor_peers(args).await?;
let neighbors = neighbors
.into_iter()
Expand Down Expand Up @@ -789,6 +793,15 @@ where
.collect()
}

fn get_blueprint(&self, args: Args) -> Result<JValue, JError> {
let mut args = args.function_args.into_iter();
let blueprint_id: String = Args::next("blueprint_id", &mut args)?;

let blueprint = self.modules.get_blueprint_from_cache(&blueprint_id)?;

Ok(json!(blueprint))
}

fn create_service(&self, args: Args, params: ParticleParams) -> Result<JValue, JError> {
let mut args = args.function_args.into_iter();
let blueprint_id: String = Args::next("blueprint_id", &mut args)?;
Expand Down Expand Up @@ -844,6 +857,16 @@ where
Ok(JValue::String(service_id))
}

fn get_service_info(&self, args: Args, params: ParticleParams) -> Result<JValue, JError> {
let mut args = args.function_args.into_iter();
let service_id_or_alias: String = Args::next("service_id_or_alias", &mut args)?;
let info = self
.services
.get_service_info(params.host_id, service_id_or_alias)?;

Ok(info)
}

fn kademlia(&self) -> &KademliaApi {
self.connectivity.as_ref()
}
Expand Down
27 changes: 26 additions & 1 deletion particle-services/src/app_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,30 @@ impl ParticleAppServices {
Ok(service_id)
}

pub fn get_service_info(
&self,
worker_id: PeerId,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mb rename it to worker_peer_id?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we call it worker_id everywhere, and there's no other id except peer id

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between this worker_id and service.worker_id? I though service.worker_id is a service/spell id of a worker, no?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no difference. service.worker_id indicates where is this service deployed

Copy link
Member Author

@folex folex Feb 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's the same thing. Services now can belong to worker_id, aka virtual peer.

service.worker_id is the PeerId of the worker aka virtual peer, same for worker_id

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we start using the word "worker" (which isn't descriptive at all) and not "virtual peer" (which is self-explanatory) then?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because worker comes from deals and is more workload and user-oriented. computation worker.

virtual peer is just some shenanigan inside rust-peer. it builds off the concept of peers. and it doesn't tell anything about computation or services. in other words, virtual peer is just one of the many pieces that make worker.

service_id_or_alias: String,
) -> Result<JValue, ServiceError> {
let services_read = self.services.read();
let (service, service_id) = get_service(
&services_read,
&self.aliases.read(),
worker_id,
self.config.local_peer_id,
service_id_or_alias,
)
.map_err(ServiceError::NoSuchService)?;

Ok(json!({
"id": service_id,
"blueprint_id": service.blueprint_id,
"owner_id": service.owner_id.to_string(),
"aliases": service.aliases,
"worker_id": service.worker_id.to_string()
}))
}

pub fn remove_service(
&self,
worker_id: PeerId,
Expand Down Expand Up @@ -573,7 +597,8 @@ impl ParticleAppServices {
"id": id,
"blueprint_id": srv.blueprint_id,
"owner_id": srv.owner_id.to_string(),
"aliases": srv.aliases
"aliases": srv.aliases,
"worker_id": srv.worker_id.to_string()
})
})
.collect();
Expand Down