use of org.apache.beam.vendor.grpc.v1p26p0.com.google.protobuf.ByteString in project bazel by bazelbuild.
the class SingleBuildFileCacheTest method testBasic.
@Test
public void testBasic() throws Exception {
ActionInput empty = ActionInputHelper.fromPath("/empty");
assertEquals(0, underTest.getSizeInBytes(empty));
byte[] digestBytes = underTest.getDigest(empty);
ByteString digest = ByteString.copyFromUtf8(BaseEncoding.base16().lowerCase().encode(digestBytes));
assertEquals(EMPTY_MD5, digest.toStringUtf8());
assertEquals("/empty", underTest.getInputFromDigest(digest).getExecPathString());
assert (underTest.contentsAvailableLocally(digest));
ByteString other = ByteString.copyFrom("f41d8cd98f00b204e9800998ecf8427e", "UTF-16");
assert (!underTest.contentsAvailableLocally(other));
assert (calls.containsKey("/empty"));
}
use of org.apache.beam.vendor.grpc.v1p26p0.com.google.protobuf.ByteString in project pulsar by yahoo.
the class ByteBufCodedInputStream method readBytes.
/** Read a {@code bytes} field value from the stream. */
public ByteString readBytes() throws IOException {
final int size = readRawVarint32();
if (size == 0) {
return ByteString.EMPTY;
} else {
RecyclableHeapByteBuf heapBuf = RecyclableHeapByteBuf.get();
if (size > heapBuf.writableBytes()) {
heapBuf.capacity(size);
}
heapBuf.writeBytes(buf, size);
ByteString res = ByteString.copyFrom(heapBuf.array(), heapBuf.arrayOffset(), heapBuf.readableBytes());
heapBuf.recycle();
return res;
}
}
use of org.apache.beam.vendor.grpc.v1p26p0.com.google.protobuf.ByteString in project aion by aionnetwork.
the class ApiAion0 method createBlockMsg.
private byte[] createBlockMsg(AionBlock blk) {
if (blk == null) {
return ApiUtil.toReturnHeader(getApiVersion(), Message.Retcode.r_fail_function_arguments_VALUE);
} else {
List<ByteString> al = new ArrayList<>();
for (AionTransaction tx : blk.getTransactionsList()) {
al.add(ByteString.copyFrom(tx.getHash()));
}
BigInteger td = this.ac.getBlockchain().getTotalDifficultyByHash(Hash256.wrap(blk.getHash()));
Message.rsp_getBlock rsp = getRsp_getBlock(blk, al, td);
byte[] retHeader = ApiUtil.toReturnHeader(getApiVersion(), Message.Retcode.r_success_VALUE);
return ApiUtil.combineRetMsg(retHeader, rsp.toByteArray());
}
}
use of org.apache.beam.vendor.grpc.v1p26p0.com.google.protobuf.ByteString in project nifi by apache.
the class FlowFileIngestService method send.
/**
* Handle receipt of a FlowFileRequest and route it to the appropriate process relationship.
*
* @param request the flowfile request
* @param responseObserver the mechanism by which to reply to the client
*/
@Override
public void send(final org.apache.nifi.processors.grpc.FlowFileRequest request, final StreamObserver<FlowFileReply> responseObserver) {
final FlowFileReply.Builder replyBuilder = FlowFileReply.newBuilder();
final String remoteHost = FlowFileIngestServiceInterceptor.REMOTE_HOST_KEY.get();
final String remoteDN = FlowFileIngestServiceInterceptor.REMOTE_DN_KEY.get();
// block until we have a session factory (occurs when processor is triggered)
ProcessSessionFactory sessionFactory = null;
while (sessionFactory == null) {
sessionFactory = sessionFactoryReference.get();
if (sessionFactory == null) {
try {
Thread.sleep(10);
} catch (final InterruptedException e) {
}
}
}
final ProcessSession session = sessionFactory.createSession();
// if there's no space available, reject the request.
final long n = filesReceived.getAndIncrement() % FILES_BEFORE_CHECKING_DESTINATION_SPACE;
if (n == 0 || !spaceAvailable.get()) {
if (context.getAvailableRelationships().isEmpty()) {
spaceAvailable.set(false);
final String message = "Received request from " + remoteHost + " but no space available; Indicating Service Unavailable";
if (logger.isDebugEnabled()) {
logger.debug(message);
}
final FlowFileReply reply = replyBuilder.setResponseCode(FlowFileReply.ResponseCode.ERROR).setBody(message).build();
responseObserver.onNext(reply);
responseObserver.onCompleted();
return;
} else {
spaceAvailable.set(true);
}
}
if (logger.isDebugEnabled()) {
logger.debug("Received request from " + remoteHost);
}
final long startNanos = System.nanoTime();
FlowFile flowFile = session.create();
// push the attributes provided onto the created flowfile
final Map<String, String> attributes = Maps.newHashMap();
attributes.putAll(request.getAttributesMap());
String sourceSystemFlowFileIdentifier = attributes.get(CoreAttributes.UUID.key());
if (sourceSystemFlowFileIdentifier != null) {
sourceSystemFlowFileIdentifier = "urn:nifi:" + sourceSystemFlowFileIdentifier;
// If we receveied a UUID, we want to give the FlowFile a new UUID and register the sending system's
// identifier as the SourceSystemFlowFileIdentifier field in the Provenance RECEIVE event
attributes.put(CoreAttributes.UUID.key(), UUID.randomUUID().toString());
}
flowFile = session.putAllAttributes(flowFile, attributes);
final ByteString content = request.getContent();
final InputStream contentStream = content.newInput();
// write the provided content to the flowfile
flowFile = session.write(flowFile, out -> {
try (final BufferedOutputStream bos = new BufferedOutputStream(out, 65536)) {
IOUtils.copy(contentStream, bos);
}
});
final long transferNanos = System.nanoTime() - startNanos;
final long transferMillis = TimeUnit.MILLISECONDS.convert(transferNanos, TimeUnit.NANOSECONDS);
session.getProvenanceReporter().receive(flowFile, SERVICE_NAME, sourceSystemFlowFileIdentifier, "Remote DN=" + remoteDN, transferMillis);
flowFile = session.putAttribute(flowFile, ListenGRPC.REMOTE_HOST, remoteHost);
flowFile = session.putAttribute(flowFile, ListenGRPC.REMOTE_USER_DN, remoteDN);
// register success
session.transfer(flowFile, ListenGRPC.REL_SUCCESS);
session.commit();
// reply to client
final FlowFileReply reply = replyBuilder.setResponseCode(FlowFileReply.ResponseCode.SUCCESS).setBody("FlowFile successfully received.").build();
responseObserver.onNext(reply);
responseObserver.onCompleted();
}
use of org.apache.beam.vendor.grpc.v1p26p0.com.google.protobuf.ByteString in project jetcd by coreos.
the class MaintenanceUnitTest method testWrite.
@Test(timeOut = 1000)
void testWrite() throws IOException {
Snapshot snapshot = maintenanceCli.snapshot();
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteString blob = ByteString.copyFromUtf8("blob");
responseObserverRef.get().onNext(SnapshotResponse.newBuilder().setBlob(blob).setRemainingBytes(0).build());
responseObserverRef.get().onCompleted();
snapshot.write(out);
assertThat(out.toByteArray()).isEqualTo(blob.toByteArray());
}
Aggregations