Package org.apache.archiva.redback.components.taskqueue.execution

Examples of org.apache.archiva.redback.components.taskqueue.execution.TaskExecutionException


            this.task = task;

            String repoId = task.getRepositoryId();
            if ( StringUtils.isBlank( repoId ) )
            {
                throw new TaskExecutionException( "Unable to execute RepositoryTask with blank repository Id." );
            }

            ManagedRepository arepo = managedRepositoryAdmin.getManagedRepository( repoId );

            // execute consumers on resource file if set
            if ( task.getResourceFile() != null )
            {
                log.debug( "Executing task from queue with job name: {}", task );
                consumers.executeConsumers( arepo, task.getResourceFile(), task.isUpdateRelatedArtifacts() );
            }
            else
            {
                log.info( "Executing task from queue with job name: {}", task );

                // otherwise, execute consumers on whole repository
                if ( arepo == null )
                {
                    throw new TaskExecutionException(
                        "Unable to execute RepositoryTask with invalid repository id: " + repoId );
                }

                long sinceWhen = RepositoryScanner.FRESH_SCAN;
                long previousFileCount = 0;

                RepositorySession repositorySession = repositorySessionFactory.createSession();
                MetadataRepository metadataRepository = repositorySession.getRepository();
                try
                {
                    if ( !task.isScanAll() )
                    {
                        RepositoryStatistics previousStats =
                            repositoryStatisticsManager.getLastStatistics( metadataRepository, repoId );
                        if ( previousStats != null )
                        {
                            sinceWhen = previousStats.getScanStartTime().getTime();
                            previousFileCount = previousStats.getTotalFileCount();
                        }
                    }

                    RepositoryScanStatistics stats;
                    try
                    {
                        stats = repoScanner.scan( arepo, sinceWhen );
                    }
                    catch ( RepositoryScannerException e )
                    {
                        throw new TaskExecutionException( "Repository error when executing repository job.", e );
                    }

                    log.info( "Finished first scan: {}", stats.toDump( arepo ) );

                    // further statistics will be populated by the following method
                    Date endTime = new Date( stats.getWhenGathered().getTime() + stats.getDuration() );

                    log.info( "Gathering repository statistics" );

                    repositoryStatisticsManager.addStatisticsAfterScan( metadataRepository, repoId,
                                                                        stats.getWhenGathered(), endTime,
                                                                        stats.getTotalFileCount(),
                                                                        stats.getTotalFileCount() - previousFileCount );
                    repositorySession.save();
                }
                catch ( MetadataRepositoryException e )
                {
                    throw new TaskExecutionException( "Unable to store updated statistics: " + e.getMessage(), e );
                }
                finally
                {
                    repositorySession.close();
                }

//                log.info( "Scanning for removed repository content" );

//                metadataRepository.findAllProjects();
                // FIXME: do something

                log.info( "Finished repository task: {}", task );

                this.task = null;
            }
        }
        catch ( RepositoryAdminException e )
        {
            log.error( e.getMessage(), e );
            throw new TaskExecutionException( e.getMessage(), e );
        }
    }
View Full Code Here


                log.info( "indexed maven repository: {}, onlyUpdate: {}, time {} ms", repository.getId(),
                          indexingTask.isOnlyUpdate(), ( end - start ) );
            }
            catch ( IOException e )
            {
                throw new TaskExecutionException( "Error scan repository " + repository, e );
            }
            log.debug( "Finishing indexing task on repo: {}", repository.getId() );
            finishIndexingTask( indexingTask, repository, context );
        }
        else
        {
            // create context if not a repo scan request
            if ( !indexingTask.isExecuteOnEntireRepo() )
            {
                try
                {
                    log.debug( "Creating indexing context on resource: {}", ( indexingTask.getResourceFile() == null
                        ? "none"
                        : indexingTask.getResourceFile().getPath() ) );
                    context = managedRepositoryAdmin.createIndexContext( repository );
                }
                catch ( RepositoryAdminException e )
                {
                    log.error( "Error occurred while creating context: " + e.getMessage() );
                    throw new TaskExecutionException( "Error occurred while creating context: " + e.getMessage(), e );
                }
            }

            if ( context == null || context.getIndexDirectory() == null )
            {
                throw new TaskExecutionException( "Trying to index an artifact but the context is already closed" );
            }

            try
            {
                File artifactFile = indexingTask.getResourceFile();
                if ( artifactFile == null )
                {
                    log.debug( "no artifact pass in indexing task so skip it" );
                }
                else
                {
                    ArtifactContext ac = artifactContextProducer.getArtifactContext( context, artifactFile );

                    if ( ac != null )
                    {
                        // MRM-1779 pom must be indexed too
                        // TODO make that configurable?
                        if ( artifactFile.getPath().endsWith( ".pom" ) )
                        {
                            ac.getArtifactInfo().fextension = "pom";
                            ac.getArtifactInfo().packaging = "pom";
                            ac.getArtifactInfo().classifier = "pom";
                        }
                        if ( indexingTask.getAction().equals( ArtifactIndexingTask.Action.ADD ) )
                        {
                            //IndexSearcher s = context.getIndexSearcher();
                            //String uinfo = ac.getArtifactInfo().getUinfo();
                            //TopDocs d = s.search( new TermQuery( new Term( ArtifactInfo.UINFO, uinfo ) ), 1 );

                            BooleanQuery q = new BooleanQuery();
                            q.add( nexusIndexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression(
                                ac.getArtifactInfo().groupId ) ), BooleanClause.Occur.MUST );
                            q.add( nexusIndexer.constructQuery( MAVEN.ARTIFACT_ID, new SourcedSearchExpression(
                                ac.getArtifactInfo().artifactId ) ), BooleanClause.Occur.MUST );
                            q.add( nexusIndexer.constructQuery( MAVEN.VERSION, new SourcedSearchExpression(
                                ac.getArtifactInfo().version ) ), BooleanClause.Occur.MUST );
                            if ( ac.getArtifactInfo().classifier != null )
                            {
                                q.add( nexusIndexer.constructQuery( MAVEN.CLASSIFIER, new SourcedSearchExpression(
                                    ac.getArtifactInfo().classifier ) ), BooleanClause.Occur.MUST );
                            }
                            if ( ac.getArtifactInfo().packaging != null )
                            {
                                q.add( nexusIndexer.constructQuery( MAVEN.PACKAGING, new SourcedSearchExpression(
                                    ac.getArtifactInfo().packaging ) ), BooleanClause.Occur.MUST );
                            }
                            FlatSearchRequest flatSearchRequest = new FlatSearchRequest( q, context );
                            FlatSearchResponse flatSearchResponse = nexusIndexer.searchFlat( flatSearchRequest );
                            if ( flatSearchResponse.getResults().isEmpty() )
                            {
                                log.debug( "Adding artifact '{}' to index..", ac.getArtifactInfo() );
                                nexusIndexer.addArtifactToIndex( ac, context );
                            }
                            else
                            {
                                log.debug( "Updating artifact '{}' in index..", ac.getArtifactInfo() );
                                // TODO check if update exists !!
                                nexusIndexer.deleteArtifactFromIndex( ac, context );
                                nexusIndexer.addArtifactToIndex( ac, context );
                            }

                            context.updateTimestamp();
                            context.commit();


                        }
                        else
                        {
                            log.debug( "Removing artifact '{}' from index..", ac.getArtifactInfo() );
                            nexusIndexer.deleteArtifactFromIndex( ac, context );
                        }
                    }
                }
                // close the context if not a repo scan request
                if ( !indexingTask.isExecuteOnEntireRepo() )
                {
                    log.debug( "Finishing indexing task on resource file : {}", indexingTask.getResourceFile() != null
                        ? indexingTask.getResourceFile().getPath()
                        : " none " );
                    finishIndexingTask( indexingTask, repository, context );
                }
            }
            catch ( IOException e )
            {
                log.error( "Error occurred while executing indexing task '" + indexingTask + "': " + e.getMessage(),
                           e );
                throw new TaskExecutionException( "Error occurred while executing indexing task '" + indexingTask + "'",
                                                  e );
            }
        }

    }
View Full Code Here

            }
        }
        catch ( IOException e )
        {
            log.error( "Error occurred while executing indexing task '" + indexingTask + "': " + e.getMessage() );
            throw new TaskExecutionException( "Error occurred while executing indexing task '" + indexingTask + "'",
                                              e );
        }
    }
View Full Code Here

                log.info( "indexed maven repository: {}, onlyUpdate: {}, time {} ms", repository.getId(),
                          indexingTask.isOnlyUpdate(), ( end - start ) );
            }
            catch ( IOException e )
            {
                throw new TaskExecutionException( "Error scan repository " + repository, e );
            }
            log.debug( "Finishing indexing task on repo: {}", repository.getId() );
            finishIndexingTask( indexingTask, repository, context );
        }
        else
        {
            // create context if not a repo scan request
            if ( !indexingTask.isExecuteOnEntireRepo() )
            {
                try
                {
                    log.debug( "Creating indexing context on resource: {}", ( indexingTask.getResourceFile() == null
                        ? "none"
                        : indexingTask.getResourceFile().getPath() ) );
                    context = managedRepositoryAdmin.createIndexContext( repository );
                }
                catch ( RepositoryAdminException e )
                {
                    log.error( "Error occurred while creating context: " + e.getMessage() );
                    throw new TaskExecutionException( "Error occurred while creating context: " + e.getMessage(), e );
                }
            }

            if ( context == null || context.getIndexDirectory() == null )
            {
                throw new TaskExecutionException( "Trying to index an artifact but the context is already closed" );
            }

            try
            {
                File artifactFile = indexingTask.getResourceFile();
                if ( artifactFile == null )
                {
                    log.debug( "no artifact pass in indexing task so skip it" );
                }
                else
                {
                    ArtifactContext ac = artifactContextProducer.getArtifactContext( context, artifactFile );

                    if ( ac != null )
                    {
                        // MRM-1779 pom must be indexed too
                        // TODO make that configurable?
                        if ( artifactFile.getPath().endsWith( ".pom" ) )
                        {
                            ac.getArtifactInfo().fextension = "pom";
                            ac.getArtifactInfo().packaging = "pom";
                            ac.getArtifactInfo().classifier = "pom";
                        }
                        if ( indexingTask.getAction().equals( ArtifactIndexingTask.Action.ADD ) )
                        {
                            //IndexSearcher s = context.getIndexSearcher();
                            //String uinfo = ac.getArtifactInfo().getUinfo();
                            //TopDocs d = s.search( new TermQuery( new Term( ArtifactInfo.UINFO, uinfo ) ), 1 );

                            BooleanQuery q = new BooleanQuery();
                            q.add( nexusIndexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression(
                                ac.getArtifactInfo().groupId ) ), BooleanClause.Occur.MUST );
                            q.add( nexusIndexer.constructQuery( MAVEN.ARTIFACT_ID, new SourcedSearchExpression(
                                ac.getArtifactInfo().artifactId ) ), BooleanClause.Occur.MUST );
                            q.add( nexusIndexer.constructQuery( MAVEN.VERSION, new SourcedSearchExpression(
                                ac.getArtifactInfo().version ) ), BooleanClause.Occur.MUST );
                            if ( ac.getArtifactInfo().classifier != null )
                            {
                                q.add( nexusIndexer.constructQuery( MAVEN.CLASSIFIER, new SourcedSearchExpression(
                                    ac.getArtifactInfo().classifier ) ), BooleanClause.Occur.MUST );
                            }
                            if ( ac.getArtifactInfo().packaging != null )
                            {
                                q.add( nexusIndexer.constructQuery( MAVEN.PACKAGING, new SourcedSearchExpression(
                                    ac.getArtifactInfo().packaging ) ), BooleanClause.Occur.MUST );
                            }
                            FlatSearchRequest flatSearchRequest = new FlatSearchRequest( q, context );
                            FlatSearchResponse flatSearchResponse = nexusIndexer.searchFlat( flatSearchRequest );
                            if ( flatSearchResponse.getResults().isEmpty() )
                            {
                                log.debug( "Adding artifact '{}' to index..", ac.getArtifactInfo() );
                                nexusIndexer.addArtifactToIndex( ac, context );
                            }
                            else
                            {
                                log.debug( "Updating artifact '{}' in index..", ac.getArtifactInfo() );
                                // TODO check if update exists !!
                                nexusIndexer.deleteArtifactFromIndex( ac, context );
                                nexusIndexer.addArtifactToIndex( ac, context );
                            }

                            context.updateTimestamp();
                            context.commit();


                        }
                        else
                        {
                            log.debug( "Removing artifact '{}' from index..", ac.getArtifactInfo() );
                            nexusIndexer.deleteArtifactFromIndex( ac, context );
                        }
                    }
                }
                // close the context if not a repo scan request
                if ( !indexingTask.isExecuteOnEntireRepo() )
                {
                    log.debug( "Finishing indexing task on resource file : {}", indexingTask.getResourceFile() != null
                        ? indexingTask.getResourceFile().getPath()
                        : " none " );
                    finishIndexingTask( indexingTask, repository, context );
                }
            }
            catch ( IOException e )
            {
                log.error( "Error occurred while executing indexing task '" + indexingTask + "': " + e.getMessage(),
                           e );
                throw new TaskExecutionException( "Error occurred while executing indexing task '" + indexingTask + "'",
                                                  e );
            }
        }

    }
View Full Code Here

            }
        }
        catch ( IOException e )
        {
            log.error( "Error occurred while executing indexing task '" + indexingTask + "': " + e.getMessage() );
            throw new TaskExecutionException( "Error occurred while executing indexing task '" + indexingTask + "'",
                                              e );
        }
    }
View Full Code Here

            RepositoryTask repoTask = (RepositoryTask) task;

            String repoId = repoTask.getRepositoryId();
            if ( StringUtils.isBlank( repoId ) )
            {
                throw new TaskExecutionException( "Unable to execute RepositoryTask with blank repository Id." );
            }

            ManagedRepository arepo = managedRepositoryAdmin.getManagedRepository( repoId );

            // execute consumers on resource file if set
            if ( repoTask.getResourceFile() != null )
            {
                log.debug( "Executing task from queue with job name: {}", repoTask );
                consumers.executeConsumers( arepo, repoTask.getResourceFile(), repoTask.isUpdateRelatedArtifacts() );
            }
            else
            {
                log.info( "Executing task from queue with job name: {}", repoTask );

                // otherwise, execute consumers on whole repository
                if ( arepo == null )
                {
                    throw new TaskExecutionException(
                        "Unable to execute RepositoryTask with invalid repository id: " + repoId );
                }

                long sinceWhen = RepositoryScanner.FRESH_SCAN;
                long previousFileCount = 0;

                RepositorySession repositorySession = repositorySessionFactory.createSession();
                MetadataRepository metadataRepository = repositorySession.getRepository();
                try
                {
                    if ( !repoTask.isScanAll() )
                    {
                        RepositoryStatistics previousStats =
                            repositoryStatisticsManager.getLastStatistics( metadataRepository, repoId );
                        if ( previousStats != null )
                        {
                            sinceWhen = previousStats.getScanStartTime().getTime();
                            previousFileCount = previousStats.getTotalFileCount();
                        }
                    }

                    RepositoryScanStatistics stats;
                    try
                    {
                        stats = repoScanner.scan( arepo, sinceWhen );
                    }
                    catch ( RepositoryScannerException e )
                    {
                        throw new TaskExecutionException( "Repository error when executing repository job.", e );
                    }

                    log.info( "Finished first scan: {}", stats.toDump( arepo ) );

                    // further statistics will be populated by the following method
                    Date endTime = new Date( stats.getWhenGathered().getTime() + stats.getDuration() );

                    log.info( "Gathering repository statistics" );

                    repositoryStatisticsManager.addStatisticsAfterScan( metadataRepository, repoId,
                                                                        stats.getWhenGathered(), endTime,
                                                                        stats.getTotalFileCount(),
                                                                        stats.getTotalFileCount() - previousFileCount );
                    repositorySession.save();
                }
                catch ( MetadataRepositoryException e )
                {
                    throw new TaskExecutionException( "Unable to store updated statistics: " + e.getMessage(), e );
                }
                finally
                {
                    repositorySession.close();
                }

//                log.info( "Scanning for removed repository content" );

//                metadataRepository.findAllProjects();
                // FIXME: do something

                log.info( "Finished repository task: {}", repoTask );

                this.task = null;
            }
        }
        catch ( RepositoryAdminException e )
        {
            log.error( e.getMessage(), e );
            throw new TaskExecutionException( e.getMessage(), e );
        }
    }
View Full Code Here

                log.info( "indexed maven repository: {}, onlyUpdate: {}, time {} ms", repository.getId(),
                          indexingTask.isOnlyUpdate(), ( end - start ) );
            }
            catch ( IOException e )
            {
                throw new TaskExecutionException( "Error scan repository " + repository, e );
            }
            log.debug( "Finishing indexing task on repo: {}", repository.getId() );
            finishIndexingTask( indexingTask, repository, context );
        }
        else
        {
            // create context if not a repo scan request
            if ( !indexingTask.isExecuteOnEntireRepo() )
            {
                try
                {
                    log.debug( "Creating indexing context on resource: {}", ( indexingTask.getResourceFile() == null
                        ? "none"
                        : indexingTask.getResourceFile().getPath() ) );
                    context = managedRepositoryAdmin.createIndexContext( repository );
                }
                catch ( RepositoryAdminException e )
                {
                    log.error( "Error occurred while creating context: " + e.getMessage() );
                    throw new TaskExecutionException( "Error occurred while creating context: " + e.getMessage(), e );
                }
            }

            if ( context == null || context.getIndexDirectory() == null )
            {
                throw new TaskExecutionException( "Trying to index an artifact but the context is already closed" );
            }

            try
            {
                File artifactFile = indexingTask.getResourceFile();
                if ( artifactFile == null )
                {
                    log.debug( "no artifact pass in indexing task so skip it" );
                }
                else
                {
                    ArtifactContext ac = artifactContextProducer.getArtifactContext( context, artifactFile );

                    if ( ac != null )
                    {
                        // MRM-1779 pom must be indexed too
                        // TODO make that configurable?
                        if ( artifactFile.getPath().endsWith( ".pom" ) )
                        {
                            ac.getArtifactInfo().fextension = "pom";
                            ac.getArtifactInfo().packaging = "pom";
                            ac.getArtifactInfo().classifier = "pom";
                        }
                        if ( indexingTask.getAction().equals( ArtifactIndexingTask.Action.ADD ) )
                        {
                            //IndexSearcher s = context.getIndexSearcher();
                            //String uinfo = ac.getArtifactInfo().getUinfo();
                            //TopDocs d = s.search( new TermQuery( new Term( ArtifactInfo.UINFO, uinfo ) ), 1 );

                            BooleanQuery q = new BooleanQuery();
                            q.add( nexusIndexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression(
                                ac.getArtifactInfo().groupId ) ), BooleanClause.Occur.MUST );
                            q.add( nexusIndexer.constructQuery( MAVEN.ARTIFACT_ID, new SourcedSearchExpression(
                                ac.getArtifactInfo().artifactId ) ), BooleanClause.Occur.MUST );
                            q.add( nexusIndexer.constructQuery( MAVEN.VERSION, new SourcedSearchExpression(
                                ac.getArtifactInfo().version ) ), BooleanClause.Occur.MUST );
                            if ( ac.getArtifactInfo().classifier != null )
                            {
                                q.add( nexusIndexer.constructQuery( MAVEN.CLASSIFIER, new SourcedSearchExpression(
                                    ac.getArtifactInfo().classifier ) ), BooleanClause.Occur.MUST );
                            }
                            if ( ac.getArtifactInfo().packaging != null )
                            {
                                q.add( nexusIndexer.constructQuery( MAVEN.PACKAGING, new SourcedSearchExpression(
                                    ac.getArtifactInfo().packaging ) ), BooleanClause.Occur.MUST );
                            }
                            FlatSearchRequest flatSearchRequest = new FlatSearchRequest( q, context );
                            FlatSearchResponse flatSearchResponse = nexusIndexer.searchFlat( flatSearchRequest );
                            if ( flatSearchResponse.getResults().isEmpty() )
                            {
                                log.debug( "Adding artifact '{}' to index..", ac.getArtifactInfo() );
                                nexusIndexer.addArtifactToIndex( ac, context );
                            }
                            else
                            {
                                log.debug( "Updating artifact '{}' in index..", ac.getArtifactInfo() );
                                // TODO check if update exists !!
                                nexusIndexer.deleteArtifactFromIndex( ac, context );
                                nexusIndexer.addArtifactToIndex( ac, context );
                            }

                            context.updateTimestamp();
                            context.commit();


                        }
                        else
                        {
                            log.debug( "Removing artifact '{}' from index..", ac.getArtifactInfo() );
                            nexusIndexer.deleteArtifactFromIndex( ac, context );
                        }
                    }
                }
                // close the context if not a repo scan request
                if ( !indexingTask.isExecuteOnEntireRepo() )
                {
                    log.debug( "Finishing indexing task on resource file : {}", indexingTask.getResourceFile() != null
                        ? indexingTask.getResourceFile().getPath()
                        : " none " );
                    finishIndexingTask( indexingTask, repository, context );
                }
            }
            catch ( IOException e )
            {
                log.error( "Error occurred while executing indexing task '" + indexingTask + "': " + e.getMessage(),
                           e );
                throw new TaskExecutionException( "Error occurred while executing indexing task '" + indexingTask + "'",
                                                  e );
            }
        }

    }
View Full Code Here

            }
        }
        catch ( IOException e )
        {
            log.error( "Error occurred while executing indexing task '" + indexingTask + "': " + e.getMessage() );
            throw new TaskExecutionException( "Error occurred while executing indexing task '" + indexingTask + "'",
                                              e );
        }
    }
View Full Code Here

            RepositoryTask repoTask = (RepositoryTask) task;

            String repoId = repoTask.getRepositoryId();
            if ( StringUtils.isBlank( repoId ) )
            {
                throw new TaskExecutionException( "Unable to execute RepositoryTask with blank repository Id." );
            }

            ManagedRepository arepo = managedRepositoryAdmin.getManagedRepository( repoId );

            // execute consumers on resource file if set
            if ( repoTask.getResourceFile() != null )
            {
                log.debug( "Executing task from queue with job name: {}", repoTask );
                consumers.executeConsumers( arepo, repoTask.getResourceFile(), repoTask.isUpdateRelatedArtifacts() );
            }
            else
            {
                log.info( "Executing task from queue with job name: {}", repoTask );

                // otherwise, execute consumers on whole repository
                if ( arepo == null )
                {
                    throw new TaskExecutionException(
                        "Unable to execute RepositoryTask with invalid repository id: " + repoId );
                }

                long sinceWhen = RepositoryScanner.FRESH_SCAN;
                long previousFileCount = 0;

                RepositorySession repositorySession = repositorySessionFactory.createSession();
                MetadataRepository metadataRepository = repositorySession.getRepository();
                try
                {
                    if ( !repoTask.isScanAll() )
                    {
                        RepositoryStatistics previousStats =
                            repositoryStatisticsManager.getLastStatistics( metadataRepository, repoId );
                        if ( previousStats != null )
                        {
                            sinceWhen = previousStats.getScanStartTime().getTime();
                            previousFileCount = previousStats.getTotalFileCount();
                        }
                    }

                    RepositoryScanStatistics stats;
                    try
                    {
                        stats = repoScanner.scan( arepo, sinceWhen );
                    }
                    catch ( RepositoryScannerException e )
                    {
                        throw new TaskExecutionException( "Repository error when executing repository job.", e );
                    }

                    log.info( "Finished first scan: {}", stats.toDump( arepo ) );

                    // further statistics will be populated by the following method
                    Date endTime = new Date( stats.getWhenGathered().getTime() + stats.getDuration() );

                    log.info( "Gathering repository statistics" );

                    repositoryStatisticsManager.addStatisticsAfterScan( metadataRepository, repoId,
                                                                        stats.getWhenGathered(), endTime,
                                                                        stats.getTotalFileCount(),
                                                                        stats.getTotalFileCount() - previousFileCount );
                    repositorySession.save();
                }
                catch ( MetadataRepositoryException e )
                {
                    throw new TaskExecutionException( "Unable to store updated statistics: " + e.getMessage(), e );
                }
                finally
                {
                    repositorySession.close();
                }

//                log.info( "Scanning for removed repository content" );

//                metadataRepository.findAllProjects();
                // FIXME: do something

                log.info( "Finished repository task: {}", repoTask );

                this.task = null;
            }
        }
        catch ( RepositoryAdminException e )
        {
            log.error( e.getMessage(), e );
            throw new TaskExecutionException( e.getMessage(), e );
        }
    }
View Full Code Here

                log.info( "indexed maven repository: {}, onlyUpdate: {}, time {} ms", repository.getId(),
                          indexingTask.isOnlyUpdate(), ( end - start ) );
            }
            catch ( IOException e )
            {
                throw new TaskExecutionException( "Error scan repository " + repository, e );
            }
            log.debug( "Finishing indexing task on repo: {}", repository.getId() );
            finishIndexingTask( indexingTask, repository, context );
        }
        else
        {
            // create context if not a repo scan request
            if ( !indexingTask.isExecuteOnEntireRepo() )
            {
                try
                {
                    log.debug( "Creating indexing context on resource: {}", ( indexingTask.getResourceFile() == null
                        ? "none"
                        : indexingTask.getResourceFile().getPath() ) );
                    context = managedRepositoryAdmin.createIndexContext( repository );
                }
                catch ( RepositoryAdminException e )
                {
                    log.error( "Error occurred while creating context: " + e.getMessage() );
                    throw new TaskExecutionException( "Error occurred while creating context: " + e.getMessage(), e );
                }
            }

            if ( context == null || context.getIndexDirectory() == null )
            {
                throw new TaskExecutionException( "Trying to index an artifact but the context is already closed" );
            }

            try
            {
                File artifactFile = indexingTask.getResourceFile();
                if ( artifactFile == null )
                {
                    log.debug( "no artifact pass in indexing task so skip it" );
                }
                else
                {
                    ArtifactContext ac = artifactContextProducer.getArtifactContext( context, artifactFile );

                    if ( ac != null )
                    {
                        if ( indexingTask.getAction().equals( ArtifactIndexingTask.Action.ADD ) )
                        {
                            //IndexSearcher s = context.getIndexSearcher();
                            //String uinfo = ac.getArtifactInfo().getUinfo();
                            //TopDocs d = s.search( new TermQuery( new Term( ArtifactInfo.UINFO, uinfo ) ), 1 );

                            BooleanQuery q = new BooleanQuery();
                            q.add( nexusIndexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression(
                                ac.getArtifactInfo().groupId ) ), BooleanClause.Occur.MUST );
                            q.add( nexusIndexer.constructQuery( MAVEN.ARTIFACT_ID, new SourcedSearchExpression(
                                ac.getArtifactInfo().artifactId ) ), BooleanClause.Occur.MUST );
                            q.add( nexusIndexer.constructQuery( MAVEN.VERSION, new SourcedSearchExpression(
                                ac.getArtifactInfo().version ) ), BooleanClause.Occur.MUST );
                            if ( ac.getArtifactInfo().classifier != null )
                            {
                                q.add( nexusIndexer.constructQuery( MAVEN.CLASSIFIER, new SourcedSearchExpression(
                                    ac.getArtifactInfo().classifier ) ), BooleanClause.Occur.MUST );
                            }
                            if ( ac.getArtifactInfo().packaging != null )
                            {
                                q.add( nexusIndexer.constructQuery( MAVEN.PACKAGING, new SourcedSearchExpression(
                                    ac.getArtifactInfo().packaging ) ), BooleanClause.Occur.MUST );
                            }
                            FlatSearchRequest flatSearchRequest = new FlatSearchRequest( q, context );
                            FlatSearchResponse flatSearchResponse = nexusIndexer.searchFlat( flatSearchRequest );
                            if ( flatSearchResponse.getResults().isEmpty() )
                            {
                                log.debug( "Adding artifact '{}' to index..", ac.getArtifactInfo() );
                                nexusIndexer.addArtifactToIndex( ac, context );
                            }
                            else
                            {
                                log.debug( "Updating artifact '{}' in index..", ac.getArtifactInfo() );
                                // TODO check if update exists !!
                                nexusIndexer.deleteArtifactFromIndex( ac, context );
                                nexusIndexer.addArtifactToIndex( ac, context );
                            }

                            context.updateTimestamp();
                            context.commit();


                        }
                        else
                        {
                            log.debug( "Removing artifact '{}' from index..", ac.getArtifactInfo() );
                            nexusIndexer.deleteArtifactFromIndex( ac, context );
                        }
                    }
                }
                // close the context if not a repo scan request
                if ( !indexingTask.isExecuteOnEntireRepo() )
                {
                    log.debug( "Finishing indexing task on resource file : {}", indexingTask.getResourceFile() != null
                        ? indexingTask.getResourceFile().getPath()
                        : " none " );
                    finishIndexingTask( indexingTask, repository, context );
                }
            }
            catch ( IOException e )
            {
                log.error( "Error occurred while executing indexing task '" + indexingTask + "': " + e.getMessage(),
                           e );
                throw new TaskExecutionException( "Error occurred while executing indexing task '" + indexingTask + "'",
                                                  e );
            }
        }

    }
View Full Code Here

TOP

Related Classes of org.apache.archiva.redback.components.taskqueue.execution.TaskExecutionException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.