use of org.apache.nifi.toolkit.cli.impl.session.SessionVariable in project nifi by apache.
the class AbstractPropertyCommand method execute.
@Override
public final R execute(final CommandLine commandLine) throws CommandException {
try {
final Properties properties = new Properties();
// start by loading the properties file if it was specified
if (commandLine.hasOption(CommandOption.PROPERTIES.getLongName())) {
final String propertiesFile = commandLine.getOptionValue(CommandOption.PROPERTIES.getLongName());
if (!StringUtils.isBlank(propertiesFile)) {
try (final InputStream in = new FileInputStream(propertiesFile)) {
properties.load(in);
}
}
} else {
// no properties file was specified so see if there is anything in the session
final SessionVariable sessionVariable = getPropertiesSessionVariable();
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)) {
properties.load(in);
}
}
}
}
// add in anything specified on command line, and override anything that was already there
for (final Option option : commandLine.getOptions()) {
final String optValue = option.getValue() == null ? "" : option.getValue();
properties.setProperty(option.getLongOpt(), optValue);
}
// delegate to sub-classes
return doExecute(properties);
} catch (CommandException ce) {
throw ce;
} catch (Exception e) {
throw new CommandException("Error executing command '" + getName() + "' : " + e.getMessage(), e);
}
}
use of org.apache.nifi.toolkit.cli.impl.session.SessionVariable in project nifi by apache.
the class ShowKeys method execute.
@Override
public VoidResult execute(CommandLine cli) throws CommandException {
println();
for (final SessionVariable variable : SessionVariable.values()) {
println("\t" + variable.getVariableName());
}
println();
return VoidResult.getInstance();
}
Aggregations