use of exec.NodeExecManager in project tessera by ConsenSys.
the class ThirdPartyIT method partyInfoKeys.
@Test
public void partyInfoKeys() {
Response partyinfoResponse = client.target(thirdPartyServerConfig.getServerUri()).path("partyinfo").path("keys").request().get();
JsonObject partyinfokeysJson = partyinfoResponse.readEntity(JsonObject.class);
assertThat(partyinfoResponse).isNotNull();
assertThat(partyinfoResponse.getStatus()).isEqualTo(200);
List<JsonObject> keys = Stream.of(firstNodeExecManager, secondNodeExecManager).map(NodeExecManager::getConfigDescriptor).map(ConfigDescriptor::getKey).map(ConfigKeyPair::getPublicKey).map(k -> Json.createObjectBuilder().add("key", k).build()).collect(Collectors.toUnmodifiableList());
assertThat(partyinfokeysJson.getJsonArray("keys")).describedAs("partyInfo response that caused failure %s", partyinfokeysJson.toString()).containsAnyElementsOf(keys);
}
use of exec.NodeExecManager in project tessera by ConsenSys.
the class TestSuite method run.
@Override
public void run(RunNotifier notifier) {
final List<ExecManager> executors = new ArrayList<>();
try {
final ProcessConfig annotatedConfig = Arrays.stream(getRunnerAnnotations()).filter(ProcessConfig.class::isInstance).map(ProcessConfig.class::cast).findAny().orElseThrow(() -> new AssertionError("No Test config found"));
ExecutionContext executionContext = ExecutionContext.Builder.create().with(annotatedConfig.communicationType()).with(annotatedConfig.dbType()).with(annotatedConfig.socketType()).with(annotatedConfig.enclaveType()).withAdmin(annotatedConfig.admin()).with(annotatedConfig.encryptorType()).with(annotatedConfig.clientMode()).prefix(annotatedConfig.prefix()).createAndSetupContext();
if (executionContext.getEnclaveType() == EnclaveType.REMOTE) {
executionContext.getConfigs().stream().map(EnclaveExecManager::new).forEach(exec -> {
exec.start();
executors.add(exec);
});
}
String nodeId = NodeId.generate(executionContext);
DatabaseServer databaseServer = executionContext.getDbType().createDatabaseServer(nodeId);
databaseServer.start();
SetupDatabase setupDatabase = new SetupDatabase(executionContext);
setupDatabase.setUp();
executionContext.getConfigs().stream().map(NodeExecManager::new).forEach(exec -> {
exec.start();
executors.add(exec);
});
PartyInfoChecker partyInfoChecker = PartyInfoChecker.create(executionContext.getCommunicationType());
CountDownLatch partyInfoSyncLatch = new CountDownLatch(1);
ExecutorService executorService = Executors.newSingleThreadExecutor();
executorService.submit(() -> {
while (!partyInfoChecker.hasSynced()) {
try {
Thread.sleep(1000L);
} catch (InterruptedException ex) {
}
}
partyInfoSyncLatch.countDown();
});
if (!partyInfoSyncLatch.await(10, TimeUnit.MINUTES)) {
Description de = getDescription();
notifier.fireTestFailure(new Failure(de, new IllegalStateException("Unable to sync party info nodes")));
}
executorService.shutdown();
super.run(notifier);
try {
ExecutionContext.destroyContext();
setupDatabase.dropAll();
} finally {
databaseServer.stop();
}
} catch (Throwable ex) {
Description de = getDescription();
notifier.fireTestFailure(new Failure(de, ex));
} finally {
executors.forEach(ExecManager::stop);
}
}
use of exec.NodeExecManager in project tessera by ConsenSys.
the class SendWithRemoteEnclaveReconnectIT method beforeTest.
@Before
public void beforeTest() throws IOException {
EncryptorConfig encryptorConfig = new EncryptorConfig() {
{
setType(EncryptorType.NACL);
}
};
ExecutionContext.Builder.create().with(CommunicationType.REST).with(DBType.H2).with(SocketType.HTTP).with(EnclaveType.REMOTE).with(encryptorConfig.getType()).with(ClientMode.TESSERA).buildAndStoreContext();
final PortUtil portGenerator = new PortUtil(50100);
final String serverUriTemplate = "http://localhost:%d";
KeyEncryptorFactory.newFactory().create(encryptorConfig);
final Config nodeConfig = new Config();
nodeConfig.setEncryptor(encryptorConfig);
JdbcConfig jdbcConfig = new JdbcConfig();
jdbcConfig.setUrl("jdbc:h2:mem:junit");
jdbcConfig.setUsername("sa");
jdbcConfig.setPassword("");
jdbcConfig.setAutoCreateTables(true);
nodeConfig.setJdbcConfig(jdbcConfig);
ServerConfig p2pServerConfig = new ServerConfig();
p2pServerConfig.setApp(AppType.P2P);
p2pServerConfig.setServerAddress(String.format(serverUriTemplate, portGenerator.nextPort()));
p2pServerConfig.setCommunicationType(CommunicationType.REST);
final ServerConfig q2tServerConfig = new ServerConfig();
q2tServerConfig.setApp(AppType.Q2T);
q2tServerConfig.setServerAddress(String.format(serverUriTemplate, portGenerator.nextPort()));
q2tServerConfig.setCommunicationType(CommunicationType.REST);
final Config enclaveConfig = new Config();
enclaveConfig.setEncryptor(nodeConfig.getEncryptor());
final ServerConfig enclaveServerConfig = new ServerConfig();
enclaveServerConfig.setApp(AppType.ENCLAVE);
enclaveServerConfig.setServerAddress(String.format(serverUriTemplate, portGenerator.nextPort()));
enclaveServerConfig.setCommunicationType(CommunicationType.REST);
nodeConfig.setServerConfigs(Arrays.asList(p2pServerConfig, q2tServerConfig, enclaveServerConfig));
KeyData keyPair = new KeyData();
keyPair.setPublicKey("/+UuD63zItL1EbjxkKUljMgG8Z1w0AJ8pNOR4iq2yQc=");
keyPair.setPrivateKey("yAWAJjwPqUtNVlqGjSrBmr1/iIkghuOh1803Yzx9jLM=");
enclaveConfig.setKeys(new KeyConfiguration());
enclaveConfig.getKeys().setKeyData(Arrays.asList(keyPair));
nodeConfig.setPeers(Arrays.asList(new Peer(p2pServerConfig.getServerAddress())));
enclaveConfig.setServerConfigs(Arrays.asList(enclaveServerConfig));
Path configPath = Files.createFile(Paths.get(UUID.randomUUID().toString()));
configPath.toFile().deleteOnExit();
Path enclaveConfigPath = Files.createFile(Paths.get(UUID.randomUUID().toString()));
enclaveConfigPath.toFile().deleteOnExit();
try (OutputStream out = Files.newOutputStream(configPath)) {
JaxbUtil.marshalWithNoValidation(nodeConfig, out);
out.flush();
}
JaxbUtil.marshalWithNoValidation(enclaveConfig, System.out);
try (OutputStream out = Files.newOutputStream(enclaveConfigPath)) {
JaxbUtil.marshalWithNoValidation(enclaveConfig, out);
out.flush();
}
ConfigDescriptor configDescriptor = new ConfigDescriptor(NodeAlias.A, configPath, nodeConfig, enclaveConfig, enclaveConfigPath);
String key = configDescriptor.getKey().getPublicKey();
URL file = Utils.toUrl(configDescriptor.getPath());
String alias = configDescriptor.getAlias().name();
this.party = new Party(key, file, alias);
nodeExecManager = new NodeExecManager(configDescriptor);
enclaveExecManager = new EnclaveExecManager(configDescriptor);
enclaveExecManager.start();
nodeExecManager.start();
client = party.getRestClient();
}
use of exec.NodeExecManager in project tessera by ConsenSys.
the class ThirdPartyIT method init.
@BeforeClass
public static void init() throws Exception {
ExecutionContext.Builder.create().with(CommunicationType.REST).with(DBType.H2).with(SocketType.HTTP).with(EncryptorType.NACL).with(EnclaveType.LOCAL).with(ClientMode.TESSERA).prefix(ThirdPartyIT.class.getSimpleName().toLowerCase()).buildAndStoreContext();
Config firstNodeDesc = createNode(NodeAlias.A);
Config secondNodeDesc = createNode(NodeAlias.B);
firstNodeDesc.setPeers(List.of(new Peer(secondNodeDesc.getP2PServerConfig().getServerAddress())));
secondNodeDesc.setPeers(List.of(new Peer(firstNodeDesc.getP2PServerConfig().getServerAddress())));
firstNodeExecManager = new NodeExecManager(createConfigDescriptor(NodeAlias.A, firstNodeDesc));
secondNodeExecManager = new NodeExecManager(createConfigDescriptor(NodeAlias.B, secondNodeDesc));
firstNodeExecManager.start();
secondNodeExecManager.start();
}
Aggregations