Commit 45c4723c authored by Benoit Lavenier's avatar Benoit Lavenier

[enh] Allow to override default endpoint API for core module

parent f460f5a6
Pipeline #4716 failed
......@@ -182,6 +182,10 @@ duniter.security.enable: true
#
# duniter.p2p.enable: false
#
# Endpoint API for core module (indices on blockchain, peers, etc) (default: ES_CORE_API)
#
# duniter.core.api: MY_CUSTOM_API
#
# Enable P2P synchronisation using websocket ? (default: true)
#
# duniter.p2p.ws.enable: false
......
......@@ -182,6 +182,10 @@ duniter.security.enable: true
#
# duniter.p2p.enable: false
#
# Endpoint API for core module (indices on blockchain, peers, etc) (default: ES_CORE_API)
#
# duniter.core.api: MY_CUSTOM_API
#
# Enable P2P synchronisation using websocket ? (default: true)
#
# duniter.p2p.ws.enable: false
......
......@@ -73,6 +73,7 @@ public class PluginSettings extends AbstractLifecycleComponent<PluginSettings> {
private String clusterRemoteUrl;
private final CryptoService cryptoService;
private final EndpointApi coreEnpointApi;
/**
* Delegate application config.
......@@ -95,6 +96,18 @@ public class PluginSettings extends AbstractLifecycleComponent<PluginSettings> {
// Set the default bundle name
addI18nBundleName(getI18nBundleName());
// Allow to redefine user api
EndpointApi endpointApi = EndpointApi.ES_CORE_API; // default value
String apiName = settings.get("duniter.core.api");
if (StringUtils.isNotBlank(apiName)) {
try {
endpointApi = EndpointApi.valueOf(apiName);
} catch (Exception e) {
logger.warn(String.format("Invalid subscription endpoint API define ni settings {duniter.core.api: %s}. Will use default value {%s}", apiName, endpointApi));
}
}
this.coreEnpointApi = endpointApi;
}
@Override
......@@ -229,6 +242,10 @@ public class PluginSettings extends AbstractLifecycleComponent<PluginSettings> {
/* -- Other settings -- */
public EndpointApi getCoreEnpointApi() {
return coreEnpointApi;
}
public boolean isIndexBulkEnable() {
return settings.getAsBoolean("duniter.bulk.enable", true);
}
......
......@@ -103,10 +103,10 @@ public class NetworkService extends AbstractService {
});
// Register ES_CORE_API as published API, inside the peering document
registerPeeringPublishApi(EndpointApi.ES_CORE_API);
registerPeeringPublishApi(pluginSettings.getCoreEnpointApi());
// Register ES_CORE_API as target API, for peering document
registerPeeringTargetApi(EndpointApi.ES_CORE_API);
registerPeeringTargetApi(pluginSettings.getCoreEnpointApi());
}
protected List<Peer> getConfigIncludesPeers(final String currencyId) {
......
......@@ -60,6 +60,7 @@ public class ServiceModule extends AbstractModule implements Module {
// Wot service
bind(WotService.class).asEagerSingleton();
bind(NetworkService.class).asEagerSingleton();
// Duniter Client API beans
bindWithLocator(BlockchainRemoteService.class);
......
......@@ -23,17 +23,11 @@ package org.duniter.elasticsearch.subscription;
*/
import org.duniter.elasticsearch.service.DocStatService;
import org.duniter.elasticsearch.service.NetworkService;
import org.duniter.elasticsearch.subscription.dao.SubscriptionIndexDao;
import org.duniter.elasticsearch.subscription.dao.record.SubscriptionRecordDao;
import org.duniter.elasticsearch.subscription.service.SubscriptionService;
import org.duniter.elasticsearch.threadpool.ThreadPool;
import org.duniter.elasticsearch.user.dao.group.GroupCommentDao;
import org.duniter.elasticsearch.user.dao.group.GroupIndexDao;
import org.duniter.elasticsearch.user.dao.group.GroupRecordDao;
import org.duniter.elasticsearch.user.dao.page.PageCommentDao;
import org.duniter.elasticsearch.user.dao.page.PageIndexDao;
import org.duniter.elasticsearch.user.dao.page.PageRecordDao;
import org.duniter.elasticsearch.user.service.*;
import org.elasticsearch.common.component.AbstractLifecycleComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.inject.Injector;
......@@ -62,6 +56,9 @@ public class PluginInit extends AbstractLifecycleComponent<PluginInit> {
@Override
protected void doStart() {
// Configure network
configureNetwork();
threadPool.scheduleOnClusterReady(() -> {
createIndices();
......@@ -80,6 +77,12 @@ public class PluginInit extends AbstractLifecycleComponent<PluginInit> {
}
protected void configureNetwork() {
// Register API to network service
injector.getInstance(NetworkService.class)
.registerPeeringPublishApi(pluginSettings.getSubscriptionEndpointApi());
}
protected void createIndices() {
boolean reloadIndices = pluginSettings.reloadIndices();
......
package org.duniter.elasticsearch.subscription.service;
import org.duniter.core.beans.Bean;
import org.duniter.core.client.model.bma.EndpointApi;
import org.duniter.elasticsearch.service.NetworkService;
import org.duniter.elasticsearch.subscription.PluginSettings;
import org.elasticsearch.common.inject.Inject;
public class NetworkServiceConfiguration implements Bean {
@Inject
public NetworkServiceConfiguration(PluginSettings pluginSettings,
NetworkService networkService) {
if (pluginSettings.enableSubscription()) {
// Register ES_SUBSCRIPTION_API, as an API to publish inside the peer document
networkService.registerPeeringPublishApi(EndpointApi.ES_SUBSCRIPTION_API);
}
}
}
......@@ -30,8 +30,5 @@ public class ServiceModule extends AbstractModule implements Module {
@Override protected void configure() {
// Subscription services
bind(SubscriptionService.class).asEagerSingleton();
// Configure network
bind(NetworkServiceConfiguration.class).asEagerSingleton();
}
}
\ No newline at end of file
......@@ -5,7 +5,7 @@
# 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.
# the most important settings you may want to configureNetwork 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>
......
......@@ -32,7 +32,6 @@ import org.elasticsearch.common.component.LifecycleComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.ESLoggerFactory;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
......
......@@ -23,6 +23,7 @@ package org.duniter.elasticsearch.user;
*/
import org.duniter.elasticsearch.service.DocStatService;
import org.duniter.elasticsearch.service.NetworkService;
import org.duniter.elasticsearch.threadpool.ThreadPool;
import org.duniter.elasticsearch.user.dao.group.GroupCommentDao;
import org.duniter.elasticsearch.user.dao.group.GroupIndexDao;
......@@ -64,6 +65,8 @@ public class PluginInit extends AbstractLifecycleComponent<PluginInit> {
@Override
protected void doStart() {
configureNetwork();
threadPool.scheduleOnClusterReady(() -> {
createIndices();
......@@ -83,8 +86,13 @@ public class PluginInit extends AbstractLifecycleComponent<PluginInit> {
}
protected void createIndices() {
protected void configureNetwork() {
// Register API to network service
injector.getInstance(NetworkService.class)
.registerPeeringPublishApi(pluginSettings.getUserEndpointApi());
}
protected void createIndices() {
// Reload all indices
if (pluginSettings.reloadAllIndices()) {
if (logger.isInfoEnabled()) {
......
package org.duniter.elasticsearch.user.service;
import org.duniter.core.beans.Bean;
import org.duniter.core.client.model.bma.EndpointApi;
import org.duniter.elasticsearch.service.NetworkService;
import org.elasticsearch.common.inject.Inject;
public class NetworkServiceConfiguration implements Bean {
@Inject
public NetworkServiceConfiguration(NetworkService networkService) {
// Register ES_USER_API, as an API to publish inside the peer document
networkService.registerPeeringPublishApi(EndpointApi.ES_USER_API);
}
}
......@@ -43,9 +43,6 @@ public class ServiceModule extends AbstractModule implements Module {
bind(UserInvitationService.class).asEagerSingleton();
bind(BlockchainUserEventService.class).asEagerSingleton();
// Configure the P2P network
bind(NetworkServiceConfiguration.class).asEagerSingleton();
}
/* protected methods */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment