Search in sources :

Example 1 with RefreshAuthorizationPolicyProtocol

use of org.apache.hadoop.security.authorize.RefreshAuthorizationPolicyProtocol in project hadoop by apache.

the class DFSAdmin method refreshServiceAcl.

/**
   * Refresh the authorization policy on the {@link NameNode}.
   * @return exitcode 0 on success, non-zero on failure
   * @throws IOException
   */
public int refreshServiceAcl() throws IOException {
    // 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, ""));
    DistributedFileSystem dfs = getDFS();
    URI dfsUri = dfs.getUri();
    boolean isHaEnabled = HAUtilClient.isLogicalUri(conf, dfsUri);
    if (isHaEnabled) {
        // Run refreshServiceAcl for all NNs if HA is enabled
        String nsId = dfsUri.getHost();
        List<ProxyAndInfo<RefreshAuthorizationPolicyProtocol>> proxies = HAUtil.getProxiesForAllNameNodesInNameservice(conf, nsId, RefreshAuthorizationPolicyProtocol.class);
        for (ProxyAndInfo<RefreshAuthorizationPolicyProtocol> proxy : proxies) {
            proxy.getProxy().refreshServiceAcl();
            System.out.println("Refresh service acl successful for " + proxy.getAddress());
        }
    } else {
        // Create the client
        RefreshAuthorizationPolicyProtocol refreshProtocol = NameNodeProxies.createProxy(conf, FileSystem.getDefaultUri(conf), RefreshAuthorizationPolicyProtocol.class).getProxy();
        // Refresh the authorization policy in-effect
        refreshProtocol.refreshServiceAcl();
        System.out.println("Refresh service acl successful");
    }
    return 0;
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) ProxyAndInfo(org.apache.hadoop.hdfs.NameNodeProxiesClient.ProxyAndInfo) RefreshAuthorizationPolicyProtocol(org.apache.hadoop.security.authorize.RefreshAuthorizationPolicyProtocol) DistributedFileSystem(org.apache.hadoop.hdfs.DistributedFileSystem) URI(java.net.URI)

Aggregations

URI (java.net.URI)1 Configuration (org.apache.hadoop.conf.Configuration)1 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)1 HdfsConfiguration (org.apache.hadoop.hdfs.HdfsConfiguration)1 ProxyAndInfo (org.apache.hadoop.hdfs.NameNodeProxiesClient.ProxyAndInfo)1 RefreshAuthorizationPolicyProtocol (org.apache.hadoop.security.authorize.RefreshAuthorizationPolicyProtocol)1