Skip to content

Commit 95100e0

Browse files
authored
Remove some duplicate request conversion methods. (#33538)
1 parent e6ca55b commit 95100e0

File tree

3 files changed

+2
-117
lines changed

3 files changed

+2
-117
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@
9595
import org.elasticsearch.index.reindex.DeleteByQueryRequest;
9696
import org.elasticsearch.index.reindex.ReindexRequest;
9797
import org.elasticsearch.index.reindex.UpdateByQueryRequest;
98-
import org.elasticsearch.protocol.xpack.license.DeleteLicenseRequest;
99-
import org.elasticsearch.protocol.xpack.license.GetLicenseRequest;
100-
import org.elasticsearch.protocol.xpack.license.PutLicenseRequest;
101-
import org.elasticsearch.protocol.xpack.watcher.DeleteWatchRequest;
102-
import org.elasticsearch.protocol.xpack.watcher.PutWatchRequest;
10398
import org.elasticsearch.rest.action.search.RestSearchAction;
10499
import org.elasticsearch.script.mustache.MultiSearchTemplateRequest;
105100
import org.elasticsearch.script.mustache.SearchTemplateRequest;
@@ -930,72 +925,6 @@ static Request deleteScript(DeleteStoredScriptRequest deleteStoredScriptRequest)
930925
return request;
931926
}
932927

933-
static Request xPackWatcherPutWatch(PutWatchRequest putWatchRequest) {
934-
String endpoint = new EndpointBuilder()
935-
.addPathPartAsIs("_xpack")
936-
.addPathPartAsIs("watcher")
937-
.addPathPartAsIs("watch")
938-
.addPathPart(putWatchRequest.getId())
939-
.build();
940-
941-
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
942-
Params params = new Params(request).withVersion(putWatchRequest.getVersion());
943-
if (putWatchRequest.isActive() == false) {
944-
params.putParam("active", "false");
945-
}
946-
ContentType contentType = createContentType(putWatchRequest.xContentType());
947-
BytesReference source = putWatchRequest.getSource();
948-
request.setEntity(new ByteArrayEntity(source.toBytesRef().bytes, 0, source.length(), contentType));
949-
return request;
950-
}
951-
952-
static Request xPackWatcherDeleteWatch(DeleteWatchRequest deleteWatchRequest) {
953-
String endpoint = new EndpointBuilder()
954-
.addPathPartAsIs("_xpack")
955-
.addPathPartAsIs("watcher")
956-
.addPathPartAsIs("watch")
957-
.addPathPart(deleteWatchRequest.getId())
958-
.build();
959-
960-
Request request = new Request(HttpDelete.METHOD_NAME, endpoint);
961-
return request;
962-
}
963-
964-
static Request putLicense(PutLicenseRequest putLicenseRequest) {
965-
String endpoint = new EndpointBuilder()
966-
.addPathPartAsIs("_xpack")
967-
.addPathPartAsIs("license")
968-
.build();
969-
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
970-
Params parameters = new Params(request);
971-
parameters.withTimeout(putLicenseRequest.timeout());
972-
parameters.withMasterTimeout(putLicenseRequest.masterNodeTimeout());
973-
if (putLicenseRequest.isAcknowledge()) {
974-
parameters.putParam("acknowledge", "true");
975-
}
976-
request.setJsonEntity(putLicenseRequest.getLicenseDefinition());
977-
return request;
978-
}
979-
980-
static Request getLicense(GetLicenseRequest getLicenseRequest) {
981-
String endpoint = new EndpointBuilder()
982-
.addPathPartAsIs("_xpack")
983-
.addPathPartAsIs("license")
984-
.build();
985-
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
986-
Params parameters = new Params(request);
987-
parameters.withLocal(getLicenseRequest.local());
988-
return request;
989-
}
990-
991-
static Request deleteLicense(DeleteLicenseRequest deleteLicenseRequest) {
992-
Request request = new Request(HttpDelete.METHOD_NAME, "/_xpack/license");
993-
Params parameters = new Params(request);
994-
parameters.withTimeout(deleteLicenseRequest.timeout());
995-
parameters.withMasterTimeout(deleteLicenseRequest.masterNodeTimeout());
996-
return request;
997-
}
998-
999928
static HttpEntity createEntity(ToXContent toXContent, XContentType xContentType) throws IOException {
1000929
BytesRef source = XContentHelper.toXContent(toXContent, xContentType, false).toBytesRef();
1001930
return new ByteArrayEntity(source.bytes, source.offset, source.length, createContentType(xContentType));

client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@
109109
import org.elasticsearch.index.reindex.ReindexRequest;
110110
import org.elasticsearch.index.reindex.RemoteInfo;
111111
import org.elasticsearch.index.reindex.UpdateByQueryRequest;
112-
import org.elasticsearch.protocol.xpack.watcher.DeleteWatchRequest;
113-
import org.elasticsearch.protocol.xpack.watcher.PutWatchRequest;
114112
import org.elasticsearch.rest.action.search.RestSearchAction;
115113
import org.elasticsearch.script.Script;
116114
import org.elasticsearch.script.ScriptType;
@@ -129,7 +127,6 @@
129127
import org.elasticsearch.test.ESTestCase;
130128
import org.elasticsearch.test.RandomObjects;
131129

132-
import java.io.ByteArrayOutputStream;
133130
import java.io.IOException;
134131
import java.io.InputStream;
135132
import java.util.ArrayList;
@@ -160,7 +157,6 @@
160157
import static org.hamcrest.CoreMatchers.equalTo;
161158
import static org.hamcrest.Matchers.hasEntry;
162159
import static org.hamcrest.Matchers.hasKey;
163-
import static org.hamcrest.Matchers.is;
164160
import static org.hamcrest.Matchers.nullValue;
165161

166162
public class RequestConvertersTests extends ESTestCase {
@@ -2212,46 +2208,6 @@ public void testEnforceSameContentType() {
22122208
+ "previous requests have content-type [" + xContentType + "]", exception.getMessage());
22132209
}
22142210

2215-
public void testXPackPutWatch() throws Exception {
2216-
PutWatchRequest putWatchRequest = new PutWatchRequest();
2217-
String watchId = randomAlphaOfLength(10);
2218-
putWatchRequest.setId(watchId);
2219-
String body = randomAlphaOfLength(20);
2220-
putWatchRequest.setSource(new BytesArray(body), XContentType.JSON);
2221-
2222-
Map<String, String> expectedParams = new HashMap<>();
2223-
if (randomBoolean()) {
2224-
putWatchRequest.setActive(false);
2225-
expectedParams.put("active", "false");
2226-
}
2227-
2228-
if (randomBoolean()) {
2229-
long version = randomLongBetween(10, 100);
2230-
putWatchRequest.setVersion(version);
2231-
expectedParams.put("version", String.valueOf(version));
2232-
}
2233-
2234-
Request request = RequestConverters.xPackWatcherPutWatch(putWatchRequest);
2235-
assertEquals(HttpPut.METHOD_NAME, request.getMethod());
2236-
assertEquals("/_xpack/watcher/watch/" + watchId, request.getEndpoint());
2237-
assertEquals(expectedParams, request.getParameters());
2238-
assertThat(request.getEntity().getContentType().getValue(), is(XContentType.JSON.mediaTypeWithoutParameters()));
2239-
ByteArrayOutputStream bos = new ByteArrayOutputStream();
2240-
request.getEntity().writeTo(bos);
2241-
assertThat(bos.toString("UTF-8"), is(body));
2242-
}
2243-
2244-
public void testXPackDeleteWatch() {
2245-
DeleteWatchRequest deleteWatchRequest = new DeleteWatchRequest();
2246-
String watchId = randomAlphaOfLength(10);
2247-
deleteWatchRequest.setId(watchId);
2248-
2249-
Request request = RequestConverters.xPackWatcherDeleteWatch(deleteWatchRequest);
2250-
assertEquals(HttpDelete.METHOD_NAME, request.getMethod());
2251-
assertEquals("/_xpack/watcher/watch/" + watchId, request.getEndpoint());
2252-
assertThat(request.getEntity(), nullValue());
2253-
}
2254-
22552211
/**
22562212
* Randomize the {@link FetchSourceContext} request parameters.
22572213
*/

client/rest-high-level/src/test/java/org/elasticsearch/client/WatcherRequestConvertersTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
public class WatcherRequestConvertersTests extends ESTestCase {
3838

39-
public void testXPackPutWatch() throws Exception {
39+
public void testPutWatch() throws Exception {
4040
PutWatchRequest putWatchRequest = new PutWatchRequest();
4141
String watchId = randomAlphaOfLength(10);
4242
putWatchRequest.setId(watchId);
@@ -65,7 +65,7 @@ public void testXPackPutWatch() throws Exception {
6565
assertThat(bos.toString("UTF-8"), is(body));
6666
}
6767

68-
public void testXPackDeleteWatch() {
68+
public void testDeleteWatch() {
6969
DeleteWatchRequest deleteWatchRequest = new DeleteWatchRequest();
7070
String watchId = randomAlphaOfLength(10);
7171
deleteWatchRequest.setId(watchId);

0 commit comments

Comments
 (0)