public ClusterBlocks build() { // We copy the block sets here in case of the builder is modified after build is called ImmutableOpenMap.Builder<String, Set<ClusterBlock>> indicesBuilder = ImmutableOpenMap.builder(indices.size()); for (Map.Entry<String, Set<ClusterBlock>> entry : indices.entrySet()) { indicesBuilder.put(entry.getKey(), unmodifiableSet(new HashSet<>(entry.getValue()))); } return new ClusterBlocks(unmodifiableSet(new HashSet<>(global)), indicesBuilder.build()); } }
@Override public ImmutableOpenMap<K, T> apply(ImmutableOpenMap<K, T> map) { ImmutableOpenMap.Builder<K, T> builder = ImmutableOpenMap.builder(); builder.putAll(map); for (K part : deletes) { builder.remove(part); } for (Map.Entry<K, Diff<T>> diff : diffs.entrySet()) { builder.put(diff.getKey(), diff.getValue().apply(builder.get(diff.getKey()))); } for (Map.Entry<K, T> upsert : upserts.entrySet()) { builder.put(upsert.getKey(), upsert.getValue()); } return builder.build(); } }
/** * Builds the routing table. Note that once this is called the builder * must be thrown away. If you need to build a new RoutingTable as a * copy of this one you'll need to build a new RoutingTable.Builder. */ public RoutingTable build() { if (indicesRouting == null) { throw new IllegalStateException("once build is called the builder cannot be reused"); } RoutingTable table = new RoutingTable(version, indicesRouting.build()); indicesRouting = null; return table; } }
@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(new AliasMetaData(in)); } aliasesBuilder.put(key, Collections.unmodifiableList(value)); } aliases = aliasesBuilder.build(); }
/** * Fills alias result with empty entries for requested indices when no specific aliases were requested. */ static ImmutableOpenMap<String, List<AliasMetaData>> postProcess(GetAliasesRequest request, String[] concreteIndices, ImmutableOpenMap<String, List<AliasMetaData>> aliases) { boolean noAliasesSpecified = request.getOriginalAliases() == null || request.getOriginalAliases().length == 0; ImmutableOpenMap.Builder<String, List<AliasMetaData>> mapBuilder = ImmutableOpenMap.builder(aliases); for (String index : concreteIndices) { if (aliases.get(index) == null && noAliasesSpecified) { List<AliasMetaData> previous = mapBuilder.put(index, Collections.emptyList()); assert previous == null; } } return mapBuilder.build(); }
private static ImmutableOpenMap<String, MappingMetaData> parseMappings(XContentParser parser) throws IOException { ImmutableOpenMap.Builder<String, MappingMetaData> indexMappings = ImmutableOpenMap.builder(); // We start at START_OBJECT since parseIndexEntry ensures that while (parser.nextToken() != Token.END_OBJECT) { ensureExpectedToken(Token.FIELD_NAME, parser.currentToken(), parser::getTokenLocation); parser.nextToken(); if (parser.currentToken() == Token.START_OBJECT) { String mappingType = parser.currentName(); indexMappings.put(mappingType, new MappingMetaData(mappingType, parser.map())); } else if (parser.currentToken() == Token.START_ARRAY) { parser.skipChildren(); } } return indexMappings.build(); }
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); 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(); }
public MultiFields merge(MultiFields mergeWith) { ImmutableOpenMap.Builder<String, FieldMapper> newMappersBuilder = ImmutableOpenMap.builder(mappers); for (ObjectCursor<FieldMapper> cursor : mergeWith.mappers.values()) { FieldMapper mergeWithMapper = cursor.value; FieldMapper mergeIntoMapper = mappers.get(mergeWithMapper.simpleName()); if (mergeIntoMapper == null) { newMappersBuilder.put(mergeWithMapper.simpleName(), mergeWithMapper); } else { FieldMapper merged = mergeIntoMapper.merge(mergeWithMapper, false); newMappersBuilder.put(merged.simpleName(), merged); // override previous definition } } ImmutableOpenMap<String, FieldMapper> mappers = newMappersBuilder.build(); return new MultiFields(mappers); }
public void addFileSizes(ImmutableOpenMap<String, Long> fileSizes) { ImmutableOpenMap.Builder<String, Long> map = ImmutableOpenMap.builder(this.fileSizes); for (Iterator<ObjectObjectCursor<String, Long>> it = fileSizes.iterator(); it.hasNext();) { ObjectObjectCursor<String, Long> entry = it.next(); if (map.containsKey(entry.key)) { Long oldValue = map.get(entry.key); map.put(entry.key, oldValue + entry.value); } else { map.put(entry.key, entry.value); } } this.fileSizes = map.build(); }
public RestoreInProgress build() { return new RestoreInProgress(entries.build()); } }
public ClusterState build() { if (UNKNOWN_UUID.equals(uuid)) { uuid = UUIDs.randomBase64UUID(); } return new ClusterState(clusterName, version, uuid, metaData, routingTable, nodes, blocks, customs.build(), fromDiff); }
@Override public void onResponse(IndicesStatsResponse indicesStatsResponse) { ShardStats[] stats = indicesStatsResponse.getShards(); ImmutableOpenMap.Builder<String, Long> newShardSizes = ImmutableOpenMap.builder(); ImmutableOpenMap.Builder<ShardRouting, String> newShardRoutingToDataPath = ImmutableOpenMap.builder(); buildShardLevelInfo(logger, stats, newShardSizes, newShardRoutingToDataPath, clusterService.state()); shardSizes = newShardSizes.build(); shardRoutingToDataPath = newShardRoutingToDataPath.build(); }
private MultiFields(ImmutableOpenMap<String, FieldMapper> mappers) { ImmutableOpenMap.Builder<String, FieldMapper> builder = new ImmutableOpenMap.Builder<>(); // we disable the all in multi-field mappers for (ObjectObjectCursor<String, FieldMapper> cursor : mappers) { builder.put(cursor.key, cursor.value); } this.mappers = builder.build(); }
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 }
@Override public void onResponse(NodesStatsResponse nodeStatses) { ImmutableOpenMap.Builder<String, DiskUsage> newLeastAvaiableUsages = ImmutableOpenMap.builder(); ImmutableOpenMap.Builder<String, DiskUsage> newMostAvaiableUsages = ImmutableOpenMap.builder(); fillDiskUsagePerNode(logger, nodeStatses.getNodes(), newLeastAvaiableUsages, newMostAvaiableUsages); leastAvailableSpaceUsages = newLeastAvaiableUsages.build(); mostAvailableSpaceUsages = newMostAvaiableUsages.build(); }
/** * @return An immutable copy of the given map */ public static <KType, VType> ImmutableOpenMap<KType, VType> copyOf(ObjectObjectMap<KType, VType> map) { Builder<KType, VType> builder = builder(); builder.putAll(map); return builder.build(); }
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); }
/** * 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()); nodes.removeAll(ingestNodes.keys()); return nodes.build(); }
/** * Get a {@link Map} of the discovered master and data nodes arranged by their ids * * @return {@link Map} of the discovered master and data nodes arranged by their ids */ public ImmutableOpenMap<String, DiscoveryNode> getMasterAndDataNodes() { ImmutableOpenMap.Builder<String, DiscoveryNode> nodes = ImmutableOpenMap.builder(dataNodes); nodes.putAll(masterNodes); return nodes.build(); }