parent
ecdb0e05af
commit
9bf05da49a
@ -0,0 +1,48 @@
|
||||
package com.bsmlab.dfx.dfxconsole.app.agent;
|
||||
|
||||
import com.bsmlab.dfx.agent.config.AgentConfigDto;
|
||||
import com.bsmlab.dfx.dfxconsole.app.agent.service.DfxAgentInfoDto;
|
||||
import com.bsmlab.dfx.dfxconsole.app.agent.service.DfxAgentInfoService;
|
||||
import com.bsmlab.dfx.dfxconsole.framework.support.ResponseUtils;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class DfxAgentInfoController {
|
||||
private final DfxAgentInfoService dfxAgentInfoService;
|
||||
|
||||
@PostMapping("/app-api/agent/getAgentInfoDtoList")
|
||||
public ResponseEntity<List<DfxAgentInfoDto>> agentConfigDtoList() {
|
||||
List<DfxAgentInfoDto> dfxAgentInfoDtoList = dfxAgentInfoService.getDfxAgentInfoDtoList();
|
||||
return ResponseEntity.ok().body(dfxAgentInfoDtoList);
|
||||
}
|
||||
|
||||
@PostMapping("/app-api/agent/getAgentInfoDto")
|
||||
public ResponseEntity<DfxAgentInfoDto> getAgentInfoDto(@RequestBody Map<String, String> paramMap) {
|
||||
String agentId = paramMap.get("agentId");
|
||||
DfxAgentInfoDto dfxAgentInfoDto = dfxAgentInfoService.getDfxAgentInfoDto(agentId);
|
||||
return ResponseEntity.ok().body(dfxAgentInfoDto);
|
||||
}
|
||||
|
||||
@PostMapping("/app-api/agent/getAgentConfigDto")
|
||||
public ResponseEntity<?> getAgentConfigDto(@RequestBody Map<String, String> paramMap) {
|
||||
String agentId = paramMap.get("agentId");
|
||||
AgentConfigDto agentConfigDto = null;
|
||||
try {
|
||||
agentConfigDto = dfxAgentInfoService.getDfxAgentConfigDto(agentId);
|
||||
return ResponseEntity.ok().body(agentConfigDto);
|
||||
} catch (JsonProcessingException e) {
|
||||
return ResponseEntity.internalServerError().body(ResponseUtils.toExceptionResponseDto(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package com.bsmlab.dfx.dfxconsole.app.agent.service;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Builder
|
||||
public class DfxAgentInfoDto {
|
||||
private String agentId;
|
||||
private String hostName;
|
||||
private int listenPort;
|
||||
private int postmanCount;
|
||||
private int dropboxCount;
|
||||
private String statusCode;
|
||||
private long lastStatusTs;
|
||||
private String settingsData;
|
||||
private String lastStatusTimeString;
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package com.bsmlab.dfx.dfxconsole.app.agent.service;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface DfxAgentInfoMapper {
|
||||
List<DfxAgentInfoDto> selectDfxAgentInfoList();
|
||||
DfxAgentInfoDto selectDfxAgentInfoByAgentId(DfxAgentInfoDto dfxAgentInfoDto);
|
||||
void insertDfxAgentInfo(DfxAgentInfoDto dfxAgentInfoDto);
|
||||
int updateDfxAgentInfo(DfxAgentInfoDto dfxAgentInfoDto);
|
||||
List<DfxDropboxDto> selectDfxDropboxList();
|
||||
DfxDropboxDto selectDfxDropboxByAgentIdAndDropBoxId(DfxDropboxDto dfxDropboxDto);
|
||||
void insertDfxDropbox(DfxDropboxDto dfxDropboxDto);
|
||||
int deleteDfxDropboxByAgentIdAndDropboxId(DfxDropboxDto dfxDropboxDto);
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
package com.bsmlab.dfx.dfxconsole.app.agent.service;
|
||||
|
||||
import com.bsmlab.dfx.agent.config.AgentConfigDto;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class DfxAgentInfoService {
|
||||
private final DfxAgentInfoMapper dfxAgentInfoMapper;
|
||||
|
||||
public List<DfxAgentInfoDto> getDfxAgentInfoDtoList() {
|
||||
List<DfxAgentInfoDto> dfxAgentInfoDtoList = null;
|
||||
dfxAgentInfoDtoList = dfxAgentInfoMapper.selectDfxAgentInfoList();
|
||||
return dfxAgentInfoDtoList;
|
||||
}
|
||||
|
||||
public DfxAgentInfoDto getDfxAgentInfoDto(String agentId) {
|
||||
DfxAgentInfoDto dfxAgentInfoDto = null;
|
||||
dfxAgentInfoDto = dfxAgentInfoMapper.selectDfxAgentInfoByAgentId(DfxAgentInfoDto.builder().agentId(agentId).build());
|
||||
return dfxAgentInfoDto;
|
||||
}
|
||||
|
||||
public void saveDfxAgentInfoDto(DfxAgentInfoDto dfxAgentInfoDto) {
|
||||
DfxAgentInfoDto existedDfxAgentInfoDto = dfxAgentInfoMapper.selectDfxAgentInfoByAgentId(dfxAgentInfoDto);
|
||||
if(existedDfxAgentInfoDto != null && StringUtils.isNotEmpty(existedDfxAgentInfoDto.getAgentId())) {
|
||||
dfxAgentInfoMapper.updateDfxAgentInfo(dfxAgentInfoDto);
|
||||
}
|
||||
else {
|
||||
dfxAgentInfoMapper.insertDfxAgentInfo(dfxAgentInfoDto);
|
||||
}
|
||||
}
|
||||
|
||||
public AgentConfigDto getDfxAgentConfigDto(String agentId) throws JsonProcessingException {
|
||||
DfxAgentInfoDto dfxAgentInfoDto = null;
|
||||
dfxAgentInfoDto = dfxAgentInfoMapper.selectDfxAgentInfoByAgentId(DfxAgentInfoDto.builder().agentId(agentId).build());
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
AgentConfigDto agentConfigDto = objectMapper.readValue(dfxAgentInfoDto.getSettingsData(), new TypeReference<AgentConfigDto>() {});
|
||||
return agentConfigDto;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package com.bsmlab.dfx.dfxconsole.app.agent.service;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
public class DfxDropboxDto {
|
||||
private String agentId;
|
||||
private String dropboxId;
|
||||
private String taskType;
|
||||
private String dataSourceId;
|
||||
private String sqlId;
|
||||
private String description;
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package com.bsmlab.dfx.dfxconsole.framework.dto;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
public class ExceptionResponseDto {
|
||||
private String message;
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package com.bsmlab.dfx.dfxconsole.framework.support;
|
||||
|
||||
import com.bsmlab.dfx.dfxconsole.framework.dto.ExceptionResponseDto;
|
||||
|
||||
public class ResponseUtils {
|
||||
public static ExceptionResponseDto toExceptionResponseDto(Exception e) {
|
||||
ExceptionResponseDto exceptionResponseDto = ExceptionResponseDto.builder().message(e.getMessage()).build();
|
||||
return exceptionResponseDto;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,87 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.bsmlab.dfx.dfxconsole.app.agent.service.DfxAgentInfoMapper">
|
||||
|
||||
<select id="selectDfxAgentInfoList" resultType="com.bsmlab.dfx.dfxconsole.app.agent.service.DfxAgentInfoDto">
|
||||
<![CDATA[
|
||||
SELECT AGENT_ID, HOST_NAME, LISTEN_PORT, DESCRIPTION, POSTMAN_COUNT, DROPBOX_COUNT, STATUS_CODE, LAST_STATUS_TS, SETTINGS_DATA
|
||||
, TO_CHAR(LAST_STATUS_TS, 'YYYY-MM-DD HH24:MI:SS') AS LAST_STATUS_TIME_STRING
|
||||
FROM TB_DFX_AGENT_INFO
|
||||
ORDER BY HOST_NAME, AGENT_ID
|
||||
]]>
|
||||
</select>
|
||||
|
||||
<select id="selectDfxAgentInfoByAgentId" parameterType="com.bsmlab.dfx.dfxconsole.app.agent.service.DfxAgentInfoDto" resultType="com.bsmlab.dfx.dfxconsole.app.agent.service.DfxAgentInfoDto">
|
||||
<![CDATA[
|
||||
SELECT AGENT_ID, HOST_NAME, LISTEN_PORT, DESCRIPTION, POSTMAN_COUNT, DROPBOX_COUNT, STATUS_CODE, LAST_STATUS_TS, SETTINGS_DATA
|
||||
, TO_CHAR(LAST_STATUS_TS, 'YYYY-MM-DD HH24:MI:SS') AS LAST_STATUS_TIME_STRING
|
||||
FROM TB_DFX_AGENT_INFO
|
||||
WHERE 1 = 1
|
||||
AND AGENT_ID = #{agentId}
|
||||
]]>
|
||||
</select>
|
||||
|
||||
<insert id="insertDfxAgentInfo" parameterType="com.bsmlab.dfx.dfxconsole.app.agent.service.DfxAgentInfoDto">
|
||||
<![CDATA[
|
||||
INSERT INTO TB_DFX_AGENT_INFO (
|
||||
AGENT_ID, HOST_NAME, LISTEN_PORT, DESCRIPTION, POSTMAN_COUNT, DROPBOX_COUNT, STATUS_CODE, LAST_STATUS_TS, SETTINGS_DATA
|
||||
)
|
||||
VALUES (
|
||||
#{agentId}, #{hostName}, #{listenPort}, #{description}, #{postmanCount}, #{dropboxCount}, #{statusCode}, #{lastStatusTs}, #{settingsData}
|
||||
)
|
||||
]]>
|
||||
</insert>
|
||||
|
||||
<update id="updateDfxAgentInfo" parameterType="com.bsmlab.dfx.dfxconsole.app.agent.service.DfxAgentInfoDto">
|
||||
<![CDATA[
|
||||
UPDATE TB_DFX_AGENT_INFO
|
||||
SET HOST_NAME = #{hostName}
|
||||
, LISTEN_PORT = #{listenPort}
|
||||
, DESCRIPTION = #{description}
|
||||
, POSTMAN_COUNT = #{postmanCount}
|
||||
, DROPBOX_COUNT = #{dropboxCount}
|
||||
, STATUS_CODE = #{statusCode}
|
||||
, LAST_STATUS_TS = #{lastStatusTs}
|
||||
, SETTINGS_DATA = #{settingsData}
|
||||
WHERE 1 = 1
|
||||
AND AGENT_ID = #{agentId}
|
||||
]]>
|
||||
</update>
|
||||
|
||||
<select id="selectDfxDropboxList" resultType="com.bsmlab.dfx.dfxconsole.app.agent.service.DfxDropboxDto">
|
||||
<![CDATA[
|
||||
SELECT AGENT_ID, DROPBOX_ID, TASK_TYPE, DATA_SOURCE_ID, SQL_ID, DESCRIPTION
|
||||
FROM TB_DFX_DROPBOX
|
||||
ORDER BY HOST_NAME, AGENT_ID, DROPBOX_ID
|
||||
]]>
|
||||
</select>
|
||||
|
||||
<select id="selectDfxDropboxByAgentIdAndDropBoxId" resultType="com.bsmlab.dfx.dfxconsole.app.agent.service.DfxDropboxDto">
|
||||
<![CDATA[
|
||||
SELECT AGENT_ID, DROPBOX_ID, TASK_TYPE, DATA_SOURCE_ID, SQL_ID, DESCRIPTION
|
||||
FROM TB_DFX_DROPBOX
|
||||
WHERE 1 = 1
|
||||
AND AGENT_ID = #{agentId}
|
||||
AND DROPBOX_ID = #{dropboxId}
|
||||
]]>
|
||||
</select>
|
||||
|
||||
<insert id="insertDfxDropbox" parameterType="com.bsmlab.dfx.dfxconsole.app.agent.service.DfxDropboxDto">
|
||||
<![CDATA[
|
||||
INSERT INTO TB_DFX_DROPBOX (
|
||||
AGENT_ID, DROPBOX_ID, TASK_TYPE, DATA_SOURCE_ID, SQL_ID, DESCRIPTION
|
||||
)
|
||||
VALUES (
|
||||
#{agentId}, #{dropboxId}, #{taskType}, #{dataSourceId}, #{sqlId}, #{description}
|
||||
)
|
||||
]]>
|
||||
</insert>
|
||||
|
||||
<update id="deleteDfxDropboxByAgentIdAndDropboxId" parameterType="com.bsmlab.dfx.dfxconsole.app.agent.service.DfxDropboxDto">
|
||||
<![CDATA[
|
||||
DELETE FROM TB_DFX_DROPBOX
|
||||
WHERE 1 = 1
|
||||
AND AGENT_ID = #{agentId} AND DROPBOX_ID = #{dropboxId}
|
||||
]]>
|
||||
</update>
|
||||
</mapper>
|
||||
Loading…
Reference in new issue