Search in sources :

Example 51 with VisibleForTesting

use of com.google.common.annotations.VisibleForTesting in project presto by prestodb.

the class EventListenerManager method setConfiguredEventListener.

@VisibleForTesting
protected void setConfiguredEventListener(String name, Map<String, String> properties) {
    requireNonNull(name, "name is null");
    requireNonNull(properties, "properties is null");
    log.info("-- Loading event listener --");
    EventListenerFactory eventListenerFactory = eventListenerFactories.get(name);
    checkState(eventListenerFactory != null, "Event listener %s is not registered", name);
    EventListener eventListener = eventListenerFactory.create(ImmutableMap.copyOf(properties));
    this.configuredEventListener.set(Optional.of(eventListener));
    log.info("-- Loaded event listener %s --", name);
}
Also used : EventListenerFactory(com.facebook.presto.spi.eventlistener.EventListenerFactory) EventListener(com.facebook.presto.spi.eventlistener.EventListener) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 52 with VisibleForTesting

use of com.google.common.annotations.VisibleForTesting in project presto by prestodb.

the class InternalResourceGroupManager method setConfigurationManager.

@VisibleForTesting
public void setConfigurationManager(String name, Map<String, String> properties) {
    requireNonNull(name, "name is null");
    requireNonNull(properties, "properties is null");
    log.info("-- Loading resource group configuration manager --");
    ResourceGroupConfigurationManagerFactory configurationManagerFactory = configurationManagerFactories.get(name);
    checkState(configurationManagerFactory != null, "Resource group configuration manager %s is not registered", name);
    ResourceGroupConfigurationManager configurationManager = configurationManagerFactory.create(ImmutableMap.copyOf(properties), () -> memoryPoolManager);
    checkState(this.configurationManager.compareAndSet(null, configurationManager), "configurationManager already set");
    log.info("-- Loaded resource group configuration manager %s --", name);
}
Also used : ResourceGroupConfigurationManagerFactory(com.facebook.presto.spi.resourceGroups.ResourceGroupConfigurationManagerFactory) ResourceGroupConfigurationManager(com.facebook.presto.spi.resourceGroups.ResourceGroupConfigurationManager) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 53 with VisibleForTesting

use of com.google.common.annotations.VisibleForTesting in project presto by prestodb.

the class HeartbeatFailureDetector method updateMonitoredServices.

@VisibleForTesting
void updateMonitoredServices() {
    Set<ServiceDescriptor> online = selector.selectAllServices().stream().filter(descriptor -> !nodeInfo.getNodeId().equals(descriptor.getNodeId())).collect(toImmutableSet());
    Set<UUID> onlineIds = online.stream().map(ServiceDescriptor::getId).collect(toImmutableSet());
    // make sure only one thread is updating the registrations
    synchronized (tasks) {
        // 1. remove expired tasks
        List<UUID> expiredIds = tasks.values().stream().filter(MonitoringTask::isExpired).map(MonitoringTask::getService).map(ServiceDescriptor::getId).collect(toImmutableList());
        tasks.keySet().removeAll(expiredIds);
        // 2. disable offline services
        tasks.values().stream().filter(task -> !onlineIds.contains(task.getService().getId())).forEach(MonitoringTask::disable);
        // 3. create tasks for new services
        Set<ServiceDescriptor> newServices = online.stream().filter(service -> !tasks.keySet().contains(service.getId())).collect(toImmutableSet());
        for (ServiceDescriptor service : newServices) {
            URI uri = getHttpUri(service);
            if (uri != null) {
                tasks.put(service.getId(), new MonitoringTask(service, uri));
            }
        }
        // 4. enable all online tasks (existing plus newly created)
        tasks.values().stream().filter(task -> onlineIds.contains(task.getService().getId())).forEach(MonitoringTask::enable);
    }
}
Also used : HttpClient(io.airlift.http.client.HttpClient) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) ServiceType(io.airlift.discovery.client.ServiceType) ScheduledFuture(java.util.concurrent.ScheduledFuture) Logger(io.airlift.log.Logger) URISyntaxException(java.net.URISyntaxException) NodeInfo(io.airlift.node.NodeInfo) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Duration(io.airlift.units.Duration) ConcurrentMap(java.util.concurrent.ConcurrentMap) ServiceSelector(io.airlift.discovery.client.ServiceSelector) Inject(javax.inject.Inject) PreDestroy(javax.annotation.PreDestroy) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) Managed(org.weakref.jmx.Managed) Threads.daemonThreadsNamed(io.airlift.concurrent.Threads.daemonThreadsNamed) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Request(io.airlift.http.client.Request) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ImmutableCollectors.toImmutableSet(com.facebook.presto.util.ImmutableCollectors.toImmutableSet) URI(java.net.URI) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) ExponentialDecay(io.airlift.stats.ExponentialDecay) Builder.prepareHead(io.airlift.http.client.Request.Builder.prepareHead) ImmutableMap(com.google.common.collect.ImmutableMap) DateTime(org.joda.time.DateTime) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) DecayCounter(io.airlift.stats.DecayCounter) ThreadSafe(javax.annotation.concurrent.ThreadSafe) UUID(java.util.UUID) ResponseHandler(io.airlift.http.client.ResponseHandler) GuardedBy(javax.annotation.concurrent.GuardedBy) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) ServiceDescriptor(io.airlift.discovery.client.ServiceDescriptor) Response(io.airlift.http.client.Response) PostConstruct(javax.annotation.PostConstruct) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ServiceDescriptor(io.airlift.discovery.client.ServiceDescriptor) UUID(java.util.UUID) URI(java.net.URI) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 54 with VisibleForTesting

use of com.google.common.annotations.VisibleForTesting in project presto by prestodb.

the class DecimalAverageAggregation method average.

@VisibleForTesting
public static BigDecimal average(LongDecimalWithOverflowAndLongState state, DecimalType type) {
    BigDecimal sum = new BigDecimal(Decimals.decodeUnscaledValue(state.getLongDecimal()), type.getScale());
    BigDecimal count = BigDecimal.valueOf(state.getLong());
    if (state.getOverflow() != 0) {
        BigInteger overflowMultiplier = TWO.shiftLeft(UNSCALED_DECIMAL_128_SLICE_LENGTH * 8 - 2);
        BigInteger overflow = overflowMultiplier.multiply(BigInteger.valueOf(state.getOverflow()));
        sum = sum.add(new BigDecimal(overflow));
    }
    return sum.divide(count, type.getScale(), ROUND_HALF_UP);
}
Also used : BigInteger(java.math.BigInteger) Decimals.writeBigDecimal(com.facebook.presto.spi.type.Decimals.writeBigDecimal) BigDecimal(java.math.BigDecimal) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 55 with VisibleForTesting

use of com.google.common.annotations.VisibleForTesting in project presto by prestodb.

the class ColorFunctions method parseRgb.

@VisibleForTesting
static int parseRgb(Slice color) {
    if (color.length() != 4 || color.getByte(0) != '#') {
        return -1;
    }
    int red = Character.digit((char) color.getByte(1), 16);
    int green = Character.digit((char) color.getByte(2), 16);
    int blue = Character.digit((char) color.getByte(3), 16);
    if (red == -1 || green == -1 || blue == -1) {
        return -1;
    }
    // replicate the nibbles to turn a color of the form #rgb => #rrggbb (css semantics)
    red = (red << 4) | red;
    green = (green << 4) | green;
    blue = (blue << 4) | blue;
    return (int) rgb(red, green, blue);
}
Also used : Constraint(com.facebook.presto.type.Constraint) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)808 IOException (java.io.IOException)135 ArrayList (java.util.ArrayList)67 Map (java.util.Map)52 Path (java.nio.file.Path)47 File (java.io.File)41 HashMap (java.util.HashMap)37 Path (org.apache.hadoop.fs.Path)33 List (java.util.List)29 ImmutableList (com.google.common.collect.ImmutableList)28 Matcher (java.util.regex.Matcher)26 HashSet (java.util.HashSet)23 ImmutableMap (com.google.common.collect.ImmutableMap)21 FileStatus (org.apache.hadoop.fs.FileStatus)21 SourcePath (com.facebook.buck.rules.SourcePath)20 FileHandle (org.apache.hadoop.nfs.nfs3.FileHandle)19 DFSClient (org.apache.hadoop.hdfs.DFSClient)18 Nfs3FileAttributes (org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes)18 ImmutableSet (com.google.common.collect.ImmutableSet)17 LinkedHashMap (java.util.LinkedHashMap)17