From d971b85da2839e21055f0078c48a5678d311a879 Mon Sep 17 00:00:00 2001 From: mabofu Date: Fri, 23 Dec 2022 16:10:00 +0800 Subject: [PATCH] Add node api to get info from dsms-storage --- .../service/impl/ClusterServiceImpl.java | 8 +- .../com/dsms/modules/util/RemoteCallUtil.java | 22 +-- .../service/impl/RemoteCallImplTest.java | 31 +++-- .../dfsbroker/cluster/api/ClusterApiTest.java | 22 +-- .../dsms/dfsbroker/node/api/NodeApiTest.java | 77 +++++++++++ .../constant/RemoteResponseStatusEnum.java | 45 +++++++ .../com/dsms/common/constant/ResultCode.java | 7 + .../remotecall/model/FinishedDetail.java | 26 ++++ .../remotecall/model/RemoteFixedParam.java | 44 ++++++ .../remotecall/model/RemoteRequest.java | 51 ++++--- .../remotecall/model/RemoteResponse.java | 125 ++++++++++++++++-- .../remotecall/service/IRemoteCall.java | 2 +- .../service/impl/RemoteCallImpl.java | 39 +++++- .../dfsbroker/cluster/api/ClusterApi.java | 12 +- .../dfsbroker/common/CommandDirector.java | 36 +++++ .../dsms/dfsbroker/common/RequestUrlEnum.java | 35 +++++ .../dsms/dfsbroker/common/api/CommonApi.java | 70 ++++++++++ .../com/dsms/dfsbroker/node/api/NodeApi.java | 53 ++++++++ .../com/dsms/dfsbroker/node/model/Device.java | 55 +++++++- .../com/dsms/dfsbroker/node/model/Node.java | 19 ++- .../dfsbroker/node/model/remote/Labels.java | 20 +++ .../dsms/dfsbroker/node/model/remote/Lvs.java | 28 ++++ .../node/model/remote/OrchDeviceLsResult.java | 47 +++++++ .../node/model/remote/OsdDfResult.java | 42 ++++++ .../node/model/remote/ResponseDevice.java | 42 ++++++ .../node/model/remote/ResponseMon.java | 25 ++++ .../node/model/remote/ResponseNode.java | 32 +++++ .../dfsbroker/node/model/remote/Stray.java | 20 +++ .../dfsbroker/node/model/remote/Summary.java | 20 +++ .../dfsbroker/node/model/remote/SysApi.java | 26 ++++ .../dfsbroker/node/request/MonRequest.java | 29 ++++ .../node/request/OrchDeviceLsRequest.java | 40 ++++++ .../dfsbroker/node/request/OsdDfRequest.java | 37 ++++++ .../dfsbroker/node/service/INodeService.java | 18 +++ 34 files changed, 1122 insertions(+), 83 deletions(-) create mode 100644 dsms-engine-application/src/test/java/com/dsms/dfsbroker/node/api/NodeApiTest.java create mode 100644 dsms-engine-common/src/main/java/com/dsms/common/constant/RemoteResponseStatusEnum.java create mode 100644 dsms-engine-common/src/main/java/com/dsms/common/remotecall/model/FinishedDetail.java create mode 100644 dsms-engine-common/src/main/java/com/dsms/common/remotecall/model/RemoteFixedParam.java create mode 100644 dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/common/CommandDirector.java create mode 100644 dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/common/RequestUrlEnum.java create mode 100644 dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/common/api/CommonApi.java create mode 100644 dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/Labels.java create mode 100644 dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/Lvs.java create mode 100644 dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/OrchDeviceLsResult.java create mode 100644 dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/OsdDfResult.java create mode 100644 dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/ResponseDevice.java create mode 100644 dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/ResponseMon.java create mode 100644 dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/ResponseNode.java create mode 100644 dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/Stray.java create mode 100644 dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/Summary.java create mode 100644 dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/SysApi.java create mode 100644 dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/request/MonRequest.java create mode 100644 dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/request/OrchDeviceLsRequest.java create mode 100644 dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/request/OsdDfRequest.java diff --git a/dsms-engine-application/src/main/java/com/dsms/modules/cluster/service/impl/ClusterServiceImpl.java b/dsms-engine-application/src/main/java/com/dsms/modules/cluster/service/impl/ClusterServiceImpl.java index e022c00c..d38f3dca 100644 --- a/dsms-engine-application/src/main/java/com/dsms/modules/cluster/service/impl/ClusterServiceImpl.java +++ b/dsms-engine-application/src/main/java/com/dsms/modules/cluster/service/impl/ClusterServiceImpl.java @@ -24,6 +24,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.dsms.common.constant.ClusterStatusEnum; import com.dsms.common.constant.ResultCode; import com.dsms.common.exception.DsmsEngineException; +import com.dsms.common.remotecall.model.RemoteFixedParam; import com.dsms.common.remotecall.model.RemoteRequest; import com.dsms.dfsbroker.cluster.api.ClusterApi; import com.dsms.dfsbroker.cluster.model.Cluster; @@ -57,7 +58,7 @@ public class ClusterServiceImpl extends ServiceImpl impl if (list.isEmpty()) { throw new DsmsEngineException(ResultCode.CLUSTER_NOTBIND); } - RemoteRequest remoteRequest = RemoteCallUtil.tranClusterToRemoteRequest(list.get(0)); + RemoteRequest remoteRequest = RemoteCallUtil.generateRemoteRequest(); Cluster clusterVersion = clusterApi.getClusterVersion(remoteRequest); return list.get(0); @@ -86,7 +87,9 @@ public class ClusterServiceImpl extends ServiceImpl impl throw new DsmsEngineException(e, ResultCode.CLUSTER_SERVICEERROR); } //3. 测试key是否有效 - RemoteRequest remoteRequest = RemoteCallUtil.tranClusterToRemoteRequest(cluster); + RemoteCallUtil.updateRemoteFixedParam(cluster); + RemoteRequest remoteRequest = RemoteCallUtil.generateRemoteRequest(); + try { Cluster clusterInfo = clusterApi.getClusterVersion(remoteRequest); log.info(clusterInfo.toString()); @@ -108,6 +111,7 @@ public class ClusterServiceImpl extends ServiceImpl impl if (!isRemove) { throw new DsmsEngineException(ResultCode.CLUSTER_NOTBIND); } + RemoteCallUtil.remoteFixedParam = null; return isRemove; } diff --git a/dsms-engine-application/src/main/java/com/dsms/modules/util/RemoteCallUtil.java b/dsms-engine-application/src/main/java/com/dsms/modules/util/RemoteCallUtil.java index 2a84e531..c0794508 100644 --- a/dsms-engine-application/src/main/java/com/dsms/modules/util/RemoteCallUtil.java +++ b/dsms-engine-application/src/main/java/com/dsms/modules/util/RemoteCallUtil.java @@ -17,6 +17,7 @@ package com.dsms.modules.util; import com.dsms.common.constant.SystemConst; import com.dsms.common.model.LoginUser; +import com.dsms.common.remotecall.model.RemoteFixedParam; import com.dsms.common.remotecall.model.RemoteRequest; import com.dsms.dfsbroker.cluster.model.Cluster; import org.springframework.security.core.Authentication; @@ -24,17 +25,20 @@ import org.springframework.security.core.context.SecurityContextHolder; public class RemoteCallUtil { - public static RemoteRequest tranClusterToRemoteRequest(Cluster cluster) { - RemoteRequest request = new RemoteRequest(); + public static RemoteFixedParam remoteFixedParam = new RemoteFixedParam(); + public static RemoteRequest generateRemoteRequest() { + return new RemoteRequest(remoteFixedParam); + } + + public static void updateRemoteFixedParam(Cluster cluster) { + remoteFixedParam = new RemoteFixedParam(); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); LoginUser loginUser = (LoginUser) authentication.getPrincipal(); - request.setScheme(SystemConst.HTTPS_SCHEME); - request.setHost(cluster.getClusterVip()); - request.setPort(cluster.getClusterPort()); - request.setUsername(loginUser.getUsername()); - request.setPassword(cluster.getAuthKey()); - - return request; + remoteFixedParam.setScheme(SystemConst.HTTPS_SCHEME); + remoteFixedParam.setHost(cluster.getClusterVip()); + remoteFixedParam.setPort(cluster.getClusterPort()); + remoteFixedParam.setUsername(loginUser.getUsername()); + remoteFixedParam.setPassword(cluster.getAuthKey()); } } diff --git a/dsms-engine-application/src/test/java/com/dsms/common/remotecall/service/impl/RemoteCallImplTest.java b/dsms-engine-application/src/test/java/com/dsms/common/remotecall/service/impl/RemoteCallImplTest.java index 664f3d5c..672ff214 100644 --- a/dsms-engine-application/src/test/java/com/dsms/common/remotecall/service/impl/RemoteCallImplTest.java +++ b/dsms-engine-application/src/test/java/com/dsms/common/remotecall/service/impl/RemoteCallImplTest.java @@ -16,8 +16,12 @@ package com.dsms.common.remotecall.service.impl; +import com.dsms.common.constant.SystemConst; import com.dsms.common.remotecall.model.RemoteRequest; import com.dsms.common.remotecall.model.RemoteResponse; +import com.dsms.modules.util.RemoteCallUtil; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -27,22 +31,25 @@ import org.springframework.test.context.ContextConfiguration; import java.util.HashMap; import java.util.Map; -@SpringBootTest +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) class RemoteCallImplTest { @Autowired RemoteCallImpl remoteCall; - @Test - void callRestfulApi() { - RemoteRequest remoteRequest = new RemoteRequest(); - remoteRequest.setHttpMethod(HttpMethod.GET); - remoteRequest.setScheme("https"); - remoteRequest.setHost("127.0.0.1"); - remoteRequest.setPort(8003); - remoteRequest.setUrlPrefix("doc"); - remoteRequest.setUsername("api"); - remoteRequest.setPassword("ecdd2f3b-ce23-4a04-acf7-9b7a514c2c0d"); + private static RemoteRequest request; - RemoteResponse remoteResponse = remoteCall.callRestfulApi(remoteRequest); + @BeforeAll + public static void setUp() { + RemoteCallUtil.remoteFixedParam.setScheme(SystemConst.HTTPS_SCHEME); + RemoteCallUtil.remoteFixedParam.setHost("node1"); + RemoteCallUtil.remoteFixedParam.setPort(8003); + RemoteCallUtil.remoteFixedParam.setUsername("admin"); + RemoteCallUtil.remoteFixedParam.setPassword("fa51c04e-31c2-4e81-bf43-4af7f1cee390"); + request = RemoteCallUtil.generateRemoteRequest(); + } + @Test + void callRestfulApi() throws Throwable { + request.setUrlPrefix("doc"); + Assertions.assertThatCode(() -> remoteCall.callRestfulApi(request)).doesNotThrowAnyException(); } } \ No newline at end of file diff --git a/dsms-engine-application/src/test/java/com/dsms/dfsbroker/cluster/api/ClusterApiTest.java b/dsms-engine-application/src/test/java/com/dsms/dfsbroker/cluster/api/ClusterApiTest.java index 4321d4a3..1118d27a 100644 --- a/dsms-engine-application/src/test/java/com/dsms/dfsbroker/cluster/api/ClusterApiTest.java +++ b/dsms-engine-application/src/test/java/com/dsms/dfsbroker/cluster/api/ClusterApiTest.java @@ -17,8 +17,11 @@ package com.dsms.dfsbroker.cluster.api; +import com.dsms.common.constant.SystemConst; import com.dsms.common.remotecall.model.RemoteRequest; +import com.dsms.modules.util.RemoteCallUtil; import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -28,16 +31,19 @@ import org.springframework.boot.test.context.SpringBootTest; class ClusterApiTest { @Autowired private ClusterApi clusterApi; + private static RemoteRequest request; + + @BeforeAll + public static void setUp() { + RemoteCallUtil.remoteFixedParam.setScheme(SystemConst.HTTPS_SCHEME); + RemoteCallUtil.remoteFixedParam.setHost("node1"); + RemoteCallUtil.remoteFixedParam.setPort(8003); + RemoteCallUtil.remoteFixedParam.setUsername("admin"); + RemoteCallUtil.remoteFixedParam.setPassword("fa51c04e-31c2-4e81-bf43-4af7f1cee390"); + request = RemoteCallUtil.generateRemoteRequest(); + } @Test void getClusterVersion() { - RemoteRequest request = new RemoteRequest(); - - request.setScheme("https"); - request.setHost("127.0.0.1"); - request.setPort(8003); - request.setUsername("api"); - request.setPassword("ecdd2f3b-ce23-4a04-acf7-9b7a514c2c0d"); - log.info(clusterApi.getClusterVersion(request).toString()); } diff --git a/dsms-engine-application/src/test/java/com/dsms/dfsbroker/node/api/NodeApiTest.java b/dsms-engine-application/src/test/java/com/dsms/dfsbroker/node/api/NodeApiTest.java new file mode 100644 index 00000000..899f61f9 --- /dev/null +++ b/dsms-engine-application/src/test/java/com/dsms/dfsbroker/node/api/NodeApiTest.java @@ -0,0 +1,77 @@ +/* + * Copyright 2022 The DSMS Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dsms.dfsbroker.node.api; + + +import com.dsms.common.constant.SystemConst; +import com.dsms.common.remotecall.model.RemoteRequest; +import com.dsms.dfsbroker.node.model.Device; +import com.dsms.dfsbroker.node.model.remote.OrchDeviceLsResult; +import com.dsms.dfsbroker.node.model.remote.ResponseMon; +import com.dsms.modules.util.RemoteCallUtil; +import lombok.extern.slf4j.Slf4j; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import java.rmi.server.RemoteCall; +import java.util.List; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; + + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@Slf4j +class NodeApiTest { + @Autowired + private NodeApi nodeApi; + + private static RemoteRequest request; + + @BeforeAll + public static void setUp() { + RemoteCallUtil.remoteFixedParam.setScheme(SystemConst.HTTPS_SCHEME); + RemoteCallUtil.remoteFixedParam.setHost("node1"); + RemoteCallUtil.remoteFixedParam.setPort(8003); + RemoteCallUtil.remoteFixedParam.setUsername("admin"); + RemoteCallUtil.remoteFixedParam.setPassword("fa51c04e-31c2-4e81-bf43-4af7f1cee390"); + request = RemoteCallUtil.generateRemoteRequest(); + } + + @Test + void getNodeList() throws Throwable { + List nodeList = nodeApi.getNodeList(request); + assertThat(nodeList, hasItems(hasProperty("name", is(request.getRemoteFixedParam().getHost())))); + } + + @Test + void getNodeInfo() throws Throwable { + OrchDeviceLsResult orchDeviceLsResult = nodeApi.getOrchDeviceLs(request, "node1"); + List devices = Device.orchDeviceLsResultParseDevice(orchDeviceLsResult); + assertThat(devices, hasItems()); + } + + @Test + void getOsdDf() { + Assertions.assertThatCode(() -> nodeApi.getOsdDf(request)).doesNotThrowAnyException(); + } + + +} \ No newline at end of file diff --git a/dsms-engine-common/src/main/java/com/dsms/common/constant/RemoteResponseStatusEnum.java b/dsms-engine-common/src/main/java/com/dsms/common/constant/RemoteResponseStatusEnum.java new file mode 100644 index 00000000..2fab375f --- /dev/null +++ b/dsms-engine-common/src/main/java/com/dsms/common/constant/RemoteResponseStatusEnum.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 The DSMS Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.dsms.common.constant; + +import lombok.AllArgsConstructor; +import lombok.Getter; + + +/** + * 响应状态枚举 + */ +@Getter +@AllArgsConstructor +public enum RemoteResponseStatusEnum { + /** + * 成功 + */ + SUCCESS(0, "success"), + /** + * 等待中 + */ + PENDING(1, "pending"), + /** + * 失败 + */ + FAILED(2, "failed"); + + + private final int status; + private final String message; + +} diff --git a/dsms-engine-common/src/main/java/com/dsms/common/constant/ResultCode.java b/dsms-engine-common/src/main/java/com/dsms/common/constant/ResultCode.java index 207abc7f..08a27f1b 100644 --- a/dsms-engine-common/src/main/java/com/dsms/common/constant/ResultCode.java +++ b/dsms-engine-common/src/main/java/com/dsms/common/constant/ResultCode.java @@ -35,6 +35,8 @@ public enum ResultCode { * 业务状态码枚举 */ SUCCESS(0, "成功"), + REMOTE_CALLFAIL(100, "调用分布式文件系统失败"), + LOGIN_EMPTY(1000, "用户名或密码为空"), LOGIN_FAIL(1001, "用户名密码错误"), LOGIN_FREEZE(1002, "用户被冻结"), @@ -45,6 +47,11 @@ public enum ResultCode { CLUSTER_SERVICEERROR(1102, "集群存储服务异常"), CLUSTER_KEY_ERROR(1103, "集群存储服务认证失败"), CLUSTER_ALREADYBIND(1104, "集群已关联"), + + NODE_ADDOSD_TASKERROR(1200, "节点新增磁盘任务创建失败"), + NODE_POOLEXIST(1201, "磁盘已占用,请先移除占用"), + NODE_REMOVEOSD_TASKERROR(1202, "节点删除磁盘任务创建失败"), + NODE_LISTNODE_ERROR(1203, "获取节点池信息失败"), ; /** diff --git a/dsms-engine-common/src/main/java/com/dsms/common/remotecall/model/FinishedDetail.java b/dsms-engine-common/src/main/java/com/dsms/common/remotecall/model/FinishedDetail.java new file mode 100644 index 00000000..f2f01713 --- /dev/null +++ b/dsms-engine-common/src/main/java/com/dsms/common/remotecall/model/FinishedDetail.java @@ -0,0 +1,26 @@ +/* + * Copyright 2022 The DSMS Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dsms.common.remotecall.model; + +import lombok.Data; + +@Data +public class FinishedDetail { + String command; + String outb; + String outs; +} diff --git a/dsms-engine-common/src/main/java/com/dsms/common/remotecall/model/RemoteFixedParam.java b/dsms-engine-common/src/main/java/com/dsms/common/remotecall/model/RemoteFixedParam.java new file mode 100644 index 00000000..cf5df2a0 --- /dev/null +++ b/dsms-engine-common/src/main/java/com/dsms/common/remotecall/model/RemoteFixedParam.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 The DSMS Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dsms.common.remotecall.model; + +import lombok.Data; + +@Data +public class RemoteFixedParam { + + /** + * 协议,例如http + */ + private String scheme; + /** + * 主机,例如127.0.0.1 + */ + private String host; + /** + * 端口,默认-1 + */ + private int port = -1; + /** + * 请求认证 useruser + */ + private String username; + /** + * 请求认证 password + */ + private String password; +} diff --git a/dsms-engine-common/src/main/java/com/dsms/common/remotecall/model/RemoteRequest.java b/dsms-engine-common/src/main/java/com/dsms/common/remotecall/model/RemoteRequest.java index 88e34dc0..3f3461e8 100644 --- a/dsms-engine-common/src/main/java/com/dsms/common/remotecall/model/RemoteRequest.java +++ b/dsms-engine-common/src/main/java/com/dsms/common/remotecall/model/RemoteRequest.java @@ -17,6 +17,7 @@ package com.dsms.common.remotecall.model; import cn.hutool.core.net.url.UrlPath; +import lombok.Builder; import lombok.Data; import org.springframework.http.HttpMethod; @@ -33,26 +34,6 @@ public class RemoteRequest { * 请求类型 */ private HttpMethod httpMethod; - /** - * 协议,例如http - */ - private String scheme; - /** - * 主机,例如127.0.0.1 - */ - private String host; - /** - * 端口,默认-1 - */ - private int port = -1; - /** - * 路径,例如/aa/bb/cc - */ - private UrlPath path; - /** - * 请求url - */ - private String url; /** * 请求前缀 */ @@ -61,12 +42,26 @@ public class RemoteRequest { * 请求体json格式 */ private String requestBody; - /** - * 请求认证 useruser - */ - private String username; - /** - * 请求认证 password - */ - private String password; + + private RemoteFixedParam remoteFixedParam; + + public RemoteRequest buildRequestParam(String urlPrefix, HttpMethod httpMethod, String requestBody) { + this.urlPrefix = urlPrefix; + this.httpMethod = httpMethod; + this.requestBody = requestBody; + return this; + } + public RemoteRequest buildRequestParam(RemoteRequest remoteRequest) { + this.urlPrefix = remoteRequest.urlPrefix; + this.httpMethod = remoteRequest.httpMethod; + this.requestBody = remoteRequest.requestBody; + return this; + } + + public RemoteRequest() { + } + + public RemoteRequest(RemoteFixedParam remoteFixedParam) { + this.remoteFixedParam = remoteFixedParam; + } } diff --git a/dsms-engine-common/src/main/java/com/dsms/common/remotecall/model/RemoteResponse.java b/dsms-engine-common/src/main/java/com/dsms/common/remotecall/model/RemoteResponse.java index f55ef5c4..d6278e0f 100644 --- a/dsms-engine-common/src/main/java/com/dsms/common/remotecall/model/RemoteResponse.java +++ b/dsms-engine-common/src/main/java/com/dsms/common/remotecall/model/RemoteResponse.java @@ -16,12 +16,15 @@ package com.dsms.common.remotecall.model; -import lombok.Data; +import com.alibaba.fastjson2.annotation.JSONField; + +import java.util.Arrays; +import java.util.List; /** * 远程调用响应体 */ -@Data +//@Data public class RemoteResponse { /** * 响应体 @@ -35,13 +38,15 @@ public class RemoteResponse { * ceph响应 finished 字段 */ private String failed; + /** * ceph响应 finished 字段 */ - private FinishedDetail[] finished; + private List finished; /** * ceph响应 hasFailed 字段 */ + @JSONField(name = "has_failed") private boolean hasFailed; /** * ceph响应 id 字段 @@ -50,12 +55,13 @@ public class RemoteResponse { /** * ceph响应 is_finished 字段 */ + @JSONField(name = "is_finished") private boolean isFinished; /** * ceph响应 isWaiting 字段 */ + @JSONField(name = "is_waiting") private boolean isWaiting; - /** * ceph响应 running 字段 */ @@ -68,11 +74,110 @@ public class RemoteResponse { * ceph响应 waiting 字段 */ private String[] waiting; -} -@Data -class FinishedDetail { - String command; - String outb; - String outs; + public String getBody() { + return body; + } + + public void setBody(String body) { + this.body = body; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getFailed() { + return failed; + } + + public void setFailed(String failed) { + this.failed = failed; + } + + + public boolean isHasFailed() { + return hasFailed; + } + + public void setHasFailed(boolean hasFailed) { + this.hasFailed = hasFailed; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public boolean getIsFinished() { + return isFinished; + } + + public void setIsFinished(boolean isFinished) { + this.isFinished = isFinished; + } + + public boolean getIsWaiting() { + return isWaiting; + } + + public void setIsWaiting(boolean isWaiting) { + this.isWaiting = isWaiting; + } + + public String[] getRunning() { + return running; + } + + public void setRunning(String[] running) { + this.running = running; + } + + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } + + public String[] getWaiting() { + return waiting; + } + + public void setWaiting(String[] waiting) { + this.waiting = waiting; + } + + public List getFinished() { + return finished; + } + + public void setFinished(List finished) { + this.finished = finished; + } + + @Override + public String toString() { + return "RemoteResponse{" + + "body='" + body + '\'' + + ", message='" + message + '\'' + + ", failed='" + failed + '\'' + + ", finished=" + finished + + ", hasFailed=" + hasFailed + + ", id='" + id + '\'' + + ", isFinished=" + isFinished + + ", isWaiting=" + isWaiting + + ", running=" + Arrays.toString(running) + + ", state='" + state + '\'' + + ", waiting=" + Arrays.toString(waiting) + + '}'; + } } diff --git a/dsms-engine-common/src/main/java/com/dsms/common/remotecall/service/IRemoteCall.java b/dsms-engine-common/src/main/java/com/dsms/common/remotecall/service/IRemoteCall.java index 6a1751c7..8125aaba 100644 --- a/dsms-engine-common/src/main/java/com/dsms/common/remotecall/service/IRemoteCall.java +++ b/dsms-engine-common/src/main/java/com/dsms/common/remotecall/service/IRemoteCall.java @@ -28,7 +28,7 @@ public interface IRemoteCall { * @param remoteRequest 请求对象 * @return RemoteResponse 响应对象 */ - RemoteResponse callRestfulApi(RemoteRequest remoteRequest); + RemoteResponse callRestfulApi(RemoteRequest remoteRequest) throws Throwable; /** * 调用dsms-storage提供的lib api diff --git a/dsms-engine-common/src/main/java/com/dsms/common/remotecall/service/impl/RemoteCallImpl.java b/dsms-engine-common/src/main/java/com/dsms/common/remotecall/service/impl/RemoteCallImpl.java index 5cafa880..d75764f2 100644 --- a/dsms-engine-common/src/main/java/com/dsms/common/remotecall/service/impl/RemoteCallImpl.java +++ b/dsms-engine-common/src/main/java/com/dsms/common/remotecall/service/impl/RemoteCallImpl.java @@ -16,11 +16,14 @@ package com.dsms.common.remotecall.service.impl; +import cn.hutool.core.io.IORuntimeException; import cn.hutool.core.net.url.UrlBuilder; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpUtil; import cn.hutool.http.Method; +import com.dsms.common.constant.ResultCode; +import com.dsms.common.exception.DsmsEngineException; import com.dsms.common.remotecall.model.RemoteRequest; import com.dsms.common.remotecall.model.RemoteResponse; import com.dsms.common.remotecall.service.IRemoteCall; @@ -31,22 +34,27 @@ import org.springframework.http.HttpStatus; import org.springframework.security.authentication.AuthenticationServiceException; import org.springframework.stereotype.Service; +import javax.security.auth.message.AuthException; +import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.util.concurrent.TimeUnit; @Slf4j @Service public class RemoteCallImpl implements IRemoteCall { + public static final int MAX_RETRIES = 3; + @Autowired private RestTemplateBuilder restTemplateBuilder; @Override - public RemoteResponse callRestfulApi(RemoteRequest remoteRequest) { + public RemoteResponse callRestfulApi(RemoteRequest remoteRequest) throws Throwable { RemoteResponse remoteResponse = new RemoteResponse(); HttpRequest httpRequest = null; - UrlBuilder of = UrlBuilder.of(remoteRequest.getScheme(), remoteRequest.getHost(), remoteRequest.getPort(), remoteRequest.getUrlPrefix(), null, null, StandardCharsets.UTF_8); + UrlBuilder of = UrlBuilder.of(remoteRequest.getRemoteFixedParam().getScheme(), remoteRequest.getRemoteFixedParam().getHost(), remoteRequest.getRemoteFixedParam().getPort(), remoteRequest.getUrlPrefix(), null, null, StandardCharsets.UTF_8); String url = of.build(); switch (remoteRequest.getHttpMethod()) { case GET: @@ -59,13 +67,30 @@ public class RemoteCallImpl implements IRemoteCall { log.error("unknown request method"); throw new RuntimeException("unknown request method"); } - httpRequest.basicAuth(remoteRequest.getUsername(), remoteRequest.getPassword()); - HttpResponse execute = httpRequest.execute(); - if(execute.getStatus() == HttpStatus.UNAUTHORIZED.value()){ + httpRequest.timeout(3000); + httpRequest.basicAuth(remoteRequest.getRemoteFixedParam().getUsername(), remoteRequest.getRemoteFixedParam().getPassword()); + if (remoteRequest.getRequestBody() != null) { + httpRequest.body(remoteRequest.getRequestBody()); + } + int numAttempts = 0; + HttpResponse httpResponse = null; + do { + numAttempts++; + try { + httpResponse = httpRequest.execute(); + } catch (IORuntimeException ex) { + log.error("remotecall fail! fail time:{},fail reason:{}", numAttempts, ex.getMessage(), ex); + } + TimeUnit.MILLISECONDS.sleep(numAttempts * 100); + } while (numAttempts <= MAX_RETRIES); + if (null == httpResponse) { + throw new DsmsEngineException(ResultCode.REMOTE_CALLFAIL); + } + if (httpResponse.getStatus() == HttpStatus.UNAUTHORIZED.value()) { throw new AuthenticationServiceException("auth: Incorrect password"); } - log.debug("request:{},response:{}", remoteRequest, execute); - remoteResponse.setBody(execute.body()); + log.debug("request:{},response:{}", remoteRequest, httpResponse); + remoteResponse.setBody(httpResponse.body()); return remoteResponse; } diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/cluster/api/ClusterApi.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/cluster/api/ClusterApi.java index c024d405..3e5b0fe4 100644 --- a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/cluster/api/ClusterApi.java +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/cluster/api/ClusterApi.java @@ -19,6 +19,8 @@ package com.dsms.dfsbroker.cluster.api; import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; +import com.dsms.common.constant.ResultCode; +import com.dsms.common.exception.DsmsEngineException; import com.dsms.common.remotecall.model.RemoteRequest; import com.dsms.common.remotecall.model.RemoteResponse; import com.dsms.common.remotecall.service.IRemoteCall; @@ -26,6 +28,7 @@ import com.dsms.dfsbroker.cluster.model.Cluster; import com.dsms.dfsbroker.node.model.Node; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpMethod; +import org.springframework.security.core.AuthenticationException; import org.springframework.stereotype.Component; import java.util.List; @@ -44,7 +47,14 @@ public class ClusterApi { remoteRequest.setUrlPrefix("server"); remoteRequest.setHttpMethod(HttpMethod.GET); - RemoteResponse remoteResponse = remoteCall.callRestfulApi(remoteRequest); + RemoteResponse remoteResponse; + try { + remoteResponse = remoteCall.callRestfulApi(remoteRequest); + } catch (AuthenticationException e) { + throw new DsmsEngineException(e, ResultCode.CLUSTER_KEY_ERROR); + } catch (Throwable e) { + throw new DsmsEngineException(e, ResultCode.REMOTE_CALLFAIL); + } String message = remoteResponse.getBody(); JSONArray objects = JSONUtil.parseArray(message); version = new Node[objects.size()]; diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/common/CommandDirector.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/common/CommandDirector.java new file mode 100644 index 00000000..2f3f9ee2 --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/common/CommandDirector.java @@ -0,0 +1,36 @@ +/* + * Copyright 2022 The DSMS Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dsms.dfsbroker.common; + +import com.dsms.common.remotecall.model.RemoteRequest; +import com.dsms.dfsbroker.node.request.MonRequest; +import com.dsms.dfsbroker.node.request.OrchDeviceLsRequest; +import com.dsms.dfsbroker.node.request.OsdDfRequest; + +public class CommandDirector { + public static void constructMonRequest(RemoteRequest request) { + request.buildRequestParam(new MonRequest()); + } + + public static void constructOrchDeviceLsRequest(RemoteRequest request, String hostname) { + request.buildRequestParam(new OrchDeviceLsRequest(hostname)); + } + + public static void constructOsdDfRequest(RemoteRequest request) { + request.buildRequestParam(new OsdDfRequest()); + } +} diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/common/RequestUrlEnum.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/common/RequestUrlEnum.java new file mode 100644 index 00000000..a3565841 --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/common/RequestUrlEnum.java @@ -0,0 +1,35 @@ +/* + * Copyright 2022 The DSMS Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dsms.dfsbroker.common; + + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * dfsbroker 请求url枚举 + */ +@Getter +@AllArgsConstructor +public enum RequestUrlEnum { + + MON_URL("mon"), + REQUEST_URL("request"); + + private final String urlPrefix; + +} diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/common/api/CommonApi.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/common/api/CommonApi.java new file mode 100644 index 00000000..41daf22c --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/common/api/CommonApi.java @@ -0,0 +1,70 @@ +/* + * Copyright 2022 The DSMS Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dsms.dfsbroker.common.api; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.dsms.common.constant.RemoteResponseStatusEnum; +import com.dsms.common.constant.ResultCode; +import com.dsms.common.exception.DsmsEngineException; +import com.dsms.common.remotecall.model.FinishedDetail; +import com.dsms.common.remotecall.model.RemoteRequest; +import com.dsms.common.remotecall.model.RemoteResponse; +import com.dsms.common.remotecall.service.IRemoteCall; +import com.dsms.dfsbroker.node.model.remote.ResponseMon; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpMethod; +import org.springframework.security.core.AuthenticationException; +import org.springframework.stereotype.Component; +import org.springframework.util.ObjectUtils; + +import java.util.*; +import java.util.concurrent.TimeUnit; + + +@Component +@Slf4j +public class CommonApi { + @Autowired + private IRemoteCall remoteCall; + + public T remoteCallRequest(RemoteRequest remoteRequest, int maxRetries, Class type) throws Throwable { + remoteRequest.setUrlPrefix("request"); + remoteRequest.setHttpMethod(HttpMethod.POST); + RemoteResponse remoteResponse = remoteCall(remoteRequest, maxRetries, RemoteResponse.class); + remoteRequest.setUrlPrefix("request" + "/" + remoteResponse.getId()); + remoteRequest.setHttpMethod(HttpMethod.GET); + RemoteResponse response = remoteCall(remoteRequest, maxRetries, RemoteResponse.class); + List finished = response.getFinished(); + return JSON.parseObject(finished.get(0).getOutb(), type); + } + + public T remoteCall(RemoteRequest remoteRequest, Integer retryTime, Class type) throws Throwable { + + for (int retry = 1; retry <= retryTime; retry++) { + RemoteResponse remoteResponse = remoteCall.callRestfulApi(remoteRequest); + T result = JSON.parseObject(remoteResponse.getBody(), type); + if (!ObjectUtils.isEmpty(result)) { + return result; + } + TimeUnit.SECONDS.sleep(1); + } + return null; + } + +} diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/api/NodeApi.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/api/NodeApi.java index b674f3cf..a3fbedc6 100644 --- a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/api/NodeApi.java +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/api/NodeApi.java @@ -16,5 +16,58 @@ package com.dsms.dfsbroker.node.api; +import com.dsms.common.remotecall.model.RemoteRequest; +import com.dsms.common.remotecall.service.IRemoteCall; +import com.dsms.dfsbroker.common.CommandDirector; +import com.dsms.dfsbroker.common.api.CommonApi; +import com.dsms.dfsbroker.node.model.remote.OrchDeviceLsResult; +import com.dsms.dfsbroker.node.model.remote.OsdDfResult; +import com.dsms.dfsbroker.node.model.remote.ResponseMon; +import com.dsms.dfsbroker.node.request.MonRequest; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.util.ObjectUtils; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +@Component +@Slf4j public class NodeApi { + + public static final int MAX_RETRIES = 3; + + @Autowired + private IRemoteCall remoteCall; + + @Autowired + private CommonApi commonApi; + + /** + * 获取集群节点列表 + * + * @return 节点列表 + */ + public List getNodeList(RemoteRequest remoteRequest) throws Throwable { + CommandDirector.constructMonRequest(remoteRequest); + ResponseMon[] responseMon = commonApi.remoteCall(remoteRequest, MAX_RETRIES, ResponseMon[].class); + return Arrays.stream(responseMon).collect(Collectors.toList()); + } + + public OrchDeviceLsResult getOrchDeviceLs(RemoteRequest remoteRequest, String hostname) throws Throwable { + CommandDirector.constructOrchDeviceLsRequest(remoteRequest, hostname); + OrchDeviceLsResult[] orchDeviceLsResults = commonApi.remoteCallRequest(remoteRequest, MAX_RETRIES, OrchDeviceLsResult[].class); + if (ObjectUtils.isEmpty(orchDeviceLsResults)) { + return null; + } + return orchDeviceLsResults[0]; + } + + public OsdDfResult getOsdDf(RemoteRequest remoteRequest) throws Throwable { + CommandDirector.constructOsdDfRequest(remoteRequest); + return commonApi.remoteCallRequest(remoteRequest, MAX_RETRIES, OsdDfResult.class); + } + } diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/Device.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/Device.java index b8cf8ae9..8ffa75cc 100644 --- a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/Device.java +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/Device.java @@ -16,18 +16,21 @@ package com.dsms.dfsbroker.node.model; +import com.dsms.common.constant.DeviceStatusEnum; +import com.dsms.dfsbroker.node.model.remote.*; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + @Data @ApiModel(value = "磁盘对象", description = "节点上磁盘") -public class Device { +public class Device implements Serializable { private static final long serialVersionUID = 1L; - @ApiModelProperty("磁盘id") - private String deviceId; - @ApiModelProperty("磁盘uuid") private String deviceUuid; @@ -37,6 +40,9 @@ public class Device { @ApiModelProperty("磁盘pg数量") private Integer devicePgs; + @ApiModelProperty("磁盘类型") + private String deviceType; + @ApiModelProperty("磁盘用量") private String deviceUsedSize; @@ -49,4 +55,45 @@ public class Device { @ApiModelProperty("osdId") private Integer osdId; + @ApiModelProperty("osdStatus") + private String osdStatus; + + + public static List osdDfResultParseDevice(OsdDfResult osdDfResult) { + List devices = new ArrayList<>(); + + List responseNodes = osdDfResult.getNodes(); + for (ResponseNode responseNode : responseNodes) { + Device deviceTmp = new Device(); + deviceTmp.setOsdId(responseNode.getId()); + deviceTmp.setDeviceUsedSize(responseNode.getKdUsed().toString()); + deviceTmp.setDevicePgs(responseNode.getPgs()); + deviceTmp.setOsdStatus(responseNode.getStatus()); + devices.add(deviceTmp); + } + + return devices; + } + + public static List orchDeviceLsResultParseDevice(OrchDeviceLsResult orchDeviceLsResult) { + List devices = new ArrayList<>(); + + List responseDevices = orchDeviceLsResult.getDevices(); + for (ResponseDevice responseDevice : responseDevices) { + Device deviceTmp = new Device(); + deviceTmp.setDeviceUuid(responseDevice.getDeviceId()); + deviceTmp.setDevicePath(responseDevice.getPath()); + deviceTmp.setDeviceType(responseDevice.getHumanReadableType()); + deviceTmp.setDeviceTotalSize(responseDevice.getSysApi().getHumanReadableSize()); + deviceTmp.setDeviceStatus(responseDevice.isAvailable() ? DeviceStatusEnum.AVAILABLE.getStatus() : DeviceStatusEnum.NOT_AVAILABLE.getStatus()); + List lvs = responseDevice.getLvs(); + for (Lvs lv : lvs) { + deviceTmp.setOsdId(Integer.valueOf(lv.getOsdId())); + } + devices.add(deviceTmp); + } + + return devices; + } + } diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/Node.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/Node.java index d07a928f..08a9ddad 100644 --- a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/Node.java +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/Node.java @@ -17,11 +17,15 @@ package com.dsms.dfsbroker.node.model; +import com.alibaba.fastjson2.JSONObject; +import com.dsms.dfsbroker.node.model.remote.ResponseMon; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; @Data @ApiModel(value = "Node对象", description = "集群节点") @@ -47,5 +51,18 @@ public class Node implements Serializable { private Integer nodeStatus; @ApiModelProperty("节点磁盘") - private Device[] devices; + private List devices; + + public static List monParseNode(List responseMons) { + List nodes = new ArrayList<>(); + + for (ResponseMon responseMon : responseMons) { + Node nodeTmp = new Node(); + nodeTmp.setNodeName(responseMon.getName()); + nodeTmp.setNodeIp(responseMon.getAddr()); + nodes.add(nodeTmp); + } + + return nodes; + } } diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/Labels.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/Labels.java new file mode 100644 index 00000000..03e247ca --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/Labels.java @@ -0,0 +1,20 @@ +/* + * Copyright 2022 The DSMS Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dsms.dfsbroker.node.model.remote; + +public class Labels { +} diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/Lvs.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/Lvs.java new file mode 100644 index 00000000..322ed278 --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/Lvs.java @@ -0,0 +1,28 @@ +/* + * Copyright 2022 The DSMS Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dsms.dfsbroker.node.model.remote; + + +import com.alibaba.fastjson2.annotation.JSONField; +import lombok.Data; + +@Data +public class Lvs { + + @JSONField(name = "osd_id") + private String osdId; +} diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/OrchDeviceLsResult.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/OrchDeviceLsResult.java new file mode 100644 index 00000000..40941bb8 --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/OrchDeviceLsResult.java @@ -0,0 +1,47 @@ +/* + * Copyright 2022 The DSMS Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dsms.dfsbroker.node.model.remote; + + +import lombok.Data; + +import java.util.List; + +/** + * orch device ls 执行结果 + */ +@Data +public class OrchDeviceLsResult { + + /** + * ceph 响应 addr 字段 + */ + private String addr; + /** + * ceph 响应 devices 字段 + */ + private List devices; + /** + * ceph 响应 labels 字段 + */ + private List labels; + + /** + * ceph 响应 name 字段 + */ + private String name; +} diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/OsdDfResult.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/OsdDfResult.java new file mode 100644 index 00000000..928e6efe --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/OsdDfResult.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 The DSMS Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dsms.dfsbroker.node.model.remote; + + +import lombok.Data; + +import java.util.List; + +/** + * osd df 执行结果 + */ +@Data +public class OsdDfResult { + + /** + * ceph 响应 nodes 字段 + */ + private List nodes; + /** + * ceph 响应 Stray 字段 + */ + private List stray; + /** + * ceph 响应 summary 字段 + */ + private Summary summary; +} diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/ResponseDevice.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/ResponseDevice.java new file mode 100644 index 00000000..8a3a139c --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/ResponseDevice.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 The DSMS Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dsms.dfsbroker.node.model.remote; + +import com.alibaba.fastjson2.annotation.JSONField; +import lombok.Data; + +import java.util.List; + + +@Data +public class ResponseDevice { + private boolean available; + @JSONField(name = "device_id") + private String deviceId; + + @JSONField(name = "human_readable_type") + private String humanReadableType; + + @JSONField(name = "path") + private String path; + + @JSONField(name = "sys_api") + private SysApi sysApi; + + private List lvs; + +} diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/ResponseMon.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/ResponseMon.java new file mode 100644 index 00000000..87b47956 --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/ResponseMon.java @@ -0,0 +1,25 @@ +/* + * Copyright 2022 The DSMS Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dsms.dfsbroker.node.model.remote; + +import lombok.Data; + +@Data +public class ResponseMon { + private String name; + private String addr; +} diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/ResponseNode.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/ResponseNode.java new file mode 100644 index 00000000..2987f6f6 --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/ResponseNode.java @@ -0,0 +1,32 @@ +/* + * Copyright 2022 The DSMS Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dsms.dfsbroker.node.model.remote; + +import com.alibaba.fastjson2.annotation.JSONField; +import lombok.Data; + +@Data +public class ResponseNode { + + + private Integer id; + private Integer pgs; + @JSONField(name = "kb_used") + private Long kdUsed; + private String status; + +} diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/Stray.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/Stray.java new file mode 100644 index 00000000..f0df3266 --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/Stray.java @@ -0,0 +1,20 @@ +/* + * Copyright 2022 The DSMS Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dsms.dfsbroker.node.model.remote; + +public class Stray { +} diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/Summary.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/Summary.java new file mode 100644 index 00000000..ffbcaa52 --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/Summary.java @@ -0,0 +1,20 @@ +/* + * Copyright 2022 The DSMS Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dsms.dfsbroker.node.model.remote; + +public class Summary { +} diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/SysApi.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/SysApi.java new file mode 100644 index 00000000..5bc6ef73 --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/SysApi.java @@ -0,0 +1,26 @@ +/* + * Copyright 2022 The DSMS Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dsms.dfsbroker.node.model.remote; + +import com.alibaba.fastjson2.annotation.JSONField; +import lombok.Data; + +@Data +public class SysApi { + @JSONField(name = "human_readable_size") + private String humanReadableSize; +} diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/request/MonRequest.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/request/MonRequest.java new file mode 100644 index 00000000..57f351e1 --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/request/MonRequest.java @@ -0,0 +1,29 @@ +/* + * Copyright 2022 The DSMS Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dsms.dfsbroker.node.request; + +import com.dsms.common.remotecall.model.RemoteRequest; +import com.dsms.dfsbroker.common.RequestUrlEnum; +import org.springframework.http.HttpMethod; + +public class MonRequest extends RemoteRequest { + + public MonRequest() { + this.setUrlPrefix(RequestUrlEnum.MON_URL.getUrlPrefix()); + this.setHttpMethod(HttpMethod.GET); + } +} diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/request/OrchDeviceLsRequest.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/request/OrchDeviceLsRequest.java new file mode 100644 index 00000000..5ec58cc8 --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/request/OrchDeviceLsRequest.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 The DSMS Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dsms.dfsbroker.node.request; + +import com.alibaba.fastjson2.JSON; +import com.dsms.common.remotecall.model.RemoteRequest; +import com.dsms.dfsbroker.common.RequestUrlEnum; +import org.springframework.http.HttpMethod; + +import java.util.HashMap; +import java.util.Map; + +public class OrchDeviceLsRequest extends RemoteRequest { + + public OrchDeviceLsRequest(String hostname) { + Map requestParam = new HashMap<>(8); + requestParam.put("prefix", "orch device ls"); + requestParam.put("refresh", true); + requestParam.put("format", "json"); + requestParam.put("wide", true); + requestParam.put("hostname", hostname); + this.setUrlPrefix(RequestUrlEnum.REQUEST_URL.getUrlPrefix()); + this.setHttpMethod(HttpMethod.POST); + this.setRequestBody(JSON.toJSONString(requestParam)); + } +} diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/request/OsdDfRequest.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/request/OsdDfRequest.java new file mode 100644 index 00000000..fe9e07c8 --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/request/OsdDfRequest.java @@ -0,0 +1,37 @@ +/* + * Copyright 2022 The DSMS Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.dsms.dfsbroker.node.request; + +import com.alibaba.fastjson2.JSON; +import com.dsms.common.remotecall.model.RemoteRequest; +import com.dsms.dfsbroker.common.RequestUrlEnum; +import org.springframework.http.HttpMethod; + +import java.util.HashMap; +import java.util.Map; + +public class OsdDfRequest extends RemoteRequest { + + public OsdDfRequest() { + Map requestParam = new HashMap<>(4); + requestParam.put("prefix", "osd df"); + requestParam.put("format", "json"); + this.setUrlPrefix(RequestUrlEnum.REQUEST_URL.getUrlPrefix()); + this.setHttpMethod(HttpMethod.POST); + this.setRequestBody(JSON.toJSONString(requestParam)); + } +} diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/service/INodeService.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/service/INodeService.java index 7717f773..cd45251c 100644 --- a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/service/INodeService.java +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/service/INodeService.java @@ -16,5 +16,23 @@ package com.dsms.dfsbroker.node.service; +import com.dsms.dfsbroker.node.model.Node; + +import java.util.List; + public interface INodeService { + + /** + * 节点池列表 + * @return 当前绑定集群的全部节点信息 + */ + List list(); + + /** + * 单个节点信息 + * @param nodeIp 节点ip + * @param nodeName 节点名称 + * @return 包含磁盘信息的node对象 + */ + Node getNodeInfo(String nodeIp, String nodeName); } -- Gitee