Skip to content

Commit

Permalink
v2 Search API changes reverted
Browse files Browse the repository at this point in the history
  • Loading branch information
ashah-splunk committed Aug 29, 2022
1 parent cf26ad8 commit 7adbaba
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
21 changes: 11 additions & 10 deletions splunk/src/main/java/com/splunk/Job.java
Original file line number Diff line number Diff line change
Expand Up @@ -368,18 +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);
}
// 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
13 changes: 8 additions & 5 deletions splunk/src/main/java/com/splunk/JobCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ 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";
//static final String REST_PATH_V2 = "search/v2/jobs";
/**
* Class constructor.
*
* @param service The connected {@code Service} instance.
*/
JobCollection(Service service) {
super(service, service.versionIsAtLeast("9.0") ? REST_PATH_V2 : REST_PATH, Job.class);
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 @@ -46,7 +47,8 @@ public class JobCollection extends EntityCollection<Job> {
* return and how to sort them (see {@link CollectionArgs}).
*/
JobCollection(Service service, Args args) {
super(service, service.versionIsAtLeast("9.0") ? REST_PATH_V2 : REST_PATH, Job.class, args);
super(service, REST_PATH, Job.class);
//super(service, service.versionIsAtLeast("9.0") ? REST_PATH_V2 : REST_PATH, Job.class, args);
this.refreshArgs.put("count", "0");
}

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

String path = service.versionIsAtLeast("9.0") ? REST_PATH_V2 : REST_PATH;
Job job = new Job(service, path + "/" + sid);
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
24 changes: 12 additions & 12 deletions splunk/src/main/java/com/splunk/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,13 @@ public InputStream export(String search, Map args) {
if (!args.containsKey("segmentation")) {
args.put("segmentation", "none");
}
ResponseMessage response;

if (versionIsAtLeast("9.0"))
response = post(JobCollection.REST_PATH_V2 + "/export", args);
else {
response = post(JobCollection.REST_PATH + "/export", args);
}
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 @@ -1257,11 +1257,11 @@ public ResponseMessage parse(String query) {
*/
public ResponseMessage parse(String query, Map args) {
args = Args.create(args).add("q", query);

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

/**
Expand Down

0 comments on commit 7adbaba

Please sign in to comment.