Package gov.usgs.earthquake.aws
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 Summary
Fields Modifier and Type Field Description protected int
connectTimeout
Connection timeout.static java.lang.String
HUB_URL_PROPERTY
Base URL for Hub API.protected java.net.URL
hubUrl
url where products are sentstatic java.util.logging.Logger
LOGGER
Initialzation of logger.static java.lang.String
PRIVATE_KEY_PROPERTY
Private Key to sign products, if signProducts is true.protected java.security.PrivateKey
privateKey
signing keyprotected int
readTimeout
Server-side timeout.static java.lang.String
SIGN_PRODUCTS_PROPERTY
Whether to sign products using private key.protected boolean
signProducts
wheter to sign products
-
Constructor Summary
Constructors Constructor Description AwsProductSender()
Empty class constructorAwsProductSender(java.net.URL url)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
configure(Config config)
Process configuration settings.java.security.PrivateKey
getPrivateKey()
getter for privateKeyboolean
getSignProducts()
Getter for signProductsprotected Product
getUploadUrls(javax.json.JsonObject json)
Get content upload urls.protected HttpResponse
postProductJson(java.net.URL url, javax.json.JsonObject product)
Post product json to a hub url.void
sendProduct(Product product)
Send a product to the hub.protected Product
sendProduct(javax.json.JsonObject json)
Send product after content has been uploaded.void
setPrivateKey(java.security.PrivateKey key)
setting for privateKeyvoid
setSignProducts(boolean sign)
Setter for signProductsprotected HttpResponse
uploadContent(java.lang.String path, Content content, java.net.URL signedUrl)
Upload content to a signed url.protected java.util.Map<java.lang.String,HttpResponse>
uploadContents(Product product, Product uploadProduct)
Upload product contents.-
Methods inherited from class gov.usgs.util.DefaultConfigurable
getName, setName, shutdown, startup
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface gov.usgs.util.Configurable
getName, setName, shutdown, startup
-
-
-
-
Field Detail
-
LOGGER
public static final java.util.logging.Logger LOGGER
Initialzation of logger. For us later in file.
-
HUB_URL_PROPERTY
public static final java.lang.String HUB_URL_PROPERTY
Base URL for Hub API.- See Also:
- Constant Field Values
-
PRIVATE_KEY_PROPERTY
public static final java.lang.String PRIVATE_KEY_PROPERTY
Private Key to sign products, if signProducts is true.- See Also:
- Constant Field Values
-
SIGN_PRODUCTS_PROPERTY
public static final java.lang.String SIGN_PRODUCTS_PROPERTY
Whether to sign products using private key.- See Also:
- Constant Field Values
-
hubUrl
protected java.net.URL hubUrl
url where products are sent
-
privateKey
protected java.security.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()
-
-
Method Detail
-
configure
public void configure(Config config) throws java.lang.Exception
Description copied from class:DefaultConfigurable
Process configuration settings. Called before startup().- Specified by:
configure
in interfaceConfigurable
- Overrides:
configure
in classDefaultConfigurable
- Parameters:
config
- the Config object with settings.- Throws:
java.lang.Exception
- if configuration exceptions occur.
-
sendProduct
public void sendProduct(Product product) throws java.lang.Exception
Send a product to the hub.- Specified by:
sendProduct
in interfaceProductSender
- Parameters:
product
- the product to send.- Throws:
java.lang.Exception
- if any errors occur while sending.
-
getUploadUrls
protected Product getUploadUrls(javax.json.JsonObject json) throws java.lang.Exception
Get content upload urls.- Parameters:
json
- product in json format.- Returns:
- product with content urls set to upload URLs.
- Throws:
java.lang.Exception
- Exception
-
postProductJson
protected HttpResponse postProductJson(java.net.URL url, javax.json.JsonObject product) throws java.lang.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 connectionproduct
- product in json format- Returns:
- new HTTP POST response
- Throws:
java.lang.Exception
- Exception
-
sendProduct
protected Product sendProduct(javax.json.JsonObject json) throws java.lang.Exception
Send product after content has been uploaded.- Parameters:
json
- product in json format.- Returns:
- product with content urls pointing to hub.
- Throws:
java.lang.Exception
- Exception
-
uploadContent
protected HttpResponse uploadContent(java.lang.String path, Content content, java.net.URL signedUrl) throws java.lang.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:
java.lang.Exception
- Exception
-
uploadContents
protected java.util.Map<java.lang.String,HttpResponse> uploadContents(Product product, Product uploadProduct) throws java.lang.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:
java.lang.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 java.security.PrivateKey getPrivateKey()
getter for privateKey- Returns:
- privateKey
-
setPrivateKey
public void setPrivateKey(java.security.PrivateKey key)
setting for privateKey- Parameters:
key
- PrivateKey
-
-