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

Http service #22

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open

Conversation

mudit1403
Copy link

Added Http Service.

import java.util.List;
import java.util.concurrent.*;

public abstract class AbstractServiceRegistry<T> implements ServiceRegistry<T> {
Copy link
Contributor

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();
Copy link
Contributor

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);
Copy link
Contributor

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;
Copy link
Contributor

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> {
Copy link
Contributor

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> {
Copy link
Contributor

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;
Copy link
Contributor

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();
Copy link
Contributor

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();
Copy link
Contributor

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) {
Copy link
Contributor

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);
Copy link
Contributor

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);

Copy link
Contributor

@Tushar-Naik Tushar-Naik left a 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");
Copy link
Contributor

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()
Copy link
Contributor

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
Copy link
Contributor

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) {
Copy link
Contributor

@Tushar-Naik Tushar-Naik Jul 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preconditions.checkNotNull(serviceName); required

pom.xml Show resolved Hide resolved
@@ -1,12 +1,12 @@
/**
* Copyright 2015 Flipkart Internet Pvt. Ltd.
*
* <p>
Copy link
Contributor

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) {
Copy link
Contributor

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>
Copy link
Collaborator

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");
Copy link
Collaborator

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))
Copy link
Collaborator

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> {
Copy link
Collaborator

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);
Copy link
Collaborator

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;
}
}
Copy link
Collaborator

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;
Copy link
Collaborator

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;
Copy link
Collaborator

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{
Copy link
Collaborator

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> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HttpResponseDecoder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants