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 5fed2a30154f42e538a304323b5e4744b1e5644d..5d2081f79f840823c8bb0a63f8d1b39dc8caebce 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 @@ -36,7 +36,7 @@ public class RemoteCallUtil { public static RemoteFixedParam remoteFixedParam = null; - @PostConstruct +// @PostConstruct public void init() { Cluster initCluster = iClusterService.getCurrentBindCluster(); updateRemoteFixedParam(initCluster); diff --git a/dsms-engine-application/src/main/resources/application.yml b/dsms-engine-application/src/main/resources/application.yml index 9e93fb7f591bc4ee2b110df3675865c844cfcb9e..ca48318549ce6c0d2a84cf83cec29987ea779d1f 100644 --- a/dsms-engine-application/src/main/resources/application.yml +++ b/dsms-engine-application/src/main/resources/application.yml @@ -29,6 +29,8 @@ spring: login-password: redis: host: 127.0.0.1 + arthas: + enabled: false #默认日志配置 logging: @@ -48,3 +50,5 @@ jwt: config: ttl: 30 key: ZHNtcy1lbmdpbmVqd3RrZXliYXNlNjQK + + diff --git a/dsms-engine-application/src/test/java/com/dsms/ClusterProperties.java b/dsms-engine-application/src/test/java/com/dsms/ClusterProperties.java new file mode 100644 index 0000000000000000000000000000000000000000..a9d443ddd21482bfa9b2c3781f55691134a80112 --- /dev/null +++ b/dsms-engine-application/src/test/java/com/dsms/ClusterProperties.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; + + +import com.dsms.dfsbroker.cluster.model.Cluster; +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + + +@Component +@ConfigurationProperties(prefix = "dsms.storage") +@Data +public class ClusterProperties { + private String clusterVip; + private Integer clusterPort; + private String authKey; + + public Cluster getTestCluster() { + Cluster cluster = new Cluster(); + cluster.setClusterVip(clusterVip); + cluster.setClusterPort(clusterPort); + cluster.setAuthKey(authKey); + return cluster; + } + +} 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 672ff2143447acaa1cb4e96765c953c011693ab7..79bda0f5fafd9d498f544118fac9a3e2818778ee 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,40 +16,40 @@ package com.dsms.common.remotecall.service.impl; -import com.dsms.common.constant.SystemConst; +import com.dsms.ClusterProperties; import com.dsms.common.remotecall.model.RemoteRequest; -import com.dsms.common.remotecall.model.RemoteResponse; +import com.dsms.dfsbroker.cluster.model.Cluster; import com.dsms.modules.util.RemoteCallUtil; import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.BeforeAll; +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.http.HttpMethod; -import org.springframework.test.context.ContextConfiguration; - -import java.util.HashMap; -import java.util.Map; +import org.springframework.test.context.junit.jupiter.EnabledIf; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@EnabledIf(expression = "${dsms.storage.enable}", loadContext = true) class RemoteCallImplTest { + + @Autowired + private ClusterProperties properties; @Autowired RemoteCallImpl remoteCall; 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"); + @BeforeEach + public void setUp() { + Cluster cluster = properties.getTestCluster(); + RemoteCallUtil.updateRemoteFixedParam(cluster); request = RemoteCallUtil.generateRemoteRequest(); } + @Test - void callRestfulApi() throws Throwable { + public void callRestfulApi() throws Throwable { request.setUrlPrefix("doc"); + request.setHttpMethod(HttpMethod.GET); 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 1118d27a9e14d7c004470dc33e716d2ede9f5805..3fb0a50794e822414fe5309c162277d40104003a 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,29 +17,32 @@ package com.dsms.dfsbroker.cluster.api; -import com.dsms.common.constant.SystemConst; +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.junit.jupiter.api.BeforeAll; +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 +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @Slf4j +@EnabledIf(expression = "${dsms.storage.enable}", loadContext = true) class ClusterApiTest { @Autowired private ClusterApi clusterApi; private static RemoteRequest request; + @Autowired + private ClusterProperties properties; + - @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"); + @BeforeEach + public void setUp() { + Cluster cluster = properties.getTestCluster(); + RemoteCallUtil.updateRemoteFixedParam(cluster); request = RemoteCallUtil.generateRemoteRequest(); } @Test 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 index 899f61f9105967198e05fe8330dce94ba64506d3..2e7db2cc5910f9a6626cc19ef7afb50f9dd96a39 100644 --- 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 @@ -17,41 +17,46 @@ package com.dsms.dfsbroker.node.api; -import com.dsms.common.constant.SystemConst; +import com.dsms.ClusterProperties; import com.dsms.common.remotecall.model.RemoteRequest; +import com.dsms.common.remotecall.model.RemoteResponse; +import com.dsms.dfsbroker.cluster.model.Cluster; 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.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.rmi.server.RemoteCall; import java.util.List; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @Slf4j +@EnabledIf(expression = "${dsms.storage.enable}", loadContext = true) 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"); + @Autowired + private ClusterProperties properties; + + @BeforeEach + public void setUp() { + Cluster cluster = properties.getTestCluster(); + RemoteCallUtil.updateRemoteFixedParam(cluster); request = RemoteCallUtil.generateRemoteRequest(); } @@ -63,7 +68,7 @@ class NodeApiTest { @Test void getNodeInfo() throws Throwable { - OrchDeviceLsResult orchDeviceLsResult = nodeApi.getOrchDeviceLs(request, "node1"); + OrchDeviceLsResult orchDeviceLsResult = nodeApi.getOrchDeviceLs(request, request.getRemoteFixedParam().getHost()); List devices = Device.orchDeviceLsResultParseDevice(orchDeviceLsResult); assertThat(devices, hasItems()); } @@ -73,5 +78,25 @@ class NodeApiTest { Assertions.assertThatCode(() -> nodeApi.getOsdDf(request)).doesNotThrowAnyException(); } + @Test + void addOsd() throws Throwable { + RemoteResponse addOsd = nodeApi.addOsd(request, request.getRemoteFixedParam().getHost(), "/dev/sdb"); + assertNotNull(addOsd.getId()); + boolean addResult = nodeApi.getAddOsdResult(request, addOsd.getId()); + assertFalse(addResult); + } + + + @Test + void rmOsd() throws Throwable { + assertFalse(nodeApi.rmOsdSchedule(request, new String[]{"100"})); + } + + + @Test + void getRmOsdStatus() { + Assertions.assertThatCode(() -> nodeApi.getRmOsdScheduleStatus(request)).doesNotThrowAnyException(); + } + } \ No newline at end of file diff --git a/dsms-engine-application/src/test/resources/application.yml b/dsms-engine-application/src/test/resources/application.yml index ba0c530cc2094e7a13143beaa842745c32a65b61..b6150c6793b1addf210a3bb834166c802175b53d 100644 --- a/dsms-engine-application/src/test/resources/application.yml +++ b/dsms-engine-application/src/test/resources/application.yml @@ -32,3 +32,10 @@ jwt: mybatis-plus: configuration: log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + +dsms: + storage: + enable: true + clusterVip: node1 + clusterPort: 8003 + authKey: fa51c04e-31c2-4e81-bf43-4af7f1cee390 diff --git a/dsms-engine-common/pom.xml b/dsms-engine-common/pom.xml index 6d8c206f740781e6eb77694d49b0f61eb872665f..6c059c61fc04de2b0048441cbe9d7e724019b8ff 100644 --- a/dsms-engine-common/pom.xml +++ b/dsms-engine-common/pom.xml @@ -117,6 +117,11 @@ spring-boot-starter-websocket + + com.taobao.arthas + arthas-spring-boot-starter + + \ No newline at end of file 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 2f3f9ee2ad4371932d7684eea21a508a31a7dfb9..f88368455fad23d51955363391dd5c33592d503b 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,9 +17,8 @@ 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; +import com.dsms.dfsbroker.common.request.GetResultRequest; +import com.dsms.dfsbroker.node.request.*; public class CommandDirector { public static void constructMonRequest(RemoteRequest request) { @@ -33,4 +32,20 @@ public class CommandDirector { public static void constructOsdDfRequest(RemoteRequest request) { request.buildRequestParam(new OsdDfRequest()); } + + public static void constructAddOsd(RemoteRequest request, String nodeName, String devicePath) { + request.buildRequestParam(new OsdAddRequest(nodeName, devicePath)); + } + + public static void constructGetRequest(RemoteRequest request, String requestId) { + request.buildRequestParam(new GetResultRequest(requestId)); + } + + public static void constructRmOsd(RemoteRequest request, String[] osdId) { + request.buildRequestParam(new RmOsdRequest(osdId)); + } + + public static void constructRmOsdStatus(RemoteRequest request) { + request.buildRequestParam(new RmOsdStatusRequest()); + } } diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/common/request/GetResultRequest.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/common/request/GetResultRequest.java new file mode 100644 index 0000000000000000000000000000000000000000..6b24c7098719f9f1c2311a39ce817fc974f67a20 --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/common/request/GetResultRequest.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.common.request; + +import com.dsms.common.remotecall.model.RemoteRequest; +import com.dsms.dfsbroker.common.RequestUrlEnum; +import org.springframework.http.HttpMethod; +import org.springframework.util.ObjectUtils; + +public class GetResultRequest extends RemoteRequest { + public GetResultRequest(String requestId) { + if (ObjectUtils.isEmpty(requestId)) { + throw new IllegalArgumentException("requestId must not be blank"); + } + this.setUrlPrefix(RequestUrlEnum.REQUEST_URL.getUrlPrefix() + "/" + requestId); + this.setHttpMethod(HttpMethod.GET); + } +} 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 a3fbedc67eda94657001e6dc0c196532d7dc32a5..306ac985f692ec6c6f4545d07d97bfe098b777b0 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,21 +16,30 @@ package com.dsms.dfsbroker.node.api; +import com.alibaba.fastjson2.JSON; +import com.dsms.common.constant.RemoteResponseStatusEnum; +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.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.OsdRmStatusResult; import com.dsms.dfsbroker.node.model.remote.ResponseMon; -import com.dsms.dfsbroker.node.request.MonRequest; +import com.dsms.dfsbroker.node.request.OsdAddRequest; +import com.dsms.dfsbroker.node.request.RmOsdRequest; +import com.dsms.dfsbroker.node.request.RmOsdStatusRequest; 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.Collections; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; @Component @@ -70,4 +79,54 @@ public class NodeApi { return commonApi.remoteCallRequest(remoteRequest, MAX_RETRIES, OsdDfResult.class); } + public RemoteResponse addOsd(RemoteRequest remoteRequest, String nodeName, String devicePath) throws Throwable { + CommandDirector.constructAddOsd(remoteRequest, nodeName, devicePath); + RemoteResponse remoteResponse = commonApi.remoteCall(remoteRequest, MAX_RETRIES, RemoteResponse.class); + return remoteResponse; + } + + public boolean getAddOsdResult(RemoteRequest remoteRequest, String requestId) throws Throwable { + CommandDirector.constructGetRequest(remoteRequest, requestId); + RemoteResponse remoteResponse = commonApi.remoteCall(remoteRequest, MAX_RETRIES, RemoteResponse.class); + if (Objects.equals(remoteResponse.getState(), RemoteResponseStatusEnum.SUCCESS.getMessage())) { + List finished = remoteResponse.getFinished(); + String outb = finished.get(0).getOutb(); + return outb.startsWith(OsdAddRequest.ADD_OSD_SUCCESS); + } + + return false; + } + + public boolean rmOsdSchedule(RemoteRequest remoteRequest, String[] osdId) throws Throwable { + CommandDirector.constructRmOsd(remoteRequest, osdId); + RemoteResponse remoteResponse = commonApi.remoteCall(remoteRequest, MAX_RETRIES, RemoteResponse.class); + CommandDirector.constructGetRequest(remoteRequest, remoteResponse.getId()); + RemoteResponse resultResponse = commonApi.remoteCall(remoteRequest, MAX_RETRIES, RemoteResponse.class); + List finished = resultResponse.getFinished(); + if (!ObjectUtils.isEmpty(finished)) { + String outb = finished.get(0).getOutb(); + return Objects.equals(outb, RmOsdRequest.RMOSD_STATUS); + } + return false; + } + + + public List getRmOsdScheduleStatus(RemoteRequest remoteRequest) throws Throwable { + CommandDirector.constructRmOsdStatus(remoteRequest); + RemoteResponse remoteResponse = commonApi.remoteCall(remoteRequest, MAX_RETRIES, RemoteResponse.class); + CommandDirector.constructGetRequest(remoteRequest, remoteResponse.getId()); + RemoteResponse resultResponse = commonApi.remoteCall(remoteRequest, MAX_RETRIES, RemoteResponse.class); + List finished = resultResponse.getFinished(); + if (!ObjectUtils.isEmpty(finished)) { + String outb = finished.get(0).getOutb(); + if (Objects.equals(outb, RmOsdStatusRequest.EMPTY_RESULT)) { + return Collections.emptyList(); + } + OsdRmStatusResult[] osdRmStatusResults = JSON.parseObject(finished.get(0).getOutb(), OsdRmStatusResult[].class); + return Arrays.asList(osdRmStatusResults); + } + return Collections.emptyList(); + + } + } diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/OsdRmStatusResult.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/OsdRmStatusResult.java new file mode 100644 index 0000000000000000000000000000000000000000..a3b114e4978ebc1197b0a33317138a3d6ca0b174 --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/model/remote/OsdRmStatusResult.java @@ -0,0 +1,43 @@ +/* + * 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.time.LocalDateTime; + +@Data +public class OsdRmStatusResult { + + @JSONField(name = "drain_done_at") + private String drainDoneAt; + @JSONField(name = "drain_started_at") + private String drainStartedAt; + @JSONField(name = "drain_stopped_at") + private String drainStoppedAt; + private boolean draining; + private boolean force; + private String hostname; + @JSONField(name = "osd_id") + private Integer osdId; + @JSONField(name = "process_started_at") + private LocalDateTime processStartedAt; + private boolean replace; + private boolean started; + private boolean stopped; +} 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 index 5ec58cc87514315e7e3e69eeb18f5a609314019c..8c1d1a7d9f3c5a152c978d4ba338c3cd1413f6a9 100644 --- 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 @@ -20,6 +20,7 @@ import com.alibaba.fastjson2.JSON; import com.dsms.common.remotecall.model.RemoteRequest; import com.dsms.dfsbroker.common.RequestUrlEnum; import org.springframework.http.HttpMethod; +import org.springframework.util.ObjectUtils; import java.util.HashMap; import java.util.Map; @@ -27,6 +28,9 @@ import java.util.Map; public class OrchDeviceLsRequest extends RemoteRequest { public OrchDeviceLsRequest(String hostname) { + if (ObjectUtils.isEmpty(hostname)) { + throw new IllegalArgumentException("hostname must not be blank"); + } Map requestParam = new HashMap<>(8); requestParam.put("prefix", "orch device ls"); requestParam.put("refresh", true); diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/request/OsdAddRequest.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/request/OsdAddRequest.java new file mode 100644 index 0000000000000000000000000000000000000000..27806faaac760e88eb7e052f81b824c68015c6d5 --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/request/OsdAddRequest.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.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 org.springframework.util.ObjectUtils; + +import java.util.HashMap; +import java.util.Map; +import java.util.StringJoiner; + +public class OsdAddRequest extends RemoteRequest { + + public static final String ADD_OSD_FAIL = "Created no osd(s)"; + public static final String ADD_OSD_SUCCESS = "Created osd(s)"; + + + public OsdAddRequest(String nodeName, String devicePath) { + if (ObjectUtils.isEmpty(nodeName) || ObjectUtils.isEmpty(devicePath)) { + throw new IllegalArgumentException("nodeName and devicePath must not be blank"); + } + StringJoiner stringJoiner = new StringJoiner(":"); + stringJoiner.add(nodeName); + stringJoiner.add(devicePath); + Map requestParam = new HashMap<>(4); + requestParam.put("prefix", "orch daemon add osd"); + requestParam.put("svc_arg", stringJoiner.toString()); + 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/RmOsdRequest.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/request/RmOsdRequest.java new file mode 100644 index 0000000000000000000000000000000000000000..051bd7b511d61cf877783eda8df3e2803ec7905f --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/request/RmOsdRequest.java @@ -0,0 +1,43 @@ +/* + * 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 org.springframework.util.ObjectUtils; + +import java.util.HashMap; +import java.util.Map; + +public class RmOsdRequest extends RemoteRequest { + + public static final String RMOSD_STATUS = "Scheduled OSD(s) for removal\n"; + + public RmOsdRequest(String[] osdId) { + if (ObjectUtils.isEmpty(osdId)) { + throw new IllegalArgumentException("osdId must not be empty"); + } + Map requestParam = new HashMap<>(4); + requestParam.put("prefix", "orch osd rm"); + requestParam.put("svc_id", osdId); + 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/RmOsdStatusRequest.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/request/RmOsdStatusRequest.java new file mode 100644 index 0000000000000000000000000000000000000000..a5f562394d465944fdb2d60f170cde2caf66a42a --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/node/request/RmOsdStatusRequest.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 RmOsdStatusRequest extends RemoteRequest { + public static final String EMPTY_RESULT = "No OSD remove/replace operations reported\n"; + public RmOsdStatusRequest() { + Map requestParam = new HashMap<>(4); + requestParam.put("prefix", "orch osd rm status"); + requestParam.put("format", "json"); + this.setUrlPrefix(RequestUrlEnum.REQUEST_URL.getUrlPrefix()); + this.setHttpMethod(HttpMethod.POST); + this.setRequestBody(JSON.toJSONString(requestParam)); + } +} diff --git a/pom.xml b/pom.xml index 2e3c15a2baefaff52f1cc900ea3bfed2ddd278a1..f775514e1db51238fd27b356a5b37344c424a93f 100644 --- a/pom.xml +++ b/pom.xml @@ -51,6 +51,8 @@ 5.8.10 0.11.5 2.0.20.graal + 3.6.7 + @@ -114,6 +116,12 @@ runtime + + com.taobao.arthas + arthas-spring-boot-starter + ${arthas.version} + +