use of org.apache.nifi.toolkit.cli.api.SessionException in project nifi by apache.
the class GetVariable method execute.
@Override
public StringResult execute(final CommandLine commandLine) throws CommandException {
final String[] args = commandLine.getArgs();
if (args == null || args.length != 1 || StringUtils.isBlank(args[0])) {
throw new CommandException("Incorrect number of arguments, should be: <var>");
}
final Session session = getContext().getSession();
try {
final String value = session.get(args[0]);
if (value == null) {
return new StringResult("", getContext().isInteractive());
} else {
return new StringResult(value, getContext().isInteractive());
}
} catch (SessionException se) {
throw new CommandException(se.getMessage(), se);
}
}
use of org.apache.nifi.toolkit.cli.api.SessionException in project nifi by apache.
the class ShowSession method execute.
@Override
public VoidResult execute(final CommandLine cli) throws CommandException {
try {
final Session session = getContext().getSession();
final PrintStream printStream = getContext().getOutput();
session.printVariables(printStream);
return VoidResult.getInstance();
} catch (SessionException se) {
throw new CommandException(se.getMessage(), se);
}
}
use of org.apache.nifi.toolkit.cli.api.SessionException in project nifi by apache.
the class PersistentSession method loadSession.
public synchronized void loadSession() throws SessionException {
wrappedSession.clear();
try (final InputStream in = new FileInputStream(persistenceFile)) {
final Properties properties = new Properties();
properties.load(in);
for (final String propName : properties.stringPropertyNames()) {
final String propValue = properties.getProperty(propName);
wrappedSession.set(propName, propValue);
}
} catch (Exception e) {
throw new SessionException("Error loading session: " + e.getMessage(), e);
}
}
use of org.apache.nifi.toolkit.cli.api.SessionException in project nifi by apache.
the class PersistentSession method saveSession.
private void saveSession() throws SessionException {
try (final OutputStream out = new FileOutputStream(persistenceFile)) {
final Properties properties = new Properties();
for (String variable : wrappedSession.keys()) {
String value = wrappedSession.get(variable);
properties.setProperty(variable, value);
}
properties.store(out, null);
out.flush();
} catch (Exception e) {
throw new SessionException("Error saving session: " + e.getMessage(), e);
}
}
Aggregations