all tests pass so move out metadata-store-cassandra from sandbox

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1491410 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2013-06-10 10:59:20 +00:00
parent db3e35c07c
commit 152cf7cd78
16 changed files with 4158 additions and 0 deletions

View File

@ -0,0 +1,305 @@
<?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>1.4.0-SNAPSHOT</version>
</parent>
<artifactId>metadata-store-cassandra</artifactId>
<packaging>bundle</packaging>
<name>Archiva Core Plugins :: Cassandra JPA Storage for Metadata</name>
<properties>
<cassandraVersion>1.2.5</cassandraVersion>
</properties>
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</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-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>net.sf.beanlib</groupId>
<artifactId>beanlib</artifactId>
<exclusions>
<exclusion>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
</exclusion>
<exclusion>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jpa_2.0_spec</artifactId>
</dependency>
<dependency>
<groupId>com.netflix.astyanax</groupId>
<artifactId>astyanax-entity-mapper</artifactId>
<version>1.56.37</version>
<exclusions>
<exclusion>
<groupId>stax</groupId>
<artifactId>stax-api</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-thrift</artifactId>
</exclusion>
<exclusion>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.netty</groupId>
<artifactId>netty</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.netflix.astyanax</groupId>
<artifactId>astyanax-core</artifactId>
<version>1.56.37</version>
</dependency>
<dependency>
<groupId>com.netflix.astyanax</groupId>
<artifactId>astyanax-thrift</artifactId>
<version>1.56.37</version>
<exclusions>
<exclusion>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-thrift</artifactId>
</exclusion>
</exclusions>
</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.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-assert-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>
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<testResources>
<testResource>
<directory>src/test/filtered-resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<Bundle-SymbolicName>org.apache.archiva.metadata.repository.cassandra</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
<Export-Package>
org.apache.archiva.metadata.repository.cassandra;version=${project.version};-split-package:=merge-first
</Export-Package>
<Import-Package>
</Import-Package>
</instructions>
</configuration>
</plugin>
<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>
</portNames>
</configuration>
</execution>
</executions>
</plugin>
<!-- TODO use dynamic port -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cassandra-maven-plugin</artifactId>
<version>1.2.1-1</version>
<executions>
<execution>
<id>start-cassandra</id>
<phase>test-compile</phase>
<goals>
<goal>start</goal>
</goals>
<configuration>
<rpcPort>${cassandraPort}</rpcPort>
</configuration>
</execution>
<execution>
<id>stop-cassandra</id>
<phase>test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-all</artifactId>
<version>${cassandraVersion}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<cassandraPort>${cassandraPort}</cassandraPort>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<repositories>
<repository>
<id>archiva.snapshots</id>
<url>https://archiva-repository.apache.org/archiva/repository/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</project>

View File

@ -0,0 +1,31 @@
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 com.netflix.astyanax.Keyspace;
/**
* @author Olivier Lamy
*/
public interface CassandraEntityManagerFactory
{
Keyspace getKeyspace();
}

View File

@ -0,0 +1,87 @@
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.model.MetadataFacetFactory;
import org.apache.archiva.metadata.repository.MetadataResolver;
import org.apache.archiva.metadata.repository.RepositorySession;
import org.apache.archiva.metadata.repository.RepositorySessionFactory;
import org.apache.commons.lang.StringUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
import java.util.HashMap;
import java.util.Map;
/**
* @author Olivier Lamy
*/
@Service( "repositorySessionFactory#cassandra" )
public class CassandraRepositorySessionFactory
implements RepositorySessionFactory
{
private Map<String, MetadataFacetFactory> metadataFacetFactories;
@Inject
@Named( value = "archivaConfiguration#default" )
private ArchivaConfiguration configuration;
@Inject
private MetadataResolver metadataResolver;
@Inject
private ApplicationContext applicationContext;
@Inject
private CassandraEntityManagerFactory cassandraEntityManagerFactory;
@PostConstruct
public void initialize()
{
Map<String, MetadataFacetFactory> tmpMetadataFacetFactories =
applicationContext.getBeansOfType( MetadataFacetFactory.class );
// olamy with spring the "id" is now "metadataFacetFactory#hint"
// whereas was only hint with plexus so let remove metadataFacetFactory#
metadataFacetFactories = new HashMap<String, MetadataFacetFactory>( tmpMetadataFacetFactories.size() );
for ( Map.Entry<String, MetadataFacetFactory> entry : tmpMetadataFacetFactories.entrySet() )
{
metadataFacetFactories.put( StringUtils.substringAfterLast( entry.getKey(), "#" ), entry.getValue() );
}
}
@Override
public RepositorySession createSession()
{
CassandraMetadataRepository metadataRepository =
new CassandraMetadataRepository( metadataFacetFactories, configuration,
cassandraEntityManagerFactory.getKeyspace() );
return new RepositorySession( metadataRepository, metadataResolver );
}
}

View File

@ -0,0 +1,95 @@
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 com.google.common.collect.ImmutableMap;
import com.netflix.astyanax.AstyanaxContext;
import com.netflix.astyanax.Keyspace;
import com.netflix.astyanax.connectionpool.NodeDiscoveryType;
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
import com.netflix.astyanax.connectionpool.impl.ConnectionPoolConfigurationImpl;
import com.netflix.astyanax.connectionpool.impl.ConnectionPoolType;
import com.netflix.astyanax.connectionpool.impl.CountingConnectionPoolMonitor;
import com.netflix.astyanax.impl.AstyanaxConfigurationImpl;
import com.netflix.astyanax.thrift.ThriftFamilyFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
/**
* FIXME make all configuration not hardcoded :-)
*
* @author Olivier Lamy
*/
@Service("archivaEntityManagerFactory#cassandra")
public class DefaultCassandraEntityManagerFactory
implements CassandraEntityManagerFactory
{
@Inject
private ApplicationContext applicationContext;
private static final String CLUSTER_NAME = "archiva";
private static final String KEYSPACE_NAME = "ArchivaKeySpace";
private Keyspace keyspace;
private AstyanaxContext<Keyspace> keyspaceContext;
@PostConstruct
public void initialize()
throws ConnectionException
{
String cassandraHost = System.getProperty( "cassandraHost", "localhost" );
String cassandraPort = System.getProperty( "cassandraPort" );
keyspaceContext = new AstyanaxContext.Builder().forCluster( CLUSTER_NAME ).forKeyspace(
KEYSPACE_NAME ).withAstyanaxConfiguration(
new AstyanaxConfigurationImpl().setDiscoveryType( NodeDiscoveryType.RING_DESCRIBE ).setConnectionPoolType(
ConnectionPoolType.TOKEN_AWARE ) ).withConnectionPoolConfiguration(
new ConnectionPoolConfigurationImpl( CLUSTER_NAME + "_" + KEYSPACE_NAME ).setSocketTimeout(
30000 ).setMaxTimeoutWhenExhausted( 2000 ).setMaxConnsPerHost( 20 ).setInitConnsPerHost( 10 ).setSeeds(
cassandraHost + ":" + cassandraPort ) ).withConnectionPoolMonitor(
new CountingConnectionPoolMonitor() ).buildKeyspace( ThriftFamilyFactory.getInstance() );
keyspaceContext.start();
keyspace = keyspaceContext.getClient();
ImmutableMap<String, Object> options = ImmutableMap.<String, Object>builder().put( "strategy_options",
ImmutableMap.<String, Object>builder().put(
"replication_factor",
"1" ).build() ).put(
"strategy_class", "SimpleStrategy" ).build();
keyspace.createKeyspace( options );
}
@Override
public Keyspace getKeyspace()
{
return keyspace;
}
}

View File

@ -0,0 +1,331 @@
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 javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.io.Serializable;
import java.util.Date;
/**
* Cassandra storage model for {@link org.apache.archiva.metadata.model.ArtifactMetadata}
*
* @author Olivier Lamy
*/
@Entity
public class ArtifactMetadataModel
implements Serializable
{
// repositoryId + namespaceId + project + projectVersion + id
@Id
private String artifactMetadataModelId;
@Column(name = "id")
private String id;
@Column(name = "repositoryId")
private String repositoryId;
@Column(name = "namespace")
private String namespace;
@Column(name = "project")
private String project;
@Column(name = "projectVersion")
private String projectVersion;
@Column(name = "version")
private String version;
@Column(name = "fileLastModified")
private long fileLastModified;
@Column(name = "size")
private long size;
@Column(name = "md5")
private String md5;
@Column(name = "sha1")
private String sha1;
@Column(name = "whenGathered")
private long whenGathered;
public ArtifactMetadataModel()
{
// no op
}
public ArtifactMetadataModel( String artifactMetadataModelId, String id, String repositoryId, String namespace,
String project, String projectVersion, String version, Date fileLastModified,
long size, String md5, String sha1, Date whenGathered )
{
this.artifactMetadataModelId = artifactMetadataModelId;
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 getArtifactMetadataModelId()
{
return artifactMetadataModelId;
}
public void setArtifactMetadataModelId( String artifactMetadataModelId )
{
this.artifactMetadataModelId = artifactMetadataModelId;
}
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;
}
@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( o == null || getClass() != o.getClass() )
{
return false;
}
ArtifactMetadataModel that = (ArtifactMetadataModel) o;
if ( !artifactMetadataModelId.equals( that.artifactMetadataModelId ) )
{
return false;
}
return true;
}
@Override
public int hashCode()
{
return artifactMetadataModelId.hashCode();
}
@Override
public String toString()
{
final StringBuilder sb = new StringBuilder( "ArtifactMetadataModel{" );
sb.append( "artifactMetadataModelId='" ).append( artifactMetadataModelId ).append( '\'' );
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().getId();
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
return this.repositoryId + "-" + this.namespaceId + "-" + this.project + "-" + this.projectVersion + "-"
+ this.id;
}
}
}

View File

@ -0,0 +1,229 @@
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 javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
/**
* Cassandra storage model for {@link org.apache.archiva.metadata.model.MetadataFacet}
*
* @author Olivier Lamy
*/
@Entity
public class MetadataFacetModel
{
// id is repositoryId + namespaceId + projectId + facetId + name + mapKey
@Id
@Column( name = "id" )
private String id;
@Column( name = "artifactMetadataModel" )
private ArtifactMetadataModel artifactMetadataModel;
@Column( name = "facetId" )
private String facetId;
@Column( name = "name" )
private String name;
@Column( name = "key" )
private String key;
@Column( name = "value" )
private String value;
public MetadataFacetModel()
{
// no op
}
public MetadataFacetModel( String id, ArtifactMetadataModel artifactMetadataModel, String facetId, String key,
String value, String name )
{
this.id = id;
this.artifactMetadataModel = artifactMetadataModel;
this.key = key;
this.value = value;
this.name = name;
this.facetId = facetId;
}
public String getFacetId()
{
return facetId;
}
public void setFacetId( String facetId )
{
this.facetId = facetId;
}
public String getId()
{
return id;
}
public void setId( String id )
{
this.id = id;
}
public ArtifactMetadataModel getArtifactMetadataModel()
{
return artifactMetadataModel;
}
public void setArtifactMetadataModel( ArtifactMetadataModel artifactMetadataModel )
{
this.artifactMetadataModel = artifactMetadataModel;
}
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;
}
@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( o == null || getClass() != o.getClass() )
{
return false;
}
MetadataFacetModel that = (MetadataFacetModel) o;
if ( !id.equals( that.id ) )
{
return false;
}
return true;
}
@Override
public int hashCode()
{
return id.hashCode();
}
@Override
public String toString()
{
final StringBuilder sb = new StringBuilder( "MetadataFacetModel{" );
sb.append( "id='" ).append( id ).append( '\'' );
sb.append( ", artifactMetadataModel=" ).append( artifactMetadataModel );
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
return ( this.artifactMetadataModel == null
? this.repositoryId
: this.artifactMetadataModel.getArtifactMetadataModelId() ) + "-" + this.facetId + "-" + this.name + "-"
+ this.key;
}
}
}

View File

@ -0,0 +1,190 @@
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 javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.io.Serializable;
/**
* @author Olivier Lamy
*/
@Entity
//@Table( name = "namespace", schema = "ArchivaKeySpace@archiva")
public class Namespace
implements Serializable
{
private static final long serialVersionUID = 1L;
@Id
@Column(name = "id")
private String id;
@Column(name = "name")
private String name;
@Column(name = "repository")
private Repository repository;
//@ManyToOne(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
//@JoinColumn(name = "repository_id")
//private transient Repository repository;
public Namespace()
{
// no op
}
public Namespace( String id, Repository repository )
{
this.id = new KeyBuilder().withNamespace( id ).withRepositoryId( repository.getId() ).build();
this.name = id;
this.repository = repository;
}
public String getId()
{
return id;
}
public void setId( String id )
{
this.id = id;
}
public String getName()
{
return name;
}
public void setName( String name )
{
this.name = name;
}
public Repository getRepository()
{
return repository;
}
public void setRepository( Repository repository )
{
this.repository = repository;
}
/*
public String getRepositoryId()
{
return repositoryId;
}
public void setRepositoryId( String repositoryId )
{
this.repositoryId = repositoryId;
}*/
@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( o == null || getClass() != o.getClass() )
{
return false;
}
Namespace namespace = (Namespace) o;
if ( !id.equals( namespace.id ) )
{
return false;
}
if ( !repository.getId().equals( namespace.repository.getId() ) )
{
return false;
}
return true;
}
@Override
public int hashCode()
{
int result = id.hashCode();
result = 31 * result + repository.getId().hashCode();
return result;
}
@Override
public String toString()
{
final StringBuilder sb = new StringBuilder( "Namespace{" );
sb.append( "id='" ).append( id ).append( '\'' );
sb.append( ", name='" ).append( name ).append( '\'' );
sb.append( ", repository='" ).append( repository ).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().getId();
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 this.repositoryId + "-" + this.namespace;
}
}
}

View File

@ -0,0 +1,163 @@
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 javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.io.Serializable;
/**
* @author Olivier Lamy
*/
@Entity
public class Project
implements Serializable
{
@Id
@Column( name = "projectKey" )
private String projectKey;
@Column( name = "projectId" )
private String projectId;
@Column( name = "repository" )
private Namespace namespace;
public Project()
{
// no op
}
public Project( String projectKey, String projectId, Namespace namespace )
{
this.projectId = projectId;
this.projectKey = projectKey;
this.namespace = namespace;
}
public String getProjectKey()
{
return projectKey;
}
public void setProjectKey( String projectKey )
{
this.projectKey = projectKey;
}
public Namespace getNamespace()
{
return namespace;
}
public void setNamespace( Namespace namespace )
{
this.namespace = namespace;
}
public String getProjectId()
{
return projectId;
}
public void setProjectId( String projectId )
{
this.projectId = projectId;
}
@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( o == null || getClass() != o.getClass() )
{
return false;
}
Project project = (Project) o;
if ( !projectKey.equals( project.projectKey ) )
{
return false;
}
if ( !namespace.equals( project.namespace ) )
{
return false;
}
return true;
}
@Override
public int hashCode()
{
int result = projectKey.hashCode();
result = 31 * result + namespace.hashCode();
return result;
}
@Override
public String toString()
{
final StringBuilder sb = new StringBuilder( "Project{" );
sb.append( "projectKey='" ).append( projectKey ).append( '\'' );
sb.append( ", projectId='" ).append( projectId ).append( '\'' );
sb.append( ", namespace=" ).append( namespace );
sb.append( '}' );
return sb.toString();
}
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 new Namespace.KeyBuilder().withNamespace( this.namespace ).build() + "-" + this.projectId;
}
}
}

View File

@ -0,0 +1,354 @@
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 javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.util.ArrayList;
import java.util.List;
/**
* @author Olivier Lamy
*/
@Entity
public class ProjectVersionMetadataModel
{
// repositoryId + namespace + projectId + id (version)
@Id
private String rowId;
@Column( name = "namespace" )
private Namespace namespace;
/**
* id is the version
*/
@Column( name = "id" )
private String id;
@Column( name = "projectId" )
private String projectId;
@Column(name = "url")
private String url;
@Column(name = "name")
private String name;
@Column(name = "description")
private String description;
@Column(name = "organization")
private Organization organization;
@Column(name = "issueManagement")
private IssueManagement issueManagement;
@Column(name = "scm")
private Scm scm;
@Column(name = "ciManagement")
private CiManagement ciManagement;
// FIXME store those values in a separate table
@Column(name = "licenses")
private List<License> licenses = new ArrayList<License>();
@Column(name = "mailingLists")
private List<MailingList> mailingLists = new ArrayList<MailingList>();
@Column(name = "dependencies")
private List<Dependency> dependencies = new ArrayList<Dependency>();
@Column(name = "incomplete")
private boolean incomplete;
public String getProjectId()
{
return projectId;
}
public void setProjectId( String projectId )
{
this.projectId = projectId;
}
public String getRowId()
{
return rowId;
}
public void setRowId( String rowId )
{
this.rowId = rowId;
}
// 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( "rowId='" ).append( rowId ).append( '\'' );
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();
}
@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( o == null || getClass() != o.getClass() )
{
return false;
}
ProjectVersionMetadataModel that = (ProjectVersionMetadataModel) o;
if ( !rowId.equals( that.rowId ) )
{
return false;
}
return true;
}
@Override
public int hashCode()
{
return rowId.hashCode();
}
public static class KeyBuilder
{
private String namespace;
private String repositoryId;
private String projectId;
private String id;
public KeyBuilder()
{
}
public KeyBuilder withNamespace( Namespace namespace )
{
this.namespace = namespace.getName();
this.repositoryId = namespace.getRepository().getId();
return this;
}
public KeyBuilder withNamespace( String namespace )
{
this.namespace = namespace;
return this;
}
public KeyBuilder withRepository( String repositoryId )
{
this.repositoryId = repositoryId;
return this;
}
public KeyBuilder withRepository( Repository repository )
{
this.repositoryId = repository.getId();
return this;
}
public KeyBuilder withProjectId( String projectId )
{
this.projectId = projectId;
return this;
}
public KeyBuilder withId( String id )
{
this.id = id;
return this;
}
public String build()
{
// FIXME add some controls
return this.repositoryId + "-" + this.namespace + "-" + this.projectId + ( this.id == null
? ""
: "-" + this.id );
}
}
}

View File

@ -0,0 +1,136 @@
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 javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* @author Olivier Lamy
*/
@Entity
@Table(name = "repository", schema = "ArchivaKeySpace@archiva")
public class Repository
implements Serializable
{
private static final long serialVersionUID = 1L;
@Id
@Column( name = "id" )
private String id;
@Column(name = "name")
private String name;
private transient List<Namespace> namespaces = new ArrayList<Namespace>();
public Repository()
{
// no op
}
public Repository( String id )
{
this.id = id;
this.name = id;
}
public String getId()
{
return id;
}
public void setId( String id )
{
this.id = id;
}
public String getName()
{
return name;
}
public void setName( String name )
{
this.name = name;
}
public List<Namespace> getNamespaces()
{
if ( this.namespaces == null )
{
this.namespaces = new ArrayList<Namespace>();
}
return namespaces;
}
public void setNamespaces( List<Namespace> namespaces )
{
this.namespaces = namespaces;
}
@Override
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( o == null || getClass() != o.getClass() )
{
return false;
}
Repository that = (Repository) o;
if ( !id.equals( that.id ) )
{
return false;
}
return true;
}
@Override
public int hashCode()
{
return id.hashCode();
}
@Override
public String toString()
{
final StringBuilder sb = new StringBuilder( "Repository{" );
sb.append( "id='" ).append( id ).append( '\'' );
sb.append( ", name='" ).append( name ).append( '\'' );
sb.append( ", namespaces=" ).append( namespaces );
sb.append( '}' );
return sb.toString();
}
}

View File

@ -0,0 +1,33 @@
<?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"/>
</beans>

View File

@ -0,0 +1,25 @@
<?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">
</beans>

View File

@ -0,0 +1,113 @@
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.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.io.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.File;
import java.util.List;
import java.util.Map;
/**
* @author Olivier Lamy
*/
public class CassandraMetadataRepositoryTest
extends AbstractMetadataRepositoryTest
{
private Logger logger = LoggerFactory.getLogger( getClass() );
@Inject
@Named( value = "archivaEntityManagerFactory#cassandra" )
CassandraEntityManagerFactory cassandraEntityManagerFactory;
CassandraMetadataRepository cmr;
@Before
public void setUp()
throws Exception
{
super.setUp();
File directory = new File( "target/test-repositories" );
if ( directory.exists() )
{
FileUtils.deleteDirectory( directory );
}
Map<String, MetadataFacetFactory> factories = createTestMetadataFacetFactories();
this.cmr = new CassandraMetadataRepository( factories, null, cassandraEntityManagerFactory.getKeyspace() );
this.repository = this.cmr;
clearReposAndNamespace();
}
@After
public void shutdown()
throws Exception
{
clearReposAndNamespace();
super.tearDown();
}
protected void clearReposAndNamespace()
throws Exception
{
List<Project> projects = cmr.getProjectEntityManager().getAll();
cmr.getProjectEntityManager().remove( projects );
List<Namespace> namespaces = cmr.getNamespaceEntityManager().getAll();
cmr.getNamespaceEntityManager().remove( namespaces );
List<Repository> repositories = cmr.getRepositoryEntityManager().getAll();
cmr.getRepositoryEntityManager().remove( repositories );
List<ArtifactMetadataModel> artifactMetadataModels = cmr.getArtifactMetadataModelEntityManager().getAll();
cmr.getArtifactMetadataModelEntityManager().remove( artifactMetadataModels );
List<MetadataFacetModel> metadataFacetModels = cmr.getMetadataFacetModelEntityManager().getAll();
cmr.getMetadataFacetModelEntityManager().remove( metadataFacetModels );
List<ProjectVersionMetadataModel> projectVersionMetadataModels =
cmr.getProjectVersionMetadataModelEntityManager().getAll();
cmr.getProjectVersionMetadataModelEntityManager().remove( projectVersionMetadataModels );
}
}

View File

@ -0,0 +1,133 @@
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.repository.cassandra.model.Namespace;
import org.apache.archiva.metadata.repository.cassandra.model.Project;
import org.apache.archiva.metadata.repository.cassandra.model.Repository;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.fest.assertions.api.Assertions;
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 java.util.List;
/**
* @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")
CassandraEntityManagerFactory cassandraEntityManagerFactory;
CassandraMetadataRepository cmr;
@Before
public void setup()
throws Exception
{
cmr = new CassandraMetadataRepository( null, null, cassandraEntityManagerFactory.getKeyspace() );
clearReposAndNamespace();
}
@After
public void shutdown()
throws Exception
{
clearReposAndNamespace();
}
@Test
public void testMetadataRepo()
throws Exception
{
Repository r = null;
Namespace n = null;
try
{
cmr.updateNamespace( "release", "org" );
r = cmr.getRepositoryEntityManager().get( "release" );
Assertions.assertThat( r ).isNotNull();
Assertions.assertThat( cmr.getRepositories() ).isNotEmpty().hasSize( 1 );
Assertions.assertThat( cmr.getNamespaces( "release" ) ).isNotEmpty().hasSize( 1 );
n = cmr.getNamespaceEntityManager().get( "release" + "-" + "org" );
Assertions.assertThat( n ).isNotNull();
Assertions.assertThat( n.getRepository() ).isNotNull();
cmr.updateNamespace( "release", "org.apache" );
r = cmr.getRepositoryEntityManager().get( "release" );
Assertions.assertThat( r ).isNotNull();
Assertions.assertThat( cmr.getNamespaces( "release" ) ).isNotEmpty().hasSize( 2 );
}
catch ( Exception e )
{
logger.error( e.getMessage(), e );
throw e;
}
finally
{
clearReposAndNamespace();
}
}
protected void clearReposAndNamespace()
throws Exception
{
List<Project> projects = cmr.getProjectEntityManager().getAll();
cmr.getProjectEntityManager().remove( projects );
List<Namespace> namespaces = cmr.getNamespaceEntityManager().getAll();
cmr.getNamespaceEntityManager().remove( namespaces );
List<Repository> repositories = cmr.getRepositoryEntityManager().getAll();
cmr.getRepositoryEntityManager().remove( repositories );
}
}

View File

@ -0,0 +1,44 @@
<?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.CassandraMetadataRepository" level="debug"/>
<root level="info" includeLocation="true">
<appender-ref ref="console"/>
</root>
</loggers>
</configuration>