diff --git a/extensions/cache/deployment/src/main/java/io/quarkus/cache/deployment/devconsole/CacheDevConsoleProcessor.java b/extensions/cache/deployment/src/main/java/io/quarkus/cache/deployment/devconsole/CacheDevConsoleProcessor.java deleted file mode 100644 index e32c6ede7fd53..0000000000000 --- a/extensions/cache/deployment/src/main/java/io/quarkus/cache/deployment/devconsole/CacheDevConsoleProcessor.java +++ /dev/null @@ -1,27 +0,0 @@ -package io.quarkus.cache.deployment.devconsole; - -import static io.quarkus.deployment.annotations.ExecutionTime.STATIC_INIT; - -import io.quarkus.cache.runtime.CaffeineCacheSupplier; -import io.quarkus.cache.runtime.devconsole.CacheDevConsoleRecorder; -import io.quarkus.deployment.IsDevelopment; -import io.quarkus.deployment.annotations.BuildStep; -import io.quarkus.deployment.annotations.Record; -import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem; -import io.quarkus.devconsole.spi.DevConsoleRouteBuildItem; -import io.quarkus.devconsole.spi.DevConsoleRuntimeTemplateInfoBuildItem; - -public class CacheDevConsoleProcessor { - - @BuildStep(onlyIf = IsDevelopment.class) - public DevConsoleRuntimeTemplateInfoBuildItem collectBeanInfo(CurateOutcomeBuildItem curateOutcomeBuildItem) { - return new DevConsoleRuntimeTemplateInfoBuildItem("cacheInfos", new CaffeineCacheSupplier(), this.getClass(), - curateOutcomeBuildItem); - } - - @BuildStep - @Record(value = STATIC_INIT, optional = true) - DevConsoleRouteBuildItem invokeEndpoint(CacheDevConsoleRecorder recorder) { - return new DevConsoleRouteBuildItem("caches", "POST", recorder.clearCacheHandler()); - } -} diff --git a/extensions/cache/deployment/src/main/java/io/quarkus/cache/deployment/devui/CacheDevUiProcessor.java b/extensions/cache/deployment/src/main/java/io/quarkus/cache/deployment/devui/CacheDevUiProcessor.java index fc7a59b21e8b2..b2311ba7db4b5 100644 --- a/extensions/cache/deployment/src/main/java/io/quarkus/cache/deployment/devui/CacheDevUiProcessor.java +++ b/extensions/cache/deployment/src/main/java/io/quarkus/cache/deployment/devui/CacheDevUiProcessor.java @@ -1,6 +1,6 @@ package io.quarkus.cache.deployment.devui; -import io.quarkus.cache.runtime.devconsole.CacheJsonRPCService; +import io.quarkus.cache.runtime.devui.CacheJsonRPCService; import io.quarkus.deployment.IsDevelopment; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem; diff --git a/extensions/cache/deployment/src/main/resources/dev-templates/caches.html b/extensions/cache/deployment/src/main/resources/dev-templates/caches.html deleted file mode 100644 index 2336f7685a186..0000000000000 --- a/extensions/cache/deployment/src/main/resources/dev-templates/caches.html +++ /dev/null @@ -1,86 +0,0 @@ -{#include main} -{#style} -.clearCacheIcon:hover { - color: #3366ac !important; - cursor: pointer; -} -.refreshCacheIcon:hover { - color: #3366ac !important; - cursor: pointer; -} -{/style} - -{#script} - -function refreshCache(cacheName){ - $.post("", - { - name: cacheName, - action: "refresh" - }, - function(data, status){ - if(status === "success"){ - updateSize(data,cacheName); - } - }); -} - -function clearCache(cacheName){ - $.post("", - { - name: cacheName, - action: "clearCache" - }, - function(data, status){ - if(status === "success"){ - updateSize(data,cacheName); - changeBackgroundColor("#76be6b", cacheName); - }else{ - changeBackgroundColor("#ff6366", cacheName); - } - }); -} - -function updateSize(data, cacheName){ - var r = JSON.parse(data); - var spanId = 'size-' + cacheName; - $('#' + spanId).html(r.size); -} - -function changeBackgroundColor(color, cacheName){ - var className = 'tr-' + cacheName; - var element = $('#' + className); - - var x = 3000; - var originalColor = element.css("background-color"); - - element.css("background", color); - setTimeout(function(){ - element.css("background", originalColor); - }, x); -} -{/script} -{#title}Caches{/title} -{#body} - - - - - - - - - {#for cacheInfo in info:cacheInfos} - - - - {/for} - -
NameSize
- {cacheInfo.name} - - {cacheInfo.size} - -
-{/body} -{/include} diff --git a/extensions/cache/deployment/src/main/resources/dev-templates/embedded.html b/extensions/cache/deployment/src/main/resources/dev-templates/embedded.html deleted file mode 100644 index ea948f9198934..0000000000000 --- a/extensions/cache/deployment/src/main/resources/dev-templates/embedded.html +++ /dev/null @@ -1,3 +0,0 @@ - - - Caches {info:cacheInfos.size()} diff --git a/extensions/cache/runtime/src/main/java/io/quarkus/cache/runtime/CaffeineCacheSupplier.java b/extensions/cache/runtime/src/main/java/io/quarkus/cache/runtime/CaffeineCacheSupplier.java deleted file mode 100644 index 4474772f66692..0000000000000 --- a/extensions/cache/runtime/src/main/java/io/quarkus/cache/runtime/CaffeineCacheSupplier.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.quarkus.cache.runtime; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Comparator; -import java.util.List; -import java.util.Optional; -import java.util.function.Supplier; - -import io.quarkus.arc.Arc; -import io.quarkus.cache.Cache; -import io.quarkus.cache.CacheManager; -import io.quarkus.cache.CaffeineCache; - -public class CaffeineCacheSupplier implements Supplier> { - - @Override - public List get() { - CacheManager cacheManager = cacheManager(); - Collection names = cacheManager.getCacheNames(); - List allCaches = new ArrayList<>(names.size()); - for (String name : names) { - Optional cache = cacheManager.getCache(name); - if (cache.isPresent() && cache.get() instanceof CaffeineCache) { - allCaches.add((CaffeineCache) cache.get()); - } - } - allCaches.sort(Comparator.comparing(CaffeineCache::getName)); - return allCaches; - } - - public static CacheManager cacheManager() { - return Arc.container().instance(CacheManager.class).get(); - } -} diff --git a/extensions/cache/runtime/src/main/java/io/quarkus/cache/runtime/devconsole/CacheDevConsoleRecorder.java b/extensions/cache/runtime/src/main/java/io/quarkus/cache/runtime/devconsole/CacheDevConsoleRecorder.java deleted file mode 100644 index 5488c24adf240..0000000000000 --- a/extensions/cache/runtime/src/main/java/io/quarkus/cache/runtime/devconsole/CacheDevConsoleRecorder.java +++ /dev/null @@ -1,74 +0,0 @@ -package io.quarkus.cache.runtime.devconsole; - -import static io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR; -import static io.netty.handler.codec.http.HttpResponseStatus.NOT_FOUND; -import static io.netty.handler.codec.http.HttpResponseStatus.OK; - -import java.util.Optional; - -import io.netty.handler.codec.http.HttpResponseStatus; -import io.quarkus.cache.Cache; -import io.quarkus.cache.CaffeineCache; -import io.quarkus.cache.runtime.CaffeineCacheSupplier; -import io.quarkus.cache.runtime.caffeine.CaffeineCacheImpl; -import io.quarkus.devconsole.runtime.spi.DevConsolePostHandler; -import io.quarkus.runtime.annotations.Recorder; -import io.quarkus.vertx.http.runtime.devmode.Json; -import io.vertx.core.Handler; -import io.vertx.core.MultiMap; -import io.vertx.ext.web.RoutingContext; - -@Recorder -public class CacheDevConsoleRecorder { - public Handler clearCacheHandler() { - return new DevConsolePostHandler() { - - @Override - protected void handlePost(RoutingContext event, MultiMap form) { - String cacheName = form.get("name"); - Optional cache = CaffeineCacheSupplier.cacheManager().getCache(cacheName); - if (cache.isPresent() && cache.get() instanceof CaffeineCache) { - CaffeineCacheImpl caffeineCache = (CaffeineCacheImpl) cache.get(); - - String action = form.get("action"); - if (action.equalsIgnoreCase("clearCache")) { - caffeineCache.invalidateAll().subscribe().with(ignored -> { - endResponse(event, OK, createResponseMessage(caffeineCache)); - }); - } else if (action.equalsIgnoreCase("refresh")) { - endResponse(event, OK, createResponseMessage(caffeineCache)); - } else { - String errorMessage = "Invalid action: " + action; - endResponse(event, INTERNAL_SERVER_ERROR, createResponseError(cacheName, errorMessage)); - } - } else { - String errorMessage = "Cache for " + cacheName + " not found"; - endResponse(event, NOT_FOUND, createResponseError(cacheName, errorMessage)); - } - } - - private void endResponse(RoutingContext event, HttpResponseStatus status, String message) { - event.response().setStatusCode(status.code()); - event.response().end(message); - } - - @Override - protected void actionSuccess(RoutingContext event) { - } - - private String createResponseMessage(CaffeineCacheImpl cache) { - Json.JsonObjectBuilder object = Json.object(); - object.put("name", cache.getName()); - object.put("size", cache.getSize()); - return object.build(); - } - - private String createResponseError(String name, String error) { - Json.JsonObjectBuilder object = Json.object(); - object.put("name", name); - object.put("error", error); - return object.build(); - } - }; - } -} diff --git a/extensions/cache/runtime/src/main/java/io/quarkus/cache/runtime/devconsole/CacheJsonRPCService.java b/extensions/cache/runtime/src/main/java/io/quarkus/cache/runtime/devui/CacheJsonRPCService.java similarity index 98% rename from extensions/cache/runtime/src/main/java/io/quarkus/cache/runtime/devconsole/CacheJsonRPCService.java rename to extensions/cache/runtime/src/main/java/io/quarkus/cache/runtime/devui/CacheJsonRPCService.java index 898341226909d..59293a3f5e322 100644 --- a/extensions/cache/runtime/src/main/java/io/quarkus/cache/runtime/devconsole/CacheJsonRPCService.java +++ b/extensions/cache/runtime/src/main/java/io/quarkus/cache/runtime/devui/CacheJsonRPCService.java @@ -1,4 +1,4 @@ -package io.quarkus.cache.runtime.devconsole; +package io.quarkus.cache.runtime.devui; import java.util.ArrayList; import java.util.Collection; diff --git a/integration-tests/devmode/src/test/java/io/quarkus/test/devconsole/DevConsoleCacheSmokeTest.java b/integration-tests/devmode/src/test/java/io/quarkus/test/devconsole/DevConsoleCacheSmokeTest.java deleted file mode 100644 index d14a8c135f98f..0000000000000 --- a/integration-tests/devmode/src/test/java/io/quarkus/test/devconsole/DevConsoleCacheSmokeTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package io.quarkus.test.devconsole; - -import jakarta.inject.Singleton; - -import org.hamcrest.Matchers; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -import io.quarkus.cache.CacheResult; -import io.quarkus.test.QuarkusDevModeTest; -import io.restassured.RestAssured; - -/** - * Note that this test cannot be placed under the relevant {@code -deployment} module because then the DEV UI processor would - * not be able to locate the template resources correctly. - */ -public class DevConsoleCacheSmokeTest { - - @RegisterExtension - static final QuarkusDevModeTest config = new QuarkusDevModeTest() - .withApplicationRoot((jar) -> jar.addClass(MyBean.class)); - - @Test - public void testCaches() { - RestAssured.get("q/dev-v1/io.quarkus.quarkus-cache/caches") - .then() - .statusCode(200).body(Matchers.containsString("myCache")); - } - - @Singleton - public static class MyBean { - - @CacheResult(cacheName = "myCache") - String ping() { - return "foo"; - } - - } - -}