Java Code Examples for org.elasticsearch.common.collect.ImmutableOpenMap#builder()
The following examples show how to use
org.elasticsearch.common.collect.ImmutableOpenMap#builder() .
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: GetWarmersResponse.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); int size = in.readVInt(); ImmutableOpenMap.Builder<String, List<IndexWarmersMetaData.Entry>> indexMapBuilder = ImmutableOpenMap.builder(); for (int i = 0; i < size; i++) { String key = in.readString(); int valueSize = in.readVInt(); List<IndexWarmersMetaData.Entry> warmerEntryBuilder = new ArrayList<>(); for (int j = 0; j < valueSize; j++) { String name = in.readString(); String[] types = in.readStringArray(); BytesReference source = in.readBytesReference(); Boolean queryCache = null; queryCache = in.readOptionalBoolean(); warmerEntryBuilder.add(new IndexWarmersMetaData.Entry( name, types, queryCache, source) ); } indexMapBuilder.put(key, Collections.unmodifiableList(warmerEntryBuilder)); } warmers = indexMapBuilder.build(); }
Example 2
Source File: MockInternalClusterInfoService.java From crate with Apache License 2.0 | 6 votes |
@Override protected CountDownLatch updateNodeStats(ActionListener<NodesStatsResponse> listener) { return super.updateNodeStats(new ActionListener<>() { @Override public void onResponse(NodesStatsResponse nodesStatsResponse) { ImmutableOpenMap.Builder<String, DiskUsage> leastAvailableUsagesBuilder = ImmutableOpenMap.builder(); ImmutableOpenMap.Builder<String, DiskUsage> mostAvailableUsagesBuilder = ImmutableOpenMap.builder(); fillDiskUsagePerNode( LOGGER, adjustNodesStats(nodesStatsResponse.getNodes()), leastAvailableUsagesBuilder, mostAvailableUsagesBuilder ); leastAvailableSpaceUsages = leastAvailableUsagesBuilder.build(); mostAvailableSpaceUsages = mostAvailableUsagesBuilder.build(); } @Override public void onFailure(Exception e) { } }); }
Example 3
Source File: GetMappingsResponse.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); int size = in.readVInt(); ImmutableOpenMap.Builder<String, ImmutableOpenMap<String, MappingMetaData>> indexMapBuilder = ImmutableOpenMap.builder(); for (int i = 0; i < size; i++) { String key = in.readString(); int valueSize = in.readVInt(); ImmutableOpenMap.Builder<String, MappingMetaData> typeMapBuilder = ImmutableOpenMap.builder(); for (int j = 0; j < valueSize; j++) { typeMapBuilder.put(in.readString(), MappingMetaData.PROTO.readFrom(in)); } indexMapBuilder.put(key, typeMapBuilder.build()); } mappings = indexMapBuilder.build(); }
Example 4
Source File: GetAliasesResponse.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); int size = in.readVInt(); ImmutableOpenMap.Builder<String, List<AliasMetaData>> aliasesBuilder = ImmutableOpenMap.builder(); for (int i = 0; i < size; i++) { String key = in.readString(); int valueSize = in.readVInt(); List<AliasMetaData> value = new ArrayList<>(valueSize); for (int j = 0; j < valueSize; j++) { value.add(AliasMetaData.Builder.readFrom(in)); } aliasesBuilder.put(key, Collections.unmodifiableList(value)); } aliases = aliasesBuilder.build(); }
Example 5
Source File: DiffableUtils.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public ImmutableOpenMap<String, T> apply(ImmutableOpenMap<String, T> map) { ImmutableOpenMap.Builder<String, T> builder = ImmutableOpenMap.builder(); builder.putAll(map); for (String part : deletes) { builder.remove(part); } for (Map.Entry<String, Diff<T>> diff : diffs.entrySet()) { builder.put(diff.getKey(), diff.getValue().apply(builder.get(diff.getKey()))); } for (Map.Entry<String, T> additon : adds.entrySet()) { builder.put(additon.getKey(), additon.getValue()); } return builder.build(); }
Example 6
Source File: MetaData.java From crate with Apache License 2.0 | 5 votes |
private static ImmutableOpenMap<String, MappingMetaData> filterFields(ImmutableOpenMap<String, MappingMetaData> mappings, Predicate<String> fieldPredicate) throws IOException { if (fieldPredicate == MapperPlugin.NOOP_FIELD_PREDICATE) { return mappings; } ImmutableOpenMap.Builder<String, MappingMetaData> builder = ImmutableOpenMap.builder(mappings.size()); for (ObjectObjectCursor<String, MappingMetaData> cursor : mappings) { builder.put(cursor.key, filterFields(cursor.value, fieldPredicate)); } return builder.build(); // No types specified means return them all }
Example 7
Source File: SnapshotsService.java From crate with Apache License 2.0 | 5 votes |
private static ImmutableOpenMap<ShardId, ShardSnapshotStatus> processWaitingShards( ImmutableOpenMap<ShardId, ShardSnapshotStatus> snapshotShards, RoutingTable routingTable) { boolean snapshotChanged = false; ImmutableOpenMap.Builder<ShardId, ShardSnapshotStatus> shards = ImmutableOpenMap.builder(); for (ObjectObjectCursor<ShardId, ShardSnapshotStatus> shardEntry : snapshotShards) { ShardSnapshotStatus shardStatus = shardEntry.value; ShardId shardId = shardEntry.key; if (shardStatus.state() == ShardState.WAITING) { IndexRoutingTable indexShardRoutingTable = routingTable.index(shardId.getIndex()); if (indexShardRoutingTable != null) { IndexShardRoutingTable shardRouting = indexShardRoutingTable.shard(shardId.id()); if (shardRouting != null && shardRouting.primaryShard() != null) { if (shardRouting.primaryShard().started()) { // Shard that we were waiting for has started on a node, let's process it snapshotChanged = true; LOGGER.trace("starting shard that we were waiting for [{}] on node [{}]", shardId, shardStatus.nodeId()); shards.put(shardId, new ShardSnapshotStatus(shardRouting.primaryShard().currentNodeId(), shardStatus.generation())); continue; } else if (shardRouting.primaryShard().initializing() || shardRouting.primaryShard().relocating()) { // Shard that we were waiting for hasn't started yet or still relocating - will continue to wait shards.put(shardId, shardStatus); continue; } } } // Shard that we were waiting for went into unassigned state or disappeared - giving up snapshotChanged = true; LOGGER.warn("failing snapshot of shard [{}] on unassigned shard [{}]", shardId, shardStatus.nodeId()); shards.put(shardId, new ShardSnapshotStatus(shardStatus.nodeId(), ShardState.FAILED, "shard is unassigned", shardStatus.generation())); } else { shards.put(shardId, shardStatus); } } if (snapshotChanged) { return shards.build(); } else { return null; } }
Example 8
Source File: ClusterInfo.java From crate with Apache License 2.0 | 5 votes |
public ClusterInfo(StreamInput in) throws IOException { Map<String, DiskUsage> leastMap = in.readMap(StreamInput::readString, DiskUsage::new); Map<String, DiskUsage> mostMap = in.readMap(StreamInput::readString, DiskUsage::new); Map<String, Long> sizeMap = in.readMap(StreamInput::readString, StreamInput::readLong); final Map<ShardRouting, String> routingMap = in.readMap(ShardRouting::new, StreamInput::readString); ImmutableOpenMap.Builder<String, DiskUsage> leastBuilder = ImmutableOpenMap.builder(); this.leastAvailableSpaceUsage = leastBuilder.putAll(leastMap).build(); ImmutableOpenMap.Builder<String, DiskUsage> mostBuilder = ImmutableOpenMap.builder(); this.mostAvailableSpaceUsage = mostBuilder.putAll(mostMap).build(); ImmutableOpenMap.Builder<String, Long> sizeBuilder = ImmutableOpenMap.builder(); this.shardSizes = sizeBuilder.putAll(sizeMap).build(); ImmutableOpenMap.Builder<ShardRouting, String> routingBuilder = ImmutableOpenMap.builder(); this.routingToDataPath = routingBuilder.putAll(routingMap).build(); }
Example 9
Source File: GetSettingsResponse.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); int size = in.readVInt(); ImmutableOpenMap.Builder<String, Settings> builder = ImmutableOpenMap.builder(); for (int i = 0; i < size; i++) { builder.put(in.readString(), Settings.readSettingsFromStream(in)); } indexToSettings = builder.build(); }
Example 10
Source File: IndexMetaData.java From crate with Apache License 2.0 | 5 votes |
public Builder(String index) { this.index = index; this.mappings = ImmutableOpenMap.builder(); this.aliases = ImmutableOpenMap.builder(); this.customMetaData = ImmutableOpenMap.builder(); this.inSyncAllocationIds = ImmutableOpenIntMap.builder(); }
Example 11
Source File: ModelManagerTests.java From anomaly-detection with Apache License 2.0 | 5 votes |
private ImmutableOpenMap<String, DiscoveryNode> createDataNodes(int numDataNodes) { ImmutableOpenMap.Builder<String, DiscoveryNode> dataNodes = ImmutableOpenMap.builder(); for (int i = 0; i < numDataNodes; i++) { dataNodes.put("foo" + i, mock(DiscoveryNode.class)); } return dataNodes.build(); }
Example 12
Source File: DiscoveryNodes.java From crate with Apache License 2.0 | 5 votes |
/** * Get a {@link Map} of the coordinating only nodes (nodes which are neither master, nor data, nor ingest nodes) arranged by their ids * * @return {@link Map} of the coordinating only nodes arranged by their ids */ public ImmutableOpenMap<String, DiscoveryNode> getCoordinatingOnlyNodes() { ImmutableOpenMap.Builder<String, DiscoveryNode> nodes = ImmutableOpenMap.builder(this.nodes); nodes.removeAll(masterNodes.keys()); nodes.removeAll(dataNodes.keys()); return nodes.build(); }
Example 13
Source File: IndexTemplateMetaData.java From Elasticsearch with Apache License 2.0 | 5 votes |
public Builder(IndexTemplateMetaData indexTemplateMetaData) { this.name = indexTemplateMetaData.name(); order(indexTemplateMetaData.order()); template(indexTemplateMetaData.template()); settings(indexTemplateMetaData.settings()); mappings = ImmutableOpenMap.builder(indexTemplateMetaData.mappings()); aliases = ImmutableOpenMap.builder(indexTemplateMetaData.aliases()); customs = ImmutableOpenMap.builder(indexTemplateMetaData.customs()); this.tenantId = indexTemplateMetaData.templateOwnerTenantId; }
Example 14
Source File: IndicesShardStoresResponse.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); int numResponse = in.readVInt(); ImmutableOpenMap.Builder<String, ImmutableOpenIntMap<List<StoreStatus>>> storeStatusesBuilder = ImmutableOpenMap.builder(); for (int i = 0; i < numResponse; i++) { String index = in.readString(); int indexEntries = in.readVInt(); ImmutableOpenIntMap.Builder<List<StoreStatus>> shardEntries = ImmutableOpenIntMap.builder(); for (int shardCount = 0; shardCount < indexEntries; shardCount++) { int shardID = in.readInt(); int nodeEntries = in.readVInt(); List<StoreStatus> storeStatuses = new ArrayList<>(nodeEntries); for (int nodeCount = 0; nodeCount < nodeEntries; nodeCount++) { storeStatuses.add(readStoreStatus(in)); } shardEntries.put(shardID, storeStatuses); } storeStatusesBuilder.put(index, shardEntries.build()); } int numFailure = in.readVInt(); List<Failure> failureBuilder = new ArrayList<>(); for (int i = 0; i < numFailure; i++) { failureBuilder.add(Failure.readFailure(in)); } storeStatuses = storeStatusesBuilder.build(); failures = Collections.unmodifiableList(failureBuilder); }
Example 15
Source File: ClusterBlocks.java From crate with Apache License 2.0 | 5 votes |
public ClusterBlocks(StreamInput in) throws IOException { Set<ClusterBlock> global = readBlockSet(in); int size = in.readVInt(); ImmutableOpenMap.Builder<String, Set<ClusterBlock>> indicesBuilder = ImmutableOpenMap.builder(size); for (int j = 0; j < size; j++) { indicesBuilder.put(in.readString().intern(), readBlockSet(in)); } this.global = global; this.indicesBlocks = indicesBuilder.build(); levelHolders = generateLevelHolders(global, indicesBlocks); }
Example 16
Source File: SnapshotsInProgressTests.java From crate with Apache License 2.0 | 5 votes |
/** * Makes sure that the indices being waited on before snapshotting commences * are populated with all shards in the relocating or initializing state. */ public void testWaitingIndices() { final Snapshot snapshot = new Snapshot("repo", new SnapshotId("snap", randomAlphaOfLength(5))); final String idx1Name = "idx1"; final String idx2Name = "idx2"; final String idx3Name = "idx3"; final String idx1UUID = randomAlphaOfLength(5); final String idx2UUID = randomAlphaOfLength(5); final String idx3UUID = randomAlphaOfLength(5); final List<IndexId> indices = Arrays.asList(new IndexId(idx1Name, randomAlphaOfLength(5)), new IndexId(idx2Name, randomAlphaOfLength(5)), new IndexId(idx3Name, randomAlphaOfLength(5))); ImmutableOpenMap.Builder<ShardId, ShardSnapshotStatus> shards = ImmutableOpenMap.builder(); // test more than one waiting shard in an index shards.put(new ShardId(idx1Name, idx1UUID, 0), new ShardSnapshotStatus(randomAlphaOfLength(2), ShardState.WAITING, "1")); shards.put(new ShardId(idx1Name, idx1UUID, 1), new ShardSnapshotStatus(randomAlphaOfLength(2), ShardState.WAITING, "1")); shards.put(new ShardId(idx1Name, idx1UUID, 2), new ShardSnapshotStatus(randomAlphaOfLength(2), randomNonWaitingState(), "", "1")); // test exactly one waiting shard in an index shards.put(new ShardId(idx2Name, idx2UUID, 0), new ShardSnapshotStatus(randomAlphaOfLength(2), ShardState.WAITING, "1")); shards.put(new ShardId(idx2Name, idx2UUID, 1), new ShardSnapshotStatus(randomAlphaOfLength(2), randomNonWaitingState(), "", "1")); // test no waiting shards in an index shards.put(new ShardId(idx3Name, idx3UUID, 0), new ShardSnapshotStatus(randomAlphaOfLength(2), randomNonWaitingState(), "", "1")); Entry entry = new Entry(snapshot, randomBoolean(), randomBoolean(), State.INIT, indices, System.currentTimeMillis(), randomLong(), shards.build(), randomBoolean()); ImmutableOpenMap<String, List<ShardId>> waitingIndices = entry.waitingIndices(); assertEquals(2, waitingIndices.get(idx1Name).size()); assertEquals(1, waitingIndices.get(idx2Name).size()); assertFalse(waitingIndices.containsKey(idx3Name)); }
Example 17
Source File: DiskThresholdDeciderTests.java From crate with Apache License 2.0 | 5 votes |
@Test public void testAverageUsage() { RoutingNode rn = new RoutingNode("node1", newNode("node1")); DiskThresholdDecider decider = makeDecider(Settings.EMPTY); ImmutableOpenMap.Builder<String, DiskUsage> usages = ImmutableOpenMap.builder(); usages.put("node2", new DiskUsage("node2", "n2", "/dev/null", 100, 50)); // 50% used usages.put("node3", new DiskUsage("node3", "n3", "/dev/null", 100, 0)); // 100% used DiskUsage node1Usage = decider.averageUsage(rn, usages.build()); assertThat(node1Usage.getTotalBytes(), equalTo(100L)); assertThat(node1Usage.getFreeBytes(), equalTo(25L)); }
Example 18
Source File: InternalClusterInfoService.java From crate with Apache License 2.0 | 4 votes |
@Override public void clusterChanged(ClusterChangedEvent event) { if (!this.enabled) { return; } // Check whether it was a data node that was added boolean dataNodeAdded = false; for (DiscoveryNode addedNode : event.nodesDelta().addedNodes()) { if (addedNode.isDataNode()) { dataNodeAdded = true; break; } } if (this.isMaster && dataNodeAdded && event.state().getNodes().getDataNodes().size() > 1) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("data node was added, retrieving new cluster info"); } threadPool.executor(executorName()).execute(this::maybeRefresh); } if (this.isMaster && event.nodesRemoved()) { for (DiscoveryNode removedNode : event.nodesDelta().removedNodes()) { if (removedNode.isDataNode()) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("Removing node from cluster info: {}", removedNode.getId()); } if (leastAvailableSpaceUsages.containsKey(removedNode.getId())) { ImmutableOpenMap.Builder<String, DiskUsage> newMaxUsages = ImmutableOpenMap.builder(leastAvailableSpaceUsages); newMaxUsages.remove(removedNode.getId()); leastAvailableSpaceUsages = newMaxUsages.build(); } if (mostAvailableSpaceUsages.containsKey(removedNode.getId())) { ImmutableOpenMap.Builder<String, DiskUsage> newMinUsages = ImmutableOpenMap.builder(mostAvailableSpaceUsages); newMinUsages.remove(removedNode.getId()); mostAvailableSpaceUsages = newMinUsages.build(); } } } } }
Example 19
Source File: IndexTemplateMetaData.java From crate with Apache License 2.0 | 4 votes |
public Builder(String name) { this.name = name; mappings = ImmutableOpenMap.builder(); aliases = ImmutableOpenMap.builder(); }
Example 20
Source File: DiscoveryNodes.java From crate with Apache License 2.0 | 4 votes |
public Builder(DiscoveryNodes nodes) { this.masterNodeId = nodes.getMasterNodeId(); this.localNodeId = nodes.getLocalNodeId(); this.nodes = ImmutableOpenMap.builder(nodes.getNodes()); }