Search in sources :

Example 1 with InternalCommunicationConfig

use of io.prestosql.server.InternalCommunicationConfig in project hetu-core by openlookeng.

the class TestStateStoreLauncherAndProvider method testRegisterDiscoveryService.

@Test(timeOut = 5000, expectedExceptions = ThreadTimeoutException.class)
public void testRegisterDiscoveryService() throws Exception {
    String failurehost = "failurehost";
    String otherhost = "otherhost";
    String localHostName = "localhost";
    int port = 8888;
    URI uri = new URI("http://" + localHostName + ":" + port);
    MockStateMap discoveryServiceMap = new MockStateMap(DISCOVERY_SERVICE, new HashMap<>());
    // Mock
    StateStore stateStore = mock(StateStore.class);
    Lock lock = mock(ReentrantLock.class);
    InternalCommunicationConfig internalCommunicationConfig = mock(InternalCommunicationConfig.class);
    HttpServerInfo httpServerInfo = mock(HttpServerInfo.class);
    when(httpServerInfo.getHttpUri()).thenReturn(uri);
    when(internalCommunicationConfig.isHttpsRequired()).thenReturn(false);
    when(stateStore.getStateCollection(DISCOVERY_SERVICE)).thenReturn(discoveryServiceMap);
    when(stateStore.getLock(DISCOVERY_SERVICE_LOCK)).thenReturn(lock);
    EmbeddedStateStoreLauncher launcher = new EmbeddedStateStoreLauncher(new SeedStoreManager(new FileSystemClientManager()), internalCommunicationConfig, httpServerInfo, new HetuConfig());
    launcher.setStateStore(stateStore);
    when(lock.tryLock(DISCOVERY_REGISTRY_LOCK_TIMEOUT, TimeUnit.MILLISECONDS)).thenReturn(true);
    // discoveryServiceMap is empty, so the current coordinator can get the lock and register itself(register=true)
    discoveryServiceMap.clear();
    assertTrue(launcher.registerDiscoveryService(failurehost));
    assertEquals(discoveryServiceMap.size(), 1);
    assertTrue(discoveryServiceMap.getAll().keySet().contains(localHostName));
    // discoveryServiceMap contains the failure host, so the current coordinator can get the lock and register itself(register=true)
    discoveryServiceMap.clear();
    discoveryServiceMap.put(failurehost, String.valueOf(port));
    assertTrue(launcher.registerDiscoveryService(failurehost));
    assertEquals(discoveryServiceMap.size(), 1);
    assertTrue(discoveryServiceMap.getAll().keySet().contains(localHostName));
    // discoveryServiceMap is already updated by other coordinator(otherhosts)
    // the current coordinator can grab the lock but will not register itself(register=false)
    discoveryServiceMap.clear();
    discoveryServiceMap.put(otherhost, String.valueOf(port));
    assertFalse(launcher.registerDiscoveryService(failurehost));
    assertEquals(discoveryServiceMap.size(), 1);
    assertFalse(discoveryServiceMap.containsKey(localHostName));
    when(lock.tryLock(DISCOVERY_REGISTRY_LOCK_TIMEOUT, TimeUnit.MILLISECONDS)).thenReturn(false);
    // discoveryServiceMap is already updated by other coordinator(otherhosts)
    // the current coordinator cannot grab the lock and not register itself
    discoveryServiceMap.clear();
    discoveryServiceMap.put(otherhost, String.valueOf(port));
    assertFalse(launcher.registerDiscoveryService(failurehost));
    assertEquals(discoveryServiceMap.size(), 1);
    assertFalse(discoveryServiceMap.containsKey(localHostName));
    // discoveryServiceMap contains failure host.
    // The current coordinator cannot get the lock and retry will cause timeout exception
    discoveryServiceMap.clear();
    discoveryServiceMap.put(failurehost, String.valueOf(port));
    launcher.registerDiscoveryService(failurehost);
}
Also used : StateStore(io.prestosql.spi.statestore.StateStore) HazelcastStateStore(io.hetu.core.statestore.hazelcast.HazelcastStateStore) URI(java.net.URI) HetuConfig(io.prestosql.utils.HetuConfig) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock) FileSystemClientManager(io.prestosql.filesystem.FileSystemClientManager) InternalCommunicationConfig(io.prestosql.server.InternalCommunicationConfig) SeedStoreManager(io.prestosql.seedstore.SeedStoreManager) HttpServerInfo(io.airlift.http.server.HttpServerInfo) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) AfterTest(org.testng.annotations.AfterTest)

Example 2 with InternalCommunicationConfig

use of io.prestosql.server.InternalCommunicationConfig in project hetu-core by openlookeng.

the class TestHetuServiceInventory method testGetDiscoveryUriSupplierHttp.

@Test
public void testGetDiscoveryUriSupplierHttp() {
    InternalCommunicationConfig internalCommunicationConfig = new InternalCommunicationConfig().setHttpsRequired(false);
    HetuConfig hetuConfig = new HetuConfig();
    hetuConfig.setMultipleCoordinatorEnabled(true);
    HetuServiceInventory inventory = new HetuServiceInventory(hetuConfig, null, createMockStateStoreProvider(), internalCommunicationConfig, new ServiceInventoryConfig(), new NodeInfo(new NodeConfig().setEnvironment("hetutest")), JsonCodec.jsonCodec(ServiceDescriptorsRepresentation.class), new TestingHttpClient(new MockExchangeRequestProcessor(new DataSize(0, BYTE))));
    Iterable<ServiceDescriptor> serviceDescriptors = inventory.getServiceDescriptors("discovery");
    List<URI> uris = new ArrayList<>();
    serviceDescriptors.forEach(serviceDescriptor -> {
        uris.add(URI.create(serviceDescriptor.getProperties().get("http")));
    });
    URI checkUri = URI.create("http://127.0.0.1:8090");
    assertEquals(uris.size(), 1);
    uris.contains(checkUri);
}
Also used : ServiceInventoryConfig(io.airlift.discovery.client.ServiceInventoryConfig) ArrayList(java.util.ArrayList) HetuConfig(io.prestosql.utils.HetuConfig) URI(java.net.URI) InternalCommunicationConfig(io.prestosql.server.InternalCommunicationConfig) ServiceDescriptorsRepresentation(io.airlift.discovery.client.ServiceDescriptorsRepresentation) MockExchangeRequestProcessor(io.prestosql.operator.MockExchangeRequestProcessor) ServiceDescriptor(io.airlift.discovery.client.ServiceDescriptor) NodeInfo(io.airlift.node.NodeInfo) TestingHttpClient(io.airlift.http.client.testing.TestingHttpClient) DataSize(io.airlift.units.DataSize) NodeConfig(io.airlift.node.NodeConfig) Test(org.testng.annotations.Test)

Example 3 with InternalCommunicationConfig

use of io.prestosql.server.InternalCommunicationConfig in project hetu-core by openlookeng.

the class TestHetuServiceInventory method testGetDiscoveryUriSupplierHttps.

@Test
public void testGetDiscoveryUriSupplierHttps() {
    InternalCommunicationConfig internalCommunicationConfig = new InternalCommunicationConfig().setHttpsRequired(true);
    HetuConfig hetuConfig = new HetuConfig();
    hetuConfig.setMultipleCoordinatorEnabled(true);
    HetuServiceInventory inventory = new HetuServiceInventory(hetuConfig, null, createMockStateStoreProvider(), internalCommunicationConfig, new ServiceInventoryConfig(), new NodeInfo(new NodeConfig().setEnvironment("hetutest")), JsonCodec.jsonCodec(ServiceDescriptorsRepresentation.class), new TestingHttpClient(new MockExchangeRequestProcessor(new DataSize(0, BYTE))));
    Iterable<ServiceDescriptor> serviceDescriptors = inventory.getServiceDescriptors("discovery");
    List<URI> uris = new ArrayList<>();
    serviceDescriptors.forEach(serviceDescriptor -> {
        uris.add(URI.create(serviceDescriptor.getProperties().get("https")));
    });
    URI checkUri = URI.create("https://127.0.0.1:8090");
    assertEquals(uris.size(), 1);
    uris.contains(checkUri);
}
Also used : ServiceInventoryConfig(io.airlift.discovery.client.ServiceInventoryConfig) ArrayList(java.util.ArrayList) HetuConfig(io.prestosql.utils.HetuConfig) URI(java.net.URI) InternalCommunicationConfig(io.prestosql.server.InternalCommunicationConfig) ServiceDescriptorsRepresentation(io.airlift.discovery.client.ServiceDescriptorsRepresentation) MockExchangeRequestProcessor(io.prestosql.operator.MockExchangeRequestProcessor) ServiceDescriptor(io.airlift.discovery.client.ServiceDescriptor) NodeInfo(io.airlift.node.NodeInfo) TestingHttpClient(io.airlift.http.client.testing.TestingHttpClient) DataSize(io.airlift.units.DataSize) NodeConfig(io.airlift.node.NodeConfig) Test(org.testng.annotations.Test)

Example 4 with InternalCommunicationConfig

use of io.prestosql.server.InternalCommunicationConfig in project hetu-core by openlookeng.

the class TestStateStoreLauncherAndProvider method testLaunchAndFailure.

// Test Launcher
@Test
public void testLaunchAndFailure() throws Exception {
    Set<Seed> seeds = new HashSet<>();
    SeedStore mockSeedStore = mock(SeedStore.class);
    Seed mockSeed1 = mock(Seed.class);
    Seed mockSeed2 = mock(Seed.class);
    seeds.add(mockSeed1);
    seeds.add(mockSeed2);
    when(mockSeed1.getLocation()).thenReturn(LOCALHOST + ":" + PORT1);
    when(mockSeed2.getLocation()).thenReturn(LOCALHOST + ":" + PORT2);
    when(mockSeedStore.get()).thenReturn(seeds);
    SeedStoreManager mockSeedStoreManager = mock(SeedStoreManager.class);
    when(mockSeedStoreManager.getSeedStore(SeedStoreSubType.HAZELCAST)).thenReturn(mockSeedStore);
    when(mockSeedStoreManager.addSeed(SeedStoreSubType.HAZELCAST, LOCALHOST, true)).thenReturn(seeds);
    when(mockSeedStoreManager.getFileSystemClient()).thenReturn(new HetuLocalFileSystemClient(new LocalConfig(new Properties()), Paths.get("/")));
    InternalCommunicationConfig mockInternalCommunicationConfig = mock(InternalCommunicationConfig.class);
    HttpServerInfo mockHttpServerInfo = mock(HttpServerInfo.class);
    when(mockHttpServerInfo.getHttpsUri()).thenReturn(new URI("https://" + LOCALHOST + ":" + PORT1));
    when(mockInternalCommunicationConfig.isHttpsRequired()).thenReturn(true);
    EmbeddedStateStoreLauncher launcher = new EmbeddedStateStoreLauncher(mockSeedStoreManager, mockInternalCommunicationConfig, mockHttpServerInfo, new HetuConfig());
    StateStoreBootstrapper bootstrapper = new HazelcastStateStoreBootstrapper();
    launcher.addStateStoreBootstrapper(bootstrapper);
    launcher.launchStateStore();
    StateStore second = setupSecondInstance();
    // mock "remove" second instance from cluster (delete from seed store)
    seeds.remove(mockSeed2);
    when(mockSeed1.getLocation()).thenReturn(LOCALHOST + ":" + PORT1);
    when(mockSeedStoreManager.addSeed(SeedStoreSubType.HAZELCAST, LOCALHOST, true)).thenReturn(seeds);
    ((HazelcastStateStore) second).shutdown();
    // Allow the first node to handle failure
    Thread.sleep(3000L);
}
Also used : HazelcastStateStore(io.hetu.core.statestore.hazelcast.HazelcastStateStore) LocalConfig(io.hetu.core.filesystem.LocalConfig) StateStore(io.prestosql.spi.statestore.StateStore) HazelcastStateStore(io.hetu.core.statestore.hazelcast.HazelcastStateStore) Properties(java.util.Properties) HazelcastStateStoreBootstrapper(io.hetu.core.statestore.hazelcast.HazelcastStateStoreBootstrapper) URI(java.net.URI) HetuConfig(io.prestosql.utils.HetuConfig) SeedStoreManager(io.prestosql.seedstore.SeedStoreManager) InternalCommunicationConfig(io.prestosql.server.InternalCommunicationConfig) Seed(io.prestosql.spi.seedstore.Seed) SeedStore(io.prestosql.spi.seedstore.SeedStore) HetuLocalFileSystemClient(io.hetu.core.filesystem.HetuLocalFileSystemClient) HttpServerInfo(io.airlift.http.server.HttpServerInfo) HazelcastStateStoreBootstrapper(io.hetu.core.statestore.hazelcast.HazelcastStateStoreBootstrapper) StateStoreBootstrapper(io.prestosql.spi.statestore.StateStoreBootstrapper) HashSet(java.util.HashSet) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) AfterTest(org.testng.annotations.AfterTest)

Example 5 with InternalCommunicationConfig

use of io.prestosql.server.InternalCommunicationConfig in project hetu-core by openlookeng.

the class TestHttpRemoteTask method createHttpRemoteTaskFactory.

private static HttpRemoteTaskFactory createHttpRemoteTaskFactory(TestingTaskResource testingTaskResource) throws Exception {
    Bootstrap app = new Bootstrap(new JsonModule(), new SmileModule(), new HandleJsonModule(), new Module() {

        @Override
        public void configure(Binder binder) {
            binder.bind(JsonMapper.class);
            binder.bind(Metadata.class).toInstance(createTestMetadataManager());
            jsonBinder(binder).addDeserializerBinding(Type.class).to(TypeDeserializer.class);
            jsonCodecBinder(binder).bindJsonCodec(TaskStatus.class);
            jsonCodecBinder(binder).bindJsonCodec(TaskInfo.class);
            jsonCodecBinder(binder).bindJsonCodec(TaskUpdateRequest.class);
            smileCodecBinder(binder).bindSmileCodec(TaskStatus.class);
            smileCodecBinder(binder).bindSmileCodec(TaskInfo.class);
            smileCodecBinder(binder).bindSmileCodec(TaskUpdateRequest.class);
        }

        @Provides
        private HttpRemoteTaskFactory createHttpRemoteTaskFactory(JsonMapper jsonMapper, JsonCodec<TaskStatus> taskStatusJsonCodec, SmileCodec<TaskStatus> taskStatusSmileCodec, JsonCodec<TaskInfo> taskInfoJsonCodec, SmileCodec<TaskInfo> taskInfoSmileCodec, JsonCodec<TaskUpdateRequest> taskUpdateRequestJsonCodec, SmileCodec<TaskUpdateRequest> taskUpdateRequestSmileCodec) {
            JaxrsTestingHttpProcessor jaxrsTestingHttpProcessor = new JaxrsTestingHttpProcessor(URI.create("http://fake.invalid/"), testingTaskResource, jsonMapper);
            TestingHttpClient testingHttpClient = new TestingHttpClient(jaxrsTestingHttpProcessor.setTrace(TRACE_HTTP));
            testingTaskResource.setHttpClient(testingHttpClient);
            return new HttpRemoteTaskFactory(new QueryManagerConfig(), TASK_MANAGER_CONFIG, testingHttpClient, new TestSqlTaskManager.MockLocationFactory(), taskStatusJsonCodec, taskStatusSmileCodec, taskInfoJsonCodec, taskInfoSmileCodec, taskUpdateRequestJsonCodec, taskUpdateRequestSmileCodec, new RemoteTaskStats(), new InternalCommunicationConfig());
        }
    });
    Injector injector = app.strictConfig().doNotInitializeLogging().quiet().initialize();
    HandleResolver handleResolver = injector.getInstance(HandleResolver.class);
    handleResolver.addConnectorName("test", new TestingHandleResolver());
    return injector.getInstance(HttpRemoteTaskFactory.class);
}
Also used : TestingHandleResolver(io.prestosql.testing.TestingHandleResolver) HandleResolver(io.prestosql.metadata.HandleResolver) JsonMapper(io.airlift.jaxrs.JsonMapper) TaskInfo(io.prestosql.execution.TaskInfo) JsonBinder.jsonBinder(io.airlift.json.JsonBinder.jsonBinder) JsonCodecBinder.jsonCodecBinder(io.airlift.json.JsonCodecBinder.jsonCodecBinder) Binder(com.google.inject.Binder) SmileCodecBinder.smileCodecBinder(io.prestosql.protocol.SmileCodecBinder.smileCodecBinder) InternalCommunicationConfig(io.prestosql.server.InternalCommunicationConfig) JaxrsTestingHttpProcessor(io.airlift.jaxrs.testing.JaxrsTestingHttpProcessor) HandleJsonModule(io.prestosql.metadata.HandleJsonModule) Injector(com.google.inject.Injector) HttpRemoteTaskFactory(io.prestosql.server.HttpRemoteTaskFactory) TestingHttpClient(io.airlift.http.client.testing.TestingHttpClient) Bootstrap(io.airlift.bootstrap.Bootstrap) TypeDeserializer(io.prestosql.type.TypeDeserializer) TestingHandleResolver(io.prestosql.testing.TestingHandleResolver) TaskUpdateRequest(io.prestosql.server.TaskUpdateRequest) TaskStatus(io.prestosql.execution.TaskStatus) Provides(com.google.inject.Provides) JsonModule(io.airlift.json.JsonModule) HandleJsonModule(io.prestosql.metadata.HandleJsonModule) SmileModule(io.prestosql.protocol.SmileModule) QueryManagerConfig(io.prestosql.execution.QueryManagerConfig) Module(com.google.inject.Module) SmileModule(io.prestosql.protocol.SmileModule) JsonModule(io.airlift.json.JsonModule) HandleJsonModule(io.prestosql.metadata.HandleJsonModule)

Aggregations

InternalCommunicationConfig (io.prestosql.server.InternalCommunicationConfig)6 URI (java.net.URI)5 HetuConfig (io.prestosql.utils.HetuConfig)4 Test (org.testng.annotations.Test)4 TestingHttpClient (io.airlift.http.client.testing.TestingHttpClient)3 DataSize (io.airlift.units.DataSize)3 Binder (com.google.inject.Binder)2 Provides (com.google.inject.Provides)2 ServiceDescriptor (io.airlift.discovery.client.ServiceDescriptor)2 ServiceDescriptorsRepresentation (io.airlift.discovery.client.ServiceDescriptorsRepresentation)2 ServiceInventoryConfig (io.airlift.discovery.client.ServiceInventoryConfig)2 HttpServerInfo (io.airlift.http.server.HttpServerInfo)2 JsonCodecBinder.jsonCodecBinder (io.airlift.json.JsonCodecBinder.jsonCodecBinder)2 NodeConfig (io.airlift.node.NodeConfig)2 NodeInfo (io.airlift.node.NodeInfo)2 HazelcastStateStore (io.hetu.core.statestore.hazelcast.HazelcastStateStore)2 Injector (com.google.inject.Injector)1 Module (com.google.inject.Module)1 Provider (com.google.inject.Provider)1 Scopes (com.google.inject.Scopes)1