Skip to content

Commit

Permalink
- Fix market/registry record storage
Browse files Browse the repository at this point in the history
 - Disable CORS
  • Loading branch information
blavenie committed Jun 21, 2016
1 parent 26982b4 commit 22bf887
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@
public class RestModule extends AbstractModule implements Module {

@Override protected void configure() {
//bind(RestCurrencyIndexAction.class).asEagerSingleton();

bind(RestCurrencyIndexAction.class).asEagerSingleton();
bind(RestMarketRecordIndexAction.class).asEagerSingleton();
bind(RestRegistryRecordIndexAction.class).asEagerSingleton();

//bind(RestRegistryRecordIndexAction.class).asEagerSingleton();

//bind(RestSecurityGetChallengeAction.class).asEagerSingleton();
//bind(RestSecurityAuthAction.class).asEagerSingleton();
bind(RestSecurityGetChallengeAction.class).asEagerSingleton();
bind(RestSecurityAuthAction.class).asEagerSingleton();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,23 @@
public class DuniterNode extends AbstractLifecycleComponent<DuniterNode> {

private final PluginSettings pluginSettings;
private final ThreadPool threadPool;
private final Injector injector;

@Inject
public DuniterNode(Settings settings, PluginSettings pluginSettings, ThreadPool threadPool, final Injector injector) {
super(settings);
this.pluginSettings = pluginSettings;
this.threadPool = threadPool;
this.injector = injector;

threadPool.scheduleOnStarted(() -> {
createIndices(injector);
});
}

@Override
protected void doStart() {

threadPool.scheduleOnStarted(() -> {
createIndices();
});
}

@Override
Expand All @@ -43,14 +46,14 @@ protected void doClose() {

}

protected void createIndices(Injector injector) {
if (logger.isInfoEnabled()) {
logger.info("Creating Duniter indices...");
}
protected void createIndices() {

boolean reloadIndices = pluginSettings.reloadIndices();
Peer peer = pluginSettings.checkAndGetPeer();
if (reloadIndices) {
if (logger.isInfoEnabled()) {
logger.info("Reloading all Duniter indices...");
}
injector.getInstance(RegistryService.class)
.deleteIndex()
.createIndexIfNotExists()
Expand All @@ -65,6 +68,10 @@ protected void createIndices(Injector injector) {
.indexLastBlocks(peer);
}
else {
if (logger.isInfoEnabled()) {
logger.info("Checking Duniter indices...");
}

injector.getInstance(RegistryService.class).createIndexIfNotExists();

injector.getInstance(MarketService.class).createIndexIfNotExists();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class BlockchainService extends AbstractService {
private static final int SYNC_MISSING_BLOCK_MAX_RETRY = 5;

private BlockchainRemoteService blockchainRemoteService;
//private CurrencyRegistryService currencyRegistryService;
private RegistryService registryService;

private Gson gson;

Expand All @@ -97,6 +97,11 @@ public BlockchainService(Client client, PluginSettings settings, ThreadPool thre
});
}

@Inject
public void setRegistryService(RegistryService registryService) {
this.registryService = registryService;
}

public BlockchainService indexLastBlocks(Peer peer) {
return indexLastBlocks(peer, new ProgressionModelImpl());
}
Expand Down Expand Up @@ -124,13 +129,9 @@ public BlockchainService indexLastBlocks(Peer peer, ProgressionModel progression
currencyName, pluginSettings.getNodeBmaHost(), pluginSettings.getNodeBmaPort()));

// Create index blockchain if need
// FIXME: avoid circular dependency
//currencyRegistryService.createIndexIfNotExists();

//Currency currency = currencyRegistryService.getCurrencyById(currencyName);
//if (currency == null) {
// currencyRegistryService.indexCurrencyFromPeer(peer);
//}
if (!registryService.isCurrencyExists(currencyName)) {
registryService.indexCurrencyFromPeer(peer);
}

// Check if index exists
createIndexIfNotExists(currencyName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public String indexRecordFromJson(String recordJson) {

public void fillRecordCategories() {
if (logger.isDebugEnabled()) {
logger.debug(String.format("[%s/%s] fill data", INDEX, RECORD_CATEGORY_TYPE));
logger.debug(String.format("[%s/%s] Fill data", INDEX, RECORD_CATEGORY_TYPE));
}

// Insert categories
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.duniter.core.exception.TechnicalException;
import org.duniter.core.service.CryptoService;
import org.duniter.core.util.ObjectUtils;
import org.duniter.core.util.StringUtils;
import org.duniter.elasticsearch.PluginSettings;
import org.duniter.elasticsearch.exception.AccessDeniedException;
import org.duniter.elasticsearch.exception.DuplicateIndexIdException;
Expand Down Expand Up @@ -168,6 +169,11 @@ public RegistryService fillRecordCategories() {
return this;
}

public boolean isCurrencyExists(String currencyName) {
String pubkey = getSenderPubkeyByCurrencyId(currencyName);
return !StringUtils.isEmpty(pubkey);
}

/**
*
* @param recordJson
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ cluster.name: duniter4j-elasticsearch
# Set a custom port for HTTP:
#
# http.port: 9200
#http.port: 9200
http.cors.enabled: true

http.cors.enabled: false
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html>
Expand Down Expand Up @@ -105,6 +105,6 @@ duniter.host: cgeek.fr
duniter.port: 9330

duniter.string.analyzer: french
duniter.indices.reload: true
#duniter.indices.reload: true

#duniter.dev.enable: true
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.duniter.elasticsearch.service.blockchain;
package org.duniter.elasticsearch.service;

/*
* #%L
Expand Down Expand Up @@ -28,16 +28,15 @@
import org.duniter.core.client.model.local.Peer;
import org.duniter.core.client.service.bma.BlockchainRemoteService;
import org.duniter.elasticsearch.TestResource;
import org.duniter.elasticsearch.service.BlockchainService;
import org.junit.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public class BlockIndexerServiceTest {
public class BlockchainServiceTest {

private static final Logger log = LoggerFactory.getLogger(BlockIndexerServiceTest.class);
private static final Logger log = LoggerFactory.getLogger(BlockchainServiceTest.class);

@ClassRule
public static final TestResource resource = TestResource.create();
Expand Down

0 comments on commit 22bf887

Please sign in to comment.