Search in sources :

Example 1 with RefreshResponse

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;
}
Also used : RefreshResponse(org.apache.hadoop.ipc.RefreshResponse) GenericRefreshResponseProto(org.apache.hadoop.ipc.proto.GenericRefreshProtocolProtos.GenericRefreshResponseProto) ArrayList(java.util.ArrayList)

Example 2 with RefreshResponse

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;
}
Also used : RefreshResponse(org.apache.hadoop.ipc.RefreshResponse)

Example 3 with RefreshResponse

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);
    }
}
Also used : RefreshResponse(org.apache.hadoop.ipc.RefreshResponse) ServiceException(com.google.protobuf.ServiceException) IOException(java.io.IOException)

Example 4 with RefreshResponse

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);
}
Also used : RefreshResponse(org.apache.hadoop.ipc.RefreshResponse) RefreshHandler(org.apache.hadoop.ipc.RefreshHandler) Before(org.junit.Before)

Example 5 with RefreshResponse

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();
}
Also used : RefreshResponse(org.apache.hadoop.ipc.RefreshResponse) GenericRefreshResponseProto(org.apache.hadoop.ipc.proto.GenericRefreshProtocolProtos.GenericRefreshResponseProto) GenericRefreshResponseCollectionProto(org.apache.hadoop.ipc.proto.GenericRefreshProtocolProtos.GenericRefreshResponseCollectionProto)

Aggregations

RefreshResponse (org.apache.hadoop.ipc.RefreshResponse)7 RefreshHandler (org.apache.hadoop.ipc.RefreshHandler)2 GenericRefreshResponseProto (org.apache.hadoop.ipc.proto.GenericRefreshProtocolProtos.GenericRefreshResponseProto)2 ServiceException (com.google.protobuf.ServiceException)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 Configuration (org.apache.hadoop.conf.Configuration)1 HdfsConfiguration (org.apache.hadoop.hdfs.HdfsConfiguration)1 DFSAdmin (org.apache.hadoop.hdfs.tools.DFSAdmin)1 GenericRefreshResponseCollectionProto (org.apache.hadoop.ipc.proto.GenericRefreshProtocolProtos.GenericRefreshResponseCollectionProto)1 GenericRefreshProtocolClientSideTranslatorPB (org.apache.hadoop.ipc.protocolPB.GenericRefreshProtocolClientSideTranslatorPB)1 GenericRefreshProtocolPB (org.apache.hadoop.ipc.protocolPB.GenericRefreshProtocolPB)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1 Before (org.junit.Before)1 Test (org.junit.Test)1