Search in sources :

Example 6 with Session

use of org.apache.nifi.toolkit.cli.api.Session 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)

Example 7 with Session

use of org.apache.nifi.toolkit.cli.api.Session in project nifi by apache.

the class AbstractCompositeCommand method createProperties.

/**
 * Creates a Properties instance by looking at the propertOption and falling back to the session.
 *
 * @param commandLine the current command line
 * @param propertyOption the options specifying a properties to load
 * @param sessionVariable the session variable specifying a properties file
 * @return a Properties instance or null if the option wasn't specified and nothing is in the session
 */
private Properties createProperties(final CommandLine commandLine, final CommandOption propertyOption, final SessionVariable sessionVariable) throws IOException, SessionException {
    // use the properties file specified by the properyOption if it exists
    if (commandLine.hasOption(propertyOption.getLongName())) {
        final String propertiesFile = commandLine.getOptionValue(propertyOption.getLongName());
        if (!StringUtils.isBlank(propertiesFile)) {
            try (final InputStream in = new FileInputStream(propertiesFile)) {
                final Properties properties = new Properties();
                properties.load(in);
                return properties;
            }
        }
    } else {
        // no properties file was specified so see if there is anything in the session
        if (sessionVariable != null) {
            final Session session = getContext().getSession();
            final String sessionPropsFiles = session.get(sessionVariable.getVariableName());
            if (!StringUtils.isBlank(sessionPropsFiles)) {
                try (final InputStream in = new FileInputStream(sessionPropsFiles)) {
                    final Properties properties = new Properties();
                    properties.load(in);
                    return properties;
                }
            }
        }
    }
    return null;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream) Session(org.apache.nifi.toolkit.cli.api.Session)

Aggregations

Session (org.apache.nifi.toolkit.cli.api.Session)7 NiFiRegistryClient (org.apache.nifi.registry.client.NiFiRegistryClient)3 CommandException (org.apache.nifi.toolkit.cli.api.CommandException)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 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 Properties (java.util.Properties)2 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 SessionException (org.apache.nifi.toolkit.cli.api.SessionException)2 StandardContext (org.apache.nifi.toolkit.cli.impl.context.StandardContext)2 File (java.io.File)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 Option (org.apache.commons.cli.Option)1 CommandProcessor (org.apache.nifi.toolkit.cli.impl.command.CommandProcessor)1