diff --git a/archiva-modules/plugins/metadata-store-cassandra/pom.xml b/archiva-modules/plugins/metadata-store-cassandra/pom.xml
index 8a6d19929..86d3aaee5 100644
--- a/archiva-modules/plugins/metadata-store-cassandra/pom.xml
+++ b/archiva-modules/plugins/metadata-store-cassandra/pom.xml
@@ -73,13 +73,14 @@
modelmapper
+
org.apache.geronimo.specs
geronimo-jpa_2.0_spec
-
+
org.apache.cassandra
cassandra-all
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 e53e4e608..e4808dfc0 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
@@ -19,14 +19,8 @@ package org.apache.archiva.metadata.repository.cassandra;
* under the License.
*/
-import com.netflix.astyanax.Keyspace;
-import com.netflix.astyanax.entitystore.EntityManager;
-import org.apache.archiva.metadata.repository.cassandra.model.ArtifactMetadataModel;
-import org.apache.archiva.metadata.repository.cassandra.model.MetadataFacetModel;
-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.ProjectVersionMetadataModel;
-import org.apache.archiva.metadata.repository.cassandra.model.Repository;
+import me.prettyprint.hector.api.Cluster;
+import me.prettyprint.hector.api.Keyspace;
/**
* @author Olivier Lamy
@@ -34,25 +28,14 @@ import org.apache.archiva.metadata.repository.cassandra.model.Repository;
*/
public interface CassandraArchivaManager
{
- Keyspace getKeyspace();
-
void start();
void shutdown();
boolean started();
- EntityManager getRepositoryEntityManager();
-
- EntityManager getNamespaceEntityManager();
-
- EntityManager getProjectEntityManager();
-
- EntityManager getArtifactMetadataModelEntityManager();
-
- EntityManager getMetadataFacetModelEntityManager();
-
- EntityManager getProjectVersionMetadataModelEntityManager();
+ Keyspace getKeyspace();
+ Cluster getCluster();
}
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 157a7920e..12c63ece8 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
@@ -19,10 +19,15 @@ package org.apache.archiva.metadata.repository.cassandra;
* under the License.
*/
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
-import com.netflix.astyanax.entitystore.EntityManager;
+import me.prettyprint.cassandra.serializers.StringSerializer;
+import me.prettyprint.hector.api.Keyspace;
+import me.prettyprint.hector.api.beans.ColumnSlice;
+import me.prettyprint.hector.api.beans.OrderedRows;
+import me.prettyprint.hector.api.beans.Row;
+import me.prettyprint.hector.api.exceptions.HInvalidRequestException;
+import me.prettyprint.hector.api.factory.HFactory;
+import me.prettyprint.hector.api.mutation.MutationResult;
+import me.prettyprint.hector.api.query.QueryResult;
import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.FacetedMetadata;
@@ -35,10 +40,7 @@ import org.apache.archiva.metadata.repository.MetadataRepository;
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.MetadataFacetModel;
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.ProjectVersionMetadataModel;
import org.apache.archiva.metadata.repository.cassandra.model.Repository;
import org.apache.commons.lang.StringUtils;
import org.modelmapper.ModelMapper;
@@ -50,9 +52,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
-import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -83,34 +83,65 @@ public class CassandraMetadataRepository
}
- public EntityManager getRepositoryEntityManager()
+ /**
+ * if the repository doesn't exist it will be created
+ *
+ * @param repositoryId
+ * @return
+ */
+ public Repository getOrCreateRepository( String repositoryId )
+ throws MetadataRepositoryException
{
- return this.cassandraArchivaManager.getRepositoryEntityManager();
+ Keyspace keyspace = cassandraArchivaManager.getKeyspace();
+ QueryResult> result = HFactory //
+ .createRangeSlicesQuery( keyspace, StringSerializer.get(), StringSerializer.get(),
+ StringSerializer.get() ) //
+ .setColumnFamily( "repository" ) //
+ .setColumnNames( "id", "name" ) //
+ .addEqualsExpression( "id", repositoryId ) //
+ .execute();
+
+ if ( result.get().getCount() < 1 )
+ {
+ // we need to create the repository
+ Repository repository = new Repository( repositoryId );
+
+ try
+ {
+ MutationResult mutationResult = HFactory.createMutator( keyspace, StringSerializer.get() ) //
+ // values
+ .addInsertion( repositoryId, "repository",
+ CassandraUtils.column( "id", repository.getId() ) ) //
+ .addInsertion( repositoryId, "repository",
+ CassandraUtils.column( "name", repository.getName() ) ) //
+ .execute();
+ logger.debug( "" );
+ return repository;
+ }
+ catch ( HInvalidRequestException e )
+ {
+ logger.error( e.getMessage(), e );
+ throw new MetadataRepositoryException( e.getMessage(), e );
+ }
+
+ }
+
+ return new Repository( result.get().getList().get( 0 ).getColumnSlice().getColumnByName( "id" ).getValue() );
}
- public EntityManager getNamespaceEntityManager()
- {
- return this.cassandraArchivaManager.getNamespaceEntityManager();
- }
- public EntityManager getProjectEntityManager()
+ protected Repository getRepository( String repositoryId )
+ throws MetadataRepositoryException
{
- return this.cassandraArchivaManager.getProjectEntityManager();
- }
-
- public EntityManager getArtifactMetadataModelEntityManager()
- {
- return cassandraArchivaManager.getArtifactMetadataModelEntityManager();
- }
-
- public EntityManager getMetadataFacetModelEntityManager()
- {
- return this.cassandraArchivaManager.getMetadataFacetModelEntityManager();
- }
-
- public EntityManager getProjectVersionMetadataModelEntityManager()
- {
- return this.cassandraArchivaManager.getProjectVersionMetadataModelEntityManager();
+ Keyspace keyspace = cassandraArchivaManager.getKeyspace();
+ QueryResult> result = HFactory //
+ .createRangeSlicesQuery( keyspace, StringSerializer.get(), StringSerializer.get(),
+ StringSerializer.get() ) //
+ .setColumnFamily( "repository" ) //
+ .setColumnNames( "id", "name" ) //
+ .addEqualsExpression( "id", repositoryId ) //
+ .execute();
+ return ( result.get().getCount() > 0 ) ? new Repository( repositoryId ) : null;
}
@Override
@@ -126,32 +157,53 @@ public class CassandraMetadataRepository
{
try
{
- Repository repository = this.getRepositoryEntityManager().get( repositoryId );
+ Repository repository = getOrCreateRepository( repositoryId );
- if ( repository == null )
- {
- repository = new Repository( repositoryId );
+ Keyspace keyspace = cassandraArchivaManager.getKeyspace();
- Namespace namespace = new Namespace( namespaceId, repository );
- this.getRepositoryEntityManager().put( repository );
-
- this.getNamespaceEntityManager().put( namespace );
- }
- // FIXME add a Namespace id builder
- Namespace namespace = getNamespaceEntityManager().get(
- new Namespace.KeyBuilder().withNamespace( namespaceId ).withRepositoryId( repositoryId ).build() );
+ Namespace namespace = getNamespace( repositoryId, namespaceId );
if ( namespace == null )
{
namespace = new Namespace( namespaceId, repository );
- getNamespaceEntityManager().put( namespace );
+ HFactory.createMutator( keyspace, StringSerializer.get() )
+ // values
+ .addInsertion( namespace.getId(), "namespace", //
+ CassandraUtils.column( "name", namespace.getName() ) ) //
+ .addInsertion( namespace.getId(), "namespace", //
+ CassandraUtils.column( "repositoryId", repository.getId() ) ) //
+ .execute();
}
+
return namespace;
}
- catch ( PersistenceException e )
+ catch ( HInvalidRequestException e )
{
+ logger.error( e.getMessage(), e );
throw new MetadataRepositoryException( e.getMessage(), e );
}
+ }
+ protected Namespace getNamespace( String repositoryId, String namespaceId )
+ {
+ Keyspace keyspace = cassandraArchivaManager.getKeyspace();
+ QueryResult> result = HFactory //
+ .createRangeSlicesQuery( keyspace, //
+ StringSerializer.get(), //
+ StringSerializer.get(), //
+ StringSerializer.get() ) //
+ .setColumnFamily( "namespace" ) //
+ .setColumnNames( "repositoryId", "name" ) //
+ .addEqualsExpression( "repositoryId", repositoryId ) //
+ .addEqualsExpression( "name", namespaceId ) //
+ .execute();
+ if ( result.get().getCount() > 0 )
+ {
+ ColumnSlice columnSlice = result.get().getList().get( 0 ).getColumnSlice();
+ return new Namespace( columnSlice.getColumnByName( "name" ).getValue(), //
+ new Repository( columnSlice.getColumnByName( "repositoryId" ).getValue() ) );
+
+ }
+ return null;
}
@@ -161,15 +213,18 @@ public class CassandraMetadataRepository
{
try
{
- Namespace namespace = getNamespaceEntityManager().get(
- new Namespace.KeyBuilder().withNamespace( namespaceId ).withRepositoryId( repositoryId ).build() );
- if ( namespace != null )
- {
- getNamespaceEntityManager().remove( namespace );
- }
+ String key =
+ new Namespace.KeyBuilder().withNamespace( namespaceId ).withRepositoryId( repositoryId ).build();
+
+ MutationResult result =
+ HFactory.createMutator( cassandraArchivaManager.getKeyspace(), new StringSerializer() ).addDeletion(
+ key, "namespace" ).execute();
+
+
}
- catch ( PersistenceException e )
+ catch ( HInvalidRequestException e )
{
+ logger.error( e.getMessage(), e );
throw new MetadataRepositoryException( e.getMessage(), e );
}
}
@@ -179,105 +234,132 @@ public class CassandraMetadataRepository
public void removeRepository( final String repositoryId )
throws MetadataRepositoryException
{
- try
+
+ // FIXME remove all datas attached to the repositoryId
+
+ // retrieve and delete all namespace with this repositoryId
+
+ List namespacesKey = new ArrayList();
+
+ Keyspace keyspace = cassandraArchivaManager.getKeyspace();
+ QueryResult> result = HFactory //
+ .createRangeSlicesQuery( keyspace, //
+ StringSerializer.get(), //
+ StringSerializer.get(), //
+ StringSerializer.get() ) //
+ .setColumnFamily( "namespace" ) //
+ .setColumnNames( "repositoryId", "name" ) //
+ .addEqualsExpression( "repositoryId", repositoryId ) //
+ .execute();
+
+ for ( Row row : result.get().getList() )
{
- final List artifactMetadataModels = new ArrayList();
+ namespacesKey.add( row.getKey() );
+ }
- // remove data related to the repository
- this.getArtifactMetadataModelEntityManager().visitAll( new Function()
+ HFactory.createMutator( cassandraArchivaManager.getKeyspace(), new StringSerializer() ) //
+ .addDeletion( namespacesKey, "namespace" ) //
+ .execute();
+
+ //delete repositoryId
+ HFactory.createMutator( cassandraArchivaManager.getKeyspace(), new StringSerializer() ) //
+ .addDeletion( repositoryId, "repository" ) //
+ .execute();
+
+/*
+ final List artifactMetadataModels = new ArrayList();
+
+ // remove data related to the repository
+ this.getArtifactMetadataModelEntityManager().visitAll( new Function()
+ {
+ @Override
+ public Boolean apply( ArtifactMetadataModel artifactMetadataModel )
{
- @Override
- public Boolean apply( ArtifactMetadataModel artifactMetadataModel )
+ if ( artifactMetadataModel != null )
{
- if ( artifactMetadataModel != null )
+ if ( StringUtils.equals( artifactMetadataModel.getRepositoryId(), repositoryId ) )
{
- if ( StringUtils.equals( artifactMetadataModel.getRepositoryId(), repositoryId ) )
- {
- artifactMetadataModels.add( artifactMetadataModel );
- }
+ artifactMetadataModels.add( artifactMetadataModel );
}
- return Boolean.TRUE;
}
- } );
-
- getArtifactMetadataModelEntityManager().remove( artifactMetadataModels );
-
- final List namespaces = new ArrayList();
-
- getNamespaceEntityManager().visitAll( new Function()
- {
- @Override
- public Boolean apply( Namespace namespace )
- {
- if ( namespace != null )
- {
- if ( StringUtils.equals( namespace.getRepository().getId(), repositoryId ) )
- {
- namespaces.add( namespace );
- }
- }
- return Boolean.TRUE;
- }
- } );
-
- getNamespaceEntityManager().remove( namespaces );
-
- final List projects = new ArrayList();
- getProjectEntityManager().visitAll( new Function()
- {
- @Override
- public Boolean apply( Project project )
- {
- if ( project != null )
- {
- if ( StringUtils.equals( project.getNamespace().getRepository().getId(), repositoryId ) )
- {
- projects.add( project );
- }
- }
- return Boolean.TRUE;
- }
- } );
-
- getProjectEntityManager().remove( projects );
-
- // TODO cleanup or not
- //final List metadataFacetModels = new ArrayList( );
- //getMetadataFacetModelEntityManager().visitAll( new Function()
-
- final List projectVersionMetadataModels =
- new ArrayList();
-
- getProjectVersionMetadataModelEntityManager().visitAll( new Function()
- {
- @Override
- public Boolean apply( ProjectVersionMetadataModel projectVersionMetadataModel )
- {
- if ( projectVersionMetadataModel != null )
- {
- if ( StringUtils.equals( projectVersionMetadataModel.getNamespace().getRepository().getId(),
- repositoryId ) )
- {
- projectVersionMetadataModels.add( projectVersionMetadataModel );
- }
- }
- return Boolean.TRUE;
- }
- } );
-
- getProjectVersionMetadataModelEntityManager().remove( projectVersionMetadataModels );
-
- Repository repository = getRepositoryEntityManager().get( repositoryId );
- if ( repository != null )
- {
- getRepositoryEntityManager().remove( repository );
+ return Boolean.TRUE;
}
+ } );
- }
- catch ( PersistenceException e )
+ getArtifactMetadataModelEntityManager().remove( artifactMetadataModels );
+
+ final List namespaces = new ArrayList();
+
+ getNamespaceEntityManager().visitAll( new Function()
{
- throw new MetadataRepositoryException( e.getMessage(), e );
+ @Override
+ public Boolean apply( Namespace namespace )
+ {
+ if ( namespace != null )
+ {
+ if ( StringUtils.equals( namespace.getRepository().getId(), repositoryId ) )
+ {
+ namespaces.add( namespace );
+ }
+ }
+ return Boolean.TRUE;
+ }
+ } );
+
+ getNamespaceEntityManager().remove( namespaces );
+
+ final List projects = new ArrayList();
+ getProjectEntityManager().visitAll( new Function()
+ {
+ @Override
+ public Boolean apply( Project project )
+ {
+ if ( project != null )
+ {
+ if ( StringUtils.equals( project.getNamespace().getRepository().getId(), repositoryId ) )
+ {
+ projects.add( project );
+ }
+ }
+ return Boolean.TRUE;
+ }
+ } );
+
+ getProjectEntityManager().remove( projects );
+
+ // TODO cleanup or not
+ //final List metadataFacetModels = new ArrayList( );
+ //getMetadataFacetModelEntityManager().visitAll( new Function()
+
+ final List projectVersionMetadataModels =
+ new ArrayList();
+
+ getProjectVersionMetadataModelEntityManager().visitAll( new Function()
+ {
+ @Override
+ public Boolean apply( ProjectVersionMetadataModel projectVersionMetadataModel )
+ {
+ if ( projectVersionMetadataModel != null )
+ {
+ if ( StringUtils.equals( projectVersionMetadataModel.getNamespace().getRepository().getId(),
+ repositoryId ) )
+ {
+ projectVersionMetadataModels.add( projectVersionMetadataModel );
+ }
+ }
+ return Boolean.TRUE;
+ }
+ } );
+
+ getProjectVersionMetadataModelEntityManager().remove( projectVersionMetadataModels );
+
+ Repository repository = getRepositoryEntityManager().get( repositoryId );
+ if ( repository != null )
+ {
+ getRepositoryEntityManager().remove( repository );
}
+
+ */
}
@Override
@@ -288,17 +370,23 @@ public class CassandraMetadataRepository
{
logger.debug( "getRepositories" );
- List repositories = getRepositoryEntityManager().getAll();
- if ( repositories == null )
+ final QueryResult> cResult = //
+ HFactory.createRangeSlicesQuery( cassandraArchivaManager.getKeyspace(), //
+ StringSerializer.get(), //
+ StringSerializer.get(), //
+ StringSerializer.get() ) //
+ .setColumnFamily( "repository" ) //
+ .setColumnNames( "name" ) //
+ .setRange( null, null, false, Integer.MAX_VALUE ) //
+ .execute();
+
+ List repoIds = new ArrayList( cResult.get().getCount() );
+
+ for ( Row row : cResult.get() )
{
- return Collections.emptyList();
+ repoIds.add( row.getColumnSlice().getColumnByName( "name" ).getValue() );
}
- List repoIds = new ArrayList( repositories.size() );
- for ( Repository repository : repositories )
- {
- repoIds.add( repository.getName() );
- }
- logger.debug( "getRepositories found: {}", repoIds );
+
return repoIds;
}
catch ( PersistenceException e )
@@ -313,201 +401,91 @@ public class CassandraMetadataRepository
public Collection getRootNamespaces( final String repoId )
throws MetadataResolutionException
{
- try
+ Keyspace keyspace = cassandraArchivaManager.getKeyspace();
+ QueryResult> result = HFactory //
+ .createRangeSlicesQuery( keyspace, //
+ StringSerializer.get(), //
+ StringSerializer.get(), //
+ StringSerializer.get() ) //
+ .setColumnFamily( "namespace" ) //
+ .setColumnNames( "name" ) //
+ .addEqualsExpression( "repositoryId", repoId ) //
+ .execute();
+
+ Set namespaces = new HashSet( result.get().getCount() );
+
+ for ( Row row : result.get() )
{
-
-
- RootNamesSpaceVisitAll rootNamesSpaceVisitAll = new RootNamesSpaceVisitAll( repoId );
-
- getNamespaceEntityManager().visitAll( rootNamesSpaceVisitAll );
-
- return rootNamesSpaceVisitAll.namespaces;
-
-
- // using cql query with index
- /*
- List namespacesList = getNamespaceEntityManager().find( "SELECT * from namespace where id <> null AND repositoryid = '" + repoId + "'" );
-
- Set namespaces = new HashSet();
-
- for (Namespace namespace : namespacesList)
- {
- String name = namespace.getName();
- if ( StringUtils.isNotEmpty( name ) )
- {
- namespaces.add( StringUtils.substringBefore( name, "." ) );
- }
- }
-
- return namespaces;
- */
-
- }
- catch ( Exception e )
- {
- throw new MetadataResolutionException( e.getMessage(), e );
+ namespaces.add(
+ StringUtils.substringBefore( row.getColumnSlice().getColumnByName( "name" ).getValue(), "." ) );
}
+
+ return namespaces;
}
- private static class RootNamesSpaceVisitAll
- implements Function
- {
- private String repoId;
-
- Set namespaces = new HashSet();
-
- private RootNamesSpaceVisitAll( String repoId )
- {
- this.repoId = repoId;
- }
-
- // @Nullable add dependency ?
- @Override
- public Boolean apply( Namespace namespace )
- {
- if ( namespace != null && namespace.getRepository() != null && StringUtils.equalsIgnoreCase( repoId,
- namespace.getRepository().getId() ) )
- {
- String name = namespace.getName();
- if ( StringUtils.isNotEmpty( name ) )
- {
- namespaces.add( StringUtils.substringBefore( name, "." ) );
- }
- }
- return Boolean.TRUE;
- }
- }
@Override
public Collection getNamespaces( final String repoId, final String namespaceId )
throws MetadataResolutionException
{
- try
+ Keyspace keyspace = cassandraArchivaManager.getKeyspace();
+ QueryResult> result = HFactory //
+ .createRangeSlicesQuery( keyspace, //
+ StringSerializer.get(), //
+ StringSerializer.get(), //
+ StringSerializer.get() ) //
+ .setColumnFamily( "namespace" ) //
+ .setColumnNames( "name" ) //
+ .addEqualsExpression( "repositoryId", repoId ) //
+ .execute();
+
+ List namespaces = new ArrayList( result.get().getCount() );
+
+ for ( Row row : result.get() )
{
- final FindNamesSpaceVisitAll findNamesSpaceVisitAll = new FindNamesSpaceVisitAll( repoId, namespaceId );
-
- getNamespaceEntityManager().visitAll( findNamesSpaceVisitAll );
-
- return findNamesSpaceVisitAll.namespaces;
- }
- catch ( PersistenceException e )
- {
- throw new MetadataResolutionException( e.getMessage(), e );
- }
-
- }
-
- private static class FindNamesSpaceVisitAll
- implements Function
- {
- private String repoId;
-
- private String namespaceId;
-
- Set namespaces = new HashSet();
-
- private FindNamesSpaceVisitAll( String repoId, String namespaceId )
- {
- this.repoId = repoId;
- this.namespaceId = namespaceId;
- }
-
- // @Nullable add dependency ?
- @Override
- public Boolean apply( Namespace namespace )
- {
- if ( namespace != null && namespace.getRepository() != null && StringUtils.equalsIgnoreCase( repoId,
- namespace.getRepository().getId() ) )
+ String currentNamespace = row.getColumnSlice().getColumnByName( "name" ).getValue();
+ if ( StringUtils.startsWith( currentNamespace, namespaceId ) && ( StringUtils.length( currentNamespace )
+ > StringUtils.length( namespaceId ) ) )
{
- String currentNamespace = namespace.getName();
- // we only return childs
- if ( StringUtils.startsWith( currentNamespace, namespaceId ) && (
- StringUtils.length( currentNamespace ) > StringUtils.length( namespaceId ) ) )
- {
- // store after namespaceId '.' but before next '.'
- // call org namespace org.apache.maven.shared -> stored apache
+ // store after namespaceId '.' but before next '.'
+ // call org namespace org.apache.maven.shared -> stored apache
- String calledNamespace =
- StringUtils.endsWith( namespaceId, "." ) ? namespaceId : namespaceId + ".";
- String storedNamespace = StringUtils.substringAfter( currentNamespace, calledNamespace );
+ String calledNamespace = StringUtils.endsWith( namespaceId, "." ) ? namespaceId : namespaceId + ".";
+ String storedNamespace = StringUtils.substringAfter( currentNamespace, calledNamespace );
- storedNamespace = StringUtils.substringBefore( storedNamespace, "." );
+ storedNamespace = StringUtils.substringBefore( storedNamespace, "." );
- namespaces.add( storedNamespace );
- }
+ namespaces.add( storedNamespace );
}
- return Boolean.TRUE;
}
+
+ return namespaces;
+
}
public List getNamespaces( final String repoId )
throws MetadataResolutionException
{
- try
+ Keyspace keyspace = cassandraArchivaManager.getKeyspace();
+ QueryResult> result = HFactory //
+ .createRangeSlicesQuery( keyspace, //
+ StringSerializer.get(), //
+ StringSerializer.get(), //
+ StringSerializer.get() ) //
+ .setColumnFamily( "namespace" ) //
+ .setColumnNames( "name" ) //
+ .addEqualsExpression( "repositoryId", repoId ) //
+ .execute();
+
+ List namespaces = new ArrayList( result.get().getCount() );
+
+ for ( Row row : result.get() )
{
- logger.debug( "getNamespaces for repository '{}'", repoId );
- //TypedQuery typedQuery =
- // entityManager.createQuery( "select n from Namespace n where n.repository_id=:id", Namespace.class );
-
- //List namespaces = typedQuery.setParameter( "id", repoId ).getResultList();
-
- Repository repository = getRepositoryEntityManager().get( repoId );
-
- if ( repository == null )
- {
- return Collections.emptyList();
- }
-
- // FIXME find correct cql query
- //String query = "select * from namespace where repository.id = '" + repoId + "';";
-
- //List namespaces = getNamespaceEntityManager().find( query );
-
- //final Set namespaces = new HashSet();
- final Set namespaces = new HashSet();
-
- getNamespaceEntityManager().visitAll( new Function()
- {
- // @Nullable add dependency ?
- @Override
- public Boolean apply( Namespace namespace )
- {
- if ( namespace != null && namespace.getRepository() != null && StringUtils.equalsIgnoreCase( repoId,
- namespace.getRepository().getId() ) )
- {
- namespaces.add( namespace.getId() );
- }
- return Boolean.TRUE;
- }
- } );
-
-
- /*
-
- 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() )
- {
- namespaceIds.add( n.getName() );
- }
-
- logger.debug( "getNamespaces for repository '{}' found {}", repoId, namespaceIds.size() );
-
- return namespaceIds;
- */
- return new ArrayList( namespaces );
- }
- catch ( PersistenceException e )
- {
- throw new MetadataResolutionException( e.getMessage(), e );
+ namespaces.add( row.getColumnSlice().getColumnByName( "name" ).getValue() );
}
+
+ return namespaces;
}
@@ -515,7 +493,7 @@ 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();
@@ -543,7 +521,7 @@ public class CassandraMetadataRepository
catch ( PersistenceException e )
{
throw new MetadataRepositoryException( e.getMessage(), e );
- }
+ }*/
}
@@ -552,7 +530,7 @@ public class CassandraMetadataRepository
throws MetadataRepositoryException
{
- // cleanup ArtifactMetadataModel
+/* // cleanup ArtifactMetadataModel
final List artifactMetadataModels = new ArrayList();
getArtifactMetadataModelEntityManager().visitAll( new Function()
@@ -614,14 +592,15 @@ public class CassandraMetadataRepository
}
logger.debug( "removeProject {}", project );
- getProjectEntityManager().remove( project );
+ getProjectEntityManager().remove( project );*/
}
@Override
public Collection getProjectVersions( final String repoId, final String namespace, final String projectId )
throws MetadataResolutionException
{
- final Set versions = new HashSet();
+ return null;
+/* final Set versions = new HashSet();
getProjectVersionMetadataModelEntityManager().visitAll( new Function()
{
@Override
@@ -659,7 +638,7 @@ public class CassandraMetadataRepository
}
} );
- return versions;
+ return versions;*/
}
@Override
@@ -667,7 +646,7 @@ public class CassandraMetadataRepository
ArtifactMetadata artifactMeta )
throws MetadataRepositoryException
{
- String namespaceKey =
+/* String namespaceKey =
new Namespace.KeyBuilder().withRepositoryId( repositoryId ).withNamespace( namespaceId ).build();
// create the namespace if not exists
Namespace namespace = getNamespaceEntityManager().get( namespaceKey );
@@ -745,7 +724,7 @@ public class CassandraMetadataRepository
}
// now facets
- updateFacets( artifactMeta, artifactMetadataModel );
+ updateFacets( artifactMeta, artifactMetadataModel );*/
}
@@ -754,7 +733,7 @@ public class CassandraMetadataRepository
final String projectVersion )
throws MetadataResolutionException
{
- final Set versions = new HashSet();
+/* final Set versions = new HashSet();
// FIXME use cql query
getArtifactMetadataModelEntityManager().visitAll( new Function()
{
@@ -775,7 +754,8 @@ public class CassandraMetadataRepository
}
} );
- return versions;
+ return versions;*/
+ return null;
}
/**
@@ -788,7 +768,7 @@ public class CassandraMetadataRepository
final ArtifactMetadataModel artifactMetadataModel )
{
- for ( final String facetId : metadataFacetFactories.keySet() )
+/* for ( final String facetId : metadataFacetFactories.keySet() )
{
MetadataFacet metadataFacet = facetedMetadata.getFacet( facetId );
if ( metadataFacet == null )
@@ -834,8 +814,7 @@ public class CassandraMetadataRepository
}
getMetadataFacetModelEntityManager().put( metadataFacetModelsToAdd );
-
- }
+ }*/
}
@Override
@@ -843,7 +822,7 @@ public class CassandraMetadataRepository
ProjectVersionMetadata versionMetadata )
throws MetadataRepositoryException
{
- String namespaceKey =
+/* String namespaceKey =
new Namespace.KeyBuilder().withRepositoryId( repositoryId ).withNamespace( namespaceId ).build();
Namespace namespace = getNamespaceEntityManager().get( namespaceKey );
if ( namespace == null )
@@ -869,8 +848,7 @@ public class CassandraMetadataRepository
if ( projectVersionMetadataModel == null )
{
- projectVersionMetadataModel =
- getModelMapper().map( versionMetadata, ProjectVersionMetadataModel.class );
+ projectVersionMetadataModel = getModelMapper().map( versionMetadata, ProjectVersionMetadataModel.class );
projectVersionMetadataModel.setRowId( key );
}
projectVersionMetadataModel.setProjectId( projectId );
@@ -892,7 +870,8 @@ public class CassandraMetadataRepository
artifactMetadataModel.setArtifactMetadataModelId(
new ArtifactMetadataModel.KeyBuilder().withId( versionMetadata.getId() ).withRepositoryId(
repositoryId ).withNamespace( namespaceId ).withProjectVersion(
- versionMetadata.getVersion() ).withProject( projectId ).build() );
+ versionMetadata.getVersion() ).withProject( projectId ).build()
+ );
artifactMetadataModel.setRepositoryId( repositoryId );
artifactMetadataModel.setNamespace( namespaceId );
artifactMetadataModel.setProject( projectId );
@@ -904,7 +883,7 @@ public class CassandraMetadataRepository
catch ( PersistenceException e )
{
throw new MetadataRepositoryException( e.getMessage(), e );
- }
+ }*/
}
@@ -917,7 +896,7 @@ public class CassandraMetadataRepository
public List getMetadataFacets( final String repositoryId, final String facetId )
throws MetadataRepositoryException
{
- // FIXME use cql query !!
+/* // FIXME use cql query !!
final List facets = new ArrayList();
this.getMetadataFacetModelEntityManager().visitAll( new Function()
{
@@ -937,7 +916,8 @@ public class CassandraMetadataRepository
}
} );
- return facets;
+ return facets;*/
+ return null;
}
@@ -952,7 +932,7 @@ public class CassandraMetadataRepository
public MetadataFacet getMetadataFacet( final String repositoryId, final String facetId, final String name )
throws MetadataRepositoryException
{
- // FIXME use cql query !!
+/* // FIXME use cql query !!
final List facets = new ArrayList();
this.getMetadataFacetModelEntityManager().visitAll( new Function()
{
@@ -990,14 +970,15 @@ public class CassandraMetadataRepository
map.put( metadataFacetModel.getKey(), metadataFacetModel.getValue() );
}
metadataFacet.fromProperties( map );
- return metadataFacet;
+ return metadataFacet;*/
+ return null;
}
@Override
public void addMetadataFacet( String repositoryId, MetadataFacet metadataFacet )
throws MetadataRepositoryException
{
-
+/*
if ( metadataFacet == null )
{
return;
@@ -1061,14 +1042,14 @@ public class CassandraMetadataRepository
}
}
- }
+ }*/
}
@Override
public void removeMetadataFacets( final String repositoryId, final String facetId )
throws MetadataRepositoryException
{
- logger.debug( "removeMetadataFacets repositoryId: '{}', facetId: '{}'", repositoryId, facetId );
+/* logger.debug( "removeMetadataFacets repositoryId: '{}', facetId: '{}'", repositoryId, facetId );
final List toRemove = new ArrayList();
// FIXME cql query
@@ -1091,14 +1072,14 @@ public class CassandraMetadataRepository
} );
logger.debug( "removeMetadataFacets repositoryId: '{}', facetId: '{}', toRemove: {}", repositoryId, facetId,
toRemove );
- getMetadataFacetModelEntityManager().remove( toRemove );
+ getMetadataFacetModelEntityManager().remove( toRemove );*/
}
@Override
public void removeMetadataFacet( final String repositoryId, final String facetId, final String name )
throws MetadataRepositoryException
{
- logger.debug( "removeMetadataFacets repositoryId: '{}', facetId: '{}'", repositoryId, facetId );
+/* logger.debug( "removeMetadataFacets repositoryId: '{}', facetId: '{}'", repositoryId, facetId );
final List toRemove = new ArrayList();
// FIXME cql query
@@ -1122,7 +1103,7 @@ public class CassandraMetadataRepository
} );
logger.debug( "removeMetadataFacets repositoryId: '{}', facetId: '{}', toRemove: {}", repositoryId, facetId,
toRemove );
- getMetadataFacetModelEntityManager().remove( toRemove );
+ getMetadataFacetModelEntityManager().remove( toRemove );*/
}
@Override
@@ -1131,7 +1112,7 @@ public class CassandraMetadataRepository
throws MetadataRepositoryException
{
- final List artifactMetadataModels = new ArrayList();
+/* final List artifactMetadataModels = new ArrayList();
// FIXME cql query
getArtifactMetadataModelEntityManager().visitAll( new Function()
@@ -1172,12 +1153,13 @@ public class CassandraMetadataRepository
logger.debug( "getArtifactsByDateRange repositoryId: {}, startTime: {}, endTime: {}, artifactMetadatas: {}",
repositoryId, startTime, endTime, artifactMetadatas );
- return artifactMetadatas;
+ return artifactMetadatas;*/
+ return Collections.emptyList();
}
protected void populateFacets( final ArtifactMetadata artifactMetadata )
{
- final List metadataFacetModels = new ArrayList();
+/* final List metadataFacetModels = new ArrayList();
getMetadataFacetModelEntityManager().visitAll( new Function()
{
@@ -1228,14 +1210,14 @@ public class CassandraMetadataRepository
factory.createMetadataFacet( artifactMetadata.getRepositoryId(), entry.getKey() );
metadataFacet.fromProperties( entry.getValue() );
artifactMetadata.addFacet( metadataFacet );
- }
+ }*/
}
@Override
public List getArtifactsByChecksum( final String repositoryId, final String checksum )
throws MetadataRepositoryException
{
- final List artifactMetadataModels = new ArrayList();
+/* final List artifactMetadataModels = new ArrayList();
if ( logger.isDebugEnabled() )
{
@@ -1277,7 +1259,8 @@ public class CassandraMetadataRepository
logger.debug( "getArtifactsByChecksum repositoryId: {}, checksum: {}, artifactMetadatas: {}", repositoryId,
checksum, artifactMetadatas );
- return artifactMetadatas;
+ return artifactMetadatas;*/
+ return Collections.emptyList();
}
@Override
@@ -1285,7 +1268,7 @@ public class CassandraMetadataRepository
final String version, final String id )
throws MetadataRepositoryException
{
- logger.debug( "removeArtifact repositoryId: '{}', namespace: '{}', project: '{}', version: '{}', id: '{}'",
+/* logger.debug( "removeArtifact repositoryId: '{}', namespace: '{}', project: '{}', version: '{}', id: '{}'",
repositoryId, namespace, project, version, id );
String key =
new ArtifactMetadataModel.KeyBuilder().withRepositoryId( repositoryId ).withNamespace( namespace ).withId(
@@ -1303,7 +1286,7 @@ public class CassandraMetadataRepository
ProjectVersionMetadataModel projectVersionMetadataModel = new ProjectVersionMetadataModel();
projectVersionMetadataModel.setRowId( key );
- getProjectVersionMetadataModelEntityManager().remove( projectVersionMetadataModel );
+ getProjectVersionMetadataModelEntityManager().remove( projectVersionMetadataModel );*/
}
@Override
@@ -1313,7 +1296,7 @@ public class CassandraMetadataRepository
logger.debug( "removeArtifact repositoryId: '{}', namespace: '{}', project: '{}', version: '{}', id: '{}'",
artifactMetadata.getRepositoryId(), artifactMetadata.getNamespace(),
artifactMetadata.getProject(), baseVersion, artifactMetadata.getId() );
- String key =
+/* String key =
new ArtifactMetadataModel.KeyBuilder().withRepositoryId( artifactMetadata.getRepositoryId() ).withNamespace(
artifactMetadata.getNamespace() ).withId( artifactMetadata.getId() ).withProjectVersion(
baseVersion ).withProject( artifactMetadata.getProject() ).build();
@@ -1321,7 +1304,7 @@ public class CassandraMetadataRepository
ArtifactMetadataModel artifactMetadataModel = new ArtifactMetadataModel();
artifactMetadataModel.setArtifactMetadataModelId( key );
- getArtifactMetadataModelEntityManager().remove( artifactMetadataModel );
+ getArtifactMetadataModelEntityManager().remove( artifactMetadataModel );*/
}
@Override
@@ -1329,7 +1312,7 @@ public class CassandraMetadataRepository
final String version, final MetadataFacet metadataFacet )
throws MetadataRepositoryException
{
- final List artifactMetadataModels = new ArrayList();
+/* final List artifactMetadataModels = new ArrayList();
getArtifactMetadataModelEntityManager().visitAll( new Function()
{
@Override
@@ -1348,7 +1331,7 @@ public class CassandraMetadataRepository
return Boolean.TRUE;
}
} );
- getArtifactMetadataModelEntityManager().remove( artifactMetadataModels );
+ getArtifactMetadataModelEntityManager().remove( artifactMetadataModels );*/
}
@@ -1357,13 +1340,13 @@ public class CassandraMetadataRepository
public List getArtifacts( final String repositoryId )
throws MetadataRepositoryException
{
- final List artifactMetadataModels = new ArrayList();
+/* final List artifactMetadataModels = new ArrayList();
// FIXME use cql query !
getArtifactMetadataModelEntityManager().visitAll( new Function()
{
@Override
public Boolean apply( ArtifactMetadataModel artifactMetadataModel )
- {
+ {
if ( artifactMetadataModel != null )
{
if ( StringUtils.equals( repositoryId, artifactMetadataModel.getRepositoryId() ) )
@@ -1385,14 +1368,16 @@ public class CassandraMetadataRepository
artifactMetadatas.add( artifactMetadata );
}
- return artifactMetadatas;
+ return artifactMetadatas;*/
+ return Collections.emptyList();
}
@Override
public ProjectMetadata getProject( final String repoId, final String namespace, final String id )
throws MetadataResolutionException
{
- //basically just checking it exists
+
+/* //basically just checking it exists
// FIXME use cql query
final BooleanHolder booleanHolder = new BooleanHolder();
@@ -1427,7 +1412,8 @@ public class CassandraMetadataRepository
logger.debug( "getProject repoId: {}, namespace: {}, projectId: {} -> {}", repoId, namespace, id,
projectMetadata );
- return projectMetadata;
+ return projectMetadata;*/
+ return null;
}
@Override
@@ -1435,7 +1421,7 @@ public class CassandraMetadataRepository
final String projectId, final String projectVersion )
throws MetadataResolutionException
{
- String key = new ProjectVersionMetadataModel.KeyBuilder().withRepository( repoId ).withNamespace(
+/* String key = new ProjectVersionMetadataModel.KeyBuilder().withRepository( repoId ).withNamespace(
namespace ).withProjectId( projectId ).withId( projectVersion ).build();
ProjectVersionMetadataModel projectVersionMetadataModel =
@@ -1512,7 +1498,8 @@ public class CassandraMetadataRepository
}
}
- return projectVersionMetadata;
+ return projectVersionMetadata;*/
+ return null;
}
@@ -1531,7 +1518,7 @@ public class CassandraMetadataRepository
{
final Set projects = new HashSet();
- // FIXME use cql query
+/* // FIXME use cql query
getProjectEntityManager().visitAll( new Function()
{
@Override
@@ -1547,7 +1534,7 @@ public class CassandraMetadataRepository
}
return Boolean.TRUE;
}
- } );
+ } );*/
return projects;
}
@@ -1558,7 +1545,7 @@ public class CassandraMetadataRepository
final String projectVersion )
throws MetadataRepositoryException
{
-
+ /*
final List artifactMetadataModels = new ArrayList();
// FIXME use cql query
@@ -1597,6 +1584,7 @@ public class CassandraMetadataRepository
projectVersionMetadataModel.setRowId( key );
getProjectVersionMetadataModelEntityManager().remove( projectVersionMetadataModel );
+ */
}
@Override
@@ -1605,6 +1593,7 @@ public class CassandraMetadataRepository
throws MetadataResolutionException
{
final List artifactMetadataModels = new ArrayList();
+ /*
// FIXME use cql query !
getArtifactMetadataModelEntityManager().visitAll( new Function()
{
@@ -1625,9 +1614,9 @@ public class CassandraMetadataRepository
return Boolean.TRUE;
}
} );
-
+ */
List artifactMetadatas = new ArrayList( artifactMetadataModels.size() );
-
+ /*
for ( ArtifactMetadataModel model : artifactMetadataModels )
{
ArtifactMetadata artifactMetadata = getModelMapper().map( model, ArtifactMetadata.class );
@@ -1715,7 +1704,7 @@ public class CassandraMetadataRepository
}
-
+ */
return artifactMetadatas;
}
diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraUtils.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraUtils.java
index c295aeab7..d0cf87deb 100644
--- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraUtils.java
+++ b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraUtils.java
@@ -19,6 +19,11 @@ package org.apache.archiva.metadata.repository.cassandra;
* under the License.
*/
+import me.prettyprint.cassandra.serializers.SerializerTypeInferer;
+import me.prettyprint.hector.api.Serializer;
+import me.prettyprint.hector.api.beans.HColumn;
+import me.prettyprint.hector.api.factory.HFactory;
+
/**
* @author Olivier Lamy
* @since 2.0.0
@@ -57,6 +62,14 @@ public class CassandraUtils
return builder.toString();
}
+ public static HColumn column( final A name, final B value )
+ {
+ return HFactory.createColumn( name, //
+ value, //
+ (Serializer) SerializerTypeInferer.getSerializer( name ), //
+ (Serializer) SerializerTypeInferer.getSerializer( value ) );
+ }
+
private CassandraUtils()
{
// no-op
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 e46415be0..3af8ca2d4 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
@@ -19,26 +19,18 @@ package org.apache.archiva.metadata.repository.cassandra;
* under the License.
*/
-import com.google.common.collect.ImmutableMap;
-import com.netflix.astyanax.AstyanaxContext;
-import com.netflix.astyanax.Keyspace;
-import com.netflix.astyanax.connectionpool.NodeDiscoveryType;
-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.Slf4jConnectionPoolMonitorImpl;
-import com.netflix.astyanax.ddl.KeyspaceDefinition;
-import com.netflix.astyanax.entitystore.DefaultEntityManager;
-import com.netflix.astyanax.entitystore.EntityManager;
-import com.netflix.astyanax.impl.AstyanaxConfigurationImpl;
-import com.netflix.astyanax.thrift.ThriftFamilyFactory;
-import org.apache.archiva.metadata.repository.cassandra.model.ArtifactMetadataModel;
-import org.apache.archiva.metadata.repository.cassandra.model.MetadataFacetModel;
-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.ProjectVersionMetadataModel;
-import org.apache.archiva.metadata.repository.cassandra.model.Repository;
+import me.prettyprint.cassandra.model.BasicColumnDefinition;
+import me.prettyprint.cassandra.model.ConfigurableConsistencyLevel;
+import me.prettyprint.cassandra.serializers.StringSerializer;
+import me.prettyprint.cassandra.service.CassandraHostConfigurator;
+import me.prettyprint.cassandra.service.ThriftKsDef;
+import me.prettyprint.hector.api.Cluster;
+import me.prettyprint.hector.api.HConsistencyLevel;
+import me.prettyprint.hector.api.Keyspace;
+import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition;
+import me.prettyprint.hector.api.ddl.ColumnIndexType;
+import me.prettyprint.hector.api.ddl.ComparatorType;
+import me.prettyprint.hector.api.factory.HFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
@@ -47,8 +39,8 @@ 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;
+import java.util.ArrayList;
+import java.util.List;
/**
* FIXME make all configuration not hardcoded :-)
@@ -70,215 +62,104 @@ public class DefaultCassandraArchivaManager
private static final String KEYSPACE_NAME = "ArchivaKeySpace";
- private AstyanaxContext keyspaceContext;
+ private boolean started;
+
+ private Cluster cluster;
private Keyspace keyspace;
- private boolean started = false;
-
- private EntityManager repositoryEntityManager;
-
- private EntityManager namespaceEntityManager;
-
- private EntityManager projectEntityManager;
-
- private EntityManager artifactMetadataModelEntityManager;
-
- private EntityManager metadataFacetModelEntityManager;
-
- private EntityManager projectVersionMetadataModelEntityManager;
-
@PostConstruct
public void initialize()
- throws ConnectionException
{
+ // FIXME must come from configuration not sys props
String cassandraHost = System.getProperty( "cassandraHost", "localhost" );
String cassandraPort = System.getProperty( "cassandraPort" );
- String cqlVersion = System.getProperty( "cassandra.cqlversion", "3.0.0" );
- keyspaceContext = new AstyanaxContext.Builder().forCluster( CLUSTER_NAME ).forKeyspace(
- KEYSPACE_NAME ).withAstyanaxConfiguration(
- new AstyanaxConfigurationImpl()
- //.setCqlVersion( cqlVersion )
- .setDiscoveryType( NodeDiscoveryType.RING_DESCRIBE )
- .setConnectionPoolType( ConnectionPoolType.TOKEN_AWARE ) )
- .withConnectionPoolConfiguration(
- new ConnectionPoolConfigurationImpl( CLUSTER_NAME + "_" + KEYSPACE_NAME )
- .setSocketTimeout( 30000 )
- .setMaxTimeoutWhenExhausted( 2000 )
- .setMaxConnsPerHost( 20 )
- .setInitConnsPerHost( 10 )
- .setSeeds( cassandraHost + ":" + cassandraPort ) )
- .withConnectionPoolMonitor( new Slf4jConnectionPoolMonitorImpl() )
- .buildKeyspace( ThriftFamilyFactory.getInstance() );
+ int maxActive = Integer.getInteger( "cassandra.maxActive", 20 );
+ String readConsistencyLevel =
+ System.getProperty( "cassandra.readConsistencyLevel", HConsistencyLevel.QUORUM.name() );
+ String writeConsistencyLevel =
+ System.getProperty( "cassandra.readConsistencyLevel", HConsistencyLevel.QUORUM.name() );
- this.start();
+ int replicationFactor = Integer.getInteger( "cassandra.replicationFactor", 1 );
- keyspace = keyspaceContext.getClient();
- //Partitioner partitioner = keyspace.getPartitioner();
+ String keyspaceName = System.getProperty( "cassandra.keyspace.name", KEYSPACE_NAME );
+ String clusterName = System.getProperty( "cassandra.cluster.name", CLUSTER_NAME );
- ImmutableMap options = ImmutableMap.builder().put( "strategy_options",
- ImmutableMap.builder().put(
- "replication_factor",
- "1" ).build() ).put(
- "strategy_class", "SimpleStrategy" ).build();
+ final CassandraHostConfigurator configurator =
+ new CassandraHostConfigurator( cassandraHost + ":" + cassandraPort );
+ configurator.setMaxActive( maxActive );
- // test if the namespace already exists if exception or null create it
- boolean keyspaceExists = false;
- try
+ cluster = HFactory.getOrCreateCluster( clusterName, configurator );
+
+ final ConfigurableConsistencyLevel consistencyLevelPolicy = new ConfigurableConsistencyLevel();
+ consistencyLevelPolicy.setDefaultReadConsistencyLevel( HConsistencyLevel.valueOf( readConsistencyLevel ) );
+ consistencyLevelPolicy.setDefaultWriteConsistencyLevel( HConsistencyLevel.valueOf( writeConsistencyLevel ) );
+ keyspace = HFactory.createKeyspace( keyspaceName, cluster, consistencyLevelPolicy );
+
+ List cfds = new ArrayList();
+
+ // namespace table
{
- KeyspaceDefinition keyspaceDefinition = keyspace.describeKeyspace();
- if ( keyspaceDefinition != null )
+
+ final ColumnFamilyDefinition namespaces =
+ HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), "namespace",
+ ComparatorType.UTF8TYPE );
+ cfds.add( namespaces );
+
+ // creating indexes for cql query
+
+ BasicColumnDefinition nameColumn = new BasicColumnDefinition();
+ nameColumn.setName( StringSerializer.get().toByteBuffer( "name" ) );
+ nameColumn.setIndexName( "name" );
+ nameColumn.setIndexType( ColumnIndexType.KEYS );
+ nameColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
+ namespaces.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 );
+ }
+
+ {
+ final ColumnFamilyDefinition repository =
+ HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), "repository",
+ ComparatorType.UTF8TYPE );
+
+ cfds.add( repository );
+
+ BasicColumnDefinition nameColumn = new BasicColumnDefinition();
+ nameColumn.setName( StringSerializer.get().toByteBuffer( "name" ) );
+ nameColumn.setIndexName( "name" );
+ nameColumn.setIndexType( ColumnIndexType.KEYS );
+ nameColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
+ repository.addColumnDefinition( nameColumn );
+ }
+
+ { // ensure keyspace exists, here if the keyspace doesn't exist we suppose nothing exist
+ if ( cluster.describeKeyspace( keyspaceName ) == null )
{
- keyspaceExists = true;
+ logger.info( "Creating Archiva Cassandra '" + keyspaceName + "' keyspace." );
+ cluster.addKeyspace( HFactory.createKeyspaceDefinition( keyspaceName, //
+ ThriftKsDef.DEF_STRATEGY_CLASS, //
+ replicationFactor, //
+ cfds )
+ );
}
-
- }
- catch ( ConnectionException e )
- {
}
- if ( !keyspaceExists )
- {
- keyspace.createKeyspace( options );
- }
-
- try
- {
- Properties properties = keyspace.getKeyspaceProperties();
- logger.info( "keyspace properties: {}", properties );
- }
- catch ( ConnectionException e )
- {
- // FIXME better logging !
- logger.warn( e.getMessage(), e );
- }
-
- try
- {
- repositoryEntityManager =
- DefaultEntityManager.builder()
- .withEntityType( Repository.class )
- .withKeyspace( keyspace )
- .withAutoCommit( true )
- .withColumnFamily( "repository" )
- .build();
- boolean exists = columnFamilyExists( "repository" );
- // TODO very basic test we must test model change too
- if ( !exists )
- {
- repositoryEntityManager.createStorage( null );
- }
-
- namespaceEntityManager =
- DefaultEntityManager.builder()
- .withEntityType( Namespace.class )
- .withKeyspace( keyspace )
- .withAutoCommit( true )
- .withColumnFamily( "namespace" )
- .build();
-
- exists = columnFamilyExists( "namespace" );
- if ( !exists )
- {
- // create secondary index
-
- options =
- ImmutableMap.builder()
- .put("repositoryid", ImmutableMap.builder()
- .put("validation_class", "UTF8Type")
- .put("index_name", "Indexrepositoryid")
- .put("index_type", "KEYS")
- .build()).build();
-
- namespaceEntityManager.createStorage( options );
- }
-
-
-
- projectEntityManager =
- DefaultEntityManager.builder()
- .withEntityType( Project.class )
- .withKeyspace( keyspace )
- .withAutoCommit( true )
- .withColumnFamily( "project" )
- .build();
-
- exists = columnFamilyExists( "project" );
- if ( !exists )
- {
- projectEntityManager.createStorage( null );
- }
-
- artifactMetadataModelEntityManager =
- DefaultEntityManager.builder()
- .withEntityType( ArtifactMetadataModel.class )
- .withAutoCommit( true )
- .withKeyspace( keyspace )
- .withColumnFamily( "artifactmetadatamodel" )
- .build();
-
- exists = columnFamilyExists( "artifactmetadatamodel" );
- if ( !exists )
- {
- artifactMetadataModelEntityManager.createStorage( null );
- }
-
- metadataFacetModelEntityManager =
- DefaultEntityManager.builder()
- .withEntityType( MetadataFacetModel.class )
- .withAutoCommit( true )
- .withKeyspace( keyspace )
- .withColumnFamily( "metadatafacetmodel" )
- .build();
-
- exists = columnFamilyExists( "metadatafacetmodel" );
- if ( !exists )
- {
- metadataFacetModelEntityManager.createStorage( null );
- }
-
- projectVersionMetadataModelEntityManager =
- DefaultEntityManager.builder()
- .withEntityType( ProjectVersionMetadataModel.class )
- .withAutoCommit( true )
- .withKeyspace( keyspace )
- .withColumnFamily( "projectversionmetadatamodel" )
- .build();
-
- exists = columnFamilyExists( "projectversionmetadatamodel" );
- if ( !exists )
- {
- projectVersionMetadataModelEntityManager.createStorage( null );
- }
-
- }
- catch ( PersistenceException e )
- {
- // FIXME report exception
- logger.error( e.getMessage(), e );
- }
- catch ( ConnectionException e )
- {
- // FIXME report exception
- logger.error( e.getMessage(), e );
- }
}
public void start()
{
- keyspaceContext.start();
- started = true;
}
@PreDestroy
public void shutdown()
{
- if ( keyspaceContext != null )
- {
- keyspaceContext.shutdown();
- started = false;
- }
}
@@ -288,21 +169,6 @@ public class DefaultCassandraArchivaManager
return started;
}
- private boolean columnFamilyExists( String columnFamilyName )
- throws ConnectionException
- {
- try
- {
- Properties properties = keyspace.getColumnFamilyProperties( columnFamilyName );
- logger.debug( "getColumnFamilyProperties for {}: {}", columnFamilyName, properties );
- return true;
- }
- catch ( NotFoundException e )
- {
- return false;
- }
- }
-
@Override
public Keyspace getKeyspace()
@@ -310,66 +176,8 @@ public class DefaultCassandraArchivaManager
return keyspace;
}
- public EntityManager getRepositoryEntityManager()
+ public Cluster getCluster()
{
- return repositoryEntityManager;
- }
-
- public void setRepositoryEntityManager( EntityManager repositoryEntityManager )
- {
- this.repositoryEntityManager = repositoryEntityManager;
- }
-
- public EntityManager getNamespaceEntityManager()
- {
- return namespaceEntityManager;
- }
-
- public void setNamespaceEntityManager( EntityManager namespaceEntityManager )
- {
- this.namespaceEntityManager = namespaceEntityManager;
- }
-
- public EntityManager getProjectEntityManager()
- {
- return projectEntityManager;
- }
-
- public void setProjectEntityManager( EntityManager projectEntityManager )
- {
- this.projectEntityManager = projectEntityManager;
- }
-
- public EntityManager getArtifactMetadataModelEntityManager()
- {
- return artifactMetadataModelEntityManager;
- }
-
- public void setArtifactMetadataModelEntityManager(
- EntityManager artifactMetadataModelEntityManager )
- {
- this.artifactMetadataModelEntityManager = artifactMetadataModelEntityManager;
- }
-
- public EntityManager getMetadataFacetModelEntityManager()
- {
- return metadataFacetModelEntityManager;
- }
-
- public void setMetadataFacetModelEntityManager(
- EntityManager metadataFacetModelEntityManager )
- {
- this.metadataFacetModelEntityManager = metadataFacetModelEntityManager;
- }
-
- public EntityManager getProjectVersionMetadataModelEntityManager()
- {
- return projectVersionMetadataModelEntityManager;
- }
-
- public void setProjectVersionMetadataModelEntityManager(
- EntityManager projectVersionMetadataModelEntityManager )
- {
- this.projectVersionMetadataModelEntityManager = projectVersionMetadataModelEntityManager;
+ return cluster;
}
}
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 ffc93be4e..ca1586537 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,12 +19,9 @@ 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;
import java.io.Serializable;
import java.util.Date;
@@ -35,58 +32,45 @@ import java.util.Date;
* @author Olivier Lamy
* @since 2.0.0
*/
-@Entity
public class ArtifactMetadataModel
implements Serializable
{
// repositoryId + namespaceId + project + projectVersion + id
@Id
- @Serializer( DeflateStringSerializer.class )
private String artifactMetadataModelId;
- @Column( name = "id" )
- @Serializer( DeflateStringSerializer.class )
+ @Column(name = "id")
private String id;
- @Column( name = "repositoryId" )
- @Serializer( DeflateStringSerializer.class )
+ @Column(name = "repositoryId")
private String repositoryId;
- @Column( name = "namespace" )
- @Serializer( DeflateStringSerializer.class )
+ @Column(name = "namespace")
private String namespace;
- @Column( name = "project" )
- @Serializer( DeflateStringSerializer.class )
+ @Column(name = "project")
private String project;
- @Column( name = "projectVersion" )
- @Serializer( DeflateStringSerializer.class )
+ @Column(name = "projectVersion")
private String projectVersion;
- @Column( name = "version" )
- @Serializer( DeflateStringSerializer.class )
+ @Column(name = "version")
private String version;
- @Column( name = "fileLastModified" )
- @Serializer( LongSerializer.class )
+ @Column(name = "fileLastModified")
private long fileLastModified;
- @Column( name = "size" )
- @Serializer( LongSerializer.class )
+ @Column(name = "size")
private long size;
- @Column( name = "md5" )
- @Serializer( DeflateStringSerializer.class )
+ @Column(name = "md5")
private String md5;
- @Column( name = "sha1" )
- @Serializer( DeflateStringSerializer.class )
+ @Column(name = "sha1")
private String sha1;
- @Column( name = "whenGathered" )
- @Serializer( LongSerializer.class )
+ @Column(name = "whenGathered")
private long whenGathered;
public ArtifactMetadataModel()
diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/DeflateStringSerializer.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/DeflateStringSerializer.java
deleted file mode 100644
index d8b17a28d..000000000
--- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/DeflateStringSerializer.java
+++ /dev/null
@@ -1,149 +0,0 @@
-package org.apache.archiva.metadata.repository.cassandra.model;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-import com.netflix.astyanax.serializers.AbstractSerializer;
-import com.netflix.astyanax.serializers.ComparatorType;
-import org.apache.commons.codec.binary.StringUtils;
-import org.apache.commons.io.IOUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.charset.Charset;
-import java.util.zip.Deflater;
-import java.util.zip.DeflaterOutputStream;
-import java.util.zip.InflaterInputStream;
-
-
-/**
- * For Huge String we use a deflate compression
- * @author Olivier Lamy
- * @since 2.0.0
- */
-public class DeflateStringSerializer
- extends AbstractSerializer
-{
-
- private Logger logger = LoggerFactory.getLogger( getClass() );
-
- private static final String UTF_8 = "UTF-8";
-
- private static final DeflateStringSerializer instance = new DeflateStringSerializer();
-
- private static final Charset charset = Charset.forName( UTF_8 );
-
- public static DeflateStringSerializer get()
- {
- return instance;
- }
-
- @Override
- public ByteBuffer toByteBuffer( String obj )
- {
- if ( obj == null )
- {
- return null;
- }
-
- try
- {
- byte[] bytes = compressWithDeflate( StringUtils.getBytesUtf8( obj ) );
- return ByteBuffer.wrap( bytes );
- }
- catch ( IOException e )
- {
- throw new RuntimeException( "Fail to compress column data", e );
- }
- }
-
- @Override
- public String fromByteBuffer( ByteBuffer byteBuffer )
- {
- if ( byteBuffer == null )
- {
- return null;
- }
-
- ByteBuffer dup = byteBuffer.duplicate();
- try
- {
- String str = getFromDeflateBytes( dup.array() );
- return str;
- }
- catch ( IOException e )
- {
- throw new RuntimeException( "Fail to decompress column data", e );
- }
-
- }
-
- public String getFromDeflateBytes( byte[] bytes )
- throws IOException
- {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( bytes );
- InflaterInputStream inflaterInputStream = new InflaterInputStream( byteArrayInputStream );
- return IOUtils.toString( inflaterInputStream );
- }
-
- public byte[] compressWithDeflate( byte[] unCompress )
- throws IOException
- {
- try
- {
- ByteArrayOutputStream buffer = new ByteArrayOutputStream();
- DeflaterOutputStream out = new DeflaterOutputStream( buffer, new Deflater( Deflater.BEST_COMPRESSION ) );
- out.write( unCompress );
- out.finish();
- ByteArrayInputStream bais = new ByteArrayInputStream( buffer.toByteArray() );
- byte[] res = IOUtils.toByteArray( bais );
- return res;
- }
- catch ( IOException e )
- {
- logger.debug( "IOException in compressStringWithDeflate", e );
- throw e;
- }
-
- }
-
- @Override
- public ComparatorType getComparatorType()
- {
- return ComparatorType.BYTESTYPE;
- }
-
- @Override
- public ByteBuffer fromString( String str )
- {
- return instance.fromString( str );
- }
-
- @Override
- public String getString( ByteBuffer byteBuffer )
- {
- return instance.getString( byteBuffer );
- }
-
-}
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 a6616dda6..1ec8c6b6e 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,11 +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;
/**
@@ -32,32 +30,26 @@ import javax.persistence.Id;
* @author Olivier Lamy
* @since 2.0.0
*/
-@Entity
public class MetadataFacetModel
{
// id is repositoryId + namespaceId + projectId + facetId + name + mapKey
@Id
- @Column( name = "id" )
- @Serializer( DeflateStringSerializer.class )
+ @Column(name = "id")
private String id;
- @Column( name = "artifactMetadataModel" )
+ @Column(name = "artifactMetadataModel")
private ArtifactMetadataModel artifactMetadataModel;
- @Column( name = "facetId" )
- @Serializer( DeflateStringSerializer.class )
+ @Column(name = "facetId")
private String facetId;
- @Column( name = "key" )
- @Serializer( DeflateStringSerializer.class )
+ @Column(name = "key")
private String key;
- @Column( name = "name" )
- @Serializer( DeflateStringSerializer.class )
+ @Column(name = "name")
private String name;
- @Column( name = "value" )
- @Serializer( DeflateStringSerializer.class )
+ @Column(name = "value")
private String value;
public MetadataFacetModel()
@@ -232,7 +224,8 @@ public class MetadataFacetModel
String str = CassandraUtils.generateKey( this.artifactMetadataModel == null
? this.repositoryId
: this.artifactMetadataModel.getArtifactMetadataModelId(),
- this.facetId, this.name, this.key );
+ 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 8c2ff27c3..a3dcefec8 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,12 +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;
import java.io.Serializable;
@@ -32,32 +29,18 @@ import java.io.Serializable;
* @author Olivier Lamy
* @since 2.0.0
*/
-@Entity
public class Namespace
implements Serializable
{
- @Id
- @Serializer( DeflateStringSerializer.class )
private String id;
- @Column( name = "name" )
- @Serializer( DeflateStringSerializer.class )
private String name;
- @Column( name = "repositoryid" )
- @Serializer( DeflateStringSerializer.class )
private String repositoryId;
- @Column( name = "repositoryname" )
- @Serializer( DeflateStringSerializer.class )
private String repositoryName;
- //@ManyToOne(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
- //@JoinColumn(name = "repository_id")
- //private transient Repository repository;
-
-
public Namespace()
{
// no op
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 9ee564ee1..74ac18972 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,11 +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;
import java.io.Serializable;
@@ -31,21 +29,18 @@ import java.io.Serializable;
* @author Olivier Lamy
* @since 2.0.0
*/
-@Entity
public class Project
implements Serializable
{
@Id
- @Column( name = "projectKey" )
- @Serializer( DeflateStringSerializer.class )
+ @Column(name = "projectKey")
private String projectKey;
- @Column( name = "projectId" )
- @Serializer( DeflateStringSerializer.class )
+ @Column(name = "projectId")
private String projectId;
- @Column( name = "repository" )
+ @Column(name = "repository")
private Namespace namespace;
public Project()
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 41f54aa47..e1160a98f 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,7 +19,6 @@ 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;
@@ -30,7 +29,6 @@ import org.apache.archiva.metadata.model.Scm;
import org.apache.archiva.metadata.repository.cassandra.CassandraUtils;
import javax.persistence.Column;
-import javax.persistence.Entity;
import javax.persistence.Id;
import java.util.ArrayList;
import java.util.List;
@@ -39,63 +37,56 @@ import java.util.List;
* @author Olivier Lamy
* @since 2.0.0
*/
-@Entity
public class ProjectVersionMetadataModel
{
// repositoryId + namespace + projectId + id (version)
@Id
- @Serializer( DeflateStringSerializer.class )
private String rowId;
- @Column( name = "namespace" )
+ @Column(name = "namespace")
private Namespace namespace;
/**
* id is the version
*/
- @Column( name = "id" )
- @Serializer( DeflateStringSerializer.class )
+ @Column(name = "id")
private String id;
- @Column( name = "projectId" )
- @Serializer( DeflateStringSerializer.class )
+ @Column(name = "projectId")
private String projectId;
- @Column( name = "url" )
- @Serializer( DeflateStringSerializer.class )
+ @Column(name = "url")
private String url;
- @Column( name = "name" )
- @Serializer( DeflateStringSerializer.class )
+ @Column(name = "name")
private String name;
- @Column( name = "description" )
- @Serializer( DeflateStringSerializer.class )
+ @Column(name = "description")
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()
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 3268ccae2..30c9ce55e 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,12 +19,6 @@ 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;
-import javax.persistence.Table;
import java.io.Serializable;
@@ -32,22 +26,14 @@ import java.io.Serializable;
* @author Olivier Lamy
* @since 2.0.0
*/
-@Entity
public class Repository
implements Serializable
{
- @Id
- @Column( name = "id" )
- @Serializer( DeflateStringSerializer.class )
private String id;
- @Column(name = "name")
- @Serializer( DeflateStringSerializer.class )
private String name;
- //private transient List namespaces = new ArrayList();
-
public Repository()
{
// no op
@@ -79,22 +65,6 @@ public class Repository
this.name = name;
}
- /*
- public List getNamespaces()
- {
- if ( this.namespaces == null )
- {
- this.namespaces = new ArrayList();
- }
- return namespaces;
- }
-
- public void setNamespaces( List namespaces )
- {
- this.namespaces = namespaces;
- }
- */
-
@Override
public boolean equals( Object o )
{
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 0e73da67f..ed71dc7c7 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
@@ -41,7 +41,7 @@ public class CassandraMetadataRepositoryTest
private Logger logger = LoggerFactory.getLogger( getClass() );
@Inject
- @Named( value = "archivaEntityManagerFactory#cassandra" )
+ @Named(value = "archivaEntityManagerFactory#cassandra")
CassandraArchivaManager cassandraArchivaManager;
CassandraMetadataRepository cmr;
@@ -78,45 +78,12 @@ 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();
+ cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
+ "project" );
+ cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
+ "namespace" );
+ cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
+ "repository" );
}
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 a0637d229..c6cd742f2 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
@@ -37,15 +37,15 @@ import javax.inject.Named;
/**
* @author Olivier Lamy
*/
-@RunWith(ArchivaSpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" })
+@RunWith( ArchivaSpringJUnit4ClassRunner.class )
+@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
public class RepositoriesNamespaceTest
{
private Logger logger = LoggerFactory.getLogger( getClass() );
@Inject
- @Named(value = "archivaEntityManagerFactory#cassandra")
+ @Named( value = "archivaEntityManagerFactory#cassandra" )
CassandraArchivaManager cassandraArchivaManager;
@@ -85,24 +85,35 @@ public class RepositoriesNamespaceTest
cmr.updateNamespace( "release", "org" );
- r = cmr.getRepositoryEntityManager().get( "release" );
+ r = cmr.getRepository( "release" );
Assertions.assertThat( r ).isNotNull();
Assertions.assertThat( cmr.getRepositories() ).isNotEmpty().hasSize( 1 );
Assertions.assertThat( cmr.getNamespaces( "release" ) ).isNotEmpty().hasSize( 1 );
- n = cmr.getNamespaceEntityManager().get( "release" + CassandraUtils.SEPARATOR + "org" );
+ n = cmr.getNamespace( "release", "org" );
Assertions.assertThat( n ).isNotNull();
Assertions.assertThat( n.getRepository() ).isNotNull();
cmr.updateNamespace( "release", "org.apache" );
- r = cmr.getRepositoryEntityManager().get( "release" );
+ r = cmr.getRepository( "release" );
Assertions.assertThat( r ).isNotNull();
Assertions.assertThat( cmr.getNamespaces( "release" ) ).isNotEmpty().hasSize( 2 );
+
+ cmr.removeNamespace( "release", "org.apache" );
+ Assertions.assertThat( cmr.getNamespaces( "release" ) ).isNotEmpty().hasSize( 1 );
+ Assertions.assertThat( cmr.getNamespaces( "release" ) ).containsExactly( "org" );
+
+ cmr.removeRepository( "release" );
+
+ r = cmr.getRepository( "release" );
+
+ Assertions.assertThat( r ).isNull();
+
}
catch ( Exception e )
{
@@ -118,22 +129,11 @@ 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();
+ cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
+ "project" );
+ cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
+ "namespace" );
+ cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
+ "repository" );
}
}