Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ACS-7350: add logging for HttpFileUploader #274

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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<String> actualBucketContent = s3StorageMock.listBucketContent(BUCKET_NAME);
Expand All @@ -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)
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,5 +27,5 @@

public interface FileUploader
{
void upload(FileUploadRequest fileUploadRequest);
void upload(FileUploadRequest fileUploadRequest, String nodeId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void configure()
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)
azakrzewski-hy marked this conversation as resolved.
Show resolved Hide resolved
{
InputStream fileData = fileUploadRequest.file().data();
try
Expand All @@ -111,6 +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());
azakrzewski-hy marked this conversation as resolved.
Show resolved Hide resolved
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Loading