-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
basic skeleton of Binder and Reconciliation service infra
- Loading branch information
1 parent
4565621
commit 6d2ea93
Showing
12 changed files
with
254 additions
and
25 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
73 changes: 73 additions & 0 deletions
73
leyden/src/main/java/com/salesforce/apollo/leyden/comm/binding/Bind.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,73 @@ | ||
package com.salesforce.apollo.leyden.comm.binding; | ||
|
||
import com.salesforce.apollo.archipelago.ManagedServerChannel; | ||
import com.salesforce.apollo.leyden.proto.BinderGrpc; | ||
import com.salesforce.apollo.leyden.proto.Binding; | ||
import com.salesforce.apollo.leyden.proto.Key_; | ||
import com.salesforce.apollo.membership.Member; | ||
import com.salesforce.apollo.membership.SigningMember; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* @author hal.hildebrand | ||
**/ | ||
public class Bind implements BinderClient { | ||
private final ManagedServerChannel channel; | ||
private final BinderMetrics metrics; | ||
private final BinderGrpc.BinderBlockingStub client; | ||
|
||
public Bind(ManagedServerChannel channel, BinderMetrics metrics) { | ||
this.channel = channel; | ||
this.metrics = metrics; | ||
this.client = BinderGrpc.newBlockingStub(channel); | ||
} | ||
|
||
public static BinderClient getCreate(ManagedServerChannel c, BinderMetrics binderMetrics) { | ||
return new Bind(c, binderMetrics); | ||
} | ||
|
||
public static BinderClient getLocalLoopback(BinderService service, SigningMember member) { | ||
return new BinderClient() { | ||
@Override | ||
public void bind(Binding binding) { | ||
service.bind(binding, member.getId()); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
// no op | ||
} | ||
|
||
@Override | ||
public Member getMember() { | ||
return member; | ||
} | ||
|
||
@Override | ||
public void unbind(Key_ key) { | ||
service.unbind(key, member.getId()); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public void bind(Binding binding) { | ||
client.bind(binding); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
channel.shutdown(); | ||
} | ||
|
||
@Override | ||
public Member getMember() { | ||
return channel.getMember(); | ||
} | ||
|
||
@Override | ||
public void unbind(Key_ key) { | ||
client.unbind(key); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
leyden/src/main/java/com/salesforce/apollo/leyden/comm/binding/BinderClient.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,15 @@ | ||
package com.salesforce.apollo.leyden.comm.binding; | ||
|
||
import com.salesforce.apollo.archipelago.Link; | ||
import com.salesforce.apollo.leyden.proto.Binding; | ||
import com.salesforce.apollo.leyden.proto.Key_; | ||
|
||
/** | ||
* @author hal.hildebrand | ||
**/ | ||
public interface BinderClient extends Link { | ||
|
||
void bind(Binding binding); | ||
|
||
void unbind(Key_ key); | ||
} |
18 changes: 18 additions & 0 deletions
18
leyden/src/main/java/com/salesforce/apollo/leyden/comm/binding/BinderMetrics.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,18 @@ | ||
package com.salesforce.apollo.leyden.comm.binding; | ||
|
||
import com.codahale.metrics.Histogram; | ||
import com.codahale.metrics.Timer; | ||
import com.salesforce.apollo.protocols.EndpointMetrics; | ||
|
||
/** | ||
* @author hal.hildebrand | ||
**/ | ||
public interface BinderMetrics extends EndpointMetrics { | ||
Histogram inboundBind(); | ||
|
||
Timer inboundBindTimer(); | ||
|
||
Histogram inboundUnbind(); | ||
|
||
Timer inboundUnbindTimer(); | ||
} |
80 changes: 80 additions & 0 deletions
80
leyden/src/main/java/com/salesforce/apollo/leyden/comm/binding/BinderServer.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,80 @@ | ||
package com.salesforce.apollo.leyden.comm.binding; | ||
|
||
import com.codahale.metrics.Timer; | ||
import com.google.protobuf.Empty; | ||
import com.salesforce.apollo.archipelago.RoutableService; | ||
import com.salesforce.apollo.cryptography.Digest; | ||
import com.salesforce.apollo.leyden.proto.BinderGrpc; | ||
import com.salesforce.apollo.leyden.proto.Binding; | ||
import com.salesforce.apollo.leyden.proto.Key_; | ||
import com.salesforce.apollo.protocols.ClientIdentity; | ||
import io.grpc.stub.StreamObserver; | ||
|
||
/** | ||
* @author hal.hildebrand | ||
**/ | ||
public class BinderServer extends BinderGrpc.BinderImplBase { | ||
|
||
private final RoutableService<BinderService> routing; | ||
private final ClientIdentity identity; | ||
private final BinderMetrics metrics; | ||
|
||
public BinderServer(RoutableService<BinderService> r, ClientIdentity clientIdentityProvider, | ||
BinderMetrics binderMetrics) { | ||
routing = r; | ||
this.identity = clientIdentityProvider; | ||
this.metrics = binderMetrics; | ||
} | ||
|
||
@Override | ||
public void bind(Binding request, StreamObserver<Empty> responseObserver) { | ||
Timer.Context timer = metrics == null ? null : metrics.inboundBindTimer().time(); | ||
if (metrics != null) { | ||
var serializedSize = request.getSerializedSize(); | ||
metrics.inboundBandwidth().mark(serializedSize); | ||
metrics.inboundBind().update(serializedSize); | ||
} | ||
Digest from = identity.getFrom(); | ||
if (from == null) { | ||
responseObserver.onError(new IllegalStateException("Member has been removed")); | ||
return; | ||
} | ||
routing.evaluate(responseObserver, s -> { | ||
try { | ||
s.bind(request, from); | ||
responseObserver.onNext(Empty.getDefaultInstance()); | ||
responseObserver.onCompleted(); | ||
} finally { | ||
if (timer != null) { | ||
timer.stop(); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void unbind(Key_ request, StreamObserver<Empty> responseObserver) { | ||
Timer.Context timer = metrics == null ? null : metrics.inboundUnbindTimer().time(); | ||
if (metrics != null) { | ||
var serializedSize = request.getSerializedSize(); | ||
metrics.inboundBandwidth().mark(serializedSize); | ||
metrics.inboundUnbind().update(serializedSize); | ||
} | ||
Digest from = identity.getFrom(); | ||
if (from == null) { | ||
responseObserver.onError(new IllegalStateException("Member has been removed")); | ||
return; | ||
} | ||
routing.evaluate(responseObserver, s -> { | ||
try { | ||
s.unbind(request, from); | ||
responseObserver.onNext(Empty.getDefaultInstance()); | ||
responseObserver.onCompleted(); | ||
} finally { | ||
if (timer != null) { | ||
timer.stop(); | ||
} | ||
} | ||
}); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
leyden/src/main/java/com/salesforce/apollo/leyden/comm/binding/BinderService.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,14 @@ | ||
package com.salesforce.apollo.leyden.comm.binding; | ||
|
||
import com.salesforce.apollo.cryptography.Digest; | ||
import com.salesforce.apollo.leyden.proto.Binding; | ||
import com.salesforce.apollo.leyden.proto.Key_; | ||
|
||
/** | ||
* @author hal.hildebrand | ||
**/ | ||
public interface BinderService { | ||
void bind(Binding request, Digest from); | ||
|
||
void unbind(Key_ request, Digest from); | ||
} |
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
4 changes: 2 additions & 2 deletions
4
...llo/leyden/comm/ReconciliationClient.java → .../comm/reconcile/ReconciliationClient.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
2 changes: 1 addition & 1 deletion
2
...lo/leyden/comm/ReconciliationMetrics.java → ...comm/reconcile/ReconciliationMetrics.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
8 changes: 4 additions & 4 deletions
8
...llo/leyden/comm/ReconciliationServer.java → .../comm/reconcile/ReconciliationServer.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
4 changes: 2 additions & 2 deletions
4
...lo/leyden/comm/ReconciliationService.java → ...comm/reconcile/ReconciliationService.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