From 4ac873046d2ae2a1b687f1fbb6771324bf78e5a5 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Tue, 25 Mar 2014 06:28:03 +0000 Subject: [PATCH] record mailing lists in Cassandra git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1581252 13f79535-47bb-0310-9956-ffa450edef68 --- .../cassandra/CassandraArchivaManager.java | 2 + .../CassandraMetadataRepository.java | 114 ++++++++++++++++++ .../DefaultCassandraArchivaManager.java | 26 ++++ .../CassandraMetadataRepositoryTest.java | 3 + 4 files changed, 145 insertions(+) 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 metadataFacetTemplate; + private final ColumnFamilyTemplate mailingListTemplate; + public CassandraMetadataRepository( Map metadataFacetFactories, ArchivaConfiguration configuration, CassandraArchivaManager cassandraArchivaManager ) @@ -134,6 +138,13 @@ public class CassandraMetadataRepository // StringSerializer.get(), // StringSerializer.get() ); + + this.mailingListTemplate = + new ThriftColumnFamilyTemplate( 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 mailingLists ) + { + if ( mailingLists == null || mailingLists.isEmpty() ) + { + return; + } + Mutator 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> result = + HFactory.createRangeSlicesQuery( cassandraArchivaManager.getKeyspace(), ss, ss, ss ) // + .setColumnFamily( cassandraArchivaManager.getMailingListFamilyName() ) // + .setColumnNames( "name" ) // + .setRowCount( Integer.MAX_VALUE ) // + .addEqualsExpression( "projectVersionMetadataModel.key", projectVersionMetadataKey ) // + .execute(); + for ( Row row : result.get() ) + { + this.mailingListTemplate.deleteRow( row.getKey() ); + } + } + + protected List getMailingLists( String projectVersionMetadataKey ) + { + List mailingLists = new ArrayList(); + + StringSerializer ss = StringSerializer.get(); + QueryResult> result = + HFactory.createRangeSlicesQuery( cassandraArchivaManager.getKeyspace(), ss, ss, ss ) // + .setColumnFamily( cassandraArchivaManager.getMailingListFamilyName() ) // + .setColumnNames( "name" ) // + .setRowCount( Integer.MAX_VALUE ) // + .addEqualsExpression( "projectVersionMetadataModel.key", projectVersionMetadataKey ) // + .execute(); + for ( Row row : result.get() ) + { + ColumnFamilyResult 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 otherArchives = new ArrayList(); + + 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; /** -- 2.39.5