From 1764e48adc240f122aea71429910f3d8d2d76552 Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Mon, 27 Nov 2023 14:56:04 -0700 Subject: [PATCH 01/14] Added mount volume for /tmp --- ...ild.from.developer.branch.deploy.to.dev.yml | 3 ++- .../build.from.main.branch.deploy.to.dev.yml | 3 ++- ...build.from.release.branch.deploy.to.dev.yml | 3 ++- .github/workflows/deploy_prod.yml | 3 ++- .github/workflows/deploy_test.yml | 3 ++- tools/openshift/api.dc.yaml | 18 ++++++++++++++++++ 6 files changed, 28 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.from.developer.branch.deploy.to.dev.yml b/.github/workflows/build.from.developer.branch.deploy.to.dev.yml index 8e79bee..7dba677 100644 --- a/.github/workflows/build.from.developer.branch.deploy.to.dev.yml +++ b/.github/workflows/build.from.developer.branch.deploy.to.dev.yml @@ -27,6 +27,7 @@ env: MAX_MEM: "900Mi" MIN_REPLICAS: "3" MAX_REPLICAS: "5" + STORAGE_LIMIT: 16Gi on: # https://docs.github.com/en/actions/reference/events-that-trigger-workflows @@ -115,7 +116,7 @@ jobs: oc -n ${{ env.OPENSHIFT_NAMESPACE }} tag ${{ steps.push-image.outputs.registry-path }} ${{ env.REPO_NAME }}:${{ env.TAG }} # Process and apply deployment template - oc process -f tools/openshift/api.dc.yaml -p IS_NAMESPACE=${{ env.OPENSHIFT_NAMESPACE }} -p REPO_NAME=${{ env.REPO_NAME }} -p TAG_NAME=${{ env.TAG }} -p HOST_ROUTE=${{ env.REPO_NAME }}-${{ env.OPENSHIFT_NAMESPACE }}.${{ env.APP_DOMAIN }} -p MIN_REPLICAS=${{ env.MIN_REPLICAS }} -p MAX_REPLICAS=${{ env.MAX_REPLICAS }} -p MIN_CPU=${{ env.MIN_CPU }} -p MAX_CPU=${{ env.MAX_CPU }} -p MIN_MEM=${{ env.MIN_MEM }} -p MAX_MEM=${{ env.MAX_MEM }} \ + oc process -f tools/openshift/api.dc.yaml -p IS_NAMESPACE=${{ env.OPENSHIFT_NAMESPACE }} -p REPO_NAME=${{ env.REPO_NAME }} -p TAG_NAME=${{ env.TAG }} -p HOST_ROUTE=${{ env.REPO_NAME }}-${{ env.OPENSHIFT_NAMESPACE }}.${{ env.APP_DOMAIN }} -p MIN_REPLICAS=${{ env.MIN_REPLICAS }} -p MAX_REPLICAS=${{ env.MAX_REPLICAS }} -p MIN_CPU=${{ env.MIN_CPU }} -p MAX_CPU=${{ env.MAX_CPU }} -p MIN_MEM=${{ env.MIN_MEM }} -p MAX_MEM=${{ env.MAX_MEM }} -p STORAGE_LIMIT=${{ env.STORAGE_LIMIT }} \ | oc apply -f - # Start rollout (if necessary) and follow it diff --git a/.github/workflows/build.from.main.branch.deploy.to.dev.yml b/.github/workflows/build.from.main.branch.deploy.to.dev.yml index 1082f7c..7cc629d 100644 --- a/.github/workflows/build.from.main.branch.deploy.to.dev.yml +++ b/.github/workflows/build.from.main.branch.deploy.to.dev.yml @@ -28,6 +28,7 @@ env: MAX_MEM: "900Mi" MIN_REPLICAS: "3" MAX_REPLICAS: "5" + STORAGE_LIMIT: 16Gi on: # https://docs.github.com/en/actions/reference/events-that-trigger-workflows @@ -105,7 +106,7 @@ jobs: oc -n ${{ env.OPENSHIFT_NAMESPACE }} tag ${{ steps.push-image.outputs.registry-path }} ${{ env.REPO_NAME }}:${{ env.TAG }} # Process and apply deployment template - oc process -f tools/openshift/api.dc.yaml -p IS_NAMESPACE=${{ env.OPENSHIFT_NAMESPACE }} -p REPO_NAME=${{ env.REPO_NAME }} -p TAG_NAME=${{ env.TAG }} -p HOST_ROUTE=${{ env.REPO_NAME }}-${{ env.OPENSHIFT_NAMESPACE }}.${{ env.APP_DOMAIN }} -p MIN_REPLICAS=${{ env.MIN_REPLICAS }} -p MAX_REPLICAS=${{ env.MAX_REPLICAS }} -p MIN_CPU=${{ env.MIN_CPU }} -p MAX_CPU=${{ env.MAX_CPU }} -p MIN_MEM=${{ env.MIN_MEM }} -p MAX_MEM=${{ env.MAX_MEM }} \ + oc process -f tools/openshift/api.dc.yaml -p IS_NAMESPACE=${{ env.OPENSHIFT_NAMESPACE }} -p REPO_NAME=${{ env.REPO_NAME }} -p TAG_NAME=${{ env.TAG }} -p HOST_ROUTE=${{ env.REPO_NAME }}-${{ env.OPENSHIFT_NAMESPACE }}.${{ env.APP_DOMAIN }} -p MIN_REPLICAS=${{ env.MIN_REPLICAS }} -p MAX_REPLICAS=${{ env.MAX_REPLICAS }} -p MIN_CPU=${{ env.MIN_CPU }} -p MAX_CPU=${{ env.MAX_CPU }} -p MIN_MEM=${{ env.MIN_MEM }} -p MAX_MEM=${{ env.MAX_MEM }} -p STORAGE_LIMIT=${{ env.STORAGE_LIMIT }} \ | oc apply -f - # Start rollout (if necessary) and follow it diff --git a/.github/workflows/build.from.release.branch.deploy.to.dev.yml b/.github/workflows/build.from.release.branch.deploy.to.dev.yml index 1e231a3..39d670a 100644 --- a/.github/workflows/build.from.release.branch.deploy.to.dev.yml +++ b/.github/workflows/build.from.release.branch.deploy.to.dev.yml @@ -27,6 +27,7 @@ env: MAX_MEM: "900Mi" MIN_REPLICAS: "3" MAX_REPLICAS: "5" + STORAGE_LIMIT: 16Gi on: # https://docs.github.com/en/actions/reference/events-that-trigger-workflows @@ -112,7 +113,7 @@ jobs: oc -n ${{ env.OPENSHIFT_NAMESPACE }} tag ${{ steps.push-image.outputs.registry-path }} ${{ env.REPO_NAME }}:${{ env.TAG }} # Process and apply deployment template - oc process -f tools/openshift/api.dc.yaml -p IS_NAMESPACE=${{ env.OPENSHIFT_NAMESPACE }} -p REPO_NAME=${{ env.REPO_NAME }} -p TAG_NAME=${{ env.TAG }} -p HOST_ROUTE=${{ env.REPO_NAME }}-${{ env.OPENSHIFT_NAMESPACE }}.${{ env.APP_DOMAIN }} -p MIN_REPLICAS=${{ env.MIN_REPLICAS }} -p MAX_REPLICAS=${{ env.MAX_REPLICAS }} -p MIN_CPU=${{ env.MIN_CPU }} -p MAX_CPU=${{ env.MAX_CPU }} -p MIN_MEM=${{ env.MIN_MEM }} -p MAX_MEM=${{ env.MAX_MEM }} \ + oc process -f tools/openshift/api.dc.yaml -p IS_NAMESPACE=${{ env.OPENSHIFT_NAMESPACE }} -p REPO_NAME=${{ env.REPO_NAME }} -p TAG_NAME=${{ env.TAG }} -p HOST_ROUTE=${{ env.REPO_NAME }}-${{ env.OPENSHIFT_NAMESPACE }}.${{ env.APP_DOMAIN }} -p MIN_REPLICAS=${{ env.MIN_REPLICAS }} -p MAX_REPLICAS=${{ env.MAX_REPLICAS }} -p MIN_CPU=${{ env.MIN_CPU }} -p MAX_CPU=${{ env.MAX_CPU }} -p MIN_MEM=${{ env.MIN_MEM }} -p MAX_MEM=${{ env.MAX_MEM }} -p STORAGE_LIMIT=${{ env.STORAGE_LIMIT }} \ | oc apply -f - # Start rollout (if necessary) and follow it diff --git a/.github/workflows/deploy_prod.yml b/.github/workflows/deploy_prod.yml index d3511e1..eb2ef7a 100644 --- a/.github/workflows/deploy_prod.yml +++ b/.github/workflows/deploy_prod.yml @@ -22,6 +22,7 @@ env: MAX_MEM: "900Mi" MIN_REPLICAS: "3" MAX_REPLICAS: "5" + STORAGE_LIMIT: 32Gi on: @@ -67,7 +68,7 @@ jobs: oc tag ${{ env.NAMESPACE }}-test/${{ env.REPO_NAME }}:${{ steps.get-latest-tag.outputs.tag }} ${{ env.NAMESPACE }}-prod/${{ env.REPO_NAME }}:${{ steps.get-latest-tag.outputs.tag }} # Process and apply deployment template - oc process -f tools/openshift/api.dc.yaml -p IS_NAMESPACE=${{ env.OPENSHIFT_NAMESPACE }} -p REPO_NAME=${{ env.REPO_NAME }} -p TAG_NAME=${{ steps.get-latest-tag.outputs.tag }} -p HOST_ROUTE=${{ env.REPO_NAME }}-${{ env.OPENSHIFT_NAMESPACE }}.${{ env.APP_DOMAIN }} -p MIN_REPLICAS=${{ env.MIN_REPLICAS }} -p MAX_REPLICAS=${{ env.MAX_REPLICAS }} -p MIN_CPU=${{ env.MIN_CPU }} -p MAX_CPU=${{ env.MAX_CPU }} -p MIN_MEM=${{ env.MIN_MEM }} -p MAX_MEM=${{ env.MAX_MEM }} \ + oc process -f tools/openshift/api.dc.yaml -p IS_NAMESPACE=${{ env.OPENSHIFT_NAMESPACE }} -p REPO_NAME=${{ env.REPO_NAME }} -p TAG_NAME=${{ steps.get-latest-tag.outputs.tag }} -p HOST_ROUTE=${{ env.REPO_NAME }}-${{ env.OPENSHIFT_NAMESPACE }}.${{ env.APP_DOMAIN }} -p MIN_REPLICAS=${{ env.MIN_REPLICAS }} -p MAX_REPLICAS=${{ env.MAX_REPLICAS }} -p MIN_CPU=${{ env.MIN_CPU }} -p MAX_CPU=${{ env.MAX_CPU }} -p MIN_MEM=${{ env.MIN_MEM }} -p MAX_MEM=${{ env.MAX_MEM }} -p STORAGE_LIMIT=${{ env.STORAGE_LIMIT }} \ | oc apply -f - # Start rollout (if necessary) and follow it diff --git a/.github/workflows/deploy_test.yml b/.github/workflows/deploy_test.yml index ecd23cf..3080aa8 100644 --- a/.github/workflows/deploy_test.yml +++ b/.github/workflows/deploy_test.yml @@ -22,6 +22,7 @@ env: MAX_MEM: "900Mi" MIN_REPLICAS: "3" MAX_REPLICAS: "5" + STORAGE_LIMIT: 32Gi on: @@ -67,7 +68,7 @@ jobs: oc tag ${{ env.NAMESPACE }}-dev/${{ env.REPO_NAME }}:${{ steps.get-latest-tag.outputs.tag }} ${{ env.NAMESPACE }}-test/${{ env.REPO_NAME }}:${{ steps.get-latest-tag.outputs.tag }} # Process and apply deployment template - oc process -f tools/openshift/api.dc.yaml -p IS_NAMESPACE=${{ env.OPENSHIFT_NAMESPACE }} -p REPO_NAME=${{ env.REPO_NAME }} -p TAG_NAME=${{ steps.get-latest-tag.outputs.tag }} -p HOST_ROUTE=${{ env.REPO_NAME }}-${{ env.OPENSHIFT_NAMESPACE }}.${{ env.APP_DOMAIN }} -p MIN_REPLICAS=${{ env.MIN_REPLICAS }} -p MAX_REPLICAS=${{ env.MAX_REPLICAS }} -p MIN_CPU=${{ env.MIN_CPU }} -p MAX_CPU=${{ env.MAX_CPU }} -p MIN_MEM=${{ env.MIN_MEM }} -p MAX_MEM=${{ env.MAX_MEM }} \ + oc process -f tools/openshift/api.dc.yaml -p IS_NAMESPACE=${{ env.OPENSHIFT_NAMESPACE }} -p REPO_NAME=${{ env.REPO_NAME }} -p TAG_NAME=${{ steps.get-latest-tag.outputs.tag }} -p HOST_ROUTE=${{ env.REPO_NAME }}-${{ env.OPENSHIFT_NAMESPACE }}.${{ env.APP_DOMAIN }} -p MIN_REPLICAS=${{ env.MIN_REPLICAS }} -p MAX_REPLICAS=${{ env.MAX_REPLICAS }} -p MIN_CPU=${{ env.MIN_CPU }} -p MAX_CPU=${{ env.MAX_CPU }} -p MIN_MEM=${{ env.MIN_MEM }} -p MAX_MEM=${{ env.MAX_MEM }} -p STORAGE_LIMIT=${{ env.STORAGE_LIMIT }} \ | oc apply -f - # Start rollout (if necessary) and follow it diff --git a/tools/openshift/api.dc.yaml b/tools/openshift/api.dc.yaml index 3de6e99..aa361ec 100644 --- a/tools/openshift/api.dc.yaml +++ b/tools/openshift/api.dc.yaml @@ -54,6 +54,8 @@ objects: volumeMounts: - name: log-storage mountPath: /logs + - name: business-data + mountPath: /tmp ports: - containerPort: ${{CONTAINER_PORT}} protocol: TCP @@ -115,6 +117,9 @@ objects: - name: flb-sc-config-volume configMap: name: "${REPO_NAME}-flb-sc-config-map" + - name: business-data + persistentVolumeClaim: + claimName: business-data test: false - apiVersion: v1 kind: Service @@ -156,6 +161,16 @@ objects: target: averageUtilization: 200 type: Utilization + - apiVersion: v1 + kind: PersistentVolumeClaim + metadata: + name: business-data + spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: ${{STORAGE_LIMIT}} parameters: - name: REPO_NAME description: Application repository name @@ -196,3 +211,6 @@ parameters: - name: MAX_MEM description: The maximum amount of memory required: true + - name: STORAGE_LIMIT + description: Max storage + required: true From 62de39f632b51676a56f62c7b0f219de83153eda Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Tue, 28 Nov 2023 10:51:33 -0700 Subject: [PATCH 02/14] Temporarily remove mount volume for /tmp --- tools/openshift/api.dc.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/openshift/api.dc.yaml b/tools/openshift/api.dc.yaml index aa361ec..5789f96 100644 --- a/tools/openshift/api.dc.yaml +++ b/tools/openshift/api.dc.yaml @@ -54,8 +54,6 @@ objects: volumeMounts: - name: log-storage mountPath: /logs - - name: business-data - mountPath: /tmp ports: - containerPort: ${{CONTAINER_PORT}} protocol: TCP From 60bbcfb119870586ba98d12e53c2e9558dcc9efc Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Tue, 28 Nov 2023 11:43:54 -0700 Subject: [PATCH 03/14] Update memory and scaling --- .github/workflows/build.from.developer.branch.deploy.to.dev.yml | 2 +- .github/workflows/build.from.main.branch.deploy.to.dev.yml | 2 +- .github/workflows/build.from.release.branch.deploy.to.dev.yml | 2 +- .github/workflows/deploy_prod.yml | 2 +- .github/workflows/deploy_test.yml | 2 +- Dockerfile | 2 +- tools/openshift/api.dc.yaml | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.from.developer.branch.deploy.to.dev.yml b/.github/workflows/build.from.developer.branch.deploy.to.dev.yml index 7dba677..5048d46 100644 --- a/.github/workflows/build.from.developer.branch.deploy.to.dev.yml +++ b/.github/workflows/build.from.developer.branch.deploy.to.dev.yml @@ -24,7 +24,7 @@ env: MIN_CPU: "30m" MAX_CPU: "120m" MIN_MEM: "350Mi" - MAX_MEM: "900Mi" + MAX_MEM: "1200Mi" MIN_REPLICAS: "3" MAX_REPLICAS: "5" STORAGE_LIMIT: 16Gi diff --git a/.github/workflows/build.from.main.branch.deploy.to.dev.yml b/.github/workflows/build.from.main.branch.deploy.to.dev.yml index 7cc629d..6d2d656 100644 --- a/.github/workflows/build.from.main.branch.deploy.to.dev.yml +++ b/.github/workflows/build.from.main.branch.deploy.to.dev.yml @@ -25,7 +25,7 @@ env: MIN_CPU: "30m" MAX_CPU: "120m" MIN_MEM: "350Mi" - MAX_MEM: "900Mi" + MAX_MEM: "1200Mi" MIN_REPLICAS: "3" MAX_REPLICAS: "5" STORAGE_LIMIT: 16Gi diff --git a/.github/workflows/build.from.release.branch.deploy.to.dev.yml b/.github/workflows/build.from.release.branch.deploy.to.dev.yml index 39d670a..b87d2ef 100644 --- a/.github/workflows/build.from.release.branch.deploy.to.dev.yml +++ b/.github/workflows/build.from.release.branch.deploy.to.dev.yml @@ -24,7 +24,7 @@ env: MIN_CPU: "30m" MAX_CPU: "120m" MIN_MEM: "350Mi" - MAX_MEM: "900Mi" + MAX_MEM: "1200Mi" MIN_REPLICAS: "3" MAX_REPLICAS: "5" STORAGE_LIMIT: 16Gi diff --git a/.github/workflows/deploy_prod.yml b/.github/workflows/deploy_prod.yml index eb2ef7a..73b9e47 100644 --- a/.github/workflows/deploy_prod.yml +++ b/.github/workflows/deploy_prod.yml @@ -19,7 +19,7 @@ env: MIN_CPU: "30m" MAX_CPU: "120m" MIN_MEM: "350Mi" - MAX_MEM: "900Mi" + MAX_MEM: "1200Mi" MIN_REPLICAS: "3" MAX_REPLICAS: "5" STORAGE_LIMIT: 32Gi diff --git a/.github/workflows/deploy_test.yml b/.github/workflows/deploy_test.yml index 3080aa8..1574b3b 100644 --- a/.github/workflows/deploy_test.yml +++ b/.github/workflows/deploy_test.yml @@ -19,7 +19,7 @@ env: MIN_CPU: "30m" MAX_CPU: "120m" MIN_MEM: "350Mi" - MAX_MEM: "900Mi" + MAX_MEM: "1200Mi" MIN_REPLICAS: "3" MAX_REPLICAS: "5" STORAGE_LIMIT: 32Gi diff --git a/Dockerfile b/Dockerfile index 9561aa7..ca8ce55 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ ARG DEPENDENCY=/workspace/app/target/dependency COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /app/lib COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /app -ENTRYPOINT ["java","-Duser.name=EDUC_GRAD_BUSINESS_API","-Xms700m","-Xmx700m","-XX:TieredStopAtLevel=1",\ +ENTRYPOINT ["java","-Duser.name=EDUC_GRAD_BUSINESS_API","-Xms1024m","-Xmx1024m","-XX:TieredStopAtLevel=1",\ "-XX:+UseParallelGC","-XX:MinHeapFreeRatio=20","-XX:MaxHeapFreeRatio=40","-XX:GCTimeRatio=4",\ "-XX:AdaptiveSizePolicyWeight=90","-XX:MaxMetaspaceSize=300m","-XX:ParallelGCThreads=1",\ "-Djava.util.concurrent.ForkJoinPool.common.parallelism=1","-XX:CICompilerCount=2",\ diff --git a/tools/openshift/api.dc.yaml b/tools/openshift/api.dc.yaml index 5789f96..887667c 100644 --- a/tools/openshift/api.dc.yaml +++ b/tools/openshift/api.dc.yaml @@ -157,7 +157,7 @@ objects: resource: name: memory target: - averageUtilization: 200 + averageUtilization: 250 type: Utilization - apiVersion: v1 kind: PersistentVolumeClaim From ad4d0bf72db63ca8310dd2db67c63abebb71ac3d Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 28 Nov 2023 11:47:31 -0700 Subject: [PATCH 04/14] More debugging added --- .../educ/api/gradbusiness/service/GradBusinessService.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java b/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java index 3c8690c..8c6443c 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java @@ -346,8 +346,8 @@ protected ResponseEntity getInternalServerErrorResponse(Throwable t) { private ResponseEntity handleBinaryResponse(byte[] resultBinary, String reportFile, MediaType contentType) { ResponseEntity response; - if(resultBinary.length > 0) { + logger.debug("Sending {} response {}M", contentType.getSubtype().toUpperCase(), resultBinary.length/(1024 * 1024)); HttpHeaders headers = new HttpHeaders(); headers.add("Content-Disposition", "inline; filename=" + reportFile); response = ResponseEntity @@ -363,9 +363,12 @@ private ResponseEntity handleBinaryResponse(byte[] resultBinary, String private void saveBinaryResponseToFile(byte[] resultBinary, String reportFile) throws IOException { if(resultBinary.length > 0) { - try (OutputStream out = new FileOutputStream(TMP + "/" + reportFile)) { + String pathToFile = TMP + "/" + reportFile; + logger.debug("Save generated PDF {} on the file system", reportFile); + try (OutputStream out = new FileOutputStream(pathToFile)) { out.write(resultBinary); } + logger.debug("PDF {} saved successfully", pathToFile); } } } From dac9c89ef6ed9ae7c0e6572d76cc0a8222d9d29a Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 28 Nov 2023 12:31:59 -0700 Subject: [PATCH 05/14] More debugging added --- .../gov/educ/api/gradbusiness/service/GradBusinessService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java b/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java index 8c6443c..9600969 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java @@ -347,7 +347,7 @@ protected ResponseEntity getInternalServerErrorResponse(Throwable t) { private ResponseEntity handleBinaryResponse(byte[] resultBinary, String reportFile, MediaType contentType) { ResponseEntity response; if(resultBinary.length > 0) { - logger.debug("Sending {} response {}M", contentType.getSubtype().toUpperCase(), resultBinary.length/(1024 * 1024)); + logger.debug("Sending {} response {} KB", contentType.getSubtype().toUpperCase(), resultBinary.length/(1024)); HttpHeaders headers = new HttpHeaders(); headers.add("Content-Disposition", "inline; filename=" + reportFile); response = ResponseEntity From e61e9f996e78d1eecda017641e4f7a023b8ea30d Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 28 Nov 2023 12:38:37 -0700 Subject: [PATCH 06/14] More debugging added --- .../api/gradbusiness/service/GradBusinessService.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java b/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java index 9600969..e41f433 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java @@ -23,10 +23,10 @@ import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.client.WebClient; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.*; import java.util.concurrent.CompletableFuture; @@ -365,9 +365,10 @@ private void saveBinaryResponseToFile(byte[] resultBinary, String reportFile) th if(resultBinary.length > 0) { String pathToFile = TMP + "/" + reportFile; logger.debug("Save generated PDF {} on the file system", reportFile); - try (OutputStream out = new FileOutputStream(pathToFile)) { - out.write(resultBinary); - } +// try (OutputStream out = new FileOutputStream(pathToFile)) { +// out.write(resultBinary); +// } + Files.write(Path.of(pathToFile), resultBinary); logger.debug("PDF {} saved successfully", pathToFile); } } From 0c46ef6b3c97efa9ba2815bbf5f3ccb38f074616 Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 28 Nov 2023 12:51:57 -0700 Subject: [PATCH 07/14] More debugging added --- .../gradbusiness/service/GradBusinessService.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java b/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java index e41f433..d6cc3f0 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java @@ -9,6 +9,7 @@ import io.github.resilience4j.retry.annotation.Retry; import jakarta.transaction.Transactional; import org.apache.commons.collections4.ListUtils; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -23,10 +24,9 @@ import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.client.WebClient; +import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; import java.util.*; import java.util.concurrent.CompletableFuture; @@ -347,7 +347,8 @@ protected ResponseEntity getInternalServerErrorResponse(Throwable t) { private ResponseEntity handleBinaryResponse(byte[] resultBinary, String reportFile, MediaType contentType) { ResponseEntity response; if(resultBinary.length > 0) { - logger.debug("Sending {} response {} KB", contentType.getSubtype().toUpperCase(), resultBinary.length/(1024)); + String fileType = contentType.getSubtype().toUpperCase(); + logger.debug("Sending {} response {} KB", fileType, resultBinary.length/(1024)); HttpHeaders headers = new HttpHeaders(); headers.add("Content-Disposition", "inline; filename=" + reportFile); response = ResponseEntity @@ -365,10 +366,7 @@ private void saveBinaryResponseToFile(byte[] resultBinary, String reportFile) th if(resultBinary.length > 0) { String pathToFile = TMP + "/" + reportFile; logger.debug("Save generated PDF {} on the file system", reportFile); -// try (OutputStream out = new FileOutputStream(pathToFile)) { -// out.write(resultBinary); -// } - Files.write(Path.of(pathToFile), resultBinary); + FileUtils.writeByteArrayToFile(new File(pathToFile), resultBinary); logger.debug("PDF {} saved successfully", pathToFile); } } From 7cb23918873c3ec964cb699826b741d5527e0956 Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 28 Nov 2023 12:57:10 -0700 Subject: [PATCH 08/14] More debugging added --- .../educ/api/gradbusiness/service/GradBusinessService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java b/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java index d6cc3f0..066c2db 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java @@ -42,7 +42,7 @@ public class GradBusinessService { private static final String APPLICATION_JSON = "application/json"; private static final String APPLICATION_PDF = "application/pdf"; private static final String ACCEPT = "*/*"; - private static final String TMP = "/tmp"; + private static final String TMP = File.pathSeparator + "tmp"; /** * The Web client. */ @@ -364,7 +364,7 @@ private ResponseEntity handleBinaryResponse(byte[] resultBinary, String private void saveBinaryResponseToFile(byte[] resultBinary, String reportFile) throws IOException { if(resultBinary.length > 0) { - String pathToFile = TMP + "/" + reportFile; + String pathToFile = TMP + File.pathSeparator + reportFile; logger.debug("Save generated PDF {} on the file system", reportFile); FileUtils.writeByteArrayToFile(new File(pathToFile), resultBinary); logger.debug("PDF {} saved successfully", pathToFile); From 742e5bf4d6aded62c391688075dee2052c2bce53 Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 28 Nov 2023 13:12:07 -0700 Subject: [PATCH 09/14] More debugging added --- .../educ/api/gradbusiness/service/GradBusinessService.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java b/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java index 066c2db..ec120c5 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java @@ -366,7 +366,12 @@ private void saveBinaryResponseToFile(byte[] resultBinary, String reportFile) th if(resultBinary.length > 0) { String pathToFile = TMP + File.pathSeparator + reportFile; logger.debug("Save generated PDF {} on the file system", reportFile); - FileUtils.writeByteArrayToFile(new File(pathToFile), resultBinary); + File fileToSave = new File(pathToFile); + if(fileToSave.exists()) { + boolean isDeleted = fileToSave.delete(); + logger.debug("{} to delete existing PDF {}", isDeleted, reportFile); + } + FileUtils.writeByteArrayToFile(fileToSave, resultBinary); logger.debug("PDF {} saved successfully", pathToFile); } } From 6b169d060d074543dd44b6cedde4d7ae708a7bb5 Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 28 Nov 2023 13:42:29 -0700 Subject: [PATCH 10/14] More debugging added --- .../educ/api/gradbusiness/service/GradBusinessService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java b/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java index ec120c5..f985fba 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java @@ -9,7 +9,6 @@ import io.github.resilience4j.retry.annotation.Retry; import jakarta.transaction.Transactional; import org.apache.commons.collections4.ListUtils; -import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -27,6 +26,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.nio.file.Files; import java.util.*; import java.util.concurrent.CompletableFuture; @@ -371,7 +371,7 @@ private void saveBinaryResponseToFile(byte[] resultBinary, String reportFile) th boolean isDeleted = fileToSave.delete(); logger.debug("{} to delete existing PDF {}", isDeleted, reportFile); } - FileUtils.writeByteArrayToFile(fileToSave, resultBinary); + Files.write(fileToSave.toPath(), resultBinary); logger.debug("PDF {} saved successfully", pathToFile); } } From a5973784b7caaadcb54cfb625a41c4b236a8d67b Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 28 Nov 2023 13:46:31 -0700 Subject: [PATCH 11/14] More debugging added --- .../educ/api/gradbusiness/service/GradBusinessService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java b/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java index f985fba..3e71b16 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java @@ -42,7 +42,7 @@ public class GradBusinessService { private static final String APPLICATION_JSON = "application/json"; private static final String APPLICATION_PDF = "application/pdf"; private static final String ACCEPT = "*/*"; - private static final String TMP = File.pathSeparator + "tmp"; + private static final String TMP = File.separator + "tmp"; /** * The Web client. */ @@ -364,7 +364,7 @@ private ResponseEntity handleBinaryResponse(byte[] resultBinary, String private void saveBinaryResponseToFile(byte[] resultBinary, String reportFile) throws IOException { if(resultBinary.length > 0) { - String pathToFile = TMP + File.pathSeparator + reportFile; + String pathToFile = TMP + File.separator + reportFile; logger.debug("Save generated PDF {} on the file system", reportFile); File fileToSave = new File(pathToFile); if(fileToSave.exists()) { From 0bdd273393ebd68e372d72541da06ce2a49f60e5 Mon Sep 17 00:00:00 2001 From: Kamal Mohammed Date: Tue, 28 Nov 2023 14:07:41 -0700 Subject: [PATCH 12/14] Update memory and scaling --- tools/openshift/api.dc.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/openshift/api.dc.yaml b/tools/openshift/api.dc.yaml index 887667c..8f08146 100644 --- a/tools/openshift/api.dc.yaml +++ b/tools/openshift/api.dc.yaml @@ -54,6 +54,8 @@ objects: volumeMounts: - name: log-storage mountPath: /logs + - name: business-data + mountPath: /tmp ports: - containerPort: ${{CONTAINER_PORT}} protocol: TCP From 10a2eb540f560844cab43c2279060f53446e780f Mon Sep 17 00:00:00 2001 From: arybakov Date: Tue, 28 Nov 2023 14:09:42 -0700 Subject: [PATCH 13/14] Fixed code smell --- .../educ/api/gradbusiness/service/GradBusinessService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java b/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java index 3e71b16..57d58f2 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java @@ -367,9 +367,9 @@ private void saveBinaryResponseToFile(byte[] resultBinary, String reportFile) th String pathToFile = TMP + File.separator + reportFile; logger.debug("Save generated PDF {} on the file system", reportFile); File fileToSave = new File(pathToFile); - if(fileToSave.exists()) { - boolean isDeleted = fileToSave.delete(); - logger.debug("{} to delete existing PDF {}", isDeleted, reportFile); + boolean isDeleted = Files.deleteIfExists(fileToSave.toPath()); + if(isDeleted) { + logger.debug("Delete existing PDF {}", reportFile); } Files.write(fileToSave.toPath(), resultBinary); logger.debug("PDF {} saved successfully", pathToFile); From 2a56142d6afeed54dfb0ee9ea93bc8e615ade56e Mon Sep 17 00:00:00 2001 From: arybakov Date: Wed, 29 Nov 2023 10:26:14 -0700 Subject: [PATCH 14/14] Fix for wasted access tokens --- .../gradbusiness/service/GradBusinessService.java | 12 ++++++------ .../gov/educ/api/gradbusiness/util/TokenUtils.java | 6 +++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java b/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java index 57d58f2..4382f96 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/service/GradBusinessService.java @@ -292,9 +292,10 @@ public ResponseEntity getStudentTranscriptPDFByType(String pen, String t private void getStudentAchievementReports(List> partitions, List locations) { logger.debug("******** Getting Student Achievement Reports ******"); for(List studentList: partitions) { + String accessToken = tokenUtils.getAccessToken(); logger.debug("******** Run partition with {} students ******", studentList.size()); List> futures = studentList.stream() - .map(studentGuid -> CompletableFuture.supplyAsync(() -> getStudentAchievementReport(studentGuid))) + .map(studentGuid -> CompletableFuture.supplyAsync(() -> getStudentAchievementReport(studentGuid, accessToken))) .toList(); CompletableFuture allFutures = CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()])); CompletableFuture> result = allFutures.thenApply(v -> futures.stream() @@ -305,10 +306,10 @@ private void getStudentAchievementReports(List> partitions, List h.setBearerAuth(accessTokenNext)).retrieve().bodyToMono(InputStreamResource.class).block(); + String finalAccessToken = tokenUtils.isTokenExpired() ? tokenUtils.getAccessToken() : accessToken; + InputStreamResource result = webClient.get().uri(String.format(educGraduationApiConstants.getStudentCredentialByType(), studentGuid, "ACHV")).headers(h -> h.setBearerAuth(finalAccessToken)).retrieve().bodyToMono(InputStreamResource.class).block(); if (result != null) { logger.debug("******** Fetched Achievement Report for {} ******", studentGuid); return result.getInputStream(); @@ -367,8 +368,7 @@ private void saveBinaryResponseToFile(byte[] resultBinary, String reportFile) th String pathToFile = TMP + File.separator + reportFile; logger.debug("Save generated PDF {} on the file system", reportFile); File fileToSave = new File(pathToFile); - boolean isDeleted = Files.deleteIfExists(fileToSave.toPath()); - if(isDeleted) { + if(Files.deleteIfExists(fileToSave.toPath())) { logger.debug("Delete existing PDF {}", reportFile); } Files.write(fileToSave.toPath(), resultBinary); diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/util/TokenUtils.java b/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/util/TokenUtils.java index 18ea101..d3d64c3 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/util/TokenUtils.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradbusiness/util/TokenUtils.java @@ -37,8 +37,12 @@ public String getAccessToken() { return this.fetchAccessToken(); } + public boolean isTokenExpired() { + return responseObjCache.isExpired(); + } + private ResponseObj getTokenResponseObject() { - if(responseObjCache.isExpired()){ + if(isTokenExpired()){ responseObjCache.setResponseObj(getResponseObj()); } return responseObjCache.getResponseObj();