dfxconsole로부터 settings.json 수신 및 적용 기능 #17

- 진행중 (ListenerService.java line 176 확인)
main
icksishu@gmail.com 2 weeks ago
parent 9896fd8284
commit 1135a74d22

@ -0,0 +1 @@
wget --no-check-certificate --header="Content-Type: application/json" --header="User-Agent: DFXConsole" --post-data="{\"comment\":\"배포하기 위해 종료\",\"exitCode\":0,\"delaySeconds\":3,\"forceAfterSeconds\":15}" https://localhost:17801/actuator/dfxagentShutdown

@ -9,6 +9,7 @@ import com.bsmlab.dfx.agent.support.MessageUtils;
import com.bsmlab.dfx.agent.support.exception.IllegalMessageException; import com.bsmlab.dfx.agent.support.exception.IllegalMessageException;
import com.bsmlab.dfx.agent.support.exception.InCompleteMessageException; import com.bsmlab.dfx.agent.support.exception.InCompleteMessageException;
import com.bsmlab.dfx.agent.support.exception.NullMessageException; import com.bsmlab.dfx.agent.support.exception.NullMessageException;
import com.bsmlab.dfx.agent.task.dropbox.DropBoxSchedulerService;
import com.bsmlab.dfx.agent.task.dropbox.DropBoxService; import com.bsmlab.dfx.agent.task.dropbox.DropBoxService;
import com.bsmlab.dfx.agent.task.postman.PostmanSchedulerService; import com.bsmlab.dfx.agent.task.postman.PostmanSchedulerService;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
@ -36,6 +37,7 @@ import java.util.Iterator;
@Service @Service
public class ListenerService { public class ListenerService {
private final DropBoxService dropBoxService; private final DropBoxService dropBoxService;
private final DropBoxSchedulerService dropBoxSchedulerService;
private final AgentConfigReader agentConfigReader; private final AgentConfigReader agentConfigReader;
private final PostmanSchedulerService postmanSchedulerService; private final PostmanSchedulerService postmanSchedulerService;
@ -155,10 +157,10 @@ public class ListenerService {
try { try {
commandDto = MessageUtils.toCommandDto(messageJsonString); commandDto = MessageUtils.toCommandDto(messageJsonString);
String resultText = null; String resultText = null;
if(CommandDto.CommandType.ALIVE == commandDto.getCommandType()) { if(CommandDto.CommandType.ALIVE == commandDto.getCommandType()) { // ALIVE 메시지인 경우 "ALIVE" 문자열 반송
resultText = "ALIVE"; resultText = "ALIVE";
} }
else if(CommandDto.CommandType.INFORMATION == commandDto.getCommandType()) { else if(CommandDto.CommandType.INFORMATION == commandDto.getCommandType()) { // INFORMATION 메시지인 경우 AgentConfigDto의 인스턴스 내용을 반송
AgentConfigDto agentConfigDto = this.agentConfigReader.getAgentConfigDto(); AgentConfigDto agentConfigDto = this.agentConfigReader.getAgentConfigDto();
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
try { try {
@ -167,6 +169,16 @@ public class ListenerService {
resultText = ""; resultText = "";
} }
} }
else if(CommandDto.CommandType.SAVE_CONFIG == commandDto.getCommandType()) { // SAVE_CONFIG 메시지인 경우 수신 데이터를 AgentConfigDto로 변환
//TODO 1. Postman, Dropbox 쓰레드 정지
this.postmanSchedulerService.stopAll();
this.dropBoxSchedulerService.stopAll();
//TODO 2. AgentConfigDto 갱신 및 settings.json으로 저장
//TODO 3. Postman, Dropbox 쓰래드 시작
this.dropBoxSchedulerService.launch();
this.postmanSchedulerService.launch();
}
ackDto = AckDto.builder().result(AckDto.ResultType.PROCESS_SUCCESS).messageUuid(commandDto.getMessageUuid()).resultText(resultText).build(); ackDto = AckDto.builder().result(AckDto.ResultType.PROCESS_SUCCESS).messageUuid(commandDto.getMessageUuid()).resultText(resultText).build();
} }
catch (IllegalMessageException | NullMessageException e) { catch (IllegalMessageException | NullMessageException e) {

@ -176,15 +176,30 @@ public class DropBoxSchedulerService {
public void launch() { // 실행확인됨 public void launch() { // 실행확인됨
log.debug("{} launch", this.getClass().getName()); log.debug("{} launch", this.getClass().getName());
dropBoxService.allowToPoll();
this.scheduledFutureMap = new HashMap<>(); this.scheduledFutureMap = new HashMap<>();
for(int i = 0; i < this.agentConfigReader.getAgentConfigDto().getDropBoxConfig().getThreadPoolSize(); i++) { for(int i = 0; i < this.agentConfigReader.getAgentConfigDto().getDropBoxConfig().getThreadPoolSize(); i++) {
this.scheduleTask(i); this.scheduleTask(i);
} }
// 수동 메지시 파일 스캐너 쓰레드 시작
// 수동 메지시 파일 스캐너
this.startManualMessageFileScanner(); this.startManualMessageFileScanner();
} }
// 전체 DropBox 중지
public void stopAll() {
// 수동 메시지 파일 스캐너 중지
manualMessageFileScannerScheduledFuture.cancel(true);
// 큐에서 수신 메시지(파일) 가져오기 중지
dropBoxService.denyToPoll();
// Dropbox 쓰레드 중지
for(ScheduledFuture<?> scheduledFuture : scheduledFutureMap.values()) {
if(scheduledFuture != null) {
scheduledFuture.cancel(true);
}
scheduledFutureMap.clear();
}
}
private void scheduleTask(int taskId) { private void scheduleTask(int taskId) {
Runnable task = () -> { Runnable task = () -> {
String messageFilePath = dropBoxService.poll(); String messageFilePath = dropBoxService.poll();

@ -28,6 +28,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
public class DropBoxService { public class DropBoxService {
private final AgentConfigReader agentConfigReader; private final AgentConfigReader agentConfigReader;
private ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<>(); private ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<>();
private boolean isAllowedToPoll;
/** /**
* (ReceiveMessageDto) UUID . UUID . * (ReceiveMessageDto) UUID . UUID .
@ -113,7 +114,15 @@ public class DropBoxService {
* @return ReceiveMessageDto serialize * @return ReceiveMessageDto serialize
*/ */
public String poll() { public String poll() {
return queue.poll(); return this.isAllowedToPoll ? queue.poll() : null;
}
public void denyToPoll() {
this.isAllowedToPoll = false;
}
public void allowToPoll() {
this.isAllowedToPoll = true;
} }
public int getPollSize() { public int getPollSize() {

@ -43,6 +43,7 @@ public class PostmanSchedulerService {
private Map<String, AgentConfigDto.Postman> postmanMap = new HashMap<>(); private Map<String, AgentConfigDto.Postman> postmanMap = new HashMap<>();
private Map<String, String> sentMessageFileMap = new HashMap<>(); private Map<String, String> sentMessageFileMap = new HashMap<>();
// 전달받은 PostmanId의 쓰레드 실행 (run)
private void startPostman(String postmanId) { private void startPostman(String postmanId) {
AgentConfigDto.Postman postman = this.postmanMap.get(postmanId); AgentConfigDto.Postman postman = this.postmanMap.get(postmanId);
this.stop(postmanId); this.stop(postmanId);
@ -59,6 +60,7 @@ public class PostmanSchedulerService {
} }
} }
// Postman 설정에 따라서 모든 Postman 쓰레드 활성화 (startPostman)
public void launch() { // 실행확인됨 public void launch() { // 실행확인됨
log.info("{} launch", this.getClass().getName()); log.info("{} launch", this.getClass().getName());
List<AgentConfigDto.Postman> postmanList = agentConfigReader.getScheduledTypePostmanList(); List<AgentConfigDto.Postman> postmanList = agentConfigReader.getScheduledTypePostmanList();
@ -71,6 +73,17 @@ public class PostmanSchedulerService {
this.findAndAddSentMessageFile(new File(agentConfigReader.getAgentConfigDto().getDropBoxConfig().getSentMessageStorageRoot())); this.findAndAddSentMessageFile(new File(agentConfigReader.getAgentConfigDto().getDropBoxConfig().getSentMessageStorageRoot()));
} }
// 현재 동작중인 모든 Postman 쓰레드 중지 및 postmanMap 제거
public void stopAll() {
for(String postmanId : postmanMap.keySet()) {
ScheduledFuture<?> scheduledFuture = scheduledFutureMap.remove(postmanId);
if(scheduledFuture != null) {
scheduledFuture.cancel(true);
}
}
postmanMap.clear();
}
private void findAndAddSentMessageFile(File parentDirectory) { private void findAndAddSentMessageFile(File parentDirectory) {
File[] filesOnDirectory = parentDirectory.listFiles(); File[] filesOnDirectory = parentDirectory.listFiles();
if(filesOnDirectory != null) { if(filesOnDirectory != null) {

Loading…
Cancel
Save