use of org.elasticsearch.cluster.ClusterName in project elasticsearch by elastic.
the class SettingsUpdaterTests method testClusterBlock.
public void testClusterBlock() {
ClusterState.Builder builder = ClusterState.builder(new ClusterName("foo"));
ClusterSettings settingsService = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
AtomicReference<Float> index = new AtomicReference<>();
AtomicReference<Float> shard = new AtomicReference<>();
settingsService.addSettingsUpdateConsumer(BalancedShardsAllocator.INDEX_BALANCE_FACTOR_SETTING, index::set);
settingsService.addSettingsUpdateConsumer(BalancedShardsAllocator.SHARD_BALANCE_FACTOR_SETTING, shard::set);
SettingsUpdater updater = new SettingsUpdater(settingsService);
MetaData.Builder metaData = MetaData.builder().persistentSettings(Settings.builder().put(BalancedShardsAllocator.INDEX_BALANCE_FACTOR_SETTING.getKey(), 1.5).put(BalancedShardsAllocator.SHARD_BALANCE_FACTOR_SETTING.getKey(), 2.5).build()).transientSettings(Settings.builder().put(BalancedShardsAllocator.INDEX_BALANCE_FACTOR_SETTING.getKey(), 3.5).put(BalancedShardsAllocator.SHARD_BALANCE_FACTOR_SETTING.getKey(), 4.5).build());
ClusterState build = builder.metaData(metaData).build();
ClusterState clusterState = updater.updateSettings(build, Settings.builder().put(MetaData.SETTING_READ_ONLY_SETTING.getKey(), true).build(), Settings.builder().put(BalancedShardsAllocator.INDEX_BALANCE_FACTOR_SETTING.getKey(), 1.6).put(BalancedShardsAllocator.SHARD_BALANCE_FACTOR_SETTING.getKey(), 1.0f).build());
assertEquals(clusterState.blocks().global().size(), 1);
assertEquals(clusterState.blocks().global().iterator().next(), MetaData.CLUSTER_READ_ONLY_BLOCK);
clusterState = updater.updateSettings(build, Settings.EMPTY, Settings.builder().put(MetaData.SETTING_READ_ONLY_SETTING.getKey(), false).build());
assertEquals(clusterState.blocks().global().size(), 0);
}
use of org.elasticsearch.cluster.ClusterName in project elasticsearch by elastic.
the class RestMainActionTests method testHeadResponse.
public void testHeadResponse() throws Exception {
final String nodeName = "node1";
final ClusterName clusterName = new ClusterName("cluster1");
final String clusterUUID = randomAsciiOfLengthBetween(10, 20);
final boolean available = randomBoolean();
final RestStatus expectedStatus = available ? RestStatus.OK : RestStatus.SERVICE_UNAVAILABLE;
final Version version = Version.CURRENT;
final Build build = Build.CURRENT;
final MainResponse mainResponse = new MainResponse(nodeName, version, clusterName, clusterUUID, build, available);
XContentBuilder builder = JsonXContent.contentBuilder();
RestRequest restRequest = new FakeRestRequest() {
@Override
public Method method() {
return Method.HEAD;
}
};
BytesRestResponse response = RestMainAction.convertMainResponse(mainResponse, restRequest, builder);
assertNotNull(response);
assertEquals(expectedStatus, response.status());
// the empty responses are handled in the HTTP layer so we do
// not assert on them here
}
use of org.elasticsearch.cluster.ClusterName in project elasticsearch by elastic.
the class RestMainActionTests method testGetResponse.
public void testGetResponse() throws Exception {
final String nodeName = "node1";
final ClusterName clusterName = new ClusterName("cluster1");
final String clusterUUID = randomAsciiOfLengthBetween(10, 20);
final boolean available = randomBoolean();
final RestStatus expectedStatus = available ? RestStatus.OK : RestStatus.SERVICE_UNAVAILABLE;
final Version version = Version.CURRENT;
final Build build = Build.CURRENT;
final boolean prettyPrint = randomBoolean();
final MainResponse mainResponse = new MainResponse(nodeName, version, clusterName, clusterUUID, build, available);
XContentBuilder builder = JsonXContent.contentBuilder();
Map<String, String> params = new HashMap<>();
if (prettyPrint == false) {
params.put("pretty", String.valueOf(prettyPrint));
}
RestRequest restRequest = new FakeRestRequest.Builder(xContentRegistry()).withParams(params).build();
BytesRestResponse response = RestMainAction.convertMainResponse(mainResponse, restRequest, builder);
assertNotNull(response);
assertEquals(expectedStatus, response.status());
assertThat(response.content().length(), greaterThan(0));
XContentBuilder responseBuilder = JsonXContent.contentBuilder();
if (prettyPrint) {
// do this to mimic what the rest layer does
responseBuilder.prettyPrint().lfAtEnd();
}
mainResponse.toXContent(responseBuilder, ToXContent.EMPTY_PARAMS);
BytesReference xcontentBytes = responseBuilder.bytes();
assertEquals(xcontentBytes, response.content());
}
use of org.elasticsearch.cluster.ClusterName in project elasticsearch by elastic.
the class ScriptServiceTests method testGetStoredScript.
public void testGetStoredScript() throws Exception {
buildScriptService(Settings.EMPTY);
ClusterState cs = ClusterState.builder(new ClusterName("_name")).metaData(MetaData.builder().putCustom(ScriptMetaData.TYPE, new ScriptMetaData.Builder(null).storeScript("_id", StoredScriptSource.parse("_lang", new BytesArray("{\"script\":\"abc\"}"), XContentType.JSON)).build())).build();
assertEquals("abc", scriptService.getStoredScript(cs, new GetStoredScriptRequest("_id", "_lang")).getCode());
assertNull(scriptService.getStoredScript(cs, new GetStoredScriptRequest("_id2", "_lang")));
cs = ClusterState.builder(new ClusterName("_name")).build();
assertNull(scriptService.getStoredScript(cs, new GetStoredScriptRequest("_id", "_lang")));
}
use of org.elasticsearch.cluster.ClusterName in project elasticsearch by elastic.
the class PrimaryShardAllocatorTests method assertClusterHealthStatus.
private void assertClusterHealthStatus(RoutingAllocation allocation, ClusterHealthStatus expectedStatus) {
RoutingTable oldRoutingTable = allocation.routingTable();
RoutingNodes newRoutingNodes = allocation.routingNodes();
final RoutingTable newRoutingTable = new RoutingTable.Builder().updateNodes(oldRoutingTable.version(), newRoutingNodes).build();
ClusterState clusterState = ClusterState.builder(new ClusterName("test-cluster")).routingTable(newRoutingTable).build();
ClusterStateHealth clusterStateHealth = new ClusterStateHealth(clusterState);
assertThat(clusterStateHealth.getStatus().ordinal(), lessThanOrEqualTo(expectedStatus.ordinal()));
}
Aggregations