Search in sources :

Example 1 with DEFAULT_SERVER_CONFIG

use of org.infinispan.server.Server.DEFAULT_SERVER_CONFIG in project infinispan by infinispan.

the class ContainerInfinispanServerDriver method start.

@Override
protected void start(String name, File rootDir, File configurationFile) {
    this.name = name;
    String jGroupsStack = System.getProperty(Server.INFINISPAN_CLUSTER_STACK);
    // Build a skeleton server layout
    createServerHierarchy(rootDir);
    // Build the command-line that launches the server
    List<String> args = new ArrayList<>();
    args.add("bin/server.sh");
    args.add("-c");
    args.add(configurationFile.getName());
    args.add("-b");
    args.add("SITE_LOCAL");
    args.add("-Djgroups.bind.address=SITE_LOCAL");
    if (jGroupsStack != null) {
        args.add("-j");
        args.add(jGroupsStack);
    }
    args.add("-Dinfinispan.cluster.name=" + name);
    args.add("-D" + TEST_HOST_ADDRESS + "=" + testHostAddress.getHostAddress());
    if (configuration.isJMXEnabled()) {
        args.add("-Dcom.sun.management.jmxremote.port=" + JMX_PORT);
        args.add("-Dcom.sun.management.jmxremote.authenticate=false");
        args.add("-Dcom.sun.management.jmxremote.ssl=false");
    }
    String logFile = System.getProperty(INFINISPAN_TEST_SERVER_LOG_FILE);
    if (logFile != null) {
        Path logPath = Paths.get(logFile);
        String logFileName = logPath.getFileName().toString();
        if (logPath.isAbsolute()) {
            try {
                // we need to copy the log file to the conf dir because the withFileFromPath("test"..) will overwrite
                // everything
                Files.copy(logPath, new File(getConfDir(), logFileName).toPath(), StandardCopyOption.REPLACE_EXISTING);
            } catch (IOException e) {
                throw new IllegalStateException("Cannot copy the log file", e);
            }
        }
        args.add("-l");
        args.add(logFileName);
    }
    Properties properties = new Properties();
    properties.setProperty(Server.INFINISPAN_SERVER_CONFIG_PATH, Paths.get(INFINISPAN_SERVER_HOME, DEFAULT_SERVER_CONFIG).toString());
    properties.setProperty(Server.INFINISPAN_CLUSTER_NAME, name);
    properties.setProperty(TEST_HOST_ADDRESS, testHostAddress.getHostName());
    configuration.properties().forEach((k, v) -> args.add("-D" + k + "=" + StringPropertyReplacer.replaceProperties((String) v, properties)));
    configureSite(args);
    boolean preserveImageAfterTest = Boolean.parseBoolean(configuration.properties().getProperty(TestSystemPropertyNames.INFINISPAN_TEST_SERVER_PRESERVE_IMAGE, "false"));
    Path tmp = Paths.get(CommonsTestingUtil.tmpDirectory(this.getClass()));
    File libDir = new File(rootDir, "lib");
    libDir.mkdirs();
    copyArtifactsToUserLibDir(libDir);
    image = new ImageFromDockerfile("localhost/testcontainers/" + Base58.randomString(16).toLowerCase(), !preserveImageAfterTest).withFileFromPath("test", rootDir.toPath()).withFileFromPath("tmp", tmp).withFileFromPath("lib", libDir.toPath());
    final boolean prebuiltImage;
    final String imageName;
    String baseImageName = configuration.properties().getProperty(TestSystemPropertyNames.INFINISPAN_TEST_SERVER_BASE_IMAGE_NAME);
    if (baseImageName == null) {
        String serverOutputDir = configuration.properties().getProperty(TestSystemPropertyNames.INFINISPAN_TEST_SERVER_DIR);
        if (serverOutputDir == null) {
            // We try to use the latest public image for this major.minor version
            imageName = "quay.io/infinispan/server:" + Version.getMajorMinor();
            prebuiltImage = true;
            log.infof("Using prebuilt image '%s'", imageName);
        } else {
            // We build our local image based on the supplied server
            Path serverOutputPath = Paths.get(serverOutputDir).normalize();
            imageName = JDK_BASE_IMAGE_NAME;
            image.withFileFromPath("target", serverOutputPath.getParent()).withFileFromPath("src", serverOutputPath.getParent().getParent().resolve("src")).withFileFromPath("build", cleanServerDirectory(serverOutputPath));
            prebuiltImage = false;
            log.infof("Using local image from server built at '%s'", serverOutputPath);
        }
    } else {
        imageName = baseImageName;
        prebuiltImage = true;
        log.infof("Using prebuilt image '%s'", imageName);
    }
    image.withDockerfileFromBuilder(builder -> {
        builder.from(imageName).env("INFINISPAN_SERVER_HOME", INFINISPAN_SERVER_HOME).env("INFINISPAN_VERSION", Version.getVersion()).label("name", "Infinispan Server").label("version", Version.getVersion()).label("release", Version.getVersion()).label("architecture", "x86_64");
        if (!prebuiltImage) {
            builder.copy("build", INFINISPAN_SERVER_HOME);
        }
        // Copy the resources to a location from where they can be added to the image
        try {
            URL resource = ContainerInfinispanServerDriver.class.getResource("/overlay");
            if (resource != null) {
                URI overlayUri = resource.toURI();
                if ("jar".equals(overlayUri.getScheme())) {
                    try (FileSystem fileSystem = FileSystems.newFileSystem(overlayUri, Collections.emptyMap())) {
                        Files.walkFileTree(fileSystem.getPath("/overlay"), new CommonsTestingUtil.CopyFileVisitor(tmp, true, f -> {
                            f.setExecutable(true, false);
                        }));
                    }
                } else {
                    Files.walkFileTree(Paths.get(overlayUri), new CommonsTestingUtil.CopyFileVisitor(tmp, true, f -> {
                        f.setExecutable(true, false);
                    }));
                }
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        builder.copy("test", INFINISPAN_SERVER_HOME + "/server").copy("tmp", INFINISPAN_SERVER_HOME).workDir(INFINISPAN_SERVER_HOME).entryPoint(args.toArray(new String[] {})).expose(// JMX Remoting
        EXPOSED_PORTS);
        builder.copy("lib", serverPathFrom("lib")).user("root").run("chown", "-R", IMAGE_USER, INFINISPAN_SERVER_HOME).run("chmod", "-R", "g+rw", INFINISPAN_SERVER_HOME).user(IMAGE_USER);
    });
    int numServers = configuration.numServers();
    CountdownLatchLoggingConsumer clusterLatch = new CountdownLatchLoggingConsumer(numServers, String.format(CLUSTER_VIEW_REGEX, numServers));
    if (configuration.isParallelStartup()) {
        CountdownLatchLoggingConsumer startupLatch = new CountdownLatchLoggingConsumer(numServers, STARTUP_MESSAGE_REGEX);
        IntStream.range(0, configuration.numServers()).forEach(i -> createContainer(i, startupLatch, clusterLatch));
        Exceptions.unchecked(() -> startupLatch.await(TIMEOUT_SECONDS, TimeUnit.SECONDS));
    } else {
        for (int i = 0; i < configuration.numServers(); i++) {
            CountdownLatchLoggingConsumer startupLatch = new CountdownLatchLoggingConsumer(1, STARTUP_MESSAGE_REGEX);
            createContainer(i, startupLatch, clusterLatch);
            Exceptions.unchecked(() -> startupLatch.await(TIMEOUT_SECONDS, TimeUnit.SECONDS));
        }
    }
    // Ensure that a cluster of numServers has actually formed before proceeding
    Exceptions.unchecked(() -> clusterLatch.await(TIMEOUT_SECONDS, TimeUnit.SECONDS));
}
Also used : Path(java.nio.file.Path) Arrays(java.util.Arrays) StringPropertyReplacer(org.infinispan.commons.util.StringPropertyReplacer) LogFactory(org.infinispan.util.logging.LogFactory) URL(java.net.URL) Mount(com.github.dockerjava.api.model.Mount) DockerClient(com.github.dockerjava.api.DockerClient) InetAddress(java.net.InetAddress) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Server(org.infinispan.server.Server) JMXConnectorFactory(javax.management.remote.JMXConnectorFactory) URI(java.net.URI) Path(java.nio.file.Path) ResourceReaper(org.testcontainers.utility.ResourceReaper) MBeanServerConnection(javax.management.MBeanServerConnection) FileVisitor(java.nio.file.FileVisitor) JMXServiceURL(javax.management.remote.JMXServiceURL) FileSystem(java.nio.file.FileSystem) InetSocketAddress(java.net.InetSocketAddress) ThreadLeakChecker(org.infinispan.commons.test.ThreadLeakChecker) FileVisitResult(java.nio.file.FileVisitResult) List(java.util.List) DEFAULT_SERVER_CONFIG(org.infinispan.server.Server.DEFAULT_SERVER_CONFIG) Exceptions(org.infinispan.commons.test.Exceptions) CommonsTestingUtil(org.infinispan.commons.test.CommonsTestingUtil) DockerClientFactory(org.testcontainers.DockerClientFactory) IntStream(java.util.stream.IntStream) ImageFromDockerfile(org.testcontainers.images.builder.ImageFromDockerfile) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) Eventually.eventually(org.infinispan.commons.test.Eventually.eventually) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) Version(org.infinispan.commons.util.Version) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry) GenericContainer(org.testcontainers.containers.GenericContainer) MountType(com.github.dockerjava.api.model.MountType) INFINISPAN_TEST_SERVER_LOG_FILE(org.infinispan.server.test.core.TestSystemPropertyNames.INFINISPAN_TEST_SERVER_LOG_FILE) OutputStream(java.io.OutputStream) Properties(java.util.Properties) Log(org.infinispan.commons.logging.Log) Files(java.nio.file.Files) Util(org.infinispan.commons.util.Util) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Network(com.github.dockerjava.api.model.Network) Paths(java.nio.file.Paths) Collections(java.util.Collections) JMXConnector(javax.management.remote.JMXConnector) OutputFrame(org.testcontainers.containers.output.OutputFrame) Base58(org.testcontainers.utility.Base58) FileSystems(java.nio.file.FileSystems) InputStream(java.io.InputStream) ContainerNetwork(com.github.dockerjava.api.model.ContainerNetwork) ImageFromDockerfile(org.testcontainers.images.builder.ImageFromDockerfile) ArrayList(java.util.ArrayList) CommonsTestingUtil(org.infinispan.commons.test.CommonsTestingUtil) IOException(java.io.IOException) Properties(java.util.Properties) URI(java.net.URI) URL(java.net.URL) JMXServiceURL(javax.management.remote.JMXServiceURL) IOException(java.io.IOException) FileSystem(java.nio.file.FileSystem) File(java.io.File)

Aggregations

DockerClient (com.github.dockerjava.api.DockerClient)1 ContainerNetwork (com.github.dockerjava.api.model.ContainerNetwork)1 Mount (com.github.dockerjava.api.model.Mount)1 MountType (com.github.dockerjava.api.model.MountType)1 Network (com.github.dockerjava.api.model.Network)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 URI (java.net.URI)1 URL (java.net.URL)1 FileSystem (java.nio.file.FileSystem)1 FileSystems (java.nio.file.FileSystems)1 FileVisitResult (java.nio.file.FileVisitResult)1 FileVisitor (java.nio.file.FileVisitor)1 Files (java.nio.file.Files)1