类org.apache.hadoop.hbase.util.Writables源码实例Demo

下面列出了怎么用org.apache.hadoop.hbase.util.Writables的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: hbase   文件: ZKSecretWatcher.java
@Override
public void nodeDataChanged(String path) {
  if (keysParentZNode.equals(ZKUtil.getParent(path))) {
    try {
      byte[] data = ZKUtil.getDataAndWatch(watcher, path);
      if (data == null || data.length == 0) {
        LOG.debug("Ignoring empty node "+path);
        return;
      }

      AuthenticationKey key = (AuthenticationKey)Writables.getWritable(data,
          new AuthenticationKey());
      secretManager.addKey(key);
    } catch (KeeperException ke) {
      LOG.error(HBaseMarkers.FATAL, "Error reading data from zookeeper", ke);
      watcher.abort("Error reading updated key znode "+path, ke);
    } catch (IOException ioe) {
      LOG.error(HBaseMarkers.FATAL, "Error reading key writables", ioe);
      watcher.abort("Error reading key writables from znode "+path, ioe);
    }
  }
}
 
源代码2 项目: hbase   文件: ZKSecretWatcher.java
private void refreshNodes(List<ZKUtil.NodeAndData> nodes) {
  for (ZKUtil.NodeAndData n : nodes) {
    String path = n.getNode();
    String keyId = ZKUtil.getNodeName(path);
    try {
      byte[] data = n.getData();
      if (data == null || data.length == 0) {
        LOG.debug("Ignoring empty node "+path);
        continue;
      }
      AuthenticationKey key = (AuthenticationKey)Writables.getWritable(
          data, new AuthenticationKey());
      secretManager.addKey(key);
    } catch (IOException ioe) {
      LOG.error(HBaseMarkers.FATAL, "Failed reading new secret key for id '" +
          keyId + "' from zk", ioe);
      watcher.abort("Error deserializing key from znode "+path, ioe);
    }
  }
}
 
源代码3 项目: hbase   文件: ZKSecretWatcher.java
public void addKeyToZK(AuthenticationKey key) {
  String keyZNode = getKeyNode(key.getKeyId());
  try {
    byte[] keyData = Writables.getBytes(key);
    // TODO: is there any point in retrying beyond what ZK client does?
    ZKUtil.createSetData(watcher, keyZNode, keyData);
  } catch (KeeperException ke) {
    LOG.error(HBaseMarkers.FATAL, "Unable to synchronize master key "+key.getKeyId()+
        " to znode "+keyZNode, ke);
    watcher.abort("Unable to synchronize secret key "+
        key.getKeyId()+" in zookeeper", ke);
  } catch (IOException ioe) {
    // this can only happen from an error serializing the key
    watcher.abort("Failed serializing key "+key.getKeyId(), ioe);
  }
}
 
源代码4 项目: hbase   文件: ZKSecretWatcher.java
public void updateKeyInZK(AuthenticationKey key) {
  String keyZNode = getKeyNode(key.getKeyId());
  try {
    byte[] keyData = Writables.getBytes(key);
    try {
      ZKUtil.updateExistingNodeData(watcher, keyZNode, keyData, -1);
    } catch (KeeperException.NoNodeException ne) {
      // node was somehow removed, try adding it back
      ZKUtil.createSetData(watcher, keyZNode, keyData);
    }
  } catch (KeeperException ke) {
    LOG.error(HBaseMarkers.FATAL, "Unable to update master key "+key.getKeyId()+
        " in znode "+keyZNode);
    watcher.abort("Unable to synchronize secret key "+
        key.getKeyId()+" in zookeeper", ke);
  } catch (IOException ioe) {
    // this can only happen from an error serializing the key
    watcher.abort("Failed serializing key "+key.getKeyId(), ioe);
  }
}
 
源代码5 项目: spliceengine   文件: ProxiedFilesystem.java
@Override
public FileStatus getFileStatus(Path f) throws IOException {
    try {
        try (PreparedStatement statement = connection.prepareStatement("call SYSCS_UTIL.SYSCS_hdfs_OPERATION(?, ?)")) {
            statement.setString(1, f.toUri().getPath());
            statement.setString(2, "status");
            try (ResultSet rs = statement.executeQuery()) {
                if (!rs.next()) {
                    throw new IOException("No results for getFileStatus");
                }
                Blob blob = rs.getBlob(1);
                byte[] bytes = blob.getBytes(1, (int) blob.length());
                FileStatus status = new FileStatus();
                Writables.copyWritable(bytes, status);
                return status;
            }
        }
    } catch (SQLException e) {
        throw new IOException(e);
    }
}
 
源代码6 项目: hbase-tools   文件: CommandAdapter.java
@SuppressWarnings("UnusedParameters")
public static NavigableMap<HRegionInfo, ServerName> regionServerMap(Args args, Configuration conf, HConnection connection, final Set<String> tableNames, final boolean offlined) throws IOException {
    long timestamp = System.currentTimeMillis();

    final NavigableMap<HRegionInfo, ServerName> regions = new TreeMap<>();
    if (tableNames.size() == 1) {
        return regionServerMap(args, conf, connection, tableNames.toArray(new String[1])[0], offlined);
    } else if (tableNames.size() > 1) {
        MetaScanner.BlockingMetaScannerVisitor visitor = new MetaScanner.BlockingMetaScannerVisitor(conf) {
            @Override
            public boolean processRowInternal(Result rowResult) throws IOException {
                HRegionInfo info = Writables.getHRegionInfo(rowResult.getValue(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER));
                byte[] value = rowResult.getValue(HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER);
                String hostAndPort = null;
                if (value != null && value.length > 0) {
                    hostAndPort = Bytes.toString(value);
                }
                value = rowResult.getValue(HConstants.CATALOG_FAMILY, HConstants.STARTCODE_QUALIFIER);
                long startcode = -1L;
                if (value != null && value.length > 0) startcode = Bytes.toLong(value);
                if (!(info.isOffline() || info.isSplit())) {
                    ServerName sn = null;
                    if (hostAndPort != null && hostAndPort.length() > 0) {
                        sn = new ServerName(hostAndPort, startcode);
                    }
                    if (info.isOffline() && !offlined) return true;

                    String tableName = info.getTableNameAsString();
                    if (tableNames.contains(tableName))
                        regions.put(info, sn);
                }
                return true;
            }
        };
        MetaScanner.metaScan(conf, visitor);
    }

    Util.printVerboseMessage(args, "CommandAdapter.regionServerMap", timestamp);
    return regions;
}
 
源代码7 项目: hbase-tools   文件: CommandAdapter.java
@SuppressWarnings("UnusedParameters")
private static NavigableMap<HRegionInfo, ServerName> regionServerMap(Args args, Configuration conf, HConnection connection, final String tableName, final boolean offlined) throws IOException {
    long timestamp = System.currentTimeMillis();

    final NavigableMap<HRegionInfo, ServerName> regions = new TreeMap<>();
    MetaScanner.MetaScannerVisitor visitor = new MetaScanner.TableMetaScannerVisitor(conf, tableName.getBytes()) {
        @Override
        public boolean processRowInternal(Result rowResult) throws IOException {
            HRegionInfo info = Writables.getHRegionInfo(rowResult.getValue(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER));
            byte[] value = rowResult.getValue(HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER);
            String hostAndPort = null;
            if (value != null && value.length > 0) {
                hostAndPort = Bytes.toString(value);
            }
            value = rowResult.getValue(HConstants.CATALOG_FAMILY, HConstants.STARTCODE_QUALIFIER);
            long startcode = -1L;
            if (value != null && value.length > 0) startcode = Bytes.toLong(value);
            if (!(info.isOffline() || info.isSplit())) {
                ServerName sn = null;
                if (hostAndPort != null && hostAndPort.length() > 0) {
                    sn = new ServerName(hostAndPort, startcode);
                }
                if (info.isOffline() && !offlined) return true;
                regions.put(info, sn);
            }
            return true;
        }
    };
    MetaScanner.metaScan(conf, visitor, tableName.getBytes());

    Util.printVerboseMessage(args, "CommandAdapter.regionServerMap", timestamp);
    return regions;
}
 
public static SingleCQKeyValueComparisonFilter parseFrom(final byte [] pbBytes) throws DeserializationException {
    try {
        return (SingleCQKeyValueComparisonFilter)Writables.getWritable(pbBytes, new SingleCQKeyValueComparisonFilter());
    } catch (IOException e) {
        throw new DeserializationException(e);
    }
}
 
源代码9 项目: phoenix   文件: ColumnProjectionFilter.java
public static ColumnProjectionFilter parseFrom(final byte [] pbBytes) throws DeserializationException {
    try {
        return (ColumnProjectionFilter)Writables.getWritable(pbBytes, new ColumnProjectionFilter());
    } catch (IOException e) {
        throw new DeserializationException(e);
    }
}
 
源代码10 项目: phoenix   文件: MultiCQKeyValueComparisonFilter.java
public static MultiCQKeyValueComparisonFilter parseFrom(final byte [] pbBytes) throws DeserializationException {
    try {
        return (MultiCQKeyValueComparisonFilter)Writables.getWritable(pbBytes, new MultiCQKeyValueComparisonFilter());
    } catch (IOException e) {
        throw new DeserializationException(e);
    }
}
 
public static MultiCFCQKeyValueComparisonFilter parseFrom(final byte [] pbBytes) throws DeserializationException {
    try {
        return (MultiCFCQKeyValueComparisonFilter)Writables.getWritable(pbBytes, new MultiCFCQKeyValueComparisonFilter());
    } catch (IOException e) {
        throw new DeserializationException(e);
    }
}
 
源代码12 项目: phoenix   文件: RowKeyComparisonFilter.java
public static RowKeyComparisonFilter parseFrom(final byte [] pbBytes) throws DeserializationException {
    try {
        return (RowKeyComparisonFilter)Writables.getWritable(pbBytes, new RowKeyComparisonFilter());
    } catch (IOException e) {
        throw new DeserializationException(e);
    }
}
 
public static SingleCFCQKeyValueComparisonFilter parseFrom(final byte [] pbBytes) throws DeserializationException {
    try {
        return (SingleCFCQKeyValueComparisonFilter)Writables.getWritable(pbBytes, new SingleCFCQKeyValueComparisonFilter());
    } catch (IOException e) {
        throw new DeserializationException(e);
    }
}
 
源代码14 项目: phoenix   文件: SkipScanFilter.java
public static SkipScanFilter parseFrom(final byte [] pbBytes) throws DeserializationException {
    try {
        return (SkipScanFilter)Writables.getWritable(pbBytes, new SkipScanFilter());
    } catch (IOException e) {
        throw new DeserializationException(e);
    }
}
 
源代码15 项目: hbase   文件: TestTokenAuthentication.java
@Test
public void testTokenCreation() throws Exception {
  Token<AuthenticationTokenIdentifier> token =
      secretManager.generateToken("testuser");

  AuthenticationTokenIdentifier ident = new AuthenticationTokenIdentifier();
  Writables.getWritable(token.getIdentifier(), ident);
  assertEquals("Token username should match", "testuser",
      ident.getUsername());
  byte[] passwd = secretManager.retrievePassword(ident);
  assertTrue("Token password and password from secret manager should match",
      Bytes.equals(token.getPassword(), passwd));
}
 
源代码16 项目: phoenix   文件: SingleCQKeyValueComparisonFilter.java
public static SingleCQKeyValueComparisonFilter parseFrom(final byte [] pbBytes) throws DeserializationException {
    try {
        SingleCQKeyValueComparisonFilter writable = (SingleCQKeyValueComparisonFilter)Writables.getWritable(pbBytes, new SingleCQKeyValueComparisonFilter());
        return writable;
    } catch (IOException e) {
        throw new DeserializationException(e);
    }
}
 
public static MultiEncodedCQKeyValueComparisonFilter parseFrom(final byte [] pbBytes) throws DeserializationException {
    try {
        return (MultiEncodedCQKeyValueComparisonFilter)Writables.getWritable(pbBytes, new MultiEncodedCQKeyValueComparisonFilter());
    } catch (IOException e) {
        throw new DeserializationException(e);
    }
}
 
源代码18 项目: phoenix   文件: ColumnProjectionFilter.java
public static ColumnProjectionFilter parseFrom(final byte [] pbBytes) throws DeserializationException {
    try {
        return (ColumnProjectionFilter)Writables.getWritable(pbBytes, new ColumnProjectionFilter());
    } catch (IOException e) {
        throw new DeserializationException(e);
    }
}
 
源代码19 项目: phoenix   文件: MultiCQKeyValueComparisonFilter.java
public static MultiCQKeyValueComparisonFilter parseFrom(final byte [] pbBytes) throws DeserializationException {
    try {
        return (MultiCQKeyValueComparisonFilter)Writables.getWritable(pbBytes, new MultiCQKeyValueComparisonFilter());
    } catch (IOException e) {
        throw new DeserializationException(e);
    }
}
 
public static MultiCFCQKeyValueComparisonFilter parseFrom(final byte [] pbBytes) throws DeserializationException {
    try {
        return (MultiCFCQKeyValueComparisonFilter)Writables.getWritable(pbBytes, new MultiCFCQKeyValueComparisonFilter());
    } catch (IOException e) {
        throw new DeserializationException(e);
    }
}
 
源代码21 项目: phoenix   文件: RowKeyComparisonFilter.java
public static RowKeyComparisonFilter parseFrom(final byte [] pbBytes) throws DeserializationException {
    try {
        return (RowKeyComparisonFilter)Writables.getWritable(pbBytes, new RowKeyComparisonFilter());
    } catch (IOException e) {
        throw new DeserializationException(e);
    }
}
 
public static SingleCFCQKeyValueComparisonFilter parseFrom(final byte [] pbBytes) throws DeserializationException {
    try {
        return (SingleCFCQKeyValueComparisonFilter)Writables.getWritable(pbBytes, new SingleCFCQKeyValueComparisonFilter());
    } catch (IOException e) {
        throw new DeserializationException(e);
    }
}
 
public static EncodedQualifiersColumnProjectionFilter parseFrom(final byte [] pbBytes) throws DeserializationException {
    try {
        return (EncodedQualifiersColumnProjectionFilter)Writables.getWritable(pbBytes, new EncodedQualifiersColumnProjectionFilter());
    } catch (IOException e) {
        throw new DeserializationException(e);
    }
}
 
源代码24 项目: phoenix   文件: SkipScanFilter.java
public static SkipScanFilter parseFrom(final byte [] pbBytes) throws DeserializationException {
    try {
        return (SkipScanFilter)Writables.getWritable(pbBytes, new SkipScanFilter());
    } catch (IOException e) {
        throw new DeserializationException(e);
    }
}
 
源代码25 项目: phoenix   文件: DistinctPrefixFilter.java
public static DistinctPrefixFilter parseFrom(final byte[] pbBytes)
        throws DeserializationException {
    try {
        return (DistinctPrefixFilter) Writables.getWritable(pbBytes,
                new DistinctPrefixFilter());
    } catch (IOException e) {
        throw new DeserializationException(e);
    }
}
 
源代码26 项目: phoenix   文件: ColumnProjectionFilter.java
@Override
public byte[] toByteArray() throws IOException {
    return Writables.getBytes(this);
}
 
源代码27 项目: phoenix   文件: BooleanExpressionFilter.java
@Override
public byte[] toByteArray() throws IOException {
    return Writables.getBytes(this);
}
 
源代码28 项目: phoenix   文件: SkipScanFilter.java
@Override
public byte[] toByteArray() throws IOException {
    return Writables.getBytes(this);
}
 
源代码29 项目: phoenix   文件: ColumnProjectionFilter.java
@Override
public byte[] toByteArray() throws IOException {
    return Writables.getBytes(this);
}
 
源代码30 项目: phoenix   文件: BooleanExpressionFilter.java
@Override
public byte[] toByteArray() throws IOException {
    return Writables.getBytes(this);
}
 
 类所在包
 同包方法