Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
server-id: splunk-artifactory
- name: build
run: mvn package --file pom.xml -DskipTests=true
- name: Create temp artifacts apidocs folder
run: mkdir apidocs
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
Expand All @@ -32,3 +34,12 @@ jobs:
env:
MAVEN_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}

- name: Zip docs
run: zip -r apidocs/docs.zip splunk/target/apidocs

- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: apidocs
path: apidocs/docs.zip
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
java-version:
- 1.8
splunk-version:
- "8.0"
- "8.2"
- "latest"
runs-on: ${{ matrix.os }}

Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Splunk Enterprise SDK for Java Changelog

## Version 1.9.0

### New Features and APIs
* SDK Support for splunkd search API changes, for Splunk 9.0+. (Github PR [#189](https://github.com/splunk/splunk-sdk-java/pull/189))

### Minor Changes
* Automated docs generation using GitHub actions. (Github PR [#184](https://github.com/splunk/splunk-sdk-java/pull/184))

## Version 1.8.0

### New Features and APIs
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![Java SDK Test](https://github.com/splunk/splunk-sdk-java/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/splunk/splunk-sdk-java/actions/workflows/test.yml)
# The Splunk Software Development Kit for Java

#### Version 1.8.0
#### Version 1.9.0

The Splunk Software Development Kit (SDK) for Java contains library code and
examples designed to enable developers to build applications using Splunk.
Expand Down Expand Up @@ -40,7 +40,7 @@ Here's what you need to get going with the Splunk SDK for Java.
If you haven't already installed Splunk, download it
[here](http://www.splunk.com/download). For more about installing and running
Splunk and system requirements, see
[Installing & Running Splunk](http://dev.splunk.com/view/SP-CAAADRV). The Splunk SDK for Java has been tested with Splunk Enterprise 8.0 and 8.2.0.
[Installing & Running Splunk](http://dev.splunk.com/view/SP-CAAADRV). The Splunk SDK for Java has been tested with Splunk Enterprise 9.0 and 8.2.

#### Splunk SDK for Java

Expand Down Expand Up @@ -75,7 +75,7 @@ To add the Splunk SDK for Java `.JAR` file as a dependency:
<dependency>
<groupId>com.splunk</groupId>
<artifactId>splunk</artifactId>
<version>1.8.0</version>
<version>1.9.0</version>
</dependency>
</dependencies>
```
Expand Down
2 changes: 1 addition & 1 deletion deploy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare -r scriptDirectory="$(dirname $(readlink -e $0))"
declare -r scriptName="$(basename $0)"
declare -r version="1.8.0"
declare -r version="1.9.0"

if [[ $# -ne 1 ]]; then
echo 1>&2 "Usage: ${scriptName} {local|staging||production}"
Expand Down
30 changes: 15 additions & 15 deletions deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ deploy \<repository-name>

##DESCRIPTION

Deploy transmits **target/splunk-1.8.0.jar**, **target/splunk-1.8.0-javadoc.jar**, and
**target/splunk-1.8.0-sources.jar** to the **local**, **staging**, or **production**
Deploy transmits **target/splunk-1.9.0.jar**, **target/splunk-1.9.0-javadoc.jar**, and
**target/splunk-1.9.0-sources.jar** to the **local**, **staging**, or **production**
maven repository. Repository names are mapped to locations as follows.

| repository-name | location |
Expand All @@ -21,18 +21,18 @@ maven repository. Repository names are mapped to locations as follows.

After deployment you should find this tree structure at the location of your repository

com/splunk/splunk/1.8.0/
├── splunk-1.8.0-javadoc.jar
├── splunk-1.8.0-javadoc.jar.md5
├── splunk-1.8.0-javadoc.jar.sha1
├── splunk-1.8.0-sources.jar
├── splunk-1.8.0-sources.jar.md5
├── splunk-1.8.0-sources.jar.sha1
├── splunk-1.8.0.jar
├── splunk-1.8.0.jar.md5
├── splunk-1.8.0.jar.sha1
├── splunk-1.8.0.pom
├── splunk-1.8.0.pom.md5
└── splunk-1.8.0.pom.sha1
com/splunk/splunk/1.9.0/
├── splunk-1.9.0-javadoc.jar
├── splunk-1.9.0-javadoc.jar.md5
├── splunk-1.9.0-javadoc.jar.sha1
├── splunk-1.9.0-sources.jar
├── splunk-1.9.0-sources.jar.md5
├── splunk-1.9.0-sources.jar.sha1
├── splunk-1.9.0.jar
├── splunk-1.9.0.jar.md5
├── splunk-1.9.0.jar.sha1
├── splunk-1.9.0.pom
├── splunk-1.9.0.pom.md5
└── splunk-1.9.0.pom.sha1

Verify this structure prior to release.
2 changes: 1 addition & 1 deletion examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<dependency>
<groupId>com.splunk</groupId>
<artifactId>splunk</artifactId>
<version>1.8.0</version>
<version>1.9.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>

<properties>
<version.number>1.8.0</version.number>
<version.number>1.9.0</version.number>
<maven.resources.overwrite>true</maven.resources.overwrite>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>8</maven.compiler.source>
Expand Down
4 changes: 2 additions & 2 deletions splunk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>splunk</artifactId>
<version>1.8.0</version>
<version>1.9.0</version>
<parent>
<artifactId>splunk-sdk-java</artifactId>
<groupId>com.splunk</groupId>
Expand Down Expand Up @@ -71,7 +71,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<version>0.8.8</version>
<executions>
<execution>
<goals>
Expand Down
4 changes: 2 additions & 2 deletions splunk/src/main/java/com/splunk/HttpService.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public boolean verify(String s, SSLSession sslSession) {
private String prefix = null;

static Map<String, String> defaultHeader = new HashMap<String, String>() {{
put("User-Agent", "splunk-sdk-java/1.8.0");
put("User-Agent", "splunk-sdk-java/1.9.0");
put("Accept", "*/*");
}};

Expand Down Expand Up @@ -208,7 +208,7 @@ public int getPort() {
/**
* Sets Custom Headers of this service
*
* @param headers
* @param headers The custom headers.
*/
public void setCustomHeaders(Map<String, String> headers) {
if (Objects.nonNull(headers)) {
Expand Down
15 changes: 14 additions & 1 deletion splunk/src/main/java/com/splunk/Job.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class Job extends Entity {
*
* @param service The connected {@code Service} instance.
* @param path The search jobs endpoint.
* @param sid The sid of the job.
*/
Job(Service service, String path) {
super(service, path);
Expand Down Expand Up @@ -367,7 +368,19 @@ private InputStream getEventsMethod(String methodPath, Map args) {
args.put("segmentation", "none");
}

ResponseMessage response = service.get(path + methodPath, args);
// Splunk version pre-9.0 doesn't support v2
// v1(GET), v2(POST)
String fullPath;
ResponseMessage response;
if (service.versionIsEarlierThan("9.0")) {
fullPath = path.replace(JobCollection.REST_PATH_V2, JobCollection.REST_PATH) + methodPath;
response = service.get(fullPath, args);
}
else {
fullPath = path.replace(JobCollection.REST_PATH, JobCollection.REST_PATH_V2) + methodPath;
response = service.post(fullPath, args);
}

return response.getContent();
}

Expand Down
8 changes: 5 additions & 3 deletions splunk/src/main/java/com/splunk/JobCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ public class JobCollection extends EntityCollection<Job> {
static String oneShotNotAllowed = String.format(
"Oneshot not allowed, use service oneshot search method");
static final String REST_PATH = "search/jobs";
static final String REST_PATH_V2 = "search/v2/jobs";
/**
* Class constructor.
*
* @param service The connected {@code Service} instance.
*/
JobCollection(Service service) {
super(service, REST_PATH, Job.class);
super(service, service.versionIsAtLeast("9.0") ? REST_PATH_V2 : REST_PATH, Job.class);
this.refreshArgs.put("count", "0");
}

Expand All @@ -45,7 +46,7 @@ public class JobCollection extends EntityCollection<Job> {
* return and how to sort them (see {@link CollectionArgs}).
*/
JobCollection(Service service, Args args) {
super(service, REST_PATH, Job.class, args);
super(service, service.versionIsAtLeast("9.0") ? REST_PATH_V2 : REST_PATH, Job.class, args);
this.refreshArgs.put("count", "0");
}

Expand Down Expand Up @@ -86,7 +87,8 @@ public Job create(String query, Map args) {
.item(0)
.getTextContent();

Job job = new Job(service, REST_PATH + "/" + sid);
String path = service.versionIsAtLeast("9.0") ? REST_PATH_V2 : REST_PATH;
Job job = new Job(service, path + "/" + sid);
job.refresh();

return job;
Expand Down
2 changes: 1 addition & 1 deletion splunk/src/main/java/com/splunk/OutputServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public String getStatus() {
/**
* Returns client certificate path.
*
* @return
* @return Path of client certificate.
*/
public String getClientCert() {
return getString("clientCert", "");
Expand Down
14 changes: 12 additions & 2 deletions splunk/src/main/java/com/splunk/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,13 @@ public InputStream export(String search, Map args) {
if (!args.containsKey("segmentation")) {
args.put("segmentation", "none");
}
ResponseMessage response = get(JobCollection.REST_PATH + "/export", args);
ResponseMessage response;

if (versionIsAtLeast("9.0"))
response = post(JobCollection.REST_PATH_V2 + "/export", args);
else {
response = post(JobCollection.REST_PATH + "/export", args);
}
return new ExportResultsStream(response.getContent());
}

Expand Down Expand Up @@ -1251,7 +1257,11 @@ public ResponseMessage parse(String query) {
*/
public ResponseMessage parse(String query, Map args) {
args = Args.create(args).add("q", query);
return get("search/parser", args);

if (versionIsAtLeast("9.0"))
return post("search/v2/parser", args);
else
return get("search/parser", args);
}

/**
Expand Down
44 changes: 44 additions & 0 deletions splunk/src/test/java/com/splunk/SearchJobTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ public void testEventsFromJob() {
job.cancel();
}

@Test
public void testEventsWithSearchParams() {
Job job = jobs.create(QUERY);
waitUntilDone(job);

Map args = new HashMap<String, Object>();
args.put("search","| head 1");
Assert.assertEquals(1, countEvents(job.getEvents(args)));

job.cancel();
}

@Test
public void testResultsFromJob() {
Job job = jobs.create(QUERY);
Expand All @@ -71,6 +83,18 @@ public void testResultsFromJob() {

job.cancel();
}

@Test
public void testResultsWithSearchParams() {
Job job = jobs.create(QUERY);
waitUntilDone(job);

Map args = new HashMap<String, Object>();
args.put("search","| head 1");
Assert.assertEquals(1, countEvents(job.getResults(args)));

job.cancel();
}

@Test
public void testGetJobBySid() {
Expand Down Expand Up @@ -584,6 +608,26 @@ public void testPreview() throws InterruptedException {
job.cancel();
}

@Test
public void testPreviewWithSearchParams() throws InterruptedException {
JobArgs args = new JobArgs();
args.put("field_list", "source,host,sourcetype");
args.setStatusBuckets(100);

Job job = jobs.create(QUERY, args);

while (!job.isReady()) {
Thread.sleep(100);
}

Map argsSearchQuery = new HashMap<String, Object>();
argsSearchQuery.put("search","| head 1");
// Assert.assertTrue(1 >= countEvents(job.getResultsPreview(args)));
Assert.assertEquals(1, countEvents(job.getResultsPreview(argsSearchQuery)));

job.cancel();
}

@Test
public void testSearchLog() {
Job job = jobs.create(QUERY);
Expand Down