record license information in cassandra

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1581637 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2014-03-26 02:40:40 +00:00
parent 663de30beb
commit fa06b7b997
5 changed files with 116 additions and 7 deletions

View File

@ -47,6 +47,7 @@ public class License
public License()
{
// no op
}
public String getName()

View File

@ -52,4 +52,6 @@ public interface CassandraArchivaManager
String getMailingListFamilyName();
String getLicenseFamilyName();
}

View File

@ -42,6 +42,7 @@ import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.CiManagement;
import org.apache.archiva.metadata.model.FacetedMetadata;
import org.apache.archiva.metadata.model.IssueManagement;
import org.apache.archiva.metadata.model.License;
import org.apache.archiva.metadata.model.MailingList;
import org.apache.archiva.metadata.model.MetadataFacet;
import org.apache.archiva.metadata.model.MetadataFacetFactory;
@ -105,6 +106,8 @@ public class CassandraMetadataRepository
private final ColumnFamilyTemplate<String, String> mailingListTemplate;
private final ColumnFamilyTemplate<String, String> licenseTemplate;
public CassandraMetadataRepository( Map<String, MetadataFacetFactory> metadataFacetFactories,
ArchivaConfiguration configuration,
CassandraArchivaManager cassandraArchivaManager )
@ -145,6 +148,12 @@ public class CassandraMetadataRepository
//
StringSerializer.get(), //
StringSerializer.get() );
this.licenseTemplate = new ThriftColumnFamilyTemplate<String, String>( cassandraArchivaManager.getKeyspace(), //
cassandraArchivaManager.getLicenseFamilyName(),
//
StringSerializer.get(), //
StringSerializer.get() );
}
@ -898,6 +907,8 @@ public class CassandraMetadataRepository
recordMailingList( key, versionMetadata.getMailingLists() );
}
recordLicenses( key, versionMetadata.getLicenses() );
MutationResult mutationResult = mutator.execute();
}
else
@ -955,12 +966,12 @@ public class CassandraMetadataRepository
}
}
if ( versionMetadata.getMailingLists() != null )
{
// update is a delete record
removeMailingList( key );
recordMailingList( key, versionMetadata.getMailingLists() );
}
// update is a delete record
removeMailingList( key );
recordMailingList( key, versionMetadata.getMailingLists() );
removeLicenses( key );
recordLicenses( key, versionMetadata.getLicenses() );
projectVersionMetadataModelTemplate.update( updater );
@ -1035,6 +1046,7 @@ public class CassandraMetadataRepository
}
}
projectVersionMetadata.setMailingLists( getMailingLists( key ) );
projectVersionMetadata.setLicenses( getLicenses( key ) );
// FIXME complete collections !!
// facets
@ -1161,7 +1173,7 @@ public class CassandraMetadataRepository
for ( String columnName : columnFamilyResult.getColumnNames() )
{
if (StringUtils.startsWith( columnName, "otherArchive." ))
if ( StringUtils.startsWith( columnName, "otherArchive." ) )
{
otherArchives.add( columnFamilyResult.getString( columnName ) );
}
@ -1174,6 +1186,72 @@ public class CassandraMetadataRepository
return mailingLists;
}
protected void recordLicenses( String projectVersionMetadataKey, List<License> licenses )
{
if ( licenses == null || licenses.isEmpty() )
{
return;
}
Mutator<String> licenseMutator = this.licenseTemplate.createMutator();
for ( License license : licenses )
{
// we don't care about the key as the real used one with the projectVersionMetadata
String keyLicense = UUID.randomUUID().toString();
String cfLicense = cassandraArchivaManager.getLicenseFamilyName();
addInsertion( licenseMutator, keyLicense, cfLicense, "projectVersionMetadataModel.key",
projectVersionMetadataKey );
addInsertion( licenseMutator, keyLicense, cfLicense, "license.name", license.getName() );
addInsertion( licenseMutator, keyLicense, cfLicense, "license.url", license.getUrl() );
}
licenseMutator.execute();
}
protected void removeLicenses( String projectVersionMetadataKey )
{
StringSerializer ss = StringSerializer.get();
QueryResult<OrderedRows<String, String, String>> result =
HFactory.createRangeSlicesQuery( cassandraArchivaManager.getKeyspace(), ss, ss, ss ) //
.setColumnFamily( cassandraArchivaManager.getLicenseFamilyName() ) //
.setColumnNames( "name" ) //
.setRowCount( Integer.MAX_VALUE ) //
.addEqualsExpression( "projectVersionMetadataModel.key", projectVersionMetadataKey ) //
.execute();
for ( Row<String, String, String> row : result.get() )
{
this.licenseTemplate.deleteRow( row.getKey() );
}
}
protected List<License> getLicenses( String projectVersionMetadataKey )
{
List<License> licenses = new ArrayList<License>();
StringSerializer ss = StringSerializer.get();
QueryResult<OrderedRows<String, String, String>> result =
HFactory.createRangeSlicesQuery( cassandraArchivaManager.getKeyspace(), ss, ss, ss ) //
.setColumnFamily( cassandraArchivaManager.getLicenseFamilyName() ) //
.setColumnNames( "projectVersionMetadataModel.key" ) //
.setRowCount( Integer.MAX_VALUE ) //
.addEqualsExpression( "projectVersionMetadataModel.key", projectVersionMetadataKey ) //
.execute();
for ( Row<String, String, String> row : result.get() )
{
ColumnFamilyResult<String, String> columnFamilyResult = this.licenseTemplate.queryColumns( row.getKey() );
licenses.add( new License( columnFamilyResult.getString( "license.name" ),
columnFamilyResult.getString( "license.url" ) ) );
}
return licenses;
}
@Override
public void updateArtifact( String repositoryId, String namespaceId, String projectId, String projectVersion,
ArtifactMetadata artifactMeta )

View File

@ -83,6 +83,8 @@ public class DefaultCassandraArchivaManager
private String mailingListFamilyName = "mailinglist";
private String licenseFamilyName = "license";
@PostConstruct
public void initialize()
@ -378,6 +380,24 @@ public class DefaultCassandraArchivaManager
projectVersionMetadataIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
mailingListCf.addColumnDefinition( projectVersionMetadataIdColumn );
}
// license table
{
final ColumnFamilyDefinition licenseCf =
HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), //
getLicenseFamilyName(), //
ComparatorType.UTF8TYPE );
cfds.add( licenseCf );
// creating indexes for cql query
BasicColumnDefinition projectVersionMetadataIdColumn = new BasicColumnDefinition();
projectVersionMetadataIdColumn.setName( StringSerializer.get().toByteBuffer( "projectVersionMetadataId" ) );
projectVersionMetadataIdColumn.setIndexName( "projectVersionMetadataId" );
projectVersionMetadataIdColumn.setIndexType( ColumnIndexType.KEYS );
projectVersionMetadataIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
licenseCf.addColumnDefinition( projectVersionMetadataIdColumn );
}
@ -458,4 +478,9 @@ public class DefaultCassandraArchivaManager
{
return mailingListFamilyName;
}
public String getLicenseFamilyName()
{
return licenseFamilyName;
}
}

View File

@ -97,6 +97,9 @@ public class CassandraMetadataRepositoryTest
cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
cassandraArchivaManager.getMailingListFamilyName() );
cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
cassandraArchivaManager.getLicenseFamilyName() );
}
}