Search in sources :

Example 1 with Server

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

the class ServerOverlayConfigurationTest method testOverlayTwice.

@Test
public void testOverlayTwice() {
    Properties properties = new Properties();
    properties.put(Server.INFINISPAN_SERVER_CONFIG_PATH, getConfigPath().toString());
    Server server = new Server(getConfigPath().toFile(), Arrays.asList(Paths.get("Base.xml"), Paths.get("Overlay.yml"), Paths.get("Overlay-AsyncReplicatedCache.yml")), properties);
    ConfigurationBuilderHolder holder = server.getConfigurationBuilderHolder();
    assertTrue(holder.getNamedConfigurationBuilders().containsKey("secondary-cache"));
    assertFalse(holder.getGlobalConfigurationBuilder().cacheContainer().statistics());
    assertFalse(holder.getGlobalConfigurationBuilder().cacheContainer().jmx().enabled());
    GlobalConfiguration global = holder.getGlobalConfigurationBuilder().build();
    assertNotNull(global.module(ServerConfiguration.class));
}
Also used : ConfigurationBuilderHolder(org.infinispan.configuration.parsing.ConfigurationBuilderHolder) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) Server(org.infinispan.server.Server) Properties(java.util.Properties) Test(org.junit.Test)

Example 2 with Server

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

the class ServerOverlayConfigurationTest method testOverlay.

@Test
public void testOverlay() {
    Properties properties = new Properties();
    properties.put(Server.INFINISPAN_SERVER_CONFIG_PATH, getConfigPath().toString());
    properties.put(Server.INFINISPAN_SERVER_HOME_PATH, getConfigPath().toString());
    Server server = new Server(getConfigPath().toFile(), Arrays.asList(Paths.get("Base.xml"), Paths.get("Overlay.yml")), properties);
    ConfigurationBuilderHolder holder = server.getConfigurationBuilderHolder();
    assertTrue(holder.getNamedConfigurationBuilders().containsKey("overlay"));
    GlobalConfiguration global = holder.getGlobalConfigurationBuilder().build();
    assertNotNull(global.module(ServerConfiguration.class));
}
Also used : ConfigurationBuilderHolder(org.infinispan.configuration.parsing.ConfigurationBuilderHolder) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) Server(org.infinispan.server.Server) Properties(java.util.Properties) Test(org.junit.Test)

Example 3 with Server

use of org.infinispan.server.Server 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)

Example 4 with Server

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

the class EmbeddedInfinispanServerDriver method restart.

@Override
public void restart(int serverIndex) {
    assert !isRunning(serverIndex);
    File serverRoot = serverRoot(getRootDir(), Integer.toString(serverIndex));
    Server server = createServerInstance(getName(), getRootDir(), new File(configuration.configurationFile()), serverIndex, serverRoot);
    servers.set(serverIndex, server);
    serverFutures.set(serverIndex, server.run());
}
Also used : Server(org.infinispan.server.Server) File(java.io.File)

Example 5 with Server

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

the class EmbeddedInfinispanServerDriver method createServerInstance.

private Server createServerInstance(String name, File rootDir, File configurationFile, int serverIndex, File serverRoot) {
    Properties properties = new Properties();
    properties.setProperty(Server.INFINISPAN_SERVER_HOME_PATH, serverRoot.getAbsolutePath());
    properties.setProperty(Server.INFINISPAN_SERVER_CONFIG_PATH, new File(rootDir, Server.DEFAULT_SERVER_CONFIG).getAbsolutePath());
    properties.setProperty(Server.INFINISPAN_PORT_OFFSET, Integer.toString(clusterPortOffset() + serverIndex * OFFSET_FACTOR));
    properties.setProperty(Server.INFINISPAN_CLUSTER_NAME, name);
    properties.setProperty(Server.INFINISPAN_CLUSTER_STACK, System.getProperty(Server.INFINISPAN_CLUSTER_STACK));
    properties.setProperty(TEST_HOST_ADDRESS, testHostAddress.getHostName());
    properties.setProperty(Server.INFINISPAN_LOG4J_SHUTDOWN, "false");
    configureSite(properties);
    configuration.properties().forEach((k, v) -> {
        String value = StringPropertyReplacer.replaceProperties((String) v, properties);
        properties.put(k, value);
        System.setProperty(k.toString(), value);
    });
    Server server = new Server(serverRoot, new File(configurationFile.getName()), properties);
    server.setExitHandler(new DefaultExitHandler());
    return server;
}
Also used : DefaultExitHandler(org.infinispan.server.DefaultExitHandler) Server(org.infinispan.server.Server) Properties(java.util.Properties) File(java.io.File)

Aggregations

Server (org.infinispan.server.Server)11 Properties (java.util.Properties)8 File (java.io.File)6 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)4 ConfigurationBuilderHolder (org.infinispan.configuration.parsing.ConfigurationBuilderHolder)4 Test (org.junit.Test)4 Path (java.nio.file.Path)3 IOException (java.io.IOException)2 InetAddress (java.net.InetAddress)2 InetSocketAddress (java.net.InetSocketAddress)2 Files (java.nio.file.Files)2 Paths (java.nio.file.Paths)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TimeUnit (java.util.concurrent.TimeUnit)2 MBeanServerConnection (javax.management.MBeanServerConnection)2 Log (org.infinispan.commons.logging.Log)2 CommonsTestingUtil (org.infinispan.commons.test.CommonsTestingUtil)2 Exceptions (org.infinispan.commons.test.Exceptions)2 Util (org.infinispan.commons.util.Util)2