From 9b8e82601b23631040ccea128f856aaf7698a2df Mon Sep 17 00:00:00 2001 From: Clebert Suconic Date: Tue, 24 Aug 2021 22:57:43 -0400 Subject: [PATCH] ARTEMIS-3442 Configure journal retention through cli create --- .../activemq/artemis/cli/commands/Create.java | 27 +- .../artemis/cli/commands/InputAbstract.java | 23 +- .../artemis/cli/commands/etc/broker.xml | 2 + tests/smoke-tests/pom.xml | 6 + .../servers/replay/replay/broker.xml | 245 ------------------ 5 files changed, 56 insertions(+), 247 deletions(-) delete mode 100644 tests/smoke-tests/src/main/resources/servers/replay/replay/broker.xml diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java index 02073448fc..3121731e79 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java @@ -277,6 +277,12 @@ public class Create extends InputAbstract { @Option(name = "--journal-device-block-size", description = "The block size by the device, default at 4096.") private int journalDeviceBlockSize = 4096; + @Option(name = "--journal-retention-days", description = "If > 0, It will enable journal-retention-directory on the broker.xml allowing replay options. This option will configure retention in days.") + private int retentionDays; + + @Option(name = "--journal-retention-max-bytes", description = "It will be passed as storage-limit on the journal-retention-directory tag") + private String retentionMaxBytes; + @Option(name = "--global-max-size", description = "Maximum amount of memory which message data may consume (Default: Undefined, half of the system's memory)") private String globalMaxSize; @@ -762,9 +768,28 @@ public class Create extends InputAbstract { javaOptions = ""; } + boolean allowAnonymous = isAllowAnonymous(); + + + if (retentionDays == 0) { + retentionDays = inputInteger("--journal-retention-days", "How many days you would like to keep retained in the journal? Use 0 for no retention.", "0"); + } + + String retentionTag = ""; + if (retentionDays > 0) { + if (retentionMaxBytes != null) { + retentionTag = "" + data + "/retention"; + } else { + retentionTag = "" + data + "/retention"; + } + } + + filters.put("${journal-retention}", retentionTag); + + filters.put("${java-opts}", javaOptions); - if (isAllowAnonymous()) { + if (allowAnonymous) { write(ETC_LOGIN_CONFIG_WITH_GUEST, new File(etcFolder, ETC_LOGIN_CONFIG), filters, false); } else { write(ETC_LOGIN_CONFIG_WITHOUT_GUEST, new File(etcFolder, ETC_LOGIN_CONFIG), filters, false); diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/InputAbstract.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/InputAbstract.java index 05a6035464..80b5378084 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/InputAbstract.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/InputAbstract.java @@ -69,6 +69,27 @@ public class InputAbstract extends ActionAbstract { return booleanValue.booleanValue(); } + public int inputInteger(String propertyName, String prompt, String silentDefault) { + + Integer value = null; + do { + String input = input(propertyName, prompt, silentDefault); + if (input == null || input.trim().equals("")) { + input = "0"; + } + + try { + value = Integer.parseInt(input); + } catch (NumberFormatException e) { + e.printStackTrace(); + value = null; + } + } + while(value == null); + + return value.intValue(); + } + protected String input(String propertyName, String prompt, String silentDefault) { return input(propertyName, prompt, silentDefault, false); } @@ -82,7 +103,7 @@ public class InputAbstract extends ActionAbstract { boolean valid = false; System.out.println(); do { - context.out.println(propertyName + ": is a mandatory property!"); + context.out.println(propertyName + ":"); context.out.println(prompt); inputStr = scanner.nextLine(); if (!acceptNull && inputStr.trim().equals("")) { diff --git a/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/broker.xml b/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/broker.xml index 83468fcbf5..18429db277 100644 --- a/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/broker.xml +++ b/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/broker.xml @@ -56,6 +56,8 @@ ${jdbc} data/retention --> + ${journal-retention} + ${fsync} 2 diff --git a/tests/smoke-tests/pom.xml b/tests/smoke-tests/pom.xml index 790a4237fd..541aec0570 100644 --- a/tests/smoke-tests/pom.xml +++ b/tests/smoke-tests/pom.xml @@ -1178,6 +1178,12 @@ --java-options -Djava.rmi.server.hostname=localhost + --journal-retention-days + 1 + --queues + RetentionTest + --name + replay diff --git a/tests/smoke-tests/src/main/resources/servers/replay/replay/broker.xml b/tests/smoke-tests/src/main/resources/servers/replay/replay/broker.xml deleted file mode 100644 index 25601c67ce..0000000000 --- a/tests/smoke-tests/src/main/resources/servers/replay/replay/broker.xml +++ /dev/null @@ -1,245 +0,0 @@ - - - - - - - - replay - - - true - - - NIO - - ./data/paging - - ./data/bindings - - ./data/journal - - ./data/large-messages - - ./data/retention - - - - true - - 2 - - 10 - - 4096 - - 10M - - - - - - - - - - - - - - - - - - - - - 5000 - - - 90 - - - true - - 120000 - - 60000 - - HALT - - - - - - - - - - - - - - - - - - tcp://0.0.0.0:61616?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;amqpMinLargeMessageSize=102400;protocols=CORE,AMQP,STOMP,HORNETQ,MQTT,OPENWIRE;useEpoll=true;amqpCredits=1000;amqpLowCredits=300;amqpDuplicateDetection=true;supportAdvisory=false;suppressInternalManagementObjects=false - - - tcp://0.0.0.0:5672?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=AMQP;useEpoll=true;amqpCredits=1000;amqpLowCredits=300;amqpMinLargeMessageSize=102400;amqpDuplicateDetection=true - - - tcp://0.0.0.0:61613?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=STOMP;useEpoll=true - - - tcp://0.0.0.0:5445?anycastPrefix=jms.queue.;multicastPrefix=jms.topic.;protocols=HORNETQ,STOMP;useEpoll=true - - - tcp://0.0.0.0:1883?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=MQTT;useEpoll=true - - - - - - - - - - - - - - - - - - - - - - - - DLQ - ExpiryQueue - 0 - - -1 - 10 - PAGE - true - true - true - true - - - - DLQ - ExpiryQueue - 0 - - -1 - 10 - PAGE - true - true - true - true - false - false - - - - -
- - - -
-
- - - -
- -
- - - -
- -
- - - - -
-