java.lang.Object
org.hansken.plugin.extraction.runtime.grpc.common.Pack

public final class Pack extends Object
Utility class to convert from native Java or plugin API data structures to their gRPC message counterparts. For the other way around, see Unpack.
  • Field Details

    • FIRST_BYTES_SIZE

      public static final int FIRST_BYTES_SIZE
      Amount of bytes initially sent with the RpcRandomAccessDataMeta (for performance reasons). It is useless to make it greater than the cache size.
      See Also:
  • Method Details

    • trace

      public static RpcTrace trace(String id, ImmutableTrace trace)
      Convert given Trace to their RpcTrace counterpart.
      Parameters:
      id - the id of the trace
      trace - the trace to convert
      Returns:
      the converted trace
      Throws:
      IllegalArgumentException - if the trace contains properties which are not of an expected primitive type
    • searchTrace

      public static RpcSearchTrace searchTrace(SearchTrace trace)
      Convert given SearchTrace to their RpcSearchTrace counterpart.
      Parameters:
      trace - the search trace to convert
      Returns:
      the converted trace
      Throws:
      IllegalArgumentException - if the trace contains properties which are not of an expected primitive type
    • property

      public static RpcTraceProperty property(String name, Object value)
    • primitive

      public static com.google.protobuf.Message primitive(Object object)
      Convert given object to their RPC primitive message counterpart (see PrimitiveMessages proto definitions), based on the runtime type. If the type is a generic List or Map, the elements, keys and values must all be of the same type.
      Parameters:
      object - the object to convert
      Returns:
      the converted object
      Throws:
      IllegalArgumentException - if the type of the object is not supported, or if not all elements of a collection (like) object are of the same type, or if any of these elements is null
    • metaOfDataContext

      public static RpcDataContext metaOfDataContext(DataContext context)
      Convert given DataContext to their RpcDataContext counterpart. Only the metadata of the data sequence will be packed, see metaOfData(String, RandomAccessData).
      Parameters:
      context - the context to convert
      Returns:
      the converted context
    • metaOfData

      public static RpcRandomAccessDataMeta metaOfData(String dataType, RandomAccessData data)
      Convert given RandomAccessData to their RpcRandomAccessDataMeta counterpart. This does not copy the entire data contained in the sequence, only the size and the first 1MB if available.
      Parameters:
      dataType - the dataType of the sequence
      data - the data sequence to convert
      Returns:
      the converted data sequence
    • randomAccessDataMeta

      public static RpcRandomAccessDataMeta randomAccessDataMeta(String dataType, ImmutableTrace trace)
      Pack given dataType and trace into an RPC message. Note that this message does not include any data.
      Parameters:
      dataType - type of the data
      trace - trace used to infer size of the data
      Returns:
      RpcRandomAccessDataMeta message
    • pluginInfo

      public static RpcPluginInfo pluginInfo(PluginInfo info)
      Convert given PluginInfo to their RpcPluginInfo counterpart.
      Parameters:
      info - the info to convert
      Returns:
      the converted info
    • pluginId

      public static RpcPluginIdentifier pluginId(PluginId id)
    • author

      public static RpcAuthor author(Author author)
      Convert given Author to their RpcAuthor counterpart.
      Parameters:
      author - the author to convert
      Returns:
      the converted author
    • maturityLevel

      public static RpcMaturity maturityLevel(MaturityLevel maturity)
      Convert given MaturityLevel to their RpcMaturity counterpart.
      Parameters:
      maturity - the maturity to convert
      Returns:
      the converted maturity
      Throws:
      IllegalArgumentException - when the given maturity is not mappable
    • pluginType

      public static RpcPluginType pluginType(PluginType type)
      Convert given PluginType to their RpcPluginType counterpart.
      Parameters:
      type - the type to convert
      Returns:
      the converted type
      Throws:
      IllegalArgumentException - when the given type is not mappable
    • readParameters

      public static RpcRead readParameters(long position, int count, String traceUid, String type)
      Create an RpcRead message from given position and size.
      Parameters:
      position - the position to read at
      count - the amount of bytes to read
      traceUid - the uid of the trace to read from
      type - the type of the data stream to read
      Returns:
      the created message
    • searchRequest

      public static RpcSearchRequest searchRequest(String query, int count, TraceSearcher.SearchScope scope)
      Create a RpcSearchRequest message from given query and count.
      Parameters:
      query - string to query
      count - maximum number of results returned
      scope - scope to limit the search to (image or project)
      Returns:
      the created message
    • genericList

      public static RpcList genericList(List<Object> list)
      Packs a (potentially non-homogeneous) List into a RpcList. TODO HANSKEN-21534: Remove non-generic lists and maps in extraction plugins, allowing this method to be removed.
      Parameters:
      list - The list that we want to pack.
      Returns:
      The packed RpcList.
    • genericMap

      public static RpcMap genericMap(Map<String,Object> map)
      Packs a (potentially non-homogeneous) Map into a RpcMap. TODO HANSKEN-21534: Remove non-generic lists and maps in extraction plugins, allowing this method to be removed.
      Parameters:
      map - The map that we want to pack.
      Returns:
      The packed RpcMap.
    • transformerArgument

      public static RpcTransformerArgument transformerArgument(Object argument)
      Packs an object into a RpcTransformerArgument.
      Parameters:
      argument - The object that we want to pack as an RpcTransformerArgument.
      Returns:
      The packed RpcTransformerArgument.
    • transformerArgumentMap

      public static Map<String,RpcTransformerArgument> transformerArgumentMap(Map<String,TransformerArgument> arguments)
      Packs a map of TransformerArguments into a RpcTransformerArguments.
      Parameters:
      arguments - The map of arguments where we want to pack TransformerArguments into RpcTransformerArguments.
      Returns:
      A map where the TransformerArgument values are converted into RpcTransformerArguments.
    • transformerRequest

      public static RpcTransformerRequest transformerRequest(TransformerLabel label, Map<String,RpcTransformerArgument> arguments)
      Packs a transformer label describing the transformer and arguments to invoke it into a transformer request.
      Parameters:
      label - The label containing the name, parameters and return type of the transformer.
      arguments - The arguments to invoke the transformer with provided as a (name, value) pair.
      Returns:
      The transformer request that can be sent over grpc to the plugin.
    • traceEnrichment

      public static RpcEnrichTrace traceEnrichment(String id, Set<String> types, Map<String,Object> properties, List<Trace.Tracelet> tracelets, Map<String,List<DataTransformation>> transformations)
      Create a RpcEnrichTrace message which contains given set of types and properties to send to the client and used to enrich the currently processed trace with.
      Parameters:
      id - the id of the trace to enrich
      types - the types to add
      properties - the properties to add
      tracelets - the tracelets to add
      transformations - the transformations to add
      Returns:
      the created message
    • searchResult

      public static RpcSearchResult searchResult(SearchResult result)
      Create a RpcSearchResult from a given SearchResult.
      Parameters:
      result - the search result containing searched traces
      Returns:
      the created RpcSearchResult
    • asStatusRuntimeException

      public static io.grpc.StatusRuntimeException asStatusRuntimeException(io.grpc.Status.Code statusCode, Throwable t)
      Wrap a throwable in a status exception which can be used to signal an error on gRPC stream.
      Parameters:
      statusCode - the error code
      t - the error cause
      Returns:
      a status exception which can be signaled on the gRPC stream