Search in sources :

Example 1 with Job

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();
}
Also used : JobResultsArgs(com.splunk.JobResultsArgs) SplunkEvent(org.apache.camel.component.splunk.event.SplunkEvent) JobCollection(com.splunk.JobCollection) JobArgs(com.splunk.JobArgs) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) InputStream(java.io.InputStream) Matchers.anyString(org.mockito.Matchers.anyString) Job(com.splunk.Job) Test(org.junit.Test)

Example 2 with Job

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();
}
Also used : JobResultsArgs(com.splunk.JobResultsArgs) SplunkEvent(org.apache.camel.component.splunk.event.SplunkEvent) JobCollection(com.splunk.JobCollection) JobArgs(com.splunk.JobArgs) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) InputStream(java.io.InputStream) Matchers.anyString(org.mockito.Matchers.anyString) Job(com.splunk.Job) Test(org.junit.Test)

Example 3 with Job

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);
}
Also used : Service(com.splunk.Service) Job(com.splunk.Job)

Example 4 with Job

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;
}
Also used : SavedSearchCollection(com.splunk.SavedSearchCollection) SplunkEvent(org.apache.camel.component.splunk.event.SplunkEvent) ServiceArgs(com.splunk.ServiceArgs) SavedSearch(com.splunk.SavedSearch) Calendar(java.util.Calendar) Service(com.splunk.Service) SavedSearchDispatchArgs(com.splunk.SavedSearchDispatchArgs) Job(com.splunk.Job)

Aggregations

Job (com.splunk.Job)4 SplunkEvent (org.apache.camel.component.splunk.event.SplunkEvent)3 JobArgs (com.splunk.JobArgs)2 JobCollection (com.splunk.JobCollection)2 JobResultsArgs (com.splunk.JobResultsArgs)2 Service (com.splunk.Service)2 InputStream (java.io.InputStream)2 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)2 Test (org.junit.Test)2 Matchers.anyString (org.mockito.Matchers.anyString)2 SavedSearch (com.splunk.SavedSearch)1 SavedSearchCollection (com.splunk.SavedSearchCollection)1 SavedSearchDispatchArgs (com.splunk.SavedSearchDispatchArgs)1 ServiceArgs (com.splunk.ServiceArgs)1 Calendar (java.util.Calendar)1