From 37f830c972e7218b852abfa68baa612509911101 Mon Sep 17 00:00:00 2001 From: SaarHV Date: Mon, 16 Jan 2023 14:19:51 +0800 Subject: [PATCH] Update the interface of get a single node info,Add the info of osd occupied bu the storage pool --- .../node/service/impl/NodeServiceImpl.java | 25 +++++++++ .../dfsbroker/osd/osd/api/OsdApiTest.java | 54 +++++++++++++++++++ .../storagepool/api/StoragePoolApiTest.java | 7 ++- .../dfsbroker/common/CommandDirector.java | 10 ++++ .../dsms/dfsbroker/common/RequestUrlEnum.java | 3 +- .../com/dsms/dfsbroker/node/model/Device.java | 2 + .../com/dsms/dfsbroker/node/model/Node.java | 3 ++ .../dsms/dfsbroker/osd/osd/api/OsdApi.java | 41 ++++++++++++++ .../osd/osd/model/remote/OSDResult.java | 35 ++++++++++++ .../osd/osd/request/GetOsdByIdRequest.java | 29 ++++++++++ .../storagepool/api/StoragePoolApi.java | 10 ++++ .../GetStoragePoolByPoolIdRequest.java | 29 ++++++++++ 12 files changed, 246 insertions(+), 2 deletions(-) create mode 100644 dsms-engine-application/src/test/java/com/dsms/dfsbroker/osd/osd/api/OsdApiTest.java create mode 100644 dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/osd/osd/api/OsdApi.java create mode 100644 dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/osd/osd/model/remote/OSDResult.java create mode 100644 dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/osd/osd/request/GetOsdByIdRequest.java create mode 100644 dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/storagepool/request/GetStoragePoolByPoolIdRequest.java diff --git a/dsms-engine-application/src/main/java/com/dsms/modules/node/service/impl/NodeServiceImpl.java b/dsms-engine-application/src/main/java/com/dsms/modules/node/service/impl/NodeServiceImpl.java index e13dce5..018a95c 100644 --- a/dsms-engine-application/src/main/java/com/dsms/modules/node/service/impl/NodeServiceImpl.java +++ b/dsms-engine-application/src/main/java/com/dsms/modules/node/service/impl/NodeServiceImpl.java @@ -31,6 +31,10 @@ 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.service.INodeService; +import com.dsms.dfsbroker.osd.osd.api.OsdApi; +import com.dsms.dfsbroker.osd.osd.model.remote.OSDResult; +import com.dsms.dfsbroker.storagepool.api.StoragePoolApi; +import com.dsms.dfsbroker.storagepool.model.remote.ResponseStoragePool; import com.dsms.modules.util.RemoteCallUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -48,6 +52,12 @@ public class NodeServiceImpl implements INodeService { @Autowired private NodeApi nodeApi; + @Autowired + private OsdApi osdApi; + + @Autowired + private StoragePoolApi storagePoolApi; + @Autowired private ITaskService taskService; @@ -132,6 +142,21 @@ public class NodeServiceImpl implements INodeService { } catch (Throwable e) { log.warn("get osd info from dsms-storage fail", e); } + + //obtain the info of osd occupied by the storage pool + for (Device device : devices) { + try { + OSDResult osd = osdApi.getOsdById(RemoteCallUtil.generateRemoteRequest(), device.getOsdId()); + if (osd.getPools().size() != 0) { + ResponseStoragePool storagePoolByPoolId = storagePoolApi.getStoragePoolByPoolId(RemoteCallUtil.generateRemoteRequest(), osd.getPools().get(0)); + device.setUsedPool(storagePoolByPoolId.getPoolName()); + } + } catch (Throwable e) { + log.warn("get osd's pool info from dsms-storage fail", e); + } + } + long poolUsedDevice = devices.stream().filter(device -> device.getUsedPool() != null).count(); + node.setPoolUsedDevice((int) poolUsedDevice); node.setDevices(devices); return node; diff --git a/dsms-engine-application/src/test/java/com/dsms/dfsbroker/osd/osd/api/OsdApiTest.java b/dsms-engine-application/src/test/java/com/dsms/dfsbroker/osd/osd/api/OsdApiTest.java new file mode 100644 index 0000000..5cb95a0 --- /dev/null +++ b/dsms-engine-application/src/test/java/com/dsms/dfsbroker/osd/osd/api/OsdApiTest.java @@ -0,0 +1,54 @@ +/* + * 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.osd.osd.api; + + +import com.dsms.ClusterProperties; +import com.dsms.common.remotecall.model.RemoteRequest; +import com.dsms.dfsbroker.cluster.model.Cluster; +import com.dsms.modules.util.RemoteCallUtil; +import lombok.extern.slf4j.Slf4j; +import org.assertj.core.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; + + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@Slf4j +@EnabledIf(expression = "${dsms.storage.enable}", loadContext = true) +class OsdApiTest { + private static RemoteRequest request; + @Autowired + private OsdApi osdApi; + @Autowired + private ClusterProperties properties; + + @BeforeEach + public void setUp() { + Cluster cluster = properties.getTestCluster(); + RemoteCallUtil.updateRemoteFixedParam(cluster); + request = RemoteCallUtil.generateRemoteRequest(); + } + + @Test + void getOsdById() { + Assertions.assertThatCode(() -> osdApi.getOsdById(request, 0)).doesNotThrowAnyException(); + } +} \ No newline at end of file diff --git a/dsms-engine-application/src/test/java/com/dsms/dfsbroker/storagepool/api/StoragePoolApiTest.java b/dsms-engine-application/src/test/java/com/dsms/dfsbroker/storagepool/api/StoragePoolApiTest.java index cc8b885..b22563d 100644 --- a/dsms-engine-application/src/test/java/com/dsms/dfsbroker/storagepool/api/StoragePoolApiTest.java +++ b/dsms-engine-application/src/test/java/com/dsms/dfsbroker/storagepool/api/StoragePoolApiTest.java @@ -57,6 +57,11 @@ public class StoragePoolApiTest { request = RemoteCallUtil.generateRemoteRequest(); } + @Test + void getPoolByPooId() { + Assertions.assertThatCode(() -> storagePoolApi.getStoragePoolByPoolId(request, 2)).doesNotThrowAnyException(); + } + @Test void getPoolList() throws Throwable { Assertions.assertThatCode(() -> storagePoolApi.getStoragePoolList(request)).doesNotThrowAnyException(); @@ -69,7 +74,7 @@ public class StoragePoolApiTest { @Test void createPoolNormal() throws Throwable { - ErasureCreateDTO erasureCreateDTO = new ErasureCreateDTO("apiTest_root", 3, 32, 32, "apiTest_root"); + ErasureCreateDTO erasureCreateDTO = new ErasureCreateDTO("apiTest_root", 3, 32, 32, null); RemoteResponse response = storagePoolApi.createPool(request, erasureCreateDTO); sleep(Duration.ofMillis(500)); RemoteResponse createPoolResult = storagePoolApi.getCreatePoolResult(request, response.getId()); 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 e30e134..5be224d 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 @@ -25,9 +25,11 @@ import com.dsms.dfsbroker.osd.crushmap.request.CreateBucketRequest; import com.dsms.dfsbroker.osd.crushmap.request.CreateRuleRequest; import com.dsms.dfsbroker.osd.ecprofile.model.dto.EcProfileDto; import com.dsms.dfsbroker.osd.ecprofile.request.CreateEcProfileRequest; +import com.dsms.dfsbroker.osd.osd.request.GetOsdByIdRequest; import com.dsms.dfsbroker.storagepool.model.dto.StoragePoolCreateDTO; import com.dsms.dfsbroker.storagepool.request.CreateStoragePoolRequest; import com.dsms.dfsbroker.storagepool.request.DfRequest; +import com.dsms.dfsbroker.storagepool.request.GetStoragePoolByPoolIdRequest; import com.dsms.dfsbroker.storagepool.request.StoragePoolLsRequest; public class CommandDirector { @@ -64,6 +66,10 @@ public class CommandDirector { request.buildRequestParam(new RmOsdStatusRequest()); } + public static void constructGetStoragePoolByPoolIdRequest(RemoteRequest request, int id) { + request.buildRequestParam(new GetStoragePoolByPoolIdRequest(id)); + } + public static void constructStoragePoolLsRequest(RemoteRequest request) { request.buildRequestParam(new StoragePoolLsRequest()); } @@ -91,4 +97,8 @@ public class CommandDirector { public static void constructCreatePoolRequest(RemoteRequest request, StoragePoolCreateDTO pool) { request.buildRequestParam(new CreateStoragePoolRequest(pool)); } + + public static void constructGetOSDById(RemoteRequest request, int id) { + request.buildRequestParam(new GetOsdByIdRequest(id)); + } } 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 8afec5e..e782603 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 @@ -30,7 +30,8 @@ public enum RequestUrlEnum { MON_URL("mon"), SERVER_URL("server"), REQUEST_URL("request"), - POOL_URL("pool"); + POOL_URL("pool"), + OSD_URL("osd"); private final String urlPrefix; 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 8ffa75c..7f19b28 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 @@ -58,6 +58,8 @@ public class Device implements Serializable { @ApiModelProperty("osdStatus") private String osdStatus; + @ApiModelProperty("占用此磁盘的存储池名称") + private String usedPool; public static List osdDfResultParseDevice(OsdDfResult osdDfResult) { List devices = new ArrayList<>(); 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 7b0c8c7..28f8b8a 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 @@ -56,6 +56,9 @@ public class Node implements Serializable { @ApiModelProperty("节点总磁盘数") private Integer nodeAllDevice; + @ApiModelProperty("节点已被存储池使用磁盘数") + private Integer poolUsedDevice; + public static List monParseNode(List responseMons) { List nodes = new ArrayList<>(); diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/osd/osd/api/OsdApi.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/osd/osd/api/OsdApi.java new file mode 100644 index 0000000..232c191 --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/osd/osd/api/OsdApi.java @@ -0,0 +1,41 @@ +/* + * 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.osd.osd.api; + +import com.dsms.common.remotecall.model.RemoteRequest; +import com.dsms.common.remotecall.model.RemoteResponse; +import com.dsms.dfsbroker.common.CommandDirector; +import com.dsms.dfsbroker.common.api.CommonApi; +import com.dsms.dfsbroker.osd.ecprofile.model.dto.EcProfileDto; +import com.dsms.dfsbroker.osd.osd.model.remote.OSDResult; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class OsdApi { + public static final int MAX_RETRIES = 3; + + @Autowired + private CommonApi commonApi; + + public OSDResult getOsdById(RemoteRequest remoteRequest, int osdId) throws Throwable { + CommandDirector.constructGetOSDById(remoteRequest, osdId); + OSDResult osdResult = commonApi.remoteCall(remoteRequest, MAX_RETRIES, OSDResult.class); + return osdResult; + + } +} diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/osd/osd/model/remote/OSDResult.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/osd/osd/model/remote/OSDResult.java new file mode 100644 index 0000000..c53ba2b --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/osd/osd/model/remote/OSDResult.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.osd.osd.model.remote; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@NoArgsConstructor +@Data +public class OSDResult { + @JsonProperty("osd") + private Integer osd; + @JsonProperty("pools") + private List pools; + @JsonProperty("server") + private String server; + +} diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/osd/osd/request/GetOsdByIdRequest.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/osd/osd/request/GetOsdByIdRequest.java new file mode 100644 index 0000000..7e75779 --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/osd/osd/request/GetOsdByIdRequest.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.osd.osd.request; + +import com.dsms.common.remotecall.model.RemoteRequest; +import com.dsms.dfsbroker.common.RequestUrlEnum; +import org.springframework.http.HttpMethod; + +public class GetOsdByIdRequest extends RemoteRequest { + + public GetOsdByIdRequest(int osdId) { + this.setUrlPrefix(RequestUrlEnum.OSD_URL.getUrlPrefix() + "/" + osdId); + this.setHttpMethod(HttpMethod.GET); + } +} diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/storagepool/api/StoragePoolApi.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/storagepool/api/StoragePoolApi.java index 331e4b0..3114c31 100644 --- a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/storagepool/api/StoragePoolApi.java +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/storagepool/api/StoragePoolApi.java @@ -39,6 +39,16 @@ public class StoragePoolApi { @Autowired private CommonApi commonApi; + /** + * obtain the basic information of storage pools by poolId + * + * @return ResponseStoragePool + */ + public ResponseStoragePool getStoragePoolByPoolId(RemoteRequest remoteRequest, int poolId) throws Throwable { + CommandDirector.constructGetStoragePoolByPoolIdRequest(remoteRequest, poolId); + return commonApi.remoteCall(remoteRequest, MAX_RETRIES, ResponseStoragePool.class); + } + /** * obtain the basic information list of storage pools * diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/storagepool/request/GetStoragePoolByPoolIdRequest.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/storagepool/request/GetStoragePoolByPoolIdRequest.java new file mode 100644 index 0000000..fa10026 --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/storagepool/request/GetStoragePoolByPoolIdRequest.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.storagepool.request; + +import com.dsms.common.remotecall.model.RemoteRequest; +import com.dsms.dfsbroker.common.RequestUrlEnum; +import org.springframework.http.HttpMethod; + +public class GetStoragePoolByPoolIdRequest extends RemoteRequest { + + public GetStoragePoolByPoolIdRequest(int id) { + this.setUrlPrefix(RequestUrlEnum.POOL_URL.getUrlPrefix() + "/" + id); + this.setHttpMethod(HttpMethod.GET); + } +} -- Gitee