use of org.apache.nifi.toolkit.cli.impl.client.NiFiRegistryClientFactory 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();
}
use of org.apache.nifi.toolkit.cli.impl.client.NiFiRegistryClientFactory 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);
}
use of org.apache.nifi.toolkit.cli.impl.client.NiFiRegistryClientFactory 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);
}
Aggregations