Package gov.usgs.earthquake.aws
Class AwsProductSender
java.lang.Object
gov.usgs.util.DefaultConfigurable
gov.usgs.earthquake.aws.AwsProductSender
- All Implemented Interfaces:
ProductSender
,Configurable
Send using AWS Hub API.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Static exception class for when a command times out -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Property key for connect timeout propertyprotected int
Connection timeout.static final int
Default value to use for connect timeout property if not configuredstatic final long
static final int
Default value to use for read timeout property if not configuredprotected HttpClient
client used for http requestsstatic final String
Base URL for Hub API.protected URL
url where products are sentstatic final Logger
Initialzation of logger.static final String
Max JSON notification size for sending productsstatic final String
Private Key to sign products, if signProducts is true.static final String
Secret key to retrieveprotected PrivateKey
signing keystatic final String
Property key for read timeout propertyprotected int
Server-side timeout.static final String
Resolver class to use to get a secret for the private keystatic final String
Whether to sign products using private key.protected boolean
wheter to sign products -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
checkProductJsonSize
(javax.json.JsonObject json) void
Process configuration settings.getter for privateKeyboolean
Getter for signProductsprotected Product
getUploadUrls
(javax.json.JsonObject json, String urn) Get content upload urls.protected HttpResponse<String>
postProductJson
(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, String urn) Send product after content has been uploaded.void
setPrivateKey
(PrivateKey key) setting for privateKeyvoid
setSignProducts
(boolean sign) Setter for signProductsprotected HttpResponse<String>
uploadContent
(String path, Content content, URL signedUrl) Upload content to a signed url.protected Map<String,
HttpResponse<String>> 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 Details
-
LOGGER
Initialzation of logger. For us later in file. -
CONNECT_TIMEOUT_PROPERTY
Property key for connect timeout property- See Also:
-
HUB_URL_PROPERTY
Base URL for Hub API.- See Also:
-
MAX_PAYLOAD_BYTES_PROPERTY
Max JSON notification size for sending products- See Also:
-
PRIVATE_KEY_PROPERTY
Private Key to sign products, if signProducts is true.- See Also:
-
READ_TIMEOUT_PROPERTY
Property key for read timeout property- See Also:
-
SIGN_PRODUCTS_PROPERTY
Whether to sign products using private key.- See Also:
-
SECRET_RESOLVER_PROPERTY
Resolver class to use to get a secret for the private key- See Also:
-
PRIVATE_KEY_SECRET_NAME_PROPERTY
Secret key to retrieve- See Also:
-
DEFAULT_CONNECT_TIMEOUT
public static final int DEFAULT_CONNECT_TIMEOUTDefault value to use for connect timeout property if not configured- See Also:
-
DEFAULT_READ_TIMEOUT
public static final int DEFAULT_READ_TIMEOUTDefault value to use for read timeout property if not configured- See Also:
-
httpClient
client used for http requests -
hubUrl
url where products are sent -
privateKey
signing key -
signProducts
protected boolean signProductswheter to sign products -
connectTimeout
protected int connectTimeoutConnection timeout. 5s seems excessive, but be cautious for now -
readTimeout
protected int readTimeoutServer-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
Setter for product sender- Parameters:
url
- URL for sender hub
-
-
Method Details
-
configure
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:
Exception
- if configuration exceptions occur.
-
checkProductJsonSize
- Throws:
Exception
-
sendProduct
Send a product to the hub.- Specified by:
sendProduct
in interfaceProductSender
- Parameters:
product
- the product to send.- Throws:
Exception
- if any errors occur while sending.
-
getUploadUrls
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 connectionproduct
- product in json format- Returns:
- new HTTP POST response
- Throws:
Exception
- Exception
-
sendProduct
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
getter for privateKey- Returns:
- privateKey
-
setPrivateKey
setting for privateKey- Parameters:
key
- PrivateKey
-