Skip to content

Commit 7c55dd6

Browse files
ARTEMIS-5862 CLI command to export broker properties
1 parent 510b19f commit 7c55dd6

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import org.apache.activemq.artemis.cli.commands.messages.perf.PerfGroup;
5454
import org.apache.activemq.artemis.cli.commands.queue.QueueGroup;
5555
import org.apache.activemq.artemis.cli.commands.tools.DataGroup;
56+
import org.apache.activemq.artemis.cli.commands.tools.config.ExportProperties;
5657
import org.apache.activemq.artemis.cli.commands.tools.journal.PerfJournal;
5758
import org.apache.activemq.artemis.cli.commands.user.UserGroup;
5859
import org.apache.activemq.artemis.dto.ManagementContextDTO;
@@ -281,6 +282,7 @@ public static CommandLine buildCommand(boolean includeInstanceCommands, boolean
281282
}
282283

283284
if (includeInstanceCommands) {
285+
commandLine.addSubcommand(new ExportProperties());
284286
commandLine.addSubcommand(new ActivationGroup(commandLine));
285287
commandLine.addSubcommand(new DataGroup(commandLine));
286288
commandLine.addSubcommand(new UserGroup(commandLine));
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.activemq.artemis.cli.commands.tools.config;
19+
20+
import java.io.BufferedOutputStream;
21+
import java.io.File;
22+
import java.io.FileOutputStream;
23+
import java.io.OutputStream;
24+
import java.io.PrintStream;
25+
26+
import org.apache.activemq.artemis.cli.commands.ActionContext;
27+
import org.apache.activemq.artemis.cli.commands.Configurable;
28+
import org.apache.activemq.artemis.core.config.impl.FileConfiguration;
29+
import picocli.CommandLine;
30+
31+
@CommandLine.Command(name = "properties", description = "Export the broker's configuration as a properties file to be used with broker properties.")
32+
public class ExportProperties extends Configurable {
33+
34+
@CommandLine.Option(names = "--output", description = "Output name for the file.", defaultValue = "broker.properties")
35+
private File output;
36+
37+
@Override
38+
public Object execute(ActionContext context) throws Exception {
39+
super.execute(context);
40+
41+
PrintStream out = context.out;
42+
OutputStream outputStream = null;
43+
44+
System.out.println("Exporting configuration as broker.properties");
45+
46+
if (output == null) {
47+
throw new RuntimeException("output is a required property");
48+
}
49+
50+
51+
if (output != null) {
52+
outputStream = new BufferedOutputStream(new FileOutputStream(output));
53+
PrintStream printStream = new PrintStream(outputStream);
54+
context.out = printStream;
55+
}
56+
57+
FileConfiguration configuration = readConfiguration();
58+
configuration.exportAsProperties(output);
59+
60+
return null;
61+
}
62+
63+
}

0 commit comments

Comments
 (0)