Skip to content

Commit

Permalink
add read from config file
Browse files Browse the repository at this point in the history
  • Loading branch information
rayz committed Nov 13, 2023
1 parent 5b0a2f1 commit c5f28ed
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions tools/misbehaving-jmx-server/misbehaving-seed-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
seed: 12345
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,19 @@ class AppConfig {
public String rmiHost = Defaults.JMXSERVER_RMI_INTERFACE;

@Parameter(names = {"--rng-seed", "-rs"})
public long rngSeed = 1042849;
public Long rngSeed = 54321L;

// Can only be set via env var
public int controlPort = Defaults.JMXSERVER_CONTROL_PORT;

@Parameter(names = {"--config-path", "-cfp"})
public String config_path = "./misbehaving-jmx-domains-config.yaml";

@Parameter(names = {"--seed-config-path", "-scfp"})
public String seed_config_path = "./misbehaving-seed-config.yaml";

public JmxDomainConfigurations jmxDomainConfigurations;
public RNGSeedConfiguration rngSeedConfiguration;

public void overrideFromEnv() {
String val;
Expand All @@ -80,7 +84,7 @@ public void overrideFromEnv() {
}
}

public void readConfigFileOnDisk () {
public void readDomainsConfigFileOnDisk () {
File f = new File(config_path);
String yamlPath = f.getPath();
try{
Expand All @@ -93,6 +97,33 @@ public void readConfigFileOnDisk () {
jmxDomainConfigurations = null;
}
}

public void readSeedConfigFileOnDisk () {
File f = new File(seed_config_path);
String yamlPath = f.getPath();
try{
FileInputStream yamlInputStream = new FileInputStream(yamlPath);
Yaml yaml = new Yaml(new Constructor(RNGSeedConfiguration.class));
rngSeedConfiguration = yaml.load(yamlInputStream);
log.info("RNGSeed configuration read from " + seed_config_path + " is:\n" + rngSeedConfiguration);
} catch (FileNotFoundException e) {
log.warn("Could not find your config file at " + yamlPath);
rngSeedConfiguration = null;
}
}
}

class RNGSeedConfiguration {
public Long seed;

@Override
public String toString() {
if (seed != null) {
return "RNG Seed: " + seed;
}
return "No seed specified in seed configuration file";
}

}

class JmxDomainConfigurations {
Expand Down Expand Up @@ -158,7 +189,8 @@ public static void main( String[] args ) throws IOException, MalformedObjectName
jCommander.usage();
System.exit(1);
}
config.readConfigFileOnDisk();
config.readDomainsConfigFileOnDisk();
config.readSeedConfigFileOnDisk();

InterruptibleRMISocketFactory customRMISocketFactory = new InterruptibleRMISocketFactory();
// I don't think this call is actually important for jmx, the below 'env' param to JMXConnectorServerFactory is the important one
Expand All @@ -175,6 +207,10 @@ public static void main( String[] args ) throws IOException, MalformedObjectName
MetricDAO mDao = new MetricDAO();
mDao.runTickLoop();

// rng seed config file overrides flag
if (config.rngSeedConfiguration != null) {
config.rngSeed = config.rngSeedConfiguration.seed;
}
BeanManager bm = new BeanManager(mbs, mDao, config.rngSeed);

// Set up test domain
Expand Down

0 comments on commit c5f28ed

Please sign in to comment.