diff options
author | Olivier Lamy <olamy@apache.org> | 2014-03-25 06:28:03 +0000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2014-03-25 06:28:03 +0000 |
commit | 4ac873046d2ae2a1b687f1fbb6771324bf78e5a5 (patch) | |
tree | 78fc5a70facb236f99fe03f8a8d9b70f42fe2268 /archiva-modules/plugins | |
parent | 91c9d36a7b5aabde1d614b88fa7c42a091e01a12 (diff) | |
download | archiva-4ac873046d2ae2a1b687f1fbb6771324bf78e5a5.tar.gz archiva-4ac873046d2ae2a1b687f1fbb6771324bf78e5a5.zip |
record mailing lists in Cassandra
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1581252 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/plugins')
4 files changed, 145 insertions, 0 deletions
diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraArchivaManager.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraArchivaManager.java index e028d79dd..160d66a05 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraArchivaManager.java +++ b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraArchivaManager.java @@ -50,4 +50,6 @@ public interface CassandraArchivaManager String getMetadataFacetModelFamilyName(); + String getMailingListFamilyName(); + } diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java index d7ba7b117..78b7f8611 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java +++ b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java @@ -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, diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/DefaultCassandraArchivaManager.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/DefaultCassandraArchivaManager.java index 651507d02..abf060502 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/DefaultCassandraArchivaManager.java +++ b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/DefaultCassandraArchivaManager.java @@ -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; + } } diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java b/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java index e501b8266..5da758b90 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java +++ b/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java @@ -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; /** |