use of org.apache.hadoop.ipc.RefreshResponse in project hadoop by apache.
the class GenericRefreshProtocolClientSideTranslatorPB method unpack.
private Collection<RefreshResponse> unpack(GenericRefreshResponseCollectionProto collection) {
List<GenericRefreshResponseProto> responseProtos = collection.getResponsesList();
List<RefreshResponse> responses = new ArrayList<RefreshResponse>();
for (GenericRefreshResponseProto rp : responseProtos) {
RefreshResponse response = unpack(rp);
responses.add(response);
}
return responses;
}
use of org.apache.hadoop.ipc.RefreshResponse in project hadoop by apache.
the class GenericRefreshProtocolClientSideTranslatorPB method unpack.
private RefreshResponse unpack(GenericRefreshResponseProto proto) {
// The default values
String message = null;
String sender = null;
int returnCode = -1;
// ... that can be overridden by data from the protobuf
if (proto.hasUserMessage()) {
message = proto.getUserMessage();
}
if (proto.hasExitStatus()) {
returnCode = proto.getExitStatus();
}
if (proto.hasSenderName()) {
sender = proto.getSenderName();
}
// ... and put into a RefreshResponse
RefreshResponse response = new RefreshResponse(returnCode, message);
response.setSenderName(sender);
return response;
}
use of org.apache.hadoop.ipc.RefreshResponse in project hadoop by apache.
the class GenericRefreshProtocolServerSideTranslatorPB method refresh.
@Override
public GenericRefreshResponseCollectionProto refresh(RpcController controller, GenericRefreshRequestProto request) throws ServiceException {
try {
List<String> argList = request.getArgsList();
String[] args = argList.toArray(new String[argList.size()]);
if (!request.hasIdentifier()) {
throw new ServiceException("Request must contain identifier");
}
Collection<RefreshResponse> results = impl.refresh(request.getIdentifier(), args);
return pack(results);
} catch (IOException e) {
throw new ServiceException(e);
}
}
use of org.apache.hadoop.ipc.RefreshResponse in project hadoop by apache.
the class TestGenericRefresh method setUp.
@Before
public void setUp() throws Exception {
// Register Handlers, first one just sends an ok response
firstHandler = Mockito.mock(RefreshHandler.class);
Mockito.stub(firstHandler.handleRefresh(Mockito.anyString(), Mockito.any(String[].class))).toReturn(RefreshResponse.successResponse());
RefreshRegistry.defaultRegistry().register("firstHandler", firstHandler);
// Second handler has conditional response for testing args
secondHandler = Mockito.mock(RefreshHandler.class);
Mockito.stub(secondHandler.handleRefresh("secondHandler", new String[] { "one", "two" })).toReturn(new RefreshResponse(3, "three"));
Mockito.stub(secondHandler.handleRefresh("secondHandler", new String[] { "one" })).toReturn(new RefreshResponse(2, "two"));
RefreshRegistry.defaultRegistry().register("secondHandler", secondHandler);
}
use of org.apache.hadoop.ipc.RefreshResponse in project hadoop by apache.
the class GenericRefreshProtocolServerSideTranslatorPB method pack.
// Convert a collection of RefreshResponse objects to a
// RefreshResponseCollection proto
private GenericRefreshResponseCollectionProto pack(Collection<RefreshResponse> responses) {
GenericRefreshResponseCollectionProto.Builder b = GenericRefreshResponseCollectionProto.newBuilder();
for (RefreshResponse response : responses) {
GenericRefreshResponseProto.Builder respBuilder = GenericRefreshResponseProto.newBuilder();
respBuilder.setExitStatus(response.getReturnCode());
respBuilder.setUserMessage(response.getMessage());
respBuilder.setSenderName(response.getSenderName());
// Add to collection
b.addResponses(respBuilder);
}
return b.build();
}
Aggregations