@Override
 public void handleRequest(final RestRequest request, final RestChannel channel) {
   PutWarmerRequest putWarmerRequest = new PutWarmerRequest(request.param("name"));
   putWarmerRequest.listenerThreaded(false);
   SearchRequest searchRequest =
       new SearchRequest(Strings.splitStringByCommaToArray(request.param("index")))
           .types(Strings.splitStringByCommaToArray(request.param("type")))
           .source(request.content(), request.contentUnsafe());
   searchRequest.indicesOptions(
       IndicesOptions.fromRequest(request, searchRequest.indicesOptions()));
   putWarmerRequest.searchRequest(searchRequest);
   putWarmerRequest.timeout(request.paramAsTime("timeout", putWarmerRequest.timeout()));
   putWarmerRequest.masterNodeTimeout(
       request.paramAsTime("master_timeout", putWarmerRequest.masterNodeTimeout()));
   client
       .admin()
       .indices()
       .putWarmer(
           putWarmerRequest, new AcknowledgedRestResponseActionListener(request, channel, logger));
 }
Ejemplo n.º 2
0
  @Test
  public void testPutWarmerTimeoutBwComp_Post0906Format() throws Exception {
    PutWarmerRequest outRequest = new PutWarmerRequest("warmer1");
    outRequest.timeout(TimeValue.timeValueMillis(1000));

    ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
    OutputStreamStreamOutput out = new OutputStreamStreamOutput(outBuffer);
    out.setVersion(Version.V_0_90_6);
    outRequest.writeTo(out);

    ByteArrayInputStream esInBuffer = new ByteArrayInputStream(outBuffer.toByteArray());
    InputStreamStreamInput esBuffer = new InputStreamStreamInput(esInBuffer);
    esBuffer.setVersion(Version.V_0_90_6);
    PutWarmerRequest inRequest = new PutWarmerRequest();
    inRequest.readFrom(esBuffer);

    assertThat(inRequest.name(), equalTo("warmer1"));
    // timeout is default as we don't read it from the received buffer
    assertThat(inRequest.timeout().millis(), equalTo(outRequest.timeout().millis()));
  }