Skip to content

Commit

Permalink
Merge branch 'main' into logback1.5.13
Browse files Browse the repository at this point in the history
  • Loading branch information
cfkoehler authored Jan 28, 2025
2 parents 73bdfba + af7cdd3 commit 7bd69a2
Show file tree
Hide file tree
Showing 56 changed files with 1,648 additions and 249 deletions.
18 changes: 15 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>gov.nsa.emissary</groupId>
<artifactId>emissary</artifactId>
<version>8.19.0-SNAPSHOT</version>
<version>8.22.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Emissary</name>
<description>Distributed P2P Data-driven Workflow Framework</description>
Expand Down Expand Up @@ -64,14 +64,15 @@
<dep.guava.version>32.1.2-jre</dep.guava.version>
<dep.httpclient.version>5.2.1</dep.httpclient.version>
<dep.httpcore.version>5.2.1</dep.httpcore.version>
<dep.icu4j.version>73.2</dep.icu4j.version>
<dep.jackson.version>2.15.2</dep.jackson.version>
<dep.jakarta.xml.bind-api.version>3.0.1</dep.jakarta.xml.bind-api.version>
<dep.janino.version>3.1.12</dep.janino.version>
<dep.jaxb.runtime.version>3.0.1</dep.jaxb.runtime.version>
<dep.jdom.version>2.0.6.1</dep.jdom.version>
<dep.jersey.version>3.1.3</dep.jersey.version>
<dep.jetty.version>11.0.24</dep.jetty.version>
<dep.junit-jupiter.version>5.10.0</dep.junit-jupiter.version>
<dep.junit-jupiter.version>5.11.4</dep.junit-jupiter.version>
<dep.logback.version>1.5.13</dep.logback.version>
<dep.mockito.version>5.5.0</dep.mockito.version>
<dep.picocli.version>4.7.4</dep.picocli.version>
Expand Down Expand Up @@ -305,6 +306,12 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
<version>${dep.icu4j.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down Expand Up @@ -523,6 +530,11 @@
<artifactId>error_prone_annotations</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-jetty</artifactId>
Expand Down Expand Up @@ -1499,7 +1511,7 @@
<arg>-1</arg>
<arg>-Xmaxwarns</arg>
<arg>-1</arg>
<!--arg>-Werror</arg-->
<arg>-Werror</arg>
<!--arg>-Xlint:all</arg-->
<arg>-XDcompilePolicy=simple</arg>
<arg>-Xplugin:ErrorProne \
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/emissary/admin/Startup.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import emissary.pickup.PickUpPlace;
import emissary.place.CoordinationPlace;
import emissary.place.IServiceProviderPlace;
import emissary.server.EmissaryServer;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -290,7 +291,7 @@ protected boolean localDirectorySetup(final Map<String, String> localDirectories

final long start = System.currentTimeMillis();
final Map<String, String> dirStarts = new HashMap<>();
EmissaryNode emissaryNode = new EmissaryNode();
EmissaryNode emissaryNode = EmissaryServer.getInstance().getNode();
for (final String thePlaceLocation : hostParameters) {

final String host = placeHost(thePlaceLocation);
Expand Down
40 changes: 12 additions & 28 deletions src/main/java/emissary/command/ServerCommand.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package emissary.command;

import emissary.client.EmissaryResponse;
import emissary.command.converter.ModeConverter;
import emissary.command.converter.ProjectBaseConverter;
import emissary.command.validator.ServerModeValidator;
import emissary.core.EmissaryException;
import emissary.core.EmissaryRuntimeException;
import emissary.directory.EmissaryNode;
import emissary.server.EmissaryServer;
import emissary.server.api.Pause;

Expand All @@ -28,15 +27,9 @@ public class ServerCommand extends ServiceCommand {

public static final int DEFAULT_PORT = 8001;

private String mode = "standalone";

@Option(names = {"-m", "--mode"}, description = "mode: standalone or cluster\nDefault: ${DEFAULT-VALUE}", defaultValue = "standalone")
@SuppressWarnings("unused")
private void setMode(String value) {
ServerModeValidator smv = new ServerModeValidator();
smv.validate("mode", value);
mode = value;
}
@Option(names = {"-m", "--mode"}, description = "mode: standalone or cluster\nDefault: ${DEFAULT-VALUE}", converter = ModeConverter.class,
defaultValue = "standalone")
private EmissaryNode.Mode mode;

@Option(names = "--staticDir", description = "path to static assets, loaded from classpath otherwise", converter = ProjectBaseConverter.class)
private Path staticDir;
Expand All @@ -60,7 +53,7 @@ public int getDefaultPort() {
return DEFAULT_PORT;
}

public String getMode() {
public EmissaryNode.Mode getMode() {
return mode;
}

Expand Down Expand Up @@ -89,20 +82,15 @@ public boolean shouldStrictMode() {
public void setupCommand() {
setupHttp();
reinitLogback();
try {
setupServer();
} catch (EmissaryException e) {
LOG.error("Got an exception", e);
throw new EmissaryRuntimeException(e);
}
setupServer();
}

public void setupServer() throws EmissaryException {
public void setupServer() {
String flavorMode;
if (getFlavor() == null) {
flavorMode = getMode().toUpperCase(Locale.getDefault());
flavorMode = getMode().toString();
} else {
flavorMode = getMode().toUpperCase(Locale.getDefault()) + "," + getFlavor();
flavorMode = getMode().toString() + "," + getFlavor();
}

if (shouldStrictMode()) {
Expand All @@ -124,12 +112,8 @@ public void setupServer() throws EmissaryException {

@Override
protected void startService() {
try {
LOG.info("Running Emissary Server");
new EmissaryServer(this).startServer();
} catch (EmissaryException e) {
LOG.error("Unable to start server", e);
}
LOG.info("Running Emissary Server");
EmissaryServer.init(this).startServer();
}

@Override
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/emissary/command/converter/ModeConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package emissary.command.converter;

import emissary.directory.EmissaryNode;

import picocli.CommandLine.ITypeConverter;

import java.util.Locale;

public class ModeConverter implements ITypeConverter<EmissaryNode.Mode> {

@Override
public EmissaryNode.Mode convert(String s) throws Exception {
switch (s.toLowerCase(Locale.getDefault())) {
case "cluster":
return EmissaryNode.Mode.CLUSTER;
case "standalone":
return EmissaryNode.Mode.STANDALONE;
default:
throw new IllegalArgumentException("Unknown mode: " + s);
}
}
}
21 changes: 0 additions & 21 deletions src/main/java/emissary/command/validator/ServerModeValidator.java

This file was deleted.

4 changes: 0 additions & 4 deletions src/main/java/emissary/command/validator/package-info.java

This file was deleted.

6 changes: 3 additions & 3 deletions src/main/java/emissary/config/ExtractResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public String getResource(final String theResource) throws IOException {
}
logger.debug("Reading " + resource);
final String result;
try (final InputStream is = ConfigUtil.getConfigStream(resource);
final ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
try (InputStream is = ConfigUtil.getConfigStream(resource);
ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
final byte[] buf = new byte[4096];
int thisReadOp = 0;
while ((thisReadOp = is.read(buf)) > -1) {
Expand All @@ -63,7 +63,7 @@ public void writeResource(final String theResource) throws IOException {
final String rezdata = getResource(resource);
final String outputPath = this.outputDirectory + "/" + resource.replaceAll("/", ".");
logger.debug("Writing " + outputPath);
try (final BufferedOutputStream os = new BufferedOutputStream(Files.newOutputStream(Paths.get(outputPath)))) {
try (BufferedOutputStream os = new BufferedOutputStream(Files.newOutputStream(Paths.get(outputPath)))) {
os.write(rezdata.getBytes());
}
}
Expand Down
35 changes: 32 additions & 3 deletions src/main/java/emissary/core/BaseDataObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ public class BaseDataObject implements Serializable, Cloneable, Remote, IBaseDat
@Nullable
protected SeekableByteChannelFactory seekableByteChannelFactory;

@Nullable
protected final IBaseDataObject tld;

protected enum DataState {
NO_DATA, CHANNEL_ONLY, BYTE_ARRAY_ONLY, BYTE_ARRAY_AND_CHANNEL
Expand Down Expand Up @@ -238,6 +240,7 @@ protected DataState getDataState() {
public BaseDataObject() {
this.theData = null;
setCreationTimestamp(Instant.now());
tld = null;
}

/**
Expand All @@ -251,6 +254,7 @@ public BaseDataObject(final byte[] newData, final String name) {
setData(newData);
setFilename(name);
setCreationTimestamp(Instant.now());
tld = null;
}

/**
Expand All @@ -275,6 +279,24 @@ public BaseDataObject(final byte[] newData, final String name, final String form
}
}

public BaseDataObject(final byte[] newData, final String name, @Nullable final String form, IBaseDataObject tld) {
setData(newData);
setFilename(name);
setCreationTimestamp(Instant.now());
if (form != null) {
pushCurrentForm(form);
}
this.tld = tld;
}

public BaseDataObject(final byte[] newData, final String name, @Nullable final String form, @Nullable final String fileType,
IBaseDataObject tld) {
this(newData, name, form, tld);
if (fileType != null) {
this.setFileType(fileType);
}
}

/**
* Set the header byte array WARNING: this implementation uses the passed in array directly, no copy is made so the
* caller should not reuse the array.
Expand Down Expand Up @@ -470,7 +492,7 @@ public long getChannelSize() throws IOException {
case BYTE_ARRAY_ONLY:
return ArrayUtils.getLength(theData);
case CHANNEL_ONLY:
try (final SeekableByteChannel sbc = this.seekableByteChannelFactory.create()) {
try (SeekableByteChannel sbc = this.seekableByteChannelFactory.create()) {
return sbc.size();
}
case NO_DATA:
Expand Down Expand Up @@ -970,9 +992,10 @@ public boolean appendUniqueParameter(final String key, final CharSequence value)
public String getParameterAsString(final String key) {
final var obj = getParameterAsStrings(key);
if (obj.size() > 1) {
logger.warn("Multiple values for parameter, returning the first - parameter:{}, number of values:{}", key, obj.size());
logger.warn("Multiple values for parameter, parameter:{}, number of values:{}", key, obj.size());
return getParameterAsConcatString(key);
}
return StringUtils.trimToNull(obj.stream().findFirst().orElse(null));
return obj.stream().findFirst().orElse(null);
}

/**
Expand Down Expand Up @@ -1462,4 +1485,10 @@ public String getTransactionId() {
public void setTransactionId(String transactionId) {
this.transactionId = transactionId;
}

@Override
public IBaseDataObject getTld() {
return tld;
}

}
30 changes: 30 additions & 0 deletions src/main/java/emissary/core/DataObjectFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,20 @@ public static IBaseDataObject getInstance(final byte[] payload, final String fil
return getInstance(payload, filename, fileTypeAndForm, fileTypeAndForm);
}

/**
* Get an instance of the configured DataObject impl with filename, form, and file type set, and top level document
*
* @param payload the payload data
* @param filename the filename
* @param fileTypeAndForm the form and filetype to set on the IBDO
* @param tld The top level document
* @return an IBDO with the payload, filename, top level document set with the file type and form set to the same value
*/
public static IBaseDataObject getInstance(final byte[] payload, final String filename, final String fileTypeAndForm, IBaseDataObject tld) {
final Object o = Factory.create(clazz, payload, filename, fileTypeAndForm, tld);
return (IBaseDataObject) o;
}

/**
* Get an instance of the configured DataObject impl with filename, form, and file type set
*
Expand All @@ -128,6 +142,22 @@ public static IBaseDataObject getInstance(final byte[] payload, final String fil
return (IBaseDataObject) o;
}

/**
* Get an instance of the configured DataObject impl with filename, form, file type, and top level document set
*
* @param payload the payload data
* @param filename the filename
* @param form the form to set on the IBDO
* @param fileType the file type to set on the IBDO
* @param tld The top level document
* @return an IBDO with the payload, filename, file type, form, and top level document set
*/
public static IBaseDataObject getInstance(final byte[] payload, final String filename, final String form, final String fileType,
IBaseDataObject tld) {
final Object o = Factory.create(clazz, payload, filename, form, fileType, tld);
return (IBaseDataObject) o;
}

/* IExtractedRecord */

/**
Expand Down
Loading

0 comments on commit 7bd69a2

Please sign in to comment.