move cassandra to simply use hector client: start with repositories and namespaces

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1579819 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2014-03-20 23:22:20 +00:00
parent 44880ea190
commit 50cb8970ef
14 changed files with 536 additions and 1008 deletions

View File

@ -73,13 +73,14 @@
<artifactId>modelmapper</artifactId>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jpa_2.0_spec</artifactId>
</dependency>
<!-- FIXME still need old jackson -->
<!--
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
@ -145,7 +146,7 @@
</exclusion>
</exclusions>
</dependency>
-->
<dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-all</artifactId>

View File

@ -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<Repository, String> getRepositoryEntityManager();
EntityManager<Namespace, String> getNamespaceEntityManager();
EntityManager<Project, String> getProjectEntityManager();
EntityManager<ArtifactMetadataModel, String> getArtifactMetadataModelEntityManager();
EntityManager<MetadataFacetModel, String> getMetadataFacetModelEntityManager();
EntityManager<ProjectVersionMetadataModel, String> getProjectVersionMetadataModelEntityManager();
Keyspace getKeyspace();
Cluster getCluster();
}

View File

@ -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 <A, B> HColumn<A, B> column( final A name, final B value )
{
return HFactory.createColumn( name, //
value, //
(Serializer<A>) SerializerTypeInferer.getSerializer( name ), //
(Serializer<B>) SerializerTypeInferer.getSerializer( value ) );
}
private CassandraUtils()
{
// no-op

View File

@ -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<Keyspace> keyspaceContext;
private boolean started;
private Cluster cluster;
private Keyspace keyspace;
private boolean started = false;
private EntityManager<Repository, String> repositoryEntityManager;
private EntityManager<Namespace, String> namespaceEntityManager;
private EntityManager<Project, String> projectEntityManager;
private EntityManager<ArtifactMetadataModel, String> artifactMetadataModelEntityManager;
private EntityManager<MetadataFacetModel, String> metadataFacetModelEntityManager;
private EntityManager<ProjectVersionMetadataModel, String> 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<String, Object> options = ImmutableMap.<String, Object>builder().put( "strategy_options",
ImmutableMap.<String, Object>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<ColumnFamilyDefinition> cfds = new ArrayList<ColumnFamilyDefinition>();
// 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.<Repository, String>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.<Namespace, String>builder()
.withEntityType( Namespace.class )
.withKeyspace( keyspace )
.withAutoCommit( true )
.withColumnFamily( "namespace" )
.build();
exists = columnFamilyExists( "namespace" );
if ( !exists )
{
// create secondary index
options =
ImmutableMap.<String, Object>builder()
.put("repositoryid", ImmutableMap.<String, Object>builder()
.put("validation_class", "UTF8Type")
.put("index_name", "Indexrepositoryid")
.put("index_type", "KEYS")
.build()).build();
namespaceEntityManager.createStorage( options );
}
projectEntityManager =
DefaultEntityManager.<Project, String>builder()
.withEntityType( Project.class )
.withKeyspace( keyspace )
.withAutoCommit( true )
.withColumnFamily( "project" )
.build();
exists = columnFamilyExists( "project" );
if ( !exists )
{
projectEntityManager.createStorage( null );
}
artifactMetadataModelEntityManager =
DefaultEntityManager.<ArtifactMetadataModel, String>builder()
.withEntityType( ArtifactMetadataModel.class )
.withAutoCommit( true )
.withKeyspace( keyspace )
.withColumnFamily( "artifactmetadatamodel" )
.build();
exists = columnFamilyExists( "artifactmetadatamodel" );
if ( !exists )
{
artifactMetadataModelEntityManager.createStorage( null );
}
metadataFacetModelEntityManager =
DefaultEntityManager.<MetadataFacetModel, String>builder()
.withEntityType( MetadataFacetModel.class )
.withAutoCommit( true )
.withKeyspace( keyspace )
.withColumnFamily( "metadatafacetmodel" )
.build();
exists = columnFamilyExists( "metadatafacetmodel" );
if ( !exists )
{
metadataFacetModelEntityManager.createStorage( null );
}
projectVersionMetadataModelEntityManager =
DefaultEntityManager.<ProjectVersionMetadataModel, String>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<Repository, String> getRepositoryEntityManager()
public Cluster getCluster()
{
return repositoryEntityManager;
}
public void setRepositoryEntityManager( EntityManager<Repository, String> repositoryEntityManager )
{
this.repositoryEntityManager = repositoryEntityManager;
}
public EntityManager<Namespace, String> getNamespaceEntityManager()
{
return namespaceEntityManager;
}
public void setNamespaceEntityManager( EntityManager<Namespace, String> namespaceEntityManager )
{
this.namespaceEntityManager = namespaceEntityManager;
}
public EntityManager<Project, String> getProjectEntityManager()
{
return projectEntityManager;
}
public void setProjectEntityManager( EntityManager<Project, String> projectEntityManager )
{
this.projectEntityManager = projectEntityManager;
}
public EntityManager<ArtifactMetadataModel, String> getArtifactMetadataModelEntityManager()
{
return artifactMetadataModelEntityManager;
}
public void setArtifactMetadataModelEntityManager(
EntityManager<ArtifactMetadataModel, String> artifactMetadataModelEntityManager )
{
this.artifactMetadataModelEntityManager = artifactMetadataModelEntityManager;
}
public EntityManager<MetadataFacetModel, String> getMetadataFacetModelEntityManager()
{
return metadataFacetModelEntityManager;
}
public void setMetadataFacetModelEntityManager(
EntityManager<MetadataFacetModel, String> metadataFacetModelEntityManager )
{
this.metadataFacetModelEntityManager = metadataFacetModelEntityManager;
}
public EntityManager<ProjectVersionMetadataModel, String> getProjectVersionMetadataModelEntityManager()
{
return projectVersionMetadataModelEntityManager;
}
public void setProjectVersionMetadataModelEntityManager(
EntityManager<ProjectVersionMetadataModel, String> projectVersionMetadataModelEntityManager )
{
this.projectVersionMetadataModelEntityManager = projectVersionMetadataModelEntityManager;
return cluster;
}
}

View File

@ -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()

View File

@ -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<String>
{
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 );
}
}

View File

@ -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;

View File

@ -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

View File

@ -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()

View File

@ -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<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()

View File

@ -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<Namespace> namespaces = new ArrayList<Namespace>();
public Repository()
{
// no op
@ -79,22 +65,6 @@ public class Repository
this.name = name;
}
/*
public List<Namespace> getNamespaces()
{
if ( this.namespaces == null )
{
this.namespaces = new ArrayList<Namespace>();
}
return namespaces;
}
public void setNamespaces( List<Namespace> namespaces )
{
this.namespaces = namespaces;
}
*/
@Override
public boolean equals( Object o )
{

View File

@ -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<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();
cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
"project" );
cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
"namespace" );
cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
"repository" );
}

View File

@ -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<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();
cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
"project" );
cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
"namespace" );
cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
"repository" );
}
}