Skip to content

Commit

Permalink
added flag to disable cart discovery and use routes instead for blue/…
Browse files Browse the repository at this point in the history
…green
  • Loading branch information
siamaksade committed Oct 10, 2017
1 parent 1123ebc commit acce376
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,9 @@ public void start() {

// Cart lookup
Single<WebClient> cartDiscoveryRequest;
String cartEndpoint = System.getenv("CART_ENDPOINT_HOST");

if (cartEndpoint != null) {
cartDiscoveryRequest = Single.just(WebClient.create(vertx,
new WebClientOptions()
.setDefaultHost(cartEndpoint)
.setDefaultPort(80)));
if (Boolean.parseBoolean(System.getenv("DISABLE_CART_DISCOVERY"))) {
LOG.info("Disable Cart discovery");
cartDiscoveryRequest = Single.just(null);
} else {
cartDiscoveryRequest = HttpEndpoint.rxGetWebClient(discovery,
rec -> rec.getName().equals("cart"))
Expand Down Expand Up @@ -146,6 +142,10 @@ private void products(RoutingContext rc) {
private void getCart(RoutingContext rc) {
String cartId = rc.request().getParam("cartId");

if (cart == null) {
initCartClient(rc);
}

circuit.executeWithFallback(
future -> {
cart.get("/api/cart/" + cartId).as(BodyCodec.jsonObject())
Expand All @@ -166,6 +166,10 @@ private void addToCart(RoutingContext rc) {
String itemId = rc.request().getParam("itemId");
String quantity = rc.request().getParam("quantity");

if (cart == null) {
initCartClient(rc);
}

circuit.executeWithFallback(
future -> {
cart.post("/api/cart/" + cartId + "/" + itemId + "/" + quantity)
Expand All @@ -187,6 +191,10 @@ private void deleteFromCart(RoutingContext rc) {
String itemId = rc.request().getParam("itemId");
String quantity = rc.request().getParam("quantity");

if (cart == null) {
initCartClient(rc);
}

circuit.executeWithFallback(
future -> {
cart.delete("/api/cart/" + cartId + "/" + itemId + "/" + quantity)
Expand All @@ -202,4 +210,13 @@ private void deleteFromCart(RoutingContext rc) {
});
}, v -> new JsonObject());
}

private void initCartClient(RoutingContext rc) {
String cartRoute = rc.request().host().replaceAll("^gw-(.*)$", "cart-$1");
LOG.info("Initiaizing Cart webclient at {}", cartRoute);
cart = WebClient.create(vertx,
new WebClientOptions()
.setDefaultHost(cartRoute)
.setDefaultPort(80));
}
}
4 changes: 2 additions & 2 deletions openshift/coolstore-deployment-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ objects:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: CART_ENDPOINT
value: cart-${HOSTNAME_SUFFIX}
- name: DISABLE_CART_DISCOVERY
value: true
image: library/coolstore-gw:${APP_VERSION}
livenessProbe:
httpGet:
Expand Down

0 comments on commit acce376

Please sign in to comment.