Search in sources :

Example 1 with CacheConfiguration

use of org.apache.archiva.rest.api.v2.model.CacheConfiguration in project archiva by apache.

the class DefaultSecurityConfigurationService method getCacheConfiguration.

@Override
public CacheConfiguration getCacheConfiguration() throws ArchivaRestServiceException {
    try {
        RedbackRuntimeConfiguration redbackRuntimeConfiguration = redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration();
        log.debug("getRedbackRuntimeConfiguration -> {}", redbackRuntimeConfiguration);
        return CacheConfiguration.of(redbackRuntimeConfiguration.getUsersCacheConfiguration());
    } catch (RepositoryAdminException e) {
        throw new ArchivaRestServiceException(ErrorMessage.of(REPOSITORY_ADMIN_ERROR));
    }
}
Also used : ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) RedbackRuntimeConfiguration(org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Example 2 with CacheConfiguration

use of org.apache.archiva.rest.api.v2.model.CacheConfiguration in project archiva by apache.

the class DefaultSecurityConfigurationService method updateCacheConfiguration.

@Override
public CacheConfiguration updateCacheConfiguration(CacheConfiguration cacheConfiguration) throws ArchivaRestServiceException {
    if (cacheConfiguration == null) {
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.MISSING_DATA), 400);
    }
    try {
        RedbackRuntimeConfiguration redbackRuntimeConfiguration = redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration();
        log.debug("getRedbackRuntimeConfiguration -> {}", redbackRuntimeConfiguration);
        updateConfig(cacheConfiguration, redbackRuntimeConfiguration);
        redbackRuntimeConfigurationAdmin.updateRedbackRuntimeConfiguration(redbackRuntimeConfiguration);
        return getCacheConfiguration();
    } catch (RepositoryAdminException e) {
        throw new ArchivaRestServiceException(ErrorMessage.of(REPOSITORY_ADMIN_ERROR));
    }
}
Also used : ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) RedbackRuntimeConfiguration(org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Example 3 with CacheConfiguration

use of org.apache.archiva.rest.api.v2.model.CacheConfiguration in project archiva by apache.

the class NativeSecurityConfigurationServiceTest method testUpdateCacheConfiguration.

@Test
void testUpdateCacheConfiguration() {
    String token = getAdminToken();
    try {
        Map<String, Object> jsonMap = new HashMap<>();
        jsonMap.put("time_to_idle_seconds", 1600);
        jsonMap.put("time_to_live_seconds", 12000);
        jsonMap.put("max_entries_in_memory", 500);
        jsonMap.put("max_entries_on_disk", 400);
        Response response = given().spec(getRequestSpec(token)).contentType(JSON).when().body(jsonMap).put("config/cache").then().statusCode(200).extract().response();
        assertNotNull(response);
        response = given().spec(getRequestSpec(token)).contentType(JSON).when().get("config/cache").then().statusCode(200).extract().response();
        assertNotNull(response);
        CacheConfiguration config = response.getBody().jsonPath().getObject("", CacheConfiguration.class);
        assertEquals(1600, config.getTimeToIdleSeconds());
        assertEquals(12000, config.getTimeToLiveSeconds());
        assertEquals(500, config.getMaxEntriesInMemory());
        assertEquals(400, config.getMaxEntriesOnDisk());
    } finally {
        Map<String, Object> jsonMap = new HashMap<>();
        jsonMap.put("time_to_idle_seconds", 1800);
        jsonMap.put("time_to_live_seconds", 14400);
        jsonMap.put("max_entries_in_memory", 1000);
        jsonMap.put("max_entries_on_disk", 0);
        given().spec(getRequestSpec(token)).contentType(JSON).when().body(jsonMap).put("config/cache").then().statusCode(200);
    }
}
Also used : Response(io.restassured.response.Response) HashMap(java.util.HashMap) CacheConfiguration(org.apache.archiva.rest.api.v2.model.CacheConfiguration) Test(org.junit.jupiter.api.Test)

Aggregations

RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)2 RedbackRuntimeConfiguration (org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration)2 ArchivaRestServiceException (org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException)2 Response (io.restassured.response.Response)1 HashMap (java.util.HashMap)1 CacheConfiguration (org.apache.archiva.rest.api.v2.model.CacheConfiguration)1 Test (org.junit.jupiter.api.Test)1