Skip to content

Commit 3b2136e

Browse files
authored
Merge pull request #169 from Dokyeongyun/ft-220216-consoleApp
Ft 220216 console app
2 parents fd65b72 + c3979b1 commit 3b2136e

File tree

7 files changed

+139
-78
lines changed

7 files changed

+139
-78
lines changed

src/main/java/root/applications/ConsoleApp.java

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,31 @@
88
import java.util.List;
99
import java.util.stream.Collectors;
1010

11+
import dnl.utils.text.table.TextTable;
12+
import dnl.utils.text.table.csv.CsvTableModel;
13+
import root.common.database.contracts.AbstractDatabase;
14+
import root.common.database.implement.JdbcDatabase;
15+
import root.common.server.implement.JschServer;
16+
import root.core.batch.DBCheckBatch;
17+
import root.core.batch.ServerCheckBatch;
18+
import root.core.domain.AlertLogCommandPeriod;
19+
import root.core.domain.JdbcConnectionInfo;
20+
import root.core.domain.JschConnectionInfo;
21+
import root.core.repository.constracts.DBCheckRepository;
1122
import root.core.repository.constracts.PropertyRepository;
23+
import root.core.repository.constracts.ServerCheckRepository;
24+
import root.core.repository.implement.DBCheckRepositoryImpl;
1225
import root.core.repository.implement.PropertyRepositoryImpl;
26+
import root.core.repository.implement.ReportFileRepo;
27+
import root.core.repository.implement.ServerCheckRepositoryImpl;
1328
import root.core.service.contracts.PropertyService;
1429
import root.core.service.implement.FilePropertyService;
30+
import root.core.usecase.constracts.DBCheckUsecase;
31+
import root.core.usecase.constracts.ServerCheckUsecase;
32+
import root.core.usecase.implement.DBCheckUsecaseImpl;
33+
import root.core.usecase.implement.ServerCheckUsecaseImpl;
34+
import root.utils.CsvUtils;
35+
import root.utils.DateUtils;
1536
import root.utils.PatternUtils;
1637

1738
/**
@@ -77,17 +98,17 @@ public static void main(String[] args) throws IOException {
7798
String selectedPreset = "";
7899
while (true) {
79100
System.out.println(String.format("사용하실 모니터링여부 설정을 선택해주세요."));
80-
101+
81102
List<String> presetNames = propService.getMonitoringPresetNameList();
82103
if (presetNames.size() == 0) {
83104
System.out.println("모니터링여부 설정파일이 존재하지 않습니다. 프로그램을 종료합니다.");
84105
return;
85106
}
86-
107+
87108
for (int i = 0; i < presetNames.size(); i++) {
88109
System.out.println(String.format("[%d] %s", (i + 1), presetNames.get(i)));
89110
}
90-
111+
91112
String input = br.readLine().trim();
92113
if (!PatternUtils.isOnlyNumber(input)) {
93114
System.out.println("잘못 입력하셨습니다. 모니터링여부 설정파일을 다시 선택해주세요.");
@@ -104,5 +125,53 @@ public static void main(String[] args) throws IOException {
104125
break;
105126
}
106127
System.out.println(String.format("선택된 파일은 [%s] 입니다.", selectedPreset));
128+
129+
// STEP4: 설정파일의 접속정보를 읽어 DB,Server 객체 생성 및 출력
130+
List<String> dbNames = propService.getMonitoringDBNameList();
131+
List<JdbcConnectionInfo> jdbcConnectionList = propService.getJdbcConnInfoList(dbNames);
132+
System.out.println("저장된 DB접속정보는 다음과 같습니다.");
133+
TextTable dbTable = new TextTable(
134+
new CsvTableModel(CsvUtils.toCsvString(jdbcConnectionList, JdbcConnectionInfo.class)));
135+
dbTable.printTable(System.out, 2);
136+
137+
List<String> serverNames = propService.getMonitoringServerNameList();
138+
List<JschConnectionInfo> jschConnectionList = propService.getJschConnInfoList(serverNames);
139+
System.out.println("저장된 Server접속정보는 다음과 같습니다.");
140+
TextTable serverTable = new TextTable(
141+
new CsvTableModel(CsvUtils.toCsvString(jschConnectionList, JschConnectionInfo.class)));
142+
serverTable.printTable(System.out, 2);
143+
144+
// TODO STEP5: 모니터링여부 설정 읽기
145+
146+
// STEP6: 모니터링 수행
147+
System.out.println("DB 모니터링을 수행합니다.");
148+
for (JdbcConnectionInfo jdbc : jdbcConnectionList) {
149+
System.out.println("■ [ " + jdbc.getJdbcDBName() + " Monitoring Start ]\n");
150+
AbstractDatabase db = new JdbcDatabase(jdbc);
151+
db.init();
152+
DBCheckRepository repo = new DBCheckRepositoryImpl(db);
153+
DBCheckUsecase usecase = new DBCheckUsecaseImpl(repo, ReportFileRepo.getInstance());
154+
DBCheckBatch dbBatch = new DBCheckBatch(usecase);
155+
dbBatch.startBatchArchiveUsageCheck();
156+
dbBatch.startBatchTableSpaceUsageCheck();
157+
dbBatch.startBatchASMDiskUsageCheck();
158+
System.out.println("■ [ " + jdbc.getJdbcDBName() + " Monitoring End ]\n\n");
159+
}
160+
161+
System.out.println("Server 모니터링을 수행합니다.");
162+
for (JschConnectionInfo jsch : jschConnectionList) {
163+
System.out.println("■ [ " + jsch.getServerName() + " Monitoring Start ]\n");
164+
JschServer server = new JschServer(jsch);
165+
server.init();
166+
ServerCheckRepository repo = new ServerCheckRepositoryImpl(server);
167+
ServerCheckUsecase usecase = new ServerCheckUsecaseImpl(repo);
168+
ServerCheckBatch serverBatch = new ServerCheckBatch(usecase);
169+
170+
AlertLogCommandPeriod alcp = new AlertLogCommandPeriod(jsch.getAlc(),
171+
DateUtils.addDate(DateUtils.getToday("yyyy-MM-dd"), 0, 0, -1), DateUtils.getToday("yyyy-MM-dd"));
172+
serverBatch.startBatchAlertLogCheckDuringPeriod(alcp);
173+
serverBatch.startBatchOSDiskUsageCheck();
174+
System.out.println("■ [ " + jsch.getServerName() + " Monitoring End ]\n\n");
175+
}
107176
}
108177
}

src/main/java/root/core/repository/constracts/PropertyRepository.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ public interface PropertyRepository {
5959

6060
void createNewPropertiesFile(String filePath, String type);
6161

62-
List<JdbcConnectionInfo> getJdbcConnectionMap();
62+
JdbcConnectionInfo getJdbcConnectionInfo(String dbName);
6363

64-
List<JschConnectionInfo> getJschConnectionMap();
65-
66-
Map<String, AlertLogCommand> getAlertLogCommandMap();
64+
JschConnectionInfo getJschConnectionInfo(String serverName);
65+
66+
AlertLogCommand getAlertLogCommand(String serverName);
6767
}

src/main/java/root/core/repository/implement/PropertyRepositoryImpl.java

Lines changed: 6 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import java.io.FileWriter;
66
import java.io.IOException;
77
import java.util.ArrayList;
8-
import java.util.Collections;
9-
import java.util.HashMap;
108
import java.util.LinkedHashMap;
119
import java.util.List;
1210
import java.util.Map;
@@ -486,31 +484,14 @@ public void createNewPropertiesFile(String filePath, String type) {
486484
}
487485
}
488486

489-
/**
490-
* Properties 파일에서 모니터링할 DB명을 읽어온 후, 각 DB별 JDBC Connection 정보 가지는 객체 생성
491-
*
492-
* @return 각 DB별 JdbcConnectionInfo 객체를 담은 후 DB Name 순으로 정렬한 리스트
493-
*/
494-
@Override
495-
public List<JdbcConnectionInfo> getJdbcConnectionMap() {
496-
String[] dbNames = connInfoConfig.getStringArray("dbnames");
497-
if (dbNames == null || dbNames.length == 0) {
498-
return new ArrayList<>();
499-
}
500-
List<JdbcConnectionInfo> jdbcList = new ArrayList<>();
501-
for (String dbName : dbNames)
502-
jdbcList.add(getJdbcConnectionInfo(dbName));
503-
Collections.sort(jdbcList, (o1, o2) -> o1.getJdbcDBName().compareTo(o2.getJdbcDBName()) < 0 ? -1 : 1);
504-
return jdbcList;
505-
}
506-
507487
/**
508488
* Properties 파일에서 DB별 JdbcConnectionInfo를 읽어와 객체를 생성
509489
*
510490
* @param dbName
511491
* @return
512492
*/
513-
private JdbcConnectionInfo getJdbcConnectionInfo(String dbName) {
493+
@Override
494+
public JdbcConnectionInfo getJdbcConnectionInfo(String dbName) {
514495
String jdbcAlias = connInfoConfig.getString(dbName + ".jdbc.alias");
515496
String jdbcDriver = connInfoConfig.getString(dbName + ".jdbc.driver");
516497
String jdbcUrl = connInfoConfig.getString(dbName + ".jdbc.url");
@@ -521,31 +502,14 @@ private JdbcConnectionInfo getJdbcConnectionInfo(String dbName) {
521502
return new JdbcConnectionInfo(jdbcAlias, jdbcDriver, jdbcUrl, jdbcId, jdbcPw, jdbcValidation, jdbcConnections);
522503
}
523504

524-
/**
525-
* Properties 파일에서 모니터링할 Server명을 읽어온 후, 각 DB별 JSchConnection 정보 가지는 객체 생성
526-
*
527-
* @return 각 DB별 JdbcConnectionInfo 객체를 담은 후 Server Name 순으로 정렬한 리스트
528-
*/
529-
@Override
530-
public List<JschConnectionInfo> getJschConnectionMap() {
531-
String[] serverNames = connInfoConfig.getStringArray("servernames");
532-
if (serverNames == null || serverNames.length == 0) {
533-
return new ArrayList<>();
534-
}
535-
List<JschConnectionInfo> jschList = new ArrayList<>();
536-
for (String serverName : serverNames)
537-
jschList.add(getJschConnectionInfo(serverName));
538-
Collections.sort(jschList, (o1, o2) -> o1.getServerName().compareTo(o2.getServerName()) < 0 ? -1 : 1);
539-
return jschList;
540-
}
541-
542505
/**
543506
* Properties 파일에서 Server별 JschConnectionInfo를 읽어와 객체를 생성
544507
*
545508
* @param serverName
546509
* @return
547510
*/
548-
private JschConnectionInfo getJschConnectionInfo(String serverName) {
511+
@Override
512+
public JschConnectionInfo getJschConnectionInfo(String serverName) {
549513
String serverHost = connInfoConfig.getString(serverName + ".server.host");
550514
String serverPort = connInfoConfig.getString(serverName + ".server.port");
551515
String serverUserName = connInfoConfig.getString(serverName + ".server.username");
@@ -561,7 +525,8 @@ private JschConnectionInfo getJschConnectionInfo(String serverName) {
561525
* @param serverName
562526
* @return
563527
*/
564-
private AlertLogCommand getAlertLogCommand(String serverName) {
528+
@Override
529+
public AlertLogCommand getAlertLogCommand(String serverName) {
565530
String alertLogFilePath = connInfoConfig.getString(serverName + ".server.alertlog.filepath");
566531
String alertLogReadLine = connInfoConfig.getString(serverName + ".server.alertlog.readline");
567532
String alertLogDateFormat = connInfoConfig.getString(serverName + ".server.alertlog.dateformat");
@@ -570,18 +535,4 @@ private AlertLogCommand getAlertLogCommand(String serverName) {
570535
alertLogDateFormatRegex);
571536
return alc;
572537
}
573-
574-
/**
575-
* Properties 파일에서 모니터링할 서버명을 읽어온 후, 각 서버별 AlertLogCommand 객체를 생성한다.
576-
*
577-
* @return 각 DB별 JdbcConnectionInfo 객체를 담은 후 DB Name 순으로 정렬한 리스트
578-
*/
579-
@Override
580-
public Map<String, AlertLogCommand> getAlertLogCommandMap() {
581-
String[] serverNames = connInfoConfig.getStringArray("servernames");
582-
Map<String, AlertLogCommand> alcMap = new HashMap<>();
583-
for (String serverName : serverNames)
584-
alcMap.put(serverName, getAlertLogCommand(serverName));
585-
return alcMap;
586-
}
587538
}

src/main/java/root/core/service/contracts/PropertyService.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import java.util.List;
44
import java.util.Map;
55

6+
import root.core.domain.JdbcConnectionInfo;
7+
import root.core.domain.JschConnectionInfo;
8+
69
public interface PropertyService {
710

811
Map<String, String> getMonitoringPresetMap();
@@ -12,4 +15,12 @@ public interface PropertyService {
1215
List<String> getMonitoringPresetNameList();
1316

1417
String getMonitoringPresetFilePath(String presetName);
18+
19+
List<String> getMonitoringDBNameList();
20+
21+
List<String> getMonitoringServerNameList();
22+
23+
List<JdbcConnectionInfo> getJdbcConnInfoList(List<String> dbNames);
24+
25+
List<JschConnectionInfo> getJschConnInfoList(List<String> serverNames);
1526
}

src/main/java/root/core/service/implement/FilePropertyService.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package root.core.service.implement;
22

33
import java.util.ArrayList;
4+
import java.util.Arrays;
45
import java.util.List;
56
import java.util.Map;
67
import java.util.Spliterator;
@@ -10,6 +11,8 @@
1011
import java.util.stream.Collectors;
1112
import java.util.stream.StreamSupport;
1213

14+
import root.core.domain.JdbcConnectionInfo;
15+
import root.core.domain.JschConnectionInfo;
1316
import root.core.repository.constracts.PropertyRepository;
1417
import root.core.service.contracts.PropertyService;
1518

@@ -19,7 +22,7 @@ public class FilePropertyService implements PropertyService {
1922
private static final Pattern MONITORING_PRESET_KEY_PATTERN = Pattern.compile(MONITORING_PRESET_KEY);
2023

2124
private PropertyRepository propRepo;
22-
25+
2326
public FilePropertyService(PropertyRepository propRepo) {
2427
this.propRepo = propRepo;
2528
}
@@ -29,8 +32,7 @@ public Map<String, String> getMonitoringPresetMap() {
2932
return StreamSupport
3033
.stream(Spliterators.spliteratorUnknownSize(propRepo.getConfiguration("connInfoConfig").getKeys(),
3134
Spliterator.ORDERED), false)
32-
.filter(key -> key.matches(MONITORING_PRESET_KEY))
33-
.collect(Collectors.toUnmodifiableMap(key -> {
35+
.filter(key -> key.matches(MONITORING_PRESET_KEY)).collect(Collectors.toUnmodifiableMap(key -> {
3436
Matcher m = MONITORING_PRESET_KEY_PATTERN.matcher(key);
3537
return m.matches() ? m.group(1) : null;
3638
}, key -> key));
@@ -50,4 +52,26 @@ public List<String> getMonitoringPresetNameList() {
5052
public String getMonitoringPresetFilePath(String presetName) {
5153
return getMonitoringPresetMap().get(presetName);
5254
}
55+
56+
@Override
57+
public List<String> getMonitoringDBNameList() {
58+
return Arrays.asList(propRepo.getMonitoringDBNames());
59+
}
60+
61+
@Override
62+
public List<String> getMonitoringServerNameList() {
63+
return Arrays.asList(propRepo.getMonitoringServerNames());
64+
}
65+
66+
@Override
67+
public List<JdbcConnectionInfo> getJdbcConnInfoList(List<String> dbNames) {
68+
return dbNames.stream().sorted()
69+
.collect(Collectors.mapping(dbName -> propRepo.getJdbcConnectionInfo(dbName), Collectors.toList()));
70+
}
71+
72+
@Override
73+
public List<JschConnectionInfo> getJschConnInfoList(List<String> serverNames) {
74+
return serverNames.stream().sorted().collect(
75+
Collectors.mapping(serverName -> propRepo.getJschConnectionInfo(serverName), Collectors.toList()));
76+
}
5377
}

src/main/java/root/javafx/Controller/RunMenuController.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import root.core.repository.implement.PropertyRepositoryImpl;
4141
import root.core.repository.implement.ReportFileRepo;
4242
import root.core.repository.implement.ServerCheckRepositoryImpl;
43+
import root.core.service.contracts.PropertyService;
44+
import root.core.service.implement.FilePropertyService;
4345
import root.core.usecase.constracts.DBCheckUsecase;
4446
import root.core.usecase.constracts.ServerCheckUsecase;
4547
import root.core.usecase.implement.DBCheckUsecaseImpl;
@@ -50,10 +52,12 @@
5052
import root.utils.AlertUtils;
5153

5254
public class RunMenuController implements Initializable {
53-
55+
56+
5457
/* Dependency Injection */
5558
PropertyRepository propRepo = PropertyRepositoryImpl.getInstance();
5659
ReportRepository reportRepository = ReportFileRepo.getInstance();
60+
PropertyService propService = new FilePropertyService(propRepo);
5761

5862
/* View Binding */
5963
@FXML JFXComboBox<String> runConnInfoFileComboBox;
@@ -280,9 +284,10 @@ private void loadConnectionInfoProperties(String connInfoConfigFilePath) {
280284
public void runMonitoring(ActionEvent e) {
281285
if(!validateInput()) return;
282286

283-
// DB Usage Check
284-
List<JdbcConnectionInfo> jdbcConnectionList = propRepo.getJdbcConnectionMap();
285-
for(JdbcConnectionInfo jdbc : jdbcConnectionList) {
287+
// DB Usage Check
288+
List<JdbcConnectionInfo> jdbcConnectionList = propService
289+
.getJdbcConnInfoList(propService.getMonitoringDBNameList());
290+
for (JdbcConnectionInfo jdbc : jdbcConnectionList) {
286291
System.out.println("■ [ " + jdbc.getJdbcDBName() + " Monitoring Start ]\n");
287292
JdbcDatabase db = new JdbcDatabase(jdbc);
288293
db.init();
@@ -292,12 +297,13 @@ public void runMonitoring(ActionEvent e) {
292297
tableSpaceUsageMAP.addTableData(jdbc.getJdbcDBName(), usecase.getCurrentTableSpaceUsage());
293298
asmDiskUsageMAP.addTableData(jdbc.getJdbcDBName(), usecase.getCurrentASMDiskUsage());
294299
db.uninit();
295-
}
296-
300+
}
301+
297302
String alertLogStartDay = alertLogStartDayDP.getValue().toString();
298303
String alertLogEndDay = alertLogEndDayDP.getValue().toString();
299-
List<JschConnectionInfo> jschConnectionList = propRepo.getJschConnectionMap();
300-
for(JschConnectionInfo jsch : jschConnectionList) {
304+
List<JschConnectionInfo> jschConnectionList = propService
305+
.getJschConnInfoList(propService.getMonitoringServerNameList());
306+
for (JschConnectionInfo jsch : jschConnectionList) {
301307
System.out.println("■ [ " + jsch.getServerName() + " Monitoring Start ]\n");
302308
JschServer server = new JschServer(jsch);
303309
server.init();

0 commit comments

Comments
 (0)