Skip to content

Commit

Permalink
Added check of config to be valid on start
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBlagov committed Oct 1, 2018
1 parent 7d59d35 commit e7bd365
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,15 @@ public String pass(@NotNull String request) throws IOException {
private List<Control> controlsDisabledOnDisconnected;
private List<Control> controlsDisabledOnConnected;
private List<Control> controlsDisabledOnMetadataNotExists;
private List<Control> controlsDisabledOnConfigInvalid;

@Override
public void initialize(URL location, ResourceBundle resources) {
initHostnamesComboBox();
controlsDisabledOnConnected = Arrays.asList(hostnamesComboBox, rpcPortTextField, connectButton);
controlsDisabledOnDisconnected = Arrays.asList(disconnectButton, startTRexButton, stopTRexButton);
controlsDisabledOnMetadataNotExists = Arrays.asList(configEditTitledPane, loadDefaultConfigButton);
controlsDisabledOnConfigInvalid = Arrays.asList(startTRexButton);
configEditTitledPane.expandedProperty().bind(configEditTitledPane.disableProperty().not());
this.configFilename = System.getProperty("user.name");
refreshControlsAvailability();
Expand Down Expand Up @@ -199,6 +201,12 @@ private void refreshControlsAvailability() {
for (Control control: controlsDisabledOnMetadataNotExists) {
control.setDisable(this.metadata == null);
}

for (Control control: controlsDisabledOnConfigInvalid) {
if (userConfigModel != null && !userConfigModel.isValid()) {
control.setDisable(true);
}
}
}

private boolean isConnected() {
Expand Down Expand Up @@ -327,8 +335,8 @@ private void startTRex() {
.param("trex_cmd_options", cmdParams)
.param("user", System.getProperty("user.name"))
.param("stateless", true)
.param("block_to_success", false)
.returnAs(Integer.class)
.param("timeout", 15)
.execute();
log(LogType.INFO, "TRex started successfully");
} catch (RuntimeException ex) {
Expand Down Expand Up @@ -369,6 +377,7 @@ private void initConfigTree() {
private void updateYAML() {
try {
yamlPreviewTextfield.setText(userConfigModel.getYAMLString());
refreshControlsAvailability();
} catch (JsonProcessingException e) {
log(LogType.ERROR, MessageFormat.format("Unable to get YAML conents: {0}", e));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public String getYAMLString() throws JsonProcessingException {
return "### errors in config:\n# "+ errors.stream().collect(Collectors.joining("\n# "));
}

public boolean isValid() {
return getErrors().isEmpty();
}

private List<String> getErrors() {
List<String> errors = new ArrayList<>();
for (ConfigNode node : valuedata) {
Expand Down

0 comments on commit e7bd365

Please sign in to comment.