Project

General

Profile

« Previous | Next » 

Revision 54404

Cache evict for direct index api called on the endpoint specified by the new property dnet.openaire.index.api.cacheEvictUrl

View differences:

SwitchIndexesJobNode.java
8 8
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
9 9
import org.apache.commons.logging.Log;
10 10
import org.apache.commons.logging.LogFactory;
11
import org.apache.http.client.methods.CloseableHttpResponse;
12
import org.apache.http.client.methods.HttpGet;
13
import org.apache.http.impl.client.CloseableHttpClient;
14
import org.apache.http.impl.client.HttpClients;
15
import org.springframework.beans.factory.annotation.Value;
11 16

  
12 17
/**
13 18
 * SwitchIndexesJobNode guides the index switches on all search services whose ids are in the queue available in the parameter named 'searchService_ids'.
......
20 25

  
21 26
	private static final Log log = LogFactory.getLog(SwitchIndexesJobNode.class);
22 27

  
28
	@Value("dnet.openaire.index.api.cacheEvictUrl")
29
	private String indexApiCacheEvictUrl;
30

  
23 31
	@Override
24 32
	protected String execute(final NodeToken token) throws Exception {
25 33
		Queue<String> q = (Queue<String>) token.getEnv().getTransientAttribute("searchService_ids");
26 34
		log.debug("Got the searchService_ids queue: " + q.toString());
27 35
		if (q == null) throw new MSROException("Transient param 'searchService_ids' with queue of string could not be found");
28 36
		if (q.isEmpty()) {
29
			log.info("searchService_ids queue consumed, now ending cycle");
30
			return Arc.DEFAULT_ARC;
37
			log.info("searchService_ids queue consumed, now ending cycle and evicting direct indexing api cache");
38
			HttpGet get = new HttpGet(indexApiCacheEvictUrl);
39
			CloseableHttpClient httpclient = HttpClients.createDefault();
40
			try(CloseableHttpResponse response = httpclient.execute(get)){
41
				if(response.getStatusLine().getStatusCode() == 200){
42
					return Arc.DEFAULT_ARC;
43
				}
44
				else throw new MSROException("Cannot evict cache of direct indexing API at: "+indexApiCacheEvictUrl);
45
			}
46

  
31 47
		} else {
32 48
			//we have something to do: setting the xqueryForServiceIdParam for the SwitchIndexJobNode
33 49
			String id = q.poll();
......
39 55
			token.getEnv().setTransientAttribute("searchService_ids", q);
40 56
			return "switch";
41 57
		}
58

  
42 59
	}
43

  
44 60
}

Also available in: Unified diff