|
|
@@ -2,10 +2,7 @@ package cn.reghao.oss.sdk;
|
|
|
|
|
|
import cn.reghao.jutil.jdk.result.WebResult;
|
|
|
import cn.reghao.jutil.jdk.serializer.JsonConverter;
|
|
|
-import cn.reghao.oss.store.api.dto.DownloadUrl;
|
|
|
-import cn.reghao.oss.store.api.dto.ObjectChannel;
|
|
|
-import cn.reghao.oss.store.api.dto.ObjectInfo;
|
|
|
-import cn.reghao.oss.store.api.dto.ServerInfo;
|
|
|
+import cn.reghao.oss.store.api.dto.*;
|
|
|
import cn.reghao.oss.store.api.dto.media.*;
|
|
|
import com.google.gson.reflect.TypeToken;
|
|
|
|
|
|
@@ -66,8 +63,11 @@ public class OssConsoleClient {
|
|
|
this.token = webResult.getData();
|
|
|
}
|
|
|
|
|
|
+ // ****************************************************************************************************************
|
|
|
+ // oss-store 调用的接口(不需要认证)
|
|
|
+ // ****************************************************************************************************************
|
|
|
public void registerNode(String jsonPayload) throws Exception {
|
|
|
- String api = String.format("%s/api/oss/store/node/register", endpoint);
|
|
|
+ String api = String.format("%s/api/oss/store/register", endpoint);
|
|
|
HttpClient httpClient = HttpClient.newBuilder().build();
|
|
|
HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
.header("content-type", "application/json")
|
|
|
@@ -89,10 +89,9 @@ public class OssConsoleClient {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public ServerInfo getServerInfo(int channelId) throws Exception {
|
|
|
- String api = String.format("%s/api/oss/server/info?channelId=%s", endpoint, channelId);
|
|
|
+ public List<ObjectChannel> getObjectChannels(String nodeAddr) throws Exception {
|
|
|
+ String api = String.format("%s/api/oss/store/channels?nodeAddr=%s", endpoint, nodeAddr);
|
|
|
HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
- .header("authorization", "Bearer " + token)
|
|
|
.version(HttpClient.Version.HTTP_1_1)
|
|
|
.GET()
|
|
|
.build();
|
|
|
@@ -104,8 +103,8 @@ public class OssConsoleClient {
|
|
|
throw new Exception(errMsg);
|
|
|
}
|
|
|
|
|
|
- Type type = new TypeToken<WebResult<ServerInfo>>(){}.getType();
|
|
|
- WebResult<ServerInfo> webResult = JsonConverter.jsonToObject(body, type);
|
|
|
+ Type type = new TypeToken<WebResult<List<ObjectChannel>>>(){}.getType();
|
|
|
+ WebResult<List<ObjectChannel>> webResult = JsonConverter.jsonToObject(body, type);
|
|
|
if (webResult.getCode() != 0) {
|
|
|
String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
|
|
|
throw new Exception(errMsg);
|
|
|
@@ -114,8 +113,8 @@ public class OssConsoleClient {
|
|
|
return webResult.getData();
|
|
|
}
|
|
|
|
|
|
- public List<ObjectChannel> getObjectChannels(String nodeAddr) throws Exception {
|
|
|
- String api = String.format("%s/api/oss/channels?nodeAddr=%s", endpoint, nodeAddr);
|
|
|
+ public ObjectChannel getObjectChannel(int createBy, String nodeAddr, int channelId) throws Exception {
|
|
|
+ String api = String.format("%s/api/oss/store/channel?createBy=%s&nodeAddr=%s&channelId=%s", endpoint, createBy, nodeAddr, channelId);
|
|
|
HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
.version(HttpClient.Version.HTTP_1_1)
|
|
|
.GET()
|
|
|
@@ -128,8 +127,8 @@ public class OssConsoleClient {
|
|
|
throw new Exception(errMsg);
|
|
|
}
|
|
|
|
|
|
- Type type = new TypeToken<WebResult<List<ObjectChannel>>>(){}.getType();
|
|
|
- WebResult<List<ObjectChannel>> webResult = JsonConverter.jsonToObject(body, type);
|
|
|
+ Type type = new TypeToken<WebResult<ObjectChannel>>(){}.getType();
|
|
|
+ WebResult<ObjectChannel> webResult = JsonConverter.jsonToObject(body, type);
|
|
|
if (webResult.getCode() != 0) {
|
|
|
String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
|
|
|
throw new Exception(errMsg);
|
|
|
@@ -138,8 +137,8 @@ public class OssConsoleClient {
|
|
|
return webResult.getData();
|
|
|
}
|
|
|
|
|
|
- public ObjectChannel getObjectChannel(int createBy, String nodeAddr, int channelId) throws Exception {
|
|
|
- String api = String.format("%s/api/oss/channel?createBy=%s&nodeAddr=%s&channelId=%s", endpoint, createBy, nodeAddr, channelId);
|
|
|
+ public StoreProperties getStoreProperties(String nodeAddr) throws Exception {
|
|
|
+ String api = String.format("%s/api/oss/store/properties?nodeAddr=%s", endpoint, nodeAddr);
|
|
|
HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
.version(HttpClient.Version.HTTP_1_1)
|
|
|
.GET()
|
|
|
@@ -152,8 +151,36 @@ public class OssConsoleClient {
|
|
|
throw new Exception(errMsg);
|
|
|
}
|
|
|
|
|
|
- Type type = new TypeToken<WebResult<ObjectChannel>>(){}.getType();
|
|
|
- WebResult<ObjectChannel> webResult = JsonConverter.jsonToObject(body, type);
|
|
|
+ Type type = new TypeToken<WebResult<StoreProperties>>(){}.getType();
|
|
|
+ WebResult<StoreProperties> webResult = JsonConverter.jsonToObject(body, type);
|
|
|
+ if (webResult.getCode() != 0) {
|
|
|
+ String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
|
|
|
+ throw new Exception(errMsg);
|
|
|
+ }
|
|
|
+
|
|
|
+ return webResult.getData();
|
|
|
+ }
|
|
|
+
|
|
|
+ // ****************************************************************************************************************
|
|
|
+ // Object 相关接口
|
|
|
+ // ****************************************************************************************************************
|
|
|
+ public ServerInfo getServerInfo(int channelId) throws Exception {
|
|
|
+ String api = String.format("%s/api/oss/server/info?channelId=%s", endpoint, channelId);
|
|
|
+ HttpRequest httpRequest = HttpRequest.newBuilder(new URI(api))
|
|
|
+ .header("authorization", "Bearer " + token)
|
|
|
+ .version(HttpClient.Version.HTTP_1_1)
|
|
|
+ .GET()
|
|
|
+ .build();
|
|
|
+ HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
|
|
|
+ int statusCode = httpResponse.statusCode();
|
|
|
+ String body = httpResponse.body();
|
|
|
+ if (statusCode != 200) {
|
|
|
+ String errMsg = String.format("%s -> %s", statusCode, body);
|
|
|
+ throw new Exception(errMsg);
|
|
|
+ }
|
|
|
+
|
|
|
+ Type type = new TypeToken<WebResult<ServerInfo>>(){}.getType();
|
|
|
+ WebResult<ServerInfo> webResult = JsonConverter.jsonToObject(body, type);
|
|
|
if (webResult.getCode() != 0) {
|
|
|
String errMsg = String.format("%s - %s", webResult.getCode(), webResult.getMsg());
|
|
|
throw new Exception(errMsg);
|