-
Notifications
You must be signed in to change notification settings - Fork 30
CF-2067 : Add Flink artifact management commands for Confluent Platform #3406
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
Open
Paras Negi (paras-negi-flink)
wants to merge
6
commits into
main
Choose a base branch
from
cf-2067-flink-artifact-cli
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
98f6e1b
CF-2067 : Add Flink artifact management commands for Confluent Platform
paras-negi-flink 592c669
CF-2067 : Address review feedback on Flink artifact commands
paras-negi-flink 70f8756
CF-2067 : Simplify Flink artifact command internals
paras-negi-flink f045817
CF-2067 : Show artifact labels and annotations in human output
paras-negi-flink 68aaff2
CF-2067 : Overwrite the output file on Flink artifact download
paras-negi-flink 1cd3acc
CF-2067 : Tighten Flink artifact upload status check and tests
paras-negi-flink File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package flink | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
|
|
||
| pcmd "github.com/confluentinc/cli/v4/pkg/cmd" | ||
| "github.com/confluentinc/cli/v4/pkg/examples" | ||
| ) | ||
|
|
||
| func (c *command) newArtifactCreateCommandOnPrem() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "create <name>", | ||
| Short: "Create a Flink artifact in Confluent Platform.", | ||
| Long: "Create a Flink artifact in Confluent Platform by uploading a JAR or ZIP file. This creates version 1 of the artifact.", | ||
| Args: cobra.ExactArgs(1), | ||
| Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireCloudLogout}, | ||
| RunE: c.artifactCreateOnPrem, | ||
| Example: examples.BuildExampleString( | ||
| examples.Example{ | ||
| Text: `Create Flink artifact "my-artifact" in the environment "my-environment".`, | ||
| Code: "confluent flink artifact create my-artifact --artifact-file artifact.jar --environment my-environment", | ||
| }, | ||
| ), | ||
| } | ||
|
|
||
| cmd.Flags().String("environment", "", "Name of the Flink environment.") | ||
| cmd.Flags().String("artifact-file", "", "Path to the Flink artifact JAR or ZIP file.") | ||
|
Check failure on line 27 in internal/flink/command_artifact_create_onprem.go
|
||
| cmd.Flags().StringSlice("label", nil, `A comma-separated list of "key=value" label pairs.`) | ||
| addCmfFlagSet(cmd) | ||
| pcmd.AddOutputFlag(cmd) | ||
|
|
||
| cobra.CheckErr(cmd.MarkFlagRequired("environment")) | ||
| cobra.CheckErr(cmd.MarkFlagRequired("artifact-file")) | ||
| cobra.CheckErr(cmd.MarkFlagFilename("artifact-file", "jar", "zip")) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func (c *command) artifactCreateOnPrem(cmd *cobra.Command, args []string) error { | ||
| name := args[0] | ||
|
|
||
| environment, err := cmd.Flags().GetString("environment") | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| artifactFile, err := cmd.Flags().GetString("artifact-file") | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| labels, err := getLabelsFlag(cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| client, err := c.GetCmfClient(cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| file, err := openArtifactFile(artifactFile) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| defer file.Close() | ||
|
|
||
| outputArtifact, err := client.CreateArtifact(c.createContext(), environment, newSdkArtifact(name, labels), file) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return printArtifactOnPrem(cmd, outputArtifact) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package flink | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
|
|
||
| pcmd "github.com/confluentinc/cli/v4/pkg/cmd" | ||
| "github.com/confluentinc/cli/v4/pkg/deletion" | ||
| "github.com/confluentinc/cli/v4/pkg/errors" | ||
| "github.com/confluentinc/cli/v4/pkg/resource" | ||
| ) | ||
|
|
||
| func (c *command) newArtifactDeleteCommandOnPrem() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "delete <name-1> [name-2] ... [name-n]", | ||
| Short: "Delete one or more Flink artifacts in Confluent Platform.", | ||
| Long: "Delete one or more Flink artifacts in Confluent Platform, including all of their versions.", | ||
| Args: cobra.MinimumNArgs(1), | ||
| Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireCloudLogout}, | ||
| RunE: c.artifactDeleteOnPrem, | ||
| } | ||
|
|
||
| cmd.Flags().String("environment", "", "Name of the Flink environment.") | ||
| addCmfFlagSet(cmd) | ||
| pcmd.AddForceFlag(cmd) | ||
|
|
||
| cobra.CheckErr(cmd.MarkFlagRequired("environment")) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func (c *command) artifactDeleteOnPrem(cmd *cobra.Command, args []string) error { | ||
| environment, err := cmd.Flags().GetString("environment") | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| client, err := c.GetCmfClient(cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| existenceFunc := func(name string) bool { | ||
| _, err := client.DescribeArtifact(c.createContext(), environment, name, "") | ||
| return err == nil | ||
| } | ||
|
|
||
| if err := deletion.ValidateAndConfirm(cmd, args, existenceFunc, resource.FlinkArtifact); err != nil { | ||
| return errors.NewErrorWithSuggestions(err.Error(), artifactLookupSuggestions) | ||
| } | ||
|
|
||
| // An empty version deletes the artifact and all of its versions. | ||
| deleteFunc := func(name string) error { | ||
| return client.DeleteArtifact(c.createContext(), environment, name, "") | ||
| } | ||
|
|
||
| _, err = deletion.Delete(cmd, args, deleteFunc, resource.FlinkArtifact) | ||
| return err | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package flink | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
|
|
||
| pcmd "github.com/confluentinc/cli/v4/pkg/cmd" | ||
| ) | ||
|
|
||
| func (c *command) newArtifactDescribeCommandOnPrem() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "describe <name>", | ||
| Short: "Describe a Flink artifact in Confluent Platform.", | ||
| Long: "Describe a Flink artifact in Confluent Platform. Details reflect the latest version of the artifact.", | ||
| Args: cobra.ExactArgs(1), | ||
| Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireCloudLogout}, | ||
| RunE: c.artifactDescribeOnPrem, | ||
| } | ||
|
|
||
| cmd.Flags().String("environment", "", "Name of the Flink environment.") | ||
| addCmfFlagSet(cmd) | ||
| pcmd.AddOutputFlag(cmd) | ||
|
|
||
| cobra.CheckErr(cmd.MarkFlagRequired("environment")) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func (c *command) artifactDescribeOnPrem(cmd *cobra.Command, args []string) error { | ||
| name := args[0] | ||
|
|
||
| environment, err := cmd.Flags().GetString("environment") | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| client, err := c.GetCmfClient(cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| sdkArtifact, err := client.DescribeArtifact(c.createContext(), environment, name, "") | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return printArtifactOnPrem(cmd, sdkArtifact) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package flink | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
|
|
||
| pcmd "github.com/confluentinc/cli/v4/pkg/cmd" | ||
| "github.com/confluentinc/cli/v4/pkg/output" | ||
| ) | ||
|
|
||
| func (c *command) newArtifactListCommandOnPrem() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "list", | ||
| Short: "List Flink artifacts in Confluent Platform.", | ||
| Args: cobra.NoArgs, | ||
| Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireCloudLogout}, | ||
| RunE: c.artifactListOnPrem, | ||
| } | ||
|
|
||
| cmd.Flags().String("environment", "", "Name of the Flink environment.") | ||
| addCmfFlagSet(cmd) | ||
| pcmd.AddOutputFlag(cmd) | ||
|
|
||
| cobra.CheckErr(cmd.MarkFlagRequired("environment")) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func (c *command) artifactListOnPrem(cmd *cobra.Command, _ []string) error { | ||
| environment, err := cmd.Flags().GetString("environment") | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| client, err := c.GetCmfClient(cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| sdkArtifacts, err := client.ListArtifacts(c.createContext(), environment) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if output.GetFormat(cmd) == output.Human { | ||
| list := output.NewList(cmd) | ||
| for _, artifact := range sdkArtifacts { | ||
| list.Add(newArtifactOutOnPrem(artifact)) | ||
| } | ||
| return list.Print() | ||
| } | ||
|
|
||
| localArtifacts := make([]LocalArtifact, 0, len(sdkArtifacts)) | ||
| for _, sdkArtifact := range sdkArtifacts { | ||
| localArtifacts = append(localArtifacts, convertSdkArtifactToLocalArtifact(sdkArtifact)) | ||
| } | ||
|
|
||
| return output.SerializedOutput(cmd, localArtifacts) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
existenceFunccollapses every failure ofDescribeArtifact(404, but also 401/expired token, 500, connection refused) tofalse, so those all surface as"Flink artifact \"x\" not found". This matches the entrenched repo pattern, so not asking to rework it — but note theversion deleteprecheck you added in this same PR does it better (it preserveserr.Error()). Worth making the inconsistency a conscious choice; ideally only a true 404 maps to "not found".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.
Leaving as-is to match the shared
deletion.ValidateAndConfirmbool contract.