Commit b811f9ea authored by zeroleak's avatar zeroleak
Browse files

fix #19 Startup failure for `cli.mix.clients` option

parent 89175cb1
......@@ -208,7 +208,7 @@ public abstract class CliConfigFile {
}
public static class MixConfig {
@NotEmpty private int clients;
/*@NotEmpty TODO constraint temporary disabled*/ private int clients;
@NotEmpty private int clientsPerPool;
@NotEmpty private int clientDelay;
@NotEmpty private int tx0Delay;
......@@ -234,8 +234,9 @@ public abstract class CliConfigFile {
return clients;
}
public void setClients(int clients) {
this.clients = clients;
// public void setClients(int clients) { // TODO constraint temporary disabled
public void setClients(Integer clients) {
this.clients = clients != null ? clients : 0;
}
public int getClientsPerPool() {
......
......@@ -3,15 +3,13 @@ package com.samourai.whirlpool.cli.run;
import com.samourai.whirlpool.cli.config.CliConfig;
import com.samourai.whirlpool.cli.services.CliConfigService;
import java.lang.invoke.MethodHandles;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RunUpgradeCli {
private Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private static final int CLI_V1 = 1;
private static final int CLI_V3 = 3;
private CliConfig cliConfig;
private CliConfigService cliConfigService;
......@@ -20,19 +18,21 @@ public class RunUpgradeCli {
this.cliConfigService = cliConfigService;
}
public void run(int lastVersion) throws Exception {
public void run(int localVersion) throws Exception {
// run upgrades
if (lastVersion < CLI_V3) {
upgradeV3();
if (localVersion < CliConfigService.CLI_VERSION_4) {
upgradeV4();
}
}
public void upgradeV3() throws Exception {
log.info(" - Upgrading to: V3");
public void upgradeV4() throws Exception {
log.info(" - Upgrading to: V4");
// unset mix.clients=
// Properties props = cliConfigService.loadProperties();
// props.put(CliConfigService.KEY_MIX_CLIENTS, "");
// cliConfigService.saveProperties(props);
// set cli.mix.clients=5 when missing
if (cliConfig.getMix().getClients() == 0) {
Properties props = cliConfigService.loadProperties();
props.put(CliConfigService.KEY_MIX_CLIENTS, "5");
cliConfigService.saveProperties(props);
}
}
}
......@@ -33,7 +33,9 @@ import org.springframework.util.DefaultPropertiesPersister;
public class CliConfigService {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
public static final int CLI_VERSION = 3;
public static final int CLI_VERSION_4 = 4;
public static final int CLI_VERSION = CLI_VERSION_4;
public static final String CLI_CONFIG_FILENAME = "whirlpool-cli-config.properties";
private static final String KEY_APIKEY = "cli.apiKey";
private static final String KEY_SEED = "cli.seed";
......@@ -42,6 +44,7 @@ public class CliConfigService {
private static final String KEY_DOJO_APIKEY = "cli.dojo.apiKey";
public static final String KEY_DOJO_ENABLED = "cli.dojo.enabled";
private static final String KEY_VERSION = "cli.version";
public static final String KEY_MIX_CLIENTS = "cli.mix.clients";
private CliConfig cliConfig;
private CliStatus cliStatus;
......@@ -269,14 +272,14 @@ public class CliConfigService {
public boolean checkUpgrade() throws Exception {
boolean shouldRestart = false;
int lastVersion = cliConfig.getVersion();
int localVersion = cliConfig.getVersion();
if (lastVersion < CLI_VERSION) {
if (localVersion < CLI_VERSION) {
// older version => run upgrade
if (log.isDebugEnabled()) {
log.debug(" • Upgrading cli wallet: " + lastVersion + " -> " + CLI_VERSION);
log.debug(" • Upgrading cli wallet: " + localVersion + " -> " + CLI_VERSION);
}
new RunUpgradeCli(cliConfig, this).run(lastVersion);
new RunUpgradeCli(cliConfig, this).run(localVersion);
// set version
setVersionCurrent();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment