Skip to content

Commit

Permalink
Remove reading artifacts file from standalone feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Thushani-Jayasekera committed Jan 21, 2025
1 parent 016722c commit 85b08af
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 39 deletions.
39 changes: 9 additions & 30 deletions adapter/internal/api/apis_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
"github.com/wso2/product-microgateway/adapter/internal/oasparser/model"
mgw "github.com/wso2/product-microgateway/adapter/internal/oasparser/model"
"github.com/wso2/product-microgateway/adapter/pkg/synchronizer"
sync "github.com/wso2/product-microgateway/adapter/pkg/synchronizer"
)

// API Controller related constants
Expand Down Expand Up @@ -65,14 +64,6 @@ const (
apisArtifactDir string = "apis"
)

func init() {
conf, _ := config.ReadConfigs()
sync.InitializeWorkerPool(conf.ControlPlane.RequestWorkerPool.PoolSize, conf.ControlPlane.RequestWorkerPool.QueueSizePerPool,
conf.ControlPlane.RequestWorkerPool.PauseTimeAfterFailure, conf.Adapter.Truststore.Location,
conf.ControlPlane.SkipSSLVerification, conf.ControlPlane.HTTPClient.RequestTimeOut, conf.ControlPlane.RetryInterval,
conf.ControlPlane.ServiceURL, conf.ControlPlane.Username, conf.ControlPlane.Password)
}

// extractAPIProject accepts the API project as a zip file and returns the extracted content.
// The apictl project must be in zipped format.
// API type is decided by the type field in the api.yaml file.
Expand Down Expand Up @@ -108,7 +99,6 @@ func extractAPIProject(payload []byte) (apiProject mgw.ProjectAPI, err error) {
// ProcessMountedAPIProjects iterates through the api artifacts directory and apply the projects located within the directory.
func ProcessMountedAPIProjects() (err error) {
conf, _ := config.ReadConfigs()
isPaidOrg := false
apisDirName := filepath.FromSlash(conf.Adapter.ArtifactsDirectory + "/" + apisArtifactDir)
files, err := ioutil.ReadDir((apisDirName))
if err != nil {
Expand All @@ -119,23 +109,6 @@ func ProcessMountedAPIProjects() (err error) {
}
}

payload, err := ioutil.ReadFile(apisDirName)
zipReader, err := zip.NewReader(bytes.NewReader(payload), int64(len(payload)))
if err != nil {
loggers.LoggerSync.Errorf("Error occured while unzipping the apictl project. Error: %v", err.Error())
return err
}

deploymentDescriptor, _, err := sync.ReadRootFiles(zipReader)
if err != nil {
loggers.LoggerAPI.Error("Error occured while reading root files ", err)
return err
}

if len(deploymentDescriptor.Data.Deployments) > 0 {
isPaidOrg = deploymentDescriptor.Data.Deployments[0].IsPaidOrg
}

for _, apiProjectFile := range files {
if apiProjectFile.IsDir() {
apiProject := mgw.ProjectAPI{
Expand Down Expand Up @@ -164,8 +137,10 @@ func ProcessMountedAPIProjects() (err error) {
continue
}

// setting false as this feature is not in use
apiProject.IsPaidOrg = false

overrideValue := false
apiProject.IsPaidOrg = isPaidOrg
err = validateAndUpdateXds(apiProject, &overrideValue)
if err != nil {
loggers.LoggerAPI.Errorf("Error while processing api artifact - %s during startup : %v", apiProjectFile.Name(), err)
Expand Down Expand Up @@ -251,7 +226,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{}, apiProject.IsPaidOrg)
_, err = xds.UpdateAPI(vhost, apiProject, environments, common.XdsOptions{})
if err != nil {
return
}
Expand Down Expand Up @@ -313,7 +288,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, apiProject.IsPaidOrg)
deployedRevision, err := xds.UpdateAPI(vhost, apiProject, environments, xdsOptions)
if err != nil {
return deployedRevisionList, fmt.Errorf("%v:%v with UUID \"%v\"", apiYaml.Name, apiYaml.Version, apiYaml.ID)
}
Expand All @@ -332,6 +307,10 @@ func ApplyAPIProjectInStandaloneMode(payload []byte, override *bool) (err error)
if err != nil {
return err
}

// setting false as this feature is not in use
apiProject.IsPaidOrg = false

return validateAndUpdateXds(apiProject, override)
}

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, isPaidOrg bool) (*notifier.DeployedAPIRevision, error) {
xdsOptions common.XdsOptions) (*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, isPaidOrg)
mgwSwagger.GetProdEndpoints().SetEndpointsConfig(apiYaml.EndpointConfig.ProductionEndpoints, apiYaml.EndpointConfig.EndpointType, apiYaml.OrganizationID, apiProject.IsPaidOrg)
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, isPaidOrg)
mgwSwagger.GetSandEndpoints().SetEndpointsConfig(apiYaml.EndpointConfig.SandBoxEndpoints, apiYaml.EndpointConfig.EndpointType, apiYaml.OrganizationID, apiProject.IsPaidOrg)
if !mgwSwagger.GetSandEndpoints().SecurityConfig.Enabled && apiYaml.EndpointConfig.APIEndpointSecurity.Sandbox.Enabled {
mgwSwagger.GetSandEndpoints().SecurityConfig = apiYaml.EndpointConfig.APIEndpointSecurity.Sandbox
}
Expand Down
12 changes: 6 additions & 6 deletions adapter/pkg/synchronizer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ type DeploymentData struct {
// APIDeployment represents an API project that contains zip file name and
// gateway environments (labels) that the project to be deployed
type APIDeployment struct {
APIFile string `json:"apiFile"`
Environments []GatewayLabel `json:"environments"`
APIFile string `json:"apiFile"`
Environments []GatewayLabel `json:"environments"`
// These properties are used by global Adapter
OrganizationID string `json:"organizationId"`
IsPaidOrg bool `json:"isPaidOrg"`
APIContext string `json:"apiContext"`
Version string `json:"version"`
OrganizationID string `json:"organizationId"`
IsPaidOrg bool `json:"isPaidOrg"`
APIContext string `json:"apiContext"`
Version string `json:"version"`
}

// GatewayLabel represents gateway environment name, vhost and deployedTimeStamp of an API project.
Expand Down

0 comments on commit 85b08af

Please sign in to comment.