Search in sources :

Example 6 with Collection

use of java.util.Collection in project elasticsearch by elastic.

the class GeoContextMapping method toInternalQueryContexts.

/**
     * Parse a list of {@link GeoQueryContext}
     * using <code>parser</code>. A QueryContexts accepts one of the following forms:
     *
     * <ul>
     *     <li>Object: GeoQueryContext</li>
     *     <li>String: GeoQueryContext value with boost=1  precision=PRECISION neighbours=[PRECISION]</li>
     *     <li>Array: <pre>[GeoQueryContext, ..]</pre></li>
     * </ul>
     *
     *  A GeoQueryContext has one of the following forms:
     *  <ul>
     *     <li>Object:
     *     <ul>
     *         <li><pre>GEO POINT</pre></li>
     *         <li><pre>{&quot;lat&quot;: <i>&lt;double&gt;</i>, &quot;lon&quot;: <i>&lt;double&gt;</i>, &quot;precision&quot;: <i>&lt;int&gt;</i>, &quot;neighbours&quot;: <i>&lt;[int, ..]&gt;</i>}</pre></li>
     *         <li><pre>{&quot;context&quot;: <i>&lt;string&gt;</i>, &quot;boost&quot;: <i>&lt;int&gt;</i>, &quot;precision&quot;: <i>&lt;int&gt;</i>, &quot;neighbours&quot;: <i>&lt;[int, ..]&gt;</i>}</pre></li>
     *         <li><pre>{&quot;context&quot;: <i>&lt;GEO POINT&gt;</i>, &quot;boost&quot;: <i>&lt;int&gt;</i>, &quot;precision&quot;: <i>&lt;int&gt;</i>, &quot;neighbours&quot;: <i>&lt;[int, ..]&gt;</i>}</pre></li>
     *     </ul>
     *     <li>String: <pre>GEO POINT</pre></li>
     *  </ul>
     * see {@link GeoUtils#parseGeoPoint(String, GeoPoint)} for GEO POINT
     */
@Override
public List<InternalQueryContext> toInternalQueryContexts(List<GeoQueryContext> queryContexts) {
    List<InternalQueryContext> internalQueryContextList = new ArrayList<>();
    for (GeoQueryContext queryContext : queryContexts) {
        int minPrecision = Math.min(this.precision, queryContext.getPrecision());
        GeoPoint point = queryContext.getGeoPoint();
        final Collection<String> locations = new HashSet<>();
        String geoHash = stringEncode(point.getLon(), point.getLat(), minPrecision);
        locations.add(geoHash);
        if (queryContext.getNeighbours().isEmpty() && geoHash.length() == this.precision) {
            addNeighbors(geoHash, locations);
        } else if (queryContext.getNeighbours().isEmpty() == false) {
            queryContext.getNeighbours().stream().filter(neighbourPrecision -> neighbourPrecision < geoHash.length()).forEach(neighbourPrecision -> {
                String truncatedGeoHash = geoHash.substring(0, neighbourPrecision);
                locations.add(truncatedGeoHash);
                addNeighbors(truncatedGeoHash, locations);
            });
        }
        internalQueryContextList.addAll(locations.stream().map(location -> new InternalQueryContext(location, queryContext.getBoost(), location.length() < this.precision)).collect(Collectors.toList()));
    }
    return internalQueryContextList;
}
Also used : GeoUtils(org.elasticsearch.common.geo.GeoUtils) StringField(org.apache.lucene.document.StringField) IndexableField(org.apache.lucene.index.IndexableField) Document(org.elasticsearch.index.mapper.ParseContext.Document) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) ParseContext(org.elasticsearch.index.mapper.ParseContext) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Map(java.util.Map) GeoPoint(org.elasticsearch.common.geo.GeoPoint) FieldMapper(org.elasticsearch.index.mapper.FieldMapper) GeoPointFieldMapper(org.elasticsearch.index.mapper.GeoPointFieldMapper) Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) GeoHashUtils.stringEncode(org.elasticsearch.common.geo.GeoHashUtils.stringEncode) Collectors(java.util.stream.Collectors) QueryParseContext(org.elasticsearch.index.query.QueryParseContext) XContentParser(org.elasticsearch.common.xcontent.XContentParser) Objects(java.util.Objects) List(java.util.List) DistanceUnit(org.elasticsearch.common.unit.DistanceUnit) DocValuesType(org.apache.lucene.index.DocValuesType) Token(org.elasticsearch.common.xcontent.XContentParser.Token) GeoHashUtils.addNeighbors(org.elasticsearch.common.geo.GeoHashUtils.addNeighbors) ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException) GeoPoint(org.elasticsearch.common.geo.GeoPoint) ArrayList(java.util.ArrayList) GeoPoint(org.elasticsearch.common.geo.GeoPoint) HashSet(java.util.HashSet)

Example 7 with Collection

use of java.util.Collection in project elasticsearch by elastic.

the class ClusterModule method createAllocationDeciders.

// TODO: this is public so allocation benchmark can access the default deciders...can we do that in another way?
/** Return a new {@link AllocationDecider} instance with builtin deciders as well as those from plugins. */
public static Collection<AllocationDecider> createAllocationDeciders(Settings settings, ClusterSettings clusterSettings, List<ClusterPlugin> clusterPlugins) {
    // collect deciders by class so that we can detect duplicates
    Map<Class, AllocationDecider> deciders = new LinkedHashMap<>();
    addAllocationDecider(deciders, new MaxRetryAllocationDecider(settings));
    addAllocationDecider(deciders, new ReplicaAfterPrimaryActiveAllocationDecider(settings));
    addAllocationDecider(deciders, new RebalanceOnlyWhenActiveAllocationDecider(settings));
    addAllocationDecider(deciders, new ClusterRebalanceAllocationDecider(settings, clusterSettings));
    addAllocationDecider(deciders, new ConcurrentRebalanceAllocationDecider(settings, clusterSettings));
    addAllocationDecider(deciders, new EnableAllocationDecider(settings, clusterSettings));
    addAllocationDecider(deciders, new NodeVersionAllocationDecider(settings));
    addAllocationDecider(deciders, new SnapshotInProgressAllocationDecider(settings));
    addAllocationDecider(deciders, new FilterAllocationDecider(settings, clusterSettings));
    addAllocationDecider(deciders, new SameShardAllocationDecider(settings, clusterSettings));
    addAllocationDecider(deciders, new DiskThresholdDecider(settings, clusterSettings));
    addAllocationDecider(deciders, new ThrottlingAllocationDecider(settings, clusterSettings));
    addAllocationDecider(deciders, new ShardsLimitAllocationDecider(settings, clusterSettings));
    addAllocationDecider(deciders, new AwarenessAllocationDecider(settings, clusterSettings));
    clusterPlugins.stream().flatMap(p -> p.createAllocationDeciders(settings, clusterSettings).stream()).forEach(d -> addAllocationDecider(deciders, d));
    return deciders.values();
}
Also used : MetaData(org.elasticsearch.cluster.metadata.MetaData) DelayedAllocationService(org.elasticsearch.cluster.routing.DelayedAllocationService) IngestMetadata(org.elasticsearch.ingest.IngestMetadata) AwarenessAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.AwarenessAllocationDecider) Property(org.elasticsearch.common.settings.Setting.Property) SameShardAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.SameShardAllocationDecider) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService) Reader(org.elasticsearch.common.io.stream.Writeable.Reader) ConcurrentRebalanceAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ConcurrentRebalanceAllocationDecider) ClusterPlugin(org.elasticsearch.plugins.ClusterPlugin) Settings(org.elasticsearch.common.settings.Settings) SnapshotInProgressAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.SnapshotInProgressAllocationDecider) Map(java.util.Map) TaskResultsService(org.elasticsearch.tasks.TaskResultsService) ParseField(org.elasticsearch.common.ParseField) NamedXContentRegistry(org.elasticsearch.common.xcontent.NamedXContentRegistry) ShardsLimitAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ShardsLimitAllocationDecider) MappingUpdatedAction(org.elasticsearch.cluster.action.index.MappingUpdatedAction) BalancedShardsAllocator(org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator) Setting(org.elasticsearch.common.settings.Setting) AbstractModule(org.elasticsearch.common.inject.AbstractModule) DiskThresholdDecider(org.elasticsearch.cluster.routing.allocation.decider.DiskThresholdDecider) Collection(java.util.Collection) NodeMappingRefreshAction(org.elasticsearch.cluster.action.index.NodeMappingRefreshAction) Objects(java.util.Objects) RebalanceOnlyWhenActiveAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.RebalanceOnlyWhenActiveAllocationDecider) List(java.util.List) ShardStateAction(org.elasticsearch.cluster.action.shard.ShardStateAction) AllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider) NodeVersionAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.NodeVersionAllocationDecider) FilterAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.FilterAllocationDecider) ThrottlingAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider) MetaDataCreateIndexService(org.elasticsearch.cluster.metadata.MetaDataCreateIndexService) ReplicaAfterPrimaryActiveAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ReplicaAfterPrimaryActiveAllocationDecider) MaxRetryAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider) ClusterService(org.elasticsearch.cluster.service.ClusterService) NamedWriteable(org.elasticsearch.common.io.stream.NamedWriteable) IndexGraveyard(org.elasticsearch.cluster.metadata.IndexGraveyard) HashMap(java.util.HashMap) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) MetaDataUpdateSettingsService(org.elasticsearch.cluster.metadata.MetaDataUpdateSettingsService) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) AllocationDeciders(org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders) ClusterRebalanceAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider) EnableAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider) RepositoriesMetaData(org.elasticsearch.cluster.metadata.RepositoriesMetaData) MetaDataIndexAliasesService(org.elasticsearch.cluster.metadata.MetaDataIndexAliasesService) ShardsAllocator(org.elasticsearch.cluster.routing.allocation.allocator.ShardsAllocator) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) MetaDataIndexTemplateService(org.elasticsearch.cluster.metadata.MetaDataIndexTemplateService) ScriptMetaData(org.elasticsearch.script.ScriptMetaData) MetaDataMappingService(org.elasticsearch.cluster.metadata.MetaDataMappingService) RoutingService(org.elasticsearch.cluster.routing.RoutingService) MetaDataDeleteIndexService(org.elasticsearch.cluster.metadata.MetaDataDeleteIndexService) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) Writeable(org.elasticsearch.common.io.stream.Writeable) GatewayAllocator(org.elasticsearch.gateway.GatewayAllocator) MetaDataIndexStateService(org.elasticsearch.cluster.metadata.MetaDataIndexStateService) Entry(org.elasticsearch.common.io.stream.NamedWriteableRegistry.Entry) SnapshotInProgressAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.SnapshotInProgressAllocationDecider) EnableAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider) RebalanceOnlyWhenActiveAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.RebalanceOnlyWhenActiveAllocationDecider) ThrottlingAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider) MaxRetryAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider) ReplicaAfterPrimaryActiveAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ReplicaAfterPrimaryActiveAllocationDecider) LinkedHashMap(java.util.LinkedHashMap) ClusterRebalanceAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider) SameShardAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.SameShardAllocationDecider) FilterAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.FilterAllocationDecider) DiskThresholdDecider(org.elasticsearch.cluster.routing.allocation.decider.DiskThresholdDecider) ShardsLimitAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ShardsLimitAllocationDecider) AwarenessAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.AwarenessAllocationDecider) NodeVersionAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.NodeVersionAllocationDecider) AwarenessAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.AwarenessAllocationDecider) SameShardAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.SameShardAllocationDecider) ConcurrentRebalanceAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ConcurrentRebalanceAllocationDecider) SnapshotInProgressAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.SnapshotInProgressAllocationDecider) ShardsLimitAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ShardsLimitAllocationDecider) RebalanceOnlyWhenActiveAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.RebalanceOnlyWhenActiveAllocationDecider) AllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider) NodeVersionAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.NodeVersionAllocationDecider) FilterAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.FilterAllocationDecider) ThrottlingAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider) ReplicaAfterPrimaryActiveAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ReplicaAfterPrimaryActiveAllocationDecider) MaxRetryAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider) ClusterRebalanceAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider) EnableAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider) ConcurrentRebalanceAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ConcurrentRebalanceAllocationDecider)

Example 8 with Collection

use of java.util.Collection in project elasticsearch by elastic.

the class ClusterModuleTests method testRegisterAllocationDeciderDuplicate.

public void testRegisterAllocationDeciderDuplicate() {
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new ClusterModule(Settings.EMPTY, clusterService, Collections.<ClusterPlugin>singletonList(new ClusterPlugin() {

        @Override
        public Collection<AllocationDecider> createAllocationDeciders(Settings settings, ClusterSettings clusterSettings) {
            return Collections.singletonList(new EnableAllocationDecider(settings, clusterSettings));
        }
    })));
    assertEquals(e.getMessage(), "Cannot specify allocation decider [" + EnableAllocationDecider.class.getName() + "] twice");
}
Also used : ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) ClusterPlugin(org.elasticsearch.plugins.ClusterPlugin) EnableAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider) Collection(java.util.Collection) Settings(org.elasticsearch.common.settings.Settings) IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings)

Example 9 with Collection

use of java.util.Collection in project buck by facebook.

the class Types method getContainerClass.

/**
   * @return The raw type of the {@link Collection} a field represents, even if contained in an
   *    {@link Optional}, but without the ParameterizedType information.
   */
@SuppressWarnings("unchecked")
@Nullable
public static Class<? extends Collection<?>> getContainerClass(Field field) {
    Type type = getFirstNonOptionalType(field);
    if (!(type instanceof ParameterizedType)) {
        return null;
    }
    Type rawType = ((ParameterizedType) type).getRawType();
    if (!(rawType instanceof Class)) {
        return null;
    }
    Class<?> clazz = (Class<?>) rawType;
    if (!(Collection.class.isAssignableFrom(clazz))) {
        return null;
    }
    return (Class<? extends Collection<?>>) clazz;
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) WildcardType(java.lang.reflect.WildcardType) Collection(java.util.Collection) Nullable(javax.annotation.Nullable)

Example 10 with Collection

use of java.util.Collection in project jetty.project by eclipse.

the class ObjectMBean method getAttribute.

/* ------------------------------------------------------------ */
public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException, ReflectionException {
    Method getter = (Method) _getters.get(name);
    if (getter == null) {
        throw new AttributeNotFoundException(name);
    }
    try {
        Object o = _managed;
        if (getter.getDeclaringClass().isInstance(this))
            // mbean method
            o = this;
        // get the attribute
        Object r = getter.invoke(o, (java.lang.Object[]) null);
        // convert to ObjectName if the type has the @ManagedObject annotation
        if (r != null) {
            if (r.getClass().isArray()) {
                if (r.getClass().getComponentType().isAnnotationPresent(ManagedObject.class)) {
                    ObjectName[] on = new ObjectName[Array.getLength(r)];
                    for (int i = 0; i < on.length; i++) {
                        on[i] = _mbeanContainer.findMBean(Array.get(r, i));
                    }
                    r = on;
                }
            } else if (r instanceof Collection<?>) {
                @SuppressWarnings("unchecked") Collection<Object> c = (Collection<Object>) r;
                if (!c.isEmpty() && c.iterator().next().getClass().isAnnotationPresent(ManagedObject.class)) {
                    // check the first thing out
                    ObjectName[] on = new ObjectName[c.size()];
                    int i = 0;
                    for (Object obj : c) {
                        on[i++] = _mbeanContainer.findMBean(obj);
                    }
                    r = on;
                }
            } else {
                Class<?> clazz = r.getClass();
                while (clazz != null) {
                    if (clazz.isAnnotationPresent(ManagedObject.class)) {
                        ObjectName mbean = _mbeanContainer.findMBean(r);
                        if (mbean != null) {
                            return mbean;
                        } else {
                            return null;
                        }
                    }
                    clazz = clazz.getSuperclass();
                }
            }
        }
        return r;
    } catch (IllegalAccessException e) {
        LOG.warn(Log.EXCEPTION, e);
        throw new AttributeNotFoundException(e.toString());
    } catch (InvocationTargetException e) {
        LOG.warn(Log.EXCEPTION, e);
        throw new ReflectionException(new Exception(e.getCause()));
    }
}
Also used : ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) AttributeNotFoundException(javax.management.AttributeNotFoundException) ReflectionException(javax.management.ReflectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) ObjectName(javax.management.ObjectName) Collection(java.util.Collection) ManagedObject(org.eclipse.jetty.util.annotation.ManagedObject) ManagedObject(org.eclipse.jetty.util.annotation.ManagedObject)

Aggregations

Collection (java.util.Collection)8532 ArrayList (java.util.ArrayList)2646 Map (java.util.Map)2119 List (java.util.List)1956 HashMap (java.util.HashMap)1657 Test (org.junit.Test)1476 Set (java.util.Set)1137 Iterator (java.util.Iterator)1090 HashSet (java.util.HashSet)1085 Collectors (java.util.stream.Collectors)951 IOException (java.io.IOException)823 Collections (java.util.Collections)660 Arrays (java.util.Arrays)446 Optional (java.util.Optional)423 File (java.io.File)386 Logger (org.slf4j.Logger)344 LoggerFactory (org.slf4j.LoggerFactory)330 PersistenceManager (javax.jdo.PersistenceManager)309 LinkedHashMap (java.util.LinkedHashMap)299 Query (javax.jdo.Query)294