Search in sources :

Example 1 with InMemorySession

use of org.apache.nifi.toolkit.cli.impl.session.InMemorySession in project nifi by apache.

the class CLIMain method createContext.

private static Context createContext(final PrintStream output, final boolean isInteractive) {
    Session session;
    final String userHomeValue = System.getProperty("user.home");
    final File userHome = Paths.get(userHomeValue).toFile();
    if (!userHome.exists() || !userHome.canRead() || !userHome.canWrite()) {
        session = new InMemorySession();
        if (isInteractive) {
            output.println();
            output.println("Unable to create session from " + userHomeValue + ", falling back to in-memory session");
            output.println();
        }
    } else {
        final InMemorySession inMemorySession = new InMemorySession();
        final File sessionState = new File(userHome.getAbsolutePath(), SESSION_PERSISTENCE_FILE);
        try {
            if (!sessionState.exists()) {
                sessionState.createNewFile();
            }
            final PersistentSession persistentSession = new PersistentSession(sessionState, inMemorySession);
            persistentSession.loadSession();
            session = persistentSession;
            if (isInteractive) {
                output.println();
                output.println("Session loaded from " + sessionState.getAbsolutePath());
                output.println();
            }
        } catch (Exception e) {
            session = inMemorySession;
            if (isInteractive) {
                output.println();
                output.println("Unable to load session from " + sessionState.getAbsolutePath() + ", falling back to in-memory session");
                output.println();
            }
        }
    }
    final ClientFactory<NiFiClient> niFiClientFactory = new NiFiClientFactory();
    final ClientFactory<NiFiRegistryClient> nifiRegClientFactory = new NiFiRegistryClientFactory();
    return new StandardContext.Builder().output(output).session(session).nifiClientFactory(niFiClientFactory).nifiRegistryClientFactory(nifiRegClientFactory).interactive(isInteractive).build();
}
Also used : NiFiClientFactory(org.apache.nifi.toolkit.cli.impl.client.NiFiClientFactory) NiFiClient(org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClient) NiFiRegistryClientFactory(org.apache.nifi.toolkit.cli.impl.client.NiFiRegistryClientFactory) LineReaderBuilder(org.jline.reader.LineReaderBuilder) TerminalBuilder(org.jline.terminal.TerminalBuilder) PersistentSession(org.apache.nifi.toolkit.cli.impl.session.PersistentSession) IOException(java.io.IOException) EndOfFileException(org.jline.reader.EndOfFileException) UserInterruptException(org.jline.reader.UserInterruptException) NiFiRegistryClient(org.apache.nifi.registry.client.NiFiRegistryClient) InMemorySession(org.apache.nifi.toolkit.cli.impl.session.InMemorySession) File(java.io.File) PersistentSession(org.apache.nifi.toolkit.cli.impl.session.PersistentSession) Session(org.apache.nifi.toolkit.cli.api.Session) InMemorySession(org.apache.nifi.toolkit.cli.impl.session.InMemorySession)

Example 2 with InMemorySession

use of org.apache.nifi.toolkit.cli.impl.session.InMemorySession in project nifi by apache.

the class NiFiCLIMainRunner method main.

public static void main(String[] args) {
    final String[] cmdArgs = ("registry list-buckets help " + "").split("[ ]");
    final Session session = new InMemorySession();
    final ClientFactory<NiFiClient> niFiClientFactory = new NiFiClientFactory();
    final ClientFactory<NiFiRegistryClient> nifiRegClientFactory = new NiFiRegistryClientFactory();
    final Context context = new StandardContext.Builder().output(System.out).session(session).nifiClientFactory(niFiClientFactory).nifiRegistryClientFactory(nifiRegClientFactory).build();
    final Map<String, Command> commands = CommandFactory.createTopLevelCommands(context);
    final Map<String, CommandGroup> commandGroups = CommandFactory.createCommandGroups(context);
    final CommandProcessor processor = new CommandProcessor(commands, commandGroups, context);
    processor.process(cmdArgs);
}
Also used : StandardContext(org.apache.nifi.toolkit.cli.impl.context.StandardContext) Context(org.apache.nifi.toolkit.cli.api.Context) NiFiClientFactory(org.apache.nifi.toolkit.cli.impl.client.NiFiClientFactory) NiFiClient(org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClient) NiFiRegistryClientFactory(org.apache.nifi.toolkit.cli.impl.client.NiFiRegistryClientFactory) CommandGroup(org.apache.nifi.toolkit.cli.api.CommandGroup) NiFiRegistryClient(org.apache.nifi.registry.client.NiFiRegistryClient) Command(org.apache.nifi.toolkit.cli.api.Command) InMemorySession(org.apache.nifi.toolkit.cli.impl.session.InMemorySession) StandardContext(org.apache.nifi.toolkit.cli.impl.context.StandardContext) CommandProcessor(org.apache.nifi.toolkit.cli.impl.command.CommandProcessor) Session(org.apache.nifi.toolkit.cli.api.Session) InMemorySession(org.apache.nifi.toolkit.cli.impl.session.InMemorySession)

Example 3 with InMemorySession

use of org.apache.nifi.toolkit.cli.impl.session.InMemorySession in project nifi by apache.

the class TestCLICompleter method setupCompleter.

@BeforeClass
public static void setupCompleter() {
    final Session session = new InMemorySession();
    final ClientFactory<NiFiClient> niFiClientFactory = new NiFiClientFactory();
    final ClientFactory<NiFiRegistryClient> nifiRegClientFactory = new NiFiRegistryClientFactory();
    final Context context = new StandardContext.Builder().output(System.out).session(session).nifiClientFactory(niFiClientFactory).nifiRegistryClientFactory(nifiRegClientFactory).build();
    final Map<String, Command> commands = CommandFactory.createTopLevelCommands(context);
    final Map<String, CommandGroup> commandGroups = CommandFactory.createCommandGroups(context);
    completer = new CLICompleter(commands.values(), commandGroups.values());
    lineReader = Mockito.mock(LineReader.class);
}
Also used : StandardContext(org.apache.nifi.toolkit.cli.impl.context.StandardContext) Context(org.apache.nifi.toolkit.cli.api.Context) NiFiClientFactory(org.apache.nifi.toolkit.cli.impl.client.NiFiClientFactory) NiFiClient(org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClient) NiFiRegistryClientFactory(org.apache.nifi.toolkit.cli.impl.client.NiFiRegistryClientFactory) NiFiRegistryCommandGroup(org.apache.nifi.toolkit.cli.impl.command.registry.NiFiRegistryCommandGroup) CommandGroup(org.apache.nifi.toolkit.cli.api.CommandGroup) NiFiRegistryClient(org.apache.nifi.registry.client.NiFiRegistryClient) Command(org.apache.nifi.toolkit.cli.api.Command) InMemorySession(org.apache.nifi.toolkit.cli.impl.session.InMemorySession) StandardContext(org.apache.nifi.toolkit.cli.impl.context.StandardContext) LineReader(org.jline.reader.LineReader) Session(org.apache.nifi.toolkit.cli.api.Session) InMemorySession(org.apache.nifi.toolkit.cli.impl.session.InMemorySession) BeforeClass(org.junit.BeforeClass)

Aggregations

NiFiRegistryClient (org.apache.nifi.registry.client.NiFiRegistryClient)3 Session (org.apache.nifi.toolkit.cli.api.Session)3 NiFiClientFactory (org.apache.nifi.toolkit.cli.impl.client.NiFiClientFactory)3 NiFiRegistryClientFactory (org.apache.nifi.toolkit.cli.impl.client.NiFiRegistryClientFactory)3 NiFiClient (org.apache.nifi.toolkit.cli.impl.client.nifi.NiFiClient)3 InMemorySession (org.apache.nifi.toolkit.cli.impl.session.InMemorySession)3 Command (org.apache.nifi.toolkit.cli.api.Command)2 CommandGroup (org.apache.nifi.toolkit.cli.api.CommandGroup)2 Context (org.apache.nifi.toolkit.cli.api.Context)2 StandardContext (org.apache.nifi.toolkit.cli.impl.context.StandardContext)2 File (java.io.File)1 IOException (java.io.IOException)1 CommandProcessor (org.apache.nifi.toolkit.cli.impl.command.CommandProcessor)1 NiFiRegistryCommandGroup (org.apache.nifi.toolkit.cli.impl.command.registry.NiFiRegistryCommandGroup)1 PersistentSession (org.apache.nifi.toolkit.cli.impl.session.PersistentSession)1 EndOfFileException (org.jline.reader.EndOfFileException)1 LineReader (org.jline.reader.LineReader)1 LineReaderBuilder (org.jline.reader.LineReaderBuilder)1 UserInterruptException (org.jline.reader.UserInterruptException)1 TerminalBuilder (org.jline.terminal.TerminalBuilder)1