mc ilm fix some functionality changes (#3221)
This commit is contained in:
@@ -17,6 +17,8 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/cmd/ilm"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
@@ -86,6 +88,10 @@ func mainILMExport(ctx *cli.Context) error {
|
||||
|
||||
ilmCfg, err := client.GetLifecycle()
|
||||
fatalIf(err.Trace(args...), "Unable to get lifecycle configuration")
|
||||
if len(ilmCfg.Rules) == 0 {
|
||||
fatalIf(probe.NewError(errors.New("lifecycle configuration not set")).Trace(urlStr),
|
||||
"Unable to export lifecycle configuration")
|
||||
}
|
||||
|
||||
printMsg(ilmExportMessage{
|
||||
Status: "success",
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ USAGE:
|
||||
{{.HelpName}} TARGET
|
||||
|
||||
DESCRIPTION:
|
||||
Import entire lifecyle configuration from STDIN, input file is expected to be in JSON format.
|
||||
Import entire lifecycle configuration from STDIN, input file is expected to be in JSON format.
|
||||
|
||||
EXAMPLES:
|
||||
1. Set lifecycle configuration for the testbucket on alias 'myminio' to the rules imported from lifecycle.json
|
||||
|
||||
+2
-2
@@ -267,8 +267,8 @@ func mainILMList(ctx *cli.Context) error {
|
||||
fatalIf(err.Trace(args...), "Unable to get lifecycle")
|
||||
|
||||
if len(ilmCfg.Rules) == 0 {
|
||||
fatalIf(probe.NewError(errors.New("lifecyle configuration not set")).Trace(urlStr),
|
||||
"Unable to list lifecyle configuration")
|
||||
fatalIf(probe.NewError(errors.New("lifecycle configuration not set")).Trace(urlStr),
|
||||
"Unable to list lifecycle configuration")
|
||||
}
|
||||
|
||||
printMsg(ilmListMessage{
|
||||
|
||||
+1
-1
@@ -100,7 +100,7 @@ func checkILMRemoveSyntax(ctx *cli.Context) {
|
||||
forceChk := (ilmAll && ilmForce) || (!ilmAll && !ilmForce)
|
||||
if !forceChk {
|
||||
fatalIf(errInvalidArgument(),
|
||||
"It is mandatory to specify --all and --force flag together for mc"+ctx.Command.FullName()+".")
|
||||
"It is mandatory to specify --all and --force flag together for mc "+ctx.Command.FullName()+".")
|
||||
}
|
||||
if ilmAll && ilmForce {
|
||||
return
|
||||
|
||||
@@ -42,7 +42,7 @@ type LifecycleTag struct {
|
||||
Value string `xml:"Value,omitempty" json:"Value,omitempty"`
|
||||
}
|
||||
|
||||
// LifecycleTransition structure - transition details of lifeycle configuration
|
||||
// LifecycleTransition structure - transition details of lifecycle configuration
|
||||
type LifecycleTransition struct {
|
||||
XMLName xml.Name `xml:"Transition" json:"-"`
|
||||
TransitionDate *time.Time `xml:"Date,omitempty" json:"Date,omitempty"`
|
||||
@@ -70,7 +70,7 @@ type LifecycleRuleFilter struct {
|
||||
Tag *LifecycleTag `xml:"Tag,omitempty" json:"-"`
|
||||
}
|
||||
|
||||
// LifecycleExpiration structure - expiration details of lifeycle configuration
|
||||
// LifecycleExpiration structure - expiration details of lifecycle configuration
|
||||
type LifecycleExpiration struct {
|
||||
XMLName xml.Name `xml:"Expiration,omitempty" json:"-"`
|
||||
ExpirationDate *time.Time `xml:"Date,omitempty" json:"Date,omitempty"`
|
||||
|
||||
+5
-2
@@ -74,6 +74,9 @@ func getRightAligned(label string, maxLen int) string {
|
||||
|
||||
// RemoveILMRule - Remove the ILM rule (with ilmID) from the configuration in XML that is provided.
|
||||
func RemoveILMRule(lfcCfg LifecycleConfiguration, ilmID string) (LifecycleConfiguration, *probe.Error) {
|
||||
if len(lfcCfg.Rules) == 0 {
|
||||
return lfcCfg, probe.NewError(fmt.Errorf("lifecycle configuration not set"))
|
||||
}
|
||||
n := 0
|
||||
for _, rule := range lfcCfg.Rules {
|
||||
if rule.ID != ilmID {
|
||||
@@ -81,12 +84,12 @@ func RemoveILMRule(lfcCfg LifecycleConfiguration, ilmID string) (LifecycleConfig
|
||||
n++
|
||||
}
|
||||
}
|
||||
lfcCfg.Rules = lfcCfg.Rules[:n]
|
||||
if n == len(lfcCfg.Rules) && len(lfcCfg.Rules) > 0 {
|
||||
// if there was no filtering then rules will be of same length, means we didn't find
|
||||
// our ilm id return an error here.
|
||||
return lfcCfg, probe.NewError(fmt.Errorf("lifecycle rule for id '%s' not found", ilmID))
|
||||
}
|
||||
lfcCfg.Rules = lfcCfg.Rules[:n]
|
||||
return lfcCfg, nil
|
||||
}
|
||||
|
||||
@@ -181,7 +184,7 @@ func getLifecycleOptions(ctx *cli.Context) lifecycleOptions {
|
||||
}
|
||||
}
|
||||
|
||||
// ApplyNewILMConfig apply new lifecyle rules to existing lifecycle configuration, this
|
||||
// ApplyNewILMConfig apply new lifecycle rules to existing lifecycle configuration, this
|
||||
// function returns modified/overwritten rules if any.
|
||||
func ApplyNewILMConfig(ctx *cli.Context, lfcCfg LifecycleConfiguration) (LifecycleConfiguration, *probe.Error) {
|
||||
opts := getLifecycleOptions(ctx)
|
||||
|
||||
+2
-1
@@ -75,7 +75,7 @@ func validateTranDays(rule LifecycleRule) error {
|
||||
transitionSet := (rule.Transition != nil)
|
||||
transitionDaySet := transitionSet && (rule.Transition.TransitionInDays > 0)
|
||||
if transitionDaySet && rule.Transition.TransitionInDays < 30 && strings.ToLower(rule.Transition.StorageClass) == "standard_ia" {
|
||||
return errors.New("Transition Date/Days are less than or equal to 30 and Storage class is STANDARD_IA")
|
||||
return errors.New("Transition Date/Days are less than or equal to 30 when Storage class is STANDARD_IA")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -148,6 +148,7 @@ func parseTransition(storageClass, transitionDateStr, transitionDayStr string) (
|
||||
} else {
|
||||
return LifecycleTransition{}, probe.NewError(errors.New("if storage class is set a valid transitionDate or transitionDay must be set"))
|
||||
}
|
||||
transition.StorageClass = storageClass
|
||||
}
|
||||
|
||||
return transition, nil
|
||||
|
||||
Reference in New Issue
Block a user