From 8553f7687f2801cbe3f3eae69f9f31b755a5dc21 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Mon, 18 Nov 2013 05:47:25 +0000 Subject: [PATCH] move to cassandra 2.0 compress huge string in cassandra git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1542899 13f79535-47bb-0310-9956-ffa450edef68 --- .../plugins/metadata-store-cassandra/pom.xml | 14 +++-- .../CassandraEntityManagerFactory.java | 6 +++ .../CassandraMetadataRepository.java | 51 ++++++++++++++----- .../DefaultCassandraEntityManagerFactory.java | 42 ++++++++++++--- .../model/ArtifactMetadataModel.java | 47 ++++++++++++----- .../cassandra/model/MetadataFacetModel.java | 42 ++++++++------- .../repository/cassandra/model/Namespace.java | 26 ++++------ .../repository/cassandra/model/Project.java | 8 ++- .../model/ProjectVersionMetadataModel.java | 42 ++++++++------- .../cassandra/model/Repository.java | 13 +++-- .../CassandraMetadataRepositoryTest.java | 19 ++++++- .../cassandra/RepositoriesNamespaceTest.java | 22 +++++--- .../DefaultRepositoryStatisticsManager.java | 4 +- 13 files changed, 229 insertions(+), 107 deletions(-) diff --git a/archiva-modules/plugins/metadata-store-cassandra/pom.xml b/archiva-modules/plugins/metadata-store-cassandra/pom.xml index 9ecdc5d8b..c064bec24 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/pom.xml +++ b/archiva-modules/plugins/metadata-store-cassandra/pom.xml @@ -31,8 +31,11 @@ Archiva Core Plugins :: Cassandra JPA Storage for Metadata - 1.2.9 - 1.56.43 + + 2.0.2 + 1.56.44 @@ -249,7 +252,10 @@ org.apache.commons.lang;version="[2.4,3)", org.slf4j;resolution:=optional, org.springframework.context, - org.springframework.stereotype + org.springframework.stereotype, + com.netflix.astyanax.serializers, + org.apache.commons.codec.binary, + org.apache.commons.io @@ -277,7 +283,7 @@ org.codehaus.mojo cassandra-maven-plugin - 1.2.5-1-SNAPSHOT + 2.0.0-1-SNAPSHOT start-cassandra diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraEntityManagerFactory.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraEntityManagerFactory.java index dcb18d742..e198cab94 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraEntityManagerFactory.java +++ b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraEntityManagerFactory.java @@ -35,6 +35,12 @@ public interface CassandraEntityManagerFactory { Keyspace getKeyspace(); + void start(); + + void shutdown(); + + boolean started(); + EntityManager getRepositoryEntityManager(); EntityManager getNamespaceEntityManager(); diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java index 50de1dd87..35003334b 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java +++ b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java @@ -73,14 +73,14 @@ public class CassandraMetadataRepository private CassandraEntityManagerFactory cassandraEntityManagerFactory; public CassandraMetadataRepository( Map metadataFacetFactories, - ArchivaConfiguration configuration, CassandraEntityManagerFactory cassandraEntityManagerFactory ) + ArchivaConfiguration configuration, + CassandraEntityManagerFactory cassandraEntityManagerFactory ) { this.metadataFacetFactories = metadataFacetFactories; this.configuration = configuration; this.cassandraEntityManagerFactory = cassandraEntityManagerFactory; } - public EntityManager getRepositoryEntityManager() { @@ -314,7 +314,25 @@ public class CassandraMetadataRepository { try { - final Set namespaces = new HashSet(); + + //final List namespaceList = + // getNamespaceEntityManager().find( "SELECT name FROM namespace WHERE repository.id='"+ repoId + "'" ); + + //final Set namespaces = new HashSet( namespaceList.size() ); + + final Set namespaces = new HashSet( ); + + /* + for ( Namespace namespace : namespaceList ) + { + String name = namespace.getName(); + if ( StringUtils.isNotEmpty( name ) ) + { + namespaces.add( StringUtils.substringBefore( name, "." ) ); + } + } + */ + getNamespaceEntityManager().visitAll( new Function() { @@ -322,8 +340,8 @@ public class CassandraMetadataRepository @Override public Boolean apply( Namespace namespace ) { - if ( namespace != null && namespace.getRepository() != null && StringUtils.equalsIgnoreCase( repoId, - namespace.getRepository().getId() ) ) + if ( namespace != null && namespace.getRepository() != null + && StringUtils.equalsIgnoreCase( repoId, namespace.getRepository().getId() ) ) { String name = namespace.getName(); if ( StringUtils.isNotEmpty( name ) ) @@ -413,7 +431,8 @@ public class CassandraMetadataRepository //List namespaces = getNamespaceEntityManager().find( query ); - final Set namespaces = new HashSet(); + //final Set namespaces = new HashSet(); + final Set namespaces = new HashSet(); getNamespaceEntityManager().visitAll( new Function() { @@ -424,18 +443,21 @@ public class CassandraMetadataRepository if ( namespace != null && namespace.getRepository() != null && StringUtils.equalsIgnoreCase( repoId, namespace.getRepository().getId() ) ) { - namespaces.add( namespace ); + namespaces.add( namespace.getId() ); } return Boolean.TRUE; } } ); - repository.setNamespaces( new ArrayList( namespaces ) ); + /* + + repository.setNamespaces( new ArrayList( namespaces ) ); if ( repository == null || repository.getNamespaces().isEmpty() ) { return Collections.emptyList(); } + List namespaceIds = new ArrayList( repository.getNamespaces().size() ); for ( Namespace n : repository.getNamespaces() ) @@ -444,7 +466,10 @@ public class CassandraMetadataRepository } logger.debug( "getNamespaces for repository '{}' found {}", repoId, namespaceIds.size() ); + return namespaceIds; + */ + return new ArrayList( namespaces ); } catch ( PersistenceException e ) { @@ -671,7 +696,8 @@ public class CassandraMetadataRepository key = new ProjectVersionMetadataModel.KeyBuilder().withRepository( repositoryId ).withNamespace( namespace ).withProjectId( projectId ).withId( projectVersion ).build(); - ProjectVersionMetadataModel projectVersionMetadataModel = getProjectVersionMetadataModelEntityManager().get( key ); + ProjectVersionMetadataModel projectVersionMetadataModel = + getProjectVersionMetadataModelEntityManager().get( key ); if ( projectVersionMetadataModel == null ) { @@ -805,7 +831,8 @@ public class CassandraMetadataRepository key = new ProjectVersionMetadataModel.KeyBuilder().withRepository( repositoryId ).withNamespace( namespaceId ).withProjectId( projectId ).withId( versionMetadata.getId() ).build(); - ProjectVersionMetadataModel projectVersionMetadataModel = getProjectVersionMetadataModelEntityManager().get( key ); + ProjectVersionMetadataModel projectVersionMetadataModel = + getProjectVersionMetadataModelEntityManager().get( key ); if ( projectVersionMetadataModel == null ) { @@ -824,7 +851,6 @@ public class CassandraMetadataRepository projectVersionMetadataModel.setDependencies( versionMetadata.getDependencies() ); projectVersionMetadataModel.setLicenses( versionMetadata.getLicenses() ); - try { getProjectVersionMetadataModelEntityManager().put( projectVersionMetadataModel ); @@ -1379,7 +1405,8 @@ public class CassandraMetadataRepository String key = new ProjectVersionMetadataModel.KeyBuilder().withRepository( repoId ).withNamespace( namespace ).withProjectId( projectId ).withId( projectVersion ).build(); - ProjectVersionMetadataModel projectVersionMetadataModel = getProjectVersionMetadataModelEntityManager().get( key ); + ProjectVersionMetadataModel projectVersionMetadataModel = + getProjectVersionMetadataModelEntityManager().get( key ); if ( projectVersionMetadataModel == null ) { diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/DefaultCassandraEntityManagerFactory.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/DefaultCassandraEntityManagerFactory.java index a03ae394c..c70e82f73 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/DefaultCassandraEntityManagerFactory.java +++ b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/DefaultCassandraEntityManagerFactory.java @@ -27,7 +27,6 @@ import com.netflix.astyanax.connectionpool.exceptions.ConnectionException; import com.netflix.astyanax.connectionpool.exceptions.NotFoundException; import com.netflix.astyanax.connectionpool.impl.ConnectionPoolConfigurationImpl; import com.netflix.astyanax.connectionpool.impl.ConnectionPoolType; -import com.netflix.astyanax.connectionpool.impl.CountingConnectionPoolMonitor; import com.netflix.astyanax.connectionpool.impl.Slf4jConnectionPoolMonitorImpl; import com.netflix.astyanax.ddl.KeyspaceDefinition; import com.netflix.astyanax.entitystore.DefaultEntityManager; @@ -46,6 +45,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; import javax.inject.Inject; import javax.persistence.PersistenceException; import java.util.Properties; @@ -73,6 +73,8 @@ public class DefaultCassandraEntityManagerFactory private Keyspace keyspace; + private boolean started = false; + private EntityManager repositoryEntityManager; private EntityManager namespaceEntityManager; @@ -101,9 +103,10 @@ public class DefaultCassandraEntityManagerFactory cassandraHost + ":" + cassandraPort ) ).withConnectionPoolMonitor( new Slf4jConnectionPoolMonitorImpl() ).buildKeyspace( ThriftFamilyFactory.getInstance() ); - keyspaceContext.start(); + this.start(); keyspace = keyspaceContext.getClient(); + //Partitioner partitioner = keyspace.getPartitioner(); ImmutableMap options = ImmutableMap.builder().put( "strategy_options", ImmutableMap.builder().put( @@ -146,7 +149,7 @@ public class DefaultCassandraEntityManagerFactory { repositoryEntityManager = new DefaultEntityManager.Builder().withEntityType( Repository.class ).withKeyspace( - keyspace ).build(); + keyspace ).withAutoCommit( true ).build(); boolean exists = columnFamilyExists( "repository" ); // TODO very basic test we must test model change too if ( !exists ) @@ -156,7 +159,7 @@ public class DefaultCassandraEntityManagerFactory namespaceEntityManager = new DefaultEntityManager.Builder().withEntityType( Namespace.class ).withKeyspace( - keyspace ).build(); + keyspace ).withAutoCommit( true ).build(); exists = columnFamilyExists( "namespace" ); if ( !exists ) @@ -166,7 +169,7 @@ public class DefaultCassandraEntityManagerFactory projectEntityManager = new DefaultEntityManager.Builder().withEntityType( Project.class ).withKeyspace( - keyspace ).build(); + keyspace ).withAutoCommit( true ).build(); exists = columnFamilyExists( "project" ); if ( !exists ) @@ -176,7 +179,7 @@ public class DefaultCassandraEntityManagerFactory artifactMetadataModelEntityManager = new DefaultEntityManager.Builder().withEntityType( - ArtifactMetadataModel.class ).withKeyspace( keyspace ).build(); + ArtifactMetadataModel.class ).withAutoCommit( true ).withKeyspace( keyspace ).build(); exists = columnFamilyExists( "artifactmetadatamodel" ); if ( !exists ) @@ -186,7 +189,7 @@ public class DefaultCassandraEntityManagerFactory metadataFacetModelEntityManager = new DefaultEntityManager.Builder().withEntityType( - MetadataFacetModel.class ).withKeyspace( keyspace ).build(); + MetadataFacetModel.class ).withAutoCommit( true ).withKeyspace( keyspace ).build(); exists = columnFamilyExists( "metadatafacetmodel" ); if ( !exists ) @@ -196,7 +199,7 @@ public class DefaultCassandraEntityManagerFactory projectVersionMetadataModelEntityManager = new DefaultEntityManager.Builder().withEntityType( - ProjectVersionMetadataModel.class ).withKeyspace( keyspace ).build(); + ProjectVersionMetadataModel.class ).withAutoCommit( true ).withKeyspace( keyspace ).build(); exists = columnFamilyExists( "projectversionmetadatamodel" ); if ( !exists ) @@ -217,6 +220,29 @@ public class DefaultCassandraEntityManagerFactory } } + public void start() + { + keyspaceContext.start(); + started = true; + } + + @PreDestroy + public void shutdown() + { + if ( keyspaceContext != null ) + { + keyspaceContext.shutdown(); + started = false; + } + } + + + @Override + public boolean started() + { + return started; + } + private boolean columnFamilyExists( String columnFamilyName ) throws ConnectionException { diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/ArtifactMetadataModel.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/ArtifactMetadataModel.java index c9960aeda..fbb7d95f9 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/ArtifactMetadataModel.java +++ b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/ArtifactMetadataModel.java @@ -19,6 +19,10 @@ package org.apache.archiva.metadata.repository.cassandra.model; * under the License. */ +import com.netflix.astyanax.entitystore.Serializer; +import com.netflix.astyanax.serializers.LongSerializer; +import org.apache.archiva.metadata.repository.cassandra.CassandraUtils; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; @@ -37,39 +41,51 @@ public class ArtifactMetadataModel // repositoryId + namespaceId + project + projectVersion + id @Id + @Serializer( HugeStringSerializer.class ) private String artifactMetadataModelId; - @Column(name = "id") + @Column( name = "id" ) + @Serializer( HugeStringSerializer.class ) private String id; - @Column(name = "repositoryId") + @Column( name = "repositoryId" ) + @Serializer( HugeStringSerializer.class ) private String repositoryId; - @Column(name = "namespace") + @Column( name = "namespace" ) + @Serializer( HugeStringSerializer.class ) private String namespace; - @Column(name = "project") + @Column( name = "project" ) + @Serializer( HugeStringSerializer.class ) private String project; - @Column(name = "projectVersion") + @Column( name = "projectVersion" ) + @Serializer( HugeStringSerializer.class ) private String projectVersion; - @Column(name = "version") + @Column( name = "version" ) + @Serializer( HugeStringSerializer.class ) private String version; - @Column(name = "fileLastModified") + @Column( name = "fileLastModified" ) + @Serializer( LongSerializer.class ) private long fileLastModified; - @Column(name = "size") + @Column( name = "size" ) + @Serializer( LongSerializer.class ) private long size; - @Column(name = "md5") + @Column( name = "md5" ) + @Serializer( HugeStringSerializer.class ) private String md5; - @Column(name = "sha1") + @Column( name = "sha1" ) + @Serializer( HugeStringSerializer.class ) private String sha1; - @Column(name = "whenGathered") + @Column( name = "whenGathered" ) + @Serializer( LongSerializer.class ) private long whenGathered; public ArtifactMetadataModel() @@ -323,8 +339,13 @@ public class ArtifactMetadataModel { //repositoryId + namespaceId + project + projectVersion + id // FIXME add some controls - long hash = this.repositoryId.hashCode() + this.namespaceId.hashCode() + this.project.hashCode() + this.projectVersion.hashCode() + this.id.hashCode(); - return Long.toString( hash ); + + String str = + CassandraUtils.generateKey( this.repositoryId, this.namespaceId, this.project, this.projectVersion, + this.id ); + + //return Long.toString( str.hashCode() ); + return str; } } diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/MetadataFacetModel.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/MetadataFacetModel.java index 2cb101521..a77c29dda 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/MetadataFacetModel.java +++ b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/MetadataFacetModel.java @@ -19,6 +19,10 @@ package org.apache.archiva.metadata.repository.cassandra.model; * under the License. */ +import com.netflix.astyanax.entitystore.Serializer; +import com.netflix.astyanax.serializers.GzipStringSerializer; +import org.apache.archiva.metadata.repository.cassandra.CassandraUtils; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; @@ -33,22 +37,27 @@ public class MetadataFacetModel { // id is repositoryId + namespaceId + projectId + facetId + name + mapKey @Id - @Column(name = "id") + @Column( name = "id" ) + @Serializer( HugeStringSerializer.class ) private String id; - @Column(name = "artifactMetadataModel") + @Column( name = "artifactMetadataModel" ) private ArtifactMetadataModel artifactMetadataModel; - @Column(name = "facetId") + @Column( name = "facetId" ) + @Serializer( HugeStringSerializer.class ) private String facetId; - @Column(name = "name") - private String name; - - @Column(name = "key") + @Column( name = "key" ) + @Serializer( HugeStringSerializer.class ) private String key; - @Column(name = "value") + @Column( name = "name" ) + @Serializer( HugeStringSerializer.class ) + private String name; + + @Column( name = "value" ) + @Serializer( HugeStringSerializer.class ) private String value; public MetadataFacetModel() @@ -220,16 +229,13 @@ public class MetadataFacetModel // FIXME add some controls // getArtifactMetadataModelId can have no namespace, no project and no projectid for statistics // only repositoryId with artifactMetadataModel - long hash = - ( this.artifactMetadataModel == null - ? this.repositoryId.hashCode() - : Long.parseLong( this.artifactMetadataModel.getArtifactMetadataModelId() ) ) - + this.facetId.hashCode() - + ( this.name == null ? 0 : this.name.hashCode() ) - + ( this.key == null ? 0 : this.key.hashCode() ); - - String hashStr = Long.toString( hash ); - return hashStr; + String str = CassandraUtils.generateKey( this.artifactMetadataModel == null + ? this.repositoryId + : this.artifactMetadataModel.getArtifactMetadataModelId(), + this.facetId, this.name, this.key ); + + //return Long.toString( str.hashCode() ); + return str; } } } diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/Namespace.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/Namespace.java index fb42b0b8d..c5eb24d61 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/Namespace.java +++ b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/Namespace.java @@ -19,6 +19,9 @@ package org.apache.archiva.metadata.repository.cassandra.model; * under the License. */ +import com.netflix.astyanax.entitystore.Serializer; +import org.apache.archiva.metadata.repository.cassandra.CassandraUtils; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; @@ -34,16 +37,16 @@ public class Namespace implements Serializable { - private static final long serialVersionUID = 1L; - @Id - @Column(name = "id") + @Column( name = "id" ) + @Serializer( HugeStringSerializer.class ) private String id; - @Column(name = "name") + @Column( name = "name" ) + @Serializer( HugeStringSerializer.class ) private String name; - @Column(name = "repository") + @Column( name = "repository" ) private Repository repository; //@ManyToOne(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER) @@ -94,17 +97,6 @@ public class Namespace this.repository = repository; } - /* - public String getRepositoryId() - { - return repositoryId; - } - - public void setRepositoryId( String repositoryId ) - { - this.repositoryId = repositoryId; - }*/ - @Override public boolean equals( Object o ) { @@ -184,7 +176,7 @@ public class Namespace public String build() { // FIXME add some controls - return this.repositoryId + "-" + this.namespace; + return CassandraUtils.generateKey( this.repositoryId, this.namespace ); } } } diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/Project.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/Project.java index 4a167a420..4ac0a0ad9 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/Project.java +++ b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/Project.java @@ -19,6 +19,9 @@ package org.apache.archiva.metadata.repository.cassandra.model; * under the License. */ +import com.netflix.astyanax.entitystore.Serializer; +import org.apache.archiva.metadata.repository.cassandra.CassandraUtils; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; @@ -33,9 +36,11 @@ public class Project { @Id @Column( name = "projectKey" ) + @Serializer( HugeStringSerializer.class ) private String projectKey; @Column( name = "projectId" ) + @Serializer( HugeStringSerializer.class ) private String projectId; @@ -157,7 +162,8 @@ public class Project public String build() { // FIXME add some controls - return new Namespace.KeyBuilder().withNamespace( this.namespace ).build() + "-" + this.projectId; + return CassandraUtils.generateKey( new Namespace.KeyBuilder().withNamespace( this.namespace ).build(), + this.projectId ); } } } diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/ProjectVersionMetadataModel.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/ProjectVersionMetadataModel.java index 0a4adacae..8d8b57b1a 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/ProjectVersionMetadataModel.java +++ b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/ProjectVersionMetadataModel.java @@ -19,6 +19,7 @@ package org.apache.archiva.metadata.repository.cassandra.model; * under the License. */ +import com.netflix.astyanax.entitystore.Serializer; import org.apache.archiva.metadata.model.CiManagement; import org.apache.archiva.metadata.model.Dependency; import org.apache.archiva.metadata.model.IssueManagement; @@ -26,6 +27,7 @@ import org.apache.archiva.metadata.model.License; import org.apache.archiva.metadata.model.MailingList; import org.apache.archiva.metadata.model.Organization; import org.apache.archiva.metadata.model.Scm; +import org.apache.archiva.metadata.repository.cassandra.CassandraUtils; import javax.persistence.Column; import javax.persistence.Entity; @@ -41,52 +43,58 @@ public class ProjectVersionMetadataModel { // repositoryId + namespace + projectId + id (version) @Id + @Serializer( HugeStringSerializer.class ) private String rowId; - @Column(name = "namespace") + @Column( name = "namespace" ) private Namespace namespace; /** * id is the version */ - @Column(name = "id") + @Column( name = "id" ) + @Serializer( HugeStringSerializer.class ) private String id; - @Column(name = "projectId") + @Column( name = "projectId" ) + @Serializer( HugeStringSerializer.class ) private String projectId; - @Column(name = "url") + @Column( name = "url" ) + @Serializer( HugeStringSerializer.class ) private String url; - @Column(name = "name") + @Column( name = "name" ) + @Serializer( HugeStringSerializer.class ) private String name; - @Column(name = "description") + @Column( name = "description" ) + @Serializer( HugeStringSerializer.class ) private String description; - @Column(name = "organization") + @Column( name = "organization" ) private Organization organization; - @Column(name = "issueManagement") + @Column( name = "issueManagement" ) private IssueManagement issueManagement; - @Column(name = "scm") + @Column( name = "scm" ) private Scm scm; - @Column(name = "ciManagement") + @Column( name = "ciManagement" ) private CiManagement ciManagement; // FIXME store those values in a separate table - @Column(name = "licenses") + @Column( name = "licenses" ) private List licenses = new ArrayList(); - @Column(name = "mailingLists") + @Column( name = "mailingLists" ) private List mailingLists = new ArrayList(); - @Column(name = "dependencies") + @Column( name = "dependencies" ) private List dependencies = new ArrayList(); - @Column(name = "incomplete") + @Column( name = "incomplete" ) private boolean incomplete; public String getProjectId() @@ -346,11 +354,7 @@ public class ProjectVersionMetadataModel public String build() { // FIXME add some controls - long hash = - this.repositoryId.hashCode() + this.namespace.hashCode() + this.projectId.hashCode() + ( this.id == null - ? 0 - : +this.id.hashCode() ); - return Long.toString( hash ); + return CassandraUtils.generateKey( this.repositoryId, this.namespace, this.projectId, this.id ); } } } diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/Repository.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/Repository.java index 25f8281da..b3c684c0e 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/Repository.java +++ b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/Repository.java @@ -19,6 +19,8 @@ package org.apache.archiva.metadata.repository.cassandra.model; * under the License. */ +import com.netflix.astyanax.entitystore.Serializer; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; @@ -37,16 +39,16 @@ public class Repository implements Serializable { - private static final long serialVersionUID = 1L; - @Id @Column( name = "id" ) + @Serializer( HugeStringSerializer.class ) private String id; @Column(name = "name") + @Serializer( HugeStringSerializer.class ) private String name; - private transient List namespaces = new ArrayList(); + //private transient List namespaces = new ArrayList(); public Repository() { @@ -79,7 +81,7 @@ public class Repository this.name = name; } - + /* public List getNamespaces() { if ( this.namespaces == null ) @@ -93,6 +95,7 @@ public class Repository { this.namespaces = namespaces; } + */ @Override public boolean equals( Object o ) @@ -129,7 +132,7 @@ public class Repository final StringBuilder sb = new StringBuilder( "Repository{" ); sb.append( "id='" ).append( id ).append( '\'' ); sb.append( ", name='" ).append( name ).append( '\'' ); - sb.append( ", namespaces=" ).append( namespaces ); + //sb.append( ", namespaces=" ).append( namespaces ); sb.append( '}' ); return sb.toString(); } diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java b/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java index 075946493..1361585db 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java +++ b/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java @@ -85,28 +85,45 @@ public class CassandraMetadataRepositoryTest protected void clearReposAndNamespace() throws Exception { + /* List projects = cmr.getProjectEntityManager().getAll(); cmr.getProjectEntityManager().remove( projects ); + */ + cmr.getProjectEntityManager().truncate(); + /* List namespaces = cmr.getNamespaceEntityManager().getAll(); cmr.getNamespaceEntityManager().remove( namespaces ); + */ + cmr.getNamespaceEntityManager().truncate(); + /* List repositories = cmr.getRepositoryEntityManager().getAll(); cmr.getRepositoryEntityManager().remove( repositories ); + */ + cmr.getRepositoryEntityManager().truncate(); + /* List artifactMetadataModels = cmr.getArtifactMetadataModelEntityManager().getAll(); cmr.getArtifactMetadataModelEntityManager().remove( artifactMetadataModels ); + */ + cmr.getArtifactMetadataModelEntityManager().truncate(); + /* List metadataFacetModels = cmr.getMetadataFacetModelEntityManager().getAll(); cmr.getMetadataFacetModelEntityManager().remove( metadataFacetModels ); + */ + cmr.getMetadataFacetModelEntityManager().truncate(); + /* List projectVersionMetadataModels = cmr.getProjectVersionMetadataModelEntityManager().getAll(); cmr.getProjectVersionMetadataModelEntityManager().remove( projectVersionMetadataModels ); - + */ + cmr.getProjectVersionMetadataModelEntityManager().truncate(); } diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/RepositoriesNamespaceTest.java b/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/RepositoriesNamespaceTest.java index 0ba18cab1..32fb9eb18 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/RepositoriesNamespaceTest.java +++ b/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/RepositoriesNamespaceTest.java @@ -57,10 +57,12 @@ public class RepositoriesNamespaceTest public void setup() throws Exception { - cmr = new CassandraMetadataRepository( null, null, cassandraEntityManagerFactory ); + if ( !cassandraEntityManagerFactory.started() ) + { + cassandraEntityManagerFactory.start(); + } clearReposAndNamespace(); - } @After @@ -68,6 +70,7 @@ public class RepositoriesNamespaceTest throws Exception { clearReposAndNamespace(); + cassandraEntityManagerFactory.shutdown(); } @@ -91,7 +94,7 @@ public class RepositoriesNamespaceTest Assertions.assertThat( cmr.getRepositories() ).isNotEmpty().hasSize( 1 ); Assertions.assertThat( cmr.getNamespaces( "release" ) ).isNotEmpty().hasSize( 1 ); - n = cmr.getNamespaceEntityManager().get( "release" + "-" + "org" ); + n = cmr.getNamespaceEntityManager().get( "release" + CassandraUtils.SEPARATOR + "org" ); Assertions.assertThat( n ).isNotNull(); Assertions.assertThat( n.getRepository() ).isNotNull(); @@ -117,17 +120,22 @@ public class RepositoriesNamespaceTest protected void clearReposAndNamespace() throws Exception { + /* List projects = cmr.getProjectEntityManager().getAll(); - cmr.getProjectEntityManager().remove( projects ); + */ + cmr.getProjectEntityManager().truncate(); + /* List namespaces = cmr.getNamespaceEntityManager().getAll(); - cmr.getNamespaceEntityManager().remove( namespaces ); + */ + cmr.getNamespaceEntityManager().truncate(); + /* List repositories = cmr.getRepositoryEntityManager().getAll(); - cmr.getRepositoryEntityManager().remove( repositories ); - + */ + cmr.getRepositoryEntityManager().truncate(); } } diff --git a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java index e93405b55..1ce90027d 100644 --- a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java +++ b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java @@ -81,8 +81,8 @@ public class DefaultRepositoryStatisticsManager { String name = scans.get( scans.size() - 1 ); RepositoryStatistics repositoryStatistics = - (RepositoryStatistics) metadataRepository.getMetadataFacet( repositoryId, RepositoryStatistics.FACET_ID, - name ); + RepositoryStatistics.class.cast( metadataRepository.getMetadataFacet( repositoryId, RepositoryStatistics.FACET_ID, + name )); stopWatch.stop(); log.debug( "time to find last RepositoryStatistics: {} ms", stopWatch.getTime() ); return repositoryStatistics; -- 2.39.5