]> source.dussan.org Git - archiva.git/commitdiff
use a better name
authorOlivier Lamy <olamy@apache.org>
Thu, 20 Mar 2014 23:22:05 +0000 (23:22 +0000)
committerOlivier Lamy <olamy@apache.org>
Thu, 20 Mar 2014 23:22:05 +0000 (23:22 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1579817 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/plugins/metadata-store-cassandra/pom.xml
archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraArchivaManager.java [new file with mode: 0644]
archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraEntityManagerFactory.java [deleted file]
archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java
archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraRepositorySessionFactory.java
archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/DefaultCassandraArchivaManager.java [new file with mode: 0644]
archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/DefaultCassandraEntityManagerFactory.java [deleted file]
archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java
archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/RepositoriesNamespaceTest.java

index c5747e53bbff4859111c24df7ce19a71e7ccf5f6..8a6d19929afac41d39facd66272f79ebfc3f140a 100644 (file)
     </dependency>
 
     <dependency>
-      <groupId>org.apache.thrift</groupId>
-      <artifactId>libthrift</artifactId>
-      <version>0.9.1</version>
+      <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>
+      </exclusions>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.cassandra</groupId>
+      <artifactId>cassandra-thrift</artifactId>
+      <version>1.2.15</version>
+      <exclusions>
+        <exclusion>
+          <groupId>javax.servlet</groupId>
+          <artifactId>servlet-api</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
 
 
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
new file mode 100644 (file)
index 0000000..e53e4e6
--- /dev/null
@@ -0,0 +1,58 @@
+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;
+import com.netflix.astyanax.entitystore.EntityManager;
+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;
+
+/**
+ * @author Olivier Lamy
+ * @since 2.0.0
+ */
+public interface CassandraArchivaManager
+{
+    Keyspace getKeyspace();
+
+    void start();
+
+    void shutdown();
+
+    boolean started();
+
+    EntityManager<Repository, String> getRepositoryEntityManager();
+
+    EntityManager<Namespace, String> getNamespaceEntityManager();
+
+    EntityManager<Project, String> getProjectEntityManager();
+
+    EntityManager<ArtifactMetadataModel, String> getArtifactMetadataModelEntityManager();
+
+    EntityManager<MetadataFacetModel, String> getMetadataFacetModelEntityManager();
+
+    EntityManager<ProjectVersionMetadataModel, String> getProjectVersionMetadataModelEntityManager();
+
+
+}
diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraEntityManagerFactory.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraEntityManagerFactory.java
deleted file mode 100644 (file)
index aaa04d9..0000000
+++ /dev/null
@@ -1,58 +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 com.netflix.astyanax.Keyspace;
-import com.netflix.astyanax.entitystore.EntityManager;
-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;
-
-/**
- * @author Olivier Lamy
- * @since 2.0.0
- */
-public interface CassandraEntityManagerFactory
-{
-    Keyspace getKeyspace();
-
-    void start();
-
-    void shutdown();
-
-    boolean started();
-
-    EntityManager<Repository, String> getRepositoryEntityManager();
-
-    EntityManager<Namespace, String> getNamespaceEntityManager();
-
-    EntityManager<Project, String> getProjectEntityManager();
-
-    EntityManager<ArtifactMetadataModel, String> getArtifactMetadataModelEntityManager();
-
-    EntityManager<MetadataFacetModel, String> getMetadataFacetModelEntityManager();
-
-    EntityManager<ProjectVersionMetadataModel, String> getProjectVersionMetadataModelEntityManager();
-
-
-}
index 4db61b0c8a7f712209e5adba70be0073c2b47f40..157a7920e4e3038202e93fa5cfbb7bd94bc972a8 100644 (file)
@@ -71,46 +71,46 @@ public class CassandraMetadataRepository
 
     private final Map<String, MetadataFacetFactory> metadataFacetFactories;
 
-    private CassandraEntityManagerFactory cassandraEntityManagerFactory;
+    private CassandraArchivaManager cassandraArchivaManager;
 
     public CassandraMetadataRepository( Map<String, MetadataFacetFactory> metadataFacetFactories,
                                         ArchivaConfiguration configuration,
-                                        CassandraEntityManagerFactory cassandraEntityManagerFactory )
+                                        CassandraArchivaManager cassandraArchivaManager )
     {
         this.metadataFacetFactories = metadataFacetFactories;
         this.configuration = configuration;
-        this.cassandraEntityManagerFactory = cassandraEntityManagerFactory;
+        this.cassandraArchivaManager = cassandraArchivaManager;
     }
 
 
     public EntityManager<Repository, String> getRepositoryEntityManager()
     {
-        return this.cassandraEntityManagerFactory.getRepositoryEntityManager();
+        return this.cassandraArchivaManager.getRepositoryEntityManager();
     }
 
     public EntityManager<Namespace, String> getNamespaceEntityManager()
     {
-        return this.cassandraEntityManagerFactory.getNamespaceEntityManager();
+        return this.cassandraArchivaManager.getNamespaceEntityManager();
     }
 
     public EntityManager<Project, String> getProjectEntityManager()
     {
-        return this.cassandraEntityManagerFactory.getProjectEntityManager();
+        return this.cassandraArchivaManager.getProjectEntityManager();
     }
 
     public EntityManager<ArtifactMetadataModel, String> getArtifactMetadataModelEntityManager()
     {
-        return cassandraEntityManagerFactory.getArtifactMetadataModelEntityManager();
+        return cassandraArchivaManager.getArtifactMetadataModelEntityManager();
     }
 
     public EntityManager<MetadataFacetModel, String> getMetadataFacetModelEntityManager()
     {
-        return this.cassandraEntityManagerFactory.getMetadataFacetModelEntityManager();
+        return this.cassandraArchivaManager.getMetadataFacetModelEntityManager();
     }
 
     public EntityManager<ProjectVersionMetadataModel, String> getProjectVersionMetadataModelEntityManager()
     {
-        return this.cassandraEntityManagerFactory.getProjectVersionMetadataModelEntityManager();
+        return this.cassandraArchivaManager.getProjectVersionMetadataModelEntityManager();
     }
 
     @Override
index 3d96609eef26d5dbffb9e6848f65130235aef7aa..f9f1580fdd632b364f65f07cb83b3d74edef5479 100644 (file)
@@ -56,7 +56,7 @@ public class CassandraRepositorySessionFactory
     private ApplicationContext applicationContext;
 
     @Inject
-    private CassandraEntityManagerFactory cassandraEntityManagerFactory;
+    private CassandraArchivaManager cassandraArchivaManager;
 
     @PostConstruct
     public void initialize()
@@ -80,7 +80,7 @@ public class CassandraRepositorySessionFactory
     public RepositorySession createSession()
     {
         CassandraMetadataRepository metadataRepository =
-            new CassandraMetadataRepository( metadataFacetFactories, configuration, cassandraEntityManagerFactory );
+            new CassandraMetadataRepository( metadataFacetFactories, configuration, cassandraArchivaManager );
         return new RepositorySession( metadataRepository, metadataResolver );
     }
 
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
new file mode 100644 (file)
index 0000000..e46415b
--- /dev/null
@@ -0,0 +1,375 @@
+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.exceptions.NotFoundException;
+import com.netflix.astyanax.connectionpool.impl.ConnectionPoolConfigurationImpl;
+import com.netflix.astyanax.connectionpool.impl.ConnectionPoolType;
+import com.netflix.astyanax.connectionpool.impl.Slf4jConnectionPoolMonitorImpl;
+import com.netflix.astyanax.ddl.KeyspaceDefinition;
+import com.netflix.astyanax.entitystore.DefaultEntityManager;
+import com.netflix.astyanax.entitystore.EntityManager;
+import com.netflix.astyanax.impl.AstyanaxConfigurationImpl;
+import com.netflix.astyanax.thrift.ThriftFamilyFactory;
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.ApplicationContext;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.persistence.PersistenceException;
+import java.util.Properties;
+
+/**
+ * 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 AstyanaxContext<Keyspace> keyspaceContext;
+
+    private Keyspace keyspace;
+
+    private boolean started = false;
+
+    private EntityManager<Repository, String> repositoryEntityManager;
+
+    private EntityManager<Namespace, String> namespaceEntityManager;
+
+    private EntityManager<Project, String> projectEntityManager;
+
+    private EntityManager<ArtifactMetadataModel, String> artifactMetadataModelEntityManager;
+
+    private EntityManager<MetadataFacetModel, String> metadataFacetModelEntityManager;
+
+    private EntityManager<ProjectVersionMetadataModel, String> projectVersionMetadataModelEntityManager;
+
+
+    @PostConstruct
+    public void initialize()
+        throws ConnectionException
+    {
+        String cassandraHost = System.getProperty( "cassandraHost", "localhost" );
+        String cassandraPort = System.getProperty( "cassandraPort" );
+        String cqlVersion = System.getProperty( "cassandra.cqlversion", "3.0.0" );
+        keyspaceContext = new AstyanaxContext.Builder().forCluster( CLUSTER_NAME ).forKeyspace(
+            KEYSPACE_NAME ).withAstyanaxConfiguration(
+            new AstyanaxConfigurationImpl()
+                //.setCqlVersion( cqlVersion )
+                .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 Slf4jConnectionPoolMonitorImpl() )
+            .buildKeyspace( ThriftFamilyFactory.getInstance() );
+
+        this.start();
+
+        keyspace = keyspaceContext.getClient();
+        //Partitioner partitioner = keyspace.getPartitioner();
+
+        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();
+
+        // test if the namespace already exists if exception or null create it
+        boolean keyspaceExists = false;
+        try
+        {
+            KeyspaceDefinition keyspaceDefinition = keyspace.describeKeyspace();
+            if ( keyspaceDefinition != null )
+            {
+                keyspaceExists = true;
+            }
+
+        }
+        catch ( ConnectionException e )
+        {
+        }
+
+        if ( !keyspaceExists )
+        {
+            keyspace.createKeyspace( options );
+        }
+
+        try
+        {
+            Properties properties = keyspace.getKeyspaceProperties();
+            logger.info( "keyspace properties: {}", properties );
+        }
+        catch ( ConnectionException e )
+        {
+            // FIXME better logging !
+            logger.warn( e.getMessage(), e );
+        }
+
+        try
+        {
+            repositoryEntityManager =
+                DefaultEntityManager.<Repository, String>builder()
+                    .withEntityType( Repository.class )
+                    .withKeyspace( keyspace )
+                    .withAutoCommit( true )
+                    .withColumnFamily( "repository" )
+                    .build();
+            boolean exists = columnFamilyExists( "repository" );
+            // TODO very basic test we must test model change too
+            if ( !exists )
+            {
+                repositoryEntityManager.createStorage( null );
+            }
+
+            namespaceEntityManager =
+                DefaultEntityManager.<Namespace, String>builder()
+                    .withEntityType( Namespace.class )
+                    .withKeyspace( keyspace )
+                    .withAutoCommit( true )
+                    .withColumnFamily( "namespace" )
+                    .build();
+
+            exists = columnFamilyExists( "namespace" );
+            if ( !exists )
+            {
+                // create secondary index
+
+                options =
+                    ImmutableMap.<String, Object>builder()
+                        .put("repositoryid", ImmutableMap.<String, Object>builder()
+                            .put("validation_class", "UTF8Type")
+                            .put("index_name",       "Indexrepositoryid")
+                            .put("index_type",       "KEYS")
+                            .build()).build();
+
+                namespaceEntityManager.createStorage( options );
+            }
+
+
+
+            projectEntityManager =
+                DefaultEntityManager.<Project, String>builder()
+                    .withEntityType( Project.class )
+                    .withKeyspace( keyspace )
+                    .withAutoCommit( true )
+                    .withColumnFamily( "project" )
+                    .build();
+
+            exists = columnFamilyExists( "project" );
+            if ( !exists )
+            {
+                projectEntityManager.createStorage( null );
+            }
+
+            artifactMetadataModelEntityManager =
+                DefaultEntityManager.<ArtifactMetadataModel, String>builder()
+                    .withEntityType( ArtifactMetadataModel.class )
+                    .withAutoCommit( true )
+                    .withKeyspace( keyspace )
+                    .withColumnFamily( "artifactmetadatamodel" )
+                    .build();
+
+            exists = columnFamilyExists( "artifactmetadatamodel" );
+            if ( !exists )
+            {
+                artifactMetadataModelEntityManager.createStorage( null );
+            }
+
+            metadataFacetModelEntityManager =
+                DefaultEntityManager.<MetadataFacetModel, String>builder()
+                    .withEntityType( MetadataFacetModel.class )
+                    .withAutoCommit( true )
+                    .withKeyspace( keyspace )
+                    .withColumnFamily( "metadatafacetmodel" )
+                    .build();
+
+            exists = columnFamilyExists( "metadatafacetmodel" );
+            if ( !exists )
+            {
+                metadataFacetModelEntityManager.createStorage( null );
+            }
+
+            projectVersionMetadataModelEntityManager =
+                DefaultEntityManager.<ProjectVersionMetadataModel, String>builder()
+                    .withEntityType( ProjectVersionMetadataModel.class )
+                    .withAutoCommit( true )
+                    .withKeyspace( keyspace )
+                    .withColumnFamily( "projectversionmetadatamodel" )
+                    .build();
+
+            exists = columnFamilyExists( "projectversionmetadatamodel" );
+            if ( !exists )
+            {
+                projectVersionMetadataModelEntityManager.createStorage( null );
+            }
+
+        }
+        catch ( PersistenceException e )
+        {
+            // FIXME report exception
+            logger.error( e.getMessage(), e );
+        }
+        catch ( ConnectionException e )
+        {
+            // FIXME report exception
+            logger.error( e.getMessage(), e );
+        }
+    }
+
+    public void start()
+    {
+        keyspaceContext.start();
+        started = true;
+    }
+
+    @PreDestroy
+    public void shutdown()
+    {
+        if ( keyspaceContext != null )
+        {
+            keyspaceContext.shutdown();
+            started = false;
+        }
+    }
+
+
+    @Override
+    public boolean started()
+    {
+        return started;
+    }
+
+    private boolean columnFamilyExists( String columnFamilyName )
+        throws ConnectionException
+    {
+        try
+        {
+            Properties properties = keyspace.getColumnFamilyProperties( columnFamilyName );
+            logger.debug( "getColumnFamilyProperties for {}: {}", columnFamilyName, properties );
+            return true;
+        }
+        catch ( NotFoundException e )
+        {
+            return false;
+        }
+    }
+
+
+    @Override
+    public Keyspace getKeyspace()
+    {
+        return keyspace;
+    }
+
+    public EntityManager<Repository, String> getRepositoryEntityManager()
+    {
+        return repositoryEntityManager;
+    }
+
+    public void setRepositoryEntityManager( EntityManager<Repository, String> repositoryEntityManager )
+    {
+        this.repositoryEntityManager = repositoryEntityManager;
+    }
+
+    public EntityManager<Namespace, String> getNamespaceEntityManager()
+    {
+        return namespaceEntityManager;
+    }
+
+    public void setNamespaceEntityManager( EntityManager<Namespace, String> namespaceEntityManager )
+    {
+        this.namespaceEntityManager = namespaceEntityManager;
+    }
+
+    public EntityManager<Project, String> getProjectEntityManager()
+    {
+        return projectEntityManager;
+    }
+
+    public void setProjectEntityManager( EntityManager<Project, String> projectEntityManager )
+    {
+        this.projectEntityManager = projectEntityManager;
+    }
+
+    public EntityManager<ArtifactMetadataModel, String> getArtifactMetadataModelEntityManager()
+    {
+        return artifactMetadataModelEntityManager;
+    }
+
+    public void setArtifactMetadataModelEntityManager(
+        EntityManager<ArtifactMetadataModel, String> artifactMetadataModelEntityManager )
+    {
+        this.artifactMetadataModelEntityManager = artifactMetadataModelEntityManager;
+    }
+
+    public EntityManager<MetadataFacetModel, String> getMetadataFacetModelEntityManager()
+    {
+        return metadataFacetModelEntityManager;
+    }
+
+    public void setMetadataFacetModelEntityManager(
+        EntityManager<MetadataFacetModel, String> metadataFacetModelEntityManager )
+    {
+        this.metadataFacetModelEntityManager = metadataFacetModelEntityManager;
+    }
+
+    public EntityManager<ProjectVersionMetadataModel, String> getProjectVersionMetadataModelEntityManager()
+    {
+        return projectVersionMetadataModelEntityManager;
+    }
+
+    public void setProjectVersionMetadataModelEntityManager(
+        EntityManager<ProjectVersionMetadataModel, String> projectVersionMetadataModelEntityManager )
+    {
+        this.projectVersionMetadataModelEntityManager = projectVersionMetadataModelEntityManager;
+    }
+}
diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/DefaultCassandraEntityManagerFactory.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/DefaultCassandraEntityManagerFactory.java
deleted file mode 100644 (file)
index 24150e6..0000000
+++ /dev/null
@@ -1,379 +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 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.exceptions.NotFoundException;
-import com.netflix.astyanax.connectionpool.impl.ConnectionPoolConfigurationImpl;
-import com.netflix.astyanax.connectionpool.impl.ConnectionPoolType;
-import com.netflix.astyanax.connectionpool.impl.Slf4jConnectionPoolMonitorImpl;
-import com.netflix.astyanax.ddl.ColumnDefinition;
-import com.netflix.astyanax.ddl.ColumnFamilyDefinition;
-import com.netflix.astyanax.ddl.KeyspaceDefinition;
-import com.netflix.astyanax.entitystore.CompositeEntityManager;
-import com.netflix.astyanax.entitystore.DefaultEntityManager;
-import com.netflix.astyanax.entitystore.EntityManager;
-import com.netflix.astyanax.impl.AstyanaxConfigurationImpl;
-import com.netflix.astyanax.thrift.ThriftFamilyFactory;
-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.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.context.ApplicationContext;
-import org.springframework.stereotype.Service;
-
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import javax.inject.Inject;
-import javax.persistence.PersistenceException;
-import java.util.Map;
-import java.util.Properties;
-
-/**
- * FIXME make all configuration not hardcoded :-)
- *
- * @author Olivier Lamy
- * @since 2.0.0
- */
-@Service( "archivaEntityManagerFactory#cassandra" )
-public class DefaultCassandraEntityManagerFactory
-    implements CassandraEntityManagerFactory
-{
-
-    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 AstyanaxContext<Keyspace> keyspaceContext;
-
-    private Keyspace keyspace;
-
-    private boolean started = false;
-
-    private EntityManager<Repository, String> repositoryEntityManager;
-
-    private EntityManager<Namespace, String> namespaceEntityManager;
-
-    private EntityManager<Project, String> projectEntityManager;
-
-    private EntityManager<ArtifactMetadataModel, String> artifactMetadataModelEntityManager;
-
-    private EntityManager<MetadataFacetModel, String> metadataFacetModelEntityManager;
-
-    private EntityManager<ProjectVersionMetadataModel, String> projectVersionMetadataModelEntityManager;
-
-
-    @PostConstruct
-    public void initialize()
-        throws ConnectionException
-    {
-        String cassandraHost = System.getProperty( "cassandraHost", "localhost" );
-        String cassandraPort = System.getProperty( "cassandraPort" );
-        String cqlVersion = System.getProperty( "cassandra.cqlversion", "3.0.0" );
-        keyspaceContext = new AstyanaxContext.Builder().forCluster( CLUSTER_NAME ).forKeyspace(
-            KEYSPACE_NAME ).withAstyanaxConfiguration(
-            new AstyanaxConfigurationImpl()
-                //.setCqlVersion( cqlVersion )
-                .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 Slf4jConnectionPoolMonitorImpl() )
-            .buildKeyspace( ThriftFamilyFactory.getInstance() );
-
-        this.start();
-
-        keyspace = keyspaceContext.getClient();
-        //Partitioner partitioner = keyspace.getPartitioner();
-
-        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();
-
-        // test if the namespace already exists if exception or null create it
-        boolean keyspaceExists = false;
-        try
-        {
-            KeyspaceDefinition keyspaceDefinition = keyspace.describeKeyspace();
-            if ( keyspaceDefinition != null )
-            {
-                keyspaceExists = true;
-            }
-
-        }
-        catch ( ConnectionException e )
-        {
-        }
-
-        if ( !keyspaceExists )
-        {
-            keyspace.createKeyspace( options );
-        }
-
-        try
-        {
-            Properties properties = keyspace.getKeyspaceProperties();
-            logger.info( "keyspace properties: {}", properties );
-        }
-        catch ( ConnectionException e )
-        {
-            // FIXME better logging !
-            logger.warn( e.getMessage(), e );
-        }
-
-        try
-        {
-            repositoryEntityManager =
-                DefaultEntityManager.<Repository, String>builder()
-                    .withEntityType( Repository.class )
-                    .withKeyspace( keyspace )
-                    .withAutoCommit( true )
-                    .withColumnFamily( "repository" )
-                    .build();
-            boolean exists = columnFamilyExists( "repository" );
-            // TODO very basic test we must test model change too
-            if ( !exists )
-            {
-                repositoryEntityManager.createStorage( null );
-            }
-
-            namespaceEntityManager =
-                DefaultEntityManager.<Namespace, String>builder()
-                    .withEntityType( Namespace.class )
-                    .withKeyspace( keyspace )
-                    .withAutoCommit( true )
-                    .withColumnFamily( "namespace" )
-                    .build();
-
-            exists = columnFamilyExists( "namespace" );
-            if ( !exists )
-            {
-                // create secondary index
-
-                options =
-                    ImmutableMap.<String, Object>builder()
-                        .put("repositoryid", ImmutableMap.<String, Object>builder()
-                            .put("validation_class", "UTF8Type")
-                            .put("index_name",       "Indexrepositoryid")
-                            .put("index_type",       "KEYS")
-                            .build()).build();
-
-                namespaceEntityManager.createStorage( options );
-            }
-
-
-
-            projectEntityManager =
-                DefaultEntityManager.<Project, String>builder()
-                    .withEntityType( Project.class )
-                    .withKeyspace( keyspace )
-                    .withAutoCommit( true )
-                    .withColumnFamily( "project" )
-                    .build();
-
-            exists = columnFamilyExists( "project" );
-            if ( !exists )
-            {
-                projectEntityManager.createStorage( null );
-            }
-
-            artifactMetadataModelEntityManager =
-                DefaultEntityManager.<ArtifactMetadataModel, String>builder()
-                    .withEntityType( ArtifactMetadataModel.class )
-                    .withAutoCommit( true )
-                    .withKeyspace( keyspace )
-                    .withColumnFamily( "artifactmetadatamodel" )
-                    .build();
-
-            exists = columnFamilyExists( "artifactmetadatamodel" );
-            if ( !exists )
-            {
-                artifactMetadataModelEntityManager.createStorage( null );
-            }
-
-            metadataFacetModelEntityManager =
-                DefaultEntityManager.<MetadataFacetModel, String>builder()
-                    .withEntityType( MetadataFacetModel.class )
-                    .withAutoCommit( true )
-                    .withKeyspace( keyspace )
-                    .withColumnFamily( "metadatafacetmodel" )
-                    .build();
-
-            exists = columnFamilyExists( "metadatafacetmodel" );
-            if ( !exists )
-            {
-                metadataFacetModelEntityManager.createStorage( null );
-            }
-
-            projectVersionMetadataModelEntityManager =
-                DefaultEntityManager.<ProjectVersionMetadataModel, String>builder()
-                    .withEntityType( ProjectVersionMetadataModel.class )
-                    .withAutoCommit( true )
-                    .withKeyspace( keyspace )
-                    .withColumnFamily( "projectversionmetadatamodel" )
-                    .build();
-
-            exists = columnFamilyExists( "projectversionmetadatamodel" );
-            if ( !exists )
-            {
-                projectVersionMetadataModelEntityManager.createStorage( null );
-            }
-
-        }
-        catch ( PersistenceException e )
-        {
-            // FIXME report exception
-            logger.error( e.getMessage(), e );
-        }
-        catch ( ConnectionException e )
-        {
-            // FIXME report exception
-            logger.error( e.getMessage(), e );
-        }
-    }
-
-    public void start()
-    {
-        keyspaceContext.start();
-        started = true;
-    }
-
-    @PreDestroy
-    public void shutdown()
-    {
-        if ( keyspaceContext != null )
-        {
-            keyspaceContext.shutdown();
-            started = false;
-        }
-    }
-
-
-    @Override
-    public boolean started()
-    {
-        return started;
-    }
-
-    private boolean columnFamilyExists( String columnFamilyName )
-        throws ConnectionException
-    {
-        try
-        {
-            Properties properties = keyspace.getColumnFamilyProperties( columnFamilyName );
-            logger.debug( "getColumnFamilyProperties for {}: {}", columnFamilyName, properties );
-            return true;
-        }
-        catch ( NotFoundException e )
-        {
-            return false;
-        }
-    }
-
-
-    @Override
-    public Keyspace getKeyspace()
-    {
-        return keyspace;
-    }
-
-    public EntityManager<Repository, String> getRepositoryEntityManager()
-    {
-        return repositoryEntityManager;
-    }
-
-    public void setRepositoryEntityManager( EntityManager<Repository, String> repositoryEntityManager )
-    {
-        this.repositoryEntityManager = repositoryEntityManager;
-    }
-
-    public EntityManager<Namespace, String> getNamespaceEntityManager()
-    {
-        return namespaceEntityManager;
-    }
-
-    public void setNamespaceEntityManager( EntityManager<Namespace, String> namespaceEntityManager )
-    {
-        this.namespaceEntityManager = namespaceEntityManager;
-    }
-
-    public EntityManager<Project, String> getProjectEntityManager()
-    {
-        return projectEntityManager;
-    }
-
-    public void setProjectEntityManager( EntityManager<Project, String> projectEntityManager )
-    {
-        this.projectEntityManager = projectEntityManager;
-    }
-
-    public EntityManager<ArtifactMetadataModel, String> getArtifactMetadataModelEntityManager()
-    {
-        return artifactMetadataModelEntityManager;
-    }
-
-    public void setArtifactMetadataModelEntityManager(
-        EntityManager<ArtifactMetadataModel, String> artifactMetadataModelEntityManager )
-    {
-        this.artifactMetadataModelEntityManager = artifactMetadataModelEntityManager;
-    }
-
-    public EntityManager<MetadataFacetModel, String> getMetadataFacetModelEntityManager()
-    {
-        return metadataFacetModelEntityManager;
-    }
-
-    public void setMetadataFacetModelEntityManager(
-        EntityManager<MetadataFacetModel, String> metadataFacetModelEntityManager )
-    {
-        this.metadataFacetModelEntityManager = metadataFacetModelEntityManager;
-    }
-
-    public EntityManager<ProjectVersionMetadataModel, String> getProjectVersionMetadataModelEntityManager()
-    {
-        return projectVersionMetadataModelEntityManager;
-    }
-
-    public void setProjectVersionMetadataModelEntityManager(
-        EntityManager<ProjectVersionMetadataModel, String> projectVersionMetadataModelEntityManager )
-    {
-        this.projectVersionMetadataModelEntityManager = projectVersionMetadataModelEntityManager;
-    }
-}
index 1361585db6752f6a8d9f677b27f62f6b747bc16e..0e73da67f480657beb2fa6f8ccaf774308198636 100644 (file)
@@ -21,12 +21,6 @@ package org.apache.archiva.metadata.repository.cassandra;
 
 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;
@@ -36,7 +30,6 @@ import org.slf4j.LoggerFactory;
 import javax.inject.Inject;
 import javax.inject.Named;
 import java.io.File;
-import java.util.List;
 import java.util.Map;
 
 /**
@@ -49,7 +42,7 @@ public class CassandraMetadataRepositoryTest
 
     @Inject
     @Named( value = "archivaEntityManagerFactory#cassandra" )
-    CassandraEntityManagerFactory cassandraEntityManagerFactory;
+    CassandraArchivaManager cassandraArchivaManager;
 
     CassandraMetadataRepository cmr;
 
@@ -67,7 +60,7 @@ public class CassandraMetadataRepositoryTest
 
         Map<String, MetadataFacetFactory> factories = createTestMetadataFacetFactories();
 
-        this.cmr = new CassandraMetadataRepository( factories, null, cassandraEntityManagerFactory );
+        this.cmr = new CassandraMetadataRepository( factories, null, cassandraArchivaManager );
         this.repository = this.cmr;
 
         clearReposAndNamespace();
index 32fb9eb187a3cbe48c838c3f37a9cd8ead524811..a0637d229de48311096a9afaf4ad7ae1c83a245e 100644 (file)
@@ -20,7 +20,6 @@ package org.apache.archiva.metadata.repository.cassandra;
  */
 
 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;
@@ -34,7 +33,6 @@ import org.springframework.test.context.ContextConfiguration;
 
 import javax.inject.Inject;
 import javax.inject.Named;
-import java.util.List;
 
 /**
  * @author Olivier Lamy
@@ -48,7 +46,7 @@ public class RepositoriesNamespaceTest
 
     @Inject
     @Named(value = "archivaEntityManagerFactory#cassandra")
-    CassandraEntityManagerFactory cassandraEntityManagerFactory;
+    CassandraArchivaManager cassandraArchivaManager;
 
 
     CassandraMetadataRepository cmr;
@@ -57,10 +55,10 @@ public class RepositoriesNamespaceTest
     public void setup()
         throws Exception
     {
-        cmr = new CassandraMetadataRepository( null, null, cassandraEntityManagerFactory );
-        if ( !cassandraEntityManagerFactory.started() )
+        cmr = new CassandraMetadataRepository( null, null, cassandraArchivaManager );
+        if ( !cassandraArchivaManager.started() )
         {
-            cassandraEntityManagerFactory.start();
+            cassandraArchivaManager.start();
         }
         clearReposAndNamespace();
     }
@@ -70,7 +68,7 @@ public class RepositoriesNamespaceTest
         throws Exception
     {
         clearReposAndNamespace();
-        cassandraEntityManagerFactory.shutdown();
+        cassandraArchivaManager.shutdown();
     }