Project

General

Profile

« Previous | Next » 

Revision 49819

implemented new way to fetch the lastIndexingDate

View differences:

modules/dnet-openaire-exporter/branches/beta/dnet-openaire-exporter.iml
19 19
    <orderEntry type="sourceFolder" forTests="false" />
20 20
    <orderEntry type="library" name="Maven: eu.dnetlib:dnet-pace-core:2.5.1" level="project" />
21 21
    <orderEntry type="library" name="Maven: org.apache.solr:solr-solrj:5.5.4" level="project" />
22
    <orderEntry type="library" name="Maven: org.apache.solr:solr-solrj:4.10.4" level="project" />
22 23
    <orderEntry type="library" name="Maven: eu.dnetlib:cnr-rmi-api:2.6.2-SNAPSHOT" level="project" />
23 24
    <orderEntry type="library" name="Maven: org.apache.cxf:cxf-core:3.1.5" level="project" />
24 25
    <orderEntry type="library" name="Maven: org.codehaus.woodstox:woodstox-core-asl:4.4.1" level="project" />
modules/dnet-openaire-exporter/branches/beta/src/main/java/eu/dnetlib/openaire/exporter/datasource/clients/DatasourceIndexClient.java
1 1
package eu.dnetlib.openaire.exporter.datasource.clients;
2 2

  
3 3
import java.io.IOException;
4
import java.util.Date;
5
import java.util.List;
4
import java.util.Calendar;
6 5
import java.util.Map;
7 6
import java.util.Queue;
8 7
import java.util.concurrent.*;
......
28 27
import org.apache.solr.client.solrj.response.QueryResponse;
29 28
import org.apache.solr.common.SolrDocument;
30 29
import org.springframework.beans.factory.annotation.Autowired;
30
import org.springframework.cache.annotation.Cacheable;
31 31
import org.springframework.http.HttpStatus;
32 32
import org.springframework.stereotype.Component;
33 33

  
......
147 147
			//				throw new ApiException(HttpStatus.INTERNAL_SERVER_ERROR.value(), String.format("cannot find document matching query: %s", queryTotal));
148 148
			//			}
149 149
			return new IndexRecordsInfo()
150
					.setDate(getDate(doc))
150
					.setDate(getLastIndexingDate(indexClient))
151 151
					.setTotal(rsp.getResults().getNumFound());
152 152
		} catch (Throwable e) {
153 153
			throw new ApiException(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Error querying information system", e);
154 154
		}
155 155
	}
156 156

  
157
	private String getDate(final SolrDocument doc) throws ApiException {
158
		final List<Date> dsversion = (List<Date>) doc.get(DSVERSION);
159
		if (dsversion == null || dsversion.isEmpty()) {
160
			throw new ApiException(HttpStatus.INTERNAL_SERVER_ERROR.value(), String.format("cannot find %s in matched solr document", DSVERSION));
161
		}
162
		final Date date = Iterables.getLast(dsversion);
157
	@Cacheable("index-cache")
158
	public String getLastIndexingDate(final CloudIndexClient indexClient) throws ApiException {
159
		try {
160
			final QueryResponse rsp = indexClient.query("oaftype:datasource", 1);
161
			if (rsp.getResults().getNumFound() > 0) {
162
				final SolrDocument doc = Iterables.getFirst(rsp.getResults(), null);
163 163

  
164
		return DateFormatUtils.format(date, DatasourceFunctions.DATE_FORMAT);
165
	}
166

  
167
	public String getLastIndexingDate(final IndexDsInfo info) throws ApiException {
168
		try {
169
			final QueryResponse rsp = getIndexClient(info).query("oaftype:datasource", 1);
170
			final SolrDocument doc = Iterables.getFirst(rsp.getResults(), null);
171
			final String dsversion = doc.get("__dsversion").toString();
172
			return StringUtils.substringBefore(dsversion, "T");
164
				final String dsversion = doc.get(DSVERSION).toString();
165
				return StringUtils.substringBefore(dsversion, "T");
166
			} else {
167
				final String defaultDate = getDefaultLastIndexingDate();
168
				log.debug("unable to find documents, defaulting to " + defaultDate);
169
				return defaultDate;
170
			}
173 171
		} catch (CloudIndexClientException e) {
174
			throw new ApiException(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Error querying index DS profile: " + info, e);
172
			throw new ApiException(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Error querying index DS profile", e);
175 173
		}
176 174
	}
177 175

  
176
	private String getDefaultLastIndexingDate() {
177
		final Calendar cal = Calendar.getInstance();
178
		cal.add(Calendar.MONTH, -1);
179
		return DateFormatUtils.format(cal.getTime(), DatasourceFunctions.DATE_FORMAT);
180
	}
181

  
178 182
	private synchronized CloudIndexClient getIndexClient(final IndexDsInfo info) throws CloudIndexClientException {
179 183
		if (!indexClientMap.containsKey(info.getColl())) {
180 184
			indexClientMap.put(info.getColl(), CloudIndexClientFactory.newIndexClient(info.getIndexBaseUrl(), info.getColl(), false));
modules/dnet-openaire-exporter/branches/beta/src/main/resources/ehcache.xml
49 49
		<persistence strategy="localTempSwap" />
50 50
	</cache>
51 51

  
52
	<cache name="index-cache"
53
	       maxEntriesLocalHeap="100"
54
	       maxEntriesLocalDisk="1000"
55
	       eternal="false"
56
	       diskSpoolBufferSizeMB="10"
57
	       timeToIdleSeconds="86400" timeToLiveSeconds="86400"
58
	       memoryStoreEvictionPolicy="LFU"
59
	       transactionalMode="off">
60
		<persistence strategy="localTempSwap" />
61
	</cache>
52 62

  
63

  
53 64
</ehcache>
modules/dnet-openaire-exporter/branches/beta/src/main/resources/logback-spring.xml
10 10
	<logger name="eu.dnetlib" level="INFO" additivity="false">
11 11
		<appender-ref ref="CONSOLE" />
12 12
	</logger>
13
	<logger name="eu.dnetlib.openaire.exporter" level="DEBUG" additivity="false">
13
	<logger name="eu.dnetlib.openaire.exporter" level="INFO" additivity="false">
14 14
		<appender-ref ref="CONSOLE" />
15 15
	</logger>
16 16
</configuration>

Also available in: Unified diff