Skip to content

Commit f60b6be

Browse files
authored
Merge pull request #216 from Dokyeongyun/ft-220417-addServerOSInfo
Ft 220417 add server os info
2 parents 5b890e4 + 75f4d18 commit f60b6be

File tree

8 files changed

+90
-36
lines changed

8 files changed

+90
-36
lines changed

src/main/java/root/core/domain/JschConnectionInfo.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package root.core.domain;
22

33
import lombok.Data;
4+
import root.core.domain.enums.ServerOS;
45

56
@Data
67
public class JschConnectionInfo {
78
private String serverName;
9+
private ServerOS serverOS;
810
private String host;
911
private int port;
1012
private String userName;
@@ -15,29 +17,37 @@ public JschConnectionInfo() {
1517
this.alc = new AlertLogCommand();
1618
}
1719

18-
public JschConnectionInfo(String serverName, String host, int port, String userName, String password) {
20+
public JschConnectionInfo(String serverName, ServerOS serverOS, String host, int port, String userName,
21+
String password) {
1922
this.serverName = serverName;
23+
this.serverOS = serverOS;
2024
this.host = host;
2125
this.port = port;
2226
this.userName = userName;
2327
this.password = password;
2428
this.alc = new AlertLogCommand();
2529
}
2630

27-
public JschConnectionInfo(String serverName, String host, String port, String userName, String password) {
28-
this(serverName, host, 22, userName, password);
31+
public JschConnectionInfo(String serverName, ServerOS serverOS, String host, String port, String userName,
32+
String password) {
33+
this(serverName, serverOS, host, 22, userName, password);
2934
this.setPort(port);
3035
}
3136

32-
public JschConnectionInfo(String serverName, String host, int port, String userName, String password,
33-
AlertLogCommand alc) {
34-
this(serverName, host, port, userName, password);
37+
public JschConnectionInfo(String serverName, ServerOS serverOS, String host, int port, String userName,
38+
String password, AlertLogCommand alc) {
39+
this(serverName, serverOS, host, port, userName, password);
3540
this.alc = alc;
3641
}
3742

38-
public JschConnectionInfo(String serverName, String host, String port, String userName, String password,
39-
AlertLogCommand alc) {
40-
this(serverName, host, 22, userName, password, alc);
43+
public JschConnectionInfo(String serverName, ServerOS serverOS, String host, String port, String userName,
44+
String password, AlertLogCommand alc) {
45+
this(serverName, serverOS, host, 22, userName, password, alc);
46+
this.setPort(port);
47+
}
48+
49+
public JschConnectionInfo(String host, String port, String userName, String password) {
50+
this("", null, host, 22, userName, password);
4151
this.setPort(port);
4252
}
4353

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package root.core.domain.enums;
2+
3+
public enum ServerOS {
4+
WINDOW, LINUX
5+
}

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import root.core.domain.AlertLogCommand;
3434
import root.core.domain.JdbcConnectionInfo;
3535
import root.core.domain.JschConnectionInfo;
36+
import root.core.domain.enums.ServerOS;
3637
import root.core.repository.constracts.PropertyRepository;
3738

3839
@Slf4j
@@ -173,8 +174,8 @@ public void saveDBConnectionInfo(String filePath, Map<String, JdbcConnectionInfo
173174

174175
log.info("[" + filePath + "] 파일 저장이 성공적으로 완료되었습니다.");
175176
} catch (Exception e) {
176-
e.printStackTrace();
177177
log.error("[" + filePath + "] 파일 저장에 실패했습니다.");
178+
log.error(e.getMessage());
178179
}
179180
}
180181

@@ -188,7 +189,8 @@ public void saveServerConnectionInfo(String filePath, Map<String, JschConnection
188189
serverNames += serverName + ",";
189190

190191
JschConnectionInfo jsch = serverConfig.get(serverName);
191-
config.setProperty(serverName + ".server.servername", jsch.getServerName());
192+
config.setProperty(serverName + ".server.name", jsch.getServerName());
193+
config.setProperty(serverName + ".server.os", jsch.getServerOS().name());
192194
config.setProperty(serverName + ".server.host", jsch.getHost());
193195
config.setProperty(serverName + ".server.port", jsch.getPort());
194196
config.setProperty(serverName + ".server.username", jsch.getUserName());
@@ -206,9 +208,8 @@ public void saveServerConnectionInfo(String filePath, Map<String, JschConnection
206208
config.setProperty(serverName + ".server.alertlog.dateformat", dateFormat);
207209
config.setProperty(serverName + ".server.alertlog.dateformatregex", dateFormatRegex);
208210
config.setProperty(serverName + ".server.alertlog.filepath", jsch.getAlc().getReadFilePath());
209-
config.setProperty(serverName + ".server.alertlog.readLine", 500);
211+
config.setProperty(serverName + ".server.alertlog.readline", 500);
210212
}
211-
212213
config.setProperty("servernames", serverNames.substring(0, serverNames.length() - 1));
213214

214215
PropertiesConfigurationLayout layout = config.getLayout();
@@ -244,8 +245,8 @@ public void saveServerConnectionInfo(String filePath, Map<String, JschConnection
244245

245246
log.info("[" + filePath + "] 파일 저장이 성공적으로 완료되었습니다.");
246247
} catch (Exception e) {
247-
e.printStackTrace();
248248
log.error("[" + filePath + "] 파일 저장에 실패했습니다.");
249+
log.error(e.getMessage());
249250
}
250251
}
251252

@@ -529,11 +530,16 @@ public JdbcConnectionInfo getJdbcConnectionInfo(String dbName) {
529530
@Override
530531
public JschConnectionInfo getJschConnectionInfo(String serverName) {
531532
String serverHost = connInfoConfig.getString(serverName + ".server.host");
533+
ServerOS serverOS = null;
534+
try {
535+
serverOS = ServerOS.valueOf(connInfoConfig.getString(serverName + ".server.os"));
536+
} catch (Exception e) {
537+
}
532538
String serverPort = connInfoConfig.getString(serverName + ".server.port");
533539
String serverUserName = connInfoConfig.getString(serverName + ".server.username");
534540
String serverPassword = connInfoConfig.getString(serverName + ".server.password");
535541
AlertLogCommand alc = getAlertLogCommand(serverName);
536-
return new JschConnectionInfo(serverName.toUpperCase(), serverHost, serverPort, serverUserName, serverPassword,
542+
return new JschConnectionInfo(serverName, serverOS, serverHost, serverPort, serverUserName, serverPassword,
537543
alc);
538544
}
539545

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import javafx.stage.FileChooser.ExtensionFilter;
3030
import javafx.stage.Stage;
3131
import javafx.util.StringConverter;
32+
import lombok.extern.slf4j.Slf4j;
3233
import root.core.domain.JdbcConnectionInfo;
3334
import root.core.domain.JschConnectionInfo;
3435
import root.core.domain.MonitoringYN;
@@ -47,6 +48,7 @@
4748
import root.utils.AlertUtils;
4849
import root.utils.UnitUtils.FileSize;
4950

51+
@Slf4j
5052
public class SettingMenuController implements Initializable {
5153

5254
/* Dependency Injection */
@@ -90,12 +92,15 @@ public void initialize(URL location, ResourceBundle resources) {
9092

9193
// remember.properties 파일에서, 최근 사용된 설정파일 경로가 있다면 해당 설정파일을 불러온다.
9294
String lastUsePropertiesFile = propService.getLastUseConnectionInfoFilePath();
95+
log.debug("Last use properties file: " + lastUsePropertiesFile);
9396
if (lastUsePropertiesFile != null) {
9497
loadSelectedConfigFile(lastUsePropertiesFile);
9598

9699
// [설정] - [모니터링 여부 설정] - Preset 변경 Event
97100
monitoringPresetComboBox.valueProperty().addListener((options, oldValue, newValue) -> {
98-
loadMonitoringConfigFile(propService.getMonitoringPresetFilePath(newValue));
101+
if(newValue != null) {
102+
loadMonitoringConfigFile(propService.getMonitoringPresetFilePath(newValue));
103+
}
99104
});
100105
} else {
101106
setVisible(noConnInfoConfigAP, true);
@@ -246,6 +251,7 @@ private void loadSelectedConfigFile(String absoluteFilePath) {
246251
* @param filePath
247252
*/
248253
private void loadMonitoringConfigFile(String filePath) {
254+
log.debug("Load monitoring config file: " + filePath);
249255
monitoringElementsVBox.getChildren().clear();
250256

251257
String presetConfigFileName = monitoringPresetComboBox.getSelectionModel().getSelectedItem();

src/main/java/root/javafx/CustomView/ServerConnInfoControl.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import javafx.scene.control.Alert.AlertType;
88
import javafx.scene.control.PasswordField;
99
import javafx.scene.control.TextField;
10+
import lombok.extern.slf4j.Slf4j;
1011
import root.core.domain.JschConnectionInfo;
1112
import root.core.repository.constracts.PropertyRepository;
1213
import root.core.repository.implement.PropertyRepositoryImpl;
@@ -15,6 +16,7 @@
1516
import root.javafx.Service.ServerConnectService;
1617
import root.utils.AlertUtils;
1718

19+
@Slf4j
1820
public class ServerConnInfoControl implements ConnInfoControl<JschConnectionInfo> {
1921

2022
/* Dependency Injection */
@@ -31,7 +33,8 @@ public boolean save(String configFilePath, Collection<StatefulAP> statefulAP) {
3133
return false;
3234
}
3335
JschConnectionInfo jsch = serverConnAP.getInputValues();
34-
config.put(jsch.getServerName().toUpperCase(), jsch);
36+
config.put(jsch.getServerName(), jsch);
37+
log.debug(jsch.toString());
3538
}
3639

3740
propertyRepository.saveServerConnectionInfo(configFilePath, config);
@@ -51,7 +54,7 @@ public ConnectionTestService getConnectionTestService(ConnectionInfoAP curAP) {
5154
String id = ((TextField) curAP.lookup("#userTF")).getText();
5255
String pw = ((PasswordField) curAP.lookup("#passwordPF")).getText();
5356

54-
return new ServerConnectService(new JschConnectionInfo("", host, port, id, pw));
57+
return new ServerConnectService(new JschConnectionInfo(host, port, id, pw));
5558
}
5659

5760
@Override

src/main/java/root/javafx/CustomView/ServerConnectionInfoAnchorPane.java

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@
1212
import javafx.scene.control.TextField;
1313
import lombok.Data;
1414
import lombok.EqualsAndHashCode;
15+
import lombok.extern.slf4j.Slf4j;
1516
import root.core.domain.AlertLogCommand;
1617
import root.core.domain.JschConnectionInfo;
18+
import root.core.domain.enums.ServerOS;
1719
import root.core.repository.constracts.PropertyRepository;
1820
import root.core.repository.implement.PropertyRepositoryImpl;
1921
import root.javafx.DI.DependencyInjection;
2022

2123
@EqualsAndHashCode(callSuper = false)
2224
@Data
25+
@Slf4j
2326
public class ServerConnectionInfoAnchorPane extends ConnectionInfoAP {
2427

2528
/* Dependency Injection */
@@ -28,6 +31,9 @@ public class ServerConnectionInfoAnchorPane extends ConnectionInfoAP {
2831
@FXML
2932
TextField serverNameTF;
3033

34+
@FXML
35+
JFXComboBox<ServerOS> serverOSCB;
36+
3137
@FXML
3238
TextField hostTF;
3339

@@ -62,18 +68,22 @@ public ServerConnectionInfoAnchorPane() {
6268
boolean isAnyEmptyInputForConnectionTest() {
6369
return StringUtils.isAnyEmpty(hostTF.getText(), portTF.getText(), userTF.getText(), passwordPF.getText());
6470
}
65-
71+
6672
public void init() {
6773
// Set textFormatter
6874
portTF.setTextFormatter(new NumberTextFormatter());
69-
75+
7076
// Set AlertLogDateFormat ComboBox values
7177
alertLogDateFormatCB.getItems()
72-
.addAll(propertyRepository.getCommonResources("server.setting.dateformat.combo"));
78+
.addAll(propertyRepository.getCommonResources("server.setting.dateformat.combo"));
79+
80+
// Set ServerOS ComboBox values
81+
serverOSCB.getItems().addAll(ServerOS.values());
7382
}
7483

7584
public void setInitialValue(JschConnectionInfo jsch) {
7685
serverNameTF.setText(jsch.getServerName());
86+
serverOSCB.getSelectionModel().select(jsch.getServerOS());
7787
hostTF.setText(jsch.getHost());
7888
portTF.setText(String.valueOf(jsch.getPort()));
7989
userTF.setText(jsch.getUserName());
@@ -84,21 +94,28 @@ public void setInitialValue(JschConnectionInfo jsch) {
8494

8595
public JschConnectionInfo getInputValues() {
8696
JschConnectionInfo jsch = new JschConnectionInfo();
87-
jsch.setServerName(this.serverNameTF.getText());
88-
jsch.setHost(this.hostTF.getText());
89-
jsch.setPort(this.portTF.getText());
90-
jsch.setUserName(this.userTF.getText());
91-
jsch.setPassword(this.passwordPF.getText());
97+
jsch.setServerName(serverNameTF.getText());
98+
jsch.setServerOS(serverOSCB.getSelectionModel().getSelectedItem());
99+
jsch.setHost(hostTF.getText());
100+
jsch.setPort(portTF.getText());
101+
jsch.setUserName(userTF.getText());
102+
jsch.setPassword(passwordPF.getText());
92103
AlertLogCommand alc = new AlertLogCommand();
93-
alc.setReadFilePath(this.alertLogFilePathTF.getText());
94-
alc.setDateFormat(this.alertLogDateFormatCB.getSelectionModel().getSelectedItem());
104+
alc.setReadFilePath(alertLogFilePathTF.getText());
105+
alc.setDateFormat(alertLogDateFormatCB.getSelectionModel().getSelectedItem());
95106
jsch.setAlc(alc);
96107
return jsch;
97108
}
98109

99110
public boolean isAnyEmptyInput() {
100-
return StringUtils.isAnyEmpty(hostTF.getText(), portTF.getText(), userTF.getText(), serverNameTF.getText(),
101-
passwordPF.getText(), alertLogFilePathTF.getText(),
102-
alertLogDateFormatCB.getSelectionModel().getSelectedItem());
111+
ServerOS serverOS = serverOSCB.getSelectionModel().getSelectedItem();
112+
if(serverOS == null) {
113+
log.info("ServerOS input is not valid");
114+
return true;
115+
}
116+
117+
return StringUtils.isAnyEmpty(serverOS.name(), hostTF.getText(),
118+
portTF.getText(), userTF.getText(), serverNameTF.getText(), passwordPF.getText(),
119+
alertLogFilePathTF.getText(), alertLogDateFormatCB.getSelectionModel().getSelectedItem());
103120
}
104121
}

src/main/resources/fxml/ServerConnectionInfoAnchorPane.fxml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
<?import javafx.scene.layout.GridPane?>
1111
<?import javafx.scene.layout.RowConstraints?>
1212

13-
1413
<fx:root style="-fx-background-color: white;" stylesheets="@../css/javaFx.css" type="AnchorPane" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1">
1514
<children>
1615
<GridPane AnchorPane.bottomAnchor="5.0" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="5.0">
@@ -50,6 +49,12 @@
5049
<PasswordField fx:id="passwordPF" prefWidth="200.0" promptText="hidden" GridPane.columnIndex="1" GridPane.columnSpan="2" GridPane.rowIndex="2" />
5150
<Label style="-fx-font-size: 11px;" styleClass="basic-font" stylesheets="@../css/javaFx.css" text="AlertLog DateFormat :" GridPane.rowIndex="4" />
5251
<JFXComboBox fx:id="alertLogDateFormatCB" prefWidth="424.0" GridPane.columnIndex="1" GridPane.rowIndex="4" />
52+
<Label style="-fx-font-size: 11px;" styleClass="basic-font" stylesheets="@../css/javaFx.css" text="Server OS" GridPane.columnIndex="2" GridPane.rowIndex="2">
53+
<padding>
54+
<Insets left="10.0" />
55+
</padding>
56+
</Label>
57+
<JFXComboBox fx:id="serverOSCB" prefWidth="100.0" GridPane.columnIndex="3" GridPane.rowIndex="2" />
5358
</children>
5459
<padding>
5560
<Insets bottom="5.0" left="10.0" right="10.0" top="5.0" />

src/test/java/root/common/server/implement/JschServerTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.jcraft.jsch.Session;
2121

2222
import root.core.domain.JschConnectionInfo;
23+
import root.core.domain.enums.ServerOS;
2324

2425
public class JschServerTest {
2526

@@ -28,11 +29,12 @@ public class JschServerTest {
2829
@BeforeAll
2930
public static void setup() {
3031
String serverName = "DKY SERVER";
32+
ServerOS serverOS = ServerOS.WINDOW;
3133
String host = "192.168.154.1";
3234
String userName = "dky";
3335
String port = "22";
3436
String password = "ehruddbs1!";
35-
jsch = new JschServer(new JschConnectionInfo(serverName, host, port, userName, password));
37+
jsch = new JschServer(new JschConnectionInfo(serverName, serverOS, host, port, userName, password));
3638
}
3739

3840
@Test
@@ -128,23 +130,23 @@ public void testGetServerName() {
128130
String serverName = jsch.getServerName();
129131
assertEquals(serverName, "DKY SERVER");
130132
}
131-
133+
132134
@Test
133135
public void testExecuteCommand_EchoCommand() throws Exception {
134136
jsch.init();
135137
Session session = jsch.getSession();
136138
String result = jsch.executeCommand(session, "echo 1");
137139
assertEquals("1", result.trim());
138140
}
139-
141+
140142
@Test
141143
public void testExecuteCommand_TailCommand() throws Exception {
142144
jsch.init();
143145
Session session = jsch.getSession();
144146
String result = jsch.executeCommand(session, "tail -500 C://Users/aserv/Desktop/alert_DB.log");
145147
assertNotEquals(result, "");
146148
}
147-
149+
148150
@Test
149151
public void testValidateConn_Valid() throws Exception {
150152
jsch.init();

0 commit comments

Comments
 (0)