use of com.quorum.tessera.server.TesseraServer in project tessera by ConsenSys.
the class JerseyServerFactory method createServer.
@Override
public TesseraServer createServer(ServerConfig serverConfig, Set<Object> services) {
LOGGER.debug("Creating JAXRS application with {} services: {}", serverConfig, services.stream().map(Object::toString).collect(Collectors.joining(",")));
Application application = services.stream().filter(TesseraApp.class::isInstance).filter(Application.class::isInstance).map(TesseraApp.class::cast).filter(a -> a.getAppType().equals(serverConfig.getApp())).map(Application.class::cast).findFirst().get();
LOGGER.debug("Created JAXRS application {}", application);
return new JerseyServer(serverConfig, application.getClass());
}
use of com.quorum.tessera.server.TesseraServer in project tessera by ConsenSys.
the class ServerURIFileWriterTest method writeAllServersToOutputPath.
@Test
public void writeAllServersToOutputPath() throws IOException {
final TesseraServer adminServer = mock(TesseraServer.class);
final TesseraServer enclaveServer = mock(TesseraServer.class);
final TesseraServer p2pServer = mock(TesseraServer.class);
final TesseraServer q2tServer = mock(TesseraServer.class);
final TesseraServer thirdPartyServer = mock(TesseraServer.class);
final String adminServerURI = "http://admin";
final String enclaveServerURI = "http://enclave";
final String p2pServerURI = "http://p2p";
final String q2tServerURI = "http://q2t";
final String thirdPartyServerURI = "http://thirdparty";
final String fileName = "tessera.uris";
when(adminServer.getAppType()).thenReturn(AppType.ADMIN);
when(adminServer.getUri()).thenReturn(URI.create(adminServerURI));
when(enclaveServer.getAppType()).thenReturn(AppType.ENCLAVE);
when(enclaveServer.getUri()).thenReturn(URI.create(enclaveServerURI));
when(p2pServer.getAppType()).thenReturn(AppType.P2P);
when(p2pServer.getUri()).thenReturn(URI.create(p2pServerURI));
when(q2tServer.getAppType()).thenReturn(AppType.Q2T);
when(q2tServer.getUri()).thenReturn(URI.create(q2tServerURI));
when(thirdPartyServer.getAppType()).thenReturn(AppType.THIRD_PARTY);
when(thirdPartyServer.getUri()).thenReturn(URI.create(thirdPartyServerURI));
final List<TesseraServer> serverList = List.of(adminServer, enclaveServer, p2pServer, q2tServer, thirdPartyServer);
final Path path = directory.toPath();
ServerURIFileWriter.writeURIFile(path, serverList);
assertThat(directory.exists()).isTrue();
assertThat(directory.isDirectory()).isTrue();
assertThat(directory.list().length).isEqualTo(1);
assertThat(getFileNames(directory.listFiles())).contains(fileName);
final List<String> fileLines = getFileLines(Path.of(directory.getPath() + "/" + fileName));
assertThat(fileLines.size()).isEqualTo(6);
assertThat(fileLines).contains(String.format("%s=%s", AppType.ADMIN, adminServerURI));
assertThat(fileLines).contains(String.format("%s=%s", AppType.ENCLAVE, enclaveServerURI));
assertThat(fileLines).contains(String.format("%s=%s", AppType.P2P, p2pServerURI));
assertThat(fileLines).contains(String.format("%s=%s", AppType.Q2T, q2tServerURI));
assertThat(fileLines).contains(String.format("%s=%s", AppType.THIRD_PARTY, thirdPartyServerURI));
}
use of com.quorum.tessera.server.TesseraServer in project tessera by ConsenSys.
the class Main method main.
public static void main(String... args) throws Exception {
Security.addProvider(new BouncyCastleProvider());
final CommandLine commandLine = new CommandLine(new EnclaveCliAdapter());
commandLine.registerConverter(Config.class, new ConfigConverter()).setSeparator(" ").setCaseInsensitiveEnumValuesAllowed(true);
commandLine.execute(args);
final CliResult cliResult = commandLine.getExecutionResult();
if (cliResult == null) {
System.exit(1);
}
if (!cliResult.getConfig().isPresent()) {
System.exit(cliResult.getStatus());
}
final TesseraServerFactory restServerFactory = TesseraServerFactory.create(CommunicationType.REST);
final Config config = cliResult.getConfig().get();
ConfigFactory.create().store(config);
final ServerConfig serverConfig = config.getServerConfigs().stream().findFirst().get();
Enclave enclave = EnclaveServer.create();
LOGGER.debug("Created enclave {}", enclave);
final TesseraServer server = restServerFactory.createServer(serverConfig, Set.of(new EnclaveApplication(enclave)));
server.start();
CountDownLatch latch = new CountDownLatch(1);
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
server.stop();
} catch (Exception ex) {
LOGGER.error(null, ex);
} finally {
}
}));
latch.await();
}
use of com.quorum.tessera.server.TesseraServer in project tessera by ConsenSys.
the class ServerURIFileWriter method writeURIFile.
public static void writeURIFile(final Path dirPath, final List<TesseraServer> servers) {
final List<TesseraServer> serverList = servers.stream().filter(tesseraServer -> tesseraServer.getAppType() != null).collect(Collectors.toList());
final String fileName = "tessera.uris";
final String fileHeader = "This file contains the URIs used by the running servers in Tessera";
final List<String> uriList = new LinkedList<>();
serverList.forEach(tesseraServer -> uriList.add(String.format("%s=%s", tesseraServer.getAppType().toString(), getUriOrEmpty(tesseraServer))));
final File file = new File(dirPath.toFile(), fileName);
file.deleteOnExit();
try {
uriList.add(0, String.format("#%s. This file will be deleted after the enclave is shutdown.", fileHeader));
Files.write(Path.of(dirPath.toAbsolutePath() + "/" + fileName), uriList, Charset.defaultCharset());
} catch (final Exception e) {
LOGGER.debug(String.format("Error writing %s file", fileName), e);
}
}
use of com.quorum.tessera.server.TesseraServer in project tessera by ConsenSys.
the class ServerURIFileWriterTest method readOnlyPathShouldNotThrowException.
@Test
public void readOnlyPathShouldNotThrowException() {
final TesseraServer p2pServer = mock(TesseraServer.class);
final String p2pServerURI = "http://p2p";
when(p2pServer.getAppType()).thenReturn(AppType.P2P);
when(p2pServer.getUri()).thenReturn(URI.create(p2pServerURI));
final List<TesseraServer> serverList = List.of(p2pServer);
directory.setReadOnly();
assertThat(directory.exists()).isTrue();
assertThat(directory.canWrite()).isFalse();
assertThat(directory.isDirectory()).isTrue();
assertThat(directory.list().length).isEqualTo(0);
final Path path = directory.toPath();
assertThatCode(() -> ServerURIFileWriter.writeURIFile(path, serverList)).doesNotThrowAnyException();
assertThat(directory.list().length).isEqualTo(0);
}
Aggregations