refactor: 主机服务抽离.
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
### 查询主机配置
|
||||
GET {{baseUrl}}/asset/host-config/get?hostId=1&type=SSH
|
||||
Authorization: {{token}}
|
||||
|
||||
### 查询全部主机配置
|
||||
GET {{baseUrl}}/asset/host-config/list?hostId=1
|
||||
Authorization: {{token}}
|
||||
|
||||
### 通过 id 更新主机配置
|
||||
PUT {{baseUrl}}/asset/host-config/update
|
||||
Content-Type: application/json
|
||||
Authorization: {{token}}
|
||||
|
||||
{
|
||||
"id": "",
|
||||
"config": "",
|
||||
"version": ""
|
||||
}
|
||||
|
||||
### 通过 id 更新主机配置状态
|
||||
PUT {{baseUrl}}/asset/host-config/update-status
|
||||
Content-Type: application/json
|
||||
Authorization: {{token}}
|
||||
|
||||
{
|
||||
"id": "",
|
||||
"status": "",
|
||||
"version": ""
|
||||
}
|
||||
|
||||
###
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.orion.ops.module.asset.controller;
|
||||
|
||||
import com.orion.ops.framework.biz.operator.log.core.annotation.OperatorLog;
|
||||
import com.orion.ops.framework.log.core.annotation.IgnoreLog;
|
||||
import com.orion.ops.framework.log.core.enums.IgnoreLogMode;
|
||||
import com.orion.ops.framework.web.core.annotation.RestWrapper;
|
||||
import com.orion.ops.module.asset.define.operator.HostOperatorType;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostConfigUpdateRequest;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostConfigUpdateStatusRequest;
|
||||
import com.orion.ops.module.asset.entity.vo.HostConfigVO;
|
||||
import com.orion.ops.module.asset.service.HostConfigService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 主机配置 api
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-9-11 14:16
|
||||
*/
|
||||
@Tag(name = "asset - 主机配置服务")
|
||||
@Slf4j
|
||||
@Validated
|
||||
@RestWrapper
|
||||
@RestController
|
||||
@RequestMapping("/asset/host-config")
|
||||
@SuppressWarnings({"ELValidationInJSP", "SpringElInspection"})
|
||||
public class HostConfigController {
|
||||
|
||||
@Resource
|
||||
private HostConfigService hostConfigService;
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "查询主机配置")
|
||||
@Parameter(name = "hostId", description = "hostId", required = true)
|
||||
@Parameter(name = "type", description = "配置类型", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('asset:host:query')")
|
||||
public HostConfigVO getHostConfig(@RequestParam("hostId") Long hostId,
|
||||
@RequestParam(name = "type") String type) {
|
||||
return hostConfigService.getHostConfig(hostId, type);
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "查询全部主机配置")
|
||||
@Parameter(name = "hostId", description = "hostId", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('asset:host:query')")
|
||||
public List<HostConfigVO> getHostConfigList(@RequestParam("hostId") Long hostId) {
|
||||
return hostConfigService.getHostConfigList(hostId);
|
||||
}
|
||||
|
||||
@OperatorLog(HostOperatorType.UPDATE_CONFIG)
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新主机配置")
|
||||
@PreAuthorize("@ss.hasPermission('asset:host:update-config')")
|
||||
public Integer updateHostConfig(@Validated @RequestBody HostConfigUpdateRequest request) {
|
||||
return hostConfigService.updateHostConfig(request);
|
||||
}
|
||||
|
||||
@OperatorLog(HostOperatorType.UPDATE_CONFIG_STATUS)
|
||||
@PutMapping("/update-status")
|
||||
@Operation(summary = "更新主机配置状态")
|
||||
@PreAuthorize("@ss.hasPermission('asset:host:update-config')")
|
||||
public Integer updateHostConfigStatus(@Validated @RequestBody HostConfigUpdateStatusRequest request) {
|
||||
return hostConfigService.updateHostConfigStatus(request);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -53,15 +53,4 @@ DELETE {{baseUrl}}/asset/host/delete?id=1
|
||||
Authorization: {{token}}
|
||||
|
||||
|
||||
### 更新主机别名
|
||||
PUT {{baseUrl}}/asset/host/update-alias
|
||||
Content-Type: application/json
|
||||
Authorization: {{token}}
|
||||
|
||||
{
|
||||
"id": 1,
|
||||
"name": "alias"
|
||||
}
|
||||
|
||||
|
||||
###
|
||||
|
||||
@@ -5,17 +5,13 @@ import com.orion.ops.framework.biz.operator.log.core.annotation.OperatorLog;
|
||||
import com.orion.ops.framework.common.validator.group.Page;
|
||||
import com.orion.ops.framework.log.core.annotation.IgnoreLog;
|
||||
import com.orion.ops.framework.log.core.enums.IgnoreLogMode;
|
||||
import com.orion.ops.framework.security.core.utils.SecurityUtils;
|
||||
import com.orion.ops.framework.web.core.annotation.RestWrapper;
|
||||
import com.orion.ops.module.asset.define.operator.HostOperatorType;
|
||||
import com.orion.ops.module.asset.entity.request.host.*;
|
||||
import com.orion.ops.module.asset.entity.vo.HostConfigVO;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostCreateRequest;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostQueryRequest;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostUpdateRequest;
|
||||
import com.orion.ops.module.asset.entity.vo.HostVO;
|
||||
import com.orion.ops.module.asset.service.HostConfigService;
|
||||
import com.orion.ops.module.asset.service.HostService;
|
||||
import com.orion.ops.module.infra.api.DataAliasApi;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataAliasUpdateDTO;
|
||||
import com.orion.ops.module.infra.enums.DataExtraTypeEnum;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -46,12 +42,6 @@ public class HostController {
|
||||
@Resource
|
||||
private HostService hostService;
|
||||
|
||||
@Resource
|
||||
private HostConfigService hostConfigService;
|
||||
|
||||
@Resource
|
||||
private DataAliasApi dataAliasApi;
|
||||
|
||||
@OperatorLog(HostOperatorType.CREATE)
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建主机")
|
||||
@@ -102,52 +92,5 @@ public class HostController {
|
||||
return hostService.deleteHostById(id);
|
||||
}
|
||||
|
||||
@PutMapping("/update-alias")
|
||||
@Operation(summary = "修改主机别名")
|
||||
public Integer updateHostAlias(@Validated @RequestBody HostAliasUpdateRequest request) {
|
||||
DataAliasUpdateDTO update = DataAliasUpdateDTO.builder()
|
||||
.userId(SecurityUtils.getLoginUserId())
|
||||
.relId(request.getId())
|
||||
.alias(request.getName())
|
||||
.build();
|
||||
return dataAliasApi.updateDataAlias(update, DataExtraTypeEnum.HOST);
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@GetMapping("/get-config")
|
||||
@Operation(summary = "查询主机配置")
|
||||
@Parameter(name = "hostId", description = "hostId", required = true)
|
||||
@Parameter(name = "type", description = "配置类型", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('asset:host:query')")
|
||||
public HostConfigVO getHostConfig(@RequestParam("hostId") Long hostId,
|
||||
@RequestParam(name = "type") String type) {
|
||||
return hostConfigService.getHostConfig(hostId, type);
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@GetMapping("/get-config-all")
|
||||
@Operation(summary = "查询主机配置 - 全部")
|
||||
@Parameter(name = "hostId", description = "hostId", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('asset:host:query')")
|
||||
public List<HostConfigVO> getHostConfig(@RequestParam("hostId") Long hostId) {
|
||||
return hostConfigService.getHostConfig(hostId);
|
||||
}
|
||||
|
||||
@OperatorLog(HostOperatorType.UPDATE_CONFIG)
|
||||
@PutMapping("/update-config")
|
||||
@Operation(summary = "更新主机配置")
|
||||
@PreAuthorize("@ss.hasPermission('asset:host:update-config')")
|
||||
public Integer updateHostConfig(@Validated @RequestBody HostConfigUpdateRequest request) {
|
||||
return hostConfigService.updateHostConfig(request);
|
||||
}
|
||||
|
||||
@OperatorLog(HostOperatorType.UPDATE_CONFIG_STATUS)
|
||||
@PutMapping("/update-config-status")
|
||||
@Operation(summary = "更新主机配置状态")
|
||||
@PreAuthorize("@ss.hasPermission('asset:host:update-config')")
|
||||
public Integer updateHostConfigStatus(@Validated @RequestBody HostConfigUpdateStatusRequest request) {
|
||||
return hostConfigService.updateHostConfigStatus(request);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
### 修改主机别名
|
||||
PUT {{baseUrl}}/asset/host-extra/update-alias
|
||||
Content-Type: application/json
|
||||
Authorization: {{token}}
|
||||
|
||||
{
|
||||
"id": 1,
|
||||
"name": "alias"
|
||||
}
|
||||
|
||||
###
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.orion.ops.module.asset.controller;
|
||||
|
||||
import com.orion.ops.framework.web.core.annotation.RestWrapper;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostAliasUpdateRequest;
|
||||
import com.orion.ops.module.asset.service.HostExtraService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 主机拓展信息 api
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-9-11 14:16
|
||||
*/
|
||||
@Tag(name = "asset - 主机拓展信息服务")
|
||||
@Slf4j
|
||||
@Validated
|
||||
@RestWrapper
|
||||
@RestController
|
||||
@RequestMapping("/asset/host-extra")
|
||||
@SuppressWarnings({"ELValidationInJSP", "SpringElInspection"})
|
||||
public class HostExtraController {
|
||||
|
||||
@Resource
|
||||
private HostExtraService hostExtraService;
|
||||
|
||||
@PutMapping("/update-alias")
|
||||
@Operation(summary = "修改主机别名")
|
||||
public Integer updateHostAlias(@Validated @RequestBody HostAliasUpdateRequest request) {
|
||||
return hostExtraService.updateHostAlias(request);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public interface HostConfigService {
|
||||
* @param hostId hostId
|
||||
* @return 配置
|
||||
*/
|
||||
List<HostConfigVO> getHostConfig(Long hostId);
|
||||
List<HostConfigVO> getHostConfigList(Long hostId);
|
||||
|
||||
/**
|
||||
* 更新配置
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.orion.ops.module.asset.service;
|
||||
|
||||
import com.orion.ops.module.asset.entity.request.host.HostAliasUpdateRequest;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
/**
|
||||
* 主机拓展信息 服务
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/12/20 12:04
|
||||
*/
|
||||
public interface HostExtraService {
|
||||
|
||||
/**
|
||||
* 修改主机别名
|
||||
*
|
||||
* @param request request
|
||||
* @return effect
|
||||
*/
|
||||
Integer updateHostAlias(@Validated @RequestBody HostAliasUpdateRequest request);
|
||||
|
||||
}
|
||||
@@ -69,7 +69,7 @@ public class HostConfigServiceImpl implements HostConfigService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HostConfigVO> getHostConfig(Long hostId) {
|
||||
public List<HostConfigVO> getHostConfigList(Long hostId) {
|
||||
List<HostConfigDO> configs = hostConfigDAO.getHostConfigByHostId(hostId);
|
||||
if (configs.isEmpty()) {
|
||||
// 初始化 兜底
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.orion.ops.module.asset.service.impl;
|
||||
|
||||
import com.orion.ops.framework.security.core.utils.SecurityUtils;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostAliasUpdateRequest;
|
||||
import com.orion.ops.module.asset.service.HostExtraService;
|
||||
import com.orion.ops.module.infra.api.DataAliasApi;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataAliasUpdateDTO;
|
||||
import com.orion.ops.module.infra.enums.DataExtraTypeEnum;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 主机拓展信息 服务实现类
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/12/20 12:11
|
||||
*/
|
||||
@Service
|
||||
public class HostExtraServiceImpl implements HostExtraService {
|
||||
|
||||
@Resource
|
||||
private DataAliasApi dataAliasApi;
|
||||
|
||||
@Override
|
||||
public Integer updateHostAlias(HostAliasUpdateRequest request) {
|
||||
DataAliasUpdateDTO update = DataAliasUpdateDTO.builder()
|
||||
.userId(SecurityUtils.getLoginUserId())
|
||||
.relId(request.getId())
|
||||
.alias(request.getName())
|
||||
.build();
|
||||
return dataAliasApi.updateDataAlias(update, DataExtraTypeEnum.HOST);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user