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

[DO NOT MERGE] skeleton myst shard discovery #24

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
}
}
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);
}
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;
Copy link
Contributor

Choose a reason for hiding this comment

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

Not used.

}

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

Choose a reason for hiding this comment

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

By convention the newBuilder() should be main class which is MystEndpoint.

MystEndpoint.newBuilder() reads better than MystEndpoint.Builder.newBuilder().

return new Builder();
}

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