Skip to content

Commit

Permalink
Merge pull request #121 from NitorCreations/remove-property-defaults
Browse files Browse the repository at this point in the history
remove default values from config parameters, add missing values to config files
  • Loading branch information
eputtone committed Mar 3, 2015
2 parents 064f7ef + 75a7e7b commit 0a1b9bd
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public class EngineConfiguration {
@Bean
public WorkflowInstanceExecutor nflowExecutor(@NFlow ThreadFactory nflowThreadFactory, Environment env) {
int threadCount = env.getProperty("nflow.executor.thread.count", Integer.class, 2 * getRuntime().availableProcessors());
int awaitTerminationSeconds = env.getProperty("nflow.dispatcher.await.termination.seconds", Integer.class, 60);
int awaitTerminationSeconds = env.getRequiredProperty("nflow.dispatcher.await.termination.seconds", Integer.class);
int queueSize = env.getProperty("nflow.dispatcher.executor.queue.size", Integer.class, 2 * threadCount);
int notifyThreshold = env.getProperty("nflow.dispatcher.executor.queue.wait_until_threshold", Integer.class, queueSize / 2);
int keepAliveSeconds = env.getProperty("nflow.dispatcher.executor.thread.keepalive.seconds", Integer.class, 0);
int keepAliveSeconds = env.getRequiredProperty("nflow.dispatcher.executor.thread.keepalive.seconds", Integer.class);
return new WorkflowInstanceExecutor(queueSize, threadCount, notifyThreshold, awaitTerminationSeconds, keepAliveSeconds,
nflowThreadFactory);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class WorkflowLifecycle implements SmartLifecycle {
@Inject
public WorkflowLifecycle(WorkflowDispatcher dispatcher, @NFlow ThreadFactory nflowThreadFactory, Environment env) {
this.dispatcher = dispatcher;
autoStart = env.getProperty("nflow.autostart", Boolean.class, true);
autoStart = env.getRequiredProperty("nflow.autostart", Boolean.class);
dispatcherThread = nflowThreadFactory.newThread(dispatcher);
dispatcherThread.setName("nflow-dispatcher");
if (!autoStart) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static com.nitorcreations.nflow.engine.internal.dao.DaoUtil.toDateTime;
import static com.nitorcreations.nflow.engine.internal.storage.db.DatabaseConfiguration.NFLOW_DATABASE_INITIALIZER;
import static com.nitorcreations.nflow.engine.workflow.instance.WorkflowInstanceAction.WorkflowActionType.recovery;
import static java.util.concurrent.TimeUnit.MINUTES;
import static org.apache.commons.lang3.StringUtils.trimToNull;
import static org.joda.time.DateTime.now;
import static org.springframework.transaction.support.TransactionSynchronizationManager.isActualTransactionActive;
Expand Down Expand Up @@ -60,8 +59,8 @@ public class ExecutorDao {
public void setEnvironment(Environment env) {
this.executorGroup = trimToNull(env.getRequiredProperty("nflow.executor.group"));
this.executorGroupCondition = createWhereCondition(executorGroup);
timeoutSeconds = env.getProperty("nflow.executor.timeout.seconds", Integer.class, (int) MINUTES.toSeconds(15));
keepaliveIntervalSeconds = env.getProperty("nflow.executor.keepalive.seconds", Integer.class, (int) MINUTES.toSeconds(1));
timeoutSeconds = env.getRequiredProperty("nflow.executor.timeout.seconds", Integer.class);
keepaliveIntervalSeconds = env.getRequiredProperty("nflow.executor.keepalive.seconds", Integer.class);
}

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public WorkflowDispatcher(WorkflowInstanceExecutor executor, WorkflowInstanceDao
this.workflowInstances = workflowInstances;
this.stateProcessorFactory = stateProcessorFactory;
this.executorRecovery = executorRecovery;
this.sleepTime = env.getProperty("nflow.dispatcher.sleep.ms", Long.class, 5000l);
this.sleepTime = env.getRequiredProperty("nflow.dispatcher.sleep.ms", Long.class);
if (!executorRecovery.isTransactionSupportEnabled()) {
throw new BeanCreationException("Transaction support must be enabled");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.math.BigInteger;

import org.joda.time.DateTime;
import org.springframework.core.env.Environment;

/**
* Configuration for the workflow execution.
Expand Down Expand Up @@ -50,32 +49,11 @@ public class WorkflowSettings {
*/
public static class Builder {

int maxErrorTransitionDelay;
int minErrorTransitionDelay;
int shortTransitionDelay;
int immediateTransitionDelay;
int maxRetries;

/**
* Create builder for workflow settings using default values.
*/
public Builder() {
this(null);
}

/**
* Create builder for workflow settings using configured default values.
*
* @param env
* Spring environment.
*/
public Builder(Environment env) {
minErrorTransitionDelay = getIntegerProperty(env, "nflow.transition.delay.error.min.ms", (int) MINUTES.toMillis(1));
maxErrorTransitionDelay = getIntegerProperty(env, "nflow.transition.delay.error.max.ms", (int) DAYS.toMillis(1));
shortTransitionDelay = getIntegerProperty(env, "nflow.transition.delay.waitshort.ms", (int) SECONDS.toMillis(30));
immediateTransitionDelay = getIntegerProperty(env, "nflow.transition.delay.immediate.ms", 0);
maxRetries = getIntegerProperty(env, "nflow.max.state.retries", 17);
}
int maxErrorTransitionDelay = (int) DAYS.toMillis(1);
int minErrorTransitionDelay = (int) MINUTES.toMillis(1);
int shortTransitionDelay = (int) SECONDS.toMillis(30);
int immediateTransitionDelay = 0;
int maxRetries = 17;

/**
* Set the maximum delay on execution retry after an error.
Expand Down Expand Up @@ -137,13 +115,6 @@ public Builder setMaxRetries(int maxRetries) {
return this;
}

private int getIntegerProperty(Environment env, String key, int defaultValue) {
if (env != null) {
return env.getProperty(key, Integer.class, defaultValue);
}
return defaultValue;
}

/**
* Create workflow settings object.
*
Expand Down
14 changes: 2 additions & 12 deletions nflow-engine/src/main/resources/nflow-engine.properties
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
nflow.autostart=true
nflow.executor.group=nflow
nflow.executor.timeout.seconds=900
nflow.executor.keepalive.seconds=60

nflow.dispatcher.sleep.ms=1000
nflow.dispatcher.executor.queue.wait_until_threshold=0
nflow.dispatcher.await.termination.seconds=60
nflow.dispatcher.executor.queue.wait_until_threshold=0
nflow.dispatcher.executor.thread.keepalive.seconds=0

nflow.executor.timeout.seconds=900
nflow.executor.keepalive.seconds=60

nflow.transition.delay.immediate.ms=0
nflow.transition.delay.waitshort.ms=30000
nflow.transition.delay.error.min.ms=60000
nflow.transition.delay.error.max.ms=86400000

nflow.max.state.retries=3

nflow.workflow.instance.query.max.results=10000
nflow.workflow.instance.query.max.results.default=100

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
public class EngineConfigurationTest {

@Spy
private final MockEnvironment environment = new MockEnvironment().withProperty("nflow.executor.thread.count", "100");
private final MockEnvironment environment = new MockEnvironment().withProperty("nflow.executor.thread.count", "100")
.withProperty("nflow.dispatcher.await.termination.seconds", "60")
.withProperty("nflow.dispatcher.executor.thread.keepalive.seconds", "0");
@Mock
private ThreadFactory threadFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class WorkflowLifecycleTest {

@Before
public void setup() {
when(env.getProperty("nflow.autostart", Boolean.class, true)).thenReturn(TRUE);
when(env.getRequiredProperty("nflow.autostart", Boolean.class)).thenReturn(TRUE);
when(threadFactory.newThread(dispatcher)).thenReturn(dispatcherThread);
lifecycle = new WorkflowLifecycle(dispatcher, threadFactory, env);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public class WorkflowDispatcherTest {

@Before
public void setup() {
when(env.getProperty("nflow.dispatcher.sleep.ms", Long.class, 5000l)).thenReturn(0l);
when(env.getProperty("nflow.dispatcher.executor.queue.wait_until_threshold", Integer.class, 0)).thenReturn(0);
when(env.getRequiredProperty("nflow.dispatcher.sleep.ms", Long.class)).thenReturn(0l);
when(env.getRequiredProperty("nflow.dispatcher.executor.queue.wait_until_threshold", Integer.class)).thenReturn(0);
when(recovery.isTransactionSupportEnabled()).thenReturn(true);
executor = new WorkflowInstanceExecutor(3, 2, 0, 10, 0, new CustomizableThreadFactory("nflow-executor-"));
dispatcher = new WorkflowDispatcher(executor, workflowInstances, executorFactory, recovery, env);
Expand Down
2 changes: 2 additions & 0 deletions nflow-engine/src/test/resources/junit.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
nflow.executor.group=junit
nflow.executor.timeout.seconds=900
nflow.executor.keepalive.seconds=60

nflow.workflow.instance.query.max.results=10000
nflow.workflow.instance.query.max.results.default=100
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ public class StartNflow

private final Set<Class<?>> annotatedContextClasses = new LinkedHashSet<>();

public static final String DEFAULT_HOST = "localhost";
public static final int DEFAULT_PORT = 7500;

public static void main(final String... args) throws Exception {
new StartNflow().startJetty(Collections.<String, Object>emptyMap());
}
Expand All @@ -85,14 +82,13 @@ public JettyServerContainer startJetty(Map<String, Object> properties) throws Ex
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
ConfigurableEnvironment env = new NflowStandardEnvironment(properties);
String host = env.getProperty("host", DEFAULT_HOST);
int port = env.getProperty("port", Integer.class, DEFAULT_PORT);
KillProcess.gracefullyTerminateOrKillProcessUsingPort(port, env.getProperty("terminate.timeout", Integer.class, 30), true);
String host = env.getRequiredProperty("host");
int port = env.getRequiredProperty("port", Integer.class);
KillProcess.gracefullyTerminateOrKillProcessUsingPort(port, env.getRequiredProperty("terminate.timeout", Integer.class), true);
Server server = setupServer();
setupJmx(server, env);
setupServerConnector(server, host, port);
ServletContextHandler context = setupServletContextHandler(env.getProperty("extra.resource.directories", String[].class,
new String[0]));
ServletContextHandler context = setupServletContextHandler(env.getRequiredProperty("extra.resource.directories", String[].class));
setupHandlers(server, context);
setupSpring(context, env);
setupCxf(context);
Expand Down
1 change: 1 addition & 0 deletions nflow-jetty/src/main/resources/nflow-jetty.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
host=0.0.0.0
port=7500
terminate.timeout=30
extra.resource.directories=

nflow.rest.allow.origin=*
7 changes: 7 additions & 0 deletions nflow-jetty/src/test/resources/junit.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
host=0.0.0.0
port=7500
terminate.timeout=30
extra.resource.directories=

nflow.rest.allow.origin=*

nflow.executor.group=junit

nflow.db.h2.driver=org.h2.jdbcx.JdbcDataSource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public CorsHeaderContainerResponseFilter(final Environment env) {

@Override
public void filter(final ContainerRequestContext requestContext, final ContainerResponseContext responseContext) {
String origin = env.getProperty("nflow.rest.allow.origin", "*");
String origin = env.getRequiredProperty("nflow.rest.allow.origin");
responseContext.getHeaders().add("Access-Control-Allow-Origin", origin);
responseContext.getHeaders().add("Access-Control-Allow-Headers",
"X-Requested-With, Content-Type, Origin, Referer, User-Agent, Accept");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void setup() {
@Test
public void addsHeaders() {
String host="example.com";
when(env.getProperty("nflow.rest.allow.origin", "*")).thenReturn(host);
when(env.getRequiredProperty("nflow.rest.allow.origin")).thenReturn(host);

filter.filter(requestContext, responseContext);

Expand Down
7 changes: 6 additions & 1 deletion nflow-tests/src/main/resources/local.properties
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
nflow.non_spring_workflows_filename=nflow-workflows.txt
host=0.0.0.0
port=7500
terminate.timeout=30
extra.resource.directories=

nflow.non_spring_workflows_filename=nflow-workflows.txt
2 changes: 1 addition & 1 deletion nflow-tests/src/main/resources/nflow-tests.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nflow.url=http://localhost:7500
nflow.url=http://localhost:7500

0 comments on commit 0a1b9bd

Please sign in to comment.