etcd-io / jetcd Goto Github PK
View Code? Open in Web Editor NEWetcd java client
License: Apache License 2.0
etcd java client
License: Apache License 2.0
I think it'd be useful for the client to be able to set custom metadata (e.g. HTTP2 request headers) that would be part of the remote call. Basically, a way for the client to set gRPC metadata. It could be abstracted supported something like:
Map<String, String> requestHeaders = new HashMap<>(); requestHeaders.put("someKaey", "someValue"); EtcdClient client = EtcdClientBuilder.newBuilder().endpoints("localhost:4004").requestHeaders(requestHeaders).build();
I would like to add a internal package such as "com.coreos.jetcd.internal" and move some implementation classes like EtcdKVImpl to it.
And we should document that all the classes in package internal are our internal implementation detail and should not be used directly.
Then We can update them freely.
please confirm above question.
Has anyone managed to get a java etcd client to use SSL, and if so, how?
I have generated self-signed certificates (ca, server, and client) that work fine with etcdctl (with etcd3) but cannot get it to work with netty-tcnative from java. I always get the following:
io.netty.handler.ssl.OpenSslEngine - SSL_read failed: OpenSSL error: error:10000412:SSL routines:OPENSSL_internal:SSLV3_ALERT_BAD_CERTIFICATE
One question, which JDK version should we support in jetcd?
java8? or java 7?
I just checked out master and ran mvn package
and it appears seven tests are failing:
Failed tests:
EtcdAuthClientTest.testRoleAdd:59 » Execution io.grpc.StatusRuntimeException: ...
EtcdAuthClientTest.testUserAdd:75 » Execution io.grpc.StatusRuntimeException: ...
EtcdClusterClientTest.testListCluster:32 » Execution io.grpc.StatusRuntimeExce...
EtcdLeaseTest.testGrant:43 » Execution io.grpc.StatusRuntimeException: UNAVAIL...
MaintenanceTest.testAlarmList:46 » Execution io.grpc.StatusRuntimeException: U...
MaintenanceTest.testDefragment:84 » Execution io.grpc.StatusRuntimeException: ...
MaintenanceTest.testStatusMember:35 » Execution io.grpc.StatusRuntimeException...
Tests run: 37, Failures: 7, Errors: 0, Skipped: 15
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 27.076 s
[INFO] Finished at: 2016-12-17T16:01:27-05:00
[INFO] Final Memory: 40M/666M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project jetcd: There are test failures.
We probably just want to use a real etcd cluster for testing instead of mocking it for now.
Something like this https://github.com/justinsb/jetcd/blob/master/scripts/run_etcd.sh should be good enough.
I think Txn.Builder would be more user friendly if it allowed appending If/Then/Else operations rather than just replacing them. Right now you have to prepare them in some lists, then add them to builder.
<goals> <goal>add-source</goal> </goals> <configuration> <sources> <source>${basedir}/target/generated-sources</source> </sources> </configuration>
I think this config above is incorrect.
It must change to config like below:
<goals> <goal>add-source</goal> </goals> <configuration> <sources> <source>${basedir}/target/generated-sources/protobuf/java</source> <source>${basedir}/target/generated-sources/protobuf/grpc-java</source> </sources> </configuration>
so it can find the correct source folder.
same with title
Cannot run following code snippet
// create client
Client client = ClientBuilder.newBuilder().endpoints("http://localhost:2379").build();
KV kvClient = client.getKVClient();
ByteSequence key = ByteSequence.fromString("test_key");
ByteSequence value = ByteSequence.fromString("test_value");
// put the key-value
kvClient.put(key, value).get();
// get the CompletableFuture
CompletableFuture getFuture = kvClient.get(key);
// get the value from CompletableFuture
RangeResponse response = getFuture.get();
// delete the key
DeleteRangeResponse deleteRangeResponse = kvClient.delete(key).get();
it throws :
Caused by: io.grpc.StatusRuntimeException: UNKNOWN
at io.grpc.Status.asRuntimeException(Status.java:540)
at io.grpc.stub.ClientCalls$UnaryStreamToFuture.onClose(ClientCalls.java:439)
at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:426)
at io.grpc.internal.ClientCallImpl.access$100(ClientCallImpl.java:76)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:512)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$700(ClientCallImpl.java:429)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:544)
at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:52)
at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:117)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoSuchMethodError: io.netty.handler.codec.http2.Http2Connection$Endpoint.maxStreams(II)V
at io.grpc.netty.FixedHttp2ConnectionDecoder$FrameReadListener.applyLocalSettings(FixedHttp2ConnectionDecoder.java:416)
at io.grpc.netty.FixedHttp2ConnectionDecoder$FrameReadListener.onSettingsAckRead(FixedHttp2ConnectionDecoder.java:390)
at io.grpc.netty.FixedHttp2ConnectionDecoder$PrefaceFrameListener.onSettingsAckRead(FixedHttp2ConnectionDecoder.java:660)
at io.netty.handler.codec.http2.Http2InboundFrameLogger$1.onSettingsAckRead(Http2InboundFrameLogger.java:86)
at io.netty.handler.codec.http2.DefaultHttp2FrameReader.readSettingsFrame(DefaultHttp2FrameReader.java:522)
at io.netty.handler.codec.http2.DefaultHttp2FrameReader.processPayloadState(DefaultHttp2FrameReader.java:263)
at io.netty.handler.codec.http2.DefaultHttp2FrameReader.readFrame(DefaultHttp2FrameReader.java:160)
at io.netty.handler.codec.http2.Http2InboundFrameLogger.readFrame(Http2InboundFrameLogger.java:41)
at io.grpc.netty.FixedHttp2ConnectionDecoder.decodeFrame(FixedHttp2ConnectionDecoder.java:119)
at io.netty.handler.codec.http2.Http2ConnectionHandler$FrameDecoder.decode(Http2ConnectionHandler.java:353)
at io.netty.handler.codec.http2.Http2ConnectionHandler$PrefaceDecoder.decode(Http2ConnectionHandler.java:224)
at io.netty.handler.codec.http2.Http2ConnectionHandler.decode(Http2ConnectionHandler.java:413)
at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:489)
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:428)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:265)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1334)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:134)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:644)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:579)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:496)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:458)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:138)
... 1 more
Although test cases are running without throwing errors. This error is fixed in grpc version 1.4.0. Need to update the dependency .
Am I missing something? Or the callback parameter is never actually used?
I see the EtcdKV interface and impl are wrapping the generated gRPC clients with some helper utilities. At least for simple things like put and delete, I'd like to discuss if these should wrap, or sit to the side? For example.
generatedClient.put(EtcdUtil.putRequest(key, value));
This way users can still easily choose their interaction model(blocking, future, async), but still get the benefit of a nicer builder and handy defaults.
I expect there to be recipes as well for common multi-step interactions, and those very well may need to wrap, but the items so far seem capable of living to the side as helpers.
Thoughts?
Hi, as discussed in PR #40 , we should discuss about the goals of etcd watch client.
As my idea, etcd watch is a client to manage watch requests.
Goals:
Hope for your ideas about watch client, @hongchaodeng @sijie @xiang90 @adohe .
In @jurmous etcd4j's client, there were a simple dns srv discovery util to get a list of etcd instances, would it make sense to port it here ?
We should hide the exception throw directly from gRPC. So we can have better defined errorCode and status for easier error handling.
com.coreos.jetcd.api.KVGrpc and com.coreos.jetcd.api.LeaseGrpc cannot be generated from auth.proto, kv.proto and rpc.proto by protoc-3.0.0-win32.
I used the latest version of master, if any configuration missed?
As subject...
The package com.coreos.jetcd contains both the interface definition and the related implementations that cane be instantiated as they are public and have a public constructor so I think it would be nice to do eithe make the visibility of the implemntation classes as package scope or move them to com.coreos.jetcd.internal.impl so at least the name mark them as non public.
Thoughts ?
If I properly understood etcd set-ups channels and eventually authentication on constructors (Client, KVImpl, etc) but that may be a little bit early so it would be nice to have an option to delay it to later stage i.e. when the first request is made.
Does it make sense ?
Currently, all tests are running against one etcd cluster. This is bad because ordering of how tests case are being run can affect the correctness of the test; A test failure might cause by operations done to the shared cluster from another test.
We need a better test framework that allows each test to spawn its own etcd cluster and runs against it. In this way, all tests don't need to share a test etcd cluster and are way more self contained.
Is jetcd released in some Maven repo? The 'releases' tab in GitHub shows 0.
I am fine by this - can use mvn install -DskipTests
- but this StackOverflow entry might benefit from official comments.
Exception in thread "main" java.lang.IncompatibleClassChangeError: Found interface com.coreos.jetcd.Client, but class was expected
I'm wondering if it could make sense to enhance client interface with convenient methods i.e:
ListenableFuture<PutResponse> put(ByteString key, ByteString value);
void put(
ByteString key, ByteString value,
PutOption option,
Consumer<PutResponse> onResponse, Consumer<Throwable> onError);
void put(
ByteString key, ByteString value,
Consumer<PutResponse> onResponse, Consumer<Throwable> onError);
void put(
ByteString key, ByteString value,
Consumer<PutResponse> onResponse); throws an RuntimeException in case of error
hi, now we are using grpc version 0.15.0, and the new version of grpc is 1.0.0.pre2。
should we update to this version now? One strong reason is that in this version protobuf has been update to release version 3.0.0 and netty is udpate to 3.1.7-final with some bug fixing.
I have to say that in 1.0.0-pre2 (includes pre1) there are some big changes we have to face:
public static interface KV {}
public static interface KVBlockingClient {}
public static interface KVFutureClient {}
PS: in 0.15.0, these interfaces are marked as Deprecated.
2. The stub class is now changed to be "final"
Now in the client we have only one choice :
public static class KVStub extends io.grpc.stub.AbstractStub{}
And in 1.0.0-pre2, this class is marked in final class.
So if we want to do some unit test to mock the special error case, we have to introduce something like powermock to mock final class.
Should we update it now or later?
jetcd should support nested txn behavior as documented here etcd-io/etcd#7857.
50% of time testKeepAliveOnceStreamCloseOnSuccess() blocks on this.responseObserverRef.get().onNext(lrp);
public void testKeepAliveOnceStreamCloseOnSuccess()
throws ExecutionException, InterruptedException {
CompletableFuture<com.coreos.jetcd.lease.LeaseKeepAliveResponse> lrpFuture = this.leaseCli
.keepAliveOnce(LEASE_ID);
LeaseKeepAliveResponse lrp = LeaseKeepAliveResponse
.newBuilder()
.setID(LEASE_ID)
.build();
this.responseObserverRef.get().onNext(lrp);
lrpFuture.get();
verify(this.requestStreamObserverMock, timeout(100).times(1)).onCompleted();
}
For some reason, onNext()
doesn't return.
Importing jetcd to intellij IDEA cause missing com.coreos.jetcd.api
Anybody faced same issue?
you can reproduce this bug as such steps:
When I using code below to start watch a key, but failed with an exception
WatchOption watchOption = WatchOption.DEFAULT;
try {
watcher = watchClient.watch(key, watchOption, new WatchCallback() {
@Override
public void onWatch(EtcdHeader header, List<WatchEvent> events) {
System.out.println("onWatch() called");
}
@Override
public void onResuming() {
}
}).get();
} catch (InterruptedException | ExecutionException e) {
logger.error("Error watch leader", e);
} catch (Exception e) {
logger.error("Unexpected exception", e);
}
Exception:
May 10, 2017 10:14:38 AM io.grpc.internal.SerializingExecutor$TaskRunner run
SEVERE: Exception while executing runnable io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1MessageRead@6d32cbca
java.util.NoSuchElementException: No value present
at java.util.Optional.get(Optional.java:135)
at com.coreos.jetcd.EtcdWatchImpl.getResumeWatchOptionWithWatcher(EtcdWatchImpl.java:298)
at com.coreos.jetcd.EtcdWatchImpl.resumeWatchers(EtcdWatchImpl.java:251)
at com.coreos.jetcd.EtcdWatchImpl.resume(EtcdWatchImpl.java:107)
at com.coreos.jetcd.EtcdWatchImpl.access$400(EtcdWatchImpl.java:32)
at com.coreos.jetcd.EtcdWatchImpl$1.onError(EtcdWatchImpl.java:139)
at io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter.onClose(ClientCalls.java:392)
at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:428)
at io.grpc.internal.ClientCallImpl.access$100(ClientCallImpl.java:76)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:514)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$700(ClientCallImpl.java:431)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1MessageRead.runInContext(ClientCallImpl.java:499)
at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:52)
at io.grpc.internal.SerializingExecutor$TaskRunner.run(SerializingExecutor.java:152)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
the root cause is:
private WatchOption getResumeWatchOptionWithWatcher(Watcher watcher) {
WatchOption oldOption = watcher.getWatchOption();
return WatchOption.newBuilder().withNoDelete(oldOption.isNoDelete())
.withNoPut(oldOption.isNoPut())
.withPrevKV(oldOption.isPrevKV())
.withProgressNotify(oldOption.isProgressNotify())
.withRange(oldOption.getEndKey().get()) // THIS LINE
.withRevision(watcher.getLastRevision() + 1)
.withResuming(true)
.build();
}
wish u to give a solution, thanks
Probably we need to add doc to talk about:
So that the java implementation can be close to go impl.
currently all test cases in AuthClientTest depends on each other and should be decoupled. each test should be self contained.
In order to remove grpc and guava dependency, all the responses that jetcd returns shouldn't be a direct message type from grpc because the grpc message contains ByteString field which is a type from protobuf Library. Then user needs to import Guava/Protobuf library and can cause Guava/Protobuf version conflicts.
There is another java project named jetcd on github and it is a java client for etcd v2.
Do we change to another name? like jetcd3?
Hello,
I am trying to use jetcd. However, it needs a lot of dependency jar files. I have downloaded/included all slf4j-1.7.25, protobuf-java-3.2.0, grpc-java-1.0.0,netty-4.1.9.Final JAR files. But, still when running the java program, I am getting "Exception in thread "main" java.lang.NoClassDefFoundError: .io/netty/handler/codec/BinaryHeaders". I am not sure what else need to be included. Is there a list of dependency jars (tree of jars) for jetcd?
Thanks!
Exception info as below:
Exception while executing runnable io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1MessageRead@7f9132bb
java.util.NoSuchElementException: No value present
at java.util.Optional.get(Optional.java:135)
at com.coreos.jetcd.WatchImpl.getResumeWatchOptionWithWatcher(WatchImpl.java:299)
at com.coreos.jetcd.WatchImpl.resumeWatchers(WatchImpl.java:252)
at com.coreos.jetcd.WatchImpl.resume(WatchImpl.java:108)
at com.coreos.jetcd.WatchImpl.access$400(WatchImpl.java:33)
at com.coreos.jetcd.WatchImpl$1.onError(WatchImpl.java:140)
at io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter.onClose(ClientCalls.java:392)
at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:428)
at io.grpc.internal.ClientCallImpl.access$100(ClientCallImpl.java:76)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:514)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$700(ClientCallImpl.java:431)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1MessageRead.runInContext(ClientCallImpl.java:499)
at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:52)
at io.grpc.internal.SerializingExecutor$TaskRunner.run(SerializingExecutor.java:152)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
You can reproduce ti as such steps:
Could you locate and fix this issue as soon as possible ? Thanks a lot!
Currently, EtcdLease exposes com.google.common.util.concurrent.ListenableFuture as a part of API. If ListenableFuture is used directly, it will conflict with user-side guava library. Instead, ListenableSetFuture in #45 or some wrapper class in com.coreos.jetcd should be used to avoid the problem.
edit: no need to add Hash() because etcd go client doesn't have it.
I'm trying to implement a micro service demo using etcd as service registry center. Assume I have deployed three etcd nodes, which are 192.168.99.11:2379, 192.168.99.22:2379 and 192.168.99.33:2379, along with a service process deployed on each node.
The service process on each node is listening on port 9999 and registered in the etcd cluster with keys /etcd3/foo/192.168.99.11:9999, /etcd3/foo/192.168.99.22:9999 and /etcd3/foo/192.168.99.33:9999.
My question is how to use java gRPC and jetcd to discover the list of three service nodes and do rpc call with round robin load balancing. I've tried many ways only to find the NameResolver really confuses me and EtcdKV doesn't support get with prefix. I can't get the service list from key /etcd3/foo/ without get with prefix. However, I can get the service list from key /etcd3/foo/ on command line using etcdctl get --prefix /etcd3/foo/.
Better show me some sample codes. It's kinda urgent. Thanks in advance!
Could someone write a few lines in the README with:
Hello,
Am I correct in assuming there is no actual way to use EtcdLeaseImpl at the moment or have I missed something?
Hello,
I'm prototyping etcd
to run our local service discovery.
I'm running Debian 8.0, and using the official Quay Docker image to run etcd
.
I've started the docker single instance cluster using:
docker run -d -v /usr/share/ca-certificates/:/etc/ssl/certs -p 4001:4001 -p 2380:2380 -p 2379:2379 \
--name etcd quay.io/coreos/etcd etcd \
-name etcd0 \
-advertise-client-urls http://${HostIP}:2379,http://${HostIP}:4001 \
-listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \
-initial-advertise-peer-urls http://${HostIP}:2380 \
-listen-peer-urls http://0.0.0.0:2380 \
-initial-cluster-token etcd-cluster-1 \
-initial-cluster etcd0=http://${HostIP}:2380 \
-initial-cluster-state new
If I clone the latest coreos/jetcd
and run mvn package
, I get a test failure:
Tests run: 34, Failures: 2, Errors: 0, Skipped: 3, Time elapsed: 28.542 sec <<< FAILURE! - in TestSuite
testListCluster(com.coreos.jetcd.EtcdClusterClientTest) Time elapsed: 0.013 sec <<< FAILURE!
java.lang.AssertionError: Members: 1 expected [3] but found [1]
at com.coreos.jetcd.EtcdClusterClientTest.testListCluster(EtcdClusterClientTest.java:33)
Is this a known issue?
Also, if I try to run it again, I get that same error, plus a new one:
testGetSortedPrefix(com.coreos.jetcd.EtcdKVTest) Time elapsed: 0.034 sec <<< FAILURE!
java.lang.AssertionError: expected [3] but found [4]
at com.coreos.jetcd.EtcdKVTest.testGetSortedPrefix(EtcdKVTest.java:115)
So as a secondary issue, there may be a need to setup the environment properly.
Thank you,
Dustin
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.