refactored large func

This commit is contained in:
2026-06-25 14:16:35 +02:00
parent e1291d1d92
commit d60983411e

View File

@@ -35,6 +35,7 @@ import (
var ( var (
matchDuration = regexp.MustCompile(`(\d+)([dhms])`) matchDuration = regexp.MustCompile(`(\d+)([dhms])`)
IlmPhaseOrder = []string{"hot", "warm", "cold", "frozen", "delete"}
) )
type NextPhase struct { type NextPhase struct {
@@ -161,6 +162,7 @@ func virtualAge(phase *PhaseData) time.Duration {
return time.Duration(virtualAge) * time.Second return time.Duration(virtualAge) * time.Second
} }
// Retrieve all index, ilm-explain and ilm-policies in parallel
func getIlmPhaseData(conf *cfg.Config) ([]PhaseData, error) { func getIlmPhaseData(conf *cfg.Config) ([]PhaseData, error) {
responses := make(chan apiResponse, 3) responses := make(chan apiResponse, 3)
wg := &sync.WaitGroup{} wg := &sync.WaitGroup{}
@@ -254,10 +256,7 @@ func getIlmPhaseData(conf *cfg.Config) ([]PhaseData, error) {
return list, nil return list, nil
} }
func findNextPhase(policy types.IlmPolicy, currentPhase string) *NextPhase { func registerPhases(policy types.IlmPolicy, currentPhase string) (map[string]*types.Phase, int) {
// phase list to determine which comes next
order := []string{"hot", "warm", "cold", "frozen", "delete"}
// register phases configured in the policy // register phases configured in the policy
phases := map[string]*types.Phase{ phases := map[string]*types.Phase{
"hot": nil, "hot": nil,
@@ -271,7 +270,7 @@ func findNextPhase(policy types.IlmPolicy, currentPhase string) *NextPhase {
start := 0 start := 0
// register phases // register phases
for idx, phase := range order { for idx, phase := range IlmPhaseOrder {
switch phase { switch phase {
case "hot": case "hot":
if policy.Phases.Hot != nil { if policy.Phases.Hot != nil {
@@ -304,11 +303,18 @@ func findNextPhase(policy types.IlmPolicy, currentPhase string) *NextPhase {
} }
} }
return phases, start
}
func findNextPhase(policy types.IlmPolicy, currentPhase string) *NextPhase {
// phase list to determine which comes next
phases, start := registerPhases(policy, currentPhase)
nextPhase := &NextPhase{} nextPhase := &NextPhase{}
// finally determine which phase comes next // finally determine which phase comes next
// exception: hot, where we look for rollover rules // exception: hot, where we look for rollover rules
for idx, phase := range order { for idx, phase := range IlmPhaseOrder {
if idx < start { if idx < start {
continue continue
} }