github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/avs/evaluation_manager.go (about)

     1  package avs
     2  
     3  import (
     4  	"github.com/kyma-project/kyma-environment-broker/internal"
     5  	"github.com/sirupsen/logrus"
     6  )
     7  
     8  type EvaluationManager struct {
     9  	avsConfig         Config
    10  	delegator         *Delegator
    11  	internalAssistant *InternalEvalAssistant
    12  	externalAssistant *ExternalEvalAssistant
    13  }
    14  
    15  func NewEvaluationManager(delegator *Delegator, config Config) *EvaluationManager {
    16  	return &EvaluationManager{
    17  		delegator:         delegator,
    18  		avsConfig:         config,
    19  		internalAssistant: NewInternalEvalAssistant(config),
    20  		externalAssistant: NewExternalEvalAssistant(config),
    21  	}
    22  }
    23  
    24  // SetStatus updates evaluation monitors (internal and external) status.
    25  func (em *EvaluationManager) SetStatus(status string, avsData *internal.AvsLifecycleData, logger logrus.FieldLogger) error {
    26  	// do internal monitor status update
    27  	err := em.delegator.SetStatus(logger, avsData, em.internalAssistant, status)
    28  	if err != nil {
    29  		return err
    30  	}
    31  
    32  	// do external monitor status update
    33  	err = em.delegator.SetStatus(logger, avsData, em.externalAssistant, status)
    34  	if err != nil {
    35  		return err
    36  	}
    37  
    38  	return nil
    39  }
    40  
    41  // RestoreStatus reverts previously set evaluation monitors status.
    42  // On error, parent method should fail the operation progress.
    43  // On delay, parent method should retry.
    44  func (em *EvaluationManager) RestoreStatus(avsData *internal.AvsLifecycleData, logger logrus.FieldLogger) error {
    45  	// do internal monitor status reset
    46  	err := em.delegator.ResetStatus(logger, avsData, em.internalAssistant)
    47  	if err != nil {
    48  		return err
    49  	}
    50  
    51  	// do external monitor status reset
    52  	err = em.delegator.ResetStatus(logger, avsData, em.externalAssistant)
    53  	if err != nil {
    54  		return err
    55  	}
    56  
    57  	return nil
    58  }
    59  
    60  func (em *EvaluationManager) SetMaintenanceStatus(avsData *internal.AvsLifecycleData, logger logrus.FieldLogger) error {
    61  	return em.SetStatus(StatusMaintenance, avsData, logger)
    62  }
    63  
    64  func (em *EvaluationManager) InMaintenance(avsData internal.AvsLifecycleData) bool {
    65  	inMaintenance := true
    66  
    67  	// check for internal monitor
    68  	if em.internalAssistant.IsValid(avsData) {
    69  		inMaintenance = inMaintenance && em.internalAssistant.IsInMaintenance(avsData)
    70  	}
    71  
    72  	// check for external monitor
    73  	if em.externalAssistant.IsValid(avsData) {
    74  		inMaintenance = inMaintenance && em.externalAssistant.IsInMaintenance(avsData)
    75  	}
    76  
    77  	return inMaintenance
    78  }
    79  
    80  func (em *EvaluationManager) HasMonitors(avsData internal.AvsLifecycleData) bool {
    81  	return em.internalAssistant.IsValid(avsData) || em.externalAssistant.IsValid(avsData)
    82  }
    83  
    84  func (em *EvaluationManager) IsMaintenanceModeDisabled() bool {
    85  	return em.avsConfig.MaintenanceModeDuringUpgradeDisabled
    86  }
    87  
    88  func (em *EvaluationManager) IsMaintenanceModeApplicableForGAID(gaID string) bool {
    89  	for _, id := range em.avsConfig.MaintenanceModeDuringUpgradeAlwaysDisabledGAIDs {
    90  		if id == gaID {
    91  			return false
    92  		}
    93  	}
    94  	return true
    95  }