archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1580691 - in /archiva/trunk/archiva-modules: metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/ metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/ plugins/metadata-sto...
Date Mon, 24 Mar 2014 01:36:40 GMT
Author: olamy
Date: Mon Mar 24 01:36:39 2014
New Revision: 1580691

URL: http://svn.apache.org/r1580691
Log:
fix checksum search cassandra search

Modified:
    archiva/trunk/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java
    archiva/trunk/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java
    archiva/trunk/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java
    archiva/trunk/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/DefaultCassandraArchivaManager.java
    archiva/trunk/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumer.java

Modified: archiva/trunk/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java?rev=1580691&r1=1580690&r2=1580691&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java
(original)
+++ archiva/trunk/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java
Mon Mar 24 01:36:39 2014
@@ -98,7 +98,7 @@ public interface MetadataRepository
     Collection<String> getRepositories()
         throws MetadataRepositoryException;
 
-    List<ArtifactMetadata> getArtifactsByChecksum( String repositoryId, String checksum
)
+    Collection<ArtifactMetadata> getArtifactsByChecksum( String repositoryId, String
checksum )
         throws MetadataRepositoryException;
 
     void removeArtifact( String repositoryId, String namespace, String project, String version,
String id )

Modified: archiva/trunk/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java?rev=1580691&r1=1580690&r2=1580691&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java
(original)
+++ archiva/trunk/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java
Mon Mar 24 01:36:39 2014
@@ -1164,7 +1164,7 @@ public abstract class AbstractMetadataRe
         ArtifactMetadata artifact = createArtifact();
         repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION,
artifact );
 
-        List<ArtifactMetadata> artifactsByChecksum = repository.getArtifactsByChecksum(
TEST_REPO_ID, "not checksum" );
+        Collection<ArtifactMetadata> artifactsByChecksum = repository.getArtifactsByChecksum(
TEST_REPO_ID, "not checksum" );
         assertEquals( Collections.<ArtifactMetadata>emptyList(), artifactsByChecksum
);
     }
 

Modified: archiva/trunk/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java?rev=1580691&r1=1580690&r2=1580691&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java
(original)
+++ archiva/trunk/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java
Mon Mar 24 01:36:39 2014
@@ -723,7 +723,7 @@ public class CassandraMetadataRepository
         return projectMetadata;
     }
 
-    protected ProjectVersionMetadataModel map( ColumnSlice<String, String> columnSlice
)
+    protected ProjectVersionMetadataModel mapProjectVersionMetadataModel( ColumnSlice<String,
String> columnSlice )
     {
         ProjectVersionMetadataModel projectVersionMetadataModel = new ProjectVersionMetadataModel();
         projectVersionMetadataModel.setId( getStringValue( columnSlice, "id" ) );
@@ -786,7 +786,8 @@ public class CassandraMetadataRepository
         boolean creation = true;
         if ( result.get().getCount() > 0 )
         {
-            projectVersionMetadataModel = map( result.get().getList().get( 0 ).getColumnSlice()
);
+            projectVersionMetadataModel =
+                mapProjectVersionMetadataModel( result.get().getList().get( 0 ).getColumnSlice()
);
             creation = false;
         }
         else
@@ -1675,27 +1676,11 @@ public class CassandraMetadataRepository
         for ( Row<String, String, Long> row : result.get() )
         {
             ColumnSlice<String, Long> columnSlice = row.getColumnSlice();
-            String repositoryName =
-                ss.fromByteBuffer( columnSlice.getColumnByName( "repositoryName" ).getValueBytes()
);
+            String repositoryName = getAsStringValue( columnSlice, "repositoryName" );
             if ( StringUtils.equals( repositoryName, repositoryId ) )
             {
-                ArtifactMetadata artifactMetadata = new ArtifactMetadata();
-                artifactMetadata.setNamespace( getAsStringValue( columnSlice, "namespaceId"
) );
-                artifactMetadata.setSize( getLongValue( columnSlice, "size" ) );
-                artifactMetadata.setId( getAsStringValue( columnSlice, "id" ) );
-                artifactMetadata.setFileLastModified( getLongValue( columnSlice, "fileLastModified"
) );
-                artifactMetadata.setMd5( getAsStringValue( columnSlice, "md5" ) );
-                artifactMetadata.setProject( getAsStringValue( columnSlice, "project" ) );
-                artifactMetadata.setProjectVersion( getAsStringValue( columnSlice, "projectVersion"
) );
-                artifactMetadata.setRepositoryId( repositoryName );
-                artifactMetadata.setSha1( getAsStringValue( columnSlice, "sha1" ) );
-                artifactMetadata.setVersion( getAsStringValue( columnSlice, "version" ) );
-                Long whenGathered = getLongValue( columnSlice, "whenGathered" );
-                if ( whenGathered != null )
-                {
-                    artifactMetadata.setWhenGathered( new Date( whenGathered ) );
-                }
-                artifactMetadatas.add( artifactMetadata );
+
+                artifactMetadatas.add( mapArtifactMetadataLongColumnSlice( columnSlice )
);
             }
         }
 
@@ -1703,6 +1688,27 @@ public class CassandraMetadataRepository
     }
 
 
+    protected ArtifactMetadata mapArtifactMetadataLongColumnSlice( ColumnSlice columnSlice
)
+    {
+        ArtifactMetadata artifactMetadata = new ArtifactMetadata();
+        artifactMetadata.setNamespace( getAsStringValue( columnSlice, "namespaceId" ) );
+        artifactMetadata.setSize( getLongValue( columnSlice, "size" ) );
+        artifactMetadata.setId( getAsStringValue( columnSlice, "id" ) );
+        artifactMetadata.setFileLastModified( getLongValue( columnSlice, "fileLastModified"
) );
+        artifactMetadata.setMd5( getAsStringValue( columnSlice, "md5" ) );
+        artifactMetadata.setProject( getAsStringValue( columnSlice, "project" ) );
+        artifactMetadata.setProjectVersion( getAsStringValue( columnSlice, "projectVersion"
) );
+        artifactMetadata.setRepositoryId( getStringValue( columnSlice, "repositoryName" )
);
+        artifactMetadata.setSha1( getAsStringValue( columnSlice, "sha1" ) );
+        artifactMetadata.setVersion( getAsStringValue( columnSlice, "version" ) );
+        Long whenGathered = getLongValue( columnSlice, "whenGathered" );
+        if ( whenGathered != null )
+        {
+            artifactMetadata.setWhenGathered( new Date( whenGathered ) );
+        }
+        return artifactMetadata;
+    }
+
     protected void populateFacets( final ArtifactMetadata artifactMetadata )
     {
 /*        final List<MetadataFacetModel> metadataFacetModels = new ArrayList<MetadataFacetModel>();
@@ -1760,55 +1766,61 @@ public class CassandraMetadataRepository
     }
 
     @Override
-    public List<ArtifactMetadata> getArtifactsByChecksum( final String repositoryId,
final String checksum )
+    public Collection<ArtifactMetadata> getArtifactsByChecksum( final String repositoryId,
final String checksum )
         throws MetadataRepositoryException
     {
-/*        final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
+        Keyspace keyspace = cassandraArchivaManager.getKeyspace();
+        StringSerializer ss = StringSerializer.get();
 
-        if ( logger.isDebugEnabled() )
-        {
-            logger.debug( "all ArtifactMetadataModel: {}", getArtifactMetadataModelEntityManager().getAll()
);
-        }
+        // cql cannot run or in queries so running twice the query
+        Map<String, ArtifactMetadata> artifactMetadataMap = new HashMap<String,
ArtifactMetadata>();
 
-        // FIXME cql query
-        getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel,
Boolean>()
+        RangeSlicesQuery<String, String, String> query = HFactory //
+            .createRangeSlicesQuery( keyspace, ss, ss, ss ) //
+            .setColumnFamily( cassandraArchivaManager.getArtifactMetadataModelFamilyName()
) //
+            .setColumnNames( "namespaceId", "size", "id", "fileLastModified", "md5", "project",
"projectVersion",
+                             "repositoryName", "version", "whenGathered", "sha1" ); //
+
+        query = query.addEqualsExpression( "sha1", checksum );
+
+        QueryResult<OrderedRows<String, String, String>> result = query.execute();
+
+        for ( Row<String, String, String> row : result.get() )
         {
-            @Override
-            public Boolean apply( ArtifactMetadataModel artifactMetadataModel )
+            ColumnSlice<String, String> columnSlice = row.getColumnSlice();
+            String repositoryName = getStringValue( columnSlice, "repositoryName" );
+            if ( StringUtils.equals( repositoryName, repositoryId ) )
             {
-                if ( artifactMetadataModel != null )
-                {
-                    if ( StringUtils.equals( artifactMetadataModel.getRepositoryId(), repositoryId
)
-                        && artifactMetadataModel.getNamespace() != null &&
-                        artifactMetadataModel.getProject() != null && artifactMetadataModel.getId()
!= null )
-                    {
 
-                        if ( StringUtils.equals( checksum, artifactMetadataModel.getMd5()
) || StringUtils.equals(
-                            checksum, artifactMetadataModel.getSha1() ) )
-                        {
-                            artifactMetadataModels.add( artifactMetadataModel );
-                        }
-                    }
-                }
-                return Boolean.TRUE;
+                artifactMetadataMap.put( row.getKey(), mapArtifactMetadataLongColumnSlice(
columnSlice ) );
             }
-        } );
-        List<ArtifactMetadata> artifactMetadatas = new ArrayList<ArtifactMetadata>(
artifactMetadataModels.size() );
+        }
 
-        for ( ArtifactMetadataModel model : artifactMetadataModels )
+        query = HFactory //
+            .createRangeSlicesQuery( keyspace, ss, ss, ss ) //
+            .setColumnFamily( cassandraArchivaManager.getArtifactMetadataModelFamilyName()
) //
+            .setColumnNames( "namespaceId", "size", "id", "fileLastModified", "md5", "project",
"projectVersion",
+                             "repositoryName", "version", "whenGathered", "sha1" ); //
+
+        query = query.addEqualsExpression( "md5", checksum );
+
+        result = query.execute();
+
+        for ( Row<String, String, String> row : result.get() )
         {
-            ArtifactMetadata artifactMetadata = getModelMapper().map( model, ArtifactMetadata.class
);
-            populateFacets( artifactMetadata );
-            artifactMetadatas.add( artifactMetadata );
-        }
+            ColumnSlice<String, String> columnSlice = row.getColumnSlice();
+            String repositoryName = getStringValue( columnSlice, "repositoryName" );
+            if ( StringUtils.equals( repositoryName, repositoryId ) )
+            {
 
-        logger.debug( "getArtifactsByChecksum repositoryId: {}, checksum: {}, artifactMetadatas:
{}", repositoryId,
-                      checksum, artifactMetadatas );
+                artifactMetadataMap.put( row.getKey(), mapArtifactMetadataLongColumnSlice(
columnSlice ) );
+            }
+        }
 
-        return artifactMetadatas;*/
-        return Collections.emptyList();
+        return artifactMetadataMap.values();
     }
 
+
     @Override
     public void removeArtifact( final String repositoryId, final String namespace, final
String project,
                                 final String version, final String id )

Modified: archiva/trunk/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/DefaultCassandraArchivaManager.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/DefaultCassandraArchivaManager.java?rev=1580691&r1=1580690&r2=1580691&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/DefaultCassandraArchivaManager.java
(original)
+++ archiva/trunk/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/DefaultCassandraArchivaManager.java
Mon Mar 24 01:36:39 2014
@@ -288,6 +288,19 @@ public class DefaultCassandraArchivaMana
             whenGatheredColumn.setValidationClass( ComparatorType.LONGTYPE.getClassName()
);
             artifactMetadataModel.addColumnDefinition( whenGatheredColumn );
 
+            BasicColumnDefinition sha1Column = new BasicColumnDefinition();
+            sha1Column.setName( StringSerializer.get().toByteBuffer( "sha1" ) );
+            sha1Column.setIndexName( "sha1" );
+            sha1Column.setIndexType( ColumnIndexType.KEYS );
+            sha1Column.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
+            artifactMetadataModel.addColumnDefinition( sha1Column );
+
+            BasicColumnDefinition md5Column = new BasicColumnDefinition();
+            md5Column.setName( StringSerializer.get().toByteBuffer( "md5" ) );
+            md5Column.setIndexName( "md5" );
+            md5Column.setIndexType( ColumnIndexType.KEYS );
+            md5Column.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
+            artifactMetadataModel.addColumnDefinition( md5Column );
 
 
         }

Modified: archiva/trunk/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumer.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumer.java?rev=1580691&r1=1580690&r2=1580691&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumer.java
(original)
+++ archiva/trunk/archiva-modules/plugins/problem-reports/src/main/java/org/apache/archiva/reports/consumers/DuplicateArtifactsConsumer.java
Mon Mar 24 01:36:39 2014
@@ -49,6 +49,7 @@ import javax.inject.Named;
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
 import java.util.List;
@@ -158,7 +159,7 @@ public class DuplicateArtifactsConsumer
 
         MetadataRepository metadataRepository = repositorySession.getRepository();
 
-        List<ArtifactMetadata> results;
+        Collection<ArtifactMetadata> results;
         try
         {
             results = metadataRepository.getArtifactsByChecksum( repoId, checksumSha1 );



Mime
View raw message