Skip to content

Commit 25d90c6

Browse files
committed
revert
1 parent c9deb5f commit 25d90c6

File tree

11 files changed

+56
-65
lines changed

11 files changed

+56
-65
lines changed

cmd/arduino-app-cli/app/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (r appListResult) String() string {
8383
cmdutil.IDToAlias(app.ID),
8484
app.Name,
8585
app.Icon,
86-
app.State,
86+
app.Status,
8787
app.Example,
8888
})
8989
}

cmd/arduino-app-cli/app/start.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ func newStartCmd(cfg config.Configuration) *cobra.Command {
4747
return startHandler(cmd.Context(), cfg, app)
4848
},
4949
ValidArgsFunction: completion.ApplicationNamesWithFilterFunc(cfg, func(apps orchestrator.AppInfo) bool {
50-
return apps.State != orchestrator.StatusStarting &&
51-
apps.State != orchestrator.StatusRunning
50+
return apps.Status != orchestrator.StatusStarting &&
51+
apps.Status != orchestrator.StatusRunning
5252
}),
5353
}
5454
}

cmd/arduino-app-cli/app/stop.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ func newStopCmd(cfg config.Configuration) *cobra.Command {
4545
return stopHandler(cmd.Context(), app)
4646
},
4747
ValidArgsFunction: completion.ApplicationNamesWithFilterFunc(cfg, func(apps orchestrator.AppInfo) bool {
48-
return apps.State == orchestrator.StatusStarting ||
49-
apps.State == orchestrator.StatusRunning
48+
return apps.Status == orchestrator.StatusStarting ||
49+
apps.Status == orchestrator.StatusRunning
5050
}),
5151
}
5252
}

cmd/gendoc/docs.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ func NewOpenApiGenerator(version string) *Generator {
6969
openapi3.SchemaOrRef{
7070
Schema: &openapi3.Schema{
7171
UniqueItems: f.Ptr(true),
72-
Enum: f.Map(orchestrator.State("").AllowedStates(), func(v orchestrator.State) interface{} { return v }),
72+
Enum: f.Map(orchestrator.Status("").AllowedStatuses(), func(v orchestrator.Status) interface{} { return v }),
7373
Type: f.Ptr(openapi3.SchemaTypeString),
7474
Description: f.Ptr("Application status"),
75-
ReflectType: reflect.TypeOf(orchestrator.State("")),
75+
ReflectType: reflect.TypeOf(orchestrator.Status("")),
7676
},
7777
},
7878
)
@@ -205,7 +205,7 @@ func NewOpenApiGenerator(version string) *Generator {
205205
reflector.DefaultOptions = append(reflector.DefaultOptions,
206206
jsonschema.InterceptSchema(func(params jsonschema.InterceptSchemaParams) (stop bool, err error) {
207207

208-
if params.Value.Type() == reflect.TypeOf(orchestrator.State("")) {
208+
if params.Value.Type() == reflect.TypeOf(orchestrator.Status("")) {
209209
params.Schema.WithRef("#/components/schemas/Status")
210210
return true, nil
211211
}
@@ -632,8 +632,8 @@ Contains a JSON object with the details of an error.
632632
Path: "/v1/apps",
633633
Request: (*orchestrator.ListAppRequest)(nil),
634634
Parameters: (*struct {
635-
Filter string `query:"filter" description:"Filters apps by apps,examples,default"`
636-
Status orchestrator.State `query:"status" description:"Filters applications by status"`
635+
Filter string `query:"filter" description:"Filters apps by apps,examples,default"`
636+
Status orchestrator.Status `query:"status" description:"Filters applications by status"`
637637
})(nil),
638638
CustomSuccessResponse: &CustomResponseDef{
639639
ContentType: "application/json",

internal/api/handlers/app_list.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,21 @@ func HandleAppList(
5151
showApps = slices.Contains(filters, "apps")
5252
}
5353

54-
var stateFilter orchestrator.State
54+
var statusFilter orchestrator.Status
5555
if status := queryParams.Get("status"); status != "" {
56-
status, err := orchestrator.ParseStates(status)
56+
status, err := orchestrator.ParseStatus(status)
5757
if err != nil {
5858
render.EncodeResponse(w, http.StatusBadRequest, models.ErrorResponse{Details: "invalid status filter"})
5959
return
6060
}
61-
stateFilter = status
61+
statusFilter = status
6262
}
6363

6464
res, err := orchestrator.ListApps(r.Context(), dockerCli, orchestrator.ListAppRequest{
6565
ShowApps: showApps,
6666
ShowExamples: showExamples,
6767
ShowOnlyDefault: showOnlyDefault,
68-
StateFilter: stateFilter,
68+
StatusFilter: statusFilter,
6969
}, idProvider, cfg)
7070
if err != nil {
7171
slog.Error("Unable to parse the app.yaml", slog.String("error", err.Error()))

internal/api/handlers/app_status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func HandlerAppStatus(
4747
sseStream.SendError(render.SSEErrorData{Code: render.InternalServiceErr, Message: err.Error()})
4848
}
4949
for _, app := range result.Apps {
50-
if app.State != "" {
50+
if app.Status != "" {
5151
sseStream.Send(render.SSEEvent{Type: "app", Data: app})
5252
}
5353
}

internal/orchestrator/app_status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func parseDockerStatusEvent(ctx context.Context, cfg config.Configuration, docke
115115
Name: app.Descriptor.Name,
116116
Description: app.Descriptor.Description,
117117
Icon: app.Descriptor.Icon,
118-
State: appStatus.State,
118+
Status: appStatus.Status,
119119
Example: id.IsExample(),
120120
Default: isDefault,
121121
}, nil

internal/orchestrator/helpers_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestParseAppStatus(t *testing.T) {
2727
tests := []struct {
2828
name string
2929
containerState []container.ContainerState
30-
want State
30+
want Status
3131
}{
3232
{
3333
name: "everything running",
@@ -46,7 +46,7 @@ func TestParseAppStatus(t *testing.T) {
4646
},
4747
{
4848
name: "failed container takes precedence over stopping and starting",
49-
containerState: []container.ContainerState{container.StateRunning, container.StateDead, container.StateRemoving, container.StateRestarting, container.StateExited},
49+
containerState: []container.ContainerState{container.StateRunning, container.StateDead, container.StateRemoving, container.StateRestarting},
5050
want: StatusFailed,
5151
},
5252
{
@@ -61,7 +61,7 @@ func TestParseAppStatus(t *testing.T) {
6161
},
6262
{
6363
name: "starting",
64-
containerState: []container.ContainerState{container.StateRestarting},
64+
containerState: []container.ContainerState{container.StateRestarting, container.StateExited},
6565
want: StatusStarting,
6666
},
6767
}
@@ -76,7 +76,7 @@ func TestParseAppStatus(t *testing.T) {
7676
})
7777
res := parseAppStatus(input)
7878
require.Len(t, res, 1)
79-
require.Equal(t, tc.want, res[0].State)
79+
require.Equal(t, tc.want, res[0].Status)
8080
require.Equal(t, "path1", res[0].AppPath.String())
8181
})
8282
}

internal/orchestrator/orchestrator.go

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -389,16 +389,6 @@ func stopAppWithCmd(ctx context.Context, docker command.Cli, app app.ArduinoApp,
389389
ctx, cancel := context.WithCancel(ctx)
390390
defer cancel()
391391

392-
appStatus, err := getAppStatus(ctx, docker, app)
393-
if err != nil {
394-
yield(StreamMessage{error: err})
395-
return
396-
}
397-
if appStatus.State != StatusStarting && appStatus.State != StatusRunning {
398-
yield(StreamMessage{data: fmt.Sprintf("app %q is not running", app.Name)})
399-
return
400-
}
401-
402392
if !yield(StreamMessage{data: fmt.Sprintf("Stopping app %q", app.Name)}) {
403393
return
404394
}
@@ -420,7 +410,7 @@ func stopAppWithCmd(ctx context.Context, docker command.Cli, app app.ArduinoApp,
420410
yield(StreamMessage{error: err})
421411
return
422412
}
423-
if appStatus.State != StatusStarting && appStatus.State != StatusRunning {
413+
if appStatus.Status != StatusStarting && appStatus.Status != StatusRunning {
424414
yield(StreamMessage{data: fmt.Sprintf("app %q is not running", app.Name)})
425415
return
426416
}
@@ -523,7 +513,7 @@ func StartDefaultApp(
523513
if err != nil {
524514
return fmt.Errorf("failed to get app details: %w", err)
525515
}
526-
if status.State == "running" {
516+
if status.Status == "running" {
527517
return nil
528518
}
529519

@@ -547,7 +537,7 @@ type AppInfo struct {
547537
Name string `json:"name"`
548538
Description string `json:"description"`
549539
Icon string `json:"icon"`
550-
State State `json:"state,omitempty"`
540+
Status Status `json:"status,omitempty"`
551541
Example bool `json:"example"`
552542
Default bool `json:"default"`
553543
}
@@ -561,7 +551,8 @@ type ListAppRequest struct {
561551
ShowExamples bool
562552
ShowOnlyDefault bool
563553
ShowApps bool
564-
StateFilter State
554+
StatusFilter Status
555+
565556
// IncludeNonStandardLocationApps will include apps that are not in the standard apps directory.
566557
// We will search by looking for docker container metadata, and add the app not present in the
567558
// standard apps directory in the result list.
@@ -637,14 +628,14 @@ func ListApps(
637628
continue
638629
}
639630

640-
var state State
631+
var status Status
641632
if idx := slices.IndexFunc(apps, func(a AppStatusInfo) bool {
642633
return a.AppPath.EqualsTo(app.FullPath)
643634
}); idx != -1 {
644-
state = apps[idx].State
635+
status = apps[idx].Status
645636
}
646637

647-
if req.StateFilter != "" && req.StateFilter != state {
638+
if req.StatusFilter != "" && req.StatusFilter != status {
648639
continue
649640
}
650641

@@ -659,7 +650,7 @@ func ListApps(
659650
Name: app.Name,
660651
Description: app.Descriptor.Description,
661652
Icon: app.Descriptor.Icon,
662-
State: state,
653+
Status: status,
663654
Example: id.IsExample(),
664655
Default: isDefault,
665656
},
@@ -675,7 +666,7 @@ type AppDetailedInfo struct {
675666
Path string `json:"path"`
676667
Description string `json:"description"`
677668
Icon string `json:"icon"`
678-
State State `json:"state" required:"true"`
669+
Status Status `json:"status" required:"true"`
679670
Example bool `json:"example"`
680671
Default bool `json:"default"`
681672
Bricks []AppDetailedBrick `json:"bricks,omitempty"`
@@ -699,15 +690,15 @@ func AppDetails(
699690
var wg sync.WaitGroup
700691
wg.Add(2)
701692
var defaultAppPath string
702-
var state State
693+
var status Status
703694
go func() {
704695
defer wg.Done()
705696
app, err := getAppStatus(ctx, docker, userApp)
706697
if err != nil {
707698
slog.Warn("unable to get app status", slog.String("error", err.Error()), slog.String("path", userApp.FullPath.String()))
708-
state = StatusStopped
699+
status = StatusStopped
709700
} else {
710-
state = app.State
701+
status = app.Status
711702
}
712703
}()
713704
go func() {
@@ -736,7 +727,7 @@ func AppDetails(
736727
Path: userApp.FullPath.String(),
737728
Description: userApp.Descriptor.Description,
738729
Icon: userApp.Descriptor.Icon,
739-
State: state,
730+
Status: status,
740731
Example: id.IsExample(),
741732
Default: defaultAppPath == userApp.FullPath.String(),
742733
Bricks: f.Map(userApp.Descriptor.Bricks, func(b app.Brick) AppDetailedBrick {

internal/orchestrator/orchestrator_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func TestListApp(t *testing.T) {
266266
res, err := ListApps(t.Context(), dockerCli, ListAppRequest{
267267
ShowApps: true,
268268
ShowExamples: true,
269-
StateFilter: "",
269+
StatusFilter: "",
270270
}, idProvider, cfg)
271271
require.NoError(t, err)
272272
assert.Empty(t, res.BrokenApps)
@@ -276,7 +276,7 @@ func TestListApp(t *testing.T) {
276276
Name: "example1",
277277
Description: "",
278278
Icon: "😃",
279-
State: "",
279+
Status: "",
280280
Example: true,
281281
Default: false,
282282
},
@@ -285,7 +285,7 @@ func TestListApp(t *testing.T) {
285285
Name: "app1",
286286
Description: "",
287287
Icon: "😃",
288-
State: "",
288+
Status: "",
289289
Example: false,
290290
Default: false,
291291
},
@@ -294,7 +294,7 @@ func TestListApp(t *testing.T) {
294294
Name: "app2",
295295
Description: "",
296296
Icon: "😃",
297-
State: "",
297+
Status: "",
298298
Example: false,
299299
Default: false,
300300
},
@@ -305,7 +305,7 @@ func TestListApp(t *testing.T) {
305305
res, err := ListApps(t.Context(), dockerCli, ListAppRequest{
306306
ShowApps: true,
307307
ShowExamples: false,
308-
StateFilter: "",
308+
StatusFilter: "",
309309
}, idProvider, cfg)
310310
require.NoError(t, err)
311311
assert.Empty(t, res.BrokenApps)
@@ -315,7 +315,7 @@ func TestListApp(t *testing.T) {
315315
Name: "app1",
316316
Description: "",
317317
Icon: "😃",
318-
State: "",
318+
Status: "",
319319
Example: false,
320320
Default: false,
321321
},
@@ -324,7 +324,7 @@ func TestListApp(t *testing.T) {
324324
Name: "app2",
325325
Description: "",
326326
Icon: "😃",
327-
State: "",
327+
Status: "",
328328
Example: false,
329329
Default: false,
330330
},
@@ -335,7 +335,7 @@ func TestListApp(t *testing.T) {
335335
res, err := ListApps(t.Context(), dockerCli, ListAppRequest{
336336
ShowApps: false,
337337
ShowExamples: true,
338-
StateFilter: "",
338+
StatusFilter: "",
339339
}, idProvider, cfg)
340340
require.NoError(t, err)
341341
assert.Empty(t, res.BrokenApps)
@@ -345,7 +345,7 @@ func TestListApp(t *testing.T) {
345345
Name: "example1",
346346
Description: "",
347347
Icon: "😃",
348-
State: "",
348+
Status: "",
349349
Example: true,
350350
Default: false,
351351
},

0 commit comments

Comments
 (0)