diff --git a/CHANGELOG.md b/CHANGELOG.md
index a758d08b..64e736ce 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,9 @@
# Changelog
All notable changes to this project will be documented in this file.
+## [1.0-RC16]
+- Fixed hierarchical environment aware shard selector : If a service is deployed with environment : env.x.y.z then it should be able to discover other services present in environment - [env , env.x , env.x.y, env.x.y.z ]
+
## [1.0-RC15]
- Moved discovery bundle from https://github.com/appform-io/dropwizard-service-discovery.
- Updated to dropwizard version 2.1.10 : BOM update.
diff --git a/pom.xml b/pom.xml
index b14a9849..8e8ccebb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
io.appform.ranger
ranger
pom
- 1.0-RC15
+ 1.0-RC16
Ranger
https://github.com/appform-io/ranger
Service Discovery for Java
diff --git a/ranger-client/pom.xml b/ranger-client/pom.xml
index 727e9c1b..6b6f2107 100644
--- a/ranger-client/pom.xml
+++ b/ranger-client/pom.xml
@@ -5,7 +5,7 @@
ranger
io.appform.ranger
- 1.0-RC15
+ 1.0-RC16
4.0.0
diff --git a/ranger-core/pom.xml b/ranger-core/pom.xml
index 634ab4a9..163a05a4 100644
--- a/ranger-core/pom.xml
+++ b/ranger-core/pom.xml
@@ -5,7 +5,7 @@
ranger
io.appform.ranger
- 1.0-RC15
+ 1.0-RC16
4.0.0
diff --git a/ranger-discovery-bundle/pom.xml b/ranger-discovery-bundle/pom.xml
index a0d4245d..d4b71e20 100644
--- a/ranger-discovery-bundle/pom.xml
+++ b/ranger-discovery-bundle/pom.xml
@@ -5,7 +5,7 @@
ranger
io.appform.ranger
- 1.0-RC15
+ 1.0-RC16
4.0.0
diff --git a/ranger-discovery-bundle/src/main/java/io/appform/ranger/discovery/bundle/selectors/HierarchicalEnvironmentAwareShardSelector.java b/ranger-discovery-bundle/src/main/java/io/appform/ranger/discovery/bundle/selectors/HierarchicalEnvironmentAwareShardSelector.java
index c3f442d3..34682111 100644
--- a/ranger-discovery-bundle/src/main/java/io/appform/ranger/discovery/bundle/selectors/HierarchicalEnvironmentAwareShardSelector.java
+++ b/ranger-discovery-bundle/src/main/java/io/appform/ranger/discovery/bundle/selectors/HierarchicalEnvironmentAwareShardSelector.java
@@ -109,7 +109,7 @@ public IterableEnvironment next() {
}
log.debug("Effective environment for discovery is {}", remainingEnvironment);
val shardInfo = new IterableEnvironment(remainingEnvironment, separator);
- val sepIndex = remainingEnvironment.indexOf(this.separator);
+ val sepIndex = remainingEnvironment.lastIndexOf(this.separator);
remainingEnvironment = sepIndex < 0
? ""
: remainingEnvironment.substring(0, sepIndex);
diff --git a/ranger-discovery-bundle/src/test/java/io/appform/ranger/discovery/bundle/selectors/HierarchicalEnvironmentAwareShardSelectorTest.java b/ranger-discovery-bundle/src/test/java/io/appform/ranger/discovery/bundle/selectors/HierarchicalEnvironmentAwareShardSelectorTest.java
index 472919c1..b9259b95 100644
--- a/ranger-discovery-bundle/src/test/java/io/appform/ranger/discovery/bundle/selectors/HierarchicalEnvironmentAwareShardSelectorTest.java
+++ b/ranger-discovery-bundle/src/test/java/io/appform/ranger/discovery/bundle/selectors/HierarchicalEnvironmentAwareShardSelectorTest.java
@@ -18,6 +18,7 @@
package io.appform.ranger.discovery.bundle.selectors;
import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ListMultimap;
import io.appform.ranger.common.server.ShardInfo;
import io.appform.ranger.core.finder.serviceregistry.MapBasedServiceRegistry;
import io.appform.ranger.core.healthcheck.HealthcheckStatus;
@@ -30,6 +31,7 @@
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
+import java.util.List;
import java.util.UUID;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -148,4 +150,64 @@ void testNoNodeAvailableForChildEnvButAvailableForParentEnv() {
assertEquals("host2", nodes.get(0).getHost());
assertEquals(9999, nodes.get(0).getPort());
}
+
+ @Test
+ void testChildNodesAvailableForParentEnv() {
+ val serviceName = UUID.randomUUID().toString();
+ val service = Mockito.mock(Service.class);
+ doReturn(serviceName).when(service).getServiceName();
+ doReturn(service).when(serviceRegistry).getService();
+
+ // service in env: x.y.z should be able to discover service in env: x
+ ListMultimap> serviceNodes = ArrayListMultimap.create();
+ serviceNodes.put(
+ ShardInfo.builder().environment("x").build(),
+ new ServiceNode<>("host1",
+ 8888,
+ ShardInfo.builder().environment("x").build(),
+ HealthcheckStatus.healthy,
+ System.currentTimeMillis(),
+ "http"));
+ doReturn(serviceNodes).when(serviceRegistry).nodes();
+
+ List> nodes = selector("x.y.z").nodes(null, serviceRegistry);
+ assertEquals(1, nodes.size());
+ assertEquals("host1", nodes.get(0).getHost());
+ assertEquals(8888, nodes.get(0).getPort());
+
+ // service in env: x.y.z should be able to discover service in env: x.y
+ serviceNodes = ArrayListMultimap.create();
+ serviceNodes.put(
+ ShardInfo.builder().environment("x.y").build(),
+ new ServiceNode<>("host2",
+ 9999,
+ ShardInfo.builder().environment("x.y").build(),
+ HealthcheckStatus.healthy,
+ System.currentTimeMillis(),
+ "http"));
+ doReturn(serviceNodes).when(serviceRegistry).nodes();
+
+ nodes = selector("x.y.z").nodes(null, serviceRegistry);
+ assertEquals(1, nodes.size());
+ assertEquals("host2", nodes.get(0).getHost());
+ assertEquals(9999, nodes.get(0).getPort());
+
+ // service in env: x.y.z should be able to discover service in env: x
+ serviceNodes = ArrayListMultimap.create();
+ serviceNodes.put(
+ ShardInfo.builder().environment("x").build(),
+ new ServiceNode<>("host3",
+ 9999,
+ ShardInfo.builder().environment("x").build(),
+ HealthcheckStatus.healthy,
+ System.currentTimeMillis(),
+ "http"));
+ doReturn(serviceNodes).when(serviceRegistry).nodes();
+
+ nodes = selector("x.y.z").nodes(null, serviceRegistry);
+ assertEquals(1, nodes.size());
+ assertEquals("host3", nodes.get(0).getHost());
+ assertEquals(9999, nodes.get(0).getPort());
+
+ }
}
\ No newline at end of file
diff --git a/ranger-http-client/pom.xml b/ranger-http-client/pom.xml
index ff13feea..ccab0446 100644
--- a/ranger-http-client/pom.xml
+++ b/ranger-http-client/pom.xml
@@ -5,7 +5,7 @@
ranger
io.appform.ranger
- 1.0-RC15
+ 1.0-RC16
4.0.0
diff --git a/ranger-http-model/pom.xml b/ranger-http-model/pom.xml
index d3937423..fcbb1717 100644
--- a/ranger-http-model/pom.xml
+++ b/ranger-http-model/pom.xml
@@ -5,7 +5,7 @@
ranger
io.appform.ranger
- 1.0-RC15
+ 1.0-RC16
4.0.0
diff --git a/ranger-http-server-bundle/pom.xml b/ranger-http-server-bundle/pom.xml
index 740183ff..b375ad63 100644
--- a/ranger-http-server-bundle/pom.xml
+++ b/ranger-http-server-bundle/pom.xml
@@ -5,7 +5,7 @@
ranger
io.appform.ranger
- 1.0-RC15
+ 1.0-RC16
4.0.0
diff --git a/ranger-http-server/pom.xml b/ranger-http-server/pom.xml
index 4989fdb9..728ba499 100644
--- a/ranger-http-server/pom.xml
+++ b/ranger-http-server/pom.xml
@@ -5,7 +5,7 @@
ranger
io.appform.ranger
- 1.0-RC15
+ 1.0-RC16
4.0.0
diff --git a/ranger-http/pom.xml b/ranger-http/pom.xml
index ab190b79..d4fab212 100644
--- a/ranger-http/pom.xml
+++ b/ranger-http/pom.xml
@@ -5,7 +5,7 @@
ranger
io.appform.ranger
- 1.0-RC15
+ 1.0-RC16
4.0.0
diff --git a/ranger-server-bundle/pom.xml b/ranger-server-bundle/pom.xml
index ba3c9510..90631e93 100644
--- a/ranger-server-bundle/pom.xml
+++ b/ranger-server-bundle/pom.xml
@@ -5,7 +5,7 @@
ranger
io.appform.ranger
- 1.0-RC15
+ 1.0-RC16
4.0.0
diff --git a/ranger-server-common/pom.xml b/ranger-server-common/pom.xml
index ab777715..881aaf05 100644
--- a/ranger-server-common/pom.xml
+++ b/ranger-server-common/pom.xml
@@ -5,7 +5,7 @@
ranger
io.appform.ranger
- 1.0-RC15
+ 1.0-RC16
4.0.0
diff --git a/ranger-zk-client/pom.xml b/ranger-zk-client/pom.xml
index 8b6443d3..b567bd5f 100644
--- a/ranger-zk-client/pom.xml
+++ b/ranger-zk-client/pom.xml
@@ -5,7 +5,7 @@
ranger
io.appform.ranger
- 1.0-RC15
+ 1.0-RC16
4.0.0
diff --git a/ranger-zk-server-bundle/pom.xml b/ranger-zk-server-bundle/pom.xml
index cf76d7d5..1ead47a8 100644
--- a/ranger-zk-server-bundle/pom.xml
+++ b/ranger-zk-server-bundle/pom.xml
@@ -5,7 +5,7 @@
ranger
io.appform.ranger
- 1.0-RC15
+ 1.0-RC16
4.0.0
diff --git a/ranger-zk-server/pom.xml b/ranger-zk-server/pom.xml
index b4a7f298..3c5a01c9 100644
--- a/ranger-zk-server/pom.xml
+++ b/ranger-zk-server/pom.xml
@@ -5,7 +5,7 @@
ranger
io.appform.ranger
- 1.0-RC15
+ 1.0-RC16
4.0.0
diff --git a/ranger-zookeeper/pom.xml b/ranger-zookeeper/pom.xml
index e9356012..a92e1b65 100644
--- a/ranger-zookeeper/pom.xml
+++ b/ranger-zookeeper/pom.xml
@@ -5,7 +5,7 @@
ranger
io.appform.ranger
- 1.0-RC15
+ 1.0-RC16
4.0.0