use of com.splunk.Job in project camel by apache.
the class ConsumerStreamingTest method testSearch.
@Test
public void testSearch() throws Exception {
MockEndpoint searchMock = getMockEndpoint("mock:search-result");
searchMock.expectedMessageCount(3);
JobCollection jobCollection = mock(JobCollection.class);
Job jobMock = mock(Job.class);
when(service.getJobs()).thenReturn(jobCollection);
when(jobCollection.create(anyString(), any(JobArgs.class))).thenReturn(jobMock);
when(jobMock.isDone()).thenReturn(Boolean.TRUE);
InputStream stream = ConsumerTest.class.getResourceAsStream("/resultsreader_test_data.json");
when(jobMock.getResults(any(JobResultsArgs.class))).thenReturn(stream);
assertMockEndpointsSatisfied();
SplunkEvent recieved = searchMock.getReceivedExchanges().get(0).getIn().getBody(SplunkEvent.class);
assertNotNull(recieved);
Map<String, String> data = recieved.getEventData();
assertEquals("indexertpool", data.get("name"));
stream.close();
}
use of com.splunk.Job in project camel by apache.
the class ConsumerTest method testSearch.
@Test
public void testSearch() throws Exception {
MockEndpoint searchMock = getMockEndpoint("mock:search-result");
searchMock.expectedMessageCount(3);
searchMock.expectedPropertyReceived(Exchange.BATCH_SIZE, 3);
JobCollection jobCollection = mock(JobCollection.class);
Job jobMock = mock(Job.class);
when(service.getJobs()).thenReturn(jobCollection);
when(jobCollection.create(anyString(), any(JobArgs.class))).thenReturn(jobMock);
when(jobMock.isDone()).thenReturn(Boolean.TRUE);
InputStream stream = ConsumerTest.class.getResourceAsStream("/resultsreader_test_data.json");
when(jobMock.getResults(any(JobResultsArgs.class))).thenReturn(stream);
assertMockEndpointsSatisfied();
SplunkEvent recieved = searchMock.getReceivedExchanges().get(0).getIn().getBody(SplunkEvent.class);
assertNotNull(recieved);
Map<String, String> data = recieved.getEventData();
assertEquals("indexertpool", data.get("name"));
assertEquals(true, searchMock.getReceivedExchanges().get(2).getProperty(Exchange.BATCH_COMPLETE, Boolean.class));
stream.close();
}
use of com.splunk.Job in project camel by apache.
the class SplunkDataReader method runQuery.
private List<SplunkEvent> runQuery(JobArgs queryArgs, boolean realtime, SplunkResultProcessor callback) throws Exception {
Service service = endpoint.getService();
Job job = service.getJobs().create(getSearch(), queryArgs);
LOG.debug("Running search : {} with queryArgs : {}", getSearch(), queryArgs);
if (realtime) {
while (!job.isReady()) {
Thread.sleep(500);
}
// Besides job.isReady there must be some delay before real time job
// is ready
// TODO seems that the realtime stream is not quite isReady to be
// read
Thread.sleep(4000);
} else {
while (!job.isDone()) {
Thread.sleep(500);
}
}
return extractData(job, realtime, callback);
}
use of com.splunk.Job in project camel by apache.
the class SplunkDataReader method savedSearch.
private List<SplunkEvent> savedSearch(SplunkResultProcessor callback) throws Exception {
LOG.trace("saved search start");
ServiceArgs queryArgs = new ServiceArgs();
queryArgs.setApp("search");
if (ObjectHelper.isNotEmpty(endpoint.getConfiguration().getOwner())) {
queryArgs.setOwner(endpoint.getConfiguration().getOwner());
}
if (ObjectHelper.isNotEmpty(endpoint.getConfiguration().getApp())) {
queryArgs.setApp(endpoint.getConfiguration().getApp());
}
Calendar startTime = Calendar.getInstance();
SavedSearch search = null;
Job job = null;
String latestTime = getLatestTime(startTime, false);
String earliestTime = getEarliestTime(startTime, false);
Service service = endpoint.getService();
SavedSearchCollection savedSearches = service.getSavedSearches(queryArgs);
for (SavedSearch s : savedSearches.values()) {
if (s.getName().equals(getSavedSearch())) {
search = s;
break;
}
}
if (search != null) {
SavedSearchDispatchArgs args = new SavedSearchDispatchArgs();
args.setForceDispatch(true);
args.setDispatchEarliestTime(earliestTime);
args.setDispatchLatestTime(latestTime);
job = search.dispatch(args);
} else {
throw new RuntimeException("Unable to find saved search '" + getSavedSearch() + "'.");
}
while (!job.isDone()) {
Thread.sleep(2000);
}
List<SplunkEvent> data = extractData(job, false, callback);
this.lastSuccessfulReadTime = startTime;
return data;
}
Aggregations