Java Code Examples for org.apache.hadoop.util.Time#formatTime()

The following examples show how to use org.apache.hadoop.util.Time#formatTime() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RandomKeyGenerator.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
private FreonJobInfo() {
  this.status = exception != null ? "Failed" : "Success";
  this.numOfVolumes = RandomKeyGenerator.this.numOfVolumes;
  this.numOfBuckets = RandomKeyGenerator.this.numOfBuckets;
  this.numOfKeys = RandomKeyGenerator.this.numOfKeys;
  this.numOfThreads = RandomKeyGenerator.this.numOfThreads;
  this.keySize = RandomKeyGenerator.this.keySize;
  this.bufferSize = RandomKeyGenerator.this.bufferSize;
  this.jobStartTime = Time.formatTime(RandomKeyGenerator.this.jobStartTime);
  this.replicationFactor = RandomKeyGenerator.this.factor.name();
  this.replicationType = RandomKeyGenerator.this.type.name();

  long totalBytes =
      (long) numOfVolumes * numOfBuckets * numOfKeys * keySize;
  this.dataWritten = getInStorageUnits((double) totalBytes);
  this.totalThroughputPerSecond = getInStorageUnits(
      (totalBytes * 1.0) / TimeUnit.NANOSECONDS
          .toSeconds(
              RandomKeyGenerator.this.keyWriteTime.get() / threadPoolSize));
}
 
Example 2
Source File: OzoneDelegationTokenSecretManager.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if TokenInfo for the given identifier exists in database and if the
 * token is expired.
 */
private TokenInfo validateToken(OzoneTokenIdentifier identifier)
    throws InvalidToken {
  TokenInfo info = currentTokens.get(identifier);
  if (info == null) {
    throw new InvalidToken("token " + formatTokenId(identifier)
        + " can't be found in cache");
  }
  long now = Time.now();
  if (info.getRenewDate() < now) {
    throw new InvalidToken("token " + formatTokenId(identifier) + " is " +
        "expired, current time: " + Time.formatTime(now) +
        " expected renewal time: " + Time.formatTime(info.getRenewDate()));
  }
  if (!verifySignature(identifier, info.getPassword())) {
    throw new InvalidToken("Tampered/Invalid token.");
  }
  return info;
}
 
Example 3
Source File: OzoneBlockTokenSecretManager.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
/**
 * Find the OzoneBlockTokenInfo for the given token id, and verify that if the
 * token is not expired.
 */
public boolean validateToken(OzoneBlockTokenIdentifier identifier)
    throws InvalidToken {
  long now = Time.now();
  if (identifier.getExpiryDate() < now) {
    throw new InvalidToken("token " + formatTokenId(identifier) + " is " +
        "expired, current time: " + Time.formatTime(now) +
        " expiry time: " + identifier.getExpiryDate());
  }

  if (!verifySignature(identifier, createPassword(identifier))) {
    throw new InvalidToken("Tampered/Invalid token.");
  }
  return true;
}
 
Example 4
Source File: OzoneDelegationTokenSecretManager.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
/**
 * Renew a delegation token.
 *
 * @param token the token to renew
 * @param renewer the full principal name of the user doing the renewal
 * @return the new expiration time
 * @throws InvalidToken if the token is invalid
 * @throws AccessControlException if the user can't renew token
 */
@Override
public synchronized long renewToken(Token<OzoneTokenIdentifier> token,
    String renewer) throws IOException {
  ByteArrayInputStream buf = new ByteArrayInputStream(token.getIdentifier());
  DataInputStream in = new DataInputStream(buf);
  OzoneTokenIdentifier id = OzoneTokenIdentifier.readProtoBuf(in);
  if (LOG.isDebugEnabled()) {
    LOG.debug("Token renewal for identifier: {}, total currentTokens: {}",
        formatTokenId(id), currentTokens.size());
  }

  long now = Time.now();
  if (id.getMaxDate() < now) {
    throw new OMException(renewer + " tried to renew an expired token "
        + formatTokenId(id) + " max expiration date: "
        + Time.formatTime(id.getMaxDate())
        + " currentTime: " + Time.formatTime(now), TOKEN_EXPIRED);
  }
  validateToken(id);
  if ((id.getRenewer() == null) || (id.getRenewer().toString().isEmpty())) {
    throw new AccessControlException(renewer +
        " tried to renew a token " + formatTokenId(id)
        + " without a renewer");
  }
  if (!id.getRenewer().toString().equals(renewer)) {
    throw new AccessControlException(renewer
        + " tries to renew a token " + formatTokenId(id)
        + " with non-matching renewer " + id.getRenewer());
  }

  long renewTime = Math.min(id.getMaxDate(), now + getTokenRenewInterval());

  // For HA ratis will take care of updating.
  // This will be removed, when HA/Non-HA code is merged.
  if (!isRatisEnabled) {
    try {
      addToTokenStore(id, token.getPassword(), renewTime);
    } catch (IOException e) {
      LOG.error("Unable to update token " + id.getSequenceNumber(), e);
    }
  }
  return renewTime;
}