diff --git a/ucoinj-elasticsearch-plugin/src/main/filtered-resources/plugin-descriptor.properties b/ucoinj-elasticsearch-plugin/src/main/filtered-resources/plugin-descriptor.properties index e161442c5e8ab9aca86ba906e2d8c3b111d5ecf1..7960daf87a68f056f195609c9965c5d886b34736 100644 --- a/ucoinj-elasticsearch-plugin/src/main/filtered-resources/plugin-descriptor.properties +++ b/ucoinj-elasticsearch-plugin/src/main/filtered-resources/plugin-descriptor.properties @@ -1,6 +1,8 @@ name=ucoinj-elasticsearch -description=${project.description} -version=${project.version} +#description=${project.description} +description=ucoinj-elasticsearch +version=1.0 +#version=${project.version} site=false jvm=true classname=io.ucoin.ucoinj.elasticsearch.plugin.Plugin diff --git a/ucoinj-elasticsearch-plugin/src/main/java/io/ucoin/ucoinj/elasticsearch/action/RestModule.java b/ucoinj-elasticsearch-plugin/src/main/java/io/ucoin/ucoinj/elasticsearch/action/RestModule.java index 99726aba0a93cd0ba3c2497520bcaca26c573793..af97463d16628aae8631bf3f140b145a7e2acd08 100644 --- a/ucoinj-elasticsearch-plugin/src/main/java/io/ucoin/ucoinj/elasticsearch/action/RestModule.java +++ b/ucoinj-elasticsearch-plugin/src/main/java/io/ucoin/ucoinj/elasticsearch/action/RestModule.java @@ -1,7 +1,7 @@ package io.ucoin.ucoinj.elasticsearch.action; import io.ucoin.ucoinj.elasticsearch.action.currency.RestCurrencyIndexAction; -import io.ucoin.ucoinj.elasticsearch.action.product.RestProductIndexAction; +import io.ucoin.ucoinj.elasticsearch.action.product.RestRecordIndexAction; import io.ucoin.ucoinj.elasticsearch.action.security.RestSecurityAuthAction; import io.ucoin.ucoinj.elasticsearch.action.security.RestSecurityGetChallengeAction; import org.elasticsearch.common.inject.AbstractModule; @@ -12,7 +12,7 @@ public class RestModule extends AbstractModule implements Module { @Override protected void configure() { bind(RestCurrencyIndexAction.class).asEagerSingleton(); - bind(RestProductIndexAction.class).asEagerSingleton(); + bind(RestRecordIndexAction.class).asEagerSingleton(); bind(RestSecurityGetChallengeAction.class).asEagerSingleton(); bind(RestSecurityAuthAction.class).asEagerSingleton(); diff --git a/ucoinj-elasticsearch-plugin/src/main/java/io/ucoin/ucoinj/elasticsearch/action/product/RestProductIndexAction.java b/ucoinj-elasticsearch-plugin/src/main/java/io/ucoin/ucoinj/elasticsearch/action/product/RestRecordIndexAction.java similarity index 68% rename from ucoinj-elasticsearch-plugin/src/main/java/io/ucoin/ucoinj/elasticsearch/action/product/RestProductIndexAction.java rename to ucoinj-elasticsearch-plugin/src/main/java/io/ucoin/ucoinj/elasticsearch/action/product/RestRecordIndexAction.java index 0b55e0dfa06b7f0cff5b037e71fdae4dfbaa2cdb..ccb682c85416db4ddd72305faa9b22c8e949c8b5 100644 --- a/ucoinj-elasticsearch-plugin/src/main/java/io/ucoin/ucoinj/elasticsearch/action/product/RestProductIndexAction.java +++ b/ucoinj-elasticsearch-plugin/src/main/java/io/ucoin/ucoinj/elasticsearch/action/product/RestRecordIndexAction.java @@ -11,20 +11,20 @@ import org.elasticsearch.rest.*; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestStatus.OK; -public class RestProductIndexAction extends BaseRestHandler { +public class RestRecordIndexAction extends BaseRestHandler { - private static final ESLogger log = ESLoggerFactory.getLogger(RestProductIndexAction.class.getName()); + private static final ESLogger log = ESLoggerFactory.getLogger(RestRecordIndexAction.class.getName()); @Inject - public RestProductIndexAction(Settings settings, RestController controller, Client client) { + public RestRecordIndexAction(Settings settings, RestController controller, Client client) { super(settings, controller, client); - controller.registerHandler(POST, "/product", this); + controller.registerHandler(POST, "/store/record", this); } @Override protected void handleRequest(final RestRequest request, RestChannel restChannel, Client client) throws Exception { - String productId = ServiceLocator.instance().getProductIndexerService().indexProductFromJson(request.content().toUtf8()); + String productId = ServiceLocator.instance().getRecordIndexerService().indexRecordFromJson(request.content().toUtf8()); restChannel.sendResponse(new BytesRestResponse(OK, productId)); } diff --git a/ucoinj-elasticsearch-plugin/src/test/es-home/config/elasticsearch.yml b/ucoinj-elasticsearch-plugin/src/test/es-home/config/elasticsearch.yml new file mode 100644 index 0000000000000000000000000000000000000000..385de0467da2cffb0690251875b262c660595462 --- /dev/null +++ b/ucoinj-elasticsearch-plugin/src/test/es-home/config/elasticsearch.yml @@ -0,0 +1,96 @@ +# ======================== Elasticsearch Configuration ========================= +# +# NOTE: Elasticsearch comes with reasonable defaults for most settings. +# Before you set out to tweak and tune the configuration, make sure you +# understand what are you trying to accomplish and the consequences. +# +# The primary way of configuring a node is via this file. This template lists +# the most important settings you may want to configure for a production cluster. +# +# Please see the documentation for further information on configuration options: +# <http://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration.html> +# +# ---------------------------------- Cluster ----------------------------------- +# +# Use a descriptive name for your cluster: +# +# cluster.name: my-application +# +# ------------------------------------ Node ------------------------------------ +# +# Use a descriptive name for the node: +# +# node.name: node-1 +# +# Add custom attributes to the node: +# +# node.rack: r1 +# +# ----------------------------------- Paths ------------------------------------ +# +# Path to directory where to store the data (separate multiple locations by comma): +# +# path.data: /path/to/data +# +# Path to log files: +# +# path.logs: /path/to/logs +# +# ----------------------------------- Memory ----------------------------------- +# +# Lock the memory on startup: +# +# bootstrap.mlockall: true +# +# Make sure that the `ES_HEAP_SIZE` environment variable is set to about half the memory +# available on the system and that the owner of the process is allowed to use this limit. +# +# Elasticsearch performs poorly when the system is swapping the memory. +# +# ---------------------------------- Network ----------------------------------- +# +# Set the bind address to a specific IP (IPv4 or IPv6): +# +# network.host: 192.168.0.1 +# +# Set a custom port for HTTP: +# +http.port: 9292 +# +# For more information, see the documentation at: +# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html> +# +# ---------------------------------- Gateway ----------------------------------- +# +# Block initial recovery after a full cluster restart until N nodes are started: +# +# gateway.recover_after_nodes: 3 +# +# For more information, see the documentation at: +# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-gateway.html> +# +# --------------------------------- Discovery ---------------------------------- +# +# Elasticsearch nodes will find each other via unicast, by default. +# +# Pass an initial list of hosts to perform discovery when new node is started: +# The default list of hosts is ["127.0.0.1", "[::1]"] +# +# discovery.zen.ping.unicast.hosts: ["host1", "host2"] +# +# Prevent the "split brain" by configuring the majority of nodes (total number of nodes / 2 + 1): +# +# discovery.zen.minimum_master_nodes: 3 +# +# For more information, see the documentation at: +# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-discovery.html> +# +# ---------------------------------- Various ----------------------------------- +# +# Disable starting multiple nodes on a single system: +# +# node.max_local_storage_nodes: 1 +# +# Require explicit names when deleting indices: +# +# action.destructive_requires_name: true diff --git a/ucoinj-elasticsearch-plugin/src/test/es-home/config/logging.yml b/ucoinj-elasticsearch-plugin/src/test/es-home/config/logging.yml new file mode 100644 index 0000000000000000000000000000000000000000..939aa1eed0ef7c035b173d8ea0905743b618f9d1 --- /dev/null +++ b/ucoinj-elasticsearch-plugin/src/test/es-home/config/logging.yml @@ -0,0 +1,85 @@ +# you can override this using by setting a system property, for example -Des.logger.level=DEBUG +es.logger.level: INFO +rootLogger: ${es.logger.level}, console, file +logger: + # log action execution errors for easier debugging + action: DEBUG + + # deprecation logging, turn to DEBUG to see them + deprecation: INFO, deprecation_log_file + + # reduce the logging for aws, too much is logged under the default INFO + com.amazonaws: WARN + # aws will try to do some sketchy JMX stuff, but its not needed. + com.amazonaws.jmx.SdkMBeanRegistrySupport: ERROR + com.amazonaws.metrics.AwsSdkMetrics: ERROR + + org.apache.http: INFO + + # gateway + #gateway: DEBUG + #index.gateway: DEBUG + + # peer shard recovery + #indices.recovery: DEBUG + + # discovery + #discovery: TRACE + + index.search.slowlog: TRACE, index_search_slow_log_file + index.indexing.slowlog: TRACE, index_indexing_slow_log_file + +additivity: + index.search.slowlog: false + index.indexing.slowlog: false + deprecation: false + +appender: + console: + type: console + layout: + type: consolePattern + conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %m%n" + + file: + type: dailyRollingFile + file: ${path.logs}/${cluster.name}.log + datePattern: "'.'yyyy-MM-dd" + layout: + type: pattern + conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %.10000m%n" + + # Use the following log4j-extras RollingFileAppender to enable gzip compression of log files. + # For more information see https://logging.apache.org/log4j/extras/apidocs/org/apache/log4j/rolling/RollingFileAppender.html + #file: + #type: extrasRollingFile + #file: ${path.logs}/${cluster.name}.log + #rollingPolicy: timeBased + #rollingPolicy.FileNamePattern: ${path.logs}/${cluster.name}.log.%d{yyyy-MM-dd}.gz + #layout: + #type: pattern + #conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %m%n" + + deprecation_log_file: + type: dailyRollingFile + file: ${path.logs}/${cluster.name}_deprecation.log + datePattern: "'.'yyyy-MM-dd" + layout: + type: pattern + conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %m%n" + + index_search_slow_log_file: + type: dailyRollingFile + file: ${path.logs}/${cluster.name}_index_search_slowlog.log + datePattern: "'.'yyyy-MM-dd" + layout: + type: pattern + conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %m%n" + + index_indexing_slow_log_file: + type: dailyRollingFile + file: ${path.logs}/${cluster.name}_index_indexing_slowlog.log + datePattern: "'.'yyyy-MM-dd" + layout: + type: pattern + conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %m%n" diff --git a/ucoinj-elasticsearch/src/main/filtered-resources/log4j.properties b/ucoinj-elasticsearch/src/main/filtered-resources/log4j.properties index 377ad53caf3f07bd89e9faf6fca928a3e0410ef3..6cf6649f438e305729b2a5e3422dc3b5b92d56aa 100644 --- a/ucoinj-elasticsearch/src/main/filtered-resources/log4j.properties +++ b/ucoinj-elasticsearch/src/main/filtered-resources/log4j.properties @@ -12,7 +12,7 @@ log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} %5p %m%n log4j.logger.io.ucoin.ucoinj=INFO #log4j.logger.io.ucoin.ucoinj.core.client=DEBUG #log4j.logger.io.ucoin.ucoinj.core.client.service=DEBUG -#log4j.logger.io.ucoin.ucoinj.elasticsearch=DEBUG +log4j.logger.io.ucoin.ucoinj.elasticsearch=DEBUG # Other frameworks levels log4j.logger.org.nuiton.util=WARN diff --git a/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/action/HelpAction.java b/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/action/HelpAction.java index ea8f698804d3e5fbccd3f74d163d0edd18e218c9..83a288025b83ccdd40facef0263dce432bc80f69 100644 --- a/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/action/HelpAction.java +++ b/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/action/HelpAction.java @@ -33,8 +33,9 @@ public class HelpAction { .append("Commands:\n\n") .append(" start Start elastic search node\n") .append(" index Index blocks from BMA Node\n") - .append(" reset-data Reset indexed data for the uCoin node's currency\n") - .append(" reset-data-product Reset indexed products data\n") + .append(" reset-data Reset all indexed data (blocks and records)\n") + .append(" reset-data-blocks Reset only indexed blocks (from uCoin node's)\n") + .append(" reset-data-records Reset only indexed records\n") .append("\n") .append("\n") .append("Options:\n\n") diff --git a/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/action/IndexerAction.java b/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/action/IndexerAction.java index 0e6d117a62f314ee2a067a9a87bfa46104077a25..2da45cb323a7287195961d9d428b7b0b30ac3709 100644 --- a/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/action/IndexerAction.java +++ b/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/action/IndexerAction.java @@ -32,7 +32,7 @@ import io.ucoin.ucoinj.core.util.websocket.WebsocketClientEndpoint; import io.ucoin.ucoinj.elasticsearch.config.Configuration; import io.ucoin.ucoinj.elasticsearch.service.BlockIndexerService; import io.ucoin.ucoinj.elasticsearch.service.CategoryIndexerService; -import io.ucoin.ucoinj.elasticsearch.service.ProductIndexerService; +import io.ucoin.ucoinj.elasticsearch.service.RecordIndexerService; import io.ucoin.ucoinj.elasticsearch.service.ServiceLocator; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; @@ -42,7 +42,7 @@ public class IndexerAction { /* Logger */ private static final Logger log = LoggerFactory.getLogger(IndexerAction.class); - public void indexation() { + public void indexBlocksFromNode() { final boolean async = ServiceLocator.instance().getElasticSearchService().isNodeInstance(); @@ -78,7 +78,12 @@ public class IndexerAction { } } - public void resetCurrencyBlocks() { + public void resetAllData() { + resetDataBlocks(); + resetDataRecords(); + } + + public void resetDataBlocks() { BlockchainRemoteService blockchainService = ServiceLocator.instance().getBlockchainRemoteService(); BlockIndexerService indexerService = ServiceLocator.instance().getBlockIndexerService(); Configuration config = Configuration.instance(); @@ -110,42 +115,28 @@ public class IndexerAction { } } - public void resetProducts() { - ProductIndexerService productIndexerService = ServiceLocator.instance().getProductIndexerService(); - - try { - // Delete then create index on product - boolean indexExists = productIndexerService.existsIndex(); - if (indexExists) { - productIndexerService.deleteIndex(); - } - log.info(String.format("Successfully reset products data")); - } catch(Exception e) { - log.error("Error during reset products data: " + e.getMessage(), e); - } - } - - public void resetCategories() { + public void resetDataRecords() { + RecordIndexerService recordIndexerService = ServiceLocator.instance().getRecordIndexerService(); CategoryIndexerService categoryIndexerService = ServiceLocator.instance().getCategoryIndexerService(); try { - // Delete then create index on product - boolean indexExists = categoryIndexerService.existsIndex(); + // Delete then create index on records + boolean indexExists = recordIndexerService.existsIndex(); if (indexExists) { - categoryIndexerService.deleteIndex(); + recordIndexerService.deleteIndex(); } + log.info(String.format("Successfully reset products data")); - // Init data categoryIndexerService.createIndex(); categoryIndexerService.initCategories(); - log.info(String.format("Successfully re-initialized categories data")); + } catch(Exception e) { - log.error("Error during reset categories data: " + e.getMessage(), e); + log.error("Error during reset products data: " + e.getMessage(), e); } } - /* -- -- */ + /* -- internal methods -- */ protected Peer checkConfigAndGetPeer(Configuration config) { if (StringUtils.isBlank(config.getNodeBmaHost())) { diff --git a/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/action/NodeAction.java b/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/action/NodeAction.java index 3c6f45cecf92af2f4681e63c9bf1211d2a02a11c..68746b7d66615de83ab8b9511bc045663aa6ae32 100644 --- a/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/action/NodeAction.java +++ b/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/action/NodeAction.java @@ -24,15 +24,11 @@ package io.ucoin.ucoinj.elasticsearch.action; * #L% */ -import io.ucoin.ucoinj.core.util.CommandLinesUtils; -import io.ucoin.ucoinj.core.util.StringUtils; import io.ucoin.ucoinj.elasticsearch.config.Configuration; import io.ucoin.ucoinj.elasticsearch.service.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; - public class NodeAction { /* Logger */ private static final Logger log = LoggerFactory.getLogger(NodeAction.class); @@ -78,8 +74,8 @@ public class NodeAction { currencyIndexerService.createIndexIfNotExists(); // Product index - ProductIndexerService productIndexerService = ServiceLocator.instance().getProductIndexerService(); - productIndexerService.createIndexIfNotExists(); + RecordIndexerService recordIndexerService = ServiceLocator.instance().getRecordIndexerService(); + recordIndexerService.createIndexIfNotExists(); // Category index CategoryIndexerService categoryIndexerService = ServiceLocator.instance().getCategoryIndexerService(); diff --git a/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/config/ConfigurationAction.java b/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/config/ConfigurationAction.java index 22b0afdc4e777fac0f5011ecd2ab699d8827215f..ee21bd1b4b17c84cb935a0184a2414278877cafd 100644 --- a/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/config/ConfigurationAction.java +++ b/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/config/ConfigurationAction.java @@ -35,13 +35,13 @@ public enum ConfigurationAction implements ConfigActionDef { START(NodeAction.class.getName() + "#start", "start"), - INDEX_BLOCKS(IndexerAction.class.getName() + "#indexation", "index"), + INDEX_BLOCKS(IndexerAction.class.getName() + "#indexBlocksFromNode", "index"), - RESET_BLOCKS(IndexerAction.class.getName() + "#resetCurrencyBlocks", "reset-data"), + RESET_ALL_DATA(IndexerAction.class.getName() + "#resetAllData", "reset-data"), - RESET_PRODUCTS(IndexerAction.class.getName() + "#resetProducts", "reset-products"), + RESET_BLOCKS(IndexerAction.class.getName() + "#resetDataBlocks", "reset-data-blocks"), - RESET_CATEGORIES(IndexerAction.class.getName() + "#resetCategories", "reset-categories"); + RESET_RECORDS(IndexerAction.class.getName() + "#resetDataRecords", "reset-data-records"); public String action; diff --git a/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/service/BlockIndexerService.java b/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/service/BlockIndexerService.java index b8f992d7aa5c3f60f7ae31ba2cfa2bca16fa5ea9..8469dc6c12fa7f3489eedc81b04ed7437be6d846 100644 --- a/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/service/BlockIndexerService.java +++ b/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/service/BlockIndexerService.java @@ -215,7 +215,7 @@ public class BlockIndexerService extends BaseIndexerService { } } } catch(Exception e) { - log.error("Error during indexation: " + e.getMessage(), e); + log.error("Error during indexBlocksFromNode: " + e.getMessage(), e); progressionModel.setStatus(ProgressionModel.Status.FAILED); } } @@ -265,7 +265,7 @@ public class BlockIndexerService extends BaseIndexerService { * Create or update a block, depending on its existence and hash * @param block * @param updateWhenSameHash if true, always update an existing block. If false, update only if hash has changed. - * @param wait wait indexation end + * @param wait wait indexBlocksFromNode end * @throws DuplicateIndexIdException */ public void saveBlock(BlockchainBlock block, boolean updateWhenSameHash, boolean wait) throws DuplicateIndexIdException { @@ -324,12 +324,12 @@ public class BlockIndexerService extends BaseIndexerService { // WARN: must use GSON, to have same JSON result (e.g identities and joiners field must be converted into String) String json = gson.toJson(block); - // Preparing indexation + // Preparing indexBlocksFromNode IndexRequestBuilder indexRequest = getClient().prepareIndex(block.getCurrency(), INDEX_TYPE_BLOCK) .setId(block.getNumber().toString()) .setSource(json); - // Execute indexation + // Execute indexBlocksFromNode ActionFuture<IndexResponse> futureResponse = indexRequest .setRefresh(true) .execute(); @@ -349,13 +349,13 @@ public class BlockIndexerService extends BaseIndexerService { ObjectUtils.checkNotNull(json); ObjectUtils.checkArgument(json.length > 0); - // Preparing indexation + // Preparing indexBlocksFromNode IndexRequestBuilder indexRequest = getClient().prepareIndex(currencyName, INDEX_TYPE_BLOCK) .setId(String.valueOf(number)) .setRefresh(refresh) .setSource(json); - // Execute indexation + // Execute indexBlocksFromNode if (!wait) { indexRequest.execute(); } @@ -382,13 +382,13 @@ public class BlockIndexerService extends BaseIndexerService { log.info(I18n.t("ucoinj.blockIndexerService.indexBlock", currencyName, peer, number)); - // Preparing indexation + // Preparing indexBlocksFromNode IndexRequestBuilder indexRequest = getClient().prepareIndex(currencyName, INDEX_TYPE_BLOCK) .setId(String.valueOf(number)) .setRefresh(refresh) .setSource(json); - // Execute indexation + // Execute indexBlocksFromNode if (!wait) { indexRequest.execute(); } @@ -424,13 +424,13 @@ public class BlockIndexerService extends BaseIndexerService { ObjectUtils.checkNotNull(currentBlockJson); ObjectUtils.checkArgument(currentBlockJson.length() > 0); - // Preparing indexation + // Preparing indexBlocksFromNode IndexRequestBuilder indexRequest = getClient().prepareIndex(currencyName, INDEX_TYPE_BLOCK) .setId(INDEX_BLOCK_CURRENT_ID) .setRefresh(true) .setSource(currentBlockJson); - // Execute indexation + // Execute indexBlocksFromNode if (!wait) { boolean acceptedInPool = false; while(!acceptedInPool) diff --git a/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/service/CategoryIndexerService.java b/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/service/CategoryIndexerService.java index 548cb3d473e350f0a822a530a231ab1d188099e9..68cac548ef6bcdc9c52bd51b50604c8101c0bf0e 100644 --- a/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/service/CategoryIndexerService.java +++ b/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/service/CategoryIndexerService.java @@ -58,7 +58,7 @@ public class CategoryIndexerService extends BaseIndexerService { private static final Logger log = LoggerFactory.getLogger(CategoryIndexerService.class); - public static final String INDEX_NAME = "product"; + public static final String INDEX_NAME = "store"; public static final String INDEX_TYPE = "category"; private Gson gson; @@ -137,11 +137,11 @@ public class CategoryIndexerService extends BaseIndexerService { log.debug("Indexing a category"); } - // Preparing indexation + // Preparing indexBlocksFromNode IndexRequestBuilder indexRequest = getClient().prepareIndex(INDEX_NAME, INDEX_TYPE) .setSource(jsonCategory); - // Execute indexation + // Execute indexBlocksFromNode IndexResponse response = indexRequest .setRefresh(false) .execute().actionGet(); diff --git a/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/service/CurrencyIndexerService.java b/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/service/CurrencyIndexerService.java index fb7589f9a4ffce884b2eab0ce0a179daa4737246..d215e2c69afad98c5a3c24a4a84c5d5e20efc350 100644 --- a/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/service/CurrencyIndexerService.java +++ b/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/service/CurrencyIndexerService.java @@ -206,12 +206,12 @@ public class CurrencyIndexerService extends BaseIndexerService { // Serialize into JSON byte[] json = getObjectMapper().writeValueAsBytes(currency); - // Preparing indexation + // Preparing indexBlocksFromNode IndexRequestBuilder indexRequest = getClient().prepareIndex(INDEX_NAME, INDEX_TYPE_SIMPLE) .setId(currency.getCurrencyName()) .setSource(json); - // Execute indexation + // Execute indexBlocksFromNode indexRequest .setRefresh(true) .execute().actionGet(); diff --git a/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/service/ProductIndexerService.java b/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/service/RecordIndexerService.java similarity index 68% rename from ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/service/ProductIndexerService.java rename to ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/service/RecordIndexerService.java index dd9ebd03c0dcef9d84cd9359f5be588cb3460379..d68597c9740144a3ded4bd9f3421e8ac22c76f24 100644 --- a/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/service/ProductIndexerService.java +++ b/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/service/RecordIndexerService.java @@ -24,70 +24,31 @@ package io.ucoin.ucoinj.elasticsearch.service; import com.fasterxml.jackson.core.JsonProcessingException; -import com.google.common.base.Objects; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Lists; import com.google.gson.Gson; -import io.ucoin.ucoinj.core.client.model.bma.BlockchainBlock; -import io.ucoin.ucoinj.core.client.model.bma.BlockchainParameters; -import io.ucoin.ucoinj.core.client.model.bma.EndpointProtocol; import io.ucoin.ucoinj.core.client.model.bma.gson.GsonUtils; -import io.ucoin.ucoinj.core.client.model.bma.gson.JsonAttributeParser; -import io.ucoin.ucoinj.core.client.model.elasticsearch.Currency; -import io.ucoin.ucoinj.core.client.model.local.Peer; -import io.ucoin.ucoinj.core.client.service.bma.BlockchainRemoteService; -import io.ucoin.ucoinj.core.client.service.bma.NetworkRemoteService; import io.ucoin.ucoinj.core.client.service.bma.WotRemoteService; -import io.ucoin.ucoinj.core.client.service.exception.HttpBadRequestException; -import io.ucoin.ucoinj.core.client.service.exception.JsonSyntaxException; import io.ucoin.ucoinj.core.exception.TechnicalException; -import io.ucoin.ucoinj.core.model.ProgressionModel; -import io.ucoin.ucoinj.core.model.ProgressionModelImpl; -import io.ucoin.ucoinj.core.util.CollectionUtils; -import io.ucoin.ucoinj.core.util.ObjectUtils; -import io.ucoin.ucoinj.core.util.StringUtils; import io.ucoin.ucoinj.elasticsearch.config.Configuration; -import io.ucoin.ucoinj.elasticsearch.service.exception.DuplicateIndexIdException; -import org.apache.commons.lang3.ArrayUtils; -import org.elasticsearch.action.ActionFuture; import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; -import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; -import org.elasticsearch.action.bulk.BulkItemResponse; -import org.elasticsearch.action.bulk.BulkRequestBuilder; -import org.elasticsearch.action.bulk.BulkResponse; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.index.IndexResponse; -import org.elasticsearch.action.search.SearchRequestBuilder; -import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.action.search.SearchType; -import org.elasticsearch.client.Client; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.search.SearchHit; -import org.elasticsearch.search.SearchHitField; -import org.elasticsearch.search.aggregations.AggregationBuilders; -import org.elasticsearch.search.aggregations.metrics.max.Max; -import org.elasticsearch.search.highlight.HighlightField; -import org.elasticsearch.search.sort.SortOrder; -import org.nuiton.i18n.I18n; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; -import java.util.*; /** * Created by Benoit on 30/03/2015. */ -public class ProductIndexerService extends BaseIndexerService { +public class RecordIndexerService extends BaseIndexerService { - private static final Logger log = LoggerFactory.getLogger(ProductIndexerService.class); + private static final Logger log = LoggerFactory.getLogger(RecordIndexerService.class); - public static final String INDEX_NAME = "product"; - public static final String INDEX_TYPE_SIMPLE = "simple"; + public static final String INDEX_NAME = "store"; + public static final String INDEX_TYPE_SIMPLE = "record"; private Gson gson; @@ -95,7 +56,7 @@ public class ProductIndexerService extends BaseIndexerService { private WotRemoteService wotRemoteService; - public ProductIndexerService() { + public RecordIndexerService() { gson = GsonUtils.newBuilder().create(); } @@ -142,7 +103,7 @@ public class ProductIndexerService extends BaseIndexerService { } /** - * Create index need for product registry + * Create index need for record registry * @throws JsonProcessingException */ public void createIndex() throws JsonProcessingException { @@ -161,19 +122,19 @@ public class ProductIndexerService extends BaseIndexerService { /** * - * @param productJson - * @return the product id + * @param recordJson + * @return the record id */ - public String indexProductFromJson(String productJson) { + public String indexRecordFromJson(String recordJson) { if (log.isDebugEnabled()) { - log.debug("Indexing a product"); + log.debug("Indexing a record"); } - // Preparing indexation + // Preparing indexBlocksFromNode IndexRequestBuilder indexRequest = getClient().prepareIndex(INDEX_NAME, INDEX_TYPE_SIMPLE) - .setSource(productJson); + .setSource(recordJson); - // Execute indexation + // Execute indexBlocksFromNode IndexResponse response = indexRequest .setRefresh(false) .execute().actionGet(); diff --git a/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/service/ServiceLocator.java b/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/service/ServiceLocator.java index ec49163e131f010b5a6bee846fbf14924daf0b25..d094fe14dc9e3cfff36b59fd24af0f84588733c0 100644 --- a/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/service/ServiceLocator.java +++ b/ucoinj-elasticsearch/src/main/java/io/ucoin/ucoinj/elasticsearch/service/ServiceLocator.java @@ -63,8 +63,8 @@ public class ServiceLocator extends io.ucoin.ucoinj.core.client.service.ServiceL return getBean(ExecutorService.class); } - public ProductIndexerService getProductIndexerService() { - return getBean(ProductIndexerService.class); + public RecordIndexerService getRecordIndexerService() { + return getBean(RecordIndexerService.class); } public CategoryIndexerService getCategoryIndexerService() { diff --git a/ucoinj-elasticsearch/src/main/resources/META-INF/services/io.ucoin.ucoinj.core.beans.Bean b/ucoinj-elasticsearch/src/main/resources/META-INF/services/io.ucoin.ucoinj.core.beans.Bean index 71b3337f6991940a68763d1151c41946d871c86d..3c97b16d92056f466d440d71cae4ced209543e5a 100644 --- a/ucoinj-elasticsearch/src/main/resources/META-INF/services/io.ucoin.ucoinj.core.beans.Bean +++ b/ucoinj-elasticsearch/src/main/resources/META-INF/services/io.ucoin.ucoinj.core.beans.Bean @@ -12,7 +12,7 @@ io.ucoin.ucoinj.core.client.dao.mem.MemoryCurrencyDaoImpl io.ucoin.ucoinj.core.client.dao.mem.MemoryPeerDaoImpl io.ucoin.ucoinj.elasticsearch.service.ElasticSearchService io.ucoin.ucoinj.elasticsearch.service.CurrencyIndexerService -io.ucoin.ucoinj.elasticsearch.service.ProductIndexerService +io.ucoin.ucoinj.elasticsearch.service.RecordIndexerService io.ucoin.ucoinj.elasticsearch.service.BlockIndexerService io.ucoin.ucoinj.elasticsearch.service.ExecutorServiceImpl io.ucoin.ucoinj.elasticsearch.service.CategoryIndexerService