Skip to content

Commit

Permalink
New flag to prevent Wildfly to finish the deployment before MetricsSe…
Browse files Browse the repository at this point in the history
…rvice is started

After a minute, we let the deployment finish even if the metrics service is not started yet.
Initialization process will continue in the background, until the deployment is stopped.

rest-tests and ptrans itests setups make use of the new flag to avoid failing the build if
the metrics service takes some time to get ready.
  • Loading branch information
tsegismont committed Jun 5, 2015
1 parent 67c38e9 commit 2178ac9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
package org.hawkular.metrics.api.jaxrs;

import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.NANOSECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;

import static org.hawkular.metrics.api.jaxrs.config.ConfigurationKey.CASSANDRA_CQL_PORT;
import static org.hawkular.metrics.api.jaxrs.config.ConfigurationKey.CASSANDRA_KEYSPACE;
import static org.hawkular.metrics.api.jaxrs.config.ConfigurationKey.CASSANDRA_NODES;
import static org.hawkular.metrics.api.jaxrs.config.ConfigurationKey.CASSANDRA_RESETDB;
import static org.hawkular.metrics.api.jaxrs.config.ConfigurationKey.WAIT_FOR_SERVICE;

import java.io.IOException;
import java.util.Arrays;
Expand Down Expand Up @@ -51,6 +53,7 @@
import com.datastax.driver.core.Session;
import com.google.common.base.Throwables;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.Uninterruptibles;

/**
* Bean created on startup to manage the lifecycle of the {@link MetricsService} instance shared in application scope.
Expand Down Expand Up @@ -93,6 +96,11 @@ public enum State {
@ConfigurationProperty(CASSANDRA_RESETDB)
private String resetDb;

@Inject
@Configurable
@ConfigurationProperty(WAIT_FOR_SERVICE)
private String waitForService;

private volatile State state;
private int connectionAttempts;
private Session session;
Expand Down Expand Up @@ -122,7 +130,15 @@ public State getState() {
@PostConstruct
void init() {
lifecycleExecutor.submit(this::startMetricsService);
// TODO wait for state started if eager flag is ON
if (Boolean.parseBoolean(waitForService)) {
long start = System.nanoTime();
while (state == State.STARTING
// Give up after a minute. The deployment won't be failed and we'll continue to try to start the
// service in the background.
&& NANOSECONDS.convert(1, MINUTES) > System.nanoTime() - start) {
Uninterruptibles.sleepUninterruptibly(1, SECONDS);
}
}
}

private void startMetricsService() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public enum ConfigurationKey {
CASSANDRA_NODES("hawkular-metrics.cassandra-nodes", "127.0.0.1", "CASSANDRA_NODES", false),
CASSANDRA_CQL_PORT("hawkular-metrics.cassandra-cql-port", "9042", "CASSANDRA_CQL_PORT", false),
CASSANDRA_KEYSPACE("cassandra.keyspace", "hawkular_metrics", null, false),
CASSANDRA_RESETDB("cassandra.resetdb", null, null, true);
CASSANDRA_RESETDB("cassandra.resetdb", null, null, true),
WAIT_FOR_SERVICE("hawkular.metrics.waitForService", null, null, true);

private final String name;
private final String env;
Expand Down
1 change: 1 addition & 0 deletions clients/ptranslator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@
<javaOpt>-Dhawkular-metrics.backend=${hawkular-metrics.backend}</javaOpt>
<javaOpt>-Dcassandra.keyspace=${cassandra.keyspace}</javaOpt>
<javaOpt>-Dcassandra.resetdb=true</javaOpt>
<javaOpt>-Dhawkular.metrics.waitForService</javaOpt>
<javaOpt>-Xdebug</javaOpt>
<javaOpt>-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8787</javaOpt>
</javaOpts>
Expand Down
1 change: 1 addition & 0 deletions rest-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
<javaOpt>-Dhawkular-metrics.backend=${hawkular-metrics.backend}</javaOpt>
<javaOpt>-Dcassandra.keyspace=${cassandra.keyspace}</javaOpt>
<javaOpt>-Dcassandra.resetdb=true</javaOpt>
<javaOpt>-Dhawkular.metrics.waitForService</javaOpt>
<javaOpt>-Xdebug</javaOpt>
<javaOpt>-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8787</javaOpt>
</javaOpts>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import com.google.common.base.Charsets
import groovyx.net.http.ContentType
import groovyx.net.http.RESTClient

import static org.junit.Assert.fail

class RESTTest {

static baseURI = System.getProperty('hawkular-metrics.base-uri') ?: '127.0.0.1:8080/hawkular/metrics'
Expand All @@ -52,24 +50,6 @@ class RESTTest {
}
defaultFailureHandler(resp)
}
waitAvailable();
}

static void waitAvailable() {
def available = false;
def startTime = System.currentTimeMillis();
while (available != true || (System.currentTimeMillis() - startTime) > 5000) {
def response = hawkularMetrics.get(path: "")
if (response.status != 200) {
wait(500);
} else {
available = true;
}
}

if (available == false) {
fail("Could not connect to the server");
}
}

static String nextTenantId() {
Expand Down

0 comments on commit 2178ac9

Please sign in to comment.