From 8eddb8a616f9c3f2c03c074b7bdc3a63ea2e1314 Mon Sep 17 00:00:00 2001 From: "adam.zakrzewski" Date: Tue, 9 Apr 2024 09:12:53 +0200 Subject: [PATCH 1/5] adding logging for HttpFileUploader --- .../hx_insight/storage/HttpHxInsightStorageClient.java | 2 +- .../hx_insight/storage/connector/FileUploader.java | 3 +++ .../hx_insight/storage/connector/HttpFileUploader.java | 10 +++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/HttpHxInsightStorageClient.java b/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/HttpHxInsightStorageClient.java index 50c9078f2..9bb346abc 100644 --- a/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/HttpHxInsightStorageClient.java +++ b/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/HttpHxInsightStorageClient.java @@ -61,7 +61,7 @@ public IngestContentResponse upload(File file, String contentType, String nodeId try (InputStream fileData = file.data()) { log.atDebug().log("Upload :: Transferring to S3 content of node: {} with size of {} bytes", nodeId, fileData.available()); - fileUploader.upload(new FileUploadRequest(new File(fileData), contentType, preSignedUrl)); + fileUploader.upload(new FileUploadRequest(new File(fileData), contentType, preSignedUrl), nodeId); } catch (IOException e) { diff --git a/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/FileUploader.java b/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/FileUploader.java index b0af9221b..84aba87dc 100644 --- a/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/FileUploader.java +++ b/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/FileUploader.java @@ -27,5 +27,8 @@ public interface FileUploader { + @SuppressWarnings({"PMD.CloseResource", "PMD.PreserveStackTrace"}) void upload(FileUploadRequest fileUploadRequest); + + void upload(FileUploadRequest fileUploadRequest, String nodeId); } diff --git a/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/HttpFileUploader.java b/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/HttpFileUploader.java index aed49da3e..b1b224b53 100644 --- a/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/HttpFileUploader.java +++ b/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/HttpFileUploader.java @@ -91,13 +91,20 @@ public void configure() // @formatter:on } + @Override + @SuppressWarnings({"PMD.CloseResource", "PMD.PreserveStackTrace"}) + public void upload(FileUploadRequest fileUploadRequest) + { + upload(fileUploadRequest, null); + } + @Retryable(retryFor = EndpointServerErrorException.class, maxAttemptsExpression = "#{@integrationProperties.hylandExperience.storage.upload.retry.attempts}", backoff = @Backoff(delayExpression = "#{@integrationProperties.hylandExperience.storage.upload.retry.initialDelay}", multiplierExpression = "#{@integrationProperties.hylandExperience.storage.upload.retry.delayMultiplier}")) @Override @SuppressWarnings({"PMD.CloseResource", "PMD.PreserveStackTrace"}) - public void upload(FileUploadRequest fileUploadRequest) + public void upload(FileUploadRequest fileUploadRequest, String nodeId) { InputStream fileData = fileUploadRequest.file().data(); try @@ -111,6 +118,7 @@ STORAGE_LOCATION_HEADER, wrapRawToken(fileUploadRequest.storageLocation()), .withHeaders(headers) .withBody(fileData) .request(); + log.atDebug().log("Upload :: PDF rendition of the node: {} to presignedUrl: {}", nodeId, fileUploadRequest.storageLocation().getPath()); } catch (Exception e) { From 834370f9c14b631c7bb9810f4b3a6fd8dae7fa6e Mon Sep 17 00:00:00 2001 From: "adam.zakrzewski" Date: Tue, 9 Apr 2024 09:23:08 +0200 Subject: [PATCH 2/5] updating copyright message in FileUploader --- .../messaging/hx_insight/storage/connector/FileUploader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/FileUploader.java b/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/FileUploader.java index 84aba87dc..6ea1a2f48 100644 --- a/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/FileUploader.java +++ b/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/FileUploader.java @@ -2,7 +2,7 @@ * #%L * Alfresco HX Insight Connector * %% - * Copyright (C) 2024 Alfresco Software Limited + * Copyright (C) 2023 - 2024 Alfresco Software Limited * %% * This file is part of the Alfresco software. * If the software was purchased under a paid Alfresco license, the terms of From 2847b8cd8fd29e9dc2ad4089ff01af5461dc2660 Mon Sep 17 00:00:00 2001 From: "adam.zakrzewski" Date: Tue, 9 Apr 2024 09:40:09 +0200 Subject: [PATCH 3/5] adding @Retryable annotation for upload method --- .../hx_insight/storage/connector/HttpFileUploader.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/HttpFileUploader.java b/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/HttpFileUploader.java index b1b224b53..f60140d00 100644 --- a/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/HttpFileUploader.java +++ b/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/HttpFileUploader.java @@ -91,6 +91,10 @@ public void configure() // @formatter:on } + @Retryable(retryFor = EndpointServerErrorException.class, + maxAttemptsExpression = "#{@integrationProperties.hylandExperience.storage.upload.retry.attempts}", + backoff = @Backoff(delayExpression = "#{@integrationProperties.hylandExperience.storage.upload.retry.initialDelay}", + multiplierExpression = "#{@integrationProperties.hylandExperience.storage.upload.retry.delayMultiplier}")) @Override @SuppressWarnings({"PMD.CloseResource", "PMD.PreserveStackTrace"}) public void upload(FileUploadRequest fileUploadRequest) From 260c2e120a8371465126244b8ca2362e94ece209 Mon Sep 17 00:00:00 2001 From: "adam.zakrzewski" Date: Tue, 9 Apr 2024 10:39:05 +0200 Subject: [PATCH 4/5] adding node id to tests using upload method --- .../connector/HttpFileUploaderIntegrationTest.java | 11 ++++++----- .../hx_insight/storage/connector/FileUploader.java | 3 --- .../storage/connector/HttpFileUploader.java | 11 ----------- .../storage/HttpHxInsightStorageClientTest.java | 2 +- .../storage/connector/HttpFileUploaderTest.java | 9 +++++---- 5 files changed, 12 insertions(+), 24 deletions(-) diff --git a/live-ingester/src/integration-test/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/HttpFileUploaderIntegrationTest.java b/live-ingester/src/integration-test/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/HttpFileUploaderIntegrationTest.java index 81e68490b..9402d8d1b 100644 --- a/live-ingester/src/integration-test/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/HttpFileUploaderIntegrationTest.java +++ b/live-ingester/src/integration-test/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/HttpFileUploaderIntegrationTest.java @@ -80,6 +80,7 @@ class HttpFileUploaderIntegrationTest private static final String OBJECT_CONTENT_TYPE = "plain/text"; private static final int RETRY_ATTEMPTS = 3; private static final int RETRY_DELAY_MS = 0; + private static final String NODE_ID = "node-ref"; @Container @SuppressWarnings("PMD.FieldNamingConventions") @@ -110,7 +111,7 @@ void testUpload() throws IOException FileUploadRequest fileUploadRequest = new FileUploadRequest(fileToUpload, OBJECT_CONTENT_TYPE, preSignedUrl); // when - fileUploader.upload(fileUploadRequest); + fileUploader.upload(fileUploadRequest, NODE_ID); // then List actualBucketContent = s3StorageMock.listBucketContent(BUCKET_NAME); @@ -132,10 +133,10 @@ void testUpload_serverError_doRetry() throws IOException FileUploadRequest fileUploadRequest = new FileUploadRequest(fileToUpload, OBJECT_CONTENT_TYPE, preSignedUrl); // when - Throwable thrown = catchThrowable(() -> fileUploader.upload(fileUploadRequest)); + Throwable thrown = catchThrowable(() -> fileUploader.upload(fileUploadRequest, NODE_ID)); // then - then(fileUploader).should(times(RETRY_ATTEMPTS)).upload(any()); + then(fileUploader).should(times(RETRY_ATTEMPTS)).upload(any(), any()); assertThat(thrown) .cause().isInstanceOf(EndpointServerErrorException.class) .rootCause().isInstanceOf(HttpHostConnectException.class) @@ -154,10 +155,10 @@ void testUpload_clientError_dontRetry() throws IOException FileUploadRequest fileUploadRequest = new FileUploadRequest(fileToUpload, OBJECT_CONTENT_TYPE, preSignedUrl); // when - Throwable thrown = catchThrowable(() -> fileUploader.upload(fileUploadRequest)); + Throwable thrown = catchThrowable(() -> fileUploader.upload(fileUploadRequest, NODE_ID)); // then - then(fileUploader).should(times(1)).upload(any()); + then(fileUploader).should(times(1)).upload(any(), any()); assertThat(thrown).cause().isInstanceOf(EndpointClientErrorException.class); } diff --git a/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/FileUploader.java b/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/FileUploader.java index 6ea1a2f48..8ba21f997 100644 --- a/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/FileUploader.java +++ b/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/FileUploader.java @@ -27,8 +27,5 @@ public interface FileUploader { - @SuppressWarnings({"PMD.CloseResource", "PMD.PreserveStackTrace"}) - void upload(FileUploadRequest fileUploadRequest); - void upload(FileUploadRequest fileUploadRequest, String nodeId); } diff --git a/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/HttpFileUploader.java b/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/HttpFileUploader.java index f60140d00..24bc010a9 100644 --- a/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/HttpFileUploader.java +++ b/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/HttpFileUploader.java @@ -91,17 +91,6 @@ public void configure() // @formatter:on } - @Retryable(retryFor = EndpointServerErrorException.class, - maxAttemptsExpression = "#{@integrationProperties.hylandExperience.storage.upload.retry.attempts}", - backoff = @Backoff(delayExpression = "#{@integrationProperties.hylandExperience.storage.upload.retry.initialDelay}", - multiplierExpression = "#{@integrationProperties.hylandExperience.storage.upload.retry.delayMultiplier}")) - @Override - @SuppressWarnings({"PMD.CloseResource", "PMD.PreserveStackTrace"}) - public void upload(FileUploadRequest fileUploadRequest) - { - upload(fileUploadRequest, null); - } - @Retryable(retryFor = EndpointServerErrorException.class, maxAttemptsExpression = "#{@integrationProperties.hylandExperience.storage.upload.retry.attempts}", backoff = @Backoff(delayExpression = "#{@integrationProperties.hylandExperience.storage.upload.retry.initialDelay}", diff --git a/live-ingester/src/test/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/HttpHxInsightStorageClientTest.java b/live-ingester/src/test/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/HttpHxInsightStorageClientTest.java index ec641cdf0..ff17f1896 100644 --- a/live-ingester/src/test/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/HttpHxInsightStorageClientTest.java +++ b/live-ingester/src/test/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/HttpHxInsightStorageClientTest.java @@ -83,6 +83,6 @@ void testUploadDataFromInputStream() StorageLocationRequest expectedStorageLocationRequest = new StorageLocationRequest(NODE_ID, FILE_CONTENT_TYPE); then(storageLocationRequesterMock).should().requestStorageLocation(expectedStorageLocationRequest); FileUploadRequest expectedFileUploadRequest = new FileUploadRequest(new File(inputStreamMock), FILE_CONTENT_TYPE, urlMock); - then(fileUploaderMock).should().upload(expectedFileUploadRequest); + then(fileUploaderMock).should().upload(expectedFileUploadRequest, NODE_ID); } } diff --git a/live-ingester/src/test/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/HttpFileUploaderTest.java b/live-ingester/src/test/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/HttpFileUploaderTest.java index 7ab00ecc5..5832de771 100644 --- a/live-ingester/src/test/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/HttpFileUploaderTest.java +++ b/live-ingester/src/test/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/HttpFileUploaderTest.java @@ -64,6 +64,7 @@ class HttpFileUploaderTest { private static final String MOCK_ENDPOINT = "mock:s3-endpoint"; private static final String CONTENT_TYPE = "content/type"; + private static final String NODE_ID = "node-ref"; CamelContext camelContext; MockEndpoint mockEndpoint; @@ -104,7 +105,7 @@ void testUpload() throws InterruptedException mockEndpointWillExpectInRequestHeader(Exchange.CONTENT_TYPE, CONTENT_TYPE); // when - Throwable thrown = catchThrowable(() -> httpFileUploader.upload(request)); + Throwable thrown = catchThrowable(() -> httpFileUploader.upload(request, NODE_ID)); // then mockEndpoint.assertIsSatisfied(); @@ -126,7 +127,7 @@ void testUpload_verifyRawQueryParam() throws InterruptedException mockEndpointWillExpectInRequestHeader(STORAGE_LOCATION_HEADER, expectedRawUrl); // when - Throwable thrown = catchThrowable(() -> httpFileUploader.upload(request)); + Throwable thrown = catchThrowable(() -> httpFileUploader.upload(request, NODE_ID)); // then mockEndpoint.assertIsSatisfied(); @@ -141,7 +142,7 @@ void testUpload_invalidResponseStatusCode5xx() mockEndpointWillRespondWith(500); // when - Throwable thrown = catchThrowable(() -> httpFileUploader.upload(request)); + Throwable thrown = catchThrowable(() -> httpFileUploader.upload(request, NODE_ID)); // then assertThat(thrown) @@ -158,7 +159,7 @@ void testUpload_invalidResponseStatusCode4xx() mockEndpointWillRespondWith(400); // when - Throwable thrown = catchThrowable(() -> httpFileUploader.upload(request)); + Throwable thrown = catchThrowable(() -> httpFileUploader.upload(request, NODE_ID)); // then assertThat(thrown) From 244617b49e260b75bb450fcd947b3ea4f194261c Mon Sep 17 00:00:00 2001 From: "adam.zakrzewski" Date: Tue, 9 Apr 2024 12:04:39 +0200 Subject: [PATCH 5/5] updating log message --- .../hx_insight/storage/connector/HttpFileUploader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/HttpFileUploader.java b/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/HttpFileUploader.java index 24bc010a9..37f17943e 100644 --- a/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/HttpFileUploader.java +++ b/live-ingester/src/main/java/org/alfresco/hxi_connector/live_ingester/adapters/messaging/hx_insight/storage/connector/HttpFileUploader.java @@ -111,7 +111,7 @@ STORAGE_LOCATION_HEADER, wrapRawToken(fileUploadRequest.storageLocation()), .withHeaders(headers) .withBody(fileData) .request(); - log.atDebug().log("Upload :: PDF rendition of the node: {} to presignedUrl: {}", nodeId, fileUploadRequest.storageLocation().getPath()); + log.atDebug().log("Upload :: PDF rendition of the node: {} successfully uploaded to pre-signed URL: {}", nodeId, fileUploadRequest.storageLocation().getPath()); } catch (Exception e) {