Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(QTDI-1188): call reset cache endpoint #989

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 19 additions & 34 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,9 @@ pipeline {

parameters {
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
separator(name: "BASIC_CONFIG",
sectionHeader: "Basic configuration",
separator(name: "BASIC_CONFIG", sectionHeader: "Basic configuration",
sectionHeaderStyle: """ background-color: #ABEBC6;
text-align: center; font-size: 35px !important; font-weight : bold;
""")
text-align: center; font-size: 35px !important; font-weight : bold; """)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
choice(
name: 'Action',
Expand All @@ -131,23 +129,19 @@ pipeline {
description: 'Force documentation stage for development branches. No effect on master and maintenance.')

string(name: 'JAVA_VERSION',
defaultValue: 'adoptopenjdk-17.0.5+8',
defaultValue: 'from .tool-versions',
description: """Provided java version will be installed with asdf
Examples: adoptopenjdk-11.0.22+7, adoptopenjdk-17.0.11+9
""")
Examples: adoptopenjdk-11.0.22+7, adoptopenjdk-17.0.11+9 """)

string(name: 'MAVEN_VERSION',
defaultValue: '3.8.8',
defaultValue: 'from .tool-versions',
description: """Provided maven version will be installed with asdf
Examples: 3.8.8, 4.0.0-beta-4
""")
Examples: 3.8.8, 4.0.0-beta-4 """)

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
separator(name: "DEPLOY_CONFIG",
sectionHeader: "Deployment configuration",
separator(name: "DEPLOY_CONFIG", sectionHeader: "Deployment configuration",
sectionHeaderStyle: """ background-color: #F9E79F;
text-align: center; font-size: 35px !important; font-weight : bold;
""")
text-align: center; font-size: 35px !important; font-weight : bold; """)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
booleanParam(
name: 'MAVEN_DEPLOY',
Expand All @@ -171,11 +165,9 @@ pipeline {
description: 'Choose which docker image you want to build and push. Only available if DOCKER_PUSH == True.')

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
separator(name: "QUALIFIER_CONFIG",
sectionHeader: "Qualifier configuration",
separator(name: "QUALIFIER_CONFIG", sectionHeader: "Qualifier configuration",
sectionHeaderStyle: """ background-color: #AED6F1;
text-align: center; font-size: 35px !important; font-weight : bold;
""")
text-align: center; font-size: 35px !important; font-weight : bold; """)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
string(
name: 'VERSION_QUALIFIER',
Expand All @@ -186,11 +178,9 @@ pipeline {
From "user/JIRA-12345_some_information" the qualifier will be JIRA-12345.''')

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
separator(name: "ADVANCED_CONFIG",
sectionHeader: "Advanced configuration",
separator(name: "ADVANCED_CONFIG", sectionHeader: "Advanced configuration",
sectionHeaderStyle: """ background-color: #F8C471;
text-align: center; font-size: 35px !important; font-weight : bold;
""")
text-align: center; font-size: 35px !important; font-weight : bold; """)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
string(
name: 'EXTRA_BUILD_PARAMS',
Expand All @@ -210,19 +200,15 @@ pipeline {
description: 'Force dependencies report stage for branches.')

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
separator(name: "EXPERT_CONFIG",
sectionHeader: "Expert configuration",
separator(name: "EXPERT_CONFIG", sectionHeader: "Expert configuration",
sectionHeaderStyle: """ background-color: #A9A9A9;
text-align: center; font-size: 35px !important; font-weight : bold;
""")
text-align: center; font-size: 35px !important; font-weight : bold;""")
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
separator(name: "DEBUG_CONFIG",
sectionHeader: "Jenkins job debug configuration ",
separator(name: "DEBUG_CONFIG", sectionHeader: "Jenkins job debug configuration ",
sectionHeaderStyle: """ background-color: #FF0000;
text-align: center; font-size: 35px !important; font-weight : bold;
""")
text-align: center; font-size: 35px !important; font-weight : bold;""")
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
booleanParam(
name: 'JENKINS_DEBUG',
Expand Down Expand Up @@ -255,11 +241,10 @@ pipeline {
script {
echo "edit asdf tool version with version from jenkins param"

asdfTools.edit_version_in_file("$env.WORKSPACE/.tool-versions", 'java', params.JAVA_VERSION)
jenkinsJobTools.job_description_append("Use java version: $params.JAVA_VERSION ")
asdfTools.edit_version_in_file("$env.WORKSPACE/.tool-versions", 'maven', params.MAVEN_VERSION)
jenkinsJobTools.job_description_append("Use maven version: $params.MAVEN_VERSION ")

String javaVersion = asdfTools.setVersion("$env.WORKSPACE/.tool-versions", 'java', params.JAVA_VERSION)
String mavenVersion = asdfTools.setVersion("$env.WORKSPACE/.tool-versions", 'maven', params.MAVEN_VERSION)
jenkinsJobTools.job_description_append("Use java $javaVersion with maven $mavenVersion ")
}

///////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright (C) 2006-2025 Talend Inc. - www.talend.com
*
* Licensed 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.
*/
package org.talend.sdk.component.server.api;

import javax.ws.rs.GET;
import javax.ws.rs.Path;

import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import org.eclipse.microprofile.openapi.annotations.tags.Tag;

@Path("cache")
@Tag(name = "Cache", description = "Endpoints related to caches management.")
public interface CacheResource {

@GET
@Path("clear")
@Operation(operationId = "clearCaches", description = "Clear all caches.")
@APIResponse(responseCode = "204", description = "Clear all caches.")
void clearCaches();
}
1 change: 1 addition & 0 deletions component-server-parent/component-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@
<endpointClass>org.talend.sdk.component.server.front.ConfigurationTypeResourceImpl</endpointClass>
<endpointClass>org.talend.sdk.component.server.front.DocumentationResourceImpl</endpointClass>
<endpointClass>org.talend.sdk.component.server.front.EnvironmentResourceImpl</endpointClass>
<endpointClass>org.talend.sdk.component.server.service.jcache.FrontCacheResolver</endpointClass>
</endpointClasses>
<info>
<version>1</version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.geronimo.jcache.simple.cdi.CacheResolverImpl;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.talend.sdk.component.api.meta.Documentation;
import org.talend.sdk.component.server.api.CacheResource;
import org.talend.sdk.component.server.front.EnvironmentResourceImpl;
import org.talend.sdk.component.server.front.model.Environment;
import org.talend.sdk.components.vault.jcache.CacheConfigurationFactory;
Expand All @@ -45,7 +46,7 @@

@Slf4j
@ApplicationScoped
public class FrontCacheResolver implements CacheResolverFactory {
public class FrontCacheResolver implements CacheResolverFactory, CacheResource {

@Inject
private CacheManager cacheManager;
Expand Down Expand Up @@ -116,6 +117,7 @@ private void updateIfNeeded() {
}
}

@Override
public void clearCaches() {
StreamSupport
.stream(cacheManager.getCacheNames().spliterator(), false)
Expand All @@ -124,6 +126,19 @@ public void clearCaches() {
.forEach(r -> cacheManager.getCache(r).clear());
}

/**
* mainly used for testing purpose.
*
* @return active caches count
*/
public long countActiveCaches() {
return StreamSupport
.stream(cacheManager.getCacheNames().spliterator(), false)
.filter(name -> name.startsWith("org.talend.sdk.component.server.front."))
.filter(c -> cacheManager.getCache(c).iterator().hasNext())
.count();
}

@Override
public CacheResolver getCacheResolver(final CacheMethodDetails<? extends Annotation> cacheMethodDetails) {
return findCacheResolver(cacheMethodDetails.getCacheName());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Copyright (C) 2006-2025 Talend Inc. - www.talend.com
*
* Licensed 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.
*/
package org.talend.sdk.component.server.service.jcache;

import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;
import static org.junit.jupiter.api.Assertions.assertEquals;

import javax.inject.Inject;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;

import org.apache.meecrowave.junit5.MonoMeecrowaveConfig;
import org.junit.jupiter.api.Test;
import org.talend.sdk.component.server.test.ComponentClient;

@MonoMeecrowaveConfig
class FrontCacheResolverTest {

@Inject
private ComponentClient client;

@Inject
private WebTarget base;

@Inject
private FrontCacheResolver cacheResolver;

@Test
void clearCaches() {
cacheResolver.clearCaches();
assertEquals(0, cacheResolver.countActiveCaches());
client.fetchIndex();
assertEquals(1, cacheResolver.countActiveCaches());
client.fetchConfigTypeNodes();
assertEquals(2, cacheResolver.countActiveCaches());
final Response resp = base
.path("cache/clear")
.request(APPLICATION_JSON_TYPE)
.get();
assertEquals(204, resp.getStatus());
assertEquals(0, cacheResolver.countActiveCaches());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class ApiDemoEndpoints {

private static final String PATH_ENVIRONMENT = "/api/v1/environment";

private static final String PATH_CACHE_RESET = "/api/v1/cache/clear";

private static final String PATH_ACTION_INDEX = "/api/v1/action/index";

private static final String PATH_ACTION_EXECUTE = "/api/v1/action/execute";
Expand Down Expand Up @@ -166,6 +168,12 @@ public Response environment(@PathParam("version") final String version) {
.build();
}

@GET
@Path(RES_VERSION + PATH_CACHE_RESET)
public Response clearCaches() {
return Response.noContent().build();
}

@GET
@Path(RES_VERSION + PATH_ACTION_INDEX)
@Produces({ APPLICATION_JSON })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ public Collection<Route> collectResources() {
.add(route("component_server_environment", "/api/v1/environment", MapBuilder.map().done(),
emptyMap(), emptyMap(), jsonb.toJson(environment.get())));

routes.add(route("component_server_environment", "/api/v1/cache/clear", MapBuilder.map().done(),
emptyMap(), emptyMap(), null));

final ActionResource actions = container.select(ActionResource.class).get();
routes
.addAll(languages
Expand Down

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions talend-component-maven-plugin/src/it/web/test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<module>tck-action-validation-api-test</module>
<module>tck-action-healthcheck-api-test</module>
<module>tck-bulk-api-test</module>
<module>tck-cache-api-test</module>
<module>tck-component-icon-api-test</module>
<module>tck-component-dependencies-api-test</module>
<module>tck-component-dependency-api-test</module>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2006-2025 Talend Inc. - www.talend.com
Licensed 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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>tck-cache-api-test</artifactId>

<parent>
<groupId>org.talend.ci.api-tester</groupId>
<artifactId>tck-endpoints-api-test</artifactId>
<version>1.0.0</version>
</parent>

<build>
<plugins>
<plugin>
<groupId>org.talend.ci</groupId>
<artifactId>api-tester-maven-plugin</artifactId>
<version>${api-tester.version}</version>

<executions>
<execution>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<!-- START: Local configuration that applies only for this module -->
<file>${project.basedir}/tck_cache_api_test.json</file>
<!-- END: Local configuration that applies only for this module -->
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Loading