Skip to content

Commit

Permalink
feat: adding proxy timeout config to legacy (#433)
Browse files Browse the repository at this point in the history
* feat: adding proxy timeout config to legacy

* fix: adding error handler to orgbook

Some requests can return an error due to the amount of requests being done to orgbook.

* fix: updating timeout for legacy

* fix: reworking report to be automatically generated

* chore: fixing tests

* chore: changing cleaning and resources

- increasing resource to prevent out of memory
- adding a remove endpoint to clean old reports
- adding PVC to report folder
- increased the time between report cleaning
- increased test coverage
  • Loading branch information
Paulo Gomes da Cruz Junior authored Apr 21, 2023
1 parent 0dd61d3 commit 7985962
Show file tree
Hide file tree
Showing 9 changed files with 313 additions and 157 deletions.
2 changes: 1 addition & 1 deletion backend/src/test/java/ca/bc/gov/app/TestConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ public class TestConstants {
"requestType":"",
"name":"Auric Enterprises",
"clientType":"A",
"updated":" | 2023-04-19",
"updated":" | %s",
"status":"Submitted"
}
]""";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import ca.bc.gov.app.utils.ClientSubmissionAggregator;
import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
import java.net.URI;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
Expand Down Expand Up @@ -182,7 +184,8 @@ void shouldListAndSearch(
.expectStatus().isOk()
.expectBody()
.json(found ?
TestConstants.SUBMISSION_LIST_CONTENT :
String.format(TestConstants.SUBMISSION_LIST_CONTENT, LocalDate.now().format(
DateTimeFormatter.ISO_DATE)) :
TestConstants.SUBMISSION_LIST_CONTENT_EMPTY
);
}
Expand Down
3 changes: 0 additions & 3 deletions frontend/.vscode/extensions.json

This file was deleted.

24 changes: 19 additions & 5 deletions legacy/openshift.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ objects:
requests:
storage: ${CERT_PVC_SIZE}
storageClassName: netapp-file-standard
- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
labels:
app: ${NAME}-${ZONE}
name: ${NAME}-${ZONE}-${COMPONENT}-reports
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 125Mi
storageClassName: netapp-file-standard
- apiVersion: v1
kind: DeploymentConfig
metadata:
Expand Down Expand Up @@ -102,8 +115,9 @@ objects:
- name: ${NAME}-${ZONE}-certs
persistentVolumeClaim:
claimName: ${NAME}-${ZONE}-${COMPONENT}
- name: reports
emptyDir: { }
- name: ${NAME}-${ZONE}-reports
persistentVolumeClaim:
claimName: ${NAME}-${ZONE}-${COMPONENT}-reports
initContainers:
- name: ${NAME}-init
image: ${REGISTRY}/bcgov/${NAME}/common:${ZONE}
Expand All @@ -127,10 +141,10 @@ objects:
resources:
limits:
cpu: ${CPU_LIMIT}
memory: 75Mi
memory: 125Mi
requests:
cpu: ${CPU_REQUEST}
memory: 75Mi
memory: 125Mi
containers:
- image: ${NAME}-${ZONE}-${COMPONENT}:${IMAGE_TAG}
imagePullPolicy: Always
Expand Down Expand Up @@ -220,7 +234,7 @@ objects:
- mountPath: /cert
name: ${NAME}-${ZONE}-certs
- mountPath: /workspace/temp
name: reports
name: ${NAME}-${ZONE}-reports
- apiVersion: v1
kind: Service
metadata:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,28 @@

import ca.bc.gov.app.service.ReportingClientService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.io.File;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ZeroCopyHttpOutputMessage;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

Expand All @@ -23,42 +33,60 @@
name = "Forest Client Reporting",
description = "Generate reports for the forest client"
)
@RequestMapping(value = "/api/reports", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@RequestMapping(value = "/api/reports")
@RequiredArgsConstructor
public class ReportingClientController {

private final ReportingClientService service;

@GetMapping("/all")
@Operation(summary = "Get an excel report file for all existing forest clients")
@GetMapping(value = "/{id}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@Operation(summary = "Get an excel report file")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Excel file generated successfully"),
@ApiResponse(responseCode = "500", description = "Internal server error")
@ApiResponse(responseCode = "404", description = "No report found for ID 00000000")
})
public Mono<Void> getAllClientsReport(ServerHttpResponse response) {
return
getReport(
service.generateAllClientsReport(),
response,
"All Clients"
);
public Mono<Void> getReport(
@Parameter(name = "id", in = ParameterIn.PATH, description = "ID of the report to be downloaded")
@PathVariable String id,
ServerHttpResponse response
) {
return getReport(service.getReportFile(id), response, id);
}

@GetMapping("/businessAs")
@Operation(summary = "Get a business as excel report file")
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "List Existing Report Files")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Excel file generated successfully"),
@ApiResponse(responseCode = "500", description = "Internal server error")
@ApiResponse(
responseCode = "200",
description = "A list of available reports",
content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
array = @ArraySchema(
schema = @Schema(implementation = String.class)
)
)
)
})
public Mono<Void> getBusinessAsReport(ServerHttpResponse response) {
return
getReport(
service.generateDoingBusinessAsReport(),
response,
"Business As"
);
public Mono<List<String>> listReports() {
return service.listReports().collectList();
}

@DeleteMapping(value = "/{id}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@Operation(summary = "Delete an excel report file")
@ApiResponses(value = {
@ApiResponse(responseCode = "202", description = "Excel file deleted successfully"),
@ApiResponse(responseCode = "404", description = "No report found for ID 00000000")
})
@ResponseStatus(HttpStatus.ACCEPTED)
public Mono<Void> removeReport(
@Parameter(name = "id", in = ParameterIn.PATH, description = "ID of the report to be removed")
@PathVariable String id,
ServerHttpResponse response
) {
return service.removeReport(id);
}


private Mono<Void> getReport(Mono<File> request, ServerHttpResponse response, String fileName) {
ZeroCopyHttpOutputMessage zeroCopyResponse = (ZeroCopyHttpOutputMessage) response;
zeroCopyResponse.getHeaders()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ca.bc.gov.app.exception;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.server.ResponseStatusException;

@ResponseStatus(HttpStatus.NOT_FOUND)
public class MissingReportFileException extends ResponseStatusException {
public MissingReportFileException(String reportId) {
super(HttpStatus.NOT_FOUND, "No report found for ID " + reportId);
}
}
Loading

0 comments on commit 7985962

Please sign in to comment.