You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.2 KiB
68 lines
2.2 KiB
package com.bsmlab.dfx.agent.config;
|
|
|
|
import com.fasterxml.jackson.databind.DatabindException;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import lombok.Getter;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
@Slf4j
|
|
@Component
|
|
@Getter
|
|
public class AgentConfigReader {
|
|
private AgentConfigDto agentConfigDto = null;
|
|
|
|
public void loadConfigFile(String configFilePath) {
|
|
try {
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
this.agentConfigDto = objectMapper.readValue(new File(configFilePath), AgentConfigDto.class);
|
|
} catch (DatabindException e) {
|
|
log.error("cannot parse a setting file. {}", configFilePath, e);
|
|
log.error(e.getMessage(), e);
|
|
} catch (IOException e) {
|
|
log.error("cannot read a setting file. {}", configFilePath);
|
|
log.error(e.getMessage(), e);
|
|
}
|
|
}
|
|
|
|
public AgentConfigDto.DropBox getDropBox(String dropBoxId) {
|
|
AgentConfigDto.DropBox found = null;
|
|
for(AgentConfigDto.DropBox dropBox : this.agentConfigDto.getDropBox().getDropBoxList()) {
|
|
if(dropBox.getDropBoxId().equals(dropBoxId)) {
|
|
found = dropBox;
|
|
break;
|
|
}
|
|
}
|
|
return found;
|
|
}
|
|
|
|
public AgentConfigDto.KnownAgent getKnownAgent(String hostId) {
|
|
AgentConfigDto.KnownAgent found = null;
|
|
for(AgentConfigDto.KnownAgent knownAgent : this.agentConfigDto.getKnownAgentList()) {
|
|
if(knownAgent.getHostId().equals(hostId)) {
|
|
found = knownAgent;
|
|
break;
|
|
}
|
|
}
|
|
return found;
|
|
}
|
|
|
|
public List<AgentConfigDto.Postman> getScheduledTypePostmanList() {
|
|
List<AgentConfigDto.Postman> postmanList = null;
|
|
for(AgentConfigDto.Postman postman : this.agentConfigDto.getPostman()) {
|
|
if(AgentConfigDto.ActionType.SCHEDULED == postman.getAction().getType()) {
|
|
if(postmanList == null) {
|
|
postmanList = new ArrayList<>();
|
|
}
|
|
postmanList.add(postman);
|
|
}
|
|
}
|
|
return postmanList;
|
|
}
|
|
}
|