You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by br...@apache.org on 2010/12/30 07:13:07 UTC

svn commit: r1053806 - in /archiva/sandbox/populate-jcr-repo: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/archiva/ src/main/java/org/apache/archiva/metadata/ src/main/java/org/apache/archiva/me...

Author: brett
Date: Thu Dec 30 06:13:07 2010
New Revision: 1053806

URL: http://svn.apache.org/viewvc?rev=1053806&view=rev
Log:
JCR query test app for populating from a local repository and then being able to query it quickly to test performance of different types of queries

Added:
    archiva/sandbox/populate-jcr-repo/   (with props)
    archiva/sandbox/populate-jcr-repo/pom.xml   (with props)
    archiva/sandbox/populate-jcr-repo/src/
    archiva/sandbox/populate-jcr-repo/src/main/
    archiva/sandbox/populate-jcr-repo/src/main/java/
    archiva/sandbox/populate-jcr-repo/src/main/java/org/
    archiva/sandbox/populate-jcr-repo/src/main/java/org/apache/
    archiva/sandbox/populate-jcr-repo/src/main/java/org/apache/archiva/
    archiva/sandbox/populate-jcr-repo/src/main/java/org/apache/archiva/metadata/
    archiva/sandbox/populate-jcr-repo/src/main/java/org/apache/archiva/metadata/repository/
    archiva/sandbox/populate-jcr-repo/src/main/java/org/apache/archiva/metadata/repository/jcr/
    archiva/sandbox/populate-jcr-repo/src/main/java/org/apache/archiva/metadata/repository/jcr/PopulateRepoApp.java   (with props)
    archiva/sandbox/populate-jcr-repo/src/main/java/org/apache/archiva/metadata/repository/jcr/QueryRepoApp.java   (with props)
    archiva/sandbox/populate-jcr-repo/src/main/repository.xml
      - copied unchanged from r1053791, archiva/branches/MRM-1327-jcr-backend-default/archiva-jetty/src/main/conf/repository.xml

Propchange: archiva/sandbox/populate-jcr-repo/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Dec 30 06:13:07 2010
@@ -0,0 +1,3 @@
+target
+*.iml
+jcr

Added: archiva/sandbox/populate-jcr-repo/pom.xml
URL: http://svn.apache.org/viewvc/archiva/sandbox/populate-jcr-repo/pom.xml?rev=1053806&view=auto
==============================================================================
--- archiva/sandbox/populate-jcr-repo/pom.xml (added)
+++ archiva/sandbox/populate-jcr-repo/pom.xml Thu Dec 30 06:13:07 2010
@@ -0,0 +1,46 @@
+<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>
+
+  <groupId>org.apache.archiva</groupId>
+  <artifactId>populate-jcr-repo</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+
+  <name>populate-jcr-repo</name>
+  <url>http://maven.apache.org</url>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+      <version>1.4</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.archiva</groupId>
+      <artifactId>metadata-store-jcr</artifactId>
+      <version>1.4-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.jackrabbit</groupId>
+      <artifactId>jackrabbit-core</artifactId>
+      <version>2.2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-simple</artifactId>
+      <version>1.5.8</version>
+      <scope>runtime</scope>
+    </dependency>
+  </dependencies>
+</project>

Propchange: archiva/sandbox/populate-jcr-repo/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: archiva/sandbox/populate-jcr-repo/src/main/java/org/apache/archiva/metadata/repository/jcr/PopulateRepoApp.java
URL: http://svn.apache.org/viewvc/archiva/sandbox/populate-jcr-repo/src/main/java/org/apache/archiva/metadata/repository/jcr/PopulateRepoApp.java?rev=1053806&view=auto
==============================================================================
--- archiva/sandbox/populate-jcr-repo/src/main/java/org/apache/archiva/metadata/repository/jcr/PopulateRepoApp.java (added)
+++ archiva/sandbox/populate-jcr-repo/src/main/java/org/apache/archiva/metadata/repository/jcr/PopulateRepoApp.java Thu Dec 30 06:13:07 2010
@@ -0,0 +1,96 @@
+package org.apache.archiva.metadata.repository.jcr;
+
+import org.apache.archiva.metadata.model.ArtifactMetadata;
+import org.apache.archiva.metadata.model.MetadataFacetFactory;
+import org.apache.archiva.metadata.repository.MetadataRepositoryException;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.filefilter.IOFileFilter;
+import org.apache.commons.io.filefilter.NotFileFilter;
+import org.apache.commons.io.filefilter.WildcardFileFilter;
+import org.apache.jackrabbit.core.TransientRepository;
+import org.apache.jackrabbit.core.config.RepositoryConfig;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+
+/**
+ * Hello world!
+ */
+public class PopulateRepoApp
+{
+    private static final String REPO_ID = "internal";
+
+    public static void main( String[] args )
+        throws RepositoryException, MetadataRepositoryException
+    {
+        RepositoryConfig config = RepositoryConfig.create( "src/main/repository.xml", "jcr" );
+        Repository repository = new TransientRepository( config );
+
+        JcrMetadataRepository jcrMetadataRepository = new JcrMetadataRepository(
+            Collections.<String, MetadataFacetFactory>emptyMap(), repository );
+
+        JcrMetadataRepository.initialize( jcrMetadataRepository.getJcrSession() );
+
+        try
+        {
+            File basedir;
+            if ( args.length > 0 )
+            {
+                basedir = new File( args[0] );
+            }
+            else
+            {
+                basedir = new File( System.getProperty( "user.home" ),
+                                    "Library/Application Support/Archiva/data/repositories/internal" );
+            }
+            IOFileFilter dirFilter = new NotFileFilter( new WildcardFileFilter( ".index*" ) );
+            IOFileFilter fileFilter = new NotFileFilter( new WildcardFileFilter(
+                new String[]{"*.asc", "*.md5", "*.sha1", "maven-metadata*.xml"} ) );
+            Collection<File> files = FileUtils.listFiles( basedir, fileFilter, dirFilter );
+
+            int count = 0, total = files.size();
+            for ( File f : files )
+            {
+                ArtifactMetadata artifact = new ArtifactMetadata();
+                artifact.setId( f.getName() );
+                artifact.setWhenGathered( new Date() );
+
+                File projectVersion = f.getParentFile();
+                File project = projectVersion.getParentFile();
+                File namespace = project.getParentFile();
+                String ns = namespace.getName();
+                while ( !namespace.getParentFile().equals( basedir ) )
+                {
+                    namespace = namespace.getParentFile();
+                    ns = namespace.getName() + "." + ns;
+                }
+
+                artifact.setNamespace( ns );
+                artifact.setProject( project.getName() );
+                artifact.setRepositoryId( REPO_ID );
+                artifact.setFileLastModified( f.lastModified() );
+                artifact.setVersion( projectVersion.getName() );
+                artifact.setProjectVersion( projectVersion.getName() );
+                artifact.setSize( f.length() );
+
+                jcrMetadataRepository.updateArtifact( REPO_ID, ns, artifact.getProject(), artifact.getProjectVersion(),
+                                                      artifact );
+
+                if ( ++count % 500 == 0 )
+                {
+                    System.out.println( "saving " + ( count * 100 / total ) + "%" );
+                    jcrMetadataRepository.save();
+                }
+            }
+            jcrMetadataRepository.save();
+        }
+        finally
+        {
+            jcrMetadataRepository.close();
+        }
+    }
+}

Propchange: archiva/sandbox/populate-jcr-repo/src/main/java/org/apache/archiva/metadata/repository/jcr/PopulateRepoApp.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: archiva/sandbox/populate-jcr-repo/src/main/java/org/apache/archiva/metadata/repository/jcr/QueryRepoApp.java
URL: http://svn.apache.org/viewvc/archiva/sandbox/populate-jcr-repo/src/main/java/org/apache/archiva/metadata/repository/jcr/QueryRepoApp.java?rev=1053806&view=auto
==============================================================================
--- archiva/sandbox/populate-jcr-repo/src/main/java/org/apache/archiva/metadata/repository/jcr/QueryRepoApp.java (added)
+++ archiva/sandbox/populate-jcr-repo/src/main/java/org/apache/archiva/metadata/repository/jcr/QueryRepoApp.java Thu Dec 30 06:13:07 2010
@@ -0,0 +1,87 @@
+package org.apache.archiva.metadata.repository.jcr;
+
+/*
+ * 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.jackrabbit.commons.JcrUtils;
+import org.apache.jackrabbit.core.TransientRepository;
+import org.apache.jackrabbit.core.config.RepositoryConfig;
+
+import java.util.Collections;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryResult;
+import javax.jcr.query.Row;
+
+/**
+ * Hello world!
+ */
+public class QueryRepoApp
+{
+    public static void main( String[] args )
+        throws RepositoryException
+    {
+        RepositoryConfig config = RepositoryConfig.create( "src/main/repository.xml", "jcr" );
+        Repository repository = new TransientRepository( config );
+
+        JcrMetadataRepository jcrMetadataRepository = new JcrMetadataRepository(
+            Collections.<String, MetadataFacetFactory>emptyMap(), repository );
+
+        try
+        {
+            Session session = jcrMetadataRepository.getJcrSession();
+
+            System.out.println( "querying" );
+            long time = System.currentTimeMillis();
+
+            String q = "SELECT size FROM [archiva:artifact] AS artifact";
+
+            Query query = session.getWorkspace().getQueryManager().createQuery( q, Query.JCR_SQL2 );
+
+            QueryResult queryResult = query.execute();
+            System.out.println( "query in " + ( System.currentTimeMillis() - time ) + "ms" );
+
+            time = System.currentTimeMillis();
+
+            long totalSize = 0, totalJars = 0, totalArtifacts = 0;
+            for ( Row row : JcrUtils.getRows( queryResult ) )
+            {
+                if ( row.getPath().startsWith( "/repositories/internal/content/" ) )
+                {
+                    totalSize += row.getValue( "size" ).getLong();
+                    if ( row.getNode().getName().endsWith( ".jar" ) )
+                    {
+                        totalJars++;
+                    }
+                    totalArtifacts++;
+                }
+            }
+            System.out.println(
+                totalArtifacts + " artifacts, " + totalSize + " bytes, " + totalJars + " jars (count in " +
+                    ( System.currentTimeMillis() - time ) + "ms)" );
+        }
+        finally
+        {
+            jcrMetadataRepository.close();
+        }
+    }
+}

Propchange: archiva/sandbox/populate-jcr-repo/src/main/java/org/apache/archiva/metadata/repository/jcr/QueryRepoApp.java
------------------------------------------------------------------------------
    svn:eol-style = native