Skip to content

Commit 64f5cde

Browse files
jbertramtabish121
authored andcommitted
ARTEMIS-5786 determine if address is blocked via mngmnt API
1 parent ccc4c00 commit 64f5cde

8 files changed

Lines changed: 76 additions & 8 deletions

File tree

artemis-commons/src/main/java/org/apache/activemq/artemis/logs/AuditLogger.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2896,4 +2896,11 @@ static void retryMessages(Object source, Object... args) {
28962896
@LogMessage(id = 601802, value = "User {} is retry sending messages on target resource: {} {}", level = LogMessage.Level.INFO)
28972897
void retryMessages(String user, Object source, String args);
28982898

2899+
static void isBlockedViaManagement(Object source) {
2900+
BASE_LOGGER.isBlockedViaManagement(getCaller(), source);
2901+
}
2902+
2903+
@LogMessage(id = 601803, value = "User {} is getting BlockedViaManagement on target resource: {}", level = LogMessage.Level.INFO)
2904+
void isBlockedViaManagement(String user, Object source);
2905+
28992906
}

artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/AddressControl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ public interface AddressControl {
155155
@Operation(desc = "Resumes message production to this address, if previously blocked.", impact = MBeanOperationInfo.ACTION)
156156
void unblock() throws Exception;
157157

158+
/**
159+
* {@return whether message production to this address is blocked via management (via the {@code block} operation)}
160+
*/
161+
@Attribute(desc = "whether message production to this address is blocked via management (via the block operation)")
162+
boolean isBlockedViaManagement() throws Exception;
163+
158164
/**
159165
* {@return the number of bytes used by each page for this address}
160166
*/

artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,26 @@ public void unblock() {
481481
}
482482
}
483483

484+
@Override
485+
public boolean isBlockedViaManagement() throws Exception {
486+
if (AuditLogger.isBaseLoggingEnabled()) {
487+
AuditLogger.isBlockedViaManagement(this.addressInfo);
488+
}
489+
clearIO();
490+
try {
491+
final PagingStore pagingStore = getPagingStore();
492+
if (pagingStore != null) {
493+
return pagingStore.isBlockedViaManagement();
494+
} else {
495+
return false;
496+
}
497+
} catch (Exception e) {
498+
return false;
499+
} finally {
500+
blockOnIO();
501+
}
502+
}
503+
484504
@Override
485505
public long getNumberOfPages() {
486506
if (AuditLogger.isBaseLoggingEnabled()) {

artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/PagingStore.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ default void addSize(int size) {
284284

285285
void unblock();
286286

287+
boolean isBlockedViaManagement();
288+
287289
default boolean hasPendingIO() {
288290
return false;
289291
}

artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PagingStoreImpl.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public class PagingStoreImpl implements PagingStore {
170170

171171
private volatile boolean blocking = false;
172172

173-
private volatile boolean blockedViaAddressControl = false;
173+
private volatile boolean blockedViaManagement = false;
174174

175175
private long rejectThreshold;
176176

@@ -1290,7 +1290,7 @@ private void addToBlockList(AtomicRunnable atomicRunnable, Consumer<AtomicRunnab
12901290
public boolean checkMemory(boolean runOnFailure, Runnable runWhenAvailableParameter, Runnable runWhenBlocking, Consumer<AtomicRunnable> blockedCallback) {
12911291
AtomicRunnable runWhenAvailable = AtomicRunnable.checkAtomic(runWhenAvailableParameter);
12921292

1293-
if (blockedViaAddressControl) {
1293+
if (blockedViaManagement) {
12941294
if (runWhenAvailable != null) {
12951295
addToBlockList(runWhenAvailable, blockedCallback);
12961296
}
@@ -1404,7 +1404,7 @@ public void addSize(final int size, boolean sizeOnly, boolean affectGlobal) {
14041404

14051405
@Override
14061406
public boolean checkReleasedMemory() {
1407-
if (!blockedViaAddressControl && !pagingManager.isGlobalFull() && !full) {
1407+
if (!blockedViaManagement && !pagingManager.isGlobalFull() && !full) {
14081408
executor.execute(this::memoryReleased);
14091409
if (blocking) {
14101410
ActiveMQServerLogger.LOGGER.unblockingMessageProduction(address, getPageInfo());
@@ -1876,21 +1876,26 @@ public int getAddressLimitPercent() {
18761876

18771877
@Override
18781878
public void block() {
1879-
if (!blockedViaAddressControl) {
1879+
if (!blockedViaManagement) {
18801880
ActiveMQServerLogger.LOGGER.blockingViaControl(address);
18811881
}
1882-
blockedViaAddressControl = true;
1882+
blockedViaManagement = true;
18831883
}
18841884

18851885
@Override
18861886
public void unblock() {
1887-
if (blockedViaAddressControl) {
1887+
if (blockedViaManagement) {
18881888
ActiveMQServerLogger.LOGGER.unblockingViaControl(address);
18891889
}
1890-
blockedViaAddressControl = false;
1890+
blockedViaManagement = false;
18911891
checkReleasedMemory();
18921892
}
18931893

1894+
@Override
1895+
public boolean isBlockedViaManagement() {
1896+
return blockedViaManagement;
1897+
}
1898+
18941899
@Override
18951900
public boolean isRejectingMessages() {
18961901
if (addressFullMessagePolicy != AddressFullMessagePolicy.BLOCK) {

tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,24 @@ public void testAddressSizeAfterRestartWithPaging() throws Exception {
880880
assertEquals(exactPercentBeforeRestart, addressControl.getAddressLimitPercent());
881881
}
882882

883+
@Test
884+
public void testIsBlockedViaManagement() throws Exception {
885+
SimpleString address = RandomUtil.randomUUIDSimpleString();
886+
SimpleString queue = RandomUtil.randomUUIDSimpleString();
887+
888+
session.createQueue(QueueConfiguration.of(queue).setAddress(address).setDurable(false));
889+
890+
AddressControl addressControl = createManagementControl(address);
891+
892+
assertFalse(addressControl.isBlockedViaManagement());
893+
addressControl.block();
894+
assertTrue(addressControl.isBlockedViaManagement());
895+
addressControl.unblock();
896+
assertFalse(addressControl.isBlockedViaManagement());
897+
898+
session.deleteQueue(queue);
899+
}
900+
883901

884902
@Override
885903
@BeforeEach

tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlUsingCoreTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,12 @@ public boolean block() throws Exception {
128128

129129
@Override
130130
public void unblock() throws Exception {
131-
proxy.invokeOperation("unBlock");
131+
proxy.invokeOperation("unblock");
132+
}
133+
134+
@Override
135+
public boolean isBlockedViaManagement() throws Exception {
136+
return (boolean) proxy.retrieveAttributeValue("blockedViaManagement");
132137
}
133138

134139
@Override

tests/performance-tests/src/test/java/org/apache/activemq/artemis/tests/performance/storage/PersistMultiThreadTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,5 +614,10 @@ public void block() {
614614
@Override
615615
public void unblock() {
616616
}
617+
618+
@Override
619+
public boolean isBlockedViaManagement() {
620+
return false;
621+
}
617622
}
618623
}

0 commit comments

Comments
 (0)