Search in sources :

Example 1 with GenericRefreshProtocolPB

use of org.apache.hadoop.ipc.protocolPB.GenericRefreshProtocolPB 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)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)1 Configuration (org.apache.hadoop.conf.Configuration)1 HdfsConfiguration (org.apache.hadoop.hdfs.HdfsConfiguration)1 RefreshResponse (org.apache.hadoop.ipc.RefreshResponse)1 GenericRefreshProtocolClientSideTranslatorPB (org.apache.hadoop.ipc.protocolPB.GenericRefreshProtocolClientSideTranslatorPB)1 GenericRefreshProtocolPB (org.apache.hadoop.ipc.protocolPB.GenericRefreshProtocolPB)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1