private void storeOrUpdateRMDelegationTokenState(
      RMDelegationTokenIdentifier identifier, Long renewDate, boolean isUpdate) throws Exception {
    Path nodeCreatePath =
        getNodePath(
            rmDTSecretManagerRoot, DELEGATION_TOKEN_PREFIX + identifier.getSequenceNumber());
    RMDelegationTokenIdentifierData identifierData =
        new RMDelegationTokenIdentifierData(identifier, renewDate);
    if (isUpdate) {
      LOG.info("Updating RMDelegationToken_" + identifier.getSequenceNumber());
      updateFile(nodeCreatePath, identifierData.toByteArray(), true);
    } else {
      LOG.info("Storing RMDelegationToken_" + identifier.getSequenceNumber());
      writeFileWithRetries(nodeCreatePath, identifierData.toByteArray(), true);

      // store sequence number
      Path latestSequenceNumberPath =
          getNodePath(
              rmDTSecretManagerRoot,
              DELEGATION_TOKEN_SEQUENCE_NUMBER_PREFIX + identifier.getSequenceNumber());
      LOG.info(
          "Storing " + DELEGATION_TOKEN_SEQUENCE_NUMBER_PREFIX + identifier.getSequenceNumber());
      if (dtSequenceNumberPath == null) {
        if (!createFileWithRetries(latestSequenceNumberPath)) {
          throw new Exception("Failed to create " + latestSequenceNumberPath);
        }
      } else {
        if (!renameFileWithRetries(dtSequenceNumberPath, latestSequenceNumberPath)) {
          throw new Exception("Failed to rename " + dtSequenceNumberPath);
        }
      }
      dtSequenceNumberPath = latestSequenceNumberPath;
    }
  }
예제 #2
0
 private void storeOrUpdateRMDT(
     RMDelegationTokenIdentifier tokenId, Long renewDate, boolean isUpdate) throws IOException {
   String tokenKey = getRMDTTokenNodeKey(tokenId);
   RMDelegationTokenIdentifierData tokenData =
       new RMDelegationTokenIdentifierData(tokenId, renewDate);
   if (LOG.isDebugEnabled()) {
     LOG.debug("Storing token to " + tokenKey);
   }
   try {
     WriteBatch batch = db.createWriteBatch();
     try {
       batch.put(bytes(tokenKey), tokenData.toByteArray());
       if (!isUpdate) {
         ByteArrayOutputStream bs = new ByteArrayOutputStream();
         try (DataOutputStream ds = new DataOutputStream(bs)) {
           ds.writeInt(tokenId.getSequenceNumber());
         }
         if (LOG.isDebugEnabled()) {
           LOG.debug(
               "Storing " + tokenId.getSequenceNumber() + " to " + RM_DT_SEQUENCE_NUMBER_KEY);
         }
         batch.put(bytes(RM_DT_SEQUENCE_NUMBER_KEY), bs.toByteArray());
       }
       db.write(batch);
     } finally {
       batch.close();
     }
   } catch (DBException e) {
     throw new IOException(e);
   }
 }