use of suite.NodeAlias in project tessera by ConsenSys.
the class ConfigGenerator method generateConfigs.
public List<ConfigDescriptor> generateConfigs(ExecutionContext executionContext) {
Objects.requireNonNull(executionContext, "Execution context is required");
Path path = calculatePath(executionContext);
try {
Files.createDirectories(path);
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
List<Config> configs = createConfigs(executionContext);
List<Config> enclaveConfigs;
if (executionContext.getEnclaveType() == EnclaveType.REMOTE) {
enclaveConfigs = configs.stream().map(this::createEnclaveConfig).collect(Collectors.toList());
configs.forEach(c -> c.setKeys(null));
} else {
enclaveConfigs = Collections.emptyList();
}
// Remove keys
List<ConfigDescriptor> configList = new ArrayList<>();
for (NodeAlias alias : NodeAlias.values()) {
int i = alias.ordinal();
final Config config = configs.get(i);
final String filename = String.format("config%d.json", (i + 1));
final Path ouputFile = path.resolve(filename);
try (OutputStream out = Files.newOutputStream(ouputFile)) {
JaxbUtil.marshalWithNoValidation(config, out);
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
final Config enclaveConfig;
final Path enclaveOuputFile;
if (!enclaveConfigs.isEmpty()) {
enclaveConfig = enclaveConfigs.get(i);
String enclaveFilename = String.format("enclave%d.json", (i + 1));
enclaveOuputFile = path.resolve(enclaveFilename);
try (OutputStream enclaveout = Files.newOutputStream(enclaveOuputFile)) {
JaxbUtil.marshalWithNoValidation(enclaveConfig, enclaveout);
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
} else {
enclaveConfig = null;
enclaveOuputFile = null;
}
configList.add(new ConfigDescriptor(alias, ouputFile, config, enclaveConfig, enclaveOuputFile));
}
return configList;
}
Aggregations