Skip to content

Commit

Permalink
Updated VSCode settings and added HTTP configuration for scheduler
Browse files Browse the repository at this point in the history
 • Changed VSCode Java build configuration setting from automatic to interactive
 • Added new CFHTTPConfiguration class to configure additional Tomcat connector for HTTP on port 8090
 • Set server port to 8083 and added HTTP port configuration in application.yml
  • Loading branch information
bonzofenix committed Dec 29, 2024
1 parent 211ea58 commit 1f586b4
Show file tree
Hide file tree
Showing 13 changed files with 224 additions and 175 deletions.
4 changes: 2 additions & 2 deletions jobs/scalingengine/spec
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ properties:
default: 8080

autoscaler.cf_server.xfcc.valid_org_guid:
description: approve org guid for xfcc endpoint
description: allowed org guid for xfcc endpoint
default: ''

autoscaler.cf_server.xfcc.valid_space_guid:
description: approve space guid for xfcc endpoint
description: allowed space guid for xfcc endpoint
default: ''

autoscaler.scalingengine.health.port:
Expand Down
3 changes: 2 additions & 1 deletion jobs/scheduler/templates/scheduler.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,15 @@ scheduler:
############################################################
server:
port: <%=p('autoscaler.scheduler.port') %>
http:
port: <%=p('autoscaler.cf_server.port') %>
ssl:
ciphers: TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
enabled-protocols: TLSv1.3
bundle: "server"
client-auth: NEED

cf-server:
port: <%=p('autoscaler.cf_server.port') %>
validOrgGuid: <%= p("autoscaler.cf_server.xfcc.valid_org_guid") %>
validSpaceGuid: <%= p("autoscaler.cf_server.xfcc.valid_space_guid") %>

Expand Down
29 changes: 27 additions & 2 deletions operations/use-cf-services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
client_secret: ((routing_api_client_secret))
client_private_key: ((!routing_api_tls_client_private_key))
server_ca_cert: ((!routing_api_server_ca_cert))
api_url: https://api.((system_domain)):443
oauth_url: https://uaa.((system_domain)):443
api_url: "https://api.((system_domain)):443"
oauth_url: "https://uaa.((system_domain)):443"
routes:
- name: ((deployment_name))_postgres
registration_interval: 5s
Expand Down Expand Up @@ -77,3 +77,28 @@
uris:
- ((deployment_name))-cf-scalingengine.((system_domain))

## EVENTGENERATOR - Enable cf Server to receive calls from api running on cf --

- type: replace
path: /instance_groups/name=eventgenerator/jobs/name=eventgenerator/properties/autoscaler/eventgenerator/cf_server?/xfcc?/valid_org_guid?
value: ((autoscaler_cf_server_xfcc_valid_org_guid))

- type: replace
path: /instance_groups/name=eventgenerator/jobs/name=eventgenerator/properties/autoscaler/eventgenerator/cf_server?/xfcc?/valid_space_guid?
value: ((autoscaler_cf_server_xfcc_valid_space_guid))


- type: replace
path: /instance_groups/name=eventgenerator/jobs/name=eventgenerator/properties/autoscaler/eventgenerator/cf_server?/port?
value: &EventGeneratorCfPort 6205

- type: replace
path: /instance_groups/name=postgres/jobs/name=route_registrar/properties/route_registrar/routes/-
value:
name: ((deployment_name))-cf-eventgenerator
registration_interval: 20s
port: *EventGeneratorCfPort
tags:
component: autoscaler_cf_eventgenerator
uris:
- ((deployment_name))-cf-eventgenerator.((system_domain))
102 changes: 63 additions & 39 deletions src/autoscaler/api/cmd/api/api_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main_test

import (
"crypto/rand"
"crypto/rsa"
"fmt"
"io"
"net/http"
Expand All @@ -9,9 +11,9 @@ import (
"strings"

"code.cloudfoundry.org/app-autoscaler/src/autoscaler/api/config"
"code.cloudfoundry.org/app-autoscaler/src/autoscaler/configutil"
"code.cloudfoundry.org/app-autoscaler/src/autoscaler/db"

. "code.cloudfoundry.org/app-autoscaler/src/autoscaler/testhelpers"
"code.cloudfoundry.org/app-autoscaler/src/autoscaler/testhelpers"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -44,9 +46,9 @@ var _ = Describe("Api", func() {

vcapPort = 8080 + GinkgoParallelProcess()

brokerHttpClient = NewServiceBrokerClient()
brokerHttpClient = testhelpers.NewServiceBrokerClient()
healthHttpClient = &http.Client{}
apiHttpClient = NewPublicApiClient()
apiHttpClient = testhelpers.NewPublicApiClient()
cfServerHttpClient = &http.Client{}

serverURL, err = url.Parse(fmt.Sprintf("https://127.0.0.1:%d", cfg.Server.Port))
Expand Down Expand Up @@ -166,7 +168,7 @@ var _ = Describe("Api", func() {

bodyBytes, err := io.ReadAll(rsp.Body)

FailOnError("Read failed", err)
testhelpers.FailOnError("Read failed", err)
if len(bodyBytes) == 0 {
Fail("body empty")
}
Expand Down Expand Up @@ -297,50 +299,72 @@ var _ = Describe("Api", func() {
})

When("running CF server", func() {
XWhen("running in outside cf", func() {})
When("running in CF", func() {
var (
cfInstanceKeyFile string
cfInstanceCertFile string
)

BeforeEach(func() {
os.Setenv("VCAP_APPLICATION", "{}")
os.Setenv("VCAP_SERVICES", getVcapServices())
os.Setenv("PORT", fmt.Sprintf("%d", vcapPort))
runner.Start()
})
AfterEach(func() {
runner.Interrupt()
Eventually(runner.Session, 5).Should(Exit(0))
os.Unsetenv("VCAP_APPLICATION")
os.Unsetenv("VCAP_SERVICES")
os.Unsetenv("PORT")
})
BeforeEach(func() {
rsaPrivateKey, err := rsa.GenerateKey(rand.Reader, 2048)
Expect(err).NotTo(HaveOccurred())

It("should start a cf server", func() {
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/v1/info", cfServerURL), nil)
Expect(err).NotTo(HaveOccurred())
cfInstanceCert, err := testhelpers.GenerateClientCertWithPrivateKey("org-guid", "space-guid", rsaPrivateKey)
Expect(err).NotTo(HaveOccurred())

rsp, err = cfServerHttpClient.Do(req)
Expect(err).ToNot(HaveOccurred())
certTmpDir := os.TempDir()

bodyBytes, err := io.ReadAll(rsp.Body)
Expect(err).ToNot(HaveOccurred())
Expect(bodyBytes).To(ContainSubstring("Automatically increase or decrease the number of application instances based on a policy you define."))
cfInstanceCertFile, err := configutil.MaterializeContentInFile(certTmpDir, "eventgenerator.crt", string(cfInstanceCert))
Expect(err).NotTo(HaveOccurred())
os.Setenv("CF_INSTANCE_CERT", string(cfInstanceCertFile))

req, err = http.NewRequest(http.MethodGet, fmt.Sprintf("%s/v2/catalog", cfServerURL), nil)
Expect(err).NotTo(HaveOccurred())
req.SetBasicAuth(username, password)
cfInstanceKey := testhelpers.GenerateClientKeyWithPrivateKey(rsaPrivateKey)
cfInstanceKeyFile, err = configutil.MaterializeContentInFile(certTmpDir, "eventgenerator.key", string(cfInstanceKey))
Expect(err).NotTo(HaveOccurred())
os.Setenv("CF_INSTANCE_KEY", string(cfInstanceKeyFile))

rsp, err = cfServerHttpClient.Do(req)
Expect(err).ToNot(HaveOccurred())
Expect(rsp.StatusCode).To(Equal(http.StatusOK))
os.Setenv("VCAP_APPLICATION", "{}")
os.Setenv("VCAP_SERVICES", getVcapServices())
os.Setenv("PORT", fmt.Sprintf("%d", vcapPort))
runner.Start()
})
AfterEach(func() {
runner.Interrupt()
Eventually(runner.Session, 5).Should(Exit(0))

bodyBytes, err = io.ReadAll(rsp.Body)
Expect(err).ToNot(HaveOccurred())
Expect(bodyBytes).To(ContainSubstring("autoscaler-free-plan-id"))
})
os.Remove(cfInstanceKeyFile)
os.Remove(cfInstanceCertFile)

os.Unsetenv("CF_INSTANCE_KEY")
os.Unsetenv("CF_INSTANCE_CERT")
os.Unsetenv("VCAP_APPLICATION")
os.Unsetenv("VCAP_SERVICES")
os.Unsetenv("PORT")
})
})

It("should start a cf server", func() {
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/v1/info", cfServerURL), nil)
Expect(err).NotTo(HaveOccurred())

rsp, err = cfServerHttpClient.Do(req)
Expect(err).ToNot(HaveOccurred())

bodyBytes, err := io.ReadAll(rsp.Body)
Expect(err).ToNot(HaveOccurred())
Expect(bodyBytes).To(ContainSubstring("Automatically increase or decrease the number of application instances based on a policy you define."))

req, err = http.NewRequest(http.MethodGet, fmt.Sprintf("%s/v2/catalog", cfServerURL), nil)
Expect(err).NotTo(HaveOccurred())
req.SetBasicAuth(username, password)

rsp, err = cfServerHttpClient.Do(req)
Expect(err).ToNot(HaveOccurred())
Expect(rsp.StatusCode).To(Equal(http.StatusOK))

bodyBytes, err = io.ReadAll(rsp.Body)
Expect(err).ToNot(HaveOccurred())
Expect(bodyBytes).To(ContainSubstring("autoscaler-free-plan-id"))
})
})
})

func getVcapServices() (result string) {
Expand Down
11 changes: 3 additions & 8 deletions src/autoscaler/api/publicapiserver/public_api_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (s *PublicApiServer) CreateHealthServer() (ifrit.Runner, error) {
return nil, err
}

return helpers.NewHTTPServer(s.logger, s.conf.Health.ServerConfig, s.healthRouter)
return helpers.NewHTTPServer(s.logger.Session("HealthServer"), s.conf.Health.ServerConfig, s.healthRouter)
}

func (s *PublicApiServer) setupBrokerRouter() error {
Expand All @@ -102,22 +102,17 @@ func (s *PublicApiServer) CreateCFServer() (ifrit.Runner, error) {
return nil, err
}

mainRouter := mux.NewRouter()
r := s.autoscalerRouter.GetRouter()
mainRouter.PathPrefix("/v2").Handler(r)
mainRouter.PathPrefix("/v1").Handler(r)
mainRouter.PathPrefix("/health").Handler(r)
mainRouter.PathPrefix("/").Handler(s.healthRouter)

return helpers.NewHTTPServer(s.logger, s.conf.VCAPServer, mainRouter)
return helpers.NewHTTPServer(s.logger.Session("CfServer"), s.conf.VCAPServer, r)
}

func (s *PublicApiServer) CreateMtlsServer() (ifrit.Runner, error) {
if err := s.setupApiRoutes(); err != nil {
return nil, err
}

return helpers.NewHTTPServer(s.logger, s.conf.Server, s.autoscalerRouter.GetRouter())
return helpers.NewHTTPServer(s.logger.Session("MtlsServer"), s.conf.Server, s.autoscalerRouter.GetRouter())
}

func (s *PublicApiServer) setupApiProtectedRoutes(pah *PublicApiHandler, scalingHistoryHandler http.Handler) {
Expand Down
3 changes: 3 additions & 0 deletions src/autoscaler/build-extension-file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export POSTGRES_EXTERNAL_PORT="${PR_NUMBER:-5432}"
export METRICSFORWARDER_HOST="${METRICSFORWARDER_HOST:-"${DEPLOYMENT_NAME}-metricsforwarder"}"
export METRICSFORWARDER_MTLS_HOST="${METRICSFORWARDER_MTLS_HOST:-"${DEPLOYMENT_NAME}-metricsforwarder-mtls"}"
export SCALINGENGINE_HOST="${SCALINGENGINE_HOST:-"${DEPLOYMENT_NAME}-cf-scalingengine"}"
export EVENTGENERATOR_HOST="${EVENTGENERATOR_HOST:-"${DEPLOYMENT_NAME}-cf-eventgenerator"}"
export PUBLICAPISERVER_HOST="${PUBLICAPISERVER_HOST:-"${DEPLOYMENT_NAME}"}"
export SERVICEBROKER_HOST="${SERVICEBROKER_HOST:-"${DEPLOYMENT_NAME}servicebroker"}"

Expand Down Expand Up @@ -116,4 +117,6 @@ resources:
metrics_forwarder_mtls_url: ${METRICSFORWARDER_MTLS_HOST}.\${default-domain}
scaling_engine:
scaling_engine_url: ${SCALINGENGINE_HOST}.\${default-domain}
event_generator:
event_generator_url: ${EVENTGENERATOR_HOST}.\${default-domain}
EOF
Loading

0 comments on commit 1f586b4

Please sign in to comment.