This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 727
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#151 Implemented GetSettings and UpdateSettings actions
- Loading branch information
Cihat Keser
committed
Oct 21, 2014
1 parent
a9cd676
commit e5b8cd6
Showing
5 changed files
with
205 additions
and
10 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
22 changes: 22 additions & 0 deletions
22
jest-common/src/main/java/io/searchbox/indices/settings/IndicesSettingsAbstractAction.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,22 @@ | ||
package io.searchbox.indices.settings; | ||
|
||
import io.searchbox.action.GenericResultAbstractAction; | ||
|
||
/** | ||
* @author cihat keser | ||
*/ | ||
public abstract class IndicesSettingsAbstractAction extends GenericResultAbstractAction { | ||
|
||
protected IndicesSettingsAbstractAction(Builder builder) { | ||
super(builder); | ||
setURI(buildURI()); | ||
} | ||
|
||
@Override | ||
protected String buildURI() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append(super.buildURI()).append("/_settings"); | ||
return sb.toString(); | ||
} | ||
|
||
} |
43 changes: 42 additions & 1 deletion
43
jest-common/src/main/java/io/searchbox/indices/settings/UpdateSettings.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 |
---|---|---|
@@ -1,9 +1,50 @@ | ||
package io.searchbox.indices.settings; | ||
|
||
import com.google.gson.Gson; | ||
import io.searchbox.action.AbstractMultiIndexActionBuilder; | ||
|
||
/** | ||
* Change specific index level settings in real time. | ||
* | ||
* @author Dogukan Sonmez | ||
* @author cihat keser | ||
*/ | ||
public class UpdateSettings extends IndicesSettingsAbstractAction { | ||
|
||
private Object source; | ||
|
||
private UpdateSettings(Builder builder) { | ||
super(builder); | ||
this.source = builder.source; | ||
} | ||
|
||
@Override | ||
public String getRestMethodName() { | ||
return "PUT"; | ||
} | ||
|
||
@Override | ||
public Object getData(Gson gson) { | ||
return source; | ||
} | ||
|
||
public static class Builder extends AbstractMultiIndexActionBuilder<UpdateSettings, Builder> { | ||
private final Object source; | ||
|
||
/** | ||
* Please see the <a href="http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-update-settings.html#indices-update-settings">related page on Elasticsearch guide</a> | ||
* for the list of settings that can be changed using this action/API. | ||
* | ||
* @param source body of request that includes updated settings | ||
*/ | ||
public Builder(Object source) { | ||
this.source = source; | ||
} | ||
|
||
@Override | ||
public UpdateSettings build() { | ||
return new UpdateSettings(this); | ||
} | ||
} | ||
|
||
public class UpdateSettings { | ||
} |
20 changes: 20 additions & 0 deletions
20
jest-common/src/test/java/io/searchbox/indices/settings/UpdateSettingsTest.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,20 @@ | ||
package io.searchbox.indices.settings; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
public class UpdateSettingsTest { | ||
|
||
@Test | ||
public void testDefaultBehaviour() { | ||
String expectedUri = "_all/_settings"; | ||
|
||
UpdateSettings updateSettings = new UpdateSettings.Builder("").build(); | ||
assertEquals(expectedUri, updateSettings.getURI()); | ||
assertEquals("", updateSettings.getData(null)); | ||
assertEquals("PUT", updateSettings.getRestMethodName()); | ||
} | ||
|
||
} |
118 changes: 118 additions & 0 deletions
118
jest/src/test/java/io/searchbox/indices/settings/UpdateSettingsIntegrationTest.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,118 @@ | ||
package io.searchbox.indices.settings; | ||
|
||
import io.searchbox.client.JestResult; | ||
import io.searchbox.common.AbstractIntegrationTest; | ||
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest; | ||
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse; | ||
import org.elasticsearch.test.ElasticsearchIntegrationTest; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* @author cihat keser | ||
*/ | ||
@ElasticsearchIntegrationTest.ClusterScope(scope = ElasticsearchIntegrationTest.Scope.SUITE, numDataNodes = 1) | ||
public class UpdateSettingsIntegrationTest extends AbstractIntegrationTest { | ||
private static final String INDEX_1 = "updatesettingstest1"; | ||
private static final String INDEX_2 = "updatesettingstest2"; | ||
|
||
@Before | ||
public void init() { | ||
createIndex(INDEX_1, INDEX_2); | ||
ensureGreen(INDEX_1, INDEX_2); | ||
} | ||
|
||
@Test | ||
public void testBasicFlowForAllIndices() throws IOException { | ||
GetSettingsResponse getSettingsResponse = | ||
client().admin().indices().getSettings(new GetSettingsRequest()).actionGet(); | ||
Integer originalNumberOfReplicas = Integer.parseInt(getSettingsResponse.getSetting(INDEX_1, "index.number_of_replicas")); | ||
Integer expectedNumberOfReplicas = originalNumberOfReplicas + 1; | ||
|
||
String body = "{ \"index\" : { " + | ||
"\"number_of_replicas\" : " + expectedNumberOfReplicas.toString() + | ||
"} }"; | ||
|
||
UpdateSettings updateSettings = new UpdateSettings.Builder(body).build(); | ||
JestResult result = client.execute(updateSettings); | ||
assertNotNull(result); | ||
|
||
assertTrue(result.isSucceeded()); | ||
|
||
getSettingsResponse = client().admin().indices().getSettings(new GetSettingsRequest()).actionGet(); | ||
Integer actualNumberOfReplicasForIndex1 = Integer.parseInt(getSettingsResponse.getSetting(INDEX_1, "index.number_of_replicas")); | ||
Integer actualNumberOfReplicasForIndex2 = Integer.parseInt(getSettingsResponse.getSetting(INDEX_2, "index.number_of_replicas")); | ||
|
||
assertEquals(expectedNumberOfReplicas, actualNumberOfReplicasForIndex1); | ||
assertEquals(expectedNumberOfReplicas, actualNumberOfReplicasForIndex2); | ||
} | ||
|
||
@Test | ||
public void testBasicFlowForNonExistingIndex() throws IOException { | ||
String body = "{ \"index\" : { " + | ||
"\"number_of_replicas\" : 3" + | ||
"} }"; | ||
|
||
UpdateSettings updateSettings = new UpdateSettings.Builder(body).addIndex("idontexist").build(); | ||
JestResult result = client.execute(updateSettings); | ||
assertNotNull(result); | ||
|
||
assertFalse(result.isSucceeded()); | ||
} | ||
|
||
@Test | ||
public void testBasicFlowForTargetedIndex() throws IOException { | ||
GetSettingsResponse getSettingsResponse = | ||
client().admin().indices().getSettings(new GetSettingsRequest()).actionGet(); | ||
Integer originalNumberOfReplicasForIndex1 = Integer.parseInt(getSettingsResponse.getSetting(INDEX_1, "index.number_of_replicas")); | ||
Integer originalNumberOfReplicasForIndex2 = Integer.parseInt(getSettingsResponse.getSetting(INDEX_2, "index.number_of_replicas")); | ||
Integer expectedNumberOfReplicasForIndex1 = originalNumberOfReplicasForIndex1 + 1; | ||
|
||
String body = "{ \"index\" : { " + | ||
"\"number_of_replicas\" : " + expectedNumberOfReplicasForIndex1.toString() + | ||
"} }"; | ||
|
||
UpdateSettings updateSettings = new UpdateSettings.Builder(body).addIndex(INDEX_1).build(); | ||
JestResult result = client.execute(updateSettings); | ||
assertNotNull(result); | ||
|
||
assertTrue(result.isSucceeded()); | ||
|
||
getSettingsResponse = client().admin().indices().getSettings(new GetSettingsRequest()).actionGet(); | ||
Integer actualNumberOfReplicasForIndex1 = Integer.parseInt(getSettingsResponse.getSetting(INDEX_1, "index.number_of_replicas")); | ||
Integer actualNumberOfReplicasForIndex2 = Integer.parseInt(getSettingsResponse.getSetting(INDEX_2, "index.number_of_replicas")); | ||
|
||
assertEquals(expectedNumberOfReplicasForIndex1, actualNumberOfReplicasForIndex1); | ||
assertEquals(originalNumberOfReplicasForIndex2, actualNumberOfReplicasForIndex2); | ||
} | ||
|
||
@Test | ||
public void testWithEmptySource() throws IOException { | ||
UpdateSettings updateSettings = new UpdateSettings.Builder("").addIndex(INDEX_1).build(); | ||
JestResult result = client.execute(updateSettings); | ||
assertNotNull(result); | ||
|
||
assertTrue(result.isSucceeded()); | ||
} | ||
|
||
@Test | ||
public void testWithEmptyJsonSource() throws IOException { | ||
UpdateSettings updateSettings = new UpdateSettings.Builder("{}").addIndex(INDEX_1).build(); | ||
JestResult result = client.execute(updateSettings); | ||
assertNotNull(result); | ||
|
||
assertTrue(result.isSucceeded()); | ||
} | ||
|
||
@Test | ||
public void testWithNullSource() throws IOException { | ||
UpdateSettings updateSettings = new UpdateSettings.Builder(null).addIndex(INDEX_1).build(); | ||
JestResult result = client.execute(updateSettings); | ||
assertNotNull(result); | ||
|
||
assertTrue(result.isSucceeded()); | ||
} | ||
|
||
} |