diff options
author | Olivier Lamy <olamy@apache.org> | 2012-12-28 21:40:29 +0000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2012-12-28 21:40:29 +0000 |
commit | 46a1c6516952db6c81e8bf9102aa1a055cc90a63 (patch) | |
tree | c3010bc786cb13f22eccd6bf8025521a5f07f8d3 /archiva-modules/archiva-web/archiva-rest | |
parent | aa482e9b9bef10d2cebf4e00357f38a8c0324ed2 (diff) | |
download | archiva-46a1c6516952db6c81e8bf9102aa1a055cc90a63.tar.gz archiva-46a1c6516952db6c81e8bf9102aa1a055cc90a63.zip |
[MRM-526] add services to configure the cache
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1426642 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-web/archiva-rest')
2 files changed, 136 insertions, 0 deletions
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ArchivaRuntimeConfigurationService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ArchivaRuntimeConfigurationService.java new file mode 100644 index 000000000..f3f62740a --- /dev/null +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ArchivaRuntimeConfigurationService.java @@ -0,0 +1,53 @@ +package org.apache.archiva.rest.api.services; +/* + * 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 org.apache.archiva.admin.model.beans.ArchivaRuntimeConfiguration; +import org.apache.archiva.redback.authorization.RedbackAuthorization; +import org.apache.archiva.security.common.ArchivaRoleConstants; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +/** + * @author Olivier Lamy + * @since 1.4-M4 + */ +@Path( "/archivaRuntimeConfigurationService/" ) +public interface ArchivaRuntimeConfigurationService +{ + @Path( "archivaRuntimeConfiguration" ) + @GET + @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) + @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION ) + ArchivaRuntimeConfiguration getArchivaRuntimeConfiguration() + throws ArchivaRestServiceException; + + @Path( "archivaRuntimeConfiguration" ) + @PUT + @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) + @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) + @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION ) + Boolean updateArchivaRuntimeConfiguration( ArchivaRuntimeConfiguration archivaRuntimeConfiguration ) + throws ArchivaRestServiceException; +} diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaRuntimeConfigurationService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaRuntimeConfigurationService.java new file mode 100644 index 000000000..e39af9ba7 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaRuntimeConfigurationService.java @@ -0,0 +1,83 @@ +package org.apache.archiva.rest.services; +/* + * 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 org.apache.archiva.admin.model.RepositoryAdminException; +import org.apache.archiva.admin.model.beans.ArchivaRuntimeConfiguration; +import org.apache.archiva.admin.model.beans.CacheConfiguration; +import org.apache.archiva.admin.model.runtime.ArchivaRuntimeConfigurationAdmin; +import org.apache.archiva.redback.components.cache.Cache; +import org.apache.archiva.rest.api.services.ArchivaRestServiceException; +import org.apache.archiva.rest.api.services.ArchivaRuntimeConfigurationService; +import org.springframework.stereotype.Service; + +import javax.inject.Inject; +import javax.inject.Named; + +/** + * @author Olivier Lamy + * @since 1.4-M4 + */ +@Service( "archivaRuntimeConfigurationService#rest" ) +public class DefaultArchivaRuntimeConfigurationService + extends AbstractRestService + implements ArchivaRuntimeConfigurationService +{ + @Inject + private ArchivaRuntimeConfigurationAdmin archivaRuntimeConfigurationAdmin; + + @Inject + @Named( value = "cache#url-failures-cache" ) + private Cache usersCache; + + public ArchivaRuntimeConfiguration getArchivaRuntimeConfiguration() + throws ArchivaRestServiceException + { + try + { + return archivaRuntimeConfigurationAdmin.getArchivaRuntimeConfiguration(); + } + catch ( RepositoryAdminException e ) + { + throw new ArchivaRestServiceException( e.getMessage(), e ); + } + } + + public Boolean updateArchivaRuntimeConfiguration( ArchivaRuntimeConfiguration archivaRuntimeConfiguration ) + throws ArchivaRestServiceException + { + try + { + archivaRuntimeConfigurationAdmin.updateArchivaRuntimeConfiguration( archivaRuntimeConfiguration ); + CacheConfiguration cacheConfiguration = archivaRuntimeConfiguration.getUrlFailureCacheConfiguration(); + if ( cacheConfiguration != null ) + { + usersCache.setTimeToLiveSeconds( cacheConfiguration.getTimeToLiveSeconds() ); + usersCache.setTimeToIdleSeconds( cacheConfiguration.getTimeToIdleSeconds() ); + usersCache.setMaxElementsOnDisk( cacheConfiguration.getMaxElementsOnDisk() ); + usersCache.setMaxElementsInMemory( cacheConfiguration.getMaxElementsInMemory() ); + } + } + catch ( RepositoryAdminException e ) + { + throw new ArchivaRestServiceException( e.getMessage(), e ); + } + return Boolean.TRUE; + } +} |