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);
}
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);
}
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);
}
}
Aggregations