Search in sources :

Example 1 with CmdGenerateDocs

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;
}
Also used : MetadataStore(org.apache.pulsar.metadata.api.MetadataStore) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) PulsarResources(org.apache.pulsar.broker.resources.PulsarResources) JCommander(com.beust.jcommander.JCommander) CmdGenerateDocs(org.apache.pulsar.common.util.CmdGenerateDocs)

Example 2 with CmdGenerateDocs

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");
}
Also used : PulsarResources(org.apache.pulsar.broker.resources.PulsarResources) JCommander(com.beust.jcommander.JCommander) CmdGenerateDocs(org.apache.pulsar.common.util.CmdGenerateDocs) MetadataStoreExtended(org.apache.pulsar.metadata.api.extended.MetadataStoreExtended)

Example 3 with CmdGenerateDocs

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());
}
Also used : JCommander(com.beust.jcommander.JCommander) CmdGenerateDocs(org.apache.pulsar.common.util.CmdGenerateDocs)

Example 4 with CmdGenerateDocs

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;
}
Also used : CmdGenerateDocs(org.apache.pulsar.common.util.CmdGenerateDocs) JCommander(com.beust.jcommander.JCommander) ArrayList(java.util.ArrayList)

Example 5 with CmdGenerateDocs

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);
    }
}
Also used : PrintStream(java.io.PrintStream) Field(java.lang.reflect.Field) Constructor(java.lang.reflect.Constructor) CmdGenerateDocs(org.apache.pulsar.common.util.CmdGenerateDocs) Parameter(com.beust.jcommander.Parameter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.testng.annotations.Test)

Aggregations

CmdGenerateDocs (org.apache.pulsar.common.util.CmdGenerateDocs)36 JCommander (com.beust.jcommander.JCommander)30 MetadataStoreExtended (org.apache.pulsar.metadata.api.extended.MetadataStoreExtended)12 PulsarResources (org.apache.pulsar.broker.resources.PulsarResources)9 Parameter (com.beust.jcommander.Parameter)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 IOException (java.io.IOException)6 PrintStream (java.io.PrintStream)6 Constructor (java.lang.reflect.Constructor)6 Field (java.lang.reflect.Field)6 Cleanup (lombok.Cleanup)6 BookKeeper (org.apache.bookkeeper.client.BookKeeper)6 MetadataStore (org.apache.pulsar.metadata.api.MetadataStore)6 Test (org.testng.annotations.Test)6 DefaultUsageFormatter (com.beust.jcommander.DefaultUsageFormatter)3 IUsageFormatter (com.beust.jcommander.IUsageFormatter)3 ParameterException (com.beust.jcommander.ParameterException)3 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)3 EventLoopGroup (io.netty.channel.EventLoopGroup)3