Class Pack
java.lang.Object
org.hansken.plugin.extraction.runtime.grpc.common.Pack
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final intAmount of bytes initially sent with the RpcRandomAccessDataMeta (for performance reasons). -
Method Summary
Modifier and TypeMethodDescriptionstatic io.grpc.StatusRuntimeExceptionasStatusRuntimeException(io.grpc.Status.Code statusCode, Throwable t) Wrap athrowablein a status exception which can be used to signal an error on gRPC stream.static RpcAuthorstatic RpcListgenericList(List<Object> list) Packs a (potentially non-homogeneous) List into a RpcList.static RpcMapgenericMap(Map<String, Object> map) Packs a (potentially non-homogeneous) Map into a RpcMap.static RpcMaturitymaturityLevel(MaturityLevel maturity) Convert givenMaturityLevelto theirRpcMaturitycounterpart.static RpcRandomAccessDataMetametaOfData(String dataType, RandomAccessData data) Convert givenRandomAccessDatato theirRpcRandomAccessDataMetacounterpart.static RpcDataContextmetaOfDataContext(DataContext context) Convert givenDataContextto theirRpcDataContextcounterpart.static RpcPluginIdentifierstatic RpcPluginInfopluginInfo(PluginInfo info) Convert givenPluginInfoto theirRpcPluginInfocounterpart.static RpcPluginTypepluginType(PluginType type) Convert givenPluginTypeto theirRpcPluginTypecounterpart.static com.google.protobuf.MessageConvert given object to their RPC primitive message counterpart (see PrimitiveMessages proto definitions), based on the runtime type.static RpcTracePropertystatic RpcRandomAccessDataMetarandomAccessDataMeta(String dataType, ImmutableTrace trace) Pack given dataType and trace into an RPC message.static RpcReadreadParameters(long position, int count, String traceUid, String type) Create anRpcReadmessage from given position and size.static RpcSearchRequestsearchRequest(String query, int count, TraceSearcher.SearchScope scope) Create aRpcSearchRequestmessage from given query and count.static RpcSearchResultsearchResult(SearchResult result) Create aRpcSearchResultfrom a givenSearchResult.static RpcSearchTracesearchTrace(SearchTrace trace) Convert givenSearchTraceto theirRpcSearchTracecounterpart.static RpcTracetrace(String id, ImmutableTrace trace) static RpcEnrichTracetraceEnrichment(String id, Set<String> types, Map<String, Object> properties, List<Trace.Tracelet> tracelets, Map<String, List<DataTransformation>> transformations) Create aRpcEnrichTracemessage which contains given set of types and properties to send to the client and used to enrich the currently processed trace with.static RpcTransformerArgumenttransformerArgument(Object argument) Packs an object into a RpcTransformerArgument.static Map<String, RpcTransformerArgument> transformerArgumentMap(Map<String, TransformerArgument> arguments) Packs a map of TransformerArguments into a RpcTransformerArguments.static RpcTransformerRequesttransformerRequest(TransformerLabel label, Map<String, RpcTransformerArgument> arguments) Packs a transformer label describing the transformer and arguments to invoke it into a transformer request.
-
Field Details
-
FIRST_BYTES_SIZE
public static final int FIRST_BYTES_SIZEAmount 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
- Parameters:
id- the id of the tracetrace- the trace to convert- Returns:
- the converted trace
- Throws:
IllegalArgumentException- if the trace contains properties which are not of an expected primitive type
-
searchTrace
Convert givenSearchTraceto theirRpcSearchTracecounterpart.- 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
-
primitive
Convert given object to their RPC primitive message counterpart (see PrimitiveMessages proto definitions), based on the runtime type. If the type is a genericListorMap, 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
Convert givenDataContextto theirRpcDataContextcounterpart. Only the metadata of the data sequence will be packed, seemetaOfData(String, RandomAccessData).- Parameters:
context- the context to convert- Returns:
- the converted context
-
metaOfData
Convert givenRandomAccessDatato theirRpcRandomAccessDataMetacounterpart. This does not copy the entire data contained in the sequence, only thesizeand the first 1MB if available.- Parameters:
dataType- the dataType of the sequencedata- the data sequence to convert- Returns:
- the converted data sequence
-
randomAccessDataMeta
Pack given dataType and trace into an RPC message. Note that this message does not include any data.- Parameters:
dataType- type of the datatrace- trace used to infer size of the data- Returns:
- RpcRandomAccessDataMeta message
-
pluginInfo
Convert givenPluginInfoto theirRpcPluginInfocounterpart.- Parameters:
info- the info to convert- Returns:
- the converted info
-
pluginId
-
author
- Parameters:
author- the author to convert- Returns:
- the converted author
-
maturityLevel
Convert givenMaturityLevelto theirRpcMaturitycounterpart.- Parameters:
maturity- the maturity to convert- Returns:
- the converted maturity
- Throws:
IllegalArgumentException- when the given maturity is not mappable
-
pluginType
Convert givenPluginTypeto theirRpcPluginTypecounterpart.- Parameters:
type- the type to convert- Returns:
- the converted type
- Throws:
IllegalArgumentException- when the given type is not mappable
-
readParameters
Create anRpcReadmessage from given position and size.- Parameters:
position- the position to read atcount- the amount of bytes to readtraceUid- the uid of the trace to read fromtype- 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 aRpcSearchRequestmessage from given query and count.- Parameters:
query- string to querycount- maximum number of results returnedscope- scope to limit the search to (image or project)- Returns:
- the created message
-
genericList
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
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
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 aRpcEnrichTracemessage 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 enrichtypes- the types to addproperties- the properties to addtracelets- the tracelets to addtransformations- the transformations to add- Returns:
- the created message
-
searchResult
Create aRpcSearchResultfrom a givenSearchResult.- 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 athrowablein a status exception which can be used to signal an error on gRPC stream.- Parameters:
statusCode- the error codet- the error cause- Returns:
- a status exception which can be signaled on the gRPC stream
-