Skip to content

Commit

Permalink
(#85) Network Viewer - Add getWorkdirPackages to backend
Browse files Browse the repository at this point in the history
  • Loading branch information
mario4tier committed Apr 29, 2024
1 parent 5808579 commit 396c7b9
Show file tree
Hide file tree
Showing 13 changed files with 320 additions and 377 deletions.
23 changes: 21 additions & 2 deletions rust/demo-app/move/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.22.0"
edition = "legacy"
compiler-version = "1.23.0"
edition = "2024.beta"
flavor = "sui"

[env]



[env.suibase]
test = 12

[env.localnet_proxy]
chain-id = "599ba668"
original-published-id = "0x4fc94af2a4f1982f56ad734a50b8df98cbf7e45553e0dbb475daab6cd0ab5436"
latest-published-id = "0x4fc94af2a4f1982f56ad734a50b8df98cbf7e45553e0dbb475daab6cd0ab5436"
published-version = "1"

[env.testnet_proxy]
chain-id = "4c78adac"
original-published-id = "0xb7f03f869344fc7359bc709b54f923e581c9d1ceb8bbfc673dab182d7b3f50a0"
latest-published-id = "0xb7f03f869344fc7359bc709b54f923e581c9d1ceb8bbfc673dab182d7b3f50a0"
published-version = "1"
6 changes: 3 additions & 3 deletions rust/suibase/crates/dtp-daemon/src/api/impl_dtp_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,10 +774,10 @@ impl DtpApiServer for DtpApiImpl {
.create_send_callback(workdir_idx, host_sla_idx, tc_address.clone())
.await;

let message = if message.is_none() {
"ping".to_string()
let message = if let Some(message) = message {
message
} else {
message.unwrap()
"ping".to_string()
};

let _ = {
Expand Down
27 changes: 12 additions & 15 deletions rust/suibase/crates/dtp-daemon/src/workers/websocket_worker_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,19 +332,18 @@ impl WebSocketWorkerIOThread {
// Assume this is a valid response to the subscription request.
// Get the host_sla_idx and trig a response for it if exists in the globals.
let host_sla_idx = ipipe.host_sla_idx;

{
{
let mut conns_state_guard = self
.params
.globals
.dtp_conns_state_client(self.params.workdir_idx)
.write()
.await;
let conns_state = &mut *conns_state_guard;

conns_state.trigger_subs_callback(host_sla_idx);
}
};
let mut conns_state_guard = self
.params
.globals
.dtp_conns_state_client(self.params.workdir_idx)
.write()
.await;
let conns_state = &mut *conns_state_guard;

conns_state.trigger_subs_callback(host_sla_idx);
}
}
}
}
Expand Down Expand Up @@ -757,9 +756,7 @@ impl WebSocketWorkerIOThread {
.await;
let conns_state = &mut *conns_state_guard;

let host_sla_idx = conns_state
.conns
.get_if_some(service_idx, &srv_host_addr, 0);
let host_sla_idx = conns_state.conns.get_if_some(service_idx, srv_host_addr, 0);

if host_sla_idx.is_none() {
// TODO It should have been created on "publish", but can be created here as needed.
Expand Down
6 changes: 6 additions & 0 deletions rust/suibase/crates/suibase-daemon/src/api/def_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ impl<T: Clone + PartialEq + VersionedEq> Versioned<T> {
self.uuid.clone()
}

// When owner did get_mut_data and made modifications to the data
// directly, it must call this method to increment the version.
pub fn inc_uuid(&mut self) {
self.uuid.increment();
}

// readonly access
pub fn get_data(&self) -> &T {
&self.data
Expand Down
46 changes: 9 additions & 37 deletions rust/suibase/crates/suibase-daemon/src/api/def_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,6 @@ pub struct WorkdirStatusResponse {
// Finer grain status for each process/feature/service.
#[serde(skip_serializing_if = "Option::is_none")]
pub services: Option<Vec<StatusService>>,

// This is the output when the option 'display' is true.
// Will also change the default to false for all the other fields.
#[serde(skip_serializing_if = "Option::is_none")]
pub display: Option<String>,

// This is the output when the option 'debug' is true.
// Will also change the default to true for the other fields.
#[serde(skip_serializing_if = "Option::is_none")]
pub debug: Option<String>,
}

impl WorkdirStatusResponse {
Expand All @@ -207,8 +197,6 @@ impl WorkdirStatusResponse {
network_version: None,
asui_selection: None,
services: None,
display: None,
debug: None,
}
}
}
Expand Down Expand Up @@ -369,7 +357,7 @@ impl Default for MoveConfig {
#[serde_as]
#[derive(Clone, Debug, JsonSchema, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct PackagesConfigResponse {
pub struct WorkdirPackagesResponse {
pub header: Header,

// One entry per distinct Move.toml published.
Expand All @@ -384,38 +372,25 @@ pub struct PackagesConfigResponse {
// Among the move_configs, there is an additional constraint:
// - The MoveConfig.path must all be distinct.
//
#[serde(skip_serializing_if = "Option::is_none")]
pub move_configs: Option<HashMap<String, MoveConfig>>,

// This is the output when the option 'display' is true.
// Will also change the default to false for all the other fields.
#[serde(skip_serializing_if = "Option::is_none")]
pub display: Option<String>,

// This is the output when the option 'debug' is true.
// Will also change the default to true for the other fields.
#[serde(skip_serializing_if = "Option::is_none")]
pub debug: Option<String>,
pub move_configs: HashMap<String, MoveConfig>,
}

impl PackagesConfigResponse {
impl WorkdirPackagesResponse {
pub fn new() -> Self {
Self {
header: Header::default(),
move_configs: None,
display: None,
debug: None,
move_configs: HashMap::new(),
}
}
}

impl Default for PackagesConfigResponse {
impl Default for WorkdirPackagesResponse {
fn default() -> Self {
Self::new()
}
}

impl VersionedEq for PackagesConfigResponse {
impl VersionedEq for WorkdirPackagesResponse {
fn versioned_eq(&self, other: &Self) -> bool {
// Purposely do not include header in the comparison.
self.move_configs == other.move_configs
Expand Down Expand Up @@ -527,16 +502,13 @@ pub trait PackagesApi {
last_ts: Option<String>,
) -> RpcResult<WorkdirSuiEventsResponse>;

#[method(name = "getWorkdirPackagesConfig")]
async fn get_workdir_packages_config(
#[method(name = "getWorkdirPackages")]
async fn get_workdir_packages(
&self,
workdir: String,
data: Option<bool>,
display: Option<bool>,
debug: Option<bool>,
method_uuid: Option<String>,
data_uuid: Option<String>,
) -> RpcResult<PackagesConfigResponse>;
) -> RpcResult<WorkdirPackagesResponse>;

#[method(name = "prePublish")]
async fn pre_publish(
Expand Down
34 changes: 26 additions & 8 deletions rust/suibase/crates/suibase-daemon/src/api/impl_general_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use super::{
};

use super::def_header::Versioned;
use crate::api::WorkdirPackagesResponse;

pub struct GeneralApiImpl {
pub globals: Globals,
Expand Down Expand Up @@ -376,17 +377,17 @@ impl GeneralApiImpl {
// Does costly CLI calls. Use only on initialization, recovery, etc...

// Update the status of workdirs one-by-one until you get one with a known asui_selection!
for workdir_idx in 0..WORKDIRS_KEYS.len() {
for (workdir_idx, workdir_key) in WORKDIRS_KEYS.iter().enumerate() {
let mut api_mutex_guard = self.globals.get_api_mutex(workdir_idx as u8).lock().await;
let api_mutex = &mut *api_mutex_guard;

let last_api_call_timestamp = &mut api_mutex.last_api_call_timestamp;
let last_api_call_timestamp = &mut api_mutex.last_get_workdir_status_time;

// Use the internal implementation
{
let update_result = self
.update_globals_workdir_status(
WORKDIRS_KEYS[workdir_idx].to_string(),
workdir_key.to_string(),
workdir_idx as u8,
last_api_call_timestamp,
)
Expand Down Expand Up @@ -472,22 +473,39 @@ impl GeneralApiServer for GeneralApiImpl {
let mut api_mutex_guard = self.globals.get_api_mutex(workdir_idx).lock().await;
let api_mutex = &mut *api_mutex_guard;

let last_api_call_timestamp = &mut api_mutex.last_api_call_timestamp;
let last_api_call_timestamp = &mut api_mutex.last_get_workdir_status_time;

// Use the internal implementation
// Section for getWorkdirStatus version.
{
// Use the internal implementation
let update_result = self
.update_globals_workdir_status(workdir, workdir_idx, last_api_call_timestamp)
.await;

// Read access to globals for versioning all components.
// If no change, then the version remains the same for that global component.
if let Ok(results) = update_result {
resp.versions.push(results.0);
let mut status_resp = results.0;
status_resp.key = None; // No need to repeat the key here (already in the getVersions header).
resp.versions.push(status_resp);
resp.asui_selection = results.1;
}
}

// Section for getWorkdirPackages version.
{
// Get the data from the globals.get_packages
let globals_read_guard = self.globals.get_packages(workdir_idx).read().await;
let globals = &*globals_read_guard;
if let Some(ui) = &globals.ui {
// Create an header that has the same UUID as the globals.
let mut wp_resp = WorkdirPackagesResponse::new();
wp_resp.header.method = "getWorkdirPackages".to_string();
wp_resp.header.set_from_uuids(ui.get_uuid());
resp.versions.push(wp_resp.header);
}
}

// Initialize the uuids in the response header.
// Use api_mutex.last_responses to detect if this response is equivalent to the previous one.
// If not, increment the uuid_data.
Expand Down Expand Up @@ -529,7 +547,7 @@ impl GeneralApiServer for GeneralApiImpl {
let mut api_mutex_guard = self.globals.get_api_mutex(workdir_idx).lock().await;
let api_mutex = &mut *api_mutex_guard;

let last_api_call_timestamp = &mut api_mutex.last_api_call_timestamp;
let last_api_call_timestamp = &mut api_mutex.last_get_workdir_status_time;

// Use the internal implementation (same logic as done with get_versions).

Expand Down Expand Up @@ -568,7 +586,7 @@ impl GeneralApiServer for GeneralApiImpl {
}
}
let mut resp = ui.get_data().clone();
resp.header.set_from_uuids(&ui.get_uuid());
resp.header.set_from_uuids(ui.get_uuid());
return Ok(resp);
} else {
return Err(
Expand Down
Loading

0 comments on commit 396c7b9

Please sign in to comment.