use of org.infinispan.server.test.core.TestSystemPropertyNames.INFINISPAN_TEST_SERVER_LOG_FILE 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));
}
Aggregations