Skip to content

Commit

Permalink
Add Stork + k8s coverage
Browse files Browse the repository at this point in the history
- default service discovery
- default load balncer
  • Loading branch information
pablo gonzalez granados committed Mar 21, 2022
1 parent 40b0804 commit fb8ec0b
Show file tree
Hide file tree
Showing 19 changed files with 209 additions and 164 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -651,9 +651,9 @@ this.router.get("/secured")
* authZ::authorize: custom AuthZ(authorization) provider.
* secure.helloWorld(rc): actual http endpoint (Rest layer).

### Service-discovery/stork-consul
### Service-discovery/stork

Verifies Stork-consul integration in order to provide service discovering and round-robin load balancing between services
Verifies Stork integration in order to provide service discovering and round-robin load balancing between services

`StorkServiceDiscoveryIT` scenario deploys four services:
* Pung: is a simple endpoint that returns "pung" as a string
Expand All @@ -662,8 +662,6 @@ Verifies Stork-consul integration in order to provide service discovering and ro
* Ping: is the main client microservice that will use `pung` and `pong` (Pong and PongReplica) services. The service
discovery will be done by Stork, and the request dispatching between "pong" services is going to be done by Stork load balancer.



### `monitoring/microprofile`

Verifies combined usage of MicroProfile RestClient, Fault Tolerance and OpenTracing.
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@
<module>docker-build</module>
<module>javaee-like-getting-started</module>
<module>scaling</module>
<module>service-discovery/stork-consul</module>
<module>service-discovery/stork</module>
<module>lifecycle-application</module>
<module>external-applications</module>
<module>scheduling/quartz</module>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</parent>
<artifactId>stork</artifactId>
<packaging>jar</packaging>
<name>Quarkus QE TS: Service-discovery: Stork-consul</name>
<name>Quarkus QE TS: Service-discovery: Stork</name>
<dependencies>
<dependency>
<groupId>io.smallrye.stork</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import javax.ws.rs.core.MediaType;

import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
import org.jboss.resteasy.reactive.RestResponse;

import io.smallrye.mutiny.Uni;

Expand All @@ -15,5 +16,5 @@ public interface MyBackendPongProxy {
@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("/")
Uni<String> get();
Uni<RestResponse<String>> get();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,27 @@
@RouteBase(path = "/ping", produces = MediaType.TEXT_PLAIN)
public class PingResource {

public static final String PING_PREFIX = "ping-";
public static final String HEADER_ID = "x-id";

@RestClient
MyBackendPongProxy pongService;

@RestClient
MyBackendPungProxy pungService;

@Route(methods = Route.HttpMethod.GET, path = "/pung")
public Uni<String> pung(RoutingContext context) {
return formatResponse(pungService.get());
public Uni<String> pung() {
return pungService.get()
.onFailure().transform(error -> new WebApplicationException(error.getMessage()))
.map(resp -> PING_PREFIX + resp);
}

@Route(methods = Route.HttpMethod.GET, path = "/pong")
public Uni<String> pong(RoutingContext context) {
return formatResponse(pongService.get());
}

private Uni<String> formatResponse(Uni<String> response) {
return response
.onFailure().transform(error -> new WebApplicationException(error.getMessage()))
.map(resp -> "ping-" + resp);
public void pong(RoutingContext context) {
pongService.get().onFailure().transform(error -> new WebApplicationException(error.getMessage())).subscribe()
.with(resp -> context.response()
.putHeader(HEADER_ID, resp.getHeaderString(HEADER_ID))
.end(PING_PREFIX + resp.getEntity()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,26 @@ public class PongReplicaResource {

private static final String DEFAULT_PONG_REPLICA_RESPONSE = "pongReplica";

@ConfigProperty(name = "stork.pong-replica.service-discovery.consul-host")
@ConfigProperty(name = "stork.pong-replica.service-discovery.consul-host", defaultValue = "localhost")
String host;
@ConfigProperty(name = "stork.pong-replica.service-discovery.consul-port")
@ConfigProperty(name = "stork.pong-replica.service-discovery.consul-port", defaultValue = "8500")
String port;
@ConfigProperty(name = "pong-replica-service-port")
@ConfigProperty(name = "pong-replica-service-port", defaultValue = "8080")
String pongPort;
@ConfigProperty(name = "pong-replica-service-host")
@ConfigProperty(name = "pong-replica-service-host", defaultValue = "localhost")
String pongHost;
@ConfigProperty(name = "stork.pong-replica.service-discovery", defaultValue = "consul")
String serviceDiscoveryType;

public void init(@Observes StartupEvent ev, Vertx vertx) {
ConsulClient client = ConsulClient.create(vertx,
new ConsulClientOptions().setHost(host).setPort(Integer.parseInt(port)));

client.registerServiceAndAwait(
new ServiceOptions().setPort(Integer.parseInt(pongPort)).setAddress(pongHost).setName(PONG_SERVICE_NAME)
.setId("pongReplica"));
if (serviceDiscoveryType.equalsIgnoreCase("consul")) {
ConsulClient client = ConsulClient.create(vertx,
new ConsulClientOptions().setHost(host).setPort(Integer.parseInt(port)));

client.registerServiceAndAwait(
new ServiceOptions().setPort(Integer.parseInt(pongPort)).setAddress(pongHost).setName(PONG_SERVICE_NAME)
.setId("pongReplica"));
}
}

@Route(path = "/", methods = Route.HttpMethod.GET)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.quarkus.ts.stork;

import java.util.UUID;

import javax.enterprise.event.Observes;
import javax.ws.rs.core.MediaType;

import org.eclipse.microprofile.config.inject.ConfigProperty;

import io.quarkus.runtime.StartupEvent;
import io.quarkus.vertx.web.Route;
import io.quarkus.vertx.web.RouteBase;
import io.vertx.ext.consul.ConsulClientOptions;
import io.vertx.ext.consul.ServiceOptions;
import io.vertx.ext.web.RoutingContext;
import io.vertx.mutiny.core.Vertx;
import io.vertx.mutiny.ext.consul.ConsulClient;

@RouteBase(path = "/pong", produces = MediaType.TEXT_PLAIN)
public class PongResource {

public static final String PONG_SERVICE_NAME = "pong";
private static final String DEFAULT_PONG_RESPONSE = "pong";
private static final String HEADER_ID = "x-id";
private String instanceUniqueId;

@ConfigProperty(name = "stork.pong.service-discovery.consul-host", defaultValue = "localhost")
String host;
@ConfigProperty(name = "stork.pong.service-discovery.consul-port", defaultValue = "8500")
String port;
@ConfigProperty(name = "pong-service-port", defaultValue = "8080")
String pongPort;
@ConfigProperty(name = "pong-service-host", defaultValue = "localhost")
String pongHost;
@ConfigProperty(name = "stork.pong.service-discovery", defaultValue = "consul")
String serviceDiscoveryType;

public void init(@Observes StartupEvent ev, Vertx vertx) {
instanceUniqueId = UUID.randomUUID().toString();
if (serviceDiscoveryType.equalsIgnoreCase("consul")) {
ConsulClient client = ConsulClient.create(vertx,
new ConsulClientOptions().setHost(host).setPort(Integer.parseInt(port)));

client.registerServiceAndAwait(
new ServiceOptions().setPort(Integer.parseInt(pongPort)).setAddress(pongHost).setName(PONG_SERVICE_NAME)
.setId("pong"));
}
}

@Route(path = "/", methods = Route.HttpMethod.GET)
public void pong(final RoutingContext context) {
context.response().putHeader(HEADER_ID, instanceUniqueId).end(DEFAULT_PONG_RESPONSE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# application properties should be here
# TODO https://github.com/quarkusio/quarkus/issues/24444
quarkus.native.additional-build-args=--allow-incomplete-classpath, --initialize-at-run-time=io.fabric8.kubernetes.client.internal.CertUtils, --enable-url-protocols=https
Loading

0 comments on commit fb8ec0b

Please sign in to comment.