Skip to content

Commit

Permalink
Removed the explicit constructor in ServiceNode
Browse files Browse the repository at this point in the history
  • Loading branch information
koushikr committed Dec 27, 2021
1 parent 8fcac41 commit 234c388
Show file tree
Hide file tree
Showing 27 changed files with 24 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.flipkart.ranger.core.finder.ServiceFinder;
import com.flipkart.ranger.core.model.ServiceNode;
import com.flipkart.ranger.core.model.ServiceRegistry;
import lombok.val;

import java.util.List;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.google.common.base.Preconditions;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import lombok.val;

import java.util.Collection;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

import com.flipkart.ranger.client.utils.RangerHubTestUtils;
import com.flipkart.ranger.core.model.Service;
import com.flipkart.ranger.core.model.ServiceNode;
import com.flipkart.ranger.core.units.TestNodeData;
import com.flipkart.ranger.core.utils.RangerTestUtils;
import com.flipkart.ranger.core.utils.TestUtils;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -27,8 +25,6 @@
import org.junit.Assert;
import org.junit.Test;

import java.util.Optional;

@Slf4j
public class AbstractRangerHubClientTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ static class TestDataSource implements NodeDataSource<TestNodeData, Deserializer
@Override
public List<ServiceNode<TestNodeData>> refresh(Deserializer<TestNodeData> deserializer) {
return Collections.singletonList(
new ServiceNode<>("localhost", 9200, TestNodeData.builder().shardId(1).build())
ServiceNode.<TestNodeData>builder()
.host("localhost")
.port(9200)
.nodeData(TestNodeData.builder().shardId(1).build())
.build()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import lombok.extern.slf4j.Slf4j;
import lombok.var;

import javax.swing.text.html.Option;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.google.common.collect.ImmutableList;
import lombok.val;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package com.flipkart.ranger.core.healthcheck;

import lombok.Builder;
import lombok.Data;
import lombok.Value;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.Date;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,22 @@
package com.flipkart.ranger.core.model;

import com.flipkart.ranger.core.healthcheck.HealthcheckStatus;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ServiceNode<T> {
private String host;
private int port;
private T nodeData;
private HealthcheckStatus healthcheckStatus = HealthcheckStatus.healthy;
private long lastUpdatedTimeStamp = Long.MIN_VALUE;

public ServiceNode() {
}

public ServiceNode(String host, int port, T nodeData) {
this.host = host;
this.port = port;
this.nodeData = nodeData;
}

public String representation() {
return String.format("%s:%d", host, port);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ protected final ServiceProvider<T, S> buildProvider() {
.add(healthcheckUpdateSignalGenerator)
.addAll(additionalRefreshSignals)
.build();
val serviceProvider = new ServiceProvider<>(service,
new ServiceNode<>(hostname, port, nodeData),
val serviceProvider = new ServiceProvider<>(service, ServiceNode.<T>builder().host(hostname).port(port).nodeData(nodeData).build(),
serializer,
usableNodeDataSource,
signalGenerators);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.flipkart.ranger.core.model.ServiceNode;
import com.flipkart.ranger.core.units.TestNodeData;
import lombok.val;
import lombok.var;
import org.junit.Assert;
import org.junit.Test;

Expand All @@ -29,9 +28,9 @@ public class RoundRobinServiceNodeSelectorTest {
public void testRandomNodeSelector(){
val roundRobinSelector = new RoundRobinServiceNodeSelector<TestNodeData>();
val serviceNodes = new ArrayList<ServiceNode<TestNodeData>>();
serviceNodes.add(new ServiceNode<>("localhost-1", 9000, TestNodeData.builder().shardId(1).build()));
serviceNodes.add(new ServiceNode<>("localhost-2", 9001, TestNodeData.builder().shardId(2).build()));
serviceNodes.add(new ServiceNode<>("localhost-3", 9002, TestNodeData.builder().shardId(3).build()));
serviceNodes.add(ServiceNode.<TestNodeData>builder().host("localhost-1").port(9000).nodeData(TestNodeData.builder().shardId(1).build()).build());
serviceNodes.add(ServiceNode.<TestNodeData>builder().host("localhost-2").port(9001).nodeData(TestNodeData.builder().shardId(2).build()).build());
serviceNodes.add(ServiceNode.<TestNodeData>builder().host("localhost-3").port(9002).nodeData(TestNodeData.builder().shardId(3).build()).build());
Assert.assertEquals("localhost-2", roundRobinSelector.select(serviceNodes).getHost());
Assert.assertEquals("localhost-3", roundRobinSelector.select(serviceNodes).getHost());
Assert.assertEquals("localhost-1", roundRobinSelector.select(serviceNodes).getHost());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public static MapBasedServiceRegistry<TestNodeData> getServiceRegistry(){
val service = RangerTestUtils.getService();
val serviceRegistry = new MapBasedServiceRegistry<TestNodeData>(service);
val serviceNodes = ImmutableList.of(
new ServiceNode<>("localhost-1", 9000, TestNodeData.builder().shardId(1).build()),
new ServiceNode<>("localhost-2", 9001, TestNodeData.builder().shardId(2).build()),
new ServiceNode<>("localhost-3", 9002, TestNodeData.builder().shardId(3).build())
ServiceNode.<TestNodeData>builder().host("localhost-1").port(9000).nodeData(TestNodeData.builder().shardId(1).build()).build(),
ServiceNode.<TestNodeData>builder().host("localhost-2").port(9001).nodeData(TestNodeData.builder().shardId(2).build()).build(),
ServiceNode.<TestNodeData>builder().host("localhost-3").port(9002).nodeData(TestNodeData.builder().shardId(3).build()).build()
);
serviceRegistry.updateNodes(serviceNodes);
return serviceRegistry;
Expand All @@ -42,9 +42,9 @@ public static ListBasedServiceRegistry<TestNodeData> getUnshardedRegistry(){
val service = RangerTestUtils.getService();
val serviceRegistry = new ListBasedServiceRegistry<TestNodeData>(service);
val serviceNodes = ImmutableList.of(
new ServiceNode<>("localhost-1", 9000, TestNodeData.builder().shardId(1).build()),
new ServiceNode<>("localhost-2", 9001, TestNodeData.builder().shardId(2).build()),
new ServiceNode<>("localhost-3", 9002, TestNodeData.builder().shardId(3).build())
ServiceNode.<TestNodeData>builder().host("localhost-1").port(9000).nodeData(TestNodeData.builder().shardId(1).build()).build(),
ServiceNode.<TestNodeData>builder().host("localhost-2").port(9001).nodeData(TestNodeData.builder().shardId(2).build()).build(),
ServiceNode.<TestNodeData>builder().host("localhost-3").port(9002).nodeData(TestNodeData.builder().shardId(3).build()).build()
);
serviceRegistry.updateNodes(serviceNodes);
return serviceRegistry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public abstract class BaseRangerHttpClientTest {
@Before
public void startTestCluster() throws Exception {
val testNode = TestNodeData.builder().shardId(1).build();
val node = new ServiceNode<>("127.0.0.1", 80, testNode);
val node = ServiceNode.<TestNodeData>builder().host("127.0.0.1").port(80).nodeData(testNode).build();
node.setHealthcheckStatus(HealthcheckStatus.healthy);
node.setLastUpdatedTimeStamp(System.currentTimeMillis());
val payload = objectMapper.writeValueAsBytes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
*/
package com.flipkart.ranger.client.http;

import com.flipkart.ranger.core.model.ServiceNode;
import com.flipkart.ranger.core.units.TestNodeData;
import com.flipkart.ranger.core.utils.RangerTestUtils;
import com.flipkart.ranger.core.utils.TestUtils;
import lombok.val;
import lombok.var;
import org.junit.Assert;
import org.junit.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.flipkart.ranger.client.http;

import com.flipkart.ranger.core.model.ServiceNode;
import com.flipkart.ranger.core.units.TestNodeData;
import com.flipkart.ranger.core.utils.TestUtils;
import lombok.val;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.flipkart.ranger.client.http;

import com.flipkart.ranger.core.model.ServiceNode;
import com.flipkart.ranger.core.units.TestNodeData;
import com.flipkart.ranger.core.utils.RangerTestUtils;
import com.flipkart.ranger.core.utils.TestUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public NodeData(@JsonProperty("name") String name) {
@Test
public void testFinder() throws Exception {
val testNode = new NodeData("testNode");
val node = new ServiceNode<>("127.0.0.1", 80, testNode);
val node = ServiceNode.<NodeData>builder().host("127.0.0.1").port(80).nodeData(testNode).build();
node.setHealthcheckStatus(HealthcheckStatus.healthy);
node.setLastUpdatedTimeStamp(System.currentTimeMillis());
val payload = MAPPER.writeValueAsBytes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public TestNodeData(@JsonProperty("farmId") String farmId) {
@Test
public void testProvider() throws Exception {
val farmNodeData = TestNodeData.builder().farmId("farm1").build();
val testNode = new ServiceNode<>("localhost-1", 80, farmNodeData);
val testNode = ServiceNode.<TestNodeData>builder().host("127.0.0.1").port(80).nodeData(farmNodeData).build();
val response = MAPPER.writeValueAsBytes(
GenericResponse.builder()
.code(RangerResponseCode.SUCCESS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.flipkart.ranger.client.RangerHubClient;
import com.flipkart.ranger.client.utils.RangerHubTestUtils;
import com.flipkart.ranger.core.model.ServiceNode;
import com.flipkart.ranger.core.units.TestNodeData;
import com.flipkart.ranger.core.utils.RangerTestUtils;
import com.flipkart.ranger.core.utils.TestUtils;
Expand All @@ -42,7 +41,6 @@

import java.util.Collections;
import java.util.List;
import java.util.Optional;

import static com.flipkart.ranger.client.utils.RangerHubTestUtils.service;
import static org.mockito.ArgumentMatchers.any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.junit.Test;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.stream.Collectors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.flipkart.ranger.client.zk;

import com.flipkart.ranger.core.model.ServiceNode;
import com.flipkart.ranger.core.units.TestNodeData;
import com.flipkart.ranger.core.utils.RangerTestUtils;
import com.flipkart.ranger.core.utils.TestUtils;
Expand All @@ -24,8 +23,6 @@
import org.junit.Assert;
import org.junit.Test;

import java.util.Optional;

@Slf4j
public class ShardedZKRangerClientTest extends BaseRangerZKClientTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@
*/
package com.flipkart.ranger.client.zk;

import com.flipkart.ranger.core.model.ServiceNode;
import com.flipkart.ranger.core.units.TestNodeData;
import lombok.val;
import org.junit.Assert;
import org.junit.Test;

import java.util.Optional;

public class SimpleRangerZKClientTest extends BaseRangerZKClientTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.flipkart.ranger.client.zk;

import com.flipkart.ranger.core.model.ServiceNode;
import com.flipkart.ranger.core.units.TestNodeData;
import com.flipkart.ranger.core.utils.RangerTestUtils;
import com.flipkart.ranger.core.utils.TestUtils;
Expand All @@ -24,8 +23,6 @@
import org.junit.Assert;
import org.junit.Test;

import java.util.Optional;

@Slf4j
public class UnshardedZKRangerClientTest extends BaseRangerZKClientTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import lombok.var;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import lombok.var;
import org.apache.curator.test.TestingCluster;
import org.junit.After;
import org.junit.Assert;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.flipkart.ranger.zookeeper.ServiceFinderBuilders;
import com.flipkart.ranger.zookeeper.ServiceProviderBuilders;
import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multiset;
import lombok.val;
import org.apache.curator.test.TestingCluster;
import org.junit.After;
Expand Down

0 comments on commit 234c388

Please sign in to comment.