Search in sources :

Example 21 with ByteString

use of org.apache.beam.vendor.grpc.v1p43p2.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"));
}
Also used : ActionInput(com.google.devtools.build.lib.actions.ActionInput) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 22 with ByteString

use of org.apache.beam.vendor.grpc.v1p43p2.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;
    }
}
Also used : RecyclableHeapByteBuf(com.yahoo.pulsar.common.api.Commands.RecyclableHeapByteBuf) ByteString(com.google.protobuf.ByteString)

Example 23 with ByteString

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString in project BIMserver by opensourceBIM.

the class ProtocolBuffersConverter method convertFieldValue.

private Object convertFieldValue(SField field, Object val) throws ConvertException {
    if (val instanceof EnumValueDescriptor) {
        EnumValueDescriptor enumValueDescriptor = (EnumValueDescriptor) val;
        Class<?> enumClass;
        try {
            enumClass = Class.forName("org.bimserver.interfaces.objects." + enumValueDescriptor.getType().getName());
            for (Object v : enumClass.getEnumConstants()) {
                Enum<?> e = (Enum<?>) v;
                if (e.ordinal() == enumValueDescriptor.getNumber()) {
                    val = e;
                    break;
                }
            }
        } catch (ClassNotFoundException e) {
            LOGGER.error("", e);
        }
        return val;
    } else if (field.getType().getInstanceClass() == Date.class) {
        return new Date((Long) val);
    } else if (field.getType().getInstanceClass() == DataHandler.class) {
        ByteString byteString = (ByteString) val;
        ByteArrayDataSource byteArrayDataSource = new ByteArrayDataSource("test", byteString.toByteArray());
        return new DataHandler(byteArrayDataSource);
    } else if (val instanceof DynamicMessage) {
        return convertProtocolBuffersMessageToSObject((DynamicMessage) val, null, field.isAggregate() ? field.getGenericType() : field.getType());
    } else {
        return val;
    }
}
Also used : ByteString(com.google.protobuf.ByteString) DataHandler(javax.activation.DataHandler) DynamicMessage(com.google.protobuf.DynamicMessage) ByteArrayDataSource(org.bimserver.utils.ByteArrayDataSource) EnumValueDescriptor(com.google.protobuf.Descriptors.EnumValueDescriptor) Date(java.util.Date)

Example 24 with ByteString

use of org.apache.beam.vendor.grpc.v1p43p2.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());
    }
}
Also used : ByteString(com.google.protobuf.ByteString) BigInteger(java.math.BigInteger) AionTransaction(org.aion.zero.types.AionTransaction)

Example 25 with ByteString

use of org.apache.beam.vendor.grpc.v1p43p2.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();
}
Also used : ProcessSession(org.apache.nifi.processor.ProcessSession) FlowFile(org.apache.nifi.flowfile.FlowFile) ProcessContext(org.apache.nifi.processor.ProcessContext) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ProcessSession(org.apache.nifi.processor.ProcessSession) UUID(java.util.UUID) ComponentLog(org.apache.nifi.logging.ComponentLog) Maps(com.google.common.collect.Maps) ProcessSessionFactory(org.apache.nifi.processor.ProcessSessionFactory) AtomicReference(java.util.concurrent.atomic.AtomicReference) BufferedOutputStream(java.io.BufferedOutputStream) ByteString(com.google.protobuf.ByteString) TimeUnit(java.util.concurrent.TimeUnit) IOUtils(org.apache.commons.io.IOUtils) AtomicLong(java.util.concurrent.atomic.AtomicLong) StreamObserver(io.grpc.stub.StreamObserver) Map(java.util.Map) CoreAttributes(org.apache.nifi.flowfile.attributes.CoreAttributes) InputStream(java.io.InputStream) FlowFile(org.apache.nifi.flowfile.FlowFile) ByteString(com.google.protobuf.ByteString) InputStream(java.io.InputStream) ByteString(com.google.protobuf.ByteString) ProcessSessionFactory(org.apache.nifi.processor.ProcessSessionFactory) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

ByteString (com.google.protobuf.ByteString)406 Test (org.junit.Test)143 ArrayList (java.util.ArrayList)65 ByteString (org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString)63 HashMap (java.util.HashMap)41 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)40 IOException (java.io.IOException)37 List (java.util.List)33 Map (java.util.Map)33 ServerRequest (com.pokegoapi.main.ServerRequest)17 ExecutionException (java.util.concurrent.ExecutionException)16 AnnotateImageRequest (com.google.cloud.vision.v1.AnnotateImageRequest)14 AnnotateImageResponse (com.google.cloud.vision.v1.AnnotateImageResponse)14 BatchAnnotateImagesResponse (com.google.cloud.vision.v1.BatchAnnotateImagesResponse)14 Feature (com.google.cloud.vision.v1.Feature)14 Image (com.google.cloud.vision.v1.Image)14 ImageAnnotatorClient (com.google.cloud.vision.v1.ImageAnnotatorClient)14 FileInputStream (java.io.FileInputStream)13 ByteBuffer (java.nio.ByteBuffer)13 WebImage (com.google.cloud.vision.v1.WebDetection.WebImage)12