From 55a2ad89178a01ace31c263b31284f5792600da1 Mon Sep 17 00:00:00 2001 From: eostermueller Date: Sun, 12 Feb 2023 12:59:21 -0600 Subject: [PATCH] release 0.0.4b --- backend/pom.xml | 14 +- .../eostermueller/snail4j/DefaultFactory.java | 80 ++- .../snail4j/config/package-info.java | 1 - .../snail4j/controller/package-info.java | 8 - .../install/AvailableMemoryValidatorImpl.java | 43 +- .../snail4j/install/DefaultSutInstaller.java | 14 +- .../install/DiskSpaceValidatorImpl.java | 3 +- .../snail4j/install/InstallAdvice.java | 2 +- .../snail4j/install/Snail4jInstaller.java | 79 ++- .../snail4j/install/Snail4jInstaller.java.bak | 616 ------------------ .../snail4j/install/package-info.java | 1 - .../snail4j/launcher/BootstrapConfig.java | 29 +- .../launcher/DefaultConfiguration.java | 11 +- .../snail4j/launcher/Factory.java | 23 +- .../snail4j/launcher/Messages.java | 3 + .../snail4j/launcher/Messages_en_US.java | 10 +- .../eostermueller/snail4j/package-info.java | 8 - .../AvailableDiskSpaceValidation.java | 7 +- .../AvailableMemoryValidation.java | 2 +- .../BooleanSystemPropertyImpl.java | 5 +- .../snail4j/systemproperty/DeleteSut.java | 8 +- .../snail4j/systemproperty/Headless.java | 14 +- .../LongSystemPropertyImpl.java | 2 +- .../StringSystemPropertyImpl.java | 2 +- .../systemproperty/SutGitCloneUrl.java | 2 +- .../systemproperty/SystemProperty.java | 3 +- .../snail4j/systemproperty/package-info.java | 1 - .../snail4j/util/package-info.java | 1 - .../SystemPropertyTestValueRepoImpl.java | 18 +- .../test/FluxCapacitorTestBoolean.java | 9 +- .../test/FluxCapacitorTestLong.java | 10 +- .../test/FluxCapacitorTestString.java | 11 +- build/packageFast.sh | 2 + build/packageSlow.sh | 2 +- build/setenv_02.sh | 2 +- .../health-checks/health-checks.component.ts | 17 +- .../main/web/src/app/services/config.model.ts | 1 + 37 files changed, 302 insertions(+), 762 deletions(-) delete mode 100644 backend/src/main/java/com/github/eostermueller/snail4j/config/package-info.java delete mode 100644 backend/src/main/java/com/github/eostermueller/snail4j/controller/package-info.java delete mode 100644 backend/src/main/java/com/github/eostermueller/snail4j/install/Snail4jInstaller.java.bak delete mode 100644 backend/src/main/java/com/github/eostermueller/snail4j/install/package-info.java delete mode 100644 backend/src/main/java/com/github/eostermueller/snail4j/package-info.java delete mode 100644 backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/package-info.java delete mode 100644 backend/src/main/java/com/github/eostermueller/snail4j/util/package-info.java diff --git a/backend/pom.xml b/backend/pom.xml index 3ad67a3..2458dc6 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -96,11 +96,12 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs ${project.version} runtime - - org.eclipse.jgit - org.eclipse.jgit - 6.2.0.202206071550-r - + + org.eclipse.jgit + org.eclipse.jgit + 5.13.1.202206130422-r + + org.skyscreamer jsonassert @@ -240,7 +241,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs org.apache.maven.plugins - maven-compiler-plugin + maven-compiler-plugin + 3.10.1 diff --git a/backend/src/main/java/com/github/eostermueller/snail4j/DefaultFactory.java b/backend/src/main/java/com/github/eostermueller/snail4j/DefaultFactory.java index f6ea597..b4e2e96 100644 --- a/backend/src/main/java/com/github/eostermueller/snail4j/DefaultFactory.java +++ b/backend/src/main/java/com/github/eostermueller/snail4j/DefaultFactory.java @@ -3,6 +3,8 @@ import java.io.File; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; import java.util.Locale; import java.util.concurrent.atomic.AtomicInteger; @@ -28,6 +30,10 @@ import com.github.eostermueller.snail4j.launcher.EventHistory; import com.github.eostermueller.snail4j.launcher.Factory; import com.github.eostermueller.snail4j.launcher.Messages; + +/** + * Messages_en_US is used as a default if java.util.Locale.getDefault() + */ import com.github.eostermueller.snail4j.launcher.Messages_en_US; import com.github.eostermueller.snail4j.processmodel.DefaultLoadGenerator; import com.github.eostermueller.snail4j.processmodel.DefaultProcessModelBuilder; @@ -36,6 +42,8 @@ import com.github.eostermueller.snail4j.processmodel.ProcessModelBuilder; import com.github.eostermueller.snail4j.processmodel.SystemUnderTest; import com.github.eostermueller.snail4j.systemproperty.AvailableDiskSpaceValidation; +import com.github.eostermueller.snail4j.systemproperty.Headless; +import com.github.eostermueller.snail4j.systemproperty.OneTimeConfigChanger; import com.github.eostermueller.snail4j.systemproperty.SystemPropertyManager; import com.github.eostermueller.snail4j.systemproperty.SystemPropertyManagerImpl; import com.google.common.flogger.FluentLogger; @@ -64,21 +72,6 @@ private DefaultFactory() { static EventHistory eventHistory = new EventHistory(); static Factory FACTORY_INSTANCE = null; - static SystemPropertyManager SYSTEM_PROPERTY_MGR_SINGLETON = new SystemPropertyManagerImpl(); - - @Override - public SystemPropertyManager getSystemPropertyMgr() { - return SYSTEM_PROPERTY_MGR_SINGLETON; - } - /** - * Must only be called during JUnit tests!!!! - * @param testRepo - */ - @Override - public void setSystemPropertyTestValueRepo(SystemPropertyManager testRepo) { - SystemPropertyManagerImpl impl = (SystemPropertyManagerImpl) this.getSystemPropertyMgr(); - impl.setSystemPropertyTestValueRepository(testRepo); - } /** @@ -95,6 +88,23 @@ public void setConfiguration(Configuration cfg) { this.configuration = cfg; } } + @Override + public OneTimeConfigChanger[] getOneTimeDashDSystemPropertyConfigChanges() { + List oneTimeConfigChangers = new ArrayList(); + oneTimeConfigChangers.add( new Headless() ); + return oneTimeConfigChangers.toArray(new OneTimeConfigChanger[0]); +// return (OneTimeConfigChanger[]) oneTimeConfigChangers.toArray(); + } + + + + + private void oneTimeConfigurationChanges(Configuration cfg) throws Snail4jException { + for(OneTimeConfigChanger oneTimeConfigChanger : this.getOneTimeDashDSystemPropertyConfigChanges() ) { + oneTimeConfigChanger.oneTimeChange(cfg); + } + } + @Override public GenericConfigFileReaderWriter getGenericConfigReaderWriter() { return new DefaultGenericConfigFileReaderWriter(); @@ -102,7 +112,8 @@ public GenericConfigFileReaderWriter getGenericConfigReaderWriter() { @Override public Configuration getConfiguration() throws Snail4jException { return getConfiguration( new BootstrapConfig() ); - } + } + @Override public Configuration getConfiguration(BootstrapConfig bootstrapConfig) throws Snail4jException { if (this.configuration == null) { @@ -111,20 +122,22 @@ public Configuration getConfiguration(BootstrapConfig bootstrapConfig) throws Sn ConfigReaderWriter configReaderWriter = DefaultFactory.getFactory().getConfigReaderWriter(); - File snail4jConfigFile = bootstrapConfig.getFullPathToConfigFile().toFile(); + File loadTestInABoxConfigFile = bootstrapConfig.getFullPathToConfigFile().toFile(); try { Class configurationClass = (Class) Class.forName(this.getConfigurationClassName()); - if (snail4jConfigFile.exists()) { - this.configuration = configReaderWriter.read(snail4jConfigFile, configurationClass); + if (loadTestInABoxConfigFile.exists()) { + this.configuration = configReaderWriter.read(loadTestInABoxConfigFile, configurationClass); } else { this.configuration = (Configuration) configurationClass.getDeclaredConstructor(null).newInstance(null); - bootstrapConfig.createSnail4jHomeIfNotExist(); - configReaderWriter.write( - bootstrapConfig.getFullPathToConfigFile().toFile(), - this.configuration - ); + bootstrapConfig.createLoadTestInABoxHomeIfNotExist(); } + this.oneTimeConfigurationChanges(this.configuration); + configReaderWriter.write( + bootstrapConfig.getFullPathToConfigFile().toFile(), + this.configuration + ); + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { @@ -164,7 +177,8 @@ public String getConfigurationClassName() { public Locale getLocaleForMessages() { return localeForMessages; } - /* (non-Javadoc) + /* Override this to set a locale other than your JVM's java.util.Locale.getDefault() + * (non-Javadoc) * @see com.github.eostermueller.tjp.launcher.agent.MyFactory#setLocaleForMessages(java.lang.String) */ @Override @@ -185,6 +199,8 @@ public Messages getMessages() { * dashes (-) with with underscores, so that the string * can be appended to java class names. * https://en.wikipedia.org/wiki/IETF_language_tag + * The following details the Underscore character's special designation as a "JavaLetter", meaning that it is allowed in a Java Class name, and a dash is not. + * https://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.8 * @return */ private String getMangledLanguageTag() { @@ -298,19 +314,11 @@ public Installer createSutInstaller() throws Snail4jException { return new DefaultSutInstaller(); } - @Override - /** - * calling this is Required at the end of unit tests that invoke Factory#setSystemPropertyTestValueRepo(); - * ...calling this does no harm (nor provides any particular benefit) in production code. - * Calling this wipes out all JUnit system properties defined by Factory#setSystemPropertyTestValueRepo() ). - * - */ - public void resetUnitTestSystemProperties() { - setSystemPropertyTestValueRepo(null); - } @Override public AvailableMemoryValidator getAvailableMemoryValidator() throws Snail4jException { - return new AvailableMemoryValidatorImpl(); + AvailableMemoryValidator validator = new AvailableMemoryValidatorImpl(); + validator.setMinMemoryAvailableRequirementInBytes( (getConfiguration().getMinMemoryAvailableRequirementInBytes() )); + return validator; } @Override public DiskSpaceValidator getDiskSpaceValidator() throws Snail4jException { diff --git a/backend/src/main/java/com/github/eostermueller/snail4j/config/package-info.java b/backend/src/main/java/com/github/eostermueller/snail4j/config/package-info.java deleted file mode 100644 index a66c01f..0000000 --- a/backend/src/main/java/com/github/eostermueller/snail4j/config/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.github.eostermueller.snail4j.config; \ No newline at end of file diff --git a/backend/src/main/java/com/github/eostermueller/snail4j/controller/package-info.java b/backend/src/main/java/com/github/eostermueller/snail4j/controller/package-info.java deleted file mode 100644 index 6530e49..0000000 --- a/backend/src/main/java/com/github/eostermueller/snail4j/controller/package-info.java +++ /dev/null @@ -1,8 +0,0 @@ -/** - * - */ -/** - * @author eostermueller - * - */ -package com.github.eostermueller.snail4j.controller; \ No newline at end of file diff --git a/backend/src/main/java/com/github/eostermueller/snail4j/install/AvailableMemoryValidatorImpl.java b/backend/src/main/java/com/github/eostermueller/snail4j/install/AvailableMemoryValidatorImpl.java index 18664a2..90d11ca 100644 --- a/backend/src/main/java/com/github/eostermueller/snail4j/install/AvailableMemoryValidatorImpl.java +++ b/backend/src/main/java/com/github/eostermueller/snail4j/install/AvailableMemoryValidatorImpl.java @@ -2,16 +2,53 @@ import com.github.eostermueller.snail4j.DefaultFactory; import com.github.eostermueller.snail4j.Snail4jException; +import com.github.eostermueller.snail4j.launcher.BootstrapConfig; import com.github.eostermueller.snail4j.systemproperty.AvailableMemoryValidation; +/** + * Important doc: + * + * https://developers.redhat.com/articles/2022/04/19/java-17-whats-new-openjdks-container-awareness#why_container_awareness_is_important + *
+ * cgroups v2 support
+Since Java 15, OpenJDK detects the cgroup version in use and detects limits according to cgroup version-specific settings. For Java 15 and onwards, OpenJDK supports cgroups v1 as well as cgroups v2 or the unified hierarchy (see JDK-8230305 for more on this).
+
+If you run Java 11 or Java 8 on a system that has only cgroups v2 , no container detection will be in place and the host values will be used instead. As explained earlier, this might yield unexpected application behavior in containerized deployments.
+
+One quick way to show which cgroup version is in use on a system is the -XshowSettings:system option of the java launcher. (This option is Linux-specific.) Here's an example:
+
+$ java -XshowSettings:system -version
+Operating System Metrics:
+    Provider: cgroupv2
+    Effective CPU Count: 2
+    CPU Period: 100000us
+    CPU Quota: 200000us
+    CPU Shares: 1024us
+    List of Processors: N/A
+    List of Effective Processors, 4 total:
+    0 1 2 3
+    List of Memory Nodes: N/A
+    List of Available Memory Nodes, 1 total:
+    0
+    Memory Limit: 1.00G
+    Memory Soft Limit: 800.00M
+    Memory & Swap Limit: 1.00G
+ * 
errors = new ArrayList(); int timeoutMs = 20000; List targets = new ArrayList(); diff --git a/backend/src/main/java/com/github/eostermueller/snail4j/install/Snail4jInstaller.java b/backend/src/main/java/com/github/eostermueller/snail4j/install/Snail4jInstaller.java index abcc53c..2eb358b 100644 --- a/backend/src/main/java/com/github/eostermueller/snail4j/install/Snail4jInstaller.java +++ b/backend/src/main/java/com/github/eostermueller/snail4j/install/Snail4jInstaller.java @@ -1,6 +1,9 @@ package com.github.eostermueller.snail4j.install; import java.io.File; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + import java.net.MalformedURLException; import java.nio.file.Files; import java.nio.file.Path; @@ -11,12 +14,14 @@ import com.github.eostermueller.snail4j.Application; import com.github.eostermueller.snail4j.DefaultFactory; import com.github.eostermueller.snail4j.Snail4jException; +import com.github.eostermueller.snail4j.config.GenericConfigFileReaderWriter; import com.github.eostermueller.snail4j.install.InstallAdvice.StartupLogger; import com.github.eostermueller.snail4j.install.Installer; import com.github.eostermueller.snail4j.launcher.CannotFindSnail4jFactoryClass; import com.github.eostermueller.snail4j.launcher.Configuration; import com.github.eostermueller.snail4j.launcher.Messages; import com.github.eostermueller.snail4j.util.JdkUtils; +import com.github.eostermueller.snail4j.util.JsonPatchUtils; import com.github.eostermueller.snail4j.util.NonStaticOsUtils; import com.github.eostermueller.snail4j.util.OS; import com.github.eostermueller.snail4j.util.OS.OsFamily; @@ -102,22 +107,22 @@ public int preInstallValidation(Configuration cfg) throws MalformedURLException, } errorCount += preInstallJavaValidation(cfg); - int countOfUnavailablePorts = ia.sutPortsAreAvailable(cfg); + int countOfUnavailablePorts = ia.getCountOfUnavailableSUTTcpPorts(cfg); switch(countOfUnavailablePorts) { case 0: //zero problems break; - case 4:; + case 4: info("Found processes listening on all 4 SUT ports -- assuming the SUT is up."); //not an error break; - default: + default: /** * assuming that either: * a) SUT is only partially up, and end user will have to force it down. - * b) the ports in use are actually collisions, non-Workbench processes are using same ports at Workbench. + * b) the ports in use are actually collisions, likely to be non-Workbench processes are using same ports at Workbench. */ - errorCount += 1; - + errorCount += countOfUnavailablePorts; + break; } info("Number if install issues: " + errorCount ); @@ -247,6 +252,7 @@ private void installGlowroot() throws Snail4jException { * glowroot agent jar needs to be extracted from zip */ cleansedPath = pathUtil.cleanPath(path); + if ( !this.getConfiguration().getGlowrootHome().toFile().exists() ) { LOGGER.info("About to unzip [" + this.getConfiguration().getGlowrootZipFileName() + "] from [" + cleansedPath + "] to [" + targetGlowrootZipFile + "]"); pathUtil.extractZipFromZip(cleansedPath, this.getConfiguration().getGlowrootZipFileName(), targetGlowrootZipFile.toString() ); @@ -256,6 +262,9 @@ private void installGlowroot() throws Snail4jException { pathUtil.unzip(targetGlowrootZipFile.toFile(), this.getConfiguration().getGlowrootHome().toString() ); targetGlowrootZipFile.toFile().delete(); } + + optionallyCreateGlowrootAdminJson(); + } else { LOGGER.error("launch as 'java -jar to get maven to install"); @@ -266,7 +275,63 @@ private void installGlowroot() throws Snail4jException { } - private void createLogDir() throws Snail4jException { + /** + * Makes Glowroot available from a machine other than the one where the ubar jar was launched from. + * https://github.com/glowroot/glowroot/wiki/Agent-Installation-%28with-Embedded-Collector%29 + * + * @throws Snail4jException + */ + private void optionallyCreateGlowrootAdminJson() throws Snail4jException { + String origAdminJsonString = null; + String patchedJsonString = null; + String adminJsonPath = null; + try { + if (this.getConfiguration().isHeadless() ) { + + if (!this.getConfiguration().getGlowrootHome().toFile().exists()) { + throw new Snail4jException("Was expecting the glowroot folder in load-test-in-a-box home folder to exist: " + this.getConfiguration().getGlowrootHome().toString() ); + } + + Path adminJsonHome = Paths.get( this.getConfiguration().getGlowrootHome().toString() , "glowroot"); + if (!adminJsonHome.toFile().exists()) { + throw new Snail4jException("Was expecting glowroot/glowroot folder to exist inside the load-test-in-a-box home folder: " + adminJsonHome.toString() ); + } + + Path adminJson = Paths.get( adminJsonHome.toString() , "admin.json"); + adminJsonPath = adminJson.toString(); + + GenericConfigFileReaderWriter readerWriter = DefaultFactory.getFactory().getGenericConfigReaderWriter(); + + if (adminJson.toFile().exists()) { + adminJsonPath = adminJson.toString(); + origAdminJsonString = readerWriter.read(adminJson); + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode adminJsonNode = objectMapper.readTree(origAdminJsonString); + JsonPatchUtils utils = new JsonPatchUtils(); + + JsonNode fullyPatched = utils.setGlowrootBindAddress(adminJsonNode,"0.0.0.0"); + patchedJsonString = fullyPatched.toPrettyString(); + readerWriter.write(patchedJsonString, adminJson); + + } else { + String bareBonesAdminJson = "{\r\n" + + " \"web\": {\r\n" + + " \"bindAddress\": \"0.0.0.0\"\r\n" + + " }\r\n" + + "}"; + readerWriter.write(bareBonesAdminJson, adminJson); + } + } + } catch (Exception e) { + throw new Snail4jException(e,"Unsuccessful write to [" + adminJsonPath + + " file. Original data [" + origAdminJsonString + "] patched data[" + + patchedJsonString + "]"); + } + + +} + + private void createLogDir() throws Snail4jException { File logDir = this.getConfiguration().getLogDir().toFile(); if (!logDir.exists()) diff --git a/backend/src/main/java/com/github/eostermueller/snail4j/install/Snail4jInstaller.java.bak b/backend/src/main/java/com/github/eostermueller/snail4j/install/Snail4jInstaller.java.bak deleted file mode 100644 index d2c656a..0000000 --- a/backend/src/main/java/com/github/eostermueller/snail4j/install/Snail4jInstaller.java.bak +++ /dev/null @@ -1,616 +0,0 @@ -package com.github.eostermueller.snail4j.install; - -import java.io.File; -import java.net.MalformedURLException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.github.eostermueller.snail4j.Application; -import com.github.eostermueller.snail4j.DefaultFactory; -import com.github.eostermueller.snail4j.Snail4jException; -import com.github.eostermueller.snail4j.install.InstallAdvice.StartupLogger; -import com.github.eostermueller.snail4j.install.Installer; -import com.github.eostermueller.snail4j.launcher.CannotFindSnail4jFactoryClass; -import com.github.eostermueller.snail4j.launcher.Configuration; -import com.github.eostermueller.snail4j.launcher.Messages; -import com.github.eostermueller.snail4j.util.JdkUtils; -import com.github.eostermueller.snail4j.util.NonStaticOsUtils; -import com.github.eostermueller.snail4j.util.OS; -import com.github.eostermueller.snail4j.util.OS.OsFamily; -import com.github.eostermueller.snail4j.util.OsUtils; -import com.github.eostermueller.snail4j.util.PathUtil; -import com.github.eostermueller.snail4j.util.OsUtils.OsResult; - -/** - * The SpringBootStartupInstaller will (ultimately) handle progress meter - * for installation activity in this class. - * Files to be unzipped: - *
- * backend/src/main/resources
-drwxr-xr-x  4 erikostermueller  staff        128 Jul 13 13:26 ..
--rw-r--r--  1 erikostermueller  staff        100 Sep  4 00:39 application.properties
--rw-r--r--  1 erikostermueller  staff    9102386 Sep  4 02:13 apache-maven-3.6.2-bin.zip
--rw-r--r--  1 erikostermueller  staff  561333342 Sep  4 02:13 repository.zip
--rw-r--r--  1 erikostermueller  staff     140497 Sep  4 02:13 sut.zip
-drwxr-xr-x  7 erikostermueller  staff        224 Sep 15 10:30 .
--rw-r--r--@ 1 erikostermueller  staff    3056049 Sep 15 10:30 wiremock-2.24.1.jar
- 
- * 
- * @author erikostermueller - * - */ -public class Snail4jInstaller implements InstallAdvice.StartupLogger { - public static final String LOG_PREFIX = "#### "; - - Messages messages = null; - public Snail4jInstaller() throws CannotFindSnail4jFactoryClass { - messages = DefaultFactory.getFactory().getMessages(); - - } - - /** - * Here is some research from the JDKs installed on my machine: - * java -XshowSettings:properties -version - * - * java.specification.version = 14 - * java.specification.version = 1.8 - * java.specification.version = 9 - - * THe JAVA_HOME validation is a must for Mac because of the complicated folder structure of the distribution. - * But regardless of the OS, snail4j can't find jcmd and other tools in the path, it uses JAVA_HOME to location them. - * @return - * @throws Snail4jException - */ - public int preInstallJavaValidation(Configuration cfg) throws MalformedURLException, Snail4jException { - int errorCount = 0; - - InstallAdvice ia = new InstallAdvice((InstallAdvice.StartupLogger)this); - - if (!ia.isJavaSpecificationVersionOk() ) - errorCount++; //Unlikely this will happen, because 1.7 or before JDK won't run a 1.8 or higher jar file. - - Path javac_dir = JdkUtils.getDirectoryOfJavaCompiler(); - if (javac_dir!=null) { - cfg.setJavaHome( javac_dir.getParent() ); - } else { - Path pathOfThisJvm = Paths.get(JdkUtils.getInstallPathOfThisJvm() ); - info( messages.jreIsNotEnough( pathOfThisJvm ) ); - Path java_home_from_env = new NonStaticOsUtils().get_JAVA_HOME(); - info( messages.attemptingToUseJavaHomeToFindJavaCompiler( java_home_from_env ) ); - - if (!ia.isJavaHomeDirExists(java_home_from_env) ) - errorCount++; - else { - - if( JdkUtils.pointsToCurrentJava(java_home_from_env) ) { - cfg.setJavaHome(java_home_from_env); - javac_dir = JdkUtils.getDirectoryOfJavaCompiler(java_home_from_env); - if (javac_dir==null ) { - info( messages.jreIsNotEnough( java_home_from_env ) ); - errorCount++; - } else { - cfg.setJavaHome(javac_dir.getParent() ); - } - } else { - error( messages.JAVA_HOME_mustPointToCurrentJava(java_home_from_env, pathOfThisJvm)); - errorCount++; - } - } - } - - - LOGGER.debug(LOG_PREFIX+String.format("Detected [%d] JDK issues",errorCount)); - return errorCount; - } - public int preInstallValidation(Configuration cfg) throws MalformedURLException, Snail4jException { - InstallAdvice ia = new InstallAdvice((InstallAdvice.StartupLogger)this); - int errorCount = 0; - - try { - DiskSpaceValidator diskSpaceValidator = DefaultFactory.getFactory().getDiskSpaceValidator(); - diskSpaceValidator.validate(); - ia.startupLogger.debug("No exception from DiskSpaceValidator"); - } catch (Snail4jException s) { - errorCount++; - ia.startupLogger.error(s.getMessage()); - } - try { - AvailableMemoryValidator availableMemoryValidator = DefaultFactory.getFactory().getAvailableMemoryValidator(); - availableMemoryValidator.validate(); - ia.startupLogger.debug("No exception from AvailableMemoryValidator"); - } catch (Snail4jException s) { - errorCount++; - ia.startupLogger.error(s.getMessage()); - } - - errorCount += preInstallJavaValidation(cfg); - int countOfUnavailablePorts = ia.sutPortsAreAvailable(cfg); - switch(countOfUnavailablePorts) { - case 0: - //zero problems - break; - case 4:; - info("Found processes listening on all 4 SUT ports -- assuming the SUT is up."); //not an error - break; - default: - /** - * assuming that either: - * a) SUT is only partially up, and end user will have to force it down. - * b) the ports in use are actually collisions, non-Workbench processes are using same ports at Workbench. - */ - errorCount += 1; - - } - - info("Number if install issues: " + errorCount ); - - return errorCount; - } - - Configuration getConfiguration() throws Snail4jException { - return DefaultFactory.getFactory().getConfiguration(); - } - private final Logger LOGGER = LoggerFactory.getLogger(this.getClass()); - /** - * @optimization: all install* methods could be invoked in separate threads. - */ - public void install() throws Snail4jException { - - try { - - createLogDir(); - - installMaven(); - installMavenRepository(); - DefaultFactory - .getFactory() - .createSutInstaller() - .install(); - installWiremock(); - installH2DbData(); - installJMeterFiles(); - installJMeterDistribution(); - installGlowroot(); - installProcessManager(); - - } catch (Snail4jException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - throw e; - } - - } - - private void installJMeterDistribution() throws Snail4jException { - PathUtil pathUtil = new PathUtil(); - String path = pathUtil.getBaseClassspath(); - String cleansedPath; - String jmeterDistZip = this.getConfiguration().getJMeterZipFileNameWithoutExtension() + ".zip"; - try { - Path targetJMeterZipFile = Paths.get( this.getConfiguration().getSnail4jHome().toString(), jmeterDistZip ); - if (pathUtil.isUberJar()) { - - /** - * jmeter zip needs to be extracted from executable jar file - */ - cleansedPath = pathUtil.cleanPath(path); - if ( !this.getConfiguration().getJMeterDistHome().toFile().exists() ) { - LOGGER.info("About to unzip [" + jmeterDistZip + "] from [" + cleansedPath + "] to [" + targetJMeterZipFile + "]"); - pathUtil.extractZipFromZip(cleansedPath, jmeterDistZip, targetJMeterZipFile.toString() ); - - LOGGER.info("does [" + targetJMeterZipFile.toFile().getAbsolutePath().toString() + "] exist? [" + targetJMeterZipFile.toFile().exists() + "]" ); - - pathUtil.unzip(targetJMeterZipFile.toFile(), this.getConfiguration().getSnail4jHome().toString() ); - targetJMeterZipFile.toFile().delete(); - } - if (!this.getConfiguration().isOsWin() ) { - File jmeterBinFolder = new File(this.getConfiguration().getJMeterDistHome().toFile(), "bin"); - File jmeterExe = new File( jmeterBinFolder, "jmeter.sh"); - if (jmeterExe.exists()) { - String cmd = "chmod +x " + jmeterExe.getAbsolutePath().toString(); - OsUtils.executeProcess_bash(cmd, jmeterBinFolder); - } else { - String err= "java.util.File is reporting that the jmeter.sh executable doesn't exist. [" + jmeterExe.toString() + "]. Cmon, we just installed it. It should be there!"; - LOGGER.error(err); - throw new Snail4jException(err); - } - File jmeterExe2 = new File( jmeterBinFolder, "jmeter"); - if (jmeterExe2.exists()) { - String cmd = "chmod +x " + jmeterExe2.getAbsolutePath().toString(); - OsUtils.executeProcess_bash(cmd, jmeterBinFolder); - } else { - String err= "java.util.File is reporting that the jmeter executable doesn't exist. [" + jmeterExe2.toString() + "]. Cmon, we just installed it. It should be there!"; - LOGGER.error(err); - throw new Snail4jException(err); - } - - File shutdownExe = new File( jmeterBinFolder, "shutdown.sh"); - if (shutdownExe.exists()) { - String cmd = "chmod +x " + shutdownExe.getAbsolutePath().toString(); - OsUtils.executeProcess_bash(cmd, jmeterBinFolder); - } else { - String err= "java.util.File is reporting that the jmeter shutdown.sh executable doesn't exist. [" + shutdownExe.toString() + "]. Cmon, we just installed it. It should be there!"; - LOGGER.error(err); - throw new Snail4jException(err); - } - } - } else { - LOGGER.error("launch as 'java -jar to get maven to install"); - } - } catch (Exception e) { - throw new Snail4jException(e); - } - - - } -/** - * Would be nice to just pull glowroot from maven, so I tried referencing this: - *
-   * https://search.maven.org/artifact/org.glowroot/glowroot-agent/0.13.5/jar
-   * 
- * - * but ran into this exact problem: - *
-   * https://github.com/glowroot/glowroot/issues/582
-   * 
- * ....so my fallback plan is this method. - * @param cfg2 - * @throws Snail4jException - */ - private void installGlowroot() throws Snail4jException { - PathUtil pathUtil = new PathUtil(); - String path = pathUtil.getBaseClassspath(); - String cleansedPath; - try { - Path targetGlowrootZipFile = Paths.get( this.getConfiguration().getSnail4jHome().toString(), this.getConfiguration().getGlowrootZipFileName() ); - if (pathUtil.isUberJar()) { - - /** - * glowroot agent jar needs to be extracted from zip - */ - cleansedPath = pathUtil.cleanPath(path); - if ( !this.getConfiguration().getGlowrootHome().toFile().exists() ) { - LOGGER.info("About to unzip [" + this.getConfiguration().getGlowrootZipFileName() + "] from [" + cleansedPath + "] to [" + targetGlowrootZipFile + "]"); - pathUtil.extractZipFromZip(cleansedPath, this.getConfiguration().getGlowrootZipFileName(), targetGlowrootZipFile.toString() ); - - LOGGER.info("does [" + targetGlowrootZipFile.toFile().getAbsolutePath().toString() + "] exist? [" + targetGlowrootZipFile.toFile().exists() + "]" ); - - pathUtil.unzip(targetGlowrootZipFile.toFile(), this.getConfiguration().getGlowrootHome().toString() ); - targetGlowrootZipFile.toFile().delete(); - } - - } else { - LOGGER.error("launch as 'java -jar to get maven to install"); - } - } catch (Exception e) { - throw new Snail4jException(e); - } - - - } - private void createLogDir() throws Snail4jException { - - File logDir = this.getConfiguration().getLogDir().toFile(); - if (!logDir.exists()) - logDir.mkdirs(); - } -protected void installProcessManager() throws Snail4jException { - PathUtil pathUtil = new PathUtil(); - String path = pathUtil.getBaseClassspath(); - String cleansedPath; - - - try { - Path targetProcessManagerZipFile = Paths.get( this.getConfiguration().getProcessManagerHome().toString(), this.getConfiguration().getProcessManagerZipFileName() ); - - if (this.getConfiguration().getProcessManagerHome().toFile().exists()) { - LOGGER.info("dir for processManager already exists."); - } else { - LOGGER.info("Creating dir for processManager files"); - this.getConfiguration().getProcessManagerHome().toFile().mkdirs(); - } - - if (pathUtil.isUberJar()) { - - /** - * processManager files must be extracted from a zip. - */ - cleansedPath = pathUtil.cleanPath(path); - - if ( targetProcessManagerZipFile.toFile().exists() ) { - LOGGER.info("processManager.zip exists. will not overwrite [" + targetProcessManagerZipFile.toString() + "]"); - } else { - LOGGER.info("About to unzip [" + targetProcessManagerZipFile.toString() + "] from [" + cleansedPath + "] to [" + targetProcessManagerZipFile.toString() + "]"); - pathUtil.extractZipFromZip(cleansedPath, this.getConfiguration().getProcessManagerZipFileName(), targetProcessManagerZipFile.toString() ); - } - - String[] fileNames=this.getConfiguration().getProcessManagerHome().toFile().list(); - - LOGGER.info("[" + fileNames.length + "] file(s) exist(s) in [" + this.getConfiguration().getProcessManagerHome() + "]"); - - if (fileNames.length<1) { - throw new Snail4jException("Install failed. Tried to uznip [" + this.getConfiguration().getProcessManagerZipFileName() + "] to [" + this.getConfiguration().getProcessManagerHome() + "] but [" + targetProcessManagerZipFile.toString() + "] does not exist." ); - } else if (fileNames.length==1 && fileNames[0].equals(this.getConfiguration().getProcessManagerZipFileName()) ) { - pathUtil.unzip(targetProcessManagerZipFile.toFile(), this.getConfiguration().getProcessManagerHome().toString() ); - targetProcessManagerZipFile.toFile().delete(); // don't need anymore because we just unzipped its contents. - } else { - LOGGER.info("Will not unzip [" + this.getConfiguration().getProcessManagerZipFileName() + "] to avoid overwriting local changes to unzipped files. Delete all files in USER_HOME/" + Application.INSTALL_ROOT + "/processManager and restart snail4j executable jar"); - } - - - } else { - LOGGER.error("launch as 'java -jar to get processManager to install"); - } - - } catch (Exception e) { - throw new Snail4jException(e); - } - } - - protected void installJMeterFiles() throws Snail4jException { - PathUtil pathUtil = new PathUtil(); - String path = pathUtil.getBaseClassspath(); - String cleansedPath; - - - try { - Path targetJMeterFilesZipFile = Paths.get( this.getConfiguration().getJMeterFilesHome().toString(), this.getConfiguration().getJMeterFilesZipFileName() ); - - if (this.getConfiguration().getJMeterFilesHome().toFile().exists()) { - LOGGER.info("dir for jmeter files already exists."); - } else { - LOGGER.info("Creating dir for jmter .jmx plan files and the maven file to launch jmeter."); - this.getConfiguration().getJMeterFilesHome().toFile().mkdirs(); - } - - if (pathUtil.isUberJar()) { - - /** - * jmeter files must be extracted from a zip. - */ - cleansedPath = pathUtil.cleanPath(path); - - if ( targetJMeterFilesZipFile.toFile().exists() ) { - LOGGER.info("jmeterFiles.zip exists. will not overwrite [" + targetJMeterFilesZipFile.toString() + "]"); - } else { - LOGGER.info("About to unzip [" + targetJMeterFilesZipFile.toString() + "] from [" + cleansedPath + "] to [" + targetJMeterFilesZipFile.toString() + "]"); - pathUtil.extractZipFromZip(cleansedPath, this.getConfiguration().getJMeterFilesZipFileName(), targetJMeterFilesZipFile.toString() ); - } - - String[] fileNames=this.getConfiguration().getJMeterFilesHome().toFile().list(); - - LOGGER.info("[" + fileNames.length + "] file(s) exist(s) in [" + this.getConfiguration().getJMeterFilesHome() + "]"); - - if (fileNames.length<1) { - throw new Snail4jException("Install failed. Tried to uznip [" + this.getConfiguration().getJMeterFilesZipFileName() + "] to [" + this.getConfiguration().getJMeterFilesHome() + "] but [" + targetJMeterFilesZipFile.toString() + "] does not exist." ); - } else if (fileNames.length==1 && fileNames[0].equals(this.getConfiguration().getJMeterFilesZipFileName()) ) { - pathUtil.unzip(targetJMeterFilesZipFile.toFile(), this.getConfiguration().getJMeterFilesHome().toString() ); - targetJMeterFilesZipFile.toFile().delete(); // don't need anymore because we just unzipped its contents. - } else { - LOGGER.info("Will not unzip [" + this.getConfiguration().getJMeterFilesZipFileName() + "] to avoid overwriting local changes to unzipped files. Delete all files in USER_HOME/" + Application.INSTALL_ROOT +"/jmeterFiles and restart snail4j executable jar"); - } - - - } else { - LOGGER.error("launch as 'java -jar to get JMeter test files to install"); - } - - } catch (Exception e) { - throw new Snail4jException(e); - } - } -/** - * Unzip wiremock executable jar file to its own folder on the file system, but don't unzip it! - * http://repo1.maven.org/maven2/com/github/tomakehurst/wiremock-standalone/2.24.1/wiremock-standalone-2.24.1.jar - * @param cfg - * @throws Exception - */ - protected void installWiremock() throws Snail4jException { - PathUtil pathUtil = new PathUtil(); - String path = pathUtil.getBaseClassspath(); - String cleansedPath; - - - try { - Path targetWiremockFilesZipFile = Paths.get( this.getConfiguration().getWiremockFilesHome().toString(), this.getConfiguration().getWiremockFilesZipFileName() ); - - if (this.getConfiguration().getWiremockFilesHome().toFile().exists()) { - LOGGER.info("dir for wiremock files already exists."); - } else { - LOGGER.info("Creating dir for jmter .jmx plan files and the maven file to launch wiremock."); - this.getConfiguration().getWiremockFilesHome().toFile().mkdirs(); - } - - if (pathUtil.isUberJar()) { - - /** - * wiremock files must be extracted from a zip. - */ - cleansedPath = pathUtil.cleanPath(path); - - if ( targetWiremockFilesZipFile.toFile().exists() ) { - LOGGER.info("wiremockFiles.zip exists. will not overwrite [" + targetWiremockFilesZipFile.toString() + "]"); - } else { - LOGGER.info("About to unzip [" + targetWiremockFilesZipFile.toString() + "] from [" + cleansedPath + "] to [" + targetWiremockFilesZipFile.toString() + "]"); - pathUtil.extractZipFromZip(cleansedPath, this.getConfiguration().getWiremockFilesZipFileName(), targetWiremockFilesZipFile.toString() ); - } - - String[] fileNames=this.getConfiguration().getWiremockFilesHome().toFile().list(); - - LOGGER.info("[" + fileNames.length + "] file(s) exist(s) in [" + this.getConfiguration().getWiremockFilesHome() + "]"); - - if (fileNames.length<1) { - throw new Snail4jException("Install failed. Tried to unzip [" + this.getConfiguration().getWiremockFilesZipFileName() + "] to [" + this.getConfiguration().getWiremockFilesHome() + "] but [" + targetWiremockFilesZipFile.toString() + "] does not exist." ); - } else if (fileNames.length==1 && fileNames[0].equals(this.getConfiguration().getWiremockFilesZipFileName()) ) { - pathUtil.unzip(targetWiremockFilesZipFile.toFile(), this.getConfiguration().getWiremockFilesHome().toString() ); - targetWiremockFilesZipFile.toFile().delete(); // don't need anymore because we just unzipped its contents. - } else { - LOGGER.info("Will not unzip [" + this.getConfiguration().getWiremockFilesZipFileName() + "] to avoid overwriting local changes to unzipped files. Delete all files in USER_HOME/." + Application.INSTALL_ROOT + "/wiremockFiles and restart snail4j executable jar"); - } - - - } else { - LOGGER.error("launch as 'java -jar to get maven to install"); - } - - } catch (Exception e) { - throw new Snail4jException(e); - } - } - /** - * When the SUT launches from maven, use the following parameter to specify the - * local repository (which will be packaged inside snail4j to improve starup perf and enabl offline installations). - *
-   * -Dmaven.repo.local=/my/rep0
-   * 
- * - * @param cfg - * @throws Exception - */ - protected void installMavenRepository() throws Snail4jException { - PathUtil pathUtil = new PathUtil(); - String path = pathUtil.getBaseClassspath(); - String cleansedPath; - String zipName = "repository.zip"; - - try { - Path targetMavenRepositoryZipFile = Paths.get( this.getConfiguration().getSnail4jHome().toString(), zipName ); - if (pathUtil.isUberJar()) { - - /** - * maven repository zip needs to be extracted from executable jar file - */ - cleansedPath = pathUtil.cleanPath(path); - if ( this.getConfiguration().getMavenRepositoryHome().toFile().exists() ) { - LOGGER.info("Maven home exists. will not overwrite [" + this.getConfiguration().getMavenRepositoryHome().toString() + "]"); - } else { - LOGGER.info("About to unzip [" + zipName + "] from [" + cleansedPath + "] to [" + targetMavenRepositoryZipFile + "]"); - pathUtil.extractZipFromZip(cleansedPath, zipName, targetMavenRepositoryZipFile.toString() ); - - LOGGER.info("does [" + targetMavenRepositoryZipFile.toFile().getAbsolutePath().toString() + "] exist? [" + targetMavenRepositoryZipFile.toFile().exists() + "]" ); - - pathUtil.unzip(targetMavenRepositoryZipFile.toFile(), this.getConfiguration().getSnail4jHome().toString() ); - targetMavenRepositoryZipFile.toFile().delete(); - } - - } else { - LOGGER.error("launch as 'java -jar to get maven to install"); - } - } catch (Exception e) { - throw new Snail4jException(e); - } - - } - protected void installH2DbData() throws Snail4jException { - PathUtil pathUtil = new PathUtil(); - String path = pathUtil.getBaseClassspath(); - String cleansedPath; - String zipName = "data.zip"; - - - try { - Path targetH2ZipFile = Paths.get( this.getConfiguration().getH2DataFileHome().toString(), zipName ); - Path targetH2DataFile = Paths.get( this.getConfiguration().getH2DataFileHome().toString(), this.getConfiguration().getH2DataFileName() ); - - if (this.getConfiguration().getH2DataFileHome().toFile().exists()) { - LOGGER.info("dir for h2 db already exists."); - } else { - LOGGER.info("Creating dir for h2 db data file"); - this.getConfiguration().getH2DataFileHome().toFile().mkdirs(); - } - - if (pathUtil.isUberJar()) { - - cleansedPath = pathUtil.cleanPath(path); - - if ( targetH2ZipFile.toFile().exists() ) { - LOGGER.info("H2Data home exists. will not overwrite [" + targetH2ZipFile.toString() + "]"); - } else { - LOGGER.info("About to unzip [" + zipName + "] from [" + cleansedPath + "] to [" + targetH2ZipFile.toString() + "]"); - pathUtil.extractZipFromZip(cleansedPath, zipName, targetH2ZipFile.toString() ); - } - - LOGGER.info("does [" + targetH2DataFile.toFile().getAbsolutePath().toString() + "] exist? [" + targetH2DataFile.toFile().exists() + "]" ); - if (targetH2DataFile.toFile().exists()) { - LOGGER.info("[" + targetH2DataFile.toFile().getAbsolutePath().toString() + "] does exist. will not overwrite."); - } else { - pathUtil.unzip(targetH2ZipFile.toFile(), this.getConfiguration().getH2DataFileHome().toString() ); - targetH2ZipFile.toFile().delete(); // don't need anymore because we just unzipped its contents. - } - - - } else { - LOGGER.error("launch as 'java -jar to get maven to install"); - } - - } catch (Exception e) { - throw new Snail4jException(e); - } - } - - protected void installMaven() throws Snail4jException { - PathUtil pathUtil = new PathUtil(); - String path = pathUtil.getBaseClassspath(); - String cleansedPath; - try { - Path targetMavenZipFile = Paths.get( this.getConfiguration().getSnail4jHome().toString(), this.getConfiguration().getMavenZipFileName() ); - if (pathUtil.isUberJar()) { - - /** - * maven zip needs to be extracted from executable jar file - */ - cleansedPath = pathUtil.cleanPath(path); - if ( !this.getConfiguration().getMavenHome().toFile().exists() ) { - LOGGER.info("About to unzip [" + this.getConfiguration().getMavenZipFileName() + "] from [" + cleansedPath + "] to [" + targetMavenZipFile + "]"); - pathUtil.extractZipFromZip(cleansedPath, this.getConfiguration().getMavenZipFileName(), targetMavenZipFile.toString() ); - - LOGGER.info("does [" + targetMavenZipFile.toFile().getAbsolutePath().toString() + "] exist? [" + targetMavenZipFile.toFile().exists() + "]" ); - - pathUtil.unzip(targetMavenZipFile.toFile(), this.getConfiguration().getSnail4jHome().toString() ); - targetMavenZipFile.toFile().delete(); - } - if (!this.getConfiguration().isOsWin() ) { - File mavenBinFolder = new File(this.getConfiguration().getMavenHome().toFile(), "bin"); - File mavenExe = new File( mavenBinFolder, "mvn"); - if (mavenExe.exists()) { - String cmd = "chmod +x " + mavenExe.getAbsolutePath().toString(); - OsUtils.executeProcess_bash(cmd, mavenBinFolder); - } else { - String err= "java.util.File is reporting that the maven executable doesn't exist. [" + mavenExe.toString() + "]. Cmon, we just installed it. It should be there!"; - LOGGER.error(err); - throw new Snail4jException(err); - } - } - } else { - LOGGER.error("launch as 'java -jar to get maven to install"); - } - } catch (Exception e) { - throw new Snail4jException(e); - } - - - } - @Override - public void error(String msg) { - System.out.println(LOG_PREFIX + "ERROR: " + msg); - } - @Override - public void info(String msg) { - System.out.println(LOG_PREFIX+ "INFO: " + msg); - } - @Override - public void debug(String msg) { - if (LOGGER.isDebugEnabled()) - System.out.println(LOG_PREFIX+"DEBUG: "+msg); - } - - @Override - public void warn(String msg) { - // TODO Auto-generated method stub - - } - -} diff --git a/backend/src/main/java/com/github/eostermueller/snail4j/install/package-info.java b/backend/src/main/java/com/github/eostermueller/snail4j/install/package-info.java deleted file mode 100644 index f12c33f..0000000 --- a/backend/src/main/java/com/github/eostermueller/snail4j/install/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.github.eostermueller.snail4j.install; \ No newline at end of file diff --git a/backend/src/main/java/com/github/eostermueller/snail4j/launcher/BootstrapConfig.java b/backend/src/main/java/com/github/eostermueller/snail4j/launcher/BootstrapConfig.java index 8b910b1..3b1bc30 100644 --- a/backend/src/main/java/com/github/eostermueller/snail4j/launcher/BootstrapConfig.java +++ b/backend/src/main/java/com/github/eostermueller/snail4j/launcher/BootstrapConfig.java @@ -6,10 +6,12 @@ import java.nio.file.Paths; import com.github.eostermueller.snail4j.Application; +import com.github.eostermueller.snail4j.systemproperty.SystemPropertyManager; +import com.github.eostermueller.snail4j.systemproperty.SystemPropertyManagerImpl; /** * just the bare minimum required to find and read the snail4j.json config file. - * Currently, user cannot change any of these settings, like ".load-test-i-a-box" folder and "snail4j.json" config file name. + * Currently, user cannot change any of these settings, like ".load-test-in-a-box" folder and "load-test-in-a-box.json" config file name. * @author erikostermueller * */ @@ -24,7 +26,30 @@ public BootstrapConfig() { Application.INSTALL_ROOT, Application.CONFIG_FILE_NAME); } - public void createSnail4jHomeIfNotExist() throws CannotFindSnail4jFactoryClass { + static SystemPropertyManager SYSTEM_PROPERTY_MGR_SINGLETON = new SystemPropertyManagerImpl(); + + public SystemPropertyManager getSystemPropertyMgr() { + return SYSTEM_PROPERTY_MGR_SINGLETON; + } + /** + * Must only be called during JUnit tests!!!! + * @param testRepo + */ + public void setSystemPropertyTestValueRepo(SystemPropertyManager testRepo) { + SystemPropertyManagerImpl impl = (SystemPropertyManagerImpl) this.getSystemPropertyMgr(); + impl.setSystemPropertyTestValueRepository(testRepo); + } + /** + * calling this is Required at the end of unit tests that invoke Factory#setSystemPropertyTestValueRepo(); + * ...calling this does no harm (nor provides any particular benefit) in production code. + * Calling this wipes out all JUnit system properties defined by Factory#setSystemPropertyTestValueRepo() ). + * + */ + public void resetUnitTestSystemProperties() { + setSystemPropertyTestValueRepo(null); + } + + public void createLoadTestInABoxHomeIfNotExist() throws CannotFindSnail4jFactoryClass { File snail4jHomeDir = getSnail4jHome().toFile(); if (!snail4jHomeDir.exists()) snail4jHomeDir.mkdirs(); diff --git a/backend/src/main/java/com/github/eostermueller/snail4j/launcher/DefaultConfiguration.java b/backend/src/main/java/com/github/eostermueller/snail4j/launcher/DefaultConfiguration.java index 3418282..dac12a6 100644 --- a/backend/src/main/java/com/github/eostermueller/snail4j/launcher/DefaultConfiguration.java +++ b/backend/src/main/java/com/github/eostermueller/snail4j/launcher/DefaultConfiguration.java @@ -13,7 +13,10 @@ import com.github.eostermueller.snail4j.Application; import com.github.eostermueller.snail4j.DefaultFactory; import com.github.eostermueller.snail4j.Snail4jException; +import com.github.eostermueller.snail4j.systemproperty.BooleanSystemProperty; +import com.github.eostermueller.snail4j.systemproperty.BooleanSystemPropertyImpl; import com.github.eostermueller.snail4j.systemproperty.Headless; +import com.github.eostermueller.snail4j.systemproperty.SystemPropertyManagerImpl; import com.github.eostermueller.snail4j.util.NonStaticOsUtils; /** @@ -262,17 +265,15 @@ public DefaultConfiguration() throws Snail4jException { this.setSutClassName("com.github.eostermueller.tjp2.PerformanceSandboxApp"); - this.setMinDiskSpaceAvailableRequirementInBytes(3*1024*1024*1024 /* 3g */); + this.setMinDiskSpaceAvailableRequirementInBytes(2L*1024*1024*1024 /* 2g */); /** When I tested with Shawn's 4G linux vm, it failed. * Let's assume that 1 of those g was for linux. * ...and so if he had a 5g VM with 4g free, we probably would have been ok. */ - this.setMinMemoryAvailableRequirementInBytes (4*1024*1024*1024 /* 4g */); + this.setMinMemoryAvailableRequirementInBytes (3L*1024*1024*1024 /* 3g */); + - this.setHeadless( - DefaultFactory.getFactory().getSystemPropertyMgr().getBoolean( new Headless() ) - ); } /* diff --git a/backend/src/main/java/com/github/eostermueller/snail4j/launcher/Factory.java b/backend/src/main/java/com/github/eostermueller/snail4j/launcher/Factory.java index 2f2a621..f368a6c 100644 --- a/backend/src/main/java/com/github/eostermueller/snail4j/launcher/Factory.java +++ b/backend/src/main/java/com/github/eostermueller/snail4j/launcher/Factory.java @@ -10,8 +10,22 @@ import com.github.eostermueller.snail4j.processmodel.LoadGenerator; import com.github.eostermueller.snail4j.processmodel.ProcessModelBuilder; import com.github.eostermueller.snail4j.processmodel.SystemUnderTest; +import com.github.eostermueller.snail4j.systemproperty.OneTimeConfigChanger; import com.github.eostermueller.snail4j.systemproperty.SystemPropertyManager; +/** + * These methods + *
    + *
  • SystemPropertyManager getSystemPropertyMgr();
  • + *
  • void setSystemPropertyTestValueRepo(SystemPropertyManager testRepo);
  • + *
  • void resetUnitTestSystemProperties();
  • + + *
      + used to be in here, but that created a cyclic dependency + + * @author eoste + * + */ public interface Factory { /** @@ -55,17 +69,12 @@ public interface Factory { Installer createSutInstaller() throws Snail4jException; - SystemPropertyManager getSystemPropertyMgr(); - /** - * Must only be called during JUnit tests!!!! - * @param testRepo - */ - void setSystemPropertyTestValueRepo(SystemPropertyManager testRepo); - void resetUnitTestSystemProperties(); AvailableMemoryValidator getAvailableMemoryValidator() throws Snail4jException; DiskSpaceValidator getDiskSpaceValidator() throws Snail4jException; GenericConfigFileReaderWriter getGenericConfigReaderWriter(); + + OneTimeConfigChanger[] getOneTimeDashDSystemPropertyConfigChanges(); } \ No newline at end of file diff --git a/backend/src/main/java/com/github/eostermueller/snail4j/launcher/Messages.java b/backend/src/main/java/com/github/eostermueller/snail4j/launcher/Messages.java index e0c83a3..79586ee 100644 --- a/backend/src/main/java/com/github/eostermueller/snail4j/launcher/Messages.java +++ b/backend/src/main/java/com/github/eostermueller/snail4j/launcher/Messages.java @@ -4,6 +4,8 @@ import java.nio.file.Path; import java.util.List; +import com.github.eostermueller.snail4j.systemproperty.SutGitCloneUrl; + public interface Messages { String warning(); @@ -102,5 +104,6 @@ String getSutStopMessage(String humanReadableString, String absolutePath, boolea String insufficientMemory(long actualMemoryAvailabilInBytes, long minMemoryAvailableRequirementInBytes); String abortingInstall(Exception e); String docForHeadlessProperty(); + String getDocForDeleteSut(); } \ No newline at end of file diff --git a/backend/src/main/java/com/github/eostermueller/snail4j/launcher/Messages_en_US.java b/backend/src/main/java/com/github/eostermueller/snail4j/launcher/Messages_en_US.java index f54fd1c..3a45f6d 100644 --- a/backend/src/main/java/com/github/eostermueller/snail4j/launcher/Messages_en_US.java +++ b/backend/src/main/java/com/github/eostermueller/snail4j/launcher/Messages_en_US.java @@ -255,7 +255,7 @@ public String abortingInstall(Exception e) { */ @Override public String insufficientMemory(long actualMemoryAvailabilInBytes, long minMemoryAvailableRequirementInBytes) { - return String.format("Insufficient memory. Consider adding more RAM or stopping programs to free up existing RAM. \nExpected min RAM: %,d\nCurrentActual RAM: %,d\n", minMemoryAvailableRequirementInBytes, actualMemoryAvailabilInBytes); + return String.format("Insufficient memory. Consider adding more RAM or stopping programs to free up existing RAM. \nExpected min available RAM: %,d\nActual available RAM: %,d\n", minMemoryAvailableRequirementInBytes, actualMemoryAvailabilInBytes); } @Override @@ -289,7 +289,7 @@ public String getAvailableMemoryValidationDoc() { @Override public String getDeleteSutDoc() { - return String.format("Setting this to 'true' will delete the $HOME/.load-test-in-a-box/sutApp folder before starting the uber jar (aka, agent). The property [%s] is required with this property.", new SutGitCloneUrl().getDashDProperty() ); + return String.format("Setting this to 'true' will delete the $HOME/.load-test-in-a-box/sutApp folder before starting the uber jar (aka, agent). The property [%s] is required with this property.", new SutGitCloneUrl().getDashDPropertyName() ); } @Override @@ -320,5 +320,11 @@ public String javaHomeFolderDoesNotExistOrLackingPermissions(File javaHomeFolder public String docForHeadlessProperty() { return "Remote machines can access glowroot only when set to true. Like all properties with 'config' in the name, using this property on agent startup will permanently set the property until altered using the same system property. Corresponds to the 'headless' attribute in [" + Application.CONFIG_FILE_NAME + "] See https://github.com/glowroot/glowroot/wiki/Agent-Installation-%28with-Embedded-Collector%29#optional-post-installation-steps"; } + + @Override + public String getDocForDeleteSut() { + return "CAUTION. When set to true, deletes $HOME/.load-test-in-a-box/sutApp -- the folder where the SUT resides." + + "When [" + new SutGitCloneUrl().getDashDPropertyName() + "] is also set to true, the git URL will be put into place in sutApp AFTER the sutApp folder has been deleted. "; + } } \ No newline at end of file diff --git a/backend/src/main/java/com/github/eostermueller/snail4j/package-info.java b/backend/src/main/java/com/github/eostermueller/snail4j/package-info.java deleted file mode 100644 index 1a6b6cd..0000000 --- a/backend/src/main/java/com/github/eostermueller/snail4j/package-info.java +++ /dev/null @@ -1,8 +0,0 @@ -/** - * - */ -/** - * @author eostermueller - * - */ -package com.github.eostermueller.snail4j; \ No newline at end of file diff --git a/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/AvailableDiskSpaceValidation.java b/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/AvailableDiskSpaceValidation.java index 381adad..3f40225 100644 --- a/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/AvailableDiskSpaceValidation.java +++ b/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/AvailableDiskSpaceValidation.java @@ -12,12 +12,13 @@ public boolean getDefaultValue() { @Override public String getHumanReadableDocumentation() throws CannotFindSnail4jFactoryClass { - return DefaultFactory.getFactory().getMessages().getDeleteSutDoc(); + return DefaultFactory.getFactory().getMessages().getAvailableDiskSizeValidationDoc(); } @Override - public String getDashDProperty() { - return "com.github.eostermueller.snail4j.delete.sut"; + public String getDashDPropertyName() { + return "com.github.eostermueller.snail4j.available.disk.space.validation"; } + } diff --git a/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/AvailableMemoryValidation.java b/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/AvailableMemoryValidation.java index dfbc749..1949bf5 100644 --- a/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/AvailableMemoryValidation.java +++ b/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/AvailableMemoryValidation.java @@ -17,7 +17,7 @@ public String getHumanReadableDocumentation() throws CannotFindSnail4jFactoryCla } @Override - public String getDashDProperty() { + public String getDashDPropertyName() { return "com.github.eostermueller.snail4j.available.memory.size.validation"; } diff --git a/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/BooleanSystemPropertyImpl.java b/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/BooleanSystemPropertyImpl.java index 011427f..824dbc8 100644 --- a/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/BooleanSystemPropertyImpl.java +++ b/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/BooleanSystemPropertyImpl.java @@ -1,6 +1,5 @@ package com.github.eostermueller.snail4j.systemproperty; -import com.github.eostermueller.snail4j.DefaultFactory; import com.github.eostermueller.snail4j.Snail4jException; import com.github.eostermueller.snail4j.util.StringUtils; @@ -8,11 +7,12 @@ public abstract class BooleanSystemPropertyImpl implements BooleanSystemProperty public boolean getValue() throws Snail4jException { boolean rc = getBooleanParameter( - this.getDashDProperty(), + this.getDashDPropertyName(), this.getDefaultValue() ); return rc; } + private boolean getBooleanParameter(String dashDVariableName, boolean boolDefault) throws Snail4jException { boolean rc = boolDefault; String value = System.getProperty(dashDVariableName); @@ -21,5 +21,4 @@ private boolean getBooleanParameter(String dashDVariableName, boolean boolDefaul } return rc; } - } diff --git a/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/DeleteSut.java b/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/DeleteSut.java index a5e42c4..21da387 100644 --- a/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/DeleteSut.java +++ b/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/DeleteSut.java @@ -7,18 +7,18 @@ public class DeleteSut extends BooleanSystemPropertyImpl { @Override public boolean getDefaultValue() { - return true; + return false; } @Override public String getHumanReadableDocumentation() throws CannotFindSnail4jFactoryClass { - return DefaultFactory.getFactory().getMessages().getAvailableMemoryValidationDoc(); + return DefaultFactory.getFactory().getMessages().getDocForDeleteSut(); } @Override - public String getDashDProperty() { - return "com.github.eostermueller.snail4j.available.memory.size.validation"; + public String getDashDPropertyName() { + return "com.github.eostermueller.snail4j.delete.sut"; } } diff --git a/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/Headless.java b/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/Headless.java index 9d3f3ca..b071043 100644 --- a/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/Headless.java +++ b/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/Headless.java @@ -1,9 +1,11 @@ package com.github.eostermueller.snail4j.systemproperty; import com.github.eostermueller.snail4j.DefaultFactory; +import com.github.eostermueller.snail4j.Snail4jException; import com.github.eostermueller.snail4j.launcher.CannotFindSnail4jFactoryClass; +import com.github.eostermueller.snail4j.launcher.Configuration; -public class Headless extends BooleanSystemPropertyImpl { +public class Headless extends BooleanSystemPropertyImpl implements OneTimeConfigChanger { @Override public String getHumanReadableDocumentation() throws CannotFindSnail4jFactoryClass { @@ -11,7 +13,7 @@ public String getHumanReadableDocumentation() throws CannotFindSnail4jFactoryCla } @Override - public String getDashDProperty() { + public String getDashDPropertyName() { return "com.github.eostermueller.snail4j.config.headless"; } @@ -22,4 +24,12 @@ public String getDashDProperty() { public boolean getDefaultValue() { return false; } + + @Override + public void oneTimeChange(Configuration cfg) throws Snail4jException { + cfg.setHeadless( + new SystemPropertyManagerImpl().getBoolean( this ) + ); + + } } diff --git a/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/LongSystemPropertyImpl.java b/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/LongSystemPropertyImpl.java index 512c15e..dc2964c 100644 --- a/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/LongSystemPropertyImpl.java +++ b/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/LongSystemPropertyImpl.java @@ -10,7 +10,7 @@ public long getValue() throws Snail4jException { } private long getLongParameter() throws Snail4jException { long rc = this.getDefaultValue(); - String value = System.getProperty(this.getDashDProperty()); + String value = System.getProperty(this.getDashDPropertyName()); if (value != null && value.length() > 0) { try { rc = Long.parseLong(value); diff --git a/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/StringSystemPropertyImpl.java b/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/StringSystemPropertyImpl.java index 237a038..9e16a7e 100644 --- a/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/StringSystemPropertyImpl.java +++ b/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/StringSystemPropertyImpl.java @@ -5,7 +5,7 @@ public abstract class StringSystemPropertyImpl implements StringSystemProperty { public String getValue() { String rc = getStringParameter( - this.getDashDProperty(), + this.getDashDPropertyName(), this.getDefaultValue() ); return rc; diff --git a/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/SutGitCloneUrl.java b/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/SutGitCloneUrl.java index e6f9b60..9879aeb 100644 --- a/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/SutGitCloneUrl.java +++ b/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/SutGitCloneUrl.java @@ -12,7 +12,7 @@ public String getDefaultValue() { } @Override - public String getDashDProperty() { + public String getDashDPropertyName() { return "com.github.eostermueller.snail4j.sutGitCloneUrl"; } diff --git a/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/SystemProperty.java b/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/SystemProperty.java index 2bfecd3..ebdc18a 100644 --- a/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/SystemProperty.java +++ b/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/SystemProperty.java @@ -3,12 +3,11 @@ import com.github.eostermueller.snail4j.launcher.CannotFindSnail4jFactoryClass; public interface SystemProperty { - String getHumanReadableDocumentation() throws CannotFindSnail4jFactoryClass; /** * Name of a JVM "System Property" used by load-test-in-a-box * https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html */ - String getDashDProperty(); + String getDashDPropertyName(); } diff --git a/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/package-info.java b/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/package-info.java deleted file mode 100644 index c824394..0000000 --- a/backend/src/main/java/com/github/eostermueller/snail4j/systemproperty/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.github.eostermueller.snail4j.systemproperty; \ No newline at end of file diff --git a/backend/src/main/java/com/github/eostermueller/snail4j/util/package-info.java b/backend/src/main/java/com/github/eostermueller/snail4j/util/package-info.java deleted file mode 100644 index 17f91d4..0000000 --- a/backend/src/main/java/com/github/eostermueller/snail4j/util/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.github.eostermueller.snail4j.util; \ No newline at end of file diff --git a/backend/src/test/java/com/github/eostermueller/snail4j/systemproperty/SystemPropertyTestValueRepoImpl.java b/backend/src/test/java/com/github/eostermueller/snail4j/systemproperty/SystemPropertyTestValueRepoImpl.java index c10026c..2470d3e 100644 --- a/backend/src/test/java/com/github/eostermueller/snail4j/systemproperty/SystemPropertyTestValueRepoImpl.java +++ b/backend/src/test/java/com/github/eostermueller/snail4j/systemproperty/SystemPropertyTestValueRepoImpl.java @@ -37,8 +37,8 @@ public class SystemPropertyTestValueRepoImpl implements SystemPropertyManager, S public boolean getBoolean(BooleanSystemProperty systemProperty) throws Snail4jException { boolean rc; - if (booleanSystemProperties.containsKey(systemProperty.getDashDProperty())) - rc = booleanSystemProperties.get(systemProperty.getDashDProperty()); + if (booleanSystemProperties.containsKey(systemProperty.getDashDPropertyName())) + rc = booleanSystemProperties.get(systemProperty.getDashDPropertyName()); else rc = systemProperty.getDefaultValue(); @@ -49,8 +49,8 @@ public boolean getBoolean(BooleanSystemProperty systemProperty) throws Snail4jEx public long getLong(LongSystemProperty systemProperty) throws Snail4jException { long rc; - if (longSystemProperties.containsKey(systemProperty.getDashDProperty())) - rc = longSystemProperties.get(systemProperty.getDashDProperty()); + if (longSystemProperties.containsKey(systemProperty.getDashDPropertyName())) + rc = longSystemProperties.get(systemProperty.getDashDPropertyName()); else rc = systemProperty.getDefaultValue(); @@ -61,8 +61,8 @@ public long getLong(LongSystemProperty systemProperty) throws Snail4jException { public String getString(StringSystemProperty systemProperty) { String rc; - if (stringSystemProperties.containsKey(systemProperty.getDashDProperty())) - rc = stringSystemProperties.get(systemProperty.getDashDProperty()); + if (stringSystemProperties.containsKey(systemProperty.getDashDPropertyName())) + rc = stringSystemProperties.get(systemProperty.getDashDPropertyName()); else rc = systemProperty.getDefaultValue(); @@ -71,17 +71,17 @@ public String getString(StringSystemProperty systemProperty) { /**/ @Override public void setBoolean(BooleanSystemProperty systemProperty, boolean val) throws Snail4jException { - booleanSystemProperties.put(systemProperty.getDashDProperty(),new Boolean(val) ); + booleanSystemProperties.put(systemProperty.getDashDPropertyName(),new Boolean(val) ); } @Override public void setLong(LongSystemProperty systemProperty, long val) throws Snail4jException { - longSystemProperties.put(systemProperty.getDashDProperty(),new Long(val)); + longSystemProperties.put(systemProperty.getDashDPropertyName(),new Long(val)); } @Override public void setString(StringSystemProperty systemProperty, String s) { - stringSystemProperties.put(systemProperty.getDashDProperty(), s); + stringSystemProperties.put(systemProperty.getDashDPropertyName(), s); } } diff --git a/backend/src/test/java/com/github/eostermueller/snail4j/systemproperty/test/FluxCapacitorTestBoolean.java b/backend/src/test/java/com/github/eostermueller/snail4j/systemproperty/test/FluxCapacitorTestBoolean.java index f3f1d6d..8caf593 100644 --- a/backend/src/test/java/com/github/eostermueller/snail4j/systemproperty/test/FluxCapacitorTestBoolean.java +++ b/backend/src/test/java/com/github/eostermueller/snail4j/systemproperty/test/FluxCapacitorTestBoolean.java @@ -5,6 +5,7 @@ import com.github.eostermueller.snail4j.DefaultFactory; import com.github.eostermueller.snail4j.Snail4jException; +import com.github.eostermueller.snail4j.launcher.BootstrapConfig; import com.github.eostermueller.snail4j.launcher.CannotFindSnail4jFactoryClass; import com.github.eostermueller.snail4j.systemproperty.BooleanSystemPropertyImpl; import com.github.eostermueller.snail4j.systemproperty.SystemPropertyTestValueRepoImpl; @@ -26,7 +27,7 @@ public void canSetFluxCapacitorValueForUnitTest() throws Snail4jException { //Create this object where system property values for JUnit tests will be kept. SystemPropertyTestValueRepoImpl repo = new SystemPropertyTestValueRepoImpl(); //Make the junit values available to the load-test-in-a-box code base. - DefaultFactory.getFactory().setSystemPropertyTestValueRepo(repo); + new BootstrapConfig().setSystemPropertyTestValueRepo(repo); repo.setBoolean(new FluxCapacitorActivator(), true); @@ -37,7 +38,7 @@ public void canSetFluxCapacitorValueForUnitTest() throws Snail4jException { Assertions.assertEquals(true,thingy.isFluxCapacitorActivated()); } finally { - DefaultFactory.getFactory().resetUnitTestSystemProperties(); //required in unit tests, does not harm in production + new BootstrapConfig().resetUnitTestSystemProperties(); //required in unit tests, does not harm in production } } @@ -57,7 +58,7 @@ public void setFluxCapacitorActivated(boolean fluxCapacitorActivated) { public YourClassThatUsesBooleanSystemProperty() throws Snail4jException { setFluxCapacitorActivated( //This line shows how to get value of the system property. - DefaultFactory.getFactory().getSystemPropertyMgr().getBoolean( new FluxCapacitorActivator() ) + new BootstrapConfig().getSystemPropertyMgr().getBoolean( new FluxCapacitorActivator() ) ); } } @@ -85,7 +86,7 @@ public String getHumanReadableDocumentation() throws CannotFindSnail4jFactoryCla } @Override - public String getDashDProperty() { + public String getDashDPropertyName() { return "com.github.eostermueller.test.snail4j.flux.capacitor.activation"; } } diff --git a/backend/src/test/java/com/github/eostermueller/snail4j/systemproperty/test/FluxCapacitorTestLong.java b/backend/src/test/java/com/github/eostermueller/snail4j/systemproperty/test/FluxCapacitorTestLong.java index 737f046..497377c 100644 --- a/backend/src/test/java/com/github/eostermueller/snail4j/systemproperty/test/FluxCapacitorTestLong.java +++ b/backend/src/test/java/com/github/eostermueller/snail4j/systemproperty/test/FluxCapacitorTestLong.java @@ -5,8 +5,8 @@ import com.github.eostermueller.snail4j.DefaultFactory; import com.github.eostermueller.snail4j.Snail4jException; +import com.github.eostermueller.snail4j.launcher.BootstrapConfig; import com.github.eostermueller.snail4j.launcher.CannotFindSnail4jFactoryClass; -import com.github.eostermueller.snail4j.systemproperty.BooleanSystemPropertyImpl; import com.github.eostermueller.snail4j.systemproperty.LongSystemPropertyImpl; import com.github.eostermueller.snail4j.systemproperty.SystemPropertyTestValueRepoImpl; @@ -28,7 +28,7 @@ public void canSetFluxCapacitorValueForUnitTest() throws Snail4jException { //Create this object where system property values for JUnit tests will be kept. SystemPropertyTestValueRepoImpl repo = new SystemPropertyTestValueRepoImpl(); //Make the junit values available to the load-test-in-a-box code base. - DefaultFactory.getFactory().setSystemPropertyTestValueRepo(repo); + new BootstrapConfig().setSystemPropertyTestValueRepo(repo); repo.setLong(new FluxCapacitorPowerCap(), 8675309);//rememberable number @@ -38,7 +38,7 @@ public void canSetFluxCapacitorValueForUnitTest() throws Snail4jException { //Confirm that pink.flux.capacitor is found Assertions.assertEquals(8675309,thingy.getFluxCapacitorPowerCap()); } finally { - DefaultFactory.getFactory().resetUnitTestSystemProperties(); + new BootstrapConfig().resetUnitTestSystemProperties(); } } } @@ -59,7 +59,7 @@ public void setFluxCapacitorPowerCap(long fluxCapacitorPowerCap) { public YourClassThatUsesLongSystemProperty() throws Snail4jException { setFluxCapacitorPowerCap( //This line shows how to get value of the system property. - DefaultFactory.getFactory().getSystemPropertyMgr().getLong( new FluxCapacitorPowerCap() ) + new BootstrapConfig().getSystemPropertyMgr().getLong( new FluxCapacitorPowerCap() ) ); } } @@ -86,7 +86,7 @@ public String getHumanReadableDocumentation() throws CannotFindSnail4jFactoryCla } @Override - public String getDashDProperty() { + public String getDashDPropertyName() { return "com.github.eostermueller.test.snail4j.flux.capacitor.power.cap"; } diff --git a/backend/src/test/java/com/github/eostermueller/snail4j/systemproperty/test/FluxCapacitorTestString.java b/backend/src/test/java/com/github/eostermueller/snail4j/systemproperty/test/FluxCapacitorTestString.java index 4a280a1..68d0160 100644 --- a/backend/src/test/java/com/github/eostermueller/snail4j/systemproperty/test/FluxCapacitorTestString.java +++ b/backend/src/test/java/com/github/eostermueller/snail4j/systemproperty/test/FluxCapacitorTestString.java @@ -4,6 +4,7 @@ import org.junit.jupiter.api.Test; import com.github.eostermueller.snail4j.DefaultFactory; +import com.github.eostermueller.snail4j.launcher.BootstrapConfig; import com.github.eostermueller.snail4j.launcher.CannotFindSnail4jFactoryClass; import com.github.eostermueller.snail4j.systemproperty.StringSystemPropertyImpl; import com.github.eostermueller.snail4j.systemproperty.SystemPropertyTestValueRepoImpl; @@ -13,7 +14,7 @@ public class FluxCapacitorTestString { @Test public void canFindDefaultFluxCapacitor() throws CannotFindSnail4jFactoryClass { - DefaultFactory.getFactory().setSystemPropertyTestValueRepo(null);//Purge values from previous unit tests + new BootstrapConfig().setSystemPropertyTestValueRepo(null);//Purge values from previous unit tests YourClassThatUsesSystemProperty thingy = new YourClassThatUsesSystemProperty(); Assertions.assertEquals(FluxCapacitorName.WARP,thingy.getFluxCapacitorName()); @@ -26,7 +27,7 @@ public void canSetFluxCapacitorValueForUnitTest() throws CannotFindSnail4jFactor //Create this object where system property values for JUnit tests will be kept. SystemPropertyTestValueRepoImpl repo = new SystemPropertyTestValueRepoImpl(); //Make the junit values available to the load-test-in-a-box code base. - DefaultFactory.getFactory().setSystemPropertyTestValueRepo(repo); + new BootstrapConfig().setSystemPropertyTestValueRepo(repo); repo.setString(new FluxCapacitorName(), "pink.flux.capacitor"); @@ -36,7 +37,7 @@ public void canSetFluxCapacitorValueForUnitTest() throws CannotFindSnail4jFactor //Confirm that pink.flux.capacitor is found Assertions.assertEquals(thingy.getFluxCapacitorName(),"pink.flux.capacitor"); } finally { - DefaultFactory.getFactory().resetUnitTestSystemProperties(); //required in unit tests, does not harm in production + new BootstrapConfig().resetUnitTestSystemProperties(); //required in unit tests, does not harm in production } } } @@ -47,7 +48,7 @@ class YourClassThatUsesSystemProperty { public YourClassThatUsesSystemProperty() throws CannotFindSnail4jFactoryClass { setFluxCapacitorName( //This line shows how to get value of the system property. - DefaultFactory.getFactory().getSystemPropertyMgr().getString( new FluxCapacitorName() ) + new BootstrapConfig().getSystemPropertyMgr().getString( new FluxCapacitorName() ) ); } @@ -84,7 +85,7 @@ public String getHumanReadableDocumentation() throws CannotFindSnail4jFactoryCla } @Override - public String getDashDProperty() { + public String getDashDPropertyName() { return "com.github.eostermueller.test.snail4j.flux.capacitor.name"; } diff --git a/build/packageFast.sh b/build/packageFast.sh index 02755fb..de7232b 100755 --- a/build/packageFast.sh +++ b/build/packageFast.sh @@ -51,3 +51,5 @@ echo to trim uber jar size, deleting unused copies of snail4js own uber jar from echo Number of files to be deleted: $( ls -lart $MAVEN_LOCAL_REPO/repository/${SNAIL4J_MVN_DIR}/*.jar 2>/dev/null | wc -l ) echo sizes of files to be deleted: $( ls -lart $MAVEN_LOCAL_REPO/repository/${SNAIL4J_MVN_DIR}/*.jar 2>/dev/null ) rm -rf $MAVEN_LOCAL_REPO/repository/${SNAIL4J_MVN_DIR}/*.jar +echo about to delete robolectric maven repo folder -- 131412304 bytes!!! ./android-all/10-robolectric-5803371/android-all-10-robolectric-5803371.jar +rm -rf $MAVEN_LOCAL_REPO/repository/org/robolectric diff --git a/build/packageSlow.sh b/build/packageSlow.sh index 2501fd5..579d9d7 100755 --- a/build/packageSlow.sh +++ b/build/packageSlow.sh @@ -51,5 +51,5 @@ ls -lart $TARGET/${MVN_ZIP_NAME} echo Downloading Glowroot from $GLOWROOT_BIN # without the -L, curl doesn't handle the REDIRECT that github uses -curl -L -o $TARGET/${GLOWROOT_DIST_ZIP} -O $GLOWROOT_BIN +curl -L -o $TARGET/${GLOWROOT_INSTALL_ZIP} -O $GLOWROOT_BIN echo CHECKPOINT: Just downloaded $TARGET/${GLOWROOT_DIST_ZIP} : $( ls -lart $TARGET/${GLOWROOT_DIST_ZIP} ) diff --git a/build/setenv_02.sh b/build/setenv_02.sh index d69042c..992a2cb 100755 --- a/build/setenv_02.sh +++ b/build/setenv_02.sh @@ -61,7 +61,7 @@ H2_MAVEN_PLUGIN_DIR=$SRC_DIR/load-test-in-a-box_m2-plugin_h2 GLOWROOT_VERSION=0.14.0-beta.3 GLOWROOT_DIST_ZIP=glowroot-${GLOWROOT_VERSION}-dist.zip GLOWROOT_BIN=https://github.com/glowroot/glowroot/releases/download/v${GLOWROOT_VERSION}/${GLOWROOT_DIST_ZIP} - +GLOWROOT_INSTALL_ZIP=glowroot.zip MVN_VERSION=3.6.3 MVN_ZIP_NAME=apache-maven-${MVN_VERSION}-bin.zip MVN_URL=https://downloads.apache.org/maven/maven-3/${MVN_VERSION}/binaries/${MVN_ZIP_NAME} diff --git a/frontend/src/main/web/src/app/health-checks/health-checks.component.ts b/frontend/src/main/web/src/app/health-checks/health-checks.component.ts index 53db7ca..a8e0916 100644 --- a/frontend/src/main/web/src/app/health-checks/health-checks.component.ts +++ b/frontend/src/main/web/src/app/health-checks/health-checks.component.ts @@ -50,14 +50,21 @@ export class HealthChecksComponent implements OnInit { * @stolenFrom: https://stackblitz.com/edit/angular-abcqen */ ngOnInit() { + + + var glowrootHostName = "localhost"; //By default assume that Angular UI runs as same machine as java uber jar + + if (this.config.headless) { //Can by set by uber jar -D parameter com.github.eostermueller.config.headless=true or in the load-test-in-a-box.json file (headless property). + /** + * Insure URL to glowroot has hostname so that a machine across a network from where uber jar is deployed can load glowroot. + */ + glowrootHostName = this.config.sutAppHostname; + } + //set a 3 minute timerange, because //locating perf changes in longer timeframes (like default 30 minutes) is really difficult -// this.sutGlowrootUrl = 'http://localhost:' + this.config.glowrootPort + '/transaction/average?transaction-type=Web&last=180000'; + this.sutGlowrootUrl = 'http://' + glowrootHostName + ':' + this.config.glowrootPort + '/transaction/average?transaction-type=Web&last=180000'; - //The above is nice, but the glowroot link on the snail4j UI won't be correct - //if your browser is on a separate machine from the SUT :-( - //To Fix that, use this line instead: - this.sutGlowrootUrl = 'http://' + this.config.sutAppHostname + ':' + this.config.glowrootPort + '/transaction/average?transaction-type=Web&last=180000'; // Then the install should edit the following file: // $HOME/.snail4j/glowroot/glowroot/admin.json ///to have "web": { diff --git a/frontend/src/main/web/src/app/services/config.model.ts b/frontend/src/main/web/src/app/services/config.model.ts index d7f54ce..37eec0d 100644 --- a/frontend/src/main/web/src/app/services/config.model.ts +++ b/frontend/src/main/web/src/app/services/config.model.ts @@ -12,6 +12,7 @@ export interface ConfigModel { sutAppHostname : string; mavenExePath : string; mavenOnline : boolean; + headless : boolean; snail4jMavenRepo : boolean; wiremockHostname : string; wiremockPort : number;