use of org.pentaho.di.pan.CommandLineOption in project pentaho-kettle by pentaho.
the class KitchenIT method testArgumentMaxLogTimeout_valid.
public void testArgumentMaxLogTimeout_valid() throws KettleException {
final String maxLogTimeoutArg = "658";
int expected = 658;
CommandLineOption opt = new CommandLineOption("maxlogtimeout", null, new StringBuilder(maxLogTimeoutArg));
int maxLogLines = Kitchen.parseIntArgument(opt, 0);
assertEquals(expected, maxLogLines);
}
use of org.pentaho.di.pan.CommandLineOption in project pentaho-kettle by pentaho.
the class Spoon method getCommandLineArgs.
public static CommandLineOption[] getCommandLineArgs(List<String> args) {
CommandLineOption[] clOptions = new CommandLineOption[] { new CommandLineOption("rep", "Repository name", new StringBuilder()), new CommandLineOption("user", "Repository username", new StringBuilder()), new CommandLineOption("pass", "Repository password", new StringBuilder()), new CommandLineOption("job", "The name of the job to launch", new StringBuilder()), new CommandLineOption("trans", "The name of the transformation to launch", new StringBuilder()), new CommandLineOption("dir", "The directory (don't forget the leading /)", new StringBuilder()), new CommandLineOption("file", "The filename (Transformation in XML) to launch", new StringBuilder()), new CommandLineOption("level", "The logging level (Basic, Detailed, Debug, Rowlevel, Error, Nothing)", new StringBuilder()), new CommandLineOption("logfile", "The logging file to write to", new StringBuilder()), new CommandLineOption("log", "The logging file to write to (deprecated)", new StringBuilder(), false, true), new CommandLineOption("perspective", "The perspective to start in", new StringBuilder(), false, true) };
// start with the default logger until we find out otherwise
//
log = new LogChannel(APP_NAME);
// Parse the options...
if (!CommandLineOption.parseArguments(args, clOptions, log)) {
log.logError("Command line option not understood");
System.exit(8);
}
String kettleRepname = Const.getEnvironmentVariable("KETTLE_REPOSITORY", null);
String kettleUsername = Const.getEnvironmentVariable("KETTLE_USER", null);
String kettlePassword = Const.getEnvironmentVariable("KETTLE_PASSWORD", null);
if (!Utils.isEmpty(kettleRepname)) {
clOptions[0].setArgument(new StringBuilder(kettleRepname));
}
if (!Utils.isEmpty(kettleUsername)) {
clOptions[1].setArgument(new StringBuilder(kettleUsername));
}
if (!Utils.isEmpty(kettlePassword)) {
clOptions[2].setArgument(new StringBuilder(kettlePassword));
}
return clOptions;
}
use of org.pentaho.di.pan.CommandLineOption in project pentaho-kettle by pentaho.
the class Kitchen method main.
public static void main(String[] a) throws Exception {
final ExecutorService executor = ExecutorUtil.getExecutor();
final RepositoryPluginType repositoryPluginType = RepositoryPluginType.getInstance();
final Future<Map.Entry<KettlePluginException, Future<KettleException>>> repositoryRegisterFuture = executor.submit(new Callable<Map.Entry<KettlePluginException, Future<KettleException>>>() {
@Override
public Map.Entry<KettlePluginException, Future<KettleException>> call() throws Exception {
PluginRegistry.addPluginType(repositoryPluginType);
try {
KettleClientEnvironment.getInstance().setClient(KettleClientEnvironment.ClientType.KITCHEN);
KettleClientEnvironment.init();
} catch (KettlePluginException e) {
return new AbstractMap.SimpleImmutableEntry<KettlePluginException, Future<KettleException>>(e, null);
}
Future<KettleException> kettleEnvironmentInitFuture = executor.submit(new Callable<KettleException>() {
@Override
public KettleException call() throws Exception {
try {
KettleClientEnvironment.getInstance().setClient(KettleClientEnvironment.ClientType.KITCHEN);
KettleEnvironment.init();
} catch (KettleException e) {
return e;
}
return null;
}
});
return new AbstractMap.SimpleImmutableEntry<KettlePluginException, Future<KettleException>>(null, kettleEnvironmentInitFuture);
}
});
List<String> args = new ArrayList<String>();
for (int i = 0; i < a.length; i++) {
if (a[i].length() > 0) {
args.add(a[i]);
}
}
DelegatingMetaStore metaStore = new DelegatingMetaStore();
metaStore.addMetaStore(MetaStoreConst.openLocalPentahoMetaStore());
metaStore.setActiveMetaStoreName(metaStore.getName());
RepositoryMeta repositoryMeta = null;
Job job = null;
StringBuilder optionRepname, optionUsername, optionTrustUser, optionPassword, optionJobname, optionDirname, initialDir;
StringBuilder optionFilename, optionLoglevel, optionLogfile, optionLogfileOld, optionListdir;
StringBuilder optionListjobs, optionListrep, optionNorep, optionVersion, optionListParam, optionExport;
NamedParams optionParams = new NamedParamsDefault();
NamedParams customOptions = new NamedParamsDefault();
CommandLineOption maxLogLinesOption = new CommandLineOption("maxloglines", BaseMessages.getString(PKG, "Kitchen.CmdLine.MaxLogLines"), new StringBuilder());
CommandLineOption maxLogTimeoutOption = new CommandLineOption("maxlogtimeout", BaseMessages.getString(PKG, "Kitchen.CmdLine.MaxLogTimeout"), new StringBuilder());
CommandLineOption[] options = new CommandLineOption[] { new CommandLineOption("rep", BaseMessages.getString(PKG, "Kitchen.CmdLine.RepName"), optionRepname = new StringBuilder()), new CommandLineOption("user", BaseMessages.getString(PKG, "Kitchen.CmdLine.RepUsername"), optionUsername = new StringBuilder()), new CommandLineOption("trustuser", BaseMessages.getString(PKG, "Kitchen.ComdLine.RepUsername"), optionTrustUser = new StringBuilder()), new CommandLineOption("pass", BaseMessages.getString(PKG, "Kitchen.CmdLine.RepPassword"), optionPassword = new StringBuilder()), new CommandLineOption("job", BaseMessages.getString(PKG, "Kitchen.CmdLine.RepJobName"), optionJobname = new StringBuilder()), new CommandLineOption("dir", BaseMessages.getString(PKG, "Kitchen.CmdLine.RepDir"), optionDirname = new StringBuilder()), new CommandLineOption("file", BaseMessages.getString(PKG, "Kitchen.CmdLine.XMLJob"), optionFilename = new StringBuilder()), new CommandLineOption("level", BaseMessages.getString(PKG, "Kitchen.CmdLine.LogLevel"), optionLoglevel = new StringBuilder()), new CommandLineOption("logfile", BaseMessages.getString(PKG, "Kitchen.CmdLine.LogFile"), optionLogfile = new StringBuilder()), new CommandLineOption("log", BaseMessages.getString(PKG, "Kitchen.CmdLine.LogFileOld"), optionLogfileOld = new StringBuilder(), false, true), new CommandLineOption("listdir", BaseMessages.getString(PKG, "Kitchen.CmdLine.ListDir"), optionListdir = new StringBuilder(), true, false), new CommandLineOption("listjobs", BaseMessages.getString(PKG, "Kitchen.CmdLine.ListJobsDir"), optionListjobs = new StringBuilder(), true, false), new CommandLineOption("listrep", BaseMessages.getString(PKG, "Kitchen.CmdLine.ListAvailableReps"), optionListrep = new StringBuilder(), true, false), new CommandLineOption("norep", BaseMessages.getString(PKG, "Kitchen.CmdLine.NoRep"), optionNorep = new StringBuilder(), true, false), new CommandLineOption("version", BaseMessages.getString(PKG, "Kitchen.CmdLine.Version"), optionVersion = new StringBuilder(), true, false), new CommandLineOption("param", BaseMessages.getString(PKG, "Kitchen.ComdLine.Param"), optionParams, false), new CommandLineOption("listparam", BaseMessages.getString(PKG, "Kitchen.ComdLine.ListParam"), optionListParam = new StringBuilder(), true, false), new CommandLineOption("export", BaseMessages.getString(PKG, "Kitchen.ComdLine.Export"), optionExport = new StringBuilder(), true, false), new CommandLineOption("initialDir", null, initialDir = new StringBuilder(), false, true), new CommandLineOption("custom", BaseMessages.getString(PKG, "Kitchen.ComdLine.Custom"), customOptions, false), maxLogLinesOption, maxLogTimeoutOption };
if (args.size() == 2) {
// 2 internal hidden argument (flag and value)
CommandLineOption.printUsage(options);
exitJVM(9);
}
LogChannelInterface log = new LogChannel(STRING_KITCHEN);
CommandLineOption.parseArguments(args, options, log);
configureLogging(maxLogLinesOption, maxLogTimeoutOption);
String kettleRepname = Const.getEnvironmentVariable("KETTLE_REPOSITORY", null);
String kettleUsername = Const.getEnvironmentVariable("KETTLE_USER", null);
String kettlePassword = Const.getEnvironmentVariable("KETTLE_PASSWORD", null);
if (!Utils.isEmpty(kettleRepname)) {
optionRepname = new StringBuilder(kettleRepname);
}
if (!Utils.isEmpty(kettleUsername)) {
optionUsername = new StringBuilder(kettleUsername);
}
if (!Utils.isEmpty(kettlePassword)) {
optionPassword = new StringBuilder(kettlePassword);
}
if (Utils.isEmpty(optionLogfile) && !Utils.isEmpty(optionLogfileOld)) {
// if the old style of logging name is filled in, and the new one is not
// overwrite the new by the old
optionLogfile = optionLogfileOld;
}
Map.Entry<KettlePluginException, Future<KettleException>> repositoryRegisterResults = repositoryRegisterFuture.get();
// It's a singleton map with one key-value pair (a Pair collection)
KettlePluginException repositoryRegisterException = repositoryRegisterResults.getKey();
if (repositoryRegisterException != null) {
throw repositoryRegisterException;
}
Future<KettleException> kettleInitFuture = repositoryRegisterResults.getValue();
if (!Utils.isEmpty(optionLogfile)) {
fileAppender = new FileLoggingEventListener(optionLogfile.toString(), true);
KettleLogStore.getAppender().addLoggingEventListener(fileAppender);
} else {
fileAppender = null;
}
if (!Utils.isEmpty(optionLoglevel)) {
log.setLogLevel(LogLevel.getLogLevelForCode(optionLoglevel.toString()));
log.logMinimal(BaseMessages.getString(PKG, "Kitchen.Log.LogLevel", log.getLogLevel().getDescription()));
}
// Start the action...
//
int returnCode = CommandExecutorCodes.Kitchen.SUCCESS.getCode();
try {
if (getCommandExecutor() == null) {
// init
setCommandExecutor(new KitchenCommandExecutor(PKG, log, kettleInitFuture));
}
if (!Utils.isEmpty(optionVersion)) {
getCommandExecutor().printVersion();
if (a.length == 1) {
exitJVM(CommandExecutorCodes.Pan.KETTLE_VERSION_PRINT.getCode());
}
}
returnCode = getCommandExecutor().execute(optionRepname.toString(), optionNorep.toString(), optionUsername.toString(), optionTrustUser.toString(), optionPassword.toString(), optionDirname.toString(), optionFilename.toString(), optionJobname.toString(), optionListjobs.toString(), optionListdir.toString(), optionExport.toString(), initialDir.toString(), optionListrep.toString(), optionListParam.toString(), optionParams, customOptions, args.toArray(new String[args.size()]));
} catch (Throwable t) {
t.printStackTrace();
returnCode = CommandExecutorCodes.Pan.UNEXPECTED_ERROR.getCode();
} finally {
if (fileAppender != null) {
fileAppender.close();
KettleLogStore.getAppender().removeLoggingEventListener(fileAppender);
}
}
exitJVM(returnCode);
}
use of org.pentaho.di.pan.CommandLineOption in project pentaho-kettle by pentaho.
the class RepositorySpoonStartExtensionPoint method callExtensionPoint.
@Override
public void callExtensionPoint(LogChannelInterface log, Object object) throws KettleException {
if (!(object instanceof CommandLineOption[])) {
return;
}
CommandLineOption[] options = (CommandLineOption[]) object;
StringBuilder optionRepname = getCommandLineOption(options, "rep").getArgument();
StringBuilder optionFilename = getCommandLineOption(options, "file").getArgument();
StringBuilder optionUsername = getCommandLineOption(options, "user").getArgument();
StringBuilder optionPassword = getCommandLineOption(options, "pass").getArgument();
if (!Utils.isEmpty(optionRepname) && Utils.isEmpty(optionFilename)) {
RepositoryMeta repositoryMeta = repositoryConnectController.getRepositoryMetaByName(optionRepname.toString());
if (repositoryMeta != null && !Utils.isEmpty(optionUsername) && !Utils.isEmpty(optionPassword)) {
repositoryConnectController.connectToRepository(repositoryMeta, optionUsername.toString(), optionPassword.toString());
} else if (repositoryMeta != null) {
repositoryConnectController.connectToRepository(repositoryMeta, null, null);
}
if (!repositoryConnectController.isConnected()) {
String msg = BaseMessages.getString(PKG, "Repository.NoConnected.Message");
// "No repositories defined on this system."
log.logError(msg);
MessageBox mb = new MessageBox(getSpoon().getShell(), SWT.OK | SWT.ICON_ERROR);
mb.setMessage(BaseMessages.getString(PKG, "Repository.NoConnected.Message", optionRepname.toString()));
mb.setText(BaseMessages.getString(PKG, "Repository.NoConnected.Message.Title"));
mb.open();
}
} else if (Utils.isEmpty(optionFilename)) {
RepositoryMeta repositoryMeta = repositoryConnectController.getDefaultRepositoryMeta();
if (repositoryMeta != null) {
if (repositoryMeta.getId().equals("KettleFileRepository")) {
repositoryConnectController.connectToRepository(repositoryMeta);
} else {
new RepositoryDialog(getSpoon().getShell(), repositoryConnectController).openLogin(repositoryMeta);
}
}
}
}
use of org.pentaho.di.pan.CommandLineOption in project pentaho-kettle by pentaho.
the class Spoon method main.
/**
* This is the main procedure for Spoon.
*
* @param a
* Arguments are available in the "Get System Info" step.
*/
public static void main(String[] a) throws KettleException {
boolean doConsoleRedirect = !Boolean.getBoolean("Spoon.Console.Redirect.Disabled");
if (doConsoleRedirect) {
try {
Path parent = Paths.get(System.getProperty("user.dir") + File.separator + "logs");
Files.createDirectories(parent);
Files.deleteIfExists(Paths.get(parent.toString(), "spoon.log"));
Path path = Files.createFile(Paths.get(parent.toString(), "spoon.log"));
System.setProperty("LOG_PATH", path.toString());
final FileOutputStream fos = new FileOutputStream(path.toFile());
System.setOut(new PrintStream(new TeeOutputStream(originalSystemOut, fos)));
System.setErr(new PrintStream(new TeeOutputStream(originalSystemErr, fos)));
KettleLogStore.OriginalSystemOut = System.out;
KettleLogStore.OriginalSystemErr = System.err;
} catch (Throwable ignored) {
// ignored
}
}
ExecutorService executor = Executors.newCachedThreadPool();
Future<KettleException> pluginRegistryFuture = executor.submit(new Callable<KettleException>() {
@Override
public KettleException call() throws Exception {
registerUIPluginObjectTypes();
KettleClientEnvironment.getInstance().setClient(KettleClientEnvironment.ClientType.SPOON);
try {
KettleEnvironment.init();
} catch (KettleException e) {
return e;
}
return null;
}
});
try {
OsHelper.setAppName();
// Bootstrap Kettle
//
Display display;
if (System.getProperties().containsKey("SLEAK")) {
DeviceData data = new DeviceData();
data.tracking = true;
display = new Display(data);
Sleak sleak = new Sleak();
Shell sleakShell = new Shell(display);
sleakShell.setText("S-Leak");
org.eclipse.swt.graphics.Point size = sleakShell.getSize();
sleakShell.setSize(size.x / 2, size.y / 2);
sleak.create(sleakShell);
sleakShell.open();
} else {
display = new Display();
}
// Note: this needs to be done before the look and feel is set
OsHelper.initOsHandlers(display);
UIManager.setLookAndFeel(new MetalLookAndFeel());
// The core plugin types don't know about UI classes. Add them in now
// before the PluginRegistry is inited.
splash = new Splash(display);
List<String> args = new ArrayList<>(Arrays.asList(a));
CommandLineOption[] commandLineOptions = getCommandLineArgs(args);
KettleException registryException = pluginRegistryFuture.get();
if (registryException != null) {
throw registryException;
}
PropsUI.init(display, Props.TYPE_PROPERTIES_SPOON);
KettleLogStore.init(PropsUI.getInstance().getMaxNrLinesInLog(), PropsUI.getInstance().getMaxLogLineTimeoutMinutes());
initLogging(commandLineOptions);
// remember...
staticSpoon = new Spoon();
staticSpoon.commandLineOptions = commandLineOptions;
// pull the startup perspective id from the command line options and hand it to Spoon
String pId;
StringBuilder perspectiveIdBuff = Spoon.getCommandLineOption(commandLineOptions, "perspective").getArgument();
pId = perspectiveIdBuff.toString();
if (!Utils.isEmpty(pId)) {
Spoon.staticSpoon.startupPerspective = pId;
}
SpoonFactory.setSpoonInstance(staticSpoon);
staticSpoon.setDestroy(true);
GUIFactory.setThreadDialogs(new ThreadGuiResources());
staticSpoon.setArguments(args.toArray(new String[args.size()]));
staticSpoon.start();
} catch (Throwable t) {
// avoid calls to Messages i18n method getString() in this block
// We do this to (hopefully) also catch Out of Memory Exceptions
//
t.printStackTrace();
if (staticSpoon != null) {
log.logError("Fatal error : " + Const.NVL(t.toString(), Const.NVL(t.getMessage(), "Unknown error")));
log.logError(Const.getStackTracker(t));
}
}
// Kill all remaining things in this VM!
System.exit(0);
}
Aggregations