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 Based finders #31

Open
wants to merge 86 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
41be82c
Abstracted out node data source
santanusinha Dec 16, 2019
aa9d5f3
ServiceProvider refactor
santanusinha Dec 17, 2019
49576c8
Removed useless interface
santanusinha Dec 17, 2019
22f04a3
Provider moved to signals as well
santanusinha Dec 25, 2019
e873526
Fixed some sonar comments
santanusinha Dec 25, 2019
66b51b9
Used lombok annotations
santanusinha Dec 25, 2019
68129b3
Added capability to add registry refresh signal generators in builder
santanusinha Dec 26, 2019
20db43a
Fully modularized
santanusinha Dec 30, 2019
18529b9
Added service finder hub
santanusinha Jan 2, 2020
3ed5df7
HTTP finder
santanusinha Feb 10, 2020
745846f
HTTP Service finder
santanusinha Feb 29, 2020
1c56a3d
Marked http connection as always active
santanusinha Feb 29, 2020
1830115
Code cleanup and removals of exists() check before node data read
santanusinha Feb 29, 2020
d0653de
Merge branch 'master' into http
santanusinha Mar 2, 2020
52c9f70
Handled interrupted exception properly
santanusinha Sep 21, 2021
459e774
minor fixes
santanusinha Sep 21, 2021
4fcfe36
0) Renamed UnshardedClusterInfo into UnshardedFinder and introduced a…
koushikr Oct 18, 2021
9bd12b9
a) Usage of val where it could be used. Retained type initialisation …
koushikr Oct 18, 2021
77981ea
1) Added error to httpResponses 2) Fixed formatting to align with sou…
koushikr Oct 18, 2021
7fdeb8f
1. Added a ranger-client module to contain the client creation abstra…
koushikr Oct 18, 2021
6a40297
a. Added a ranger-server module with zk as the backend. b. Optimized …
koushikr Oct 18, 2021
a449ee6
a. Added a local.yml for the server to test out the resources
koushikr Oct 18, 2021
a163766
Split the tests in the ranger-client into stubs so that the testjar c…
koushikr Oct 18, 2021
a95814c
a) Separated ranger-server from ranger-server-bundle and have written…
koushikr Oct 18, 2021
9b72546
a) Added test-jar to ranger-client. b) Changed the http node data sou…
koushikr Oct 21, 2021
c6351bc
Small refactoring in http sinks/source, sending out an empty list in …
koushikr Oct 21, 2021
d409853
a) Added an http-server as well, which can act as a discovery hub ato…
koushikr Oct 21, 2021
6a22930
Added a local.yml for ranger-http-server
koushikr Oct 21, 2021
4b48f73
Added tests for ranger-common where shardInfo is being maintained
koushikr Oct 21, 2021
4de42df
Removed services from the configuration of server, all services by de…
koushikr Oct 21, 2021
bb9852d
Added README.md to server bundle. Renamed ranger-server to ranger-zk-…
koushikr Oct 21, 2021
81fc343
a) Fixed the deserializer in the ranger app, using the hub
koushikr Oct 26, 2021
fed0be6
Optimized unnecessary imports
koushikr Oct 26, 2021
fb694f5
a. Added missing licenses
koushikr Nov 9, 2021
beedfdd
Minor formatting issues fixed
koushikr Nov 16, 2021
0847a28
Minor formatting issues fixed w.r.t dual licence on RotationStatusMon…
koushikr Nov 17, 2021
826c456
java doc for RangerBundleManager if there would be confusion for why …
koushikr Dec 9, 2021
32ea6d2
Typo in the javadoc fixed
koushikr Dec 9, 2021
62f306b
javadoc added for http App as well for the .run method on init
koushikr Dec 9, 2021
964932a
An incorrect exception from httpNodeDataSource was being thrown in ca…
koushikr Dec 13, 2021
b17b635
There was an unnecessary deserializer used in RangerServerBundle, rem…
koushikr Dec 13, 2021
7aaf5fe
a) Moved criteria to predicates b) Replaced lombak-able refrences wit…
koushikr Dec 17, 2021
5945a29
a) Uniform lombok usage across the codebase
koushikr Dec 20, 2021
f4d244c
a) Renamed getServices to getRegisteredServices() b) Lombok usage in …
koushikr Dec 20, 2021
0ceafce
Added a default value of emptySet to services in client inits
koushikr Dec 20, 2021
d3982f5
Added a null check to assertion in tests
koushikr Dec 20, 2021
987c9ef
Changed the optional usage to orElse(null) across all the tests
koushikr Dec 20, 2021
bcb4ac8
Fixed customShardSelectorTest
koushikr Dec 20, 2021
9cd3f6b
scope provided in bundle for dropwizard core
koushikr Dec 20, 2021
e4f4496
Small fix in the handling of InterruptedException
koushikr Dec 20, 2021
e9e14ae
Additional lombok cleanups
koushikr Dec 20, 2021
b348057
Moved to ?: in shardSelectors from the original guardRail if - to mai…
koushikr Dec 20, 2021
0562ef3
a) Lombok issues addressed across the codebase b) Formatting changes …
koushikr Dec 20, 2021
c018444
a) Few more lombok fixes
koushikr Dec 21, 2021
14f69f0
Optimized unnecessary imports
koushikr Dec 21, 2021
b009ee3
val fixes in FinderHub
koushikr Dec 21, 2021
a8a9c6b
The bug in PathBuilder is fixed. The servicePath and instancePath sho…
koushikr Dec 21, 2021
a9ca546
Pathbug in datsource is also fixed
koushikr Dec 21, 2021
7bb1103
Added a feature to merge the initial criteria if required with the ar…
koushikr Dec 23, 2021
8fcac41
Fixed a few more lombok usages, brought in var as a replacement for a…
koushikr Dec 26, 2021
234c388
Removed the explicit constructor in ServiceNode
koushikr Dec 27, 2021
ab0967e
Added a missing utility class annotation on ResourceHelper
koushikr Dec 27, 2021
a4b0ac3
Removed the unnecessary comment
koushikr Dec 27, 2021
e456799
Added the missing val in ServiceNoPoviderTest
koushikr Dec 27, 2021
c11da3a
Fixed await until usages, using an upper bound. Brought down the test…
koushikr Dec 31, 2021
8771dca
Simplified another awaitility usage
koushikr Dec 31, 2021
f9ab00f
Simplified exception handling in HttpNodeDataSink>
koushikr Dec 31, 2021
6e2027a
Trimmed down the success method in httpResponses
koushikr Dec 31, 2021
d9c87f7
Fixed serviceProvider tests
koushikr Dec 31, 2021
2a8f14f
Removed the RangerResponseCode. It is adding no real value and keepin…
koushikr Dec 31, 2021
6017744
Remvoed the bound condition in the hub, using the finder one all around
koushikr Dec 31, 2021
a15cbf8
Updated README
koushikr Dec 31, 2021
f6ad95f
Changed the utils to remove the useless started flag in finder
koushikr Dec 31, 2021
89022d2
Fixed the typo in serializer spelling
koushikr Jan 4, 2022
a1658e8
Removed the unnecessary imports
koushikr Jan 4, 2022
969db5e
Changed the order of hub assertions
koushikr Jan 4, 2022
18647f7
Added awaitility with seconds and bounds
koushikr Jan 4, 2022
5d9cfa9
Introduced an atMost to on await
koushikr Jan 4, 2022
4591194
Awaitility intervals coded for finder and hub starts
koushikr Jan 4, 2022
81bcfd7
Merged all testUtils into a single utils class
koushikr Jan 4, 2022
ce1e2c4
Refactored the rangerTestUtils to simplify awaitility usages
koushikr Jan 4, 2022
600e3d9
Removed the unnecessary imports
koushikr Jan 4, 2022
b325512
Removed an unnecessary assignment in RegistryTestUtils
koushikr Jan 4, 2022
88eb770
Simplified the awaitility bound condition further
koushikr Jan 4, 2022
4afb6ac
Using a consistent Duration.of everywhere
koushikr Jan 4, 2022
d6d7990
Merge pull request #44 from koushikr/server
santanusinha Jan 5, 2022
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
2 changes: 2 additions & 0 deletions lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lombok.addLombokGeneratedAnnotation = true
lombok.extern.findbugs.addSuppressFBWarnings = true
51 changes: 28 additions & 23 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@

<groupId>com.flipkart.ranger</groupId>
<artifactId>ranger</artifactId>
<packaging>jar</packaging>
<version>0.6.3</version>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>ranger-core</module>
<module>ranger-zookeeper</module>
<module>ranger-http</module>
<module>ranger-server</module>
</modules>

<distributionManagement>
<repository>
Expand Down Expand Up @@ -50,38 +56,36 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<guava.version>26.0-jre</guava.version>
<curator.version>4.0.1</curator.version>
<jackson.version>2.9.5</jackson.version>
<jackson.version>2.10.1</jackson.version>
<slf4j.version>1.7.25</slf4j.version>
<apache.httpclient.version>4.5.6</apache.httpclient.version>

<maven.compiler.version>3.8.0</maven.compiler.version>
<java.version>1.8</java.version>
<lombok.version>1.18.4</lombok.version>

</properties>

<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>

<!--Curator-->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>${curator.version}</version>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
<version>3.0.1</version>
</dependency>

<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>${curator.version}</version>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
<version>${curator.version}</version>
<scope>test</scope>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.26</version>
</dependency>

<dependency>
Expand All @@ -108,9 +112,10 @@
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${apache.httpclient.version}</version>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>4.0.2</version>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down
45 changes: 45 additions & 0 deletions ranger-core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ranger</artifactId>
<groupId>com.flipkart.ranger</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>ranger-core</artifactId>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.11</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
/**
* Copyright 2015 Flipkart Internet Pvt. Ltd.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.flipkart.ranger.core.finder;

import com.flipkart.ranger.core.finder.signals.ScheduledRegistryUpdateSignal;
import com.flipkart.ranger.core.model.*;
import com.flipkart.ranger.core.signals.Signal;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import lombok.val;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;

@Slf4j
public abstract class BaseServiceFinderBuilder
<
T,
R extends ServiceRegistry<T>,
F extends ServiceFinder<T, R>,
B extends BaseServiceFinderBuilder<T, R, F, B, D>,
D extends Deserializer<T>> {

protected String namespace;
protected String serviceName;
protected int nodeRefreshIntervalMs;
protected boolean disablePushUpdaters;
protected D deserializer;
protected ShardSelector<T, R> shardSelector;
protected ServiceNodeSelector<T> nodeSelector = new RandomServiceNodeSelector<>();
protected final List<Signal<T>> additionalRefreshSignals = new ArrayList<>();
protected final List<Consumer<Void>> startSignalHandlers = Lists.newArrayList();
protected final List<Consumer<Void>> stopSignalHandlers = Lists.newArrayList();

public B withNamespace(final String namespace) {
this.namespace = namespace;
return (B)this;
}

public B withServiceName(final String serviceName) {
this.serviceName = serviceName;
return (B)this;
}

public B withDeserializer(D deserializer) {
this.deserializer = deserializer;
return (B)this;
}

public B withShardSelector(ShardSelector<T, R> shardSelector) {
this.shardSelector = shardSelector;
return (B)this;
}

public B withNodeSelector(ServiceNodeSelector<T> nodeSelector) {
this.nodeSelector = null != nodeSelector ? nodeSelector : this.nodeSelector;
return (B)this;
}

public B withNodeRefreshIntervalMs(int nodeRefreshIntervalMs) {
this.nodeRefreshIntervalMs = nodeRefreshIntervalMs;
return (B)this;
}

public B withDisableWatchers() {
this.disablePushUpdaters = true;
return (B)this;
}

public B withDisableWatchers(boolean disablePushUpdaters) {
this.disablePushUpdaters = disablePushUpdaters;
return (B)this;
}

public B withAdditionalSignalGenerator(Signal<T> signalGenerator) {
this.additionalRefreshSignals.add(signalGenerator);
return (B)this;
}

public B withAdditionalSignalGenerators(Signal<T>... signalGenerators) {
this.additionalRefreshSignals.addAll(Arrays.asList(signalGenerators));
return (B)this;
}

public B withAdditionalSignalGenerators(List<Signal<T>> signalGenerators) {
this.additionalRefreshSignals.addAll(signalGenerators);
return (B)this;
}

public B withStartSignalHandler(Consumer<Void> startSignalHandler) {
this.startSignalHandlers.add(startSignalHandler);
return (B)this;
}

public B withStartSignalHandlers(List<Consumer<Void>> startSignalHandlers) {
this.startSignalHandlers.addAll(startSignalHandlers);
return (B)this;
}

public B withStopSignalHandler(Consumer<Void> stopSignalHandler) {
this.stopSignalHandlers.add(stopSignalHandler);
return (B)this;
}

public B withStopSignalHandlers(List<Consumer<Void>> stopSignalHandlers) {
this.stopSignalHandlers.addAll(stopSignalHandlers);
return (B)this;
}

public abstract F build();

protected F buildFinder() {
Preconditions.checkNotNull(namespace);
Preconditions.checkNotNull(serviceName);
Preconditions.checkNotNull(deserializer);

if (nodeRefreshIntervalMs < 1000) {
log.warn("Node refresh interval for {} is too low: {} ms. Has been upgraded to 1000ms ",
serviceName, nodeRefreshIntervalMs);
nodeRefreshIntervalMs = 1000;
}
Service service = new Service(namespace, serviceName);
val finder = buildFinder(service, shardSelector, nodeSelector);
val registry = finder.getServiceRegistry();
List<Signal<T>> signalGenerators = new ArrayList<>();
final NodeDataSource<T, D> nodeDataSource = dataSource(service);

signalGenerators.add(new ScheduledRegistryUpdateSignal<>(service, nodeRefreshIntervalMs));
additionalRefreshSignals.addAll(implementationSpecificRefreshSignals(service, nodeDataSource));
if (!additionalRefreshSignals.isEmpty()) {
signalGenerators.addAll(additionalRefreshSignals);
log.debug("Added additional signal handlers");
}

val updater = new ServiceRegistryUpdater<T, D>(registry, nodeDataSource, signalGenerators, deserializer);
finder.getStartSignal()
.registerConsumers(startSignalHandlers)
.registerConsumer(x -> nodeDataSource.start())
.registerConsumer(x -> updater.start())
.registerConsumer(x -> signalGenerators.forEach(Signal::start));

finder.getStopSignal()
.registerConsumer(x -> signalGenerators.forEach(Signal::stop))
.registerConsumer(x -> updater.stop())
.registerConsumer(x -> nodeDataSource.stop())
.registerConsumers(stopSignalHandlers);
return finder;
}

protected List<Signal<T>> implementationSpecificRefreshSignals(Service service, NodeDataSource<T, D> nodeDataSource) {
return Collections.emptyList();
}

protected abstract NodeDataSource<T, D> dataSource(Service service);

protected abstract F buildFinder(
Service service,
ShardSelector<T, R> shardSelector,
ServiceNodeSelector<T> nodeSelector);

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

package com.flipkart.ranger.finder;
package com.flipkart.ranger.core.finder;

import com.flipkart.ranger.model.ServiceNode;
import com.flipkart.ranger.model.ServiceNodeSelector;
import com.flipkart.ranger.core.model.ServiceNode;
import com.flipkart.ranger.core.model.ServiceNodeSelector;

import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

package com.flipkart.ranger.finder;
package com.flipkart.ranger.core.finder;

import com.flipkart.ranger.model.ServiceNode;
import com.flipkart.ranger.model.ServiceNodeSelector;
import com.flipkart.ranger.core.model.ServiceNode;
import com.flipkart.ranger.core.model.ServiceNodeSelector;

import java.util.List;

Expand Down
Loading