Skip to content

Commit

Permalink
WIP: Integration test for api - scheduler cf http server endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
bonzofenix committed Dec 29, 2024
1 parent 1f586b4 commit a722abc
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var _ = Describe("Integration_GolangApi_Scheduler", func() {
stopScheduler()
})

Describe("When offered as a service", func() {
When("offered as a service", func() {

BeforeEach(func() {
golangApiServerConfPath := components.PrepareGolangApiServerConfig(
Expand Down Expand Up @@ -483,6 +483,52 @@ var _ = Describe("Integration_GolangApi_Scheduler", func() {

})
})

Describe("When scheduler responding on cf server via http", func() {
BeforeEach(func() {
golangApiServerConfPath := components.PrepareGolangApiServerConfig(
dbUrl,
components.Ports[GolangAPIServer],
components.Ports[GolangServiceBroker],
fakeCCNOAAUAA.URL(),
fmt.Sprintf("https://127.0.0.1:%d", components.Ports[Scheduler]),
fmt.Sprintf("https://127.0.0.1:%d", components.Ports[ScalingEngine]),
fmt.Sprintf("https://127.0.0.1:%d", components.Ports[EventGenerator]),
"https://127.0.0.1:8888",
tmpDir)

startGolangApiServer(golangApiServerConfPath)

})
When("binding to it", func() {
var (
defaultPolicy []byte
err error
resp *http.Response
)
BeforeEach(func() {
defaultPolicy = setPolicyRecurringDate(readPolicyFromFile("fakePolicyWithSchedule.json"))
})

JustBeforeEach(func() {
resp, err = bindService(bindingId, appId, serviceInstanceId, nil, components.Ports[GolangServiceBroker], httpClientForPublicApi)
Expect(err).NotTo(HaveOccurred(), "Error: %s", err)
Expect(resp.StatusCode).To(Equal(http.StatusCreated), ResponseMessage(resp))
defer func() { _ = resp.Body.Close() }()

})

AfterEach(func() {
unbindAndDeProvision(bindingId, appId, serviceInstanceId, components.Ports[GolangServiceBroker], httpClientForPublicApi)
})

FIt("creates a policy and associated schedules", func() {
By("setting the default policy on apps without an explicit one")
checkApiServerContent(appId, defaultPolicy, http.StatusOK, components.Ports[GolangAPIServer], httpClientForPublicApi)
assertScheduleContents(appId, http.StatusOK, map[string]int{"recurring_schedule": 4, "specific_date": 2})
})
})
})
})

func ResponseMessage(resp *http.Response) string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

import org.apache.catalina.connector.Connector;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.cloudfoundry.autoscaler.scheduler.filter.XfccFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CFHTTPConfiguration {
private Logger logger = LoggerFactory.getLogger(this.getClass());

@Bean
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> httpConnectorCustomizer() {
Expand All @@ -18,4 +23,15 @@ public WebServerFactoryCustomizer<TomcatServletWebServerFactory> httpConnectorCu
factory.addAdditionalTomcatConnectors(connector);
};
}

@Bean
public FilterRegistrationBean<XfccFilter> xfccFilterRegistration(XfccFilter xfccFilter) {
FilterRegistrationBean<XfccFilter> registrationBean = new FilterRegistrationBean<>();
registrationBean.setFilter(xfccFilter);
registrationBean.addUrlPatterns("/*"); // Apply filter to all incoming requests
registrationBean.setOrder(1); // Set filter precedence

logger.info("Registering XFCC Filter for CF Server");
return registrationBean;
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@

@Component
public class XfccFilter extends OncePerRequestFilter {

@Value("${approved.space.guid}")
@Value("${cfserver.validSpaceGuid}")
private String validSpaceGuid;

@Value("${approved.org.guid}")
@Value("${cfserver.validOrgGuid}")
private String validOrgGuid;


@Override
protected void doFilterInternal(HttpServletRequest request,
HttpServletResponse response, FilterChain filterChain)
Expand Down
2 changes: 1 addition & 1 deletion src/scheduler/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,6 @@ server:
# Unified cf Server - XFCC
############################################################

cf-server:
cfserver:
validOrgGuid: "some-org-guid"
validSpaceGuid: "some-space-guid"

0 comments on commit a722abc

Please sign in to comment.