github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/avs/internal_eval_assistant.go (about) 1 package avs 2 3 import ( 4 "time" 5 6 "github.com/kyma-project/kyma-environment-broker/internal" 7 "github.com/kyma-project/kyma-environment-broker/internal/broker" 8 ) 9 10 type InternalEvalAssistant struct { 11 avsConfig Config 12 retryConfig *RetryConfig 13 } 14 15 func NewInternalEvalAssistant(avsConfig Config) *InternalEvalAssistant { 16 return &InternalEvalAssistant{ 17 avsConfig: avsConfig, 18 retryConfig: &RetryConfig{maxTime: 10 * time.Minute, retryInterval: 30 * time.Second}, 19 } 20 } 21 22 func (iec *InternalEvalAssistant) CreateBasicEvaluationRequest(operations internal.Operation, url string) (*BasicEvaluationCreateRequest, error) { 23 return newBasicEvaluationCreateRequest(operations, iec, url) 24 } 25 26 func (iec *InternalEvalAssistant) IsAlreadyCreated(lifecycleData internal.AvsLifecycleData) bool { 27 return lifecycleData.AvsEvaluationInternalId != 0 28 } 29 30 func (iec *InternalEvalAssistant) IsValid(lifecycleData internal.AvsLifecycleData) bool { 31 return iec.IsAlreadyCreated(lifecycleData) && !iec.IsAlreadyDeletedOrEmpty(lifecycleData) 32 } 33 34 func (iec *InternalEvalAssistant) ProvideSuffix() string { 35 return "int" 36 } 37 38 func (iec *InternalEvalAssistant) ProvideTesterAccessId(pp internal.ProvisioningParameters) int64 { 39 if (broker.IsTrialPlan(pp.PlanID) || broker.IsFreemiumPlan(pp.PlanID)) && iec.avsConfig.IsTrialConfigured() { 40 return iec.avsConfig.TrialInternalTesterAccessId 41 } 42 return iec.avsConfig.InternalTesterAccessId 43 } 44 45 func (iec *InternalEvalAssistant) ProvideGroupId(pp internal.ProvisioningParameters) int64 { 46 if (broker.IsTrialPlan(pp.PlanID) || broker.IsFreemiumPlan(pp.PlanID)) && iec.avsConfig.IsTrialConfigured() { 47 return iec.avsConfig.TrialGroupId 48 } 49 return iec.avsConfig.GroupId 50 } 51 52 func (iec *InternalEvalAssistant) ProvideParentId(pp internal.ProvisioningParameters) int64 { 53 if (broker.IsTrialPlan(pp.PlanID) || broker.IsFreemiumPlan(pp.PlanID)) && iec.avsConfig.IsTrialConfigured() { 54 return iec.avsConfig.TrialParentId 55 } 56 return iec.avsConfig.ParentId 57 } 58 59 func (iec *InternalEvalAssistant) ProvideCheckType() string { 60 return "" 61 } 62 63 func (iec *InternalEvalAssistant) ProvideTags(operation internal.Operation) []*Tag { 64 65 tags := []*Tag{ 66 { 67 Content: operation.InstanceID, 68 TagClassId: iec.avsConfig.InstanceIdTagClassId, 69 }, 70 { 71 Content: operation.ProvisioningParameters.ErsContext.GlobalAccountID, 72 TagClassId: iec.avsConfig.GlobalAccountIdTagClassId, 73 }, 74 { 75 Content: operation.ProvisioningParameters.ErsContext.SubAccountID, 76 TagClassId: iec.avsConfig.SubAccountIdTagClassId, 77 }, 78 { 79 Content: operation.ProvisioningParameters.PlatformRegion, 80 TagClassId: iec.avsConfig.LandscapeTagClassId, 81 }, 82 { 83 Content: convertAZR(providerCodeByPlan(operation.ProvisioningParameters.PlanID)), 84 TagClassId: iec.avsConfig.ProviderTagClassId, 85 }, 86 { 87 Content: operation.ShootName, 88 TagClassId: iec.avsConfig.ShootNameTagClassId, 89 }, 90 } 91 92 region := "" 93 if operation.ProvisioningParameters.Parameters.Region != nil { 94 region = *operation.ProvisioningParameters.Parameters.Region 95 } else if operation.LastRuntimeState.ClusterSetup != nil { 96 region = operation.LastRuntimeState.ClusterSetup.Metadata.Region 97 } else if operation.LastRuntimeState.ClusterConfig.Region != "" { 98 region = operation.LastRuntimeState.ClusterConfig.Region 99 } else if operation.Region != "" { 100 region = operation.Region 101 } 102 103 tags = append(tags, &Tag{ 104 Content: region, 105 TagClassId: iec.avsConfig.RegionTagClassId, 106 }) 107 108 return tags 109 110 } 111 112 func (iec *InternalEvalAssistant) ProvideNewOrDefaultServiceName(defaultServiceName string) string { 113 if iec.avsConfig.InternalTesterService == "" { 114 return defaultServiceName 115 } 116 return iec.avsConfig.InternalTesterService 117 } 118 119 func (iec *InternalEvalAssistant) SetEvalId(lifecycleData *internal.AvsLifecycleData, evalId int64) { 120 lifecycleData.AvsEvaluationInternalId = evalId 121 } 122 123 func (iec *InternalEvalAssistant) SetEvalStatus(lifecycleData *internal.AvsLifecycleData, status string) { 124 current := lifecycleData.AvsInternalEvaluationStatus.Current 125 if ValidStatus(current) { 126 lifecycleData.AvsInternalEvaluationStatus.Original = current 127 } 128 lifecycleData.AvsInternalEvaluationStatus.Current = status 129 } 130 131 func (iec *InternalEvalAssistant) GetEvalStatus(lifecycleData internal.AvsLifecycleData) string { 132 return lifecycleData.AvsInternalEvaluationStatus.Current 133 } 134 135 func (iec *InternalEvalAssistant) GetOriginalEvalStatus(lifecycleData internal.AvsLifecycleData) string { 136 return lifecycleData.AvsInternalEvaluationStatus.Original 137 } 138 139 func (iec *InternalEvalAssistant) IsInMaintenance(lifecycleData internal.AvsLifecycleData) bool { 140 return lifecycleData.AvsInternalEvaluationStatus.Current == StatusMaintenance 141 } 142 143 func (iec *InternalEvalAssistant) IsAlreadyDeletedOrEmpty(lifecycleData internal.AvsLifecycleData) bool { 144 return lifecycleData.AVSInternalEvaluationDeleted || lifecycleData.AvsEvaluationInternalId == 0 145 } 146 147 func (iec *InternalEvalAssistant) GetEvaluationId(lifecycleData internal.AvsLifecycleData) int64 { 148 return lifecycleData.AvsEvaluationInternalId 149 } 150 151 func (iec *InternalEvalAssistant) SetDeleted(lifecycleData *internal.AvsLifecycleData, deleted bool) { 152 lifecycleData.AVSInternalEvaluationDeleted = deleted 153 } 154 155 func (iec *InternalEvalAssistant) provideRetryConfig() *RetryConfig { 156 return iec.retryConfig 157 }