Skip to content

Commit

Permalink
Deleted version based on deactivation ts #10794
Browse files Browse the repository at this point in the history
  • Loading branch information
anatol-sialitski committed Dec 11, 2024
1 parent 69276b2 commit 001465b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,22 @@
public class DeleteSnapshotsResult
extends AbstractImmutableEntitySet<String>
{
private final Set<String> failedSnapshotNames;
private final Set<String> failedSnapshots;

private DeleteSnapshotsResult( final Builder builder )
{
super( ImmutableSet.copyOf( builder.snapshotNames ) );
this.failedSnapshotNames = ImmutableSet.copyOf( builder.failedSnapshotNames );
this.failedSnapshots = ImmutableSet.copyOf( builder.failedSnapshots );
}

public Set<String> getFailedSnapshotNames()
public Set<String> getDeletedSnapshots()
{
return failedSnapshotNames;
return this.getSet();
}

public Set<String> getFailedSnapshots()
{
return failedSnapshots;
}

public static Builder create()
Expand All @@ -35,7 +40,7 @@ public static class Builder
{
private final Set<String> snapshotNames = new HashSet<>();

private final Set<String> failedSnapshotNames = new HashSet<>();
private final Set<String> failedSnapshots = new HashSet<>();


public Builder add( final String snapshotName )
Expand All @@ -53,7 +58,7 @@ public Builder addAll( final Collection<String> snapshotNames )

public Builder addFailed( final String snapshotName )
{
this.failedSnapshotNames.add( snapshotName );
this.failedSnapshots.add( snapshotName );
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.enonic.xp.node.DeleteSnapshotParams;
import com.enonic.xp.node.DeleteSnapshotsResult;
Expand All @@ -19,8 +17,6 @@
public class SnapshotsVacuumTask
implements VacuumTask
{
private static final Logger LOG = LoggerFactory.getLogger( SnapshotsVacuumTask.class );

private static final int ORDER = 400;

private static final String NAME = "SnapshotsVacuumTask";
Expand All @@ -45,8 +41,8 @@ public VacuumTaskResult execute( final VacuumTaskParams params )
final DeleteSnapshotsResult deleteSnapshotsResult =
snapshotService.delete( DeleteSnapshotParams.create().before( Instant.now().minusMillis( params.getAgeThreshold() ) ).build() );

deleteSnapshotsResult.stream().forEach( snapshot -> builder.processed() );
deleteSnapshotsResult.getFailedSnapshotNames().forEach( snapshot -> builder.failed() );
deleteSnapshotsResult.getDeletedSnapshots().forEach( snapshot -> builder.processed() );
deleteSnapshotsResult.getFailedSnapshots().forEach( snapshot -> builder.failed() );

return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ void testDelete()
assertEquals( 2, result.getSize() );
assertTrue( result.getSet().contains( "snapshot1" ) );
assertTrue( result.getSet().contains( "snapshot3" ) );
assertEquals( 2, result.getFailedSnapshotNames().size() );
assertTrue( result.getFailedSnapshotNames().contains( "snapshot2" ) );
assertTrue( result.getFailedSnapshotNames().contains( "snapshot4" ) );
assertEquals( 2, result.getFailedSnapshots().size() );
assertTrue( result.getFailedSnapshots().contains( "snapshot2" ) );
assertTrue( result.getFailedSnapshots().contains( "snapshot4" ) );
}

private static SnapshotInfo mockSnapshot( String name, SnapshotState state, Instant endTime )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private DeleteSnapshotsResultJson( final Set<String> deletedSnapshots, final Set

public static DeleteSnapshotsResultJson from( final DeleteSnapshotsResult result )
{
return new DeleteSnapshotsResultJson( result.getSet(), result.getFailedSnapshotNames() );
return new DeleteSnapshotsResultJson( result.getDeletedSnapshots(), result.getFailedSnapshots() );
}

public Set<String> getDeletedSnapshots()
Expand Down

0 comments on commit 001465b

Please sign in to comment.