use of com.splunk.ServiceArgs in project camel by apache.
the class SplunkConnectionFactory method createService.
public synchronized Service createService(CamelContext camelContext) {
final ServiceArgs args = new ServiceArgs();
if (host != null) {
args.setHost(host);
}
if (port > 0) {
args.setPort(port);
}
if (scheme != null) {
args.setScheme(scheme);
}
if (app != null) {
args.setApp(app);
}
if (owner != null) {
args.setOwner(owner);
}
args.setUsername(username);
args.setPassword(password);
// (wls i'm looking at you)
if (isUseSunHttpsHandler()) {
String sunHandlerClassName = "sun.net.www.protocol.https.Handler";
Class<URLStreamHandler> clazz = camelContext.getClassResolver().resolveClass(sunHandlerClassName, URLStreamHandler.class);
if (clazz != null) {
URLStreamHandler handler = camelContext.getInjector().newInstance(clazz);
args.setHTTPSHandler(handler);
LOG.debug("using the URLStreamHandler {} for {}", handler, args);
} else {
LOG.warn("could not resolve and use the URLStreamHandler class '{}'", sunHandlerClassName);
}
}
ExecutorService executor = camelContext.getExecutorServiceManager().newSingleThreadExecutor(this, "DefaultSplunkConnectionFactory");
Future<Service> future = executor.submit(new Callable<Service>() {
public Service call() throws Exception {
if (Service.DEFAULT_SCHEME.equals(getScheme())) {
LOG.debug("Https in use. Setting SSL protocol to {}", getSslProtocol());
HttpService.setSslSecurityProtocol(getSslProtocol());
}
return Service.connect(args);
}
});
try {
Service service = null;
if (connectionTimeout > 0) {
service = future.get(connectionTimeout, TimeUnit.MILLISECONDS);
} else {
service = future.get();
}
LOG.info("Successfully connected to Splunk");
return service;
} catch (Exception e) {
throw new RuntimeException(String.format("could not connect to Splunk Server @ %s:%d - %s", host, port, e.getMessage()));
} finally {
if (executor != null) {
camelContext.getExecutorServiceManager().shutdownNow(executor);
}
}
}
use of com.splunk.ServiceArgs 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