Java Code Examples for org.elasticsearch.common.collect.ImmutableOpenMap#of()

The following examples show how to use org.elasticsearch.common.collect.ImmutableOpenMap#of() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InternalClusterInfoService.java    From crate with Apache License 2.0 6 votes vote down vote up
public InternalClusterInfoService(Settings settings, ClusterService clusterService, ThreadPool threadPool, NodeClient client) {
    this.leastAvailableSpaceUsages = ImmutableOpenMap.of();
    this.mostAvailableSpaceUsages = ImmutableOpenMap.of();
    this.shardRoutingToDataPath = ImmutableOpenMap.of();
    this.shardSizes = ImmutableOpenMap.of();
    this.clusterService = clusterService;
    this.threadPool = threadPool;
    this.client = client;
    this.updateFrequency = INTERNAL_CLUSTER_INFO_UPDATE_INTERVAL_SETTING.get(settings);
    this.fetchTimeout = INTERNAL_CLUSTER_INFO_TIMEOUT_SETTING.get(settings);
    this.enabled = DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_DISK_THRESHOLD_ENABLED_SETTING.get(settings);
    ClusterSettings clusterSettings = clusterService.getClusterSettings();
    //clusterSettings.addSettingsUpdateConsumer(INTERNAL_CLUSTER_INFO_TIMEOUT_SETTING, this::setFetchTimeout);
    //clusterSettings.addSettingsUpdateConsumer(INTERNAL_CLUSTER_INFO_UPDATE_INTERVAL_SETTING, this::setUpdateFrequency);
    clusterSettings.addSettingsUpdateConsumer(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_DISK_THRESHOLD_ENABLED_SETTING, this::setEnabled);

    // Add InternalClusterInfoService to listen for Master changes
    this.clusterService.addLocalNodeMasterListener(this);
    // Add to listen for state changes (when nodes are added)
    this.clusterService.addListener(this);
}
 
Example 2
Source File: RestoreInProgress.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Creates new restore metadata
 *
 * @param snapshot   snapshot
 * @param state      current state of the restore process
 * @param indices    list of indices being restored
 * @param shards     map of shards being restored to their current restore status
 */
public Entry(Snapshot snapshot, State state, List<String> indices, ImmutableOpenMap<ShardId, ShardRestoreStatus> shards) {
    this.snapshot = Objects.requireNonNull(snapshot);
    this.state = Objects.requireNonNull(state);
    this.indices = Objects.requireNonNull(indices);
    if (shards == null) {
        this.shards = ImmutableOpenMap.of();
    } else {
        this.shards = shards;
    }
}
 
Example 3
Source File: PercolateContext.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public ImmutableOpenMap<Object, Object> getContext() {
    return ImmutableOpenMap.of();
}
 
Example 4
Source File: ParentChildIndexFieldData.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
protected AtomicParentChildFieldData empty(int maxDoc) {
    return new ParentChildAtomicFieldData(ImmutableOpenMap.<String, AtomicOrdinalsFieldData>of());
}
 
Example 5
Source File: FieldMapper.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public static MultiFields empty() {
    return new MultiFields(ContentPath.Type.FULL, ImmutableOpenMap.<String, FieldMapper>of());
}
 
Example 6
Source File: ContextAndHeaderHolder.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public synchronized ImmutableOpenMap<Object, Object> getContext() {
    return context != null ? ImmutableOpenMap.copyOf(context) : ImmutableOpenMap.of();
}
 
Example 7
Source File: TransportGetIndexAction.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
protected void doMasterOperation(final GetIndexRequest request, String[] concreteIndices, final ClusterState state,
                                 final ActionListener<GetIndexResponse> listener) {
    ImmutableOpenMap<String, List<Entry>> warmersResult = ImmutableOpenMap.of();
    ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappingsResult = ImmutableOpenMap.of();
    ImmutableOpenMap<String, List<AliasMetaData>> aliasesResult = ImmutableOpenMap.of();
    ImmutableOpenMap<String, Settings> settings = ImmutableOpenMap.of();
    Feature[] features = request.features();
    boolean doneAliases = false;
    boolean doneMappings = false;
    boolean doneSettings = false;
    boolean doneWarmers = false;
    for (Feature feature : features) {
        switch (feature) {
        case WARMERS:
                if (!doneWarmers) {
                    warmersResult = state.metaData().findWarmers(concreteIndices, request.types(), Strings.EMPTY_ARRAY);
                    doneWarmers = true;
                }
                break;
        case MAPPINGS:
                if (!doneMappings) {
                    mappingsResult = state.metaData().findMappings(concreteIndices, request.types());
                    doneMappings = true;
                }
                break;
        case ALIASES:
                if (!doneAliases) {
                    aliasesResult = state.metaData().findAliases(Strings.EMPTY_ARRAY, concreteIndices);
                    doneAliases = true;
                }
                break;
        case SETTINGS:
                if (!doneSettings) {
                    ImmutableOpenMap.Builder<String, Settings> settingsMapBuilder = ImmutableOpenMap.builder();
                    for (String index : concreteIndices) {
                        Settings indexSettings = state.metaData().index(index).getSettings();
                        if (request.humanReadable()) {
                            indexSettings = IndexMetaData.addHumanReadableSettings(indexSettings);
                        }
                        settingsMapBuilder.put(index, indexSettings);
                    }
                    settings = settingsMapBuilder.build();
                    doneSettings = true;
                }
                break;

            default:
                throw new IllegalStateException("feature [" + feature + "] is not valid");
        }
    }
    listener.onResponse(new GetIndexResponse(concreteIndices, warmersResult, mappingsResult, aliasesResult, settings));
}
 
Example 8
Source File: IndicesShardStoresResponse.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
IndicesShardStoresResponse() {
    this(ImmutableOpenMap.<String, ImmutableOpenIntMap<List<StoreStatus>>>of(), Collections.<Failure>emptyList());
}
 
Example 9
Source File: FieldMapper.java    From crate with Apache License 2.0 4 votes vote down vote up
public static MultiFields empty() {
    return new MultiFields(ImmutableOpenMap.<String, FieldMapper>of());
}
 
Example 10
Source File: ClusterInfo.java    From crate with Apache License 2.0 4 votes vote down vote up
protected ClusterInfo() {
    this(ImmutableOpenMap.of(), ImmutableOpenMap.of(), ImmutableOpenMap.of(), ImmutableOpenMap.of());
}
 
Example 11
Source File: DiskThresholdDeciderUnitTests.java    From crate with Apache License 2.0 4 votes vote down vote up
@Test
public void testCanAllocateUsesMaxAvailableSpace() {
    ClusterSettings nss = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    DiskThresholdDecider decider = new DiskThresholdDecider(Settings.EMPTY, nss);

    MetaData metaData = MetaData.builder()
        .put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1))
        .build();

    final Index index = metaData.index("test").getIndex();

    ShardRouting test_0 = ShardRouting.newUnassigned(new ShardId(index, 0), true, EmptyStoreRecoverySource.INSTANCE,
                                                     new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
    DiscoveryNode node_0 = new DiscoveryNode("node_0", buildNewFakeTransportAddress(), Collections.emptyMap(),
                                             new HashSet<>(Arrays.asList(DiscoveryNode.Role.values())), Version.CURRENT);
    DiscoveryNode node_1 = new DiscoveryNode("node_1", buildNewFakeTransportAddress(), Collections.emptyMap(),
                                             new HashSet<>(Arrays.asList(DiscoveryNode.Role.values())), Version.CURRENT);

    RoutingTable routingTable = RoutingTable.builder()
        .addAsNew(metaData.index("test"))
        .build();

    ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY))
        .metaData(metaData).routingTable(routingTable).build();

    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder()
                                                                .add(node_0)
                                                                .add(node_1)
    ).build();

    // actual test -- after all that bloat :)
    ImmutableOpenMap.Builder<String, DiskUsage> leastAvailableUsages = ImmutableOpenMap.builder();
    leastAvailableUsages.put("node_0", new DiskUsage("node_0", "node_0", "_na_", 100, 0)); // all full
    leastAvailableUsages.put("node_1", new DiskUsage("node_1", "node_1", "_na_", 100, 0)); // all full

    ImmutableOpenMap.Builder<String, DiskUsage> mostAvailableUsage = ImmutableOpenMap.builder();
    // 20 - 99 percent since after allocation there must be at least 10% left and shard is 10byte
    mostAvailableUsage.put("node_0", new DiskUsage("node_0", "node_0", "_na_", 100, randomIntBetween(20, 100)));
    // this is weird and smells like a bug! it should be up to 20%?
    mostAvailableUsage.put("node_1", new DiskUsage("node_1", "node_1", "_na_", 100, randomIntBetween(0, 10)));

    ImmutableOpenMap.Builder<String, Long> shardSizes = ImmutableOpenMap.builder();
    shardSizes.put("[test][0][p]", 10L); // 10 bytes
    final ClusterInfo clusterInfo = new ClusterInfo(leastAvailableUsages.build(),
                                                    mostAvailableUsage.build(), shardSizes.build(), ImmutableOpenMap.of());
    RoutingAllocation allocation = new RoutingAllocation(new AllocationDeciders(Collections.singleton(decider)),
                                                         clusterState.getRoutingNodes(), clusterState, clusterInfo, System.nanoTime());
    allocation.debugDecision(true);
    Decision decision = decider.canAllocate(test_0, new RoutingNode("node_0", node_0), allocation);
    assertEquals(mostAvailableUsage.toString(), Decision.Type.YES, decision.type());
    assertThat(decision.getExplanation(), containsString("enough disk for shard on node"));
    decision = decider.canAllocate(test_0, new RoutingNode("node_1", node_1), allocation);
    assertEquals(mostAvailableUsage.toString(), Decision.Type.NO, decision.type());
    assertThat(decision.getExplanation(), containsString("the node is above the high watermark cluster " +
                                                         "setting [cluster.routing.allocation.disk.watermark.high=90%], using more disk space than the maximum allowed [90.0%]"));
}
 
Example 12
Source File: DiskThresholdDeciderUnitTests.java    From crate with Apache License 2.0 4 votes vote down vote up
@Test
public void testCannotAllocateDueToLackOfDiskResources() {
    ClusterSettings nss = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    DiskThresholdDecider decider = new DiskThresholdDecider(Settings.EMPTY, nss);

    MetaData metaData = MetaData.builder()
        .put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1))
        .build();

    final Index index = metaData.index("test").getIndex();

    ShardRouting test_0 = ShardRouting.newUnassigned(new ShardId(index, 0), true, EmptyStoreRecoverySource.INSTANCE,
                                                     new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
    DiscoveryNode node_0 = new DiscoveryNode("node_0", buildNewFakeTransportAddress(), Collections.emptyMap(),
                                             new HashSet<>(Arrays.asList(DiscoveryNode.Role.values())), Version.CURRENT);
    DiscoveryNode node_1 = new DiscoveryNode("node_1", buildNewFakeTransportAddress(), Collections.emptyMap(),
                                             new HashSet<>(Arrays.asList(DiscoveryNode.Role.values())), Version.CURRENT);

    RoutingTable routingTable = RoutingTable.builder()
        .addAsNew(metaData.index("test"))
        .build();

    ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY))
        .metaData(metaData).routingTable(routingTable).build();

    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder()
                                                                .add(node_0)
                                                                .add(node_1)
    ).build();

    // actual test -- after all that bloat :)

    ImmutableOpenMap.Builder<String, DiskUsage> leastAvailableUsages = ImmutableOpenMap.builder();
    leastAvailableUsages.put("node_0", new DiskUsage("node_0", "node_0", "_na_", 100, 0)); // all full
    ImmutableOpenMap.Builder<String, DiskUsage> mostAvailableUsage = ImmutableOpenMap.builder();
    final int freeBytes = randomIntBetween(20, 100);
    mostAvailableUsage.put("node_0", new DiskUsage("node_0", "node_0", "_na_", 100, freeBytes));

    ImmutableOpenMap.Builder<String, Long> shardSizes = ImmutableOpenMap.builder();
    // way bigger than available space
    final long shardSize = randomIntBetween(110, 1000);
    shardSizes.put("[test][0][p]", shardSize);
    ClusterInfo clusterInfo = new ClusterInfo(leastAvailableUsages.build(), mostAvailableUsage.build(),
                                              shardSizes.build(), ImmutableOpenMap.of());
    RoutingAllocation allocation = new RoutingAllocation(new AllocationDeciders(Collections.singleton(decider)),
                                                         clusterState.getRoutingNodes(), clusterState, clusterInfo, System.nanoTime());
    allocation.debugDecision(true);
    Decision decision = decider.canAllocate(test_0, new RoutingNode("node_0", node_0), allocation);
    assertEquals(Decision.Type.NO, decision.type());

    assertThat(decision.getExplanation(), containsString(
        "allocating the shard to this node will bring the node above the high watermark cluster setting "
        +"[cluster.routing.allocation.disk.watermark.high=90%] "
        + "and cause it to have less than the minimum required [0b] of free space "
        + "(free: [" + freeBytes + "b], estimated shard size: [" + shardSize + "b])"));
}