Search in sources :

Example 51 with ClusterName

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);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) MetaData(org.elasticsearch.cluster.metadata.MetaData) ClusterName(org.elasticsearch.cluster.ClusterName) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 52 with ClusterName

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
}
Also used : FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) RestRequest(org.elasticsearch.rest.RestRequest) RestStatus(org.elasticsearch.rest.RestStatus) Version(org.elasticsearch.Version) MainResponse(org.elasticsearch.action.main.MainResponse) Build(org.elasticsearch.Build) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) ClusterName(org.elasticsearch.cluster.ClusterName) FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 53 with ClusterName

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());
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) HashMap(java.util.HashMap) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) RestRequest(org.elasticsearch.rest.RestRequest) RestStatus(org.elasticsearch.rest.RestStatus) Version(org.elasticsearch.Version) MainResponse(org.elasticsearch.action.main.MainResponse) Build(org.elasticsearch.Build) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) ClusterName(org.elasticsearch.cluster.ClusterName) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 54 with ClusterName

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")));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) BytesArray(org.elasticsearch.common.bytes.BytesArray) ClusterName(org.elasticsearch.cluster.ClusterName) GetStoredScriptRequest(org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest)

Example 55 with ClusterName

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()));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterStateHealth(org.elasticsearch.cluster.health.ClusterStateHealth) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) RoutingNodes(org.elasticsearch.cluster.routing.RoutingNodes) ClusterName(org.elasticsearch.cluster.ClusterName)

Aggregations

ClusterName (org.elasticsearch.cluster.ClusterName)95 ClusterState (org.elasticsearch.cluster.ClusterState)76 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)22 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)20 Settings (org.elasticsearch.common.settings.Settings)20 Matchers.containsString (org.hamcrest.Matchers.containsString)17 Version (org.elasticsearch.Version)14 AtomicReference (java.util.concurrent.atomic.AtomicReference)12 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)12 MetaData (org.elasticsearch.cluster.metadata.MetaData)12 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)12 ArrayList (java.util.ArrayList)11 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)10 List (java.util.List)9 IndexShardRoutingTable (org.elasticsearch.cluster.routing.IndexShardRoutingTable)9 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 Collectors (java.util.stream.Collectors)8 BytesArray (org.elasticsearch.common.bytes.BytesArray)8 ESTestCase (org.elasticsearch.test.ESTestCase)8