Example usage for org.apache.hadoop.util Time now

List of usage examples for org.apache.hadoop.util Time now

Introduction

In this page you can find the example usage for org.apache.hadoop.util Time now.

Prototype

public static long now() 

Source Link

Document

Current system time.

Usage

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

License:Apache License

@Override
public DataEncryptionKey newDataEncryptionKey() throws IOException {
    if (shouldEncryptData()) {
        synchronized (this) {
            if (encryptionKey == null || encryptionKey.expiryDate < Time.now()) {
                LOG.debug("Getting new encryption token from NN");
                encryptionKey = namenode.getDataEncryptionKey();
            }//  w  ww  .j a v a  2 s  . c om
            return encryptionKey;
        }
    } else {
        return null;
    }
}

From source file:io.hops.experiments.benchmarks.blockreporting.BlockReportingBenchmark.java

License:Apache License

@Override
protected WarmUpCommand.Response warmUp(WarmUpCommand.Request warmUp) throws Exception {
    try {// ww w . ja  v a 2s  .c  o m
        BlockReportingWarmUp.Request request = (BlockReportingWarmUp.Request) warmUp;

        datanodes = new TinyDatanodes(conf, request.getBaseDir(), numThreads, request.getBlocksPerReport(),
                request.getBlocksPerFile(), request.getFilesPerDir(), request.getReplication(),
                request.getMaxBlockSize(), slaveId, request.getDatabaseConnection(), fsName);
        long t = Time.now();
        datanodes.generateInput(request.isSkipCreations(), executor);
        Logger.printMsg("WarmUp done in " + (Time.now() - t) / 1000 + " seconds");

    } catch (Exception e) {
        Logger.error(e);
        throw e;
    }
    return new BlockReportingWarmUp.Response();
}

From source file:io.hops.experiments.benchmarks.blockreporting.BlockReportingBenchmark.java

License:Apache License

@Override
protected BenchmarkCommand.Response processCommandInternal(BenchmarkCommand.Request command)
        throws IOException, InterruptedException {
    BlockReportingBenchmarkCommand.Request request = (BlockReportingBenchmarkCommand.Request) command;

    List workers = Lists.newArrayList();
    for (int dn = 0; dn < numThreads; dn++) {
        workers.add(//  w w w .  j  a v  a2s.co  m
                new Reporter(dn, request.getMinTimeBeforeNextReport(), request.getMaxTimeBeforeNextReport()));
    }

    startTime = Time.now();
    executor.invokeAll(workers, request.getBlockReportBenchMarkDuration(), TimeUnit.MILLISECONDS);
    double speed = currentSpeed();
    datanodes.printStats();

    return new BlockReportingBenchmarkCommand.Response(successfulOps.get(), failedOps.get(), speed,
            brElapsedTimes.getMean(), getNewNameNodeElapsedTime.getMean(), getAliveNNsCount());
}

From source file:io.hops.experiments.benchmarks.blockreporting.BlockReportingBenchmark.java

License:Apache License

double currentSpeed() {
    double timePassed = Time.now() - startTime;
    double opsPerMSec = (double) (successfulOps.get()) / timePassed;
    return DFSOperationsUtils.round(opsPerMSec * 1000);
}

From source file:io.hops.experiments.benchmarks.blockreporting.TinyDatanode.java

License:Apache License

private long[] blockReport(long[] blocksReport) throws Exception {
    long start1 = Time.now();
    DatanodeProtocol nameNodeToReportTo = nameNodeSelector.getNameNodeToReportTo(blocksReport.length);

    long start = Time.now();
    blockReport(nameNodeToReportTo, blocksReport);
    long end = Time.now();
    return new long[] { start - start1, end - start };
}

From source file:io.hops.leaderElection.LeaderElection.java

License:Apache License

public void waitActive() throws InterruptedException {
    long start = -1;
    while (true) {
        Thread.sleep(100);/*  w  ww .  j a  v  a2 s .  co m*/
        if (context.memberShip == null) {
            continue;
        }
        if (context.memberShip.size() >= 1) {
            if (start < 0) {
                start = Time.now();
            }
            // HOPS-626
            if (isLeader()
                    || Time.now() - start > context.time_period * (context.max_missed_hb_threshold + 1)) {
                return;
            }
        }
    }
}

From source file:io.hops.metadata.security.token.block.NameNodeBlockTokenSecretManager.java

License:Apache License

private void generateKeys() throws IOException {
    if (!isMaster) {
        return;/*w  w w. j  ava 2  s.  c om*/
    }
    /*
     * Need to set estimated expiry dates for currentKey and nextKey so that if
     * NN crashes, DN can still expire those keys. NN will stop using the newly
     * generated currentKey after the first keyUpdateInterval, however it may
     * still be used by DN and Balancer to generate new tokens before they get a
     * chance to sync their keys with NN. Since we require keyUpdInterval to be
     * long enough so that all live DN's and Balancer will sync their keys with
     * NN at least once during the period, the estimated expiry date for
     * currentKey is set to now() + 2 * keyUpdateInterval + tokenLifetime.
     * Similarly, the estimated expiry date for nextKey is one keyUpdateInterval
     * more.
     */
    setSerialNo(serialNo + 1);
    currentKey = new BlockKey(serialNo, Time.now() + 2 * keyUpdateInterval + tokenLifetime, generateSecret());
    currentKey.setKeyType(BlockKey.KeyType.CurrKey);
    setSerialNo(serialNo + 1);
    nextKey = new BlockKey(serialNo, Time.now() + 3 * keyUpdateInterval + tokenLifetime, generateSecret());
    nextKey.setKeyType(BlockKey.KeyType.NextKey);
    addBlockKeys();
}

From source file:io.hops.metadata.security.token.block.NameNodeBlockTokenSecretManager.java

License:Apache License

@Override
public DataEncryptionKey generateDataEncryptionKey() throws IOException {
    byte[] nonce = new byte[8];
    nonceGenerator.nextBytes(nonce);/*from  www  .ja va  2 s.c o  m*/
    BlockKey key = getBlockKeyByType(BlockKey.KeyType.CurrKey);

    byte[] encryptionKey = createPassword(nonce, key.getKey());
    return new DataEncryptionKey(key.getKeyId(), blockPoolId, nonce, encryptionKey, Time.now() + tokenLifetime,
            encryptionAlgorithm);
}

From source file:io.hops.metadata.security.token.block.NameNodeBlockTokenSecretManager.java

License:Apache License

@Override
protected byte[] createPassword(BlockTokenIdentifier identifier) {
    BlockKey key;/*from  www  . j a v  a  2  s  .co  m*/
    try {
        key = getBlockKeyByType(BlockKey.KeyType.CurrKey);
    } catch (IOException ex) {
        throw new IllegalStateException("currentKey hasn't been initialized. [" + ex.getMessage() + "]");
    }
    if (key == null) {
        throw new IllegalStateException("currentKey hasn't been initialized.");
    }
    identifier.setExpiryDate(Time.now() + tokenLifetime);
    identifier.setKeyId(key.getKeyId());
    if (LOG.isDebugEnabled()) {
        LOG.debug("Generating block token for " + identifier.toString());
    }
    return createPassword(identifier.getBytes(), key.getKey());
}

From source file:io.hops.metadata.security.token.block.NameNodeBlockTokenSecretManager.java

License:Apache License

private boolean updateBlockKeys() throws IOException {
    return (Boolean) new HopsTransactionalRequestHandler(HDFSOperationType.UPDATE_BLOCK_KEYS) {
        @Override/* w  ww  .  ja  v a2  s.c  o  m*/
        public void acquireLock(TransactionLocks locks) throws IOException {
            LockFactory lf = LockFactory.getInstance();
            locks.add(lf.getVariableLock(Variable.Finder.BlockTokenKeys, LockType.WRITE));
        }

        @Override
        public Object performTask() throws StorageException, IOException {
            Map<Integer, BlockKey> keys = HdfsVariables.getAllBlockTokenKeysByType();
            if (keys.isEmpty()) {
                log.debug("keys is not generated yet to be updated");
                return false;
            }
            // set final expiry date of retiring currentKey
            // also modifying this key to mark it as 'simple key' instead of 'current key'
            BlockKey currentKeyFromDB = keys.get(BlockKey.KeyType.CurrKey.ordinal());
            currentKeyFromDB.setExpiryDate(Time.now() + keyUpdateInterval + tokenLifetime);
            currentKeyFromDB.setKeyType(BlockKey.KeyType.SimpleKey);

            // after above update, we only have a key marked as 'next key'
            // the 'next key' becomes the 'current key'
            // update the estimated expiry date of new currentKey
            BlockKey nextKeyFromDB = keys.get(BlockKey.KeyType.NextKey.ordinal());
            currentKey = new BlockKey(nextKeyFromDB.getKeyId(),
                    Time.now() + 2 * keyUpdateInterval + tokenLifetime, nextKeyFromDB.getKey());
            currentKey.setKeyType(BlockKey.KeyType.CurrKey);

            // generate a new nextKey
            setSerialNo(serialNo + 1);
            nextKey = new BlockKey(serialNo, Time.now() + 3 * keyUpdateInterval + tokenLifetime,
                    generateSecret());
            nextKey.setKeyType(BlockKey.KeyType.NextKey);

            HdfsVariables.updateBlockTokenKeys(currentKey, nextKey, currentKeyFromDB);
            return true;
        }
    }.handle();
}