Skip to content

Commit

Permalink
Revert "GEODE-10327: Overhaul GfshRule to kill processes and save art…
Browse files Browse the repository at this point in the history
…ifacts (apache#7731)" (apache#7750)

This reverts commit 3f8f8db.
  • Loading branch information
kirklund authored Jun 2, 2022
1 parent 3f8f8db commit b093aaa
Show file tree
Hide file tree
Showing 96 changed files with 2,254 additions and 3,538 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
*/
package org.apache.geode.session.tests;

import static java.nio.file.Files.copy;
import static java.util.stream.Collectors.joining;
import static org.apache.geode.session.tests.ContainerInstall.TMP_DIR;
import static org.apache.geode.test.process.JavaModuleHelper.getJvmModuleOptions;

import java.io.File;
Expand All @@ -33,7 +33,6 @@
import org.codehaus.cargo.container.ContainerType;
import org.codehaus.cargo.container.InstalledLocalContainer;
import org.codehaus.cargo.container.State;
import org.codehaus.cargo.container.configuration.Configuration;
import org.codehaus.cargo.container.configuration.ConfigurationType;
import org.codehaus.cargo.container.configuration.LocalConfiguration;
import org.codehaus.cargo.container.deployable.WAR;
Expand All @@ -56,30 +55,32 @@
* Subclasses provide setup and configuration of specific containers.
*/
public abstract class ServerContainer {

protected static final Logger logger = LogService.getLogger();

private static final String DEFAULT_LOGGING_LEVEL = LoggingLevel.LOW.getLevel();

private final Path containerConfigHome;
private final File containerConfigHome;
private final IntSupplier portSupplier;
private final InstalledLocalContainer container;
private final ContainerInstall install;

private String locatorAddress;
private int locatorPort;
private Path warFile;
private File warFile;

public String description;
public Path cacheXMLFile;
public Path cargoLogDir;
public File gemfireLogFile;
public File cacheXMLFile;
public File cargoLogDir;

public String loggingLevel;

private String loggingLevel;
public HashMap<String, String> cacheProperties;
public HashMap<String, String> systemProperties;

protected HashMap<String, String> cacheProperties;
protected HashMap<String, String> systemProperties;
public final String DEFAULT_CONF_DIR;

final Path defaultConfigDir;
public static final String DEFAULT_LOGGING_LEVEL = LoggingLevel.LOW.getLevel();
public static final String DEFAULT_LOG_DIR = "cargo_logs/";
public static final String DEFAULT_CONFIG_DIR = TMP_DIR + "/cargo_configs/";

public static final Logger logger = LogService.getLogger();

/**
* Sets up the container using the given installation
Expand All @@ -90,91 +91,85 @@ public abstract class ServerContainer {
* variable.
*
* @param install the installation with which to set up the container
* @param rootDir The root folder used by default for cargo logs, container configs and other
* files and directories
* @param containerConfigHome The folder that the container configuration folder should be setup
* in
* @param containerDescriptors A string of extra descriptors for the container used in the
* containers {@link #description}
* @param portSupplier allocates ports for use by the container
* @throws IOException if an exception is encountered
*/
public ServerContainer(ContainerInstall install, Path rootDir, Path containerConfigHome,
public ServerContainer(ContainerInstall install, File containerConfigHome,
String containerDescriptors, IntSupplier portSupplier) throws IOException {
this.install = install;
this.portSupplier = portSupplier;
// Get a container description for logging and output
description = generateUniqueContainerDescription(containerDescriptors);
// Setup logging
loggingLevel = DEFAULT_LOGGING_LEVEL;
cargoLogDir = rootDir.resolve("cargo_logs").resolve(description);
Files.createDirectories(cargoLogDir);
cargoLogDir = new File(DEFAULT_LOG_DIR + description);
cargoLogDir.mkdirs();

logger.info("Creating new container {}", description);

defaultConfigDir = install.getHome().resolve("conf");

DEFAULT_CONF_DIR = install.getHome() + "/conf/";
// Use the default configuration home path if not passed a config home
Path defaultConfigDir = rootDir.resolve("cargo_configs");

this.containerConfigHome = containerConfigHome == null
? defaultConfigDir.resolve(description) : containerConfigHome;
? new File(DEFAULT_CONFIG_DIR + description) : containerConfigHome;

// Init the property lists
cacheProperties = new HashMap<>();
systemProperties = new HashMap<>();
// Set WAR file to session testing war
warFile = install.getWarFilePath();
warFile = new File(install.getWarFilePath());

// Create the Cargo Container instance wrapping our physical container
Configuration configuration = new DefaultConfigurationFactory()
LocalConfiguration configuration = (LocalConfiguration) new DefaultConfigurationFactory()
.createConfiguration(install.getInstallId(), ContainerType.INSTALLED,
ConfigurationType.STANDALONE, this.containerConfigHome.toString());

ConfigurationType.STANDALONE, this.containerConfigHome.getAbsolutePath());
// Set configuration/container logging level
configuration.setProperty(GeneralPropertySet.LOGGING, loggingLevel);
// Removes secureRandom generation so that container startup is much faster
configuration.setProperty(GeneralPropertySet.JVMARGS,
"-Djava.security.egd=file:/dev/./urandom -Xmx256m -Xms64m");

// Setup the gemfire log file for this container
Path gemfireLogFile = cargoLogDir.resolve("gemfire.log");
Files.createDirectories(cargoLogDir);
setSystemProperty("log-file", gemfireLogFile.toString());
gemfireLogFile = new File(cargoLogDir.getAbsolutePath() + "/gemfire.log");
gemfireLogFile.getParentFile().mkdirs();
setSystemProperty("log-file", gemfireLogFile.getAbsolutePath());

logger.info("Gemfire logs can be found in {}", gemfireLogFile);
logger.info("Gemfire logs can be found in {}", gemfireLogFile.getAbsolutePath());

// Create the container
container = (InstalledLocalContainer) new DefaultContainerFactory()
container = (InstalledLocalContainer) (new DefaultContainerFactory())
.createContainer(install.getInstallId(), ContainerType.INSTALLED, configuration);
// Set container's home dir to where it was installed
container.setHome(install.getHome().toString());
container.setHome(install.getHome());
// Set container output log to directory setup for it
container.setOutput(cargoLogDir.resolve("container.log").toString());
container.setOutput(cargoLogDir.getAbsolutePath() + "/container.log");

// Set cacheXML file
Path installXMLFile = install.getCacheXMLFile();
File installXMLFile = install.getCacheXMLFile();
// Sets the cacheXMLFile variable and adds the cache XML file server system property map
setCacheXMLFile(cargoLogDir.resolve(installXMLFile.getFileName()));
setCacheXMLFile(new File(cargoLogDir.getAbsolutePath() + "/" + installXMLFile.getName()));
// Copy the cacheXML file to a new, unique location for this container
copy(installXMLFile, cacheXMLFile);
FileUtils.copyFile(installXMLFile, cacheXMLFile);
}

/*
* Generates a unique, mostly human readable, description string of the container using the
* installation's description, extraIdentifiers, and the current system nano time
*/
private String generateUniqueContainerDescription(String extraIdentifiers) {
public String generateUniqueContainerDescription(String extraIdentifiers) {
return String.join("_", Arrays.asList(install.getInstallDescription(), extraIdentifiers,
UUID.randomUUID().toString()));
}

/**
* Deploys the {@link #warFile} to the cargo container ({@link #container}).
*/
protected void deployWar() {
public void deployWar() {
// Get the cargo war from the war file
WAR war = new WAR(warFile.toString());
WAR war = new WAR(warFile.getAbsolutePath());
// Set context access to nothing
war.setContext("");
// Deploy the war the container's configuration
Expand Down Expand Up @@ -237,8 +232,8 @@ public void stop() {

public void dumpLogs() {
System.out.println("Logs for container " + this);
dumpLogsInDir(cargoLogDir);
dumpLogsInDir(containerConfigHome.resolve("logs"));
dumpLogsInDir(cargoLogDir.toPath());
dumpLogsInDir(containerConfigHome.toPath().resolve("logs"));
dumpConfiguration();
}

Expand All @@ -259,7 +254,7 @@ private static void dumpToStdOut(Path path) {
System.out.println(path.toAbsolutePath());
System.out.println("-------------------------------------------");
try {
copy(path, System.out);
Files.copy(path, System.out);
} catch (IOException thrown) {
System.out.println("Exception while dumping log file to stdout.");
System.out.println(" File: " + path.toAbsolutePath());
Expand Down Expand Up @@ -307,7 +302,7 @@ public void cleanUp() throws IOException {
* @param port the port that the locator is listening on
* @throws IOException if an exception is encountered when updating the locator property file
*/
protected void setLocator(String address, int port) throws IOException {
public void setLocator(String address, int port) throws IOException {
locatorAddress = address;
locatorPort = port;
updateLocator();
Expand All @@ -316,29 +311,29 @@ protected void setLocator(String address, int port) throws IOException {
/*
* Sets the container's cache XML file
*/
private void setCacheXMLFile(Path cacheXMLFile) throws IOException {
setSystemProperty("cache-xml-file", cacheXMLFile.toString());
public void setCacheXMLFile(File cacheXMLFile) throws IOException {
setSystemProperty("cache-xml-file", cacheXMLFile.getAbsolutePath());
this.cacheXMLFile = cacheXMLFile;
}

/*
* Set a geode session replication property
*/
protected String setCacheProperty(String name, String value) throws IOException {
public String setCacheProperty(String name, String value) throws IOException {
return cacheProperties.put(name, value);
}

/*
* Set geode distributed system property
*/
private String setSystemProperty(String name, String value) throws IOException {
public String setSystemProperty(String name, String value) throws IOException {
return systemProperties.put(name, value);
}

/*
* Sets the war file for this container to deploy and use
*/
void setWarFile(Path warFile) {
public void setWarFile(File warFile) {
this.warFile = warFile;
}

Expand All @@ -361,7 +356,7 @@ public ContainerInstall getInstall() {
return install;
}

public Path getWarFile() {
public File getWarFile() {
return warFile;
}

Expand All @@ -377,11 +372,11 @@ public State getState() {
return container.getState();
}

protected String getCacheProperty(String name) {
public String getCacheProperty(String name) {
return cacheProperties.get(name);
}

protected String getSystemProperty(String name) {
public String getSystemProperty(String name) {
return systemProperties.get(name);
}

Expand Down Expand Up @@ -457,7 +452,8 @@ private void updateLocator() throws IOException {
attributes.put("host", locatorAddress);
attributes.put("port", Integer.toString(locatorPort));

ContainerInstall.editXMLFile(cacheXMLFile, "locator", "pool", attributes, true);
ContainerInstall.editXMLFile(cacheXMLFile.getAbsolutePath(), "locator", "pool",
attributes, true);
} else {
setSystemProperty("locators", locatorAddress + "[" + locatorPort + "]");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
*/
package org.apache.geode.session.tests;

import static java.nio.file.Files.copy;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.function.IntSupplier;

import org.apache.commons.io.FileUtils;
import org.codehaus.cargo.container.configuration.FileConfig;
import org.codehaus.cargo.container.configuration.StandaloneLocalConfiguration;
import org.codehaus.cargo.container.tomcat.TomcatPropertySet;
Expand All @@ -35,15 +34,14 @@
*/
public class TomcatContainer extends ServerContainer {

private final Path contextXMLFile;
private final Path serverXMLFile;
private final File contextXMLFile;
private final File serverXMLFile;

private static final String DEFAULT_TOMCAT_CONFIG_XML_DIR = "conf/";
public static final String DEFAULT_TOMCAT_CONFIG_XML_DIR = "conf/";

private static final String DEFAULT_TOMCAT_XML_REPLACEMENT_DIR =
public static final String DEFAULT_TOMCAT_XML_REPLACEMENT_DIR =
DEFAULT_TOMCAT_CONFIG_XML_DIR + "Catalina/localhost/";

private static final String DEFAULT_TOMCAT_CONTEXT_XML_REPLACEMENT_NAME = "context.xml.default";
public static final String DEFAULT_TOMCAT_CONTEXT_XML_REPLACEMENT_NAME = "context.xml.default";

/*
* Setup the Tomcat container
Expand All @@ -53,19 +51,18 @@ public class TomcatContainer extends ServerContainer {
* properties, deploys the session testing WAR file to the Cargo container, and sets various
* container properties (i.e. locator, local cache, etc.)
*/
TomcatContainer(TomcatInstall install, Path rootDir, Path containerConfigHome,
public TomcatContainer(TomcatInstall install, File containerConfigHome,
String containerDescriptors, IntSupplier portSupplier) throws IOException {
super(install, rootDir, containerConfigHome, containerDescriptors, portSupplier);
super(install, containerConfigHome, containerDescriptors, portSupplier);

// Setup container specific XML files
contextXMLFile = cargoLogDir.resolve("context.xml");
serverXMLFile = defaultConfigDir.resolve("server.xml");
contextXMLFile = new File(cargoLogDir.getAbsolutePath() + "/context.xml");
serverXMLFile = new File(DEFAULT_CONF_DIR + "server.xml");

// Copy the default container context XML file from the install to the specified path
copy(defaultConfigDir.resolve("context.xml"), contextXMLFile);
FileUtils.copyFile(new File(DEFAULT_CONF_DIR + "context.xml"), contextXMLFile);
// Set the container context XML file to the new location copied to above
setConfigFile(contextXMLFile,
DEFAULT_TOMCAT_XML_REPLACEMENT_DIR,
setConfigFile(contextXMLFile.getAbsolutePath(), DEFAULT_TOMCAT_XML_REPLACEMENT_DIR,
DEFAULT_TOMCAT_CONTEXT_XML_REPLACEMENT_NAME);

if (install.getConnectionType() == ContainerInstall.ConnectionType.CLIENT_SERVER ||
Expand Down Expand Up @@ -97,25 +94,23 @@ public String getAJPPort() {
}

/**
* Implements the {@code ServerContainer#writeSettings()} function in order to write the proper
* Implements the {@link ServerContainer#writeSettings()} function in order to write the proper
* settings to the container
*
* <p>
* Method uses the {@link ContainerInstall#editXMLFile(Path, String, String, String, HashMap)}
* Method uses the {@link ContainerInstall#editXMLFile(String, String, String, String, HashMap)}
* to edit the {@link #contextXMLFile} with the {@link #cacheProperties}. Method uses
* {@link #writePropertiesToConfig(StandaloneLocalConfiguration, String, String, HashMap)} to
* write the {@link #systemProperties} to the {@link #serverXMLFile} using the container's
* configuration (obtained from {@link #getConfiguration()}).
*/
@Override
public void writeSettings() {
public void writeSettings() throws IOException {
StandaloneLocalConfiguration config = (StandaloneLocalConfiguration) getConfiguration();

// Edit the context XML file
ContainerInstall.editXMLFile(contextXMLFile, "Tomcat", "Manager", "Context",
ContainerInstall.editXMLFile(contextXMLFile.getAbsolutePath(), "Tomcat", "Manager", "Context",
cacheProperties);
writePropertiesToConfig(config,
DEFAULT_TOMCAT_CONFIG_XML_DIR + "/" + serverXMLFile.toFile().getName(),
writePropertiesToConfig(config, DEFAULT_TOMCAT_CONFIG_XML_DIR + "/" + serverXMLFile.getName(),
"//Server/Listener[@className='"
+ ((TomcatInstall) getInstall()).getServerLifeCycleListenerClass() + "']",
systemProperties);
Expand Down Expand Up @@ -161,10 +156,10 @@ private void writePropertiesToConfig(StandaloneLocalConfiguration config, String
* @param configDirDest The name of the directory that the configuration file be placed in
* @param configFileDestName The name of destination file for the new configuration file
*/
private void setConfigFile(Path filePath, String configDirDest, String configFileDestName) {
private void setConfigFile(String filePath, String configDirDest, String configFileDestName) {
FileConfig configFile = new FileConfig();

configFile.setFile(filePath.toString());
configFile.setFile(filePath);
configFile.setToDir(configDirDest);
configFile.setToFile(configFileDestName);
getConfiguration().setConfigFileProperty(configFile);
Expand Down
Loading

0 comments on commit b093aaa

Please sign in to comment.