Search in sources :

Example 16 with SeedStore

use of io.prestosql.spi.seedstore.SeedStore in project hetu-core by openlookeng.

the class TestHetuMetastoreGlobalCache method setUpHazelcast.

@BeforeTest
private void setUpHazelcast() throws IOException {
    Set<Seed> seeds = new HashSet<>();
    SeedStore mockSeedStore = mock(SeedStore.class);
    Seed mockSeed = mock(Seed.class);
    seeds.add(mockSeed);
    SeedStoreManager mockSeedStoreManager = mock(SeedStoreManager.class);
    when(mockSeedStoreManager.getSeedStore(any(SeedStoreSubType.class))).thenReturn(mockSeedStore);
    when(mockSeed.getLocation()).thenReturn(LOCALHOST + ":" + PORT3);
    when(mockSeedStore.get()).thenReturn(seeds);
    factory = new HazelcastStateStoreFactory();
    stateStoreProvider = new LocalStateStoreProvider(mockSeedStoreManager);
    stateStoreProvider.addStateStoreFactory(factory);
}
Also used : LocalStateStoreProvider(io.prestosql.statestore.LocalStateStoreProvider) SeedStoreManager(io.prestosql.seedstore.SeedStoreManager) Seed(io.prestosql.spi.seedstore.Seed) SeedStore(io.prestosql.spi.seedstore.SeedStore) HazelcastStateStoreFactory(io.hetu.core.statestore.hazelcast.HazelcastStateStoreFactory) HashSet(java.util.HashSet) SeedStoreSubType(io.prestosql.spi.seedstore.SeedStoreSubType) BeforeTest(org.testng.annotations.BeforeTest)

Example 17 with SeedStore

use of io.prestosql.spi.seedstore.SeedStore in project hetu-core by openlookeng.

the class HazelcastStateStoreFactory method create.

@Override
public StateStore create(String stateStoreName, SeedStore seedStore, Map<String, String> properties) {
    if (properties == null) {
        throw new IllegalArgumentException(format("found no state store config"));
    }
    this.name = stateStoreName;
    requireNonNull(properties, "properties is null");
    log.info("-- Starting new state store client --");
    String clusterId = properties.get(STATE_STORE_CLUSTER_CONFIG_NAME);
    if (clusterId == null) {
        log.info("cluster name not provided, using default cluster name: %s", DEFAULT_CLUSTER_ID);
        clusterId = DEFAULT_CLUSTER_ID;
    }
    ClientConfig clientConfig = new ClientConfig();
    // Add serialization for Slice
    SerializerConfig sc = new SerializerConfig().setImplementation(new HazelCastSliceSerializer()).setTypeClass(Slice.class);
    clientConfig.getSerializationConfig().addSerializerConfig(sc);
    SerializerConfig catalogEntity = new SerializerConfig().setImplementation(new HazelcastCatalogSerializer()).setTypeClass(CatalogEntity.class);
    clientConfig.getSerializationConfig().addSerializerConfig(catalogEntity);
    SerializerConfig dataEntity = new SerializerConfig().setImplementation(new HazelcastDatabaseEntitySerializer()).setTypeClass(DatabaseEntity.class);
    clientConfig.getSerializationConfig().addSerializerConfig(dataEntity);
    SerializerConfig tableEntity = new SerializerConfig().setImplementation(new HazelcastTableEntitySerializer()).setTypeClass(TableEntity.class);
    clientConfig.getSerializationConfig().addSerializerConfig(tableEntity);
    SerializerConfig op = new SerializerConfig().setImplementation(new HazelcastOptionalSerializer()).setTypeClass(Optional.class);
    clientConfig.getSerializationConfig().addSerializerConfig(op);
    clientConfig.setClusterName(clusterId);
    // set security config
    if (Boolean.parseBoolean(properties.get(KERBEROS_ENABLED))) {
        KerberosConfig.setKerberosEnabled(true);
        KerberosConfig.setLoginContextName(properties.get(KERBEROS_LOGIN_CONTEXT_NAME));
        KerberosConfig.setServicePrincipalName(properties.get(KERBEROS_SERVICE_PRINCIPAL));
        System.setProperty("java.security.krb5.conf", properties.get(KRB5_CONFIG_FILE));
        System.setProperty("java.security.auth.login.config", properties.get(JAAS_CONFIG_FILE));
    }
    // Set hazelcast SSL config
    if (Boolean.parseBoolean(properties.get(HAZELCAST_SSL_ENABLED))) {
        SslConfig.setSslEnabled(true);
        SslConfig.setKeyStorePath(properties.get(SSL_KEYSTORE_PATH));
        SslConfig.setKeyStorePassword(properties.get(SSL_KEYSTORE_PASSWORD));
        SslConfig.setTrustStorePath(properties.get(SSL_TRUSTSTORE_PATH));
        SslConfig.setTrustStorePassword(properties.get(SSL_TRUSTSTORE_PASSWORD));
        SslConfig.setCipherSuites(properties.get(SSL_CIPHER_SUITES));
        SslConfig.setProtocols(properties.get(SSL_PROTOCOLS));
    }
    // Set heartbeat config
    final String heartbeatInterval = properties.get(HEARTBEAT_INTERVAL_SECONDS);
    final String heartbeatTimeout = properties.get(HEARTBEAT_TIMEOUT_SECONDS);
    if (heartbeatInterval != null) {
        clientConfig.setProperty(CLIENT_HEARTBEAT_INTERVAL, String.valueOf(Integer.parseInt(heartbeatInterval) * 1000));
    }
    if (heartbeatTimeout != null) {
        clientConfig.setProperty(CLIENT_HEARTBEAT_TIMEOUT, String.valueOf(Integer.parseInt(heartbeatTimeout) * 1000));
    }
    final String discoveryMode = properties.get(DISCOVERY_MODE_CONFIG_NAME);
    if (discoveryMode == null || discoveryMode.equalsIgnoreCase(DISCOVERY_MODE_MULTICAST)) {
        log.info("Using Multicast discovery for Hazelcast");
        clientConfig.setProperty(DISCOVERY_ENABLED, "true");
        DiscoveryStrategyConfig strategy = new DiscoveryStrategyConfig(DISCOVERY_MULTICAST_STRATEGY_CLASS_NAME);
        clientConfig.getNetworkConfig().getDiscoveryConfig().addDiscoveryStrategyConfig(strategy);
    } else if (discoveryMode.equalsIgnoreCase(DISCOVERY_MODE_TCPIP)) {
        String tcpipSeeds = properties.get(DISCOVERY_TCPIP_SEEDS);
        Collection<String> seedLocation = new HashSet<>();
        if (tcpipSeeds != null && !tcpipSeeds.trim().isEmpty()) {
            for (String seed : tcpipSeeds.split(COMMA)) {
                seedLocation.add(seed);
            }
        } else {
            seedStore.setName(clusterId);
            seedLocation = getSeedLocation(seedStore);
        }
        log.info("Using TCP-IP discovery for Hazelcast, seed nodes are: %s", String.join(",", seedLocation));
        seedLocation.stream().forEach(ip -> {
            clientConfig.getNetworkConfig().addAddress(ip);
        });
    } else {
        throw new PrestoException(CONFIGURATION_INVALID, "Discovery mode not supported: " + discoveryMode);
    }
    HazelcastInstance hzClient = HazelcastClient.newHazelcastClient(clientConfig);
    CipherService.Type encryptionType = getEncryptionTypeFromConfig(properties);
    return new HazelcastStateStore(hzClient, stateStoreName, encryptionType);
}
Also used : SSL_KEYSTORE_PASSWORD(io.hetu.core.statestore.hazelcast.HazelcastConstants.SSL_KEYSTORE_PASSWORD) StateStore(io.prestosql.spi.statestore.StateStore) CONFIGURATION_INVALID(io.prestosql.spi.StandardErrorCode.CONFIGURATION_INVALID) DISCOVERY_MULTICAST_STRATEGY_CLASS_NAME(io.hetu.core.statestore.hazelcast.HazelcastConstants.DISCOVERY_MULTICAST_STRATEGY_CLASS_NAME) Map(java.util.Map) KRB5_CONFIG_FILE(io.hetu.core.statestore.hazelcast.HazelcastConstants.KRB5_CONFIG_FILE) SSL_PROTOCOLS(io.hetu.core.statestore.hazelcast.HazelcastConstants.SSL_PROTOCOLS) SSL_TRUSTSTORE_PASSWORD(io.hetu.core.statestore.hazelcast.HazelcastConstants.SSL_TRUSTSTORE_PASSWORD) DatabaseEntity(io.prestosql.spi.metastore.model.DatabaseEntity) DISCOVERY_MODE_MULTICAST(io.hetu.core.statestore.hazelcast.HazelcastConstants.DISCOVERY_MODE_MULTICAST) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) KERBEROS_ENABLED(io.hetu.core.statestore.hazelcast.HazelcastConstants.KERBEROS_ENABLED) PrestoException(io.prestosql.spi.PrestoException) SeedStore(io.prestosql.spi.seedstore.SeedStore) DISCOVERY_MODE_CONFIG_NAME(io.hetu.core.statestore.hazelcast.HazelcastConstants.DISCOVERY_MODE_CONFIG_NAME) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) JAAS_CONFIG_FILE(io.hetu.core.statestore.hazelcast.HazelcastConstants.JAAS_CONFIG_FILE) Optional(java.util.Optional) SslConfig(io.hetu.core.security.networking.ssl.SslConfig) CatalogEntity(io.prestosql.spi.metastore.model.CatalogEntity) STATE_STORE_FAILURE(io.prestosql.spi.StandardErrorCode.STATE_STORE_FAILURE) Slice(io.airlift.slice.Slice) Logger(io.airlift.log.Logger) HazelcastClient(com.hazelcast.client.HazelcastClient) STATE_STORE_CLUSTER_CONFIG_NAME(io.hetu.core.statestore.Constants.STATE_STORE_CLUSTER_CONFIG_NAME) HAZELCAST_SSL_ENABLED(io.hetu.core.statestore.hazelcast.HazelcastConstants.HAZELCAST_SSL_ENABLED) KerberosConfig(io.hetu.core.security.authentication.kerberos.KerberosConfig) SSL_KEYSTORE_PATH(io.hetu.core.statestore.hazelcast.HazelcastConstants.SSL_KEYSTORE_PATH) HashSet(java.util.HashSet) StateStoreUtils.getEncryptionTypeFromConfig(io.hetu.core.statestore.StateStoreUtils.getEncryptionTypeFromConfig) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) DISCOVERY_TCPIP_SEEDS(io.hetu.core.statestore.hazelcast.HazelcastConstants.DISCOVERY_TCPIP_SEEDS) Objects.requireNonNull(java.util.Objects.requireNonNull) SSL_TRUSTSTORE_PATH(io.hetu.core.statestore.hazelcast.HazelcastConstants.SSL_TRUSTSTORE_PATH) ClientConfig(com.hazelcast.client.config.ClientConfig) SerializerConfig(com.hazelcast.config.SerializerConfig) DISCOVERY_ENABLED(io.hetu.core.statestore.hazelcast.HazelcastConstants.DISCOVERY_ENABLED) DEFAULT_CLUSTER_ID(io.hetu.core.statestore.hazelcast.HazelcastConstants.DEFAULT_CLUSTER_ID) DISCOVERY_MODE_TCPIP(io.hetu.core.statestore.hazelcast.HazelcastConstants.DISCOVERY_MODE_TCPIP) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CipherService(io.prestosql.spi.statestore.CipherService) KERBEROS_SERVICE_PRINCIPAL(io.hetu.core.statestore.hazelcast.HazelcastConstants.KERBEROS_SERVICE_PRINCIPAL) Seed(io.prestosql.spi.seedstore.Seed) KERBEROS_LOGIN_CONTEXT_NAME(io.hetu.core.statestore.hazelcast.HazelcastConstants.KERBEROS_LOGIN_CONTEXT_NAME) IOException(java.io.IOException) ThreadContextClassLoader(io.prestosql.spi.classloader.ThreadContextClassLoader) HEARTBEAT_INTERVAL_SECONDS(io.hetu.core.statestore.hazelcast.HazelcastConstants.HEARTBEAT_INTERVAL_SECONDS) TimeUnit(java.util.concurrent.TimeUnit) TableEntity(io.prestosql.spi.metastore.model.TableEntity) StateStoreFactory(io.prestosql.spi.statestore.StateStoreFactory) HEARTBEAT_TIMEOUT_SECONDS(io.hetu.core.statestore.hazelcast.HazelcastConstants.HEARTBEAT_TIMEOUT_SECONDS) SSL_CIPHER_SUITES(io.hetu.core.statestore.hazelcast.HazelcastConstants.SSL_CIPHER_SUITES) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) CipherService(io.prestosql.spi.statestore.CipherService) PrestoException(io.prestosql.spi.PrestoException) SerializerConfig(com.hazelcast.config.SerializerConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Collection(java.util.Collection) ClientConfig(com.hazelcast.client.config.ClientConfig)

Example 18 with SeedStore

use of io.prestosql.spi.seedstore.SeedStore in project hetu-core by openlookeng.

the class DistributedQueryRunnerWithStateStore method setupStateStore.

public void setupStateStore() throws Exception {
    int port = SslSocketUtil.getAvailablePort();
    for (TestingPrestoServer server : servers) {
        server.installPlugin(new StateStoreManagerPlugin());
        // State Store
        StateStoreLauncher launcher = server.getInstance(Key.get(StateStoreLauncher.class));
        if (launcher instanceof EmbeddedStateStoreLauncher) {
            Set<String> ips = Sets.newHashSet(Arrays.asList("127.0.0.1"));
            Map<String, String> stateStoreProperties = new HashMap<>();
            stateStoreProperties.put(DISCOVERY_PORT_CONFIG_NAME, port + "");
            stateStoreProperties.putIfAbsent(HazelcastConstants.DISCOVERY_MODE_CONFIG_NAME, HazelcastConstants.DISCOVERY_MODE_TCPIP);
            this.stateStores.add(((EmbeddedStateStoreLauncher) launcher).launchStateStore(ips, stateStoreProperties));
        }
        launcher.launchStateStore();
        StateStoreProvider provider = server.getInstance(Key.get(StateStoreProvider.class));
        Seed seed = new FileBasedSeed("127.0.0.1:" + port, 0);
        SeedStore seedStore = new SeedStore() {

            @Override
            public Collection<Seed> add(Collection<Seed> seeds) throws IOException {
                return null;
            }

            @Override
            public Collection<Seed> get() throws IOException {
                return new ArrayList<>((Arrays.asList(seed)));
            }

            @Override
            public Collection<Seed> remove(Collection<Seed> seeds) throws IOException {
                return null;
            }

            @Override
            public Seed create(Map<String, String> properties) {
                return null;
            }

            @Override
            public String getName() {
                return null;
            }

            @Override
            public void setName(String name) {
            }
        };
        server.getInstance(Key.get(SeedStoreManager.class)).setSeedStore(SeedStoreSubType.HAZELCAST, seedStore);
        if (provider instanceof LocalStateStoreProvider) {
            Map<String, String> stateStoreProperties = new HashMap<>();
            stateStoreProperties.putIfAbsent(HazelcastConstants.DISCOVERY_MODE_CONFIG_NAME, HazelcastConstants.DISCOVERY_MODE_TCPIP);
            stateStoreProperties.put(DISCOVERY_PORT_CONFIG_NAME, port + "");
            ((LocalStateStoreProvider) provider).setStateStore("hazelcast", stateStoreProperties);
            ((LocalStateStoreProvider) provider).createStateCollections();
        }
        provider.loadStateStore();
        this.providers.add(provider);
    }
}
Also used : EmbeddedStateStoreLauncher(io.prestosql.statestore.EmbeddedStateStoreLauncher) FileBasedSeed(io.hetu.core.seedstore.filebased.FileBasedSeed) HashMap(java.util.HashMap) TestingPrestoServer(io.prestosql.server.testing.TestingPrestoServer) ArrayList(java.util.ArrayList) LocalStateStoreProvider(io.prestosql.statestore.LocalStateStoreProvider) StateStoreProvider(io.prestosql.statestore.StateStoreProvider) LocalStateStoreProvider(io.prestosql.statestore.LocalStateStoreProvider) FileBasedSeed(io.hetu.core.seedstore.filebased.FileBasedSeed) Seed(io.prestosql.spi.seedstore.Seed) StateStoreLauncher(io.prestosql.statestore.StateStoreLauncher) EmbeddedStateStoreLauncher(io.prestosql.statestore.EmbeddedStateStoreLauncher) SeedStore(io.prestosql.spi.seedstore.SeedStore) Collection(java.util.Collection) StateStoreManagerPlugin(io.hetu.core.statestore.StateStoreManagerPlugin) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

SeedStore (io.prestosql.spi.seedstore.SeedStore)18 Seed (io.prestosql.spi.seedstore.Seed)15 PrestoException (io.prestosql.spi.PrestoException)9 HashSet (java.util.HashSet)9 HashMap (java.util.HashMap)7 Map (java.util.Map)6 BeforeTest (org.testng.annotations.BeforeTest)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 SeedStoreManager (io.prestosql.seedstore.SeedStoreManager)4 SeedStoreFactory (io.prestosql.spi.seedstore.SeedStoreFactory)4 SeedStoreSubType (io.prestosql.spi.seedstore.SeedStoreSubType)4 IOException (java.io.IOException)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 Logger (io.airlift.log.Logger)3 ThreadContextClassLoader (io.prestosql.spi.classloader.ThreadContextClassLoader)3 StateStore (io.prestosql.spi.statestore.StateStore)3 LocalStateStoreProvider (io.prestosql.statestore.LocalStateStoreProvider)3 String.format (java.lang.String.format)3 Collection (java.util.Collection)3 Test (org.testng.annotations.Test)3