Class AwsProductSender

java.lang.Object
gov.usgs.util.DefaultConfigurable
gov.usgs.earthquake.aws.AwsProductSender
All Implemented Interfaces:
ProductSender, Configurable

public class AwsProductSender extends DefaultConfigurable implements ProductSender
Send using AWS Hub API.
  • Field Details

    • LOGGER

      public static final Logger LOGGER
      Initialzation of logger. For us later in file.
    • CONNECT_TIMEOUT_PROPERTY

      public static final String CONNECT_TIMEOUT_PROPERTY
      Property key for connect timeout property
      See Also:
    • HUB_URL_PROPERTY

      public static final String HUB_URL_PROPERTY
      Base URL for Hub API.
      See Also:
    • MAX_PAYLOAD_BYTES_PROPERTY

      public static final String MAX_PAYLOAD_BYTES_PROPERTY
      Max JSON notification size for sending products
      See Also:
    • PRIVATE_KEY_PROPERTY

      public static final String PRIVATE_KEY_PROPERTY
      Private Key to sign products, if signProducts is true.
      See Also:
    • READ_TIMEOUT_PROPERTY

      public static final String READ_TIMEOUT_PROPERTY
      Property key for read timeout property
      See Also:
    • SIGN_PRODUCTS_PROPERTY

      public static final String SIGN_PRODUCTS_PROPERTY
      Whether to sign products using private key.
      See Also:
    • SECRET_RESOLVER_PROPERTY

      public static final String SECRET_RESOLVER_PROPERTY
      Resolver class to use to get a secret for the private key
      See Also:
    • PRIVATE_KEY_SECRET_NAME_PROPERTY

      public static final String PRIVATE_KEY_SECRET_NAME_PROPERTY
      Secret key to retrieve
      See Also:
    • DEFAULT_CONNECT_TIMEOUT

      public static final int DEFAULT_CONNECT_TIMEOUT
      Default value to use for connect timeout property if not configured
      See Also:
    • DEFAULT_READ_TIMEOUT

      public static final int DEFAULT_READ_TIMEOUT
      Default value to use for read timeout property if not configured
      See Also:
    • httpClient

      protected HttpClient httpClient
      client used for http requests
    • hubUrl

      protected URL hubUrl
      url where products are sent
    • privateKey

      protected PrivateKey privateKey
      signing key
    • signProducts

      protected boolean signProducts
      wheter to sign products
    • connectTimeout

      protected int connectTimeout
      Connection timeout. 5s seems excessive, but be cautious for now
    • readTimeout

      protected int readTimeout
      Server-side timeout. Called at getInputStream().read()
    • DEFAULT_MAX_PAYLOAD_BYTES

      public static final long DEFAULT_MAX_PAYLOAD_BYTES
      See Also:
  • Constructor Details

    • AwsProductSender

      public AwsProductSender()
      Empty class constructor
    • AwsProductSender

      public AwsProductSender(URL url)
      Setter for product sender
      Parameters:
      url - URL for sender hub
  • Method Details

    • configure

      public void configure(Config config) throws Exception
      Description copied from class: DefaultConfigurable
      Process configuration settings. Called before startup().
      Specified by:
      configure in interface Configurable
      Overrides:
      configure in class DefaultConfigurable
      Parameters:
      config - the Config object with settings.
      Throws:
      Exception - if configuration exceptions occur.
    • checkProductJsonSize

      public void checkProductJsonSize(javax.json.JsonObject json) throws Exception
      Throws:
      Exception
    • sendProduct

      public void sendProduct(Product product) throws Exception
      Send a product to the hub.
      Specified by:
      sendProduct in interface ProductSender
      Parameters:
      product - the product to send.
      Throws:
      Exception - if any errors occur while sending.
    • getUploadUrls

      protected Product getUploadUrls(javax.json.JsonObject json, String urn) throws Exception
      Get content upload urls.
      Parameters:
      json - product in json format.
      Returns:
      product with content urls set to upload URLs.
      Throws:
      Exception - Exception
    • postProductJson

      protected HttpResponse<String> postProductJson(URL url, javax.json.JsonObject product) throws Exception
      Post product json to a hub url. This is a HTTP POST method, with a JSON content body with a "product" property with the product.
      Parameters:
      url - url of connection
      product - product in json format
      Returns:
      new HTTP POST response
      Throws:
      Exception - Exception
    • sendProduct

      protected Product sendProduct(javax.json.JsonObject json, String urn) throws Exception
      Send product after content has been uploaded.
      Parameters:
      json - product in json format.
      Returns:
      product with content urls pointing to hub.
      Throws:
      Exception - Exception
    • uploadContent

      protected HttpResponse<String> uploadContent(String path, Content content, URL signedUrl) throws Exception
      Upload content to a signed url.
      Parameters:
      path - content path.
      content - content to upload.
      signedUrl - url where content should be uploaded.
      Returns:
      HTTP result
      Throws:
      Exception - Exception
    • uploadContents

      protected Map<String,HttpResponse<String>> uploadContents(Product product, Product uploadProduct) throws Exception
      Upload product contents. Runs uploads in parallel using a parallel stream. This can be called within a custom ForkJoinPool to use a non-default pool, the default pool is shared by the process and based on number of available cores.
      Parameters:
      product - product to upload.
      uploadProduct - product with signed upload urls.
      Returns:
      upload results
      Throws:
      Exception - if any upload errors occur
    • getSignProducts

      public boolean getSignProducts()
      Getter for signProducts
      Returns:
      boolean
    • setSignProducts

      public void setSignProducts(boolean sign)
      Setter for signProducts
      Parameters:
      sign - boolean
    • getPrivateKey

      public PrivateKey getPrivateKey()
      getter for privateKey
      Returns:
      privateKey
    • setPrivateKey

      public void setPrivateKey(PrivateKey key)
      setting for privateKey
      Parameters:
      key - PrivateKey