Events-cli: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(22 intermediate revisions by the same user not shown)
Line 10: Line 10:
Enforces the following command line structure:
Enforces the following command line structure:


  <''parser''> [''command''] [''command-options''] [''query''] <file1> [<file2> ...]
  <''parser''> [''[[Events-api_Concepts#Query|query]]''] [''[[#Parser-specific_Top-level_Argument_Processing|parser-specific-top-level-arguments]]''] [''command'' [''command-options'']] <file1> [<file2> ...]


   cat <input-file> | <''parser''> [''command''] [''command-options''] [''query'']
   cat <input-file> | <''parser''> [''[[Events-api_Concepts#Query|query]]''] [''command''] [''command-options'']  
 
where the commands represent [[events-processing]] procedures.


=User Manual=
=User Manual=
==Usage==
<syntaxhighlight lang='java'>
public class Main {
  public static final String APPLICATION_NAME = "some-app";
  public static void main(String[] args) throws Exception {
    try {
        Parser parser = new SomeAppParser();
        ProcedureFactory procedureFactory = new SomeAppProcedureFactory();
        ApplicationSpecificBehavior asb = new ApplicationSpecificBehavior(parser, procedureFactory);
        EventParserRuntime runtime = new EventParserRuntime(args, APPLICATION_NAME, asb);
        if (runtime.getConfiguration().isHelp()) {
            runtime.displayHelp(APPLICATION_NAME);
            return;
        }
        runtime.run();
    }
    catch(UserErrorException e) {
        System.err.println(e.getMessage());
    }
  }
}
</syntaxhighlight>
For more details about application-specific behavior pattern see: {{Internal|Nova Ordis Application-Specific Behavior Pattern#Overview|novaordis-utilities Application-Specific Behavior Pattern}}
==Parser-specific Top-level Argument Processing==
Each parser may have top-level command-line arguments that only make sense in the context of this specific parser, and are not part of parser-specific command (procedure) specification. For example, in case of the log4j log parser, the expected log4j pattern layout may be specified on the command line with -f '%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n'. These arguments can only be identified by application specific command-line argument processor, and they must have a syntax that allows them to be identified by such processor. The generic events-cli command line parsing logic exposes with priority the command line to such a processor - if it was installed via the [[Nova Ordis Application-Specific Behavior Pattern#Overview|novaordis-utilities Application-Specific Behavior Pattern API]], to give it a chance to recognize those arguments and remove them from the list of arguments.
Such processor must implement [https://github.com/NovaOrdis/events-cli/blob/master/src/main/java/io/novaordis/events/cli/TopLevelArgumentProcessor.java TopLevelArgumentProcessor] interface.
==End-to-end Testing==
<syntaxhighlight lang='java'>
File f = new File(System.getProperty("basedir"), "src/test/resources/data/something.txt");
assertTrue(f.isFile());
Parser parser = new SomeParser();
MockProcedureFactory mf = new MockProcedureFactory();
ApplicationSpecificBehavior asb = new ApplicationSpecificBehavior(parser, mf);
String[] commandLine = {
    "mock-procedure",
    f.getPath()
};
EventParserRuntime r = new EventParserRuntime(commandLine, "test", asb);
r.run();
</syntaxhighlight>


=Development=
=Development=
Line 23: Line 94:


==Maven==
==Maven==
<dependency>
    <groupId>io.novaordis.events.cli</groupId>
    <artifactId>events-cli</artifactId>
    <version>${events.cli.version}</version>
</dependency>

Latest revision as of 17:03, 28 October 2017

Internal

Overview

Command line logic for event parsers.

Enforces the following command line structure:

<parser> [query] [parser-specific-top-level-arguments] [command [command-options]] <file1> [<file2> ...]
 cat <input-file> | <parser> [query] [command] [command-options] 

where the commands represent events-processing procedures.

User Manual

Usage

public class Main {

  public static final String APPLICATION_NAME = "some-app";

  public static void main(String[] args) throws Exception {

    try {

        Parser parser = new SomeAppParser();

        ProcedureFactory procedureFactory = new SomeAppProcedureFactory();

        ApplicationSpecificBehavior asb = new ApplicationSpecificBehavior(parser, procedureFactory);

        EventParserRuntime runtime = new EventParserRuntime(args, APPLICATION_NAME, asb);

        if (runtime.getConfiguration().isHelp()) {

            runtime.displayHelp(APPLICATION_NAME);
            return;
        }

        runtime.run();

    }
    catch(UserErrorException e) {

        System.err.println(e.getMessage());
    }
  }
}

For more details about application-specific behavior pattern see:

novaordis-utilities Application-Specific Behavior Pattern

Parser-specific Top-level Argument Processing

Each parser may have top-level command-line arguments that only make sense in the context of this specific parser, and are not part of parser-specific command (procedure) specification. For example, in case of the log4j log parser, the expected log4j pattern layout may be specified on the command line with -f '%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n'. These arguments can only be identified by application specific command-line argument processor, and they must have a syntax that allows them to be identified by such processor. The generic events-cli command line parsing logic exposes with priority the command line to such a processor - if it was installed via the novaordis-utilities Application-Specific Behavior Pattern API, to give it a chance to recognize those arguments and remove them from the list of arguments.

Such processor must implement TopLevelArgumentProcessor interface.

End-to-end Testing

File f = new File(System.getProperty("basedir"), "src/test/resources/data/something.txt");
assertTrue(f.isFile());

Parser parser = new SomeParser();

MockProcedureFactory mf = new MockProcedureFactory();

ApplicationSpecificBehavior asb = new ApplicationSpecificBehavior(parser, mf);

String[] commandLine = {

    "mock-procedure",
    f.getPath()
};

EventParserRuntime r = new EventParserRuntime(commandLine, "test", asb);

r.run();

Development

GitHub

https://github.com/NovaOrdis/events-cli

Maven

<dependency>
    <groupId>io.novaordis.events.cli</groupId>
    <artifactId>events-cli</artifactId>
    <version>${events.cli.version}</version>
</dependency>