Search in sources :

Example 1 with TesseraServer

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());
}
Also used : TesseraApp(com.quorum.tessera.config.apps.TesseraApp) CommunicationType(com.quorum.tessera.config.CommunicationType) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Application(jakarta.ws.rs.core.Application) Set(java.util.Set) TesseraServer(com.quorum.tessera.server.TesseraServer) ServerConfig(com.quorum.tessera.config.ServerConfig) Collectors(java.util.stream.Collectors) TesseraServerFactory(com.quorum.tessera.server.TesseraServerFactory) TesseraApp(com.quorum.tessera.config.apps.TesseraApp) Application(jakarta.ws.rs.core.Application)

Example 2 with TesseraServer

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));
}
Also used : Path(java.nio.file.Path) TesseraServer(com.quorum.tessera.server.TesseraServer) Test(org.junit.Test)

Example 3 with TesseraServer

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();
}
Also used : ConfigConverter(com.quorum.tessera.cli.parsers.ConfigConverter) TesseraServerFactory(com.quorum.tessera.server.TesseraServerFactory) ServerConfig(com.quorum.tessera.config.ServerConfig) Config(com.quorum.tessera.config.Config) CountDownLatch(java.util.concurrent.CountDownLatch) ServerConfig(com.quorum.tessera.config.ServerConfig) TesseraServer(com.quorum.tessera.server.TesseraServer) CommandLine(picocli.CommandLine) CliResult(com.quorum.tessera.cli.CliResult) EnclaveCliAdapter(com.quorum.tessera.enclave.server.EnclaveCliAdapter) Enclave(com.quorum.tessera.enclave.Enclave) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Example 4 with TesseraServer

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);
    }
}
Also used : List(java.util.List) Logger(org.slf4j.Logger) Charset(java.nio.charset.Charset) Files(java.nio.file.Files) LoggerFactory(org.slf4j.LoggerFactory) TesseraServer(com.quorum.tessera.server.TesseraServer) LinkedList(java.util.LinkedList) Path(java.nio.file.Path) Collectors(java.util.stream.Collectors) File(java.io.File) TesseraServer(com.quorum.tessera.server.TesseraServer) File(java.io.File) LinkedList(java.util.LinkedList)

Example 5 with TesseraServer

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);
}
Also used : Path(java.nio.file.Path) TesseraServer(com.quorum.tessera.server.TesseraServer) Test(org.junit.Test)

Aggregations

TesseraServer (com.quorum.tessera.server.TesseraServer)6 Path (java.nio.file.Path)3 CliResult (com.quorum.tessera.cli.CliResult)2 Config (com.quorum.tessera.config.Config)2 ServerConfig (com.quorum.tessera.config.ServerConfig)2 Enclave (com.quorum.tessera.enclave.Enclave)2 TesseraServerFactory (com.quorum.tessera.server.TesseraServerFactory)2 Collectors (java.util.stream.Collectors)2 BouncyCastleProvider (org.bouncycastle.jce.provider.BouncyCastleProvider)2 Test (org.junit.Test)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 CliException (com.quorum.tessera.cli.CliException)1 ConfigConverter (com.quorum.tessera.cli.parsers.ConfigConverter)1 CommunicationType (com.quorum.tessera.config.CommunicationType)1 ConfigException (com.quorum.tessera.config.ConfigException)1 TesseraApp (com.quorum.tessera.config.apps.TesseraApp)1 PicoCliDelegate (com.quorum.tessera.config.cli.PicoCliDelegate)1 RuntimeContext (com.quorum.tessera.context.RuntimeContext)1 Discovery (com.quorum.tessera.discovery.Discovery)1