mirror of https://github.com/apache/archiva.git
record mailing lists in Cassandra
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1581252 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
91c9d36a7b
commit
4ac873046d
|
@ -50,4 +50,6 @@ public interface CassandraArchivaManager
|
|||
|
||||
String getMetadataFacetModelFamilyName();
|
||||
|
||||
String getMailingListFamilyName();
|
||||
|
||||
}
|
||||
|
|
|
@ -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.MailingList;
|
||||
import org.apache.archiva.metadata.model.MetadataFacet;
|
||||
import org.apache.archiva.metadata.model.MetadataFacetFactory;
|
||||
import org.apache.archiva.metadata.model.Organization;
|
||||
|
@ -74,6 +75,7 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.apache.archiva.metadata.repository.cassandra.CassandraUtils.*;
|
||||
|
||||
|
@ -101,6 +103,8 @@ public class CassandraMetadataRepository
|
|||
|
||||
private final ColumnFamilyTemplate<String, String> metadataFacetTemplate;
|
||||
|
||||
private final ColumnFamilyTemplate<String, String> mailingListTemplate;
|
||||
|
||||
public CassandraMetadataRepository( Map<String, MetadataFacetFactory> metadataFacetFactories,
|
||||
ArchivaConfiguration configuration,
|
||||
CassandraArchivaManager cassandraArchivaManager )
|
||||
|
@ -134,6 +138,13 @@ public class CassandraMetadataRepository
|
|||
//
|
||||
StringSerializer.get(), //
|
||||
StringSerializer.get() );
|
||||
|
||||
this.mailingListTemplate =
|
||||
new ThriftColumnFamilyTemplate<String, String>( cassandraArchivaManager.getKeyspace(), //
|
||||
cassandraArchivaManager.getMailingListFamilyName(),
|
||||
//
|
||||
StringSerializer.get(), //
|
||||
StringSerializer.get() );
|
||||
}
|
||||
|
||||
|
||||
|
@ -879,6 +890,11 @@ public class CassandraMetadataRepository
|
|||
}
|
||||
}
|
||||
|
||||
if ( versionMetadata.getMailingLists() != null )
|
||||
{
|
||||
recordMailingList( key, versionMetadata.getMailingLists() );
|
||||
}
|
||||
|
||||
MutationResult mutationResult = mutator.execute();
|
||||
}
|
||||
else
|
||||
|
@ -936,6 +952,13 @@ public class CassandraMetadataRepository
|
|||
}
|
||||
}
|
||||
|
||||
if ( versionMetadata.getMailingLists() != null )
|
||||
{
|
||||
// update is a delete record
|
||||
removeMailingList( key );
|
||||
recordMailingList( key, versionMetadata.getMailingLists() );
|
||||
}
|
||||
|
||||
projectVersionMetadataModelTemplate.update( updater );
|
||||
|
||||
}
|
||||
|
@ -1008,6 +1031,7 @@ public class CassandraMetadataRepository
|
|||
projectVersionMetadata.setScm( new Scm( conn, devConn, url ) );
|
||||
}
|
||||
}
|
||||
projectVersionMetadata.setMailingLists( getMailingLists( key ) );
|
||||
// FIXME complete collections !!
|
||||
// facets
|
||||
|
||||
|
@ -1056,6 +1080,96 @@ public class CassandraMetadataRepository
|
|||
return projectVersionMetadata;
|
||||
}
|
||||
|
||||
protected void recordMailingList( String projectVersionMetadataKey, List<MailingList> mailingLists )
|
||||
{
|
||||
if ( mailingLists == null || mailingLists.isEmpty() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
Mutator<String> mailingMutator = this.mailingListTemplate.createMutator();
|
||||
for ( MailingList mailingList : mailingLists )
|
||||
{
|
||||
// we don't care about the key as the real used one with the projectVersionMetadata
|
||||
String keyMailingList = UUID.randomUUID().toString();
|
||||
String cfMailingList = cassandraArchivaManager.getMailingListFamilyName();
|
||||
|
||||
addInsertion( mailingMutator, keyMailingList, cfMailingList, "projectVersionMetadataModel.key",
|
||||
projectVersionMetadataKey );
|
||||
addInsertion( mailingMutator, keyMailingList, cfMailingList, "name", mailingList.getName() );
|
||||
addInsertion( mailingMutator, keyMailingList, cfMailingList, "mainArchiveUrl",
|
||||
mailingList.getMainArchiveUrl() );
|
||||
addInsertion( mailingMutator, keyMailingList, cfMailingList, "postAddress", mailingList.getPostAddress() );
|
||||
addInsertion( mailingMutator, keyMailingList, cfMailingList, "subscribeAddress",
|
||||
mailingList.getSubscribeAddress() );
|
||||
addInsertion( mailingMutator, keyMailingList, cfMailingList, "unsubscribeAddress",
|
||||
mailingList.getUnsubscribeAddress() );
|
||||
int idx = 0;
|
||||
for ( String otherArchive : mailingList.getOtherArchives() )
|
||||
{
|
||||
addInsertion( mailingMutator, keyMailingList, cfMailingList, "otherArchive." + idx, otherArchive );
|
||||
idx++;
|
||||
}
|
||||
|
||||
}
|
||||
mailingMutator.execute();
|
||||
}
|
||||
|
||||
protected void removeMailingList( String projectVersionMetadataKey )
|
||||
{
|
||||
StringSerializer ss = StringSerializer.get();
|
||||
QueryResult<OrderedRows<String, String, String>> result =
|
||||
HFactory.createRangeSlicesQuery( cassandraArchivaManager.getKeyspace(), ss, ss, ss ) //
|
||||
.setColumnFamily( cassandraArchivaManager.getMailingListFamilyName() ) //
|
||||
.setColumnNames( "name" ) //
|
||||
.setRowCount( Integer.MAX_VALUE ) //
|
||||
.addEqualsExpression( "projectVersionMetadataModel.key", projectVersionMetadataKey ) //
|
||||
.execute();
|
||||
for ( Row<String, String, String> row : result.get() )
|
||||
{
|
||||
this.mailingListTemplate.deleteRow( row.getKey() );
|
||||
}
|
||||
}
|
||||
|
||||
protected List<MailingList> getMailingLists( String projectVersionMetadataKey )
|
||||
{
|
||||
List<MailingList> mailingLists = new ArrayList<MailingList>();
|
||||
|
||||
StringSerializer ss = StringSerializer.get();
|
||||
QueryResult<OrderedRows<String, String, String>> result =
|
||||
HFactory.createRangeSlicesQuery( cassandraArchivaManager.getKeyspace(), ss, ss, ss ) //
|
||||
.setColumnFamily( cassandraArchivaManager.getMailingListFamilyName() ) //
|
||||
.setColumnNames( "name" ) //
|
||||
.setRowCount( Integer.MAX_VALUE ) //
|
||||
.addEqualsExpression( "projectVersionMetadataModel.key", projectVersionMetadataKey ) //
|
||||
.execute();
|
||||
for ( Row<String, String, String> row : result.get() )
|
||||
{
|
||||
ColumnFamilyResult<String, String> columnFamilyResult =
|
||||
this.mailingListTemplate.queryColumns( row.getKey() );
|
||||
|
||||
MailingList mailingList = new MailingList();
|
||||
mailingList.setName( columnFamilyResult.getString( "name" ) );
|
||||
mailingList.setMainArchiveUrl( columnFamilyResult.getString( "mainArchiveUrl" ) );
|
||||
mailingList.setPostAddress( columnFamilyResult.getString( "postAddress" ) );
|
||||
mailingList.setSubscribeAddress( columnFamilyResult.getString( "subscribeAddress" ) );
|
||||
mailingList.setUnsubscribeAddress( columnFamilyResult.getString( "unsubscribeAddress" ) );
|
||||
|
||||
List<String> otherArchives = new ArrayList<String>();
|
||||
|
||||
for ( String columnName : columnFamilyResult.getColumnNames() )
|
||||
{
|
||||
if (StringUtils.startsWith( columnName, "otherArchive." ))
|
||||
{
|
||||
otherArchives.add( columnFamilyResult.getString( columnName ) );
|
||||
}
|
||||
}
|
||||
|
||||
mailingList.setOtherArchives( otherArchives );
|
||||
mailingLists.add( mailingList );
|
||||
}
|
||||
|
||||
return mailingLists;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateArtifact( String repositoryId, String namespaceId, String projectId, String projectVersion,
|
||||
|
|
|
@ -81,6 +81,8 @@ public class DefaultCassandraArchivaManager
|
|||
|
||||
private String metadataFacetModelFamilyName = "metadatafacetmodel";
|
||||
|
||||
private String mailingListFamilyName = "mailinglist";
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void initialize()
|
||||
|
@ -359,6 +361,25 @@ public class DefaultCassandraArchivaManager
|
|||
|
||||
}
|
||||
|
||||
// mailinglist table
|
||||
{
|
||||
final ColumnFamilyDefinition mailingListCf =
|
||||
HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), //
|
||||
getMailingListFamilyName(), //
|
||||
ComparatorType.UTF8TYPE );
|
||||
cfds.add( mailingListCf );
|
||||
|
||||
// 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() );
|
||||
mailingListCf.addColumnDefinition( projectVersionMetadataIdColumn );
|
||||
|
||||
|
||||
}
|
||||
|
||||
// TODO take care of update new table!!
|
||||
{ // ensure keyspace exists, here if the keyspace doesn't exist we suppose nothing exist
|
||||
|
@ -432,4 +453,9 @@ public class DefaultCassandraArchivaManager
|
|||
{
|
||||
return metadataFacetModelFamilyName;
|
||||
}
|
||||
|
||||
public String getMailingListFamilyName()
|
||||
{
|
||||
return mailingListFamilyName;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,9 @@ import org.slf4j.LoggerFactory;
|
|||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue