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 classStatic exception class for when a command times out -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringProperty key for connect timeout propertyprotected intConnection timeout.static final StringContent format to post products as (Either MAP or LIST)static final intDefault value to use for connect timeout property if not configuredstatic final StringDefault value to use for contentFormat if not configuredstatic final longstatic final intDefault value to use for read timeout property if not configuredprotected booleanwhether or not to format contents as map or arraystatic final StringDefault value to use as the UriTemplate for uploadUrlsPath.static final StringConfiguration property key for setting getUploadUrlsPath.protected HttpClientclient used for http requestsstatic final StringDefault hub urlstatic final StringBase URL for Hub API.protected URLurl where products are sentstatic final LoggerInitialzation of logger.static final StringMax JSON notification size for sending productsstatic final StringPrivate Key to sign products, if signProducts is true.static final StringSecret key to retrieveprotected PrivateKeysigning keystatic final StringProperty key for read timeout propertyprotected intServer-side timeout.static final StringResolver class to use to get a secret for the private keystatic final StringDefault value to use as the UriTemplate for sendProductPath.static final StringConfiguration property key for setting sendProductPath.static final StringWhether to sign products using private key.protected booleanwhether to sign products -
Constructor Summary
ConstructorsConstructorDescriptionEmpty class constructorAwsProductSender(URL url) Setter for product senderAwsProductSender(URL url, HttpClient httpClient) -
Method Summary
Modifier and TypeMethodDescriptionvoidcheckProductJsonSize(javax.json.JsonObject json) voidProcess configuration settings.Generates a new url for sending productsgenerateUploadsURL(String urn) Generates a new url for getting upload urlsgetter for privateKeybooleanGetter for signProductsprotected ProductgetUploadUrls(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.voidsendProduct(Product product) Send a product to the hub.protected ProductsendProduct(javax.json.JsonObject json, String urn) Send product after content has been uploaded.voidsetPrivateKey(PrivateKey key) setting for privateKeyvoidsetSignProducts(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, startupMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:
-
HUB_URL_DEFAULT
Default hub url- 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:
-
SEND_PRODUCT_PATH_PROPERTY
Configuration property key for setting sendProductPath.- See Also:
-
SEND_PRODUCT_PATH_DEFAULT
Default value to use as the UriTemplate for sendProductPath.- See Also:
-
GET_UPLOAD_URLS_PATH_PROPERTY
Configuration property key for setting getUploadUrlsPath.- See Also:
-
GET_UPLOAD_URLS_PATH_DEFAULT
Default value to use as the UriTemplate for uploadUrlsPath.- See Also:
-
CONTENT_FORMAT_PROPERTY
Content format to post products as (Either MAP or LIST)- 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:
-
DEFAULT_CONTENT_FORMAT
Default value to use for contentFormat if not configured- See Also:
-
httpClient
client used for http requests -
hubUrl
url where products are sent -
privateKey
signing key -
signProducts
protected boolean signProductswhether to sign products -
formatContentsAsArray
protected boolean formatContentsAsArraywhether or not to format contents as map or array -
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
Empty class constructor- Throws:
MalformedURLException
-
AwsProductSender
Setter for product sender- Parameters:
url- URL for sender hub
-
AwsProductSender
-
-
Method Details
-
configure
Description copied from class:DefaultConfigurableProcess configuration settings. Called before startup().- Specified by:
configurein interfaceConfigurable- Overrides:
configurein 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:
sendProductin 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
-
generateSendProductURL
Generates a new url for sending products- Parameters:
urn- urn replacement parameter to replace {urn} path parameter if configured- Returns:
- URL generated with the class configuration path and the given baseUrl
- Throws:
MalformedURLExceptionURISyntaxException
-
generateUploadsURL
Generates a new url for getting upload urls- Parameters:
urn- urn replacement parameter to replace {urn} path parameter if configured- Returns:
- URL generated with the class configuration path and the given baseUrl
- Throws:
MalformedURLExceptionURISyntaxException
-
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
-