Skip to content

Commit

Permalink
release 0.0.4b
Browse files Browse the repository at this point in the history
  • Loading branch information
eostermueller committed Feb 12, 2023
1 parent 2e461fa commit 55a2ad8
Show file tree
Hide file tree
Showing 37 changed files with 302 additions and 762 deletions.
14 changes: 8 additions & 6 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,12 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>6.2.0.202206071550-r</version>
</dependency>
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>5.13.1.202206130422-r</version>
</dependency>

<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
Expand Down Expand Up @@ -240,7 +241,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}


/**
Expand All @@ -95,14 +88,32 @@ public void setConfiguration(Configuration cfg) {
this.configuration = cfg;
}
}
@Override
public OneTimeConfigChanger[] getOneTimeDashDSystemPropertyConfigChanges() {
List<OneTimeConfigChanger> oneTimeConfigChangers = new ArrayList<OneTimeConfigChanger>();
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();
}
@Override
public Configuration getConfiguration() throws Snail4jException {
return getConfiguration( new BootstrapConfig() );
}
}

@Override
public Configuration getConfiguration(BootstrapConfig bootstrapConfig) throws Snail4jException {
if (this.configuration == null) {
Expand All @@ -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<Configuration> configurationClass = (Class<Configuration>) 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) {
Expand Down Expand Up @@ -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
Expand All @@ -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() {
Expand Down Expand Up @@ -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 {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
* <pre>
* 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
* </pre
* @author eoste
*
*/
public class AvailableMemoryValidatorImpl implements AvailableMemoryValidator {

public AvailableMemoryValidatorImpl() throws Snail4jException {

this.setAvailableMemoryValidationActive( DefaultFactory.getFactory().getSystemPropertyMgr().getBoolean(new AvailableMemoryValidation()));

this.setActualMemoryAvailableInBytes( Runtime.getRuntime().freeMemory() );
this.setAvailableMemoryValidationActive( new BootstrapConfig().getSystemPropertyMgr().getBoolean(new AvailableMemoryValidation()));

com.sun.management.OperatingSystemMXBean bean =
(com.sun.management.OperatingSystemMXBean)
java.lang.management.ManagementFactory.getOperatingSystemMXBean();

this.setActualMemoryAvailableInBytes( bean.getFreePhysicalMemorySize() );

}
private long minMemoryAvailableRequirementInBytes = 0;
private long actualMemoryAvailableInBytes = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
import org.eclipse.jgit.api.CloneCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidRemoteException;
import org.eclipse.jgit.api.errors.TransportException;

import com.github.eostermueller.snail4j.Application;
import com.github.eostermueller.snail4j.Context;
import com.github.eostermueller.snail4j.DefaultContext;
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.DeleteSut;
import com.github.eostermueller.snail4j.systemproperty.SutGitCloneUrl;
Expand All @@ -32,7 +30,7 @@ Context getContext() {
@Override
public void install() throws Snail4jException {

if (DefaultFactory.getFactory().getSystemPropertyMgr().getBoolean( new DeleteSut())) {
if (new BootstrapConfig().getSystemPropertyMgr().getBoolean( new DeleteSut())) {
File sutAppFolder = this.getContext().getConfiguration().getSutAppHome().toFile();
String strSutAppFolder;
try {
Expand All @@ -55,7 +53,7 @@ public void install() throws Snail4jException {
}
}

String sutGitCloneRepo = DefaultFactory.getFactory().getSystemPropertyMgr().getString(new SutGitCloneUrl());
String sutGitCloneRepo = new BootstrapConfig().getSystemPropertyMgr().getString(new SutGitCloneUrl());

if (sutGitCloneRepo !=null
&& !sutGitCloneRepo.trim().isEmpty()) {
Expand All @@ -66,7 +64,7 @@ public void install() throws Snail4jException {
getContext().getLogger().info("After git repo has been cloned.");
} else {
getContext().getLogger().error("Will not clone repo because sutApp folder exists here: " + this.getContext().getConfiguration().getSutAppHome().toFile().toString() );
getContext().getLogger().info("Restart the Snail4j uber jar with -D parameter [" + new DeleteSut().getDashDProperty() + "] to delete the sutApp folder.");
getContext().getLogger().info("Restart the Snail4j uber jar with -D parameter [" + new DeleteSut().getDashDPropertyName() + "] to delete the sutApp folder.");
}
} else {
getContext().getLogger().info("About to install the native sutApp.");
Expand Down Expand Up @@ -95,7 +93,7 @@ protected void cloneSutGitRepo() throws CannotFindSnail4jFactoryClass, InstallEx
this.getContext().getConfiguration().getSutAppHome().toFile().mkdir();

CloneCommand cloneCommand = Git.cloneRepository();
cloneCommand.setURI( DefaultFactory.getFactory().getSystemPropertyMgr().getString(new SutGitCloneUrl()).trim() );
cloneCommand.setURI( new BootstrapConfig().getSystemPropertyMgr().getString(new SutGitCloneUrl()).trim() );
//The following might be a nice feature enhancement in the future
//cloneCommand.setCredentialsProvider( new UsernamePasswordCredentialsProvider( "user", "pwd" ) );
cloneCommand.setDirectory(this.getContext().getConfiguration().getSutAppHome().toFile());
Expand All @@ -106,7 +104,7 @@ protected void cloneSutGitRepo() throws CannotFindSnail4jFactoryClass, InstallEx
} catch (GitAPIException e) {
String msg = getContext().getMessages()
.unableToCloneSutRepo(
DefaultFactory.getFactory().getSystemPropertyMgr().getString(new SutGitCloneUrl()).trim(),
new BootstrapConfig().getSystemPropertyMgr().getString(new SutGitCloneUrl()).trim(),
this.getContext().getConfiguration().getSutAppHome().toFile().toString() );

throw new InstallException(e, msg );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.AvailableDiskSpaceValidation;
import com.github.eostermueller.snail4j.systemproperty.AvailableMemoryValidation;
Expand All @@ -29,7 +30,7 @@ public DiskSpaceValidatorImpl() throws Snail4jException {

// ...but of course if they set the -D parameter for validation to true, we'll validate for them.
this.setAvailableDiskSpaceValidationActive(
DefaultFactory.getFactory().getSystemPropertyMgr().getBoolean(new AvailableDiskSpaceValidation()));
new BootstrapConfig().getSystemPropertyMgr().getBoolean(new AvailableDiskSpaceValidation()));

this.setMinDiskSpaceAvailableRequirementInBytes(
DefaultFactory.getFactory().getConfiguration().getMinDiskSpaceAvailableRequirementInBytes() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public Path getJdkForSUT() throws Snail4jException {

}

public int sutPortsAreAvailable(Configuration cfg) throws CannotFindSnail4jFactoryClass, Snail4jMultiException {
public int getCountOfUnavailableSUTTcpPorts(Configuration cfg) throws CannotFindSnail4jFactoryClass, Snail4jMultiException {
List<String> errors = new ArrayList<String>();
int timeoutMs = 20000;
List<TcpTarget> targets = new ArrayList<TcpTarget>();
Expand Down
Loading

0 comments on commit 55a2ad8

Please sign in to comment.