Skip to content

Commit

Permalink
APIGOV-28984 Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Deepak Kasu committed Nov 13, 2024
1 parent ab1d16f commit bd215f7
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 39 deletions.
28 changes: 14 additions & 14 deletions pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ type agentData struct {
agentFeaturesCfg config.AgentFeaturesConfig
tokenRequester auth.PlatformTokenGetter

teamMap cache.Cache
cacheManager agentcache.Manager
apiValidator APIValidator
apiValidatorLock sync.Mutex
apiValidatorJobID string
configChangeHandler ConfigChangeHandler
agentResourceChangeHandler ConfigChangeHandler
customUnitMetricServerManager *customunit.CustomUnitHandler
agentShutdownHandler ShutdownHandler
proxyResourceHandler *handler.StreamWatchProxyHandler
isInitialized bool
teamMap cache.Cache
cacheManager agentcache.Manager
apiValidator APIValidator
apiValidatorLock sync.Mutex
apiValidatorJobID string
configChangeHandler ConfigChangeHandler
agentResourceChangeHandler ConfigChangeHandler
customUnitHandler *customunit.CustomUnitHandler
agentShutdownHandler ShutdownHandler
proxyResourceHandler *handler.StreamWatchProxyHandler
isInitialized bool

provisioner provisioning.Provisioning
streamer *stream.StreamerClient
Expand Down Expand Up @@ -168,7 +168,7 @@ func InitializeWithAgentFeatures(centralCfg config.CentralConfig, agentFeaturesC

// call the metric services.
metricServicesConfigs := agentFeaturesCfg.GetMetricServicesConfigs()
agent.customUnitMetricServerManager = customunit.NewCustomUnitMetricServerManager(metricServicesConfigs, agent.cacheManager, centralCfg.GetAgentType())
agent.customUnitHandler = customunit.NewCustomUnitHandler(metricServicesConfigs, agent.cacheManager, centralCfg.GetAgentType())

if !agent.isInitialized {
err = handleInitialization()
Expand Down Expand Up @@ -433,8 +433,8 @@ func GetAuthProviderRegistry() oauth.ProviderRegistry {
return agent.authProviderRegistry
}

func GetCustomUnitMetricServerManager() *customunit.CustomUnitHandler {
return agent.customUnitMetricServerManager
func GetCustomUnitHandler() *customunit.CustomUnitHandler {
return agent.customUnitHandler
}

// RegisterShutdownHandler - Registers shutdown handler
Expand Down
26 changes: 13 additions & 13 deletions pkg/agent/handler/accessrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@ type arProvisioner interface {
AccessRequestProvision(accessRequest prov.AccessRequest) (status prov.RequestStatus, data prov.AccessData)
AccessRequestDeprovision(accessRequest prov.AccessRequest) (status prov.RequestStatus)
}
type customUnitMetricServerManager interface {
type customUnitHandler interface {
HandleQuotaEnforcement(*management.AccessRequest, *management.ManagedApplication) error
}

type accessRequestHandler struct {
marketplaceHandler
prov arProvisioner
cache agentcache.Manager
client client
encryptSchema encryptSchemaFunc
customUnitMetricServerManager customUnitMetricServerManager
prov arProvisioner
cache agentcache.Manager
client client
encryptSchema encryptSchemaFunc
customUnitHandler customUnitHandler
}

// NewAccessRequestHandler creates a Handler for Access Requests
func NewAccessRequestHandler(prov arProvisioner, cache agentcache.Manager, client client, customUnitMetricServerManager customUnitMetricServerManager) Handler {
func NewAccessRequestHandler(prov arProvisioner, cache agentcache.Manager, client client, customUnitHandler customUnitHandler) Handler {
return &accessRequestHandler{
prov: prov,
cache: cache,
client: client,
encryptSchema: encryptSchema,
customUnitMetricServerManager: customUnitMetricServerManager,
prov: prov,
cache: cache,
client: client,
encryptSchema: encryptSchema,
customUnitHandler: customUnitHandler,
}
}

Expand Down Expand Up @@ -139,7 +139,7 @@ func (h *accessRequestHandler) onPending(ctx context.Context, ar *management.Acc
status, accessData := h.prov.AccessRequestProvision(req)

if status.GetStatus() == prov.Success && len(ar.Spec.AdditionalQuotas) > 0 {
err := h.customUnitMetricServerManager.HandleQuotaEnforcement(ar, app)
err := h.customUnitHandler.HandleQuotaEnforcement(ar, app)

if err != nil {
// h.onError(ctx, ar, err)
Expand Down
12 changes: 6 additions & 6 deletions pkg/agent/handler/accessrequest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ func TestAccessRequestHandler(t *testing.T) {
c.isDeleting = true
}
af := config.NewAgentFeaturesConfiguration().GetMetricServicesConfigs()
customUnitMetricServerManager := customunit.NewCustomUnitMetricServerManager(af, cm, config.DiscoveryAgent)
handler := NewAccessRequestHandler(arp, cm, c, customUnitMetricServerManager)
customUnitHandler := customunit.NewCustomUnitHandler(af, cm, config.DiscoveryAgent)
handler := NewAccessRequestHandler(arp, cm, c, customUnitHandler)
v := handler.(*accessRequestHandler)
v.encryptSchema = func(_, _ map[string]interface{}, _, _, _ string) (map[string]interface{}, error) {
return map[string]interface{}{}, nil
Expand Down Expand Up @@ -251,8 +251,8 @@ func TestAccessRequestHandler_deleting(t *testing.T) {
t: t,
}
af := config.NewAgentFeaturesConfiguration().GetMetricServicesConfigs()
customUnitMetricServerManager := customunit.NewCustomUnitMetricServerManager(af, cm, config.DiscoveryAgent)
handler := NewAccessRequestHandler(arp, cm, c, customUnitMetricServerManager)
customUnitHandler := customunit.NewCustomUnitHandler(af, cm, config.DiscoveryAgent)
handler := NewAccessRequestHandler(arp, cm, c, customUnitHandler)

ri, _ := ar.AsInstance()

Expand All @@ -276,8 +276,8 @@ func TestAccessRequestHandler_wrong_kind(t *testing.T) {
}
ar := &mockARProvision{}
af := config.NewAgentFeaturesConfiguration().GetMetricServicesConfigs()
customUnitMetricServerManager := customunit.NewCustomUnitMetricServerManager(af, cm, config.DiscoveryAgent)
handler := NewAccessRequestHandler(ar, cm, c, customUnitMetricServerManager)
customUnitHandler := customunit.NewCustomUnitHandler(af, cm, config.DiscoveryAgent)
handler := NewAccessRequestHandler(ar, cm, c, customUnitHandler)
ri := &v1.ResourceInstance{
ResourceMeta: v1.ResourceMeta{
GroupVersionKind: management.EnvironmentGVK(),
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ func RegisterProvisioner(provisioner provisioning.Provisioning) {
if agent.cfg.GetAgentType() == config.DiscoveryAgent || agent.cfg.GetAgentType() == config.GovernanceAgent {
agent.proxyResourceHandler.RegisterTargetHandler(
"accessrequesthandler",
handler.NewAccessRequestHandler(agent.provisioner, agent.cacheManager, agent.apicClient, agent.customUnitMetricServerManager),
handler.NewAccessRequestHandler(agent.provisioner, agent.cacheManager, agent.apicClient, agent.customUnitHandler),
)
agent.proxyResourceHandler.RegisterTargetHandler(
"managedappHandler",
Expand Down
2 changes: 1 addition & 1 deletion pkg/customunit/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type agentCacheManager interface {
GetManagedApplicationByName(string) *v1.ResourceInstance
}

func NewCustomUnitMetricServerManager(servicesConfigs []config.MetricServiceConfiguration, cache agentCacheManager, agentType config.AgentType) *CustomUnitHandler {
func NewCustomUnitHandler(servicesConfigs []config.MetricServiceConfiguration, cache agentCacheManager, agentType config.AgentType) *CustomUnitHandler {
return &CustomUnitHandler{
servicesConfigs: servicesConfigs,
cache: cache,
Expand Down
6 changes: 3 additions & 3 deletions pkg/customunit/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ const instRefID = "inst-id-1"
const instRefName = "inst-name-1"
const managedAppRefName = "managed-app-name"

func Test_NewCustomUnitMetricServerManager(t *testing.T) {
func Test_NewCustomUnitHandler(t *testing.T) {
metricServicesConfigs := config.NewAgentFeaturesConfiguration().GetMetricServicesConfigs()
cm := agentcache.NewAgentCacheManager(&config.CentralConfiguration{}, false)
handler := NewCustomUnitMetricServerManager(metricServicesConfigs, cm, config.DiscoveryAgent)
handler := NewCustomUnitHandler(metricServicesConfigs, cm, config.DiscoveryAgent)

assert.NotNil(t, handler)
}
Expand Down Expand Up @@ -90,7 +90,7 @@ func Test_HandleQuotaEnforcementInfo(t *testing.T) {
},
}

manager := NewCustomUnitMetricServerManager(metricServicesConfigs, cm, config.DiscoveryAgent)
manager := NewCustomUnitHandler(metricServicesConfigs, cm, config.DiscoveryAgent)
err := manager.HandleQuotaEnforcement(accessReq, managedAppForTest)

assert.Nil(t, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/transaction/metric/metricscollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func GetMetricCollector() Collector {

if globalMetricCollector == nil && util.IsNotTest() {
globalMetricCollector = createMetricCollector()
agent.GetCustomUnitMetricServerManager().HandleMetricReporting(globalMetricCollector)
agent.GetCustomUnitHandler().HandleMetricReporting(globalMetricCollector)

}
return globalMetricCollector
Expand Down

0 comments on commit bd215f7

Please sign in to comment.