Skip to content

Commit

Permalink
set circuitbreaker if org is paid
Browse files Browse the repository at this point in the history
  • Loading branch information
Thushani-Jayasekera committed Dec 11, 2024
1 parent b300035 commit 071bf3c
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 19 deletions.
5 changes: 3 additions & 2 deletions adapter/internal/api/apis_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func validateAndUpdateXds(apiProject mgw.ProjectAPI, override *bool) (err error)

// TODO: (renuka) optimize to update cache only once when all internal memory maps are updated
for vhost, environments := range vhostToEnvsMap {
_, err = xds.UpdateAPI(vhost, apiProject, environments, common.XdsOptions{})
_, err = xds.UpdateAPI(vhost, apiProject, environments, common.XdsOptions{}, synchronizer.ChoreoComponentInfo{})
if err != nil {
return
}
Expand All @@ -238,6 +238,7 @@ func ApplyAPIProjectFromAPIM(
vhostToEnvsMap map[string][]*synchronizer.GatewayLabel,
apiEnvs map[string]map[string]synchronizer.APIEnvProps,
xdsOptions common.XdsOptions,
choreoComponentInfo synchronizer.ChoreoComponentInfo,
) (deployedRevisionList []*notifier.DeployedAPIRevision, err error) {
apiProject, err := extractAPIProject(payload)
if err != nil {
Expand Down Expand Up @@ -283,7 +284,7 @@ func ApplyAPIProjectFromAPIM(
loggers.LoggerAPI.Debugf("Update all environments (%v) of API %v %v:%v with UUID \"%v\".",
environments, vhost, apiYaml.Name, apiYaml.Version, apiYaml.ID)
// first update the API for vhost
deployedRevision, err := xds.UpdateAPI(vhost, apiProject, environments, xdsOptions)
deployedRevision, err := xds.UpdateAPI(vhost, apiProject, environments, xdsOptions, choreoComponentInfo)
if err != nil {
return deployedRevisionList, fmt.Errorf("%v:%v with UUID \"%v\"", apiYaml.Name, apiYaml.Version, apiYaml.ID)
}
Expand Down
6 changes: 3 additions & 3 deletions adapter/internal/discovery/xds/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func DeployReadinessAPI(envs []string) {

// UpdateAPI updates the Xds Cache when OpenAPI Json content is provided
func UpdateAPI(vHost string, apiProject mgw.ProjectAPI, deployedEnvironments []*synchronizer.GatewayLabel,
xdsOptions common.XdsOptions) (*notifier.DeployedAPIRevision, error) {
xdsOptions common.XdsOptions, apiChoreoComponentInfo synchronizer.ChoreoComponentInfo) (*notifier.DeployedAPIRevision, error) {

var mgwSwagger mgw.MgwSwagger
var deployedRevision *notifier.DeployedAPIRevision
Expand Down Expand Up @@ -372,14 +372,14 @@ func UpdateAPI(vHost string, apiProject mgw.ProjectAPI, deployedEnvironments []*
apiHashValue := generateHashValue(apiYaml.Name, apiYaml.Version)

if mgwSwagger.GetProdEndpoints() != nil {
mgwSwagger.GetProdEndpoints().SetEndpointsConfig(apiYaml.EndpointConfig.ProductionEndpoints, apiYaml.EndpointConfig.EndpointType, apiYaml.OrganizationID)
mgwSwagger.GetProdEndpoints().SetEndpointsConfig(apiYaml.EndpointConfig.ProductionEndpoints, apiYaml.EndpointConfig.EndpointType, apiYaml.OrganizationID, apiChoreoComponentInfo.IsChoreoOrgPaid)
if !mgwSwagger.GetProdEndpoints().SecurityConfig.Enabled && apiYaml.EndpointConfig.APIEndpointSecurity.Production.Enabled {
mgwSwagger.GetProdEndpoints().SecurityConfig = apiYaml.EndpointConfig.APIEndpointSecurity.Production
}
}

if mgwSwagger.GetSandEndpoints() != nil {
mgwSwagger.GetSandEndpoints().SetEndpointsConfig(apiYaml.EndpointConfig.SandBoxEndpoints, apiYaml.EndpointConfig.EndpointType, apiYaml.OrganizationID)
mgwSwagger.GetSandEndpoints().SetEndpointsConfig(apiYaml.EndpointConfig.SandBoxEndpoints, apiYaml.EndpointConfig.EndpointType, apiYaml.OrganizationID, apiChoreoComponentInfo.IsChoreoOrgPaid)
if !mgwSwagger.GetSandEndpoints().SecurityConfig.Enabled && apiYaml.EndpointConfig.APIEndpointSecurity.Sandbox.Enabled {
mgwSwagger.GetSandEndpoints().SecurityConfig = apiYaml.EndpointConfig.APIEndpointSecurity.Sandbox
}
Expand Down
12 changes: 7 additions & 5 deletions adapter/internal/oasparser/model/mgw_swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ type MgwSwagger struct {

// ChoreoComponentInfo represents the information of the Choreo component
type ChoreoComponentInfo struct {
OrganizationID string
ProjectID string
ComponentID string
VersionID string
OrganizationID string
ProjectID string
ComponentID string
VersionID string
IsChoreoOrgPaid bool
}

// EndpointCluster represent an upstream cluster
Expand Down Expand Up @@ -643,7 +644,7 @@ func (swagger *MgwSwagger) setXWso2Endpoints() error {
}

// SetEndpointsConfig set configs for Endpoints sent by api.yaml
func (endpointCluster *EndpointCluster) SetEndpointsConfig(endpointInfos []EndpointInfo, apiType string, orgID string) error {
func (endpointCluster *EndpointCluster) SetEndpointsConfig(endpointInfos []EndpointInfo, apiType string, orgID string, isChoreoOrgPaid bool) error {
if endpointInfos == nil || len(endpointInfos) == 0 {
return nil
}
Expand Down Expand Up @@ -685,6 +686,7 @@ func (endpointCluster *EndpointCluster) SetEndpointsConfig(endpointInfos []Endpo
var selectedCircuitBreaker *CircuitBreakers

for _, circuitBreaker := range conf.Envoy.Upstream.CircuitBreakers {
// check ispaidorg from here
if utills.GetIsOrganizationInList(orgID, circuitBreaker.Organizations) {
selectedCircuitBreaker = createCircuitBreaker(
circuitBreaker.MaxConnections,
Expand Down
9 changes: 5 additions & 4 deletions adapter/internal/oasparser/model/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,11 @@ type apiData struct {
}

type choreoComponentInfo struct {
OrganizationID string `json:"organizationId,omitempty"`
ProjectID string `json:"projectId,omitempty"`
ComponentID string `json:"componentId,omitempty"`
VersionID string `json:"versionId,omitempty"`
OrganizationID string `json:"organizationId,omitempty"`
ProjectID string `json:"projectId,omitempty"`
ComponentID string `json:"componentId,omitempty"`
VersionID string `json:"versionId,omitempty"`
IsChoreoOrgPaid bool `json:"isChoreoOrgPaid,omitempty"`
}

type backendJWTConfiguration struct {
Expand Down
6 changes: 4 additions & 2 deletions adapter/internal/synchronizer/apis_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ func PushAPIProjects(payload []byte, environments []string, xdsOptions common.Xd
return err
}

choreoComponentInfo := deployment.ChoreoComponentInfo

vhostToEnvsMap := make(map[string][]*synchronizer.GatewayLabel)
for index := range deployment.Environments {
env := deployment.Environments[index]
Expand All @@ -113,7 +115,7 @@ func PushAPIProjects(payload []byte, environments []string, xdsOptions common.Xd
// Pass the byte slice for the XDS APIs to push it to the enforcer and router
// TODO: (renuka) optimize applying API project, update maps one by one and apply xds once
var deployedRevisionList []*notifier.DeployedAPIRevision
deployedRevisionList, err = apiServer.ApplyAPIProjectFromAPIM(apiFileData, vhostToEnvsMap, envProps, xdsOptions)
deployedRevisionList, err = apiServer.ApplyAPIProjectFromAPIM(apiFileData, vhostToEnvsMap, envProps, xdsOptions, choreoComponentInfo)
if err != nil {
logger.LoggerSync.Errorf("Error occurred while applying project %v", err)
} else if deployedRevisionList != nil {
Expand All @@ -123,7 +125,7 @@ func PushAPIProjects(payload []byte, environments []string, xdsOptions common.Xd

// TODO: (renuka) notify the revision deployment to the control plane once all chunks are deployed.
// This is not fixed as notify the control plane chunk by chunk (even though the chunk is not really applied to the Enforcer and Router) is not a drastic issue.
// This path is only happening when Adapter is restarting and at that time the deployed time is already updated in the control plane.
// This path is only happening when Adapter is restarting and at that time the deployed time is already updated in the control plane.
notifier.SendRevisionUpdate(deploymentList)
logger.LoggerSync.Infof("Successfully deployed %d API/s", len(deploymentList))
// Error nil for successful execution
Expand Down
15 changes: 12 additions & 3 deletions adapter/pkg/synchronizer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ type APIDeployment struct {
APIFile string `json:"apiFile"`
Environments []GatewayLabel `json:"environments"`
// These properties are used by global Adapter
OrganizationID string `json:"organizationId"`
APIContext string `json:"apiContext"`
Version string `json:"version"`
OrganizationID string `json:"organizationId"`
ChoreoComponentInfo ChoreoComponentInfo `json:"choreoComponentInfo"`
APIContext string `json:"apiContext"`
Version string `json:"version"`
}

// GatewayLabel represents gateway environment name, vhost and deployedTimeStamp of an API project.
Expand All @@ -68,6 +69,14 @@ type GatewayLabel struct {
DeploymentType string `json:"deploymentType"`
}

type ChoreoComponentInfo struct {
OrganizationId string `json:"organizationId"`
ProjectId string `json:"projectId"`
ComponentId string `json:"componentId"`
VersionId string `json:"versionId"`
IsChoreoOrgPaid bool `json:"isChoreoOrgPaid"` // isPaidOrg
}

// APIConfigs represents env properties belongs to the API
type APIConfigs struct {
ProductionEndpoint string `mapstructure:"productionEndpoint,omitempty"`
Expand Down

0 comments on commit 071bf3c

Please sign in to comment.