org.elasticsearch.common.util.CollectionUtils Java Examples
The following examples show how to use
org.elasticsearch.common.util.CollectionUtils.
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: ClassificationAssociatorTest.java From atlas with Apache License 2.0 | 6 votes |
@Test public void updaterEntityWithUniqueName() throws IOException, AtlasBaseException { AtlasEntityDef ed = getAtlasEntityDefFromFile("col-entity-def-unique-name"); AtlasEntityHeaders entityHeaderMap = getEntityHeaderMapFromFile("header-PII-no-qualifiedName"); AtlasEntityStore entitiesStore = mock(AtlasEntityStore.class); AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTypeRegistry.AtlasTransientTypeRegistry ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(CollectionUtils.newSingletonArrayList(ed)); AtlasGraph atlasGraph = mock(AtlasGraph.class); ClassificationAssociatorUpdaterForSpy updater = new ClassificationAssociatorUpdaterForSpy(atlasGraph, ttr, entitiesStore, "col-entity-PII"); String summary = updater.setClassifications(entityHeaderMap.getGuidHeaderMap()); TypeReference<String[]> typeReference = new TypeReference<String[]>() {}; String[] summaryArray = AtlasJson.fromJson(summary, typeReference); assertEquals(summaryArray.length, 1); assertSummaryElement(summaryArray[0], "Update", STATUS_DONE, "PII"); }
Example #2
Source File: UnicastZenPing.java From Elasticsearch with Apache License 2.0 | 6 votes |
private UnicastPingResponse handlePingRequest(final UnicastPingRequest request) { if (!lifecycle.started()) { throw new IllegalStateException("received ping request while not started"); } temporalResponses.add(request.pingResponse); threadPool.schedule(TimeValue.timeValueMillis(request.timeout.millis() * 2), ThreadPool.Names.SAME, new Runnable() { @Override public void run() { temporalResponses.remove(request.pingResponse); } }); List<PingResponse> pingResponses = CollectionUtils.iterableAsArrayList(temporalResponses); pingResponses.add(createPingResponse(contextProvider.nodes())); UnicastPingResponse unicastPingResponse = new UnicastPingResponse(); unicastPingResponse.id = request.id; unicastPingResponse.pingResponses = pingResponses.toArray(new PingResponse[pingResponses.size()]); return unicastPingResponse; }
Example #3
Source File: BinaryFieldMapper.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public BytesRef binaryValue() { try { CollectionUtils.sortAndDedup(bytesList); int size = bytesList.size(); final byte[] bytes = new byte[totalSize + (size + 1) * 5]; ByteArrayDataOutput out = new ByteArrayDataOutput(bytes); out.writeVInt(size); // write total number of values for (int i = 0; i < size; i ++) { final byte[] value = bytesList.get(i); int valueLength = value.length; out.writeVInt(valueLength); out.writeBytes(value, 0, valueLength); } return new BytesRef(bytes, 0, out.getPosition()); } catch (IOException e) { throw new ElasticsearchException("Failed to get binary value", e); } }
Example #4
Source File: NumberFieldMapper.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public BytesRef binaryValue() { CollectionUtils.sortAndDedup(values); // here is the trick: // - the first value is zig-zag encoded so that eg. -5 would become positive and would be better compressed by vLong // - for other values, we only encode deltas using vLong final byte[] bytes = new byte[values.size() * ByteUtils.MAX_BYTES_VLONG]; final ByteArrayDataOutput out = new ByteArrayDataOutput(bytes); ByteUtils.writeVLong(out, ByteUtils.zigZagEncode(values.get(0))); for (int i = 1; i < values.size(); ++i) { final long delta = values.get(i) - values.get(i - 1); ByteUtils.writeVLong(out, delta); } return new BytesRef(bytes, 0, out.getPosition()); }
Example #5
Source File: FilterPath.java From Elasticsearch with Apache License 2.0 | 6 votes |
public static FilterPath[] compile(String... filters) { if (CollectionUtils.isEmpty(filters)) { return null; } List<FilterPath> paths = new ArrayList<>(); for (String filter : filters) { if (filter != null) { filter = filter.trim(); if (filter.length() > 0) { paths.add(parse(filter, filter)); } } } return paths.toArray(new FilterPath[paths.size()]); }
Example #6
Source File: MinHashFieldMapper.java From elasticsearch-minhash with Apache License 2.0 | 6 votes |
@Override public BytesRef binaryValue() { try { CollectionUtils.sortAndDedup(bytesList); final int size = bytesList.size(); final byte[] bytes = new byte[totalSize + (size + 1) * 5]; final ByteArrayDataOutput out = new ByteArrayDataOutput(bytes); out.writeVInt(size); // write total number of values for (int i = 0; i < size; i++) { final byte[] value = bytesList.get(i); final int valueLength = value.length; out.writeVInt(valueLength); out.writeBytes(value, 0, valueLength); } return new BytesRef(bytes, 0, out.getPosition()); } catch (final IOException e) { throw new ElasticsearchException("Failed to get MinHash value", e); } }
Example #7
Source File: JsonXContentGenerator.java From Elasticsearch with Apache License 2.0 | 6 votes |
public JsonXContentGenerator(JsonGenerator jsonGenerator, OutputStream os, String... filters) { if (jsonGenerator instanceof GeneratorBase) { this.base = (GeneratorBase) jsonGenerator; } else { this.base = null; } if (CollectionUtils.isEmpty(filters)) { this.generator = jsonGenerator; this.filter = null; } else { this.filter = new FilteringGeneratorDelegate(jsonGenerator, new FilterPathBasedFilter(filters), true, true); this.generator = this.filter; } this.os = os; }
Example #8
Source File: DeleteWarmerRequest.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = null; if (CollectionUtils.isEmpty(names)) { validationException = addValidationError("warmer names are missing", validationException); } else { validationException = checkForEmptyString(validationException, names); } if (CollectionUtils.isEmpty(indices)) { validationException = addValidationError("indices are missing", validationException); } else { validationException = checkForEmptyString(validationException, indices); } return validationException; }
Example #9
Source File: DeleteIndexRequest.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = null; if (CollectionUtils.isEmpty(indices)) { validationException = addValidationError("index / indices is missing", validationException); } return validationException; }
Example #10
Source File: CloseIndexRequest.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = null; if (CollectionUtils.isEmpty(indices)) { validationException = addValidationError("index is missing", validationException); } return validationException; }
Example #11
Source File: IndicesAliasesRequest.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = null; if (allAliasActions.isEmpty()) { return addValidationError("Must specify at least one alias action", validationException); } for (AliasActions aliasAction : allAliasActions) { if (CollectionUtils.isEmpty(aliasAction.aliases)) { validationException = addValidationError("Alias action [" + aliasAction.actionType().name().toLowerCase(Locale.ENGLISH) + "]: Property [alias/aliases] is either missing or null", validationException); } else { for (String alias : aliasAction.aliases) { if (!Strings.hasText(alias)) { validationException = addValidationError("Alias action [" + aliasAction.actionType().name().toLowerCase(Locale.ENGLISH) + "]: [alias/aliases] may not be empty string", validationException); } } } if (CollectionUtils.isEmpty(aliasAction.indices)) { validationException = addValidationError("Alias action [" + aliasAction.actionType().name().toLowerCase(Locale.ENGLISH) + "]: Property [index/indices] is either missing or null", validationException); } else { for (String index : aliasAction.indices) { if (!Strings.hasText(index)) { validationException = addValidationError("Alias action [" + aliasAction.actionType().name().toLowerCase(Locale.ENGLISH) + "]: [index/indices] may not be empty string", validationException); } } } } return validationException; }
Example #12
Source File: OpenIndexRequest.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = null; if (CollectionUtils.isEmpty(indices)) { validationException = addValidationError("index is missing", validationException); } return validationException; }
Example #13
Source File: TransportGetSettingsAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override protected void masterOperation(GetSettingsRequest request, ClusterState state, ActionListener<GetSettingsResponse> listener) { String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); ImmutableOpenMap.Builder<String, Settings> indexToSettingsBuilder = ImmutableOpenMap.builder(); for (String concreteIndex : concreteIndices) { IndexMetaData indexMetaData = state.getMetaData().index(concreteIndex); if (indexMetaData == null) { continue; } Settings settings = SettingsFilter.filterSettings(settingsFilter.getPatterns(), indexMetaData.getSettings()); if (request.humanReadable()) { settings = IndexMetaData.addHumanReadableSettings(settings); } if (!CollectionUtils.isEmpty(request.names())) { Settings.Builder settingsBuilder = Settings.builder(); for (Map.Entry<String, String> entry : settings.getAsMap().entrySet()) { if (Regex.simpleMatch(request.names(), entry.getKey())) { settingsBuilder.put(entry.getKey(), entry.getValue()); } } settings = settingsBuilder.build(); } indexToSettingsBuilder.put(concreteIndex, settings); } listener.onResponse(new GetSettingsResponse(indexToSettingsBuilder.build())); }
Example #14
Source File: DoubleFieldMapper.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public BytesRef binaryValue() { CollectionUtils.sortAndDedup(values); final byte[] bytes = new byte[values.size() * 8]; for (int i = 0; i < values.size(); ++i) { ByteUtils.writeDoubleLE(values.get(i), bytes, i * 8); } return new BytesRef(bytes); }
Example #15
Source File: FloatFieldMapper.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public BytesRef binaryValue() { CollectionUtils.sortAndDedup(values); final byte[] bytes = new byte[values.size() * 4]; for (int i = 0; i < values.size(); ++i) { ByteUtils.writeFloatLE(values.get(i), bytes, i * 4); } return new BytesRef(bytes); }
Example #16
Source File: ElectMasterService.java From Elasticsearch with Apache License 2.0 | 5 votes |
private List<DiscoveryNode> sortedMasterNodes(Iterable<DiscoveryNode> nodes) { List<DiscoveryNode> possibleNodes = CollectionUtils.iterableAsArrayList(nodes); if (possibleNodes.isEmpty()) { return null; } // clean non master nodes for (Iterator<DiscoveryNode> it = possibleNodes.iterator(); it.hasNext(); ) { DiscoveryNode node = it.next(); if (!node.masterNode()) { it.remove(); } } CollectionUtil.introSort(possibleNodes, nodeComparator); return possibleNodes; }
Example #17
Source File: AzureSeedHostsProviderTest.java From crate with Apache License 2.0 | 5 votes |
@Before public void setUp() throws IOException, ServiceException { logger = LogManager.getLogger(this.getClass()); ResourceId resourceId = new ResourceId(); resourceId.setId("/subscriptions/xx/resourceGroups/my_resourcegroup/providers/Microsoft.Network/networkInterfaces/nic_dummy/ipConfigurations/Nic-IP-config"); Subnet subnet = new Subnet(); subnet.setIpConfigurations(CollectionUtils.asArrayList(resourceId)); subnet.setName("mySubnet"); VirtualNetworkOperations virtualNetworkOperations = mock(VirtualNetworkOperationsImpl.class); VirtualNetworkGetResponse virtualNetworkGetResponse = mock(VirtualNetworkGetResponse.class); final NetworkInterfaceOperations networkInterfaceOperations = mock(NetworkInterfaceOperationsImpl.class); NetworkInterfaceGetResponse networkInterfaceGetResponse = mock(NetworkInterfaceGetResponse.class); NetworkInterfaceIpConfiguration ipConfiguration = new NetworkInterfaceIpConfiguration(); ipConfiguration.setPrivateIpAddress("10.0.0.4"); NetworkInterface nic = new NetworkInterface(); nic.setName("nic_dummy"); nic.setIpConfigurations(CollectionUtils.asArrayList(ipConfiguration)); VirtualNetwork virtualNetwork = new VirtualNetwork(); virtualNetwork.setSubnets(CollectionUtils.asArrayList(subnet)); when(virtualNetworkGetResponse.getVirtualNetwork()).thenReturn(virtualNetwork); when(providerClient.getVirtualNetworksOperations()).thenReturn(virtualNetworkOperations); when(virtualNetworkOperations.get(rgName, vnetName)).thenReturn(virtualNetworkGetResponse); when(providerClient.getNetworkInterfacesOperations()).thenReturn(networkInterfaceOperations); when(networkInterfaceOperations.get(rgName, "nic_dummy")).thenReturn(networkInterfaceGetResponse); when(networkInterfaceGetResponse.getNetworkInterface()).thenReturn(nic); }
Example #18
Source File: RotationShardShuffler.java From crate with Apache License 2.0 | 4 votes |
@Override public List<ShardRouting> shuffle(List<ShardRouting> shards, int seed) { return CollectionUtils.rotate(shards, seed); }
Example #19
Source File: Strings.java From crate with Apache License 2.0 | 4 votes |
/** * If an array only consists of zero or one element, which is "*" or "_all" return an empty array * which is usually used as everything */ public static boolean isAllOrWildcard(String[] data) { return CollectionUtils.isEmpty(data) || data.length == 1 && ("_all".equals(data[0]) || "*".equals(data[0])); }
Example #20
Source File: AzureSeedHostsProviderTest.java From crate with Apache License 2.0 | 4 votes |
@Test public void testMultipleSubnet() throws IOException, ServiceException { ResourceId resourceId2 = new ResourceId(); resourceId2.setId("/subscriptions/xx/resourceGroups/my_resourcegroup/providers/Microsoft.Network/networkInterfaces/nic_dummy2/ipConfigurations/Nic-IP-config"); ResourceId resourceId3 = new ResourceId(); resourceId3.setId("/subscriptions/xx/resourceGroups/my_resourcegroup/providers/Microsoft.Network/publicIPAddresses/ip_public1"); Subnet subnet2 = new Subnet(); subnet2.setIpConfigurations(CollectionUtils.asArrayList(resourceId2)); subnet2.setName("mySubnet2"); NetworkInterfaceGetResponse networkInterfaceGetResponse2 = mock(NetworkInterfaceGetResponse.class); PublicIpAddressOperations publicIpAddressOperations = mock(PublicIpAddressOperationsImpl.class); PublicIpAddressGetResponse publicIpAddressGetResponse = mock(PublicIpAddressGetResponse.class); NetworkInterfaceIpConfiguration ipConfiguration2 = new NetworkInterfaceIpConfiguration(); ipConfiguration2.setPrivateIpAddress("10.0.0.5"); ipConfiguration2.setPublicIpAddress(resourceId3); PublicIpAddress publicIpAddress = new PublicIpAddress(); publicIpAddress.setIpAddress("33.33.33.33"); NetworkInterface nic2 = new NetworkInterface(); nic2.setName("nic_dummy2"); nic2.setIpConfigurations(CollectionUtils.asArrayList(ipConfiguration2)); providerClient.getVirtualNetworksOperations().get(rgName, vnetName).getVirtualNetwork().getSubnets().add(subnet2); when(providerClient.getNetworkInterfacesOperations().get(rgName, "nic_dummy2")).thenReturn(networkInterfaceGetResponse2); when(networkInterfaceGetResponse2.getNetworkInterface()).thenReturn(nic2); when(providerClient.getPublicIpAddressesOperations()).thenReturn(publicIpAddressOperations); when(publicIpAddressOperations.get(rgName, "ip_public1")).thenReturn(publicIpAddressGetResponse); when(publicIpAddressGetResponse.getPublicIpAddress()).thenReturn(publicIpAddress); List<String> networkAddresses = AzureSeedHostsProvider.listIPAddresses(providerClient, rgName, vnetName, subnetName, "subnet", AzureSeedHostsProvider.HostType.PRIVATE_IP, logger); assertEquals(networkAddresses.size(), 1); assertEquals(networkAddresses.get(0), "10.0.0.5"); List<String> networkAddresses2 = AzureSeedHostsProvider.listIPAddresses(providerClient, rgName, vnetName, subnetName, "vnet", AzureSeedHostsProvider.HostType.PRIVATE_IP, logger); assertEquals(networkAddresses2.size(), 2); assertEquals(networkAddresses2.contains("10.0.0.5"), true); assertEquals(networkAddresses2.contains("10.0.0.4"), true); List<String> networkAddresses3 = AzureSeedHostsProvider.listIPAddresses(providerClient, rgName, vnetName, subnetName, "vnet", AzureSeedHostsProvider.HostType.PUBLIC_IP, logger); assertEquals(networkAddresses3.size(), 1); assertEquals(networkAddresses3.contains("33.33.33.33"), true); assertEquals(networkAddresses3.contains("10.0.0.5"), false); assertEquals(networkAddresses3.contains("10.0.0.4"), false); }
Example #21
Source File: Strings.java From Elasticsearch with Apache License 2.0 | 4 votes |
/** * If an array only consists of zero or one element, which is "*" or "_all" return an empty array * which is usually used as everything */ public static boolean isAllOrWildcard(String[] data) { return CollectionUtils.isEmpty(data) || data.length == 1 && ("_all".equals(data[0]) || "*".equals(data[0])); }
Example #22
Source File: FilterPathBasedFilter.java From Elasticsearch with Apache License 2.0 | 4 votes |
public FilterPathBasedFilter(FilterPath[] filters) { if (CollectionUtils.isEmpty(filters)) { throw new IllegalArgumentException("filters cannot be null or empty"); } this.filters = filters; }
Example #23
Source File: RotationShardShuffler.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public List<ShardRouting> shuffle(List<ShardRouting> shards, int seed) { return CollectionUtils.rotate(shards, seed); }
Example #24
Source File: ElectMasterService.java From Elasticsearch with Apache License 2.0 | 4 votes |
/** * Returns the given nodes sorted by likelyhood of being elected as master, most likely first. * Non-master nodes are not removed but are rather put in the end */ public List<DiscoveryNode> sortByMasterLikelihood(Iterable<DiscoveryNode> nodes) { ArrayList<DiscoveryNode> sortedNodes = CollectionUtils.iterableAsArrayList(nodes); CollectionUtil.introSort(sortedNodes, nodeComparator); return sortedNodes; }
Example #25
Source File: UnicastZenPing.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Inject public UnicastZenPing(Settings settings, ThreadPool threadPool, TransportService transportService, ClusterName clusterName, Version version, ElectMasterService electMasterService, @Nullable Set<UnicastHostsProvider> unicastHostsProviders) { super(settings); this.threadPool = threadPool; this.transportService = transportService; this.clusterName = clusterName; this.electMasterService = electMasterService; if (unicastHostsProviders != null) { for (UnicastHostsProvider unicastHostsProvider : unicastHostsProviders) { addHostsProvider(unicastHostsProvider); } } this.concurrentConnects = this.settings.getAsInt("discovery.zen.ping.unicast.concurrent_connects", 10); String[] hostArr = this.settings.getAsArray(DISCOVERY_ZEN_PING_UNICAST_HOSTS); // trim the hosts for (int i = 0; i < hostArr.length; i++) { hostArr[i] = hostArr[i].trim(); } List<String> hosts = CollectionUtils.arrayAsArrayList(hostArr); final int limitPortCounts; if (hosts.isEmpty()) { // if unicast hosts are not specified, fill with simple defaults on the local machine limitPortCounts = LIMIT_LOCAL_PORTS_COUNT; hosts.addAll(transportService.getLocalAddresses()); } else { // we only limit to 1 addresses, makes no sense to ping 100 ports limitPortCounts = LIMIT_FOREIGN_PORTS_COUNT; } logger.debug("using initial hosts {}, with concurrent_connects [{}]", hosts, concurrentConnects); List<DiscoveryNode> configuredTargetNodes = new ArrayList<>(); for (String host : hosts) { try { TransportAddress[] addresses = transportService.addressesFromString(host, limitPortCounts); for (TransportAddress address : addresses) { configuredTargetNodes.add(new DiscoveryNode(UNICAST_NODE_PREFIX + unicastNodeIdGenerator.incrementAndGet() + "#", address, version.minimumCompatibilityVersion())); } } catch (Exception e) { throw new IllegalArgumentException("Failed to resolve address for [" + host + "]", e); } } this.configuredTargetNodes = configuredTargetNodes.toArray(new DiscoveryNode[configuredTargetNodes.size()]); transportService.registerRequestHandler(ACTION_NAME, UnicastPingRequest.class, ThreadPool.Names.SAME, new UnicastPingRequestHandler()); ThreadFactory threadFactory = EsExecutors.daemonThreadFactory(settings, "[unicast_connect]"); unicastConnectExecutor = EsExecutors.newScaling("unicast_connect", 0, concurrentConnects, 60, TimeUnit.SECONDS, threadFactory); }
Example #26
Source File: Join.java From Elasticsearch with Apache License 2.0 | 2 votes |
/** * Appends each of the {@code tokens} to {@code appendable}, separated by * {@code delimiter}. * <p> * Each token will be converted to a {@link CharSequence} using * {@link String#valueOf(Object)}, if it isn't a {@link CharSequence} already. * Note that this implies that null tokens will be appended as the * four-character string {@code "null"}. * * @param appendable the object to append the results to * @param delimiter a string to append between every element, but not at the * beginning or end * @param firstToken the first object to append * @param otherTokens subsequent objects to append * @return the same {@code Appendable} instance that was passed in * @throws JoinException if an {@link IOException} occurs */ public static <T extends Appendable> T join(T appendable, String delimiter, @Nullable Object firstToken, Object... otherTokens) { checkNotNull(otherTokens); return join(appendable, delimiter, CollectionUtils.asArrayList(firstToken, otherTokens)); }
Example #27
Source File: Join.java From Elasticsearch with Apache License 2.0 | 2 votes |
/** * Returns a string containing the {@code tokens}, converted to strings if * necessary, separated by {@code delimiter}. * <p> * Each token will be converted to a {@link CharSequence} using * {@link String#valueOf(Object)}, if it isn't a {@link CharSequence} already. * Note that this implies that null tokens will be appended as the * four-character string {@code "null"}. * * @param delimiter a string to append between every element, but not at the * beginning or end * @param firstToken the first object to append * @param otherTokens subsequent objects to append * @return a string consisting of the joined elements */ public static String join( String delimiter, @Nullable Object firstToken, Object... otherTokens) { checkNotNull(otherTokens); return join(delimiter, CollectionUtils.asArrayList(firstToken, otherTokens)); }