use of org.apache.pulsar.common.util.CmdGenerateDocs in project pulsar by apache.
the class PulsarInitialNamespaceSetup method doMain.
public static int doMain(String[] args) throws Exception {
Arguments arguments = new Arguments();
JCommander jcommander = new JCommander();
try {
jcommander.addObject(arguments);
jcommander.parse(args);
if (arguments.help) {
jcommander.usage();
return 0;
}
if (arguments.generateDocs) {
CmdGenerateDocs cmd = new CmdGenerateDocs("pulsar");
cmd.addCommand("initialize-namespace", arguments);
cmd.run(null);
return 0;
}
} catch (Exception e) {
jcommander.usage();
return 1;
}
if (arguments.configurationStore == null) {
System.err.println("Configuration store address argument is required (--configuration-store)");
jcommander.usage();
return 1;
}
try (MetadataStore configStore = PulsarClusterMetadataSetup.initMetadataStore(arguments.configurationStore, arguments.zkSessionTimeoutMillis)) {
PulsarResources pulsarResources = new PulsarResources(null, configStore);
for (String namespace : arguments.namespaces) {
NamespaceName namespaceName = null;
try {
namespaceName = NamespaceName.get(namespace);
} catch (Exception e) {
System.out.println("Invalid namespace name.");
return 1;
}
// Create specified tenant
PulsarClusterMetadataSetup.createTenantIfAbsent(pulsarResources, namespaceName.getTenant(), arguments.cluster);
// Create specified namespace
PulsarClusterMetadataSetup.createNamespaceIfAbsent(pulsarResources, namespaceName, arguments.cluster);
}
}
System.out.println("Initial namespace setup success");
return 0;
}
use of org.apache.pulsar.common.util.CmdGenerateDocs in project pulsar by apache.
the class PulsarTransactionCoordinatorMetadataSetup method main.
public static void main(String[] args) throws Exception {
Arguments arguments = new Arguments();
JCommander jcommander = new JCommander();
try {
jcommander.addObject(arguments);
jcommander.parse(args);
if (arguments.help) {
jcommander.usage();
return;
}
if (arguments.generateDocs) {
CmdGenerateDocs cmd = new CmdGenerateDocs("pulsar");
cmd.addCommand("initialize-transaction-coordinator-metadata", arguments);
cmd.run(null);
return;
}
} catch (Exception e) {
jcommander.usage();
throw e;
}
if (arguments.configurationStore == null) {
System.err.println("Configuration store address argument is required (--configuration-store)");
jcommander.usage();
System.exit(1);
}
if (arguments.numTransactionCoordinators <= 0) {
System.err.println("Number of transaction coordinators must greater than 0");
System.exit(1);
}
try (MetadataStoreExtended configStore = PulsarClusterMetadataSetup.initMetadataStore(arguments.configurationStore, arguments.zkSessionTimeoutMillis)) {
PulsarResources pulsarResources = new PulsarResources(null, configStore);
// Create system tenant
PulsarClusterMetadataSetup.createTenantIfAbsent(pulsarResources, NamespaceName.SYSTEM_NAMESPACE.getTenant(), arguments.cluster);
// Create system namespace
PulsarClusterMetadataSetup.createNamespaceIfAbsent(pulsarResources, NamespaceName.SYSTEM_NAMESPACE, arguments.cluster);
// Create transaction coordinator assign partitioned topic
PulsarClusterMetadataSetup.createPartitionedTopic(configStore, TopicName.TRANSACTION_COORDINATOR_ASSIGN, arguments.numTransactionCoordinators);
}
System.out.println("Transaction coordinator metadata setup success");
}
use of org.apache.pulsar.common.util.CmdGenerateDocs in project pulsar by apache.
the class PulsarVersionStarter method main.
public static void main(String[] args) {
Arguments arguments = new Arguments();
JCommander jcommander = new JCommander();
try {
jcommander.addObject(arguments);
jcommander.parse(args);
if (arguments.help) {
jcommander.usage();
return;
}
if (arguments.generateDocs) {
CmdGenerateDocs cmd = new CmdGenerateDocs("pulsar");
cmd.addCommand("version", arguments);
cmd.run(null);
return;
}
} catch (Exception e) {
jcommander.usage();
return;
}
System.out.println("Current version of pulsar is: " + PulsarVersion.getVersion());
}
use of org.apache.pulsar.common.util.CmdGenerateDocs in project pulsar by apache.
the class GenerateDocsCommand method apply.
private boolean apply(GenerateDocsCommand.GenDocFlags flags) {
CmdGenerateDocs cmd = new CmdGenerateDocs("pulsar");
JCommander commander = new JCommander();
commander.addCommand("load-report", new LoadReportCommand.Flags());
cmd.addCommand("broker-tool", commander);
if (flags.commandNames.isEmpty()) {
cmd.run(null);
} else {
ArrayList<String> args = new ArrayList(flags.commandNames);
args.add(0, "-n");
cmd.run(args.toArray(new String[0]));
}
return true;
}
use of org.apache.pulsar.common.util.CmdGenerateDocs in project pulsar by apache.
the class CompactorToolTest method testGenerateDocs.
/**
* Test broker-tool generate docs
*
* @throws Exception
*/
@Test
public void testGenerateDocs() throws Exception {
PrintStream oldStream = System.out;
try {
ByteArrayOutputStream baoStream = new ByteArrayOutputStream();
System.setOut(new PrintStream(baoStream));
Class argumentsClass = Class.forName("org.apache.pulsar.compaction.CompactorTool$Arguments");
Constructor constructor = argumentsClass.getDeclaredConstructor();
constructor.setAccessible(true);
Object obj = constructor.newInstance();
CmdGenerateDocs cmd = new CmdGenerateDocs("pulsar");
cmd.addCommand("compact-topic", obj);
cmd.run(null);
String message = baoStream.toString();
Field[] fields = argumentsClass.getDeclaredFields();
for (Field field : fields) {
boolean fieldHasAnno = field.isAnnotationPresent(Parameter.class);
if (fieldHasAnno) {
Parameter fieldAnno = field.getAnnotation(Parameter.class);
String[] names = fieldAnno.names();
String nameStr = Arrays.asList(names).toString();
nameStr = nameStr.substring(1, nameStr.length() - 1);
assertTrue(message.indexOf(nameStr) > 0);
}
}
} finally {
System.setOut(oldStream);
}
}
Aggregations