Skip to content

Commit e7a921b

Browse files
committed
Revert "v2 Search API changes reverted"
This reverts commit 7adbaba.
1 parent d6fe200 commit e7a921b

File tree

3 files changed

+27
-31
lines changed

3 files changed

+27
-31
lines changed

splunk/src/main/java/com/splunk/Job.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -368,19 +368,18 @@ private InputStream getEventsMethod(String methodPath, Map args) {
368368
args.put("segmentation", "none");
369369
}
370370

371-
ResponseMessage response = service.get(path + methodPath, args);
372371
// Splunk version pre-9.0 doesn't support v2
373372
// v1(GET), v2(POST)
374-
// String fullPath;
375-
// ResponseMessage response;
376-
// if (service.versionIsEarlierThan("9.0")) {
377-
// fullPath = path.replace(JobCollection.REST_PATH_V2, JobCollection.REST_PATH) + methodPath;
378-
// response = service.get(fullPath, args);
379-
// }
380-
// else {
381-
// fullPath = path.replace(JobCollection.REST_PATH, JobCollection.REST_PATH_V2) + methodPath;
382-
// response = service.post(fullPath, args);
383-
// }
373+
String fullPath;
374+
ResponseMessage response;
375+
if (service.versionIsEarlierThan("9.0")) {
376+
fullPath = path.replace(JobCollection.REST_PATH_V2, JobCollection.REST_PATH) + methodPath;
377+
response = service.get(fullPath, args);
378+
}
379+
else {
380+
fullPath = path.replace(JobCollection.REST_PATH, JobCollection.REST_PATH_V2) + methodPath;
381+
response = service.post(fullPath, args);
382+
}
384383

385384
return response.getContent();
386385
}

splunk/src/main/java/com/splunk/JobCollection.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,14 @@ public class JobCollection extends EntityCollection<Job> {
2727
static String oneShotNotAllowed = String.format(
2828
"Oneshot not allowed, use service oneshot search method");
2929
static final String REST_PATH = "search/jobs";
30-
//static final String REST_PATH_V2 = "search/v2/jobs";
30+
static final String REST_PATH_V2 = "search/v2/jobs";
3131
/**
3232
* Class constructor.
3333
*
3434
* @param service The connected {@code Service} instance.
3535
*/
3636
JobCollection(Service service) {
37-
super(service, REST_PATH, Job.class);
38-
//super(service, service.versionIsAtLeast("9.0") ? REST_PATH_V2 : REST_PATH, Job.class);
37+
super(service, service.versionIsAtLeast("9.0") ? REST_PATH_V2 : REST_PATH, Job.class);
3938
this.refreshArgs.put("count", "0");
4039
}
4140

@@ -47,8 +46,7 @@ public class JobCollection extends EntityCollection<Job> {
4746
* return and how to sort them (see {@link CollectionArgs}).
4847
*/
4948
JobCollection(Service service, Args args) {
50-
super(service, REST_PATH, Job.class);
51-
//super(service, service.versionIsAtLeast("9.0") ? REST_PATH_V2 : REST_PATH, Job.class, args);
49+
super(service, service.versionIsAtLeast("9.0") ? REST_PATH_V2 : REST_PATH, Job.class, args);
5250
this.refreshArgs.put("count", "0");
5351
}
5452

@@ -89,9 +87,8 @@ public Job create(String query, Map args) {
8987
.item(0)
9088
.getTextContent();
9189

92-
Job job = new Job(service, REST_PATH + "/" + sid);
93-
//String path = service.versionIsAtLeast("9.0") ? REST_PATH_V2 : REST_PATH;
94-
//Job job = new Job(service, path + "/" + sid);
90+
String path = service.versionIsAtLeast("9.0") ? REST_PATH_V2 : REST_PATH;
91+
Job job = new Job(service, path + "/" + sid);
9592
job.refresh();
9693

9794
return job;

splunk/src/main/java/com/splunk/Service.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,13 @@ public InputStream export(String search, Map args) {
223223
if (!args.containsKey("segmentation")) {
224224
args.put("segmentation", "none");
225225
}
226-
ResponseMessage response = get(JobCollection.REST_PATH + "/export", args);
227-
// ResponseMessage response;
228-
// if (versionIsAtLeast("9.0"))
229-
// response = post(JobCollection.REST_PATH_V2 + "/export", args);
230-
// else {
231-
// response = post(JobCollection.REST_PATH + "/export", args);
232-
// }
226+
ResponseMessage response;
227+
228+
if (versionIsAtLeast("9.0"))
229+
response = post(JobCollection.REST_PATH_V2 + "/export", args);
230+
else {
231+
response = post(JobCollection.REST_PATH + "/export", args);
232+
}
233233
return new ExportResultsStream(response.getContent());
234234
}
235235

@@ -1257,11 +1257,11 @@ public ResponseMessage parse(String query) {
12571257
*/
12581258
public ResponseMessage parse(String query, Map args) {
12591259
args = Args.create(args).add("q", query);
1260-
return get("search/parser", args);
1261-
// if (versionIsAtLeast("9.0"))
1262-
// return post("search/v2/parser", args);
1263-
// else
1264-
// return get("search/parser", args);
1260+
1261+
if (versionIsAtLeast("9.0"))
1262+
return post("search/v2/parser", args);
1263+
else
1264+
return get("search/parser", args);
12651265
}
12661266

12671267
/**

0 commit comments

Comments
 (0)