diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6ff012f8..d4cdce89 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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: @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1df987b9..84ca35c8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: java-version: - 1.8 splunk-version: - - "8.0" + - "8.2" - "latest" runs-on: ${{ matrix.os }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 2438cf0c..aa425ff9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 77483b8a..3087c219 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 @@ -75,7 +75,7 @@ To add the Splunk SDK for Java `.JAR` file as a dependency: com.splunk splunk - 1.8.0 + 1.9.0 ``` diff --git a/deploy b/deploy index 5a7a6c0d..cb13e579 100755 --- a/deploy +++ b/deploy @@ -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}" diff --git a/deploy.md b/deploy.md index af57427a..ec5046e5 100644 --- a/deploy.md +++ b/deploy.md @@ -9,8 +9,8 @@ deploy \ ##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 | @@ -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. diff --git a/examples/pom.xml b/examples/pom.xml index 49d8981c..4b2b2462 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -37,7 +37,7 @@ com.splunk splunk - 1.8.0 + 1.9.0 provided diff --git a/pom.xml b/pom.xml index 9bfafba5..195c08c8 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 - 1.8.0 + 1.9.0 true UTF-8 8 diff --git a/splunk/pom.xml b/splunk/pom.xml index 4e0e361d..80680170 100644 --- a/splunk/pom.xml +++ b/splunk/pom.xml @@ -5,7 +5,7 @@ 4.0.0 splunk - 1.8.0 + 1.9.0 splunk-sdk-java com.splunk @@ -71,7 +71,7 @@ org.jacoco jacoco-maven-plugin - 0.8.7 + 0.8.8 diff --git a/splunk/src/main/java/com/splunk/HttpService.java b/splunk/src/main/java/com/splunk/HttpService.java index ef7d335d..693f3a36 100644 --- a/splunk/src/main/java/com/splunk/HttpService.java +++ b/splunk/src/main/java/com/splunk/HttpService.java @@ -89,7 +89,7 @@ public boolean verify(String s, SSLSession sslSession) { private String prefix = null; static Map defaultHeader = new HashMap() {{ - put("User-Agent", "splunk-sdk-java/1.8.0"); + put("User-Agent", "splunk-sdk-java/1.9.0"); put("Accept", "*/*"); }}; @@ -208,7 +208,7 @@ public int getPort() { /** * Sets Custom Headers of this service * - * @param headers + * @param headers The custom headers. */ public void setCustomHeaders(Map headers) { if (Objects.nonNull(headers)) { diff --git a/splunk/src/main/java/com/splunk/Job.java b/splunk/src/main/java/com/splunk/Job.java index 3456b1e0..d101eeaf 100644 --- a/splunk/src/main/java/com/splunk/Job.java +++ b/splunk/src/main/java/com/splunk/Job.java @@ -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); @@ -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(); } diff --git a/splunk/src/main/java/com/splunk/JobCollection.java b/splunk/src/main/java/com/splunk/JobCollection.java index 529fb9da..b47feadc 100644 --- a/splunk/src/main/java/com/splunk/JobCollection.java +++ b/splunk/src/main/java/com/splunk/JobCollection.java @@ -27,13 +27,14 @@ public class JobCollection extends EntityCollection { 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"); } @@ -45,7 +46,7 @@ public class JobCollection extends EntityCollection { * 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"); } @@ -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; diff --git a/splunk/src/main/java/com/splunk/OutputServer.java b/splunk/src/main/java/com/splunk/OutputServer.java index 2bcd19b3..cafec3f6 100644 --- a/splunk/src/main/java/com/splunk/OutputServer.java +++ b/splunk/src/main/java/com/splunk/OutputServer.java @@ -92,7 +92,7 @@ public String getStatus() { /** * Returns client certificate path. * - * @return + * @return Path of client certificate. */ public String getClientCert() { return getString("clientCert", ""); diff --git a/splunk/src/main/java/com/splunk/Service.java b/splunk/src/main/java/com/splunk/Service.java index 4f4edcad..cbe63b4a 100644 --- a/splunk/src/main/java/com/splunk/Service.java +++ b/splunk/src/main/java/com/splunk/Service.java @@ -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()); } @@ -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); } /** diff --git a/splunk/src/test/java/com/splunk/SearchJobTest.java b/splunk/src/test/java/com/splunk/SearchJobTest.java index 5993417d..fbb7cbce 100644 --- a/splunk/src/test/java/com/splunk/SearchJobTest.java +++ b/splunk/src/test/java/com/splunk/SearchJobTest.java @@ -62,6 +62,18 @@ public void testEventsFromJob() { job.cancel(); } + @Test + public void testEventsWithSearchParams() { + Job job = jobs.create(QUERY); + waitUntilDone(job); + + Map args = new HashMap(); + args.put("search","| head 1"); + Assert.assertEquals(1, countEvents(job.getEvents(args))); + + job.cancel(); + } + @Test public void testResultsFromJob() { Job job = jobs.create(QUERY); @@ -71,6 +83,18 @@ public void testResultsFromJob() { job.cancel(); } + + @Test + public void testResultsWithSearchParams() { + Job job = jobs.create(QUERY); + waitUntilDone(job); + + Map args = new HashMap(); + args.put("search","| head 1"); + Assert.assertEquals(1, countEvents(job.getResults(args))); + + job.cancel(); + } @Test public void testGetJobBySid() { @@ -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(); + 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);