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

To Get List Of EndPoints #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions meta-grpc-client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def grpcVersion = '1.40.0'
def protobufVersion = '3.15.6'
def protocVersion = protobufVersion




dependencies {

api project(':core')
Expand All @@ -60,6 +63,7 @@ dependencies {
implementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.14.1'
implementation group: 'org.apache.logging.log4j', name: 'log4j-1.2-api', version: '2.14.1'
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.14.1'
implementation 'org.projectlombok:lombok:1.18.16'

testImplementation "io.grpc:grpc-testing:${grpcVersion}"
testImplementation "io.grpc:grpc-testing:${grpcVersion}"
Expand All @@ -76,6 +80,9 @@ dependencies {
testCommonImplementation group: 'org.roaringbitmap', name: 'RoaringBitmap', version: '0.9.3'
testCommonImplementation "io.grpc:grpc-stub:${grpcVersion}"

compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.13.0-rc2'
compile 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.0-rc2'

}

protobuf {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* This file is part of OpenTSDB.
* Copyright (C) 2021 Yahoo.
*
* 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 net.opentsdb.aura.metrics.meta.endpoints;

public interface ShardEndPoint {

String getHost();

boolean equals(Object that);

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,27 @@
/*
* This file is part of OpenTSDB.
* Copyright (C) 2021 Yahoo.
*
* 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 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,107 @@
/*
* This file is part of OpenTSDB.
* Copyright (C) 2021 Yahoo.
*
* 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 net.opentsdb.aura.metrics.meta.endpoints.impl;

import com.fasterxml.jackson.annotation.JsonProperty;

public class Component {

@JsonProperty("component")
private String name;

@JsonProperty("num-shards")
private int numShards;

@JsonProperty("replicas")
private int numReplicas;

private static final String[] replicas = {"a", "b", "c", "d", "e"};
private int port;


public Component() {

}

public String getName() {

return name;
}

public int getNumShards() {

return numShards;
}

public int getNumReplicas() {
if(numReplicas < replicas.length) {
return numReplicas;
}else{
return 1;
}
}

public void setNumReplicas(int numReplicas) {
if(numReplicas < replicas.length) {
this.numReplicas = numReplicas;
}else{
this.numReplicas = 1;
}
}

public String getReplica(int replicaId){
return replicas[replicaId];
}

public int getPort() {

return port;
}

public void setPort(int port) {

this.port = port;
}


public void setNumShards(int numShards) {

this.numShards = numShards;
}

public void setName(String name) {

this.name = name;
}

public void setDefaultComponent(Component defaultComponent) {
if (this.numShards == 0){
this.numShards = defaultComponent.getNumShards();
}
if (this.numReplicas == 0){
this.numReplicas = defaultComponent.getNumReplicas();
}
if (this.port == 0){
this.port = defaultComponent.getPort();
}
}

@Override
public String toString() {
return "Components {name=" + name + ", num-shards=" + numShards + ", replicas=" + numReplicas + ", port=" + port + "}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* This file is part of OpenTSDB.
* Copyright (C) 2021 Yahoo.
*
* 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 net.opentsdb.aura.metrics.meta.endpoints.impl;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DeploymentConfig {

@JsonProperty("kubernetes.statefulset.registry.cluster")
private String clusterName;

public String getClusterName() {
return clusterName;
}

@JsonProperty("kubernetes.statefulset.registry.cluster.domain")
private String clusterDomain;

@JsonProperty("kubernetes.statefulset.registry.namespaces")
private List<Namespace> namespaces;

private final Map<String,Namespace> namespaceMap = new HashMap<>();

public DeploymentConfig(){

}

public String getClusterDomain() {
return clusterDomain;
}

public void setClusterDomain(String clusterDomain) {
this.clusterDomain=clusterDomain;
}

public void setClusterName(String clusterName) {
this.clusterName = clusterName;
}

public List<Namespace> getListOfNamespaces() {
return namespaces;
}

public void setListOfNamespaces(List<Namespace> namespaces) {
this.namespaces = namespaces;
}

public Map<String,Namespace> toMap() {
Namespace defaultNamespace = null;
try {
for (Namespace namespace : namespaces) {
namespace.toMap();
if (namespace.getName().equals("default")) {
defaultNamespace = namespace;
} else {
namespaceMap.put(namespace.getName(), namespace);
}
}
for (String key : namespaceMap.keySet()) {
namespaceMap.get(key).setDefaultNamespace(defaultNamespace);
}
} catch (Exception e){
System.out.println(e);
}

return namespaceMap;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* This file is part of OpenTSDB.
* Copyright (C) 2021 Yahoo.
*
* 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 net.opentsdb.aura.metrics.meta.endpoints.impl;

import net.opentsdb.aura.metrics.meta.endpoints.ShardEndPoint;

import java.util.Objects;


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 equals(Object that){
if (Objects.isNull(that)){
return false;
}
if (this == that){
return true;
}else if (!(that instanceof ShardEndPoint)) {
return false;

}else{
if (Objects.equals(this.getHost(), ((ShardEndPoint) that).getHost()) &&
Objects.equals(this.getPort(), ((ShardEndPoint) that).getPort())
&& Objects.equals(this.getProtocol(), ((ShardEndPoint) that).getProtocol()) &&
((ShardEndPoint) that).mtls() == false && this.mtls() == false ){

return true;
}else{
return false;
}
}
}


@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() {
return new Builder();
}

}
@Override
public String toString() {
return "Endpoints {host=" + host + ", port=" + port +"}";
}
}
Loading