<name>Archiva Core Plugins :: Cassandra JPA Storage for Metadata</name>
<properties>
- <cassandraVersion>1.2.9</cassandraVersion>
- <astyanax.version>1.56.43</astyanax.version>
+ <!--
+ <cassandraVersion>1.2.11</cassandraVersion>
+ -->
+ <cassandraVersion>2.0.2</cassandraVersion>
+ <astyanax.version>1.56.44</astyanax.version>
</properties>
<dependencies>
org.apache.commons.lang;version="[2.4,3)",
org.slf4j;resolution:=optional,
org.springframework.context,
- org.springframework.stereotype
+ org.springframework.stereotype,
+ com.netflix.astyanax.serializers,
+ org.apache.commons.codec.binary,
+ org.apache.commons.io
</Import-Package>
</instructions>
</configuration>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cassandra-maven-plugin</artifactId>
- <version>1.2.5-1-SNAPSHOT</version>
+ <version>2.0.0-1-SNAPSHOT</version>
<executions>
<execution>
<id>start-cassandra</id>
{
Keyspace getKeyspace();
+ void start();
+
+ void shutdown();
+
+ boolean started();
+
EntityManager<Repository, String> getRepositoryEntityManager();
EntityManager<Namespace, String> getNamespaceEntityManager();
private CassandraEntityManagerFactory cassandraEntityManagerFactory;
public CassandraMetadataRepository( Map<String, MetadataFacetFactory> metadataFacetFactories,
- ArchivaConfiguration configuration, CassandraEntityManagerFactory cassandraEntityManagerFactory )
+ ArchivaConfiguration configuration,
+ CassandraEntityManagerFactory cassandraEntityManagerFactory )
{
this.metadataFacetFactories = metadataFacetFactories;
this.configuration = configuration;
this.cassandraEntityManagerFactory = cassandraEntityManagerFactory;
}
-
public EntityManager<Repository, String> getRepositoryEntityManager()
{
{
try
{
- final Set<String> namespaces = new HashSet<String>();
+
+ //final List<Namespace> namespaceList =
+ // getNamespaceEntityManager().find( "SELECT name FROM namespace WHERE repository.id='"+ repoId + "'" );
+
+ //final Set<String> namespaces = new HashSet<String>( namespaceList.size() );
+
+ final Set<String> namespaces = new HashSet<String>( );
+
+ /*
+ for ( Namespace namespace : namespaceList )
+ {
+ String name = namespace.getName();
+ if ( StringUtils.isNotEmpty( name ) )
+ {
+ namespaces.add( StringUtils.substringBefore( name, "." ) );
+ }
+ }
+ */
+
getNamespaceEntityManager().visitAll( new Function<Namespace, Boolean>()
{
@Override
public Boolean apply( Namespace namespace )
{
- if ( namespace != null && namespace.getRepository() != null && StringUtils.equalsIgnoreCase( repoId,
- namespace.getRepository().getId() ) )
+ if ( namespace != null && namespace.getRepository() != null
+ && StringUtils.equalsIgnoreCase( repoId, namespace.getRepository().getId() ) )
{
String name = namespace.getName();
if ( StringUtils.isNotEmpty( name ) )
//List<Namespace> namespaces = getNamespaceEntityManager().find( query );
- final Set<Namespace> namespaces = new HashSet<Namespace>();
+ //final Set<Namespace> namespaces = new HashSet<Namespace>();
+ final Set<String> namespaces = new HashSet<String>();
getNamespaceEntityManager().visitAll( new Function<Namespace, Boolean>()
{
if ( namespace != null && namespace.getRepository() != null && StringUtils.equalsIgnoreCase( repoId,
namespace.getRepository().getId() ) )
{
- namespaces.add( namespace );
+ namespaces.add( namespace.getId() );
}
return Boolean.TRUE;
}
} );
- repository.setNamespaces( new ArrayList<Namespace>( namespaces ) );
+ /*
+
+ repository.setNamespaces( new ArrayList<Namespace>( namespaces ) );
if ( repository == null || repository.getNamespaces().isEmpty() )
{
return Collections.emptyList();
}
+
List<String> namespaceIds = new ArrayList<String>( repository.getNamespaces().size() );
for ( Namespace n : repository.getNamespaces() )
}
logger.debug( "getNamespaces for repository '{}' found {}", repoId, namespaceIds.size() );
+
return namespaceIds;
+ */
+ return new ArrayList<String>( namespaces );
}
catch ( PersistenceException e )
{
key = new ProjectVersionMetadataModel.KeyBuilder().withRepository( repositoryId ).withNamespace(
namespace ).withProjectId( projectId ).withId( projectVersion ).build();
- ProjectVersionMetadataModel projectVersionMetadataModel = getProjectVersionMetadataModelEntityManager().get( key );
+ ProjectVersionMetadataModel projectVersionMetadataModel =
+ getProjectVersionMetadataModelEntityManager().get( key );
if ( projectVersionMetadataModel == null )
{
key = new ProjectVersionMetadataModel.KeyBuilder().withRepository( repositoryId ).withNamespace(
namespaceId ).withProjectId( projectId ).withId( versionMetadata.getId() ).build();
- ProjectVersionMetadataModel projectVersionMetadataModel = getProjectVersionMetadataModelEntityManager().get( key );
+ ProjectVersionMetadataModel projectVersionMetadataModel =
+ getProjectVersionMetadataModelEntityManager().get( key );
if ( projectVersionMetadataModel == null )
{
projectVersionMetadataModel.setDependencies( versionMetadata.getDependencies() );
projectVersionMetadataModel.setLicenses( versionMetadata.getLicenses() );
-
try
{
getProjectVersionMetadataModelEntityManager().put( projectVersionMetadataModel );
String key = new ProjectVersionMetadataModel.KeyBuilder().withRepository( repoId ).withNamespace(
namespace ).withProjectId( projectId ).withId( projectVersion ).build();
- ProjectVersionMetadataModel projectVersionMetadataModel = getProjectVersionMetadataModelEntityManager().get( key );
+ ProjectVersionMetadataModel projectVersionMetadataModel =
+ getProjectVersionMetadataModelEntityManager().get( key );
if ( projectVersionMetadataModel == null )
{
import com.netflix.astyanax.connectionpool.exceptions.NotFoundException;
import com.netflix.astyanax.connectionpool.impl.ConnectionPoolConfigurationImpl;
import com.netflix.astyanax.connectionpool.impl.ConnectionPoolType;
-import com.netflix.astyanax.connectionpool.impl.CountingConnectionPoolMonitor;
import com.netflix.astyanax.connectionpool.impl.Slf4jConnectionPoolMonitorImpl;
import com.netflix.astyanax.ddl.KeyspaceDefinition;
import com.netflix.astyanax.entitystore.DefaultEntityManager;
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;
private Keyspace keyspace;
+ private boolean started = false;
+
private EntityManager<Repository, String> repositoryEntityManager;
private EntityManager<Namespace, String> namespaceEntityManager;
cassandraHost + ":" + cassandraPort ) ).withConnectionPoolMonitor(
new Slf4jConnectionPoolMonitorImpl() ).buildKeyspace( ThriftFamilyFactory.getInstance() );
- keyspaceContext.start();
+ this.start();
keyspace = keyspaceContext.getClient();
+ //Partitioner partitioner = keyspace.getPartitioner();
ImmutableMap<String, Object> options = ImmutableMap.<String, Object>builder().put( "strategy_options",
ImmutableMap.<String, Object>builder().put(
{
repositoryEntityManager =
new DefaultEntityManager.Builder<Repository, String>().withEntityType( Repository.class ).withKeyspace(
- keyspace ).build();
+ keyspace ).withAutoCommit( true ).build();
boolean exists = columnFamilyExists( "repository" );
// TODO very basic test we must test model change too
if ( !exists )
namespaceEntityManager =
new DefaultEntityManager.Builder<Namespace, String>().withEntityType( Namespace.class ).withKeyspace(
- keyspace ).build();
+ keyspace ).withAutoCommit( true ).build();
exists = columnFamilyExists( "namespace" );
if ( !exists )
projectEntityManager =
new DefaultEntityManager.Builder<Project, String>().withEntityType( Project.class ).withKeyspace(
- keyspace ).build();
+ keyspace ).withAutoCommit( true ).build();
exists = columnFamilyExists( "project" );
if ( !exists )
artifactMetadataModelEntityManager =
new DefaultEntityManager.Builder<ArtifactMetadataModel, String>().withEntityType(
- ArtifactMetadataModel.class ).withKeyspace( keyspace ).build();
+ ArtifactMetadataModel.class ).withAutoCommit( true ).withKeyspace( keyspace ).build();
exists = columnFamilyExists( "artifactmetadatamodel" );
if ( !exists )
metadataFacetModelEntityManager =
new DefaultEntityManager.Builder<MetadataFacetModel, String>().withEntityType(
- MetadataFacetModel.class ).withKeyspace( keyspace ).build();
+ MetadataFacetModel.class ).withAutoCommit( true ).withKeyspace( keyspace ).build();
exists = columnFamilyExists( "metadatafacetmodel" );
if ( !exists )
projectVersionMetadataModelEntityManager =
new DefaultEntityManager.Builder<ProjectVersionMetadataModel, String>().withEntityType(
- ProjectVersionMetadataModel.class ).withKeyspace( keyspace ).build();
+ ProjectVersionMetadataModel.class ).withAutoCommit( true ).withKeyspace( keyspace ).build();
exists = columnFamilyExists( "projectversionmetadatamodel" );
if ( !exists )
}
}
+ public void start()
+ {
+ keyspaceContext.start();
+ started = true;
+ }
+
+ @PreDestroy
+ public void shutdown()
+ {
+ if ( keyspaceContext != null )
+ {
+ keyspaceContext.shutdown();
+ started = false;
+ }
+ }
+
+
+ @Override
+ public boolean started()
+ {
+ return started;
+ }
+
private boolean columnFamilyExists( String columnFamilyName )
throws ConnectionException
{
* 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;
// repositoryId + namespaceId + project + projectVersion + id
@Id
+ @Serializer( HugeStringSerializer.class )
private String artifactMetadataModelId;
- @Column(name = "id")
+ @Column( name = "id" )
+ @Serializer( HugeStringSerializer.class )
private String id;
- @Column(name = "repositoryId")
+ @Column( name = "repositoryId" )
+ @Serializer( HugeStringSerializer.class )
private String repositoryId;
- @Column(name = "namespace")
+ @Column( name = "namespace" )
+ @Serializer( HugeStringSerializer.class )
private String namespace;
- @Column(name = "project")
+ @Column( name = "project" )
+ @Serializer( HugeStringSerializer.class )
private String project;
- @Column(name = "projectVersion")
+ @Column( name = "projectVersion" )
+ @Serializer( HugeStringSerializer.class )
private String projectVersion;
- @Column(name = "version")
+ @Column( name = "version" )
+ @Serializer( HugeStringSerializer.class )
private String version;
- @Column(name = "fileLastModified")
+ @Column( name = "fileLastModified" )
+ @Serializer( LongSerializer.class )
private long fileLastModified;
- @Column(name = "size")
+ @Column( name = "size" )
+ @Serializer( LongSerializer.class )
private long size;
- @Column(name = "md5")
+ @Column( name = "md5" )
+ @Serializer( HugeStringSerializer.class )
private String md5;
- @Column(name = "sha1")
+ @Column( name = "sha1" )
+ @Serializer( HugeStringSerializer.class )
private String sha1;
- @Column(name = "whenGathered")
+ @Column( name = "whenGathered" )
+ @Serializer( LongSerializer.class )
private long whenGathered;
public ArtifactMetadataModel()
{
//repositoryId + namespaceId + project + projectVersion + id
// FIXME add some controls
- long hash = this.repositoryId.hashCode() + this.namespaceId.hashCode() + this.project.hashCode() + this.projectVersion.hashCode() + this.id.hashCode();
- return Long.toString( hash );
+
+ String str =
+ CassandraUtils.generateKey( this.repositoryId, this.namespaceId, this.project, this.projectVersion,
+ this.id );
+
+ //return Long.toString( str.hashCode() );
+ return str;
}
}
* under the License.
*/
+import com.netflix.astyanax.entitystore.Serializer;
+import com.netflix.astyanax.serializers.GzipStringSerializer;
+import org.apache.archiva.metadata.repository.cassandra.CassandraUtils;
+
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
{
// id is repositoryId + namespaceId + projectId + facetId + name + mapKey
@Id
- @Column(name = "id")
+ @Column( name = "id" )
+ @Serializer( HugeStringSerializer.class )
private String id;
- @Column(name = "artifactMetadataModel")
+ @Column( name = "artifactMetadataModel" )
private ArtifactMetadataModel artifactMetadataModel;
- @Column(name = "facetId")
+ @Column( name = "facetId" )
+ @Serializer( HugeStringSerializer.class )
private String facetId;
- @Column(name = "name")
- private String name;
-
- @Column(name = "key")
+ @Column( name = "key" )
+ @Serializer( HugeStringSerializer.class )
private String key;
- @Column(name = "value")
+ @Column( name = "name" )
+ @Serializer( HugeStringSerializer.class )
+ private String name;
+
+ @Column( name = "value" )
+ @Serializer( HugeStringSerializer.class )
private String value;
public MetadataFacetModel()
// FIXME add some controls
// getArtifactMetadataModelId can have no namespace, no project and no projectid for statistics
// only repositoryId with artifactMetadataModel
- long hash =
- ( this.artifactMetadataModel == null
- ? this.repositoryId.hashCode()
- : Long.parseLong( this.artifactMetadataModel.getArtifactMetadataModelId() ) )
- + this.facetId.hashCode()
- + ( this.name == null ? 0 : this.name.hashCode() )
- + ( this.key == null ? 0 : this.key.hashCode() );
-
- String hashStr = Long.toString( hash );
- return hashStr;
+ String str = CassandraUtils.generateKey( this.artifactMetadataModel == null
+ ? this.repositoryId
+ : this.artifactMetadataModel.getArtifactMetadataModelId(),
+ this.facetId, this.name, this.key );
+
+ //return Long.toString( str.hashCode() );
+ return str;
}
}
}
* 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;
implements Serializable
{
- private static final long serialVersionUID = 1L;
-
@Id
- @Column(name = "id")
+ @Column( name = "id" )
+ @Serializer( HugeStringSerializer.class )
private String id;
- @Column(name = "name")
+ @Column( name = "name" )
+ @Serializer( HugeStringSerializer.class )
private String name;
- @Column(name = "repository")
+ @Column( name = "repository" )
private Repository repository;
//@ManyToOne(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
this.repository = repository;
}
- /*
- public String getRepositoryId()
- {
- return repositoryId;
- }
-
- public void setRepositoryId( String repositoryId )
- {
- this.repositoryId = repositoryId;
- }*/
-
@Override
public boolean equals( Object o )
{
public String build()
{
// FIXME add some controls
- return this.repositoryId + "-" + this.namespace;
+ return CassandraUtils.generateKey( this.repositoryId, this.namespace );
}
}
}
* 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;
{
@Id
@Column( name = "projectKey" )
+ @Serializer( HugeStringSerializer.class )
private String projectKey;
@Column( name = "projectId" )
+ @Serializer( HugeStringSerializer.class )
private String projectId;
public String build()
{
// FIXME add some controls
- return new Namespace.KeyBuilder().withNamespace( this.namespace ).build() + "-" + this.projectId;
+ return CassandraUtils.generateKey( new Namespace.KeyBuilder().withNamespace( this.namespace ).build(),
+ this.projectId );
}
}
}
* 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;
import org.apache.archiva.metadata.model.MailingList;
import org.apache.archiva.metadata.model.Organization;
import org.apache.archiva.metadata.model.Scm;
+import org.apache.archiva.metadata.repository.cassandra.CassandraUtils;
import javax.persistence.Column;
import javax.persistence.Entity;
{
// repositoryId + namespace + projectId + id (version)
@Id
+ @Serializer( HugeStringSerializer.class )
private String rowId;
- @Column(name = "namespace")
+ @Column( name = "namespace" )
private Namespace namespace;
/**
* id is the version
*/
- @Column(name = "id")
+ @Column( name = "id" )
+ @Serializer( HugeStringSerializer.class )
private String id;
- @Column(name = "projectId")
+ @Column( name = "projectId" )
+ @Serializer( HugeStringSerializer.class )
private String projectId;
- @Column(name = "url")
+ @Column( name = "url" )
+ @Serializer( HugeStringSerializer.class )
private String url;
- @Column(name = "name")
+ @Column( name = "name" )
+ @Serializer( HugeStringSerializer.class )
private String name;
- @Column(name = "description")
+ @Column( name = "description" )
+ @Serializer( HugeStringSerializer.class )
private String description;
- @Column(name = "organization")
+ @Column( name = "organization" )
private Organization organization;
- @Column(name = "issueManagement")
+ @Column( name = "issueManagement" )
private IssueManagement issueManagement;
- @Column(name = "scm")
+ @Column( name = "scm" )
private Scm scm;
- @Column(name = "ciManagement")
+ @Column( name = "ciManagement" )
private CiManagement ciManagement;
// FIXME store those values in a separate table
- @Column(name = "licenses")
+ @Column( name = "licenses" )
private List<License> licenses = new ArrayList<License>();
- @Column(name = "mailingLists")
+ @Column( name = "mailingLists" )
private List<MailingList> mailingLists = new ArrayList<MailingList>();
- @Column(name = "dependencies")
+ @Column( name = "dependencies" )
private List<Dependency> dependencies = new ArrayList<Dependency>();
- @Column(name = "incomplete")
+ @Column( name = "incomplete" )
private boolean incomplete;
public String getProjectId()
public String build()
{
// FIXME add some controls
- long hash =
- this.repositoryId.hashCode() + this.namespace.hashCode() + this.projectId.hashCode() + ( this.id == null
- ? 0
- : +this.id.hashCode() );
- return Long.toString( hash );
+ return CassandraUtils.generateKey( this.repositoryId, this.namespace, this.projectId, this.id );
}
}
}
* under the License.
*/
+import com.netflix.astyanax.entitystore.Serializer;
+
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
implements Serializable
{
- private static final long serialVersionUID = 1L;
-
@Id
@Column( name = "id" )
+ @Serializer( HugeStringSerializer.class )
private String id;
@Column(name = "name")
+ @Serializer( HugeStringSerializer.class )
private String name;
- private transient List<Namespace> namespaces = new ArrayList<Namespace>();
+ //private transient List<Namespace> namespaces = new ArrayList<Namespace>();
public Repository()
{
this.name = name;
}
-
+ /*
public List<Namespace> getNamespaces()
{
if ( this.namespaces == null )
{
this.namespaces = namespaces;
}
+ */
@Override
public boolean equals( Object o )
final StringBuilder sb = new StringBuilder( "Repository{" );
sb.append( "id='" ).append( id ).append( '\'' );
sb.append( ", name='" ).append( name ).append( '\'' );
- sb.append( ", namespaces=" ).append( namespaces );
+ //sb.append( ", namespaces=" ).append( namespaces );
sb.append( '}' );
return sb.toString();
}
protected void clearReposAndNamespace()
throws Exception
{
+ /*
List<Project> projects = cmr.getProjectEntityManager().getAll();
cmr.getProjectEntityManager().remove( projects );
+ */
+ cmr.getProjectEntityManager().truncate();
+ /*
List<Namespace> namespaces = cmr.getNamespaceEntityManager().getAll();
cmr.getNamespaceEntityManager().remove( namespaces );
+ */
+ cmr.getNamespaceEntityManager().truncate();
+ /*
List<Repository> repositories = cmr.getRepositoryEntityManager().getAll();
cmr.getRepositoryEntityManager().remove( repositories );
+ */
+ cmr.getRepositoryEntityManager().truncate();
+ /*
List<ArtifactMetadataModel> artifactMetadataModels = cmr.getArtifactMetadataModelEntityManager().getAll();
cmr.getArtifactMetadataModelEntityManager().remove( artifactMetadataModels );
+ */
+ cmr.getArtifactMetadataModelEntityManager().truncate();
+ /*
List<MetadataFacetModel> metadataFacetModels = cmr.getMetadataFacetModelEntityManager().getAll();
cmr.getMetadataFacetModelEntityManager().remove( metadataFacetModels );
+ */
+ cmr.getMetadataFacetModelEntityManager().truncate();
+ /*
List<ProjectVersionMetadataModel> projectVersionMetadataModels =
cmr.getProjectVersionMetadataModelEntityManager().getAll();
cmr.getProjectVersionMetadataModelEntityManager().remove( projectVersionMetadataModels );
-
+ */
+ cmr.getProjectVersionMetadataModelEntityManager().truncate();
}
public void setup()
throws Exception
{
-
cmr = new CassandraMetadataRepository( null, null, cassandraEntityManagerFactory );
+ if ( !cassandraEntityManagerFactory.started() )
+ {
+ cassandraEntityManagerFactory.start();
+ }
clearReposAndNamespace();
-
}
@After
throws Exception
{
clearReposAndNamespace();
+ cassandraEntityManagerFactory.shutdown();
}
Assertions.assertThat( cmr.getRepositories() ).isNotEmpty().hasSize( 1 );
Assertions.assertThat( cmr.getNamespaces( "release" ) ).isNotEmpty().hasSize( 1 );
- n = cmr.getNamespaceEntityManager().get( "release" + "-" + "org" );
+ n = cmr.getNamespaceEntityManager().get( "release" + CassandraUtils.SEPARATOR + "org" );
Assertions.assertThat( n ).isNotNull();
Assertions.assertThat( n.getRepository() ).isNotNull();
protected void clearReposAndNamespace()
throws Exception
{
+ /*
List<Project> projects = cmr.getProjectEntityManager().getAll();
-
cmr.getProjectEntityManager().remove( projects );
+ */
+ cmr.getProjectEntityManager().truncate();
+ /*
List<Namespace> namespaces = cmr.getNamespaceEntityManager().getAll();
-
cmr.getNamespaceEntityManager().remove( namespaces );
+ */
+ cmr.getNamespaceEntityManager().truncate();
+ /*
List<Repository> repositories = cmr.getRepositoryEntityManager().getAll();
-
cmr.getRepositoryEntityManager().remove( repositories );
-
+ */
+ cmr.getRepositoryEntityManager().truncate();
}
}
{
String name = scans.get( scans.size() - 1 );
RepositoryStatistics repositoryStatistics =
- (RepositoryStatistics) metadataRepository.getMetadataFacet( repositoryId, RepositoryStatistics.FACET_ID,
- name );
+ RepositoryStatistics.class.cast( metadataRepository.getMetadataFacet( repositoryId, RepositoryStatistics.FACET_ID,
+ name ));
stopWatch.stop();
log.debug( "time to find last RepositoryStatistics: {} ms", stopWatch.getTime() );
return repositoryStatistics;