-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use docker to build cassandra jar file
- Loading branch information
Showing
10 changed files
with
325 additions
and
266 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
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,82 @@ | ||
package main | ||
|
||
// #include <stdio.h> | ||
// #include <stdlib.h> | ||
import "C" | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"log" | ||
"strings" | ||
"unicode" | ||
"unsafe" | ||
|
||
"github.com/ericchiang/k8s" | ||
corev1 "github.com/ericchiang/k8s/apis/core/v1" | ||
) | ||
|
||
type endpoints struct { | ||
IPs []string `json:"ips"` | ||
} | ||
|
||
// GetEndpoints searches the endpoints of a service returning a list of IP addresses. | ||
//export GetEndpoints | ||
func GetEndpoints(namespace, service, defSeeds *C.char) *C.char { | ||
ns := C.GoString(namespace) | ||
svc := C.GoString(service) | ||
seeds := C.GoString(defSeeds) | ||
|
||
s := strings.Map(func(r rune) rune { | ||
if unicode.IsSpace(r) { | ||
return -1 | ||
} | ||
return r | ||
}, seeds) | ||
|
||
nseeds := strings.Split(s, ",") | ||
client, err := k8s.NewInClusterClient() | ||
if err != nil { | ||
log.Printf("unexpected error opening a connection against API server: %v\n", err) | ||
log.Printf("returning default seeds: %v\n", nseeds) | ||
return buildEndpoints(nseeds) | ||
} | ||
|
||
ips := make([]string, 0) | ||
|
||
var endpoints corev1.Endpoints | ||
err = client.Get(context.Background(), ns, svc, &endpoints) | ||
if err != nil { | ||
log.Printf("unexpected error obtaining information about service endpoints: %v\n", err) | ||
log.Printf("returning default seeds: %v\n", nseeds) | ||
return buildEndpoints(nseeds) | ||
} | ||
|
||
for _, endpoint := range endpoints.Subsets { | ||
for _, address := range endpoint.Addresses { | ||
ips = append(ips, *address.Ip) | ||
} | ||
} | ||
|
||
if len(ips) == 0 { | ||
return buildEndpoints(nseeds) | ||
} | ||
|
||
return buildEndpoints(ips) | ||
} | ||
|
||
func buildEndpoints(ips []string) *C.char { | ||
b, err := json.Marshal(&endpoints{ips}) | ||
if err != nil { | ||
log.Printf("unexpected error serializing JSON response: %v\n", err) | ||
rc := C.CString(`{"ips":[]}`) | ||
defer C.free(unsafe.Pointer(rc)) | ||
return rc | ||
} | ||
|
||
rc := C.CString(string(b)) | ||
defer C.free(unsafe.Pointer(rc)) | ||
return rc | ||
} | ||
|
||
func main() {} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* Created by "go tool cgo" - DO NOT EDIT. */ | ||
|
||
/* package command-line-arguments */ | ||
|
||
|
||
#line 1 "cgo-builtin-prolog" | ||
|
||
#include <stddef.h> /* for ptrdiff_t below */ | ||
|
||
#ifndef GO_CGO_EXPORT_PROLOGUE_H | ||
#define GO_CGO_EXPORT_PROLOGUE_H | ||
|
||
typedef struct { const char *p; ptrdiff_t n; } _GoString_; | ||
|
||
#endif | ||
|
||
/* Start of preamble from import "C" comments. */ | ||
|
||
|
||
#line 3 "/home/aledbf/go/src/k8s.io/examples/cassandra/go/main.go" | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#line 1 "cgo-generated-wrapper" | ||
|
||
|
||
/* End of preamble from import "C" comments. */ | ||
|
||
|
||
/* Start of boilerplate cgo prologue. */ | ||
#line 1 "cgo-gcc-export-header-prolog" | ||
|
||
#ifndef GO_CGO_PROLOGUE_H | ||
#define GO_CGO_PROLOGUE_H | ||
|
||
typedef signed char GoInt8; | ||
typedef unsigned char GoUint8; | ||
typedef short GoInt16; | ||
typedef unsigned short GoUint16; | ||
typedef int GoInt32; | ||
typedef unsigned int GoUint32; | ||
typedef long long GoInt64; | ||
typedef unsigned long long GoUint64; | ||
typedef GoInt64 GoInt; | ||
typedef GoUint64 GoUint; | ||
typedef __SIZE_TYPE__ GoUintptr; | ||
typedef float GoFloat32; | ||
typedef double GoFloat64; | ||
typedef float _Complex GoComplex64; | ||
typedef double _Complex GoComplex128; | ||
|
||
/* | ||
static assertion to make sure the file is being used on architecture | ||
at least with matching size of GoInt. | ||
*/ | ||
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1]; | ||
|
||
typedef _GoString_ GoString; | ||
typedef void *GoMap; | ||
typedef void *GoChan; | ||
typedef struct { void *t; void *v; } GoInterface; | ||
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice; | ||
|
||
#endif | ||
|
||
/* End of boilerplate cgo prologue. */ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
|
||
// GetEndpoints searches the endpoints of a service returning a list of IP addresses. | ||
|
||
extern char* GetEndpoints(char* p0, char* p1, char* p2); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
Binary file not shown.
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
54 changes: 54 additions & 0 deletions
54
cassandra/java/src/main/java/io/k8s/cassandra/GoInterface.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,54 @@ | ||
|
||
/* | ||
* Copyright (C) 2018 Google Inc. | ||
* | ||
* 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 io.k8s.cassandra; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import com.sun.jna.Library; | ||
import com.sun.jna.Pointer; | ||
import com.sun.jna.Structure; | ||
|
||
public interface GoInterface extends Library { | ||
public String GetEndpoints(String namespace, String service, String seeds); | ||
|
||
public class GoSlice extends Structure { | ||
public static class ByValue extends GoSlice implements Structure.ByValue { | ||
} | ||
|
||
public Pointer data; | ||
public long len; | ||
public long cap; | ||
|
||
protected List<String> getFieldOrder() { | ||
return Arrays.asList(new String[] { "data", "len", "cap" }); | ||
} | ||
} | ||
|
||
public class GoString extends Structure { | ||
public static class ByValue extends GoString implements Structure.ByValue { | ||
} | ||
|
||
public String p; | ||
public long n; | ||
|
||
protected List<String> getFieldOrder() { | ||
return Arrays.asList(new String[] { "p", "n" }); | ||
} | ||
} | ||
} |
Oops, something went wrong.