11use crate :: core:: component:: TEdgeComponent ;
22use crate :: core:: mapper:: start_basic_actors;
33use crate :: core:: mqtt:: configure_proxy;
4+ use crate :: core:: mqtt:: flows_status_topic;
45use anyhow:: Context ;
56use async_trait:: async_trait;
6- use aws_mapper_ext:: converter:: AwsConverter ;
7- use clock:: WallClock ;
8- use mqtt_channel:: TopicFilter ;
9- use tedge_actors:: ConvertingActor ;
10- use tedge_actors:: MessageSink ;
11- use tedge_actors:: MessageSource ;
12- use tedge_actors:: NoConfig ;
7+ use aws_mapper_ext:: AwsConverter ;
8+ use tedge_api:: mqtt_topics:: EntityTopicId ;
139use tedge_api:: mqtt_topics:: MqttSchema ;
1410use tedge_api:: service_health_topic;
1511use tedge_config:: models:: TopicPrefix ;
16- use tedge_config:: tedge_toml:: mapper_config:: AwsMapperConfig ;
1712use tedge_config:: tedge_toml:: mapper_config:: AwsMapperSpecificConfig ;
1813use tedge_config:: tedge_toml:: ProfileName ;
1914use tedge_config:: TEdgeConfig ;
15+ use tedge_file_system_ext:: FsWatchActorBuilder ;
16+ use tedge_flows:: FlowsMapperBuilder ;
2017use tedge_mqtt_bridge:: rumqttc:: Transport ;
2118use tedge_mqtt_bridge:: BridgeConfig ;
2219use tedge_mqtt_bridge:: MqttBridgeActorBuilder ;
20+ use tedge_watch_ext:: WatchActorBuilder ;
2321use tracing:: warn;
2422use yansi:: Paint ;
2523
@@ -32,15 +30,16 @@ impl TEdgeComponent for AwsMapper {
3230 async fn start (
3331 & self ,
3432 tedge_config : TEdgeConfig ,
35- _config_dir : & tedge_config:: Path ,
33+ config_dir : & tedge_config:: Path ,
3634 ) -> Result < ( ) , anyhow:: Error > {
3735 let aws_config = tedge_config. mapper_config :: < AwsMapperSpecificConfig > ( & self . profile ) ?;
3836 let prefix = & aws_config. bridge . topic_prefix ;
3937 let aws_mapper_name = format ! ( "tedge-mapper-{prefix}" ) ;
4038 let ( mut runtime, mut mqtt_actor) =
4139 start_basic_actors ( & aws_mapper_name, & tedge_config) . await ?;
42-
4340 let mqtt_schema = MqttSchema :: with_root ( tedge_config. mqtt . topic_root . clone ( ) ) ;
41+ let service_topic_id = EntityTopicId :: default_main_service ( & aws_mapper_name) ?;
42+
4443 if tedge_config. mqtt . bridge . built_in {
4544 let device_id = aws_config. device . id ( ) ?;
4645 let device_topic_id = tedge_config. mqtt . device_topic_id . clone ( ) ;
@@ -78,37 +77,36 @@ impl TEdgeComponent for AwsMapper {
7877 } else if tedge_config. proxy . address . or_none ( ) . is_some ( ) {
7978 warn ! ( "`proxy.address` is configured without the built-in bridge enabled. The bridge MQTT connection to the cloud will {} communicate via the configured proxy." , "not" . bold( ) )
8079 }
81- let clock = Box :: new ( WallClock ) ;
8280 let aws_converter = AwsConverter :: new (
8381 aws_config. cloud_specific . mapper . timestamp ,
84- clock,
85- mqtt_schema,
82+ & mqtt_schema,
8683 aws_config. cloud_specific . mapper . timestamp_format ,
8784 prefix. value ( ) . clone ( ) ,
8885 aws_config. mapper . mqtt . max_payload_size . 0 ,
86+ aws_config. topics . to_string ( ) ,
8987 ) ;
90- let mut aws_converting_actor = ConvertingActor :: builder ( "AwsConverter" , aws_converter) ;
91-
92- aws_converting_actor. connect_source ( get_topic_filter ( & aws_config) , & mut mqtt_actor) ;
93- aws_converting_actor. connect_sink ( NoConfig , & mqtt_actor) ;
94-
95- runtime. spawn ( aws_converting_actor) . await ?;
88+ let flows_dir =
89+ tedge_flows:: flows_dir ( config_dir, "aws" , self . profile . as_ref ( ) . map ( |p| p. as_ref ( ) ) ) ;
90+ let flows = aws_converter. flow_registry ( flows_dir) . await ?;
91+ let flows_status = flows_status_topic ( & mqtt_schema, & service_topic_id) ;
92+
93+ let mut fs_actor = FsWatchActorBuilder :: new ( ) ;
94+ let mut cmd_watcher_actor = WatchActorBuilder :: new ( ) ;
95+
96+ let mut flows_mapper = FlowsMapperBuilder :: try_new ( flows, flows_status) . await ?;
97+ flows_mapper. connect ( & mut mqtt_actor) ;
98+ flows_mapper. connect_fs ( & mut fs_actor) ;
99+ flows_mapper. connect_cmd ( & mut cmd_watcher_actor) ;
100+
101+ runtime. spawn ( flows_mapper) . await ?;
102+ runtime. spawn ( fs_actor) . await ?;
103+ runtime. spawn ( cmd_watcher_actor) . await ?;
96104 runtime. spawn ( mqtt_actor) . await ?;
97105 runtime. run_to_completion ( ) . await ?;
98106 Ok ( ( ) )
99107 }
100108}
101109
102- fn get_topic_filter ( aws_config : & AwsMapperConfig ) -> TopicFilter {
103- let mut topics = TopicFilter :: empty ( ) ;
104- for topic in aws_config. topics . 0 . clone ( ) {
105- if topics. try_add ( & topic) . is_err ( ) {
106- warn ! ( "The configured topic '{topic}' is invalid and ignored." ) ;
107- }
108- }
109- topics
110- }
111-
112110fn built_in_bridge_rules (
113111 remote_client_id : & str ,
114112 topic_prefix : & TopicPrefix ,
0 commit comments