Changeset 5891 for SRUAggregator


Ignore:
Timestamp:
12/05/14 08:14:03 (9 years ago)
Author:
emanuel.dima@uni-tuebingen.de
Message:

alpha 6: switched to selfcontained java jar using DropWizard?

Location:
SRUAggregator/trunk
Files:
3 added
2 deleted
5 edited
1 moved

Legend:

Unmodified
Added
Removed
  • SRUAggregator/trunk/build.sh

    r5890 r5891  
    11#!/bin/bash
    22
    3 WEBDIR=src/main/webapp
    4 LIBDIR=$WEBDIR/lib
     3ASSETDIR=src/main/resources/assets
     4LIBDIR=$ASSETDIR/lib
    55
    66if [ ! -e bower_components ]
     
    1818
    1919        mkdir -p src/main/webapp/fonts
    20         cp bower_components/bootstrap/fonts/*  $WEBDIR/fonts/
    21         cp bower_components/font-awesome/fonts/* $WEBDIR/fonts/
     20        cp bower_components/bootstrap/fonts/*  $ASSETDIR/fonts/
     21        cp bower_components/font-awesome/fonts/* $ASSETDIR/fonts/
    2222fi
    2323
    24 JSDIR=src/main/webapp/js
     24JSDIR=$ASSETDIR/js
    2525for f in $JSDIR/*.jsx; do
    2626        cp -v $f $JSDIR/`basename $f .jsx`.js;
     
    2828node_modules/react-tools/bin/jsx --no-cache-dir $JSDIR $JSDIR
    2929
    30 #mvn clean package
     30#mvn -q clean package
     31
     32# Run in production:
     33#java -jar target/Aggregator2-2.0.0-alpha-6.jar server aggregator.yml
     34
     35# Run for development:
     36#java -DEnvironment=Development -cp src/main/resources:target/Aggregator2-2.0.0-alpha-6.jar eu.clarin.sru.fcs.aggregator.app.Aggregator server aggregator.yml
  • SRUAggregator/trunk/pom.xml

    r5890 r5891  
    1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    2                 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     1<?xml version="1.0" encoding="UTF-8"?>
     2<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    33        <modelVersion>4.0.0</modelVersion>
     4        <prerequisites>
     5                <maven>3.0.0</maven>
     6        </prerequisites>
    47
    58        <groupId>eu.clarin.sru.fcs</groupId>
    69        <artifactId>Aggregator2</artifactId>
    7         <version>2.0.0-ALPHA5</version>
    8         <packaging>war</packaging>
    9 
    10         <name>Aggregator2</name>
     10        <version>2.0.0-alpha-6</version>
     11        <name>Federated Content Search Aggregator</name>
    1112
    1213        <properties>
    13                 <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
    1414                <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     15                <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    1516        </properties>
    1617
     
    1920                        <id>clarin</id>
    2021                        <url>http://catalog.clarin.eu/ds/nexus/content/repositories/Clarin/</url>
     22                </repository>
     23                <repository>
     24                        <id>sonatype-nexus-snapshots</id>
     25                        <name>Sonatype Nexus Snapshots</name>
     26                        <url>http://oss.sonatype.org/content/repositories/snapshots</url>
    2127                </repository>
    2228                <repository>
     
    2834                        <url>http://sardine.googlecode.com/svn/maven/</url>
    2935                </repository>
    30         </repositories>
    31 
     36        </repositories>
    3237
    3338        <dependencies>
     39                <dependency>
     40                        <groupId>io.dropwizard</groupId>
     41                        <artifactId>dropwizard-core</artifactId>
     42                        <version>0.7.1</version>
     43                </dependency>
     44                <dependency>
     45                        <groupId>io.dropwizard</groupId>
     46                        <artifactId>dropwizard-assets</artifactId>
     47                        <version>0.7.1</version>
     48                </dependency>
     49                <dependency>
     50                        <groupId>io.dropwizard</groupId>
     51                        <artifactId>dropwizard-spdy</artifactId>
     52                        <version>0.7.1</version>
     53                </dependency>
     54                <dependency>
     55                        <groupId>io.dropwizard</groupId>
     56                        <artifactId>dropwizard-testing</artifactId>
     57                        <version>0.7.1</version>
     58                        <scope>test</scope>
     59                </dependency>
     60
    3461                <dependency>
    3562                        <groupId>eu.clarin.sru</groupId>
     
    3764                        <version>0.9.5-DEBUG</version>
    3865                </dependency>
    39 
    4066
    4167                <dependency>
     
    81107                        <version>3.11-beta2</version>
    82108                </dependency>
    83 
    84                 <dependency>
    85                         <groupId>org.slf4j</groupId>
    86                         <artifactId>slf4j-api</artifactId>
    87                         <version>1.7.7</version>
    88                 </dependency>
    89                 <dependency>
    90                         <groupId>org.slf4j</groupId>
    91                         <artifactId>slf4j-simple</artifactId>
    92                         <version>1.7.7</version>
    93                 </dependency>
    94 
    95                 <dependency>
    96                         <groupId>joda-time</groupId>
    97                         <artifactId>joda-time</artifactId>
    98                         <version>2.5</version>
    99                 </dependency>
    100                 <dependency>
    101                         <groupId>junit</groupId>
    102                         <artifactId>junit</artifactId>
    103                         <version>4.11</version>
    104                         <scope>test</scope>
    105                         <type>jar</type>
    106                 </dependency>
    107                 <dependency>
    108                         <groupId>com.google.code.gson</groupId>
    109                         <artifactId>gson</artifactId>
    110                         <version>2.3</version>
    111                         <type>jar</type>
    112                 </dependency>
    113                 <dependency>
    114                         <groupId>javax</groupId>
    115                         <artifactId>javaee-web-api</artifactId>
    116                         <version>6.0</version>
    117                         <scope>provided</scope>
    118                 </dependency>
    119 
    120                 <dependency>
    121                         <groupId>com.sun.jersey</groupId>
    122                         <artifactId>jersey-server</artifactId>
    123                         <version>1.18.1</version>
    124                 </dependency>
    125                 <dependency>
    126                         <groupId>com.sun.jersey</groupId>
    127                         <artifactId>jersey-servlet</artifactId>
    128                         <version>1.18.1</version>
    129                 </dependency>
    130                 <dependency>
    131                         <groupId>com.sun.jersey</groupId>
    132                         <artifactId>jersey-client</artifactId>
    133                         <version>1.18.1</version>
    134                 </dependency>
    135                 <dependency>
    136                         <groupId>com.sun.jersey</groupId>
    137                         <artifactId>jersey-core</artifactId>
    138                         <version>1.18.1</version>
    139                 </dependency>
    140                 <dependency>
    141                         <groupId>com.sun.jersey</groupId>
    142                         <artifactId>jersey-json</artifactId>
    143                         <version>1.18.1</version>
    144                 </dependency>
    145                 <dependency>
    146                         <groupId>com.sun.jersey.contribs</groupId>
    147                         <artifactId>jersey-multipart</artifactId>
    148                         <version>1.18.1</version>
    149                 </dependency>
    150 
    151109        </dependencies>
    152110
    153111        <build>
    154         <finalName>${project.artifactId}</finalName>
    155112                <plugins>
     113                        <plugin>
     114                                <groupId>org.apache.maven.plugins</groupId>
     115                                <artifactId>maven-enforcer-plugin</artifactId>
     116                                <version>1.3.1</version>
     117                                <executions>
     118                                        <execution>
     119                                                <id>enforce</id>
     120                                                <configuration>
     121                                                        <rules>
     122                                                                <DependencyConvergence />
     123                                                        </rules>
     124                                                </configuration>
     125                                                <goals>
     126                                                        <!--<goal>enforce</goal>-->
     127                                                </goals>
     128                                        </execution>
     129                                </executions>
     130                        </plugin>
    156131                        <plugin>
    157132                                <groupId>org.apache.maven.plugins</groupId>
     
    161136                                        <source>1.7</source>
    162137                                        <target>1.7</target>
    163                                         <compilerArguments>
    164                                                 <endorseddirs>${endorsed.dir}</endorseddirs>
    165                                         </compilerArguments>
     138                                        <encoding>UTF-8</encoding>
    166139                                </configuration>
    167140                        </plugin>
    168                         <plugin>
    169                                 <groupId>org.apache.maven.plugins</groupId>
    170                                 <artifactId>maven-war-plugin</artifactId>
     141                        <!--<plugin>
     142                                <groupId>org.apache.maven.plugins</groupId>
     143                                <artifactId>maven-source-plugin</artifactId>
     144                                <version>2.2.1</version>
     145                                <executions>
     146                                        <execution>
     147                                                <id>attach-sources</id>
     148                                                <goals>
     149                                                        <goal>jar</goal>
     150                                                </goals>
     151                                        </execution>
     152                                </executions>
     153                        </plugin>-->
     154                        <plugin>
     155                                <groupId>org.apache.maven.plugins</groupId>
     156                                <artifactId>maven-jar-plugin</artifactId>
    171157                                <version>2.5</version>
    172158                                <configuration>
    173                                         <failOnMissingWebXml>false</failOnMissingWebXml>
     159                                        <archive>
     160                                                <manifest>
     161                                                        <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
     162                                                </manifest>
     163                                        </archive>
    174164                                </configuration>
    175165                        </plugin>
    176166                        <plugin>
    177167                                <groupId>org.apache.maven.plugins</groupId>
    178                                 <artifactId>maven-dependency-plugin</artifactId>
    179                                 <version>2.9</version>
     168                                <artifactId>maven-shade-plugin</artifactId>
     169                                <version>2.2</version>
     170                                <configuration>
     171                                        <createDependencyReducedPom>true</createDependencyReducedPom>
     172                                        <filters>
     173                                                <filter>
     174                                                        <artifact>*:*</artifact>
     175                                                        <excludes>
     176                                                                <exclude>META-INF/*.SF</exclude>
     177                                                                <exclude>META-INF/*.DSA</exclude>
     178                                                                <exclude>META-INF/*.RSA</exclude>
     179                                                        </excludes>
     180                                                </filter>
     181                                        </filters>
     182                                </configuration>
    180183                                <executions>
    181184                                        <execution>
    182                                                 <phase>validate</phase>
     185                                                <phase>package</phase>
    183186                                                <goals>
    184                                                         <goal>copy</goal>
     187                                                        <goal>shade</goal>
    185188                                                </goals>
    186189                                                <configuration>
    187                                                         <outputDirectory>${endorsed.dir}</outputDirectory>
    188                                                         <silent>true</silent>
    189                                                         <artifactItems>
    190                                                                 <artifactItem>
    191                                                                         <groupId>javax</groupId>
    192                                                                         <artifactId>javaee-endorsed-api</artifactId>
    193                                                                         <version>6.0</version>
    194                                                                         <type>jar</type>
    195                                                                 </artifactItem>
    196                                                         </artifactItems>
     190                                                        <transformers>
     191                                                                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
     192                                                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
     193                                                                        <mainClass>eu.clarin.sru.fcs.aggregator.app.Aggregator</mainClass>
     194                                                                </transformer>
     195                                                        </transformers>
    197196                                                </configuration>
    198197                                        </execution>
  • SRUAggregator/trunk/src/main/java/eu/clarin/sru/fcs/aggregator/app/Aggregator.java

    r5890 r5891  
    11package eu.clarin.sru.fcs.aggregator.app;
    22
     3import com.fasterxml.jackson.databind.ObjectMapper;
    34import eu.clarin.sru.fcs.aggregator.search.Search;
    45import eu.clarin.sru.fcs.aggregator.cache.ScanCrawlTask;
     
    910import eu.clarin.sru.fcs.aggregator.cache.EndpointUrlFilter;
    1011import eu.clarin.sru.fcs.aggregator.registry.Corpus;
     12import eu.clarin.sru.fcs.aggregator.rest.RestService;
     13import io.dropwizard.Application;
     14import io.dropwizard.assets.AssetsBundle;
     15import io.dropwizard.setup.Bootstrap;
     16import io.dropwizard.setup.Environment;
    1117import java.io.File;
    1218import java.io.IOException;
     
    2026import java.util.concurrent.ScheduledExecutorService;
    2127import java.util.concurrent.atomic.AtomicReference;
    22 import javax.servlet.ServletContextEvent;
    23 import javax.servlet.ServletContextListener;
    2428import opennlp.tools.tokenize.TokenizerModel;
    25 import org.codehaus.jackson.map.ObjectMapper;
    2629import org.slf4j.LoggerFactory;
    2730
     
    8790 *
    8891 * TODO: zoom into the results from a corpus, allow functionality only for the
    89  * view
    90  *
    91  * TODO: search for next set of results
     92 * view (search for next set of results)
    9293 *
    9394 * TODO: Clear results (also before new search)
     
    99100 * TODO: Download to personal workspace as csv, excel, tcf, plain text
    100101 *
    101  * TODO: implement
    102  *
    103102 * TODO: use SRUClient's extraResponseData POJOs
    104103 *
    105  * TODO: websockets, selfhosting
     104 * TODO: websockets
    106105 *
    107106 * TODO: atomic replace of cached corpora (file)
     
    110109 *
    111110 */
    112 public class Aggregator implements ServletContextListener {
     111public class Aggregator extends Application<AggregatorConfiguration> {
    113112
    114113        private static final org.slf4j.Logger log = LoggerFactory.getLogger(Aggregator.class);
    115114
    116         public static final String DE_TOK_MODEL = "/tokenizer/de-tuebadz-8.0-token.bin";
     115        public static final String DE_TOK_MODEL = "tokenizer/de-tuebadz-8.0-token.bin";
    117116
    118117        private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
     
    130129        private SRUThreadedClient sruScanClient = null;
    131130        private Map<Long, Search> activeSearches = Collections.synchronizedMap(new HashMap<Long, Search>());
    132         private Params params;
     131
     132        public static void main(String[] args) throws Exception {
     133                new Aggregator().run(args);
     134        }
     135
     136        @Override
     137        public String getName() {
     138                return "Federated Content Search Aggregator";
     139        }
     140
     141        @Override
     142        public void initialize(Bootstrap<AggregatorConfiguration> bootstrap) {
     143                bootstrap.addBundle(new AssetsBundle("/assets", "/", "index.html"));
     144        }
     145
     146        @Override
     147        public void run(AggregatorConfiguration config, Environment environment) {
     148                environment.jersey().setUrlPattern("/rest/*");
     149                environment.jersey().register(new RestService());
     150
     151                init(config);
     152        }
     153
    133154
    134155        public static Aggregator getInstance() {
     
    140161        }
    141162
    142         public Params getParams() {
    143                 return params;
    144         }
    145 
    146         @Override
    147         public void contextInitialized(ServletContextEvent servletContextEvent) {
     163        public void init(AggregatorConfiguration config) {
    148164                log.info("Aggregator initialization started.");
    149165                instance = this;
    150166                try {
    151                         params = new Params();
    152                         detectAndConfigureEnvironment();
     167                        detectAndConfigureEnvironment(config);
    153168
    154169                        sruScanClient = new ClarinFCSClientBuilder()
     
    166181                                        .buildThreadedClient();
    167182
    168                         File corporaCacheFile = new File(params.aggregatorFilePath);
     183                        File corporaCacheFile = new File(config.getAggregatorFilePath());
    169184                        try {
    170185                                Corpora corpora = new ObjectMapper().readValue(corporaCacheFile, Corpora.class);
     
    177192                        model = setUpTokenizers();
    178193
    179                         ScanCrawlTask task = new ScanCrawlTask(sruScanClient, params.centerRegistryUrl,
    180                                         params.cacheMaxDepth, filter, scanCacheAtom, corporaCacheFile);
     194                        ScanCrawlTask task = new ScanCrawlTask(sruScanClient, config.getCenterRegistryUrl(),
     195                                        config.getScanMaxDepth(), filter, scanCacheAtom, corporaCacheFile);
    181196                        scheduler.scheduleAtFixedRate(task, SCAN_TASK_INITIAL_DELAY,
    182                                         params.cacheUpdateInterval, params.cacheUpdateIntervalUnit);
     197                                        config.getUpdateInterval(), config.getUpdateIntervalTimeUnit());
    183198
    184199                        log.info("Aggregator initialization finished.");
     
    189204        }
    190205
    191         @Override
    192         public void contextDestroyed(ServletContextEvent sce) {
     206        public void shutdown() {
    193207                log.info("Aggregator is shutting down.");
    194208                for (Search search : activeSearches.values()) {
     
    255269        }
    256270
    257         private void detectAndConfigureEnvironment() {
     271        private void detectAndConfigureEnvironment(AggregatorConfiguration config) {
    258272                if (!"Development".equals(System.getProperty("Environment"))) {
    259273                        log.info(" *** Production Environment detected, using default settings *** ");
    260                         params.cacheMaxDepth = 1;
     274                        config.setScanMaxDepth(1);
    261275                        return;
    262276                }
     
    273287//              filter.allow("leipzig", "mpi.nl");
    274288//              filter.allow("lindat");
    275                 params.aggregatorFilePath = System.getProperty("user.home") + File.separator + "fcsAggregatorCorpora.json";
    276                 params.cacheMaxDepth = 1;
     289                config.setAggregatorFilePath(System.getProperty("user.home")
     290                                + File.separator + "fcsAggregatorCorpora.json");
     291                config.setScanMaxDepth(1);
    277292        }
    278293}
  • SRUAggregator/trunk/src/main/java/eu/clarin/sru/fcs/aggregator/cache/ScanCrawlTask.java

    r5841 r5891  
    11package eu.clarin.sru.fcs.aggregator.cache;
    22
     3import com.fasterxml.jackson.databind.ObjectMapper;
    34import eu.clarin.sru.client.SRUThreadedClient;
    45import eu.clarin.sru.fcs.aggregator.registry.CenterRegistry;
     
    78import java.io.IOException;
    89import java.util.concurrent.atomic.AtomicReference;
    9 import org.codehaus.jackson.map.ObjectMapper;
    1010import org.slf4j.LoggerFactory;
    1111
  • SRUAggregator/trunk/src/main/java/eu/clarin/sru/fcs/aggregator/rest/RestService.java

    r5841 r5891  
    11package eu.clarin.sru.fcs.aggregator.rest;
    22
    3 import com.google.gson.Gson;
    4 import com.google.gson.GsonBuilder;
    5 import com.google.gson.JsonParser;
     3import com.fasterxml.jackson.core.JsonProcessingException;
     4import com.fasterxml.jackson.databind.ObjectMapper;
     5import com.fasterxml.jackson.databind.ObjectWriter;
    66import eu.clarin.sru.client.SRUVersion;
    77import eu.clarin.sru.fcs.aggregator.app.Aggregator;
     
    3939@Path("/")
    4040public class RestService {
     41        ObjectWriter ow = new ObjectMapper().writerWithDefaultPrettyPrinter();
    4142
    4243        @Context
     
    4546        ServletContext servletContext;
    4647
    47         private String toJson(Object o) {
    48                 JsonParser parser = new JsonParser();
    49                 Gson gson = new GsonBuilder().setPrettyPrinting().create();
    50                 return gson.toJson(o);
     48        private String toJson(Object o) throws JsonProcessingException {
     49                return ow.writeValueAsString(o);
    5150        }
    5251
Note: See TracChangeset for help on using the changeset viewer.