Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Bumped Nexus to use new fixed Timeline
Browse files Browse the repository at this point in the history
git-svn-id: file:///opt/svn/repositories/sonatype.org/nexus/trunk/nexus/nexus-app@6537 2aa8b3fc-8ebb-4439-a84f-95066eaea8ab
  • Loading branch information
cstamas committed Jun 1, 2010
1 parent 798d6e9 commit 5d6b529
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 106 deletions.
54 changes: 32 additions & 22 deletions src/main/java/org/sonatype/nexus/feeds/DefaultFeedRecorder.java
Expand Up @@ -32,6 +32,8 @@
import org.sonatype.nexus.artifact.NexusItemInfo;
import org.sonatype.nexus.timeline.NexusTimeline;
import org.sonatype.timeline.TimelineFilter;
import org.sonatype.timeline.TimelineRecord;
import org.sonatype.timeline.TimelineResult;

/**
* A feed recorder that uses DefaultNexus to record feeds.
Expand Down Expand Up @@ -123,12 +125,14 @@ protected DateFormat getDateFormat()
return new SimpleDateFormat( EVENT_DATE_FORMAT );
}

protected List<NexusArtifactEvent> getAisFromMaps( List<Map<String, String>> data )
protected List<NexusArtifactEvent> getAisFromMaps( TimelineResult data )
{
List<NexusArtifactEvent> result = new ArrayList<NexusArtifactEvent>( data.size() );
List<NexusArtifactEvent> result = new ArrayList<NexusArtifactEvent>();

for ( Map<String, String> map : data )
for ( TimelineRecord record : data )
{
Map<String, String> map = record.getData();

NexusArtifactEvent nae = new NexusArtifactEvent();

NexusItemInfo ai = new NexusItemInfo();
Expand Down Expand Up @@ -174,12 +178,14 @@ protected List<NexusArtifactEvent> getAisFromMaps( List<Map<String, String>> dat
return this.feedArtifactEventFilter.filterArtifactEventList( result );
}

protected List<SystemEvent> getSesFromMaps( List<Map<String, String>> data )
protected List<SystemEvent> getSesFromMaps( TimelineResult data )
{
List<SystemEvent> result = new ArrayList<SystemEvent>( data.size() );
List<SystemEvent> result = new ArrayList<SystemEvent>();

for ( Map<String, String> map : data )
for ( TimelineRecord record : data )
{
Map<String, String> map = record.getData();

SystemEvent se = new SystemEvent( map.get( ACTION ), map.get( MESSAGE ) );

try
Expand Down Expand Up @@ -209,12 +215,14 @@ protected List<SystemEvent> getSesFromMaps( List<Map<String, String>> data )
return result;
}

protected List<AuthcAuthzEvent> getAaesFromMaps( List<Map<String, String>> data )
protected List<AuthcAuthzEvent> getAaesFromMaps( TimelineResult data )
{
List<AuthcAuthzEvent> result = new ArrayList<AuthcAuthzEvent>( data.size() );
List<AuthcAuthzEvent> result = new ArrayList<AuthcAuthzEvent>();

for ( Map<String, String> map : data )
for ( TimelineRecord record : data )
{
Map<String, String> map = record.getData();

AuthcAuthzEvent evt = new AuthcAuthzEvent( map.get( ACTION ), map.get( MESSAGE ) );

try
Expand Down Expand Up @@ -245,12 +253,14 @@ protected List<AuthcAuthzEvent> getAaesFromMaps( List<Map<String, String>> data
return result;
}

protected List<ErrorWarningEvent> getEwesFromMaps( List<Map<String, String>> data )
protected List<ErrorWarningEvent> getEwesFromMaps( TimelineResult data )
{
List<ErrorWarningEvent> result = new ArrayList<ErrorWarningEvent>( data.size() );
List<ErrorWarningEvent> result = new ArrayList<ErrorWarningEvent>();

for ( Map<String, String> map : data )
for ( TimelineRecord record : data )
{
Map<String, String> map = record.getData();

ErrorWarningEvent evt = null;

if ( StringUtils.isEmpty( map.get( STACK_TRACE ) ) )
Expand Down Expand Up @@ -289,8 +299,8 @@ protected List<ErrorWarningEvent> getEwesFromMaps( List<Map<String, String>> dat
return result;
}

public List<Map<String, String>> getEvents( Set<String> types, Set<String> subtypes, Integer from, Integer count,
TimelineFilter filter )
public TimelineResult getEvents( Set<String> types, Set<String> subtypes, Integer from, Integer count,
TimelineFilter filter )
{
int cnt = count != null ? count : DEFAULT_PAGE_SIZE;

Expand All @@ -304,8 +314,8 @@ public List<Map<String, String>> getEvents( Set<String> types, Set<String> subty
}
}

public List<Map<String, String>> getEvents( Set<String> types, Set<String> subtypes, Long ts, Integer count,
TimelineFilter filter )
public TimelineResult getEvents( Set<String> types, Set<String> subtypes, Long ts, Integer count,
TimelineFilter filter )
{
int cnt = count != null ? count : DEFAULT_PAGE_SIZE;

Expand All @@ -320,13 +330,13 @@ public List<Map<String, String>> getEvents( Set<String> types, Set<String> subty
}

public List<NexusArtifactEvent> getNexusArtifectEvents( Set<String> subtypes, Integer from, Integer count,
TimelineFilter filter )
TimelineFilter filter )
{
return getAisFromMaps( getEvents( REPO_EVENT_TYPE_SET, subtypes, from, count, filter ) );
}

public List<NexusArtifactEvent> getNexusArtifactEvents( Set<String> subtypes, Long ts, Integer count,
TimelineFilter filter )
TimelineFilter filter )
{
return getAisFromMaps( getEvents( REPO_EVENT_TYPE_SET, subtypes, ts, count, filter ) );
}
Expand All @@ -337,13 +347,13 @@ public List<SystemEvent> getSystemEvents( Set<String> subtypes, Integer from, In
}

public List<AuthcAuthzEvent> getAuthcAuthzEvents( Set<String> subtypes, Integer from, Integer count,
TimelineFilter filter )
TimelineFilter filter )
{
return getAaesFromMaps( getEvents( AUTHC_AUTHZ_EVENT_TYPE_SET, subtypes, from, count, filter ) );
}

public List<AuthcAuthzEvent> getAuthcAuthzEvents( Set<String> subtypes, Long ts, Integer count,
TimelineFilter filter )
TimelineFilter filter )
{
return getAaesFromMaps( getEvents( AUTHC_AUTHZ_EVENT_TYPE_SET, subtypes, ts, count, filter ) );
}
Expand Down Expand Up @@ -502,13 +512,13 @@ protected void addErrorWarningEvent( ErrorWarningEvent errorEvt )
}

public List<ErrorWarningEvent> getErrorWarningEvents( Set<String> subtypes, Integer from, Integer count,
TimelineFilter filter )
TimelineFilter filter )
{
return getEwesFromMaps( getEvents( ERROR_WARNING_EVENT_TYPE_SET, subtypes, from, count, filter ) );
}

public List<ErrorWarningEvent> getErrorWarningEvents( Set<String> subtypes, Long ts, Integer count,
TimelineFilter filter )
TimelineFilter filter )
{
return getEwesFromMaps( getEvents( ERROR_WARNING_EVENT_TYPE_SET, subtypes, ts, count, filter ) );
}
Expand Down
27 changes: 12 additions & 15 deletions src/main/java/org/sonatype/nexus/timeline/DefaultNexusTimeline.java
Expand Up @@ -4,7 +4,6 @@
import java.io.FileFilter;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand All @@ -19,6 +18,7 @@
import org.sonatype.timeline.TimelineConfiguration;
import org.sonatype.timeline.TimelineException;
import org.sonatype.timeline.TimelineFilter;
import org.sonatype.timeline.TimelineResult;

@Component( role = NexusTimeline.class )
public class DefaultNexusTimeline
Expand Down Expand Up @@ -59,7 +59,7 @@ public void initialize()
throw new InitializationException( "Unable to initialize Timeline!", e );
}
}

private void moveLegacyTimeline()
throws TimelineException
{
Expand Down Expand Up @@ -115,9 +115,8 @@ private void updateConfiguration()
{
File timelineDir = applicationConfiguration.getWorkingDirectory( dirName );

TimelineConfiguration config = new TimelineConfiguration( new File( timelineDir, "persist" ), new File(
timelineDir,
"index" ) );
TimelineConfiguration config =
new TimelineConfiguration( new File( timelineDir, "persist" ), new File( timelineDir, "index" ) );

configure( config );
}
Expand Down Expand Up @@ -180,37 +179,35 @@ public int purgeOlderThan( long timestamp, Set<String> types, Set<String> subTyp
return timeline.purgeOlderThan( timestamp, types, subTypes, filter );
}

public List<Map<String, String>> retrieve( long fromTs, int count, Set<String> types )
public TimelineResult retrieve( long fromTs, int count, Set<String> types )
{
return timeline.retrieve( fromTs, count, types );
}

public List<Map<String, String>> retrieve( int fromItem, int count, Set<String> types )
public TimelineResult retrieve( int fromItem, int count, Set<String> types )
{
return timeline.retrieve( fromItem, count, types );
}

public List<Map<String, String>> retrieve( long fromTs, int count, Set<String> types, Set<String> subtypes,
TimelineFilter filter )
public TimelineResult retrieve( long fromTs, int count, Set<String> types, Set<String> subtypes,
TimelineFilter filter )
{
return timeline.retrieve( fromTs, count, types, subtypes, filter );
}

public List<Map<String, String>> retrieve( int fromItem, int count, Set<String> types, Set<String> subtypes,
TimelineFilter filter )
public TimelineResult retrieve( int fromItem, int count, Set<String> types, Set<String> subtypes,
TimelineFilter filter )
{
return timeline.retrieve( fromItem, count, types, subtypes, filter );
}

public List<Map<String, String>> retrieveNewest( int count, Set<String> types )
public TimelineResult retrieveNewest( int count, Set<String> types )
{
return timeline.retrieveNewest( count, types );
}

public List<Map<String, String>> retrieveNewest( int count, Set<String> types, Set<String> subtypes,
TimelineFilter filter )
public TimelineResult retrieveNewest( int count, Set<String> types, Set<String> subtypes, TimelineFilter filter )
{
return timeline.retrieveNewest( count, types, subtypes, filter );
}

}
Expand Up @@ -14,11 +14,11 @@
package org.sonatype.nexus.timeline;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.sonatype.nexus.feeds.DefaultFeedRecorder;
import org.sonatype.timeline.TimelineFilter;
import org.sonatype.timeline.TimelineRecord;

public class RepositoryIdTimelineFilter
implements TimelineFilter
Expand All @@ -37,9 +37,9 @@ public RepositoryIdTimelineFilter( Set<String> repositoryIds )
this.repositoryIds = repositoryIds;
}

public boolean accept( Map<String, String> hit )
public boolean accept( TimelineRecord hit )
{
return ( hit.containsKey( DefaultFeedRecorder.REPOSITORY ) && repositoryIds.contains( hit
.get( DefaultFeedRecorder.REPOSITORY ) ) );
return ( hit.getData().containsKey( DefaultFeedRecorder.REPOSITORY ) && repositoryIds.contains( hit.getData().get(
DefaultFeedRecorder.REPOSITORY ) ) );
}
}
@@ -0,0 +1,31 @@
package org.sonatype.nexus.timeline;

import java.util.ArrayList;
import java.util.List;

import org.sonatype.nexus.AbstractNexusTestCase;
import org.sonatype.timeline.TimelineRecord;
import org.sonatype.timeline.TimelineResult;

public abstract class AbstractTimelineTest
extends AbstractNexusTestCase
{
/**
* Handy method that does what was done before: keeps all in memory, but this is usable for small amount of data,
* like these in UT. This should NOT be used in production code, unless you want app that kills itself with OOM.
*
* @param result
* @return
*/
protected List<TimelineRecord> asList( TimelineResult result )
{
ArrayList<TimelineRecord> records = new ArrayList<TimelineRecord>();

for ( TimelineRecord rec : result )
{
records.add( rec );
}

return records;
}
}

0 comments on commit 5d6b529

Please sign in to comment.