org.apache.zookeeper.server.ByteBufferInputStream Java Examples

The following examples show how to use org.apache.zookeeper.server.ByteBufferInputStream. 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: PackageStoreAPI.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void validate(List<String> sigs,
                      ByteBuffer buf) throws SolrException, IOException {
  Map<String, byte[]> keys = packageStore.getKeys();
  if (keys == null || keys.isEmpty()) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
        "package store does not have any keys");
  }
  CryptoKeys cryptoKeys = null;
  try {
    cryptoKeys = new CryptoKeys(keys);
  } catch (Exception e) {
    throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
        "Error parsing public keys in Package store");
  }
  for (String sig : sigs) {
    if (cryptoKeys.verify(sig, buf) == null) {
      throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Signature does not match any public key : " + sig +" len: "+buf.limit()+  " content sha512: "+
          DigestUtils.sha512Hex(new ByteBufferInputStream(buf)));
    }

  }
}
 
Example #2
Source File: TestDistribPackageStore.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public static void waitForAllNodesHaveFile(MiniSolrCloudCluster cluster, String path, Map expected , boolean verifyContent) throws Exception {
  for (JettySolrRunner jettySolrRunner : cluster.getJettySolrRunners()) {
    String baseUrl = jettySolrRunner.getBaseUrl().toString().replace("/solr", "/api");
    String url = baseUrl + "/node/files" + path + "?wt=javabin&meta=true";
    assertResponseValues(10, new Fetcher(url, jettySolrRunner), expected);

    if(verifyContent) {
      try (HttpSolrClient solrClient = (HttpSolrClient) jettySolrRunner.newClient()) {
        ByteBuffer buf = Utils.executeGET(solrClient.getHttpClient(), baseUrl + "/node/files" + path,
            Utils.newBytesConsumer(Integer.MAX_VALUE));
        assertEquals(
            "d01b51de67ae1680a84a813983b1de3b592fc32f1a22b662fc9057da5953abd1b72476388ba342cad21671cd0b805503c78ab9075ff2f3951fdf75fa16981420",
            DigestUtils.sha512Hex(new ByteBufferInputStream(buf))
        );

      }
    }

  }
}
 
Example #3
Source File: ColumnSerializationUtil.java    From SpinalTap with Apache License 2.0 5 votes vote down vote up
/**
 * mapping between column type to java type BIT => BitSet ENUM, YEAR TINY, SHORT, INT24, LONG =>
 * int SET, LONGLONG => long FLOAT => float DOUBLE => value NEWDECIMAL => BigDecimal DATE => Date
 * TIME, TIME_V2 => Time TIMESTAMP, TIMESTAMP_V2 => Timestmap DATETIME, DATETIME_V2 => Date case
 * YEAR: STRING, VARCHAR, VAR_STRING => String BLOB => byte[]
 */
public static Serializable deserializeColumn(
    @NonNull final Map<String, ByteBuffer> entity, @NonNull final String column) {
  final ByteBuffer byteBuffer = entity.get(column);

  if (byteBuffer == null) {
    return null;
  }

  final ByteBufferInputStream inputStream = new ByteBufferInputStream(byteBuffer);
  return (Serializable) SerializationUtils.deserialize(inputStream);
}
 
Example #4
Source File: Utils.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public static InputStream toJavabin(Object o) throws IOException {
  try (final JavaBinCodec jbc = new JavaBinCodec()) {
    BinaryRequestWriter.BAOS baos = new BinaryRequestWriter.BAOS();
    jbc.marshal(o, baos);
    return new ByteBufferInputStream(ByteBuffer.wrap(baos.getbuf(), 0, baos.size()));
  }
}
 
Example #5
Source File: PackageStoreAPI.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a JSON string with the metadata
 * @lucene.internal
 */
public static MetaData _createJsonMetaData(ByteBuffer buf, List<String> signatures) throws IOException {
  String sha512 = DigestUtils.sha512Hex(new ByteBufferInputStream(buf));
  Map<String, Object> vals = new HashMap<>();
  vals.put(MetaData.SHA512, sha512);
  if (signatures != null) {
    vals.put("sig", signatures);
  }
  return new MetaData(vals);
}
 
Example #6
Source File: ChaosMonkeyCnxnFactory.java    From xian with Apache License 2.0 4 votes vote down vote up
@Override
public void submitRequest(Request si)
{
    long remaining = firstError != 0 ? LOCKOUT_DURATION_MS - (System.currentTimeMillis() - firstError) : 0;
    if ( si.type != ZooDefs.OpCode.createSession && si.type != ZooDefs.OpCode.sync && si.type != ZooDefs.OpCode.ping
        && firstError != 0 && remaining > 0 )
    {
        log.debug("Rejected : " + si.toString());
        // Still reject request
        log.debug("Still not ready for " + remaining + "ms");
        ((NIOServerCnxn)si.cnxn).close();
        return;
    }
    // Submit the request to the legacy Zookeeper server
    log.debug("Applied : " + si.toString());
    super.submitRequest(si);
    // Raise an error if a lock is created
    if ( si.type == ZooDefs.OpCode.create )
    {
        CreateRequest createRequest = new CreateRequest();
        try
        {
            ByteBuffer duplicate = si.request.duplicate();
            duplicate.rewind();
            ByteBufferInputStream.byteBuffer2Record(duplicate, createRequest);
            if ( createRequest.getPath().startsWith(CHAOS_ZNODE_PREFIX)
                && firstError == 0 )
            {
                firstError = System.currentTimeMillis();
                // The znode has been created, close the connection and don't tell it to client
                log.warn("Closing connection right after " + createRequest.getPath() + " creation");
                ((NIOServerCnxn)si.cnxn).close();
            }
        }
        catch ( Exception e )
        {
            // Should not happen
            ((NIOServerCnxn)si.cnxn).close();
        }
    }
}
 
Example #7
Source File: PackageStore.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public InputStream getInputStream() {
  if (buf != null) return new ByteBufferInputStream(buf);
  return null;

}
 
Example #8
Source File: ZookeeperInfoHandler.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public InputStream getStream() throws IOException {
  return new ByteBufferInputStream(baos.getByteBuffer());
}
 
Example #9
Source File: BlobRepository.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public BlobContent(String key, ByteBuffer buffer, Decoder<T> decoder) {
  this.key = key;
  this.content = decoder == null ? (T) buffer : decoder.decode(new ByteBufferInputStream(buffer));
}
 
Example #10
Source File: ChaosMonkeyCnxnFactory.java    From curator with Apache License 2.0 4 votes vote down vote up
@Override
public void submitRequest(Request si)
{
    long remaining = firstError != 0 ? LOCKOUT_DURATION_MS - (System.currentTimeMillis() - firstError) : 0;
    if ( si.type != ZooDefs.OpCode.createSession && si.type != ZooDefs.OpCode.sync && si.type != ZooDefs.OpCode.ping
        && firstError != 0 && remaining > 0 )
    {
        log.debug("Rejected : " + si.toString());
        // Still reject request
        log.debug("Still not ready for " + remaining + "ms");
        Compatibility.serverCnxnClose(si.cnxn);
        return;
    }
    // Submit the request to the legacy Zookeeper server
    log.debug("Applied : " + si.toString());
    super.submitRequest(si);
    // Raise an error if a lock is created
    if ( (si.type == ZooDefs.OpCode.create) || (si.type == ZooDefs.OpCode.create2) )
    {
        CreateRequest createRequest = new CreateRequest();
        try
        {
            ByteBuffer duplicate = si.request.duplicate();
            duplicate.rewind();
            ByteBufferInputStream.byteBuffer2Record(duplicate, createRequest);
            if ( createRequest.getPath().startsWith(CHAOS_ZNODE_PREFIX)
                && firstError == 0 )
            {
                firstError = System.currentTimeMillis();
                // The znode has been created, close the connection and don't tell it to client
                log.warn("Closing connection right after " + createRequest.getPath() + " creation");
                Compatibility.serverCnxnClose(si.cnxn);
            }
        }
        catch ( Exception e )
        {
            // Should not happen
            Compatibility.serverCnxnClose(si.cnxn);
        }
    }
}