From 6905c4cacc13a98adf34a38c7b8eabec7d7ed2f5 Mon Sep 17 00:00:00 2001 From: mabofu Date: Tue, 27 Dec 2022 14:30:00 +0800 Subject: [PATCH] Add node info feature --- .../node/controller/NodeController.java | 14 +++++ .../dsms/modules/node/model/vo/NodeVO.java | 40 ++++++++++++++ .../node/service/impl/NodeServiceImpl.java | 33 +++++++++++- .../java/com/dsms/common/validator/Ip.java | 53 +++++++++++++++++++ .../dsms/common/validator/IpValidator.java | 35 ++++++++++++ .../dfsbroker/node/service/INodeService.java | 3 +- 6 files changed, 174 insertions(+), 4 deletions(-) create mode 100644 dsms-engine-application/src/main/java/com/dsms/modules/node/model/vo/NodeVO.java create mode 100644 dsms-engine-common/src/main/java/com/dsms/common/validator/Ip.java create mode 100644 dsms-engine-common/src/main/java/com/dsms/common/validator/IpValidator.java diff --git a/dsms-engine-application/src/main/java/com/dsms/modules/node/controller/NodeController.java b/dsms-engine-application/src/main/java/com/dsms/modules/node/controller/NodeController.java index 110d8eb..87c6cde 100644 --- a/dsms-engine-application/src/main/java/com/dsms/modules/node/controller/NodeController.java +++ b/dsms-engine-application/src/main/java/com/dsms/modules/node/controller/NodeController.java @@ -16,17 +16,25 @@ package com.dsms.modules.node.controller; +import cn.hutool.core.lang.Validator; import com.dsms.common.model.Result; import com.dsms.dfsbroker.node.model.Node; import com.dsms.dfsbroker.node.service.INodeService; +import com.dsms.modules.cluster.model.vo.ClusterVO; +import com.dsms.modules.node.model.vo.NodeVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.Validate; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.List; +import java.util.Map; @RestController @@ -45,4 +53,10 @@ public class NodeController { return Result.OK(about); } + @ApiOperation("节点池模块-获取节点详细信息") + @PostMapping("/get") + public Result info(@Validated @RequestBody NodeVO nodeVO) { + return Result.OK(nodeService.getNodeInfo(nodeVO.getNodeName())); + } + } diff --git a/dsms-engine-application/src/main/java/com/dsms/modules/node/model/vo/NodeVO.java b/dsms-engine-application/src/main/java/com/dsms/modules/node/model/vo/NodeVO.java new file mode 100644 index 0000000..7ab55c6 --- /dev/null +++ b/dsms-engine-application/src/main/java/com/dsms/modules/node/model/vo/NodeVO.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.modules.node.model.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; + +@ApiModel(value = "节点详情 Request VO", description = "节点详情") +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class NodeVO { + + + @ApiModelProperty(value = "节点名称", required = true, example = "node1") + @NotBlank(message = "节点名称不能为空") + private String nodeName; + + +} 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 3aca9b4..42ef0b6 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 @@ -23,6 +23,7 @@ import com.dsms.dfsbroker.node.api.NodeApi; import com.dsms.dfsbroker.node.model.Device; import com.dsms.dfsbroker.node.model.Node; 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.modules.util.RemoteCallUtil; @@ -93,8 +94,36 @@ public class NodeServiceImpl implements INodeService { } @Override - public Node getNodeInfo(String nodeIp, String nodeName) { + public Node getNodeInfo(String nodeName) { + Node node = new Node(); + node.setNodeName(nodeName); + OrchDeviceLsResult orchDeviceLs = null; + try { + orchDeviceLs = nodeApi.getOrchDeviceLs(RemoteCallUtil.generateRemoteRequest(), nodeName); + } catch (Throwable e) { + throw new DsmsEngineException(e, ResultCode.NODE_LISTNODE_ERROR); + } + if (ObjectUtils.isEmpty(orchDeviceLs)) { + return node; + } + List devices = Device.orchDeviceLsResultParseDevice(orchDeviceLs); + try { + OsdDfResult osdDf = nodeApi.getOsdDf(RemoteCallUtil.generateRemoteRequest()); + List osdDfDevice = Device.osdDfResultParseDevice(osdDf); + for (Device device : devices) { + for (Device deviceDf : osdDfDevice) { + if (deviceDf.getOsdId().equals(device.getOsdId())) { + device.setDevicePgs(deviceDf.getDevicePgs()); + device.setDeviceUsedSize(deviceDf.getDeviceUsedSize()); + device.setOsdStatus(deviceDf.getOsdStatus()); + } + } + } + } catch (Throwable e) { + log.warn("get osd info from dsms-storage fail", e); + } + node.setDevices(devices); - return null; + return node; } } diff --git a/dsms-engine-common/src/main/java/com/dsms/common/validator/Ip.java b/dsms-engine-common/src/main/java/com/dsms/common/validator/Ip.java new file mode 100644 index 0000000..58ebdfc --- /dev/null +++ b/dsms-engine-common/src/main/java/com/dsms/common/validator/Ip.java @@ -0,0 +1,53 @@ +/* + * 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.validator; + +import javax.validation.Constraint; +import javax.validation.Payload; +import javax.validation.constraints.Pattern; +import java.lang.annotation.Documented; +import java.lang.annotation.Repeatable; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.ElementType.TYPE_USE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Documented +@Constraint(validatedBy = {IpValidator.class}) +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) +@Retention(RUNTIME) +@Repeatable(Ip.List.class) +public @interface Ip { + String message() default "非法的ip格式"; + + Class[] groups() default {}; + + Class[] payload() default {}; + + String regexp() default ".*"; + + Pattern.Flag[] flags() default {}; + + @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) + @Retention(RUNTIME) + @Documented + public @interface List { + Ip[] value(); + } +} diff --git a/dsms-engine-common/src/main/java/com/dsms/common/validator/IpValidator.java b/dsms-engine-common/src/main/java/com/dsms/common/validator/IpValidator.java new file mode 100644 index 0000000..e53826c --- /dev/null +++ b/dsms-engine-common/src/main/java/com/dsms/common/validator/IpValidator.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.common.validator; + +import cn.hutool.core.lang.Validator; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +public class IpValidator implements ConstraintValidator { + + @Override + public void initialize(Ip constraintAnnotation) { + ConstraintValidator.super.initialize(constraintAnnotation); + } + + @Override + public boolean isValid(String value, ConstraintValidatorContext context) { + return Validator.isIpv4(value) || Validator.isIpv6(value); + } +} 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 cd45251..64cc384 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 @@ -30,9 +30,8 @@ public interface INodeService { /** * 单个节点信息 - * @param nodeIp 节点ip * @param nodeName 节点名称 * @return 包含磁盘信息的node对象 */ - Node getNodeInfo(String nodeIp, String nodeName); + Node getNodeInfo(String nodeName); } -- Gitee