Skip to content

Commit 133cfff

Browse files
authored
tracker: Use deployment tracker in all tracking (#234)
This change removes all the instances and usage of `plan.Track` and replaces them with `planutil.TrackChange` which supports deployment plan tracking, tracking of downstream changes and AppSearch. Additionally, creates some constants in `util` with the workload Kinds and changes the references to those for the constants. Signed-off-by: Marc Lopez <marc5.12@outlook.com>
1 parent a8cdffe commit 133cfff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+1072
-1487
lines changed

cmd/deployment/apm/create.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,12 @@ var createApmCmd = &cobra.Command{
106106
}
107107

108108
var track, _ = cmd.Flags().GetBool("track")
109-
return cmdutil.Track(cmdutil.TrackParams{
110-
TrackResourcesParams: depresource.TrackResourcesParams{
111-
API: ecctl.Get().API,
112-
Resources: res.Resources,
113-
Orphaned: res.ShutdownResources,
114-
OutputDevice: ecctl.Get().Config.OutputDevice,
115-
},
116-
Formatter: ecctl.Get().Formatter,
117-
Track: track,
118-
Response: res,
119-
})
109+
return cmdutil.Track(cmdutil.NewTrackParams(cmdutil.TrackParamsConfig{
110+
App: ecctl.Get(),
111+
DeploymentID: id,
112+
Track: track,
113+
Response: res,
114+
}))
120115
},
121116
}
122117

cmd/deployment/apm/delete.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
package cmdapm
1919

2020
import (
21-
"github.com/elastic/cloud-sdk-go/pkg/util/cmdutil"
21+
sdkcmdutil "github.com/elastic/cloud-sdk-go/pkg/util/cmdutil"
2222
"github.com/spf13/cobra"
2323

24+
cmdutil "github.com/elastic/ecctl/cmd/util"
2425
"github.com/elastic/ecctl/pkg/deployment/apm"
2526
"github.com/elastic/ecctl/pkg/ecctl"
2627
"github.com/elastic/ecctl/pkg/util"
@@ -29,16 +30,19 @@ import (
2930
var deleteApmCmd = &cobra.Command{
3031
Use: "delete <apm deployment id>",
3132
Short: "Deletes an APM deployment",
32-
PreRunE: cmdutil.MinimumNArgsAndUUID(1),
33+
PreRunE: sdkcmdutil.MinimumNArgsAndUUID(1),
3334
RunE: func(cmd *cobra.Command, args []string) error {
3435
if stop, _ := cmd.Flags().GetBool("stop"); stop {
3536
err := apm.Shutdown(apm.ShutdownParams{
36-
API: ecctl.Get().API,
37-
ID: args[0],
38-
TrackParams: util.TrackParams{
39-
Track: true,
40-
Output: ecctl.Get().Config.OutputDevice,
41-
},
37+
API: ecctl.Get().API,
38+
ID: args[0],
39+
Track: true,
40+
TrackChangeParams: cmdutil.NewTrackParams(cmdutil.TrackParamsConfig{
41+
App: ecctl.Get(),
42+
ResourceID: args[0],
43+
Kind: util.Apm,
44+
Track: true,
45+
}).TrackChangeParams,
4246
})
4347
if err != nil {
4448
return err

cmd/deployment/apm/plan/cancel.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
package cmdapmplan
1919

2020
import (
21-
"fmt"
22-
2321
sdkcmdutil "github.com/elastic/cloud-sdk-go/pkg/util/cmdutil"
2422
"github.com/spf13/cobra"
2523

@@ -35,20 +33,17 @@ var cancelPlanCmd = &cobra.Command{
3533
PreRunE: sdkcmdutil.MinimumNArgsAndUUID(1),
3634
RunE: func(cmd *cobra.Command, args []string) error {
3735
track, _ := cmd.Flags().GetBool("track")
38-
err := apm.CancelPlan(apm.PlanParams{
39-
API: ecctl.Get().API,
40-
ID: args[0],
41-
TrackParams: util.TrackParams{
42-
Track: track,
43-
Output: ecctl.Get().Config.OutputDevice,
44-
},
36+
return apm.CancelPlan(apm.PlanParams{
37+
API: ecctl.Get().API,
38+
ID: args[0],
39+
Track: track,
40+
TrackChangeParams: cmdutil.NewTrackParams(cmdutil.TrackParamsConfig{
41+
App: ecctl.Get(),
42+
ResourceID: args[0],
43+
Kind: util.Apm,
44+
Track: track,
45+
}).TrackChangeParams,
4546
})
46-
if err != nil {
47-
return err
48-
}
49-
50-
fmt.Printf("Cluster [%s][Apm]: pending plan canceled\n", args[0])
51-
return nil
5247
},
5348
}
5449

cmd/deployment/apm/plan/history.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ import (
2424
sdkcmdutil "github.com/elastic/cloud-sdk-go/pkg/util/cmdutil"
2525
"github.com/spf13/cobra"
2626

27-
cmdutil "github.com/elastic/ecctl/cmd/util"
2827
"github.com/elastic/ecctl/pkg/deployment/apm"
2928
"github.com/elastic/ecctl/pkg/ecctl"
30-
"github.com/elastic/ecctl/pkg/util"
3129
)
3230

3331
var listPlansCmd = &cobra.Command{
@@ -36,14 +34,9 @@ var listPlansCmd = &cobra.Command{
3634
Aliases: []string{"attempts"},
3735
PreRunE: sdkcmdutil.MinimumNArgsAndUUID(1),
3836
RunE: func(cmd *cobra.Command, args []string) error {
39-
track, _ := cmd.Flags().GetBool("track")
4037
p, err := apm.ListPlanHistory(apm.PlanParams{
4138
API: ecctl.Get().API,
4239
ID: args[0],
43-
TrackParams: util.TrackParams{
44-
Track: track,
45-
Output: ecctl.Get().Config.OutputDevice,
46-
},
4740
})
4841
if err != nil {
4942
return nil
@@ -56,7 +49,3 @@ var listPlansCmd = &cobra.Command{
5649
)
5750
},
5851
}
59-
60-
func init() {
61-
listPlansCmd.Flags().Bool("track", false, cmdutil.TrackFlagMessage)
62-
}

cmd/deployment/apm/plan/monitor.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
package cmdapmplan
1919

2020
import (
21-
"time"
22-
23-
"github.com/elastic/cloud-sdk-go/pkg/plan"
2421
sdkcmdutil "github.com/elastic/cloud-sdk-go/pkg/util/cmdutil"
2522
"github.com/spf13/cobra"
2623

@@ -35,18 +32,16 @@ var monitorPlanCmd = &cobra.Command{
3532
Short: "Monitors the pending plan",
3633
PreRunE: sdkcmdutil.MinimumNArgsAndUUID(1),
3734
RunE: func(cmd *cobra.Command, args []string) error {
38-
return util.TrackCluster(util.TrackClusterParams{
39-
TrackParams: plan.TrackParams{
40-
ID: args[0],
41-
API: ecctl.Get().API,
42-
Kind: "apm",
43-
},
44-
Output: ecctl.Get().Config.OutputDevice,
45-
})
35+
return cmdutil.Track(cmdutil.NewTrackParams(cmdutil.TrackParamsConfig{
36+
App: ecctl.Get(),
37+
DeploymentID: args[0],
38+
Kind: util.Apm,
39+
Track: true,
40+
}))
4641
},
4742
}
4843

4944
func init() {
50-
monitorPlanCmd.Flags().Duration("poll-interval", time.Second*2, "Monitor poll interval")
51-
monitorPlanCmd.Flags().Uint8("retries", 3, cmdutil.PlanRetriesFlagMessage)
45+
monitorPlanCmd.Flags().Duration("poll-interval", util.DefaultPollFrequency, "Monitor poll interval")
46+
monitorPlanCmd.Flags().Uint8("retries", util.DefaultRetries, cmdutil.PlanRetriesFlagMessage)
5247
}

cmd/deployment/apm/plan/reapply.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,30 @@ var reapplyLatestPlanCmd = &cobra.Command{
3535
Short: "Reapplies the latest plan attempt, resetting all transient settings",
3636
PreRunE: sdkcmdutil.MinimumNArgsAndUUID(1),
3737
RunE: func(cmd *cobra.Command, args []string) error {
38-
var reparams = &planutil.ReapplyParams{ID: args[0]}
38+
var reparams = planutil.ReapplyParams{ID: args[0]}
3939
// Obtains the parameter's value and sets it in params
4040
for name := range util.FieldsOfStruct(reparams) {
4141
val, err := cmd.Flags().GetBool(name)
4242
if err != nil {
4343
return err
4444
}
45-
util.Set(reparams, name, val)
45+
util.Set(&reparams, name, val)
4646
}
4747

4848
track, _ := cmd.Flags().GetBool("track")
4949
p, err := apm.ReapplyLatestPlanAttempt(
5050
apm.PlanParams{
51-
TrackParams: util.TrackParams{
52-
Track: track,
53-
Output: ecctl.Get().Config.OutputDevice,
54-
},
51+
Track: track,
52+
TrackChangeParams: cmdutil.NewTrackParams(cmdutil.TrackParamsConfig{
53+
App: ecctl.Get(),
54+
ResourceID: args[0],
55+
Kind: util.Apm,
56+
Track: track,
57+
}).TrackChangeParams,
5558
API: ecctl.Get().API,
5659
ID: args[0],
5760
},
58-
*reparams,
61+
reparams,
5962
)
6063
if err != nil {
6164
return err

cmd/deployment/apm/restart.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@ var restartApmCmd = &cobra.Command{
3939
API: ecctl.Get().API,
4040
ID: args[0],
4141
Force: force,
42-
TrackParams: util.TrackParams{
43-
Track: track,
44-
Output: ecctl.Get().Config.OutputDevice,
45-
},
42+
Track: track,
43+
TrackChangeParams: cmdutil.NewTrackParams(cmdutil.TrackParamsConfig{
44+
App: ecctl.Get(),
45+
ResourceID: args[0],
46+
Kind: util.Apm,
47+
Track: track,
48+
}).TrackChangeParams,
4649
})
4750
},
4851
}

cmd/deployment/apm/stop.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,16 @@ var stopApmCmd = &cobra.Command{
3636
track, _ := cmd.Flags().GetBool("track")
3737
hide, _ := cmd.Flags().GetBool("hide")
3838
return apm.Shutdown(apm.ShutdownParams{
39-
API: ecctl.Get().API,
40-
ID: args[0],
41-
Hide: hide,
42-
TrackParams: util.TrackParams{
43-
Track: track,
44-
Output: ecctl.Get().Config.OutputDevice,
45-
},
39+
API: ecctl.Get().API,
40+
ID: args[0],
41+
Hide: hide,
42+
Track: track,
43+
TrackChangeParams: cmdutil.NewTrackParams(cmdutil.TrackParamsConfig{
44+
App: ecctl.Get(),
45+
ResourceID: args[0],
46+
Kind: util.Apm,
47+
Track: track,
48+
}).TrackChangeParams,
4649
})
4750
},
4851
}

cmd/deployment/apm/upgrade.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,20 @@ var upgradeApmCmd = &cobra.Command{
3636
RunE: func(cmd *cobra.Command, args []string) error {
3737
track, _ := cmd.Flags().GetBool("track")
3838
res, err := apm.Upgrade(apm.UpgradeParams{
39-
API: ecctl.Get().API,
40-
ID: args[0],
41-
TrackParams: util.TrackParams{
42-
Track: track,
43-
Output: ecctl.Get().Config.OutputDevice,
44-
},
39+
API: ecctl.Get().API,
40+
ID: args[0],
41+
Track: track,
42+
TrackChangeParams: cmdutil.NewTrackParams(cmdutil.TrackParamsConfig{
43+
App: ecctl.Get(),
44+
ResourceID: args[0],
45+
Kind: util.Apm,
46+
Track: track,
47+
}).TrackChangeParams,
4548
})
4649
if err != nil {
4750
return err
4851
}
49-
return ecctl.Get().Formatter.Format(filepath.Join("apm", "upgrade"), res)
52+
return ecctl.Get().Formatter.Format(filepath.Join(util.Apm, "upgrade"), res)
5053
},
5154
}
5255

cmd/deployment/appsearch/create.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,12 @@ var createAppSearchCmd = &cobra.Command{
106106
}
107107

108108
var track, _ = cmd.Flags().GetBool("track")
109-
return cmdutil.Track(cmdutil.TrackParams{
110-
TrackResourcesParams: depresource.TrackResourcesParams{
111-
API: ecctl.Get().API,
112-
Resources: res.Resources,
113-
Orphaned: res.ShutdownResources,
114-
OutputDevice: ecctl.Get().Config.OutputDevice,
115-
},
116-
Formatter: ecctl.Get().Formatter,
117-
Track: track,
118-
Response: res,
119-
})
109+
return cmdutil.Track(cmdutil.NewTrackParams(cmdutil.TrackParamsConfig{
110+
App: ecctl.Get(),
111+
DeploymentID: id,
112+
Track: track,
113+
Response: res,
114+
}))
120115
},
121116
}
122117

0 commit comments

Comments
 (0)