-
Notifications
You must be signed in to change notification settings - Fork 13
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
[DO NOT MERGE] skeleton myst shard discovery #24
Draft
mailravi3390
wants to merge
1
commit into
OpenTSDB:master
Choose a base branch
from
mailravi3390:sharded-myst
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
meta-grpc-client/src/main/java/net/opentsdb/aura/metrics/meta/endpoints/ShardEndPoint.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,16 @@ | ||
package net.opentsdb.aura.metrics.meta.endpoints; | ||
|
||
public interface ShardEndPoint { | ||
|
||
String getHost(); | ||
|
||
int getPort(); | ||
|
||
Protocol getProtocol(); | ||
|
||
boolean mtls(); | ||
|
||
enum Protocol { | ||
http1_1, http2_0, https1_1, https_2_0 | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...client/src/main/java/net/opentsdb/aura/metrics/meta/endpoints/ShardedServiceRegistry.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,11 @@ | ||
package net.opentsdb.aura.metrics.meta.endpoints; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public interface ShardedServiceRegistry { | ||
|
||
Map<String, List<ShardEndPoint>> getEndpoints(String namespace); | ||
|
||
Map<String, List<ShardEndPoint>> getEndpoints(String namespace, long epoch); | ||
} |
41 changes: 41 additions & 0 deletions
41
...c/main/java/net/opentsdb/aura/metrics/meta/endpoints/impl/KubernetesStatefulRegistry.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,41 @@ | ||
package net.opentsdb.aura.metrics.meta.endpoints.impl; | ||
|
||
import net.opentsdb.aura.metrics.meta.endpoints.ShardedServiceRegistry; | ||
|
||
//TODO: | ||
// Parse the yaml file. | ||
// Look at Plugin implementation. | ||
// if it is too complicated, then parse the file yourself. | ||
// Parsing the file should use ObjectMapper. | ||
public abstract class KubernetesStatefulRegistry implements ShardedServiceRegistry { | ||
|
||
private String type; | ||
private final String[] replicas = {"a", "b", "c", "d", "e"}; | ||
protected static final String NUM_SHARDS = "num-shards"; | ||
protected static final String REPLICAS = "replicas"; | ||
protected static final String K8S_NAMESPACE = "k8s_namespace"; | ||
|
||
public KubernetesStatefulRegistry(final String type) { | ||
this.type = type; | ||
} | ||
|
||
protected int getNumShards(String namespace) { | ||
return 0; | ||
} | ||
|
||
protected int getNumReplicas(String namespace) { | ||
return 0; | ||
} | ||
|
||
protected String getReplica(int replicaId) { | ||
return replicas[replicaId]; | ||
} | ||
|
||
protected int getPort(String namespace) { | ||
return 0; | ||
} | ||
|
||
protected String getDomain(String namespace) { | ||
return null; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...grpc-client/src/main/java/net/opentsdb/aura/metrics/meta/endpoints/impl/MystEndpoint.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,59 @@ | ||
package net.opentsdb.aura.metrics.meta.endpoints.impl; | ||
|
||
import net.opentsdb.aura.metrics.meta.endpoints.ShardEndPoint; | ||
//TODO: Make a builder | ||
public class MystEndpoint implements ShardEndPoint { | ||
|
||
private final String host; | ||
private final int port; | ||
|
||
public MystEndpoint(String host, int port) { | ||
this.host = host; | ||
this.port = port; | ||
} | ||
|
||
|
||
@Override | ||
public String getHost() { | ||
return this.host; | ||
} | ||
|
||
@Override | ||
public int getPort() { | ||
return this.port; | ||
} | ||
|
||
@Override | ||
public Protocol getProtocol() { | ||
return Protocol.http2_0; | ||
} | ||
|
||
@Override | ||
public boolean mtls() { | ||
return false; | ||
} | ||
|
||
public static class Builder { | ||
private String l_host; | ||
private int l_port; | ||
|
||
public Builder withHost(String host) { | ||
this.l_host = host; | ||
return this; | ||
} | ||
|
||
public Builder withPort(int port) { | ||
this.l_port = port; | ||
return this; | ||
} | ||
|
||
public MystEndpoint build() { | ||
return new MystEndpoint(l_host, l_port); | ||
} | ||
|
||
public static Builder newBuilder() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By convention the
|
||
return new Builder(); | ||
} | ||
|
||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
.../src/main/java/net/opentsdb/aura/metrics/meta/endpoints/impl/MystStatefulSetRegistry.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,52 @@ | ||
package net.opentsdb.aura.metrics.meta.endpoints.impl; | ||
|
||
import net.opentsdb.aura.metrics.meta.endpoints.ShardEndPoint; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
//TODO: | ||
// make a cache | ||
// Refetch for a namespace only if things have changed | ||
// Write testcases using Mocks (jmockit or mockito) | ||
public class MystStatefulSetRegistry extends KubernetesStatefulRegistry { | ||
|
||
private static final String pod_name_pattern = "%s-myst-%s-%s.svc.%s"; | ||
|
||
public MystStatefulSetRegistry() { | ||
super("myst"); | ||
} | ||
|
||
@Override | ||
public Map<String, List<ShardEndPoint>> getEndpoints(String namespace) { | ||
Map<String, List<ShardEndPoint>> endpointsMap = new HashMap<>(); | ||
|
||
final int numShards = getNumShards(namespace); | ||
final int numReplicas = getNumReplicas(namespace); | ||
for(int i = 0; i < numReplicas; i++) { | ||
String replica = getReplica(i); | ||
List<ShardEndPoint> shardEndPoints = new ArrayList<>(); | ||
endpointsMap.put(replica, shardEndPoints); | ||
for (int j = 0; j < numShards; i++) { | ||
final MystEndpoint endpoint = MystEndpoint.Builder.newBuilder() | ||
.withHost( | ||
String.format( | ||
pod_name_pattern, | ||
namespace, | ||
replica, | ||
j, | ||
getDomain(namespace))) | ||
.withPort(getPort(namespace)) | ||
.build(); | ||
shardEndPoints.add(endpoint); | ||
} | ||
} | ||
return endpointsMap; | ||
} | ||
|
||
@Override | ||
public Map<String, List<ShardEndPoint>> getEndpoints(String namespace, long epoch) { | ||
return getEndpoints(namespace); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not used.