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 e022c00c4fbbdb9d59acceea59f729213f0bfebe..d38f3dcab7e7ba5ecc662a10c63546e93029d896 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 2a84e53183d314598e1dc38d98fa8cf6036f9fc5..c07945089e4c8144a7cdcd4b31dc4a51b8492236 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 664f3d5c54b00e2a9c0d4673c058c0f0e13413a3..672ff2143447acaa1cb4e96765c953c011693ab7 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 4321d4a3a8b9dd7de496a48647b3774d034dae76..1118d27a9e14d7c004470dc33e716d2ede9f5805 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 0000000000000000000000000000000000000000..899f61f9105967198e05fe8330dce94ba64506d3 --- /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 0000000000000000000000000000000000000000..2fab375f71bbb602debe94a152b4d4cc09d48ad6 --- /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 207abc7f703a98586695a7b644dd33d6b9188d37..08a27f1b761534ae5580945e78e7bb43e5959f43 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 0000000000000000000000000000000000000000..f2f01713075ee8504135c590a728ca7594a8d074 --- /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 0000000000000000000000000000000000000000..cf5df2a02af94b978902e77abb0574d11b02900f --- /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 88e34dc09e6112e56cf6a63b7e41de971dede527..3f3461e84cd5649a625576b4be0e0b8dc417723d 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 f55ef5c498a385a1ff59aaac40b850c618aad197..d6278e0fe601a0337239ffb090315c32f3560b0a 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 6a1751c78b4e0af3655014039827d9e8be4c573a..8125aaba5d4498499d1dc4ce2afe2fee457741ae 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 5cafa8806bdda4bc9f89c4b1f9a2533a331645f6..d75764f2cdeed2476e84f8b1c77306caeb920041 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 c024d4059c5ea70c284c29e6f4d4c18de2410a78..3e5b0fe43834ab1395b58bcac0052a9001649af1 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 0000000000000000000000000000000000000000..2f3f9ee2ad4371932d7684eea21a508a31a7dfb9 --- /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 0000000000000000000000000000000000000000..a3565841f4c0f70a519da26411122ef026353d43 --- /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 0000000000000000000000000000000000000000..41daf22cf91d5a119384fbfa5695232b161f1786 --- /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 b674f3cfc63c788969ead30d37e94ff529c5a721..a3fbedc67eda94657001e6dc0c196532d7dc32a5 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 b8cf8ae90ec81330cf038b0cb53102753cf00e7e..8ffa75cc5e017b17bfe3f5c95fd50a66434890f6 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 d07a928f75cb2c6804fc29091973ab716f11996b..08a9ddadefc31c1874a7ea28d2c9bf94e809ee4a 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 0000000000000000000000000000000000000000..03e247ca9551fd96d99dd383bab3225e3ede7829 --- /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 0000000000000000000000000000000000000000..322ed278be07e0b61cff496389aa43d712a0b045 --- /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 0000000000000000000000000000000000000000..40941bb84b2f51d5940b7970dee9e1e86ff2e961 --- /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 0000000000000000000000000000000000000000..928e6efe3758e23f5934c542de31a2a79b362a85 --- /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 0000000000000000000000000000000000000000..8a3a139ced11171a24e8c52d728259590fad6cfe --- /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 0000000000000000000000000000000000000000..87b47956b0656ba95592df4e3eecb1a0d2959740 --- /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 0000000000000000000000000000000000000000..2987f6f68429c739969fc3ca619d80e93839fc1b --- /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 0000000000000000000000000000000000000000..f0df3266b252ad2a7b5cb35ad55251e483b67b2f --- /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 0000000000000000000000000000000000000000..ffbcaa52eef4638232332df965c97142f5f1ed79 --- /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 0000000000000000000000000000000000000000..5bc6ef73d264a8aaa57513ef1131fe09a8d8f09b --- /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 0000000000000000000000000000000000000000..57f351e14ae24365a5fb22c73b0a403f8b9fcc7b --- /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 0000000000000000000000000000000000000000..5ec58cc87514315e7e3e69eeb18f5a609314019c --- /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 0000000000000000000000000000000000000000..fe9e07c802fc23aca332dc7862e7fee5a14c2754 --- /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 7717f7735bcc8e90c1d2062994a2aa7bc519d45a..cd45251ce8cb478160fa4f2782260053affb493d 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); }