use of org.apache.druid.metadata.MetadataStorageConnectorConfig in project hive by apache.
the class DruidStorageHandler method buildConnector.
private SQLMetadataConnector buildConnector() {
if (connector != null) {
return connector;
}
final String dbType = HiveConf.getVar(getConf(), HiveConf.ConfVars.DRUID_METADATA_DB_TYPE);
final String username = HiveConf.getVar(getConf(), HiveConf.ConfVars.DRUID_METADATA_DB_USERNAME);
final String password = getPassword(getConf(), HiveConf.ConfVars.DRUID_METADATA_DB_PASSWORD);
final String uri = HiveConf.getVar(getConf(), HiveConf.ConfVars.DRUID_METADATA_DB_URI);
LOG.debug("Supplying SQL Connector with DB type {}, URI {}, User {}", dbType, uri, username);
@SuppressWarnings("Guava") final Supplier<MetadataStorageConnectorConfig> storageConnectorConfigSupplier = Suppliers.ofInstance(new MetadataStorageConnectorConfig() {
@Override
public String getConnectURI() {
return uri;
}
@Override
public String getUser() {
return Strings.emptyToNull(username);
}
@Override
public String getPassword() {
return Strings.emptyToNull(password);
}
});
switch(dbType) {
case "mysql":
connector = new MySQLConnector(storageConnectorConfigSupplier, Suppliers.ofInstance(getDruidMetadataStorageTablesConfig()), new MySQLConnectorConfig());
break;
case "postgresql":
connector = new PostgreSQLConnector(storageConnectorConfigSupplier, Suppliers.ofInstance(getDruidMetadataStorageTablesConfig()), new PostgreSQLConnectorConfig(), new PostgreSQLTablesConfig());
break;
case "derby":
connector = new DerbyConnector(new DerbyMetadataStorage(storageConnectorConfigSupplier.get()), storageConnectorConfigSupplier, Suppliers.ofInstance(getDruidMetadataStorageTablesConfig()));
break;
default:
throw new IllegalStateException(String.format("Unknown metadata storage type [%s]", dbType));
}
return connector;
}
use of org.apache.druid.metadata.MetadataStorageConnectorConfig in project druid by druid-io.
the class PostgresqlFirehoseDatabaseConnectorTest method testFailWhenNoAllowlistAndHaveProperty.
@Test
public void testFailWhenNoAllowlistAndHaveProperty() {
MetadataStorageConnectorConfig connectorConfig = new MetadataStorageConnectorConfig() {
@Override
public String getConnectURI() {
return "jdbc:postgresql://localhost:3306/test?user=maytas&password=secret&keyonly";
}
};
JdbcAccessSecurityConfig securityConfig = newSecurityConfigEnforcingAllowList(ImmutableSet.of(""));
expectedException.expectMessage("is not in the allowed list");
expectedException.expect(IllegalArgumentException.class);
new PostgresqlFirehoseDatabaseConnector(connectorConfig, securityConfig);
}
use of org.apache.druid.metadata.MetadataStorageConnectorConfig in project druid by druid-io.
the class PostgresqlFirehoseDatabaseConnectorTest method testSerde.
@Test
public void testSerde() throws JsonProcessingException {
MetadataStorageConnectorConfig connectorConfig = new MetadataStorageConnectorConfig() {
@Override
public String getConnectURI() {
return "jdbc:postgresql://localhost:3306/test";
}
};
PostgresqlFirehoseDatabaseConnector connector = new PostgresqlFirehoseDatabaseConnector(connectorConfig, INJECTED_CONF);
PostgresqlFirehoseDatabaseConnector andBack = MAPPER.readValue(MAPPER.writeValueAsString(connector), PostgresqlFirehoseDatabaseConnector.class);
Assert.assertEquals(connector, andBack);
}
use of org.apache.druid.metadata.MetadataStorageConnectorConfig in project druid by druid-io.
the class PostgresqlFirehoseDatabaseConnectorTest method testSuccessOnlyValidProperty.
@Test
public void testSuccessOnlyValidProperty() {
MetadataStorageConnectorConfig connectorConfig = new MetadataStorageConnectorConfig() {
@Override
public String getConnectURI() {
return "jdbc:postgresql://localhost:3306/test?user=maytas&password=secret&keyonly";
}
};
JdbcAccessSecurityConfig securityConfig = newSecurityConfigEnforcingAllowList(ImmutableSet.of("user", "password", "keyonly", "etc"));
new PostgresqlFirehoseDatabaseConnector(connectorConfig, securityConfig);
}
use of org.apache.druid.metadata.MetadataStorageConnectorConfig in project druid by druid-io.
the class PostgresqlFirehoseDatabaseConnectorTest method testFailOnlyInvalidProperty.
@Test
public void testFailOnlyInvalidProperty() {
MetadataStorageConnectorConfig connectorConfig = new MetadataStorageConnectorConfig() {
@Override
public String getConnectURI() {
return "jdbc:postgresql://localhost:3306/test?user=maytas&password=secret&keyonly";
}
};
JdbcAccessSecurityConfig securityConfig = newSecurityConfigEnforcingAllowList(ImmutableSet.of("none", "nonenone"));
expectedException.expectMessage("is not in the allowed list");
expectedException.expect(IllegalArgumentException.class);
new PostgresqlFirehoseDatabaseConnector(connectorConfig, securityConfig);
}
Aggregations