*/
String removeExpressions( String directory );
-
}
--- /dev/null
+package org.apache.archiva.rest.api.model;
+/*
+ * 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 javax.xml.bind.annotation.XmlRootElement;
+import java.util.Date;
+
+/**
+ * @author Olivier Lamy
+ * @since 1.4-M3
+ */
+@XmlRootElement( name = "archivaRepositoryStatistics" )
+public class ArchivaRepositoryStatistics
+{
+ private Date scanEndTime;
+
+ private Date scanStartTime;
+
+ private long totalArtifactCount;
+
+ private long totalArtifactFileSize;
+
+ private long totalFileCount;
+
+ private long totalGroupCount;
+
+ private long totalProjectCount;
+
+ private long newFileCount;
+
+ public ArchivaRepositoryStatistics()
+ {
+ // no op
+ }
+
+ public Date getScanEndTime()
+ {
+ return scanEndTime;
+ }
+
+ public void setScanEndTime( Date scanEndTime )
+ {
+ this.scanEndTime = scanEndTime;
+ }
+
+ public Date getScanStartTime()
+ {
+ return scanStartTime;
+ }
+
+ public void setScanStartTime( Date scanStartTime )
+ {
+ this.scanStartTime = scanStartTime;
+ }
+
+ public long getTotalArtifactCount()
+ {
+ return totalArtifactCount;
+ }
+
+ public void setTotalArtifactCount( long totalArtifactCount )
+ {
+ this.totalArtifactCount = totalArtifactCount;
+ }
+
+ public long getTotalArtifactFileSize()
+ {
+ return totalArtifactFileSize;
+ }
+
+ public void setTotalArtifactFileSize( long totalArtifactFileSize )
+ {
+ this.totalArtifactFileSize = totalArtifactFileSize;
+ }
+
+ public long getTotalFileCount()
+ {
+ return totalFileCount;
+ }
+
+ public void setTotalFileCount( long totalFileCount )
+ {
+ this.totalFileCount = totalFileCount;
+ }
+
+ public long getTotalGroupCount()
+ {
+ return totalGroupCount;
+ }
+
+ public void setTotalGroupCount( long totalGroupCount )
+ {
+ this.totalGroupCount = totalGroupCount;
+ }
+
+ public long getTotalProjectCount()
+ {
+ return totalProjectCount;
+ }
+
+ public void setTotalProjectCount( long totalProjectCount )
+ {
+ this.totalProjectCount = totalProjectCount;
+ }
+
+ public long getNewFileCount()
+ {
+ return newFileCount;
+ }
+
+ public void setNewFileCount( long newFileCount )
+ {
+ this.newFileCount = newFileCount;
+ }
+
+ @Override
+ public String toString()
+ {
+ final StringBuilder sb = new StringBuilder();
+ sb.append( "ArchivaRepositoryStatistics" );
+ sb.append( "{scanEndTime=" ).append( scanEndTime );
+ sb.append( ", scanStartTime=" ).append( scanStartTime );
+ sb.append( ", totalArtifactCount=" ).append( totalArtifactCount );
+ sb.append( ", totalArtifactFileSize=" ).append( totalArtifactFileSize );
+ sb.append( ", totalFileCount=" ).append( totalFileCount );
+ sb.append( ", totalGroupCount=" ).append( totalGroupCount );
+ sb.append( ", totalProjectCount=" ).append( totalProjectCount );
+ sb.append( ", newFileCount=" ).append( newFileCount );
+ sb.append( '}' );
+ return sb.toString();
+ }
+}
*/
import org.apache.archiva.admin.model.beans.ManagedRepository;
+import org.apache.archiva.rest.api.model.ArchivaRepositoryStatistics;
import org.apache.archiva.security.common.ArchivaRoleConstants;
import org.codehaus.plexus.redback.authorization.RedbackAuthorization;
Boolean fileLocationExists( @QueryParam( "fileLocation" ) String fileLocation )
throws ArchivaRestServiceException;
+ @Path( "getManagedRepositoryStatistics/{repositoryId}" )
+ @GET
+ @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
+ @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
+ ArchivaRepositoryStatistics getManagedRepositoryStatistics( @PathParam( "repositoryId" ) String repositoryId )
+ throws ArchivaRestServiceException;
+
}
* under the License.
*/
+import net.sf.beanlib.provider.replicator.BeanReplicator;
import org.apache.archiva.admin.model.RepositoryAdminException;
import org.apache.archiva.admin.model.RepositoryCommonValidator;
import org.apache.archiva.admin.model.beans.ManagedRepository;
import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
+import org.apache.archiva.metadata.repository.MetadataRepository;
+import org.apache.archiva.metadata.repository.MetadataRepositoryException;
+import org.apache.archiva.metadata.repository.RepositorySession;
+import org.apache.archiva.metadata.repository.RepositorySessionFactory;
+import org.apache.archiva.metadata.repository.stats.RepositoryStatistics;
+import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
+import org.apache.archiva.rest.api.model.ArchivaRepositoryStatistics;
import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import javax.inject.Inject;
+import javax.inject.Named;
import java.io.File;
import java.util.Collections;
import java.util.List;
@Inject
private RepositoryCommonValidator repositoryCommonValidator;
+ @Inject
+ private RepositoryStatisticsManager repositoryStatisticsManager;
+
+ @Inject
+ @Named( value = "repositorySessionFactory" )
+ protected RepositorySessionFactory repositorySessionFactory;
+
public List<ManagedRepository> getManagedRepositories()
throws ArchivaRestServiceException
String location = repositoryCommonValidator.removeExpressions( fileLocation );
return new File( location ).exists();
}
+
+ public ArchivaRepositoryStatistics getManagedRepositoryStatistics( String repositoryId )
+ throws ArchivaRestServiceException
+ {
+ RepositorySession repositorySession = repositorySessionFactory.createSession();
+ try
+ {
+ MetadataRepository metadataRepository = repositorySession.getRepository();
+
+ RepositoryStatistics stats = null;
+ try
+ {
+ stats = repositoryStatisticsManager.getLastStatistics( metadataRepository, repositoryId );
+ }
+ catch ( MetadataRepositoryException e )
+ {
+ log.warn( "Error retrieving repository statistics: " + e.getMessage(), e );
+ }
+ if ( stats != null )
+ {
+ ArchivaRepositoryStatistics archivaRepositoryStatistics =
+ new BeanReplicator().replicateBean( stats, ArchivaRepositoryStatistics.class );
+
+ return archivaRepositoryStatistics;
+ }
+
+ }
+ finally
+ {
+ repositorySession.close();
+ }
+ return null;
+ }
}
import org.apache.archiva.rest.api.services.RepositoriesService;
import org.apache.archiva.rest.api.services.RepositoryGroupService;
import org.apache.archiva.rest.api.services.SearchService;
+import org.apache.archiva.security.common.ArchivaRoleConstants;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
import org.apache.cxf.jaxrs.client.WebClient;
import org.codehaus.redback.rest.services.AbstractRestServicesTest;
+import org.junit.Before;
import javax.ws.rs.core.MediaType;
import java.io.File;
+import java.util.Date;
/**
* @author Olivier Lamy
// END SNIPPET: authz-header
+
+ @Override
+ @Before
+ public void startServer()
+ throws Exception
+ {
+ File appServerBase = new File( System.getProperty( "appserver.base" ) );
+
+ File jcrDirectory = new File( appServerBase, "jcr" );
+
+ if ( jcrDirectory.exists() )
+ {
+ FileUtils.deleteDirectory( jcrDirectory );
+ }
+
+ super.startServer();
+ }
+
@Override
protected String getSpringConfigLocation()
{
}
}
+
+ protected void createAndIndexRepo( String testRepoId, String repoPath )
+ throws Exception
+ {
+ if ( getManagedRepositoriesService( authorizationHeader ).getManagedRepository( testRepoId ) != null )
+ {
+ getManagedRepositoriesService( authorizationHeader ).deleteManagedRepository( testRepoId, false );
+ }
+
+ ManagedRepository managedRepository = new ManagedRepository();
+ managedRepository.setId( testRepoId );
+ managedRepository.setName( "test repo" );
+
+ managedRepository.setLocation( new File( repoPath ).getPath() );
+ managedRepository.setIndexDirectory(
+ System.getProperty( "java.io.tmpdir" ) + "/target/.index-" + Long.toString( new Date().getTime() ) );
+
+ ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
+ service.addManagedRepository( managedRepository );
+
+ getRoleManagementService( authorizationHeader ).assignTemplatedRole(
+ ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, testRepoId, "admin" );
+
+ getRepositoriesService( authorizationHeader ).scanRepositoryNow( testRepoId, true );
+
+ }
+
+ protected void deleteTestRepo( String id )
+ throws Exception
+ {
+ if ( getManagedRepositoriesService( authorizationHeader ).getManagedRepository( id ) != null )
+ {
+ getManagedRepositoriesService( authorizationHeader ).deleteManagedRepository( id, false );
+ }
+
+ }
}
*/
import org.apache.archiva.admin.model.beans.ManagedRepository;
+import org.apache.archiva.rest.api.model.ArchivaRepositoryStatistics;
import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
+import org.apache.archiva.rest.api.services.RepositoriesService;
import org.junit.Test;
import java.io.File;
}
+ @Test
+ public void getManagedRepositoryStatistics()
+ throws Exception
+ {
+
+ String testRepoId = "test-repo";
+ // force guest user creation if not exists
+ if ( getUserService( authorizationHeader ).getGuestUser() == null )
+ {
+ assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
+ }
+ createAndIndexRepo( testRepoId, "src/test/repo-with-osgi" );
+
+ ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
+
+ RepositoriesService repositoriesService = getRepositoriesService( authorizationHeader );
+
+ ArchivaRepositoryStatistics archivaRepositoryStatistics = service.getManagedRepositoryStatistics( testRepoId );
+
+ assertNotNull( archivaRepositoryStatistics );
+
+ log.info( "archivaRepositoryStatistics:" + archivaRepositoryStatistics.toString() );
+
+ assertEquals( 92, archivaRepositoryStatistics.getNewFileCount() );
+ assertEquals( 92, archivaRepositoryStatistics.getTotalFileCount() );
+
+ deleteTestRepo( testRepoId );
+ }
}
deleteTestRepo( testRepoId );
}
- private void createAndIndexRepo( String testRepoId, String repoPath )
- throws Exception
- {
- if ( getManagedRepositoriesService( authorizationHeader ).getManagedRepository( testRepoId ) != null )
- {
- getManagedRepositoriesService( authorizationHeader ).deleteManagedRepository( testRepoId, false );
- }
-
- ManagedRepository managedRepository = new ManagedRepository();
- managedRepository.setId( testRepoId );
- managedRepository.setName( "test repo" );
-
- managedRepository.setLocation( new File( repoPath ).getPath() );
- managedRepository.setIndexDirectory( "target/.index-" + Long.toString( new Date().getTime() ) );
-
- ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
- service.addManagedRepository( managedRepository );
-
- getRoleManagementService( authorizationHeader ).assignTemplatedRole(
- ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, testRepoId, "admin" );
-
- getRepositoriesService( authorizationHeader ).scanRepositoryNow( testRepoId, true );
-
- }
-
- private void deleteTestRepo( String id )
- throws Exception
- {
- if ( getManagedRepositoriesService( authorizationHeader ).getManagedRepository( id ) != null )
- {
- getManagedRepositoriesService( authorizationHeader ).deleteManagedRepository( id, false );
- }
-
- }
-
-
}