-
Notifications
You must be signed in to change notification settings - Fork 24.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Put warmer api to support acknowledgements
Added support for acknowledgements in put warmer api using the generic mechanism introduced in #3786 Closes #3831
- Loading branch information
Showing
10 changed files
with
271 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/org/elasticsearch/action/support/master/AcknowledgedRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Licensed to ElasticSearch and Shay Banon under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. ElasticSearch licenses this | ||
* file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package org.elasticsearch.action.support.master; | ||
|
||
import org.elasticsearch.action.ActionRequest; | ||
import org.elasticsearch.common.unit.TimeValue; | ||
|
||
/** | ||
* Interface that allows to mark action requests that support acknowledgements. | ||
* Facilitates consistency across different api. | ||
*/ | ||
public interface AcknowledgedRequest<T extends ActionRequest<T>> { | ||
|
||
/** | ||
* Allows to set the timeout | ||
* @param timeout timeout as a string (e.g. 1s) | ||
* @return the request itself | ||
*/ | ||
T timeout(String timeout); | ||
|
||
/** | ||
* Allows to set the timeout | ||
* @param timeout timeout as a {@link TimeValue} | ||
* @return the request itself | ||
*/ | ||
T timeout(TimeValue timeout); | ||
|
||
/** | ||
* Returns the current timeout | ||
* @return the current timeout as a {@link TimeValue} | ||
*/ | ||
TimeValue timeout(); | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/org/elasticsearch/action/support/master/AcknowledgedResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Licensed to ElasticSearch and Shay Banon under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. ElasticSearch licenses this | ||
* file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package org.elasticsearch.action.support.master; | ||
|
||
/** | ||
* Interface that allows to mark action responses that support acknowledgements. | ||
* Facilitates consistency across different api. | ||
*/ | ||
public interface AcknowledgedResponse { | ||
|
||
/** | ||
* Returns whether the response is acknowledged or not | ||
* @return true if the response is acknowledged, false otherwise | ||
*/ | ||
boolean isAcknowledged(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/test/java/org/elasticsearch/action/admin/indices/warmer/put/PutWarmerRequestTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Licensed to ElasticSearch and Shay Banon under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. ElasticSearch licenses this | ||
* file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package org.elasticsearch.action.admin.indices.warmer.put; | ||
|
||
import org.elasticsearch.Version; | ||
import org.elasticsearch.common.io.stream.InputStreamStreamInput; | ||
import org.elasticsearch.common.io.stream.OutputStreamStreamOutput; | ||
import org.elasticsearch.common.unit.TimeValue; | ||
import org.elasticsearch.test.ElasticsearchTestCase; | ||
import org.junit.Test; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
|
||
public class PutWarmerRequestTests extends ElasticsearchTestCase { | ||
|
||
@Test | ||
public void testPutWarmerTimeoutBwComp_Pre0906Format() 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_0); | ||
outRequest.writeTo(out); | ||
|
||
ByteArrayInputStream esInBuffer = new ByteArrayInputStream(outBuffer.toByteArray()); | ||
InputStreamStreamInput esBuffer = new InputStreamStreamInput(esInBuffer); | ||
esBuffer.setVersion(Version.V_0_90_0); | ||
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(new PutWarmerRequest().timeout().millis())); | ||
} | ||
|
||
@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())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.