1
|
package eu.dnetlib.openaire.exporter.datasource.clients;
|
2
|
|
3
|
import java.nio.charset.Charset;
|
4
|
import java.util.Arrays;
|
5
|
|
6
|
import eu.dnetlib.OpenaireExporterConfig;
|
7
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
|
8
|
import eu.dnetlib.openaire.exporter.datasource.ApiException;
|
9
|
import eu.dnetlib.openaire.exporter.datasource.clients.utils.IndexDsInfo;
|
10
|
import org.apache.commons.io.IOUtils;
|
11
|
import org.apache.commons.logging.Log;
|
12
|
import org.apache.commons.logging.LogFactory;
|
13
|
import org.springframework.beans.factory.annotation.Autowired;
|
14
|
import org.springframework.cache.annotation.CacheEvict;
|
15
|
import org.springframework.cache.annotation.Cacheable;
|
16
|
import org.springframework.http.HttpStatus;
|
17
|
import org.springframework.stereotype.Component;
|
18
|
|
19
|
/**
|
20
|
* Created by claudio on 20/10/2016.
|
21
|
*/
|
22
|
@Component
|
23
|
public class ISLookupClient {
|
24
|
|
25
|
private static final Log log = LogFactory.getLog(ISLookupClient.class);
|
26
|
|
27
|
@Autowired
|
28
|
private OpenaireExporterConfig config;
|
29
|
|
30
|
@Autowired
|
31
|
private ISLookUpService isLookUpService;
|
32
|
|
33
|
@Cacheable("datasources-is-cache")
|
34
|
public IndexDsInfo calculateCurrentIndexDsInfo() throws ApiException {
|
35
|
log.warn("calculateCurrentIndexDsInfo(): not using cache");
|
36
|
try {
|
37
|
final String queryUrl = IOUtils.toString(config.getFindSolrIndexUrl().getInputStream(), Charset.defaultCharset());
|
38
|
final String queryDs = IOUtils.toString(config.getFindIndexDsInfo().getInputStream(), Charset.defaultCharset());
|
39
|
|
40
|
final String indexBaseUrl = isLookUpService.getResourceProfileByQuery(queryUrl);
|
41
|
if (log.isDebugEnabled()) {
|
42
|
log.debug(String.format("got solr url: '%s'", indexBaseUrl));
|
43
|
}
|
44
|
final String[] arr = isLookUpService.getResourceProfileByQuery(queryDs).split("@@@");
|
45
|
if (log.isDebugEnabled()) {
|
46
|
log.debug(String.format("got info: '%s'", Arrays.asList(arr)));
|
47
|
}
|
48
|
|
49
|
return new IndexDsInfo(indexBaseUrl, arr[0].trim(), arr[1].trim(), arr[2].trim());
|
50
|
} catch (Throwable e) {
|
51
|
throw new ApiException(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Error querying information system", e);
|
52
|
}
|
53
|
}
|
54
|
|
55
|
@CacheEvict(cacheNames = "datasources-is-cache", allEntries = true)
|
56
|
public void dropCache() {
|
57
|
log.info("dropped dsManager IS cache");
|
58
|
}
|
59
|
|
60
|
}
|