Class ComputeInstanceMetadataResolverUtils

java.lang.Object
io.micronaut.discovery.cloud.ComputeInstanceMetadataResolverUtils

@Internal public class ComputeInstanceMetadataResolverUtils extends Object
Utility class for ComputeInstanceMetadataResolver's.
Since:
1.1
Author:
Alvaro Sanchez-Mariscal
  • Constructor Details

    • ComputeInstanceMetadataResolverUtils

      public ComputeInstanceMetadataResolverUtils()
  • Method Details

    • readMetadataUrl

      public static com.fasterxml.jackson.databind.JsonNode readMetadataUrl(URL url, int connectionTimeoutMs, int readTimeoutMs, com.fasterxml.jackson.databind.ObjectMapper objectMapper, Map<String,String> requestProperties) throws IOException
      Reads the result of a URL and parses it using the given ObjectMapper.
      Parameters:
      url - the URL to read
      connectionTimeoutMs - connection timeout, in milliseconds
      readTimeoutMs - read timeout, in milliseconds
      objectMapper - Jackson's ObjectMapper
      requestProperties - any request properties to pass
      Returns:
      a JsonNode instance
      Throws:
      IOException - if any I/O error occurs
    • readMetadataUrl

      public static JsonNode readMetadataUrl(URL url, int connectionTimeoutMs, int readTimeoutMs, JsonNodeTreeCodec treeCodec, com.fasterxml.jackson.core.JsonFactory jsonFactory, Map<String,String> requestProperties) throws IOException
      Reads the result of a URL and parses it using the given JsonFactory.
      Parameters:
      url - the URL to read
      connectionTimeoutMs - connection timeout, in milliseconds
      readTimeoutMs - read timeout, in milliseconds
      treeCodec - Tree codec to use (contains deserialization config)
      jsonFactory - Jackson's JsonFactory
      requestProperties - any request properties to pass
      Returns:
      a JsonNode instance
      Throws:
      IOException - if any I/O error occurs
    • readMetadataUrl

      public static JsonNode readMetadataUrl(URL url, int connectionTimeoutMs, int readTimeoutMs, JsonMapper jsonMapper, Map<String,String> requestProperties) throws IOException
      Reads the result of a URL and parses it using the given JsonMapper.
      Parameters:
      url - the URL to read
      connectionTimeoutMs - connection timeout, in milliseconds
      readTimeoutMs - read timeout, in milliseconds
      jsonMapper - JSON mapper to use for parsing
      requestProperties - any request properties to pass
      Returns:
      a JsonNode instance
      Throws:
      IOException - if any I/O error occurs
      Since:
      3.3.0
    • populateMetadata

      public static void populateMetadata(AbstractComputeInstanceMetadata instanceMetadata, JsonNode metadata)
      Populates the instance instance metadata's AbstractComputeInstanceMetadata.setMetadata(Map) property.
      Parameters:
      instanceMetadata - The instance metadata
      metadata - A json object of metadata
    • stringValue

      public static Optional<String> stringValue(com.fasterxml.jackson.databind.JsonNode json, String key)
      Resolve a value as a string from the metadata json.
      Parameters:
      json - The json
      key - The key
      Returns:
      An optional value
    • populateMetadata

      public static void populateMetadata(AbstractComputeInstanceMetadata instanceMetadata, Map<?,?> metadata)
      Populates the instance instance metadata's AbstractComputeInstanceMetadata.setMetadata(Map) property.
      Parameters:
      instanceMetadata - The instance metadata
      metadata - A map of metadata