@@ -2,13 +2,13 @@ package processes
22
33import (
44 "fmt"
5+ "path/filepath"
6+ "strings"
57
68 log "github.com/sirupsen/logrus"
79 "github.com/spf13/afero"
810
911 // "github.com/unity-sds/unity-cs-manager/marketplace"
10- "path/filepath"
11- "strings"
1212
1313 "github.com/unity-sds/unity-management-console/backend/internal/application"
1414 "github.com/unity-sds/unity-management-console/backend/internal/application/config"
@@ -86,43 +86,21 @@ func BootstrapEnv(appconf *config.AppConfig) error {
8686 // log.WithError(err).Error("Problem updating ssm config")
8787 //}
8888
89- log .Infof ("Setting Up HTTPD Gateway from Marketplace" )
90- err = installGateway (store , appconf )
89+ log .Infof ("Setting Up HTTPD Gateway and API Gateway from Marketplace in parallel " )
90+ err = installGatewayAndApiGateway (store , appconf )
9191 if err != nil {
92- log .WithError (err ).Error ("Error installing HTTPD Gateway " )
92+ log .WithError (err ).Error ("Error installing Gateways " )
9393 err = store .AddToAudit (application .Bootstrap_Unsuccessful , "test" )
9494 if err != nil {
9595 log .WithError (err ).Error ("Problem writing to auditlog" )
9696 }
9797 return err
9898 }
9999
100- log .Infof ("Setting Up Health Status Lambda" )
101- err = installHealthStatusLambda (store , appconf )
100+ log .Infof ("Setting Up Health Status Lambda and Unity UI from Marketplace in parallel " )
101+ err = installHealthStatusLambdaAndUnityUi (store , appconf )
102102 if err != nil {
103- log .WithError (err ).Error ("Error installing Health Status" )
104- err = store .AddToAudit (application .Bootstrap_Unsuccessful , "test" )
105- if err != nil {
106- log .WithError (err ).Error ("Problem writing to auditlog" )
107- }
108- return err
109- }
110-
111- log .Infof ("Setting Up Basic API Gateway from Marketplace" )
112- err = installBasicAPIGateway (store , appconf )
113- if err != nil {
114- log .WithError (err ).Error ("Error installing API Gateway" )
115- err = store .AddToAudit (application .Bootstrap_Unsuccessful , "test" )
116- if err != nil {
117- log .WithError (err ).Error ("Problem writing to auditlog" )
118- }
119- return err
120- }
121-
122- log .Infof ("Setting Up Unity UI from Marketplace" )
123- err = installUnityUi (store , appconf )
124- if err != nil {
125- log .WithError (err ).Error ("Error installing unity-portal" )
103+ log .WithError (err ).Error ("Error installing Health Status Lambda and Unity UI" )
126104 err = store .AddToAudit (application .Bootstrap_Unsuccessful , "test" )
127105 if err != nil {
128106 log .WithError (err ).Error ("Problem writing to auditlog" )
@@ -184,13 +162,14 @@ required_providers {
184162 }
185163 }
186164 backend "s3" {
187- dynamodb_table = "%s-%s-terraform-state"
165+ use_lockfile = true
188166 }
189167}
190168
191169provider "aws" {
192170 region = "us-west-2"
193- }` , appConfig .Project , appConfig .Venue )
171+ }
172+ ` )
194173
195174 err := fs .MkdirAll (filepath .Join (appConfig .Workdir , "workspace" ), 0755 )
196175 if err != nil {
@@ -233,89 +212,110 @@ func storeDefaultSSMParameters(appConfig *config.AppConfig, store database.Datas
233212 return nil
234213}
235214
236- func installGateway (store database.Datastore , appConfig * config.AppConfig ) error {
215+ func installGatewayAndApiGateway (store database.Datastore , appConfig * config.AppConfig ) error {
237216 // Find the marketplace item for unity-proxy
238- var name , version string
217+ var proxyName , proxyVersion string
239218 for _ , item := range appConfig .MarketplaceItems {
240219 if item .Name == "unity-proxy" {
241- name = item .Name
242- version = item .Version
220+ proxyName = item .Name
221+ proxyVersion = item .Version
243222 break
244223 }
245224 }
246-
247- // Print the name and version
248- log .Infof ("Found marketplace item - Name: %s, Version: %s" , name , version )
249-
250- // If the item wasn't found, log an error and return
251- if name == "" || version == "" {
225+ if proxyName == "" || proxyVersion == "" {
252226 log .Error ("unity-proxy not found in MarketplaceItems" )
253227 return fmt .Errorf ("unity-proxy not found in MarketplaceItems" )
254228 }
255-
256- simplevars := make (map [string ]string )
257- simplevars ["mgmt_dns" ] = appConfig .ConsoleHost
258- // variables := marketplace.Install_Variables{Values: simplevars}
259- // applications := marketplace.Install_Applications{
260- // Name: name,
261- // Version: version,
262- // Variables: &variables,
263- // Displayname: fmt.Sprintf("%s-%s", appConfig.InstallPrefix, name),
264- // }
265- // install := marketplace.Install{
266- // Applications: &applications,
267- // DeploymentName: "Core Mgmt Gateway",
268- // }
269-
270- installParams := types.ApplicationInstallParams {
271- Name : name ,
272- Version : version ,
273- Variables : simplevars ,
274- DisplayName : "Unity Health Status Lambda" ,
275- DeploymentName : fmt .Sprintf ("default-%s" , name ),
276- }
277- err := TriggerInstall (store , & installParams , appConfig , true )
278- if err != nil {
279- log .WithError (err ).Error ("Issue installing Mgmt Gateway" )
280- return err
281- }
282- return nil
283- }
284-
285- func installBasicAPIGateway (store database.Datastore , appConfig * config.AppConfig ) error {
229+
286230 // Find the marketplace item for unity-apigateway
287- var name , version string
231+ var apiName , apiVersion string
288232 for _ , item := range appConfig .MarketplaceItems {
289233 if item .Name == "unity-apigateway" {
290- name = item .Name
291- version = item .Version
234+ apiName = item .Name
235+ apiVersion = item .Version
292236 break
293237 }
294238 }
295-
296- // Print the name and version
297- log .Infof ("Found marketplace item - Name: %s, Version: %s" , name , version )
298-
299- // If the item wasn't found, log an error and return
300- if name == "" || version == "" {
239+ if apiName == "" || apiVersion == "" {
301240 log .Error ("unity-apigateway not found in MarketplaceItems" )
302241 return fmt .Errorf ("unity-apigateway not found in MarketplaceItems" )
303242 }
304-
305- installParams := types.ApplicationInstallParams {
306- Name : name ,
307- Version : version ,
308- Variables : nil ,
309- DisplayName : "Core API Gateway" ,
310- DeploymentName : fmt .Sprintf ("default-%s" , name ),
243+
244+ // Set up variables for unity-proxy
245+ proxyVars := make (map [string ]string )
246+ proxyVars ["mgmt_dns" ] = appConfig .ConsoleHost
247+
248+ // Create installation parameters for both applications
249+ params := []* types.ApplicationInstallParams {
250+ {
251+ Name : proxyName ,
252+ Version : proxyVersion ,
253+ Variables : proxyVars ,
254+ DisplayName : "Core Mgmt Gateway" ,
255+ DeploymentName : fmt .Sprintf ("default-%s" , proxyName ),
256+ },
257+ {
258+ Name : apiName ,
259+ Version : apiVersion ,
260+ Variables : nil ,
261+ DisplayName : "Core API Gateway" ,
262+ DeploymentName : fmt .Sprintf ("default-%s" , apiName ),
263+ },
311264 }
265+
266+ // Install both applications in a single batch operation
267+ return BatchTriggerInstall (store , params , appConfig )
268+ }
312269
313- err := TriggerInstall (store , & installParams , appConfig , true )
314- if err != nil {
315- log .WithError (err ).Error ("Issue installing API Gateway" )
316- return err
270+ func installHealthStatusLambdaAndUnityUi (store database.Datastore , appConfig * config.AppConfig ) error {
271+ // Find the marketplace item for health status lambda
272+ var lambdaName , lambdaVersion string
273+ for _ , item := range appConfig .MarketplaceItems {
274+ if item .Name == "unity-cs-monitoring-lambda" {
275+ lambdaName = item .Name
276+ lambdaVersion = item .Version
277+ break
278+ }
317279 }
318- return nil
280+ if lambdaName == "" || lambdaVersion == "" {
281+ log .Error ("unity-cs-monitoring-lambda not found in MarketplaceItems" )
282+ return fmt .Errorf ("unity-cs-monitoring-lambda not found in MarketplaceItems" )
283+ }
284+
285+ // Find the marketplace item for unity-portal
286+ var uiName , uiVersion string
287+ for _ , item := range appConfig .MarketplaceItems {
288+ if item .Name == "unity-portal" {
289+ uiName = item .Name
290+ uiVersion = item .Version
291+ break
292+ }
293+ }
294+ if uiName == "" || uiVersion == "" {
295+ log .Error ("unity-portal not found in MarketplaceItems" )
296+ return fmt .Errorf ("unity-portal not found in MarketplaceItems" )
297+ }
298+
299+ // Create installation parameters for both applications
300+ params := []* types.ApplicationInstallParams {
301+ {
302+ Name : lambdaName ,
303+ Version : lambdaVersion ,
304+ Variables : nil ,
305+ DisplayName : "Unity Health Status Lambda" ,
306+ DeploymentName : fmt .Sprintf ("default-%s" , lambdaName ),
307+ },
308+ {
309+ Name : uiName ,
310+ Version : uiVersion ,
311+ Variables : nil ,
312+ DisplayName : "Unity Navbar UI" ,
313+ DeploymentName : fmt .Sprintf ("default-%s" , uiName ),
314+ },
315+ }
316+
317+ // Install both applications in a single batch operation
318+ return BatchTriggerInstall (store , params , appConfig )
319319}
320320
321321func installUnityCloudEnv (store database.Datastore , appConfig * config.AppConfig ) error {
@@ -396,88 +396,3 @@ func installUnityCloudEnv(store database.Datastore, appConfig *config.AppConfig)
396396 }
397397 return nil
398398}
399-
400- func installHealthStatusLambda (store database.Datastore , appConfig * config.AppConfig ) error {
401-
402- // Find the marketplace item for the health status lambda
403- var name , version string
404- for _ , item := range appConfig .MarketplaceItems {
405- if item .Name == "unity-cs-monitoring-lambda" {
406- name = item .Name
407- version = item .Version
408- break
409- }
410- }
411-
412- // Print the name and version
413- log .Infof ("Found marketplace item - Name: %s, Version: %s" , name , version )
414-
415- // If the item wasn't found, log an error and return
416- if name == "" || version == "" {
417- log .Error ("unity-cs-monitoring-lambda not found in MarketplaceItems" )
418- return fmt .Errorf ("unity-cs-monitoring-lambda not found in MarketplaceItems" )
419- }
420-
421- // applications := marketplace.Install_Applications{
422- // Name: name,
423- // Version: version,
424- // Variables: nil,
425- // Displayname: fmt.Sprintf("%s-%s", appConfig.InstallPrefix, name),
426- // }
427- // install := marketplace.Install{
428- // Applications: &applications,
429- // DeploymentName: "Unity Health Status Lambda",
430- // }
431-
432- installParams := types.ApplicationInstallParams {
433- Name : name ,
434- Version : version ,
435- Variables : nil ,
436- DisplayName : "Unity Health Status Lambda" ,
437- DeploymentName : fmt .Sprintf ("default-%s" , name ),
438- }
439-
440- err := TriggerInstall (store , & installParams , appConfig , true )
441- if err != nil {
442- log .WithError (err ).Error ("Issue installing Unity Health Status Lambda" )
443- return err
444- }
445- return nil
446- }
447-
448- func installUnityUi (store database.Datastore , appConfig * config.AppConfig ) error {
449-
450- // Find the marketplace item for the unity-portal
451- var name , version string
452- for _ , item := range appConfig .MarketplaceItems {
453- if item .Name == "unity-portal" {
454- name = item .Name
455- version = item .Version
456- break
457- }
458- }
459-
460- // Print the name and version
461- log .Infof ("Found marketplace item - Name: %s, Version: %s" , name , version )
462-
463- // If the item wasn't found, log an error and return
464- if name == "" || version == "" {
465- log .Error ("unity-portal not found in MarketplaceItems" )
466- return fmt .Errorf ("unity-portal not found in MarketplaceItems" )
467- }
468-
469- installParams := types.ApplicationInstallParams {
470- Name : name ,
471- Version : version ,
472- Variables : nil ,
473- DisplayName : "Unity Navbar UI" ,
474- DeploymentName : fmt .Sprintf ("default-%s" , name ),
475- }
476-
477- err := TriggerInstall (store , & installParams , appConfig , true )
478- if err != nil {
479- log .WithError (err ).Error ("Issue installing Unity Navbar UI" )
480- return err
481- }
482- return nil
483- }
0 commit comments