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 3fb0a50794e822414fe5309c162277d40104003a..fc16af3b51664c7db8fe788a32f2061e69236d7e 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 @@ -20,14 +20,21 @@ package com.dsms.dfsbroker.cluster.api; import com.dsms.ClusterProperties; import com.dsms.common.remotecall.model.RemoteRequest; import com.dsms.dfsbroker.cluster.model.Cluster; +import com.dsms.dfsbroker.cluster.model.remote.ServerResult; import com.dsms.modules.util.RemoteCallUtil; import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit.jupiter.EnabledIf; +import java.util.List; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; + @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @Slf4j @EnabledIf(expression = "${dsms.storage.enable}", loadContext = true) @@ -47,7 +54,14 @@ class ClusterApiTest { } @Test void getClusterVersion() { - log.info(clusterApi.getClusterVersion(request).toString()); + Cluster clusterVersion = clusterApi.getClusterVersion(request); + Assertions.assertNotNull(clusterVersion.getNodes()); + } + + @Test + void getServer() throws Throwable { + List server = clusterApi.getServer(request); + assertThat(server, hasItems(hasProperty("hostname", is(request.getRemoteFixedParam().getHost())))); } 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 3f3461e84cd5649a625576b4be0e0b8dc417723d..c3f268de4c0e49a7f6939a8874c87280eb04d5b5 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 @@ -16,8 +16,6 @@ package com.dsms.common.remotecall.model; -import cn.hutool.core.net.url.UrlPath; -import lombok.Builder; import lombok.Data; import org.springframework.http.HttpMethod; 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 3e5b0fe43834ab1395b58bcac0052a9001649af1..5b58c7d16e51875b85c764872095e8b525ec0f58 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 @@ -25,21 +25,32 @@ 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.cluster.model.Cluster; +import com.dsms.dfsbroker.cluster.model.remote.ServerResult; +import com.dsms.dfsbroker.common.CommandDirector; +import com.dsms.dfsbroker.common.api.CommonApi; 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.Arrays; import java.util.List; +import java.util.stream.Collectors; @Component public class ClusterApi { @Autowired private IRemoteCall remoteCall; + public static final int MAX_RETRIES = 3; + + @Autowired + private CommonApi commonApi; + /** - * @return + * get dsms-storage nodes info + * @return node info list */ public Cluster getClusterVersion(RemoteRequest remoteRequest) { Cluster cluster = new Cluster(); @@ -70,4 +81,11 @@ public class ClusterApi { return cluster; } + + public List getServer(RemoteRequest remoteRequest) throws Throwable { + CommandDirector.constructServerRequest(remoteRequest); + ServerResult[] responseMon = commonApi.remoteCall(remoteRequest, MAX_RETRIES, ServerResult[].class); + return Arrays.stream(responseMon).collect(Collectors.toList()); + + } } diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/cluster/model/remote/ServerResult.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/cluster/model/remote/ServerResult.java new file mode 100644 index 0000000000000000000000000000000000000000..fd39f715de55ed65cf92b2bbf74c1004749e11d3 --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/cluster/model/remote/ServerResult.java @@ -0,0 +1,49 @@ +/* + * 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.cluster.model.remote; + +import com.alibaba.fastjson2.annotation.JSONField; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * dsms-storage + * /server api result + */ +@NoArgsConstructor +@Data +public class ServerResult { + + @JSONField(name = "ceph_version") + private String cephVersion; + @JSONField(name = "hostname") + private String hostname; + @JSONField(name = "services") + private List services; + + @NoArgsConstructor + @Data + public static class ServicesDTO { + @JSONField(name = "id") + private String id; + @JSONField(name = "type") + private String type; + } +} + diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/cluster/request/ServerRequest.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/cluster/request/ServerRequest.java new file mode 100644 index 0000000000000000000000000000000000000000..8e431814869063becf8c21b4cbe4e6cec512c13e --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/cluster/request/ServerRequest.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.cluster.request; + +import com.dsms.common.remotecall.model.RemoteRequest; +import com.dsms.dfsbroker.common.RequestUrlEnum; +import org.springframework.http.HttpMethod; + +public class ServerRequest extends RemoteRequest { + + public ServerRequest() { + this.setUrlPrefix(RequestUrlEnum.SERVER_URL.getUrlPrefix()); + this.setHttpMethod(HttpMethod.GET); + } +} 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 index f88368455fad23d51955363391dd5c33592d503b..54b04059a993ca8be6f02d3f3095bad685191583 100644 --- 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 @@ -17,10 +17,15 @@ package com.dsms.dfsbroker.common; import com.dsms.common.remotecall.model.RemoteRequest; +import com.dsms.dfsbroker.cluster.request.ServerRequest; import com.dsms.dfsbroker.common.request.GetResultRequest; import com.dsms.dfsbroker.node.request.*; public class CommandDirector { + + public static void constructServerRequest(RemoteRequest request) { + request.buildRequestParam(new ServerRequest()); + } public static void constructMonRequest(RemoteRequest request) { request.buildRequestParam(new MonRequest()); } 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 index a3565841f4c0f70a519da26411122ef026353d43..6838231b01c3567bdf3bb0e9976992b952ce203f 100644 --- 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 @@ -28,6 +28,7 @@ import lombok.Getter; public enum RequestUrlEnum { MON_URL("mon"), + SERVER_URL("server"), REQUEST_URL("request"); private final String urlPrefix;