]> source.dussan.org Git - archiva.git/commitdiff
implement cassandra record of dependencies
authorOlivier Lamy <olamy@apache.org>
Wed, 26 Mar 2014 02:40:51 +0000 (02:40 +0000)
committerOlivier Lamy <olamy@apache.org>
Wed, 26 Mar 2014 02:40:51 +0000 (02:40 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1581638 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraArchivaManager.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/DefaultCassandraArchivaManager.java
archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java

index cbd576d9b51a4d9ead4228fc95385644197dfec0..6e47944329ccac108cc3d38cb3cba98adbb6f8c8 100644 (file)
@@ -40,6 +40,7 @@ import me.prettyprint.hector.api.query.RangeSlicesQuery;
 import org.apache.archiva.configuration.ArchivaConfiguration;
 import org.apache.archiva.metadata.model.ArtifactMetadata;
 import org.apache.archiva.metadata.model.CiManagement;
+import org.apache.archiva.metadata.model.Dependency;
 import org.apache.archiva.metadata.model.FacetedMetadata;
 import org.apache.archiva.metadata.model.IssueManagement;
 import org.apache.archiva.metadata.model.License;
@@ -108,6 +109,8 @@ public class CassandraMetadataRepository
 
     private final ColumnFamilyTemplate<String, String> licenseTemplate;
 
+    private final ColumnFamilyTemplate<String, String> dependencyTemplate;
+
     public CassandraMetadataRepository( Map<String, MetadataFacetFactory> metadataFacetFactories,
                                         ArchivaConfiguration configuration,
                                         CassandraArchivaManager cassandraArchivaManager )
@@ -154,6 +157,13 @@ public class CassandraMetadataRepository
                                                                                //
                                                                                StringSerializer.get(), //
                                                                                StringSerializer.get() );
+
+        this.dependencyTemplate =
+            new ThriftColumnFamilyTemplate<String, String>( cassandraArchivaManager.getKeyspace(), //
+                                                            cassandraArchivaManager.getDependencyFamilyName(),
+                                                            //
+                                                            StringSerializer.get(), //
+                                                            StringSerializer.get() );
     }
 
 
@@ -902,13 +912,12 @@ public class CassandraMetadataRepository
                 }
             }
 
-            if ( versionMetadata.getMailingLists() != null )
-            {
-                recordMailingList( key, versionMetadata.getMailingLists() );
-            }
+            recordMailingList( key, versionMetadata.getMailingLists() );
 
             recordLicenses( key, versionMetadata.getLicenses() );
 
+            recordDependencies( key, versionMetadata.getDependencies() );
+
             MutationResult mutationResult = mutator.execute();
         }
         else
@@ -973,6 +982,9 @@ public class CassandraMetadataRepository
             removeLicenses( key );
             recordLicenses( key, versionMetadata.getLicenses() );
 
+            removeDependencies( key );
+            recordDependencies( key, versionMetadata.getDependencies() );
+
             projectVersionMetadataModelTemplate.update( updater );
 
         }
@@ -1047,7 +1059,7 @@ public class CassandraMetadataRepository
         }
         projectVersionMetadata.setMailingLists( getMailingLists( key ) );
         projectVersionMetadata.setLicenses( getLicenses( key ) );
-        // FIXME complete collections !!
+        projectVersionMetadata.setDependencies( getDependencies( key ) );
         // facets
 
         StringSerializer ss = StringSerializer.get();
@@ -1204,9 +1216,9 @@ public class CassandraMetadataRepository
             addInsertion( licenseMutator, keyLicense, cfLicense, "projectVersionMetadataModel.key",
                           projectVersionMetadataKey );
 
-            addInsertion( licenseMutator, keyLicense, cfLicense, "license.name", license.getName() );
+            addInsertion( licenseMutator, keyLicense, cfLicense, "name", license.getName() );
 
-            addInsertion( licenseMutator, keyLicense, cfLicense, "license.url", license.getUrl() );
+            addInsertion( licenseMutator, keyLicense, cfLicense, "url", license.getUrl() );
 
         }
         licenseMutator.execute();
@@ -1245,13 +1257,108 @@ public class CassandraMetadataRepository
         {
             ColumnFamilyResult<String, String> columnFamilyResult = this.licenseTemplate.queryColumns( row.getKey() );
 
-            licenses.add( new License( columnFamilyResult.getString( "license.name" ),
-                                       columnFamilyResult.getString( "license.url" ) ) );
+            licenses.add(
+                new License( columnFamilyResult.getString( "name" ), columnFamilyResult.getString( "url" ) ) );
         }
 
         return licenses;
     }
 
+
+    protected void recordDependencies( String projectVersionMetadataKey, List<Dependency> dependencies )
+    {
+
+        if ( dependencies == null || dependencies.isEmpty() )
+        {
+            return;
+        }
+        Mutator<String> dependencyMutator = this.dependencyTemplate.createMutator();
+
+        for ( Dependency dependency : dependencies )
+        {
+            // we don't care about the key as the real used one with the projectVersionMetadata
+            String keyDependency = UUID.randomUUID().toString();
+            String cfDependency = cassandraArchivaManager.getDependencyFamilyName();
+
+            addInsertion( dependencyMutator, keyDependency, cfDependency, "projectVersionMetadataModel.key",
+                          projectVersionMetadataKey );
+
+            addInsertion( dependencyMutator, keyDependency, cfDependency, "classifier", dependency.getClassifier() );
+
+            addInsertion( dependencyMutator, keyDependency, cfDependency, "optional",
+                          Boolean.toString( dependency.isOptional() ) );
+
+            addInsertion( dependencyMutator, keyDependency, cfDependency, "scope", dependency.getScope() );
+
+            addInsertion( dependencyMutator, keyDependency, cfDependency, "systemPath", dependency.getSystemPath() );
+
+            addInsertion( dependencyMutator, keyDependency, cfDependency, "type", dependency.getType() );
+
+            addInsertion( dependencyMutator, keyDependency, cfDependency, "artifactId", dependency.getArtifactId() );
+
+            addInsertion( dependencyMutator, keyDependency, cfDependency, "groupId", dependency.getGroupId() );
+
+            addInsertion( dependencyMutator, keyDependency, cfDependency, "version", dependency.getVersion() );
+
+        } dependencyMutator.execute();
+    }
+
+    protected void removeDependencies( String projectVersionMetadataKey )
+    {
+        StringSerializer ss = StringSerializer.get();
+        QueryResult<OrderedRows<String, String, String>> result =
+            HFactory.createRangeSlicesQuery( cassandraArchivaManager.getKeyspace(), ss, ss, ss ) //
+                .setColumnFamily( cassandraArchivaManager.getDependencyFamilyName() ) //
+                .setColumnNames( "groupId" ) //
+                .setRowCount( Integer.MAX_VALUE ) //
+                .addEqualsExpression( "projectVersionMetadataModel.key", projectVersionMetadataKey ) //
+                .execute();
+        for ( Row<String, String, String> row : result.get() )
+        {
+            this.dependencyTemplate.deleteRow( row.getKey() );
+        }
+    }
+
+    protected List<Dependency> getDependencies( String projectVersionMetadataKey )
+    {
+        List<Dependency> dependencies = new ArrayList<Dependency>();
+
+        StringSerializer ss = StringSerializer.get();
+        QueryResult<OrderedRows<String, String, String>> result =
+            HFactory.createRangeSlicesQuery( cassandraArchivaManager.getKeyspace(), ss, ss, ss ) //
+                .setColumnFamily( cassandraArchivaManager.getDependencyFamilyName() ) //
+                .setColumnNames( "projectVersionMetadataModel.key" ) //
+                .setRowCount( Integer.MAX_VALUE ) //
+                .addEqualsExpression( "projectVersionMetadataModel.key", projectVersionMetadataKey ) //
+                .execute();
+
+        for ( Row<String, String, String> row : result.get() )
+        {
+            ColumnFamilyResult<String, String> columnFamilyResult = this.dependencyTemplate.queryColumns( row.getKey() );
+
+            Dependency dependency = new Dependency();
+            dependency.setClassifier( columnFamilyResult.getString( "classifier" ) );
+
+            dependency.setOptional( Boolean.parseBoolean( columnFamilyResult.getString( "optional" ) ) );
+
+            dependency.setScope( columnFamilyResult.getString( "scope" ) );
+
+            dependency.setSystemPath( columnFamilyResult.getString( "systemPath" ) );
+
+            dependency.setType( columnFamilyResult.getString( "type" ) );
+
+            dependency.setArtifactId( columnFamilyResult.getString( "artifactId" ) );
+
+            dependency.setGroupId( columnFamilyResult.getString( "groupId" ) );
+
+            dependency.setVersion( columnFamilyResult.getString( "version" ) );
+
+            dependencies.add( dependency );
+        }
+
+        return dependencies;
+    }
+
     @Override
     public void updateArtifact( String repositoryId, String namespaceId, String projectId, String projectVersion,
                                 ArtifactMetadata artifactMeta )
index eb9399adbe9e175e6df2208e3dc5c2517b586693..978ffdb9b08daf67d21e9e67b212c5329460398a 100644 (file)
@@ -85,6 +85,8 @@ public class DefaultCassandraArchivaManager
 
     private String licenseFamilyName = "license";
 
+    private String dependencyFamilyName = "dependency";
+
 
     @PostConstruct
     public void initialize()
@@ -401,6 +403,25 @@ public class DefaultCassandraArchivaManager
 
         }
 
+        // dependency table
+        {
+            final ColumnFamilyDefinition dependencyCf =
+                HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), //
+                                                       getDependencyFamilyName(), //
+                                                       ComparatorType.UTF8TYPE );
+            cfds.add( dependencyCf );
+
+            // creating indexes for cql query
+
+            BasicColumnDefinition projectVersionMetadataIdColumn = new BasicColumnDefinition();
+            projectVersionMetadataIdColumn.setName( StringSerializer.get().toByteBuffer( "projectVersionMetadataId" ) );
+            projectVersionMetadataIdColumn.setIndexName( "projectVersionMetadataId" );
+            projectVersionMetadataIdColumn.setIndexType( ColumnIndexType.KEYS );
+            projectVersionMetadataIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
+            dependencyCf.addColumnDefinition( projectVersionMetadataIdColumn );
+
+        }
+
         // 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 )
@@ -483,4 +504,9 @@ public class DefaultCassandraArchivaManager
     {
         return licenseFamilyName;
     }
+
+    public String getDependencyFamilyName()
+    {
+        return dependencyFamilyName;
+    }
 }
index 2cd6a51fb1bd1f67b44603b78cb103f55eb7d272..e43f5afcef1083a01b6cd3c7efc91944e459e2e1 100644 (file)
@@ -100,6 +100,9 @@ public class CassandraMetadataRepositoryTest
         cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
                                                        cassandraArchivaManager.getLicenseFamilyName() );
 
+        cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
+                                                       cassandraArchivaManager.getDependencyFamilyName() );
+
     }
 
 }