Dependency cleanup of metadata-store-cassandra

This commit is contained in:
Martin Stockhammer 2020-06-20 19:54:20 +02:00
parent a2637688e3
commit 20257a2d59
6 changed files with 95 additions and 76 deletions

View File

@ -50,15 +50,50 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.archiva</groupId> <groupId>org.apache.archiva</groupId>
<artifactId>archiva-test-utils</artifactId> <artifactId>archiva-common</artifactId>
<version>${project.version}</version> </dependency>
<scope>test</scope> <dependency>
<exclusions> <groupId>org.apache.archiva</groupId>
<exclusion> <artifactId>archiva-configuration</artifactId>
<groupId>org.slf4j</groupId> </dependency>
<artifactId>slf4j-simple</artifactId> <dependency>
</exclusion> <groupId>org.apache.archiva</groupId>
</exclusions> <artifactId>archiva-policies</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-xml-tools</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-repository-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-checksum</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>metadata-model</artifactId>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency> </dependency>
<dependency> <dependency>
@ -154,6 +189,18 @@
<!-- TEST Scope --> <!-- TEST Scope -->
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-test-utils</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency> <dependency>
<groupId>org.easymock</groupId> <groupId>org.easymock</groupId>
<artifactId>easymock</artifactId> <artifactId>easymock</artifactId>
@ -185,17 +232,7 @@
<version>${log4j.version}</version> <version>${log4j.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.archiva.components.cache</groupId>
<artifactId>archiva-components-spring-cache-ehcache</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -19,8 +19,6 @@ package org.apache.archiva.metadata.repository.cassandra;
* under the License. * under the License.
*/ */
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import me.prettyprint.cassandra.serializers.LongSerializer; import me.prettyprint.cassandra.serializers.LongSerializer;
import me.prettyprint.cassandra.serializers.StringSerializer; import me.prettyprint.cassandra.serializers.StringSerializer;
import me.prettyprint.cassandra.service.template.ColumnFamilyResult; import me.prettyprint.cassandra.service.template.ColumnFamilyResult;
@ -38,7 +36,6 @@ import me.prettyprint.hector.api.mutation.Mutator;
import me.prettyprint.hector.api.query.QueryResult; import me.prettyprint.hector.api.query.QueryResult;
import me.prettyprint.hector.api.query.RangeSlicesQuery; import me.prettyprint.hector.api.query.RangeSlicesQuery;
import org.apache.archiva.checksum.ChecksumAlgorithm; import org.apache.archiva.checksum.ChecksumAlgorithm;
import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.metadata.QueryParameter; import org.apache.archiva.metadata.QueryParameter;
import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.CiManagement; import org.apache.archiva.metadata.model.CiManagement;
@ -73,7 +70,18 @@ import org.slf4j.LoggerFactory;
import java.time.Instant; import java.time.Instant;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.util.*; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Spliterator;
import java.util.UUID;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -95,8 +103,6 @@ public class CassandraMetadataRepository
private static final String ARTIFACT_METADATA_MODEL_KEY = "artifactMetadataModel.key"; private static final String ARTIFACT_METADATA_MODEL_KEY = "artifactMetadataModel.key";
private Logger logger = LoggerFactory.getLogger( getClass() ); private Logger logger = LoggerFactory.getLogger( getClass() );
private ArchivaConfiguration configuration;
private final CassandraArchivaManager cassandraArchivaManager; private final CassandraArchivaManager cassandraArchivaManager;
private final ColumnFamilyTemplate<String, String> projectVersionMetadataTemplate; private final ColumnFamilyTemplate<String, String> projectVersionMetadataTemplate;
@ -120,11 +126,9 @@ public class CassandraMetadataRepository
private final StringSerializer ss = StringSerializer.get(); private final StringSerializer ss = StringSerializer.get();
public CassandraMetadataRepository( MetadataService metadataService, public CassandraMetadataRepository( MetadataService metadataService,
ArchivaConfiguration configuration,
CassandraArchivaManager cassandraArchivaManager ) CassandraArchivaManager cassandraArchivaManager )
{ {
super( metadataService ); super( metadataService );
this.configuration = configuration;
this.cassandraArchivaManager = cassandraArchivaManager; this.cassandraArchivaManager = cassandraArchivaManager;
this.keyspace = cassandraArchivaManager.getKeyspace(); this.keyspace = cassandraArchivaManager.getKeyspace();
@ -468,7 +472,7 @@ public class CassandraMetadataRepository
.addEqualsExpression( REPOSITORY_NAME.toString(), repoId ) // .addEqualsExpression( REPOSITORY_NAME.toString(), repoId ) //
.execute(); .execute();
Set<String> namespaces = new HashSet<String>( result.get().getCount() ); Set<String> namespaces = new HashSet<>( result.get( ).getCount( ) );
for ( Row<String, String, String> row : result.get() ) for ( Row<String, String, String> row : result.get() )
{ {
@ -553,11 +557,7 @@ public class CassandraMetadataRepository
.execute(); .execute();
// project exists ? if yes return nothing to update here // project exists ? if yes return nothing to update here
if ( result.get().getCount() > 0 ) if ( result.get( ).getCount( ) <= 0 )
{
return;
}
else
{ {
Namespace namespace = updateOrAddNamespace( repositoryId, projectMetadata.getNamespace() ); Namespace namespace = updateOrAddNamespace( repositoryId, projectMetadata.getNamespace() );
@ -587,7 +587,7 @@ public class CassandraMetadataRepository
.addEqualsExpression( NAMESPACE_ID.toString(), namespace ) // .addEqualsExpression( NAMESPACE_ID.toString(), namespace ) //
.execute(); .execute();
final Set<String> projects = new HashSet<String>( result.get().getCount() ); final Set<String> projects = new HashSet<>( result.get( ).getCount( ) );
for ( Row<String, String, String> row : result.get() ) for ( Row<String, String, String> row : result.get() )
{ {
@ -660,7 +660,7 @@ public class CassandraMetadataRepository
return Collections.emptyList(); return Collections.emptyList();
} }
Set<String> versions = new HashSet<String>( count ); Set<String> versions = new HashSet<>( count );
for ( Row<String, String, String> orderedRows : result.get() ) for ( Row<String, String, String> orderedRows : result.get() )
{ {
@ -757,7 +757,7 @@ public class CassandraMetadataRepository
.addEqualsExpression( PROJECT_VERSION.toString(), versionMetadata.getId() ) // .addEqualsExpression( PROJECT_VERSION.toString(), versionMetadata.getId() ) //
.execute(); .execute();
ProjectVersionMetadataModel projectVersionMetadataModel = null; ProjectVersionMetadataModel projectVersionMetadataModel;
boolean creation = true; boolean creation = true;
if ( result.get().getCount() > 0 ) if ( result.get().getCount() > 0 )
{ {
@ -853,7 +853,7 @@ public class CassandraMetadataRepository
recordDependencies( key, versionMetadata.getDependencies(), repositoryId ); recordDependencies( key, versionMetadata.getDependencies(), repositoryId );
MutationResult mutationResult = mutator.execute(); mutator.execute();
} }
else else
{ {
@ -1021,12 +1021,7 @@ public class CassandraMetadataRepository
{ {
ColumnSlice<String, String> columnSlice = row.getColumnSlice(); ColumnSlice<String, String> columnSlice = row.getColumnSlice();
String facetId = getStringValue( columnSlice, FACET_ID.toString() ); String facetId = getStringValue( columnSlice, FACET_ID.toString() );
Map<String, String> metaValues = metadataFacetsPerFacetIds.get( facetId ); Map<String, String> metaValues = metadataFacetsPerFacetIds.computeIfAbsent( facetId, k -> new HashMap<>( ) );
if ( metaValues == null )
{
metaValues = new HashMap<>();
metadataFacetsPerFacetIds.put( facetId, metaValues );
}
metaValues.put( getStringValue( columnSlice, KEY.toString() ), getStringValue( columnSlice, VALUE.toString() ) ); metaValues.put( getStringValue( columnSlice, KEY.toString() ), getStringValue( columnSlice, VALUE.toString() ) );
} }
@ -1034,7 +1029,7 @@ public class CassandraMetadataRepository
{ {
for ( Map.Entry<String, Map<String, String>> entry : metadataFacetsPerFacetIds.entrySet() ) for ( Map.Entry<String, Map<String, String>> entry : metadataFacetsPerFacetIds.entrySet() )
{ {
MetadataFacetFactory metadataFacetFactory = getFacetFactory( entry.getKey() ); MetadataFacetFactory<?> metadataFacetFactory = getFacetFactory( entry.getKey() );
if ( metadataFacetFactory != null ) if ( metadataFacetFactory != null )
{ {
MetadataFacet metadataFacet = metadataFacetFactory.createMetadataFacet(); MetadataFacet metadataFacet = metadataFacetFactory.createMetadataFacet();
@ -1381,13 +1376,13 @@ public class CassandraMetadataRepository
private Map<String, String> mapChecksums(Map<ChecksumAlgorithm,String> checksums) { private Map<String, String> mapChecksums(Map<ChecksumAlgorithm,String> checksums) {
return checksums.entrySet().stream().collect(Collectors.toMap( return checksums.entrySet().stream().collect(Collectors.toMap(
e -> e.getKey().name(), e -> e.getValue() e -> e.getKey().name(), Map.Entry::getValue
)); ));
} }
private Map<ChecksumAlgorithm, String> mapChecksumsReverse(Map<String,String> checksums) { private Map<ChecksumAlgorithm, String> mapChecksumsReverse(Map<String,String> checksums) {
return checksums.entrySet().stream().collect(Collectors.toMap( return checksums.entrySet().stream().collect(Collectors.toMap(
e -> ChecksumAlgorithm.valueOf(e.getKey()), e -> e.getValue() e -> ChecksumAlgorithm.valueOf(e.getKey()), Map.Entry::getValue
)); ));
} }
@ -1736,10 +1731,6 @@ public class CassandraMetadataRepository
return null; return null;
} }
final String facetId = metadataFacetFactory.getFacetId( ); final String facetId = metadataFacetFactory.getFacetId( );
if ( metadataFacetFactory == null )
{
return null;
}
QueryResult<OrderedRows<String, String, String>> result = HFactory // QueryResult<OrderedRows<String, String, String>> result = HFactory //
.createRangeSlicesQuery( keyspace, ss, ss, ss ) // .createRangeSlicesQuery( keyspace, ss, ss, ss ) //
@ -2025,7 +2016,7 @@ public class CassandraMetadataRepository
} }
} }
return new ArrayList(artifactMetadataMap.values()); return new ArrayList<>(artifactMetadataMap.values());
} }
/** /**
@ -2064,7 +2055,7 @@ public class CassandraMetadataRepository
return Collections.emptyList(); return Collections.emptyList();
} }
List<ArtifactMetadata> artifactMetadatas = new LinkedList<ArtifactMetadata>(); List<ArtifactMetadata> artifactMetadatas = new LinkedList<>( );
// TODO doing multiple queries, there should be a way to get all the artifactMetadatas for any number of // TODO doing multiple queries, there should be a way to get all the artifactMetadatas for any number of
// projects // projects
@ -2117,7 +2108,7 @@ public class CassandraMetadataRepository
return Collections.emptyList(); return Collections.emptyList();
} }
List<ArtifactMetadata> artifacts = new LinkedList<ArtifactMetadata>(); List<ArtifactMetadata> artifacts = new LinkedList<>( );
for ( Row<String, String, String> row : result.get() ) for ( Row<String, String, String> row : result.get() )
{ {
@ -2384,21 +2375,15 @@ public class CassandraMetadataRepository
for ( final ArtifactMetadata artifactMetadata : artifactMetadatas ) for ( final ArtifactMetadata artifactMetadata : artifactMetadatas )
{ {
Iterable<MetadataFacetModel> metadataFacetModelIterable = Iterator<MetadataFacetModel> iterator = metadataFacetModels.stream( ).filter( metadataFacetModel -> {
Iterables.filter( metadataFacetModels, new Predicate<MetadataFacetModel>() if ( metadataFacetModel != null )
{ {
@Override return StringUtils.equals( artifactMetadata.getVersion( ),
public boolean apply( MetadataFacetModel metadataFacetModel ) metadataFacetModel.getProjectVersion( ) );
{ }
if ( metadataFacetModel != null ) return false;
{
return StringUtils.equals( artifactMetadata.getVersion(), } ).iterator( );
metadataFacetModel.getProjectVersion() );
}
return false;
}
} );
Iterator<MetadataFacetModel> iterator = metadataFacetModelIterable.iterator();
Map<String, List<MetadataFacetModel>> metadataFacetValuesPerFacetId = new HashMap<>(); Map<String, List<MetadataFacetModel>> metadataFacetValuesPerFacetId = new HashMap<>();
while ( iterator.hasNext() ) while ( iterator.hasNext() )
{ {
@ -2415,7 +2400,7 @@ public class CassandraMetadataRepository
for ( Map.Entry<String, List<MetadataFacetModel>> entry : metadataFacetValuesPerFacetId.entrySet() ) for ( Map.Entry<String, List<MetadataFacetModel>> entry : metadataFacetValuesPerFacetId.entrySet() )
{ {
MetadataFacetFactory metadataFacetFactory = getFacetFactory( entry.getKey() ); MetadataFacetFactory<?> metadataFacetFactory = getFacetFactory( entry.getKey() );
if ( metadataFacetFactory != null ) if ( metadataFacetFactory != null )
{ {
List<MetadataFacetModel> facetModels = entry.getValue(); List<MetadataFacetModel> facetModels = entry.getValue();
@ -2476,7 +2461,7 @@ public class CassandraMetadataRepository
throws MetadataRepositoryException throws MetadataRepositoryException
{ {
// TODO optimize // TODO optimize
List<ArtifactMetadata> artifacts = new LinkedList<ArtifactMetadata>(); List<ArtifactMetadata> artifacts = new LinkedList<>( );
artifacts.addAll( this.getArtifactsByAttribute( session, key, text, repositoryId ) ); artifacts.addAll( this.getArtifactsByAttribute( session, key, text, repositoryId ) );
artifacts.addAll( this.getArtifactsByProjectVersionAttribute( session, key, text, repositoryId ) ); artifacts.addAll( this.getArtifactsByProjectVersionAttribute( session, key, text, repositoryId ) );
return artifacts; return artifacts;

View File

@ -20,21 +20,17 @@ package org.apache.archiva.metadata.repository.cassandra;
*/ */
import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.metadata.model.MetadataFacetFactory;
import org.apache.archiva.metadata.repository.AbstractRepositorySessionFactory; import org.apache.archiva.metadata.repository.AbstractRepositorySessionFactory;
import org.apache.archiva.metadata.repository.MetadataRepositoryException; import org.apache.archiva.metadata.repository.MetadataRepositoryException;
import org.apache.archiva.metadata.repository.MetadataResolver; import org.apache.archiva.metadata.repository.MetadataResolver;
import org.apache.archiva.metadata.repository.MetadataService; import org.apache.archiva.metadata.repository.MetadataService;
import org.apache.archiva.metadata.repository.RepositorySession; import org.apache.archiva.metadata.repository.RepositorySession;
import org.apache.archiva.metadata.repository.RepositorySessionFactory; import org.apache.archiva.metadata.repository.RepositorySessionFactory;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import java.util.HashMap;
import java.util.Map;
/** /**
* @author Olivier Lamy * @author Olivier Lamy
@ -75,7 +71,7 @@ public class CassandraRepositorySessionFactory extends AbstractRepositorySession
public RepositorySession createSession() throws MetadataRepositoryException public RepositorySession createSession() throws MetadataRepositoryException
{ {
CassandraMetadataRepository metadataRepository = CassandraMetadataRepository metadataRepository =
new CassandraMetadataRepository( metadataService, configuration, cassandraArchivaManager ); new CassandraMetadataRepository( metadataService, cassandraArchivaManager );
return new RepositorySession( metadataRepository, metadataResolver ); return new RepositorySession( metadataRepository, metadataResolver );
} }

View File

@ -93,7 +93,7 @@ public class CassandraMetadataRepositoryTest
MetadataService metadataService = new MetadataService( ); MetadataService metadataService = new MetadataService( );
metadataService.setMetadataFacetFactories( factories ); metadataService.setMetadataFacetFactories( factories );
this.cmr = new CassandraMetadataRepository( metadataService, null, cassandraArchivaManager ); this.cmr = new CassandraMetadataRepository( metadataService, cassandraArchivaManager );
sessionFactoryControl = EasyMock.createControl( ); sessionFactoryControl = EasyMock.createControl( );
sessionFactory = sessionFactoryControl.createMock( RepositorySessionFactory.class ); sessionFactory = sessionFactoryControl.createMock( RepositorySessionFactory.class );

View File

@ -57,7 +57,7 @@ public class RepositoriesNamespaceTest
public void setup() public void setup()
throws Exception throws Exception
{ {
cmr = new CassandraMetadataRepository( null, null, cassandraArchivaManager ); cmr = new CassandraMetadataRepository( null, cassandraArchivaManager );
if ( !cassandraArchivaManager.started() ) if ( !cassandraArchivaManager.started() )
{ {
cassandraArchivaManager.start(); cassandraArchivaManager.start();

View File

@ -55,6 +55,7 @@ archiva-modules
metadata-store-file metadata-store-file
audit audit
problem-reports problem-reports
metadata-store-cassandra