Skip to content

Commit

Permalink
Rename ilm set as ilm edit
Browse files Browse the repository at this point in the history
Add examples of ilm command with transition
  • Loading branch information
Poorna Krishnamoorthy committed Nov 12, 2020
1 parent 6ab7046 commit a479f80
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 163 deletions.
15 changes: 12 additions & 3 deletions cmd/admin-bucket-remote-add.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var adminBucketRemoteAddFlags = []cli.Flag{
},
cli.StringFlag{
Name: "service",
Usage: "type of service. Valid options are '[replication]'",
Usage: "type of service. Valid options are '[replication, ilm]'",
},
cli.StringFlag{
Name: "region",
Expand Down Expand Up @@ -87,14 +87,23 @@ FLAGS:
{{range .VisibleFlags}}{{.}}
{{end}}
EXAMPLES:
1. Set a new remote replication target 'targetbucket' in region "us-west-1" on https://minio.siteb.example.com for bucket 'sourcebucket'.
1. Set a new remote replication target "targetbucket" in region "us-west-1" on https://minio.siteb.example.com for bucket 'sourcebucket'.
{{.Prompt}} {{.HelpName}} sitea/sourcebucket \
https://foobar:foo12345@minio.siteb.example.com/targetbucket \
--service "replication" --region "us-west-1" --label "hdd-tier"
--service "replication" --region "us-west-1" --label "hdd-tier"
2. Set a new remote replication target 'targetbucket' in region "us-west-1" on https://minio.siteb.example.com for bucket 'sourcebucket' with bandwidth set to 2 gigabits (2*10^9) per second.
{{.Prompt}} {{.HelpName}} sitea/sourcebucket \
https://foobar:foo12345@minio.siteb.example.com/targetbucket \
--service "replication" --region "us-west-1 --bandwidth "2G"
3. Set a new remote transition target 'srcbucket' in region "us-west-1" on https://minio2:9000 for bucket 'srcbucket' on MinIO server.
{{.DisableHistory}}
{{.Prompt}} {{.HelpName}} myminio/srcbucket \
https://foobar:foo12345@minio2:9000/srcbucket \
--service "ilm" --region "us-west-1" --label "hdd-tier"
{{.EnableHistory}}
`,
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/auto-complete.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ var completeCmds = map[string]complete.Predictor{

"/ilm/ls": s3Complete{deepLevel: 2},
"/ilm/add": s3Complete{deepLevel: 2},
"/ilm/set": s3Complete{deepLevel: 2},
"/ilm/edit": s3Complete{deepLevel: 2},
"/ilm/rm": s3Complete{deepLevel: 2},
"/ilm/export": s3Complete{deepLevel: 2},
"/ilm/import": s3Complete{deepLevel: 2},
Expand Down
15 changes: 10 additions & 5 deletions cmd/ilm-add.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,17 @@ EXAMPLES:
{{.Prompt}} {{.HelpName}} --expiry-days "200" myminio/mybucket
2. Add expiry and transition date rules on a prefix in mybucket.
{{.Prompt}} {{.HelpName}} -expiry-date "2025-09-17" --transition-date "2025-05-01" \
--storage-class "GLACIER" myminio/mybucket/doc
{{.Prompt}} {{.HelpName}} --expiry-date "2025-09-17" --transition-date "2025-05-01" \
--storage-class "GLACIER" s3/mybucket/doc
3. Add expiry and transition days rules on a prefix in mybucket.
{{.Prompt}} {{.HelpName}} -expiry-days "300" --transition-days "200" \
--storage-class "GLACIER" myminio/mybucket/doc
{{.Prompt}} {{.HelpName}} --expiry-days "300" --transition-days "200" \
--storage-class "GLACIER" s3/mybucket/doc
4. Add expiry and transition days rules on a prefix in mybucket for a MinIO transition target specified by label "hdd_tier".
"hdd_tier" is the label specified when adding a remote target with "mc admin bucket remote add --service ilm --label hdd_tier"
{{.Prompt}} {{.HelpName}} --expiry-days "300" --transition-days "200" \
--storage-class "hdd_tier" myminio/mybucket/doc
`,
}

Expand All @@ -83,7 +88,7 @@ var ilmAddFlags = []cli.Flag{
},
cli.StringFlag{
Name: "storage-class",
Usage: "storage class for transition (STANDARD_IA, ONEZONE_IA, GLACIER. Etc)",
Usage: "storage class for transition (STANDARD_IA, ONEZONE_IA, GLACIER. Etc). For setting up transition to a MinIO target, use the label defined for the target",
},
cli.BoolFlag{
Name: "disable",
Expand Down
2 changes: 1 addition & 1 deletion cmd/ilm-main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var ilmSubcommands = []cli.Command{
ilmLsCmd,
ilmAddCmd,
ilmRmCmd,
ilmSetCmd,
ilmEditCmd,
ilmExportCmd,
ilmImportCmd,
}
Expand Down
32 changes: 16 additions & 16 deletions cmd/ilm-set.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ import (
"github.com/minio/minio/pkg/console"
)

var ilmSetCmd = cli.Command{
Name: "set",
var ilmEditCmd = cli.Command{
Name: "edit",
Usage: "modify a lifecycle configuration rule with given id",
Action: mainILMSet,
Action: mainILMEdit,
Before: setGlobalsFromContext,
Flags: append(ilmSetFlags, globalFlags...),
Flags: append(ilmEditFlags, globalFlags...),
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}
Expand All @@ -58,7 +58,7 @@ EXAMPLES:
`,
}

var ilmSetFlags = []cli.Flag{
var ilmEditFlags = []cli.Flag{
cli.StringFlag{
Name: "id",
Usage: "id of the rule to be modified",
Expand Down Expand Up @@ -93,26 +93,26 @@ var ilmSetFlags = []cli.Flag{
},
}

type ilmSetMessage struct {
type ilmEditMessage struct {
Status string `json:"status"`
Target string `json:"target"`
ID string `json:"id"`
}

func (i ilmSetMessage) String() string {
return console.Colorize(ilmThemeResultSuccess, "Lifecycle configuration rule added with ID `"+i.ID+"` to "+i.Target+".")
func (i ilmEditMessage) String() string {
return console.Colorize(ilmThemeResultSuccess, "Lifecycle configuration rule with ID `"+i.ID+"` modified to "+i.Target+".")
}

func (i ilmSetMessage) JSON() string {
func (i ilmEditMessage) JSON() string {
msgBytes, e := json.MarshalIndent(i, "", " ")
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
return string(msgBytes)
}

// Validate user given arguments
func checkILMSetSyntax(ctx *cli.Context) {
func checkILMEditSyntax(ctx *cli.Context) {
if len(ctx.Args()) != 1 {
cli.ShowCommandHelpAndExit(ctx, "set", globalErrorExitStatus)
cli.ShowCommandHelpAndExit(ctx, "edit", globalErrorExitStatus)
}
id := ctx.String("id")
if id == "" {
Expand All @@ -121,11 +121,11 @@ func checkILMSetSyntax(ctx *cli.Context) {
}

// Calls SetBucketLifecycle with the XML representation of lifecycleConfiguration type.
func mainILMSet(cliCtx *cli.Context) error {
ctx, cancelILMSet := context.WithCancel(globalContext)
defer cancelILMSet()
func mainILMEdit(cliCtx *cli.Context) error {
ctx, cancelILMEdit := context.WithCancel(globalContext)
defer cancelILMEdit()

checkILMSetSyntax(cliCtx)
checkILMEditSyntax(cliCtx)
setILMDisplayColorScheme()
args := cliCtx.Args()
urlStr := args.Get(0)
Expand All @@ -151,7 +151,7 @@ func mainILMSet(cliCtx *cli.Context) error {

fatalIf(client.SetLifecycle(ctx, lfcCfg).Trace(urlStr), "Unable to set new lifecycle rules")

printMsg(ilmSetMessage{
printMsg(ilmEditMessage{
Status: "success",
Target: urlStr,
ID: opts.ID,
Expand Down
13 changes: 9 additions & 4 deletions cmd/ilm/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ func (opts LifecycleOptions) ToConfig(config *lifecycle.Configuration) (*lifecyc
if err != nil {
return nil, err.Trace(opts.StorageClass, opts.TransitionDate, opts.TransitionDays)
}

andVal := lifecycle.And{
Tags: extractILMTags(opts.Tags),
}
Expand Down Expand Up @@ -163,9 +162,11 @@ func (opts LifecycleOptions) ToConfig(config *lifecycle.Configuration) (*lifecyc
}

if !ruleFound {
if err := validateILMRule(newRule); err != nil {
return nil, err.Trace(opts.ID)
}
config.Rules = append(config.Rules, newRule)
}

return config, nil
}

Expand All @@ -182,18 +183,22 @@ func GetLifecycleOptions(ctx *cli.Context) LifecycleOptions {
if len(result) > 2 {
prefix = result[len(result)-1]
}
scSet := ctx.IsSet("storage-class")
sc := strings.ToUpper(ctx.String("storage-class"))
// for MinIO transition storage-class is same as label defined on
// `mc admin bucket remote add --service ilm --label` command
return LifecycleOptions{
ID: id,
Prefix: prefix,
Status: !ctx.Bool("disable"),
IsTagsSet: ctx.IsSet("tags"),
IsStorageClassSet: ctx.IsSet("storage-class"),
IsStorageClassSet: scSet,
Tags: ctx.String("tags"),
ExpiryDate: ctx.String("expiry-date"),
ExpiryDays: ctx.String("expiry-days"),
TransitionDate: ctx.String("transition-date"),
TransitionDays: ctx.String("transition-days"),
StorageClass: ctx.String("storage-class"),
StorageClass: sc,
}
}

Expand Down
8 changes: 5 additions & 3 deletions cmd/ilm/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,13 @@ func validateTranExpDate(rule lifecycle.Rule) error {
}
}
if transitionDateSet && rule.Transition.StorageClass == "" {
return errors.New("if storage class is set a valid transitionDate or transitionDay must be set")
return errors.New("if transitionDate or transitionDay is set, a valid storage class must be set")
}
if transitionDaySet && rule.Transition.StorageClass == "" {
return errors.New("if storage class is set a valid transitionDate or transitionDay must be set")
return errors.New("if transitionDate or transitionDay is set, a valid storage class must be set")
}
if rule.Transition.StorageClass != "" && (!transitionDateSet && !transitionDaySet) {
return errors.New("if storage class is set, transitionDate or transitionDay must be set")
}
return nil
}
Expand Down Expand Up @@ -137,7 +140,6 @@ func validateILMRule(rule lifecycle.Rule) *probe.Error {

// Returns valid lifecycleTransition to be included in lifecycleRule
func parseTransition(storageClass, transitionDateStr, transitionDayStr string) (transition lifecycle.Transition, err *probe.Error) {
storageClass = strings.ToUpper(storageClass) // Just-in-case the user has entered lower case characters.
if transitionDateStr != "" {
transitionDate, e := time.Parse(defaultILMDateFormat, transitionDateStr)
if e != nil {
Expand Down
6 changes: 6 additions & 0 deletions docs/minio-admin-complete-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,12 @@ ARN = `arn:minio:replication:us-west-1:1f8712ba-e38f-4429-bcb1-a7bb5aa97447:targ

```
mc admin bucket remote add myminio/srcbucket https://foobar:foobar12345@minio2:9000/targetbucket --service "replication" --region "us-west-1" --bandwidth "2Gi"
*Example: Add a new ILM transition target `targetbucket` with label "hdd_tier" in region `us-west-1` on `https://minio2:9000` for bucket `srcbucket` on MinIO server. `foobar` and `foo12345` are credentials to target endpoint.
*
```
mc admin bucket remote add myminio/srcbucket https://foobar:foobar12345@minio2:9000/targetbucket --service "ilm" --region "us-west-1" --label "hdd_tier"
ARN = `arn:minio:replication:us-west-1:1f8712ba-e38f-4429-bcb1-a7bb5aa97447:targetbucket`
```
Expand Down
22 changes: 14 additions & 8 deletions docs/minio-client-complete-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -1259,9 +1259,10 @@ USAGE:
mc ilm COMMAND [COMMAND FLAGS | -h] [ARGUMENTS...]
COMMANDS:
list pretty print bucket lifecycle configuration
ls list lifecycle configuration rules set on a bucket
add add a lifecycle configuration rule to existing (if any) rule(s) on a bucket
remove remove (if any) existing lifecycle configuration rule with the id
rm remove (if any) existing lifecycle configuration rule
edit modify a lifecycle configuration rule with given id
export export lifecycle configuration in JSON format
import import lifecycle configuration in JSON format
Expand All @@ -1273,7 +1274,7 @@ FLAGS:
*Example: List the lifecycle management rules*

```
mc ilm list myminio/testbucket
mc ilm ls myminio/testbucket
ID | Prefix | Enabled | Expiry | Date/Days | Transition | Date/Days | Storage-Class | Tags
---------|--------|---------|--------|--------------|------------|-----------|---------------|------
Devices | dev/ | ✓ | ✓ | 17 Sep 2020 | ✗ | | |
Expand All @@ -1283,16 +1284,21 @@ mc ilm list myminio/testbucket
For more details about the lifecycle configuration, refer to official AWS S3 documentation [here](https://docs.aws.amazon.com/AmazonS3/latest/dev/intro-lifecycle-rules.html)


*Example: Add rule for testbucket on play*
*Example: Add rule for prefix "dev" in bucket "testbucket" on play and transition after 2 days to transition tier specified by storage class label "hdd_tier". "hdd_tier" is the label specified when setting up MinIO transition target via `mc admin bucket remote add` command*
```
mc ilm add --id "Devices" --prefix "dev/" --expiry-date "2020-09-17" play/testbucket
Lifecycle configuration rule added with ID `Devices` to play/testbucket.
mc ilm add --expiry-date "2020-09-17" play/testbucket/dev --transition-days 2 --storage-class "hdd_tier"
Lifecycle configuration rule added with ID `btd6pdot8748n94elvl0` to play/testbucket/dev.
```
*Example: Edit the lifecycle management configuration rule given by ID "btd6pdot8748n94elvl0" to set tags*
```
mc ilm edit --id "Documents" --tags "k1=v1&k2=v2" play/testbucket/dev
Lifecycle configurtaion rule with ID `btd6pdot8748n94elvl0` modified to play/testbucket/dev.
```

*Example: Remove the lifecycle management configuration rule given by ID "Documents"*
```
mc ilm remove --id "Documents" play/testbucket
Rule ID `Documents` from target play/testbucket removed.
mc ilm rm --id "Documents" play/testbucket/dev
Rule ID `Documents` from target play/testbucket/dev removed.
```

<a name="policy"></a>
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/minio/cli v1.22.0
github.com/minio/minio v0.0.0-20201102034248-d8e07f2c41c8
github.com/minio/minio-go/v7 v7.0.6-0.20200929220449-755b5633803a
github.com/minio/minio-go/v7 v7.0.6-0.20201013215222-14baba9e61ac
github.com/minio/sha256-simd v0.1.1
github.com/mitchellh/go-homedir v1.1.0
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
Expand All @@ -37,3 +37,5 @@ require (
)

replace go.etcd.io/etcd/v3 => go.etcd.io/etcd/v3 v3.3.0-rc.0.0.20200707003333-58bb8ae09f8e

replace github.com/minio/minio => ../minio
Loading

0 comments on commit a479f80

Please sign in to comment.