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 ee509b7
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 42 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
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
2 changes: 1 addition & 1 deletion src/scheduler/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "automatic"
"java.configuration.updateBuildConfiguration": "interactive"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.cloudfoundry.autoscaler.scheduler.conf;

import org.apache.catalina.connector.Connector;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CFHTTPConfiguration {

@Bean
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> httpConnectorCustomizer() {
return factory -> {
Connector connector = new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
connector.setPort(8090);
connector.setSecure(false); // Set to false for HTTP
factory.addAdditionalTomcatConnectors(connector);
};
}
}
3 changes: 3 additions & 0 deletions src/scheduler/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ scheduler:
############################################################

server:
port: 8083
http:
port: 8090
ssl:
ciphers: TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
enabled-protocols: TLSv1.3
Expand Down

0 comments on commit ee509b7

Please sign in to comment.