use of org.janusgraph.diskstorage.configuration.Configuration in project janusgraph by JanusGraph.
the class ExpectedValueCheckingStoreManager method beginTransaction.
@Override
public ExpectedValueCheckingTransaction beginTransaction(BaseTransactionConfig configuration) throws BackendException {
// Get a transaction without any guarantees about strong consistency
StoreTransaction inconsistentTx = manager.beginTransaction(configuration);
// Get a transaction that provides global strong consistency
Configuration customOptions = new MergedConfiguration(storeFeatures.getKeyConsistentTxConfig(), configuration.getCustomOptions());
BaseTransactionConfig consistentTxCfg = new StandardBaseTransactionConfig.Builder(configuration).customOptions(customOptions).build();
StoreTransaction strongConsistentTx = manager.beginTransaction(consistentTxCfg);
// Return a wrapper around both the inconsistent and consistent store transactions
return new ExpectedValueCheckingTransaction(inconsistentTx, strongConsistentTx, maxReadTime);
}
use of org.janusgraph.diskstorage.configuration.Configuration in project janusgraph by JanusGraph.
the class AbstractCassandraStoreManager method getFeatures.
@Override
public StoreFeatures getFeatures() {
if (features == null) {
Configuration global = GraphDatabaseConfiguration.buildGraphConfiguration().set(CASSANDRA_READ_CONSISTENCY, "QUORUM").set(CASSANDRA_WRITE_CONSISTENCY, "QUORUM").set(METRICS_PREFIX, GraphDatabaseConfiguration.METRICS_SYSTEM_PREFIX_DEFAULT);
Configuration local = GraphDatabaseConfiguration.buildGraphConfiguration().set(CASSANDRA_READ_CONSISTENCY, "LOCAL_QUORUM").set(CASSANDRA_WRITE_CONSISTENCY, "LOCAL_QUORUM").set(METRICS_PREFIX, GraphDatabaseConfiguration.METRICS_SYSTEM_PREFIX_DEFAULT);
StandardStoreFeatures.Builder fb = new StandardStoreFeatures.Builder();
fb.batchMutation(true).distributed(true);
fb.timestamps(true).cellTTL(true);
fb.keyConsistent(global, local);
fb.optimisticLocking(true);
boolean keyOrdered;
switch(getPartitioner()) {
case RANDOM:
keyOrdered = false;
fb.keyOrdered(keyOrdered).orderedScan(false).unorderedScan(true);
break;
case BYTEORDER:
keyOrdered = true;
fb.keyOrdered(keyOrdered).orderedScan(true).unorderedScan(false);
break;
default:
throw new IllegalArgumentException("Unrecognized partitioner: " + getPartitioner());
}
switch(getDeployment()) {
case REMOTE:
fb.multiQuery(true);
break;
case LOCAL:
fb.multiQuery(true).localKeyPartition(keyOrdered);
break;
case EMBEDDED:
fb.multiQuery(false).localKeyPartition(keyOrdered);
break;
default:
throw new IllegalArgumentException("Unrecognized deployment mode: " + getDeployment());
}
features = fb.build();
}
return features;
}
use of org.janusgraph.diskstorage.configuration.Configuration in project janusgraph by JanusGraph.
the class BerkeleyJEStoreManager method beginTransaction.
@Override
public BerkeleyJETx beginTransaction(final BaseTransactionConfig txCfg) throws BackendException {
try {
Transaction tx = null;
Configuration effectiveCfg = new MergedConfiguration(txCfg.getCustomOptions(), getStorageConfig());
if (transactional) {
TransactionConfig txnConfig = new TransactionConfig();
ConfigOption.getEnumValue(effectiveCfg.get(ISOLATION_LEVEL), IsolationLevel.class).configure(txnConfig);
tx = environment.beginTransaction(null, txnConfig);
}
BerkeleyJETx btx = new BerkeleyJETx(tx, ConfigOption.getEnumValue(effectiveCfg.get(LOCK_MODE), LockMode.class), txCfg);
if (log.isTraceEnabled()) {
log.trace("Berkeley tx created", new TransactionBegin(btx.toString()));
}
return btx;
} catch (DatabaseException e) {
throw new PermanentBackendException("Could not start BerkeleyJE transaction", e);
}
}
use of org.janusgraph.diskstorage.configuration.Configuration in project janusgraph by JanusGraph.
the class CQLStoreManager method initializeCluster.
Cluster initializeCluster() throws PermanentBackendException {
final Configuration configuration = getStorageConfig();
final List<InetSocketAddress> contactPoints;
try {
contactPoints = Array.of(this.hostnames).map(hostName -> hostName.split(":")).map(array -> Tuple.of(array[0], array.length == 2 ? Integer.parseInt(array[1]) : this.port)).map(tuple -> new InetSocketAddress(tuple._1, tuple._2)).toJavaList();
} catch (SecurityException | ArrayIndexOutOfBoundsException | NumberFormatException e) {
throw new PermanentBackendException("Error initialising cluster contact points", e);
}
final Builder builder = Cluster.builder().addContactPointsWithPorts(contactPoints).withClusterName(configuration.get(CLUSTER_NAME));
if (configuration.get(PROTOCOL_VERSION) != 0) {
builder.withProtocolVersion(ProtocolVersion.fromInt(configuration.get(PROTOCOL_VERSION)));
}
if (configuration.has(AUTH_USERNAME) && configuration.has(AUTH_PASSWORD)) {
builder.withCredentials(configuration.get(AUTH_USERNAME), configuration.get(AUTH_PASSWORD));
}
if (configuration.has(LOCAL_DATACENTER)) {
builder.withLoadBalancingPolicy(new TokenAwarePolicy(DCAwareRoundRobinPolicy.builder().withLocalDc(configuration.get(LOCAL_DATACENTER)).build()));
}
if (configuration.get(SSL_ENABLED)) {
try {
final TrustManager[] trustManagers;
try (final FileInputStream keyStoreStream = new FileInputStream(configuration.get(SSL_TRUSTSTORE_LOCATION))) {
final KeyStore keystore = KeyStore.getInstance("jks");
keystore.load(keyStoreStream, configuration.get(SSL_TRUSTSTORE_PASSWORD).toCharArray());
final TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keystore);
trustManagers = trustManagerFactory.getTrustManagers();
}
final SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustManagers, null);
final JdkSSLOptions sslOptions = JdkSSLOptions.builder().withSSLContext(sslContext).build();
builder.withSSL(sslOptions);
} catch (NoSuchAlgorithmException | CertificateException | IOException | KeyStoreException | KeyManagementException e) {
throw new PermanentBackendException("Error initialising SSL connection properties", e);
}
}
// Build the PoolingOptions based on the configurations
PoolingOptions poolingOptions = new PoolingOptions();
poolingOptions.setMaxRequestsPerConnection(HostDistance.LOCAL, configuration.get(LOCAL_MAX_REQUESTS_PER_CONNECTION)).setMaxRequestsPerConnection(HostDistance.REMOTE, configuration.get(REMOTE_MAX_REQUESTS_PER_CONNECTION));
poolingOptions.setConnectionsPerHost(HostDistance.LOCAL, configuration.get(LOCAL_CORE_CONNECTIONS_PER_HOST), configuration.get(LOCAL_MAX_CONNECTIONS_PER_HOST)).setConnectionsPerHost(HostDistance.REMOTE, configuration.get(REMOTE_CORE_CONNECTIONS_PER_HOST), configuration.get(REMOTE_MAX_CONNECTIONS_PER_HOST));
return builder.withPoolingOptions(poolingOptions).build();
}
use of org.janusgraph.diskstorage.configuration.Configuration in project janusgraph by JanusGraph.
the class RestClientSetup method getHttpClientConfigCallback.
/**
* <p>
* Returns the callback for customizing {@link CloseableHttpAsyncClient} or null if no
* customization is needed.
* </p>
* <p>
* See {@link RestClientBuilder#setHttpClientConfigCallback(HttpClientConfigCallback) for more details.
* </p>
*
* @param config
* ES index configuration
* @return callback or null if the client customization is not needed
*/
protected HttpClientConfigCallback getHttpClientConfigCallback(Configuration config) {
final List<HttpClientConfigCallback> callbackList = new LinkedList<>();
final HttpAuthTypes authType = ConfigOption.getEnumValue(config.get(ElasticSearchIndex.ES_HTTP_AUTH_TYPE), HttpAuthTypes.class);
log.debug("Configuring HTTP(S) authentication type {}", authType);
switch(authType) {
case BASIC:
callbackList.add(new BasicAuthHttpClientConfigCallback(config.has(ElasticSearchIndex.ES_HTTP_AUTH_REALM) ? config.get(ElasticSearchIndex.ES_HTTP_AUTH_REALM) : "", config.get(ElasticSearchIndex.ES_HTTP_AUTH_USERNAME), config.get(ElasticSearchIndex.ES_HTTP_AUTH_PASSWORD)));
break;
case CUSTOM:
callbackList.add(getCustomAuthenticator(config.get(ElasticSearchIndex.ES_HTTP_AUTHENTICATOR_CLASS), config.get(ElasticSearchIndex.ES_HTTP_AUTHENTICATOR_ARGS)));
break;
case NONE:
break;
default:
// not expected
throw new IllegalArgumentException("Authentication type \"" + authType + "\" is not implemented");
}
if (config.get(ElasticSearchIndex.SSL_ENABLED)) {
// Custom SSL configuration
final Builder sslConfCBBuilder = getSSLConfigurationCallbackBuilder();
boolean configureSSL = false;
if (config.has(ElasticSearchIndex.SSL_TRUSTSTORE_LOCATION)) {
sslConfCBBuilder.withTrustStore(config.get(ElasticSearchIndex.SSL_TRUSTSTORE_LOCATION), config.get(ElasticSearchIndex.SSL_TRUSTSTORE_PASSWORD));
configureSSL = true;
}
if (config.has(ElasticSearchIndex.SSL_KEYSTORE_LOCATION)) {
final String keystorePassword = config.get(ElasticSearchIndex.SSL_KEYSTORE_PASSWORD);
sslConfCBBuilder.withKeyStore(config.get(ElasticSearchIndex.SSL_KEYSTORE_LOCATION), keystorePassword, config.has(ElasticSearchIndex.SSL_KEY_PASSWORD) ? config.get(ElasticSearchIndex.SSL_KEY_PASSWORD) : keystorePassword);
configureSSL = true;
}
if (config.has(ElasticSearchIndex.SSL_DISABLE_HOSTNAME_VERIFICATION) && config.get(ElasticSearchIndex.SSL_DISABLE_HOSTNAME_VERIFICATION)) {
log.warn("SSL hostname verification is disabled, Elasticsearch HTTPS connections may not be secure");
sslConfCBBuilder.disableHostNameVerification();
configureSSL = true;
}
if (config.has(ElasticSearchIndex.SSL_ALLOW_SELF_SIGNED_CERTIFICATES) && config.get(ElasticSearchIndex.SSL_ALLOW_SELF_SIGNED_CERTIFICATES)) {
log.warn("Self-signed SSL certificate support is enabled, Elasticsearch HTTPS connections may not be secure");
sslConfCBBuilder.allowSelfSignedCertificates();
configureSSL = true;
}
if (configureSSL) {
callbackList.add(sslConfCBBuilder.build());
}
}
if (callbackList.isEmpty()) {
return null;
}
// will execute the chain of individual callbacks
return httpClientBuilder -> {
for (HttpClientConfigCallback cb : callbackList) {
cb.customizeHttpClient(httpClientBuilder);
}
return httpClientBuilder;
};
}
Aggregations