Switching to generics for cache implementation

This commit is contained in:
Martin Schreier 2022-01-03 20:26:49 +01:00
parent 7536a89125
commit 3756ba57f6
16 changed files with 59 additions and 17 deletions

View File

@ -324,6 +324,8 @@
</bean> </bean>
<bean name="cache#url-failures-cache" class="org.apache.archiva.components.cache.ehcache.EhcacheCache"> <bean name="cache#url-failures-cache" class="org.apache.archiva.components.cache.ehcache.EhcacheCache">
<constructor-arg index="0" value="java.lang.String"/>
<constructor-arg index="1" value="java.util.Date"/>
<property name="diskExpiryThreadIntervalSeconds" value="600"/> <property name="diskExpiryThreadIntervalSeconds" value="600"/>
<property name="diskPersistent" value="false"/> <property name="diskPersistent" value="false"/>
<property name="eternal" value="false"/> <property name="eternal" value="false"/>

View File

@ -37,6 +37,8 @@
<bean name="cache#url-failures-cache" class="org.apache.archiva.components.cache.ehcache.EhcacheCache" lazy-init="true" <bean name="cache#url-failures-cache" class="org.apache.archiva.components.cache.ehcache.EhcacheCache" lazy-init="true"
destroy-method="dispose"> destroy-method="dispose">
<constructor-arg index="0" value="java.lang.String"/>
<constructor-arg index="1" value="java.util.Date"/>
<property name="diskExpiryThreadIntervalSeconds" value="600"/> <property name="diskExpiryThreadIntervalSeconds" value="600"/>
<property name="diskPersistent" value="true"/> <property name="diskPersistent" value="true"/>
<property name="diskStorePath" value="${appserver.base}/tmp/urlcache"/> <property name="diskStorePath" value="${appserver.base}/tmp/urlcache"/>

View File

@ -30,6 +30,8 @@
<context:property-placeholder system-properties-mode="OVERRIDE"/> <context:property-placeholder system-properties-mode="OVERRIDE"/>
<bean name="cache#url-failures-cache" class="org.apache.archiva.components.cache.ehcache.EhcacheCache"> <bean name="cache#url-failures-cache" class="org.apache.archiva.components.cache.ehcache.EhcacheCache">
<constructor-arg index="0" value="java.lang.String"/>
<constructor-arg index="1" value="java.util.Date"/>
<property name="diskExpiryThreadIntervalSeconds" value="600"/> <property name="diskExpiryThreadIntervalSeconds" value="600"/>
<property name="diskPersistent" value="false"/> <property name="diskPersistent" value="false"/>
<property name="eternal" value="false"/> <property name="eternal" value="false"/>

View File

@ -109,7 +109,7 @@ public class DefaultManagedRepositoryAdmin
@Inject @Inject
@Named(value = "cache#namespaces") @Named(value = "cache#namespaces")
private Cache<String, Collection<String>> namespacesCache; private Cache<String, List<String>> namespacesCache;
@Inject @Inject
private IndexManagerFactory indexManagerFactory; private IndexManagerFactory indexManagerFactory;

View File

@ -34,6 +34,7 @@ import org.apache.archiva.configuration.util.ConfigMapper;
import org.apache.archiva.redback.configuration.UserConfiguration; import org.apache.archiva.redback.configuration.UserConfiguration;
import org.apache.archiva.redback.configuration.UserConfigurationException; import org.apache.archiva.redback.configuration.UserConfigurationException;
import org.apache.archiva.redback.configuration.UserConfigurationKeys; import org.apache.archiva.redback.configuration.UserConfigurationKeys;
import org.apache.archiva.redback.users.User;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -100,13 +101,13 @@ public class DefaultRedbackRuntimeConfigurationAdmin
LDAP_MAPPER.addBooleanMapping( LDAP_BIND_AUTHENTICATOR_ENABLED, LdapConfiguration::isBindAuthenticatorEnabled ); LDAP_MAPPER.addBooleanMapping( LDAP_BIND_AUTHENTICATOR_ENABLED, LdapConfiguration::isBindAuthenticatorEnabled );
} }
private Cache usersCache; private Cache<String, User> usersCache;
@Inject @Inject
public DefaultRedbackRuntimeConfigurationAdmin( ArchivaConfiguration archivaConfiguration,// public DefaultRedbackRuntimeConfigurationAdmin( ArchivaConfiguration archivaConfiguration,//
@Named( value = "userConfiguration#redback" ) // @Named( value = "userConfiguration#redback" ) //
UserConfiguration userConfiguration, UserConfiguration userConfiguration,
@Named( value = "cache#users" ) Cache usersCache ) @Named( value = "cache#users" ) Cache<String, User> usersCache )
{ {
this.archivaConfiguration = archivaConfiguration; this.archivaConfiguration = archivaConfiguration;
this.userConfiguration = userConfiguration; this.userConfiguration = userConfiguration;

View File

@ -68,6 +68,8 @@
<bean name="cache#url-failures-cache" class="org.apache.archiva.components.cache.ehcache.EhcacheCache" lazy-init="true" <bean name="cache#url-failures-cache" class="org.apache.archiva.components.cache.ehcache.EhcacheCache" lazy-init="true"
destroy-method="dispose"> destroy-method="dispose">
<constructor-arg index="0" value="java.lang.String"/>
<constructor-arg index="1" value="java.util.Date"/>
<property name="diskExpiryThreadIntervalSeconds" value="600"/> <property name="diskExpiryThreadIntervalSeconds" value="600"/>
<property name="diskPersistent" value="false"/> <property name="diskPersistent" value="false"/>
<property name="diskStorePath" value="${appserver.base}/tmp/urlcache"/> <property name="diskStorePath" value="${appserver.base}/tmp/urlcache"/>

View File

@ -67,7 +67,7 @@ import static org.apache.archiva.security.common.ArchivaRoleConstants.*;
* </li> * </li>
* </ul> * </ul>
* *
* @author Martin Stockhammer <martin_s@apache.org> * @author Martin Schreier <martin_s@apache.org>
* @since 3.0 * @since 3.0
*/ */
@Schema( name = "MavenManagedRepositoryService", description = "Managing and configuration of managed maven repositories" ) @Schema( name = "MavenManagedRepositoryService", description = "Managing and configuration of managed maven repositories" )
@ -425,7 +425,7 @@ public interface MavenManagedRepositoryService
permissions = { OPERATION_MANAGE_CONFIGURATION, OPERATION_DELETE_NAMESPACE }, permissions = { OPERATION_MANAGE_CONFIGURATION, OPERATION_DELETE_NAMESPACE },
resource = "{id}" resource = "{id}"
) )
@Operation( summary = "Removes a group and all subfolders from the repository", @Operation( summary = "Removes a maven group and all containing artifacts and sub groups from the repository",
security = { security = {
@SecurityRequirement( @SecurityRequirement(
name = OPERATION_MANAGE_CONFIGURATION name = OPERATION_MANAGE_CONFIGURATION

View File

@ -33,6 +33,7 @@ import org.apache.archiva.redback.policy.CookieSettings;
import org.apache.archiva.redback.policy.PasswordRule; import org.apache.archiva.redback.policy.PasswordRule;
import org.apache.archiva.redback.rbac.RBACManager; import org.apache.archiva.redback.rbac.RBACManager;
import org.apache.archiva.redback.role.RoleManager; import org.apache.archiva.redback.role.RoleManager;
import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.users.UserManager; import org.apache.archiva.redback.users.UserManager;
import org.apache.archiva.rest.api.model.ActionStatus; import org.apache.archiva.rest.api.model.ActionStatus;
import org.apache.archiva.rest.api.model.RBACManagerImplementationInformation; import org.apache.archiva.rest.api.model.RBACManagerImplementationInformation;
@ -88,7 +89,7 @@ public class DefaultRedbackRuntimeConfigurationService
@Inject @Inject
@Named(value = "cache#users") @Named(value = "cache#users")
private Cache usersCache; private Cache<String, User> usersCache;
@Inject @Inject
private LdapUserMapper ldapUserMapper; private LdapUserMapper ldapUserMapper;

View File

@ -159,7 +159,7 @@ public class DefaultRepositoriesService
*/ */
@Inject @Inject
@Named(value = "cache#namespaces") @Named(value = "cache#namespaces")
private Cache<String, Collection<String>> namespacesCache; private Cache<String, List<String>> namespacesCache;
private List<ChecksumAlgorithm> algorithms = Arrays.asList(ChecksumAlgorithm.SHA256, ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 ); private List<ChecksumAlgorithm> algorithms = Arrays.asList(ChecksumAlgorithm.SHA256, ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 );

View File

@ -128,11 +128,13 @@
<bean name="browse#versionMetadata" class="org.apache.archiva.components.cache.ehcache.EhcacheCache" <bean name="browse#versionMetadata" class="org.apache.archiva.components.cache.ehcache.EhcacheCache"
init-method="initialize"> init-method="initialize">
<constructor-arg index="0" value="java.lang.String" />
<constructor-arg index="1" value="org.apache.archiva.metadata.model.ProjectVersionMetadata"/>
<property name="diskPersistent" value="false"/> <property name="diskPersistent" value="false"/>
<property name="eternal" value="false"/> <property name="eternal" value="false"/>
<property name="maxElementsInMemory" value="1000"/> <property name="maxElementsInMemory" value="1000"/>
<property name="memoryEvictionPolicy" value="LRU"/> <property name="memoryEvictionPolicy" value="LRU"/>
<property name="name" value="userPermissions"/> <property name="name" value="versionMetadata"/>
<property name="timeToIdleSeconds" value="300"/> <property name="timeToIdleSeconds" value="300"/>
<property name="timeToLiveSeconds" value="600"/> <property name="timeToLiveSeconds" value="600"/>
</bean> </bean>

View File

@ -68,7 +68,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
* Native REST tests do not use the JAX-RS client and can be used with a remote * Native REST tests do not use the JAX-RS client and can be used with a remote
* REST API service. The tests * REST API service. The tests
* *
* @author Martin Stockhammer <martin_s@apache.org> * @author Martin Schreier <martin_s@apache.org>
*/ */
@Tag( "rest-native" ) @Tag( "rest-native" )
@Tag( "rest-v2" ) @Tag( "rest-v2" )

View File

@ -1,4 +1,4 @@
package org.apache.archiva.rest.v2.svc; package org.apache.archiva.rest.v2.svc.maven;
/* /*
* Licensed to the Apache Software Foundation (ASF) under one * Licensed to the Apache Software Foundation (ASF) under one
@ -22,6 +22,7 @@ import io.restassured.path.json.JsonPath;
import io.restassured.response.Response; import io.restassured.response.Response;
import org.apache.archiva.rest.api.v2.model.MavenManagedRepository; import org.apache.archiva.rest.api.v2.model.MavenManagedRepository;
import org.apache.archiva.rest.api.v2.svc.RestConfiguration; import org.apache.archiva.rest.api.v2.svc.RestConfiguration;
import org.apache.archiva.rest.v2.svc.AbstractNativeRestServices;
import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
@ -39,7 +40,7 @@ import static io.restassured.http.ContentType.JSON;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
/** /**
* @author Martin Stockhammer <martin_s@apache.org> * @author Martin Schreier <martin_s@apache.org>
*/ */
@TestInstance( TestInstance.Lifecycle.PER_CLASS ) @TestInstance( TestInstance.Lifecycle.PER_CLASS )
@Tag( "rest-native" ) @Tag( "rest-native" )

View File

@ -119,6 +119,8 @@
<!-- for change configuration of the users cache --> <!-- for change configuration of the users cache -->
<bean name="cache#users" class="org.apache.archiva.components.cache.ehcache.EhcacheCache" <bean name="cache#users" class="org.apache.archiva.components.cache.ehcache.EhcacheCache"
init-method="initialize"> init-method="initialize">
<constructor-arg index="0" value="java.lang.String" />
<constructor-arg index="1" value="org.apache.archiva.redback.users.User" />
<property name="diskPersistent" value="false"/> <property name="diskPersistent" value="false"/>
<property name="eternal" value="false"/> <property name="eternal" value="false"/>
<property name="maxElementsInMemory" value="1000"/> <property name="maxElementsInMemory" value="1000"/>
@ -132,6 +134,8 @@
<bean name="cache#url-failures-cache" class="org.apache.archiva.components.cache.ehcache.EhcacheCache" lazy-init="true" <bean name="cache#url-failures-cache" class="org.apache.archiva.components.cache.ehcache.EhcacheCache" lazy-init="true"
destroy-method="dispose"> destroy-method="dispose">
<constructor-arg index="0" value="java.lang.String"/>
<constructor-arg index="1" value="java.util.Date"/>
<property name="diskExpiryThreadIntervalSeconds" value="600"/> <property name="diskExpiryThreadIntervalSeconds" value="600"/>
<property name="diskPersistent" value="true"/> <property name="diskPersistent" value="true"/>
<property name="diskStorePath" value="${appserver.base}/tmp/urlcache"/> <property name="diskStorePath" value="${appserver.base}/tmp/urlcache"/>
@ -147,6 +151,8 @@
<bean name="cache#keys" class="org.apache.archiva.components.cache.ehcache.EhcacheCache" <bean name="cache#keys" class="org.apache.archiva.components.cache.ehcache.EhcacheCache"
init-method="initialize"> init-method="initialize">
<constructor-arg index="0" value="java.lang.String" />
<constructor-arg index="1" value="org.apache.archiva.redback.keys.AuthenticationKey"/>
<property name="diskPersistent" value="false"/> <property name="diskPersistent" value="false"/>
<property name="eternal" value="false"/> <property name="eternal" value="false"/>
<property name="maxElementsInMemory" value="1000"/> <property name="maxElementsInMemory" value="1000"/>
@ -158,6 +164,8 @@
<bean name="cache#operations" class="org.apache.archiva.components.cache.ehcache.EhcacheCache" <bean name="cache#operations" class="org.apache.archiva.components.cache.ehcache.EhcacheCache"
init-method="initialize"> init-method="initialize">
<constructor-arg index="0" value="java.lang.String"/>
<constructor-arg index="1" value="org.apache.archiva.redback.rbac.Operation" />
<property name="diskPersistent" value="false"/> <property name="diskPersistent" value="false"/>
<property name="eternal" value="false"/> <property name="eternal" value="false"/>
<property name="maxElementsInMemory" value="1000"/> <property name="maxElementsInMemory" value="1000"/>
@ -169,6 +177,8 @@
<bean name="cache#permissions" class="org.apache.archiva.components.cache.ehcache.EhcacheCache" <bean name="cache#permissions" class="org.apache.archiva.components.cache.ehcache.EhcacheCache"
init-method="initialize"> init-method="initialize">
<constructor-arg index="0" value="java.lang.String"/>
<constructor-arg index="1" value="org.apache.archiva.redback.rbac.Permission" />
<property name="diskPersistent" value="false"/> <property name="diskPersistent" value="false"/>
<property name="eternal" value="false"/> <property name="eternal" value="false"/>
<property name="maxElementsInMemory" value="1000"/> <property name="maxElementsInMemory" value="1000"/>
@ -180,6 +190,8 @@
<bean name="cache#resources" class="org.apache.archiva.components.cache.ehcache.EhcacheCache" <bean name="cache#resources" class="org.apache.archiva.components.cache.ehcache.EhcacheCache"
init-method="initialize"> init-method="initialize">
<constructor-arg index="0" value="java.lang.String"/>
<constructor-arg index="1" value="org.apache.archiva.redback.rbac.Resource" />
<property name="diskPersistent" value="false"/> <property name="diskPersistent" value="false"/>
<property name="eternal" value="false"/> <property name="eternal" value="false"/>
<property name="maxElementsInMemory" value="1000"/> <property name="maxElementsInMemory" value="1000"/>
@ -191,6 +203,8 @@
<bean name="cache#roles" class="org.apache.archiva.components.cache.ehcache.EhcacheCache" <bean name="cache#roles" class="org.apache.archiva.components.cache.ehcache.EhcacheCache"
init-method="initialize"> init-method="initialize">
<constructor-arg index="0" value="java.lang.String"/>
<constructor-arg index="1" value="org.apache.archiva.redback.rbac.Role" />
<property name="diskPersistent" value="false"/> <property name="diskPersistent" value="false"/>
<property name="eternal" value="false"/> <property name="eternal" value="false"/>
<property name="maxElementsInMemory" value="1000"/> <property name="maxElementsInMemory" value="1000"/>
@ -202,6 +216,8 @@
<bean name="cache#effectiveRoleSet" class="org.apache.archiva.components.cache.ehcache.EhcacheCache" <bean name="cache#effectiveRoleSet" class="org.apache.archiva.components.cache.ehcache.EhcacheCache"
init-method="initialize"> init-method="initialize">
<constructor-arg index="0" value="java.lang.String"/>
<constructor-arg index="1" value="java.util.HashSet" />
<property name="diskPersistent" value="false"/> <property name="diskPersistent" value="false"/>
<property name="eternal" value="false"/> <property name="eternal" value="false"/>
<property name="maxElementsInMemory" value="1000"/> <property name="maxElementsInMemory" value="1000"/>
@ -217,6 +233,8 @@
<bean name="cache#userAssignments" class="org.apache.archiva.components.cache.ehcache.EhcacheCache" <bean name="cache#userAssignments" class="org.apache.archiva.components.cache.ehcache.EhcacheCache"
init-method="initialize"> init-method="initialize">
<constructor-arg index="0" value="java.lang.String"/>
<constructor-arg index="1" value="org.apache.archiva.redback.rbac.UserAssignment" />
<property name="diskPersistent" value="false"/> <property name="diskPersistent" value="false"/>
<property name="eternal" value="false"/> <property name="eternal" value="false"/>
<property name="maxElementsInMemory" value="1000"/> <property name="maxElementsInMemory" value="1000"/>
@ -228,6 +246,8 @@
<bean name="cache#userPermissions" class="org.apache.archiva.components.cache.ehcache.EhcacheCache" <bean name="cache#userPermissions" class="org.apache.archiva.components.cache.ehcache.EhcacheCache"
init-method="initialize"> init-method="initialize">
<constructor-arg index="0" value="java.lang.String"/>
<constructor-arg index="1" value="java.util.HashMap" />
<property name="diskPersistent" value="false"/> <property name="diskPersistent" value="false"/>
<property name="eternal" value="false"/> <property name="eternal" value="false"/>
<property name="maxElementsInMemory" value="1000"/> <property name="maxElementsInMemory" value="1000"/>
@ -239,6 +259,8 @@
<bean name="cache#ldapRoles" class="org.apache.archiva.components.cache.ehcache.EhcacheCache" <bean name="cache#ldapRoles" class="org.apache.archiva.components.cache.ehcache.EhcacheCache"
init-method="initialize"> init-method="initialize">
<constructor-arg index="0" value="java.lang.String"/>
<constructor-arg index="1" value="org.apache.archiva.redback.rbac.Role"/>
<property name="diskPersistent" value="false"/> <property name="diskPersistent" value="false"/>
<property name="eternal" value="false"/> <property name="eternal" value="false"/>
<property name="maxElementsInMemory" value="1000"/> <property name="maxElementsInMemory" value="1000"/>
@ -250,6 +272,8 @@
<bean name="cache#namespaces" class="org.apache.archiva.components.cache.ehcache.EhcacheCache" <bean name="cache#namespaces" class="org.apache.archiva.components.cache.ehcache.EhcacheCache"
init-method="initialize"> init-method="initialize">
<constructor-arg index="0" value="java.lang.String" />
<constructor-arg index="1" value="java.util.ArrayList"/>
<property name="diskPersistent" value="false"/> <property name="diskPersistent" value="false"/>
<property name="eternal" value="false"/> <property name="eternal" value="false"/>
<property name="maxElementsInMemory" value="1000"/> <property name="maxElementsInMemory" value="1000"/>

View File

@ -20,6 +20,7 @@ package org.apache.archiva.metadata.model;
*/ */
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -28,8 +29,10 @@ import java.util.Properties;
@XmlRootElement( name = "projectVersionMetadata" ) @XmlRootElement( name = "projectVersionMetadata" )
public class ProjectVersionMetadata public class ProjectVersionMetadata
extends FacetedMetadata extends FacetedMetadata implements Serializable
{ {
private static final long serialVersionUID = 5506968284780639002L;
/** /**
* id is the version * id is the version
*/ */

View File

@ -93,7 +93,7 @@ public class DefaultMetadataResolver
*/ */
@Inject @Inject
@Named( value = "cache#namespaces" ) @Named( value = "cache#namespaces" )
private Cache<String, Collection<String>> namespacesCache; private Cache<String, List<String>> namespacesCache;
@Override @Override
public ProjectVersionMetadata resolveProjectVersion( RepositorySession session, String repoId, String namespace, public ProjectVersionMetadata resolveProjectVersion( RepositorySession session, String repoId, String namespace,
@ -193,7 +193,7 @@ public class DefaultMetadataResolver
try try
{ {
Collection<String> namespaces = namespacesCache.get( repoId ); List<String> namespaces = namespacesCache.get( repoId );
if ( namespaces != null ) if ( namespaces != null )
{ {
return namespaces; return namespaces;
@ -246,7 +246,7 @@ public class DefaultMetadataResolver
{ {
MetadataRepository metadataRepository = session.getRepository(); MetadataRepository metadataRepository = session.getRepository();
String cacheKey = repoId + "-" + namespace; String cacheKey = repoId + "-" + namespace;
Collection<String> namespaces = namespacesCache.get( cacheKey ); List<String> namespaces = namespacesCache.get( cacheKey );
if ( namespaces == null ) if ( namespaces == null )
{ {
namespaces = metadataRepository.getChildNamespaces( session, repoId, namespace ); namespaces = metadataRepository.getChildNamespaces( session, repoId, namespace );
@ -299,7 +299,7 @@ public class DefaultMetadataResolver
Collection<String> exclusions = new ArrayList<>( projects ); Collection<String> exclusions = new ArrayList<>( projects );
String cacheKey = repoId + "-" + namespace; String cacheKey = repoId + "-" + namespace;
Collection<String> namespaces = namespacesCache.get( cacheKey ); List<String> namespaces = namespacesCache.get( cacheKey );
if ( namespaces == null ) if ( namespaces == null )
{ {
namespaces = metadataRepository.getChildNamespaces( session, repoId, namespace ); namespaces = metadataRepository.getChildNamespaces( session, repoId, namespace );

View File

@ -41,11 +41,13 @@
<bean name="cache#namespaces" class="org.apache.archiva.components.cache.ehcache.EhcacheCache" <bean name="cache#namespaces" class="org.apache.archiva.components.cache.ehcache.EhcacheCache"
init-method="initialize"> init-method="initialize">
<constructor-arg index="0" value="java.lang.String" />
<constructor-arg index="1" value="java.util.ArrayList"/>
<property name="diskPersistent" value="false"/> <property name="diskPersistent" value="false"/>
<property name="eternal" value="false"/> <property name="eternal" value="false"/>
<property name="maxElementsInMemory" value="1000"/> <property name="maxElementsInMemory" value="1000"/>
<property name="memoryEvictionPolicy" value="LRU"/> <property name="memoryEvictionPolicy" value="LRU"/>
<property name="name" value="usersCache"/> <property name="name" value="namespaces"/>
<property name="timeToIdleSeconds" value="600"/> <property name="timeToIdleSeconds" value="600"/>
<property name="timeToLiveSeconds" value="600"/> <property name="timeToLiveSeconds" value="600"/>
</bean> </bean>