-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Added a ranger-client module to contain the client creation abstra…
…ctions and added http and zk clients respectively with required test cases. This will help end-clients not replicate the same boiler plate code again and again
- Loading branch information
Showing
25 changed files
with
1,641 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
ranger-client/src/main/java/com/flipkart/ranger/client/AbstractRangerHubClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Copyright 2015 Flipkart Internet Pvt. Ltd. | ||
* | ||
* 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 | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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.client; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.flipkart.ranger.core.finderhub.ServiceDataSource; | ||
import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; | ||
import com.flipkart.ranger.core.finderhub.ServiceFinderHub; | ||
import com.flipkart.ranger.core.model.*; | ||
import com.google.common.base.Preconditions; | ||
import lombok.Getter; | ||
import lombok.extern.slf4j.Slf4j; | ||
import lombok.val; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Slf4j | ||
@Getter | ||
public abstract class AbstractRangerHubClient<T, C extends Criteria<T>, R extends ServiceRegistry<T>, D extends Deserializer<T>> implements RangerHubClient<T, C> { | ||
|
||
private final String namespace; | ||
private final ObjectMapper mapper; | ||
private final C criteria; | ||
private final D deserializer; | ||
|
||
private int nodeRefreshTimeMs; | ||
private ServiceFinderHub<T, C, R> hub; | ||
|
||
public AbstractRangerHubClient( | ||
String namespace, | ||
ObjectMapper mapper, | ||
int nodeRefreshTimeMs, | ||
C criteria, | ||
D deserializer | ||
){ | ||
this.namespace = namespace; | ||
this.mapper = mapper; | ||
this.nodeRefreshTimeMs = nodeRefreshTimeMs; | ||
this.criteria = criteria; | ||
this.deserializer = deserializer; | ||
} | ||
|
||
public void start(){ | ||
Preconditions.checkNotNull(mapper, "Mapper can't be null"); | ||
Preconditions.checkNotNull(namespace, "namespace can't be null"); | ||
Preconditions.checkNotNull(deserializer, "deserializer can't be null"); | ||
|
||
if (this.nodeRefreshTimeMs < RangerClientConstants.MINIMUM_REFRESH_TIME) { | ||
log.warn("Node info update interval too low: {} ms. Has been upgraded to {} ms ", | ||
this.nodeRefreshTimeMs, | ||
RangerClientConstants.MINIMUM_REFRESH_TIME); | ||
} | ||
this.nodeRefreshTimeMs = Math.max(RangerClientConstants.MINIMUM_REFRESH_TIME, this.nodeRefreshTimeMs); | ||
this.hub = buildHub(); | ||
this.hub.start(); | ||
} | ||
|
||
public void stop(){ | ||
hub.stop(); | ||
} | ||
|
||
public Optional<ServiceNode<T>> getNode( | ||
final Service service | ||
){ | ||
return getNode(service, criteria); | ||
} | ||
|
||
public Optional<List<ServiceNode<T>>> getAllNodes( | ||
final Service service | ||
){ | ||
return getAllNodes(service, criteria); | ||
} | ||
|
||
public Optional<ServiceNode<T>> getNode( | ||
final Service service, | ||
final C criteria | ||
){ | ||
val optionalFinder = this.getHub().finder(service); | ||
return optionalFinder.map(trcServiceFinder -> trcServiceFinder.get(criteria)); | ||
} | ||
|
||
public Optional<List<ServiceNode<T>>> getAllNodes( | ||
final Service service, | ||
final C criteria | ||
){ | ||
val optionalFinder = this.getHub().finder(service); | ||
return optionalFinder.map(trcServiceFinder -> trcServiceFinder.getAll(criteria)); | ||
} | ||
|
||
protected abstract ServiceFinderHub<T, C, R> buildHub(); | ||
|
||
protected abstract ServiceDataSource buildServiceDataSource(); | ||
|
||
protected abstract ServiceFinderFactory<T,C, R> buildFinderFactory(); | ||
|
||
} | ||
|
39 changes: 39 additions & 0 deletions
39
ranger-client/src/main/java/com/flipkart/ranger/client/RangerClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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.client; | ||
|
||
import com.flipkart.ranger.core.model.Criteria; | ||
import com.flipkart.ranger.core.model.Deserializer; | ||
import com.flipkart.ranger.core.model.ServiceNode; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface RangerClient<T, C extends Criteria<T>> { | ||
|
||
void start(); | ||
|
||
void stop(); | ||
|
||
Optional<ServiceNode<T>> getNode(); | ||
|
||
Optional<ServiceNode<T>> getNode(final C criteria); | ||
|
||
Optional<List<ServiceNode<T>>> getAllNodes(); | ||
|
||
Optional<List<ServiceNode<T>>> getAllNodes(final C criteria); | ||
} |
24 changes: 24 additions & 0 deletions
24
ranger-client/src/main/java/com/flipkart/ranger/client/RangerClientConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2015 Flipkart Internet Pvt. Ltd. | ||
* | ||
* 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 | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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.client; | ||
|
||
public class RangerClientConstants { | ||
|
||
private RangerClientConstants(){} | ||
|
||
public static final int CONNECTION_RETRY_TIME = 5000; | ||
public static final int MINIMUM_REFRESH_TIME = 5000; | ||
} |
39 changes: 39 additions & 0 deletions
39
ranger-client/src/main/java/com/flipkart/ranger/client/RangerHubClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2015 Flipkart Internet Pvt. Ltd. | ||
* | ||
* 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 | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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.client; | ||
|
||
import com.flipkart.ranger.core.model.Criteria; | ||
import com.flipkart.ranger.core.model.Service; | ||
import com.flipkart.ranger.core.model.ServiceNode; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface RangerHubClient<T, C extends Criteria<T>> { | ||
|
||
void start(); | ||
|
||
void stop(); | ||
|
||
Optional<ServiceNode<T>> getNode(final Service service); | ||
|
||
Optional<ServiceNode<T>> getNode(final Service service, final C criteria); | ||
|
||
Optional<List<ServiceNode<T>>> getAllNodes(final Service service); | ||
|
||
Optional<List<ServiceNode<T>>> getAllNodes(final Service service, final C criteria); | ||
|
||
} |
Oops, something went wrong.