Skip to content

Commit 07560fe

Browse files
Add more logging during async job initialization
1 parent 3099f3a commit 07560fe

File tree

4 files changed

+41
-24
lines changed

4 files changed

+41
-24
lines changed

multiapps-controller-web/src/main/java/org/cloudfoundry/multiapps/controller/web/Messages.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@ public final class Messages {
77

88
// Exception messages
99
public static final String ERROR_EXECUTING_REST_API_CALL = "Error occurred while executing REST API call";
10-
public static final String MAX_UPLOAD_SIZE_EXCEEDED = "Cannot upload file, size is bigger than the configured maximum upload size \"{0}\" bytes";
10+
public static final String MAX_UPLOAD_SIZE_EXCEEDED_FOR_JOB_WITH_ID = "Cannot upload file, size is bigger than the configured maximum upload size \"{0}\" bytes. Job id: {1}";
1111
public static final String COULD_NOT_GET_FILES_0 = "Could not get files: {0}";
1212
public static final String COULD_NOT_UPLOAD_FILE_0 = "Could not upload file: {0}";
1313
public static final String NO_FILES_TO_UPLOAD = "Request has no files to upload!";
1414
public static final String ACTION_0_CANNOT_BE_EXECUTED_OVER_OPERATION_1_IN_STATE_2 = "Action \"{0}\" cannot be executed over operation \"{1}\" in state \"{2}\".";
1515
public static final String OPERATION_0_NOT_FOUND = "Operation \"{0}\" was not found.";
1616
public static final String TEMPORARY_PROBLEM_WITH_PERSISTENCE_LAYER = "Temporary problem with persistence layer of the service";
17-
public static final String FILE_URL_RESPONSE_DID_NOT_RETURN_CONTENT_LENGTH = "File URL response did not return Content-Length header";
18-
public static final String ERROR_FROM_REMOTE_MTAR_ENDPOINT = "Error from remote MTAR endpoint {0} with status code {1}, message: {2}";
19-
public static final String MTAR_ENDPOINT_NOT_SECURE = "Remote MTAR endpoint is not a secure connection. HTTPS required";
17+
public static final String FILE_URL_RESPONSE_DID_NOT_RETURN_CONTENT_LENGTH_FOR_JOB_WITH_ID = "File URL response did not return Content-Length header. Job id: {0}";
18+
public static final String ERROR_FROM_REMOTE_MTAR_ENDPOINT_FOR_JOB_WITH_ID = "Error from remote MTAR endpoint {0} with status code {1}, message: {2}. Job id: {3}";
19+
public static final String MTAR_ENDPOINT_NOT_SECURE_FOR_JOB_WITH_ID = "Remote MTAR endpoint is not a secure connection. HTTPS required. Job id: {0}";
2020
public static final String CANNOT_PARSE_CONTAINER_URI_OF_OBJECT_STORE = "Cannot parse container_uri of object store";
2121
public static final String REQUEST_0_1_FAILED_WITH_2 = "Request \"{0} {1}\" failed with \"{2}\"";
2222
public static final String ERROR_OCCURRED_WHILE_DELETING_JOB_ENTRY = "Error occurred while deleting job entry";
2323
public static final String CANNOT_CREATE_OBJECT_STORE_CLIENT_WITH_PROVIDER_0 = "Cannot create Object Store client with provider: {0}";
2424
public static final String NO_VALID_OBJECT_STORE_CONFIGURATION_FOUND = "No valid Object Store configuration found!";
2525
public static final String MISSING_PROPERTIES_FOR_CREATING_THE_SPECIFIC_PROVIDER = "Missing properties for creating the specific provider!";
26-
public static final String DEPLOY_FROM_URL_WRONG_CREDENTIALS = "Credentials to {0} are wrong. Make sure that they are correct.";
26+
public static final String DEPLOY_FROM_URL_WRONG_CREDENTIALS_FOR_JOB_WITH_ID = "Credentials to {0} are wrong. Make sure that they are correct. Job id: {1}";
2727
public static final String JOB_NOT_UPDATED_FOR_0_SECONDS = "Job not updated for {0} seconds";
2828

2929
public static final String FAILED_TO_CREATE_BLOB_STORE_CONTEXT = "Failed to create BlobStoreContext";
@@ -77,11 +77,11 @@ public final class Messages {
7777
public static final String ASYNC_UPLOAD_JOB_EXISTS = "Async upload job for URL {} exists: {}";
7878
public static final String CREATING_ASYNC_UPLOAD_JOB = "Creating async upload job for URL {} with ID: {}";
7979
public static final String ASYNC_UPLOAD_JOB_REJECTED = "Async upload job with space guid: {}, namespace: {}, URL: {} rejected.";
80-
public static final String STARTING_DOWNLOAD_OF_MTAR = "Starting download of MTAR from remote endpoint: {}";
81-
public static final String UPLOADED_MTAR_FROM_REMOTE_ENDPOINT_AND_JOB_ID = "Uploaded MTAR from remote endpoint {} with job id: {} in {} ms";
80+
public static final String STARTING_DOWNLOAD_OF_MTAR_WITH_JOB_ID = "Starting download of MTAR from remote endpoint: {}. Job id: {}";
81+
public static final String UPLOADED_MTAR_FROM_REMOTE_ENDPOINT_AND_JOB_ID = "Uploaded MTAR from remote endpoint {}. Job id: {} in {} ms";
8282
public static final String ASYNC_UPLOAD_JOB_FINISHED = "Async upload job {} finished";
83-
public static final String UPLOADING_MTAR_STREAM_FROM_REMOTE_ENDPOINT = "Uploading MTAR stream from remote endpoint: {}";
84-
public static final String CALLING_REMOTE_MTAR_ENDPOINT = "Calling remote MTAR endpoint {}";
83+
public static final String UPLOADING_MTAR_STREAM_FROM_REMOTE_ENDPOINT_WITH_JOB_ID = "Uploading MTAR stream from remote endpoint: {}. Job id: {}";
84+
public static final String CALLING_REMOTE_MTAR_ENDPOINT_FOR_JOB_WITH_ID = "Calling remote MTAR endpoint {}. Job id: {}";
8585

8686
private Messages() {
8787
}

multiapps-controller-web/src/main/java/org/cloudfoundry/multiapps/controller/web/upload/AsyncUploadJobOrchestrator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private AsyncUploadJobEntry createJobEntry(String spaceGuid, String namespace, S
106106
}
107107

108108
private void deployFromUrl(AsyncUploadJobEntry jobEntry, String fileUrl, UserCredentials userCredentials) {
109-
LOGGER.info(Messages.STARTING_DOWNLOAD_OF_MTAR, jobEntry.getUrl());
109+
LOGGER.info(Messages.STARTING_DOWNLOAD_OF_MTAR_WITH_JOB_ID, jobEntry.getUrl(), jobEntry.getId());
110110
var startTime = LocalDateTime.now();
111111
Lock lock = new ReentrantLock();
112112
AtomicLong counterRef = new AtomicLong();
@@ -185,7 +185,9 @@ private FileEntry doUploadMtarFromUrl(UploadFromUrlContext uploadFromUrlContext,
185185
// JClods library: https://issues.apache.org/jira/browse/JCLOUDS-1623
186186
try (CountingInputStream source = new CountingInputStream(fileFromUrlData.fileInputStream(), uploadFromUrlContext.getCounterRef());
187187
BufferedInputStream bufferedContent = new BufferedInputStream(source, INPUT_STREAM_BUFFER_SIZE)) {
188-
LOGGER.debug(Messages.UPLOADING_MTAR_STREAM_FROM_REMOTE_ENDPOINT, fileFromUrlData.uri());
188+
LOGGER.debug(Messages.UPLOADING_MTAR_STREAM_FROM_REMOTE_ENDPOINT_WITH_JOB_ID, fileFromUrlData.uri(),
189+
uploadFromUrlContext.getJobEntry()
190+
.getId());
189191
return fileService.addFile(ImmutableFileEntry.builder()
190192
.space(uploadFromUrlContext.getJobEntry()
191193
.getSpaceGuid())

multiapps-controller-web/src/main/java/org/cloudfoundry/multiapps/controller/web/upload/client/DeployFromUrlRemoteClient.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,39 +50,48 @@ public DeployFromUrlRemoteClient(ApplicationConfiguration applicationConfigurati
5050

5151
public FileFromUrlData downloadFileFromUrl(UploadFromUrlContext uploadFromUrlContext) throws Exception {
5252
if (!UriUtil.isUrlSecure(uploadFromUrlContext.getFileUrl())) {
53-
throw new SLException(Messages.MTAR_ENDPOINT_NOT_SECURE);
53+
throw new SLException(Messages.MTAR_ENDPOINT_NOT_SECURE_FOR_JOB_WITH_ID, uploadFromUrlContext.getJobEntry()
54+
.getId());
5455
}
5556
UriUtil.validateUrl(uploadFromUrlContext.getFileUrl());
5657

5758
HttpResponse<InputStream> response = callRemoteEndpointWithRetry(uploadFromUrlContext.getFileUrl(),
59+
uploadFromUrlContext.getJobEntry()
60+
.getId(),
5861
uploadFromUrlContext.getUserCredentials());
5962
long fileSize = response.headers()
6063
.firstValueAsLong(Constants.CONTENT_LENGTH)
61-
.orElseThrow(() -> new SLException(Messages.FILE_URL_RESPONSE_DID_NOT_RETURN_CONTENT_LENGTH));
64+
.orElseThrow(() -> new SLException(
65+
MessageFormat.format(Messages.FILE_URL_RESPONSE_DID_NOT_RETURN_CONTENT_LENGTH_FOR_JOB_WITH_ID,
66+
uploadFromUrlContext.getJobEntry()
67+
.getId())));
6268

6369
long maxUploadSize = applicationConfiguration.getMaxUploadSize();
6470
if (fileSize > maxUploadSize) {
65-
throw new SLException(MessageFormat.format(Messages.MAX_UPLOAD_SIZE_EXCEEDED, maxUploadSize));
71+
throw new SLException(MessageFormat.format(Messages.MAX_UPLOAD_SIZE_EXCEEDED_FOR_JOB_WITH_ID, maxUploadSize,
72+
uploadFromUrlContext.getJobEntry()
73+
.getId()));
6674
}
6775
return new FileFromUrlData(response.body(), response.uri(), fileSize);
6876
}
6977

70-
private HttpResponse<InputStream> callRemoteEndpointWithRetry(String decodedUrl, UserCredentials userCredentials)
78+
private HttpResponse<InputStream> callRemoteEndpointWithRetry(String decodedUrl, String jobId, UserCredentials userCredentials)
7179
throws Exception {
7280
return resilientOperationExecutor.execute((CheckedSupplier<HttpResponse<InputStream>>) () -> {
7381
var request = buildFetchFileRequest(decodedUrl, userCredentials);
74-
LOGGER.debug(Messages.CALLING_REMOTE_MTAR_ENDPOINT, getMaskedUri(urlDecodeUrl(decodedUrl)));
82+
LOGGER.debug(Messages.CALLING_REMOTE_MTAR_ENDPOINT_FOR_JOB_WITH_ID, getMaskedUri(urlDecodeUrl(decodedUrl)), jobId);
7583
var response = httpClient.send(request, HttpResponse.BodyHandlers.ofInputStream());
7684
if (response.statusCode() / 100 != 2) {
7785
String error = readErrorBodyFromResponse(response);
7886
LOGGER.error(error);
7987
if (response.statusCode() == HttpStatus.UNAUTHORIZED.value()) {
80-
String errorMessage = MessageFormat.format(Messages.DEPLOY_FROM_URL_WRONG_CREDENTIALS,
81-
UriUtil.stripUserInfo(decodedUrl));
88+
String errorMessage = MessageFormat.format(Messages.DEPLOY_FROM_URL_WRONG_CREDENTIALS_FOR_JOB_WITH_ID,
89+
UriUtil.stripUserInfo(decodedUrl), jobId);
8290
throw new SLException(errorMessage);
8391
}
84-
throw new SLException(MessageFormat.format(Messages.ERROR_FROM_REMOTE_MTAR_ENDPOINT, getMaskedUri(urlDecodeUrl(decodedUrl)),
85-
response.statusCode(), error));
92+
throw new SLException(
93+
MessageFormat.format(Messages.ERROR_FROM_REMOTE_MTAR_ENDPOINT_FOR_JOB_WITH_ID, getMaskedUri(urlDecodeUrl(decodedUrl)),
94+
response.statusCode(), error, jobId));
8695
}
8796
return response;
8897
});

multiapps-controller-web/src/test/java/org/cloudfoundry/multiapps/controller/web/upload/client/DeployFromUrlRemoteClientTest.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.cloudfoundry.multiapps.controller.client.util.CheckedSupplier;
1515
import org.cloudfoundry.multiapps.controller.client.util.ResilientOperationExecutor;
1616
import org.cloudfoundry.multiapps.controller.core.util.ApplicationConfiguration;
17+
import org.cloudfoundry.multiapps.controller.persistence.model.AsyncUploadJobEntry;
1718
import org.cloudfoundry.multiapps.controller.web.Constants;
1819
import org.cloudfoundry.multiapps.controller.web.Messages;
1920
import org.cloudfoundry.multiapps.controller.web.upload.UploadFromUrlContext;
@@ -57,6 +58,9 @@ class DeployFromUrlRemoteClientTest {
5758
@Mock
5859
private UploadFromUrlContext uploadContext;
5960

61+
@Mock
62+
private AsyncUploadJobEntry jobEntry;
63+
6064
private TestableDeployFromUrlRemoteClient client;
6165

6266
private class TestableDeployFromUrlRemoteClient extends DeployFromUrlRemoteClient {
@@ -89,6 +93,8 @@ void setUp() throws Exception {
8993
when(applicationConfiguration.getMaxUploadSize()).thenReturn(MAX_UPLOAD_SIZE);
9094
when(uploadContext.getFileUrl()).thenReturn(SECURE_URL);
9195
when(uploadContext.getUserCredentials()).thenReturn(userCredentials);
96+
when(uploadContext.getJobEntry()).thenReturn(jobEntry);
97+
when(jobEntry.getId()).thenReturn("test-job-id");
9298
when(userCredentials.getUsername()).thenReturn("testUser");
9399
when(userCredentials.getPassword()).thenReturn("testPassword");
94100
}
@@ -115,7 +121,7 @@ void downloadFileFromUrlInsecureUrl() {
115121
when(uploadContext.getFileUrl()).thenReturn(INSECURE_URL);
116122
Exception exception = assertThrows(SLException.class,
117123
() -> client.downloadFileFromUrl(uploadContext));
118-
assertEquals(Messages.MTAR_ENDPOINT_NOT_SECURE, exception.getMessage());
124+
assertEquals(MessageFormat.format(Messages.MTAR_ENDPOINT_NOT_SECURE_FOR_JOB_WITH_ID, "test-job-id"), exception.getMessage());
119125
}
120126

121127
@Test
@@ -127,7 +133,7 @@ void downloadFileFromUrlNoContentLength() throws Exception {
127133

128134
SLException exception = assertThrows(SLException.class,
129135
() -> client.downloadFileFromUrl(uploadContext));
130-
assertEquals(Messages.FILE_URL_RESPONSE_DID_NOT_RETURN_CONTENT_LENGTH, exception.getMessage());
136+
assertEquals(MessageFormat.format(Messages.FILE_URL_RESPONSE_DID_NOT_RETURN_CONTENT_LENGTH_FOR_JOB_WITH_ID, "test-job-id"), exception.getMessage());
131137

132138
}
133139

@@ -141,7 +147,7 @@ void downloadFileFromUrlFileSizeExceedsLimit() throws Exception {
141147

142148
SLException exception = assertThrows(SLException.class,
143149
() -> client.downloadFileFromUrl(uploadContext));
144-
assertEquals(MessageFormat.format(Messages.MAX_UPLOAD_SIZE_EXCEEDED, MAX_UPLOAD_SIZE),
150+
assertEquals(MessageFormat.format(Messages.MAX_UPLOAD_SIZE_EXCEEDED_FOR_JOB_WITH_ID, MAX_UPLOAD_SIZE, "test-job-id"),
145151
exception.getMessage());
146152

147153
}
@@ -170,7 +176,7 @@ void callRemoteEndpointWithRetryUnauthorizedError() throws Exception {
170176

171177
SLException exception = assertThrows(SLException.class,
172178
() -> client.downloadFileFromUrl(uploadContext));
173-
assertEquals("Credentials to https://example.com/file.zip are wrong. Make sure that they are correct.", exception.getMessage());
179+
assertEquals(MessageFormat.format(Messages.DEPLOY_FROM_URL_WRONG_CREDENTIALS_FOR_JOB_WITH_ID, "https://example.com/file.zip", "test-job-id"), exception.getMessage());
174180
}
175181

176182
@Test

0 commit comments

Comments
 (0)