[MRM-1293] remove use of repository content statistics from the managed repository deletion

git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@888245 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2009-12-08 04:02:18 +00:00
parent 1edb4874b2
commit 2a3f4b76be
6 changed files with 61 additions and 184 deletions

View File

@ -24,18 +24,17 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import com.opensymphony.xwork2.Preparable; import com.opensymphony.xwork2.Preparable;
import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
import org.apache.maven.archiva.database.ArchivaDAO;
import org.apache.maven.archiva.database.ArchivaDatabaseException; import org.apache.maven.archiva.database.ArchivaDatabaseException;
import org.apache.maven.archiva.database.ArtifactDAO;
import org.apache.maven.archiva.database.Constraint; import org.apache.maven.archiva.database.Constraint;
import org.apache.maven.archiva.database.ObjectNotFoundException; import org.apache.maven.archiva.database.ObjectNotFoundException;
import org.apache.maven.archiva.database.constraints.ArtifactsByRepositoryConstraint; import org.apache.maven.archiva.database.constraints.ArtifactsByRepositoryConstraint;
import org.apache.maven.archiva.database.constraints.RepositoryContentStatisticsByRepositoryConstraint;
import org.apache.maven.archiva.model.ArchivaArtifact; import org.apache.maven.archiva.model.ArchivaArtifact;
import org.apache.maven.archiva.model.RepositoryContentStatistics;
import org.apache.maven.archiva.repository.audit.AuditEvent; import org.apache.maven.archiva.repository.audit.AuditEvent;
import org.codehaus.plexus.redback.role.RoleManagerException; import org.codehaus.plexus.redback.role.RoleManagerException;
@ -56,7 +55,12 @@ public class DeleteManagedRepositoryAction
/** /**
* @plexus.requirement role-hint="jdo" * @plexus.requirement role-hint="jdo"
*/ */
private ArchivaDAO archivaDAO; private ArtifactDAO artifactDao;
/**
* @plexus.requirement
*/
private RepositoryStatisticsManager repositoryStatisticsManager;
public void prepare() public void prepare()
{ {
@ -96,7 +100,7 @@ public class DeleteManagedRepositoryAction
return ERROR; return ERROR;
} }
String result = SUCCESS; String result;
try try
{ {
@ -138,7 +142,7 @@ public class DeleteManagedRepositoryAction
{ {
removeRepositoryRoles( cleanupRepository ); removeRepositoryRoles( cleanupRepository );
cleanupDatabase( cleanupRepository.getId() ); cleanupDatabase( cleanupRepository.getId() );
cleanupScanStats( cleanupRepository.getId() ); repositoryStatisticsManager.deleteStatistics( cleanupRepository.getId() );
// TODO: delete all content for a repository from the content API? // TODO: delete all content for a repository from the content API?
List<ProxyConnectorConfiguration> proxyConnectors = getProxyConnectors(); List<ProxyConnectorConfiguration> proxyConnectors = getProxyConnectors();
@ -169,14 +173,14 @@ public class DeleteManagedRepositoryAction
{ {
Constraint constraint = new ArtifactsByRepositoryConstraint( repoId ); Constraint constraint = new ArtifactsByRepositoryConstraint( repoId );
List<ArchivaArtifact> artifacts = archivaDAO.getArtifactDAO().queryArtifacts( constraint ); List<ArchivaArtifact> artifacts = artifactDao.queryArtifacts( constraint );
for ( ArchivaArtifact artifact : artifacts ) for ( ArchivaArtifact artifact : artifacts )
{ {
log.info( "Removing artifact " + artifact + " from the database." ); log.info( "Removing artifact " + artifact + " from the database." );
try try
{ {
archivaDAO.getArtifactDAO().deleteArtifact( artifact ); artifactDao.deleteArtifact( artifact );
} }
catch ( ObjectNotFoundException oe ) catch ( ObjectNotFoundException oe )
@ -192,19 +196,6 @@ public class DeleteManagedRepositoryAction
} }
} }
private void cleanupScanStats( String repoId )
throws ArchivaDatabaseException
{
List<RepositoryContentStatistics> results =
archivaDAO.getRepositoryContentStatisticsDAO().queryRepositoryContentStatistics(
new RepositoryContentStatisticsByRepositoryConstraint( repoId ) );
for ( RepositoryContentStatistics stats : results )
{
archivaDAO.getRepositoryContentStatisticsDAO().deleteRepositoryContentStatistics( stats );
}
}
public ManagedRepositoryConfiguration getRepository() public ManagedRepositoryConfiguration getRepository()
{ {
return repository; return repository;
@ -225,13 +216,13 @@ public class DeleteManagedRepositoryAction
this.repoid = repoid; this.repoid = repoid;
} }
public void setArchivaDAO( ArchivaDAO archivaDAO ) public void setRepositoryStatisticsManager( RepositoryStatisticsManager repositoryStatisticsManager )
{ {
this.archivaDAO = archivaDAO; this.repositoryStatisticsManager = repositoryStatisticsManager;
} }
public ArchivaDAO getArchivaDAO() public void setArtifactDao( ArtifactDAO artifactDao )
{ {
return archivaDAO; this.artifactDao = artifactDao;
} }
} }

View File

@ -19,6 +19,9 @@ package org.apache.maven.archiva.web.action.admin.repositories;
* under the License. * under the License.
*/ */
import java.io.File;
import java.util.Collections;
import com.opensymphony.xwork2.Action; import com.opensymphony.xwork2.Action;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ArchivaConfiguration;
@ -26,14 +29,11 @@ import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.security.ArchivaRoleConstants; import org.apache.maven.archiva.security.ArchivaRoleConstants;
import org.codehaus.plexus.redback.role.RoleManager; import org.codehaus.plexus.redback.role.RoleManager;
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
import org.codehaus.redback.integration.interceptor.SecureActionBundle; import org.codehaus.redback.integration.interceptor.SecureActionBundle;
import org.codehaus.redback.integration.interceptor.SecureActionException; import org.codehaus.redback.integration.interceptor.SecureActionException;
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
import org.easymock.MockControl; import org.easymock.MockControl;
import java.io.File;
import java.util.Collections;
/** /**
* AddManagedRepositoryActionTest * AddManagedRepositoryActionTest
* *
@ -68,7 +68,7 @@ public class AddManagedRepositoryActionTest
{ {
super.setUp(); super.setUp();
action = (AddManagedRepositoryAction) lookup( Action.class.getName(), "addManagedRepositoryAction" ); action = new AddManagedRepositoryAction();
archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();

View File

@ -25,6 +25,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import com.opensymphony.xwork2.Action; import com.opensymphony.xwork2.Action;
import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.IndeterminateConfigurationException; import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
@ -63,6 +64,10 @@ public class DeleteManagedRepositoryActionTest
private File location; private File location;
private MockControl repositoryStatisticsManagerControl;
private RepositoryStatisticsManager repositoryStatisticsManager;
@Override @Override
protected String getPlexusConfigLocation() protected String getPlexusConfigLocation()
{ {
@ -74,7 +79,7 @@ public class DeleteManagedRepositoryActionTest
{ {
super.setUp(); super.setUp();
action = (DeleteManagedRepositoryAction) lookup( Action.class.getName(), "deleteManagedRepositoryAction" ); action = new DeleteManagedRepositoryAction();
archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
@ -83,7 +88,13 @@ public class DeleteManagedRepositoryActionTest
roleManagerControl = MockControl.createControl( RoleManager.class ); roleManagerControl = MockControl.createControl( RoleManager.class );
roleManager = (RoleManager) roleManagerControl.getMock(); roleManager = (RoleManager) roleManagerControl.getMock();
action.setRoleManager( roleManager ); action.setRoleManager( roleManager );
location = getTestFile( "target/test/location" ); location = getTestFile( "target/test/location" );
repositoryStatisticsManagerControl = MockControl.createControl( RepositoryStatisticsManager.class );
repositoryStatisticsManager = (RepositoryStatisticsManager) repositoryStatisticsManagerControl.getMock();
action.setRepositoryStatisticsManager( repositoryStatisticsManager );
action.setArtifactDao( new ArtifactDAOStub() );
} }
public void testSecureActionBundle() public void testSecureActionBundle()
@ -126,7 +137,11 @@ public class DeleteManagedRepositoryActionTest
public void testDeleteRepositoryKeepContent() public void testDeleteRepositoryKeepContent()
throws Exception throws Exception
{ {
// even when we keep the content, we don't keep the metadata at this point
repositoryStatisticsManager.deleteStatistics( REPO_ID );
repositoryStatisticsManagerControl.replay();
prepareRoleManagerMock(); prepareRoleManagerMock();
Configuration configuration = prepDeletionTest( createRepository(), 4 ); Configuration configuration = prepDeletionTest( createRepository(), 4 );
@ -138,11 +153,16 @@ public class DeleteManagedRepositoryActionTest
assertTrue( configuration.getManagedRepositories().isEmpty() ); assertTrue( configuration.getManagedRepositories().isEmpty() );
assertTrue( location.exists() ); assertTrue( location.exists() );
repositoryStatisticsManagerControl.verify();
} }
public void testDeleteRepositoryDeleteContent() public void testDeleteRepositoryDeleteContent()
throws Exception throws Exception
{ {
repositoryStatisticsManager.deleteStatistics( REPO_ID );
repositoryStatisticsManagerControl.replay();
prepareRoleManagerMock(); prepareRoleManagerMock();
Configuration configuration = prepDeletionTest( createRepository(), 4 ); Configuration configuration = prepDeletionTest( createRepository(), 4 );
@ -154,11 +174,16 @@ public class DeleteManagedRepositoryActionTest
assertTrue( configuration.getManagedRepositories().isEmpty() ); assertTrue( configuration.getManagedRepositories().isEmpty() );
assertFalse( location.exists() ); assertFalse( location.exists() );
repositoryStatisticsManagerControl.verify();
} }
public void testDeleteRepositoryAndAssociatedProxyConnectors() public void testDeleteRepositoryAndAssociatedProxyConnectors()
throws Exception throws Exception
{ {
repositoryStatisticsManager.deleteStatistics( REPO_ID );
repositoryStatisticsManagerControl.replay();
Configuration configuration = prepDeletionTest( createRepository(), 5 ); Configuration configuration = prepDeletionTest( createRepository(), 5 );
configuration.addRemoteRepository( createRemoteRepository( "codehaus", "http://repository.codehaus.org" ) ); configuration.addRemoteRepository( createRemoteRepository( "codehaus", "http://repository.codehaus.org" ) );
configuration.addRemoteRepository( createRemoteRepository( "java.net", "http://dev.java.net/maven2" ) ); configuration.addRemoteRepository( createRemoteRepository( "java.net", "http://dev.java.net/maven2" ) );
@ -175,11 +200,15 @@ public class DeleteManagedRepositoryActionTest
assertEquals( 0, configuration.getProxyConnectors().size() ); assertEquals( 0, configuration.getProxyConnectors().size() );
assertFalse( location.exists() ); assertFalse( location.exists() );
repositoryStatisticsManagerControl.verify();
} }
public void testDeleteRepositoryCancelled() public void testDeleteRepositoryCancelled()
throws Exception throws Exception
{ {
repositoryStatisticsManagerControl.replay();
ManagedRepositoryConfiguration originalRepository = createRepository(); ManagedRepositoryConfiguration originalRepository = createRepository();
Configuration configuration = prepDeletionTest( originalRepository, 3 ); Configuration configuration = prepDeletionTest( originalRepository, 3 );
String status = action.execute(); String status = action.execute();
@ -190,11 +219,16 @@ public class DeleteManagedRepositoryActionTest
assertEquals( Collections.singletonList( originalRepository ), configuration.getManagedRepositories() ); assertEquals( Collections.singletonList( originalRepository ), configuration.getManagedRepositories() );
assertTrue( location.exists() ); assertTrue( location.exists() );
repositoryStatisticsManagerControl.verify();
} }
public void testDeleteRepositoryAndReposUnderRepoGroup() public void testDeleteRepositoryAndReposUnderRepoGroup()
throws Exception throws Exception
{ {
repositoryStatisticsManager.deleteStatistics( REPO_ID );
repositoryStatisticsManagerControl.replay();
Configuration configuration = prepDeletionTest( createRepository(), 5 ); Configuration configuration = prepDeletionTest( createRepository(), 5 );
List<String> repoIds = new ArrayList<String>(); List<String> repoIds = new ArrayList<String>();
repoIds.add( REPO_ID ); repoIds.add( REPO_ID );
@ -211,6 +245,8 @@ public class DeleteManagedRepositoryActionTest
assertEquals( 0, ( ( RepositoryGroupConfiguration ) configuration.getRepositoryGroups().get( 0 ) ).getRepositories().size() ); assertEquals( 0, ( ( RepositoryGroupConfiguration ) configuration.getRepositoryGroups().get( 0 ) ).getRepositories().size() );
assertFalse( location.exists() ); assertFalse( location.exists() );
repositoryStatisticsManagerControl.verify();
} }
private Configuration prepDeletionTest( ManagedRepositoryConfiguration originalRepository, int expectCountGetConfig ) private Configuration prepDeletionTest( ManagedRepositoryConfiguration originalRepository, int expectCountGetConfig )

View File

@ -68,7 +68,7 @@ public class EditManagedRepositoryActionTest
{ {
super.setUp(); super.setUp();
action = (EditManagedRepositoryAction) lookup( Action.class.getName(), "editManagedRepositoryAction" ); action = new EditManagedRepositoryAction();
archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();

View File

@ -1,82 +0,0 @@
<!--
~ 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.
-->
<plexus>
<components>
<component>
<role>com.opensymphony.xwork2.Action</role>
<role-hint>addManagedRepositoryAction</role-hint>
<implementation>org.apache.maven.archiva.web.action.admin.repositories.AddManagedRepositoryAction</implementation>
<instantiation-strategy>per-lookup</instantiation-strategy>
<!-- no requirements set -->
</component>
<component>
<role>com.opensymphony.xwork2.Action</role>
<role-hint>deleteManagedRepositoryAction</role-hint>
<implementation>org.apache.maven.archiva.web.action.admin.repositories.DeleteManagedRepositoryAction</implementation>
<instantiation-strategy>per-lookup</instantiation-strategy>
<requirements>
<requirement>
<role>org.apache.maven.archiva.database.ArchivaDAO</role>
<role-hint>jdo</role-hint>
<field-name>archivaDAO</field-name>
</requirement>
</requirements>
</component>
<component>
<role>com.opensymphony.xwork2.Action</role>
<role-hint>editManagedRepositoryAction</role-hint>
<implementation>org.apache.maven.archiva.web.action.admin.repositories.EditManagedRepositoryAction</implementation>
<instantiation-strategy>per-lookup</instantiation-strategy>
<!-- no requirements set -->
</component>
<!-- DAO : Stubs -->
<component>
<role>org.apache.maven.archiva.database.ArchivaDAO</role>
<role-hint>jdo</role-hint>
<implementation>org.apache.maven.archiva.web.action.admin.repositories.AbstractManagedRepositoryArchivaDAOStub</implementation>
<requirements>
<requirement>
<role>org.apache.maven.archiva.database.ArtifactDAO</role>
<role-hint>jdo</role-hint>
<field-name>artifactDAO</field-name>
</requirement>
<requirement>
<role>org.apache.maven.archiva.database.RepositoryContentStatisticsDAO</role>
<role-hint>jdo</role-hint>
<field-name>repoContentStatisticsDAO</field-name>
</requirement>
</requirements>
</component>
<component>
<role>org.apache.maven.archiva.database.ArtifactDAO</role>
<role-hint>jdo</role-hint>
<implementation>org.apache.maven.archiva.web.action.admin.repositories.ArtifactDAOStub</implementation>
</component>
<component>
<role>org.apache.maven.archiva.database.RepositoryContentStatisticsDAO</role>
<role-hint>jdo</role-hint>
<implementation>org.apache.maven.archiva.web.action.admin.repositories.RepositoryContentStatisticsDAOStub</implementation>
</component>
</components>
</plexus>

View File

@ -1,68 +0,0 @@
<!--
~ 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.
-->
<plexus>
<components>
<component>
<role>org.codehaus.plexus.redback.role.RoleManager</role>
<role-hint>default</role-hint>
<implementation>org.apache.maven.archiva.web.action.admin.repositories.RoleManagerStub</implementation>
</component>
<component>
<role>com.opensymphony.xwork2.Action</role>
<role-hint>deleteManagedRepositoryAction</role-hint>
<implementation>org.apache.maven.archiva.web.action.admin.repositories.DeleteManagedRepositoryAction</implementation>
<instantiation-strategy>per-lookup</instantiation-strategy>
<requirements>
<requirement>
<role>org.apache.maven.archiva.database.ArchivaDAO</role>
<role-hint>jdo</role-hint>
<field-name>archivaDAO</field-name>
</requirement>
</requirements>
</component>
<component>
<role>org.apache.maven.archiva.database.ArchivaDAO</role>
<role-hint>jdo</role-hint>
<implementation>org.apache.maven.archiva.web.action.admin.repositories.DeleteManagedRepositoryArchivaDAOStub</implementation>
<requirements>
<requirement>
<role>org.apache.maven.archiva.database.ArtifactDAO</role>
<role-hint>jdo</role-hint>
<field-name>artifactDAO</field-name>
</requirement>
<requirement>
<role>org.apache.maven.archiva.database.RepositoryContentStatisticsDAO</role>
<role-hint>jdo</role-hint>
<field-name>repoContentStatisticsDAO</field-name>
</requirement>
</requirements>
</component>
<component>
<role>org.apache.maven.archiva.database.ArtifactDAO</role>
<role-hint>jdo</role-hint>
<implementation>org.apache.maven.archiva.web.action.admin.repositories.ArtifactDAOStub</implementation>
</component>
<component>
<role>org.apache.maven.archiva.database.RepositoryContentStatisticsDAO</role>
<role-hint>jdo</role-hint>
<implementation>org.apache.maven.archiva.web.action.admin.repositories.RepositoryContentStatisticsDAOStub</implementation>
</component>
</components>
</plexus>