diff --git a/base/commands/viridian/common.go b/base/commands/viridian/common.go index 2fb231e3..6450cf75 100644 --- a/base/commands/viridian/common.go +++ b/base/commands/viridian/common.go @@ -268,3 +268,10 @@ func fixClusterState(state string) string { state = strings.Replace(state, "STOP", "PAUSE", 1) return state } + +func ClusterType(isDev bool) string { + if isDev { + return "Development" + } + return "Production" +} diff --git a/base/commands/viridian/const.go b/base/commands/viridian/const.go index 7372f851..2d99ddbb 100644 --- a/base/commands/viridian/const.go +++ b/base/commands/viridian/const.go @@ -4,7 +4,8 @@ package viridian const ( flagName = "name" - flagClusterType = "cluster-type" + flagPrerelease = "prerelease" + flagDevelopment = "development" flagOutputDir = "output-dir" flagHazelcastVersion = "hazelcast-version" fmtSecretFileName = "%s-%s.secret" diff --git a/base/commands/viridian/viridian_cluster_create.go b/base/commands/viridian/viridian_cluster_create.go index 787cf8b7..a6b4c02b 100644 --- a/base/commands/viridian/viridian_cluster_create.go +++ b/base/commands/viridian/viridian_cluster_create.go @@ -28,7 +28,8 @@ Make sure you login before running this command. cc.SetPositionalArgCount(0, 0) cc.AddStringFlag(propAPIKey, "", "", false, "Viridian API Key") cc.AddStringFlag(flagName, "", "", false, "specify the cluster name; if not given an auto-generated name is used.") - cc.AddStringFlag(flagClusterType, "", viridian.ClusterTypeServerless, false, "type for the cluster") + cc.AddBoolFlag(flagDevelopment, "", false, false, "create a development cluster") + cc.AddBoolFlag(flagPrerelease, "", false, false, "create a prerelease cluster") return nil } @@ -38,7 +39,8 @@ func (cm ClusterCreateCmd) Exec(ctx context.Context, ec plug.ExecContext) error return err } name := ec.Props().GetString(flagName) - clusterType := ec.Props().GetString(flagClusterType) + dev := ec.Props().GetBool(flagDevelopment) + prerelease := ec.Props().GetBool(flagPrerelease) hzVersion := ec.Props().GetString(flagHazelcastVersion) csi, stop, err := ec.ExecuteBlocking(ctx, func(ctx context.Context, sp clc.Spinner) (any, error) { sp.SetText("Creating the cluster") @@ -46,7 +48,7 @@ func (cm ClusterCreateCmd) Exec(ctx context.Context, ec plug.ExecContext) error if err != nil { return nil, err } - cs, err := api.CreateCluster(ctx, name, clusterType, k8sCluster.ID, hzVersion) + cs, err := api.CreateCluster(ctx, name, getClusterType(dev), k8sCluster.ID, prerelease, hzVersion) if err != nil { return nil, err } @@ -89,6 +91,13 @@ func (cm ClusterCreateCmd) Exec(ctx context.Context, ec plug.ExecContext) error return nil } +func getClusterType(dev bool) string { + if dev { + return viridian.ClusterTypeDevMode + } + return viridian.ClusterTypeServerless +} + func getFirstAvailableK8sCluster(ctx context.Context, api *viridian.API) (viridian.K8sCluster, error) { clusters, err := api.ListAvailableK8sClusters(ctx) if err != nil { diff --git a/base/commands/viridian/viridian_cluster_get.go b/base/commands/viridian/viridian_cluster_get.go index 18e6e2f6..43df0ee6 100644 --- a/base/commands/viridian/viridian_cluster_get.go +++ b/base/commands/viridian/viridian_cluster_get.go @@ -102,6 +102,11 @@ func (cm ClusterGetCmd) Exec(ctx context.Context, ec plug.ExecContext) error { Type: serialization.TypeStringArray, Value: regionTitleSlice(c.Regions), }, + output.Column{ + Name: "Cluster Type", + Type: serialization.TypeString, + Value: ClusterType(c.ClusterType.DevMode), + }, ) } return ec.AddOutputRows(ctx, row) diff --git a/base/commands/viridian/viridian_cluster_list.go b/base/commands/viridian/viridian_cluster_list.go index e896ece9..aa3ab6d7 100644 --- a/base/commands/viridian/viridian_cluster_list.go +++ b/base/commands/viridian/viridian_cluster_list.go @@ -50,6 +50,7 @@ func (cm ClusterListCmd) Exec(ctx context.Context, ec plug.ExecContext) error { ec.PrintlnUnnecessary("No clusters found") } rows := make([]output.Row, len(cs)) + verbose := ec.Props().GetBool(clc.PropertyVerbose) for i, c := range cs { rows[i] = output.Row{ output.Column{ @@ -73,6 +74,15 @@ func (cm ClusterListCmd) Exec(ctx context.Context, ec plug.ExecContext) error { Value: c.HazelcastVersion, }, } + if verbose { + rows[i] = append(rows[i], + output.Column{ + Name: "Cluster Type", + Type: serialization.TypeString, + Value: ClusterType(c.ClusterType.DevMode), + }, + ) + } } return ec.AddOutputRows(ctx, rows...) } diff --git a/base/commands/viridian/viridian_cluster_types.go b/base/commands/viridian/viridian_cluster_types.go deleted file mode 100644 index 82020de3..00000000 --- a/base/commands/viridian/viridian_cluster_types.go +++ /dev/null @@ -1,68 +0,0 @@ -//go:build std || viridian - -package viridian - -import ( - "context" - - "github.com/hazelcast/hazelcast-commandline-client/clc" - . "github.com/hazelcast/hazelcast-commandline-client/internal/check" - "github.com/hazelcast/hazelcast-commandline-client/internal/output" - "github.com/hazelcast/hazelcast-commandline-client/internal/plug" - "github.com/hazelcast/hazelcast-commandline-client/internal/serialization" - "github.com/hazelcast/hazelcast-commandline-client/internal/viridian" -) - -type ClusterTypeListCmd struct{} - -func (ct ClusterTypeListCmd) Init(cc plug.InitContext) error { - cc.SetCommandUsage("list-cluster-types [flags]") - long := `Lists available cluster types that can be used while creating a Viridian cluster. - -Make sure you login before running this command. -` - short := "Lists Viridian cluster types" - cc.SetCommandHelp(long, short) - cc.SetPositionalArgCount(0, 0) - cc.AddStringFlag(propAPIKey, "", "", false, "Viridian API Key") - return nil -} - -func (ct ClusterTypeListCmd) Exec(ctx context.Context, ec plug.ExecContext) error { - api, err := getAPI(ec) - if err != nil { - return err - } - verbose := ec.Props().GetBool(clc.PropertyVerbose) - csi, stop, err := ec.ExecuteBlocking(ctx, func(ctx context.Context, sp clc.Spinner) (any, error) { - sp.SetText("Retrieving cluster types") - return api.ListClusterTypes(ctx) - }) - if err != nil { - return handleErrorResponse(ec, err) - } - stop() - cs := csi.([]viridian.ClusterType) - var rows []output.Row - for _, c := range cs { - var r output.Row - if verbose { - r = append(r, output.Column{ - Name: "ID", - Type: serialization.TypeInt64, - Value: c.ID, - }) - } - r = append(r, output.Column{ - Name: "Name", - Type: serialization.TypeString, - Value: c.Name, - }) - rows = append(rows, r) - } - return ec.AddOutputRows(ctx, rows...) -} - -func init() { - Must(plug.Registry.RegisterCommand("viridian:list-cluster-types", &ClusterTypeListCmd{})) -} diff --git a/base/commands/viridian/viridian_it_test.go b/base/commands/viridian/viridian_it_test.go index d8bab0ea..125b4680 100644 --- a/base/commands/viridian/viridian_it_test.go +++ b/base/commands/viridian/viridian_it_test.go @@ -160,7 +160,7 @@ func createCluster_InteractiveTest(t *testing.T) { ensureNoClusterRunning(ctx, tcx) tcx.WithReset(func() { clusterName := it.UniqueClusterName() - tcx.WriteStdinf("\\viridian create-cluster --cluster-type devmode --verbose --name %s \n", clusterName) + tcx.WriteStdinf("\\viridian create-cluster --development --verbose --name %s \n", clusterName) time.Sleep(10 * time.Second) check.Must(waitState(ctx, tcx, "", "RUNNING")) tcx.AssertStdoutContains(fmt.Sprintf("Imported configuration: %s", clusterName)) diff --git a/docs/modules/ROOT/pages/clc-viridian.adoc b/docs/modules/ROOT/pages/clc-viridian.adoc index a8c7def9..10ff22d0 100644 --- a/docs/modules/ROOT/pages/clc-viridian.adoc +++ b/docs/modules/ROOT/pages/clc-viridian.adoc @@ -14,7 +14,6 @@ clc viridian [command] [options] == Commands * <> -* <> * <> * <> * <> @@ -65,32 +64,6 @@ Parameters: |=== -== clc viridian list-cluster-types - -Lists available cluster types that can be used while creating a {hazelcast-cloud} cluster. - -Make sure you authenticate with the {hazelcast-cloud} API using `viridian login` before running this command. - -Usage: - -[source,bash] ----- -clc viridian list-cluster-types [flags] ----- - -Parameters: - -[cols="1m,1a,2a,1a"] -|=== -|Parameter|Required|Description|Default - -|`--api-key` -|Optional -|Sets the API key. Overrides the `CLC_VIRIDIAN_API_KEY` environment variable. If not given, one of the existing API keys will be used. -| - -|=== - == clc viridian create-cluster Creates a {hazelcast-cloud} cluster. @@ -120,9 +93,14 @@ Parameters: |Sets the name of the created cluster. If not given, an auto-generated name will be used. | -|`--cluster-type` +|`--development` +|Optional +|Creates a development cluster. +| + +|`--prerelease` |Optional -|Sets the cluster-type for the created cluster. +|Creates the cluster with a prerelease image. | |=== diff --git a/internal/viridian/cluster.go b/internal/viridian/cluster.go index c7a46df5..d82cf395 100644 --- a/internal/viridian/cluster.go +++ b/internal/viridian/cluster.go @@ -19,11 +19,12 @@ type createClusterRequest struct { Name string `json:"name"` ClusterTypeID int64 `json:"clusterTypeId"` PlanName string `json:"planName"` + Prerelease bool `json:"preRelease"` } type createClusterResponse Cluster -func (a *API) CreateCluster(ctx context.Context, name string, clusterType string, k8sClusterID int, hzVersion string) (Cluster, error) { +func (a *API) CreateCluster(ctx context.Context, name string, clusterType string, k8sClusterID int, prerelease bool, hzVersion string) (Cluster, error) { if name == "" { name = clusterName() } @@ -41,6 +42,7 @@ func (a *API) CreateCluster(ctx context.Context, name string, clusterType string Name: name, ClusterTypeID: clusterTypeID, PlanName: planName, + Prerelease: prerelease, } cluster, err := RetryOnAuthFail(ctx, a, func(ctx context.Context, token string) (Cluster, error) { u := a.makeURL("/cluster") diff --git a/internal/viridian/types.go b/internal/viridian/types.go index 3b653271..b2038a6c 100644 --- a/internal/viridian/types.go +++ b/internal/viridian/types.go @@ -37,8 +37,9 @@ type K8sCluster struct { } type ClusterType struct { - ID int64 `json:"id"` - Name string `json:"name"` + ID int64 `json:"id"` + Name string `json:"name"` + DevMode bool `json:"devMode"` } type Region struct { @@ -48,5 +49,5 @@ type Region struct { type IP struct { ID int `json:"id"` IP string `json:"ip"` - Description string `json:"description",omitempty` + Description string `json:"description,omitempty"` }