zentol closed pull request #7300: [FLINK-11151][rest] Create parent directories
in FileUploadHandler
URL: https://github.com/apache/flink/pull/7300
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/flink-runtime/src/main/java/org/apache/flink/runtime/rest/FileUploadHandler.java
b/flink-runtime/src/main/java/org/apache/flink/runtime/rest/FileUploadHandler.java
index 7c46af04b55..b99de66122c 100644
---
a/flink-runtime/src/main/java/org/apache/flink/runtime/rest/FileUploadHandler.java
+++
b/flink-runtime/src/main/java/org/apache/flink/runtime/rest/FileUploadHandler.java
@@ -102,6 +102,10 @@ protected void channelRead0(final ChannelHandlerContext
ctx, final HttpObject ms
checkState(currentUploadDir ==
null);
currentHttpPostRequestDecoder =
new HttpPostRequestDecoder(DATA_FACTORY, httpRequest);
currentHttpRequest =
ReferenceCountUtil.retain(httpRequest);
+
+ // make sure that we still have
a upload dir in case that it got deleted in the meanwhile
+
RestServerEndpoint.createUploadDir(uploadDir, LOG);
+
currentUploadDir =
Files.createDirectory(uploadDir.resolve(UUID.randomUUID().toString()));
} else {
ctx.fireChannelRead(ReferenceCountUtil.retain(msg));
diff --git
a/flink-runtime/src/test/java/org/apache/flink/runtime/rest/FileUploadHandlerTest.java
b/flink-runtime/src/test/java/org/apache/flink/runtime/rest/FileUploadHandlerTest.java
index 858c6620b3c..771fd8a837c 100644
---
a/flink-runtime/src/test/java/org/apache/flink/runtime/rest/FileUploadHandlerTest.java
+++
b/flink-runtime/src/test/java/org/apache/flink/runtime/rest/FileUploadHandlerTest.java
@@ -20,6 +20,7 @@
import org.apache.flink.runtime.io.network.netty.NettyLeakDetectionResource;
import org.apache.flink.runtime.rest.util.RestMapperUtils;
+import org.apache.flink.util.FileUtils;
import org.apache.flink.util.TestLogger;
import
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
@@ -123,6 +124,20 @@ private static Request
finalizeRequest(MultipartBody.Builder builder, String hea
return builder.addFormDataPart(attribute, jsonPayload);
}
+ @Test
+ public void testUploadDirectoryRegeneration() throws Exception {
+ OkHttpClient client = new OkHttpClient();
+
+ MultipartUploadResource.MultipartFileHandler fileHandler =
MULTIPART_UPLOAD_RESOURCE.getFileHandler();
+
+
FileUtils.deleteDirectory(MULTIPART_UPLOAD_RESOURCE.getUploadDirectory().toFile());
+
+ Request fileRequest =
buildFileRequest(fileHandler.getMessageHeaders().getTargetRestEndpointURL());
+ try (Response response = client.newCall(fileRequest).execute())
{
+
assertEquals(fileHandler.getMessageHeaders().getResponseStatusCode().code(),
response.code());
+ }
+ }
+
@Test
public void testMixedMultipart() throws Exception {
OkHttpClient client = new OkHttpClient();
diff --git
a/flink-runtime/src/test/java/org/apache/flink/runtime/rest/MultipartUploadResource.java
b/flink-runtime/src/test/java/org/apache/flink/runtime/rest/MultipartUploadResource.java
index 22de8a1dcde..65690c80b09 100644
---
a/flink-runtime/src/test/java/org/apache/flink/runtime/rest/MultipartUploadResource.java
+++
b/flink-runtime/src/test/java/org/apache/flink/runtime/rest/MultipartUploadResource.java
@@ -163,6 +163,10 @@ public MultipartJsonHandler getJsonHandler() {
return jsonHandler;
}
+ public Path getUploadDirectory() {
+ return configuredUploadDir;
+ }
+
public void resetState() {
mixedHandler.lastReceivedRequest = null;
jsonHandler.lastReceivedRequest = null;
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services