aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2014-03-26 02:40:51 +0000
committerOlivier Lamy <olamy@apache.org>2014-03-26 02:40:51 +0000
commit509e72be48c2930dfc2b3b6656d80d3503c7fdf7 (patch)
treebca9d31079d73e38e8070b08be0736ebee051b11 /archiva-modules
parentfa06b7b9974c3a2fa69f3f4834a9415b3340a82e (diff)
downloadarchiva-509e72be48c2930dfc2b3b6656d80d3503c7fdf7.tar.gz
archiva-509e72be48c2930dfc2b3b6656d80d3503c7fdf7.zip
implement cassandra record of dependencies
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1581638 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules')
-rw-r--r--archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraArchivaManager.java2
-rw-r--r--archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java125
-rw-r--r--archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/DefaultCassandraArchivaManager.java26
-rw-r--r--archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java3
4 files changed, 147 insertions, 9 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 4233eff6b..45af48360 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
@@ -54,4 +54,6 @@ public interface CassandraArchivaManager
String getLicenseFamilyName();
+ String getDependencyFamilyName();
+
}
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 cbd576d9b..6e4794432 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
@@ -40,6 +40,7 @@ import me.prettyprint.hector.api.query.RangeSlicesQuery;
import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.CiManagement;
+import org.apache.archiva.metadata.model.Dependency;
import org.apache.archiva.metadata.model.FacetedMetadata;
import org.apache.archiva.metadata.model.IssueManagement;
import org.apache.archiva.metadata.model.License;
@@ -108,6 +109,8 @@ public class CassandraMetadataRepository
private final ColumnFamilyTemplate<String, String> licenseTemplate;
+ private final ColumnFamilyTemplate<String, String> dependencyTemplate;
+
public CassandraMetadataRepository( Map<String, MetadataFacetFactory> metadataFacetFactories,
ArchivaConfiguration configuration,
CassandraArchivaManager cassandraArchivaManager )
@@ -154,6 +157,13 @@ public class CassandraMetadataRepository
//
StringSerializer.get(), //
StringSerializer.get() );
+
+ this.dependencyTemplate =
+ new ThriftColumnFamilyTemplate<String, String>( cassandraArchivaManager.getKeyspace(), //
+ cassandraArchivaManager.getDependencyFamilyName(),
+ //
+ StringSerializer.get(), //
+ StringSerializer.get() );
}
@@ -902,13 +912,12 @@ public class CassandraMetadataRepository
}
}
- if ( versionMetadata.getMailingLists() != null )
- {
- recordMailingList( key, versionMetadata.getMailingLists() );
- }
+ recordMailingList( key, versionMetadata.getMailingLists() );
recordLicenses( key, versionMetadata.getLicenses() );
+ recordDependencies( key, versionMetadata.getDependencies() );
+
MutationResult mutationResult = mutator.execute();
}
else
@@ -973,6 +982,9 @@ public class CassandraMetadataRepository
removeLicenses( key );
recordLicenses( key, versionMetadata.getLicenses() );
+ removeDependencies( key );
+ recordDependencies( key, versionMetadata.getDependencies() );
+
projectVersionMetadataModelTemplate.update( updater );
}
@@ -1047,7 +1059,7 @@ public class CassandraMetadataRepository
}
projectVersionMetadata.setMailingLists( getMailingLists( key ) );
projectVersionMetadata.setLicenses( getLicenses( key ) );
- // FIXME complete collections !!
+ projectVersionMetadata.setDependencies( getDependencies( key ) );
// facets
StringSerializer ss = StringSerializer.get();
@@ -1204,9 +1216,9 @@ public class CassandraMetadataRepository
addInsertion( licenseMutator, keyLicense, cfLicense, "projectVersionMetadataModel.key",
projectVersionMetadataKey );
- addInsertion( licenseMutator, keyLicense, cfLicense, "license.name", license.getName() );
+ addInsertion( licenseMutator, keyLicense, cfLicense, "name", license.getName() );
- addInsertion( licenseMutator, keyLicense, cfLicense, "license.url", license.getUrl() );
+ addInsertion( licenseMutator, keyLicense, cfLicense, "url", license.getUrl() );
}
licenseMutator.execute();
@@ -1245,13 +1257,108 @@ public class CassandraMetadataRepository
{
ColumnFamilyResult<String, String> columnFamilyResult = this.licenseTemplate.queryColumns( row.getKey() );
- licenses.add( new License( columnFamilyResult.getString( "license.name" ),
- columnFamilyResult.getString( "license.url" ) ) );
+ licenses.add(
+ new License( columnFamilyResult.getString( "name" ), columnFamilyResult.getString( "url" ) ) );
}
return licenses;
}
+
+ protected void recordDependencies( String projectVersionMetadataKey, List<Dependency> dependencies )
+ {
+
+ if ( dependencies == null || dependencies.isEmpty() )
+ {
+ return;
+ }
+ Mutator<String> dependencyMutator = this.dependencyTemplate.createMutator();
+
+ for ( Dependency dependency : dependencies )
+ {
+ // we don't care about the key as the real used one with the projectVersionMetadata
+ String keyDependency = UUID.randomUUID().toString();
+ String cfDependency = cassandraArchivaManager.getDependencyFamilyName();
+
+ addInsertion( dependencyMutator, keyDependency, cfDependency, "projectVersionMetadataModel.key",
+ projectVersionMetadataKey );
+
+ addInsertion( dependencyMutator, keyDependency, cfDependency, "classifier", dependency.getClassifier() );
+
+ addInsertion( dependencyMutator, keyDependency, cfDependency, "optional",
+ Boolean.toString( dependency.isOptional() ) );
+
+ addInsertion( dependencyMutator, keyDependency, cfDependency, "scope", dependency.getScope() );
+
+ addInsertion( dependencyMutator, keyDependency, cfDependency, "systemPath", dependency.getSystemPath() );
+
+ addInsertion( dependencyMutator, keyDependency, cfDependency, "type", dependency.getType() );
+
+ addInsertion( dependencyMutator, keyDependency, cfDependency, "artifactId", dependency.getArtifactId() );
+
+ addInsertion( dependencyMutator, keyDependency, cfDependency, "groupId", dependency.getGroupId() );
+
+ addInsertion( dependencyMutator, keyDependency, cfDependency, "version", dependency.getVersion() );
+
+ } dependencyMutator.execute();
+ }
+
+ protected void removeDependencies( String projectVersionMetadataKey )
+ {
+ StringSerializer ss = StringSerializer.get();
+ QueryResult<OrderedRows<String, String, String>> result =
+ HFactory.createRangeSlicesQuery( cassandraArchivaManager.getKeyspace(), ss, ss, ss ) //
+ .setColumnFamily( cassandraArchivaManager.getDependencyFamilyName() ) //
+ .setColumnNames( "groupId" ) //
+ .setRowCount( Integer.MAX_VALUE ) //
+ .addEqualsExpression( "projectVersionMetadataModel.key", projectVersionMetadataKey ) //
+ .execute();
+ for ( Row<String, String, String> row : result.get() )
+ {
+ this.dependencyTemplate.deleteRow( row.getKey() );
+ }
+ }
+
+ protected List<Dependency> getDependencies( String projectVersionMetadataKey )
+ {
+ List<Dependency> dependencies = new ArrayList<Dependency>();
+
+ StringSerializer ss = StringSerializer.get();
+ QueryResult<OrderedRows<String, String, String>> result =
+ HFactory.createRangeSlicesQuery( cassandraArchivaManager.getKeyspace(), ss, ss, ss ) //
+ .setColumnFamily( cassandraArchivaManager.getDependencyFamilyName() ) //
+ .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.dependencyTemplate.queryColumns( row.getKey() );
+
+ Dependency dependency = new Dependency();
+ dependency.setClassifier( columnFamilyResult.getString( "classifier" ) );
+
+ dependency.setOptional( Boolean.parseBoolean( columnFamilyResult.getString( "optional" ) ) );
+
+ dependency.setScope( columnFamilyResult.getString( "scope" ) );
+
+ dependency.setSystemPath( columnFamilyResult.getString( "systemPath" ) );
+
+ dependency.setType( columnFamilyResult.getString( "type" ) );
+
+ dependency.setArtifactId( columnFamilyResult.getString( "artifactId" ) );
+
+ dependency.setGroupId( columnFamilyResult.getString( "groupId" ) );
+
+ dependency.setVersion( columnFamilyResult.getString( "version" ) );
+
+ dependencies.add( dependency );
+ }
+
+ return dependencies;
+ }
+
@Override
public void updateArtifact( String repositoryId, String namespaceId, String projectId, String projectVersion,
ArtifactMetadata artifactMeta )
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 eb9399adb..978ffdb9b 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
@@ -85,6 +85,8 @@ public class DefaultCassandraArchivaManager
private String licenseFamilyName = "license";
+ private String dependencyFamilyName = "dependency";
+
@PostConstruct
public void initialize()
@@ -401,6 +403,25 @@ public class DefaultCassandraArchivaManager
}
+ // dependency table
+ {
+ final ColumnFamilyDefinition dependencyCf =
+ HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), //
+ getDependencyFamilyName(), //
+ ComparatorType.UTF8TYPE );
+ cfds.add( dependencyCf );
+
+ // 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() );
+ dependencyCf.addColumnDefinition( projectVersionMetadataIdColumn );
+
+ }
+
// TODO take care of update new table!!
{ // ensure keyspace exists, here if the keyspace doesn't exist we suppose nothing exist
if ( cluster.describeKeyspace( keyspaceName ) == null )
@@ -483,4 +504,9 @@ public class DefaultCassandraArchivaManager
{
return licenseFamilyName;
}
+
+ public String getDependencyFamilyName()
+ {
+ return dependencyFamilyName;
+ }
}
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 2cd6a51fb..e43f5afce 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
@@ -100,6 +100,9 @@ public class CassandraMetadataRepositoryTest
cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
cassandraArchivaManager.getLicenseFamilyName() );
+ cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(),
+ cassandraArchivaManager.getDependencyFamilyName() );
+
}
}