Class OpenLineageClientUtils

java.lang.Object
io.openlineage.client.OpenLineageClientUtils

public final class OpenLineageClientUtils extends Object
Utility class for OpenLineageClient that provides common functionalities for object mapping, JSON and YAML parsing, and URI manipulation.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    class 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    configureObjectMapper(String... disableFacets)
    Configures the object mapper to exclude specified facets from being serialized.
    static <T> T
    convertValue(Object fromValue, Class<T> toValueType)
    Converts the value of an object from one type to another.
    static <T> T
    deepCopy(T object, com.fasterxml.jackson.core.type.TypeReference<T> type)
    Performs a deep copy of an object by serializing it to JSON and then deserializing it back to its original type.
    static <T> T
    fromJson(@NonNull String json, @NonNull com.fasterxml.jackson.core.type.TypeReference<T> type)
    Converts the provided JSON string to an instance of the specified type.
    static <T extends OpenLineageConfig>
    T
    loadOpenLineageConfigFromEnvVars(com.fasterxml.jackson.core.type.TypeReference<T> valueTypeRef)
    This method reads the OpenLineage configuration from environment variables, converts it to a JSON string, and then parses the JSON string into an instance of the specified OpenLineageConfig subclass.
    static <T extends OpenLineageConfig>
    T
    loadOpenLineageConfigJson(InputStream inputStream, com.fasterxml.jackson.core.type.TypeReference<T> valueTypeRef)
    Loads and parses OpenLineage JSON configuration from an InputStream.
    static <T extends OpenLineageConfig>
    T
    loadOpenLineageConfigYaml(ConfigPathProvider configPathProvider, com.fasterxml.jackson.core.type.TypeReference<T> valueTypeRef)
    Loads and parses OpenLineage configuration from the provided paths.
    static <T extends OpenLineageConfig>
    T
    loadOpenLineageConfigYaml(InputStream inputStream, com.fasterxml.jackson.core.type.TypeReference<T> valueTypeRef)
    Loads and parses OpenLineage YAML configuration from an InputStream.
    static <T, F> T
    mergeFacets(Map<String,F> facetsMap, T facetsContainer, Class<T> klass)
    Merges the given facets map with an existing facets container, giving precedence to the values in the facets map.
    static com.fasterxml.jackson.databind.ObjectMapper
    Creates a new ObjectMapper instance configured with modules for JDK8 and JavaTime, including settings to ignore unknown properties and to not write dates as timestamps.
    static com.fasterxml.jackson.databind.ObjectMapper
    newObjectMapper(com.fasterxml.jackson.core.JsonFactory jsonFactory)
    Creates a new ObjectMapper instance configured with modules for JDK8 and JavaTime, including settings to ignore unknown properties and to not write dates as timestamps.
    runEventFromJson(@NonNull String json)
    Convenience method to convert a JSON string directly into a OpenLineage.RunEvent instance.
    static String
    toJson(@NonNull Object value)
    Converts the provided value to a JSON string.
    static URI
    toUri(@NonNull String urlString)
    Converts a string URL into an URI object.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • newObjectMapper

      public static com.fasterxml.jackson.databind.ObjectMapper newObjectMapper()
      Creates a new ObjectMapper instance configured with modules for JDK8 and JavaTime, including settings to ignore unknown properties and to not write dates as timestamps.
      Returns:
      A configured ObjectMapper instance.
    • newObjectMapper

      public static com.fasterxml.jackson.databind.ObjectMapper newObjectMapper(com.fasterxml.jackson.core.JsonFactory jsonFactory)
      Creates a new ObjectMapper instance configured with modules for JDK8 and JavaTime, including settings to ignore unknown properties and to not write dates as timestamps.
      Parameters:
      jsonFactory - JsonFactory
      Returns:
      A configured ObjectMapper instance.
    • configureObjectMapper

      public static void configureObjectMapper(String... disableFacets)
      Configures the object mapper to exclude specified facets from being serialized.
      Parameters:
      disableFacets - Array of facet names to be excluded from serialization.
    • toJson

      public static String toJson(@NonNull @NonNull Object value) throws UncheckedIOException
      Converts the provided value to a JSON string.
      Parameters:
      value - The object to be converted to JSON.
      Returns:
      A JSON string representation of the object.
      Throws:
      UncheckedIOException - If an I/O error occurs during conversion.
    • fromJson

      public static <T> T fromJson(@NonNull @NonNull String json, @NonNull @NonNull com.fasterxml.jackson.core.type.TypeReference<T> type) throws UncheckedIOException
      Converts the provided JSON string to an instance of the specified type.
      Type Parameters:
      T - The generic type of the return value.
      Parameters:
      json - The JSON string to be converted.
      type - The type to convert the JSON string into.
      Returns:
      An instance of the specified type.
      Throws:
      UncheckedIOException - If an I/O error occurs during conversion.
    • deepCopy

      public static <T> T deepCopy(@NonNull T object, com.fasterxml.jackson.core.type.TypeReference<T> type) throws UncheckedIOException
      Performs a deep copy of an object by serializing it to JSON and then deserializing it back to its original type.
      Type Parameters:
      T - The generic type of the object.
      Parameters:
      object - The object to be deep copied.
      type - The Jackson TypeReference used for deserialization.
      Returns:
      A deep copy of the input object.
      Throws:
      UncheckedIOException
    • runEventFromJson

      public static OpenLineage.RunEvent runEventFromJson(@NonNull @NonNull String json) throws UncheckedIOException
      Convenience method to convert a JSON string directly into a OpenLineage.RunEvent instance.
      Parameters:
      json - The JSON string representing a OpenLineage.RunEvent.
      Returns:
      An instance of OpenLineage.RunEvent.
      Throws:
      UncheckedIOException - If an I/O error occurs during conversion.
    • convertValue

      public static <T> T convertValue(Object fromValue, Class<T> toValueType)
      Converts the value of an object from one type to another.
      Type Parameters:
      T - The generic type of the target type.
      Parameters:
      fromValue - The object whose value is to be converted.
      toValueType - The target type for the conversion.
      Returns:
      An object of the target type with the value converted from the original object.
    • mergeFacets

      public static <T, F> T mergeFacets(Map<String,F> facetsMap, T facetsContainer, Class<T> klass)
      Merges the given facets map with an existing facets container, giving precedence to the values in the facets map.
      Type Parameters:
      T - The type of the facets container.
      F - The type of facets in the map.
      Parameters:
      facetsMap - A map containing facets to be merged.
      facetsContainer - The existing container of facets.
      klass - The class of the facets container.
      Returns:
      A new instance of the facets container with merged values.
    • toUri

      public static URI toUri(@NonNull @NonNull String urlString) throws OpenLineageClientException
      Converts a string URL into an URI object.
      Parameters:
      urlString - The string URL to be converted.
      Returns:
      An URI object.
      Throws:
      OpenLineageClientException - If the given string does not conform to the URI specification.
    • loadOpenLineageConfigYaml

      public static <T extends OpenLineageConfig> T loadOpenLineageConfigYaml(ConfigPathProvider configPathProvider, com.fasterxml.jackson.core.type.TypeReference<T> valueTypeRef) throws OpenLineageClientException
      Loads and parses OpenLineage configuration from the provided paths. Throws an OpenLineageClientException if one of the following conditions are met:
      1. The provided configPathProvider is null
      2. No configuration file could be found at any of the provided paths
      3. Load the default configuration from the classpath if no file is found
      Type Parameters:
      T - generic type of merged config
      Parameters:
      configPathProvider - Provides the paths where the configuration files can be found.
      valueTypeRef - The type to convert the JSON string into.
      Returns:
      An instance of OpenLineageConfig containing the parsed configuration.
      Throws:
      OpenLineageClientException - According to the rules defined above.
    • loadOpenLineageConfigYaml

      public static <T extends OpenLineageConfig> T loadOpenLineageConfigYaml(InputStream inputStream, com.fasterxml.jackson.core.type.TypeReference<T> valueTypeRef) throws OpenLineageClientException
      Loads and parses OpenLineage YAML configuration from an InputStream.
      Type Parameters:
      T - generic type of merged config
      Parameters:
      inputStream - The InputStream from which to load the configuration.
      valueTypeRef - The type to convert the JSON string into.
      Returns:
      An instance of OpenLineageConfig containing the parsed YAML configuration.
      Throws:
      OpenLineageClientException - If an error occurs while reading or parsing the configuration.
    • loadOpenLineageConfigJson

      public static <T extends OpenLineageConfig> T loadOpenLineageConfigJson(InputStream inputStream, com.fasterxml.jackson.core.type.TypeReference<T> valueTypeRef) throws OpenLineageClientException
      Loads and parses OpenLineage JSON configuration from an InputStream.
      Type Parameters:
      T - generic type of merged config
      Parameters:
      inputStream - The InputStream from which to load the configuration.
      valueTypeRef - The type to convert the JSON string into.
      Returns:
      An instance of OpenLineageConfig containing the parsed JSON configuration.
      Throws:
      OpenLineageClientException - If an error occurs while reading or parsing the configuration.
    • loadOpenLineageConfigFromEnvVars

      public static <T extends OpenLineageConfig> T loadOpenLineageConfigFromEnvVars(com.fasterxml.jackson.core.type.TypeReference<T> valueTypeRef) throws OpenLineageClientException
      This method reads the OpenLineage configuration from environment variables, converts it to a JSON string, and then parses the JSON string into an instance of the specified OpenLineageConfig subclass.
      Type Parameters:
      T - generic type of merged config
      Parameters:
      valueTypeRef - The type to convert the JSON string into.
      Returns:
      An instance of OpenLineageConfig containing the parsed JSON configuration.
      Throws:
      OpenLineageClientException - If an error occurs while reading or parsing the configuration.