Skip to content

Commit

Permalink
Changes to support deployment on raspberry pi ZERO and minor fixes.
Browse files Browse the repository at this point in the history
+ support disabling warnings when default configuration is loaded.
+ support argon2 configuration in security settings and HMAC algo.
+ support configuring blocked-thread-checker interval and timeout.
+ use correct zone offset in log timestamps
+ improved logging by using more accurate classes (log tag)
+ configuration factory attempts to load paths without extensions.
+ fixes for the yaml configuration factory for JSON support.
+ improved connection management + lazy connections with properties.
+ support removing close handlers on connections.
+ support binary websocket transfer mode for better performance.
+ alpn may now be enabled on non-J9 installs - requires provider on CP.
+ logging metadata can now be removed.
+ improved Response and header reflection for async clients.
+ enabled literal block style to support scripts in YAML files.
+ added full support for using YAML files with AuthenticationGenerator
+ custom index adders for persisted vs volatile CQEngine.
+ persistent CQEngine mapper no longer includes transient fields
+ the jsonmap should now be shared correctly.
+ services started from the launcher are now deployed in parallel.
  • Loading branch information
Robin Duda committed Apr 21, 2018
1 parent fa7bf46 commit 8c3d8d3
Show file tree
Hide file tree
Showing 47 changed files with 945 additions and 460 deletions.
38 changes: 21 additions & 17 deletions core/main/java/com/codingchili/core/Launcher.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.codingchili.core;

import io.vertx.core.Future;
import io.vertx.core.Verticle;
import io.vertx.core.*;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -86,7 +85,11 @@ public static void start(LaunchContext context) {
void exit() {
// no vertx context is initialized yet - but some thread pools
// might need to be shut down after running the command.
ShutdownListener.publish();
if (this.core == null) {
ShutdownListener.publish();
} else {
this.core.close();
}
}

private void clusterIfEnabled(LaunchContext launcher) {
Expand Down Expand Up @@ -125,21 +128,22 @@ private void start(CoreContext core) {
* Deploy services in the order they are defined in the service block.
*/
private void deployServices(List<String> nodes) {
String node = nodes.get(0);

if (isDeployable(node)) {
core.deploy(nodes.get(0)).setHandler(deploy -> {
if (deploy.succeeded()) {
nodes.remove(0);

if (nodes.size() > 0) {
deployServices(nodes);
}
} else {
throw new RuntimeException(deploy.cause());
}
});
List<Future> deployments = new ArrayList<>();
//String node = nodes.get(0);

for (String node : nodes) {
if (isDeployable(node)) {
Future<String> future = Future.future();
core.deploy(node).setHandler(future);
deployments.add(future);
}
}
CompositeFuture.all(deployments).setHandler(deployed -> {
if (deployed.failed()) {
logger.onError(deployed.cause());
exit();
}
});
}

private boolean isDeployable(String node) {
Expand Down
15 changes: 10 additions & 5 deletions core/main/java/com/codingchili/core/configuration/CoreStrings.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,12 @@ public static String getCommand(String command) {
return COMMAND_PREFIX + command;
}

public static String getHandlerMissing(String name) {
return String.format("The requested handler '%s' was not found.", name);
public static String getHandlerMissing() {
return "Requested handler not found.";
}

public static String getHandlerMissing(String handlerName) {
return String.format("Requested handler '%s' not found.", handlerName);
}

/**
Expand Down Expand Up @@ -369,7 +373,7 @@ public static String getGeneratingShared(String key, String path) {
}

public static String getService(String config) {
return CoreStrings.DIR_SERVICES + config + EXT_JSON;
return CoreStrings.DIR_SERVICES + config;
}

public static String format(Path path) {
Expand Down Expand Up @@ -420,7 +424,7 @@ public static String getSystemNotInitialized(String name) {
}

public static String getIdentityNotConfigured(String name) {
return "[" + name + "] Error: Identity must be configured.";
return "[" + name + "] Error: '" + ID_NODE + "' must be configured for token generation.";
}

public static String getStorageLoaderError(Class plugin, String database, String collection) {
Expand Down Expand Up @@ -568,7 +572,8 @@ public static String getSecurityDependencyMissing(String target, String identifi
}

public static String timestamp(long ms) {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(ms), ZoneOffset.UTC).toString().split("T")[1];
return LocalDateTime.ofInstant(Instant.ofEpochMilli(ms), ZoneOffset.systemDefault())
.toString().split("T")[1];
}

public static String getHashMismatchException() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.codingchili.core.configuration.Configurable;
import com.codingchili.core.configuration.CoreStrings;

import com.fasterxml.jackson.annotation.JsonIgnore;

import java.util.ArrayList;
Expand All @@ -20,6 +21,7 @@ public class LauncherSettings implements Configurable {
private String application = "launcher";
private String version = CoreStrings.VERSION;
private String author = CoreStrings.AUTHOR;
private boolean warnOnDefaultsLoaded = false;
private boolean clustered;
private HashMap<String, List<String>> blocks = defaultBlockConfiguration();
private HashMap<String, String> hosts = defaultHostConfiguration();
Expand All @@ -45,6 +47,24 @@ public LauncherSettings setVersion(String version) {
return this;
}

/**
* @return true if a warning should be logged when a configuration file is not found
* and the configurable is loaded from the java class. To avoid these errors
* add your java configurable to the Configuration.
*/
public boolean isWarnOnDefaultsLoaded() {
return warnOnDefaultsLoaded;
}

/**
* @param warnOnDefaultsLoaded set to true to disable warnings when default settings
* are loaded. Default settings will be loaded when the
* path to a configurable is not available.
*/
public void setWarnOnDefaultsLoaded(boolean warnOnDefaultsLoaded) {
this.warnOnDefaultsLoaded = warnOnDefaultsLoaded;
}

/**
* @return get the configured deployment blocks.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public class SecuritySettings implements Configurable {
private Map<String, AuthenticationDependency> dependencies = new HashMap<>();
private Map<String, TrustAndKeyProvider> loadedKeyStores = new HashMap<>();
private Set<KeyStore> keystores = new HashSet<>();
private ArgonSettings argon = new ArgonSettings();
private String hmacAlgorithm = "HmacSHA512";
;
private int secretBytes = 64;
private int tokenttl = 3600 * 24 * 7;

Expand Down Expand Up @@ -135,6 +138,35 @@ public void setSecretBytes(int secretBytes) {
this.secretBytes = secretBytes;
}

/**
* @return argon2 parameters used for password hashing.
*/
public ArgonSettings getArgon() {
return argon;
}

/**
* @param argon the argon2 parameters used for password hashing.
*/
public void setArgon(ArgonSettings argon) {
this.argon = argon;
}

/**
* @return the HMAC algorithm identifier used to create HMAC tokens.
*/
public String getHmacAlgorithm() {
return hmacAlgorithm;
}

/**
* @param hmacAlgorithm the HMAC algorithm used to create HMAC tokens,
* the specified algorithm must be available in the JVM.
*/
public void setHmacAlgorithm(String hmacAlgorithm) {
this.hmacAlgorithm = hmacAlgorithm;
}

/**
* @return a map of dependencies, where the key is the regex that match other
* configurations. The value contains the actual security configuration to be applied.
Expand Down Expand Up @@ -172,10 +204,17 @@ public SecuritySettings addDependency(String path, AuthenticationDependency depe
return this;
}

/**
* @return the time to live for generated tokens in seconds.
*/
public int getTokenttl() {
return tokenttl;
}

/**
* @param tokenttl the time to live for generated tokens in seconds.
* @return fluent.
*/
public SecuritySettings setTokenttl(int tokenttl) {
this.tokenttl = tokenttl;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class SystemSettings implements Configurable {
private boolean consoleLogging = true;
private int workerPoolSize = 16;
private int clusterTimeout = 3000;
private long blockedThreadChecker = VertxOptions.DEFAULT_BLOCKED_THREAD_CHECK_INTERVAL;
private long maxEventLoopExecuteTime = VertxOptions.DEFAULT_MAX_EVENT_LOOP_EXECUTE_TIME / (1000 * 1000);

@Override
public String getPath() {
Expand Down Expand Up @@ -118,6 +120,37 @@ public SystemSettings setShutdownHookTimeout(int shutdownHookTimeout) {
return this;
}

/**
* @return the number of milliseconds to wait before logging an error if an event
* loop thread is blocked.
*/
public long getBlockedThreadChecker() {
return blockedThreadChecker;
}

/**
* @param blockedThreadChecker sets the number of milliseconds to wait before logging an
* error if an event loop thread is blocked.
*/
public void setBlockedThreadChecker(long blockedThreadChecker) {
this.blockedThreadChecker = blockedThreadChecker;
}

/**
* @return the max event loop execute time the blocked thread checker uses in milliseconds.
*/
public long getMaxEventLoopExecuteTime() {
return maxEventLoopExecuteTime;
}

/**
* @param maxEventLoopExecuteTime the number of milliseconds the event loop can block without
* having the blocked-thread-checker generate warning.
*/
public void setMaxEventLoopExecuteTime(long maxEventLoopExecuteTime) {
this.maxEventLoopExecuteTime = maxEventLoopExecuteTime;
}

/**
* @return returns true if metrics are configured.
*/
Expand Down Expand Up @@ -149,7 +182,9 @@ public VertxOptions getOptions() {
if (options == null) {
return new VertxOptions()
.setMetricsOptions(new MetricsOptions().setEnabled(isMetrics()))
.setClusterHost(Environment.address());
.setClusterHost(Environment.address())
.setBlockedThreadCheckInterval(blockedThreadChecker)
.setMaxEventLoopExecuteTime(maxEventLoopExecuteTime * 1000 * 1000);
} else {
return options;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CoreVerticle implements Verticle, CoreDeployment {
public CoreVerticle(CoreDeployment deployment, CoreContext core) {
this.deployment = deployment;
this.core = core;
this.logger = core.logger(deployment.getClass());
this.logger = core.logger(core.getClass());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.codingchili.core.context;

import io.vertx.core.*;
import io.vertx.core.json.JsonObject;

import com.codingchili.core.configuration.CoreStrings;
import com.codingchili.core.configuration.system.RemoteStorage;
import com.codingchili.core.configuration.system.StorageSettings;
Expand All @@ -8,10 +11,6 @@
import com.codingchili.core.protocol.Serializer;
import com.codingchili.core.security.Validator;
import com.codingchili.core.storage.AsyncStorage;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.json.JsonObject;

import static com.codingchili.core.configuration.CoreStrings.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
*/
public class SystemContext implements CoreContext {
private static AtomicBoolean initialized = new AtomicBoolean(false);
protected Vertx vertx;
private Map<String, List<String>> deployments = new HashMap<>();
private WorkerExecutor executor;
private RemoteLogger logger;
protected Vertx vertx;

/**
* Creates a new system context that shares vertx instance with the given context.
Expand Down Expand Up @@ -71,7 +71,7 @@ public static void clustered(Handler<AsyncResult<CoreContext>> handler) {
}

private void initialize() {
executor = vertx.createSharedWorkerExecutor("systemcontext", system().getWorkerPoolSize());
executor = vertx.createSharedWorkerExecutor("chili-core-blocking-pool", system().getWorkerPoolSize());
vertx.exceptionHandler(throwable -> logger.onError(throwable));

if (!initialized.get()) {
Expand Down
Loading

0 comments on commit 8c3d8d3

Please sign in to comment.