diff options
author | Martin Stockhammer <martin_s@apache.org> | 2020-06-28 10:00:07 +0200 |
---|---|---|
committer | Martin Stockhammer <martin_s@apache.org> | 2020-06-28 10:00:07 +0200 |
commit | 5d058d7f4d93254291e456d2f8cb722159d053aa (patch) | |
tree | 1c186ed76ee3159d063b03561bd5727ab98da402 /archiva-modules/plugins/metadata-store-cassandra | |
parent | 5a35e01601336a462858f4a2af98f5b55de7a8d6 (diff) | |
download | archiva-5d058d7f4d93254291e456d2f8cb722159d053aa.tar.gz archiva-5d058d7f4d93254291e456d2f8cb722159d053aa.zip |
Moving metadata store providers to metadata folder
Diffstat (limited to 'archiva-modules/plugins/metadata-store-cassandra')
20 files changed, 0 insertions, 5520 deletions
diff --git a/archiva-modules/plugins/metadata-store-cassandra/pom.xml b/archiva-modules/plugins/metadata-store-cassandra/pom.xml deleted file mode 100644 index 07e066b26..000000000 --- a/archiva-modules/plugins/metadata-store-cassandra/pom.xml +++ /dev/null @@ -1,323 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one - ~ or more contributor license agreements. See the NOTICE file - ~ distributed with this work for additional information - ~ regarding copyright ownership. The ASF licenses this file - ~ to you under the Apache License, Version 2.0 (the - ~ "License"); you may not use this file except in compliance - ~ with the License. You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, - ~ software distributed under the License is distributed on an - ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - ~ KIND, either express or implied. See the License for the - ~ specific language governing permissions and limitations - ~ under the License. - --> - -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <artifactId>plugins</artifactId> - <groupId>org.apache.archiva</groupId> - <version>3.0.0-SNAPSHOT</version> - </parent> - <artifactId>metadata-store-cassandra</artifactId> - <name>Archiva Core Plugins :: Cassandra Storage for Metadata</name> - - <properties> - <site.staging.base>${project.parent.parent.basedir}</site.staging.base> - <cassandraVersion>3.11.2</cassandraVersion> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-lang3</artifactId> - </dependency> - <dependency> - <groupId>org.apache.archiva</groupId> - <artifactId>metadata-repository-api</artifactId> - </dependency> - <dependency> - <groupId>org.apache.archiva</groupId> - <artifactId>metadata-repository-api</artifactId> - <classifier>tests</classifier> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.archiva</groupId> - <artifactId>archiva-common</artifactId> - </dependency> - <dependency> - <groupId>org.apache.archiva</groupId> - <artifactId>archiva-configuration</artifactId> - </dependency> - <dependency> - <groupId>org.apache.archiva</groupId> - <artifactId>archiva-policies</artifactId> - </dependency> - <dependency> - <groupId>org.apache.archiva</groupId> - <artifactId>archiva-xml-tools</artifactId> - </dependency> - <dependency> - <groupId>org.apache.archiva</groupId> - <artifactId>archiva-repository-api</artifactId> - </dependency> - <dependency> - <groupId>org.apache.archiva</groupId> - <artifactId>archiva-checksum</artifactId> - </dependency> - <dependency> - <groupId>org.apache.archiva</groupId> - <artifactId>metadata-model</artifactId> - </dependency> - - - <dependency> - <groupId>javax.annotation</groupId> - <artifactId>javax.annotation-api</artifactId> - </dependency> - <dependency> - <groupId>javax.inject</groupId> - <artifactId>javax.inject</artifactId> - </dependency> - - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-beans</artifactId> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-context</artifactId> - </dependency> - - <dependency> - <groupId>org.modelmapper</groupId> - <artifactId>modelmapper</artifactId> - </dependency> - - <dependency> - <groupId>org.apache.cassandra</groupId> - <artifactId>cassandra-all</artifactId> - <version>${cassandraVersion}</version> - <exclusions> - <exclusion> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - </exclusion> - <exclusion> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - </exclusion> - <exclusion> - <groupId>org.slf4j</groupId> - <artifactId>jcl-over-slf4j</artifactId> - </exclusion> - <exclusion> - <groupId>ch.qos.logback</groupId> - <artifactId>logback-core</artifactId> - </exclusion> - <exclusion> - <groupId>org.mortbay.jetty</groupId> - <artifactId>jetty</artifactId> - </exclusion> - <exclusion> - <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> - </exclusion> - <exclusion> - <groupId>org.slf4j</groupId> - <artifactId>log4j-over-slf4j</artifactId> - </exclusion> - <exclusion> - <groupId>ch.qos.logback</groupId> - <artifactId>logback-classic</artifactId> - </exclusion> - <exclusion> - <groupId>org.jboss.logging</groupId> - <artifactId>jboss-logging</artifactId> - </exclusion> - </exclusions> - </dependency> - - <dependency> - <groupId>org.hectorclient</groupId> - <artifactId>hector-core</artifactId> - <version>1.1-4</version> - <exclusions> - <exclusion> - <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> - </exclusion> - <exclusion> - <groupId>com.ecyrd.speed4j</groupId> - <artifactId>speed4j</artifactId> - </exclusion> - <exclusion> - <groupId>com.yammer.metrics</groupId> - <artifactId>metrics-core</artifactId> - </exclusion> - <exclusion> - <groupId>org.slf4j</groupId> - <artifactId>log4j-over-slf4j</artifactId> - </exclusion> - </exclusions> - </dependency> - - <dependency> - <groupId>org.apache.cassandra</groupId> - <artifactId>cassandra-thrift</artifactId> - <version>3.11.2</version> - <exclusions> - <exclusion> - <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> - </exclusion> - </exclusions> - </dependency> - - <!-- Is a dependency of cassandra -> hibernate-validator and replaced by new version --> - <dependency> - <groupId>org.jboss.logging</groupId> - <artifactId>jboss-logging</artifactId> - </dependency> - - - <!-- TEST Scope --> - <dependency> - <groupId>org.apache.archiva</groupId> - <artifactId>archiva-test-utils</artifactId> - <version>${project.version}</version> - <scope>test</scope> - <exclusions> - <exclusion> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-simple</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.easymock</groupId> - <artifactId>easymock</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-test</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.archiva</groupId> - <artifactId>generic-metadata-support</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.assertj</groupId> - <artifactId>assertj-core</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-slf4j-impl</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-1.2-api</artifactId> - <version>${log4j.version}</version> - <scope>test</scope> - </dependency> - - - </dependencies> - <build> - <testResources> - <testResource> - <directory>src/test/filtered-resources</directory> - <filtering>true</filtering> - </testResource> - </testResources> - <plugins> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>build-helper-maven-plugin</artifactId> - <executions> - <execution> - <id>reserve-ports</id> - <phase>process-test-resources</phase> - <goals> - <goal>reserve-network-port</goal> - </goals> - <configuration> - <portNames> - <portName>cassandraPort</portName> - <portName>cassandra.storagePort</portName> - <portName>cassandra.stopPort</portName> - <portName>cassandra.jmxPort</portName> - </portNames> - </configuration> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>cassandra-maven-plugin</artifactId> - <version>2.0.0-1</version> - <executions> - <execution> - <id>start-cassandra</id> - <phase>process-test-classes</phase> - <goals> - <goal>start</goal> - </goals> - <configuration> - <rpcPort>${cassandraPort}</rpcPort> - <storagePort>${cassandra.storagePort}</storagePort> - <stopPort>${cassandra.stopPort}</stopPort> - <jmxPort>${cassandra.jmxPort}</jmxPort> - <addMainClasspath>false</addMainClasspath> - <addTestClasspath>false</addTestClasspath> - <startWaitSeconds>500</startWaitSeconds> - </configuration> - </execution> - <execution> - <id>stop-cassandra</id> - <phase>test</phase> - <goals> - <goal>stop</goal> - </goals> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-simple</artifactId> - <version>${slf4j.version}</version> - </dependency> - </dependencies> - </plugin> - </plugins> - <pluginManagement> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <systemPropertyVariables> - <cassandra.port>${cassandraPort}</cassandra.port> - <archiva.repositorySessionFactory.id>cassandra</archiva.repositorySessionFactory.id> - <appserver.base>${project.build.directory}/appserver-base</appserver.base> - </systemPropertyVariables> - <trimStackTrace>false</trimStackTrace> - </configuration> - </plugin> - </plugins> - </pluginManagement> - </build> - -</project> 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 deleted file mode 100644 index 41ac95a24..000000000 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraArchivaManager.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.apache.archiva.metadata.repository.cassandra; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import me.prettyprint.hector.api.Cluster; -import me.prettyprint.hector.api.Keyspace; - -/** - * @author Olivier Lamy - * @since 2.0.0 - */ -public interface CassandraArchivaManager -{ - void start(); - - void shutdown(); - - boolean started(); - - Keyspace getKeyspace(); - - Cluster getCluster(); - - String getRepositoryFamilyName(); - - String getNamespaceFamilyName(); - - String getProjectFamilyName(); - - String getProjectVersionMetadataFamilyName(); - - String getArtifactMetadataFamilyName(); - - String getMetadataFacetFamilyName(); - - String getMailingListFamilyName(); - - String getLicenseFamilyName(); - - String getDependencyFamilyName(); - - String getChecksumFamilyName(); - -} 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 deleted file mode 100644 index bc8d7da66..000000000 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java +++ /dev/null @@ -1,2506 +0,0 @@ -package org.apache.archiva.metadata.repository.cassandra; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import me.prettyprint.cassandra.serializers.LongSerializer; -import me.prettyprint.cassandra.serializers.StringSerializer; -import me.prettyprint.cassandra.service.template.ColumnFamilyResult; -import me.prettyprint.cassandra.service.template.ColumnFamilyTemplate; -import me.prettyprint.cassandra.service.template.ColumnFamilyUpdater; -import me.prettyprint.cassandra.service.template.ThriftColumnFamilyTemplate; -import me.prettyprint.hector.api.Keyspace; -import me.prettyprint.hector.api.beans.ColumnSlice; -import me.prettyprint.hector.api.beans.OrderedRows; -import me.prettyprint.hector.api.beans.Row; -import me.prettyprint.hector.api.exceptions.HInvalidRequestException; -import me.prettyprint.hector.api.factory.HFactory; -import me.prettyprint.hector.api.mutation.MutationResult; -import me.prettyprint.hector.api.mutation.Mutator; -import me.prettyprint.hector.api.query.QueryResult; -import me.prettyprint.hector.api.query.RangeSlicesQuery; -import org.apache.archiva.checksum.ChecksumAlgorithm; -import org.apache.archiva.metadata.QueryParameter; -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; -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; -import org.apache.archiva.metadata.model.ProjectMetadata; -import org.apache.archiva.metadata.model.ProjectVersionMetadata; -import org.apache.archiva.metadata.model.ProjectVersionReference; -import org.apache.archiva.metadata.model.Scm; -import org.apache.archiva.metadata.repository.AbstractMetadataRepository; -import org.apache.archiva.metadata.repository.MetadataRepository; -import org.apache.archiva.metadata.repository.MetadataRepositoryException; -import org.apache.archiva.metadata.repository.MetadataResolutionException; -import org.apache.archiva.metadata.repository.MetadataService; -import org.apache.archiva.metadata.repository.RepositorySession; -import org.apache.archiva.metadata.repository.cassandra.model.ArtifactMetadataModel; -import org.apache.archiva.metadata.repository.cassandra.model.MetadataFacetModel; -import org.apache.archiva.metadata.repository.cassandra.model.Namespace; -import org.apache.archiva.metadata.repository.cassandra.model.Project; -import org.apache.archiva.metadata.repository.cassandra.model.ProjectVersionMetadataModel; -import org.apache.archiva.metadata.repository.cassandra.model.Repository; -import org.apache.commons.lang3.StringUtils; -import org.modelmapper.ModelMapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.time.Instant; -import java.time.ZonedDateTime; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.Spliterator; -import java.util.UUID; -import java.util.function.BiFunction; -import java.util.function.Consumer; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; - -import static org.apache.archiva.metadata.model.ModelInfo.STORAGE_TZ; -import static org.apache.archiva.metadata.repository.cassandra.CassandraUtils.*; -import static org.apache.archiva.metadata.repository.cassandra.model.ColumnNames.*; - -/** - * @author Olivier Lamy - * @since 2.0.0 - */ -public class CassandraMetadataRepository - extends AbstractMetadataRepository implements MetadataRepository -{ - - private static final String ARTIFACT_METADATA_MODEL_KEY = "artifactMetadataModel.key"; - private Logger logger = LoggerFactory.getLogger( getClass() ); - - private final CassandraArchivaManager cassandraArchivaManager; - - private final ColumnFamilyTemplate<String, String> projectVersionMetadataTemplate; - - private final ColumnFamilyTemplate<String, String> projectTemplate; - - private final ColumnFamilyTemplate<String, String> artifactMetadataTemplate; - - private final ColumnFamilyTemplate<String, String> metadataFacetTemplate; - - private final ColumnFamilyTemplate<String, String> mailingListTemplate; - - private final ColumnFamilyTemplate<String, String> licenseTemplate; - - private final ColumnFamilyTemplate<String, String> dependencyTemplate; - - private final ColumnFamilyTemplate<String, String> checksumTemplate; - - private final Keyspace keyspace; - - private final StringSerializer ss = StringSerializer.get(); - - public CassandraMetadataRepository( MetadataService metadataService, - CassandraArchivaManager cassandraArchivaManager ) - { - super( metadataService ); - this.cassandraArchivaManager = cassandraArchivaManager; - this.keyspace = cassandraArchivaManager.getKeyspace(); - - this.projectVersionMetadataTemplate = - new ThriftColumnFamilyTemplate<>( cassandraArchivaManager.getKeyspace(), // - cassandraArchivaManager.getProjectVersionMetadataFamilyName(), // - StringSerializer.get(), // - StringSerializer.get() ); - - this.projectTemplate = new ThriftColumnFamilyTemplate<>( cassandraArchivaManager.getKeyspace(), // - cassandraArchivaManager.getProjectFamilyName(), // - // - StringSerializer.get(), // - StringSerializer.get() ); - - this.artifactMetadataTemplate = new ThriftColumnFamilyTemplate<>( cassandraArchivaManager.getKeyspace(), // - cassandraArchivaManager.getArtifactMetadataFamilyName(), - StringSerializer.get(), // - StringSerializer.get() ); - - this.metadataFacetTemplate = new ThriftColumnFamilyTemplate<>( cassandraArchivaManager.getKeyspace(), // - cassandraArchivaManager.getMetadataFacetFamilyName(), - // - StringSerializer.get(), // - StringSerializer.get() ); - - this.mailingListTemplate = new ThriftColumnFamilyTemplate<>( cassandraArchivaManager.getKeyspace(), // - cassandraArchivaManager.getMailingListFamilyName(), - // - StringSerializer.get(), // - StringSerializer.get() ); - - this.licenseTemplate = new ThriftColumnFamilyTemplate<>( cassandraArchivaManager.getKeyspace(), // - cassandraArchivaManager.getLicenseFamilyName(), - // - StringSerializer.get(), // - StringSerializer.get() ); - - this.dependencyTemplate = new ThriftColumnFamilyTemplate<>( cassandraArchivaManager.getKeyspace(), // - cassandraArchivaManager.getDependencyFamilyName(), - // - StringSerializer.get(), // - StringSerializer.get() ); - - this.checksumTemplate = new ThriftColumnFamilyTemplate<>( cassandraArchivaManager.getKeyspace(), // - cassandraArchivaManager.getChecksumFamilyName(), - // - StringSerializer.get(), // - StringSerializer.get() ); - } - - - /** - * if the repository doesn't exist it will be created - * - * @param repositoryId - * @return - */ - public Repository getOrCreateRepository( String repositoryId ) - throws MetadataRepositoryException - { - String cf = cassandraArchivaManager.getRepositoryFamilyName(); - - QueryResult<OrderedRows<String, String, String>> result = HFactory // - .createRangeSlicesQuery( keyspace, StringSerializer.get(), StringSerializer.get(), - StringSerializer.get() ) // - .setColumnFamily( cf ) // - .setColumnNames( REPOSITORY_NAME.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId ) // - .execute(); - - if ( result.get().getCount() < 1 ) - { - // we need to create the repository - Repository repository = new Repository( repositoryId ); - - try - { - MutationResult mutationResult = HFactory.createMutator( keyspace, StringSerializer.get() ) // - .addInsertion( repositoryId, cf, - CassandraUtils.column( REPOSITORY_NAME.toString(), repository.getName() ) ) // - .execute(); - logger.debug( "time to insert repository: {}", mutationResult.getExecutionTimeMicro() ); - return repository; - } - catch ( HInvalidRequestException e ) - { - logger.error( e.getMessage(), e ); - throw new MetadataRepositoryException( e.getMessage(), e ); - } - - } - - return new Repository( - result.get().getList().get( 0 ).getColumnSlice().getColumnByName( REPOSITORY_NAME.toString() ).getValue() ); - } - - - protected Repository getRepository( String repositoryId ) - throws MetadataRepositoryException - { - - QueryResult<OrderedRows<String, String, String>> result = HFactory // - .createRangeSlicesQuery( keyspace, StringSerializer.get(), StringSerializer.get(), - StringSerializer.get() ) // - .setColumnFamily( cassandraArchivaManager.getRepositoryFamilyName() ) // - .setColumnNames( REPOSITORY_NAME.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId ) // - .execute(); - return ( result.get().getCount() > 0 ) ? new Repository( repositoryId ) : null; - } - - @Override - public void updateNamespace( RepositorySession session, String repositoryId, String namespaceId ) - throws MetadataRepositoryException - { - updateOrAddNamespace( repositoryId, namespaceId ); - } - - private Namespace updateOrAddNamespace( String repositoryId, String namespaceId ) - throws MetadataRepositoryException - { - try - { - Repository repository = getOrCreateRepository( repositoryId ); - - String key = - new Namespace.KeyBuilder().withNamespace( namespaceId ).withRepositoryId( repositoryId ).build(); - - Namespace namespace = getNamespace( repositoryId, namespaceId ); - if ( namespace == null ) - { - String cf = cassandraArchivaManager.getNamespaceFamilyName(); - namespace = new Namespace( namespaceId, repository ); - HFactory.createMutator( keyspace, StringSerializer.get() ) - // values - .addInsertion( key, cf, CassandraUtils.column( NAME.toString(), namespace.getName() ) ) // - .addInsertion( key, cf, CassandraUtils.column( REPOSITORY_NAME.toString(), repository.getName() ) ) // - .execute(); - } - - return namespace; - } - catch ( HInvalidRequestException e ) - { - logger.error( e.getMessage(), e ); - throw new MetadataRepositoryException( e.getMessage(), e ); - } - } - - protected Namespace getNamespace( String repositoryId, String namespaceId ) - { - - QueryResult<OrderedRows<String, String, String>> result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getNamespaceFamilyName() ) // - .setColumnNames( REPOSITORY_NAME.toString(), NAME.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId ) // - .addEqualsExpression( NAME.toString(), namespaceId ) // - .execute(); - if ( result.get().getCount() > 0 ) - { - ColumnSlice<String, String> columnSlice = result.get().getList().get( 0 ).getColumnSlice(); - return new Namespace( getStringValue( columnSlice, NAME.toString() ), // - new Repository( getStringValue( columnSlice, REPOSITORY_NAME.toString() ) ) ); - - } - return null; - } - - - @Override - public void removeNamespace( RepositorySession session, String repositoryId, String namespaceId ) - throws MetadataRepositoryException - { - - try - { - String key = new Namespace.KeyBuilder() // - .withNamespace( namespaceId ) // - .withRepositoryId( repositoryId ) // - .build(); - - HFactory.createMutator( cassandraArchivaManager.getKeyspace(), new StringSerializer() ) // - .addDeletion( key, cassandraArchivaManager.getNamespaceFamilyName() ) // - .execute(); - - QueryResult<OrderedRows<String, String, String>> result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getProjectFamilyName() ) // - .setColumnNames( REPOSITORY_NAME.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId ) // - .addEqualsExpression( NAMESPACE_ID.toString(), namespaceId ) // - .execute(); - - for ( Row<String, String, String> row : result.get() ) - { - this.projectTemplate.deleteRow( row.getKey() ); - } - - result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getProjectVersionMetadataFamilyName() ) // - .setColumnNames( REPOSITORY_NAME.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId ) // - .addEqualsExpression( NAMESPACE_ID.toString(), namespaceId ) // - .execute(); - - for ( Row<String, String, String> row : result.get() ) - { - this.projectVersionMetadataTemplate.deleteRow( row.getKey() ); - removeMailingList( row.getKey() ); - } - - result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getArtifactMetadataFamilyName() ) // - .setColumnNames( REPOSITORY_NAME.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId ) // - .addEqualsExpression( NAMESPACE_ID.toString(), namespaceId ) // - .execute(); - - for ( Row<String, String, String> row : result.get() ) - { - this.artifactMetadataTemplate.deleteRow( row.getKey() ); - } - - result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getMetadataFacetFamilyName() ) // - .setColumnNames( REPOSITORY_NAME.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId ) // - .addEqualsExpression( NAMESPACE_ID.toString(), namespaceId ) // - .execute(); - - for ( Row<String, String, String> row : result.get() ) - { - this.metadataFacetTemplate.deleteRow( row.getKey() ); - } - - } - catch ( HInvalidRequestException e ) - { - logger.error( e.getMessage(), e ); - throw new MetadataRepositoryException( e.getMessage(), e ); - } - } - - - @Override - public void removeRepository( RepositorySession session, final String repositoryId ) - throws MetadataRepositoryException - { - - // TODO use cql queries to delete all - List<String> namespacesKey = new ArrayList<>(); - - QueryResult<OrderedRows<String, String, String>> result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getNamespaceFamilyName() ) // - .setColumnNames( REPOSITORY_NAME.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId ) // - .execute(); - - for ( Row<String, String, String> row : result.get().getList() ) - { - namespacesKey.add( row.getKey() ); - } - - HFactory.createMutator( cassandraArchivaManager.getKeyspace(), ss ) // - .addDeletion( namespacesKey, cassandraArchivaManager.getNamespaceFamilyName() ) // - .execute(); - - //delete repositoryId - HFactory.createMutator( cassandraArchivaManager.getKeyspace(), ss ) // - .addDeletion( repositoryId, cassandraArchivaManager.getRepositoryFamilyName() ) // - .execute(); - - result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getProjectFamilyName() ) // - .setColumnNames( REPOSITORY_NAME.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId ) // - .execute(); - - for ( Row<String, String, String> row : result.get() ) - { - this.projectTemplate.deleteRow( row.getKey() ); - } - - result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getProjectVersionMetadataFamilyName() ) // - .setColumnNames( REPOSITORY_NAME.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId ) // - .execute(); - - for ( Row<String, String, String> row : result.get() ) - { - this.projectVersionMetadataTemplate.deleteRow( row.getKey() ); - removeMailingList( row.getKey() ); - } - - result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getArtifactMetadataFamilyName() ) // - .setColumnNames( REPOSITORY_NAME.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId ) // - .execute(); - - for ( Row<String, String, String> row : result.get() ) - { - this.artifactMetadataTemplate.deleteRow( row.getKey() ); - } - - result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getMetadataFacetFamilyName() ) // - .setColumnNames( REPOSITORY_NAME.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId ) // - .execute(); - - for ( Row<String, String, String> row : result.get() ) - { - this.metadataFacetTemplate.deleteRow( row.getKey() ); - } - - - } - - // FIXME this one need peformance improvement maybe a cache? - @Override - public List<String> getRootNamespaces( RepositorySession session, final String repoId ) - throws MetadataResolutionException - { - - QueryResult<OrderedRows<String, String, String>> result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getNamespaceFamilyName() ) // - .setColumnNames( NAME.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repoId ) // - .execute(); - - Set<String> namespaces = new HashSet<>( result.get( ).getCount( ) ); - - for ( Row<String, String, String> row : result.get() ) - { - namespaces.add( StringUtils.substringBefore( getStringValue( row.getColumnSlice(), NAME.toString() ), "." ) ); - } - - return new ArrayList<>( namespaces ); - } - - // FIXME this one need peformance improvement maybe a cache? - @Override - public List<String> getChildNamespaces( RepositorySession session, final String repoId, final String namespaceId ) - throws MetadataResolutionException - { - - QueryResult<OrderedRows<String, String, String>> result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getNamespaceFamilyName() ) // - .setColumnNames( NAME.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repoId ) // - .execute(); - - List<String> namespaces = new ArrayList<>( result.get().getCount() ); - - for ( Row<String, String, String> row : result.get() ) - { - String currentNamespace = getStringValue( row.getColumnSlice(), NAME.toString() ); - if ( StringUtils.startsWith( currentNamespace, namespaceId ) // - && ( StringUtils.length( currentNamespace ) > StringUtils.length( namespaceId ) ) ) - { - // store after namespaceId '.' but before next '.' - // call org namespace org.apache.maven.shared -> stored apache - - String calledNamespace = StringUtils.endsWith( namespaceId, "." ) ? namespaceId : namespaceId + "."; - String storedNamespace = StringUtils.substringAfter( currentNamespace, calledNamespace ); - - storedNamespace = StringUtils.substringBefore( storedNamespace, "." ); - - namespaces.add( storedNamespace ); - } - } - - return namespaces; - - } - - // only use for testing purpose - protected List<String> getNamespaces( final String repoId ) - throws MetadataResolutionException - { - - QueryResult<OrderedRows<String, String, String>> result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getNamespaceFamilyName() ) // - .setColumnNames( NAME.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repoId ) // - .execute(); - - List<String> namespaces = new ArrayList<>( result.get().getCount() ); - - for ( Row<String, String, String> row : result.get() ) - { - namespaces.add( getStringValue( row.getColumnSlice(), NAME.toString() ) ); - } - - return namespaces; - } - - - @Override - public void updateProject( RepositorySession session, String repositoryId, ProjectMetadata projectMetadata ) - throws MetadataRepositoryException - { - - QueryResult<OrderedRows<String, String, String>> result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getProjectFamilyName() ) // - .setColumnNames( PROJECT_ID.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId ) // - .addEqualsExpression( NAMESPACE_ID.toString(), projectMetadata.getNamespace() ) // - .addEqualsExpression( PROJECT_ID.toString(), projectMetadata.getId() ) // - .execute(); - - // project exists ? if yes return nothing to update here - if ( result.get( ).getCount( ) <= 0 ) - { - Namespace namespace = updateOrAddNamespace( repositoryId, projectMetadata.getNamespace() ); - - String key = - new Project.KeyBuilder().withProjectId( projectMetadata.getId() ).withNamespace( namespace ).build(); - - String cf = cassandraArchivaManager.getProjectFamilyName(); - projectTemplate.createMutator() - // values - .addInsertion( key, cf, CassandraUtils.column( PROJECT_ID.toString(), projectMetadata.getId() ) ) // - .addInsertion( key, cf, CassandraUtils.column( REPOSITORY_NAME.toString(), repositoryId ) ) // - .addInsertion( key, cf, CassandraUtils.column( NAMESPACE_ID.toString(), projectMetadata.getNamespace() ) )// - .execute(); - } - } - - @Override - public List<String> getProjects( RepositorySession session, final String repoId, final String namespace ) - throws MetadataResolutionException - { - - QueryResult<OrderedRows<String, String, String>> result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getProjectFamilyName() ) // - .setColumnNames( PROJECT_ID.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repoId ) // - .addEqualsExpression( NAMESPACE_ID.toString(), namespace ) // - .execute(); - - final Set<String> projects = new HashSet<>( result.get( ).getCount( ) ); - - for ( Row<String, String, String> row : result.get() ) - { - projects.add( getStringValue( row.getColumnSlice(), PROJECT_ID.toString() ) ); - } - - return new ArrayList<>( projects ); - } - - @Override - public void removeProject( RepositorySession session, final String repositoryId, final String namespaceId, final String projectId ) - throws MetadataRepositoryException - { - - String key = new Project.KeyBuilder() // - .withProjectId( projectId ) // - .withNamespace( new Namespace( namespaceId, new Repository( repositoryId ) ) ) // - .build(); - - this.projectTemplate.deleteRow( key ); - - QueryResult<OrderedRows<String, String, String>> result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getProjectVersionMetadataFamilyName() ) // - .setColumnNames( ID.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId ) // - .addEqualsExpression( NAMESPACE_ID.toString(), namespaceId ) // - .addEqualsExpression( PROJECT_ID.toString(), projectId ) // - .execute(); - - for ( Row<String, String, String> row : result.get() ) - { - this.projectVersionMetadataTemplate.deleteRow( row.getKey() ); - removeMailingList( row.getKey() ); - } - - result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getArtifactMetadataFamilyName() ) // - .setColumnNames( PROJECT_ID.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId ) // - .addEqualsExpression( NAMESPACE_ID.toString(), namespaceId ) // - .addEqualsExpression( PROJECT_ID.toString(), projectId ) // - .execute(); - - for ( Row<String, String, String> row : result.get() ) - { - this.artifactMetadataTemplate.deleteRow( row.getKey() ); - } - } - - @Override - public List<String> getProjectVersions( RepositorySession session, final String repoId, final String namespace, final String projectId ) - throws MetadataResolutionException - { - - QueryResult<OrderedRows<String, String, String>> result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getProjectVersionMetadataFamilyName() ) // - .setColumnNames( PROJECT_VERSION.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repoId ) // - .addEqualsExpression( NAMESPACE_ID.toString(), namespace ) // - .addEqualsExpression( PROJECT_ID.toString(), projectId ) // - .execute(); - - int count = result.get().getCount(); - - if ( count < 1 ) - { - return Collections.emptyList(); - } - - Set<String> versions = new HashSet<>( count ); - - for ( Row<String, String, String> orderedRows : result.get() ) - { - versions.add( getStringValue( orderedRows.getColumnSlice(), PROJECT_VERSION.toString() ) ); - } - - return new ArrayList<>( versions ); - - } - - @Override - public ProjectMetadata getProject( RepositorySession session, final String repoId, final String namespace, final String id ) - throws MetadataResolutionException - { - - QueryResult<OrderedRows<String, String, String>> result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getProjectFamilyName() ) // - .setColumnNames( PROJECT_ID.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repoId ) // - .addEqualsExpression( NAMESPACE_ID.toString(), namespace ) // - .addEqualsExpression( PROJECT_ID.toString(), id ) // - .execute(); - - int count = result.get().getCount(); - - if ( count < 1 ) - { - return null; - } - - ProjectMetadata projectMetadata = new ProjectMetadata(); - projectMetadata.setId( id ); - projectMetadata.setNamespace( namespace ); - - logger.debug( "getProject repoId: {}, namespace: {}, projectId: {} -> {}", repoId, namespace, id, - projectMetadata ); - - return projectMetadata; - } - - protected ProjectVersionMetadataModel mapProjectVersionMetadataModel( ColumnSlice<String, String> columnSlice ) - { - ProjectVersionMetadataModel projectVersionMetadataModel = new ProjectVersionMetadataModel(); - projectVersionMetadataModel.setId( getStringValue( columnSlice, ID.toString() ) ); - projectVersionMetadataModel.setDescription( getStringValue( columnSlice, DESCRIPTION.toString() ) ); - projectVersionMetadataModel.setName( getStringValue( columnSlice, NAME.toString() ) ); - Namespace namespace = new Namespace( getStringValue( columnSlice, NAMESPACE_ID.toString() ), // - new Repository( getStringValue( columnSlice, REPOSITORY_NAME.toString() ) ) ); - projectVersionMetadataModel.setNamespace( namespace ); - projectVersionMetadataModel.setIncomplete( - Boolean.parseBoolean( getStringValue( columnSlice, "incomplete" ) ) ); - projectVersionMetadataModel.setProjectId( getStringValue( columnSlice, PROJECT_ID.toString() ) ); - projectVersionMetadataModel.setUrl( getStringValue( columnSlice, URL.toString() ) ); - return projectVersionMetadataModel; - } - - - @Override - public void updateProjectVersion( RepositorySession session, String repositoryId, String namespaceId, String projectId, - ProjectVersionMetadata versionMetadata ) - throws MetadataRepositoryException - { - try - { - Namespace namespace = getNamespace( repositoryId, namespaceId ); - - if ( namespace == null ) - { - updateOrAddNamespace( repositoryId, namespaceId ); - } - - if ( getProject( session, repositoryId, namespaceId, projectId ) == null ) - { - ProjectMetadata projectMetadata = new ProjectMetadata(); - projectMetadata.setNamespace( namespaceId ); - projectMetadata.setId( projectId ); - updateProject( session, repositoryId, projectMetadata ); - } - - } - catch ( MetadataResolutionException e ) - { - throw new MetadataRepositoryException( e.getMessage(), e ); - } - - QueryResult<OrderedRows<String, String, String>> result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getProjectVersionMetadataFamilyName() ) // - .setColumnNames( PROJECT_VERSION.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId ) // - .addEqualsExpression( NAMESPACE_ID.toString(), namespaceId ) // - .addEqualsExpression( PROJECT_ID.toString(), projectId ) // - .addEqualsExpression( PROJECT_VERSION.toString(), versionMetadata.getId() ) // - .execute(); - - ProjectVersionMetadataModel projectVersionMetadataModel; - boolean creation = true; - if ( result.get().getCount() > 0 ) - { - projectVersionMetadataModel = - mapProjectVersionMetadataModel( result.get().getList().get( 0 ).getColumnSlice() ); - creation = false; - } - else - { - projectVersionMetadataModel = getModelMapper().map( versionMetadata, ProjectVersionMetadataModel.class ); - } - - projectVersionMetadataModel.setProjectId( projectId ); - projectVersionMetadataModel.setNamespace( new Namespace( namespaceId, new Repository( repositoryId ) ) ); - - projectVersionMetadataModel.setCiManagement( versionMetadata.getCiManagement() ); - projectVersionMetadataModel.setIssueManagement( versionMetadata.getIssueManagement() ); - projectVersionMetadataModel.setOrganization( versionMetadata.getOrganization() ); - projectVersionMetadataModel.setScm( versionMetadata.getScm() ); - - projectVersionMetadataModel.setMailingLists( versionMetadata.getMailingLists() ); - projectVersionMetadataModel.setDependencies( versionMetadata.getDependencies() ); - projectVersionMetadataModel.setLicenses( versionMetadata.getLicenses() ); - - // we don't test of repository and namespace really exist ! - String key = new ProjectVersionMetadataModel.KeyBuilder() // - .withRepository( repositoryId ) // - .withNamespace( namespaceId ) // - .withProjectId( projectId ) // - .withProjectVersion( versionMetadata.getVersion() ) // - .withId( versionMetadata.getId() ) // - .build(); - - // FIXME nested objects to store!!! - if ( creation ) - { - String cf = cassandraArchivaManager.getProjectVersionMetadataFamilyName(); - Mutator<String> mutator = projectVersionMetadataTemplate.createMutator() - // values - .addInsertion( key, cf, column( PROJECT_ID.toString(), projectId ) ) // - .addInsertion( key, cf, column( REPOSITORY_NAME.toString(), repositoryId ) ) // - .addInsertion( key, cf, column( NAMESPACE_ID.toString(), namespaceId ) )// - .addInsertion( key, cf, column( PROJECT_VERSION.toString(), versionMetadata.getVersion() ) ); // - - addInsertion( mutator, key, cf, DESCRIPTION.toString(), versionMetadata.getDescription() ); - - addInsertion( mutator, key, cf, NAME.toString(), versionMetadata.getName() ); - - addInsertion( mutator, key, cf, "incomplete", Boolean.toString( versionMetadata.isIncomplete() ) ); - - addInsertion( mutator, key, cf, URL.toString(), versionMetadata.getUrl() ); - { - CiManagement ci = versionMetadata.getCiManagement(); - if ( ci != null ) - { - addInsertion( mutator, key, cf, "ciManagement.system", ci.getSystem() ); - addInsertion( mutator, key, cf, "ciManagement.url", ci.getUrl() ); - } - } - - { - IssueManagement issueManagement = versionMetadata.getIssueManagement(); - - if ( issueManagement != null ) - { - addInsertion( mutator, key, cf, "issueManagement.system", issueManagement.getSystem() ); - addInsertion( mutator, key, cf, "issueManagement.url", issueManagement.getUrl() ); - } - } - - { - Organization organization = versionMetadata.getOrganization(); - if ( organization != null ) - { - addInsertion( mutator, key, cf, "organization.name", organization.getName() ); - addInsertion( mutator, key, cf, "organization.url", organization.getUrl() ); - } - } - - { - Scm scm = versionMetadata.getScm(); - if ( scm != null ) - { - addInsertion( mutator, key, cf, "scm.url", scm.getUrl() ); - addInsertion( mutator, key, cf, "scm.connection", scm.getConnection() ); - addInsertion( mutator, key, cf, "scm.developerConnection", scm.getDeveloperConnection() ); - } - } - - recordMailingList( key, versionMetadata.getMailingLists() ); - - recordLicenses( key, versionMetadata.getLicenses() ); - - recordDependencies( key, versionMetadata.getDependencies(), repositoryId ); - - mutator.execute(); - } - else - { - ColumnFamilyUpdater<String, String> updater = projectVersionMetadataTemplate.createUpdater( key ); - addUpdateStringValue( updater, PROJECT_ID.toString(), projectId ); - addUpdateStringValue( updater, REPOSITORY_NAME.toString(), repositoryId ); - addUpdateStringValue( updater, NAMESPACE_ID.toString(), namespaceId ); - addUpdateStringValue( updater, PROJECT_VERSION.toString(), versionMetadata.getVersion() ); - addUpdateStringValue( updater, DESCRIPTION.toString(), versionMetadata.getDescription() ); - - addUpdateStringValue( updater, NAME.toString(), versionMetadata.getName() ); - - updater.setString( "incomplete", Boolean.toString( versionMetadata.isIncomplete() ) ); - addUpdateStringValue( updater, URL.toString(), versionMetadata.getUrl() ); - - { - CiManagement ci = versionMetadata.getCiManagement(); - if ( ci != null ) - { - addUpdateStringValue( updater, "ciManagement.system", ci.getSystem() ); - addUpdateStringValue( updater, "ciManagement.url", ci.getUrl() ); - } - } - { - IssueManagement issueManagement = versionMetadata.getIssueManagement(); - if ( issueManagement != null ) - { - addUpdateStringValue( updater, "issueManagement.system", issueManagement.getSystem() ); - addUpdateStringValue( updater, "issueManagement.url", issueManagement.getUrl() ); - } - } - { - Organization organization = versionMetadata.getOrganization(); - if ( organization != null ) - { - addUpdateStringValue( updater, "organization.name", organization.getName() ); - addUpdateStringValue( updater, "organization.url", organization.getUrl() ); - } - } - { - Scm scm = versionMetadata.getScm(); - if ( scm != null ) - { - addUpdateStringValue( updater, "scm.url", scm.getUrl() ); - addUpdateStringValue( updater, "scm.connection", scm.getConnection() ); - addUpdateStringValue( updater, "scm.developerConnection", scm.getDeveloperConnection() ); - } - } - - // update is a delete record - removeMailingList( key ); - recordMailingList( key, versionMetadata.getMailingLists() ); - - removeLicenses( key ); - recordLicenses( key, versionMetadata.getLicenses() ); - - removeDependencies( key ); - recordDependencies( key, versionMetadata.getDependencies(), repositoryId ); - - projectVersionMetadataTemplate.update( updater ); - - } - - ArtifactMetadataModel artifactMetadataModel = new ArtifactMetadataModel(); - artifactMetadataModel.setRepositoryId( repositoryId ); - artifactMetadataModel.setNamespace( namespaceId ); - artifactMetadataModel.setProject( projectId ); - artifactMetadataModel.setProjectVersion( versionMetadata.getVersion() ); - artifactMetadataModel.setVersion( versionMetadata.getVersion() ); - updateFacets( versionMetadata, artifactMetadataModel ); - - } - - - @Override - public ProjectVersionMetadata getProjectVersion( RepositorySession session, final String repoId, final String namespace, - final String projectId, final String projectVersion ) - throws MetadataResolutionException - { - - QueryResult<OrderedRows<String, String, String>> result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getProjectVersionMetadataFamilyName() ) // - .setColumnNames( PROJECT_VERSION.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repoId ) // - .addEqualsExpression( NAMESPACE_ID.toString(), namespace ) // - .addEqualsExpression( PROJECT_ID.toString(), projectId ) // - .addEqualsExpression( PROJECT_VERSION.toString(), projectVersion ) // - .execute(); - - if ( result.get().getCount() < 1 ) - { - return null; - } - - String key = result.get().iterator().next().getKey(); - - ColumnFamilyResult<String, String> columnFamilyResult = this.projectVersionMetadataTemplate.queryColumns( key ); - - if ( !columnFamilyResult.hasResults() ) - { - return null; - } - - ProjectVersionMetadata projectVersionMetadata = new ProjectVersionMetadata(); - projectVersionMetadata.setId( columnFamilyResult.getString( PROJECT_VERSION.toString() ) ); - projectVersionMetadata.setDescription( columnFamilyResult.getString( DESCRIPTION.toString() ) ); - projectVersionMetadata.setName( columnFamilyResult.getString( NAME.toString() ) ); - - projectVersionMetadata.setIncomplete( Boolean.parseBoolean( columnFamilyResult.getString( "incomplete" ) ) ); - - projectVersionMetadata.setUrl( columnFamilyResult.getString( URL.toString() ) ); - { - String ciUrl = columnFamilyResult.getString( "ciManagement.url" ); - String ciSystem = columnFamilyResult.getString( "ciManagement.system" ); - - if ( StringUtils.isNotEmpty( ciSystem ) || StringUtils.isNotEmpty( ciUrl ) ) - { - projectVersionMetadata.setCiManagement( new CiManagement( ciSystem, ciUrl ) ); - } - } - { - String issueUrl = columnFamilyResult.getString( "issueManagement.url" ); - String issueSystem = columnFamilyResult.getString( "issueManagement.system" ); - if ( StringUtils.isNotEmpty( issueSystem ) || StringUtils.isNotEmpty( issueUrl ) ) - { - projectVersionMetadata.setIssueManagement( new IssueManagement( issueSystem, issueUrl ) ); - } - } - { - String organizationUrl = columnFamilyResult.getString( "organization.url" ); - String organizationName = columnFamilyResult.getString( "organization.name" ); - if ( StringUtils.isNotEmpty( organizationUrl ) || StringUtils.isNotEmpty( organizationName ) ) - { - projectVersionMetadata.setOrganization( new Organization( organizationName, organizationUrl ) ); - } - } - { - String devConn = columnFamilyResult.getString( "scm.developerConnection" ); - String conn = columnFamilyResult.getString( "scm.connection" ); - String url = columnFamilyResult.getString( "scm.url" ); - if ( StringUtils.isNotEmpty( devConn ) || StringUtils.isNotEmpty( conn ) || StringUtils.isNotEmpty( url ) ) - { - projectVersionMetadata.setScm( new Scm( conn, devConn, url ) ); - } - } - projectVersionMetadata.setMailingLists( getMailingLists( key ) ); - projectVersionMetadata.setLicenses( getLicenses( key ) ); - projectVersionMetadata.setDependencies( getDependencies( key ) ); - // facets - - result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getMetadataFacetFamilyName() ) // - .setColumnNames( FACET_ID.toString(), KEY.toString(), VALUE.toString(), NAME.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repoId ) // - .addEqualsExpression( NAMESPACE_ID.toString(), namespace ) // - .addEqualsExpression( PROJECT_ID.toString(), projectId ) // - .addEqualsExpression( PROJECT_VERSION.toString(), projectVersion ) // - .execute(); - - Map<String, Map<String, String>> metadataFacetsPerFacetIds = new HashMap<>(); - - for ( Row<String, String, String> row : result.get() ) - { - ColumnSlice<String, String> columnSlice = row.getColumnSlice(); - String facetId = getStringValue( columnSlice, FACET_ID.toString() ); - Map<String, String> metaValues = metadataFacetsPerFacetIds.computeIfAbsent( facetId, k -> new HashMap<>( ) ); - metaValues.put( getStringValue( columnSlice, KEY.toString() ), getStringValue( columnSlice, VALUE.toString() ) ); - } - - if ( !metadataFacetsPerFacetIds.isEmpty() ) - { - for ( Map.Entry<String, Map<String, String>> entry : metadataFacetsPerFacetIds.entrySet() ) - { - MetadataFacetFactory<?> metadataFacetFactory = getFacetFactory( entry.getKey() ); - if ( metadataFacetFactory != null ) - { - MetadataFacet metadataFacet = metadataFacetFactory.createMetadataFacet(); - metadataFacet.fromProperties( entry.getValue() ); - projectVersionMetadata.addFacet( metadataFacet ); - } - } - } - - return projectVersionMetadata; - } - - protected void recordChecksums( String repositoryId, String artifactMetadataKey, Map<String, String> checksums) - { - if ( checksums == null || checksums.isEmpty() ) - { - return; - } - Mutator<String> checksumMutator = this.checksumTemplate.createMutator(); - for ( Map.Entry<String, String> entry : checksums.entrySet()) - { - // we don't care about the key as the real used one with the projectVersionMetadata - String keyChecksums = UUID.randomUUID().toString(); - String cfChecksums = cassandraArchivaManager.getChecksumFamilyName(); - - addInsertion( checksumMutator, keyChecksums, cfChecksums, ARTIFACT_METADATA_MODEL_KEY, - artifactMetadataKey ); - addInsertion( checksumMutator, keyChecksums, cfChecksums, CHECKSUM_ALG.toString(), entry.getKey()); - addInsertion( checksumMutator, keyChecksums, cfChecksums, CHECKSUM_VALUE.toString(), - entry.getValue() ); - addInsertion(checksumMutator, keyChecksums, cfChecksums, REPOSITORY_NAME.toString(), repositoryId); - - } - checksumMutator.execute(); - } - - protected void removeChecksums( String artifactMetadataKey ) - { - - QueryResult<OrderedRows<String, String, String>> result = - HFactory.createRangeSlicesQuery( cassandraArchivaManager.getKeyspace(), ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getChecksumFamilyName() ) // - .setColumnNames( CHECKSUM_ALG.toString() ) // - .setRowCount( Integer.MAX_VALUE ) // - .addEqualsExpression(ARTIFACT_METADATA_MODEL_KEY, artifactMetadataKey ) // - .execute(); - - if ( result.get().getCount() < 1 ) - { - return; - } - - for ( Row<String, String, String> row : result.get() ) - { - this.checksumTemplate.deleteRow( row.getKey() ); - } - - } - - protected Map<String, String> getChecksums( String artifactMetadataKey ) - { - Map<String, String> checksums = new HashMap<>(); - - QueryResult<OrderedRows<String, String, String>> result = - HFactory.createRangeSlicesQuery( cassandraArchivaManager.getKeyspace(), ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getChecksumFamilyName() ) // - .setColumnNames( ARTIFACT_METADATA_MODEL_KEY, REPOSITORY_NAME.toString(), - CHECKSUM_ALG.toString(), CHECKSUM_VALUE.toString() ) // - .setRowCount( Integer.MAX_VALUE ) // - .addEqualsExpression(ARTIFACT_METADATA_MODEL_KEY, artifactMetadataKey) // - .execute(); - for ( Row<String, String, String> row : result.get() ) - { - ColumnFamilyResult<String, String> columnFamilyResult = - this.checksumTemplate.queryColumns( row.getKey() ); - - checksums.put(columnFamilyResult.getString(CHECKSUM_ALG.toString()), - columnFamilyResult.getString(CHECKSUM_VALUE.toString())); - } - - return checksums; - } - - 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.toString(), 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 ) - { - - QueryResult<OrderedRows<String, String, String>> result = - HFactory.createRangeSlicesQuery( cassandraArchivaManager.getKeyspace(), ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getMailingListFamilyName() ) // - .setColumnNames( NAME.toString() ) // - .setRowCount( Integer.MAX_VALUE ) // - .addEqualsExpression( "projectVersionMetadataModel.key", projectVersionMetadataKey ) // - .execute(); - - if ( result.get().getCount() < 1 ) - { - return; - } - - for ( Row<String, String, String> row : result.get() ) - { - this.mailingListTemplate.deleteRow( row.getKey() ); - } - - } - - protected List<MailingList> getMailingLists( String projectVersionMetadataKey ) - { - List<MailingList> mailingLists = new ArrayList<>(); - - QueryResult<OrderedRows<String, String, String>> result = - HFactory.createRangeSlicesQuery( cassandraArchivaManager.getKeyspace(), ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getMailingListFamilyName() ) // - .setColumnNames( NAME.toString() ) // - .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.toString() ) ); - 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<>(); - - for ( String columnName : columnFamilyResult.getColumnNames() ) - { - if ( StringUtils.startsWith( columnName, "otherArchive." ) ) - { - otherArchives.add( columnFamilyResult.getString( columnName ) ); - } - } - - mailingList.setOtherArchives( otherArchives ); - mailingLists.add( mailingList ); - } - - 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, NAME.toString(), license.getName() ); - - addInsertion( licenseMutator, keyLicense, cfLicense, URL.toString(), license.getUrl() ); - - } - licenseMutator.execute(); - } - - protected void removeLicenses( String projectVersionMetadataKey ) - { - - QueryResult<OrderedRows<String, String, String>> result = - HFactory.createRangeSlicesQuery( cassandraArchivaManager.getKeyspace(), ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getLicenseFamilyName() ) // - .setColumnNames( NAME.toString() ) // - .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<>(); - - 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( NAME.toString() ), columnFamilyResult.getString( URL.toString() ) ) ); - } - - return licenses; - } - - - protected void recordDependencies( String projectVersionMetadataKey, List<Dependency> dependencies, - String repositoryId ) - { - - 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, REPOSITORY_NAME.toString(), repositoryId ); - - 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, ARTIFACT_ID.toString(), dependency.getArtifactId() ); - - addInsertion( dependencyMutator, keyDependency, cfDependency, GROUP_ID.toString(), dependency.getNamespace() ); - - addInsertion( dependencyMutator, keyDependency, cfDependency, VERSION.toString(), dependency.getVersion() ); - - } - dependencyMutator.execute(); - } - - protected void removeDependencies( String projectVersionMetadataKey ) - { - - QueryResult<OrderedRows<String, String, String>> result = - HFactory.createRangeSlicesQuery( cassandraArchivaManager.getKeyspace(), ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getDependencyFamilyName() ) // - .setColumnNames( GROUP_ID.toString() ) // - .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<>(); - - 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( ARTIFACT_ID.toString() ) ); - - dependency.setNamespace( columnFamilyResult.getString( GROUP_ID.toString() ) ); - - dependency.setVersion( columnFamilyResult.getString( VERSION.toString() ) ); - - dependencies.add( dependency ); - } - - return dependencies; - } - - private Map<String, String> mapChecksums(Map<ChecksumAlgorithm,String> checksums) { - return checksums.entrySet().stream().collect(Collectors.toMap( - e -> e.getKey().name(), Map.Entry::getValue - )); - } - - private Map<ChecksumAlgorithm, String> mapChecksumsReverse(Map<String,String> checksums) { - return checksums.entrySet().stream().collect(Collectors.toMap( - e -> ChecksumAlgorithm.valueOf(e.getKey()), Map.Entry::getValue - )); - } - - @Override - public void updateArtifact( RepositorySession session, String repositoryId, String namespaceId, String projectId, String projectVersion, - ArtifactMetadata artifactMeta ) - throws MetadataRepositoryException - { - - Namespace namespace = getNamespace( repositoryId, namespaceId ); - if ( namespace == null ) - { - namespace = updateOrAddNamespace( repositoryId, namespaceId ); - } - - ProjectMetadata projectMetadata = new ProjectMetadata(); - projectMetadata.setId( projectId ); - projectMetadata.setNamespace( namespaceId ); - updateProject( session, repositoryId, projectMetadata ); - - String key = new ArtifactMetadataModel.KeyBuilder().withNamespace( namespace ).withProject( projectId ).withId( - artifactMeta.getId() ).withProjectVersion( projectVersion ).build(); - - // exists? - - boolean exists = this.artifactMetadataTemplate.isColumnsExist( key ); - - if ( exists ) - { - // updater - ColumnFamilyUpdater<String, String> updater = this.artifactMetadataTemplate.createUpdater( key ); - updater.setLong( FILE_LAST_MODIFIED.toString(), artifactMeta.getFileLastModified().toInstant().toEpochMilli()); - updater.setLong( WHEN_GATHERED.toString(), artifactMeta.getWhenGathered().toInstant().toEpochMilli() ); - updater.setLong( SIZE.toString(), artifactMeta.getSize() ); - addUpdateStringValue( updater, VERSION.toString(), artifactMeta.getVersion() ); - removeChecksums(key); - recordChecksums(repositoryId, key, mapChecksums(artifactMeta.getChecksums())); - this.artifactMetadataTemplate.update( updater ); - } - else - { - String cf = this.cassandraArchivaManager.getArtifactMetadataFamilyName(); - // create - this.artifactMetadataTemplate.createMutator() // - .addInsertion( key, cf, column( ID.toString(), artifactMeta.getId() ) )// - .addInsertion( key, cf, column( REPOSITORY_NAME.toString(), repositoryId ) ) // - .addInsertion( key, cf, column( NAMESPACE_ID.toString(), namespaceId ) ) // - .addInsertion( key, cf, column( PROJECT.toString(), artifactMeta.getProject() ) ) // - .addInsertion( key, cf, column( PROJECT_VERSION.toString(), projectVersion ) ) // - .addInsertion( key, cf, column( VERSION.toString(), artifactMeta.getVersion() ) ) // - .addInsertion( key, cf, column( FILE_LAST_MODIFIED.toString(), artifactMeta.getFileLastModified().toInstant().toEpochMilli() ) ) // - .addInsertion( key, cf, column( SIZE.toString(), artifactMeta.getSize() ) ) // - .addInsertion( key, cf, column( WHEN_GATHERED.toString(), artifactMeta.getWhenGathered().toInstant().toEpochMilli() ) )// - .execute(); - recordChecksums(repositoryId, key, mapChecksums(artifactMeta.getChecksums())); - } - - key = new ProjectVersionMetadataModel.KeyBuilder() // - .withRepository( repositoryId ) // - .withNamespace( namespace ) // - .withProjectId( projectId ) // - .withProjectVersion( projectVersion ) // - .withId( artifactMeta.getId() ) // - .build(); - - QueryResult<OrderedRows<String, String, String>> result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getProjectVersionMetadataFamilyName() ) // - .setColumnNames( VERSION.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId ) // - .addEqualsExpression( NAMESPACE_ID.toString(), namespaceId ) // - .addEqualsExpression( PROJECT_ID.toString(), projectId ) // - .addEqualsExpression( PROJECT_VERSION.toString(), projectVersion ) // - .addEqualsExpression( VERSION.toString(), artifactMeta.getVersion() ) // - .execute(); - - exists = result.get().getCount() > 0; - - if ( !exists ) - { - String cf = this.cassandraArchivaManager.getProjectVersionMetadataFamilyName(); - - projectVersionMetadataTemplate.createMutator() // - .addInsertion( key, cf, column( NAMESPACE_ID.toString(), namespace.getName() ) ) // - .addInsertion( key, cf, column( REPOSITORY_NAME.toString(), repositoryId ) ) // - .addInsertion( key, cf, column( PROJECT_VERSION.toString(), projectVersion ) ) // - .addInsertion( key, cf, column( PROJECT_ID.toString(), projectId ) ) // - .addInsertion( key, cf, column( VERSION.toString(), artifactMeta.getVersion() ) ) // - .execute(); - - } - - ArtifactMetadataModel artifactMetadataModel = new ArtifactMetadataModel(); - - artifactMetadataModel.setRepositoryId( repositoryId ); - artifactMetadataModel.setNamespace( namespaceId ); - artifactMetadataModel.setProject( projectId ); - artifactMetadataModel.setProjectVersion( projectVersion ); - artifactMetadataModel.setVersion( artifactMeta.getVersion() ); - artifactMetadataModel.setFileLastModified( artifactMeta.getFileLastModified() == null - ? ZonedDateTime.now().toInstant().toEpochMilli() - : artifactMeta.getFileLastModified().toInstant().toEpochMilli() ); - artifactMetadataModel.setChecksums(mapChecksums(artifactMeta.getChecksums())); - - // now facets - updateFacets( artifactMeta, artifactMetadataModel ); - - } - - @Override - public List<String> getArtifactVersions( RepositorySession session, final String repoId, final String namespace, final String projectId, - final String projectVersion ) - throws MetadataResolutionException - { - - QueryResult<OrderedRows<String, String, String>> result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getProjectVersionMetadataFamilyName() ) // - .setColumnNames( VERSION.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repoId ) // - .addEqualsExpression( NAMESPACE_ID.toString(), namespace ) // - .addEqualsExpression( PROJECT_ID.toString(), projectId ) // - .addEqualsExpression( PROJECT_VERSION.toString(), projectVersion ) // - .execute(); - - final Set<String> versions = new HashSet<>(); - - for ( Row<String, String, String> row : result.get() ) - { - versions.add( getStringValue( row.getColumnSlice(), VERSION.toString() ) ); - } - - return new ArrayList<>( versions ); - - } - - /* - * iterate over available facets to remove/add from the artifactMetadata - * - * @param facetedMetadata - * @param artifactMetadataModel only use for the key - */ - private void updateFacets( final FacetedMetadata facetedMetadata, - final ArtifactMetadataModel artifactMetadataModel ) - { - - String cf = cassandraArchivaManager.getMetadataFacetFamilyName(); - - for ( final String facetId : getSupportedFacets() ) - { - MetadataFacet metadataFacet = facetedMetadata.getFacet( facetId ); - if ( metadataFacet == null ) - { - continue; - } - // clean first - - QueryResult<OrderedRows<String, String, String>> result = - HFactory.createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cf ) // - .setColumnNames( REPOSITORY_NAME.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), artifactMetadataModel.getRepositoryId() ) // - .addEqualsExpression( NAMESPACE_ID.toString(), artifactMetadataModel.getNamespace() ) // - .addEqualsExpression( PROJECT_ID.toString(), artifactMetadataModel.getProject() ) // - .addEqualsExpression( PROJECT_VERSION.toString(), artifactMetadataModel.getProjectVersion() ) // - .addEqualsExpression( FACET_ID.toString(), facetId ) // - .execute(); - - for ( Row<String, String, String> row : result.get().getList() ) - { - this.metadataFacetTemplate.deleteRow( row.getKey() ); - } - - Map<String, String> properties = metadataFacet.toProperties(); - - for ( Map.Entry<String, String> entry : properties.entrySet() ) - { - String key = new MetadataFacetModel.KeyBuilder().withKey( entry.getKey() ).withArtifactMetadataModel( - artifactMetadataModel ).withFacetId( facetId ).withName( metadataFacet.getName() ).build(); - Mutator<String> mutator = metadataFacetTemplate.createMutator() // - .addInsertion( key, cf, column( REPOSITORY_NAME.toString(), artifactMetadataModel.getRepositoryId() ) ) // - .addInsertion( key, cf, column( NAMESPACE_ID.toString(), artifactMetadataModel.getNamespace() ) ) // - .addInsertion( key, cf, column( PROJECT_ID.toString(), artifactMetadataModel.getProject() ) ) // - .addInsertion( key, cf, column( PROJECT_VERSION.toString(), artifactMetadataModel.getProjectVersion() ) ) // - .addInsertion( key, cf, column( FACET_ID.toString(), facetId ) ) // - .addInsertion( key, cf, column( KEY.toString(), entry.getKey() ) ) // - .addInsertion( key, cf, column( VALUE.toString(), entry.getValue() ) ); - - if ( metadataFacet.getName() != null ) - { - mutator.addInsertion( key, cf, column( NAME.toString(), metadataFacet.getName() ) ); - } - - mutator.execute(); - } - } - } - - - @Override - public List<String> getMetadataFacets( RepositorySession session, final String repositoryId, final String facetId ) - throws MetadataRepositoryException - { - - QueryResult<OrderedRows<String, String, String>> result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getMetadataFacetFamilyName() ) // - .setColumnNames( NAME.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId ) // - .addEqualsExpression( FACET_ID.toString(), facetId ) // - .execute(); - - final List<String> facets = new ArrayList<>(); - - for ( Row<String, String, String> row : result.get() ) - { - facets.add( getStringValue( row.getColumnSlice(), NAME.toString() ) ); - } - return facets; - } - - private <T> Spliterator<T> createResultSpliterator( QueryResult<OrderedRows<String, String, String>> result, BiFunction<Row<String, String, String>, T, T> converter) throws MetadataRepositoryException - { - final int size = result.get().getCount(); - final Iterator<Row<String, String, String>> it = result.get( ).iterator( ); - - return new Spliterator<T>( ) - { - private T lastItem = null; - - @Override - public boolean tryAdvance( Consumer<? super T> action ) - { - if (size>=1) - { - if(it.hasNext()) - { - while ( it.hasNext( ) ) - { - Row<String, String, String> row = it.next( ); - T item = converter.apply( row, lastItem ); - if ( item != null && lastItem !=null && item != lastItem ) - { - action.accept( lastItem ); - lastItem = item; - return true; - } - lastItem = item; - } - action.accept( lastItem ); - return true; - } else { - return false; - } - } - return false; - } - - @Override - public Spliterator<T> trySplit( ) - { - return null; - } - - @Override - public long estimateSize( ) - { - return size; - } - - @Override - public int characteristics( ) - { - return ORDERED+NONNULL+SIZED; - } - }; - } - - - /** - * Implementation is not very performant, because sorting is part of the stream. I do not know how to specify the sort - * in the query. - * - * @param <T> - * @param session - * @param repositoryId - * @param facetClazz - * @param queryParameter - * @return - * @throws MetadataRepositoryException - */ - @Override - public <T extends MetadataFacet> Stream<T> getMetadataFacetStream(RepositorySession session, String repositoryId, Class<T> facetClazz, QueryParameter queryParameter) throws MetadataRepositoryException - { - final MetadataFacetFactory<T> metadataFacetFactory = getFacetFactory( facetClazz ); - final String facetId = metadataFacetFactory.getFacetId( ); - - QueryResult<OrderedRows<String, String, String>> result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getMetadataFacetFamilyName( ) ) // - .setColumnNames( NAME.toString( ), KEY.toString( ), VALUE.toString( ) ) // - .addEqualsExpression( REPOSITORY_NAME.toString( ), repositoryId ) // - .addEqualsExpression( FACET_ID.toString( ), facetId ) // - .setRange( null, null, false, Integer.MAX_VALUE ) - .setRowCount( Integer.MAX_VALUE ) - .execute( ); - - - - return StreamSupport.stream( createResultSpliterator( result, ( Row<String, String, String> row, T lastItem)-> { - ColumnSlice<String, String> columnSlice = row.getColumnSlice(); - String name = getStringValue( columnSlice, NAME.toString( ) ); - T updateItem; - if (lastItem!=null && lastItem.getName().equals(name)) - { - updateItem = lastItem; - } else - { - updateItem = metadataFacetFactory.createMetadataFacet( repositoryId, name ); - } - String key = getStringValue( columnSlice, KEY.toString() ); - if (StringUtils.isNotEmpty( key )) - { - Map<String, String> map = new HashMap<>( ); - map.put( key , getStringValue( columnSlice, VALUE.toString( ) ) ); - updateItem.fromProperties( map ); - } - return updateItem; - - }), false ).sorted( (f1, f2) -> f1.getName()!=null ? f1.getName().compareTo( f2.getName() ) : 1 ).skip( queryParameter.getOffset()).limit( queryParameter.getLimit()); - } - - @Override - public boolean hasMetadataFacet( RepositorySession session, String repositoryId, String facetId ) - throws MetadataRepositoryException - { - return !getMetadataFacets( session, repositoryId, facetId ).isEmpty(); - } - - @Override - public <T extends MetadataFacet> T getMetadataFacet( RepositorySession session, final String repositoryId, final Class<T> facetClazz, final String name ) - throws MetadataRepositoryException - { - final MetadataFacetFactory<T> metadataFacetFactory = getFacetFactory( facetClazz ); - if (metadataFacetFactory==null) { - return null; - } - final String facetId = metadataFacetFactory.getFacetId( ); - - QueryResult<OrderedRows<String, String, String>> result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getMetadataFacetFamilyName() ) // - .setColumnNames( KEY.toString(), VALUE.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId ) // - .addEqualsExpression( FACET_ID.toString(), facetId ) // - .addEqualsExpression( NAME.toString(), name ) // - .execute(); - - T metadataFacet = metadataFacetFactory.createMetadataFacet( repositoryId, name ); - int size = result.get().getCount(); - if ( size < 1 ) - { - return null; - } - Map<String, String> map = new HashMap<>( size ); - for ( Row<String, String, String> row : result.get() ) - { - ColumnSlice<String, String> columnSlice = row.getColumnSlice(); - map.put( getStringValue( columnSlice, KEY.toString() ), getStringValue( columnSlice, VALUE.toString() ) ); - } - metadataFacet.fromProperties( map ); - return metadataFacet; - } - - @Override - public MetadataFacet getMetadataFacet( RepositorySession session, String repositoryId, String facetId, String name ) throws MetadataRepositoryException - { - return getMetadataFacet( session, repositoryId, getFactoryClassForId( facetId ), name ); - } - - @Override - public void addMetadataFacet( RepositorySession session, String repositoryId, MetadataFacet metadataFacet ) - throws MetadataRepositoryException - { - - if ( metadataFacet == null ) - { - return; - } - - if ( metadataFacet.toProperties().isEmpty() ) - { - String key = new MetadataFacetModel.KeyBuilder().withRepositoryId( repositoryId ).withFacetId( - metadataFacet.getFacetId() ).withName( metadataFacet.getName() ).build(); - - boolean exists = this.metadataFacetTemplate.isColumnsExist( key ); - - if ( exists ) - { - ColumnFamilyUpdater<String, String> updater = this.metadataFacetTemplate.createUpdater( key ); - addUpdateStringValue( updater, FACET_ID.toString(), metadataFacet.getFacetId() ); - addUpdateStringValue( updater, NAME.toString(), metadataFacet.getName() ); - this.metadataFacetTemplate.update( updater ); - } - else - { - String cf = this.cassandraArchivaManager.getMetadataFacetFamilyName(); - this.metadataFacetTemplate.createMutator() // - .addInsertion( key, cf, column( REPOSITORY_NAME.toString(), repositoryId ) ) // - .addInsertion( key, cf, column( FACET_ID.toString(), metadataFacet.getFacetId() ) ) // - .addInsertion( key, cf, column( NAME.toString(), metadataFacet.getName() ) ) // - .execute(); - } - - } - else - { - for ( Map.Entry<String, String> entry : metadataFacet.toProperties().entrySet() ) - { - String key = new MetadataFacetModel.KeyBuilder().withRepositoryId( repositoryId ).withFacetId( - metadataFacet.getFacetId() ).withName( metadataFacet.getName() ).withKey( entry.getKey() ).build(); - - boolean exists = this.metadataFacetTemplate.isColumnsExist( key ); - if ( !exists ) - { - String cf = this.cassandraArchivaManager.getMetadataFacetFamilyName(); - this.metadataFacetTemplate.createMutator() // - .addInsertion( key, cf, column( REPOSITORY_NAME.toString(), repositoryId ) ) // - .addInsertion( key, cf, column( FACET_ID.toString(), metadataFacet.getFacetId() ) ) // - .addInsertion( key, cf, column( NAME.toString(), metadataFacet.getName() ) ) // - .addInsertion( key, cf, column( KEY.toString(), entry.getKey() ) ) // - .addInsertion( key, cf, column( VALUE.toString(), entry.getValue() ) ) // - .execute(); - } - else - { - ColumnFamilyUpdater<String, String> updater = this.metadataFacetTemplate.createUpdater( key ); - addUpdateStringValue( updater, VALUE.toString(), entry.getValue() ); - this.metadataFacetTemplate.update( updater ); - } - } - } - } - - @Override - public void removeMetadataFacets( RepositorySession session, final String repositoryId, final String facetId ) - throws MetadataRepositoryException - { - - QueryResult<OrderedRows<String, String, String>> result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getMetadataFacetFamilyName() ) // - .setColumnNames( KEY.toString(), VALUE.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId ) // - .addEqualsExpression( FACET_ID.toString(), facetId ) // - .execute(); - - for ( Row<String, String, String> row : result.get() ) - { - this.metadataFacetTemplate.deleteRow( row.getKey() ); - } - - } - - @Override - public void removeMetadataFacet( RepositorySession session, final String repositoryId, final String facetId, final String name ) - throws MetadataRepositoryException - { - - QueryResult<OrderedRows<String, String, String>> result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getMetadataFacetFamilyName() ) // - .setColumnNames( KEY.toString(), VALUE.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId ) // - .addEqualsExpression( FACET_ID.toString(), facetId ) // - .addEqualsExpression( NAME.toString(), name ) // - .execute(); - - for ( Row<String, String, String> row : result.get() ) - { - this.metadataFacetTemplate.deleteRow( row.getKey() ); - } - } - - @Override - public List<ArtifactMetadata> getArtifactsByDateRange( RepositorySession session, final String repositoryId, final ZonedDateTime startTime, - final ZonedDateTime endTime, QueryParameter queryParameter ) - throws MetadataRepositoryException - { - - LongSerializer ls = LongSerializer.get(); - RangeSlicesQuery<String, String, Long> query = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ls ) // - .setColumnFamily( cassandraArchivaManager.getArtifactMetadataFamilyName() ) // - .setColumnNames( ArtifactMetadataModel.COLUMNS ); // - - - if ( startTime != null ) - { - query = query.addGteExpression( WHEN_GATHERED.toString(), startTime.toInstant().toEpochMilli() ); - } - if ( endTime != null ) - { - query = query.addLteExpression( WHEN_GATHERED.toString(), endTime.toInstant().toEpochMilli() ); - } - QueryResult<OrderedRows<String, String, Long>> result = query.execute(); - - List<ArtifactMetadata> artifactMetadatas = new ArrayList<>( result.get().getCount() ); - Iterator<Row<String, String, Long>> keyIter = result.get().iterator(); - if (keyIter.hasNext()) { - String key = keyIter.next().getKey(); - for (Row<String, String, Long> row : result.get()) { - ColumnSlice<String, Long> columnSlice = row.getColumnSlice(); - String repositoryName = getAsStringValue(columnSlice, REPOSITORY_NAME.toString()); - if (StringUtils.equals(repositoryName, repositoryId)) { - - artifactMetadatas.add(mapArtifactMetadataLongColumnSlice(key, columnSlice)); - } - } - } - - return artifactMetadatas; - } - - /** - * For documentation see {@link MetadataRepository#getArtifactByDateRangeStream(RepositorySession, String, ZonedDateTime, ZonedDateTime, QueryParameter)} - * - * This implementation orders the stream. It does not order the query in the backend. - * - * @param session The repository session - * @param repositoryId The repository id - * @param startTime The start time, can be <code>null</code> - * @param endTime The end time, can be <code>null</code> - * @param queryParameter Additional parameters for the query that affect ordering and number of returned results. - * @return - * @throws MetadataRepositoryException - * @see MetadataRepository#getArtifactByDateRangeStream - */ - @Override - public Stream<ArtifactMetadata> getArtifactByDateRangeStream( RepositorySession session, String repositoryId, ZonedDateTime startTime, ZonedDateTime endTime, QueryParameter queryParameter) throws MetadataRepositoryException - { - Comparator<ArtifactMetadata> comp = getArtifactMetadataComparator(queryParameter, "whenGathered"); - return getArtifactsByDateRange(session, repositoryId, startTime, endTime, queryParameter).stream().sorted(comp).skip(queryParameter.getOffset()).limit(queryParameter.getLimit()); - } - - - protected ArtifactMetadata mapArtifactMetadataLongColumnSlice( String key, ColumnSlice<String, Long> columnSlice ) - { - ArtifactMetadata artifactMetadata = new ArtifactMetadata(); - artifactMetadata.setNamespace( getAsStringValue( columnSlice, NAMESPACE_ID.toString() ) ); - artifactMetadata.setSize( getLongValue( columnSlice, SIZE.toString() ) ); - artifactMetadata.setId( getAsStringValue( columnSlice, ID.toString() ) ); - artifactMetadata.setFileLastModified( getLongValue( columnSlice, FILE_LAST_MODIFIED.toString() ) ); - artifactMetadata.setMd5( getAsStringValue( columnSlice, MD5.toString() ) ); - artifactMetadata.setProject( getAsStringValue( columnSlice, PROJECT.toString() ) ); - artifactMetadata.setProjectVersion( getAsStringValue( columnSlice, PROJECT_VERSION.toString() ) ); - artifactMetadata.setRepositoryId( getAsStringValue( columnSlice, REPOSITORY_NAME.toString() ) ); - artifactMetadata.setSha1( getAsStringValue( columnSlice, SHA1.toString() ) ); - artifactMetadata.setVersion( getAsStringValue( columnSlice, VERSION.toString() ) ); - Long whenGathered = getLongValue( columnSlice, WHEN_GATHERED.toString() ); - if ( whenGathered != null ) - { - artifactMetadata.setWhenGathered(ZonedDateTime.ofInstant(Instant.ofEpochMilli(whenGathered), STORAGE_TZ)); - } - artifactMetadata.setChecksums(mapChecksumsReverse(getChecksums(key))); - return artifactMetadata; - } - - protected ArtifactMetadata mapArtifactMetadataStringColumnSlice( String key, ColumnSlice<String, String> columnSlice ) - { - ArtifactMetadata artifactMetadata = new ArtifactMetadata(); - artifactMetadata.setNamespace( getStringValue( columnSlice, NAMESPACE_ID.toString() ) ); - artifactMetadata.setSize( getAsLongValue( columnSlice, SIZE.toString() ) ); - artifactMetadata.setId( getStringValue( columnSlice, ID.toString() ) ); - artifactMetadata.setFileLastModified( getAsLongValue( columnSlice, FILE_LAST_MODIFIED.toString() ) ); - artifactMetadata.setMd5( getStringValue( columnSlice, MD5.toString() ) ); - artifactMetadata.setProject( getStringValue( columnSlice, PROJECT.toString() ) ); - artifactMetadata.setProjectVersion( getStringValue( columnSlice, PROJECT_VERSION.toString() ) ); - artifactMetadata.setRepositoryId( getStringValue( columnSlice, REPOSITORY_NAME.toString() ) ); - artifactMetadata.setSha1( getStringValue( columnSlice, SHA1.toString() ) ); - artifactMetadata.setVersion( getStringValue( columnSlice, VERSION.toString() ) ); - Long whenGathered = getAsLongValue( columnSlice, WHEN_GATHERED.toString() ); - if ( whenGathered != null ) - { - artifactMetadata.setWhenGathered(ZonedDateTime.ofInstant(Instant.ofEpochMilli(whenGathered), STORAGE_TZ)); - } - artifactMetadata.setChecksums(mapChecksumsReverse(getChecksums(key))); - return artifactMetadata; - } - - @Override - public List<ArtifactMetadata> getArtifactsByChecksum(RepositorySession session, final String repositoryId, final String checksum ) - throws MetadataRepositoryException - { - - // cql cannot run or in queries so running twice the query - Map<String, ArtifactMetadata> artifactMetadataMap = new HashMap<>(); - - RangeSlicesQuery<String, String, String> query = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getChecksumFamilyName()) // - .setColumnNames(ARTIFACT_METADATA_MODEL_KEY); // - - query = query.addEqualsExpression( CHECKSUM_VALUE.toString(), checksum ) - .addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId ); - - QueryResult<OrderedRows<String, String, String>> result = query.execute(); - - List<String> artifactKeys = new ArrayList<>(); - for ( Row<String, String, String> row : result.get() ) - { - ColumnSlice<String, String> columnSlice = row.getColumnSlice(); - - artifactKeys.add(columnSlice.getColumnByName(ARTIFACT_METADATA_MODEL_KEY).getValue()); - - } - - for (String key : artifactKeys) { - query = HFactory // - .createRangeSlicesQuery(keyspace, ss, ss, ss) // - .setColumnFamily(cassandraArchivaManager.getArtifactMetadataFamilyName()) // - .setColumnNames(NAMESPACE_ID.toString(), SIZE.toString(), ID.toString(), FILE_LAST_MODIFIED.toString(), MD5.toString(), PROJECT.toString(), PROJECT_VERSION.toString(), - REPOSITORY_NAME.toString(), VERSION.toString(), WHEN_GATHERED.toString(), SHA1.toString()) - .setKeys(key, key); - result = query.execute(); - - for (Row<String, String, String> row : result.get()) { - ColumnSlice<String, String> columnSlice = row.getColumnSlice(); - - artifactMetadataMap.put(row.getKey(), mapArtifactMetadataStringColumnSlice(key, columnSlice)); - } - } - - return new ArrayList<>(artifactMetadataMap.values()); - } - - /** - * Project version and artifact level metadata are stored in the same place, no distinctions in Cassandra - * implementation, just calls {@link MetadataRepository#getArtifactsByAttribute(RepositorySession, String, String, String)} - */ - @Override - public List<ArtifactMetadata> getArtifactsByProjectVersionFacet( RepositorySession session, String key, String value, String repositoryId ) - throws MetadataRepositoryException - { - return this.getArtifactsByAttribute( session, key, value, repositoryId ); - } - - @Override - public List<ArtifactMetadata> getArtifactsByAttribute( RepositorySession session, String key, String value, String repositoryId ) - throws MetadataRepositoryException - { - RangeSlicesQuery<String, String, String> query = - HFactory.createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getMetadataFacetFamilyName() ) // - .setColumnNames( MetadataFacetModel.COLUMNS ) // - .addEqualsExpression( VALUE.toString(), value ); - - if ( key != null ) - { - query.addEqualsExpression( KEY.toString(), key ); // - } - if ( repositoryId != null ) - { - query.addEqualsExpression( "repositoryName", repositoryId ); - } - - QueryResult<OrderedRows<String, String, String>> metadataFacetResult = query.execute(); - if ( metadataFacetResult.get() == null || metadataFacetResult.get().getCount() < 1 ) - { - return Collections.emptyList(); - } - - List<ArtifactMetadata> artifactMetadatas = new LinkedList<>( ); - - // TODO doing multiple queries, there should be a way to get all the artifactMetadatas for any number of - // projects - for ( Row<String, String, String> row : metadataFacetResult.get() ) - { - QueryResult<OrderedRows<String, String, String>> artifactMetadataResult = - HFactory.createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getArtifactMetadataFamilyName() ) // - .setColumnNames( ArtifactMetadataModel.COLUMNS ) // - .setRowCount( Integer.MAX_VALUE ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), - getStringValue( row.getColumnSlice(), REPOSITORY_NAME ) ) // - .addEqualsExpression( NAMESPACE_ID.toString(), getStringValue( row.getColumnSlice(), NAMESPACE_ID ) ) // - .addEqualsExpression( PROJECT.toString(), getStringValue( row.getColumnSlice(), PROJECT_ID ) ) // - .addEqualsExpression( PROJECT_VERSION.toString(), - getStringValue( row.getColumnSlice(), PROJECT_VERSION ) ) // - .execute(); - - if ( artifactMetadataResult.get() == null || artifactMetadataResult.get().getCount() < 1 ) - { - return Collections.emptyList(); - } - - for ( Row<String, String, String> artifactMetadataRow : artifactMetadataResult.get() ) - { - String artifactKey = artifactMetadataRow.getKey(); - artifactMetadatas.add( mapArtifactMetadataStringColumnSlice( artifactKey, artifactMetadataRow.getColumnSlice() ) ); - } - } - - return mapArtifactFacetToArtifact( metadataFacetResult, artifactMetadatas ); - } - - @Override - public List<ArtifactMetadata> getArtifactsByProjectVersionAttribute( RepositorySession session, String key, String value, String repositoryId ) - throws MetadataRepositoryException - { - QueryResult<OrderedRows<String, String, String>> result = - HFactory.createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getProjectVersionMetadataFamilyName() ) // - .setColumnNames( PROJECT_ID.toString(), REPOSITORY_NAME.toString(), NAMESPACE_ID.toString(), - PROJECT_VERSION.toString() ) // - .addEqualsExpression( key, value ) // - .execute(); - - int count = result.get().getCount(); - - if ( count < 1 ) - { - return Collections.emptyList(); - } - - List<ArtifactMetadata> artifacts = new LinkedList<>( ); - - for ( Row<String, String, String> row : result.get() ) - { - // TODO doing multiple queries, there should be a way to get all the artifactMetadatas for any number of - // projects - try - { - artifacts.addAll( getArtifacts( session, - getStringValue( row.getColumnSlice(), REPOSITORY_NAME ), - getStringValue( row.getColumnSlice(), NAMESPACE_ID ), - getStringValue( row.getColumnSlice(), PROJECT_ID ), getStringValue( row.getColumnSlice(), PROJECT_VERSION ) ) ); - } - catch ( MetadataResolutionException e ) - { - // never raised - throw new IllegalStateException( e ); - } - } - return artifacts; - } - - @Override - public void removeArtifact( RepositorySession session, final String repositoryId, final String namespace, final String project, - final String version, final String id ) - throws MetadataRepositoryException - { - logger.debug( "removeTimestampedArtifact repositoryId: '{}', namespace: '{}', project: '{}', version: '{}', id: '{}'", - repositoryId, namespace, project, version, id ); - String key = - new ArtifactMetadataModel.KeyBuilder().withRepositoryId( repositoryId ).withNamespace( namespace ).withId( - id ).withProjectVersion( version ).withProject( project ).build(); - - this.artifactMetadataTemplate.deleteRow( key ); - - key = new ProjectVersionMetadataModel.KeyBuilder() // - .withRepository( repositoryId ) // - .withNamespace( namespace ) // - .withProjectId( project ) // - .withProjectVersion( version ) // - .withId( id ) // - .build(); - - this.projectVersionMetadataTemplate.deleteRow( key ); - } - - @Override - public void removeTimestampedArtifact( RepositorySession session, ArtifactMetadata artifactMetadata, String baseVersion ) - throws MetadataRepositoryException - { - logger.debug( "removeTimestampedArtifact repositoryId: '{}', namespace: '{}', project: '{}', version: '{}', id: '{}'", - artifactMetadata.getRepositoryId(), artifactMetadata.getNamespace(), - artifactMetadata.getProject(), baseVersion, artifactMetadata.getId() ); - String key = - new ArtifactMetadataModel.KeyBuilder().withRepositoryId( artifactMetadata.getRepositoryId() ).withNamespace( - artifactMetadata.getNamespace() ).withId( artifactMetadata.getId() ).withProjectVersion( - baseVersion ).withProject( artifactMetadata.getProject() ).build(); - - this.artifactMetadataTemplate.deleteRow( key ); - - } - - @Override - public void removeFacetFromArtifact( RepositorySession session, final String repositoryId, final String namespace, final String project, - final String version, final MetadataFacet metadataFacet ) - throws MetadataRepositoryException - { - - RangeSlicesQuery<String, String, String> query = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getArtifactMetadataFamilyName() ) // - .setColumnNames( NAMESPACE_ID.toString() ); // - - query = query.addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId ) // - .addEqualsExpression( NAMESPACE_ID.toString(), namespace ) // - .addEqualsExpression( PROJECT.toString(), project ) // - .addEqualsExpression( VERSION.toString(), version ); - - QueryResult<OrderedRows<String, String, String>> result = query.execute(); - - for ( Row<String, String, String> row : result.get() ) - { - this.artifactMetadataTemplate.deleteRow( row.getKey() ); - } - } - - - @Override - public List<ArtifactMetadata> getArtifacts( RepositorySession session, final String repositoryId ) - throws MetadataRepositoryException - { - - RangeSlicesQuery<String, String, String> query = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getArtifactMetadataFamilyName() ) // - .setColumnNames( ArtifactMetadataModel.COLUMNS ); // - - query = query.addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId ); - - QueryResult<OrderedRows<String, String, String>> result = query.execute(); - - - - List<ArtifactMetadata> artifactMetadatas = new ArrayList<>( result.get().getCount() ); - - for ( Row<String, String, String> row : result.get() ) - { - String key = row.getKey(); - ColumnSlice<String, String> columnSlice = row.getColumnSlice(); - artifactMetadatas.add( mapArtifactMetadataStringColumnSlice( key, columnSlice ) ); - - } - - return artifactMetadatas; - } - - - @Override - public List<ProjectVersionReference> getProjectReferences( RepositorySession session, String repoId, String namespace, String projectId, - String projectVersion ) - throws MetadataResolutionException - { - QueryResult<OrderedRows<String, String, String>> result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getDependencyFamilyName() ) // - .setColumnNames( "projectVersionMetadataModel.key" ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repoId ) // - .addEqualsExpression( GROUP_ID.toString(), namespace ) // - .addEqualsExpression( ARTIFACT_ID.toString(), projectId ) // - .addEqualsExpression( VERSION.toString(), projectVersion ) // - .execute(); - - List<String> dependenciesIds = new ArrayList<>( result.get().getCount() ); - - for ( Row<String, String, String> row : result.get().getList() ) - { - dependenciesIds.add( getStringValue( row.getColumnSlice(), "projectVersionMetadataModel.key" ) ); - } - - List<ProjectVersionReference> references = new ArrayList<>( result.get().getCount() ); - - for ( String key : dependenciesIds ) - { - ColumnFamilyResult<String, String> columnFamilyResult = - this.projectVersionMetadataTemplate.queryColumns( key ); - references.add( new ProjectVersionReference( ProjectVersionReference.ReferenceType.DEPENDENCY, // - columnFamilyResult.getString( PROJECT_ID.toString() ), // - columnFamilyResult.getString( NAMESPACE_ID.toString() ), // - columnFamilyResult.getString( PROJECT_VERSION.toString() ) ) ); - } - - return references; - } - - @Override - public void removeProjectVersion( RepositorySession session, final String repoId, final String namespace, final String projectId, - final String projectVersion ) - throws MetadataRepositoryException - { - - QueryResult<OrderedRows<String, String, String>> result = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getProjectVersionMetadataFamilyName() ) // - .setColumnNames( VERSION.toString() ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repoId ) // - .addEqualsExpression( NAMESPACE_ID.toString(), namespace ) // - .addEqualsExpression( PROJECT_ID.toString(), projectId ) // - .addEqualsExpression( PROJECT_VERSION.toString(), projectVersion ) // - .execute(); - - for ( Row<String, String, String> row : result.get().getList() ) - { - this.projectVersionMetadataTemplate.deleteRow( row.getKey() ); - removeMailingList( row.getKey() ); - removeLicenses( row.getKey() ); - removeDependencies( row.getKey() ); - } - - RangeSlicesQuery<String, String, String> query = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getArtifactMetadataFamilyName() ) // - .setColumnNames( NAMESPACE_ID.toString() ); // - - query = query.addEqualsExpression( REPOSITORY_NAME.toString(), repoId ) // - .addEqualsExpression( NAMESPACE_ID.toString(), namespace ) // - .addEqualsExpression( PROJECT.toString(), projectId ) // - .addEqualsExpression( PROJECT_VERSION.toString(), projectVersion ); - - result = query.execute(); - - for ( Row<String, String, String> row : result.get() ) - { - this.artifactMetadataTemplate.deleteRow( row.getKey() ); - - } - } - - @Override - public List<ArtifactMetadata> getArtifacts( RepositorySession session, final String repoId, final String namespace, - final String projectId, final String projectVersion ) - throws MetadataResolutionException - { - - QueryResult<OrderedRows<String, String, String>> result = - HFactory.createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getArtifactMetadataFamilyName() ) // - .setColumnNames( ArtifactMetadataModel.COLUMNS )// - .setRowCount( Integer.MAX_VALUE ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repoId ) // - .addEqualsExpression( NAMESPACE_ID.toString(), namespace ) // - .addEqualsExpression( PROJECT.toString(), projectId ) // - .addEqualsExpression( PROJECT_VERSION.toString(), projectVersion ) // - .execute(); - - if ( result.get() == null || result.get().getCount() < 1 ) - { - return Collections.emptyList(); - } - - List<ArtifactMetadata> artifactMetadatas = new ArrayList<>( result.get().getCount() ); - - for ( Row<String, String, String> row : result.get() ) - { - String key = row.getKey(); - artifactMetadatas.add( mapArtifactMetadataStringColumnSlice( key, row.getColumnSlice() ) ); - } - - result = HFactory.createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getMetadataFacetFamilyName() ) // - .setColumnNames( MetadataFacetModel.COLUMNS ) // - .setRowCount( Integer.MAX_VALUE ) // - .addEqualsExpression( REPOSITORY_NAME.toString(), repoId ) // - .addEqualsExpression( NAMESPACE_ID.toString(), namespace ) // - .addEqualsExpression( PROJECT_ID.toString(), projectId ) // - .addEqualsExpression( PROJECT_VERSION.toString(), projectVersion ) // - .execute(); - - return mapArtifactFacetToArtifact(result, artifactMetadatas); - } - - /** - * Attach metadata to each of the ArtifactMetadata objects - */ - private List<ArtifactMetadata> mapArtifactFacetToArtifact( QueryResult<OrderedRows<String, String, String>> result, List<ArtifactMetadata> artifactMetadatas) { - if ( result.get() == null || result.get().getCount() < 1 ) - { - return artifactMetadatas; - } - - final List<MetadataFacetModel> metadataFacetModels = new ArrayList<>( result.get().getCount() ); - - for ( Row<String, String, String> row : result.get() ) - { - ColumnSlice<String, String> columnSlice = row.getColumnSlice(); - MetadataFacetModel metadataFacetModel = new MetadataFacetModel(); - metadataFacetModel.setFacetId( getStringValue( columnSlice, FACET_ID.toString() ) ); - metadataFacetModel.setName( getStringValue( columnSlice, NAME.toString() ) ); - metadataFacetModel.setValue( getStringValue( columnSlice, VALUE.toString() ) ); - metadataFacetModel.setKey( getStringValue( columnSlice, KEY.toString() ) ); - metadataFacetModel.setProjectVersion( getStringValue( columnSlice, PROJECT_VERSION.toString() ) ); - metadataFacetModels.add( metadataFacetModel ); - } - - // rebuild MetadataFacet for artifacts - - for ( final ArtifactMetadata artifactMetadata : artifactMetadatas ) - { - Iterator<MetadataFacetModel> iterator = metadataFacetModels.stream( ).filter( metadataFacetModel -> { - if ( metadataFacetModel != null ) - { - return StringUtils.equals( artifactMetadata.getVersion( ), - metadataFacetModel.getProjectVersion( ) ); - } - return false; - - } ).iterator( ); - Map<String, List<MetadataFacetModel>> metadataFacetValuesPerFacetId = new HashMap<>(); - while ( iterator.hasNext() ) - { - MetadataFacetModel metadataFacetModel = iterator.next(); - List<MetadataFacetModel> values = metadataFacetValuesPerFacetId.get( metadataFacetModel.getName() ); - if ( values == null ) - { - values = new ArrayList<>(); - metadataFacetValuesPerFacetId.put( metadataFacetModel.getFacetId(), values ); - } - values.add( metadataFacetModel ); - - } - - for ( Map.Entry<String, List<MetadataFacetModel>> entry : metadataFacetValuesPerFacetId.entrySet() ) - { - MetadataFacetFactory<?> metadataFacetFactory = getFacetFactory( entry.getKey() ); - if ( metadataFacetFactory != null ) - { - List<MetadataFacetModel> facetModels = entry.getValue(); - if ( !facetModels.isEmpty() ) - { - MetadataFacet metadataFacet = metadataFacetFactory.createMetadataFacet(); - Map<String, String> props = new HashMap<>( facetModels.size() ); - for ( MetadataFacetModel metadataFacetModel : facetModels ) - { - props.put( metadataFacetModel.getKey(), metadataFacetModel.getValue() ); - } - metadataFacet.fromProperties( props ); - artifactMetadata.addFacet( metadataFacet ); - } - } - } - } - - return artifactMetadatas; - } - - @Override - public void close() - throws MetadataRepositoryException - { - logger.trace( "close" ); - } - - - private static class ModelMapperHolder - { - private static ModelMapper MODEL_MAPPER = new ModelMapper(); - } - - protected ModelMapper getModelMapper() - { - return ModelMapperHolder.MODEL_MAPPER; - } - - /** - * This implementation just calls getArtifactsByAttribute( null, text, repositoryId ). We can't search artifacts by - * any property. - */ - @Override - public List<ArtifactMetadata> searchArtifacts( final RepositorySession session, final String repositoryId, - final String text, final boolean exact ) - throws MetadataRepositoryException - { - return this.getArtifactsByAttribute( session, null, text, repositoryId ); - } - - /** - * The exact parameter is ignored as we can't do non exact searches in Cassandra - */ - @Override - public List<ArtifactMetadata> searchArtifacts( final RepositorySession session, final String repositoryId, - final String key, final String text, final boolean exact ) - throws MetadataRepositoryException - { - // TODO optimize - List<ArtifactMetadata> artifacts = new LinkedList<>( ); - artifacts.addAll( this.getArtifactsByAttribute( session, key, text, repositoryId ) ); - artifacts.addAll( this.getArtifactsByProjectVersionAttribute( session, key, text, repositoryId ) ); - return artifacts; - } - - @Override - public Stream<ArtifactMetadata> getArtifactStream( final RepositorySession session, final String repositoryId, - final QueryParameter queryParameter ) throws MetadataResolutionException - { - RangeSlicesQuery<String, String, String> query = HFactory // - .createRangeSlicesQuery( keyspace, ss, ss, ss ) // - .setColumnFamily( cassandraArchivaManager.getArtifactMetadataFamilyName( ) ) // - .setColumnNames( ArtifactMetadataModel.COLUMNS ); // - - query = query.addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId ); - - QueryResult<OrderedRows<String, String, String>> result = query.execute(); - - try - { - return StreamSupport.stream( createResultSpliterator( result, ( Row<String, String, String> row, ArtifactMetadata last ) -> - mapArtifactMetadataStringColumnSlice( row.getKey( ), row.getColumnSlice( ) ) ), false ) - .skip( queryParameter.getOffset( ) ).limit( queryParameter.getLimit( ) ); - } - catch ( MetadataRepositoryException e ) - { - throw new MetadataResolutionException( e.getMessage( ), e ); - } - } - - @Override - public Stream<ArtifactMetadata> getArtifactStream( final RepositorySession session, final String repoId, - final String namespace, final String projectId, final String projectVersion, - final QueryParameter queryParameter ) throws MetadataResolutionException - { - // Currently we have to align the facets with the artifacts, which means querying artifacts, querying facets and combining them. - // I so no stream friendly way to do this, so we just use the collection based method and return the stream. - // TODO: Maybe we can query the facets for each artifact separately, but not sure, if this affects performance significantly - // We need some data to verify this. - return getArtifacts( session, repoId, namespace, projectId, projectVersion ).stream( ).skip( queryParameter.getOffset( ) ).limit( queryParameter.getLimit( ) ); - } -} diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraRepositorySessionFactory.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraRepositorySessionFactory.java deleted file mode 100644 index 2f3077b3c..000000000 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraRepositorySessionFactory.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.apache.archiva.metadata.repository.cassandra; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.configuration.ArchivaConfiguration; -import org.apache.archiva.metadata.repository.AbstractRepositorySessionFactory; -import org.apache.archiva.metadata.repository.MetadataRepositoryException; -import org.apache.archiva.metadata.repository.MetadataResolver; -import org.apache.archiva.metadata.repository.MetadataService; -import org.apache.archiva.metadata.repository.RepositorySession; -import org.apache.archiva.metadata.repository.RepositorySessionFactory; -import org.springframework.context.ApplicationContext; -import org.springframework.stereotype.Service; - -import javax.inject.Inject; -import javax.inject.Named; - -/** - * @author Olivier Lamy - * @since 2.0.0 - */ -@Service("repositorySessionFactory#cassandra") -public class CassandraRepositorySessionFactory extends AbstractRepositorySessionFactory - implements RepositorySessionFactory -{ - - @Inject - @Named(value = "archivaConfiguration#default") - private ArchivaConfiguration configuration; - - @Inject - private MetadataResolver metadataResolver; - - @Inject - private ApplicationContext applicationContext; - - @Inject - private CassandraArchivaManager cassandraArchivaManager; - - @Inject - private MetadataService metadataService; - - public void initialize() - { - } - - @Override - protected void shutdown() { - cassandraArchivaManager.shutdown(); - } - - - @Override - public RepositorySession createSession() throws MetadataRepositoryException - { - CassandraMetadataRepository metadataRepository = - new CassandraMetadataRepository( metadataService, cassandraArchivaManager ); - return new RepositorySession( metadataRepository, metadataResolver ); - } - -} diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraUtils.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraUtils.java deleted file mode 100644 index f041a4396..000000000 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraUtils.java +++ /dev/null @@ -1,162 +0,0 @@ -package org.apache.archiva.metadata.repository.cassandra; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import me.prettyprint.cassandra.serializers.LongSerializer; -import me.prettyprint.cassandra.serializers.SerializerTypeInferer; -import me.prettyprint.cassandra.serializers.StringSerializer; -import me.prettyprint.cassandra.service.template.ColumnFamilyUpdater; -import me.prettyprint.hector.api.Serializer; -import me.prettyprint.hector.api.beans.ColumnSlice; -import me.prettyprint.hector.api.beans.HColumn; -import me.prettyprint.hector.api.factory.HFactory; -import me.prettyprint.hector.api.mutation.Mutator; -import org.apache.archiva.metadata.repository.cassandra.model.ColumnNames; -import org.apache.commons.lang3.StringUtils; - -/** - * @author Olivier Lamy - * @since 2.0.0 - */ -public class CassandraUtils -{ - - private static final String EMPTY_VALUE = ""; - - public static final String SEPARATOR = "->"; - - public static String generateKey( final String... bases ) - { - final StringBuilder builder = new StringBuilder(); - if ( bases == null || bases.length == 0 ) - { - return builder.toString(); - } - - for ( final String s : bases ) - { - if ( s != null ) - { - builder.append( s ); - } - else - { - builder.append( EMPTY_VALUE ); - } - builder.append( SEPARATOR ); - } - if ( builder.length() > 0 ) - { - builder.setLength( builder.length() - SEPARATOR.length() ); - } - return builder.toString(); - } - - public static <A, B> HColumn<A, B> column( final A name, final B value ) - { - - return HFactory.createColumn( name, // - value, // - SerializerTypeInferer.getSerializer( name ), // - SerializerTypeInferer.getSerializer( value ) ); - } - - public static String getStringValue( ColumnSlice<String, String> columnSlice, ColumnNames columnName ) - { - return getStringValue( columnSlice, columnName.toString() ); - } - - public static String getStringValue( ColumnSlice<String, String> columnSlice, String columnName ) - { - if ( StringUtils.isEmpty( columnName ) ) - { - return null; - } - - HColumn<String, String> hColumn = columnSlice.getColumnByName( columnName ); - return hColumn == null ? null : hColumn.getValue(); - } - - public static Long getLongValue( ColumnSlice<String, Long> columnSlice, String columnName ) - { - if ( StringUtils.isEmpty( columnName ) ) - { - return null; - } - - HColumn<String, Long> hColumn = columnSlice.getColumnByName( columnName ); - return hColumn == null ? null : hColumn.getValue(); - } - - public static <T> String getAsStringValue( ColumnSlice<String, T> columnSlice, String columnName ) - { - StringSerializer ss = StringSerializer.get(); - if ( StringUtils.isEmpty( columnName ) ) - { - return null; - } - - HColumn<String, T> hColumn = columnSlice.getColumnByName( columnName ); - return hColumn == null ? null : ss.fromByteBuffer( hColumn.getValueBytes() ); - } - - public static Long getAsLongValue( ColumnSlice<String, String> columnSlice, String columnName ) - { - LongSerializer ls = LongSerializer.get(); - if ( StringUtils.isEmpty( columnName ) ) - { - return null; - } - - HColumn<String, String> hColumn = columnSlice.getColumnByName( columnName ); - return hColumn == null ? null : ls.fromByteBuffer( hColumn.getValueBytes() ); - } - - public static void addInsertion( Mutator<String> mutator, String key, String columnFamily, String columnName, - String value ) - { - if ( value != null ) - { - mutator.addInsertion( key, columnFamily, column( columnName, value ) ); - } - } - - /** - * null check on the value to prevent {@link java.lang.IllegalArgumentException} - * @param updater - * @param columnName - * @param value - */ - public static void addUpdateStringValue(ColumnFamilyUpdater<String,String> updater, String columnName, String value ) - { - if (value == null) - { - return; - } - updater.setString( columnName, value ); - - } - - private CassandraUtils() - { - // no-op - } - -} 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 deleted file mode 100644 index 65a5901f7..000000000 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/DefaultCassandraArchivaManager.java +++ /dev/null @@ -1,606 +0,0 @@ -package org.apache.archiva.metadata.repository.cassandra; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import me.prettyprint.cassandra.model.BasicColumnDefinition; -import me.prettyprint.cassandra.model.ConfigurableConsistencyLevel; -import me.prettyprint.cassandra.serializers.StringSerializer; -import me.prettyprint.cassandra.service.CassandraHostConfigurator; -import me.prettyprint.cassandra.service.ThriftKsDef; -import me.prettyprint.hector.api.Cluster; -import me.prettyprint.hector.api.HConsistencyLevel; -import me.prettyprint.hector.api.Keyspace; -import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition; -import me.prettyprint.hector.api.ddl.ColumnIndexType; -import me.prettyprint.hector.api.ddl.ComparatorType; -import me.prettyprint.hector.api.factory.HFactory; -import org.apache.archiva.metadata.repository.RepositorySessionFactoryBean; -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.ApplicationContext; -import org.springframework.stereotype.Service; - -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import javax.inject.Inject; -import java.util.ArrayList; -import java.util.List; - -import static org.apache.archiva.metadata.repository.cassandra.model.ColumnNames.*; - -/** - * FIXME make all configuration not hardcoded :-) - * - * @author Olivier Lamy - * @since 2.0.0 - */ -@Service("archivaEntityManagerFactory#cassandra") -public class DefaultCassandraArchivaManager - implements CassandraArchivaManager -{ - - private Logger logger = LoggerFactory.getLogger( getClass() ); - - @Inject - private ApplicationContext applicationContext; - - private static final String CLUSTER_NAME = "archiva"; - - private static final String KEYSPACE_NAME = "ArchivaKeySpace"; - - private boolean started; - - private Cluster cluster; - - private Keyspace keyspace; - - // configurable??? - private String repositoryFamilyName = "repository"; - - private String namespaceFamilyName = "namespace"; - - private String projectFamilyName = PROJECT.toString(); - - private String projectVersionMetadataFamilyName = "projectversionmetadata"; - - private String artifactMetadataFamilyName = "artifactmetadata"; - - private String metadataFacetFamilyName = "metadatafacet"; - - private String mailingListFamilyName = "mailinglist"; - - private String licenseFamilyName = "license"; - - private String dependencyFamilyName = "dependency"; - - private String checksumFamilyName = "checksum"; - - @Value("${cassandra.host}") - private String cassandraHost; - - @Value("${cassandra.port}") - private String cassandraPort; - - @Value("${cassandra.maxActive}") - private int maxActive; - - @Value("${cassandra.readConsistencyLevel}") - private String readConsistencyLevel; - - @Value("${cassandra.writeConsistencyLevel}") - private String writeConsistencyLevel; - - @Value("${cassandra.replicationFactor}") - private int replicationFactor; - - @Value("${cassandra.keyspace.name}") - private String keyspaceName; - - @Value("${cassandra.cluster.name}") - private String clusterName; - - @Inject - private RepositorySessionFactoryBean repositorySessionFactoryBean; - - @PostConstruct - public void initialize() - { - // skip initialisation if not cassandra - if ( !StringUtils.equals( repositorySessionFactoryBean.getId(), "cassandra" ) ) - { - return; - } - final CassandraHostConfigurator configurator = - new CassandraHostConfigurator( cassandraHost + ":" + cassandraPort ); - configurator.setMaxActive( maxActive ); - //configurator.setCassandraThriftSocketTimeout( ); - - cluster = HFactory.getOrCreateCluster( clusterName, configurator ); - - final ConfigurableConsistencyLevel consistencyLevelPolicy = new ConfigurableConsistencyLevel(); - consistencyLevelPolicy.setDefaultReadConsistencyLevel( HConsistencyLevel.valueOf( readConsistencyLevel ) ); - consistencyLevelPolicy.setDefaultWriteConsistencyLevel( HConsistencyLevel.valueOf( writeConsistencyLevel ) ); - keyspace = HFactory.createKeyspace( keyspaceName, cluster, consistencyLevelPolicy ); - - List<ColumnFamilyDefinition> cfds = new ArrayList<>(); - - // namespace table - { - - final ColumnFamilyDefinition namespace = - HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), // - getNamespaceFamilyName(), // - ComparatorType.UTF8TYPE ); - cfds.add( namespace ); - - // creating indexes for cql query - - BasicColumnDefinition nameColumn = new BasicColumnDefinition(); - nameColumn.setName( StringSerializer.get().toByteBuffer( NAME.toString() ) ); - nameColumn.setIndexName( NAME.toString() ); - nameColumn.setIndexType( ColumnIndexType.KEYS ); - nameColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - namespace.addColumnDefinition( nameColumn ); - - BasicColumnDefinition repositoryIdColumn = new BasicColumnDefinition(); - repositoryIdColumn.setName( StringSerializer.get().toByteBuffer( REPOSITORY_NAME.toString() ) ); - repositoryIdColumn.setIndexName( REPOSITORY_NAME.toString() ); - repositoryIdColumn.setIndexType( ColumnIndexType.KEYS ); - repositoryIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - namespace.addColumnDefinition( repositoryIdColumn ); - } - - // repository table - { - final ColumnFamilyDefinition repository = - HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), // - getRepositoryFamilyName(), // - ComparatorType.UTF8TYPE ); - - cfds.add( repository ); - - BasicColumnDefinition nameColumn = new BasicColumnDefinition(); - nameColumn.setName( StringSerializer.get().toByteBuffer( REPOSITORY_NAME.toString() ) ); - nameColumn.setIndexName( REPOSITORY_NAME.toString() ); - nameColumn.setIndexType( ColumnIndexType.KEYS ); - nameColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - repository.addColumnDefinition( nameColumn ); - } - - // project table - { - - final ColumnFamilyDefinition project = HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), // - getProjectFamilyName(), // - ComparatorType.UTF8TYPE ); - cfds.add( project ); - - // creating indexes for cql query - - BasicColumnDefinition projectIdColumn = new BasicColumnDefinition(); - projectIdColumn.setName( StringSerializer.get().toByteBuffer( PROJECT_ID.toString() ) ); - projectIdColumn.setIndexName( PROJECT_ID.toString() ); - projectIdColumn.setIndexType( ColumnIndexType.KEYS ); - projectIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - project.addColumnDefinition( projectIdColumn ); - - BasicColumnDefinition repositoryIdColumn = new BasicColumnDefinition(); - repositoryIdColumn.setName( StringSerializer.get().toByteBuffer( REPOSITORY_NAME.toString() ) ); - repositoryIdColumn.setIndexName( REPOSITORY_NAME.toString() ); - repositoryIdColumn.setIndexType( ColumnIndexType.KEYS ); - repositoryIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - project.addColumnDefinition( repositoryIdColumn ); - - BasicColumnDefinition namespaceIdColumn = new BasicColumnDefinition(); - namespaceIdColumn.setName( StringSerializer.get().toByteBuffer( NAMESPACE_ID.toString() ) ); - namespaceIdColumn.setIndexName( NAMESPACE_ID.toString() ); - namespaceIdColumn.setIndexType( ColumnIndexType.KEYS ); - namespaceIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - project.addColumnDefinition( namespaceIdColumn ); - } - - //projectversionmetadatamodel - { - - final ColumnFamilyDefinition projectVersionMetadataModel = - HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), // - getProjectVersionMetadataFamilyName(), // - ComparatorType.UTF8TYPE ); - cfds.add( projectVersionMetadataModel ); - - // creating indexes for cql query - - BasicColumnDefinition namespaceIdColumn = new BasicColumnDefinition(); - namespaceIdColumn.setName( StringSerializer.get().toByteBuffer( NAMESPACE_ID.toString() ) ); - namespaceIdColumn.setIndexName( NAMESPACE_ID.toString() ); - namespaceIdColumn.setIndexType( ColumnIndexType.KEYS ); - namespaceIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - projectVersionMetadataModel.addColumnDefinition( namespaceIdColumn ); - - BasicColumnDefinition repositoryNameColumn = new BasicColumnDefinition(); - repositoryNameColumn.setName( StringSerializer.get().toByteBuffer( REPOSITORY_NAME.toString() ) ); - repositoryNameColumn.setIndexName( REPOSITORY_NAME.toString() ); - repositoryNameColumn.setIndexType( ColumnIndexType.KEYS ); - repositoryNameColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - projectVersionMetadataModel.addColumnDefinition( repositoryNameColumn ); - - BasicColumnDefinition idColumn = new BasicColumnDefinition(); - idColumn.setName( StringSerializer.get().toByteBuffer( ID.toString() ) ); - idColumn.setIndexName( ID.toString() ); - idColumn.setIndexType( ColumnIndexType.KEYS ); - idColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - projectVersionMetadataModel.addColumnDefinition( idColumn ); - - BasicColumnDefinition projectIdColumn = new BasicColumnDefinition(); - projectIdColumn.setName( StringSerializer.get().toByteBuffer( PROJECT_ID.toString() ) ); - projectIdColumn.setIndexName( PROJECT_ID.toString() ); - projectIdColumn.setIndexType( ColumnIndexType.KEYS ); - projectIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - projectVersionMetadataModel.addColumnDefinition( projectIdColumn ); - - } - - // artifactmetadatamodel table - { - - final ColumnFamilyDefinition artifactMetadataModel = - HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), // - getArtifactMetadataFamilyName(), // - ComparatorType.UTF8TYPE ); - cfds.add( artifactMetadataModel ); - - // creating indexes for cql query - - BasicColumnDefinition idColumn = new BasicColumnDefinition(); - idColumn.setName( StringSerializer.get().toByteBuffer( ID.toString() ) ); - idColumn.setIndexName( ID.toString() ); - idColumn.setIndexType( ColumnIndexType.KEYS ); - idColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - artifactMetadataModel.addColumnDefinition( idColumn ); - - BasicColumnDefinition repositoryNameColumn = new BasicColumnDefinition(); - repositoryNameColumn.setName( StringSerializer.get().toByteBuffer( REPOSITORY_NAME.toString() ) ); - repositoryNameColumn.setIndexName( REPOSITORY_NAME.toString() ); - repositoryNameColumn.setIndexType( ColumnIndexType.KEYS ); - repositoryNameColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - artifactMetadataModel.addColumnDefinition( repositoryNameColumn ); - - BasicColumnDefinition namespaceIdColumn = new BasicColumnDefinition(); - namespaceIdColumn.setName( StringSerializer.get().toByteBuffer( NAMESPACE_ID.toString() ) ); - namespaceIdColumn.setIndexName( NAMESPACE_ID.toString() ); - namespaceIdColumn.setIndexType( ColumnIndexType.KEYS ); - namespaceIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - artifactMetadataModel.addColumnDefinition( namespaceIdColumn ); - - BasicColumnDefinition projectColumn = new BasicColumnDefinition(); - projectColumn.setName( StringSerializer.get().toByteBuffer( PROJECT.toString() ) ); - projectColumn.setIndexName( PROJECT.toString() ); - projectColumn.setIndexType( ColumnIndexType.KEYS ); - projectColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - artifactMetadataModel.addColumnDefinition( projectColumn ); - - BasicColumnDefinition projectVersionColumn = new BasicColumnDefinition(); - projectVersionColumn.setName( StringSerializer.get().toByteBuffer( PROJECT_VERSION.toString() ) ); - projectVersionColumn.setIndexName( PROJECT_VERSION.toString() ); - projectVersionColumn.setIndexType( ColumnIndexType.KEYS ); - projectVersionColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - artifactMetadataModel.addColumnDefinition( projectVersionColumn ); - - BasicColumnDefinition versionColumn = new BasicColumnDefinition(); - versionColumn.setName( StringSerializer.get().toByteBuffer( VERSION.toString() ) ); - versionColumn.setIndexName( VERSION.toString() ); - versionColumn.setIndexType( ColumnIndexType.KEYS ); - versionColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - artifactMetadataModel.addColumnDefinition( versionColumn ); - - BasicColumnDefinition whenGatheredColumn = new BasicColumnDefinition(); - whenGatheredColumn.setName( StringSerializer.get().toByteBuffer( WHEN_GATHERED.toString() ) ); - whenGatheredColumn.setIndexName( WHEN_GATHERED.toString() ); - whenGatheredColumn.setIndexType( ColumnIndexType.KEYS ); - whenGatheredColumn.setValidationClass( ComparatorType.LONGTYPE.getClassName() ); - artifactMetadataModel.addColumnDefinition( whenGatheredColumn ); - - BasicColumnDefinition sha1Column = new BasicColumnDefinition(); - sha1Column.setName( StringSerializer.get().toByteBuffer( SHA1.toString() ) ); - sha1Column.setIndexName( SHA1.toString() ); - sha1Column.setIndexType( ColumnIndexType.KEYS ); - sha1Column.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - artifactMetadataModel.addColumnDefinition( sha1Column ); - - BasicColumnDefinition md5Column = new BasicColumnDefinition(); - md5Column.setName( StringSerializer.get().toByteBuffer( MD5.toString() ) ); - md5Column.setIndexName( MD5.toString() ); - md5Column.setIndexType( ColumnIndexType.KEYS ); - md5Column.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - artifactMetadataModel.addColumnDefinition( md5Column ); - - - } - - // metadatafacetmodel table - { - final ColumnFamilyDefinition metadataFacetModel = - HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), // - getMetadataFacetFamilyName(), // - ComparatorType.UTF8TYPE ); - cfds.add( metadataFacetModel ); - - // creating indexes for cql query - - BasicColumnDefinition facetIdColumn = new BasicColumnDefinition(); - facetIdColumn.setName( StringSerializer.get().toByteBuffer( FACET_ID.toString() ) ); - facetIdColumn.setIndexName( FACET_ID.toString() ); - facetIdColumn.setIndexType( ColumnIndexType.KEYS ); - facetIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - metadataFacetModel.addColumnDefinition( facetIdColumn ); - - BasicColumnDefinition repositoryNameColumn = new BasicColumnDefinition(); - repositoryNameColumn.setName( StringSerializer.get().toByteBuffer( REPOSITORY_NAME.toString() ) ); - repositoryNameColumn.setIndexName( REPOSITORY_NAME.toString() ); - repositoryNameColumn.setIndexType( ColumnIndexType.KEYS ); - repositoryNameColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - metadataFacetModel.addColumnDefinition( repositoryNameColumn ); - - BasicColumnDefinition nameColumn = new BasicColumnDefinition(); - nameColumn.setName( StringSerializer.get().toByteBuffer( NAME.toString() ) ); - nameColumn.setIndexName( NAME.toString() ); - nameColumn.setIndexType( ColumnIndexType.KEYS ); - nameColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - metadataFacetModel.addColumnDefinition( nameColumn ); - - BasicColumnDefinition namespaceColumn = new BasicColumnDefinition(); - namespaceColumn.setName( StringSerializer.get().toByteBuffer( NAMESPACE_ID.toString() ) ); - namespaceColumn.setIndexName( NAMESPACE_ID.toString() ); - namespaceColumn.setIndexType( ColumnIndexType.KEYS ); - namespaceColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - metadataFacetModel.addColumnDefinition( namespaceColumn ); - - BasicColumnDefinition projectIdColumn = new BasicColumnDefinition(); - projectIdColumn.setName( StringSerializer.get().toByteBuffer( PROJECT_ID.toString() ) ); - projectIdColumn.setIndexName( PROJECT_ID.toString() ); - projectIdColumn.setIndexType( ColumnIndexType.KEYS ); - projectIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - metadataFacetModel.addColumnDefinition( projectIdColumn ); - - BasicColumnDefinition projectVersionColumn = new BasicColumnDefinition(); - projectVersionColumn.setName( StringSerializer.get().toByteBuffer( PROJECT_VERSION.toString() ) ); - projectVersionColumn.setIndexName( PROJECT_VERSION.toString() ); - projectVersionColumn.setIndexType( ColumnIndexType.KEYS ); - projectVersionColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - metadataFacetModel.addColumnDefinition( projectVersionColumn ); - - } - - // Checksum table - { - final ColumnFamilyDefinition checksumCf = - HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), // - getChecksumFamilyName(), // - ComparatorType.UTF8TYPE ); - - BasicColumnDefinition artifactMetatadaModel_key = new BasicColumnDefinition(); - artifactMetatadaModel_key.setName( StringSerializer.get().toByteBuffer( "artifactMetadataModel.key" ) ); - artifactMetatadaModel_key.setIndexName( "artifactMetadataModel_key" ); - artifactMetatadaModel_key.setIndexType( ColumnIndexType.KEYS ); - artifactMetatadaModel_key.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - checksumCf.addColumnDefinition( artifactMetatadaModel_key ); - - - BasicColumnDefinition checksumAlgorithmColumn = new BasicColumnDefinition(); - checksumAlgorithmColumn.setName( StringSerializer.get().toByteBuffer( CHECKSUM_ALG.toString() ) ); - checksumAlgorithmColumn.setIndexName( CHECKSUM_ALG.toString() ); - checksumAlgorithmColumn.setIndexType( ColumnIndexType.KEYS ); - checksumAlgorithmColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - checksumCf.addColumnDefinition( checksumAlgorithmColumn ); - - BasicColumnDefinition checksumValueColumn = new BasicColumnDefinition(); - checksumValueColumn.setName( StringSerializer.get().toByteBuffer( CHECKSUM_VALUE.toString() ) ); - checksumValueColumn.setIndexName( CHECKSUM_VALUE.toString() ); - checksumValueColumn.setIndexType( ColumnIndexType.KEYS ); - checksumValueColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - checksumCf.addColumnDefinition( checksumValueColumn ); - - BasicColumnDefinition repositoryNameColumn = new BasicColumnDefinition(); - repositoryNameColumn.setName( StringSerializer.get().toByteBuffer( REPOSITORY_NAME.toString() ) ); - repositoryNameColumn.setIndexName( REPOSITORY_NAME.toString() ); - repositoryNameColumn.setIndexType( ColumnIndexType.KEYS ); - repositoryNameColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - checksumCf.addColumnDefinition( repositoryNameColumn ); - - - cfds.add( checksumCf ); - - // creating indexes for cql query - - } - - // mailinglist table - { - final ColumnFamilyDefinition mailingListCf = - HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), // - getMailingListFamilyName(), // - ComparatorType.UTF8TYPE ); - - BasicColumnDefinition projectVersionMetadataModel_key = new BasicColumnDefinition(); - projectVersionMetadataModel_key.setName( StringSerializer.get().toByteBuffer( "projectVersionMetadataModel.key" ) ); - projectVersionMetadataModel_key.setIndexName( "projectVersionMetadataModel_key" ); - projectVersionMetadataModel_key.setIndexType( ColumnIndexType.KEYS ); - projectVersionMetadataModel_key.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - mailingListCf.addColumnDefinition( projectVersionMetadataModel_key ); - - cfds.add( mailingListCf ); - - // creating indexes for cql query - - } - - // license table - { - final ColumnFamilyDefinition licenseCf = - HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), // - getLicenseFamilyName(), // - ComparatorType.UTF8TYPE ); - - BasicColumnDefinition projectVersionMetadataModel_key = new BasicColumnDefinition(); - projectVersionMetadataModel_key.setName( StringSerializer.get().toByteBuffer( "projectVersionMetadataModel.key" ) ); - projectVersionMetadataModel_key.setIndexName( "projectVersionMetadataModel_key" ); - projectVersionMetadataModel_key.setIndexType( ColumnIndexType.KEYS ); - projectVersionMetadataModel_key.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - licenseCf.addColumnDefinition( projectVersionMetadataModel_key ); - - cfds.add( licenseCf ); - - // creating indexes for cql query - - } - - // dependency table - { - final ColumnFamilyDefinition dependencyCf = - HFactory.createColumnFamilyDefinition( keyspace.getKeyspaceName(), // - getDependencyFamilyName(), // - ComparatorType.UTF8TYPE ); - cfds.add( dependencyCf ); - - // creating indexes for cql query - - BasicColumnDefinition groupIdColumn = new BasicColumnDefinition(); - groupIdColumn.setName( StringSerializer.get().toByteBuffer( GROUP_ID.toString() ) ); - groupIdColumn.setIndexName( "groupIdIdx" ); - groupIdColumn.setIndexType( ColumnIndexType.KEYS ); - groupIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - dependencyCf.addColumnDefinition( groupIdColumn ); - - BasicColumnDefinition projectVersionMetadataModel_key = new BasicColumnDefinition(); - projectVersionMetadataModel_key.setName( StringSerializer.get().toByteBuffer( "projectVersionMetadataModel.key" ) ); - projectVersionMetadataModel_key.setIndexName( "projectVersionMetadataModel_key" ); - projectVersionMetadataModel_key.setIndexType( ColumnIndexType.KEYS ); - projectVersionMetadataModel_key.setValidationClass( ComparatorType.UTF8TYPE.getClassName() ); - dependencyCf.addColumnDefinition( projectVersionMetadataModel_key ); - - } - - // 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 ) - { - logger.info( "Creating Archiva Cassandra '{}' keyspace.", keyspaceName ); - cluster.addKeyspace( HFactory.createKeyspaceDefinition( keyspaceName, // - ThriftKsDef.DEF_STRATEGY_CLASS, // - replicationFactor, // - cfds ) - ); - } - } - - } - - @Override - public void start() - { - } - - @PreDestroy - @Override - public void shutdown() - { - } - - - @Override - public boolean started() - { - return started; - } - - - @Override - public Keyspace getKeyspace() - { - return keyspace; - } - - @Override - public Cluster getCluster() - { - return cluster; - } - - @Override - public String getRepositoryFamilyName() - { - return repositoryFamilyName; - } - - @Override - public String getNamespaceFamilyName() - { - return namespaceFamilyName; - } - - @Override - public String getProjectFamilyName() - { - return projectFamilyName; - } - - @Override - public String getProjectVersionMetadataFamilyName() - { - return projectVersionMetadataFamilyName; - } - - @Override - public String getArtifactMetadataFamilyName() - { - return artifactMetadataFamilyName; - } - - @Override - public String getMetadataFacetFamilyName() - { - return metadataFacetFamilyName; - } - - @Override - public String getMailingListFamilyName() - { - return mailingListFamilyName; - } - - @Override - public String getLicenseFamilyName() - { - return licenseFamilyName; - } - - @Override - public String getDependencyFamilyName() - { - return dependencyFamilyName; - } - - @Override - public String getChecksumFamilyName() { - return checksumFamilyName; - } -} diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/ArtifactMetadataModel.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/ArtifactMetadataModel.java deleted file mode 100644 index 64ba9a37e..000000000 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/ArtifactMetadataModel.java +++ /dev/null @@ -1,308 +0,0 @@ -package org.apache.archiva.metadata.repository.cassandra.model; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.metadata.repository.cassandra.CassandraUtils; - -import java.io.Serializable; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; - -import static org.apache.archiva.metadata.repository.cassandra.model.ColumnNames.*; - -/** - * Cassandra storage model for {@link org.apache.archiva.metadata.model.ArtifactMetadata} - * - * @author Olivier Lamy - * @since 2.0.0 - */ -public class ArtifactMetadataModel - implements Serializable -{ - - public final static String[] COLUMNS = new String[] { ID.toString(), REPOSITORY_NAME.toString(), - NAMESPACE_ID.toString(), PROJECT.toString(), PROJECT_VERSION.toString(), VERSION.toString(), - FILE_LAST_MODIFIED.toString(), SIZE.toString(), MD5.toString(), SHA1.toString(), WHEN_GATHERED.toString() }; - - private String id; - - private String repositoryId; - - private String namespace; - - private String project; - - private String projectVersion; - - private String version; - - private long fileLastModified; - - private long size; - - private String md5; - - private String sha1; - - private long whenGathered; - - private Map<String, String> checksums = new HashMap<>(); - - public ArtifactMetadataModel() - { - // no op - } - - public ArtifactMetadataModel( String id, String repositoryId, String namespace, String project, - String projectVersion, String version, Date fileLastModified, long size, String md5, - String sha1, Date whenGathered ) - { - this.id = id; - this.repositoryId = repositoryId; - this.namespace = namespace; - this.project = project; - this.projectVersion = projectVersion; - this.version = version; - this.fileLastModified = ( fileLastModified != null ? fileLastModified.getTime() : 0 ); - this.size = size; - this.md5 = md5; - this.sha1 = sha1; - this.whenGathered = whenGathered != null ? whenGathered.getTime() : new Date().getTime(); - } - - - public String getId() - { - return id; - } - - public void setId( String id ) - { - this.id = id; - } - - public String getRepositoryId() - { - return repositoryId; - } - - public void setRepositoryId( String repositoryId ) - { - this.repositoryId = repositoryId; - } - - public String getNamespace() - { - return namespace; - } - - public void setNamespace( String namespace ) - { - this.namespace = namespace; - } - - public String getProject() - { - return project; - } - - public void setProject( String project ) - { - this.project = project; - } - - public String getProjectVersion() - { - return projectVersion; - } - - public void setProjectVersion( String projectVersion ) - { - this.projectVersion = projectVersion; - } - - public String getVersion() - { - return version; - } - - public void setVersion( String version ) - { - this.version = version; - } - - public long getFileLastModified() - { - return fileLastModified; - } - - public void setFileLastModified( long fileLastModified ) - { - this.fileLastModified = fileLastModified; - } - - public long getSize() - { - return size; - } - - public void setSize( long size ) - { - this.size = size; - } - - public String getMd5() - { - return md5; - } - - public void setMd5( String md5 ) - { - this.md5 = md5; - } - - public String getSha1() - { - return sha1; - } - - public void setSha1( String sha1 ) - { - this.sha1 = sha1; - } - - public Date getWhenGathered() - { - return new Date( whenGathered ); - } - - public void setWhenGathered( long whenGathered ) - { - this.whenGathered = whenGathered; - } - - public void setChecksum(String type, String value) { - this.checksums.put(type, value); - } - - public String getChecksum(String type) { - return this.checksums.get(type); - } - - public void setChecksums(Map<String,String> checksums) { - this.checksums = checksums; - } - - public Map<String,String> getChecksums() { - return this.checksums; - } - - - @Override - public String toString() - { - final StringBuilder sb = new StringBuilder( "ArtifactMetadataModel{" ); - sb.append( ", id='" ).append( id ).append( '\'' ); - sb.append( ", repositoryId='" ).append( repositoryId ).append( '\'' ); - sb.append( ", namespace='" ).append( namespace ).append( '\'' ); - sb.append( ", project='" ).append( project ).append( '\'' ); - sb.append( ", projectVersion='" ).append( projectVersion ).append( '\'' ); - sb.append( ", version='" ).append( version ).append( '\'' ); - sb.append( ", fileLastModified=" ).append( fileLastModified ); - sb.append( ", size=" ).append( size ); - sb.append( ", md5='" ).append( md5 ).append( '\'' ); - sb.append( ", sha1='" ).append( sha1 ).append( '\'' ); - sb.append( ", whenGathered=" ).append( whenGathered ); - sb.append( '}' ); - return sb.toString(); - } - - public static class KeyBuilder - { - - private String project; - - private String id; - - private String namespaceId; - - private String repositoryId; - - private String projectVersion; - - public KeyBuilder() - { - - } - - public KeyBuilder withId( String id ) - { - this.id = id; - return this; - } - - - public KeyBuilder withNamespace( Namespace namespace ) - { - this.namespaceId = namespace.getName(); - this.repositoryId = namespace.getRepository().getName(); - return this; - } - - public KeyBuilder withNamespace( String namespaceId ) - { - this.namespaceId = namespaceId; - return this; - } - - public KeyBuilder withProject( String project ) - { - this.project = project; - return this; - } - - public KeyBuilder withProjectVersion( String projectVersion ) - { - this.projectVersion = projectVersion; - return this; - } - - public KeyBuilder withRepositoryId( String repositoryId ) - { - this.repositoryId = repositoryId; - return this; - } - - public String build() - { - //repositoryId + namespaceId + project + projectVersion + id - // FIXME add some controls - - String str = - CassandraUtils.generateKey( this.repositoryId, this.namespaceId, this.project, this.projectVersion, - this.id ); - - //return Long.toString( str.hashCode() ); - return str; - } - } - -} diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/ColumnNames.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/ColumnNames.java deleted file mode 100644 index 8ea2f389f..000000000 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/ColumnNames.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.apache.archiva.metadata.repository.cassandra.model; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/** - * Cassandra column names - * - * @author carlos@apache.org - */ -public enum ColumnNames -{ - FACET_ID( "facetId" ), - REPOSITORY_NAME( "repositoryName" ), - NAME( "name" ), - NAMESPACE_ID( "namespaceId" ), - PROJECT_ID( "projectId" ), - PROJECT_VERSION( "projectVersion" ), - KEY( "facetKey" ), - VALUE( "value" ), - ID( "id" ), - SIZE( "size" ), - MD5( "md5" ), - SHA1( "sha1" ), - PROJECT( "project" ), - FILE_LAST_MODIFIED( "fileLastModified" ), - VERSION( "version" ), - GROUP_ID( "groupId" ), - ARTIFACT_ID( "artifactId" ), - DESCRIPTION( "description" ), - URL( "url" ), - WHEN_GATHERED( "whenGathered" ), - CHECKSUM_ALG("checksumAlgorithm"), - CHECKSUM_VALUE("checksumValue"); - - private final String name; - - private ColumnNames( String name ) - { - this.name = name; - } - - @Override - public String toString() - { - return name; - } - -} diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/MetadataFacetModel.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/MetadataFacetModel.java deleted file mode 100644 index 36b75aafb..000000000 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/MetadataFacetModel.java +++ /dev/null @@ -1,194 +0,0 @@ -package org.apache.archiva.metadata.repository.cassandra.model; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.metadata.repository.cassandra.CassandraUtils; - -import static org.apache.archiva.metadata.repository.cassandra.model.ColumnNames.*; - -/** - * Cassandra storage model for {@link org.apache.archiva.metadata.model.MetadataFacet} - * - * @author Olivier Lamy - * @since 2.0.0 - */ -public class MetadataFacetModel -{ - public static final String[] COLUMNS = new String[] { FACET_ID.toString(), KEY.toString(), VALUE.toString(), - REPOSITORY_NAME.toString(), NAMESPACE_ID.toString(), PROJECT_ID.toString(), PROJECT_VERSION.toString() }; - - private String facetId; - - private String key; - - private String name; - - private String value; - - private String projectVersion; - - public MetadataFacetModel() - { - // no op - } - - public MetadataFacetModel( String facetId, String key, String value, String name, String projectVersion ) - { - this.key = key; - this.value = value; - this.name = name; - this.facetId = facetId; - this.projectVersion = projectVersion; - } - - public String getFacetId() - { - return facetId; - } - - public void setFacetId( String facetId ) - { - this.facetId = facetId; - } - - - public String getName() - { - return name; - } - - public void setName( String name ) - { - this.name = name; - } - - public String getKey() - { - return key; - } - - public void setKey( String key ) - { - this.key = key; - } - - public String getValue() - { - return value; - } - - public void setValue( String value ) - { - this.value = value; - } - - public String getProjectVersion() - { - return projectVersion; - } - - public void setProjectVersion( String projectVersion ) - { - this.projectVersion = projectVersion; - } - - @Override - public String toString() - { - final StringBuilder sb = new StringBuilder( "MetadataFacetModel{" ); - sb.append( ", key='" ).append( key ).append( '\'' ); - sb.append( ", value='" ).append( value ).append( '\'' ); - sb.append( '}' ); - return sb.toString(); - } - - public static class KeyBuilder - { - - private ArtifactMetadataModel artifactMetadataModel; - - private String key; - - private String name; - - private String facetId; - - private String repositoryId; - - public KeyBuilder() - { - - } - - public KeyBuilder withArtifactMetadataModel( ArtifactMetadataModel artifactMetadataModel ) - { - this.artifactMetadataModel = artifactMetadataModel; - return this; - } - - public KeyBuilder withKey( String key ) - { - this.key = key; - return this; - } - - public KeyBuilder withName( String name ) - { - this.name = name; - return this; - } - - public KeyBuilder withFacetId( String facetId ) - { - this.facetId = facetId; - return this; - } - - public KeyBuilder withRepositoryId( String repositoryId ) - { - this.repositoryId = repositoryId; - return this; - } - - public String build() - { - // FIXME add some controls - // getArtifactMetadataModelId can have no namespace, no project and no projectid for statistics - // only repositoryId with artifactMetadataModel - String str = CassandraUtils.generateKey( this.artifactMetadataModel == null - ? this.repositoryId - : new ArtifactMetadataModel.KeyBuilder().withNamespace( - this.artifactMetadataModel.getNamespace() ) // - .withProject( this.artifactMetadataModel.getProject() ) // - .withProjectVersion( - this.artifactMetadataModel.getProjectVersion() ) // - .withRepositoryId( - this.artifactMetadataModel.getRepositoryId() ) // - .withId( this.artifactMetadataModel.getId() ) // - .build(), // - this.facetId, // - this.name, // - this.key - ); - - return str; - } - } -} diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/Namespace.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/Namespace.java deleted file mode 100644 index 390e7e90f..000000000 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/Namespace.java +++ /dev/null @@ -1,153 +0,0 @@ -package org.apache.archiva.metadata.repository.cassandra.model; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.metadata.repository.cassandra.CassandraUtils; - -import java.io.Serializable; - - -/** - * @author Olivier Lamy - * @since 2.0.0 - */ -public class Namespace - implements Serializable -{ - - private String name; - - private String repositoryName; - - public Namespace() - { - // no op - } - - - public Namespace( String id, Repository repository ) - { - this.name = id; - this.repositoryName = repository.getName(); - } - - - public String getName() - { - return name; - } - - public void setName( String name ) - { - this.name = name; - } - - public Repository getRepository() - { - return new Repository( this.repositoryName ); - } - - public void setRepository( Repository repository ) - { - this.repositoryName = repository.getName(); - } - - @Override - public boolean equals( Object o ) - { - if ( this == o ) - { - return true; - } - if ( o == null || getClass() != o.getClass() ) - { - return false; - } - - Namespace namespace = (Namespace) o; - - if ( !name.equals( namespace.name ) ) - { - return false; - } - if ( !repositoryName.equals( namespace.repositoryName ) ) - { - return false; - } - - return true; - } - - @Override - public int hashCode() - { - int result = name.hashCode(); - result = 31 * result + repositoryName.hashCode(); - return result; - } - - @Override - public String toString() - { - final StringBuilder sb = new StringBuilder( "Namespace{" ); - sb.append( ", name='" ).append( name ).append( '\'' ); - sb.append( ", repository='" ).append( repositoryName ).append( '\'' ); - sb.append( '}' ); - return sb.toString(); - } - - public static class KeyBuilder - { - - private String namespace; - - private String repositoryId; - - public KeyBuilder() - { - - } - - public KeyBuilder withNamespace( Namespace namespace ) - { - this.namespace = namespace.getName(); - this.repositoryId = namespace.getRepository().getName(); - return this; - } - - public KeyBuilder withNamespace( String namespace ) - { - this.namespace = namespace; - return this; - } - - public KeyBuilder withRepositoryId( String repositoryId ) - { - this.repositoryId = repositoryId; - return this; - } - - public String build() - { - // FIXME add some controls - return CassandraUtils.generateKey( this.repositoryId, this.namespace ); - } - } -} diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/Project.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/Project.java deleted file mode 100644 index 656e9099f..000000000 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/Project.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.apache.archiva.metadata.repository.cassandra.model; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.metadata.repository.cassandra.CassandraUtils; - -import java.io.Serializable; - -/** - * @author Olivier Lamy - * @since 2.0.0 - */ -public class Project - implements Serializable -{ - - public static class KeyBuilder - { - - private Namespace namespace; - - private String projectId; - - public KeyBuilder() - { - // no op - } - - public KeyBuilder withNamespace( Namespace namespace ) - { - this.namespace = namespace; - return this; - } - - public KeyBuilder withProjectId( String projectId ) - { - this.projectId = projectId; - return this; - } - - - public String build() - { - // FIXME add some controls - return CassandraUtils.generateKey( new Namespace.KeyBuilder().withNamespace( this.namespace ).build(), - this.projectId ); - } - } -} diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/ProjectVersionMetadataModel.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/ProjectVersionMetadataModel.java deleted file mode 100644 index 5b508b12b..000000000 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/ProjectVersionMetadataModel.java +++ /dev/null @@ -1,292 +0,0 @@ -package org.apache.archiva.metadata.repository.cassandra.model; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.metadata.model.CiManagement; -import org.apache.archiva.metadata.model.Dependency; -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.Organization; -import org.apache.archiva.metadata.model.Scm; -import org.apache.archiva.metadata.repository.cassandra.CassandraUtils; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author Olivier Lamy - * @since 2.0.0 - */ -public class ProjectVersionMetadataModel -{ - private Namespace namespace; - - private String id; - - private String projectId; - - private String url; - - private String name; - - private String description; - - private Organization organization; - - private IssueManagement issueManagement; - - private Scm scm; - - private CiManagement ciManagement; - - private List<License> licenses = new ArrayList<>(); - - private List<MailingList> mailingLists = new ArrayList<>(); - - private List<Dependency> dependencies = new ArrayList<>(); - - private boolean incomplete; - - public String getProjectId() - { - return projectId; - } - - public void setProjectId( String projectId ) - { - this.projectId = projectId; - } - - // FIXME must be renamed getVersion !!! - public String getId() - { - return id; - } - - public void setId( String id ) - { - this.id = id; - } - - public String getUrl() - { - return url; - } - - public void setUrl( String url ) - { - this.url = url; - } - - public String getName() - { - return name; - } - - public void setName( String name ) - { - this.name = name; - } - - public String getDescription() - { - return description; - } - - public void setDescription( String description ) - { - this.description = description; - } - - public Organization getOrganization() - { - return organization; - } - - public void setOrganization( Organization organization ) - { - this.organization = organization; - } - - public IssueManagement getIssueManagement() - { - return issueManagement; - } - - public void setIssueManagement( IssueManagement issueManagement ) - { - this.issueManagement = issueManagement; - } - - public Scm getScm() - { - return scm; - } - - public void setScm( Scm scm ) - { - this.scm = scm; - } - - public CiManagement getCiManagement() - { - return ciManagement; - } - - public void setCiManagement( CiManagement ciManagement ) - { - this.ciManagement = ciManagement; - } - - public boolean isIncomplete() - { - return incomplete; - } - - public void setIncomplete( boolean incomplete ) - { - this.incomplete = incomplete; - } - - public Namespace getNamespace() - { - return namespace; - } - - public void setNamespace( Namespace namespace ) - { - this.namespace = namespace; - } - - public List<License> getLicenses() - { - return licenses; - } - - public void setLicenses( List<License> licenses ) - { - this.licenses = licenses; - } - - public List<MailingList> getMailingLists() - { - return mailingLists; - } - - public void setMailingLists( List<MailingList> mailingLists ) - { - this.mailingLists = mailingLists; - } - - public List<Dependency> getDependencies() - { - return dependencies; - } - - public void setDependencies( List<Dependency> dependencies ) - { - this.dependencies = dependencies; - } - - - @Override - public String toString() - { - final StringBuilder sb = new StringBuilder( "ProjectVersionMetadataModel{" ); - sb.append( ", namespace=" ).append( namespace ); - sb.append( ", id='" ).append( id ).append( '\'' ); - sb.append( ", projectId='" ).append( projectId ).append( '\'' ); - sb.append( ", url='" ).append( url ).append( '\'' ); - sb.append( ", name='" ).append( name ).append( '\'' ); - sb.append( ", description='" ).append( description ).append( '\'' ); - sb.append( ", organization=" ).append( organization ); - sb.append( ", issueManagement=" ).append( issueManagement ); - sb.append( ", scm=" ).append( scm ); - sb.append( ", ciManagement=" ).append( ciManagement ); - sb.append( ", incomplete=" ).append( incomplete ); - sb.append( '}' ); - return sb.toString(); - } - - - public static class KeyBuilder - { - - private String namespace; - - private String repositoryName; - - private String projectId; - - private String projectVersion; - - private String id; - - public KeyBuilder() - { - // no op - } - - public KeyBuilder withNamespace( Namespace namespace ) - { - this.namespace = namespace.getName(); - this.repositoryName = namespace.getRepository().getName(); - return this; - } - - public KeyBuilder withNamespace( String namespace ) - { - this.namespace = namespace; - return this; - } - - public KeyBuilder withRepository( String repositoryId ) - { - this.repositoryName = repositoryId; - return this; - } - - public KeyBuilder withProjectId( String projectId ) - { - this.projectId = projectId; - return this; - } - - public KeyBuilder withProjectVersion( String projectVersion ) - { - this.projectVersion = projectVersion; - return this; - } - - public KeyBuilder withId( String id ) - { - this.id = id; - return this; - } - - public String build() - { - // FIXME add some controls - return CassandraUtils.generateKey( this.repositoryName, this.namespace, this.projectId, this.projectVersion, - this.id ); - } - } -} diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/Repository.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/Repository.java deleted file mode 100644 index 402fa8a63..000000000 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/Repository.java +++ /dev/null @@ -1,91 +0,0 @@ -package org.apache.archiva.metadata.repository.cassandra.model; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.Serializable; - - -/** - * @author Olivier Lamy - * @since 2.0.0 - */ -public class Repository - implements Serializable -{ - - - private String name; - - public Repository() - { - // no op - } - - public Repository( String name ) - { - this.name = name; - } - - public String getName() - { - return name; - } - - public void setName( String name ) - { - this.name = name; - } - - @Override - public boolean equals( Object o ) - { - if ( this == o ) - { - return true; - } - if ( o == null || getClass() != o.getClass() ) - { - return false; - } - - Repository that = (Repository) o; - - if ( !name.equals( that.name ) ) - { - return false; - } - - return true; - } - - @Override - public int hashCode() - { - return name.hashCode(); - } - - @Override - public String toString() - { - return "Repository{" + - "name='" + name + '\'' + - '}'; - } -} diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/resources/META-INF/spring-context.xml b/archiva-modules/plugins/metadata-store-cassandra/src/main/resources/META-INF/spring-context.xml deleted file mode 100644 index 805ef8ce4..000000000 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/resources/META-INF/spring-context.xml +++ /dev/null @@ -1,43 +0,0 @@ -<?xml version="1.0"?> - -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one - ~ or more contributor license agreements. See the NOTICE file - ~ distributed with this work for additional information - ~ regarding copyright ownership. The ASF licenses this file - ~ to you under the Apache License, Version 2.0 (the - ~ "License"); you may not use this file except in compliance - ~ with the License. You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, - ~ software distributed under the License is distributed on an - ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - ~ KIND, either express or implied. See the License for the - ~ specific language governing permissions and limitations - ~ under the License. - --> -<beans xmlns="http://www.springframework.org/schema/beans" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:context="http://www.springframework.org/schema/context" - xsi:schemaLocation="http://www.springframework.org/schema/beans - http://www.springframework.org/schema/beans/spring-beans-3.0.xsd - http://www.springframework.org/schema/context - http://www.springframework.org/schema/context/spring-context-3.0.xsd" - default-lazy-init="true"> - - <context:annotation-config/> - <context:component-scan base-package="org.apache.archiva.metadata.repository.cassandra"/> - - <context:property-placeholder location="classpath:default-archiva-cassandra.properties" - system-properties-mode="OVERRIDE" - order="2"/> - - <context:property-placeholder location="file:${archiva.cassandra.configuration.file}" - ignore-resource-not-found="true" - ignore-unresolvable="true" - system-properties-mode="OVERRIDE" - order="1"/> - -</beans>
\ No newline at end of file diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/resources/default-archiva-cassandra.properties b/archiva-modules/plugins/metadata-store-cassandra/src/main/resources/default-archiva-cassandra.properties deleted file mode 100644 index e55a955b8..000000000 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/resources/default-archiva-cassandra.properties +++ /dev/null @@ -1,28 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -cassandra.host=localhost -cassandra.port=9160 -cassandra.maxActive=20 -cassandra.readConsistencyLevel=QUORUM -cassandra.writeConsistencyLevel=QUORUM -cassandra.replicationFactor=1 -cassandra.keyspace.name=ArchivaKeySpace -cassandra.cluster.name=archiva - -archiva.cassandra.configuration.file=./archiva-cassandra.properties
\ No newline at end of file diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/test/filtered-resources/META-INF/spring-context.xml b/archiva-modules/plugins/metadata-store-cassandra/src/test/filtered-resources/META-INF/spring-context.xml deleted file mode 100644 index 49f80f869..000000000 --- a/archiva-modules/plugins/metadata-store-cassandra/src/test/filtered-resources/META-INF/spring-context.xml +++ /dev/null @@ -1,29 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one - ~ or more contributor license agreements. See the NOTICE file - ~ distributed with this work for additional information - ~ regarding copyright ownership. The ASF licenses this file - ~ to you under the Apache License, Version 2.0 (the - ~ "License"); you may not use this file except in compliance - ~ with the License. You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, - ~ software distributed under the License is distributed on an - ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - ~ KIND, either express or implied. See the License for the - ~ specific language governing permissions and limitations - ~ under the License. - --> - -<beans xmlns="http://www.springframework.org/schema/beans" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> - - <bean name="repositoryStorage#maven2" class="org.apache.archiva.metadata.repository.cassandra.MockRepositoryStorage"/> - - <bean name="mockrepo#listener" class="org.apache.archiva.metadata.repository.cassandra.MockRepositoryStorage"/> - -</beans>
\ No newline at end of file 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 deleted file mode 100644 index ea03801c5..000000000 --- a/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java +++ /dev/null @@ -1,182 +0,0 @@ -package org.apache.archiva.metadata.repository.cassandra; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.metadata.model.MetadataFacetFactory; -import org.apache.archiva.metadata.repository.AbstractMetadataRepositoryTest; -import org.apache.archiva.metadata.repository.MetadataRepository; -import org.apache.archiva.metadata.repository.MetadataService; -import org.apache.archiva.metadata.repository.RepositorySession; -import org.apache.archiva.metadata.repository.RepositorySessionFactory; -import org.apache.archiva.metadata.repository.cassandra.model.ProjectVersionMetadataModel; -import org.easymock.EasyMock; -import org.easymock.IMocksControl; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import javax.inject.Inject; -import javax.inject.Named; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Olivier Lamy - */ -public class CassandraMetadataRepositoryTest - extends AbstractMetadataRepositoryTest -{ - @Inject - @Named(value = "archivaEntityManagerFactory#cassandra") - CassandraArchivaManager cassandraArchivaManager; - - CassandraMetadataRepository cmr; - - IMocksControl sessionFactoryControl; - RepositorySessionFactory sessionFactory; - - IMocksControl sessionControl; - RepositorySession session; - - - - @Override - protected RepositorySessionFactory getSessionFactory( ) - { - return sessionFactory; - } - - @Override - protected MetadataRepository getRepository( ) - { - return cmr; - } - - @Before - @Override - public void setUp() - throws Exception - { - - super.setUp(); - assertMaxTries =1; - assertRetrySleepMs=10; - - Path directory = Paths.get( "target/test-repositories" ); - if ( Files.exists(directory) ) - { - org.apache.archiva.common.utils.FileUtils.deleteDirectory( directory ); - } - - List<MetadataFacetFactory> factories = createTestMetadataFacetFactories(); - MetadataService metadataService = new MetadataService( ); - metadataService.setMetadataFacetFactories( factories ); - - this.cmr = new CassandraMetadataRepository( metadataService, cassandraArchivaManager ); - - sessionFactoryControl = EasyMock.createControl( ); - sessionFactory = sessionFactoryControl.createMock( RepositorySessionFactory.class ); - sessionControl = EasyMock.createControl( ); - session = sessionControl.createMock( RepositorySession.class ); - - EasyMock.expect( sessionFactory.createSession( ) ).andStubReturn( session ); - - sessionFactoryControl.replay(); - - clearReposAndNamespace( cassandraArchivaManager ); - } - - /** - * ensure all dependant tables are cleaned up (mailinglist, license, dependencies) - * - * @throws Exception - */ - @Test - public void clean_dependant_tables() - throws Exception - { - - super.testUpdateProjectVersionMetadataWithAllElements(); - - String key = new ProjectVersionMetadataModel.KeyBuilder().withRepository( TEST_REPO_ID ) // - .withNamespace( TEST_NAMESPACE ) // - .withProjectId( TEST_PROJECT ) // - .withProjectVersion( TEST_PROJECT_VERSION ) // - .withId( TEST_PROJECT_VERSION ) // - .build(); - - this.cmr.removeProjectVersion( null, TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ); - - assertThat( - cmr.getProjectVersion( null , TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ).isNull(); - - assertThat( cmr.getMailingLists( key ) ).isNotNull().isEmpty(); - - assertThat( cmr.getLicenses( key ) ).isNotNull().isEmpty(); - - assertThat( cmr.getDependencies( key ) ).isNotNull().isEmpty(); - } - - - @After - public void shutdown() - throws Exception - { - clearReposAndNamespace( cassandraArchivaManager ); - super.tearDown(); - } - - static void clearReposAndNamespace( CassandraArchivaManager cassandraArchivaManager ) - throws Exception - { - cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(), - cassandraArchivaManager.getProjectFamilyName() ); - - cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(), - cassandraArchivaManager.getNamespaceFamilyName() ); - - cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(), - cassandraArchivaManager.getRepositoryFamilyName() ); - - cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(), - cassandraArchivaManager.getProjectVersionMetadataFamilyName() ); - - cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(), - cassandraArchivaManager.getArtifactMetadataFamilyName() ); - - cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(), - cassandraArchivaManager.getMetadataFacetFamilyName() ); - - cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(), - cassandraArchivaManager.getMailingListFamilyName() ); - - cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(), - cassandraArchivaManager.getLicenseFamilyName() ); - - cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(), - cassandraArchivaManager.getDependencyFamilyName() ); - - } - -} diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/MockRepositoryStorage.java b/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/MockRepositoryStorage.java deleted file mode 100644 index 5c82f6ee5..000000000 --- a/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/MockRepositoryStorage.java +++ /dev/null @@ -1,147 +0,0 @@ -package org.apache.archiva.metadata.repository.cassandra; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.metadata.model.ArtifactMetadata; -import org.apache.archiva.metadata.model.ProjectMetadata; -import org.apache.archiva.metadata.model.ProjectVersionMetadata; -import org.apache.archiva.metadata.repository.MetadataRepository; -import org.apache.archiva.metadata.repository.RepositorySession; -import org.apache.archiva.filter.Filter; -import org.apache.archiva.metadata.repository.storage.ReadMetadataRequest; -import org.apache.archiva.metadata.repository.storage.RelocationException; -import org.apache.archiva.metadata.repository.storage.RepositoryStorage; -import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataException; -import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException; -import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException; -import org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException; -import org.apache.archiva.policies.ProxyDownloadException; -import org.apache.archiva.repository.ManagedRepositoryContent; -import org.apache.archiva.repository.ManagedRepository; -import org.apache.archiva.metadata.audit.RepositoryListener; -import org.apache.archiva.repository.content.ItemSelector; -import org.apache.archiva.xml.XMLException; - -import java.io.IOException; -import java.util.Collection; - -/** - * @author Olivier Lamy - */ -public class MockRepositoryStorage - implements RepositoryStorage, RepositoryListener -{ - @Override - public ProjectMetadata readProjectMetadata( String repoId, String namespace, String projectId ) - { - return null; - } - - @Override - public ProjectVersionMetadata readProjectVersionMetadata( ReadMetadataRequest readMetadataRequest ) - throws RepositoryStorageMetadataInvalidException, RepositoryStorageMetadataNotFoundException, - RepositoryStorageRuntimeException - { - return null; - } - - @Override - public Collection<String> listRootNamespaces( String repoId, Filter<String> filter ) - throws RepositoryStorageRuntimeException - { - return null; - } - - @Override - public Collection<String> listNamespaces( String repoId, String namespace, Filter<String> filter ) - throws RepositoryStorageRuntimeException - { - return null; - } - - @Override - public Collection<String> listProjects( String repoId, String namespace, Filter<String> filter ) - throws RepositoryStorageRuntimeException - { - return null; - } - - @Override - public Collection<String> listProjectVersions( String repoId, String namespace, String projectId, - Filter<String> filter ) - throws RepositoryStorageRuntimeException - { - return null; - } - - @Override - public Collection<ArtifactMetadata> readArtifactsMetadata( ReadMetadataRequest readMetadataRequest ) - throws RepositoryStorageRuntimeException - { - return null; - } - - @Override - public ArtifactMetadata readArtifactMetadataFromPath( String repoId, String path ) - throws RepositoryStorageRuntimeException - { - return null; - } - - @Override - public ItemSelector applyServerSideRelocation( ManagedRepository managedRepository, ItemSelector selector ) throws ProxyDownloadException - { - return null; - } - - @Override - public String getFilePath( String requestPath, org.apache.archiva.repository.ManagedRepository managedRepository ) - { - return null; - } - - @Override - public String getFilePathWithVersion( String requestPath, ManagedRepositoryContent managedRepositoryContent ) - throws RelocationException, XMLException, IOException - { - return null; - } - - @Override - public void deleteArtifact( MetadataRepository metadataRepository, String repositoryId, String namespace, - String project, String version, String id ) - { - - } - - @Override - public void addArtifact( RepositorySession session, String repoId, String namespace, String projectId, - ProjectVersionMetadata metadata ) - { - - } - - @Override - public void addArtifactProblem( RepositorySession session, String repoId, String namespace, String projectId, - String projectVersion, RepositoryStorageMetadataException exception ) - { - - } -} diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/RepositoriesNamespaceTest.java b/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/RepositoriesNamespaceTest.java deleted file mode 100644 index 9a631907f..000000000 --- a/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/RepositoriesNamespaceTest.java +++ /dev/null @@ -1,142 +0,0 @@ -package org.apache.archiva.metadata.repository.cassandra; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.metadata.model.ProjectMetadata; -import org.apache.archiva.metadata.repository.cassandra.model.Namespace; -import org.apache.archiva.metadata.repository.cassandra.model.Repository; -import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.test.context.ContextConfiguration; - -import javax.inject.Inject; -import javax.inject.Named; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Olivier Lamy - */ -@RunWith( ArchivaSpringJUnit4ClassRunner.class ) -@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } ) -public class RepositoriesNamespaceTest -{ - - private Logger logger = LoggerFactory.getLogger( getClass() ); - - @Inject - @Named( value = "archivaEntityManagerFactory#cassandra" ) - CassandraArchivaManager cassandraArchivaManager; - - - CassandraMetadataRepository cmr; - - @Before - public void setup() - throws Exception - { - cmr = new CassandraMetadataRepository( null, cassandraArchivaManager ); - if ( !cassandraArchivaManager.started() ) - { - cassandraArchivaManager.start(); - } - CassandraMetadataRepositoryTest.clearReposAndNamespace( cassandraArchivaManager ); - } - - @After - public void shutdown() - throws Exception - { - CassandraMetadataRepositoryTest.clearReposAndNamespace( cassandraArchivaManager ); - cassandraArchivaManager.shutdown(); - } - - - @Test - public void testMetadataRepo() - throws Exception - { - - Repository r = null; - Namespace n = null; - - try - { - - cmr.updateNamespace( null , "release", "org" ); - - r = cmr.getRepository( "release" ); - - assertThat( r ).isNotNull(); - - assertThat( cmr.getNamespaces( "release" ) ).isNotEmpty().hasSize( 1 ); - - n = cmr.getNamespace( "release", "org" ); - - assertThat( n ).isNotNull(); - assertThat( n.getRepository() ).isNotNull(); - - cmr.updateNamespace( null, "release", "org.apache" ); - - r = cmr.getRepository( "release" ); - - assertThat( r ).isNotNull(); - assertThat( cmr.getNamespaces( "release" ) ).isNotEmpty().hasSize( 2 ); - - cmr.removeNamespace(null , "release", "org.apache" ); - assertThat( cmr.getNamespaces( "release" ) ).isNotEmpty().hasSize( 1 ); - assertThat( cmr.getNamespaces( "release" ) ).containsExactly( "org" ); - - ProjectMetadata projectMetadata = new ProjectMetadata(); - projectMetadata.setId( "theproject" ); - projectMetadata.setNamespace( "org" ); - - cmr.updateProject(null , "release", projectMetadata ); - - assertThat( cmr.getProjects(null , "release", "org" ) ).isNotEmpty().hasSize( 1 ).containsExactly( - "theproject" ); - - cmr.removeProject(null , "release", "org", "theproject" ); - - assertThat( cmr.getProjects(null , "release", "org" ) ).isEmpty(); - - cmr.removeRepository(null , "release" ); - - r = cmr.getRepository( "release" ); - - assertThat( r ).isNull(); - - } - catch ( Exception e ) - { - logger.error( e.getMessage(), e ); - throw e; - } - finally - { - CassandraMetadataRepositoryTest.clearReposAndNamespace( cassandraArchivaManager ); - } - } -} diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/test/resources/log4j2-test.xml b/archiva-modules/plugins/metadata-store-cassandra/src/test/resources/log4j2-test.xml deleted file mode 100644 index a2aad3034..000000000 --- a/archiva-modules/plugins/metadata-store-cassandra/src/test/resources/log4j2-test.xml +++ /dev/null @@ -1,44 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one - ~ or more contributor license agreements. See the NOTICE file - ~ distributed with this work for additional information - ~ regarding copyright ownership. The ASF licenses this file - ~ to you under the Apache License, Version 2.0 (the - ~ "License"); you may not use this file except in compliance - ~ with the License. You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, - ~ software distributed under the License is distributed on an - ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - ~ KIND, either express or implied. See the License for the - ~ specific language governing permissions and limitations - ~ under the License. - --> - - -<configuration status="debug"> - - - - <appenders> - <Console name="console" target="SYSTEM_OUT"> - <!--PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/--> - <PatternLayout pattern="%highlight{%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n}" /> - </Console> - - </appenders> - <loggers> - - - <logger name="org.apache.archiva.metadata.repository.cassandra" level="debug"/> - - <root level="info" includeLocation="true"> - <appender-ref ref="console"/> - </root> - </loggers> -</configuration> - - |