From 3c1b77f3ac17220b0df59323690bcb1a31620cdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjetil=20=C3=98rbekk?= Date: Tue, 22 May 2012 12:33:52 +0200 Subject: Add SystemService.KillMaster(). --- .../main/java/com/orbekk/same/SameController.java | 34 +++++++++- same/src/main/java/com/orbekk/same/Services.java | 74 ++++++++++++++++++++-- same/src/main/java/com/orbekk/same/services.proto | 3 +- 3 files changed, 104 insertions(+), 7 deletions(-) diff --git a/same/src/main/java/com/orbekk/same/SameController.java b/same/src/main/java/com/orbekk/same/SameController.java index 80e5589..04185db 100644 --- a/same/src/main/java/com/orbekk/same/SameController.java +++ b/same/src/main/java/com/orbekk/same/SameController.java @@ -27,6 +27,7 @@ import com.google.protobuf.RpcCallback; import com.google.protobuf.RpcController; import com.orbekk.paxos.PaxosServiceImpl; import com.orbekk.protobuf.Rpc; +import com.orbekk.protobuf.RpcChannel; import com.orbekk.protobuf.SimpleProtobufServer; import com.orbekk.same.Services.Empty; import com.orbekk.same.Services.MasterState; @@ -50,8 +51,6 @@ public class SameController { private static final int timeout = 10000; private class SystemServiceImpl extends Services.SystemService { - - private void addMasterInfo(SystemStatus.Builder response) { Master currentMaster = master; if (currentMaster != null) { @@ -81,6 +80,37 @@ public class SameController { addClientInfo(response); done.run(response.build()); } + + @Override + public void killMaster(final RpcController rpc, Empty unused, + final RpcCallback done) { + logger.info("KillMaster()."); + String clientLocation = client.getClientState().getLocation(); + String masterLocation = client.getMaster().getMasterLocation(); + if (clientLocation.equals(masterLocation)) { + SameController.this.killMaster(); + done.run(Empty.getDefaultInstance()); + return; + } else { + RpcChannel channel = connections.getChannel(masterLocation); + if (channel == null) { + logger.error("Unable to contact master."); + done.run(Empty.getDefaultInstance()); + return; + } + Services.SystemService system = Services.SystemService.newStub(channel); + final Rpc rpc_ = rpcf.create(); + RpcCallback done_ = new RpcCallback() { + @Override public void run(Empty unused) { + if (!rpc_.isOk()) { + rpc.setFailed(rpc_.errorText()); + } + done.run(Empty.getDefaultInstance()); + } + }; + system.killMaster(rpc_, Empty.getDefaultInstance(), done_); + } + } } private MasterController masterController = new MasterController() { diff --git a/same/src/main/java/com/orbekk/same/Services.java b/same/src/main/java/com/orbekk/same/Services.java index 266b30e..4b63857 100644 --- a/same/src/main/java/com/orbekk/same/Services.java +++ b/same/src/main/java/com/orbekk/same/Services.java @@ -7819,6 +7819,11 @@ public final class Services { com.orbekk.same.Services.Empty request, com.google.protobuf.RpcCallback done); + public abstract void killMaster( + com.google.protobuf.RpcController controller, + com.orbekk.same.Services.Empty request, + com.google.protobuf.RpcCallback done); + } public static com.google.protobuf.Service newReflectiveService( @@ -7832,6 +7837,14 @@ public final class Services { impl.getSystemStatus(controller, request, done); } + @java.lang.Override + public void killMaster( + com.google.protobuf.RpcController controller, + com.orbekk.same.Services.Empty request, + com.google.protobuf.RpcCallback done) { + impl.killMaster(controller, request, done); + } + }; } @@ -7856,6 +7869,8 @@ public final class Services { switch(method.getIndex()) { case 0: return impl.getSystemStatus(controller, (com.orbekk.same.Services.Empty)request); + case 1: + return impl.killMaster(controller, (com.orbekk.same.Services.Empty)request); default: throw new java.lang.AssertionError("Can't get here."); } @@ -7872,6 +7887,8 @@ public final class Services { switch(method.getIndex()) { case 0: return com.orbekk.same.Services.Empty.getDefaultInstance(); + case 1: + return com.orbekk.same.Services.Empty.getDefaultInstance(); default: throw new java.lang.AssertionError("Can't get here."); } @@ -7888,6 +7905,8 @@ public final class Services { switch(method.getIndex()) { case 0: return com.orbekk.same.Services.SystemStatus.getDefaultInstance(); + case 1: + return com.orbekk.same.Services.Empty.getDefaultInstance(); default: throw new java.lang.AssertionError("Can't get here."); } @@ -7901,6 +7920,11 @@ public final class Services { com.orbekk.same.Services.Empty request, com.google.protobuf.RpcCallback done); + public abstract void killMaster( + com.google.protobuf.RpcController controller, + com.orbekk.same.Services.Empty request, + com.google.protobuf.RpcCallback done); + public static final com.google.protobuf.Descriptors.ServiceDescriptor getDescriptor() { @@ -7928,6 +7952,11 @@ public final class Services { com.google.protobuf.RpcUtil.specializeCallback( done)); return; + case 1: + this.killMaster(controller, (com.orbekk.same.Services.Empty)request, + com.google.protobuf.RpcUtil.specializeCallback( + done)); + return; default: throw new java.lang.AssertionError("Can't get here."); } @@ -7944,6 +7973,8 @@ public final class Services { switch(method.getIndex()) { case 0: return com.orbekk.same.Services.Empty.getDefaultInstance(); + case 1: + return com.orbekk.same.Services.Empty.getDefaultInstance(); default: throw new java.lang.AssertionError("Can't get here."); } @@ -7960,6 +7991,8 @@ public final class Services { switch(method.getIndex()) { case 0: return com.orbekk.same.Services.SystemStatus.getDefaultInstance(); + case 1: + return com.orbekk.same.Services.Empty.getDefaultInstance(); default: throw new java.lang.AssertionError("Can't get here."); } @@ -7995,6 +8028,21 @@ public final class Services { com.orbekk.same.Services.SystemStatus.class, com.orbekk.same.Services.SystemStatus.getDefaultInstance())); } + + public void killMaster( + com.google.protobuf.RpcController controller, + com.orbekk.same.Services.Empty request, + com.google.protobuf.RpcCallback done) { + channel.callMethod( + getDescriptor().getMethods().get(1), + controller, + request, + com.orbekk.same.Services.Empty.getDefaultInstance(), + com.google.protobuf.RpcUtil.generalizeCallback( + done, + com.orbekk.same.Services.Empty.class, + com.orbekk.same.Services.Empty.getDefaultInstance())); + } } public static BlockingInterface newBlockingStub( @@ -8007,6 +8055,11 @@ public final class Services { com.google.protobuf.RpcController controller, com.orbekk.same.Services.Empty request) throws com.google.protobuf.ServiceException; + + public com.orbekk.same.Services.Empty killMaster( + com.google.protobuf.RpcController controller, + com.orbekk.same.Services.Empty request) + throws com.google.protobuf.ServiceException; } private static final class BlockingStub implements BlockingInterface { @@ -8027,6 +8080,18 @@ public final class Services { com.orbekk.same.Services.SystemStatus.getDefaultInstance()); } + + public com.orbekk.same.Services.Empty killMaster( + com.google.protobuf.RpcController controller, + com.orbekk.same.Services.Empty request) + throws com.google.protobuf.ServiceException { + return (com.orbekk.same.Services.Empty) channel.callBlockingMethod( + getDescriptor().getMethods().get(1), + controller, + request, + com.orbekk.same.Services.Empty.getDefaultInstance()); + } + } } @@ -8143,10 +8208,11 @@ public final class Services { "\n\007Propose\022\035.com.orbekk.same.PaxosRequest" + "\032\036.com.orbekk.same.PaxosResponse\022N\n\rAcce" + "ptRequest\022\035.com.orbekk.same.PaxosRequest" + - "\032\036.com.orbekk.same.PaxosResponse2Y\n\rSyst", - "emService\022H\n\017GetSystemStatus\022\026.com.orbek" + - "k.same.Empty\032\035.com.orbekk.same.SystemSta" + - "tusB\003\210\001\001" + "\032\036.com.orbekk.same.PaxosResponse2\227\001\n\rSys", + "temService\022H\n\017GetSystemStatus\022\026.com.orbe" + + "kk.same.Empty\032\035.com.orbekk.same.SystemSt" + + "atus\022<\n\nKillMaster\022\026.com.orbekk.same.Emp" + + "ty\032\026.com.orbekk.same.EmptyB\003\210\001\001" }; com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { diff --git a/same/src/main/java/com/orbekk/same/services.proto b/same/src/main/java/com/orbekk/same/services.proto index 8c05e3f..bf13075 100644 --- a/same/src/main/java/com/orbekk/same/services.proto +++ b/same/src/main/java/com/orbekk/same/services.proto @@ -93,4 +93,5 @@ service Paxos { service SystemService { rpc GetSystemStatus (Empty) returns (SystemStatus); -} \ No newline at end of file + rpc KillMaster (Empty) returns (Empty); +} -- cgit v1.2.3