Skip to content

Commit 13eaad6

Browse files
committed
Enhancement Request 38279477 - [37591427->25.09] Add cache destroy to the management API (merge main -> ce/25.09 @ 117883)
[git-p4: depot-paths = "//dev/coherence-ce/main/": change = 118176]
1 parent acb1971 commit 13eaad6

File tree

6 files changed

+178
-4
lines changed

6 files changed

+178
-4
lines changed

prj/coherence-core-components/src/main/java/com/tangosol/coherence/component/manageable/modelAdapter/StorageManagerMBean.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
/*
3-
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
3+
* Copyright (c) 2000, 2025, Oracle and/or its affiliates.
44
*
55
* Licensed under the Universal Permissive License v 1.0 as shown at
66
* https://oss.oracle.com/licenses/upl.
@@ -483,6 +483,18 @@ protected java.util.Map get_MethodInfo()
483483
null,
484484
});
485485
}
486+
// behavior destroyCache()
487+
{
488+
mapInfo.put("destroyCache()", new Object[]
489+
{
490+
"Completely destroys the specified collection across the cluster. All references in the entire cluster to this collection will be invalidated, the collection data will be cleared, and all internal resources will be released.",
491+
"destroyCache",
492+
"V",
493+
new String[] {},
494+
new String[] {},
495+
null,
496+
});
497+
}
486498
// behavior size()
487499
{
488500
mapInfo.put("size()", new Object[]
@@ -876,6 +888,18 @@ public void truncateCache()
876888
{
877889
}
878890

891+
/**
892+
* Destroys cache.<p>
893+
* Release and destroy this instance of NamedCollection. <p>
894+
* <b>Warning:</b> This method is used to completely destroy the specified
895+
* collection across the cluster. All references in the entire cluster to this
896+
* collection will be invalidated, the collection data will be cleared, and all
897+
* internal resources will be released.
898+
*/
899+
public void destroyCache()
900+
{
901+
}
902+
879903
/**
880904
* Returns the total size of the cache.
881905
*/

prj/coherence-core-components/src/main/java/com/tangosol/coherence/component/net/management/model/localModel/StorageManagerModel.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
/*
3-
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
3+
* Copyright (c) 2000, 2025, Oracle and/or its affiliates.
44
*
55
* Licensed under the Universal Permissive License v 1.0 as shown at
66
* https://oss.oracle.com/licenses/upl.
@@ -759,6 +759,7 @@ public void clearCache()
759759
{
760760
checkReadOnly("clearCache");
761761
Storage storage = get_Storage();
762+
if (storage != null)
762763
{
763764
PartitionedCache service = storage.getService();
764765
if (service != null)
@@ -784,6 +785,21 @@ public void truncateCache()
784785
}
785786
}
786787

788+
public void destroyCache()
789+
{
790+
checkReadOnly("destroyCache");
791+
Storage storage = get_Storage();
792+
if (storage != null)
793+
{
794+
PartitionedCache service = storage.getService();
795+
if (service != null)
796+
{
797+
NamedCache cache = service.ensureCache(storage.getCacheName(), null);
798+
cache.destroy();
799+
}
800+
}
801+
}
802+
787803
public int size()
788804
{
789805
Storage storage = get_Storage();

prj/coherence-core/src/main/java/com/tangosol/internal/management/resources/AbstractManagementResource.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
2+
* Copyright (c) 2000, 2025, Oracle and/or its affiliates.
33
*
44
* Licensed under the Universal Permissive License v 1.0 as shown at
55
* https://oss.oracle.com/licenses/upl.
@@ -2326,6 +2326,7 @@ protected boolean isFederatedServiceMemberValid(HttpRequest request)
23262326
public static final String OPTIONS = "options";
23272327
public static final String CACHE = "cache";
23282328
public static final String TRUNCATE = "truncate";
2329+
public static final String DESTROY = "destroy";
23292330
public static final String CLEAR = "clear";
23302331
public static final String DESCRIPTION = "description";
23312332

prj/coherence-core/src/main/java/com/tangosol/internal/management/resources/StorageManagerResource.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, 2024 Oracle and/or its affiliates.
2+
* Copyright (c) 2023, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Universal Permissive License v 1.0 as shown at
55
* https://oss.oracle.com/licenses/upl.
@@ -45,6 +45,7 @@ public void addRoutes(RequestRouter router, String sPathRoot)
4545

4646
router.addPost(sPathRoot + "/" + CLEAR, this::clearCache);
4747
router.addPost(sPathRoot + "/" + TRUNCATE, this::truncateCache);
48+
router.addPost(sPathRoot + "/" + DESTROY, this::destroyCache);
4849
router.addPost(sPathRoot + "/" + RESET_STATS, this::resetStatistics);
4950
router.addGet(sPathRoot + "/" + PARTITION_STATS, this::reportPartitionStats);
5051
}
@@ -156,6 +157,21 @@ public Response truncateCache(HttpRequest request)
156157
return executeMBeanOperation(request, queryBuilder, "truncateCache", null, null);
157158
}
158159

160+
/**
161+
* Call "destroyCache" operation on StorageManagerMBean for all members.
162+
*
163+
* @param request the {@link HttpRequest}
164+
*
165+
* @return the response object
166+
*/
167+
public Response destroyCache(HttpRequest request)
168+
{
169+
String sCacheName = request.getFirstPathParameter(CACHE_NAME);
170+
String sServiceName = request.getPathParameters().getFirst(SERVICE_NAME);
171+
QueryBuilder queryBuilder = getQuery(request, sCacheName, sServiceName);
172+
return executeMBeanOperation(request, queryBuilder, "destroyCache", null, null);
173+
}
174+
159175
// ----- AbstractManagementResource methods ------------------------------
160176

161177
@SuppressWarnings({"rawtypes", "unchecked"})

prj/coherence-core/src/main/resources/management-swagger.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5118,6 +5118,32 @@
51185118
}
51195119
}
51205120
},
5121+
"/management/coherence/cluster/services/{serviceName}/storage/{cacheName}/destroy": {
5122+
"post": {
5123+
"tags": [
5124+
"Storage Managers"
5125+
],
5126+
"summary": "Destroy Cache",
5127+
"description": "Use this endpoint to destroy a specific cache.",
5128+
"operationId": "/management/coherence/cluster/services/{serviceName}/storage/{cacheName}/destroy POST",
5129+
"produces": [
5130+
"application/json"
5131+
],
5132+
"parameters": [
5133+
{
5134+
"$ref": "#/parameters/serviceName"
5135+
},
5136+
{
5137+
"$ref": "#/parameters/cacheName"
5138+
}
5139+
],
5140+
"responses": {
5141+
"200": {
5142+
"description": "Command invocation is successful"
5143+
}
5144+
}
5145+
}
5146+
},
51215147
"/management/coherence/cluster/services/{serviceName}/storage/{cacheName}/clear": {
51225148
"post": {
51235149
"tags": [
@@ -6157,6 +6183,29 @@
61576183
}
61586184
}
61596185
},
6186+
"/management/coherence/cluster/storage/{cacheName}/destroy": {
6187+
"post": {
6188+
"tags": [
6189+
"Storage Managers"
6190+
],
6191+
"summary": "Destroy Cache",
6192+
"description": "Use this endpoint to destroy a specific cache.",
6193+
"operationId": "/management/coherence/cluster/storage/{cacheName}/destroy POST",
6194+
"produces": [
6195+
"application/json"
6196+
],
6197+
"parameters": [
6198+
{
6199+
"$ref": "#/parameters/cacheName"
6200+
}
6201+
],
6202+
"responses": {
6203+
"200": {
6204+
"description": "Command invocation is successful"
6205+
}
6206+
}
6207+
}
6208+
},
61606209
"/management/coherence/cluster/storage/{cacheName}/clear": {
61616210
"post": {
61626211
"tags": [

prj/test/functional/management/src/main/java/management/BaseManagementInfoResourceTests.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
import com.oracle.bedrock.testsupport.MavenProjectFileUtils;
3737

38+
import com.oracle.bedrock.testsupport.deferred.Concurrently;
3839
import com.oracle.bedrock.testsupport.deferred.Eventually;
3940

4041
import com.oracle.bedrock.testsupport.junit.TestLogs;
@@ -154,6 +155,7 @@
154155
import static com.tangosol.internal.management.resources.AbstractManagementResource.CACHES;
155156
import static com.tangosol.internal.management.resources.AbstractManagementResource.CLEAR;
156157
import static com.tangosol.internal.management.resources.AbstractManagementResource.DESCRIPTION;
158+
import static com.tangosol.internal.management.resources.AbstractManagementResource.DESTROY;
157159
import static com.tangosol.internal.management.resources.AbstractManagementResource.MANAGEMENT;
158160
import static com.tangosol.internal.management.resources.AbstractManagementResource.MEMBER;
159161
import static com.tangosol.internal.management.resources.AbstractManagementResource.MEMBERS;
@@ -3898,6 +3900,72 @@ public void testReadOnlyTruncateCache()
38983900
});
38993901
}
39003902

3903+
@Test
3904+
public void testDestroyCache()
3905+
{
3906+
Assume.assumeFalse("Skipping as management is read-only", isReadOnly());
3907+
final String CACHE_NAME = CLEAR_CACHE_NAME;
3908+
3909+
f_inClusterInvoker.accept(f_sClusterName, null, () ->
3910+
{
3911+
// fill a cache
3912+
NamedCache cache = CacheFactory.getCache(CACHE_NAME);
3913+
Binary binValue = Randoms.getRandomBinary(1024, 1024);
3914+
cache.clear();
3915+
for (int i = 0; i < 10; ++i)
3916+
{
3917+
cache.put(i, binValue);
3918+
}
3919+
return null;
3920+
});
3921+
Base.sleep(REMOTE_MODEL_PAUSE_DURATION);
3922+
3923+
Concurrently.assertThat(0,
3924+
(Function<Object, Integer>) o ->
3925+
{
3926+
Base.sleep(3000);
3927+
return getBaseTarget().path(STORAGE).path(CACHE_NAME).path(DESTROY).request().post(null).getStatus();
3928+
},
3929+
is(Response.Status.OK.getStatusCode()));
3930+
3931+
f_inClusterInvoker.accept(f_sClusterName, null, () ->
3932+
{
3933+
NamedCache cache = CacheFactory.getCache(CACHE_NAME);
3934+
Assert.assertEquals(10, cache.size());
3935+
Eventually.assertDeferred(cache::isDestroyed, is(true));
3936+
return null;
3937+
});
3938+
}
3939+
3940+
@Test
3941+
public void testReadOnlyDestroyCache()
3942+
{
3943+
// only run when read-only management is enabled
3944+
Assume.assumeTrue(isReadOnly());
3945+
final String CACHE_NAME = CLEAR_CACHE_NAME;
3946+
f_inClusterInvoker.accept(f_sClusterName, null, () ->
3947+
{
3948+
NamedCache cache = CacheFactory.getCache(CACHE_NAME);
3949+
cache.clear();
3950+
cache.put("key", "value");
3951+
return null;
3952+
});
3953+
Base.sleep(REMOTE_MODEL_PAUSE_DURATION);
3954+
3955+
Eventually.assertDeferred(
3956+
() -> getBaseTarget().path(STORAGE).path(CACHE_NAME).path(DESTROY).request().post(null).getStatus(),
3957+
is(Response.Status.UNAUTHORIZED.getStatusCode()));
3958+
Base.sleep(REMOTE_MODEL_PAUSE_DURATION);
3959+
3960+
f_inClusterInvoker.accept(f_sClusterName, null, () ->
3961+
{
3962+
NamedCache cache = CacheFactory.getCache(CACHE_NAME);
3963+
Assert.assertEquals(1, cache.size());
3964+
Assert.assertFalse(cache.isDestroyed());
3965+
return null;
3966+
});
3967+
}
3968+
39013969
@Test
39023970
public void testGetClusterConfig()
39033971
throws Exception

0 commit comments

Comments
 (0)