Skip to content

Commit 8acb1cc

Browse files
committed
refactor: update app type references from appspecification to app
1 parent 89bb0b9 commit 8acb1cc

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

internal/orchestrator/orchestrator.go

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import (
4444
"github.com/arduino/arduino-app-cli/internal/helpers"
4545
"github.com/arduino/arduino-app-cli/internal/micro"
4646
"github.com/arduino/arduino-app-cli/internal/orchestrator/app"
47-
appspecification "github.com/arduino/arduino-app-cli/internal/orchestrator/app"
4847
appgenerator "github.com/arduino/arduino-app-cli/internal/orchestrator/app/generator"
4948
"github.com/arduino/arduino-app-cli/internal/orchestrator/bricksindex"
5049
"github.com/arduino/arduino-app-cli/internal/orchestrator/config"
@@ -115,15 +114,15 @@ func StartApp(
115114
provisioner *Provision,
116115
modelsIndex *modelsindex.ModelsIndex,
117116
bricksIndex *bricksindex.BricksIndex,
118-
app appspecification.ArduinoApp,
117+
appToStart app.ArduinoApp,
119118
cfg config.Configuration,
120119
staticStore *store.StaticStore,
121120
) iter.Seq[StreamMessage] {
122121
return func(yield func(StreamMessage) bool) {
123122
ctx, cancel := context.WithCancel(ctx)
124123
defer cancel()
125124

126-
err := appspecification.ValidateBricks(app.Descriptor, bricksIndex)
125+
err := app.ValidateBricks(appToStart.Descriptor, bricksIndex)
127126
if err != nil {
128127
yield(StreamMessage{error: err})
129128
return
@@ -138,7 +137,7 @@ func StartApp(
138137
yield(StreamMessage{error: fmt.Errorf("app %q is running", running.Name)})
139138
return
140139
}
141-
if !yield(StreamMessage{data: fmt.Sprintf("Starting app %q", app.Name)}) {
140+
if !yield(StreamMessage{data: fmt.Sprintf("Starting app %q", appToStart.Name)}) {
142141
return
143142
}
144143

@@ -155,11 +154,11 @@ func StartApp(
155154
if !yield(StreamMessage{progress: &Progress{Name: "preparing", Progress: 0.0}}) {
156155
return
157156
}
158-
if app.MainSketchPath != nil {
157+
if appToStart.MainSketchPath != nil {
159158
if !yield(StreamMessage{progress: &Progress{Name: "sketch compiling and uploading", Progress: 0.0}}) {
160159
return
161160
}
162-
if err := compileUploadSketch(ctx, &app, sketchCallbackWriter); err != nil {
161+
if err := compileUploadSketch(ctx, &appToStart, sketchCallbackWriter); err != nil {
163162
yield(StreamMessage{error: err})
164163
return
165164
}
@@ -168,23 +167,23 @@ func StartApp(
168167
}
169168
}
170169

171-
if app.MainPythonFile != nil {
172-
envs := getAppEnvironmentVariables(app, bricksIndex, modelsIndex)
170+
if appToStart.MainPythonFile != nil {
171+
envs := getAppEnvironmentVariables(appToStart, bricksIndex, modelsIndex)
173172

174173
if !yield(StreamMessage{data: "python provisioning"}) {
175174
cancel()
176175
return
177176
}
178177
provisionStartProgress := float32(0.0)
179-
if app.MainSketchPath != nil {
178+
if appToStart.MainSketchPath != nil {
180179
provisionStartProgress = 10.0
181180
}
182181

183182
if !yield(StreamMessage{progress: &Progress{Name: "python provisioning", Progress: provisionStartProgress}}) {
184183
return
185184
}
186185

187-
if err := provisioner.App(ctx, bricksIndex, &app, cfg, envs, staticStore); err != nil {
186+
if err := provisioner.App(ctx, bricksIndex, &appToStart, cfg, envs, staticStore); err != nil {
188187
yield(StreamMessage{error: err})
189188
return
190189
}
@@ -195,10 +194,10 @@ func StartApp(
195194
}
196195

197196
// Launch the docker compose command to start the app
198-
overrideComposeFile := app.AppComposeOverrideFilePath()
197+
overrideComposeFile := appToStart.AppComposeOverrideFilePath()
199198

200199
commands := []string{}
201-
commands = append(commands, "docker", "compose", "-f", app.AppComposeFilePath().String())
200+
commands = append(commands, "docker", "compose", "-f", appToStart.AppComposeFilePath().String())
202201
if ok, _ := overrideComposeFile.ExistCheck(); ok {
203202
commands = append(commands, "-f", overrideComposeFile.String())
204203
}
@@ -256,7 +255,7 @@ func StartApp(
256255
// - model configuration variables (variables defined in the model configuration)
257256
// - brick instance variables (variables defined in the app.yaml for the brick instance)
258257
// In addition, it adds some useful environment variables like APP_HOME and HOST_IP.
259-
func getAppEnvironmentVariables(app appspecification.ArduinoApp, brickIndex *bricksindex.BricksIndex, modelsIndex *modelsindex.ModelsIndex) helpers.EnvVars {
258+
func getAppEnvironmentVariables(app app.ArduinoApp, brickIndex *bricksindex.BricksIndex, modelsIndex *modelsindex.ModelsIndex) helpers.EnvVars {
260259
envs := make(helpers.EnvVars)
261260

262261
for _, brick := range app.Descriptor.Bricks {
@@ -384,7 +383,7 @@ func getVideoDevices() map[int]string {
384383
return deviceMap
385384
}
386385

387-
func stopAppWithCmd(ctx context.Context, app appspecification.ArduinoApp, cmd string) iter.Seq[StreamMessage] {
386+
func stopAppWithCmd(ctx context.Context, app app.ArduinoApp, cmd string) iter.Seq[StreamMessage] {
388387
return func(yield func(StreamMessage) bool) {
389388
ctx, cancel := context.WithCancel(ctx)
390389
defer cancel()
@@ -432,11 +431,11 @@ func stopAppWithCmd(ctx context.Context, app appspecification.ArduinoApp, cmd st
432431
}
433432
}
434433

435-
func StopApp(ctx context.Context, app appspecification.ArduinoApp) iter.Seq[StreamMessage] {
434+
func StopApp(ctx context.Context, app app.ArduinoApp) iter.Seq[StreamMessage] {
436435
return stopAppWithCmd(ctx, app, "stop")
437436
}
438437

439-
func StopAndDestroyApp(ctx context.Context, app appspecification.ArduinoApp) iter.Seq[StreamMessage] {
438+
func StopAndDestroyApp(ctx context.Context, app app.ArduinoApp) iter.Seq[StreamMessage] {
440439
return stopAppWithCmd(ctx, app, "down")
441440
}
442441

@@ -446,15 +445,15 @@ func RestartApp(
446445
provisioner *Provision,
447446
modelsIndex *modelsindex.ModelsIndex,
448447
bricksIndex *bricksindex.BricksIndex,
449-
appToStart appspecification.ArduinoApp,
448+
appToStart app.ArduinoApp,
450449
cfg config.Configuration,
451450
staticStore *store.StaticStore,
452451
) iter.Seq[StreamMessage] {
453452
return func(yield func(StreamMessage) bool) {
454453
ctx, cancel := context.WithCancel(ctx)
455454
defer cancel()
456455

457-
err := appspecification.ValidateBricks(appToStart.Descriptor, bricksIndex)
456+
err := app.ValidateBricks(appToStart.Descriptor, bricksIndex)
458457
if err != nil {
459458
yield(StreamMessage{error: err})
460459
return
@@ -678,7 +677,7 @@ type AppDetailedBrick struct {
678677
func AppDetails(
679678
ctx context.Context,
680679
docker command.Cli,
681-
userApp appspecification.ArduinoApp,
680+
userApp app.ArduinoApp,
682681
bricksIndex *bricksindex.BricksIndex,
683682
idProvider *app.IDProvider,
684683
cfg config.Configuration,
@@ -902,7 +901,7 @@ func CloneApp(
902901
return CloneAppResponse{ID: id}, nil
903902
}
904903

905-
func DeleteApp(ctx context.Context, app appspecification.ArduinoApp) error {
904+
func DeleteApp(ctx context.Context, app app.ArduinoApp) error {
906905
for msg := range StopApp(ctx, app) {
907906
if msg.error != nil {
908907
return fmt.Errorf("failed to stop app: %w", msg.error)
@@ -913,7 +912,7 @@ func DeleteApp(ctx context.Context, app appspecification.ArduinoApp) error {
913912

914913
const defaultAppFileName = "default.app"
915914

916-
func SetDefaultApp(app *appspecification.ArduinoApp, cfg config.Configuration) error {
915+
func SetDefaultApp(app *app.ArduinoApp, cfg config.Configuration) error {
917916
defaultAppPath := cfg.DataDir().Join(defaultAppFileName)
918917

919918
// Remove the default app file if the app is nil.
@@ -928,7 +927,7 @@ func SetDefaultApp(app *appspecification.ArduinoApp, cfg config.Configuration) e
928927
return fatomic.WriteFile(defaultAppPath.String(), []byte(app.FullPath.String()), os.FileMode(0644))
929928
}
930929

931-
func GetDefaultApp(cfg config.Configuration) (*appspecification.ArduinoApp, error) {
930+
func GetDefaultApp(cfg config.Configuration) (*app.ArduinoApp, error) {
932931
defaultAppFilePath := cfg.DataDir().Join(defaultAppFileName)
933932
if !defaultAppFilePath.Exist() {
934933
return nil, nil
@@ -966,7 +965,7 @@ type AppEditRequest struct {
966965

967966
func EditApp(
968967
req AppEditRequest,
969-
editApp *appspecification.ArduinoApp,
968+
editApp *app.ArduinoApp,
970969
cfg config.Configuration,
971970
) (editErr error) {
972971
if req.Default != nil {
@@ -1006,7 +1005,7 @@ func EditApp(
10061005
return nil
10071006
}
10081007

1009-
func editAppDefaults(userApp *appspecification.ArduinoApp, isDefault bool, cfg config.Configuration) error {
1008+
func editAppDefaults(userApp *app.ArduinoApp, isDefault bool, cfg config.Configuration) error {
10101009
if isDefault {
10111010
if err := SetDefaultApp(userApp, cfg); err != nil {
10121011
return fmt.Errorf("failed to set default app: %w", err)
@@ -1135,7 +1134,7 @@ func addLedControl(volumes []volume) []volume {
11351134

11361135
func compileUploadSketch(
11371136
ctx context.Context,
1138-
arduinoApp *appspecification.ArduinoApp,
1137+
arduinoApp *app.ArduinoApp,
11391138
w io.Writer,
11401139
) error {
11411140
logrus.SetLevel(logrus.ErrorLevel) // Reduce the log level of arduino-cli

0 commit comments

Comments
 (0)