Changing cassandra version and using datastax driver

This commit is contained in:
Martin Stockhammer 2021-08-28 20:43:10 +02:00
parent 3e959d5b07
commit d925697678
14 changed files with 1944 additions and 2322 deletions

View File

@ -19,7 +19,6 @@ package org.apache.archiva.metadata.repository;
* under the License. * under the License.
*/ */
import junit.framework.TestCase;
import org.apache.archiva.checksum.ChecksumAlgorithm; import org.apache.archiva.checksum.ChecksumAlgorithm;
import org.apache.archiva.metadata.QueryParameter; import org.apache.archiva.metadata.QueryParameter;
import org.apache.archiva.metadata.generic.GenericMetadataFacet; import org.apache.archiva.metadata.generic.GenericMetadataFacet;
@ -37,12 +36,13 @@ import org.apache.archiva.metadata.model.ProjectMetadata;
import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.model.ProjectVersionReference; import org.apache.archiva.metadata.model.ProjectVersionReference;
import org.apache.archiva.metadata.model.Scm; import org.apache.archiva.metadata.model.Scm;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtendWith;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.ZoneId; import java.time.ZoneId;
@ -62,11 +62,12 @@ import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
@RunWith( SpringJUnit4ClassRunner.class ) @ExtendWith( SpringExtension.class )
@TestInstance( TestInstance.Lifecycle.PER_CLASS )
@ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml"} ) @ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml"} )
public abstract class AbstractMetadataRepositoryTest public abstract class AbstractMetadataRepositoryTest
extends TestCase
{ {
protected static final String OTHER_REPO_ID = "other-repo"; protected static final String OTHER_REPO_ID = "other-repo";
@ -108,6 +109,14 @@ public abstract class AbstractMetadataRepositoryTest
protected int assertMaxTries =10; protected int assertMaxTries =10;
protected int assertRetrySleepMs=500; protected int assertRetrySleepMs=500;
protected void setUp() throws Exception {
}
protected void tearDown() throws Exception {
}
/* /*
* Used by tryAssert to allow to throw exceptions in the lambda expression. * Used by tryAssert to allow to throw exceptions in the lambda expression.
*/ */
@ -452,19 +461,23 @@ public abstract class AbstractMetadataRepositoryTest
getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata ); getRepository( ).updateProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
metadata = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ); metadata = getRepository( ).getProjectVersion( session, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
assertNotNull( metadata );
assertEquals( TEST_PROJECT_VERSION, metadata.getId( ) ); assertEquals( TEST_PROJECT_VERSION, metadata.getId( ) );
assertEquals( TEST_PROJECT_VERSION, metadata.getVersion( ) ); assertEquals( TEST_PROJECT_VERSION, metadata.getVersion( ) );
assertEquals( "project name", metadata.getName( ) ); assertEquals( "project name", metadata.getName( ) );
assertEquals( "project description", metadata.getDescription( ) ); assertEquals( "project description", metadata.getDescription( ) );
assertEquals( "the url", metadata.getUrl( ) ); assertEquals( "the url", metadata.getUrl( ) );
assertNotNull( metadata.getScm( ) );
assertEquals( "connection", metadata.getScm( ).getConnection( ) ); assertEquals( "connection", metadata.getScm( ).getConnection( ) );
assertEquals( "dev conn", metadata.getScm( ).getDeveloperConnection( ) ); assertEquals( "dev conn", metadata.getScm( ).getDeveloperConnection( ) );
assertEquals( "url", metadata.getScm( ).getUrl( ) ); assertEquals( "url", metadata.getScm( ).getUrl( ) );
assertNotNull( metadata.getCiManagement( ) );
assertEquals( "system", metadata.getCiManagement( ).getSystem( ) ); assertEquals( "system", metadata.getCiManagement( ).getSystem( ) );
assertEquals( "ci url", metadata.getCiManagement( ).getUrl( ) ); assertEquals( "ci url", metadata.getCiManagement( ).getUrl( ) );
assertNotNull( metadata.getIssueManagement( ) );
assertEquals( "system", metadata.getIssueManagement( ).getSystem( ) ); assertEquals( "system", metadata.getIssueManagement( ).getSystem( ) );
assertEquals( "issue tracker url", metadata.getIssueManagement( ).getUrl( ) ); assertEquals( "issue tracker url", metadata.getIssueManagement( ).getUrl( ) );

View File

@ -31,7 +31,8 @@
<properties> <properties>
<site.staging.base>${project.parent.parent.basedir}</site.staging.base> <site.staging.base>${project.parent.parent.basedir}</site.staging.base>
<cassandraVersion>3.11.11</cassandraVersion> <cassandraVersion>4.0.0</cassandraVersion>
<datastax.driver.version>4.13.0</datastax.driver.version>
</properties> </properties>
<dependencies> <dependencies>
@ -102,16 +103,18 @@
<artifactId>modelmapper</artifactId> <artifactId>modelmapper</artifactId>
</dependency> </dependency>
<!--
<dependency> <dependency>
<groupId>org.yaml</groupId> <groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId> <artifactId>snakeyaml</artifactId>
<version>1.27</version> <version>1.27</version>
</dependency> </dependency>
-->
<dependency> <dependency>
<groupId>org.apache.cassandra</groupId> <groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-all</artifactId> <artifactId>cassandra-all</artifactId>
<version>${cassandraVersion}</version> <version>${cassandraVersion}</version>
<scope>test</scope>
<exclusions> <exclusions>
<exclusion> <exclusion>
<groupId>log4j</groupId> <groupId>log4j</groupId>
@ -166,14 +169,36 @@
<groupId>com.addthis.metrics</groupId> <groupId>com.addthis.metrics</groupId>
<artifactId>reporter-config3</artifactId> <artifactId>reporter-config3</artifactId>
</exclusion> </exclusion>
<!-- Version upgrade, see below -->
<exclusion> <exclusion>
<groupId>org.apache.tika</groupId> <groupId>net.openhft</groupId>
<artifactId>tika-core</artifactId> <artifactId>chronicle-wire</artifactId>
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>net.openhft</groupId>
<artifactId>chronicle-wire</artifactId>
<version>2.21.89</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.datastax.oss</groupId>
<artifactId>java-driver-core</artifactId>
<version>${datastax.driver.version}</version>
</dependency>
<dependency>
<groupId>com.datastax.oss</groupId>
<artifactId>java-driver-query-builder</artifactId>
<version>${datastax.driver.version}</version>
</dependency>
<dependency>
<groupId>com.datastax.oss</groupId>
<artifactId>java-driver-mapper-runtime</artifactId>
<version>${datastax.driver.version}</version>
</dependency>
<!--
<dependency> <dependency>
<groupId>org.hectorclient</groupId> <groupId>org.hectorclient</groupId>
<artifactId>hector-core</artifactId> <artifactId>hector-core</artifactId>
@ -197,6 +222,8 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
-->
<!--
<dependency> <dependency>
<groupId>org.apache.cassandra</groupId> <groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-thrift</artifactId> <artifactId>cassandra-thrift</artifactId>
@ -212,7 +239,9 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
-->
<!-- Transient dependencies of cassandra that are selected to use a higher version --> <!-- Transient dependencies of cassandra that are selected to use a higher version -->
<!--
<dependency> <dependency>
<groupId>org.apache.thrift</groupId> <groupId>org.apache.thrift</groupId>
<artifactId>libthrift</artifactId> <artifactId>libthrift</artifactId>
@ -234,25 +263,35 @@
<artifactId>tika-core</artifactId> <artifactId>tika-core</artifactId>
<version>1.26</version> <version>1.26</version>
</dependency> </dependency>
-->
<!-- Transitive dependency. Declared here to increase the version. --> <!-- Transitive dependency. Declared here to increase the version. -->
<!--
<dependency> <dependency>
<groupId>io.netty</groupId> <groupId>io.netty</groupId>
<artifactId>netty-all</artifactId> <artifactId>netty-all</artifactId>
<version>${netty.version}</version> <version>${netty.version}</version>
</dependency> </dependency>
-->
<!--
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId> <artifactId>jackson-core</artifactId>
</dependency> </dependency>
-->
<!-- Is a dependency of cassandra -> hibernate-validator and replaced by new version --> <!-- Is a dependency of cassandra -> hibernate-validator and replaced by new version -->
<!--
<dependency> <dependency>
<groupId>org.jboss.logging</groupId> <groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId> <artifactId>jboss-logging</artifactId>
</dependency> </dependency>
-->
<!-- TEST Scope --> <!-- TEST Scope -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.apache.archiva</groupId> <groupId>org.apache.archiva</groupId>
<artifactId>archiva-test-utils</artifactId> <artifactId>archiva-test-utils</artifactId>
@ -297,6 +336,12 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
@ -320,10 +365,11 @@
</goals> </goals>
<configuration> <configuration>
<portNames> <portNames>
<portName>cassandraPort</portName> <portName>cassandra.rpcPort</portName>
<portName>cassandra.storagePort</portName> <portName>cassandra.storagePort</portName>
<portName>cassandra.stopPort</portName> <portName>cassandra.stopPort</portName>
<portName>cassandra.jmxPort</portName> <portName>cassandra.jmxPort</portName>
<portName>cassandra.nativeTransportPort</portName>
</portNames> </portNames>
</configuration> </configuration>
</execution> </execution>
@ -332,27 +378,37 @@
<plugin> <plugin>
<groupId>org.codehaus.mojo</groupId> <groupId>org.codehaus.mojo</groupId>
<artifactId>cassandra-maven-plugin</artifactId> <artifactId>cassandra-maven-plugin</artifactId>
<version>2.0.0-1</version> <version>3.6</version>
<executions> <executions>
<execution> <execution>
<id>start-cassandra</id> <id>start-cassandra</id>
<phase>process-test-classes</phase> <phase>pre-integration-test</phase>
<goals> <goals>
<goal>start</goal> <goal>start</goal>
</goals> </goals>
<configuration> <configuration>
<rpcPort>${cassandraPort}</rpcPort> <nativeTransportPort>${cassandra.nativeTransportPort}</nativeTransportPort>
<rpcPort>${cassandra.rpcPort}</rpcPort>
<storagePort>${cassandra.storagePort}</storagePort> <storagePort>${cassandra.storagePort}</storagePort>
<stopPort>${cassandra.stopPort}</stopPort> <stopPort>${cassandra.stopPort}</stopPort>
<jmxPort>${cassandra.jmxPort}</jmxPort> <jmxPort>${cassandra.jmxPort}</jmxPort>
<addMainClasspath>false</addMainClasspath> <addMainClasspath>false</addMainClasspath>
<addTestClasspath>false</addTestClasspath> <addTestClasspath>false</addTestClasspath>
<startWaitSeconds>500</startWaitSeconds> <startWaitSeconds>500</startWaitSeconds>
<startNativeTransport>true</startNativeTransport>
<logLevel>DEBUG</logLevel>
<loadAfterFirstStart>false</loadAfterFirstStart>
<yaml>
broadcast_rpc_address: 127.0.0.1
</yaml>
<systemPropertyVariables>
<java.net.preferIPv4Stack>true</java.net.preferIPv4Stack>
</systemPropertyVariables>
</configuration> </configuration>
</execution> </execution>
<execution> <execution>
<id>stop-cassandra</id> <id>stop-cassandra</id>
<phase>test</phase> <phase>post-integration-test</phase>
<goals> <goals>
<goal>stop</goal> <goal>stop</goal>
</goals> </goals>
@ -364,21 +420,74 @@
<artifactId>slf4j-simple</artifactId> <artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version> <version>${slf4j.version}</version>
</dependency> </dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>4.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-all</artifactId>
<version>3.11.10</version>
</dependency>
</dependencies> </dependencies>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M5</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
<systemPropertyVariables>
<cassandra.port>${cassandra.nativeTransportPort}</cassandra.port>
<cassandra.host>127.0.0.1</cassandra.host>
<archiva.repositorySessionFactory.id>cassandra</archiva.repositorySessionFactory.id>
<appserver.base>${project.build.directory}/appserver-base</appserver.base>
<java.net.preferIPv4Stack>true</java.net.preferIPv4Stack>
</systemPropertyVariables>
<trimStackTrace>false</trimStackTrace>
<skip>false</skip>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins> </plugins>
<pluginManagement> <pluginManagement>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<executions>
</executions>
<configuration> <configuration>
<systemPropertyVariables> <skip>true</skip>
<cassandra.port>${cassandraPort}</cassandra.port> </configuration>
<archiva.repositorySessionFactory.id>cassandra</archiva.repositorySessionFactory.id> </plugin>
<appserver.base>${project.build.directory}/appserver-base</appserver.base>
</systemPropertyVariables> <plugin>
<trimStackTrace>false</trimStackTrace> <groupId>org.apache.rat</groupId>
<artifactId>apache-rat-plugin</artifactId>
<configuration>
<excludes>
<exclude>src/cassandra/**</exclude>
</excludes>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>

View File

@ -19,8 +19,9 @@ package org.apache.archiva.metadata.repository.cassandra;
* under the License. * under the License.
*/ */
import me.prettyprint.hector.api.Cluster; import com.datastax.oss.driver.api.core.CqlSession;
import me.prettyprint.hector.api.Keyspace; import com.datastax.oss.driver.api.core.CqlSessionBuilder;
import com.datastax.oss.driver.api.core.config.DriverConfigLoader;
/** /**
* @author Olivier Lamy * @author Olivier Lamy
@ -28,16 +29,14 @@ import me.prettyprint.hector.api.Keyspace;
*/ */
public interface CassandraArchivaManager public interface CassandraArchivaManager
{ {
String DEFAULT_PRIMARY_KEY = "key";
void start(); void start();
void shutdown(); void shutdown();
boolean started(); boolean started();
Keyspace getKeyspace();
Cluster getCluster();
String getRepositoryFamilyName(); String getRepositoryFamilyName();
String getNamespaceFamilyName(); String getNamespaceFamilyName();
@ -46,6 +45,8 @@ public interface CassandraArchivaManager
String getProjectVersionMetadataFamilyName(); String getProjectVersionMetadataFamilyName();
String[] getProjectVersionMetadataColumns();
String getArtifactMetadataFamilyName(); String getArtifactMetadataFamilyName();
String getMetadataFacetFamilyName(); String getMetadataFacetFamilyName();
@ -58,4 +59,12 @@ public interface CassandraArchivaManager
String getChecksumFamilyName(); String getChecksumFamilyName();
DriverConfigLoader getConfigLoader();
CqlSessionBuilder getSessionBuilder( );
CqlSession getSession();
String getKeyspaceName();
} }

View File

@ -9,8 +9,7 @@ package org.apache.archiva.metadata.repository.cassandra;
* "License"); you may not use this file except in compliance * "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at * with the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, * Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an * software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@ -19,18 +18,6 @@ package org.apache.archiva.metadata.repository.cassandra;
* under the License. * under the License.
*/ */
import me.prettyprint.cassandra.serializers.LongSerializer;
import me.prettyprint.cassandra.serializers.SerializerTypeInferer;
import me.prettyprint.cassandra.serializers.StringSerializer;
import me.prettyprint.cassandra.service.template.ColumnFamilyUpdater;
import me.prettyprint.hector.api.Serializer;
import me.prettyprint.hector.api.beans.ColumnSlice;
import me.prettyprint.hector.api.beans.HColumn;
import me.prettyprint.hector.api.factory.HFactory;
import me.prettyprint.hector.api.mutation.Mutator;
import org.apache.archiva.metadata.repository.cassandra.model.ColumnNames;
import org.apache.commons.lang3.StringUtils;
/** /**
* @author Olivier Lamy * @author Olivier Lamy
* @since 2.0.0 * @since 2.0.0
@ -69,90 +56,7 @@ public class CassandraUtils
return builder.toString(); return builder.toString();
} }
public static <A, B> HColumn<A, B> column( final A name, final B value )
{
return HFactory.createColumn( name, //
value, //
SerializerTypeInferer.getSerializer( name ), //
SerializerTypeInferer.getSerializer( value ) );
}
public static String getStringValue( ColumnSlice<String, String> columnSlice, ColumnNames columnName )
{
return getStringValue( columnSlice, columnName.toString() );
}
public static String getStringValue( ColumnSlice<String, String> columnSlice, String columnName )
{
if ( StringUtils.isEmpty( columnName ) )
{
return null;
}
HColumn<String, String> hColumn = columnSlice.getColumnByName( columnName );
return hColumn == null ? null : hColumn.getValue();
}
public static Long getLongValue( ColumnSlice<String, Long> columnSlice, String columnName )
{
if ( StringUtils.isEmpty( columnName ) )
{
return null;
}
HColumn<String, Long> hColumn = columnSlice.getColumnByName( columnName );
return hColumn == null ? null : hColumn.getValue();
}
public static <T> String getAsStringValue( ColumnSlice<String, T> columnSlice, String columnName )
{
StringSerializer ss = StringSerializer.get();
if ( StringUtils.isEmpty( columnName ) )
{
return null;
}
HColumn<String, T> hColumn = columnSlice.getColumnByName( columnName );
return hColumn == null ? null : ss.fromByteBuffer( hColumn.getValueBytes() );
}
public static Long getAsLongValue( ColumnSlice<String, String> columnSlice, String columnName )
{
LongSerializer ls = LongSerializer.get();
if ( StringUtils.isEmpty( columnName ) )
{
return null;
}
HColumn<String, String> hColumn = columnSlice.getColumnByName( columnName );
return hColumn == null ? null : ls.fromByteBuffer( hColumn.getValueBytes() );
}
public static void addInsertion( Mutator<String> mutator, String key, String columnFamily, String columnName,
String value )
{
if ( value != null )
{
mutator.addInsertion( key, columnFamily, column( columnName, value ) );
}
}
/**
* null check on the value to prevent {@link java.lang.IllegalArgumentException}
* @param updater
* @param columnName
* @param value
*/
public static void addUpdateStringValue(ColumnFamilyUpdater<String,String> updater, String columnName, String value )
{
if (value == null)
{
return;
}
updater.setString( columnName, value );
}
private CassandraUtils() private CassandraUtils()
{ {

View File

@ -19,18 +19,14 @@ package org.apache.archiva.metadata.repository.cassandra;
* under the License. * under the License.
*/ */
import me.prettyprint.cassandra.model.BasicColumnDefinition; import com.datastax.oss.driver.api.core.CqlSession;
import me.prettyprint.cassandra.model.ConfigurableConsistencyLevel; import com.datastax.oss.driver.api.core.CqlSessionBuilder;
import me.prettyprint.cassandra.serializers.StringSerializer; import com.datastax.oss.driver.api.core.config.DefaultDriverOption;
import me.prettyprint.cassandra.service.CassandraHostConfigurator; import com.datastax.oss.driver.api.core.config.DriverConfigLoader;
import me.prettyprint.cassandra.service.ThriftKsDef; import com.datastax.oss.driver.api.core.type.DataTypes;
import me.prettyprint.hector.api.Cluster; import com.datastax.oss.driver.api.querybuilder.schema.CreateIndex;
import me.prettyprint.hector.api.HConsistencyLevel; import com.datastax.oss.driver.api.querybuilder.schema.CreateKeyspace;
import me.prettyprint.hector.api.Keyspace; import com.datastax.oss.driver.api.querybuilder.schema.CreateTableWithOptions;
import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition;
import me.prettyprint.hector.api.ddl.ColumnIndexType;
import me.prettyprint.hector.api.ddl.ComparatorType;
import me.prettyprint.hector.api.factory.HFactory;
import org.apache.archiva.metadata.repository.RepositorySessionFactoryBean; import org.apache.archiva.metadata.repository.RepositorySessionFactoryBean;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -43,8 +39,12 @@ import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy; import javax.annotation.PreDestroy;
import javax.inject.Inject; import javax.inject.Inject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List; import java.util.List;
import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.literal;
import static com.datastax.oss.driver.api.querybuilder.SchemaBuilder.*;
import static org.apache.archiva.metadata.repository.cassandra.model.ColumnNames.*; import static org.apache.archiva.metadata.repository.cassandra.model.ColumnNames.*;
/** /**
@ -53,12 +53,12 @@ import static org.apache.archiva.metadata.repository.cassandra.model.ColumnNames
* @author Olivier Lamy * @author Olivier Lamy
* @since 2.0.0 * @since 2.0.0
*/ */
@Service("archivaEntityManagerFactory#cassandra") @Service( "archivaEntityManagerFactory#cassandra" )
public class DefaultCassandraArchivaManager public class DefaultCassandraArchivaManager
implements CassandraArchivaManager implements CassandraArchivaManager
{ {
private Logger logger = LoggerFactory.getLogger( getClass() ); private Logger logger = LoggerFactory.getLogger( getClass( ) );
@Inject @Inject
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
@ -69,16 +69,12 @@ public class DefaultCassandraArchivaManager
private boolean started; private boolean started;
private Cluster cluster;
private Keyspace keyspace;
// configurable??? // configurable???
private String repositoryFamilyName = "repository"; private String repositoryFamilyName = "repository";
private String namespaceFamilyName = "namespace"; private String namespaceFamilyName = "namespace";
private String projectFamilyName = PROJECT.toString(); private String projectFamilyName = PROJECT.toString( );
private String projectVersionMetadataFamilyName = "projectversionmetadata"; private String projectVersionMetadataFamilyName = "projectversionmetadata";
@ -94,513 +90,448 @@ public class DefaultCassandraArchivaManager
private String checksumFamilyName = "checksum"; private String checksumFamilyName = "checksum";
@Value("${cassandra.host}")
private static String[] projectVersionMetadataColumns;
static
{
projectVersionMetadataColumns = new String[]{
DEFAULT_PRIMARY_KEY,
NAMESPACE_ID.toString( ),
REPOSITORY_NAME.toString( ),
PROJECT_VERSION.toString( ),
PROJECT_ID.toString( ),
DESCRIPTION.toString( ),
URL.toString( ),
NAME.toString( ),
VERSION.toString( ),
VERSION_PROPERTIES.toString( ),
"incomplete",
"ciManagement.system",
"ciManagement.url",
"issueManagement.system",
"issueManagement.url",
"organization.name",
"organization.url",
"scm.url",
"scm.connection",
"scm.developerConnection"
};
Arrays.sort( projectVersionMetadataColumns );
}
@Value( "${cassandra.host}" )
private String cassandraHost; private String cassandraHost;
@Value("${cassandra.port}") @Value( "${cassandra.port}" )
private String cassandraPort; private String cassandraPort;
@Value("${cassandra.maxActive}") @Value( "${cassandra.maxActive}" )
private int maxActive; private int maxActive;
@Value("${cassandra.readConsistencyLevel}") @Value( "${cassandra.readConsistencyLevel}" )
private String readConsistencyLevel; private String readConsistencyLevel;
@Value("${cassandra.writeConsistencyLevel}") @Value( "${cassandra.writeConsistencyLevel}" )
private String writeConsistencyLevel; private String writeConsistencyLevel;
@Value("${cassandra.replicationFactor}") @Value( "${cassandra.replicationFactor}" )
private int replicationFactor; private int replicationFactor;
@Value("${cassandra.keyspace.name}") @Value( "${cassandra.keyspace.name}" )
private String keyspaceName; private String keyspaceName;
@Value("${cassandra.cluster.name}") @Value( "${cassandra.cluster.name}" )
private String clusterName; private String clusterName;
@Inject @Inject
private RepositorySessionFactoryBean repositorySessionFactoryBean; private RepositorySessionFactoryBean repositorySessionFactoryBean;
DriverConfigLoader configLoader;
CqlSession cqlSession;
@Override
public CqlSessionBuilder getSessionBuilder( )
{
return CqlSession.builder( ).withConfigLoader( configLoader ).withKeyspace( keyspaceName ).withLocalDatacenter( "datacenter1" );
}
@Override
public CqlSession getSession( )
{
if (cqlSession==null || cqlSession.isClosed()) {
this.cqlSession = getSessionBuilder( ).build( );
}
return this.cqlSession;
}
@PostConstruct @PostConstruct
public void initialize() public void initialize( )
{ {
// skip initialisation if not cassandra // skip initialisation if not cassandra
if ( !StringUtils.equals( repositorySessionFactoryBean.getId(), "cassandra" ) ) if ( !StringUtils.equals( repositorySessionFactoryBean.getId( ), "cassandra" ) )
{ {
return; return;
} }
final CassandraHostConfigurator configurator =
new CassandraHostConfigurator( cassandraHost + ":" + cassandraPort );
configurator.setMaxActive( maxActive );
//configurator.setCassandraThriftSocketTimeout( );
cluster = HFactory.getOrCreateCluster( clusterName, configurator ); List<String> hostNames = new ArrayList<>( );
hostNames.add( cassandraHost + ":" + cassandraPort );
System.out.println( "Contact point: " + cassandraHost + ":" + cassandraPort );
configLoader =
DriverConfigLoader.programmaticBuilder( )
final ConfigurableConsistencyLevel consistencyLevelPolicy = new ConfigurableConsistencyLevel(); .withStringList( DefaultDriverOption.CONTACT_POINTS, hostNames )
consistencyLevelPolicy.setDefaultReadConsistencyLevel( HConsistencyLevel.valueOf( readConsistencyLevel ) ); .withInt( DefaultDriverOption.CONNECTION_POOL_LOCAL_SIZE, maxActive )
consistencyLevelPolicy.setDefaultWriteConsistencyLevel( HConsistencyLevel.valueOf( writeConsistencyLevel ) ); .withInt( DefaultDriverOption.CONNECTION_POOL_REMOTE_SIZE, maxActive )
keyspace = HFactory.createKeyspace( keyspaceName, cluster, consistencyLevelPolicy ); //.withInt( DefaultDriverOption.CONNECTION_MAX_REQUESTS, maxActive )
.withString( DefaultDriverOption.REQUEST_CONSISTENCY, readConsistencyLevel )
.build( );
List<ColumnFamilyDefinition> cfds = new ArrayList<>();
// namespace table
{ {
final ColumnFamilyDefinition namespace = CreateKeyspace cKeySpace = createKeyspace( keyspaceName ).ifNotExists( ).withSimpleStrategy( replicationFactor );
HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), // CqlSession.builder( ).withConfigLoader( configLoader ).withLocalDatacenter( "datacenter1" ).build().execute( cKeySpace.build( ) );
getNamespaceFamilyName(), //
ComparatorType.UTF8TYPE );
cfds.add( namespace );
// creating indexes for cql query
BasicColumnDefinition nameColumn = new BasicColumnDefinition();
nameColumn.setName( StringSerializer.get().toByteBuffer( NAME.toString() ) );
nameColumn.setIndexName( NAME.toString() );
nameColumn.setIndexType( ColumnIndexType.KEYS );
nameColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
namespace.addColumnDefinition( nameColumn );
BasicColumnDefinition repositoryIdColumn = new BasicColumnDefinition();
repositoryIdColumn.setName( StringSerializer.get().toByteBuffer( REPOSITORY_NAME.toString() ) );
repositoryIdColumn.setIndexName( REPOSITORY_NAME.toString() );
repositoryIdColumn.setIndexType( ColumnIndexType.KEYS );
repositoryIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
namespace.addColumnDefinition( repositoryIdColumn );
} }
// repository table CqlSession session = getSession( );
{
final ColumnFamilyDefinition repository =
HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), //
getRepositoryFamilyName(), //
ComparatorType.UTF8TYPE );
cfds.add( repository );
BasicColumnDefinition nameColumn = new BasicColumnDefinition();
nameColumn.setName( StringSerializer.get().toByteBuffer( REPOSITORY_NAME.toString() ) );
nameColumn.setIndexName( REPOSITORY_NAME.toString() );
nameColumn.setIndexType( ColumnIndexType.KEYS );
nameColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
repository.addColumnDefinition( nameColumn );
}
// project table
{ {
final ColumnFamilyDefinition project = HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), // // namespace table
getProjectFamilyName(), //
ComparatorType.UTF8TYPE );
cfds.add( project );
// creating indexes for cql query
BasicColumnDefinition projectIdColumn = new BasicColumnDefinition();
projectIdColumn.setName( StringSerializer.get().toByteBuffer( PROJECT_ID.toString() ) );
projectIdColumn.setIndexName( PROJECT_ID.toString() );
projectIdColumn.setIndexType( ColumnIndexType.KEYS );
projectIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
project.addColumnDefinition( projectIdColumn );
BasicColumnDefinition repositoryIdColumn = new BasicColumnDefinition();
repositoryIdColumn.setName( StringSerializer.get().toByteBuffer( REPOSITORY_NAME.toString() ) );
repositoryIdColumn.setIndexName( REPOSITORY_NAME.toString() );
repositoryIdColumn.setIndexType( ColumnIndexType.KEYS );
repositoryIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
project.addColumnDefinition( repositoryIdColumn );
BasicColumnDefinition namespaceIdColumn = new BasicColumnDefinition();
namespaceIdColumn.setName( StringSerializer.get().toByteBuffer( NAMESPACE_ID.toString() ) );
namespaceIdColumn.setIndexName( NAMESPACE_ID.toString() );
namespaceIdColumn.setIndexType( ColumnIndexType.KEYS );
namespaceIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
project.addColumnDefinition( namespaceIdColumn );
}
//projectversionmetadatamodel
{
final ColumnFamilyDefinition projectVersionMetadataModel =
HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), //
getProjectVersionMetadataFamilyName(), //
ComparatorType.UTF8TYPE );
cfds.add( projectVersionMetadataModel );
// creating indexes for cql query
BasicColumnDefinition namespaceIdColumn = new BasicColumnDefinition();
namespaceIdColumn.setName( StringSerializer.get().toByteBuffer( NAMESPACE_ID.toString() ) );
namespaceIdColumn.setIndexName( NAMESPACE_ID.toString() );
namespaceIdColumn.setIndexType( ColumnIndexType.KEYS );
namespaceIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
projectVersionMetadataModel.addColumnDefinition( namespaceIdColumn );
BasicColumnDefinition repositoryNameColumn = new BasicColumnDefinition();
repositoryNameColumn.setName( StringSerializer.get().toByteBuffer( REPOSITORY_NAME.toString() ) );
repositoryNameColumn.setIndexName( REPOSITORY_NAME.toString() );
repositoryNameColumn.setIndexType( ColumnIndexType.KEYS );
repositoryNameColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
projectVersionMetadataModel.addColumnDefinition( repositoryNameColumn );
BasicColumnDefinition idColumn = new BasicColumnDefinition();
idColumn.setName( StringSerializer.get().toByteBuffer( ID.toString() ) );
idColumn.setIndexName( ID.toString() );
idColumn.setIndexType( ColumnIndexType.KEYS );
idColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
projectVersionMetadataModel.addColumnDefinition( idColumn );
BasicColumnDefinition projectIdColumn = new BasicColumnDefinition();
projectIdColumn.setName( StringSerializer.get().toByteBuffer( PROJECT_ID.toString() ) );
projectIdColumn.setIndexName( PROJECT_ID.toString() );
projectIdColumn.setIndexType( ColumnIndexType.KEYS );
projectIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
projectVersionMetadataModel.addColumnDefinition( projectIdColumn );
}
// artifactmetadatamodel table
{
final ColumnFamilyDefinition artifactMetadataModel =
HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), //
getArtifactMetadataFamilyName(), //
ComparatorType.UTF8TYPE );
cfds.add( artifactMetadataModel );
// creating indexes for cql query
BasicColumnDefinition idColumn = new BasicColumnDefinition();
idColumn.setName( StringSerializer.get().toByteBuffer( ID.toString() ) );
idColumn.setIndexName( ID.toString() );
idColumn.setIndexType( ColumnIndexType.KEYS );
idColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
artifactMetadataModel.addColumnDefinition( idColumn );
BasicColumnDefinition repositoryNameColumn = new BasicColumnDefinition();
repositoryNameColumn.setName( StringSerializer.get().toByteBuffer( REPOSITORY_NAME.toString() ) );
repositoryNameColumn.setIndexName( REPOSITORY_NAME.toString() );
repositoryNameColumn.setIndexType( ColumnIndexType.KEYS );
repositoryNameColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
artifactMetadataModel.addColumnDefinition( repositoryNameColumn );
BasicColumnDefinition namespaceIdColumn = new BasicColumnDefinition();
namespaceIdColumn.setName( StringSerializer.get().toByteBuffer( NAMESPACE_ID.toString() ) );
namespaceIdColumn.setIndexName( NAMESPACE_ID.toString() );
namespaceIdColumn.setIndexType( ColumnIndexType.KEYS );
namespaceIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
artifactMetadataModel.addColumnDefinition( namespaceIdColumn );
BasicColumnDefinition projectColumn = new BasicColumnDefinition();
projectColumn.setName( StringSerializer.get().toByteBuffer( PROJECT.toString() ) );
projectColumn.setIndexName( PROJECT.toString() );
projectColumn.setIndexType( ColumnIndexType.KEYS );
projectColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
artifactMetadataModel.addColumnDefinition( projectColumn );
BasicColumnDefinition projectVersionColumn = new BasicColumnDefinition();
projectVersionColumn.setName( StringSerializer.get().toByteBuffer( PROJECT_VERSION.toString() ) );
projectVersionColumn.setIndexName( PROJECT_VERSION.toString() );
projectVersionColumn.setIndexType( ColumnIndexType.KEYS );
projectVersionColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
artifactMetadataModel.addColumnDefinition( projectVersionColumn );
BasicColumnDefinition versionColumn = new BasicColumnDefinition();
versionColumn.setName( StringSerializer.get().toByteBuffer( VERSION.toString() ) );
versionColumn.setIndexName( VERSION.toString() );
versionColumn.setIndexType( ColumnIndexType.KEYS );
versionColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
artifactMetadataModel.addColumnDefinition( versionColumn );
BasicColumnDefinition whenGatheredColumn = new BasicColumnDefinition();
whenGatheredColumn.setName( StringSerializer.get().toByteBuffer( WHEN_GATHERED.toString() ) );
whenGatheredColumn.setIndexName( WHEN_GATHERED.toString() );
whenGatheredColumn.setIndexType( ColumnIndexType.KEYS );
whenGatheredColumn.setValidationClass( ComparatorType.LONGTYPE.getClassName() );
artifactMetadataModel.addColumnDefinition( whenGatheredColumn );
BasicColumnDefinition sha1Column = new BasicColumnDefinition();
sha1Column.setName( StringSerializer.get().toByteBuffer( SHA1.toString() ) );
sha1Column.setIndexName( SHA1.toString() );
sha1Column.setIndexType( ColumnIndexType.KEYS );
sha1Column.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
artifactMetadataModel.addColumnDefinition( sha1Column );
BasicColumnDefinition md5Column = new BasicColumnDefinition();
md5Column.setName( StringSerializer.get().toByteBuffer( MD5.toString() ) );
md5Column.setIndexName( MD5.toString() );
md5Column.setIndexType( ColumnIndexType.KEYS );
md5Column.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
artifactMetadataModel.addColumnDefinition( md5Column );
}
// metadatafacetmodel table
{
final ColumnFamilyDefinition metadataFacetModel =
HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), //
getMetadataFacetFamilyName(), //
ComparatorType.UTF8TYPE );
cfds.add( metadataFacetModel );
// creating indexes for cql query
BasicColumnDefinition facetIdColumn = new BasicColumnDefinition();
facetIdColumn.setName( StringSerializer.get().toByteBuffer( FACET_ID.toString() ) );
facetIdColumn.setIndexName( FACET_ID.toString() );
facetIdColumn.setIndexType( ColumnIndexType.KEYS );
facetIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
metadataFacetModel.addColumnDefinition( facetIdColumn );
BasicColumnDefinition repositoryNameColumn = new BasicColumnDefinition();
repositoryNameColumn.setName( StringSerializer.get().toByteBuffer( REPOSITORY_NAME.toString() ) );
repositoryNameColumn.setIndexName( REPOSITORY_NAME.toString() );
repositoryNameColumn.setIndexType( ColumnIndexType.KEYS );
repositoryNameColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
metadataFacetModel.addColumnDefinition( repositoryNameColumn );
BasicColumnDefinition nameColumn = new BasicColumnDefinition();
nameColumn.setName( StringSerializer.get().toByteBuffer( NAME.toString() ) );
nameColumn.setIndexName( NAME.toString() );
nameColumn.setIndexType( ColumnIndexType.KEYS );
nameColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
metadataFacetModel.addColumnDefinition( nameColumn );
BasicColumnDefinition namespaceColumn = new BasicColumnDefinition();
namespaceColumn.setName( StringSerializer.get().toByteBuffer( NAMESPACE_ID.toString() ) );
namespaceColumn.setIndexName( NAMESPACE_ID.toString() );
namespaceColumn.setIndexType( ColumnIndexType.KEYS );
namespaceColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
metadataFacetModel.addColumnDefinition( namespaceColumn );
BasicColumnDefinition projectIdColumn = new BasicColumnDefinition();
projectIdColumn.setName( StringSerializer.get().toByteBuffer( PROJECT_ID.toString() ) );
projectIdColumn.setIndexName( PROJECT_ID.toString() );
projectIdColumn.setIndexType( ColumnIndexType.KEYS );
projectIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
metadataFacetModel.addColumnDefinition( projectIdColumn );
BasicColumnDefinition projectVersionColumn = new BasicColumnDefinition();
projectVersionColumn.setName( StringSerializer.get().toByteBuffer( PROJECT_VERSION.toString() ) );
projectVersionColumn.setIndexName( PROJECT_VERSION.toString() );
projectVersionColumn.setIndexType( ColumnIndexType.KEYS );
projectVersionColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
metadataFacetModel.addColumnDefinition( projectVersionColumn );
}
// Checksum table
{
final ColumnFamilyDefinition checksumCf =
HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), //
getChecksumFamilyName(), //
ComparatorType.UTF8TYPE );
BasicColumnDefinition artifactMetatadaModel_key = new BasicColumnDefinition();
artifactMetatadaModel_key.setName( StringSerializer.get().toByteBuffer( "artifactMetadataModel.key" ) );
artifactMetatadaModel_key.setIndexName( "artifactMetadataModel_key" );
artifactMetatadaModel_key.setIndexType( ColumnIndexType.KEYS );
artifactMetatadaModel_key.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
checksumCf.addColumnDefinition( artifactMetatadaModel_key );
BasicColumnDefinition checksumAlgorithmColumn = new BasicColumnDefinition();
checksumAlgorithmColumn.setName( StringSerializer.get().toByteBuffer( CHECKSUM_ALG.toString() ) );
checksumAlgorithmColumn.setIndexName( CHECKSUM_ALG.toString() );
checksumAlgorithmColumn.setIndexType( ColumnIndexType.KEYS );
checksumAlgorithmColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
checksumCf.addColumnDefinition( checksumAlgorithmColumn );
BasicColumnDefinition checksumValueColumn = new BasicColumnDefinition();
checksumValueColumn.setName( StringSerializer.get().toByteBuffer( CHECKSUM_VALUE.toString() ) );
checksumValueColumn.setIndexName( CHECKSUM_VALUE.toString() );
checksumValueColumn.setIndexType( ColumnIndexType.KEYS );
checksumValueColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
checksumCf.addColumnDefinition( checksumValueColumn );
BasicColumnDefinition repositoryNameColumn = new BasicColumnDefinition();
repositoryNameColumn.setName( StringSerializer.get().toByteBuffer( REPOSITORY_NAME.toString() ) );
repositoryNameColumn.setIndexName( REPOSITORY_NAME.toString() );
repositoryNameColumn.setIndexType( ColumnIndexType.KEYS );
repositoryNameColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
checksumCf.addColumnDefinition( repositoryNameColumn );
cfds.add( checksumCf );
// creating indexes for cql query
}
// mailinglist table
{
final ColumnFamilyDefinition mailingListCf =
HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), //
getMailingListFamilyName(), //
ComparatorType.UTF8TYPE );
BasicColumnDefinition projectVersionMetadataModel_key = new BasicColumnDefinition();
projectVersionMetadataModel_key.setName( StringSerializer.get().toByteBuffer( "projectVersionMetadataModel.key" ) );
projectVersionMetadataModel_key.setIndexName( "projectVersionMetadataModel_key" );
projectVersionMetadataModel_key.setIndexType( ColumnIndexType.KEYS );
projectVersionMetadataModel_key.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
mailingListCf.addColumnDefinition( projectVersionMetadataModel_key );
cfds.add( mailingListCf );
// creating indexes for cql query
}
// license table
{
final ColumnFamilyDefinition licenseCf =
HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), //
getLicenseFamilyName(), //
ComparatorType.UTF8TYPE );
BasicColumnDefinition projectVersionMetadataModel_key = new BasicColumnDefinition();
projectVersionMetadataModel_key.setName( StringSerializer.get().toByteBuffer( "projectVersionMetadataModel.key" ) );
projectVersionMetadataModel_key.setIndexName( "projectVersionMetadataModel_key" );
projectVersionMetadataModel_key.setIndexType( ColumnIndexType.KEYS );
projectVersionMetadataModel_key.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
licenseCf.addColumnDefinition( projectVersionMetadataModel_key );
cfds.add( licenseCf );
// creating indexes for cql query
}
// dependency table
{
final ColumnFamilyDefinition dependencyCf =
HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), //
getDependencyFamilyName(), //
ComparatorType.UTF8TYPE );
cfds.add( dependencyCf );
// creating indexes for cql query
BasicColumnDefinition groupIdColumn = new BasicColumnDefinition();
groupIdColumn.setName( StringSerializer.get().toByteBuffer( GROUP_ID.toString() ) );
groupIdColumn.setIndexName( "groupIdIdx" );
groupIdColumn.setIndexType( ColumnIndexType.KEYS );
groupIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
dependencyCf.addColumnDefinition( groupIdColumn );
BasicColumnDefinition projectVersionMetadataModel_key = new BasicColumnDefinition();
projectVersionMetadataModel_key.setName( StringSerializer.get().toByteBuffer( "projectVersionMetadataModel.key" ) );
projectVersionMetadataModel_key.setIndexName( "projectVersionMetadataModel_key" );
projectVersionMetadataModel_key.setIndexType( ColumnIndexType.KEYS );
projectVersionMetadataModel_key.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
dependencyCf.addColumnDefinition( projectVersionMetadataModel_key );
}
// TODO take care of update new table!!
{ // ensure keyspace exists, here if the keyspace doesn't exist we suppose nothing exist
if ( cluster.describeKeyspace( keyspaceName ) == null )
{ {
logger.info( "Creating Archiva Cassandra '{}' keyspace.", keyspaceName ); String tableName = getNamespaceFamilyName( );
cluster.addKeyspace( HFactory.createKeyspaceDefinition( keyspaceName, // CreateTableWithOptions table = createTable( keyspaceName, tableName ).ifNotExists( )
ThriftKsDef.DEF_STRATEGY_CLASS, // .withPartitionKey( CassandraArchivaManager.DEFAULT_PRIMARY_KEY, DataTypes.TEXT )
replicationFactor, // .withColumn( NAME.toString( ), DataTypes.TEXT )
cfds ) .withColumn( REPOSITORY_NAME.toString( ), DataTypes.TEXT )
); .withCompactStorage( );
session.execute( table.build( ) );
CreateIndex index = createIndex( NAME.toString( ) ).ifNotExists( ).onTable( tableName ).andColumn( NAME.toString( ) );
session.execute( index.build( ) );
index = createIndex( REPOSITORY_NAME.toString( ) ).ifNotExists( ).onTable( tableName ).andColumn( REPOSITORY_NAME.toString( ) );
session.execute( index.build( ) );
} }
// Repository Table
{
String tableName = getRepositoryFamilyName( );
CreateTableWithOptions table = createTable( keyspaceName, tableName ).ifNotExists( )
.withPartitionKey( CassandraArchivaManager.DEFAULT_PRIMARY_KEY, DataTypes.TEXT )
.withColumn( REPOSITORY_NAME.toString( ), DataTypes.TEXT )
.withCompactStorage( );
session.execute( table.build( ) );
CreateIndex index = createIndex( REPOSITORY_NAME.toString( ) ).ifNotExists( ).onTable( tableName ).andColumn( REPOSITORY_NAME.toString( ) );
session.execute( index.build( ) );
}
// Project table
{
String tableName = getProjectFamilyName( );
CreateTableWithOptions table = createTable( keyspaceName, tableName ).ifNotExists( )
.withPartitionKey( CassandraArchivaManager.DEFAULT_PRIMARY_KEY, DataTypes.TEXT )
.withColumn( PROJECT_ID.toString( ), DataTypes.TEXT )
.withColumn( REPOSITORY_NAME.toString( ), DataTypes.TEXT )
.withColumn( NAMESPACE_ID.toString( ), DataTypes.TEXT )
.withColumn( PROJECT_PROPERTIES.toString( ), DataTypes.frozenMapOf( DataTypes.TEXT, DataTypes.TEXT ) )
.withCompactStorage( );
session.execute( table.build( ) );
CreateIndex index = createIndex( PROJECT_ID.toString( ) ).ifNotExists( ).onTable( tableName ).andColumn( PROJECT_ID.toString( ) );
session.execute( index.build( ) );
index = createIndex( REPOSITORY_NAME.toString( ) ).ifNotExists( ).onTable( tableName ).andColumn( REPOSITORY_NAME.toString( ) );
session.execute( index.build( ) );
index = createIndex( NAMESPACE_ID.toString( ) ).ifNotExists( ).onTable( tableName ).andColumn( NAMESPACE_ID.toString( ) );
session.execute( index.build( ) );
}
// Project Version Metadata Model
{
String tableName = getProjectVersionMetadataFamilyName( );
CreateTableWithOptions table = createTable( keyspaceName, tableName ).ifNotExists( )
.withPartitionKey( CassandraArchivaManager.DEFAULT_PRIMARY_KEY, DataTypes.TEXT )
.withColumn( NAMESPACE_ID.toString( ), DataTypes.TEXT )
.withColumn( REPOSITORY_NAME.toString( ), DataTypes.TEXT )
.withColumn( PROJECT_VERSION.toString( ), DataTypes.TEXT )
.withColumn( PROJECT_ID.toString( ), DataTypes.TEXT )
.withColumn( DESCRIPTION.toString( ), DataTypes.TEXT )
.withColumn( URL.toString( ), DataTypes.TEXT )
.withColumn( NAME.toString(), DataTypes.TEXT )
.withColumn( VERSION.toString(), DataTypes.TEXT )
.withColumn( VERSION_PROPERTIES.toString(), DataTypes.mapOf( DataTypes.TEXT, DataTypes.TEXT ) )
.withColumn( "incomplete", DataTypes.BOOLEAN )
.withColumn( "\"ciManagement.system\"", DataTypes.TEXT )
.withColumn( "\"ciManagement.url\"", DataTypes.TEXT )
.withColumn( "\"issueManagement.system\"", DataTypes.TEXT )
.withColumn( "\"issueManagement.url\"", DataTypes.TEXT )
.withColumn( "\"organization.name\"", DataTypes.TEXT )
.withColumn( "\"organization.url\"", DataTypes.TEXT )
.withColumn( "\"scm.url\"", DataTypes.TEXT )
.withColumn( "\"scm.connection\"", DataTypes.TEXT )
.withColumn( "\"scm.developerConnection\"", DataTypes.TEXT );
session.execute( table.build( ) );
CreateIndex index = createIndex( NAMESPACE_ID.toString( ) ).ifNotExists( ).onTable( tableName ).andColumn( NAMESPACE_ID.toString( ) );
session.execute( index.build( ) );
index = createIndex( REPOSITORY_NAME.toString( ) ).ifNotExists( ).onTable( tableName ).andColumn( REPOSITORY_NAME.toString( ) );
session.execute( index.build( ) );
index = createIndex( PROJECT_VERSION.toString( ) ).ifNotExists( ).onTable( tableName ).andColumn( PROJECT_VERSION.toString( ) );
session.execute( index.build( ) );
index = createIndex( PROJECT_ID.toString( ) ).ifNotExists( ).onTable( tableName ).andColumn( PROJECT_ID.toString( ) );
session.execute( index.build( ) );
index = createIndex( VERSION_PROPERTIES.toString( ) + "_idx" ).ifNotExists( ).onTable( tableName ).andColumnEntries( VERSION_PROPERTIES.toString( ) );
session.execute( index.build( ) );
}
// Artifact Metadata Model
{
String tableName = getArtifactMetadataFamilyName( );
CreateTableWithOptions table = createTable( keyspaceName, tableName ).ifNotExists( )
.withPartitionKey( CassandraArchivaManager.DEFAULT_PRIMARY_KEY, DataTypes.TEXT )
.withColumn( ID.toString( ), DataTypes.TEXT )
.withColumn( REPOSITORY_NAME.toString( ), DataTypes.TEXT )
.withColumn( NAMESPACE_ID.toString( ), DataTypes.TEXT )
.withColumn( PROJECT_ID.toString( ), DataTypes.TEXT )
.withColumn( PROJECT_VERSION.toString( ), DataTypes.TEXT )
.withColumn( VERSION.toString( ), DataTypes.TEXT )
.withColumn( WHEN_GATHERED.toString( ), DataTypes.BIGINT )
.withColumn( SHA1.toString( ), DataTypes.TEXT )
.withColumn( MD5.toString( ), DataTypes.TEXT )
.withColumn( FILE_LAST_MODIFIED.toString(), DataTypes.BIGINT)
.withColumn( SIZE.toString(), DataTypes.BIGINT )
.withCompactStorage( );
session.execute( table.build( ) );
CreateIndex index = createIndex( ID.toString( ) ).ifNotExists( ).onTable( tableName ).andColumn( ID.toString( ) );
session.execute( index.build( ) );
index = createIndex( REPOSITORY_NAME.toString( ) ).ifNotExists( ).onTable( tableName ).andColumn( REPOSITORY_NAME.toString( ) );
session.execute( index.build( ) );
index = createIndex( NAMESPACE_ID.toString( ) ).ifNotExists( ).onTable( tableName ).andColumn( NAMESPACE_ID.toString( ) );
session.execute( index.build( ) );
index = createIndex( PROJECT_ID.toString( ) ).ifNotExists( ).onTable( tableName ).andColumn( PROJECT_ID.toString( ) );
session.execute( index.build( ) );
index = createIndex( PROJECT_VERSION.toString( ) ).ifNotExists( ).onTable( tableName ).andColumn( PROJECT_VERSION.toString( ) );
session.execute( index.build( ) );
index = createIndex( VERSION.toString( ) ).ifNotExists( ).onTable( tableName ).andColumn( VERSION.toString( ) );
session.execute( index.build( ) );
index = createIndex( WHEN_GATHERED.toString( ) ).ifNotExists( ).onTable( tableName ).andColumn( WHEN_GATHERED.toString( ) );
session.execute( index.build( ) );
index = createIndex( SHA1.toString( ) ).ifNotExists( ).onTable( tableName ).andColumn( SHA1.toString( ) );
session.execute( index.build( ) );
index = createIndex( MD5.toString( ) ).ifNotExists( ).onTable( tableName ).andColumn( MD5.toString( ) );
session.execute( index.build( ) );
}
// Metadata Facet Model
{
String tableName = getMetadataFacetFamilyName( );
CreateTableWithOptions table = createTable( keyspaceName, tableName ).ifNotExists( )
.withPartitionKey( CassandraArchivaManager.DEFAULT_PRIMARY_KEY, DataTypes.TEXT )
.withColumn( FACET_ID.toString( ), DataTypes.TEXT )
.withColumn( REPOSITORY_NAME.toString( ), DataTypes.TEXT )
.withColumn( NAME.toString( ), DataTypes.TEXT )
.withColumn( NAMESPACE_ID.toString( ), DataTypes.TEXT )
.withColumn( PROJECT_ID.toString( ), DataTypes.TEXT )
.withColumn( PROJECT_VERSION.toString( ), DataTypes.TEXT )
.withColumn( KEY.toString(), DataTypes.TEXT )
.withColumn( VALUE.toString(), DataTypes.TEXT)
.withColumn( WHEN_GATHERED.toString(), DataTypes.BIGINT )
.withCompactStorage( );
session.execute( table.build( ) );
CreateIndex index = createIndex( FACET_ID.toString( ) ).ifNotExists( ).onTable( tableName ).andColumn( FACET_ID.toString( ) );
session.execute( index.build( ) );
index = createIndex( REPOSITORY_NAME.toString( ) ).ifNotExists( ).onTable( tableName ).andColumn( REPOSITORY_NAME.toString( ) );
session.execute( index.build( ) );
index = createIndex( NAME.toString( ) ).ifNotExists( ).onTable( tableName ).andColumn( NAME.toString( ) );
session.execute( index.build( ) );
index = createIndex( NAMESPACE_ID.toString( ) ).ifNotExists( ).onTable( tableName ).andColumn( NAMESPACE_ID.toString( ) );
session.execute( index.build( ) );
index = createIndex( PROJECT_ID.toString( ) ).ifNotExists( ).onTable( tableName ).andColumn( PROJECT_ID.toString( ) );
session.execute( index.build( ) );
index = createIndex( PROJECT_VERSION.toString( ) ).ifNotExists( ).onTable( tableName ).andColumn( PROJECT_VERSION.toString( ) );
session.execute( index.build( ) );
}
// Checksum Table
{
String tableName = getChecksumFamilyName( );
CreateTableWithOptions table = createTable( keyspaceName, tableName ).ifNotExists( )
.withPartitionKey( DEFAULT_PRIMARY_KEY, DataTypes.TEXT )
.withColumn( "\"artifactMetadataModel.key\"", DataTypes.TEXT )
.withColumn( CHECKSUM_ALG.toString( ), DataTypes.TEXT )
.withColumn( CHECKSUM_VALUE.toString( ), DataTypes.TEXT )
.withColumn( REPOSITORY_NAME.toString( ), DataTypes.TEXT )
.withCompactStorage( );
session.execute( table.build( ) );
CreateIndex index = createIndex( CHECKSUM_ALG.toString( ) ).ifNotExists( ).onTable( tableName ).andColumn( CHECKSUM_ALG.toString( ) );
session.execute( index.build( ) );
index = createIndex( CHECKSUM_VALUE.toString( ) ).ifNotExists( ).onTable( tableName ).andColumn( CHECKSUM_VALUE.toString( ) );
session.execute( index.build( ) );
index = createIndex( REPOSITORY_NAME.toString( ) ).ifNotExists( ).onTable( tableName ).andColumn( REPOSITORY_NAME.toString( ) );
session.execute( index.build( ) );
}
// Mailinglist Table
{
String tableName = getMailingListFamilyName( );
CreateTableWithOptions table = createTable( keyspaceName, tableName ).ifNotExists( )
.withPartitionKey( CassandraArchivaManager.DEFAULT_PRIMARY_KEY, DataTypes.TEXT )
.withColumn( NAME.toString(), DataTypes.TEXT )
.withColumn( "\"projectVersionMetadataModel.key\"", DataTypes.TEXT )
.withColumn( "mainArchiveUrl", DataTypes.TEXT )
.withColumn( "postAddress", DataTypes.TEXT )
.withColumn( "subscribeAddress", DataTypes.TEXT )
.withColumn( "unsubscribeAddress", DataTypes.TEXT )
.withColumn( "otherArchive", DataTypes.frozenListOf( DataTypes.TEXT ) )
.withCompactStorage( );
session.execute( table.build( ) );
CreateIndex index = createIndex( "\"projectVersionMetadataModel_key\"" ).ifNotExists( ).onTable( tableName ).andColumn( "\"\"projectVersionMetadataModel.key\"\"" );
session.execute( index.build( ) );
}
// License Table
{
String tableName = getLicenseFamilyName( );
CreateTableWithOptions table = createTable( keyspaceName, tableName ).ifNotExists( )
.withPartitionKey( CassandraArchivaManager.DEFAULT_PRIMARY_KEY, DataTypes.TEXT )
.withColumn( "\"projectVersionMetadataModel.key\"", DataTypes.TEXT )
.withColumn( NAME.toString(), DataTypes.TEXT )
.withColumn( URL.toString(), DataTypes.TEXT )
.withCompactStorage( );
session.execute( table.build( ) );
CreateIndex index = createIndex( "\"projectVersionMetadataModel_key\"" ).ifNotExists( ).onTable( tableName ).andColumn( "\"\"projectVersionMetadataModel.key\"\"" );
session.execute( index.build( ) );
}
// Dependency Table
{
String tableName = getDependencyFamilyName( );
CreateTableWithOptions table = createTable( keyspaceName, tableName ).ifNotExists( )
.withPartitionKey( CassandraArchivaManager.DEFAULT_PRIMARY_KEY, DataTypes.TEXT )
.withColumn( REPOSITORY_NAME.toString( ), DataTypes.TEXT )
.withColumn( GROUP_ID.toString( ), DataTypes.TEXT )
.withColumn( ARTIFACT_ID.toString( ), DataTypes.TEXT )
.withColumn( VERSION.toString( ), DataTypes.TEXT )
.withColumn( "\"projectVersionMetadataModel.key\"", DataTypes.TEXT )
.withColumn( "classifier", DataTypes.TEXT )
.withColumn( "optional", DataTypes.TEXT )
.withColumn( "scope", DataTypes.TEXT )
.withColumn( "systemPath", DataTypes.TEXT )
.withColumn( "type", DataTypes.TEXT )
.withCompactStorage( );
session.execute( table.build( ) );
CreateIndex index = createIndex( "groupIdIdx" ).ifNotExists( ).onTable( tableName ).andColumn( GROUP_ID.toString( ) );
session.execute( index.build( ) );
index = createIndex( "\"projectVersionMetadataModel_key\"" ).ifNotExists( ).onTable( tableName ).andColumn( "\"\"projectVersionMetadataModel.key\"\"" );
session.execute( index.build( ) );
}
} }
} }
@Override @Override
public void start() public void start( )
{ {
} }
@PreDestroy @PreDestroy
@Override @Override
public void shutdown() public void shutdown( )
{ {
if (this.cqlSession!=null) {
this.cqlSession.close( );
}
} }
@Override @Override
public boolean started() public boolean started( )
{ {
return started; return started;
} }
@Override @Override
public Keyspace getKeyspace() public String getRepositoryFamilyName( )
{
return keyspace;
}
@Override
public Cluster getCluster()
{
return cluster;
}
@Override
public String getRepositoryFamilyName()
{ {
return repositoryFamilyName; return repositoryFamilyName;
} }
@Override @Override
public String getNamespaceFamilyName() public String getNamespaceFamilyName( )
{ {
return namespaceFamilyName; return namespaceFamilyName;
} }
@Override @Override
public String getProjectFamilyName() public String getProjectFamilyName( )
{ {
return projectFamilyName; return projectFamilyName;
} }
@Override @Override
public String getProjectVersionMetadataFamilyName() public String getProjectVersionMetadataFamilyName( )
{ {
return projectVersionMetadataFamilyName; return projectVersionMetadataFamilyName;
} }
public String[] getProjectVersionMetadataColumns() {
return projectVersionMetadataColumns;
}
@Override @Override
public String getArtifactMetadataFamilyName() public String getArtifactMetadataFamilyName( )
{ {
return artifactMetadataFamilyName; return artifactMetadataFamilyName;
} }
@Override @Override
public String getMetadataFacetFamilyName() public String getMetadataFacetFamilyName( )
{ {
return metadataFacetFamilyName; return metadataFacetFamilyName;
} }
@Override @Override
public String getMailingListFamilyName() public String getMailingListFamilyName( )
{ {
return mailingListFamilyName; return mailingListFamilyName;
} }
@Override @Override
public String getLicenseFamilyName() public String getLicenseFamilyName( )
{ {
return licenseFamilyName; return licenseFamilyName;
} }
@Override @Override
public String getDependencyFamilyName() public String getDependencyFamilyName( )
{ {
return dependencyFamilyName; return dependencyFamilyName;
} }
@Override @Override
public String getChecksumFamilyName() { public String getChecksumFamilyName( )
{
return checksumFamilyName; return checksumFamilyName;
} }
@Override
public DriverConfigLoader getConfigLoader( )
{
return configLoader;
}
@Override
public String getKeyspaceName( )
{
return keyspaceName;
}
} }

View File

@ -32,6 +32,7 @@ public enum ColumnNames
NAMESPACE_ID( "namespaceId" ), NAMESPACE_ID( "namespaceId" ),
PROJECT_ID( "projectId" ), PROJECT_ID( "projectId" ),
PROJECT_VERSION( "projectVersion" ), PROJECT_VERSION( "projectVersion" ),
PROJECT_PROPERTIES("projectProperties"),
KEY( "facetKey" ), KEY( "facetKey" ),
VALUE( "value" ), VALUE( "value" ),
ID( "id" ), ID( "id" ),
@ -41,6 +42,7 @@ public enum ColumnNames
PROJECT( "project" ), PROJECT( "project" ),
FILE_LAST_MODIFIED( "fileLastModified" ), FILE_LAST_MODIFIED( "fileLastModified" ),
VERSION( "version" ), VERSION( "version" ),
VERSION_PROPERTIES("versionProperties"),
GROUP_ID( "groupId" ), GROUP_ID( "groupId" ),
ARTIFACT_ID( "artifactId" ), ARTIFACT_ID( "artifactId" ),
DESCRIPTION( "description" ), DESCRIPTION( "description" ),

View File

@ -19,6 +19,7 @@ package org.apache.archiva.metadata.repository.cassandra;
* under the License. * under the License.
*/ */
import com.datastax.oss.driver.api.core.CqlSession;
import org.apache.archiva.metadata.model.MetadataFacetFactory; import org.apache.archiva.metadata.model.MetadataFacetFactory;
import org.apache.archiva.metadata.repository.AbstractMetadataRepositoryTest; import org.apache.archiva.metadata.repository.AbstractMetadataRepositoryTest;
import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.MetadataRepository;
@ -28,22 +29,32 @@ import org.apache.archiva.metadata.repository.RepositorySessionFactory;
import org.apache.archiva.metadata.repository.cassandra.model.ProjectVersionMetadataModel; import org.apache.archiva.metadata.repository.cassandra.model.ProjectVersionMetadataModel;
import org.easymock.EasyMock; import org.easymock.EasyMock;
import org.easymock.IMocksControl; import org.easymock.IMocksControl;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.truncate;
import static com.datastax.oss.driver.api.querybuilder.SchemaBuilder.dropTable;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* @author Olivier Lamy * @author Olivier Lamy
*/ */
@ExtendWith( SpringExtension.class )
@TestInstance( TestInstance.Lifecycle.PER_CLASS )
public class CassandraMetadataRepositoryTest public class CassandraMetadataRepositoryTest
extends AbstractMetadataRepositoryTest extends AbstractMetadataRepositoryTest
{ {
@ -59,6 +70,9 @@ public class CassandraMetadataRepositoryTest
IMocksControl sessionControl; IMocksControl sessionControl;
RepositorySession session; RepositorySession session;
long cTime;
int testNum = 0;
AtomicBoolean clearedTables = new AtomicBoolean( false );
@Override @Override
@ -73,13 +87,14 @@ public class CassandraMetadataRepositoryTest
return cmr; return cmr;
} }
@Before @BeforeEach
@Override public void setUp( TestInfo testInfo )
public void setUp()
throws Exception throws Exception
{ {
cTime = System.currentTimeMillis( );
System.err.println( "Setting up "+(testNum++) + " - " + testInfo.getDisplayName() );
super.setUp(); super.setUp();
System.err.println( "Setting up 2 " + testInfo.getDisplayName( ) + " - " + (System.currentTimeMillis( ) - cTime) );
assertMaxTries =1; assertMaxTries =1;
assertRetrySleepMs=10; assertRetrySleepMs=10;
@ -104,7 +119,12 @@ public class CassandraMetadataRepositoryTest
sessionFactoryControl.replay(); sessionFactoryControl.replay();
clearReposAndNamespace( cassandraArchivaManager ); if (!clearedTables.get())
{
clearReposAndNamespace( cassandraArchivaManager );
clearedTables.set( true );
}
System.err.println( "Finished setting up "+testInfo.getDisplayName() + " - " + (System.currentTimeMillis( ) - cTime) );
} }
/** /**
@ -139,44 +159,44 @@ public class CassandraMetadataRepositoryTest
} }
@After @AfterEach
public void shutdown() public void shutdown(TestInfo testInfo)
throws Exception throws Exception
{ {
System.err.println( "Shutting down " + testInfo.getDisplayName( ) + " - " + ( System.currentTimeMillis( ) - cTime ) );
clearReposAndNamespace( cassandraArchivaManager ); clearReposAndNamespace( cassandraArchivaManager );
clearedTables.set( true );
super.tearDown(); super.tearDown();
System.err.println( "Shutting down finished" + testInfo.getDisplayName( ) + " - " + ( System.currentTimeMillis( ) - cTime ) );
} }
static void clearReposAndNamespace( CassandraArchivaManager cassandraArchivaManager ) static void clearReposAndNamespace( CassandraArchivaManager cassandraArchivaManager )
throws Exception throws Exception
{ {
cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(), if (cassandraArchivaManager!=null)
cassandraArchivaManager.getProjectFamilyName() ); {
CqlSession session = cassandraArchivaManager.getSession( );
cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(), {
cassandraArchivaManager.getNamespaceFamilyName() ); List<String> tables = Arrays.asList(
cassandraArchivaManager.getProjectFamilyName( ),
cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(), cassandraArchivaManager.getNamespaceFamilyName( ),
cassandraArchivaManager.getRepositoryFamilyName() ); cassandraArchivaManager.getRepositoryFamilyName( ),
cassandraArchivaManager.getProjectVersionMetadataFamilyName( ),
cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(), cassandraArchivaManager.getArtifactMetadataFamilyName( ),
cassandraArchivaManager.getProjectVersionMetadataFamilyName() ); cassandraArchivaManager.getMetadataFacetFamilyName( ),
cassandraArchivaManager.getMailingListFamilyName( ),
cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(), cassandraArchivaManager.getLicenseFamilyName( ),
cassandraArchivaManager.getArtifactMetadataFamilyName() ); cassandraArchivaManager.getDependencyFamilyName( )
);
cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(), for ( String table : tables )
cassandraArchivaManager.getMetadataFacetFamilyName() ); {
session.execute( truncate( table ).build( ) );
cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(), }
cassandraArchivaManager.getMailingListFamilyName() );
cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
cassandraArchivaManager.getLicenseFamilyName() );
cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
cassandraArchivaManager.getDependencyFamilyName() );
}
} else {
System.err.println( "cassandraArchivaManager is null" );
}
} }
} }

View File

@ -23,13 +23,14 @@ import org.apache.archiva.metadata.model.ProjectMetadata;
import org.apache.archiva.metadata.repository.cassandra.model.Namespace; import org.apache.archiva.metadata.repository.cassandra.model.Namespace;
import org.apache.archiva.metadata.repository.cassandra.model.Repository; import org.apache.archiva.metadata.repository.cassandra.model.Repository;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -39,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
/** /**
* @author Olivier Lamy * @author Olivier Lamy
*/ */
@RunWith( ArchivaSpringJUnit4ClassRunner.class ) @ExtendWith( SpringExtension.class )
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } ) @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
public class RepositoriesNamespaceTest public class RepositoriesNamespaceTest
{ {
@ -53,7 +54,7 @@ public class RepositoriesNamespaceTest
CassandraMetadataRepository cmr; CassandraMetadataRepository cmr;
@Before @BeforeEach
public void setup() public void setup()
throws Exception throws Exception
{ {
@ -65,7 +66,7 @@ public class RepositoriesNamespaceTest
CassandraMetadataRepositoryTest.clearReposAndNamespace( cassandraArchivaManager ); CassandraMetadataRepositoryTest.clearReposAndNamespace( cassandraArchivaManager );
} }
@After @AfterEach
public void shutdown() public void shutdown()
throws Exception throws Exception
{ {

View File

@ -35,7 +35,7 @@
<logger name="org.apache.archiva.metadata.repository.cassandra" level="debug"/> <logger name="org.apache.archiva.metadata.repository.cassandra" level="debug"/>
<root level="info" includeLocation="true"> <root level="debug" includeLocation="true">
<appender-ref ref="console"/> <appender-ref ref="console"/>
</root> </root>
</loggers> </loggers>

View File

@ -27,14 +27,13 @@ import org.apache.archiva.metadata.repository.AbstractMetadataRepositoryTest;
import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.archiva.metadata.repository.MetadataService; import org.apache.archiva.metadata.repository.MetadataService;
import org.apache.archiva.metadata.repository.RepositorySessionFactory; import org.apache.archiva.metadata.repository.RepositorySessionFactory;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Ignore; import org.junit.jupiter.api.Disabled;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.List; import java.util.List;
import java.util.Map;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -58,7 +57,7 @@ public class FileMetadataRepositoryTest
return this.sessionFactory; return this.sessionFactory;
} }
@Before @BeforeEach
@Override @Override
public void setUp() public void setUp()
throws Exception throws Exception
@ -81,7 +80,7 @@ public class FileMetadataRepositoryTest
} }
@Override @Override
@Ignore @Disabled
public void testGetArtifactsByProjectVersionMetadata() public void testGetArtifactsByProjectVersionMetadata()
throws Exception throws Exception
{ {
@ -89,7 +88,7 @@ public class FileMetadataRepositoryTest
} }
@Override @Override
@Ignore @Disabled
public void testGetArtifactsByProjectVersionMetadataNoRepository() public void testGetArtifactsByProjectVersionMetadataNoRepository()
throws Exception throws Exception
{ {
@ -97,7 +96,7 @@ public class FileMetadataRepositoryTest
} }
@Override @Override
@Ignore @Disabled
public void testGetArtifactsByProjectVersionMetadataAllRepositories() public void testGetArtifactsByProjectVersionMetadataAllRepositories()
throws Exception throws Exception
{ {
@ -105,7 +104,7 @@ public class FileMetadataRepositoryTest
} }
@Override @Override
@Ignore @Disabled
public void testGetArtifactsByMetadataAllRepositories() public void testGetArtifactsByMetadataAllRepositories()
throws Exception throws Exception
{ {
@ -113,7 +112,7 @@ public class FileMetadataRepositoryTest
} }
@Override @Override
@Ignore @Disabled
public void testGetArtifactsByPropertySingleResult() public void testGetArtifactsByPropertySingleResult()
throws Exception throws Exception
{ {
@ -121,7 +120,7 @@ public class FileMetadataRepositoryTest
} }
@Override @Override
@Ignore @Disabled
public void testSearchArtifactsByKey() public void testSearchArtifactsByKey()
throws Exception throws Exception
{ {
@ -129,7 +128,7 @@ public class FileMetadataRepositoryTest
} }
@Override @Override
@Ignore @Disabled
public void testSearchArtifactsByKeyExact() public void testSearchArtifactsByKeyExact()
throws Exception throws Exception
{ {
@ -137,7 +136,7 @@ public class FileMetadataRepositoryTest
} }
@Override @Override
@Ignore @Disabled
public void testSearchArtifactsFullText() public void testSearchArtifactsFullText()
throws Exception throws Exception
{ {
@ -145,7 +144,7 @@ public class FileMetadataRepositoryTest
} }
@Override @Override
@Ignore @Disabled
public void testSearchArtifactsFullTextExact() public void testSearchArtifactsFullTextExact()
throws Exception throws Exception
{ {
@ -153,7 +152,7 @@ public class FileMetadataRepositoryTest
} }
@Override @Override
@Ignore @Disabled
public void testSearchArtifactsByFacetKeyAllRepos() public void testSearchArtifactsByFacetKeyAllRepos()
throws Exception throws Exception
{ {
@ -161,7 +160,7 @@ public class FileMetadataRepositoryTest
} }
@Override @Override
@Ignore @Disabled
public void testSearchArtifactsByFacetKey() public void testSearchArtifactsByFacetKey()
throws Exception throws Exception
{ {
@ -169,7 +168,7 @@ public class FileMetadataRepositoryTest
} }
@Override @Override
@Ignore @Disabled
public void testSearchArtifactsFullTextByFacet() public void testSearchArtifactsFullTextByFacet()
throws Exception throws Exception
{ {

View File

@ -23,17 +23,14 @@ import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.MetadataFacetFactory; import org.apache.archiva.metadata.model.MetadataFacetFactory;
import org.apache.archiva.metadata.repository.AbstractMetadataRepositoryTest; import org.apache.archiva.metadata.repository.AbstractMetadataRepositoryTest;
import org.apache.archiva.metadata.repository.DefaultMetadataResolver; import org.apache.archiva.metadata.repository.DefaultMetadataResolver;
import org.apache.archiva.metadata.repository.MetadataRepositoryException;
import org.apache.archiva.metadata.repository.MetadataService; import org.apache.archiva.metadata.repository.MetadataService;
import org.apache.archiva.metadata.repository.MetadataSessionException;
import org.apache.archiva.metadata.repository.RepositorySession; import org.apache.archiva.metadata.repository.RepositorySession;
import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException; import org.apache.jackrabbit.oak.segment.file.InvalidFileStoreVersionException;
import org.junit.AfterClass; import org.junit.jupiter.api.AfterAll;
import org.junit.Before; import org.junit.jupiter.api.BeforeAll;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import javax.jcr.RepositoryException;
import javax.jcr.Session; import javax.jcr.Session;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
@ -67,7 +64,7 @@ public class JcrMetadataRepositoryTest
return sessionFactory; return sessionFactory;
} }
@BeforeClass @BeforeAll
public static void setupSpec( ) throws IOException, InvalidFileStoreVersionException public static void setupSpec( ) throws IOException, InvalidFileStoreVersionException
{ {
Path directory = Paths.get( "target/test-repositories" ); Path directory = Paths.get( "target/test-repositories" );
@ -89,7 +86,7 @@ public class JcrMetadataRepositoryTest
} }
@Before @BeforeEach
@Override @Override
public void setUp() throws Exception public void setUp() throws Exception
{ {
@ -106,7 +103,7 @@ public class JcrMetadataRepositoryTest
} }
} }
@AfterClass @AfterAll
public static void stopSpec( ) public static void stopSpec( )
throws Exception throws Exception
{ {

View File

@ -1800,6 +1800,12 @@
<version>${junit.jupiter.version}</version> <version>${junit.jupiter.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.easymock</groupId> <groupId>org.easymock</groupId>