feat(hudi-query): 新增写hdfs文件接口

This commit is contained in:
v-zhangjc9
2024-05-08 10:02:33 +08:00
parent 5c9089419f
commit b2e3a58d27
8 changed files with 122 additions and 92 deletions

View File

@@ -28,6 +28,12 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
<dependency>
<groupId>io.javalin</groupId>
<artifactId>javalin</artifactId>
<version>4.6.8</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@@ -2,6 +2,7 @@ package com.lanyuanxiaoyao.service.forest.service;
import com.dtflys.forest.annotation.BaseRequest;
import com.dtflys.forest.annotation.Get;
import com.dtflys.forest.annotation.Post;
import com.dtflys.forest.annotation.Query;
import com.lanyuanxiaoyao.service.configuration.entity.PageResponse;
import com.lanyuanxiaoyao.service.configuration.entity.hudi.HPath;
@@ -76,6 +77,12 @@ public interface HudiService {
@Get("/hdfs/read")
String read(@Query("root") String root);
@Post("/hdfs/write")
String write(@Query("root") String root, String text);
@Post("/hdfs/write")
String write(@Query("root") String root, String text, @Query("overwrite") Boolean overwrite);
@Get("/hdfs/download")
InputStream download(@Query("root") String root);

View File

@@ -1,7 +1,9 @@
package com.lanyuanxiaoyao.service.forest;
import com.dtflys.forest.Forest;
import com.dtflys.forest.annotation.Body;
import com.dtflys.forest.annotation.Get;
import com.dtflys.forest.annotation.Post;
import com.dtflys.forest.config.ForestConfiguration;
import com.dtflys.forest.converter.text.DefaultTextConverter;
import com.dtflys.forest.utils.ForestDataType;
@@ -21,7 +23,8 @@ public class TestClient {
TestService testService = Forest.client(TestService.class);
// System.out.println(testService.success());
// System.out.println(testService.error());
System.out.println(testService.number());
// System.out.println(testService.number());
System.out.println(testService.sendText("Hello world"));
}
public interface TestService {
@@ -31,8 +34,11 @@ public class TestClient {
@Get("http://localhost:8000/error")
String error();
@Get(value = "http://localhost:8000/number")
@Get("http://localhost:8000/number")
String number();
@Post("http://localhost:8000/receive_text")
String sendText(@Body String text);
}
@SuppressWarnings("unchecked")

View File

@@ -1,55 +1,19 @@
package com.lanyuanxiaoyao.service.forest;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import io.javalin.Javalin;
/**
* @author lanyuanxiaoyao
* @date 2024-01-24
*/
@SuppressWarnings("resource")
public class TestServer {
public static void main(String[] args) throws IOException {
HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0);
server.createContext("/success", new SuccessHandler());
server.createContext("/error", new ErrorHandler());
server.createContext("/number", new NumberHandler());
server.start();
}
public static class SuccessHandler implements HttpHandler {
@Override
public void handle(HttpExchange exchange) throws IOException {
byte[] result = "Success".getBytes();
exchange.sendResponseHeaders(200, result.length);
OutputStream body = exchange.getResponseBody();
body.write(result);
body.close();
}
}
public static class ErrorHandler implements HttpHandler {
@Override
public void handle(HttpExchange exchange) throws IOException {
byte[] result = "Error".getBytes();
exchange.sendResponseHeaders(500, result.length);
OutputStream body = exchange.getResponseBody();
body.write(result);
body.close();
}
}
public static class NumberHandler implements HttpHandler {
@Override
public void handle(HttpExchange exchange) throws IOException {
byte[] result = "-1".getBytes();
exchange.sendResponseHeaders(200, result.length);
OutputStream body = exchange.getResponseBody();
body.write(result);
body.close();
}
public static void main(String[] args) {
Javalin.create()
.get("/success", ctx -> ctx.status(200).result("Success"))
.get("/error", ctx -> ctx.status(500).result("Error"))
.get("/number", ctx -> ctx.status(200).result("-1"))
.post("/receive_text", ctx -> ctx.status(200).result(ctx.body()))
.start(8000);
}
}