-
Notifications
You must be signed in to change notification settings - Fork 21
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
Http service #22
base: master
Are you sure you want to change the base?
Http service #22
Conversation
import java.util.List; | ||
import java.util.concurrent.*; | ||
|
||
public abstract class AbstractServiceRegistry<T> implements ServiceRegistry<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this class
} | ||
} | ||
|
||
protected abstract List<ServiceNode<T>> getServiceNodes(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename this method
import org.slf4j.LoggerFactory; | ||
|
||
public class HttpSourceConfig extends SourceConfig{ | ||
private static final Logger logger = LoggerFactory.getLogger(CuratorSourceConfig.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong class, should be HttpSourceConfig
|
||
public class Service { | ||
private CuratorFramework curatorFramework; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove curatorFramework from the config
@@ -0,0 +1,7 @@ | |||
package com.flipkart.ranger.finder; | |||
|
|||
public interface ServiceVisitor<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename this class, to maybe SourceConfigVisitor
@@ -27,12 +27,12 @@ | |||
import java.util.List; | |||
import java.util.concurrent.atomic.AtomicReference; | |||
|
|||
public class MapBasedServiceRegistry<T> extends AbstractZookeeperServiceRegistry<T> { | |||
public class MapBasedServiceRegistry<T> extends AbstractServiceRegistry<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be implementing ServiceRegistry directly
private String namespace; | ||
private String serviceName; | ||
private CuratorFramework curatorFramework; | ||
private String host; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep only curatorFramework
and curatorSourceConfig
and httpSourceConfig
and simplify the builders to withCuratorSourceConfig()
and withHttpSourceConfig()
|
||
@Override | ||
public void start() throws Exception { | ||
curatorFramework = config.getCuratorFramework(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
start the curator framework here
.namespace(namespace) | ||
.connectString(connectionString) | ||
.retryPolicy(new ExponentialBackoffRetry(1000, 100)).build(); | ||
curatorFramework.start(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will not be required here
…r, removed CuratorFramework from config and other minor changes
HttpServiceRegistryUpdater<T> registryUpdater = new HttpServiceRegistryUpdater<T>(httpConfig, deserializer); | ||
return buildFinder(httpConfig, registryUpdater, deserializer, shardSelector, nodeSelector, healthcheckRefreshTimeMillis); | ||
} | ||
if (null != curatorConfig) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (curatorFramework !=null)
use the curatorFramework instead of building one
return buildFinder(curatorConfig, registryUpdater, deserializer, shardSelector, nodeSelector, healthcheckRefreshTimeMillis); | ||
} | ||
//TODO: what should be the default case? | ||
return buildFinder(null, null, deserializer, shardSelector, nodeSelector, healthcheckRefreshTimeMillis); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make the code look like before
if( null == curatorFramework) {
Preconditions.checkNotNull(connectionString);
curatorFramework = CuratorFrameworkFactory.builder()
.namespace(namespace)
.connectString(connectionString)
.retryPolicy(new ExponentialBackoffRetry(1000, 100)).build();
curatorFramework.start();
}
CuratorServiceRegistryUpdater<T> registryUpdater = new CuratorServiceRegistryUpdater<T>(curatorConfig, deserializer, curatorFramework);
return buildFinder(curatorConfig, registryUpdater, deserializer, shardSelector, nodeSelector, healthcheckRefreshTimeMillis);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a test case for HttpSourceConfig based serviceFinder. Use wiremock to mock the response of the url
httpclient = HttpClients.createDefault(); | ||
|
||
serviceRegistry.nodes(getHealthyServiceNodes()); | ||
logger.info("Started polling zookeeper for changes"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change log line
final String host = config.getHost(); | ||
final Integer port = config.getPort(); | ||
final String path = config.getPath(); | ||
final URI uri = new URIBuilder() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
URI could be created in the constructor once
} | ||
} | ||
|
||
//TODO: rename this method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove todo, add documentation to explain what the method is intended to do
.connectString(connectionString) | ||
.retryPolicy(new ExponentialBackoffRetry(1000, 100)).build(); | ||
curatorFramework.start(); | ||
} | ||
if( 0 == healthcheckRefreshTimeMillis) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preconditions.checkNotNull(serviceName);
required
@@ -1,12 +1,12 @@ | |||
/** | |||
* Copyright 2015 Flipkart Internet Pvt. Ltd. | |||
* | |||
* <p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
para not required
objectMapper.readValue(data, | ||
new TypeReference<List<ServiceNode<EnvNodeData>>>() { | ||
}); | ||
if (integer.incrementAndGet() > 2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment to signify what we are doing here
pom.xml
Outdated
@@ -114,8 +120,8 @@ | |||
<artifactId>maven-compiler-plugin</artifactId> | |||
<version>3.1</version> | |||
<configuration> | |||
<source>1.7</source> | |||
<target>1.7</target> | |||
<source>8</source> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1.8
|
||
try (CloseableHttpResponse response = httpclient.execute(httpget)) { | ||
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { | ||
logger.error("Error in Http get"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to catch the response and clearly print it out in logs if this happens including the status.
|
||
List<ServiceNode<T>> serviceNodes = config.getListDeserializer().deserialize(data); | ||
return serviceNodes.stream() | ||
.filter(node -> (node.getHealthcheckStatus() == HealthcheckStatus.healthy && node.getLastUpdatedTimeStamp() > healthcheckZombieCheckThresholdTime)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Break this line
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class HttpServiceRegistryUpdater<T> extends AbstractServiceRegistryUpdater<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so there are multiple assumption in this code:
- Rename the ListDeserializer interface to HttpResponseDecoder interface
- It assumes the return status code will be 200. Might not be.
- It assumes, the HTTP verb will be get. It can be post for whatever reason.
return null; | ||
} | ||
|
||
List<ServiceNode<T>> serviceNodes = config.getListDeserializer().deserialize(data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a transformer in the middle. Response might not be directly consumable.
public ServiceType getServiceType() { | ||
return serviceType; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add visitor interface here.
public class HttpServiceRegistryUpdater<T> extends AbstractServiceRegistryUpdater<T> { | ||
private static final Logger logger = LoggerFactory.getLogger(HttpServiceRegistryUpdater.class); | ||
|
||
private HttpSourceConfig config; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass in type param to HttpSourceConfig
public class CuratorSourceConfig<T> extends SourceConfig{ | ||
private String connectionString; | ||
private String namespace; | ||
private Deserializer<T> deserializer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is only for handling ZK Specific data, we should rename it ZookeeprNodeDataDecoder
|
||
import com.flipkart.ranger.model.Deserializer; | ||
|
||
public class CuratorSourceConfig<T> extends SourceConfig{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename this to ZookeeperSourceConfig
|
||
import java.util.List; | ||
|
||
public interface ListDeserializer<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HttpResponseDecoder
…nd https, renaming and other minor changes
Added Http Service.