|
| 1 | +// Licensed to Elasticsearch B.V. under one or more contributor |
| 2 | +// license agreements. See the NOTICE file distributed with |
| 3 | +// this work for additional information regarding copyright |
| 4 | +// ownership. Elasticsearch B.V. licenses this file to you under |
| 5 | +// the Apache License, Version 2.0 (the "License"); you may |
| 6 | +// not use this file except in compliance with the License. |
| 7 | +// You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +package cmdappsearch |
| 19 | + |
| 20 | +import ( |
| 21 | + "github.com/elastic/cloud-sdk-go/pkg/models" |
| 22 | + sdkcmdutil "github.com/elastic/cloud-sdk-go/pkg/util/cmdutil" |
| 23 | + "github.com/elastic/cloud-sdk-go/pkg/util/ec" |
| 24 | + "github.com/spf13/cobra" |
| 25 | + |
| 26 | + cmdutil "github.com/elastic/ecctl/cmd/util" |
| 27 | + "github.com/elastic/ecctl/pkg/deployment" |
| 28 | + "github.com/elastic/ecctl/pkg/deployment/depresource" |
| 29 | + "github.com/elastic/ecctl/pkg/ecctl" |
| 30 | +) |
| 31 | + |
| 32 | +// upgradeCmd is the deployment subcommand |
| 33 | +var upgradeCmd = &cobra.Command{ |
| 34 | + Use: "upgrade <deployment id>", |
| 35 | + Short: "Upgrades an AppSearch deployment to the Elasticsearch deployment version", |
| 36 | + PreRunE: sdkcmdutil.MinimumNArgsAndUUID(1), |
| 37 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 38 | + resType := "appsearch" |
| 39 | + refID, _ := cmd.Flags().GetString("ref-id") |
| 40 | + |
| 41 | + res, err := depresource.UpgradeStateless(deployment.ResourceParams{ |
| 42 | + API: ecctl.Get().API, |
| 43 | + DeploymentID: args[0], |
| 44 | + Type: resType, |
| 45 | + RefID: refID, |
| 46 | + }) |
| 47 | + |
| 48 | + if err != nil { |
| 49 | + return err |
| 50 | + } |
| 51 | + |
| 52 | + if track, _ := cmd.Flags().GetBool("track"); !track { |
| 53 | + return nil |
| 54 | + } |
| 55 | + |
| 56 | + return depresource.TrackResources(depresource.TrackResourcesParams{ |
| 57 | + API: ecctl.Get().API, |
| 58 | + OutputDevice: ecctl.Get().Config.OutputDevice, |
| 59 | + Resources: []*models.DeploymentResource{{ |
| 60 | + ID: ec.String(res.ResourceID), |
| 61 | + Kind: ec.String(resType), |
| 62 | + RefID: ec.String(refID), |
| 63 | + }}, |
| 64 | + }) |
| 65 | + }, |
| 66 | +} |
| 67 | + |
| 68 | +func init() { |
| 69 | + Command.AddCommand(upgradeCmd) |
| 70 | + upgradeCmd.Flags().BoolP("track", "t", false, cmdutil.TrackFlagMessage) |
| 71 | + upgradeCmd.Flags().String("ref-id", "", "Optional RefId, if not set, the RefId will be auto-discovered") |
| 72 | +} |
0 commit comments