Skip to content

Commit

Permalink
fix(vertx): remove vertx dependency (#12)
Browse files Browse the repository at this point in the history
* chore(vertx): remove vertx dependency

* fixup! chore(vertx): remove vertx dependency

* cleanup

* refactor

* fixup

* remove unused version property

* avoid throwing runtime exceptions

* extract constant

* Add specific exception subtype

* minor cleanup
  • Loading branch information
andrewazores authored Dec 16, 2022
1 parent 6ff6c43 commit 2b966dc
Show file tree
Hide file tree
Showing 10 changed files with 430 additions and 279 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ and how it advertises itself to a Cryostat server instance. Required properties
- [ ] `cryostat.agent.hostname` [`String`]: the hostname for this application instance. This will be used for the published JMX connection URL. If not provided then the default is to attempt to resolve the localhost hostname.
- [ ] `cryostat.agent.realm` [`String`]: the Cryostat Discovery API "realm" that this agent belongs to. This should be unique per agent instance. The default includes the `cryostat.agent.app.name` and a random UUID.
- [ ] `cryostat.agent.authorization` [`String`]: Authorization header value to include with API requests to the Cryostat server, ex. `Bearer abcd1234`. Default `None`.
- [ ] `cryostat.agent.trust-all` [`boolean`]: Control whether the agent trusts all certificates presented by the Cryostat server. Default `true`.
- [ ] `cryostat.agent.ssl.trust-all` [`boolean`]: Control whether the agent trusts all certificates presented by the Cryostat server. Default `true`.
- [ ] `cryostat.agent.ssl.verify-hostname` [`boolean`]: Control whether the agent verifies hostnames on certificates presented by the Cryostat server. Default `false`.
- [ ] `cryostat.agent.webserver.host` [`String`]: the internal hostname or IP address for the embedded webserver to bind to. Default `0.0.0.0`.
- [ ] `cryostat.agent.webserver.port` [`int`]: the internal port number for the embedded webserver to bind to. Default `9977`.
- [ ] `cryostat.agent.app.name` [`String`]: a human-friendly name for this application. Default `cryostat-agent`.
Expand Down
23 changes: 1 addition & 22 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.cryostat</groupId>
<artifactId>cryostat-agent</artifactId>
<version>0.1.0-SNAPSHOT</version>
<version>0.2.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>cryostat</name>
<url>http://maven.apache.org</url>
Expand Down Expand Up @@ -43,8 +43,6 @@
<com.google.dagger.compiler.version>2.26</com.google.dagger.compiler.version>

<org.apache.httpcomponents.version>4.5.13</org.apache.httpcomponents.version>
<io.fabric8.client.version>5.12.2</io.fabric8.client.version>
<io.vertx.web.version>4.2.5</io.vertx.web.version>
<com.fasterxml.jackson.version>2.13.3</com.fasterxml.jackson.version>
<javax.annotation.version>1.3.2</javax.annotation.version><!-- used by smallrye -->
<io.smallrye.config.version>2.11.1</io.smallrye.config.version>
Expand All @@ -66,16 +64,6 @@
<artifactId>dagger</artifactId>
<version>${com.google.dagger.version}</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web</artifactId>
<version>${io.vertx.web.version}</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web-client</artifactId>
<version>${io.vertx.web.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
Expand Down Expand Up @@ -166,15 +154,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.reactiverse</groupId>
<artifactId>vertx-maven-plugin</artifactId>
<version>${io.reactiverse.plugin.version}</version>
<configuration>
<redeploy>true</redeploy>
<launcher>${mainClass}</launcher>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down
72 changes: 30 additions & 42 deletions src/main/java/io/cryostat/agent/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,13 @@
*/
package io.cryostat.agent;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import javax.inject.Singleton;

import dagger.Component;
import io.vertx.core.CompositeFuture;
import io.vertx.core.Future;
import io.vertx.core.Promise;
import io.vertx.core.Vertx;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sun.misc.Signal;
Expand All @@ -58,21 +54,8 @@ public class Agent {
private static Logger log = LoggerFactory.getLogger(Agent.class);

public static void main(String[] args) {
List<Future> futures = new ArrayList<>();
final Client client = DaggerAgent_Client.builder().build();

Consumer<Promise<Void>> shutdown =
promise -> {
log.info("Shutting down...");
client.vertx()
.close()
.onComplete(
ar -> {
log.info("Shutdown complete");
promise.complete();
});
};

List.of(new Signal("INT"), new Signal("TERM"))
.forEach(
signal -> {
Expand All @@ -82,31 +65,36 @@ public static void main(String[] args) {
log.info("Caught SIG{}({})", s.getName(), s.getNumber());
client.registration()
.deregister()
.onComplete(
ar -> {
Promise<Void> promise =
Promise.promise();
shutdown.accept(promise);
promise.future()
.onComplete(
unused ->
oldHandler
.handle(
s));
});
.orTimeout(1, TimeUnit.SECONDS)
.thenRunAsync(
() -> {
try {
log.info("Shutting down...");
client.webServer().stop();
client.registration().stop();
client.executor().shutdown();
} catch (Exception e) {
log.warn(
"Exception during shutdown",
e);
} finally {
log.info("Shutdown complete");
oldHandler.handle(s);
}
},
client.executor());
};
Signal.handle(signal, handler);
});

futures.add(client.vertx().deployVerticle(client.registration()));

CompositeFuture.join(futures)
.onSuccess(ar -> log.info("Startup complete"))
.onFailure(
t -> {
log.error("Verticle failure", t);
client.vertx().close();
});
try {
client.registration().start();
client.webServer().start();
} catch (Exception e) {
log.error(Agent.class.getSimpleName() + " startup failure", e);
return;
}
log.info("Startup complete");
}

public static void agentmain(String args) {
Expand All @@ -128,12 +116,12 @@ public static void premain(String args) {
@Singleton
@Component(modules = {MainModule.class})
interface Client {
Vertx vertx();

WebServer webServer();

Registration registration();

ScheduledExecutorService executor();

@Component.Builder
interface Builder {
Client build();
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/io/cryostat/agent/ConfigModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public abstract class ConfigModule {
public static final String CRYOSTAT_AGENT_CALLBACK = "cryostat.agent.callback";
public static final String CRYOSTAT_AGENT_REALM = "cryostat.agent.realm";
public static final String CRYOSTAT_AGENT_AUTHORIZATION = "cryostat.agent.authorization";
public static final String CRYOSTAT_AGENT_TRUST_ALL = "cryostat.agent.trust-all";
public static final String CRYOSTAT_AGENT_SSL_TRUST_ALL = "cryostat.agent.ssl.trust-all";
public static final String CRYOSTAT_AGENT_SSL_VERIFY_HOSTNAME =
"cryostat.agent.ssl.verify-hostname";

public static final String CRYOSTAT_AGENT_WEBSERVER_HOST = "cryostat.agent.webserver.host";
public static final String CRYOSTAT_AGENT_WEBSERVER_PORT = "cryostat.agent.webserver.port";
Expand Down Expand Up @@ -111,9 +113,16 @@ public static String provideCryostatAgentAuthorization(SmallRyeConfig config) {

@Provides
@Singleton
@Named(CRYOSTAT_AGENT_TRUST_ALL)
@Named(CRYOSTAT_AGENT_SSL_TRUST_ALL)
public static boolean provideCryostatAgentTrustAll(SmallRyeConfig config) {
return config.getValue(CRYOSTAT_AGENT_TRUST_ALL, boolean.class);
return config.getValue(CRYOSTAT_AGENT_SSL_TRUST_ALL, boolean.class);
}

@Provides
@Singleton
@Named(CRYOSTAT_AGENT_SSL_VERIFY_HOSTNAME)
public static boolean provideCryostatAgentVerifyHostname(SmallRyeConfig config) {
return config.getValue(CRYOSTAT_AGENT_SSL_VERIFY_HOSTNAME, boolean.class);
}

@Provides
Expand Down
Loading

0 comments on commit 2b966dc

Please sign in to comment.