11use std:: path:: PathBuf ;
22
3- use crate :: adapters:: { ApplicationConfig , DeploymentMetadata } ;
3+ use crate :: adapters:: backend:: { ApplicationId , WorkspaceId } ;
4+ use crate :: adapters:: {
5+ ApplicationConfig , DeploymentMetadata , IngressBuilder , MonitorBuilder , PlatformBuilder ,
6+ } ;
47use crate :: fs:: { FileSystem , SessionFile } ;
58use crate :: subsystems:: CONTROLLER_SUBSYSTEM_NAME ;
69use crate :: {
710 Cli , ControllerSubsystem , adapters:: BackendClient , artifacts:: LambdaZip , config:: RunSubcommand ,
811} ;
9- use miette:: { IntoDiagnostic , Result } ;
12+ use miette:: Result ;
1013use tokio:: runtime:: Runtime ;
1114use tokio:: time:: Duration ;
1215use tokio_graceful_shutdown:: { IntoSubsystem as _, SubsystemBuilder , Toplevel } ;
@@ -21,8 +24,8 @@ const DEFAULT_SHUTDOWN_TIMEOUT: u64 = 5000;
2124pub struct Run {
2225 _terminal : Terminal ,
2326 artifact_path : PathBuf ,
24- workspace : String ,
25- application : String ,
27+ workspace_name : String ,
28+ application_name : String ,
2629 backend : BackendClient ,
2730}
2831
@@ -37,41 +40,53 @@ impl Run {
3740 _terminal : terminal,
3841 backend,
3942 artifact_path : args. artifact_path ,
40- workspace : args. workspace ,
41- application : args. application ,
43+ workspace_name : args. workspace ,
44+ application_name : args. application ,
4245 } )
4346 }
4447
4548 pub fn dispatch ( self ) -> Result < ( ) > {
49+ dbg ! ( "Executing the `run` command..." ) ;
4650 let rt = Runtime :: new ( ) . unwrap ( ) ;
4751 let _guard = rt. enter ( ) ;
4852 rt. block_on ( async {
49- // • First, we have to load the artifact.
50- // This lets us fail fast in the case where the artifact
51- // doesn't exist or we don't have permission to read the file.
53+ // First, we have to load the artifact.
54+ // This lets us fail fast in the case where the artifact
55+ // doesn't exist or we don't have permission to read the file.
56+ dbg ! ( "Loading the lambda artifact..." ) ;
5257 let artifact = LambdaZip :: load ( & self . artifact_path ) . await ?;
53- // • Now, we have to load the application's configuration
54- // from the backend. We have the name of the workspace and
55- // application, but we need to look up the details.
56- let conf = self
58+ // We need to convert our workspace and application names into the full workspace and application object
59+ dbg ! ( "Loading workspace and application..." ) ;
60+ let workspace = self
61+ . backend
62+ . get_workspace_by_name ( & self . workspace_name )
63+ . await ?;
64+ let application = self
5765 . backend
58- . fetch_config ( & self . workspace , & self . application , artifact )
66+ . get_application_by_name ( workspace. id , & self . application_name )
5967 . await ?;
60- let ApplicationConfig {
61- ingress,
62- platform,
63- monitor,
64- } = conf;
68+ // Now, we have to load the application's configuration
69+ // from the backend. We have the name of the workspace and
70+ // application, but we need to look up the details.
71+ dbg ! ( "Loading application conf..." ) ;
72+ let conf = ApplicationConfig {
73+ platform : PlatformBuilder :: new ( * application. platform , artifact)
74+ . build ( )
75+ . await ,
76+ ingress : IngressBuilder :: new ( * application. ingress ) . build ( ) . await ,
77+ monitor : MonitorBuilder :: new ( * application. monitor ) . build ( ) . await ,
78+ } ;
6579
6680 // Create a new deployment.
67- let metadata = self . create_deployment ( ) . await ?;
81+ let metadata = self . create_deployment ( workspace . id , application . id ) . await ?;
6882
6983 // Build the ControllerSubsystem using the boxed objects.
84+ dbg ! ( "Building controller..." ) ;
7085 let controller = ControllerSubsystem :: builder ( )
7186 . backend ( self . backend )
72- . monitor ( monitor)
73- . ingress ( ingress)
74- . platform ( platform)
87+ . monitor ( conf . monitor )
88+ . ingress ( conf . ingress )
89+ . platform ( conf . platform )
7590 . meta ( metadata)
7691 . build ( ) ;
7792
@@ -90,21 +105,21 @@ impl Run {
90105 } )
91106 }
92107
93- async fn create_deployment ( & self ) -> Result < DeploymentMetadata > {
94- // TODO: This `.parse().into_diagnostic()?` code is awful. Once
95- // we settle on the type of WorkspaceId and ApplicationId,
96- // we can clean it up instead of using the raw types.
108+ async fn create_deployment (
109+ & self ,
110+ workspace_id : WorkspaceId ,
111+ application_id : ApplicationId ,
112+ ) -> Result < DeploymentMetadata > {
113+ dbg ! ( "Creating new deployment..." ) ;
97114 let deployment_id = self
98115 . backend
99- . new_deployment (
100- self . workspace . parse ( ) . into_diagnostic ( ) ?,
101- self . application . parse ( ) . into_diagnostic ( ) ?,
102- )
116+ . new_deployment ( workspace_id, application_id)
103117 . await ?;
104118
119+ dbg ! ( "Creating new deployment metadata..." ) ;
105120 let meta = DeploymentMetadata :: builder ( )
106- . workspace_id ( self . workspace . parse ( ) . into_diagnostic ( ) ? )
107- . application_id ( self . application . parse ( ) . into_diagnostic ( ) ? )
121+ . workspace_id ( workspace_id )
122+ . application_id ( application_id )
108123 . deployment_id ( deployment_id)
109124 . build ( ) ;
110125 Ok ( meta)
0 commit comments