Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Child environment discovery bug fix in hierarchical env shard selector #33

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>io.appform.ranger</groupId>
<artifactId>ranger</artifactId>
<packaging>pom</packaging>
<version>1.0-RC15</version>
<version>1.0-RC16</version>
<name>Ranger</name>
<url>https://github.com/appform-io/ranger</url>
<description>Service Discovery for Java</description>
Expand Down
2 changes: 1 addition & 1 deletion ranger-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ranger</artifactId>
<groupId>io.appform.ranger</groupId>
<version>1.0-RC15</version>
<version>1.0-RC16</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion ranger-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ranger</artifactId>
<groupId>io.appform.ranger</groupId>
<version>1.0-RC15</version>
<version>1.0-RC16</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion ranger-discovery-bundle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ranger</artifactId>
<groupId>io.appform.ranger</groupId>
<version>1.0-RC15</version>
<version>1.0-RC16</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<ShardInfo, ServiceNode<ShardInfo>> 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<ServiceNode<ShardInfo>> 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());

}
}
2 changes: 1 addition & 1 deletion ranger-http-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ranger</artifactId>
<groupId>io.appform.ranger</groupId>
<version>1.0-RC15</version>
<version>1.0-RC16</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion ranger-http-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ranger</artifactId>
<groupId>io.appform.ranger</groupId>
<version>1.0-RC15</version>
<version>1.0-RC16</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion ranger-http-server-bundle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ranger</artifactId>
<groupId>io.appform.ranger</groupId>
<version>1.0-RC15</version>
<version>1.0-RC16</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion ranger-http-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ranger</artifactId>
<groupId>io.appform.ranger</groupId>
<version>1.0-RC15</version>
<version>1.0-RC16</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion ranger-http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ranger</artifactId>
<groupId>io.appform.ranger</groupId>
<version>1.0-RC15</version>
<version>1.0-RC16</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion ranger-server-bundle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ranger</artifactId>
<groupId>io.appform.ranger</groupId>
<version>1.0-RC15</version>
<version>1.0-RC16</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion ranger-server-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ranger</artifactId>
<groupId>io.appform.ranger</groupId>
<version>1.0-RC15</version>
<version>1.0-RC16</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion ranger-zk-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ranger</artifactId>
<groupId>io.appform.ranger</groupId>
<version>1.0-RC15</version>
<version>1.0-RC16</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion ranger-zk-server-bundle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ranger</artifactId>
<groupId>io.appform.ranger</groupId>
<version>1.0-RC15</version>
<version>1.0-RC16</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion ranger-zk-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ranger</artifactId>
<groupId>io.appform.ranger</groupId>
<version>1.0-RC15</version>
<version>1.0-RC16</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion ranger-zookeeper/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>ranger</artifactId>
<groupId>io.appform.ranger</groupId>
<version>1.0-RC15</version>
<version>1.0-RC16</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Loading