Example usage for org.apache.hadoop.hdfs.server.namenode NameNode getNamesystem

List of usage examples for org.apache.hadoop.hdfs.server.namenode NameNode getNamesystem

Introduction

In this page you can find the example usage for org.apache.hadoop.hdfs.server.namenode NameNode getNamesystem.

Prototype

public FSNamesystem getNamesystem() 

Source Link

Document

Return the FSNamesystem object.

Usage

From source file:backup.namenode.NameNodeBackupServicePlugin.java

License:Apache License

@Override
public void start(Object service) {
    UserGroupInformation ugi;//from ww w  .  j  a v  a2  s  .c o  m
    try {
        ugi = UserGroupInformation.getCurrentUser();
        LOG.info("Starting NameNodeBackupServicePlugin with ugi {}", ugi);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    Configuration conf = getConf();
    NameNode namenode = (NameNode) service;
    BlockManager blockManager = namenode.getNamesystem().getBlockManager();
    // This object is created here so that it's lifecycle follows the namenode
    try {
        restoreProcessor = SingletonManager.getManager(NameNodeRestoreProcessor.class).getInstance(namenode,
                () -> new NameNodeRestoreProcessor(getConf(), namenode, ugi));
        LOG.info("NameNode Backup plugin setup using UGI {}", ugi);

        NameNodeBackupRPCImpl backupRPCImpl = new NameNodeBackupRPCImpl(blockManager);

        InetSocketAddress listenerAddress = namenode.getServiceRpcAddress();
        int ipcPort = listenerAddress.getPort();
        String bindAddress = listenerAddress.getAddress().getHostAddress();
        int port = conf.getInt(DFS_BACKUP_NAMENODE_RPC_PORT_KEY, DFS_BACKUP_NAMENODE_RPC_PORT_DEFAULT);
        if (port == 0) {
            port = ipcPort + 1;
        }
        server = new RPC.Builder(conf).setBindAddress(bindAddress).setPort(port).setInstance(backupRPCImpl)
                .setProtocol(NameNodeBackupRPC.class).build();
        ServiceAuthorizationManager serviceAuthorizationManager = server.getServiceAuthorizationManager();
        serviceAuthorizationManager.refresh(conf, new BackupPolicyProvider());
        server.start();

        LOG.info("NameNode Backup RPC listening on {}", port);

        int httpPort = getConf().getInt(DFS_BACKUP_NAMENODE_HTTP_PORT_KEY,
                DFS_BACKUP_NAMENODE_HTTP_PORT_DEFAULT);
        if (httpPort != 0) {
            ClassLoader classLoader = getClassLoader();
            if (classLoader != null) {
                ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
                try {
                    BackupWebService<Stats> stats = getBackupWebService(ugi, blockManager, restoreProcessor);

                    // Have to setup classloader in thread context to get the static
                    // files in the http server tp be setup correctly.
                    Thread.currentThread().setContextClassLoader(classLoader);
                    Class<?> backupStatusServerClass = classLoader.loadClass(BACKUP_WEB_BACKUP_WEB_SERVER);

                    Object server = DuckTypeUtil.newInstance(backupStatusServerClass,
                            new Class[] { Integer.TYPE, BackupWebService.class },
                            new Object[] { httpPort, stats });
                    httpServer = DuckTypeUtil.wrap(HttpServer.class, server);
                    httpServer.start();
                    LOG.info("NameNode Backup HTTP listening on {}", httpPort);
                } finally {
                    Thread.currentThread().setContextClassLoader(contextClassLoader);
                }
            } else {
                LOG.info("NameNode Backup HTTP classes not found.");
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:backup.namenode.NameNodeRestoreProcessor.java

License:Apache License

public NameNodeRestoreProcessor(Configuration conf, NameNode namenode, UserGroupInformation ugi)
        throws Exception {
    this.ugi = ugi;
    this.conf = conf;
    this.namesystem = namenode.getNamesystem();
    this.blockManager = namesystem.getBlockManager();
    Cache<ExtendedBlock, Boolean> cache = CacheBuilder.newBuilder().expireAfterWrite(10, TimeUnit.MINUTES)
            .build();/*ww w .j ava 2 s  . c om*/
    currentRequestedRestore = Collections.newSetFromMap(cache.asMap());
    pollTime = conf.getLong(DFS_BACKUP_NAMENODE_MISSING_BLOCKS_POLL_TIME_KEY,
            DFS_BACKUP_NAMENODE_MISSING_BLOCKS_POLL_TIME_DEFAULT);
    blockCheck = new NameNodeBackupBlockCheckProcessor(conf, this, namenode, ugi);
    start();
}

From source file:com.mellanox.r4h.MiniDFSCluster.java

License:Apache License

/**
 * Returns true if the NameNode is running and is out of Safe Mode
 * or if waiting for safe mode is disabled.
 *//*w  w w  .  j  a  va2  s  .  com*/
public boolean isNameNodeUp(int nnIndex) {
    NameNode nameNode = nameNodes[nnIndex].nameNode;
    if (nameNode == null) {
        return false;
    }
    long[] sizes;
    sizes = NameNodeAdapter.getStats(nameNode.getNamesystem());
    boolean isUp = false;
    synchronized (this) {
        isUp = ((!nameNode.isInSafeMode() || !waitSafeMode)
                && sizes[ClientProtocol.GET_STATS_CAPACITY_IDX] != 0);
    }
    return isUp;
}

From source file:io.hops.TestUtil.java

License:Apache License

/**
 * Get the inodeId for a file./*from   w w  w .  j  a v a 2  s.c  o  m*/
 *
 * @param nameNode the NameNode
 * @param path the path to the file
 * @return the inodeId
 * @throws IOException
 */
public static int getINodeId(final NameNode nameNode, final Path path) throws IOException {
    final String filePath = path.toUri().getPath();
    return (Integer) new HopsTransactionalRequestHandler(HDFSOperationType.TEST) {
        @Override
        public void acquireLock(TransactionLocks locks) throws IOException {
            LockFactory lf = LockFactory.getInstance();
            locks.add(lf.getINodeLock(nameNode, TransactionLockTypes.INodeLockType.READ_COMMITTED,
                    TransactionLockTypes.INodeResolveType.PATH, filePath));
        }

        @Override
        public Object performTask() throws IOException {
            INode targetNode = nameNode.getNamesystem().getINode(filePath);
            return targetNode.getId();
        }
    }.handle();
}

From source file:org.apache.hawq.pxf.service.utilities.SecuredHDFS.java

License:Apache License

/**
 * The function will verify the token with NameNode if available and will
 * create a UserGroupInformation.//ww  w  . j av  a  2 s  .  c o  m
 *
 * Code in this function is copied from JspHelper.getTokenUGI
 *
 * @param identifier Delegation token identifier
 * @param password Delegation token password
 * @param kind the kind of token
 * @param service the service for this token
 * @param servletContext Jetty servlet context which contains the NN address
 *
 * @throws SecurityException Thrown when authentication fails
 */
private static void verifyToken(byte[] identifier, byte[] password, Text kind, Text service,
        ServletContext servletContext) {
    try {
        Token<DelegationTokenIdentifier> token = new Token<DelegationTokenIdentifier>(identifier, password,
                kind, service);

        ByteArrayInputStream buf = new ByteArrayInputStream(token.getIdentifier());
        DataInputStream in = new DataInputStream(buf);
        DelegationTokenIdentifier id = new DelegationTokenIdentifier();
        id.readFields(in);

        final NameNode nn = NameNodeHttpServer.getNameNodeFromContext(servletContext);
        if (nn != null) {
            nn.getNamesystem().verifyToken(id, token.getPassword());
        }

        UserGroupInformation userGroupInformation = id.getUser();
        userGroupInformation.addToken(token);
        LOG.debug("user " + userGroupInformation.getUserName() + " (" + userGroupInformation.getShortUserName()
                + ") authenticated");

        // re-login if necessary
        userGroupInformation.checkTGTAndReloginFromKeytab();
    } catch (IOException e) {
        throw new SecurityException("Failed to verify delegation token " + e, e);
    }
}