Skip to content

Commit 998f0f4

Browse files
Merge pull request #390 from code0-tech/#379-send-all-available-modules
send all available modules
2 parents fb3d332 + de3545a commit 998f0f4

6 files changed

Lines changed: 65 additions & 12 deletions

File tree

Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ opentelemetry = { version = "0.32.0", features = ["metrics"] }
1111
tracing = { version = "0.1.41", features = ["log"] }
1212
prost = "0.14.1"
1313
tonic = "0.14.1"
14-
tucana = { version = "0.0.75", features = ["all"] }
15-
code0-flow = { version = "0.0.40", features = ["flow_config", "flow_health", "flow_telemetry"] }
14+
tucana = { version = "0.0.76", features = ["all"] }
15+
code0-flow = { version = "0.0.41", features = ["flow_config", "flow_health", "flow_telemetry"] }
1616
serde_json = "1.0.140"
1717
async-nats = "0.49.0"
1818
tonic-health = "0.14.1"

service.configuration.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"runtimes": [
44
{
55
"identifier": "taurus",
6-
"token": "HsCEzbCuaUtUGSCrvwsSbJSlS2HH6TrW0ZeEKUZGTiOH8vPEZxyAEOx974Ku72l4"
6+
"token": "HsCEzbCuaUtUGSCrvwsSbJSlS2HH6TrW0ZeEKUZGTiOH8vPEZxyAEOx974Ku72l4",
7+
"resolved_modules": ["taurus-boolean", "taurus-control", "taurus-http", "taurus-list", "taurus-number", "taurus-object", "taurus-text"]
78
},
89
{
910
"identifier": "draco-rest",

src/configuration/service.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ pub struct ActionServiceConfiguration {
4343
pub struct RuntimeServiceConfiguration {
4444
token: String,
4545
identifier: String,
46+
#[serde(default)]
47+
resolved_modules: Vec<String>,
4648
}
4749

4850
#[derive(Serialize, Deserialize, Clone, Default)]
@@ -144,6 +146,24 @@ impl ServiceConfiguration {
144146
}
145147
}
146148

149+
pub fn collect_modules(&self) -> Vec<String> {
150+
let actions: Vec<String> = self
151+
.actions
152+
.iter()
153+
.map(|x| format!("action.{}", x.service_name))
154+
.collect();
155+
let runtime: Vec<String> = self
156+
.runtimes
157+
.iter()
158+
.flat_map(|x| match x.resolved_modules.is_empty() {
159+
true => vec![x.identifier.clone()],
160+
false => x.resolved_modules.clone(),
161+
})
162+
.collect();
163+
164+
vec![actions, runtime].concat()
165+
}
166+
147167
pub fn from_path(path: impl AsRef<Path>) -> Self {
148168
let mut data = String::new();
149169

@@ -203,14 +223,20 @@ mod tests {
203223
RuntimeServiceConfiguration {
204224
token: String::from("taurus-token"),
205225
identifier: String::from("taurus"),
226+
resolved_modules: vec![
227+
String::from("taurus-boolean"),
228+
String::from("taurus-number"),
229+
],
206230
},
207231
RuntimeServiceConfiguration {
208232
token: String::from("draco-rest-token"),
209233
identifier: String::from("draco-rest"),
234+
resolved_modules: vec![],
210235
},
211236
RuntimeServiceConfiguration {
212237
token: String::from("draco-cron-token"),
213238
identifier: String::from("draco-cron"),
239+
resolved_modules: vec![],
214240
},
215241
],
216242
}
@@ -278,6 +304,22 @@ mod tests {
278304
assert!(!config.has_service(&String::from("action-token"), &String::from("taurus-x")));
279305
}
280306

307+
#[test]
308+
fn collect_modules_uses_definition_source_identifiers() {
309+
let config = fixture();
310+
311+
assert_eq!(
312+
config.collect_modules(),
313+
vec![
314+
String::from("action.action-identifier"),
315+
String::from("taurus-boolean"),
316+
String::from("taurus-number"),
317+
String::from("draco-rest"),
318+
String::from("draco-cron"),
319+
]
320+
);
321+
}
322+
281323
#[test]
282324
fn get_action_configuration_requires_matching_token_and_identifier() {
283325
let config: ServiceConfiguration = SerializableServiceConfiguration {

src/sagittarius/module_service_client_impl.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
1+
use crate::configuration::service::ServiceConfiguration;
12
use crate::{authorization::authorization::get_authorization_metadata, telemetry::errors};
23
use std::time::Duration;
34
use tonic::transport::Channel;
45
use tonic::{Extensions, Request};
56

67
pub struct SagittariusModuleServiceClient {
8+
service: ServiceConfiguration,
79
client: tucana::sagittarius::module_service_client::ModuleServiceClient<Channel>,
810
token: String,
911
unary_rpc_timeout: Duration,
1012
}
1113

1214
impl SagittariusModuleServiceClient {
13-
pub fn new(channel: Channel, token: String, unary_rpc_timeout: Duration) -> Self {
15+
pub fn new(
16+
channel: Channel,
17+
token: String,
18+
unary_rpc_timeout: Duration,
19+
service_configuration: ServiceConfiguration,
20+
) -> Self {
1421
let client = tucana::sagittarius::module_service_client::ModuleServiceClient::new(channel);
1522

1623
Self {
1724
client,
1825
token,
1926
unary_rpc_timeout,
27+
service: service_configuration,
2028
}
2129
}
2230

@@ -40,6 +48,7 @@ impl SagittariusModuleServiceClient {
4048
Extensions::new(),
4149
tucana::sagittarius::ModuleUpdateRequest {
4250
modules: modules_update_request.modules,
51+
available_defintition_soruces: self.service.collect_modules(),
4352
},
4453
);
4554
request.set_timeout(self.unary_rpc_timeout);

src/server/dynamic_server.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ impl AquilaDynamicServer {
9393
self.channel.clone(),
9494
self.token.clone(),
9595
self.sagittarius_unary_rpc_timeout,
96+
self.service_configuration.clone(),
9697
)));
9798

9899
info!("ModuleService started");

0 commit comments

Comments
 (0)