Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/ci-mapped.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2021 JanusGraph Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Publish package to GitHub Packages
on:
release:
types: [created]
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'adopt'

- name: Setup unique version
run: mvn versions:set -DnewVersion=$(date +%s) -DgenerateBackupPoms=false

- name: Compile and prepare release
run: mvn clean install -Pjanusgraph-release -Dgpg.skip=true -DskipTests=true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Deploy release
run: mvn deploy -Pjanusgraph-release -Dgpg.skip=true -DskipTests=true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.CqlSessionBuilder;
import com.datastax.oss.driver.api.core.config.DriverConfigLoader;
import com.datastax.oss.driver.internal.core.config.typesafe.DefaultDriverConfigLoader;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import com.typesafe.config.ConfigParseOptions;
import org.janusgraph.diskstorage.PermanentBackendException;
import org.janusgraph.diskstorage.configuration.Configuration;
import org.janusgraph.diskstorage.cql.CQLConfigOptions;
Expand All @@ -27,7 +31,8 @@
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
import java.util.Optional;
import java.util.function.Supplier;

public class CQLSessionBuilder {

Expand All @@ -49,50 +54,91 @@ public CqlSession build(Configuration configuration, String[] baseHostnames, int
contactPoints.add(contactPoint);
}

DriverConfigLoader driverConfigLoader;
if(configuration.get(CQLConfigOptions.BASE_PROGRAMMATIC_CONFIGURATION_ENABLED)){
driverConfigLoader = baseConfigurationLoaderBuilder.build(configuration, contactPoints, baseConnectionTimeoutMS);
} else {
driverConfigLoader = null;
}

Optional<Supplier<Config>> internalConfigurationSupplier = getInternalConfigSupplier(configuration, driverConfigLoader == null);
final CqlSessionBuilder builder = CqlSession.builder();

Stack<DriverConfigLoader> driverConfigLoadersToUse = new Stack<>();
if(internalConfigurationSupplier.isPresent()){
DriverConfigLoader internalDriverConfigLoader = new DefaultDriverConfigLoader(
internalConfigurationSupplier.get(), false);
if(driverConfigLoader == null){
driverConfigLoader = internalDriverConfigLoader;
} else {
driverConfigLoader = DriverConfigLoader.compose(internalDriverConfigLoader, driverConfigLoader);
}
}

if(configuration.get(CQLConfigOptions.BASE_PROGRAMMATIC_CONFIGURATION_ENABLED)){
driverConfigLoadersToUse.push(baseConfigurationLoaderBuilder.build(configuration, contactPoints, baseConnectionTimeoutMS));
if(driverConfigLoader != null){
builder.withConfigLoader(driverConfigLoader);
}

return builder.build();
}

private Optional<Supplier<Config>> getInternalConfigSupplier(Configuration configuration, boolean withFallbackDefaultConfiguration) throws PermanentBackendException {
boolean hasFileConfiguration = configuration.has(CQLConfigOptions.FILE_CONFIGURATION);
boolean hasResourceConfiguration = configuration.has(CQLConfigOptions.RESOURCE_CONFIGURATION);
boolean hasStringConfiguration = configuration.has(CQLConfigOptions.STRING_CONFIGURATION);
boolean hasUrlConfiguration = configuration.has(CQLConfigOptions.URL_CONFIGURATION);

boolean hasAnyInternalConfiguration = hasFileConfiguration
|| hasResourceConfiguration
|| hasStringConfiguration
|| hasUrlConfiguration;

if(!hasAnyInternalConfiguration){
return Optional.empty();
}

if(configuration.has(CQLConfigOptions.URL_CONFIGURATION)){
final URL url;
if(hasUrlConfiguration){
String stringUrlRepresentation = configuration.get(CQLConfigOptions.URL_CONFIGURATION);
URL url;
try {
url = new URL(stringUrlRepresentation);
} catch (MalformedURLException e) {
throw new PermanentBackendException("Malformed URL: "+stringUrlRepresentation, e);
}
driverConfigLoadersToUse.push(DriverConfigLoader.fromUrl(url));
} else {
url = null;
}

if(configuration.has(CQLConfigOptions.STRING_CONFIGURATION)){
String stringConfiguration = configuration.get(CQLConfigOptions.STRING_CONFIGURATION);
driverConfigLoadersToUse.push(DriverConfigLoader.fromString(stringConfiguration));
}
return Optional.of(() -> {
ConfigFactory.invalidateCaches();
Config config = ConfigFactory.defaultOverrides();
if(hasFileConfiguration){
String fileConfigurationPath = configuration.get(CQLConfigOptions.FILE_CONFIGURATION);
config = config.withFallback(ConfigFactory.parseFileAnySyntax(new File(fileConfigurationPath)));
}

if(configuration.has(CQLConfigOptions.RESOURCE_CONFIGURATION)){
String resourceConfigurationPath = configuration.get(CQLConfigOptions.RESOURCE_CONFIGURATION);
driverConfigLoadersToUse.push(DriverConfigLoader.fromClasspath(resourceConfigurationPath));
}
if(hasResourceConfiguration){
String resourceConfigurationPath = configuration.get(CQLConfigOptions.RESOURCE_CONFIGURATION);
config = config.withFallback(ConfigFactory.parseResourcesAnySyntax(resourceConfigurationPath,
ConfigParseOptions.defaults().setClassLoader(Thread.currentThread().getContextClassLoader())));
}

if(configuration.has(CQLConfigOptions.FILE_CONFIGURATION)){
String fileConfigurationPath = configuration.get(CQLConfigOptions.FILE_CONFIGURATION);
driverConfigLoadersToUse.push(DriverConfigLoader.fromFile(new File(fileConfigurationPath)));
}
if(hasStringConfiguration){
String stringConfiguration = configuration.get(CQLConfigOptions.STRING_CONFIGURATION);
config = config.withFallback(ConfigFactory.parseString(stringConfiguration));
}

if(!driverConfigLoadersToUse.empty()){
DriverConfigLoader composedDriverConfigLoader = driverConfigLoadersToUse.pop();
while (!driverConfigLoadersToUse.empty()){
composedDriverConfigLoader = DriverConfigLoader.compose(composedDriverConfigLoader, driverConfigLoadersToUse.pop());
if(hasUrlConfiguration){
config = config.withFallback(ConfigFactory.parseURL(url));
}
builder.withConfigLoader(composedDriverConfigLoader);
}

return builder.build();
if(withFallbackDefaultConfiguration){
config = config.withFallback(ConfigFactory.defaultReference(CqlSession.class.getClassLoader()));
}

config = config.resolve();

return config.getConfig(DefaultDriverConfigLoader.DEFAULT_ROOT_PATH);
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@

package org.janusgraph.diskstorage.cql;

import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.config.DefaultDriverOption;
import com.datastax.oss.driver.api.core.config.DriverConfigLoader;
import com.datastax.oss.driver.api.core.config.DriverExecutionProfile;
import com.datastax.oss.driver.internal.core.tracker.RequestLogger;
import org.apache.commons.io.FileUtils;
import org.apache.tinkerpop.gremlin.process.traversal.P;
Expand All @@ -23,13 +25,15 @@
import org.janusgraph.JanusGraphCassandraContainer;
import org.janusgraph.core.JanusGraphFactory;
import org.janusgraph.core.schema.JanusGraphManagement;
import org.janusgraph.diskstorage.PermanentBackendException;
import org.janusgraph.diskstorage.configuration.BasicConfiguration;
import org.janusgraph.diskstorage.configuration.ConfigElement;
import org.janusgraph.diskstorage.configuration.Configuration;
import org.janusgraph.diskstorage.configuration.ExecutorServiceBuilder;
import org.janusgraph.diskstorage.configuration.ModifiableConfiguration;
import org.janusgraph.diskstorage.configuration.WriteConfiguration;
import org.janusgraph.diskstorage.cql.builder.CQLProgrammaticConfigurationLoaderBuilder;
import org.janusgraph.diskstorage.cql.builder.CQLSessionBuilder;
import org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration;
import org.janusgraph.graphdb.configuration.JanusGraphConstants;
import org.janusgraph.graphdb.database.StandardJanusGraph;
Expand Down Expand Up @@ -126,6 +130,11 @@ public class CQLConfigTest {
"basic.contact-points = [ \"${hostname}:${port}\" ]\n" +
"}\n";

private static final String DATASTAX_JAVA_DRIVER_STRING_CONNECTION_TIMEOUT_ONLY_CONFIGURATION_PATTERN =
"datastax-java-driver {\n" +
"advanced.connection.connect-timeout = 54321 milliseconds\n" +
"}\n";

private StandardJanusGraph graph;

@Container
Expand Down Expand Up @@ -567,6 +576,33 @@ public void shouldTryToCreateCQLSessionWithDefaultDataStaxConfigurationOnlyButFa
assertThrows(RuntimeException.class, () -> JanusGraphFactory.open(wc));
}

@Test
public void fallbackConfigurationsShouldNotBeOverwrittenWithDefaultValues() throws PermanentBackendException {
Duration expectedCqlRequestTimeout = Duration.ofMillis(1234L);

WriteConfiguration writeConfiguration = getConfiguration();
writeConfiguration.set(ConfigElement.getPath(REQUEST_TIMEOUT), expectedCqlRequestTimeout.toMillis());
writeConfiguration.set(ConfigElement.getPath(STRING_CONFIGURATION),
DATASTAX_JAVA_DRIVER_STRING_CONNECTION_TIMEOUT_ONLY_CONFIGURATION_PATTERN);
String[] hostname = writeConfiguration.get(ConfigElement.getPath(STORAGE_HOSTS), String[].class);
Integer port = writeConfiguration.get(ConfigElement.getPath(STORAGE_PORT), Integer.class);
Duration timeout = writeConfiguration.get(ConfigElement.getPath(CONNECTION_TIMEOUT), Duration.class);
if(timeout == null){
timeout = CONNECTION_TIMEOUT.getDefaultValue();
}

Configuration config = new ModifiableConfiguration(ROOT_NS, writeConfiguration, BasicConfiguration.Restriction.NONE);
CQLProgrammaticConfigurationLoaderBuilder cqlProgrammaticConfigurationLoaderBuilder =
new CQLProgrammaticConfigurationLoaderBuilder();
CQLSessionBuilder builder = new CQLSessionBuilder();

CqlSession cqlSession = builder.build(config, hostname, port, timeout, cqlProgrammaticConfigurationLoaderBuilder);

DriverExecutionProfile defaultDriverExecutionProfile = cqlSession.getContext().getConfig().getDefaultProfile();
Duration requestTimeout = defaultDriverExecutionProfile.getDuration(DefaultDriverOption.REQUEST_TIMEOUT);
assertEquals(expectedCqlRequestTimeout, requestTimeout);
}

private static String prepareDataStaxConfiguration(WriteConfiguration wc){

String[] hostname = wc.get(ConfigElement.getPath(STORAGE_HOSTS), String[].class);
Expand Down
12 changes: 7 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@
</scm>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<id>github</id>
<name>GitHub Packages</name>
<url>https://maven.pkg.github.com/mapped/janusgraph</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
<id>github</id>
<name>GitHub Packages</name>
<url>https://maven.pkg.github.com/mapped/janusgraph</url>
</repository>
</distributionManagement>
<properties>
Expand Down Expand Up @@ -488,7 +490,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<version>0.8.8</version>
</plugin>
</plugins>
</pluginManagement>
Expand Down