Skip to content

Commit cabf8b8

Browse files
committedFeb 25, 2018
Use docker to build cassandra jar file
1 parent 2845293 commit cabf8b8

File tree

10 files changed

+325
-266
lines changed

10 files changed

+325
-266
lines changed
 

‎cassandra/image/Makefile renamed to ‎cassandra/Makefile

+12-7
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,29 @@
1313
# limitations under the License.
1414

1515
# build the cassandra image.
16-
VERSION=v13
16+
VERSION=v14
1717
PROJECT_ID?=google_samples
1818
PROJECT=gcr.io/${PROJECT_ID}
1919
CASSANDRA_VERSION=3.11.2
2020

2121
all: kubernetes-cassandra.jar build
2222

23-
kubernetes-cassandra.jar: ../java/* ../java/src/main/java/io/k8s/cassandra/*.java
24-
cd ../java && mvn clean && mvn package
25-
mv ../java/target/kubernetes-cassandra*.jar files/kubernetes-cassandra.jar
26-
cd ../java && mvn clean
23+
build-go:
24+
go build -a -installsuffix cgo \
25+
-ldflags "-s -w" \
26+
-o image/files/cassandra-seed.so -buildmode=c-shared go/main.go
27+
28+
kubernetes-cassandra.jar:
29+
@echo "Building kubernetes-cassandra.jar"
30+
docker run -v ${PWD}/java:/usr/src/app maven:3-jdk-8-onbuild-alpine mvn clean install
31+
cp java/target/kubernetes-cassandra*.jar image/files/kubernetes-cassandra.jar
2732

2833
container:
2934
@echo "Building ${PROJECT}/cassandra:${VERSION}"
30-
docker build --pull --build-arg "CASSANDRA_VERSION=${CASSANDRA_VERSION}" -t ${PROJECT}/cassandra:${VERSION} .
35+
docker build --pull --build-arg "CASSANDRA_VERSION=${CASSANDRA_VERSION}" -t ${PROJECT}/cassandra:${VERSION} image
3136

3237
container-dev:
33-
docker build --pull --build-arg "CASSANDRA_VERSION=${CASSANDRA_VERSION}" --build-arg "DEV_CONTAINER=true" -t ${PROJECT}/cassandra:${VERSION}-dev .
38+
docker build --pull --build-arg "CASSANDRA_VERSION=${CASSANDRA_VERSION}" --build-arg "DEV_CONTAINER=true" -t ${PROJECT}/cassandra:${VERSION}-dev image
3439

3540
build: container container-dev
3641

‎cassandra/cassandra-statefulset.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ spec:
1818
terminationGracePeriodSeconds: 1800
1919
containers:
2020
- name: cassandra
21-
image: gcr.io/google-samples/cassandra:v13
21+
image: gcr.io/google-samples/cassandra:v14
2222
imagePullPolicy: Always
2323
ports:
2424
- containerPort: 7000
@@ -60,6 +60,8 @@ spec:
6060
value: "DC1-K8Demo"
6161
- name: CASSANDRA_RACK
6262
value: "Rack1-K8Demo"
63+
- name: CASSANDRA_SEED_PROVIDER
64+
value: io.k8s.cassandra.KubernetesSeedProvider
6365
- name: POD_IP
6466
valueFrom:
6567
fieldRef:

‎cassandra/go/main.go

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package main
2+
3+
// #include <stdio.h>
4+
// #include <stdlib.h>
5+
import "C"
6+
7+
import (
8+
"context"
9+
"encoding/json"
10+
"log"
11+
"strings"
12+
"unicode"
13+
"unsafe"
14+
15+
"github.com/ericchiang/k8s"
16+
corev1 "github.com/ericchiang/k8s/apis/core/v1"
17+
)
18+
19+
type endpoints struct {
20+
IPs []string `json:"ips"`
21+
}
22+
23+
// GetEndpoints searches the endpoints of a service returning a list of IP addresses.
24+
//export GetEndpoints
25+
func GetEndpoints(namespace, service, defSeeds *C.char) *C.char {
26+
ns := C.GoString(namespace)
27+
svc := C.GoString(service)
28+
seeds := C.GoString(defSeeds)
29+
30+
s := strings.Map(func(r rune) rune {
31+
if unicode.IsSpace(r) {
32+
return -1
33+
}
34+
return r
35+
}, seeds)
36+
37+
nseeds := strings.Split(s, ",")
38+
client, err := k8s.NewInClusterClient()
39+
if err != nil {
40+
log.Printf("unexpected error opening a connection against API server: %v\n", err)
41+
log.Printf("returning default seeds: %v\n", nseeds)
42+
return buildEndpoints(nseeds)
43+
}
44+
45+
ips := make([]string, 0)
46+
47+
var endpoints corev1.Endpoints
48+
err = client.Get(context.Background(), ns, svc, &endpoints)
49+
if err != nil {
50+
log.Printf("unexpected error obtaining information about service endpoints: %v\n", err)
51+
log.Printf("returning default seeds: %v\n", nseeds)
52+
return buildEndpoints(nseeds)
53+
}
54+
55+
for _, endpoint := range endpoints.Subsets {
56+
for _, address := range endpoint.Addresses {
57+
ips = append(ips, *address.Ip)
58+
}
59+
}
60+
61+
if len(ips) == 0 {
62+
return buildEndpoints(nseeds)
63+
}
64+
65+
return buildEndpoints(ips)
66+
}
67+
68+
func buildEndpoints(ips []string) *C.char {
69+
b, err := json.Marshal(&endpoints{ips})
70+
if err != nil {
71+
log.Printf("unexpected error serializing JSON response: %v\n", err)
72+
rc := C.CString(`{"ips":[]}`)
73+
defer C.free(unsafe.Pointer(rc))
74+
return rc
75+
}
76+
77+
rc := C.CString(string(b))
78+
defer C.free(unsafe.Pointer(rc))
79+
return rc
80+
}
81+
82+
func main() {}

‎cassandra/image/files/build.sh

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ else
5555
rm -rf $CASSANDRA_HOME/pylib;
5656
fi
5757

58+
mv /kubernetes-cassandra.jar /usr/local/apache-cassandra-${CASSANDRA_VERSION}/lib
59+
mv /cassandra-seed.so /etc/cassandra/
60+
mv /cassandra-seed.h /usr/local/lib/include
61+
5862
apt-get -y purge localepurge
5963
apt-get -y autoremove
6064
apt-get clean
+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/* Created by "go tool cgo" - DO NOT EDIT. */
2+
3+
/* package command-line-arguments */
4+
5+
6+
#line 1 "cgo-builtin-prolog"
7+
8+
#include <stddef.h> /* for ptrdiff_t below */
9+
10+
#ifndef GO_CGO_EXPORT_PROLOGUE_H
11+
#define GO_CGO_EXPORT_PROLOGUE_H
12+
13+
typedef struct { const char *p; ptrdiff_t n; } _GoString_;
14+
15+
#endif
16+
17+
/* Start of preamble from import "C" comments. */
18+
19+
20+
#line 3 "/home/aledbf/go/src/k8s.io/examples/cassandra/go/main.go"
21+
#include <stdio.h>
22+
#include <stdlib.h>
23+
24+
#line 1 "cgo-generated-wrapper"
25+
26+
27+
/* End of preamble from import "C" comments. */
28+
29+
30+
/* Start of boilerplate cgo prologue. */
31+
#line 1 "cgo-gcc-export-header-prolog"
32+
33+
#ifndef GO_CGO_PROLOGUE_H
34+
#define GO_CGO_PROLOGUE_H
35+
36+
typedef signed char GoInt8;
37+
typedef unsigned char GoUint8;
38+
typedef short GoInt16;
39+
typedef unsigned short GoUint16;
40+
typedef int GoInt32;
41+
typedef unsigned int GoUint32;
42+
typedef long long GoInt64;
43+
typedef unsigned long long GoUint64;
44+
typedef GoInt64 GoInt;
45+
typedef GoUint64 GoUint;
46+
typedef __SIZE_TYPE__ GoUintptr;
47+
typedef float GoFloat32;
48+
typedef double GoFloat64;
49+
typedef float _Complex GoComplex64;
50+
typedef double _Complex GoComplex128;
51+
52+
/*
53+
static assertion to make sure the file is being used on architecture
54+
at least with matching size of GoInt.
55+
*/
56+
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
57+
58+
typedef _GoString_ GoString;
59+
typedef void *GoMap;
60+
typedef void *GoChan;
61+
typedef struct { void *t; void *v; } GoInterface;
62+
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
63+
64+
#endif
65+
66+
/* End of boilerplate cgo prologue. */
67+
68+
#ifdef __cplusplus
69+
extern "C" {
70+
#endif
71+
72+
73+
// GetEndpoints searches the endpoints of a service returning a list of IP addresses.
74+
75+
extern char* GetEndpoints(char* p0, char* p1, char* p2);
76+
77+
#ifdef __cplusplus
78+
}
79+
#endif
-1.91 KB
Binary file not shown.

‎cassandra/java/pom.xml

+5-7
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
<modelVersion>4.0.0</modelVersion>
1818
<groupId>io.k8s.cassandra</groupId>
1919
<artifactId>kubernetes-cassandra</artifactId>
20-
<version>1.0.2</version>
20+
<version>1.0.3</version>
2121
<build>
2222
<plugins>
2323
<plugin>
2424
<artifactId>maven-compiler-plugin</artifactId>
25-
<version>3.5.1</version>
25+
<version>3.5.1</version>
2626
<configuration>
2727
<source>1.8</source>
2828
<target>1.8</target>
@@ -33,7 +33,7 @@
3333

3434
<properties>
3535
<logback.version>1.1.3</logback.version>
36-
<cassandra.version>3.9</cassandra.version>
36+
<cassandra.version>3.11.2</cassandra.version>
3737
</properties>
3838

3939
<dependencies>
@@ -61,7 +61,6 @@
6161
<version>${logback.version}</version>
6262
<scope>provided</scope>
6363
</dependency>
64-
6564
<dependency>
6665
<groupId>ch.qos.logback</groupId>
6766
<artifactId>logback-core</artifactId>
@@ -72,14 +71,13 @@
7271
<dependency>
7372
<groupId>org.codehaus.jackson</groupId>
7473
<artifactId>jackson-core-asl</artifactId>
75-
<version>1.6.3</version>
74+
<version>1.9.13</version>
7675
<scope>provided</scope>
7776
</dependency>
78-
7977
<dependency>
8078
<groupId>org.codehaus.jackson</groupId>
8179
<artifactId>jackson-mapper-asl</artifactId>
82-
<version>1.6.3</version>
80+
<version>1.9.13</version>
8381
<scope>provided</scope>
8482
</dependency>
8583

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
/*
3+
* Copyright (C) 2018 Google Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
6+
* use this file except in compliance with the License. You may obtain a copy of
7+
* the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
* License for the specific language governing permissions and limitations under
15+
* the License.
16+
*/
17+
18+
package io.k8s.cassandra;
19+
20+
import java.util.Arrays;
21+
import java.util.List;
22+
23+
import com.sun.jna.Library;
24+
import com.sun.jna.Pointer;
25+
import com.sun.jna.Structure;
26+
27+
public interface GoInterface extends Library {
28+
public String GetEndpoints(String namespace, String service, String seeds);
29+
30+
public class GoSlice extends Structure {
31+
public static class ByValue extends GoSlice implements Structure.ByValue {
32+
}
33+
34+
public Pointer data;
35+
public long len;
36+
public long cap;
37+
38+
protected List<String> getFieldOrder() {
39+
return Arrays.asList(new String[] { "data", "len", "cap" });
40+
}
41+
}
42+
43+
public class GoString extends Structure {
44+
public static class ByValue extends GoString implements Structure.ByValue {
45+
}
46+
47+
public String p;
48+
public long n;
49+
50+
protected List<String> getFieldOrder() {
51+
return Arrays.asList(new String[] { "p", "n" });
52+
}
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
/*
23
* Copyright (C) 2015 Google Inc.
34
*
@@ -16,237 +17,87 @@
1617

1718
package io.k8s.cassandra;
1819

19-
import org.apache.cassandra.config.Config;
20-
import org.apache.cassandra.config.ConfigurationLoader;
21-
import org.apache.cassandra.config.YamlConfigurationLoader;
22-
import org.apache.cassandra.exceptions.ConfigurationException;
20+
import java.io.IOException;
21+
import java.net.InetAddress;
22+
import java.util.Collections;
23+
import java.util.List;
24+
import java.util.Map;
25+
2326
import org.apache.cassandra.locator.SeedProvider;
24-
import org.apache.cassandra.locator.SimpleSeedProvider;
25-
import org.apache.cassandra.utils.FBUtilities;
2627
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
2728
import org.codehaus.jackson.map.ObjectMapper;
2829
import org.slf4j.Logger;
2930
import org.slf4j.LoggerFactory;
3031

31-
import javax.net.ssl.*;
32-
import java.io.IOException;
33-
import java.net.InetAddress;
34-
import java.net.URL;
35-
import java.net.UnknownHostException;
36-
import java.nio.file.Files;
37-
import java.nio.file.Paths;
38-
import java.security.SecureRandom;
39-
import java.security.cert.X509Certificate;
40-
import java.util.ArrayList;
41-
import java.util.Collections;
42-
import java.util.List;
43-
import java.util.Map;
32+
import com.sun.jna.Native;
4433

4534
/**
4635
* Self discovery {@link SeedProvider} that creates a list of Cassandra Seeds by
4736
* communicating with the Kubernetes API.
48-
* <p>Various System Variable can be used to configure this provider:
37+
* <p>
38+
* Various System Variable can be used to configure this provider:
4939
* <ul>
50-
* <li>KUBERNETES_PORT_443_TCP_ADDR defaults to kubernetes.default.svc.cluster.local</li>
51-
* <li>KUBERNETES_PORT_443_TCP_PORT defaults to 443</li>
52-
* <li>CASSANDRA_SERVICE defaults to cassandra</li>
53-
* <li>POD_NAMESPACE defaults to 'default'</li>
54-
* <li>CASSANDRA_SERVICE_NUM_SEEDS defaults to 8 seeds</li>
55-
* <li>K8S_ACCOUNT_TOKEN defaults to the path for the default token</li>
40+
* <li>CASSANDRA_SERVICE defaults to cassandra</li>
41+
* <li>POD_NAMESPACE defaults to 'default'</li>
42+
* <li>CASSANDRA_SERVICE_NUM_SEEDS defaults to 8 seeds</li>
5643
* </ul>
5744
*/
5845
public class KubernetesSeedProvider implements SeedProvider {
5946

60-
private static final Logger logger = LoggerFactory.getLogger(KubernetesSeedProvider.class);
61-
62-
/**
63-
* default seeds to fall back on
64-
*/
65-
private List<InetAddress> defaultSeeds;
66-
67-
private TrustManager[] trustAll;
68-
69-
private HostnameVerifier trustAllHosts;
70-
71-
/**
72-
* Create new Seeds
73-
* @param params
74-
*/
75-
public KubernetesSeedProvider(Map<String, String> params) {
76-
77-
// Create default seeds
78-
defaultSeeds = createDefaultSeeds();
79-
80-
// TODO: Load the CA cert when it is available on all platforms.
81-
trustAll = new TrustManager[] {
82-
new X509TrustManager() {
83-
public void checkServerTrusted(X509Certificate[] certs, String authType) {}
84-
public void checkClientTrusted(X509Certificate[] certs, String authType) {}
85-
public X509Certificate[] getAcceptedIssuers() { return null; }
86-
}
87-
};
88-
89-
trustAllHosts = new HostnameVerifier() {
90-
public boolean verify(String hostname, SSLSession session) {
91-
return true;
92-
}
93-
};
94-
}
95-
96-
/**
97-
* Call kubernetes API to collect a list of seed providers
98-
* @return list of seed providers
99-
*/
100-
public List<InetAddress> getSeeds() {
101-
102-
String host = getEnvOrDefault("KUBERNETES_PORT_443_TCP_ADDR", "kubernetes.default.svc.cluster.local");
103-
String port = getEnvOrDefault("KUBERNETES_PORT_443_TCP_PORT", "443");
104-
String serviceName = getEnvOrDefault("CASSANDRA_SERVICE", "cassandra");
105-
String podNamespace = getEnvOrDefault("POD_NAMESPACE", "default");
106-
String path = String.format("/api/v1/namespaces/%s/endpoints/", podNamespace);
107-
String seedSizeVar = getEnvOrDefault("CASSANDRA_SERVICE_NUM_SEEDS", "8");
108-
Integer seedSize = Integer.valueOf(seedSizeVar);
109-
String accountToken = getEnvOrDefault("K8S_ACCOUNT_TOKEN", "/var/run/secrets/kubernetes.io/serviceaccount/token");
110-
111-
List<InetAddress> seeds = new ArrayList<InetAddress>();
112-
try {
113-
String token = getServiceAccountToken(accountToken);
114-
115-
SSLContext ctx = SSLContext.getInstance("SSL");
116-
ctx.init(null, trustAll, new SecureRandom());
117-
118-
String PROTO = "https://";
119-
URL url = new URL(PROTO + host + ":" + port + path + serviceName);
120-
logger.info("Getting endpoints from " + url);
121-
HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
122-
123-
// TODO: Remove this once the CA cert is propagated everywhere, and replace
124-
// with loading the CA cert.
125-
conn.setHostnameVerifier(trustAllHosts);
126-
127-
conn.setSSLSocketFactory(ctx.getSocketFactory());
128-
conn.addRequestProperty("Authorization", "Bearer " + token);
129-
ObjectMapper mapper = new ObjectMapper();
130-
Endpoints endpoints = mapper.readValue(conn.getInputStream(), Endpoints.class);
131-
132-
if (endpoints != null) {
133-
// Here is a problem point, endpoints.subsets can be null in first node cases.
134-
if (endpoints.subsets != null && !endpoints.subsets.isEmpty()){
135-
for (Subset subset : endpoints.subsets) {
136-
if (subset.addresses != null && !subset.addresses.isEmpty()) {
137-
for (Address address : subset.addresses) {
138-
seeds.add(InetAddress.getByName(address.ip));
139-
140-
if(seeds.size() >= seedSize) {
141-
logger.info("Available num endpoints: " + seeds.size());
142-
return Collections.unmodifiableList(seeds);
143-
}
144-
}
145-
}
146-
}
147-
}
148-
logger.info("Available num endpoints: " + seeds.size());
149-
} else {
150-
logger.warn("Endpoints are not available using default seeds in cassandra.yaml");
151-
return Collections.unmodifiableList(defaultSeeds);
152-
}
153-
} catch (Exception ex) {
154-
logger.warn("Request to kubernetes apiserver failed, using default seeds in cassandra.yaml", ex);
155-
return Collections.unmodifiableList(defaultSeeds);
156-
}
157-
158-
if (seeds.size() == 0) {
159-
// If we got nothing, we might be the first instance, in that case
160-
// fall back on the seeds that were passed in cassandra.yaml.
161-
logger.warn("Seeds are not available using default seeds in cassandra.yaml");
162-
return Collections.unmodifiableList(defaultSeeds);
163-
}
164-
165-
return Collections.unmodifiableList(seeds);
166-
}
167-
168-
/**
169-
* Code taken from {@link SimpleSeedProvider}. This is used as a fall back
170-
* incase we don't find seeds
171-
* @return
172-
*/
173-
protected List<InetAddress> createDefaultSeeds()
174-
{
175-
Config conf;
176-
try {
177-
conf = loadConfig();
178-
}
179-
catch (Exception e) {
180-
throw new AssertionError(e);
181-
}
182-
String[] hosts = conf.seed_provider.parameters.get("seeds").split(",", -1);
183-
List<InetAddress> seeds = new ArrayList<InetAddress>();
184-
for (String host : hosts) {
185-
try {
186-
seeds.add(InetAddress.getByName(host.trim()));
187-
}
188-
catch (UnknownHostException ex) {
189-
// not fatal... DD will bark if there end up being zero seeds.
190-
logger.warn("Seed provider couldn't lookup host {}", host);
191-
}
192-
}
193-
194-
if(seeds.size() == 0) {
195-
try {
196-
seeds.add(InetAddress.getLocalHost());
197-
} catch (UnknownHostException e) {
198-
logger.warn("Seed provider couldn't lookup localhost");
199-
}
200-
}
201-
return Collections.unmodifiableList(seeds);
202-
}
203-
204-
/**
205-
* Code taken from {@link SimpleSeedProvider}
206-
* @return
207-
*/
208-
protected static Config loadConfig() throws ConfigurationException
209-
{
210-
String loaderClass = System.getProperty("cassandra.config.loader");
211-
ConfigurationLoader loader = loaderClass == null
212-
? new YamlConfigurationLoader()
213-
: FBUtilities.<ConfigurationLoader>construct(loaderClass, "configuration loading");
214-
return loader.loadConfig();
215-
}
216-
217-
private static String getEnvOrDefault(String var, String def) {
218-
String val = System.getenv(var);
219-
if (val == null) {
220-
val = def;
221-
}
222-
return val;
223-
}
224-
225-
private static String getServiceAccountToken(String file) {
226-
try {
227-
return new String(Files.readAllBytes(Paths.get(file)));
228-
} catch (IOException e) {
229-
logger.warn("unable to load service account token" + file);
230-
throw new RuntimeException("Unable to load services account token " + file);
231-
}
232-
}
233-
234-
protected List<InetAddress> getDefaultSeeds() {
235-
return defaultSeeds;
236-
}
237-
238-
@JsonIgnoreProperties(ignoreUnknown = true)
239-
static class Address {
240-
public String ip;
241-
}
242-
243-
@JsonIgnoreProperties(ignoreUnknown = true)
244-
static class Subset {
245-
public List<Address> addresses;
246-
}
247-
248-
@JsonIgnoreProperties(ignoreUnknown = true)
249-
static class Endpoints {
250-
public List<Subset> subsets;
251-
}
47+
private static final Logger logger = LoggerFactory.getLogger(KubernetesSeedProvider.class);
48+
49+
50+
/**
51+
* Create new seed provider
52+
*
53+
* @param params
54+
*/
55+
public KubernetesSeedProvider(Map<String, String> params) {
56+
}
57+
58+
/**
59+
* Call Kubernetes API to collect a list of seed providers
60+
*
61+
* @return list of seed providers
62+
*/
63+
public List<InetAddress> getSeeds() {
64+
GoInterface go = (GoInterface) Native.loadLibrary("cassandra-seed.so", GoInterface.class);
65+
66+
String service = getEnvOrDefault("CASSANDRA_SERVICE", "cassandra");
67+
String namespace = getEnvOrDefault("POD_NAMESPACE", "default");
68+
69+
String initialSeeds = getEnvOrDefault("CASSANDRA_SEEDS", "");
70+
if (initialSeeds.equals("")) {
71+
initialSeeds = getEnvOrDefault("POD_IP", "");
72+
}
73+
74+
String seedSizeVar = getEnvOrDefault("CASSANDRA_SERVICE_NUM_SEEDS", "8");
75+
Integer seedSize = Integer.valueOf(seedSizeVar);
76+
77+
String data = go.GetEndpoints(namespace, service, initialSeeds);
78+
ObjectMapper mapper = new ObjectMapper();
79+
80+
try {
81+
Endpoints endpoints = mapper.readValue(data, Endpoints.class);
82+
logger.info("cassandra seeds: " + endpoints.ips.toString());
83+
return Collections.unmodifiableList(endpoints.ips);
84+
} catch (IOException e) {
85+
// This should not happen
86+
logger.error("unexpected error building cassandra seeds: " + e.getMessage());
87+
return Collections.emptyList();
88+
}
89+
}
90+
91+
private static String getEnvOrDefault(String var, String def) {
92+
String val = System.getenv(var);
93+
if (val == null) {
94+
val = def;
95+
}
96+
return val;
97+
}
98+
99+
@JsonIgnoreProperties(ignoreUnknown = true)
100+
static class Endpoints {
101+
public List<InetAddress> ips;
102+
}
252103
}

‎cassandra/java/src/test/java/io/k8s/cassandra/KubernetesSeedProviderTest.java

+17-33
Original file line numberDiff line numberDiff line change
@@ -16,48 +16,32 @@
1616

1717
package io.k8s.cassandra;
1818

19-
import org.apache.cassandra.locator.SeedProvider;
20-
import org.junit.Ignore;
21-
import org.junit.Test;
22-
import org.slf4j.Logger;
23-
import org.slf4j.LoggerFactory;
24-
25-
import static org.hamcrest.Matchers.*;
19+
import static org.hamcrest.Matchers.empty;
20+
import static org.hamcrest.Matchers.is;
21+
import static org.hamcrest.Matchers.not;
22+
import static org.junit.Assert.assertThat;
2623

2724
import java.net.InetAddress;
28-
import java.util.ArrayList;
2925
import java.util.HashMap;
3026
import java.util.List;
3127

32-
import static org.junit.Assert.*;
28+
import org.apache.cassandra.locator.SeedProvider;
29+
import org.junit.Ignore;
30+
import org.junit.Test;
31+
import org.slf4j.Logger;
32+
import org.slf4j.LoggerFactory;
3333

3434
public class KubernetesSeedProviderTest {
3535

36-
private static final Logger logger = LoggerFactory.getLogger(KubernetesSeedProviderTest.class);
37-
38-
@Test
39-
@Ignore("has to be run inside of a kube cluster")
40-
public void getSeeds() throws Exception {
41-
SeedProvider provider = new KubernetesSeedProvider(new HashMap<String, String>());
42-
List<InetAddress> seeds = provider.getSeeds();
43-
44-
assertThat(seeds, is(not(empty())));
45-
46-
}
47-
48-
@Test
49-
public void testDefaultSeeds() throws Exception {
50-
51-
KubernetesSeedProvider provider = new KubernetesSeedProvider(new HashMap<String,String>());
52-
List<InetAddress> seeds = provider.getDefaultSeeds();
53-
List<InetAddress> seedsTest = new ArrayList<>();
54-
seedsTest.add(InetAddress.getByName("8.4.4.4"));
55-
seedsTest.add(InetAddress.getByName("8.8.8.8"));
56-
assertThat(seeds, is(not(empty())));
57-
assertThat(seeds, is(seedsTest));
58-
logger.debug("seeds loaded {}", seeds);
36+
private static final Logger logger = LoggerFactory.getLogger(KubernetesSeedProviderTest.class);
5937

60-
}
38+
@Test
39+
@Ignore("has to be run inside of a kube cluster")
40+
public void getSeeds() throws Exception {
41+
SeedProvider provider = new KubernetesSeedProvider(new HashMap<String, String>());
42+
List<InetAddress> seeds = provider.getSeeds();
6143

44+
assertThat(seeds, is(not(empty())));
6245

46+
}
6347
}

0 commit comments

Comments
 (0)
Please sign in to comment.