mirror of https://github.com/apache/archiva.git
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:
parent
44880ea190
commit
50cb8970ef
|
@ -73,13 +73,14 @@
|
||||||
<artifactId>modelmapper</artifactId>
|
<artifactId>modelmapper</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.geronimo.specs</groupId>
|
<groupId>org.apache.geronimo.specs</groupId>
|
||||||
<artifactId>geronimo-jpa_2.0_spec</artifactId>
|
<artifactId>geronimo-jpa_2.0_spec</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- FIXME still need old jackson -->
|
<!-- FIXME still need old jackson -->
|
||||||
|
<!--
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.codehaus.jackson</groupId>
|
<groupId>org.codehaus.jackson</groupId>
|
||||||
<artifactId>jackson-mapper-asl</artifactId>
|
<artifactId>jackson-mapper-asl</artifactId>
|
||||||
|
@ -145,7 +146,7 @@
|
||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.cassandra</groupId>
|
<groupId>org.apache.cassandra</groupId>
|
||||||
<artifactId>cassandra-all</artifactId>
|
<artifactId>cassandra-all</artifactId>
|
||||||
|
|
|
@ -19,14 +19,8 @@ package org.apache.archiva.metadata.repository.cassandra;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.netflix.astyanax.Keyspace;
|
import me.prettyprint.hector.api.Cluster;
|
||||||
import com.netflix.astyanax.entitystore.EntityManager;
|
import me.prettyprint.hector.api.Keyspace;
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Olivier Lamy
|
* @author Olivier Lamy
|
||||||
|
@ -34,25 +28,14 @@ import org.apache.archiva.metadata.repository.cassandra.model.Repository;
|
||||||
*/
|
*/
|
||||||
public interface CassandraArchivaManager
|
public interface CassandraArchivaManager
|
||||||
{
|
{
|
||||||
Keyspace getKeyspace();
|
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
|
|
||||||
void shutdown();
|
void shutdown();
|
||||||
|
|
||||||
boolean started();
|
boolean started();
|
||||||
|
|
||||||
EntityManager<Repository, String> getRepositoryEntityManager();
|
Keyspace getKeyspace();
|
||||||
|
|
||||||
EntityManager<Namespace, String> getNamespaceEntityManager();
|
|
||||||
|
|
||||||
EntityManager<Project, String> getProjectEntityManager();
|
|
||||||
|
|
||||||
EntityManager<ArtifactMetadataModel, String> getArtifactMetadataModelEntityManager();
|
|
||||||
|
|
||||||
EntityManager<MetadataFacetModel, String> getMetadataFacetModelEntityManager();
|
|
||||||
|
|
||||||
EntityManager<ProjectVersionMetadataModel, String> getProjectVersionMetadataModelEntityManager();
|
|
||||||
|
|
||||||
|
Cluster getCluster();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,10 +19,15 @@ package org.apache.archiva.metadata.repository.cassandra;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import me.prettyprint.cassandra.serializers.StringSerializer;
|
||||||
import com.google.common.base.Predicate;
|
import me.prettyprint.hector.api.Keyspace;
|
||||||
import com.google.common.collect.Iterables;
|
import me.prettyprint.hector.api.beans.ColumnSlice;
|
||||||
import com.netflix.astyanax.entitystore.EntityManager;
|
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.configuration.ArchivaConfiguration;
|
||||||
import org.apache.archiva.metadata.model.ArtifactMetadata;
|
import org.apache.archiva.metadata.model.ArtifactMetadata;
|
||||||
import org.apache.archiva.metadata.model.FacetedMetadata;
|
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.MetadataRepositoryException;
|
||||||
import org.apache.archiva.metadata.repository.MetadataResolutionException;
|
import org.apache.archiva.metadata.repository.MetadataResolutionException;
|
||||||
import org.apache.archiva.metadata.repository.cassandra.model.ArtifactMetadataModel;
|
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.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.archiva.metadata.repository.cassandra.model.Repository;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.modelmapper.ModelMapper;
|
import org.modelmapper.ModelMapper;
|
||||||
|
@ -50,9 +52,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -83,34 +83,65 @@ public class CassandraMetadataRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public EntityManager<Repository, String> 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<OrderedRows<String, String, String>> 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 );
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityManager<Namespace, String> getNamespaceEntityManager()
|
|
||||||
{
|
|
||||||
return this.cassandraArchivaManager.getNamespaceEntityManager();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityManager<Project, String> getProjectEntityManager()
|
return new Repository( result.get().getList().get( 0 ).getColumnSlice().getColumnByName( "id" ).getValue() );
|
||||||
{
|
|
||||||
return this.cassandraArchivaManager.getProjectEntityManager();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityManager<ArtifactMetadataModel, String> getArtifactMetadataModelEntityManager()
|
|
||||||
{
|
|
||||||
return cassandraArchivaManager.getArtifactMetadataModelEntityManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
public EntityManager<MetadataFacetModel, String> getMetadataFacetModelEntityManager()
|
protected Repository getRepository( String repositoryId )
|
||||||
|
throws MetadataRepositoryException
|
||||||
{
|
{
|
||||||
return this.cassandraArchivaManager.getMetadataFacetModelEntityManager();
|
Keyspace keyspace = cassandraArchivaManager.getKeyspace();
|
||||||
}
|
QueryResult<OrderedRows<String, String, String>> result = HFactory //
|
||||||
|
.createRangeSlicesQuery( keyspace, StringSerializer.get(), StringSerializer.get(),
|
||||||
public EntityManager<ProjectVersionMetadataModel, String> getProjectVersionMetadataModelEntityManager()
|
StringSerializer.get() ) //
|
||||||
{
|
.setColumnFamily( "repository" ) //
|
||||||
return this.cassandraArchivaManager.getProjectVersionMetadataModelEntityManager();
|
.setColumnNames( "id", "name" ) //
|
||||||
|
.addEqualsExpression( "id", repositoryId ) //
|
||||||
|
.execute();
|
||||||
|
return ( result.get().getCount() > 0 ) ? new Repository( repositoryId ) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -126,32 +157,53 @@ public class CassandraMetadataRepository
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Repository repository = this.getRepositoryEntityManager().get( repositoryId );
|
Repository repository = getOrCreateRepository( repositoryId );
|
||||||
|
|
||||||
if ( repository == null )
|
Keyspace keyspace = cassandraArchivaManager.getKeyspace();
|
||||||
{
|
|
||||||
repository = new Repository( repositoryId );
|
|
||||||
|
|
||||||
Namespace namespace = new Namespace( namespaceId, repository );
|
Namespace namespace = getNamespace( repositoryId, namespaceId );
|
||||||
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() );
|
|
||||||
if ( namespace == null )
|
if ( namespace == null )
|
||||||
{
|
{
|
||||||
namespace = new Namespace( namespaceId, repository );
|
namespace = new Namespace( namespaceId, repository );
|
||||||
getNamespaceEntityManager().put( namespace );
|
HFactory.createMutator( keyspace, StringSerializer.get() )
|
||||||
}
|
// values
|
||||||
return namespace;
|
.addInsertion( namespace.getId(), "namespace", //
|
||||||
}
|
CassandraUtils.column( "name", namespace.getName() ) ) //
|
||||||
catch ( PersistenceException e )
|
.addInsertion( namespace.getId(), "namespace", //
|
||||||
{
|
CassandraUtils.column( "repositoryId", repository.getId() ) ) //
|
||||||
throw new MetadataRepositoryException( e.getMessage(), e );
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return namespace;
|
||||||
|
}
|
||||||
|
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<OrderedRows<String, String, String>> 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<String, String> 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
|
try
|
||||||
{
|
{
|
||||||
Namespace namespace = getNamespaceEntityManager().get(
|
String key =
|
||||||
new Namespace.KeyBuilder().withNamespace( namespaceId ).withRepositoryId( repositoryId ).build() );
|
new Namespace.KeyBuilder().withNamespace( namespaceId ).withRepositoryId( repositoryId ).build();
|
||||||
if ( namespace != null )
|
|
||||||
{
|
MutationResult result =
|
||||||
getNamespaceEntityManager().remove( namespace );
|
HFactory.createMutator( cassandraArchivaManager.getKeyspace(), new StringSerializer() ).addDeletion(
|
||||||
|
key, "namespace" ).execute();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
catch ( HInvalidRequestException e )
|
||||||
catch ( PersistenceException e )
|
|
||||||
{
|
{
|
||||||
|
logger.error( e.getMessage(), e );
|
||||||
throw new MetadataRepositoryException( e.getMessage(), e );
|
throw new MetadataRepositoryException( e.getMessage(), e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -179,8 +234,39 @@ public class CassandraMetadataRepository
|
||||||
public void removeRepository( final String repositoryId )
|
public void removeRepository( final String repositoryId )
|
||||||
throws MetadataRepositoryException
|
throws MetadataRepositoryException
|
||||||
{
|
{
|
||||||
try
|
|
||||||
|
// FIXME remove all datas attached to the repositoryId
|
||||||
|
|
||||||
|
// retrieve and delete all namespace with this repositoryId
|
||||||
|
|
||||||
|
List<String> namespacesKey = new ArrayList<String>();
|
||||||
|
|
||||||
|
Keyspace keyspace = cassandraArchivaManager.getKeyspace();
|
||||||
|
QueryResult<OrderedRows<String, String, String>> result = HFactory //
|
||||||
|
.createRangeSlicesQuery( keyspace, //
|
||||||
|
StringSerializer.get(), //
|
||||||
|
StringSerializer.get(), //
|
||||||
|
StringSerializer.get() ) //
|
||||||
|
.setColumnFamily( "namespace" ) //
|
||||||
|
.setColumnNames( "repositoryId", "name" ) //
|
||||||
|
.addEqualsExpression( "repositoryId", repositoryId ) //
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
for ( Row<String, String, String> row : result.get().getList() )
|
||||||
{
|
{
|
||||||
|
namespacesKey.add( row.getKey() );
|
||||||
|
}
|
||||||
|
|
||||||
|
HFactory.createMutator( cassandraArchivaManager.getKeyspace(), new StringSerializer() ) //
|
||||||
|
.addDeletion( namespacesKey, "namespace" ) //
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
//delete repositoryId
|
||||||
|
HFactory.createMutator( cassandraArchivaManager.getKeyspace(), new StringSerializer() ) //
|
||||||
|
.addDeletion( repositoryId, "repository" ) //
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
/*
|
||||||
final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
|
final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
|
||||||
|
|
||||||
// remove data related to the repository
|
// remove data related to the repository
|
||||||
|
@ -273,11 +359,7 @@ public class CassandraMetadataRepository
|
||||||
getRepositoryEntityManager().remove( repository );
|
getRepositoryEntityManager().remove( repository );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
*/
|
||||||
catch ( PersistenceException e )
|
|
||||||
{
|
|
||||||
throw new MetadataRepositoryException( e.getMessage(), e );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -288,17 +370,23 @@ public class CassandraMetadataRepository
|
||||||
{
|
{
|
||||||
logger.debug( "getRepositories" );
|
logger.debug( "getRepositories" );
|
||||||
|
|
||||||
List<Repository> repositories = getRepositoryEntityManager().getAll();
|
final QueryResult<OrderedRows<String, String, String>> cResult = //
|
||||||
if ( repositories == null )
|
HFactory.createRangeSlicesQuery( cassandraArchivaManager.getKeyspace(), //
|
||||||
|
StringSerializer.get(), //
|
||||||
|
StringSerializer.get(), //
|
||||||
|
StringSerializer.get() ) //
|
||||||
|
.setColumnFamily( "repository" ) //
|
||||||
|
.setColumnNames( "name" ) //
|
||||||
|
.setRange( null, null, false, Integer.MAX_VALUE ) //
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
List<String> repoIds = new ArrayList<String>( cResult.get().getCount() );
|
||||||
|
|
||||||
|
for ( Row<String, String, String> row : cResult.get() )
|
||||||
{
|
{
|
||||||
return Collections.emptyList();
|
repoIds.add( row.getColumnSlice().getColumnByName( "name" ).getValue() );
|
||||||
}
|
}
|
||||||
List<String> repoIds = new ArrayList<String>( repositories.size() );
|
|
||||||
for ( Repository repository : repositories )
|
|
||||||
{
|
|
||||||
repoIds.add( repository.getName() );
|
|
||||||
}
|
|
||||||
logger.debug( "getRepositories found: {}", repoIds );
|
|
||||||
return repoIds;
|
return repoIds;
|
||||||
}
|
}
|
||||||
catch ( PersistenceException e )
|
catch ( PersistenceException e )
|
||||||
|
@ -313,122 +401,56 @@ public class CassandraMetadataRepository
|
||||||
public Collection<String> getRootNamespaces( final String repoId )
|
public Collection<String> getRootNamespaces( final String repoId )
|
||||||
throws MetadataResolutionException
|
throws MetadataResolutionException
|
||||||
{
|
{
|
||||||
try
|
Keyspace keyspace = cassandraArchivaManager.getKeyspace();
|
||||||
|
QueryResult<OrderedRows<String, String, String>> result = HFactory //
|
||||||
|
.createRangeSlicesQuery( keyspace, //
|
||||||
|
StringSerializer.get(), //
|
||||||
|
StringSerializer.get(), //
|
||||||
|
StringSerializer.get() ) //
|
||||||
|
.setColumnFamily( "namespace" ) //
|
||||||
|
.setColumnNames( "name" ) //
|
||||||
|
.addEqualsExpression( "repositoryId", repoId ) //
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
Set<String> namespaces = new HashSet<String>( result.get().getCount() );
|
||||||
|
|
||||||
|
for ( Row<String, String, String> row : result.get() )
|
||||||
{
|
{
|
||||||
|
namespaces.add(
|
||||||
|
StringUtils.substringBefore( row.getColumnSlice().getColumnByName( "name" ).getValue(), "." ) );
|
||||||
RootNamesSpaceVisitAll rootNamesSpaceVisitAll = new RootNamesSpaceVisitAll( repoId );
|
|
||||||
|
|
||||||
getNamespaceEntityManager().visitAll( rootNamesSpaceVisitAll );
|
|
||||||
|
|
||||||
return rootNamesSpaceVisitAll.namespaces;
|
|
||||||
|
|
||||||
|
|
||||||
// using cql query with index
|
|
||||||
/*
|
|
||||||
List<Namespace> namespacesList = getNamespaceEntityManager().find( "SELECT * from namespace where id <> null AND repositoryid = '" + repoId + "'" );
|
|
||||||
|
|
||||||
Set<String> namespaces = new HashSet<String>();
|
|
||||||
|
|
||||||
for (Namespace namespace : namespacesList)
|
|
||||||
{
|
|
||||||
String name = namespace.getName();
|
|
||||||
if ( StringUtils.isNotEmpty( name ) )
|
|
||||||
{
|
|
||||||
namespaces.add( StringUtils.substringBefore( name, "." ) );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return namespaces;
|
return namespaces;
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
|
||||||
catch ( Exception e )
|
|
||||||
{
|
|
||||||
throw new MetadataResolutionException( e.getMessage(), e );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class RootNamesSpaceVisitAll
|
|
||||||
implements Function<Namespace, Boolean>
|
|
||||||
{
|
|
||||||
private String repoId;
|
|
||||||
|
|
||||||
Set<String> namespaces = new HashSet<String>();
|
|
||||||
|
|
||||||
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
|
@Override
|
||||||
public Collection<String> getNamespaces( final String repoId, final String namespaceId )
|
public Collection<String> getNamespaces( final String repoId, final String namespaceId )
|
||||||
throws MetadataResolutionException
|
throws MetadataResolutionException
|
||||||
{
|
{
|
||||||
try
|
Keyspace keyspace = cassandraArchivaManager.getKeyspace();
|
||||||
|
QueryResult<OrderedRows<String, String, String>> result = HFactory //
|
||||||
|
.createRangeSlicesQuery( keyspace, //
|
||||||
|
StringSerializer.get(), //
|
||||||
|
StringSerializer.get(), //
|
||||||
|
StringSerializer.get() ) //
|
||||||
|
.setColumnFamily( "namespace" ) //
|
||||||
|
.setColumnNames( "name" ) //
|
||||||
|
.addEqualsExpression( "repositoryId", repoId ) //
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
List<String> namespaces = new ArrayList<String>( result.get().getCount() );
|
||||||
|
|
||||||
|
for ( Row<String, String, String> row : result.get() )
|
||||||
{
|
{
|
||||||
final FindNamesSpaceVisitAll findNamesSpaceVisitAll = new FindNamesSpaceVisitAll( repoId, namespaceId );
|
String currentNamespace = row.getColumnSlice().getColumnByName( "name" ).getValue();
|
||||||
|
if ( StringUtils.startsWith( currentNamespace, namespaceId ) && ( StringUtils.length( currentNamespace )
|
||||||
getNamespaceEntityManager().visitAll( findNamesSpaceVisitAll );
|
> StringUtils.length( namespaceId ) ) )
|
||||||
|
|
||||||
return findNamesSpaceVisitAll.namespaces;
|
|
||||||
}
|
|
||||||
catch ( PersistenceException e )
|
|
||||||
{
|
|
||||||
throw new MetadataResolutionException( e.getMessage(), e );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class FindNamesSpaceVisitAll
|
|
||||||
implements Function<Namespace, Boolean>
|
|
||||||
{
|
|
||||||
private String repoId;
|
|
||||||
|
|
||||||
private String namespaceId;
|
|
||||||
|
|
||||||
Set<String> namespaces = new HashSet<String>();
|
|
||||||
|
|
||||||
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 = namespace.getName();
|
|
||||||
// we only return childs
|
|
||||||
if ( StringUtils.startsWith( currentNamespace, namespaceId ) && (
|
|
||||||
StringUtils.length( currentNamespace ) > StringUtils.length( namespaceId ) ) )
|
|
||||||
{
|
{
|
||||||
// store after namespaceId '.' but before next '.'
|
// store after namespaceId '.' but before next '.'
|
||||||
// call org namespace org.apache.maven.shared -> stored apache
|
// call org namespace org.apache.maven.shared -> stored apache
|
||||||
|
|
||||||
String calledNamespace =
|
String calledNamespace = StringUtils.endsWith( namespaceId, "." ) ? namespaceId : namespaceId + ".";
|
||||||
StringUtils.endsWith( namespaceId, "." ) ? namespaceId : namespaceId + ".";
|
|
||||||
String storedNamespace = StringUtils.substringAfter( currentNamespace, calledNamespace );
|
String storedNamespace = StringUtils.substringAfter( currentNamespace, calledNamespace );
|
||||||
|
|
||||||
storedNamespace = StringUtils.substringBefore( storedNamespace, "." );
|
storedNamespace = StringUtils.substringBefore( storedNamespace, "." );
|
||||||
|
@ -436,78 +458,34 @@ public class CassandraMetadataRepository
|
||||||
namespaces.add( storedNamespace );
|
namespaces.add( storedNamespace );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Boolean.TRUE;
|
|
||||||
}
|
return namespaces;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<String> getNamespaces( final String repoId )
|
public List<String> getNamespaces( final String repoId )
|
||||||
throws MetadataResolutionException
|
throws MetadataResolutionException
|
||||||
{
|
{
|
||||||
try
|
Keyspace keyspace = cassandraArchivaManager.getKeyspace();
|
||||||
|
QueryResult<OrderedRows<String, String, String>> result = HFactory //
|
||||||
|
.createRangeSlicesQuery( keyspace, //
|
||||||
|
StringSerializer.get(), //
|
||||||
|
StringSerializer.get(), //
|
||||||
|
StringSerializer.get() ) //
|
||||||
|
.setColumnFamily( "namespace" ) //
|
||||||
|
.setColumnNames( "name" ) //
|
||||||
|
.addEqualsExpression( "repositoryId", repoId ) //
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
List<String> namespaces = new ArrayList<String>( result.get().getCount() );
|
||||||
|
|
||||||
|
for ( Row<String, String, String> row : result.get() )
|
||||||
{
|
{
|
||||||
logger.debug( "getNamespaces for repository '{}'", repoId );
|
namespaces.add( row.getColumnSlice().getColumnByName( "name" ).getValue() );
|
||||||
//TypedQuery<Repository> typedQuery =
|
|
||||||
// entityManager.createQuery( "select n from Namespace n where n.repository_id=:id", Namespace.class );
|
|
||||||
|
|
||||||
//List<Repository> namespaces = typedQuery.setParameter( "id", repoId ).getResultList();
|
|
||||||
|
|
||||||
Repository repository = getRepositoryEntityManager().get( repoId );
|
|
||||||
|
|
||||||
if ( repository == null )
|
|
||||||
{
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME find correct cql query
|
return namespaces;
|
||||||
//String query = "select * from namespace where repository.id = '" + repoId + "';";
|
|
||||||
|
|
||||||
//List<Namespace> namespaces = getNamespaceEntityManager().find( query );
|
|
||||||
|
|
||||||
//final Set<Namespace> namespaces = new HashSet<Namespace>();
|
|
||||||
final Set<String> namespaces = new HashSet<String>();
|
|
||||||
|
|
||||||
getNamespaceEntityManager().visitAll( new Function<Namespace, Boolean>()
|
|
||||||
{
|
|
||||||
// @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<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() )
|
|
||||||
{
|
|
||||||
namespaceIds.add( n.getName() );
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.debug( "getNamespaces for repository '{}' found {}", repoId, namespaceIds.size() );
|
|
||||||
|
|
||||||
return namespaceIds;
|
|
||||||
*/
|
|
||||||
return new ArrayList<String>( namespaces );
|
|
||||||
}
|
|
||||||
catch ( PersistenceException e )
|
|
||||||
{
|
|
||||||
throw new MetadataResolutionException( e.getMessage(), e );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -515,7 +493,7 @@ public class CassandraMetadataRepository
|
||||||
public void updateProject( String repositoryId, ProjectMetadata projectMetadata )
|
public void updateProject( String repositoryId, ProjectMetadata projectMetadata )
|
||||||
throws MetadataRepositoryException
|
throws MetadataRepositoryException
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
// project exists ? if yes return
|
// project exists ? if yes return
|
||||||
String projectKey = new Project.KeyBuilder().withProjectId( projectMetadata.getId() ).withNamespace(
|
String projectKey = new Project.KeyBuilder().withProjectId( projectMetadata.getId() ).withNamespace(
|
||||||
new Namespace( projectMetadata.getNamespace(), new Repository( repositoryId ) ) ).build();
|
new Namespace( projectMetadata.getNamespace(), new Repository( repositoryId ) ) ).build();
|
||||||
|
@ -543,7 +521,7 @@ public class CassandraMetadataRepository
|
||||||
catch ( PersistenceException e )
|
catch ( PersistenceException e )
|
||||||
{
|
{
|
||||||
throw new MetadataRepositoryException( e.getMessage(), e );
|
throw new MetadataRepositoryException( e.getMessage(), e );
|
||||||
}
|
}*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -552,7 +530,7 @@ public class CassandraMetadataRepository
|
||||||
throws MetadataRepositoryException
|
throws MetadataRepositoryException
|
||||||
{
|
{
|
||||||
|
|
||||||
// cleanup ArtifactMetadataModel
|
/* // cleanup ArtifactMetadataModel
|
||||||
final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
|
final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
|
||||||
|
|
||||||
getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
|
getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
|
||||||
|
@ -614,14 +592,15 @@ public class CassandraMetadataRepository
|
||||||
}
|
}
|
||||||
logger.debug( "removeProject {}", project );
|
logger.debug( "removeProject {}", project );
|
||||||
|
|
||||||
getProjectEntityManager().remove( project );
|
getProjectEntityManager().remove( project );*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<String> getProjectVersions( final String repoId, final String namespace, final String projectId )
|
public Collection<String> getProjectVersions( final String repoId, final String namespace, final String projectId )
|
||||||
throws MetadataResolutionException
|
throws MetadataResolutionException
|
||||||
{
|
{
|
||||||
final Set<String> versions = new HashSet<String>();
|
return null;
|
||||||
|
/* final Set<String> versions = new HashSet<String>();
|
||||||
getProjectVersionMetadataModelEntityManager().visitAll( new Function<ProjectVersionMetadataModel, Boolean>()
|
getProjectVersionMetadataModelEntityManager().visitAll( new Function<ProjectVersionMetadataModel, Boolean>()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@ -659,7 +638,7 @@ public class CassandraMetadataRepository
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
return versions;
|
return versions;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -667,7 +646,7 @@ public class CassandraMetadataRepository
|
||||||
ArtifactMetadata artifactMeta )
|
ArtifactMetadata artifactMeta )
|
||||||
throws MetadataRepositoryException
|
throws MetadataRepositoryException
|
||||||
{
|
{
|
||||||
String namespaceKey =
|
/* String namespaceKey =
|
||||||
new Namespace.KeyBuilder().withRepositoryId( repositoryId ).withNamespace( namespaceId ).build();
|
new Namespace.KeyBuilder().withRepositoryId( repositoryId ).withNamespace( namespaceId ).build();
|
||||||
// create the namespace if not exists
|
// create the namespace if not exists
|
||||||
Namespace namespace = getNamespaceEntityManager().get( namespaceKey );
|
Namespace namespace = getNamespaceEntityManager().get( namespaceKey );
|
||||||
|
@ -745,7 +724,7 @@ public class CassandraMetadataRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
// now facets
|
// now facets
|
||||||
updateFacets( artifactMeta, artifactMetadataModel );
|
updateFacets( artifactMeta, artifactMetadataModel );*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -754,7 +733,7 @@ public class CassandraMetadataRepository
|
||||||
final String projectVersion )
|
final String projectVersion )
|
||||||
throws MetadataResolutionException
|
throws MetadataResolutionException
|
||||||
{
|
{
|
||||||
final Set<String> versions = new HashSet<String>();
|
/* final Set<String> versions = new HashSet<String>();
|
||||||
// FIXME use cql query
|
// FIXME use cql query
|
||||||
getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
|
getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
|
||||||
{
|
{
|
||||||
|
@ -775,7 +754,8 @@ public class CassandraMetadataRepository
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
return versions;
|
return versions;*/
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -788,7 +768,7 @@ public class CassandraMetadataRepository
|
||||||
final ArtifactMetadataModel artifactMetadataModel )
|
final ArtifactMetadataModel artifactMetadataModel )
|
||||||
{
|
{
|
||||||
|
|
||||||
for ( final String facetId : metadataFacetFactories.keySet() )
|
/* for ( final String facetId : metadataFacetFactories.keySet() )
|
||||||
{
|
{
|
||||||
MetadataFacet metadataFacet = facetedMetadata.getFacet( facetId );
|
MetadataFacet metadataFacet = facetedMetadata.getFacet( facetId );
|
||||||
if ( metadataFacet == null )
|
if ( metadataFacet == null )
|
||||||
|
@ -834,8 +814,7 @@ public class CassandraMetadataRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
getMetadataFacetModelEntityManager().put( metadataFacetModelsToAdd );
|
getMetadataFacetModelEntityManager().put( metadataFacetModelsToAdd );
|
||||||
|
}*/
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -843,7 +822,7 @@ public class CassandraMetadataRepository
|
||||||
ProjectVersionMetadata versionMetadata )
|
ProjectVersionMetadata versionMetadata )
|
||||||
throws MetadataRepositoryException
|
throws MetadataRepositoryException
|
||||||
{
|
{
|
||||||
String namespaceKey =
|
/* String namespaceKey =
|
||||||
new Namespace.KeyBuilder().withRepositoryId( repositoryId ).withNamespace( namespaceId ).build();
|
new Namespace.KeyBuilder().withRepositoryId( repositoryId ).withNamespace( namespaceId ).build();
|
||||||
Namespace namespace = getNamespaceEntityManager().get( namespaceKey );
|
Namespace namespace = getNamespaceEntityManager().get( namespaceKey );
|
||||||
if ( namespace == null )
|
if ( namespace == null )
|
||||||
|
@ -869,8 +848,7 @@ public class CassandraMetadataRepository
|
||||||
|
|
||||||
if ( projectVersionMetadataModel == null )
|
if ( projectVersionMetadataModel == null )
|
||||||
{
|
{
|
||||||
projectVersionMetadataModel =
|
projectVersionMetadataModel = getModelMapper().map( versionMetadata, ProjectVersionMetadataModel.class );
|
||||||
getModelMapper().map( versionMetadata, ProjectVersionMetadataModel.class );
|
|
||||||
projectVersionMetadataModel.setRowId( key );
|
projectVersionMetadataModel.setRowId( key );
|
||||||
}
|
}
|
||||||
projectVersionMetadataModel.setProjectId( projectId );
|
projectVersionMetadataModel.setProjectId( projectId );
|
||||||
|
@ -892,7 +870,8 @@ public class CassandraMetadataRepository
|
||||||
artifactMetadataModel.setArtifactMetadataModelId(
|
artifactMetadataModel.setArtifactMetadataModelId(
|
||||||
new ArtifactMetadataModel.KeyBuilder().withId( versionMetadata.getId() ).withRepositoryId(
|
new ArtifactMetadataModel.KeyBuilder().withId( versionMetadata.getId() ).withRepositoryId(
|
||||||
repositoryId ).withNamespace( namespaceId ).withProjectVersion(
|
repositoryId ).withNamespace( namespaceId ).withProjectVersion(
|
||||||
versionMetadata.getVersion() ).withProject( projectId ).build() );
|
versionMetadata.getVersion() ).withProject( projectId ).build()
|
||||||
|
);
|
||||||
artifactMetadataModel.setRepositoryId( repositoryId );
|
artifactMetadataModel.setRepositoryId( repositoryId );
|
||||||
artifactMetadataModel.setNamespace( namespaceId );
|
artifactMetadataModel.setNamespace( namespaceId );
|
||||||
artifactMetadataModel.setProject( projectId );
|
artifactMetadataModel.setProject( projectId );
|
||||||
|
@ -904,7 +883,7 @@ public class CassandraMetadataRepository
|
||||||
catch ( PersistenceException e )
|
catch ( PersistenceException e )
|
||||||
{
|
{
|
||||||
throw new MetadataRepositoryException( e.getMessage(), e );
|
throw new MetadataRepositoryException( e.getMessage(), e );
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -917,7 +896,7 @@ public class CassandraMetadataRepository
|
||||||
public List<String> getMetadataFacets( final String repositoryId, final String facetId )
|
public List<String> getMetadataFacets( final String repositoryId, final String facetId )
|
||||||
throws MetadataRepositoryException
|
throws MetadataRepositoryException
|
||||||
{
|
{
|
||||||
// FIXME use cql query !!
|
/* // FIXME use cql query !!
|
||||||
final List<String> facets = new ArrayList<String>();
|
final List<String> facets = new ArrayList<String>();
|
||||||
this.getMetadataFacetModelEntityManager().visitAll( new Function<MetadataFacetModel, Boolean>()
|
this.getMetadataFacetModelEntityManager().visitAll( new Function<MetadataFacetModel, Boolean>()
|
||||||
{
|
{
|
||||||
|
@ -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 )
|
public MetadataFacet getMetadataFacet( final String repositoryId, final String facetId, final String name )
|
||||||
throws MetadataRepositoryException
|
throws MetadataRepositoryException
|
||||||
{
|
{
|
||||||
// FIXME use cql query !!
|
/* // FIXME use cql query !!
|
||||||
final List<MetadataFacetModel> facets = new ArrayList<MetadataFacetModel>();
|
final List<MetadataFacetModel> facets = new ArrayList<MetadataFacetModel>();
|
||||||
this.getMetadataFacetModelEntityManager().visitAll( new Function<MetadataFacetModel, Boolean>()
|
this.getMetadataFacetModelEntityManager().visitAll( new Function<MetadataFacetModel, Boolean>()
|
||||||
{
|
{
|
||||||
|
@ -990,14 +970,15 @@ public class CassandraMetadataRepository
|
||||||
map.put( metadataFacetModel.getKey(), metadataFacetModel.getValue() );
|
map.put( metadataFacetModel.getKey(), metadataFacetModel.getValue() );
|
||||||
}
|
}
|
||||||
metadataFacet.fromProperties( map );
|
metadataFacet.fromProperties( map );
|
||||||
return metadataFacet;
|
return metadataFacet;*/
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addMetadataFacet( String repositoryId, MetadataFacet metadataFacet )
|
public void addMetadataFacet( String repositoryId, MetadataFacet metadataFacet )
|
||||||
throws MetadataRepositoryException
|
throws MetadataRepositoryException
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
if ( metadataFacet == null )
|
if ( metadataFacet == null )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -1061,14 +1042,14 @@ public class CassandraMetadataRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeMetadataFacets( final String repositoryId, final String facetId )
|
public void removeMetadataFacets( final String repositoryId, final String facetId )
|
||||||
throws MetadataRepositoryException
|
throws MetadataRepositoryException
|
||||||
{
|
{
|
||||||
logger.debug( "removeMetadataFacets repositoryId: '{}', facetId: '{}'", repositoryId, facetId );
|
/* logger.debug( "removeMetadataFacets repositoryId: '{}', facetId: '{}'", repositoryId, facetId );
|
||||||
final List<MetadataFacetModel> toRemove = new ArrayList<MetadataFacetModel>();
|
final List<MetadataFacetModel> toRemove = new ArrayList<MetadataFacetModel>();
|
||||||
|
|
||||||
// FIXME cql query
|
// FIXME cql query
|
||||||
|
@ -1091,14 +1072,14 @@ public class CassandraMetadataRepository
|
||||||
} );
|
} );
|
||||||
logger.debug( "removeMetadataFacets repositoryId: '{}', facetId: '{}', toRemove: {}", repositoryId, facetId,
|
logger.debug( "removeMetadataFacets repositoryId: '{}', facetId: '{}', toRemove: {}", repositoryId, facetId,
|
||||||
toRemove );
|
toRemove );
|
||||||
getMetadataFacetModelEntityManager().remove( toRemove );
|
getMetadataFacetModelEntityManager().remove( toRemove );*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeMetadataFacet( final String repositoryId, final String facetId, final String name )
|
public void removeMetadataFacet( final String repositoryId, final String facetId, final String name )
|
||||||
throws MetadataRepositoryException
|
throws MetadataRepositoryException
|
||||||
{
|
{
|
||||||
logger.debug( "removeMetadataFacets repositoryId: '{}', facetId: '{}'", repositoryId, facetId );
|
/* logger.debug( "removeMetadataFacets repositoryId: '{}', facetId: '{}'", repositoryId, facetId );
|
||||||
final List<MetadataFacetModel> toRemove = new ArrayList<MetadataFacetModel>();
|
final List<MetadataFacetModel> toRemove = new ArrayList<MetadataFacetModel>();
|
||||||
|
|
||||||
// FIXME cql query
|
// FIXME cql query
|
||||||
|
@ -1122,7 +1103,7 @@ public class CassandraMetadataRepository
|
||||||
} );
|
} );
|
||||||
logger.debug( "removeMetadataFacets repositoryId: '{}', facetId: '{}', toRemove: {}", repositoryId, facetId,
|
logger.debug( "removeMetadataFacets repositoryId: '{}', facetId: '{}', toRemove: {}", repositoryId, facetId,
|
||||||
toRemove );
|
toRemove );
|
||||||
getMetadataFacetModelEntityManager().remove( toRemove );
|
getMetadataFacetModelEntityManager().remove( toRemove );*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1131,7 +1112,7 @@ public class CassandraMetadataRepository
|
||||||
throws MetadataRepositoryException
|
throws MetadataRepositoryException
|
||||||
{
|
{
|
||||||
|
|
||||||
final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
|
/* final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
|
||||||
|
|
||||||
// FIXME cql query
|
// FIXME cql query
|
||||||
getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
|
getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
|
||||||
|
@ -1172,12 +1153,13 @@ public class CassandraMetadataRepository
|
||||||
logger.debug( "getArtifactsByDateRange repositoryId: {}, startTime: {}, endTime: {}, artifactMetadatas: {}",
|
logger.debug( "getArtifactsByDateRange repositoryId: {}, startTime: {}, endTime: {}, artifactMetadatas: {}",
|
||||||
repositoryId, startTime, endTime, artifactMetadatas );
|
repositoryId, startTime, endTime, artifactMetadatas );
|
||||||
|
|
||||||
return artifactMetadatas;
|
return artifactMetadatas;*/
|
||||||
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void populateFacets( final ArtifactMetadata artifactMetadata )
|
protected void populateFacets( final ArtifactMetadata artifactMetadata )
|
||||||
{
|
{
|
||||||
final List<MetadataFacetModel> metadataFacetModels = new ArrayList<MetadataFacetModel>();
|
/* final List<MetadataFacetModel> metadataFacetModels = new ArrayList<MetadataFacetModel>();
|
||||||
|
|
||||||
getMetadataFacetModelEntityManager().visitAll( new Function<MetadataFacetModel, Boolean>()
|
getMetadataFacetModelEntityManager().visitAll( new Function<MetadataFacetModel, Boolean>()
|
||||||
{
|
{
|
||||||
|
@ -1228,14 +1210,14 @@ public class CassandraMetadataRepository
|
||||||
factory.createMetadataFacet( artifactMetadata.getRepositoryId(), entry.getKey() );
|
factory.createMetadataFacet( artifactMetadata.getRepositoryId(), entry.getKey() );
|
||||||
metadataFacet.fromProperties( entry.getValue() );
|
metadataFacet.fromProperties( entry.getValue() );
|
||||||
artifactMetadata.addFacet( metadataFacet );
|
artifactMetadata.addFacet( metadataFacet );
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ArtifactMetadata> getArtifactsByChecksum( final String repositoryId, final String checksum )
|
public List<ArtifactMetadata> getArtifactsByChecksum( final String repositoryId, final String checksum )
|
||||||
throws MetadataRepositoryException
|
throws MetadataRepositoryException
|
||||||
{
|
{
|
||||||
final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
|
/* final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
|
||||||
|
|
||||||
if ( logger.isDebugEnabled() )
|
if ( logger.isDebugEnabled() )
|
||||||
{
|
{
|
||||||
|
@ -1277,7 +1259,8 @@ public class CassandraMetadataRepository
|
||||||
logger.debug( "getArtifactsByChecksum repositoryId: {}, checksum: {}, artifactMetadatas: {}", repositoryId,
|
logger.debug( "getArtifactsByChecksum repositoryId: {}, checksum: {}, artifactMetadatas: {}", repositoryId,
|
||||||
checksum, artifactMetadatas );
|
checksum, artifactMetadatas );
|
||||||
|
|
||||||
return artifactMetadatas;
|
return artifactMetadatas;*/
|
||||||
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1285,7 +1268,7 @@ public class CassandraMetadataRepository
|
||||||
final String version, final String id )
|
final String version, final String id )
|
||||||
throws MetadataRepositoryException
|
throws MetadataRepositoryException
|
||||||
{
|
{
|
||||||
logger.debug( "removeArtifact repositoryId: '{}', namespace: '{}', project: '{}', version: '{}', id: '{}'",
|
/* logger.debug( "removeArtifact repositoryId: '{}', namespace: '{}', project: '{}', version: '{}', id: '{}'",
|
||||||
repositoryId, namespace, project, version, id );
|
repositoryId, namespace, project, version, id );
|
||||||
String key =
|
String key =
|
||||||
new ArtifactMetadataModel.KeyBuilder().withRepositoryId( repositoryId ).withNamespace( namespace ).withId(
|
new ArtifactMetadataModel.KeyBuilder().withRepositoryId( repositoryId ).withNamespace( namespace ).withId(
|
||||||
|
@ -1303,7 +1286,7 @@ public class CassandraMetadataRepository
|
||||||
ProjectVersionMetadataModel projectVersionMetadataModel = new ProjectVersionMetadataModel();
|
ProjectVersionMetadataModel projectVersionMetadataModel = new ProjectVersionMetadataModel();
|
||||||
projectVersionMetadataModel.setRowId( key );
|
projectVersionMetadataModel.setRowId( key );
|
||||||
|
|
||||||
getProjectVersionMetadataModelEntityManager().remove( projectVersionMetadataModel );
|
getProjectVersionMetadataModelEntityManager().remove( projectVersionMetadataModel );*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1313,7 +1296,7 @@ public class CassandraMetadataRepository
|
||||||
logger.debug( "removeArtifact repositoryId: '{}', namespace: '{}', project: '{}', version: '{}', id: '{}'",
|
logger.debug( "removeArtifact repositoryId: '{}', namespace: '{}', project: '{}', version: '{}', id: '{}'",
|
||||||
artifactMetadata.getRepositoryId(), artifactMetadata.getNamespace(),
|
artifactMetadata.getRepositoryId(), artifactMetadata.getNamespace(),
|
||||||
artifactMetadata.getProject(), baseVersion, artifactMetadata.getId() );
|
artifactMetadata.getProject(), baseVersion, artifactMetadata.getId() );
|
||||||
String key =
|
/* String key =
|
||||||
new ArtifactMetadataModel.KeyBuilder().withRepositoryId( artifactMetadata.getRepositoryId() ).withNamespace(
|
new ArtifactMetadataModel.KeyBuilder().withRepositoryId( artifactMetadata.getRepositoryId() ).withNamespace(
|
||||||
artifactMetadata.getNamespace() ).withId( artifactMetadata.getId() ).withProjectVersion(
|
artifactMetadata.getNamespace() ).withId( artifactMetadata.getId() ).withProjectVersion(
|
||||||
baseVersion ).withProject( artifactMetadata.getProject() ).build();
|
baseVersion ).withProject( artifactMetadata.getProject() ).build();
|
||||||
|
@ -1321,7 +1304,7 @@ public class CassandraMetadataRepository
|
||||||
ArtifactMetadataModel artifactMetadataModel = new ArtifactMetadataModel();
|
ArtifactMetadataModel artifactMetadataModel = new ArtifactMetadataModel();
|
||||||
artifactMetadataModel.setArtifactMetadataModelId( key );
|
artifactMetadataModel.setArtifactMetadataModelId( key );
|
||||||
|
|
||||||
getArtifactMetadataModelEntityManager().remove( artifactMetadataModel );
|
getArtifactMetadataModelEntityManager().remove( artifactMetadataModel );*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1329,7 +1312,7 @@ public class CassandraMetadataRepository
|
||||||
final String version, final MetadataFacet metadataFacet )
|
final String version, final MetadataFacet metadataFacet )
|
||||||
throws MetadataRepositoryException
|
throws MetadataRepositoryException
|
||||||
{
|
{
|
||||||
final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
|
/* final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
|
||||||
getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
|
getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@ -1348,7 +1331,7 @@ public class CassandraMetadataRepository
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
getArtifactMetadataModelEntityManager().remove( artifactMetadataModels );
|
getArtifactMetadataModelEntityManager().remove( artifactMetadataModels );*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1357,7 +1340,7 @@ public class CassandraMetadataRepository
|
||||||
public List<ArtifactMetadata> getArtifacts( final String repositoryId )
|
public List<ArtifactMetadata> getArtifacts( final String repositoryId )
|
||||||
throws MetadataRepositoryException
|
throws MetadataRepositoryException
|
||||||
{
|
{
|
||||||
final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
|
/* final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
|
||||||
// FIXME use cql query !
|
// FIXME use cql query !
|
||||||
getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
|
getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
|
||||||
{
|
{
|
||||||
|
@ -1385,14 +1368,16 @@ public class CassandraMetadataRepository
|
||||||
artifactMetadatas.add( artifactMetadata );
|
artifactMetadatas.add( artifactMetadata );
|
||||||
}
|
}
|
||||||
|
|
||||||
return artifactMetadatas;
|
return artifactMetadatas;*/
|
||||||
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProjectMetadata getProject( final String repoId, final String namespace, final String id )
|
public ProjectMetadata getProject( final String repoId, final String namespace, final String id )
|
||||||
throws MetadataResolutionException
|
throws MetadataResolutionException
|
||||||
{
|
{
|
||||||
//basically just checking it exists
|
|
||||||
|
/* //basically just checking it exists
|
||||||
// FIXME use cql query
|
// FIXME use cql query
|
||||||
|
|
||||||
final BooleanHolder booleanHolder = new BooleanHolder();
|
final BooleanHolder booleanHolder = new BooleanHolder();
|
||||||
|
@ -1427,7 +1412,8 @@ public class CassandraMetadataRepository
|
||||||
logger.debug( "getProject repoId: {}, namespace: {}, projectId: {} -> {}", repoId, namespace, id,
|
logger.debug( "getProject repoId: {}, namespace: {}, projectId: {} -> {}", repoId, namespace, id,
|
||||||
projectMetadata );
|
projectMetadata );
|
||||||
|
|
||||||
return projectMetadata;
|
return projectMetadata;*/
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1435,7 +1421,7 @@ public class CassandraMetadataRepository
|
||||||
final String projectId, final String projectVersion )
|
final String projectId, final String projectVersion )
|
||||||
throws MetadataResolutionException
|
throws MetadataResolutionException
|
||||||
{
|
{
|
||||||
String key = new ProjectVersionMetadataModel.KeyBuilder().withRepository( repoId ).withNamespace(
|
/* String key = new ProjectVersionMetadataModel.KeyBuilder().withRepository( repoId ).withNamespace(
|
||||||
namespace ).withProjectId( projectId ).withId( projectVersion ).build();
|
namespace ).withProjectId( projectId ).withId( projectVersion ).build();
|
||||||
|
|
||||||
ProjectVersionMetadataModel projectVersionMetadataModel =
|
ProjectVersionMetadataModel projectVersionMetadataModel =
|
||||||
|
@ -1512,7 +1498,8 @@ public class CassandraMetadataRepository
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return projectVersionMetadata;
|
return projectVersionMetadata;*/
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1531,7 +1518,7 @@ public class CassandraMetadataRepository
|
||||||
{
|
{
|
||||||
final Set<String> projects = new HashSet<String>();
|
final Set<String> projects = new HashSet<String>();
|
||||||
|
|
||||||
// FIXME use cql query
|
/* // FIXME use cql query
|
||||||
getProjectEntityManager().visitAll( new Function<Project, Boolean>()
|
getProjectEntityManager().visitAll( new Function<Project, Boolean>()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@ -1547,7 +1534,7 @@ public class CassandraMetadataRepository
|
||||||
}
|
}
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
}
|
}
|
||||||
} );
|
} );*/
|
||||||
|
|
||||||
return projects;
|
return projects;
|
||||||
}
|
}
|
||||||
|
@ -1558,7 +1545,7 @@ public class CassandraMetadataRepository
|
||||||
final String projectVersion )
|
final String projectVersion )
|
||||||
throws MetadataRepositoryException
|
throws MetadataRepositoryException
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
|
final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
|
||||||
|
|
||||||
// FIXME use cql query
|
// FIXME use cql query
|
||||||
|
@ -1597,6 +1584,7 @@ public class CassandraMetadataRepository
|
||||||
projectVersionMetadataModel.setRowId( key );
|
projectVersionMetadataModel.setRowId( key );
|
||||||
|
|
||||||
getProjectVersionMetadataModelEntityManager().remove( projectVersionMetadataModel );
|
getProjectVersionMetadataModelEntityManager().remove( projectVersionMetadataModel );
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1605,6 +1593,7 @@ public class CassandraMetadataRepository
|
||||||
throws MetadataResolutionException
|
throws MetadataResolutionException
|
||||||
{
|
{
|
||||||
final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
|
final List<ArtifactMetadataModel> artifactMetadataModels = new ArrayList<ArtifactMetadataModel>();
|
||||||
|
/*
|
||||||
// FIXME use cql query !
|
// FIXME use cql query !
|
||||||
getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
|
getArtifactMetadataModelEntityManager().visitAll( new Function<ArtifactMetadataModel, Boolean>()
|
||||||
{
|
{
|
||||||
|
@ -1625,9 +1614,9 @@ public class CassandraMetadataRepository
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
*/
|
||||||
List<ArtifactMetadata> artifactMetadatas = new ArrayList<ArtifactMetadata>( artifactMetadataModels.size() );
|
List<ArtifactMetadata> artifactMetadatas = new ArrayList<ArtifactMetadata>( artifactMetadataModels.size() );
|
||||||
|
/*
|
||||||
for ( ArtifactMetadataModel model : artifactMetadataModels )
|
for ( ArtifactMetadataModel model : artifactMetadataModels )
|
||||||
{
|
{
|
||||||
ArtifactMetadata artifactMetadata = getModelMapper().map( model, ArtifactMetadata.class );
|
ArtifactMetadata artifactMetadata = getModelMapper().map( model, ArtifactMetadata.class );
|
||||||
|
@ -1715,7 +1704,7 @@ public class CassandraMetadataRepository
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
return artifactMetadatas;
|
return artifactMetadatas;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,11 @@ package org.apache.archiva.metadata.repository.cassandra;
|
||||||
* under the License.
|
* 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
|
* @author Olivier Lamy
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
|
@ -57,6 +62,14 @@ public class CassandraUtils
|
||||||
return builder.toString();
|
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()
|
private CassandraUtils()
|
||||||
{
|
{
|
||||||
// no-op
|
// no-op
|
||||||
|
|
|
@ -19,26 +19,18 @@ package org.apache.archiva.metadata.repository.cassandra;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import me.prettyprint.cassandra.model.BasicColumnDefinition;
|
||||||
import com.netflix.astyanax.AstyanaxContext;
|
import me.prettyprint.cassandra.model.ConfigurableConsistencyLevel;
|
||||||
import com.netflix.astyanax.Keyspace;
|
import me.prettyprint.cassandra.serializers.StringSerializer;
|
||||||
import com.netflix.astyanax.connectionpool.NodeDiscoveryType;
|
import me.prettyprint.cassandra.service.CassandraHostConfigurator;
|
||||||
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
|
import me.prettyprint.cassandra.service.ThriftKsDef;
|
||||||
import com.netflix.astyanax.connectionpool.exceptions.NotFoundException;
|
import me.prettyprint.hector.api.Cluster;
|
||||||
import com.netflix.astyanax.connectionpool.impl.ConnectionPoolConfigurationImpl;
|
import me.prettyprint.hector.api.HConsistencyLevel;
|
||||||
import com.netflix.astyanax.connectionpool.impl.ConnectionPoolType;
|
import me.prettyprint.hector.api.Keyspace;
|
||||||
import com.netflix.astyanax.connectionpool.impl.Slf4jConnectionPoolMonitorImpl;
|
import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition;
|
||||||
import com.netflix.astyanax.ddl.KeyspaceDefinition;
|
import me.prettyprint.hector.api.ddl.ColumnIndexType;
|
||||||
import com.netflix.astyanax.entitystore.DefaultEntityManager;
|
import me.prettyprint.hector.api.ddl.ComparatorType;
|
||||||
import com.netflix.astyanax.entitystore.EntityManager;
|
import me.prettyprint.hector.api.factory.HFactory;
|
||||||
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 org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
@ -47,8 +39,8 @@ import org.springframework.stereotype.Service;
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.PreDestroy;
|
import javax.annotation.PreDestroy;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.persistence.PersistenceException;
|
import java.util.ArrayList;
|
||||||
import java.util.Properties;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FIXME make all configuration not hardcoded :-)
|
* FIXME make all configuration not hardcoded :-)
|
||||||
|
@ -70,215 +62,104 @@ public class DefaultCassandraArchivaManager
|
||||||
|
|
||||||
private static final String KEYSPACE_NAME = "ArchivaKeySpace";
|
private static final String KEYSPACE_NAME = "ArchivaKeySpace";
|
||||||
|
|
||||||
private AstyanaxContext<Keyspace> keyspaceContext;
|
private boolean started;
|
||||||
|
|
||||||
|
private Cluster cluster;
|
||||||
|
|
||||||
private Keyspace keyspace;
|
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
|
@PostConstruct
|
||||||
public void initialize()
|
public void initialize()
|
||||||
throws ConnectionException
|
|
||||||
{
|
{
|
||||||
|
// FIXME must come from configuration not sys props
|
||||||
String cassandraHost = System.getProperty( "cassandraHost", "localhost" );
|
String cassandraHost = System.getProperty( "cassandraHost", "localhost" );
|
||||||
String cassandraPort = System.getProperty( "cassandraPort" );
|
String cassandraPort = System.getProperty( "cassandraPort" );
|
||||||
String cqlVersion = System.getProperty( "cassandra.cqlversion", "3.0.0" );
|
int maxActive = Integer.getInteger( "cassandra.maxActive", 20 );
|
||||||
keyspaceContext = new AstyanaxContext.Builder().forCluster( CLUSTER_NAME ).forKeyspace(
|
String readConsistencyLevel =
|
||||||
KEYSPACE_NAME ).withAstyanaxConfiguration(
|
System.getProperty( "cassandra.readConsistencyLevel", HConsistencyLevel.QUORUM.name() );
|
||||||
new AstyanaxConfigurationImpl()
|
String writeConsistencyLevel =
|
||||||
//.setCqlVersion( cqlVersion )
|
System.getProperty( "cassandra.readConsistencyLevel", HConsistencyLevel.QUORUM.name() );
|
||||||
.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() );
|
|
||||||
|
|
||||||
this.start();
|
int replicationFactor = Integer.getInteger( "cassandra.replicationFactor", 1 );
|
||||||
|
|
||||||
keyspace = keyspaceContext.getClient();
|
String keyspaceName = System.getProperty( "cassandra.keyspace.name", KEYSPACE_NAME );
|
||||||
//Partitioner partitioner = keyspace.getPartitioner();
|
String clusterName = System.getProperty( "cassandra.cluster.name", CLUSTER_NAME );
|
||||||
|
|
||||||
ImmutableMap<String, Object> options = ImmutableMap.<String, Object>builder().put( "strategy_options",
|
final CassandraHostConfigurator configurator =
|
||||||
ImmutableMap.<String, Object>builder().put(
|
new CassandraHostConfigurator( cassandraHost + ":" + cassandraPort );
|
||||||
"replication_factor",
|
configurator.setMaxActive( maxActive );
|
||||||
"1" ).build() ).put(
|
|
||||||
"strategy_class", "SimpleStrategy" ).build();
|
|
||||||
|
|
||||||
// test if the namespace already exists if exception or null create it
|
cluster = HFactory.getOrCreateCluster( clusterName, configurator );
|
||||||
boolean keyspaceExists = false;
|
|
||||||
try
|
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",
|
||||||
keyspaceExists = true;
|
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 );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
catch ( ConnectionException e )
|
|
||||||
{
|
{
|
||||||
|
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 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !keyspaceExists )
|
{ // ensure keyspace exists, here if the keyspace doesn't exist we suppose nothing exist
|
||||||
|
if ( cluster.describeKeyspace( keyspaceName ) == null )
|
||||||
{
|
{
|
||||||
keyspace.createKeyspace( options );
|
logger.info( "Creating Archiva Cassandra '" + keyspaceName + "' keyspace." );
|
||||||
|
cluster.addKeyspace( HFactory.createKeyspaceDefinition( keyspaceName, //
|
||||||
|
ThriftKsDef.DEF_STRATEGY_CLASS, //
|
||||||
|
replicationFactor, //
|
||||||
|
cfds )
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
public void start()
|
||||||
{
|
{
|
||||||
keyspaceContext.start();
|
|
||||||
started = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreDestroy
|
@PreDestroy
|
||||||
public void shutdown()
|
public void shutdown()
|
||||||
{
|
{
|
||||||
if ( keyspaceContext != null )
|
|
||||||
{
|
|
||||||
keyspaceContext.shutdown();
|
|
||||||
started = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -288,21 +169,6 @@ public class DefaultCassandraArchivaManager
|
||||||
return started;
|
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
|
@Override
|
||||||
public Keyspace getKeyspace()
|
public Keyspace getKeyspace()
|
||||||
|
@ -310,66 +176,8 @@ public class DefaultCassandraArchivaManager
|
||||||
return keyspace;
|
return keyspace;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityManager<Repository, String> getRepositoryEntityManager()
|
public Cluster getCluster()
|
||||||
{
|
{
|
||||||
return repositoryEntityManager;
|
return cluster;
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,12 +19,9 @@ package org.apache.archiva.metadata.repository.cassandra.model;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.netflix.astyanax.entitystore.Serializer;
|
|
||||||
import com.netflix.astyanax.serializers.LongSerializer;
|
|
||||||
import org.apache.archiva.metadata.repository.cassandra.CassandraUtils;
|
import org.apache.archiva.metadata.repository.cassandra.CassandraUtils;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -35,58 +32,45 @@ import java.util.Date;
|
||||||
* @author Olivier Lamy
|
* @author Olivier Lamy
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
@Entity
|
|
||||||
public class ArtifactMetadataModel
|
public class ArtifactMetadataModel
|
||||||
implements Serializable
|
implements Serializable
|
||||||
{
|
{
|
||||||
|
|
||||||
// repositoryId + namespaceId + project + projectVersion + id
|
// repositoryId + namespaceId + project + projectVersion + id
|
||||||
@Id
|
@Id
|
||||||
@Serializer( DeflateStringSerializer.class )
|
|
||||||
private String artifactMetadataModelId;
|
private String artifactMetadataModelId;
|
||||||
|
|
||||||
@Column( name = "id" )
|
@Column(name = "id")
|
||||||
@Serializer( DeflateStringSerializer.class )
|
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
@Column( name = "repositoryId" )
|
@Column(name = "repositoryId")
|
||||||
@Serializer( DeflateStringSerializer.class )
|
|
||||||
private String repositoryId;
|
private String repositoryId;
|
||||||
|
|
||||||
@Column( name = "namespace" )
|
@Column(name = "namespace")
|
||||||
@Serializer( DeflateStringSerializer.class )
|
|
||||||
private String namespace;
|
private String namespace;
|
||||||
|
|
||||||
@Column( name = "project" )
|
@Column(name = "project")
|
||||||
@Serializer( DeflateStringSerializer.class )
|
|
||||||
private String project;
|
private String project;
|
||||||
|
|
||||||
@Column( name = "projectVersion" )
|
@Column(name = "projectVersion")
|
||||||
@Serializer( DeflateStringSerializer.class )
|
|
||||||
private String projectVersion;
|
private String projectVersion;
|
||||||
|
|
||||||
@Column( name = "version" )
|
@Column(name = "version")
|
||||||
@Serializer( DeflateStringSerializer.class )
|
|
||||||
private String version;
|
private String version;
|
||||||
|
|
||||||
@Column( name = "fileLastModified" )
|
@Column(name = "fileLastModified")
|
||||||
@Serializer( LongSerializer.class )
|
|
||||||
private long fileLastModified;
|
private long fileLastModified;
|
||||||
|
|
||||||
@Column( name = "size" )
|
@Column(name = "size")
|
||||||
@Serializer( LongSerializer.class )
|
|
||||||
private long size;
|
private long size;
|
||||||
|
|
||||||
@Column( name = "md5" )
|
@Column(name = "md5")
|
||||||
@Serializer( DeflateStringSerializer.class )
|
|
||||||
private String md5;
|
private String md5;
|
||||||
|
|
||||||
@Column( name = "sha1" )
|
@Column(name = "sha1")
|
||||||
@Serializer( DeflateStringSerializer.class )
|
|
||||||
private String sha1;
|
private String sha1;
|
||||||
|
|
||||||
@Column( name = "whenGathered" )
|
@Column(name = "whenGathered")
|
||||||
@Serializer( LongSerializer.class )
|
|
||||||
private long whenGathered;
|
private long whenGathered;
|
||||||
|
|
||||||
public ArtifactMetadataModel()
|
public ArtifactMetadataModel()
|
||||||
|
|
|
@ -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 );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -19,11 +19,9 @@ package org.apache.archiva.metadata.repository.cassandra.model;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.netflix.astyanax.entitystore.Serializer;
|
|
||||||
import org.apache.archiva.metadata.repository.cassandra.CassandraUtils;
|
import org.apache.archiva.metadata.repository.cassandra.CassandraUtils;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,32 +30,26 @@ import javax.persistence.Id;
|
||||||
* @author Olivier Lamy
|
* @author Olivier Lamy
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
@Entity
|
|
||||||
public class MetadataFacetModel
|
public class MetadataFacetModel
|
||||||
{
|
{
|
||||||
// id is repositoryId + namespaceId + projectId + facetId + name + mapKey
|
// id is repositoryId + namespaceId + projectId + facetId + name + mapKey
|
||||||
@Id
|
@Id
|
||||||
@Column( name = "id" )
|
@Column(name = "id")
|
||||||
@Serializer( DeflateStringSerializer.class )
|
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
@Column( name = "artifactMetadataModel" )
|
@Column(name = "artifactMetadataModel")
|
||||||
private ArtifactMetadataModel artifactMetadataModel;
|
private ArtifactMetadataModel artifactMetadataModel;
|
||||||
|
|
||||||
@Column( name = "facetId" )
|
@Column(name = "facetId")
|
||||||
@Serializer( DeflateStringSerializer.class )
|
|
||||||
private String facetId;
|
private String facetId;
|
||||||
|
|
||||||
@Column( name = "key" )
|
@Column(name = "key")
|
||||||
@Serializer( DeflateStringSerializer.class )
|
|
||||||
private String key;
|
private String key;
|
||||||
|
|
||||||
@Column( name = "name" )
|
@Column(name = "name")
|
||||||
@Serializer( DeflateStringSerializer.class )
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Column( name = "value" )
|
@Column(name = "value")
|
||||||
@Serializer( DeflateStringSerializer.class )
|
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
public MetadataFacetModel()
|
public MetadataFacetModel()
|
||||||
|
@ -232,7 +224,8 @@ public class MetadataFacetModel
|
||||||
String str = CassandraUtils.generateKey( this.artifactMetadataModel == null
|
String str = CassandraUtils.generateKey( this.artifactMetadataModel == null
|
||||||
? this.repositoryId
|
? this.repositoryId
|
||||||
: this.artifactMetadataModel.getArtifactMetadataModelId(),
|
: this.artifactMetadataModel.getArtifactMetadataModelId(),
|
||||||
this.facetId, this.name, this.key );
|
this.facetId, this.name, this.key
|
||||||
|
);
|
||||||
|
|
||||||
//return Long.toString( str.hashCode() );
|
//return Long.toString( str.hashCode() );
|
||||||
return str;
|
return str;
|
||||||
|
|
|
@ -19,12 +19,9 @@ package org.apache.archiva.metadata.repository.cassandra.model;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.netflix.astyanax.entitystore.Serializer;
|
|
||||||
import org.apache.archiva.metadata.repository.cassandra.CassandraUtils;
|
import org.apache.archiva.metadata.repository.cassandra.CassandraUtils;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,32 +29,18 @@ import java.io.Serializable;
|
||||||
* @author Olivier Lamy
|
* @author Olivier Lamy
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
@Entity
|
|
||||||
public class Namespace
|
public class Namespace
|
||||||
implements Serializable
|
implements Serializable
|
||||||
{
|
{
|
||||||
|
|
||||||
@Id
|
|
||||||
@Serializer( DeflateStringSerializer.class )
|
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
@Column( name = "name" )
|
|
||||||
@Serializer( DeflateStringSerializer.class )
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Column( name = "repositoryid" )
|
|
||||||
@Serializer( DeflateStringSerializer.class )
|
|
||||||
private String repositoryId;
|
private String repositoryId;
|
||||||
|
|
||||||
@Column( name = "repositoryname" )
|
|
||||||
@Serializer( DeflateStringSerializer.class )
|
|
||||||
private String repositoryName;
|
private String repositoryName;
|
||||||
|
|
||||||
//@ManyToOne(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
|
|
||||||
//@JoinColumn(name = "repository_id")
|
|
||||||
//private transient Repository repository;
|
|
||||||
|
|
||||||
|
|
||||||
public Namespace()
|
public Namespace()
|
||||||
{
|
{
|
||||||
// no op
|
// no op
|
||||||
|
|
|
@ -19,11 +19,9 @@ package org.apache.archiva.metadata.repository.cassandra.model;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.netflix.astyanax.entitystore.Serializer;
|
|
||||||
import org.apache.archiva.metadata.repository.cassandra.CassandraUtils;
|
import org.apache.archiva.metadata.repository.cassandra.CassandraUtils;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@ -31,21 +29,18 @@ import java.io.Serializable;
|
||||||
* @author Olivier Lamy
|
* @author Olivier Lamy
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
@Entity
|
|
||||||
public class Project
|
public class Project
|
||||||
implements Serializable
|
implements Serializable
|
||||||
{
|
{
|
||||||
@Id
|
@Id
|
||||||
@Column( name = "projectKey" )
|
@Column(name = "projectKey")
|
||||||
@Serializer( DeflateStringSerializer.class )
|
|
||||||
private String projectKey;
|
private String projectKey;
|
||||||
|
|
||||||
@Column( name = "projectId" )
|
@Column(name = "projectId")
|
||||||
@Serializer( DeflateStringSerializer.class )
|
|
||||||
private String projectId;
|
private String projectId;
|
||||||
|
|
||||||
|
|
||||||
@Column( name = "repository" )
|
@Column(name = "repository")
|
||||||
private Namespace namespace;
|
private Namespace namespace;
|
||||||
|
|
||||||
public Project()
|
public Project()
|
||||||
|
|
|
@ -19,7 +19,6 @@ package org.apache.archiva.metadata.repository.cassandra.model;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.netflix.astyanax.entitystore.Serializer;
|
|
||||||
import org.apache.archiva.metadata.model.CiManagement;
|
import org.apache.archiva.metadata.model.CiManagement;
|
||||||
import org.apache.archiva.metadata.model.Dependency;
|
import org.apache.archiva.metadata.model.Dependency;
|
||||||
import org.apache.archiva.metadata.model.IssueManagement;
|
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 org.apache.archiva.metadata.repository.cassandra.CassandraUtils;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -39,63 +37,56 @@ import java.util.List;
|
||||||
* @author Olivier Lamy
|
* @author Olivier Lamy
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
@Entity
|
|
||||||
public class ProjectVersionMetadataModel
|
public class ProjectVersionMetadataModel
|
||||||
{
|
{
|
||||||
// repositoryId + namespace + projectId + id (version)
|
// repositoryId + namespace + projectId + id (version)
|
||||||
@Id
|
@Id
|
||||||
@Serializer( DeflateStringSerializer.class )
|
|
||||||
private String rowId;
|
private String rowId;
|
||||||
|
|
||||||
@Column( name = "namespace" )
|
@Column(name = "namespace")
|
||||||
private Namespace namespace;
|
private Namespace namespace;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* id is the version
|
* id is the version
|
||||||
*/
|
*/
|
||||||
@Column( name = "id" )
|
@Column(name = "id")
|
||||||
@Serializer( DeflateStringSerializer.class )
|
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
@Column( name = "projectId" )
|
@Column(name = "projectId")
|
||||||
@Serializer( DeflateStringSerializer.class )
|
|
||||||
private String projectId;
|
private String projectId;
|
||||||
|
|
||||||
@Column( name = "url" )
|
@Column(name = "url")
|
||||||
@Serializer( DeflateStringSerializer.class )
|
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
@Column( name = "name" )
|
@Column(name = "name")
|
||||||
@Serializer( DeflateStringSerializer.class )
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Column( name = "description" )
|
@Column(name = "description")
|
||||||
@Serializer( DeflateStringSerializer.class )
|
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
@Column( name = "organization" )
|
@Column(name = "organization")
|
||||||
private Organization organization;
|
private Organization organization;
|
||||||
|
|
||||||
@Column( name = "issueManagement" )
|
@Column(name = "issueManagement")
|
||||||
private IssueManagement issueManagement;
|
private IssueManagement issueManagement;
|
||||||
|
|
||||||
@Column( name = "scm" )
|
@Column(name = "scm")
|
||||||
private Scm scm;
|
private Scm scm;
|
||||||
|
|
||||||
@Column( name = "ciManagement" )
|
@Column(name = "ciManagement")
|
||||||
private CiManagement ciManagement;
|
private CiManagement ciManagement;
|
||||||
|
|
||||||
// FIXME store those values in a separate table
|
// FIXME store those values in a separate table
|
||||||
@Column( name = "licenses" )
|
@Column(name = "licenses")
|
||||||
private List<License> licenses = new ArrayList<License>();
|
private List<License> licenses = new ArrayList<License>();
|
||||||
|
|
||||||
@Column( name = "mailingLists" )
|
@Column(name = "mailingLists")
|
||||||
private List<MailingList> mailingLists = new ArrayList<MailingList>();
|
private List<MailingList> mailingLists = new ArrayList<MailingList>();
|
||||||
|
|
||||||
@Column( name = "dependencies" )
|
@Column(name = "dependencies")
|
||||||
private List<Dependency> dependencies = new ArrayList<Dependency>();
|
private List<Dependency> dependencies = new ArrayList<Dependency>();
|
||||||
|
|
||||||
@Column( name = "incomplete" )
|
@Column(name = "incomplete")
|
||||||
private boolean incomplete;
|
private boolean incomplete;
|
||||||
|
|
||||||
public String getProjectId()
|
public String getProjectId()
|
||||||
|
|
|
@ -19,12 +19,6 @@ package org.apache.archiva.metadata.repository.cassandra.model;
|
||||||
* under the License.
|
* 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;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,22 +26,14 @@ import java.io.Serializable;
|
||||||
* @author Olivier Lamy
|
* @author Olivier Lamy
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
@Entity
|
|
||||||
public class Repository
|
public class Repository
|
||||||
implements Serializable
|
implements Serializable
|
||||||
{
|
{
|
||||||
|
|
||||||
@Id
|
|
||||||
@Column( name = "id" )
|
|
||||||
@Serializer( DeflateStringSerializer.class )
|
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
@Column(name = "name")
|
|
||||||
@Serializer( DeflateStringSerializer.class )
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
//private transient List<Namespace> namespaces = new ArrayList<Namespace>();
|
|
||||||
|
|
||||||
public Repository()
|
public Repository()
|
||||||
{
|
{
|
||||||
// no op
|
// no op
|
||||||
|
@ -79,22 +65,6 @@ public class Repository
|
||||||
this.name = name;
|
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
|
@Override
|
||||||
public boolean equals( Object o )
|
public boolean equals( Object o )
|
||||||
{
|
{
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class CassandraMetadataRepositoryTest
|
||||||
private Logger logger = LoggerFactory.getLogger( getClass() );
|
private Logger logger = LoggerFactory.getLogger( getClass() );
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named( value = "archivaEntityManagerFactory#cassandra" )
|
@Named(value = "archivaEntityManagerFactory#cassandra")
|
||||||
CassandraArchivaManager cassandraArchivaManager;
|
CassandraArchivaManager cassandraArchivaManager;
|
||||||
|
|
||||||
CassandraMetadataRepository cmr;
|
CassandraMetadataRepository cmr;
|
||||||
|
@ -78,45 +78,12 @@ public class CassandraMetadataRepositoryTest
|
||||||
protected void clearReposAndNamespace()
|
protected void clearReposAndNamespace()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
/*
|
cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
|
||||||
List<Project> projects = cmr.getProjectEntityManager().getAll();
|
"project" );
|
||||||
|
cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
|
||||||
cmr.getProjectEntityManager().remove( projects );
|
"namespace" );
|
||||||
*/
|
cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
|
||||||
cmr.getProjectEntityManager().truncate();
|
"repository" );
|
||||||
|
|
||||||
/*
|
|
||||||
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();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,15 +37,15 @@ import javax.inject.Named;
|
||||||
/**
|
/**
|
||||||
* @author Olivier Lamy
|
* @author Olivier Lamy
|
||||||
*/
|
*/
|
||||||
@RunWith(ArchivaSpringJUnit4ClassRunner.class)
|
@RunWith( ArchivaSpringJUnit4ClassRunner.class )
|
||||||
@ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" })
|
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
|
||||||
public class RepositoriesNamespaceTest
|
public class RepositoriesNamespaceTest
|
||||||
{
|
{
|
||||||
|
|
||||||
private Logger logger = LoggerFactory.getLogger( getClass() );
|
private Logger logger = LoggerFactory.getLogger( getClass() );
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named(value = "archivaEntityManagerFactory#cassandra")
|
@Named( value = "archivaEntityManagerFactory#cassandra" )
|
||||||
CassandraArchivaManager cassandraArchivaManager;
|
CassandraArchivaManager cassandraArchivaManager;
|
||||||
|
|
||||||
|
|
||||||
|
@ -85,24 +85,35 @@ public class RepositoriesNamespaceTest
|
||||||
|
|
||||||
cmr.updateNamespace( "release", "org" );
|
cmr.updateNamespace( "release", "org" );
|
||||||
|
|
||||||
r = cmr.getRepositoryEntityManager().get( "release" );
|
r = cmr.getRepository( "release" );
|
||||||
|
|
||||||
Assertions.assertThat( r ).isNotNull();
|
Assertions.assertThat( r ).isNotNull();
|
||||||
|
|
||||||
Assertions.assertThat( cmr.getRepositories() ).isNotEmpty().hasSize( 1 );
|
Assertions.assertThat( cmr.getRepositories() ).isNotEmpty().hasSize( 1 );
|
||||||
Assertions.assertThat( cmr.getNamespaces( "release" ) ).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 ).isNotNull();
|
||||||
Assertions.assertThat( n.getRepository() ).isNotNull();
|
Assertions.assertThat( n.getRepository() ).isNotNull();
|
||||||
|
|
||||||
cmr.updateNamespace( "release", "org.apache" );
|
cmr.updateNamespace( "release", "org.apache" );
|
||||||
|
|
||||||
r = cmr.getRepositoryEntityManager().get( "release" );
|
r = cmr.getRepository( "release" );
|
||||||
|
|
||||||
Assertions.assertThat( r ).isNotNull();
|
Assertions.assertThat( r ).isNotNull();
|
||||||
Assertions.assertThat( cmr.getNamespaces( "release" ) ).isNotEmpty().hasSize( 2 );
|
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 )
|
catch ( Exception e )
|
||||||
{
|
{
|
||||||
|
@ -118,22 +129,11 @@ public class RepositoriesNamespaceTest
|
||||||
protected void clearReposAndNamespace()
|
protected void clearReposAndNamespace()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
/*
|
cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
|
||||||
List<Project> projects = cmr.getProjectEntityManager().getAll();
|
"project" );
|
||||||
cmr.getProjectEntityManager().remove( projects );
|
cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
|
||||||
*/
|
"namespace" );
|
||||||
cmr.getProjectEntityManager().truncate();
|
cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
|
||||||
|
"repository" );
|
||||||
/*
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue