class DatanodeWebHdfsMethods {

  @VisibleForTesting
  Token<DelegationTokenIdentifier> deserializeToken
          (String delegation,String nnId) throws IOException {
    final DataNode datanode = (DataNode) context.getAttribute("datanode");
    final Configuration conf = datanode.getConf();
    final Token<DelegationTokenIdentifier> token = new
            Token<DelegationTokenIdentifier>();
    token.decodeFromUrlString(delegation);
    URI nnUri = URI.create(HdfsConstants.HDFS_URI_SCHEME +
            "://" + nnId);
    boolean isHA = HAUtil.isLogicalUri(conf, nnUri);
    if (isHA) {
      token.setService(HAUtil.buildTokenServiceForLogicalUri(nnUri));
    } else {
      token.setService(SecurityUtil.buildTokenService(nnUri));
    }
    token.setKind(DelegationTokenIdentifier.HDFS_DELEGATION_KIND);
    return token;
  }

}