Skip to content
Snippets Groups Projects
Commit 2104eb23 authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

Generate cesium config.js file dynamically

parent 9c6ba6ba
No related branches found
No related tags found
No related merge requests found
Showing
with 199 additions and 1841 deletions
......@@ -310,7 +310,9 @@
</goals>
<configuration>
<target>
<!--<chmod perm="ug+rw">
<fileset dir="${es.home}/lib"/>
</chmod>-->
<ac:if xmlns:ac="antlib:net.sf.antcontrib">
<istrue value="${assembly.skip}"/>
<then>
......@@ -320,6 +322,8 @@
</copy>
</then>
<else>
<delete dir="${project.build.directory}/${bundlePrefix}"/>
<delete dir="${run.es.home}"/>
<!-- Unzip standalone zip-->
<unzip src="${project.build.directory}/${bundlePrefix}-standalone.zip"
dest="${project.build.directory}"
......@@ -329,6 +333,12 @@
</else>
</ac:if>
<!-- Use files from src/test/es-home -->
<copy todir="${run.es.home}"
overwrite="true">
<fileset dir="${project.basedir}/src/test/es-home" includes="**/*.*">
</fileset>
</copy>
</target>
</configuration>
</execution>
......
......@@ -32,6 +32,7 @@ import org.duniter.elasticsearch.action.registry.RestRegistryRecordIndexAction;
import org.duniter.elasticsearch.action.registry.RestRegistryRecordUpdateAction;
import org.duniter.elasticsearch.action.security.RestSecurityAuthAction;
import org.duniter.elasticsearch.action.security.RestSecurityGetChallengeAction;
import org.duniter.elasticsearch.action.site.RestCesiumConfigAction;
import org.duniter.elasticsearch.action.user.RestUserProfileIndexAction;
import org.duniter.elasticsearch.action.user.RestUserProfileUpdateAction;
import org.elasticsearch.common.inject.AbstractModule;
......@@ -65,5 +66,8 @@ public class RestModule extends AbstractModule implements Module {
// History
bind(RestHistoryDeleteIndexAction.class).asEagerSingleton();
// Cesium
bind(RestCesiumConfigAction.class).asEagerSingleton();
}
}
\ No newline at end of file
package org.duniter.elasticsearch.action.site;
/*
* #%L
* duniter4j-elasticsearch-plugin
* %%
* Copyright (C) 2014 - 2016 EIS
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/
import org.duniter.core.exception.BusinessException;
import org.duniter.elasticsearch.PluginSettings;
import org.duniter.elasticsearch.exception.DuniterElasticsearchException;
import org.duniter.elasticsearch.exception.NodeConfigException;
import org.duniter.elasticsearch.rest.XContentThrowableRestResponse;
import org.duniter.elasticsearch.service.RegistryService;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.ESLoggerFactory;
import org.elasticsearch.common.network.NetworkAddress;
import org.elasticsearch.common.network.NetworkService;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.BoundTransportAddress;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.http.HttpChannel;
import org.elasticsearch.http.HttpServerTransport;
import org.elasticsearch.index.translog.TranslogService;
import org.elasticsearch.node.Node;
import org.elasticsearch.rest.*;
import org.elasticsearch.transport.TransportService;
import java.io.IOException;
import java.net.InetAddress;
import static org.elasticsearch.rest.RestStatus.OK;
public class RestCesiumConfigAction extends RestFilter {
private static final ESLogger log = ESLoggerFactory.getLogger(RestCesiumConfigAction.class.getName());
private static final String CONFIG_FILE_PATH = "/_plugin/duniter4j-elasticsearch/config.js";
private NetworkService networkService;
private HttpServerTransport transport;
private PluginSettings pluginSettings;
private String configJsContent;
@Inject
public RestCesiumConfigAction(RestController controller, PluginSettings pluginSettings, NetworkService networkService,
HttpServerTransport transport) {
controller.registerFilter(this);
this.networkService = networkService;
this.pluginSettings = pluginSettings;
this.transport = transport;
}
@Override
public void process(final RestRequest request, RestChannel restChannel, RestFilterChain restFilterChain) throws Exception {
// If path = config file: send content
if (CONFIG_FILE_PATH.equalsIgnoreCase(request.path())) {
handleRequest(request, restChannel);
}
else {
// Continue
restFilterChain.continueProcessing(request, restChannel);
}
}
protected void handleRequest(final RestRequest request, RestChannel restChannel) throws Exception {
try {
restChannel.sendResponse(new BytesRestResponse(OK, getCesiumConfigJs()));
}
catch(DuniterElasticsearchException | BusinessException e) {
log.error(e.getMessage(), e);
restChannel.sendResponse(new XContentThrowableRestResponse(request, e));
}
catch(Exception e) {
log.error(e.getMessage(), e);
}
}
protected String getCesiumConfigJs() throws DuniterElasticsearchException {
if (configJsContent != null) {
return configJsContent;
}
// Compute the ES node address
String esNode = "localhost:9200";
BoundTransportAddress host = transport.boundAddress();
if (host != null) {
TransportAddress address = host.publishAddress();
if (address != null) {
esNode = address.toString();
}
}
// Compute the Duniter node address
String duniterNode = String.format("%s:%s",
pluginSettings.getNodeBmaHost(),
pluginSettings.getNodeBmaPort());
// Compute the config file content
configJsContent = String.format("angular.module(\"cesium.config\", [])\n" +
".constant(\"APP_CONFIG\", {\n" +
" \"DUNITER_NODE\": \"%s\",\n" +
" \"DUNITER_NODE_ES\": \"%s\",\n" +
" \"NEW_ISSUE_LINK\": \"https://github.com/duniter/cesium/issues/new?labels=bug\",\n" +
" \"TIMEOUT\": 4000,\n" +
" \"DEBUG\": false,\n" +
" \"VERSION\": \"0.1.28\",\n" +
" \"BUILD_DATE\": \"2016-08-18T16:45:31.702Z\"});",
duniterNode,
esNode
);
return configJsContent;
}
}
\ No newline at end of file
package org.duniter.elasticsearch.exception;
/*
* #%L
* UCoin Java Client :: Core API
* %%
* Copyright (C) 2014 - 2015 EIS
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/
import org.elasticsearch.rest.RestStatus;
/**
* Created by Benoit on 03/04/2015.
*/
public class NodeConfigException extends DuniterElasticsearchException{
public NodeConfigException(Throwable cause) {
super(cause);
}
public NodeConfigException(String msg, Object... args) {
super(msg, args);
}
public NodeConfigException(String msg, Throwable cause, Object... args) {
super(msg, args, cause);
}
@Override
public RestStatus status() {
return RestStatus.INTERNAL_SERVER_ERROR;
}
}
#Generated by org.nuiton.i18n.init.UserI18nInitializer
#Mon Aug 01 16:23:47 CEST 2016
locales=fr_FR,en_GB
bundles.en_GB=i18n/nuiton-utils_en_GB.properties,i18n/duniter4j-core-client_en_GB.properties,i18n/duniter4j-elasticsearch_en_GB.properties,i18n/ucoinj-elasticsearch_en_GB.properties
version=0.1
encoding=UTF-8
bundles.fr_FR=i18n/nuiton-utils_fr_FR.properties,i18n/duniter4j-core-client_fr_FR.properties,i18n/duniter4j-elasticsearch_fr_FR.properties,i18n/ucoinj-elasticsearch_fr_FR.properties
#Mon Aug 01 16:23:45 CEST 2016
duniter4j-elasticsearch.config=
duniter4j.blockIndexerService.indexBlock=[%s] [%s] Indexing block \#%s
duniter4j.blockIndexerService.indexLastBlocks.otherPeers.task=Indexing missing blocks of [%s] from other peers
duniter4j.blockIndexerService.indexLastBlocks.progress=[%s] [%s] Indexing block \#%s / %s (%s%%)...
duniter4j.blockIndexerService.indexLastBlocks.stopped=[%s] [%s] Indexing last block - stopped
duniter4j.blockIndexerService.indexLastBlocks.task=Indexing last blocks of [%s] from peer [%s\:%s]...
duniter4j.config=
duniter4j.config.option.basedir.description=
duniter4j.config.option.cache.directory.description=
duniter4j.config.option.data.directory.description=
duniter4j.config.option.elasticsearch.bulk.enable.description=
duniter4j.config.option.elasticsearch.bulk.size.description=
duniter4j.config.option.elasticsearch.cluster.name.description=
duniter4j.config.option.elasticsearch.embedded.enable.description=
duniter4j.config.option.elasticsearch.host.description=
duniter4j.config.option.elasticsearch.local.description=
duniter4j.config.option.elasticsearch.network.host.description=
duniter4j.config.option.elasticsearch.string.analyze.description=
duniter4j.config.option.i18n.directory.description=
duniter4j.config.option.i18n.locale.description=
duniter4j.config.option.inceptionYear.description=
duniter4j.config.option.index.parallel_processing.description=
duniter4j.config.option.launch.mode.description=
duniter4j.config.option.network.timeout.description=
duniter4j.config.option.node.currency.description=
duniter4j.config.option.node.elasticsearch.cluster.name.description=
duniter4j.config.option.node.elasticsearch.clusterName.description=
duniter4j.config.option.node.elasticsearch.daemon.description=
duniter4j.config.option.node.elasticsearch.embeddeb.description=
duniter4j.config.option.node.elasticsearch.embeddeb.http.description=
duniter4j.config.option.node.elasticsearch.embeddeb.local.description=
duniter4j.config.option.node.elasticsearch.embedded.enable.description=
duniter4j.config.option.node.elasticsearch.embedded.http.enable.description=
duniter4j.config.option.node.elasticsearch.embedded.local.description=
duniter4j.config.option.node.elasticsearch.host.description=
duniter4j.config.option.node.elasticsearch.http.enable.description=
duniter4j.config.option.node.elasticsearch.local.clusterName.description=
duniter4j.config.option.node.elasticsearch.local.description=
duniter4j.config.option.node.elasticsearch.port.description=
duniter4j.config.option.node.elasticsearch.protocol.description=
duniter4j.config.option.node.elasticsearch.rest.host.description=
duniter4j.config.option.node.elasticsearch.rest.port.description=
duniter4j.config.option.node.elasticsearch.rest.protocol.description=
duniter4j.config.option.node.elasticsearch.rest.url.description=
duniter4j.config.option.node.elasticsearch.url.description=
duniter4j.config.option.node.host.description=
duniter4j.config.option.node.port.description=
duniter4j.config.option.node.protocol.description=
duniter4j.config.option.organizationName.description=
duniter4j.config.option.passwd.description=
duniter4j.config.option.plugins.directory.description=
duniter4j.config.option.salt.description=
duniter4j.config.option.site.url.description=
duniter4j.config.option.taskExecutor.queueCapacity.description=
duniter4j.config.option.tasks.queueCapacity.description=
duniter4j.config.option.temp.directory.description=
duniter4j.config.option.tmp.directory.description=
duniter4j.config.option.version.description=
duniter4j.config.parse.error=
duniter4j.executor.task.waitingExecution=
duniter4j.job.stopped=
duniter4j.job.stopping=
duniter4j.job.success=
duniter4j.task.issuer.system=System
duniter4j.task.starting=Starting task...
nuitonutil.config.moving.conf=Moving old configuration file from %s to %s
nuitonutil.debug.objectutil.create=Try to create %s with %s
nuitonutil.debug.objectutil.instantiate=Can't instantiate %s with params %s
nuitonutil.debug.objectutil.invoke=Invoke %s with %s
nuitonutil.error.add.url.in.classloader=Can't add url in classloader %1$s for reason %2$s
nuitonutil.error.applicationconfig.save=Can't save config in file %s
nuitonutil.error.cant.instanciate.class=Class %s can't be instanciated with %s
nuitonutil.error.class.with.more.than.one.constructor=Your class %s has more than one constructor
nuitonutil.error.convert.file.to.url=Can't convert %s for reason %s
nuitonutil.error.convertor.noValue=No value specified for converter %s
nuitonutil.error.could.not.addPCL=Could not add the PropertychangeListener %1$s on object %2$s for following reason \: %3$s
nuitonutil.error.could.not.find.MD5=Could not find MD5 algorithm
nuitonutil.error.could.not.removePCL=Could remove the PropertychangeListener %1$s from object %2$s for following reason \: %3$s
nuitonutil.error.get.url.from.zip=Error while reading %s \: %s
nuitonutil.error.no.convertor=no convertor found for type %2$s and objet '%1$s'
nuitonutil.error.not.an.enum=The type %1$s ins not an Enum type
nuitonutil.error.null.parameter=The parameter %1$s is null\!
nuitonutil.error.resource.not.found=Can't find resource \: %s
nuitonutil.error.unfound.assignable.argument=Can't find assignable argument for %s in %s
nuitonutil.error.unfound.month=could not found month from '%s', use default month '%s'
nuitonutil.error.unknown.url.type=could not treate unknown type of url %1$s
nuitonutil.error.url.convertor=a problem occurs while converting value '%s' with url convertor %s for reason %s
nuitonutil.error.version.convertor=Could not convert version %1$s with converter %2$s for reason \: %3$s
nuitonutil.error.version.pattern=Pattern of version not found for %1$s
nuitonutil.fileCompletion.cancel=.. to cancel or return to parent directory
nuitonutil.fileCompletion.enter=Enter to display file list, or to complete path
nuitonutil.fileCompletion.exit=Enter "\!q" to exit
nuitonutil.fileCompletion.save=Enter "\!s" in the end of the file name to save
nuitonutil.month.april=april
nuitonutil.month.august=august
nuitonutil.month.december=december
nuitonutil.month.february=february
nuitonutil.month.january=january
nuitonutil.month.july=july
nuitonutil.month.june=june
nuitonutil.month.march=march
nuitonutil.month.may=may
nuitonutil.month.november=november
nuitonutil.month.october=october
nuitonutil.month.september=september
#Mon Aug 01 16:23:45 CEST 2016
duniter4j-elasticsearch.config=
duniter4j.blockIndexerService.indexBlock=[%s] [%s] Indexing block \#%s
duniter4j.blockIndexerService.indexLastBlocks.otherPeers.task=Indexing missing blocks of [%s] from other peers
duniter4j.blockIndexerService.indexLastBlocks.progress=[%s] [%s] Indexing block \#%s / %s (%s%%)...
duniter4j.blockIndexerService.indexLastBlocks.stopped=[%s] [%s] Indexing last block - stopped
duniter4j.blockIndexerService.indexLastBlocks.task=Indexing last blocks of [%s] from peer [%s\:%s]...
duniter4j.config=
duniter4j.config.option.basedir.description=
duniter4j.config.option.cache.directory.description=
duniter4j.config.option.data.directory.description=
duniter4j.config.option.elasticsearch.bulk.enable.description=
duniter4j.config.option.elasticsearch.bulk.size.description=
duniter4j.config.option.elasticsearch.cluster.name.description=
duniter4j.config.option.elasticsearch.embedded.enable.description=
duniter4j.config.option.elasticsearch.host.description=
duniter4j.config.option.elasticsearch.local.description=
duniter4j.config.option.elasticsearch.network.host.description=
duniter4j.config.option.elasticsearch.string.analyze.description=
duniter4j.config.option.i18n.directory.description=
duniter4j.config.option.i18n.locale.description=
duniter4j.config.option.inceptionYear.description=
duniter4j.config.option.index.parallel_processing.description=
duniter4j.config.option.launch.mode.description=
duniter4j.config.option.network.timeout.description=
duniter4j.config.option.node.currency.description=
duniter4j.config.option.node.elasticsearch.cluster.name.description=
duniter4j.config.option.node.elasticsearch.clusterName.description=
duniter4j.config.option.node.elasticsearch.daemon.description=
duniter4j.config.option.node.elasticsearch.embeddeb.description=
duniter4j.config.option.node.elasticsearch.embeddeb.http.description=
duniter4j.config.option.node.elasticsearch.embeddeb.local.description=
duniter4j.config.option.node.elasticsearch.embedded.enable.description=
duniter4j.config.option.node.elasticsearch.embedded.http.enable.description=
duniter4j.config.option.node.elasticsearch.embedded.local.description=
duniter4j.config.option.node.elasticsearch.host.description=
duniter4j.config.option.node.elasticsearch.http.enable.description=
duniter4j.config.option.node.elasticsearch.local.clusterName.description=
duniter4j.config.option.node.elasticsearch.local.description=
duniter4j.config.option.node.elasticsearch.port.description=
duniter4j.config.option.node.elasticsearch.protocol.description=
duniter4j.config.option.node.elasticsearch.rest.host.description=
duniter4j.config.option.node.elasticsearch.rest.port.description=
duniter4j.config.option.node.elasticsearch.rest.protocol.description=
duniter4j.config.option.node.elasticsearch.rest.url.description=
duniter4j.config.option.node.elasticsearch.url.description=
duniter4j.config.option.node.host.description=
duniter4j.config.option.node.port.description=
duniter4j.config.option.node.protocol.description=
duniter4j.config.option.organizationName.description=
duniter4j.config.option.passwd.description=
duniter4j.config.option.plugins.directory.description=
duniter4j.config.option.salt.description=
duniter4j.config.option.site.url.description=
duniter4j.config.option.taskExecutor.queueCapacity.description=
duniter4j.config.option.tasks.queueCapacity.description=
duniter4j.config.option.temp.directory.description=
duniter4j.config.option.tmp.directory.description=
duniter4j.config.option.version.description=
duniter4j.config.parse.error=
duniter4j.executor.task.waitingExecution=
duniter4j.job.stopped=
duniter4j.job.stopping=
duniter4j.job.success=
duniter4j.task.issuer.system=Système
duniter4j.task.starting=Démarrage du traitement...
nuitonutil.config.moving.conf=Déplacement du fichier de configuration depuis %s vers %s
nuitonutil.debug.objectutil.create=Essaye de créer %s avec %s
nuitonutil.debug.objectutil.instantiate=Ne peut pas instancier %s avec les paramêtres %s
nuitonutil.debug.objectutil.invoke=Invocation de %s avec %s
nuitonutil.error.add.url.in.classloader=Impossible d'ajouter une url dans le classloader %s pour la raison \: %s
nuitonutil.error.applicationconfig.save=Impossible de sauvegarder le fichier de configuration dans %s
nuitonutil.error.cant.instanciate.class=La Classe %s n'a pas pu être instanciée avec %s
nuitonutil.error.class.with.more.than.one.constructor=Votre classe %s a plus d'un constructeur
nuitonutil.error.convert.file.to.url=Le fichier '%1$s' n'a pas pu être converti en URL pour la raison suivante \: %2$S
nuitonutil.error.convertor.noValue=Aucune valeur à convertir pour le convertisseur %s
nuitonutil.error.could.not.addPCL=N'a pas pu ajouté le PropertychangeListener %1$s sur l'objet %2$s pour la raison suivante \: %3$s
nuitonutil.error.could.not.find.MD5=L'algorithme MD5 n'a pas été trouvé\!
nuitonutil.error.could.not.removePCL=N'a pas pu enlevé le PropertychangeListener %1$s sur l'objet %2$s pour la raison suivante \: %3$s
nuitonutil.error.get.url.from.zip=Erreur lors de la lecture du fichier compressé %1$s \: %2$s
nuitonutil.error.no.convertor=Aucun convertisseur trouvé pour le type %2$s et l''objet '%1$s'
nuitonutil.error.not.an.enum=Le type %1$s n'est pas une enumeration java
nuitonutil.error.null.parameter=Le paramètre '%1$s' est null\!
nuitonutil.error.resource.not.found=Impossible de trouver la ressource \: %s
nuitonutil.error.unfound.assignable.argument=N'a pas pu trouver un argument assignable pour %s dans %s
nuitonutil.error.unfound.month=n'a pas pu trouvé le mois à partir de '%s', utilise le mois par défaut '%s'
nuitonutil.error.unknown.url.type=could not treate unknown type of url %1$s
nuitonutil.error.url.convertor=Un problème est apparu lors de la convertion en url de '%s' avec le convertisseur %s pour la raison suivante \: %s
nuitonutil.error.version.convertor=N'a pas pu convertir la valeur %1$s avec le converter %2$s pour la raison suivante \: %3$s
nuitonutil.error.version.pattern=Pattern de version non connu pour %1$s
nuitonutil.fileCompletion.cancel=.. pour annuler ou pour revenir au repertoire précédent
nuitonutil.fileCompletion.enter=Entrer pour afficher la liste des fichiers, ou pour compléter le chemin
nuitonutil.fileCompletion.exit=Saisir "\!q" pour quitter
nuitonutil.fileCompletion.save=Saisir "\!s" a la fin du nom de fichier pour l'enregistrer
nuitonutil.month.april=avril
nuitonutil.month.august=août
nuitonutil.month.december=décembre
nuitonutil.month.february=février
nuitonutil.month.january=janvier
nuitonutil.month.july=juillet
nuitonutil.month.june=juin
nuitonutil.month.march=mars
nuitonutil.month.may=mai
nuitonutil.month.november=novembre
nuitonutil.month.october=octobre
nuitonutil.month.september=septembre
This diff is collapsed.
name=duniter
description=Duniter :: ElasticSearch Plugin
version=0.1-SNAPSHOT
site=false
jvm=true
classname=org.duniter.elasticsearch.Plugin
java.version=1.7
elasticsearch.version=2.3.3
isolated=true
\ No newline at end of file
grant codeBase "file:${es.path.home}/plugins/duniter4j-elasticsearch/"{
permission java.io.FilePermission "/etc/ld.so.conf", "read";
permission java.io.FilePermission "/etc/ld.so.conf.d/*.conf", "read";
permission java.io.FilePermission "/usr/local/lib/*", "read";
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment