-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(kafka): add promote command #1805
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
package promote | ||
|
||
import ( | ||
"github.com/redhat-developer/app-services-cli/pkg/cmd/kafka/flagutil" | ||
"github.com/redhat-developer/app-services-cli/pkg/core/localize" | ||
"github.com/redhat-developer/app-services-cli/pkg/shared/contextutil" | ||
"github.com/redhat-developer/app-services-cli/pkg/shared/factory" | ||
"github.com/redhat-developer/app-services-cli/pkg/shared/kafkautil" | ||
"github.com/spf13/cobra" | ||
|
||
kafkamgmtclient "github.com/redhat-developer/app-services-sdk-go/kafkamgmt/apiv1/client" | ||
kafkamgmtv1errors "github.com/redhat-developer/app-services-sdk-go/kafkamgmt/apiv1/error" | ||
) | ||
|
||
type options struct { | ||
id string | ||
name string | ||
marketplaceAcctId string | ||
marketplace string | ||
desiredBillingModel string | ||
|
||
f *factory.Factory | ||
} | ||
|
||
func NewPromoteCommand(f *factory.Factory) *cobra.Command { | ||
|
||
opts := &options{ | ||
f: f, | ||
} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "promote", | ||
Short: opts.f.Localizer.MustLocalize("kafka.promote.cmd.shortDescription"), | ||
Long: opts.f.Localizer.MustLocalize("kafka.promote.cmd.longDescription"), | ||
Example: opts.f.Localizer.MustLocalize("kafka.promote.cmd.example"), | ||
Args: cobra.NoArgs, | ||
Hidden: true, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
|
||
if opts.name != "" && opts.id != "" { | ||
return opts.f.Localizer.MustLocalizeError("service.error.idAndNameCannotBeUsed") | ||
} | ||
|
||
if opts.id != "" || opts.name != "" { | ||
return runPromote(opts) | ||
} | ||
|
||
kafkaInstance, err := contextutil.GetCurrentKafkaInstance(f) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
opts.id = kafkaInstance.GetId() | ||
|
||
return runPromote(opts) | ||
}, | ||
} | ||
|
||
flags := flagutil.NewFlagSet(cmd, opts.f.Localizer) | ||
|
||
flags.StringVar(&opts.id, "id", "", opts.f.Localizer.MustLocalize("kafka.promote.flag.id")) | ||
flags.StringVar(&opts.name, "name", "", opts.f.Localizer.MustLocalize("kafka.promote.flag.name")) | ||
|
||
flags.StringVar(&opts.marketplaceAcctId, "marketplace-account-id", "", f.Localizer.MustLocalize("kafka.common.flag.marketplaceId.description")) | ||
flags.StringVar(&opts.marketplace, "marketplace", "", f.Localizer.MustLocalize("kafka.common.flag.marketplaceType.description")) | ||
flags.StringVar(&opts.desiredBillingModel, "billing-model", "", f.Localizer.MustLocalize("kafka.common.flag.billingModel.description")) | ||
|
||
_ = cmd.MarkFlagRequired("billing-model") | ||
|
||
return cmd | ||
|
||
} | ||
|
||
func runPromote(opts *options) error { | ||
|
||
conn, err := opts.f.Connection() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
api := conn.API() | ||
|
||
if opts.name != "" { | ||
response, _, newErr := kafkautil.GetKafkaByName(opts.f.Context, api.KafkaMgmt(), opts.name) | ||
if newErr != nil { | ||
return newErr | ||
} | ||
|
||
opts.id = response.GetId() | ||
} | ||
|
||
a := api.KafkaMgmt().PromoteKafka(opts.f.Context, opts.id) | ||
|
||
var promoteOptions kafkamgmtclient.KafkaPromoteRequest | ||
|
||
promoteOptions.SetDesiredKafkaBillingModel(opts.desiredBillingModel) | ||
|
||
if opts.marketplace != "" { | ||
promoteOptions.SetDesiredMarketplace(opts.marketplace) | ||
} | ||
|
||
if opts.marketplaceAcctId != "" { | ||
promoteOptions.SetDesiredKafkaBillingModel(opts.marketplaceAcctId) | ||
} | ||
|
||
a = a.KafkaPromoteRequest(promoteOptions) | ||
a = a.Async(true) | ||
|
||
httpRes, err := a.Execute() | ||
if httpRes != nil { | ||
defer httpRes.Body.Close() | ||
} | ||
|
||
if apiErr := kafkamgmtv1errors.GetAPIError(err); apiErr != nil { | ||
switch apiErr.GetCode() { | ||
case kafkamgmtv1errors.ERROR_120: | ||
// For standard instances | ||
return opts.f.Localizer.MustLocalizeError("kafka.create.error.quota.exceeded") | ||
case kafkamgmtv1errors.ERROR_24: | ||
// For dev instances | ||
return opts.f.Localizer.MustLocalizeError("kafka.create.error.instance.limit") | ||
case kafkamgmtv1errors.ERROR_9: | ||
return opts.f.Localizer.MustLocalizeError("kafka.create.error.standard.promote") | ||
case kafkamgmtv1errors.ERROR_43: | ||
return opts.f.Localizer.MustLocalizeError("kafka.create.error.billing.invalid", localize.NewEntry("Billing", opts.marketplaceAcctId)) | ||
} | ||
} | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
opts.f.Logger.Info(opts.f.Localizer.MustLocalize("kafka.promote.info.successAsync")) | ||
|
||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,15 @@ one = 'Kafka instance ID. Uses the current instance if not set' | |
[kafkas.common.flag.output.description] | ||
one = 'Format in which to display the Kafka instances (choose from: "json", "yml", "yaml")' | ||
|
||
[kafka.common.flag.marketplaceId.description] | ||
one = 'Cloud Account ID for the marketplace' | ||
|
||
[kafka.common.flag.billingModel.description] | ||
one = 'Billing model to be used' | ||
|
||
[kafka.common.flag.marketplaceType.description] | ||
one = 'Name of the marketplace where the instance is purchased on' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest: 'Name of cloud marketplace where Kafka instance was purchased' |
||
|
||
[kafka.common.input.instanceName.message] | ||
one = 'Select Kafka instance:' | ||
|
||
|
@@ -286,15 +295,6 @@ one = 'Wait until the Kafka instance is created' | |
[kafka.create.flag.dryrun.description] | ||
one = 'Validate all user provided arguments without creating the Kafka instance' | ||
|
||
[kafka.create.flag.marketplaceId.description] | ||
one = 'Cloud Account ID for the marketplace' | ||
|
||
[kafka.create.flag.billingModel.description] | ||
one = 'Billing model to be used' | ||
|
||
[kafka.create.flag.marketplaceType.description] | ||
one = 'Name of the marketplace where the instance is purchased on' | ||
|
||
[kafka.create.log.info.creatingKafka] | ||
description = 'Message when Kafka instance is being created' | ||
one = 'Creating Kafka instance "{{.Name}}"...' | ||
|
@@ -396,6 +396,9 @@ one = 'unable to create new Kafka instance at this time in specified cloud provi | |
[kafka.create.error.instance.limit] | ||
one = 'maximum number of allowed kafka instances has been reached. Please review all instances that your user has access to and delete one or more instances before creating a new one' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest: 'the maximum number of Kafka instances for your organization has been reached. Before you can create a new instance, you must delete one or more of the existing instances' |
||
|
||
[kafka.create.error.standard.promote] | ||
one = 'only Kafka instances with billing model "eval" can be promoted' | ||
|
||
[kafka.create.region.error.invalidRegion] | ||
one = ''' | ||
the region "{{.Region}}" is not available for the cloud provider "{{.Provider}}". | ||
|
@@ -591,6 +594,26 @@ $ rhoas kafka billing | |
[kafka.billing.log.info.noStandardInstancesAvailable] | ||
one = "Only developer instances are available" | ||
|
||
[kafka.promote.cmd.shortDescription] | ||
one = 'Promote eval Kafka instance' | ||
|
||
[kafka.promote.cmd.longDescription] | ||
one = 'Promote an evaluation Kafka instance to billing model "standard" or "marketplace"' | ||
|
||
[kafka.promote.cmd.example] | ||
one = ''' | ||
# Promote eval instance to standard | ||
$ rhoas kafka promote --billing-model standard --id 1iSY6RQ3JKI8Q0OTmjQFd3ocFRg | ||
''' | ||
|
||
[kafka.promote.flag.id] | ||
one = 'ID of the Kafka instance' | ||
|
||
[kafka.promote.flag.name] | ||
one = 'Name of the Kafka instance' | ||
|
||
[kafka.promote.info.successAsync] | ||
one = 'Kafka instance is being promoted. To monitor its status run "rhoas kafka describe".' | ||
|
||
[kafka.list.cmd.shortDescription] | ||
description = "Short description for command" | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest: "Account ID for cloud marketplace"