aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/plugins/metadata-store-cassandra/src
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2014-03-20 23:22:50 +0000
committerOlivier Lamy <olamy@apache.org>2014-03-20 23:22:50 +0000
commit2e2090deacfe942899ba62f6c3469a826f90003a (patch)
tree416b439530844352e2267711002d376d28508387 /archiva-modules/plugins/metadata-store-cassandra/src
parentf995680a818e2f33bd686c8b7db5ba3082b4f97f (diff)
downloadarchiva-2e2090deacfe942899ba62f6c3469a826f90003a.tar.gz
archiva-2e2090deacfe942899ba62f6c3469a826f90003a.zip
start moving project data handling to hector
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1579822 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/plugins/metadata-store-cassandra/src')
-rw-r--r--archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraArchivaManager.java2
-rw-r--r--archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java104
-rw-r--r--archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/DefaultCassandraArchivaManager.java49
-rw-r--r--archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/RepositoriesNamespaceTest.java10
4 files changed, 113 insertions, 52 deletions
diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraArchivaManager.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraArchivaManager.java
index 605883649..38e7e2519 100644
--- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraArchivaManager.java
+++ b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraArchivaManager.java
@@ -42,4 +42,6 @@ public interface CassandraArchivaManager
String getNamespaceFamilyName();
+ String getProjectFamilyName();
+
}
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 88ed20ff9..142e134bc 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
@@ -41,6 +41,7 @@ import org.apache.archiva.metadata.repository.MetadataRepositoryException;
import org.apache.archiva.metadata.repository.MetadataResolutionException;
import org.apache.archiva.metadata.repository.cassandra.model.ArtifactMetadataModel;
import org.apache.archiva.metadata.repository.cassandra.model.Namespace;
+import org.apache.archiva.metadata.repository.cassandra.model.Project;
import org.apache.archiva.metadata.repository.cassandra.model.Repository;
import org.apache.commons.lang.StringUtils;
import org.modelmapper.ModelMapper;
@@ -497,36 +498,71 @@ public class CassandraMetadataRepository
public void updateProject( String repositoryId, ProjectMetadata projectMetadata )
throws MetadataRepositoryException
{
-/*
- // project exists ? if yes return
- String projectKey = new Project.KeyBuilder().withProjectId( projectMetadata.getId() ).withNamespace(
- new Namespace( projectMetadata.getNamespace(), new Repository( repositoryId ) ) ).build();
+ Keyspace keyspace = cassandraArchivaManager.getKeyspace();
- Project project = getProjectEntityManager().get( projectKey );
- if ( project != null )
+ QueryResult<OrderedRows<String, String, String>> result = HFactory //
+ .createRangeSlicesQuery( keyspace, //
+ StringSerializer.get(), //
+ StringSerializer.get(), //
+ StringSerializer.get() ) //
+ .setColumnFamily( cassandraArchivaManager.getProjectFamilyName() ) //
+ .setColumnNames( "projectId" ) //
+ .addEqualsExpression( "repositoryId", repositoryId ) //
+ .addEqualsExpression( "namespaceId", projectMetadata.getNamespace() ) //
+ .addEqualsExpression( "projectId", projectMetadata.getId() ) //
+ .execute();
+
+ // project exists ? if yes return
+ if ( result.get().getCount() > 0 )
{
return;
}
- String namespaceKey = new Namespace.KeyBuilder().withRepositoryId( repositoryId ).withNamespace(
- projectMetadata.getNamespace() ).build();
- Namespace namespace = getNamespaceEntityManager().get( namespaceKey );
- if ( namespace == null )
- {
- namespace = updateOrAddNamespace( repositoryId, projectMetadata.getNamespace() );
- }
+ Namespace namespace = updateOrAddNamespace( repositoryId, projectMetadata.getNamespace() );
- project = new Project( projectKey, projectMetadata.getId(), namespace );
+ String key =
+ new Project.KeyBuilder().withProjectId( projectMetadata.getId() ).withNamespace( namespace ).build();
+
+ HFactory.createMutator( keyspace, StringSerializer.get() )
+ // values
+ .addInsertion( key, //
+ cassandraArchivaManager.getProjectFamilyName(), //
+ CassandraUtils.column( "projectId", projectMetadata.getId() ) ) //
+ .addInsertion( key, //
+ cassandraArchivaManager.getProjectFamilyName(), //
+ CassandraUtils.column( "repositoryId", repositoryId ) ) //
+ .addInsertion( key, //
+ cassandraArchivaManager.getProjectFamilyName(), //
+ CassandraUtils.column( "namespaceId", projectMetadata.getNamespace() ) )//
+ .execute();
+ }
- try
+ @Override
+ public Collection<String> getProjects( final String repoId, final String namespace )
+ throws MetadataResolutionException
+ {
+
+ Keyspace keyspace = cassandraArchivaManager.getKeyspace();
+
+ QueryResult<OrderedRows<String, String, String>> result = HFactory //
+ .createRangeSlicesQuery( keyspace, //
+ StringSerializer.get(), //
+ StringSerializer.get(), //
+ StringSerializer.get() ) //
+ .setColumnFamily( cassandraArchivaManager.getProjectFamilyName() ) //
+ .setColumnNames( "projectId" ) //
+ .addEqualsExpression( "repositoryId", repoId ) //
+ .addEqualsExpression( "namespaceId", namespace ) //
+ .execute();
+
+ final Set<String> projects = new HashSet<String>( result.get().getCount() );
+
+ for ( Row<String, String, String> row : result.get() )
{
- getProjectEntityManager().put( project );
+ projects.add( row.getColumnSlice().getColumnByName( "projectId" ).getValue() );
}
- catch ( PersistenceException e )
- {
- throw new MetadataRepositoryException( e.getMessage(), e );
- }*/
+ return projects;
}
@Override
@@ -1517,34 +1553,6 @@ public class CassandraMetadataRepository
}
@Override
- public Collection<String> getProjects( final String repoId, final String namespace )
- throws MetadataResolutionException
- {
- final Set<String> projects = new HashSet<String>();
-
-/* // FIXME use cql query
- getProjectEntityManager().visitAll( new Function<Project, Boolean>()
- {
- @Override
- public Boolean apply( Project project )
- {
- if ( project != null )
- {
- if ( StringUtils.equals( repoId, project.getNamespace().getRepository().getName() )
- && StringUtils.startsWith( project.getNamespace().getName(), namespace ) )
- {
- projects.add( project.getProjectId() );
- }
- }
- return Boolean.TRUE;
- }
- } );*/
-
- return projects;
- }
-
-
- @Override
public void removeProjectVersion( final String repoId, final String namespace, final String projectId,
final String projectVersion )
throws MetadataRepositoryException
diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/DefaultCassandraArchivaManager.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/DefaultCassandraArchivaManager.java
index 4314a071f..a5c212e48 100644
--- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/DefaultCassandraArchivaManager.java
+++ b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/DefaultCassandraArchivaManager.java
@@ -73,6 +73,8 @@ public class DefaultCassandraArchivaManager
private String namespaceFamilyName = "namespace";
+ private String projectFamilyName = "project";
+
@PostConstruct
public void initialize()
@@ -107,11 +109,11 @@ public class DefaultCassandraArchivaManager
// namespace table
{
- final ColumnFamilyDefinition namespaces =
+ final ColumnFamilyDefinition namespace =
HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), //
getNamespaceFamilyName(), //
ComparatorType.UTF8TYPE );
- cfds.add( namespaces );
+ cfds.add( namespace );
// creating indexes for cql query
@@ -120,16 +122,17 @@ public class DefaultCassandraArchivaManager
nameColumn.setIndexName( "name" );
nameColumn.setIndexType( ColumnIndexType.KEYS );
nameColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
- namespaces.addColumnDefinition( nameColumn );
+ namespace.addColumnDefinition( nameColumn );
BasicColumnDefinition repositoryIdColumn = new BasicColumnDefinition();
repositoryIdColumn.setName( StringSerializer.get().toByteBuffer( "repositoryId" ) );
repositoryIdColumn.setIndexName( "repositoryId" );
repositoryIdColumn.setIndexType( ColumnIndexType.KEYS );
repositoryIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
- namespaces.addColumnDefinition( repositoryIdColumn );
+ namespace.addColumnDefinition( repositoryIdColumn );
}
+ // repository table
{
final ColumnFamilyDefinition repository =
HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), //
@@ -146,6 +149,39 @@ public class DefaultCassandraArchivaManager
repository.addColumnDefinition( nameColumn );
}
+ // project table
+ {
+
+ final ColumnFamilyDefinition project =
+ HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), //
+ getProjectFamilyName(), //
+ ComparatorType.UTF8TYPE );
+ cfds.add( project );
+
+ // creating indexes for cql query
+
+ BasicColumnDefinition projectIdColumn = new BasicColumnDefinition();
+ projectIdColumn.setName( StringSerializer.get().toByteBuffer( "projectId" ) );
+ projectIdColumn.setIndexName( "projectId" );
+ projectIdColumn.setIndexType( ColumnIndexType.KEYS );
+ projectIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
+ project.addColumnDefinition( projectIdColumn );
+
+ BasicColumnDefinition repositoryIdColumn = new BasicColumnDefinition();
+ repositoryIdColumn.setName( StringSerializer.get().toByteBuffer( "repositoryId" ) );
+ repositoryIdColumn.setIndexName( "repositoryId" );
+ repositoryIdColumn.setIndexType( ColumnIndexType.KEYS );
+ repositoryIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
+ project.addColumnDefinition( repositoryIdColumn );
+
+ BasicColumnDefinition namespaceIdColumn = new BasicColumnDefinition();
+ namespaceIdColumn.setName( StringSerializer.get().toByteBuffer( "namespaceId" ) );
+ namespaceIdColumn.setIndexName( "namespaceId" );
+ namespaceIdColumn.setIndexType( ColumnIndexType.KEYS );
+ namespaceIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
+ project.addColumnDefinition( namespaceIdColumn );
+ }
+
{ // ensure keyspace exists, here if the keyspace doesn't exist we suppose nothing exist
if ( cluster.describeKeyspace( keyspaceName ) == null )
{
@@ -197,4 +233,9 @@ public class DefaultCassandraArchivaManager
{
return namespaceFamilyName;
}
+
+ public String getProjectFamilyName()
+ {
+ return projectFamilyName;
+ }
}
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 c6cd742f2..403a9326e 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
@@ -19,6 +19,7 @@ package org.apache.archiva.metadata.repository.cassandra;
* under the License.
*/
+import org.apache.archiva.metadata.model.ProjectMetadata;
import org.apache.archiva.metadata.repository.cassandra.model.Namespace;
import org.apache.archiva.metadata.repository.cassandra.model.Repository;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
@@ -108,6 +109,15 @@ public class RepositoriesNamespaceTest
Assertions.assertThat( cmr.getNamespaces( "release" ) ).isNotEmpty().hasSize( 1 );
Assertions.assertThat( cmr.getNamespaces( "release" ) ).containsExactly( "org" );
+ ProjectMetadata projectMetadata = new ProjectMetadata();
+ projectMetadata.setId( "theproject" );
+ projectMetadata.setNamespace( "org" );
+
+ cmr.updateProject( "release", projectMetadata );
+
+ Assertions.assertThat( cmr.getProjects( "release", "org" ) ).isNotEmpty().hasSize( 1 ).containsExactly(
+ "theproject" );
+
cmr.removeRepository( "release" );
r = cmr.getRepository( "release" );