Search in sources :

Example 6 with RefreshResponse

use of org.apache.hadoop.ipc.RefreshResponse in project hadoop by apache.

the class DFSAdmin method genericRefresh.

public int genericRefresh(String[] argv, int i) throws IOException {
    String hostport = argv[i++];
    String identifier = argv[i++];
    String[] args = Arrays.copyOfRange(argv, i, argv.length);
    // Get the current configuration
    Configuration conf = getConf();
    // for security authorization
    // server principal for this call
    // should be NN's one.
    conf.set(CommonConfigurationKeys.HADOOP_SECURITY_SERVICE_USER_NAME_KEY, conf.get(DFSConfigKeys.DFS_NAMENODE_KERBEROS_PRINCIPAL_KEY, ""));
    // Create the client
    Class<?> xface = GenericRefreshProtocolPB.class;
    InetSocketAddress address = NetUtils.createSocketAddr(hostport);
    UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
    RPC.setProtocolEngine(conf, xface, ProtobufRpcEngine.class);
    GenericRefreshProtocolPB proxy = (GenericRefreshProtocolPB) RPC.getProxy(xface, RPC.getProtocolVersion(xface), address, ugi, conf, NetUtils.getDefaultSocketFactory(conf), 0);
    Collection<RefreshResponse> responses = null;
    try (GenericRefreshProtocolClientSideTranslatorPB xlator = new GenericRefreshProtocolClientSideTranslatorPB(proxy)) {
        // Refresh
        responses = xlator.refresh(identifier, args);
        int returnCode = 0;
        // Print refresh responses
        System.out.println("Refresh Responses:\n");
        for (RefreshResponse response : responses) {
            System.out.println(response.toString());
            if (returnCode == 0 && response.getReturnCode() != 0) {
                // This is the first non-zero return code, so we should return this
                returnCode = response.getReturnCode();
            } else if (returnCode != 0 && response.getReturnCode() != 0) {
                // Then now we have multiple non-zero return codes,
                // so we merge them into -1
                returnCode = -1;
            }
        }
        return returnCode;
    } finally {
        if (responses == null) {
            System.out.println("Failed to get response.\n");
            return -1;
        }
    }
}
Also used : GenericRefreshProtocolPB(org.apache.hadoop.ipc.protocolPB.GenericRefreshProtocolPB) RefreshResponse(org.apache.hadoop.ipc.RefreshResponse) Configuration(org.apache.hadoop.conf.Configuration) HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) GenericRefreshProtocolClientSideTranslatorPB(org.apache.hadoop.ipc.protocolPB.GenericRefreshProtocolClientSideTranslatorPB) InetSocketAddress(java.net.InetSocketAddress) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 7 with RefreshResponse

use of org.apache.hadoop.ipc.RefreshResponse in project hadoop by apache.

the class TestGenericRefresh method testMultipleReturnCodeMerging.

@Test
public void testMultipleReturnCodeMerging() throws Exception {
    // Two handlers which return two non-zero values
    RefreshHandler handlerOne = Mockito.mock(RefreshHandler.class);
    Mockito.stub(handlerOne.handleRefresh(Mockito.anyString(), Mockito.any(String[].class))).toReturn(new RefreshResponse(23, "Twenty Three"));
    RefreshHandler handlerTwo = Mockito.mock(RefreshHandler.class);
    Mockito.stub(handlerTwo.handleRefresh(Mockito.anyString(), Mockito.any(String[].class))).toReturn(new RefreshResponse(10, "Ten"));
    // Then registered to the same ID
    RefreshRegistry.defaultRegistry().register("shared", handlerOne);
    RefreshRegistry.defaultRegistry().register("shared", handlerTwo);
    // We refresh both
    DFSAdmin admin = new DFSAdmin(config);
    String[] args = new String[] { "-refresh", "localhost:" + cluster.getNameNodePort(), "shared" };
    int exitCode = admin.run(args);
    // We get -1 because of our logic for melding non-zero return codes
    assertEquals(-1, exitCode);
    // Verify we called both
    Mockito.verify(handlerOne).handleRefresh("shared", new String[] {});
    Mockito.verify(handlerTwo).handleRefresh("shared", new String[] {});
    RefreshRegistry.defaultRegistry().unregisterAll("shared");
}
Also used : RefreshResponse(org.apache.hadoop.ipc.RefreshResponse) DFSAdmin(org.apache.hadoop.hdfs.tools.DFSAdmin) RefreshHandler(org.apache.hadoop.ipc.RefreshHandler) Test(org.junit.Test)

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