Search in sources :

Example 1 with NodeRole

use of org.apache.druid.discovery.NodeRole in project druid by druid-io.

the class InitializationTest method testCreateInjectorWithNodeRoleFilter_moduleNotLoaded.

@Test
public void testCreateInjectorWithNodeRoleFilter_moduleNotLoaded() {
    final DruidNode expected = new DruidNode("test-inject", null, false, null, null, true, false);
    Injector startupInjector = GuiceInjectors.makeStartupInjector();
    Injector injector = Initialization.makeInjectorWithModules(ImmutableSet.of(new NodeRole("role1"), new NodeRole("role2")), startupInjector, ImmutableList.of((com.google.inject.Module) binder -> JsonConfigProvider.bindInstance(binder, Key.get(DruidNode.class, Self.class), expected), new LoadOnAnnotationTestModule()));
    Assert.assertNotNull(injector);
    Assert.assertEquals(expected, injector.getInstance(Key.get(DruidNode.class, Self.class)));
    Assert.assertThrows("Guice configuration errors", ConfigurationException.class, () -> injector.getInstance(Key.get(String.class, Names.named("emperor"))));
}
Also used : NodeRole(org.apache.druid.discovery.NodeRole) Injector(com.google.inject.Injector) DruidNode(org.apache.druid.server.DruidNode) Module(com.fasterxml.jackson.databind.Module) Test(org.junit.Test)

Example 2 with NodeRole

use of org.apache.druid.discovery.NodeRole in project druid by druid-io.

the class ITHighAvailabilityTest method testCustomDiscovery.

@Test
public void testCustomDiscovery() {
    ITRetryUtil.retryUntil(() -> {
        try {
            DruidNodeDiscovery customDisco = druidNodeDiscovery.getForNodeRole(new NodeRole(CliCustomNodeRole.SERVICE_NAME));
            int count = testSelfDiscovery(customDisco.getAllNodes());
            return count > 0;
        } catch (Throwable t) {
            return false;
        }
    }, true, RETRY_DELAY, NUM_RETRIES, "Custom service discovered");
}
Also used : CliCustomNodeRole(org.apache.druid.cli.CliCustomNodeRole) NodeRole(org.apache.druid.discovery.NodeRole) DruidNodeDiscovery(org.apache.druid.discovery.DruidNodeDiscovery) Test(org.testng.annotations.Test) AbstractIndexerTest(org.apache.druid.tests.indexer.AbstractIndexerTest)

Example 3 with NodeRole

use of org.apache.druid.discovery.NodeRole in project druid by druid-io.

the class CommonCacheNotifier method sendUpdate.

private List<ListenableFuture<StatusResponseHolder>> sendUpdate(String updatedAuthenticatorPrefix, byte[] serializedEntity) {
    List<ListenableFuture<StatusResponseHolder>> futures = new ArrayList<>();
    for (NodeRole nodeRole : NODE_TYPES) {
        DruidNodeDiscovery nodeDiscovery = discoveryProvider.getForNodeRole(nodeRole);
        Collection<DiscoveryDruidNode> nodes = nodeDiscovery.getAllNodes();
        for (DiscoveryDruidNode node : nodes) {
            URL listenerURL = getListenerURL(node.getDruidNode(), StringUtils.format(baseUrl, StringUtils.urlEncode(updatedAuthenticatorPrefix)));
            // best effort, if this fails, remote node will poll and pick up the update eventually
            Request req = new Request(HttpMethod.POST, listenerURL);
            req.setContent(MediaType.APPLICATION_JSON, serializedEntity);
            BasicAuthDBConfig itemConfig = itemConfigMap.get(updatedAuthenticatorPrefix);
            ListenableFuture<StatusResponseHolder> future = httpClient.go(req, new ResponseHandler(), Duration.millis(itemConfig.getCacheNotificationTimeout()));
            futures.add(future);
        }
    }
    return futures;
}
Also used : HttpResponseHandler(org.apache.druid.java.util.http.client.response.HttpResponseHandler) DruidNodeDiscovery(org.apache.druid.discovery.DruidNodeDiscovery) ArrayList(java.util.ArrayList) Request(org.apache.druid.java.util.http.client.Request) URL(java.net.URL) NodeRole(org.apache.druid.discovery.NodeRole) DiscoveryDruidNode(org.apache.druid.discovery.DiscoveryDruidNode) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder)

Example 4 with NodeRole

use of org.apache.druid.discovery.NodeRole in project druid by druid-io.

the class InitializationTest method testCreateInjectorWithNodeRoles.

@Test
public void testCreateInjectorWithNodeRoles() {
    final DruidNode expected = new DruidNode("test-inject", null, false, null, null, true, false);
    Injector startupInjector = GuiceInjectors.makeStartupInjector();
    Injector injector = Initialization.makeInjectorWithModules(ImmutableSet.of(new NodeRole("role1"), new NodeRole("role2")), startupInjector, ImmutableList.of(binder -> JsonConfigProvider.bindInstance(binder, Key.get(DruidNode.class, Self.class), expected)));
    Assert.assertNotNull(injector);
    Assert.assertEquals(expected, injector.getInstance(Key.get(DruidNode.class, Self.class)));
}
Also used : Module(com.fasterxml.jackson.databind.Module) MethodSorters(org.junit.runners.MethodSorters) Arrays(java.util.Arrays) Self(org.apache.druid.guice.annotations.Self) URL(java.net.URL) Inject(com.google.inject.Inject) Key(com.google.inject.Key) Collections2(com.google.common.collect.Collections2) HashSet(java.util.HashSet) URLClassLoader(java.net.URLClassLoader) ImmutableList(com.google.common.collect.ImmutableList) Binder(com.google.inject.Binder) ExtensionsConfig(org.apache.druid.guice.ExtensionsConfig) Nullable(javax.annotation.Nullable) LinkedHashSet(java.util.LinkedHashSet) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) JsonConfigProvider(org.apache.druid.guice.JsonConfigProvider) LoadScope(org.apache.druid.guice.annotations.LoadScope) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConfigurationException(com.google.inject.ConfigurationException) Set(java.util.Set) ISE(org.apache.druid.java.util.common.ISE) Test(org.junit.Test) IOException(java.io.IOException) Names(com.google.inject.name.Names) Multibinder(com.google.inject.multibindings.Multibinder) Sets(com.google.common.collect.Sets) GuiceInjectors(org.apache.druid.guice.GuiceInjectors) File(java.io.File) Injector(com.google.inject.Injector) List(java.util.List) Rule(org.junit.Rule) DruidNode(org.apache.druid.server.DruidNode) NodeRole(org.apache.druid.discovery.NodeRole) Assert(org.junit.Assert) FixMethodOrder(org.junit.FixMethodOrder) Comparator(java.util.Comparator) TemporaryFolder(org.junit.rules.TemporaryFolder) NodeRole(org.apache.druid.discovery.NodeRole) Injector(com.google.inject.Injector) DruidNode(org.apache.druid.server.DruidNode) Self(org.apache.druid.guice.annotations.Self) Test(org.junit.Test)

Example 5 with NodeRole

use of org.apache.druid.discovery.NodeRole in project druid by druid-io.

the class InitializationTest method testCreateInjectorWithNodeRoleFilterUsingInject_moduleLoaded.

@Test
public void testCreateInjectorWithNodeRoleFilterUsingInject_moduleLoaded() {
    final Set<NodeRole> nodeRoles = ImmutableSet.of(new NodeRole("role1"), new NodeRole("druid"));
    final DruidNode expected = new DruidNode("test-inject", null, false, null, null, true, false);
    Injector startupInjector = GuiceInjectors.makeStartupInjectorWithModules(ImmutableList.of(binder -> {
        Multibinder<NodeRole> selfBinder = Multibinder.newSetBinder(binder, NodeRole.class, Self.class);
        nodeRoles.forEach(nodeRole -> selfBinder.addBinding().toInstance(nodeRole));
    }));
    Injector injector = Initialization.makeInjectorWithModules(nodeRoles, startupInjector, ImmutableList.of((com.google.inject.Module) binder -> JsonConfigProvider.bindInstance(binder, Key.get(DruidNode.class, Self.class), expected), new NodeRolesInjectTestModule()));
    Assert.assertNotNull(injector);
    Assert.assertEquals(expected, injector.getInstance(Key.get(DruidNode.class, Self.class)));
    Assert.assertEquals("I am Druid", injector.getInstance(Key.get(String.class, Names.named("emperor"))));
}
Also used : Module(com.fasterxml.jackson.databind.Module) MethodSorters(org.junit.runners.MethodSorters) Arrays(java.util.Arrays) Self(org.apache.druid.guice.annotations.Self) URL(java.net.URL) Inject(com.google.inject.Inject) Key(com.google.inject.Key) Collections2(com.google.common.collect.Collections2) HashSet(java.util.HashSet) URLClassLoader(java.net.URLClassLoader) ImmutableList(com.google.common.collect.ImmutableList) Binder(com.google.inject.Binder) ExtensionsConfig(org.apache.druid.guice.ExtensionsConfig) Nullable(javax.annotation.Nullable) LinkedHashSet(java.util.LinkedHashSet) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) JsonConfigProvider(org.apache.druid.guice.JsonConfigProvider) LoadScope(org.apache.druid.guice.annotations.LoadScope) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConfigurationException(com.google.inject.ConfigurationException) Set(java.util.Set) ISE(org.apache.druid.java.util.common.ISE) Test(org.junit.Test) IOException(java.io.IOException) Names(com.google.inject.name.Names) Multibinder(com.google.inject.multibindings.Multibinder) Sets(com.google.common.collect.Sets) GuiceInjectors(org.apache.druid.guice.GuiceInjectors) File(java.io.File) Injector(com.google.inject.Injector) List(java.util.List) Rule(org.junit.Rule) DruidNode(org.apache.druid.server.DruidNode) NodeRole(org.apache.druid.discovery.NodeRole) Assert(org.junit.Assert) FixMethodOrder(org.junit.FixMethodOrder) Comparator(java.util.Comparator) TemporaryFolder(org.junit.rules.TemporaryFolder) NodeRole(org.apache.druid.discovery.NodeRole) Multibinder(com.google.inject.multibindings.Multibinder) Injector(com.google.inject.Injector) DruidNode(org.apache.druid.server.DruidNode) Self(org.apache.druid.guice.annotations.Self) Module(com.fasterxml.jackson.databind.Module) Test(org.junit.Test)

Aggregations

NodeRole (org.apache.druid.discovery.NodeRole)7 Module (com.fasterxml.jackson.databind.Module)5 Injector (com.google.inject.Injector)5 DruidNode (org.apache.druid.server.DruidNode)5 Test (org.junit.Test)5 URL (java.net.URL)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Function (com.google.common.base.Function)3 Collections2 (com.google.common.collect.Collections2)3 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 Sets (com.google.common.collect.Sets)3 Binder (com.google.inject.Binder)3 ConfigurationException (com.google.inject.ConfigurationException)3 Inject (com.google.inject.Inject)3 Key (com.google.inject.Key)3 Multibinder (com.google.inject.multibindings.Multibinder)3 Names (com.google.inject.name.Names)3 File (java.io.File)3 IOException (java.io.IOException)3