Class AwsBatchIndexer

  • All Implemented Interfaces:
    Bootstrappable

    public class AwsBatchIndexer
    extends java.lang.Object
    implements Bootstrappable
    Class to index a batch of products that have already been sent to the AWS hub. Reads a list of products to be indexed. Reads indexer from configuration file. For each product, fetch product information from the get_product AWS endpoint and call indexer.onProduct.
    • Field Detail

      • FORCE_REINDEX_ARGUMENT

        public static final java.lang.String FORCE_REINDEX_ARGUMENT
        Force reindex argument
        See Also:
        Constant Field Values
      • GET_PRODUCT_URL_ARGUMENT

        public static final java.lang.String GET_PRODUCT_URL_ARGUMENT
        Get product URL argument
        See Also:
        Constant Field Values
      • INDEXER_CONFIG_NAME_ARGUMENT

        public static final java.lang.String INDEXER_CONFIG_NAME_ARGUMENT
        Argument for indexer configuration name
        See Also:
        Constant Field Values
      • INDEXER_CONFIG_NAME_DEFAULT

        public static final java.lang.String INDEXER_CONFIG_NAME_DEFAULT
        Default indexer configuration name
        See Also:
        Constant Field Values
      • DATABASE_DRIVER_ARGUMENT

        public static final java.lang.String DATABASE_DRIVER_ARGUMENT
        Argument for database driver
        See Also:
        Constant Field Values
      • DATABASE_URL_ARGUMENT

        public static final java.lang.String DATABASE_URL_ARGUMENT
        Argument for database URL
        See Also:
        Constant Field Values
      • INDEXER_DATABASE_ARGUMENT

        public static final java.lang.String INDEXER_DATABASE_ARGUMENT
        Argument for indexer database
        See Also:
        Constant Field Values
      • INDEXER_DATABASE_DEFAULT

        public static final java.lang.String INDEXER_DATABASE_DEFAULT
        Default database for indexer
        See Also:
        Constant Field Values
    • Constructor Detail

      • AwsBatchIndexer

        public AwsBatchIndexer()
    • Method Detail

      • run

        public void run​(java.lang.String[] args)
                 throws java.lang.Exception
        Description copied from interface: Bootstrappable
        Called by Bootstrap after processing the Configurable interface.
        Specified by:
        run in interface Bootstrappable
        Parameters:
        args - array of command line arguments.
        Throws:
        java.lang.Exception - Exception
      • getProductUrl

        public java.net.URL getProductUrl​(ProductId id)
                                   throws java.lang.Exception
        Use getProductUrl template to generate URL. Replace "{source}", "{type}", "{code}", and "{updateTime}" placeholders.
        Parameters:
        id - which product.
        Returns:
        URL with placeholders replaced.
        Throws:
        java.lang.Exception - Exception
      • getProduct

        public Product getProduct​(ProductId id)
                           throws java.lang.Exception
        Get Product from endpoint.
        Parameters:
        id - which product.
        Returns:
        Product object.
        Throws:
        java.lang.Exception - Exception
      • processProductId

        public void processProductId​(ProductId id)
        Fetch and Index a product. Called from executor service to process product ids.
        Parameters:
        id - which product
      • readProductIdsFromDatabase

        public void readProductIdsFromDatabase​(java.lang.String driver,
                                               java.lang.String url)
                                        throws java.lang.Exception
        Read product ids (as urns) from database and submit to executor for processing.
        Parameters:
        driver - database driver
        url - database url
        Throws:
        java.lang.Exception - exception
      • readProductIdsFromStdin

        public void readProductIdsFromStdin()
                                     throws java.lang.Exception
        Read product ids (as urns) from stdin and submit to executor for processing.
        Throws:
        java.lang.Exception - Exception
      • submitProductId

        public void submitProductId​(ProductId id)
                             throws java.lang.InterruptedException
        Submit a product id to the executor service for processing. If queue is too large (500 ids), blocks until queue is smaller (100 ids).
        Parameters:
        id - which product
        Throws:
        java.lang.InterruptedException - InterruptedException