Search in sources :

Example 1 with ENGLISH

use of java.util.Locale.ENGLISH in project presto by prestodb.

the class DiscoveryNodeManager method refreshNodesInternal.

private synchronized PrestoNode refreshNodesInternal() {
    lastUpdateTimestamp = System.nanoTime();
    // This is currently a blacklist.
    // TODO: make it a whitelist (a failure-detecting service selector) and maybe build in support for injecting this in airlift
    Set<ServiceDescriptor> services = serviceSelector.selectAllServices().stream().filter(service -> !failureDetector.getFailed().contains(service)).collect(toImmutableSet());
    PrestoNode currentNode = null;
    ImmutableSet.Builder<Node> activeNodesBuilder = ImmutableSet.builder();
    ImmutableSet.Builder<Node> inactiveNodesBuilder = ImmutableSet.builder();
    ImmutableSet.Builder<Node> shuttingDownNodesBuilder = ImmutableSet.builder();
    ImmutableSet.Builder<Node> coordinatorsBuilder = ImmutableSet.builder();
    ImmutableSetMultimap.Builder<ConnectorId, Node> byConnectorIdBuilder = ImmutableSetMultimap.builder();
    for (ServiceDescriptor service : services) {
        URI uri = getHttpUri(service);
        NodeVersion nodeVersion = getNodeVersion(service);
        boolean coordinator = isCoordinator(service);
        if (uri != null && nodeVersion != null) {
            PrestoNode node = new PrestoNode(service.getNodeId(), uri, nodeVersion, coordinator);
            NodeState nodeState = getNodeState(node);
            // record current node
            if (node.getNodeIdentifier().equals(nodeInfo.getNodeId())) {
                currentNode = node;
                checkState(currentNode.getNodeVersion().equals(expectedNodeVersion), "INVARIANT: current node version (%s) should be equal to %s", currentNode.getNodeVersion(), expectedNodeVersion);
            }
            switch(nodeState) {
                case ACTIVE:
                    activeNodesBuilder.add(node);
                    if (coordinator) {
                        coordinatorsBuilder.add(node);
                    }
                    // record available active nodes organized by connector id
                    String connectorIds = service.getProperties().get("connectorIds");
                    if (connectorIds != null) {
                        connectorIds = connectorIds.toLowerCase(ENGLISH);
                        for (String connectorId : CONNECTOR_ID_SPLITTER.split(connectorIds)) {
                            byConnectorIdBuilder.put(new ConnectorId(connectorId), node);
                        }
                    }
                    // always add system connector
                    byConnectorIdBuilder.put(new ConnectorId(GlobalSystemConnector.NAME), node);
                    break;
                case INACTIVE:
                    inactiveNodesBuilder.add(node);
                    break;
                case SHUTTING_DOWN:
                    shuttingDownNodesBuilder.add(node);
                    break;
                default:
                    throw new IllegalArgumentException("Unknown node state " + nodeState);
            }
        }
    }
    if (allNodes != null) {
        // log node that are no longer active (but not shutting down)
        SetView<Node> missingNodes = difference(allNodes.getActiveNodes(), Sets.union(activeNodesBuilder.build(), shuttingDownNodesBuilder.build()));
        for (Node missingNode : missingNodes) {
            log.info("Previously active node is missing: %s (last seen at %s)", missingNode.getNodeIdentifier(), missingNode.getHostAndPort());
        }
    }
    allNodes = new AllNodes(activeNodesBuilder.build(), inactiveNodesBuilder.build(), shuttingDownNodesBuilder.build());
    activeNodesByConnectorId = byConnectorIdBuilder.build();
    coordinators = coordinatorsBuilder.build();
    checkState(currentNode != null, "INVARIANT: current node not returned from service selector");
    return currentNode;
}
Also used : HttpClient(io.airlift.http.client.HttpClient) ServiceType(io.airlift.discovery.client.ServiceType) Logger(io.airlift.log.Logger) URISyntaxException(java.net.URISyntaxException) NodeInfo(io.airlift.node.NodeInfo) NodeVersion(com.facebook.presto.client.NodeVersion) Duration(io.airlift.units.Duration) ACTIVE(com.facebook.presto.spi.NodeState.ACTIVE) ServiceSelector(io.airlift.discovery.client.ServiceSelector) Inject(javax.inject.Inject) PreDestroy(javax.annotation.PreDestroy) Sets.difference(com.google.common.collect.Sets.difference) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) Node(com.facebook.presto.spi.Node) Managed(org.weakref.jmx.Managed) GlobalSystemConnector(com.facebook.presto.connector.system.GlobalSystemConnector) Arrays.asList(java.util.Arrays.asList) Objects.requireNonNull(java.util.Objects.requireNonNull) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ImmutableCollectors.toImmutableSet(com.facebook.presto.util.ImmutableCollectors.toImmutableSet) URI(java.net.URI) Splitter(com.google.common.base.Splitter) ENGLISH(java.util.Locale.ENGLISH) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) ImmutableSet(com.google.common.collect.ImmutableSet) SHUTTING_DOWN(com.facebook.presto.spi.NodeState.SHUTTING_DOWN) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SetView(com.google.common.collect.Sets.SetView) Set(java.util.Set) ThreadSafe(javax.annotation.concurrent.ThreadSafe) GuardedBy(javax.annotation.concurrent.GuardedBy) Threads.threadsNamed(io.airlift.concurrent.Threads.threadsNamed) NodeState(com.facebook.presto.spi.NodeState) SetMultimap(com.google.common.collect.SetMultimap) Sets(com.google.common.collect.Sets) Preconditions.checkState(com.google.common.base.Preconditions.checkState) TimeUnit(java.util.concurrent.TimeUnit) ServiceDescriptor(io.airlift.discovery.client.ServiceDescriptor) FailureDetector(com.facebook.presto.failureDetector.FailureDetector) PostConstruct(javax.annotation.PostConstruct) HttpUriBuilder.uriBuilderFrom(io.airlift.http.client.HttpUriBuilder.uriBuilderFrom) Optional(java.util.Optional) ConnectorId(com.facebook.presto.connector.ConnectorId) INACTIVE(com.facebook.presto.spi.NodeState.INACTIVE) NodeState(com.facebook.presto.spi.NodeState) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) Node(com.facebook.presto.spi.Node) URI(java.net.URI) NodeVersion(com.facebook.presto.client.NodeVersion) ImmutableCollectors.toImmutableSet(com.facebook.presto.util.ImmutableCollectors.toImmutableSet) ImmutableSet(com.google.common.collect.ImmutableSet) ServiceDescriptor(io.airlift.discovery.client.ServiceDescriptor) ConnectorId(com.facebook.presto.connector.ConnectorId)

Example 2 with ENGLISH

use of java.util.Locale.ENGLISH in project error-prone by google.

the class ErrorProneJavacPluginTest method hello.

@Test
public void hello() throws IOException {
    FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix());
    Path source = fileSystem.getPath("Test.java");
    Files.write(source, ImmutableList.of("import java.util.HashSet;", "import java.util.Set;", "class Test {", "  public static void main(String[] args) {", "    Set<Short> s = new HashSet<>();", "    for (short i = 0; i < 100; i++) {", "      s.add(i);", "      s.remove(i - 1);", "    }", "    System.out.println(s.size());", "  }", "}"), UTF_8);
    JavacFileManager fileManager = new JavacFileManager(new Context(), false, UTF_8);
    DiagnosticCollector<JavaFileObject> diagnosticCollector = new DiagnosticCollector<>();
    JavacTask task = JavacTool.create().getTask(null, fileManager, diagnosticCollector, ImmutableList.of("-Xplugin:ErrorProne"), ImmutableList.of(), fileManager.getJavaFileObjects(source));
    assertThat(task.call()).isFalse();
    Diagnostic<? extends JavaFileObject> diagnostic = diagnosticCollector.getDiagnostics().stream().filter(d -> d.getKind() == Diagnostic.Kind.ERROR).collect(onlyElement());
    assertThat(diagnostic.getMessage(ENGLISH)).contains("[CollectionIncompatibleType]");
}
Also used : Path(java.nio.file.Path) JavacFileManager(com.sun.tools.javac.file.JavacFileManager) Context(com.sun.tools.javac.util.Context) Configuration(com.google.common.jimfs.Configuration) JavacFileManager(com.sun.tools.javac.file.JavacFileManager) JavacTask(com.sun.source.util.JavacTask) Files(java.nio.file.Files) UTF_8(java.nio.charset.StandardCharsets.UTF_8) RunWith(org.junit.runner.RunWith) IOException(java.io.IOException) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) FileSystem(java.nio.file.FileSystem) MoreCollectors.onlyElement(com.google.common.collect.MoreCollectors.onlyElement) JavaFileObject(javax.tools.JavaFileObject) ImmutableList(com.google.common.collect.ImmutableList) JavacTool(com.sun.tools.javac.api.JavacTool) Jimfs(com.google.common.jimfs.Jimfs) Diagnostic(javax.tools.Diagnostic) Context(com.sun.tools.javac.util.Context) ENGLISH(java.util.Locale.ENGLISH) Path(java.nio.file.Path) DiagnosticCollector(javax.tools.DiagnosticCollector) JavaFileObject(javax.tools.JavaFileObject) FileSystem(java.nio.file.FileSystem) DiagnosticCollector(javax.tools.DiagnosticCollector) JavacTask(com.sun.source.util.JavacTask) Test(org.junit.Test)

Aggregations

ENGLISH (java.util.Locale.ENGLISH)2 NodeVersion (com.facebook.presto.client.NodeVersion)1 ConnectorId (com.facebook.presto.connector.ConnectorId)1 GlobalSystemConnector (com.facebook.presto.connector.system.GlobalSystemConnector)1 FailureDetector (com.facebook.presto.failureDetector.FailureDetector)1 Node (com.facebook.presto.spi.Node)1 NodeState (com.facebook.presto.spi.NodeState)1 ACTIVE (com.facebook.presto.spi.NodeState.ACTIVE)1 INACTIVE (com.facebook.presto.spi.NodeState.INACTIVE)1 SHUTTING_DOWN (com.facebook.presto.spi.NodeState.SHUTTING_DOWN)1 ImmutableCollectors.toImmutableSet (com.facebook.presto.util.ImmutableCollectors.toImmutableSet)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Splitter (com.google.common.base.Splitter)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)1 MoreCollectors.onlyElement (com.google.common.collect.MoreCollectors.onlyElement)1 SetMultimap (com.google.common.collect.SetMultimap)1 Sets (com.google.common.collect.Sets)1 SetView (com.google.common.collect.Sets.SetView)1