]> source.dussan.org Git - archiva.git/commitdiff
move to cassandra 2.0
authorOlivier Lamy <olamy@apache.org>
Mon, 18 Nov 2013 05:47:25 +0000 (05:47 +0000)
committerOlivier Lamy <olamy@apache.org>
Mon, 18 Nov 2013 05:47:25 +0000 (05:47 +0000)
compress huge string in cassandra

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1542899 13f79535-47bb-0310-9956-ffa450edef68

13 files changed:
archiva-modules/plugins/metadata-store-cassandra/pom.xml
archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraEntityManagerFactory.java
archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java
archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/DefaultCassandraEntityManagerFactory.java
archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/ArtifactMetadataModel.java
archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/MetadataFacetModel.java
archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/Namespace.java
archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/Project.java
archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/ProjectVersionMetadataModel.java
archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/Repository.java
archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java
archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/RepositoriesNamespaceTest.java
archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java

index 9ecdc5d8b38921e23380d6838ce463f7212c1bf4..c064bec24b0f19cbd465b8dcd85a6543cd259346 100644 (file)
   <name>Archiva Core Plugins :: Cassandra JPA Storage for Metadata</name>
 
   <properties>
-    <cassandraVersion>1.2.9</cassandraVersion>
-    <astyanax.version>1.56.43</astyanax.version>
+    <!--
+    <cassandraVersion>1.2.11</cassandraVersion>
+    -->
+    <cassandraVersion>2.0.2</cassandraVersion>
+    <astyanax.version>1.56.44</astyanax.version>
   </properties>
 
   <dependencies>
                 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
             </Import-Package>
           </instructions>
         </configuration>
       <plugin>
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>cassandra-maven-plugin</artifactId>
-        <version>1.2.5-1-SNAPSHOT</version>
+        <version>2.0.0-1-SNAPSHOT</version>
         <executions>
           <execution>
             <id>start-cassandra</id>
index dcb18d7420c9a5c6fa0b1a498bf3db956be124cc..e198cab94995bd4f6ac8dee57b526606b5c68b99 100644 (file)
@@ -35,6 +35,12 @@ public interface CassandraEntityManagerFactory
 {
     Keyspace getKeyspace();
 
+    void start();
+
+    void shutdown();
+
+    boolean started();
+
     EntityManager<Repository, String> getRepositoryEntityManager();
 
     EntityManager<Namespace, String> getNamespaceEntityManager();
index 50de1dd877af0f31e2c7056444ae589f9f1e90d0..35003334b1d79e45d697f85c0f5c85cabf9a73e3 100644 (file)
@@ -73,14 +73,14 @@ public class CassandraMetadataRepository
     private CassandraEntityManagerFactory cassandraEntityManagerFactory;
 
     public CassandraMetadataRepository( Map<String, MetadataFacetFactory> metadataFacetFactories,
-                                        ArchivaConfiguration configuration, CassandraEntityManagerFactory cassandraEntityManagerFactory )
+                                        ArchivaConfiguration configuration,
+                                        CassandraEntityManagerFactory cassandraEntityManagerFactory )
     {
         this.metadataFacetFactories = metadataFacetFactories;
         this.configuration = configuration;
         this.cassandraEntityManagerFactory = cassandraEntityManagerFactory;
     }
 
-    
 
     public EntityManager<Repository, String> getRepositoryEntityManager()
     {
@@ -314,7 +314,25 @@ public class CassandraMetadataRepository
     {
         try
         {
-            final Set<String> namespaces = new HashSet<String>();
+
+            //final List<Namespace> namespaceList =
+            //    getNamespaceEntityManager().find( "SELECT name FROM namespace WHERE repository.id='"+ repoId + "'" );
+
+            //final Set<String> namespaces = new HashSet<String>( namespaceList.size() );
+
+            final Set<String> namespaces = new HashSet<String>( );
+
+            /*
+            for ( Namespace namespace : namespaceList )
+            {
+                String name = namespace.getName();
+                if ( StringUtils.isNotEmpty( name ) )
+                {
+                    namespaces.add( StringUtils.substringBefore( name, "." ) );
+                }
+            }
+            */
+
 
             getNamespaceEntityManager().visitAll( new Function<Namespace, Boolean>()
             {
@@ -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<Namespace> namespaces = getNamespaceEntityManager().find( query );
 
-            final Set<Namespace> namespaces = new HashSet<Namespace>();
+            //final Set<Namespace> namespaces = new HashSet<Namespace>();
+            final Set<String> namespaces = new HashSet<String>();
 
             getNamespaceEntityManager().visitAll( new Function<Namespace, Boolean>()
             {
@@ -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<Namespace>( namespaces ) );
 
+            /*
+
+            repository.setNamespaces( new ArrayList<Namespace>( namespaces ) );
             if ( repository == null || repository.getNamespaces().isEmpty() )
             {
                 return Collections.emptyList();
             }
+
             List<String> namespaceIds = new ArrayList<String>( 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<String>( 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 )
         {
index a03ae394c676a7c53e2a81294e762785947f31be..c70e82f730cd2e3a6eedae8eee92b8d2443ee7aa 100644 (file)
@@ -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<Repository, String> repositoryEntityManager;
 
     private EntityManager<Namespace, String> 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<String, Object> options = ImmutableMap.<String, Object>builder().put( "strategy_options",
                                                                                            ImmutableMap.<String, Object>builder().put(
@@ -146,7 +149,7 @@ public class DefaultCassandraEntityManagerFactory
         {
             repositoryEntityManager =
                 new DefaultEntityManager.Builder<Repository, String>().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<Namespace, String>().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<Project, String>().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<ArtifactMetadataModel, String>().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<MetadataFacetModel, String>().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<ProjectVersionMetadataModel, String>().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
     {
index c9960aeda05ad088105c64e9756806aba9127a1a..fbb7d95f9c89978ee82cd7f419c608477466b8a9 100644 (file)
@@ -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;
         }
     }
 
index 2cb101521b5e4cfe9b16153e1b9e49f2e6c70b25..a77c29ddae93f60dff3c57a9eb2fd0716baee02a 100644 (file)
@@ -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;
         }
     }
 }
index fb42b0b8df8a7d719a332c55f0eb1262f69ee326..c5eb24d613e504febb7effd84bf7452043ec0adc 100644 (file)
@@ -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 );
         }
     }
 }
index 4a167a42076e4a880d4aea65f964ea18571d2565..4ac0a0ad9c12cf179f5b05b41702024d9841832d 100644 (file)
@@ -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 );
         }
     }
 }
index 0a4adacaeff52e4ba0de999498c95cc6f984982d..8d8b57b1acaab61b1c6e7cee7558df70b4cf2d41 100644 (file)
@@ -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<License> licenses = new ArrayList<License>();
 
-    @Column(name = "mailingLists")
+    @Column( name = "mailingLists" )
     private List<MailingList> mailingLists = new ArrayList<MailingList>();
 
-    @Column(name = "dependencies")
+    @Column( name = "dependencies" )
     private List<Dependency> dependencies = new ArrayList<Dependency>();
 
-    @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 );
         }
     }
 }
index 25f8281dac7ec93b92b226a5c89a02a4f2b8d63a..b3c684c0ea44359740d7f9ae32ed2e25096f8efd 100644 (file)
@@ -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<Namespace> namespaces = new ArrayList<Namespace>();
+    //private transient List<Namespace> namespaces = new ArrayList<Namespace>();
 
     public Repository()
     {
@@ -79,7 +81,7 @@ public class Repository
         this.name = name;
     }
 
-
+    /*
     public List<Namespace> 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();
     }
index 07594649310fd1876abc936a071f3e39a1213d0b..1361585db6752f6a8d9f677b27f62f6b747bc16e 100644 (file)
@@ -85,28 +85,45 @@ public class CassandraMetadataRepositoryTest
     protected void clearReposAndNamespace()
         throws Exception
     {
+        /*
         List<Project> projects = cmr.getProjectEntityManager().getAll();
 
         cmr.getProjectEntityManager().remove( projects );
+        */
+        cmr.getProjectEntityManager().truncate();
 
+        /*
         List<Namespace> namespaces = cmr.getNamespaceEntityManager().getAll();
 
         cmr.getNamespaceEntityManager().remove( namespaces );
+        */
+        cmr.getNamespaceEntityManager().truncate();
 
+        /*
         List<Repository> repositories = cmr.getRepositoryEntityManager().getAll();
 
         cmr.getRepositoryEntityManager().remove( repositories );
+        */
+        cmr.getRepositoryEntityManager().truncate();
 
+        /*
         List<ArtifactMetadataModel> artifactMetadataModels = cmr.getArtifactMetadataModelEntityManager().getAll();
         cmr.getArtifactMetadataModelEntityManager().remove( artifactMetadataModels );
+        */
+        cmr.getArtifactMetadataModelEntityManager().truncate();
 
+        /*
         List<MetadataFacetModel> metadataFacetModels = cmr.getMetadataFacetModelEntityManager().getAll();
         cmr.getMetadataFacetModelEntityManager().remove( metadataFacetModels );
+        */
+        cmr.getMetadataFacetModelEntityManager().truncate();
 
+        /*
         List<ProjectVersionMetadataModel> projectVersionMetadataModels =
             cmr.getProjectVersionMetadataModelEntityManager().getAll();
         cmr.getProjectVersionMetadataModelEntityManager().remove( projectVersionMetadataModels );
-
+        */
+        cmr.getProjectVersionMetadataModelEntityManager().truncate();
 
     }
 
index 0ba18cab1f861878bd6e3d91546d03b5a08fa11f..32fb9eb187a3cbe48c838c3f37a9cd8ead524811 100644 (file)
@@ -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<Project> projects = cmr.getProjectEntityManager().getAll();
-
         cmr.getProjectEntityManager().remove( projects );
+        */
+        cmr.getProjectEntityManager().truncate();
 
+        /*
         List<Namespace> namespaces = cmr.getNamespaceEntityManager().getAll();
-
         cmr.getNamespaceEntityManager().remove( namespaces );
+        */
+        cmr.getNamespaceEntityManager().truncate();
 
+        /*
         List<Repository> repositories = cmr.getRepositoryEntityManager().getAll();
-
         cmr.getRepositoryEntityManager().remove( repositories );
-
+        */
+        cmr.getRepositoryEntityManager().truncate();
     }
 }
index e93405b555e84a5f390fdf31ed64ea62d4fd79a8..1ce90027dd971a809b60f1bcce6faa6ce67ae068 100644 (file)
@@ -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;