Search in sources :

Example 1 with IConfigOptions

use of org.apache.hop.core.config.plugin.IConfigOptions in project hop by apache.

the class HopSearch method main.

public static void main(String[] args) {
    HopSearch hopSearch = new HopSearch();
    try {
        HopEnvironment.init();
        // Also register the search plugin type (usually only done for the GUI)
        // We don't want to load these in HopEnvironmnent.init() because for now it would
        // only be useful in Hop GUI and Hop Search.  There is no need to slow down
        // Hop Run or Hop Server with this.
        // 
        PluginRegistry registry = PluginRegistry.getInstance();
        SearchableAnalyserPluginType searchableAnalyserPluginType = SearchableAnalyserPluginType.getInstance();
        registry.addPluginType(searchableAnalyserPluginType);
        searchableAnalyserPluginType.searchPlugins();
        CommandLine cmd = new CommandLine(hopSearch);
        List<IPlugin> configPlugins = registry.getPlugins(ConfigPluginType.class);
        for (IPlugin configPlugin : configPlugins) {
            // Load only the plugins of the "search" category
            if (ConfigPlugin.CATEGORY_SEARCH.equals(configPlugin.getCategory())) {
                IConfigOptions configOptions = registry.loadClass(configPlugin, IConfigOptions.class);
                cmd.addMixin(configPlugin.getIds()[0], configOptions);
            }
        }
        hopSearch.setCmd(cmd);
        CommandLine.ParseResult parseResult = cmd.parseArgs(args);
        if (CommandLine.printHelpIfRequested(parseResult)) {
            System.exit(1);
        } else {
            hopSearch.run();
            System.exit(0);
        }
    } catch (ParameterException e) {
        System.err.println(e.getMessage());
        hopSearch.cmd.usage(System.err);
        System.exit(9);
    } catch (ExecutionException e) {
        System.err.println("Error found during execution!");
        System.err.println(Const.getStackTracker(e));
        System.exit(1);
    } catch (Exception e) {
        System.err.println("General error found, something went horribly wrong!");
        System.err.println(Const.getStackTracker(e));
        System.exit(2);
    }
}
Also used : CommandLine(picocli.CommandLine) IConfigOptions(org.apache.hop.core.config.plugin.IConfigOptions) PluginRegistry(org.apache.hop.core.plugins.PluginRegistry) ParameterException(picocli.CommandLine.ParameterException) ExecutionException(picocli.CommandLine.ExecutionException) HopException(org.apache.hop.core.exception.HopException) ParameterException(picocli.CommandLine.ParameterException) ExecutionException(picocli.CommandLine.ExecutionException) IPlugin(org.apache.hop.core.plugins.IPlugin)

Example 2 with IConfigOptions

use of org.apache.hop.core.config.plugin.IConfigOptions in project hop by apache.

the class HopImport method main.

public static void main(String[] args) {
    HopImport hopImport = new HopImport();
    try {
        // Create the command line options...
        // 
        CommandLine cmd = new CommandLine(hopImport);
        // Initialize the Hop environment: load plugins and more
        // 
        HopEnvironment.init();
        // Picks up the system settings in the variables
        // 
        hopImport.buildVariableSpace();
        // Now add run configuration plugins...
        // 
        List<IPlugin> configPlugins = PluginRegistry.getInstance().getPlugins(ConfigPluginType.class);
        for (IPlugin configPlugin : configPlugins) {
            // Load only the plugins of the "import" category
            if (ConfigPlugin.CATEGORY_IMPORT.equals(configPlugin.getCategory())) {
                IConfigOptions configOptions = PluginRegistry.getInstance().loadClass(configPlugin, IConfigOptions.class);
                cmd.addMixin(configPlugin.getIds()[0], configOptions);
            }
        }
        hopImport.setCmd(cmd);
        // This will calculate the option values and put them in HopRun or the plugin classes
        // 
        CommandLine.ParseResult parseResult = cmd.parseArgs(args);
        if (CommandLine.printHelpIfRequested(parseResult)) {
            System.exit(1);
        } else {
            // now run!
            // 
            hopImport.run();
            if (hopImport != null && hopImport.isFinishedWithoutError()) {
                System.exit(0);
            } else {
                System.exit(1);
            }
        }
    } catch (ParameterException e) {
        System.err.println(e.getMessage());
        hopImport.cmd.usage(System.err);
        System.exit(9);
    } catch (ExecutionException e) {
        System.err.println("Error found during execution!");
        System.err.println(Const.getStackTracker(e));
        System.exit(1);
    } catch (Exception e) {
        System.err.println("General error found, something went horribly wrong!");
        System.err.println(Const.getStackTracker(e));
        System.exit(2);
    }
}
Also used : CommandLine(picocli.CommandLine) IConfigOptions(org.apache.hop.core.config.plugin.IConfigOptions) ParameterException(picocli.CommandLine.ParameterException) ExecutionException(picocli.CommandLine.ExecutionException) HopException(org.apache.hop.core.exception.HopException) ParameterException(picocli.CommandLine.ParameterException) ExecutionException(picocli.CommandLine.ExecutionException) IOException(java.io.IOException) IPlugin(org.apache.hop.core.plugins.IPlugin)

Example 3 with IConfigOptions

use of org.apache.hop.core.config.plugin.IConfigOptions in project hop by apache.

the class HopImport method run.

@Override
public void run() {
    try {
        log = new LogChannel("HopImport");
        if (listPluginTypes != null && listPluginTypes) {
            printPluginTypes();
            return;
        }
        if (!validateOptions()) {
            cmd.usage(System.err);
            return;
        }
        hopImport = loadImportPlugin();
        if (hopImport == null) {
            return;
        }
        log.logDetailed("Start of Hop Import");
        // Set the options...
        // 
        hopImport.setValidateInputFolder(inputFolderName);
        hopImport.setValidateOutputFolder(outputFolderName);
        hopImport.setKettlePropertiesFilename(kettlePropertiesFilename);
        hopImport.setJdbcPropertiesFilename(jdbcPropertiesFilename);
        hopImport.setSharedXmlFilename(sharedXmlFilename);
        if (skippingExistingTargetFiles != null) {
            log.logBasic("Import is " + (skippingExistingTargetFiles ? "" : "not ") + "skipping existing target files");
            hopImport.setSkippingExistingTargetFiles(skippingExistingTargetFiles);
        }
        if (skippingHiddenFilesAndFolders != null) {
            log.logBasic("Import is " + (skippingHiddenFilesAndFolders ? "" : "not ") + "skipping hidden files and folders");
            hopImport.setSkippingHiddenFilesAndFolders(skippingHiddenFilesAndFolders);
        }
        if (skippingFolders != null) {
            log.logBasic("Import is " + (skippingFolders ? "" : "not ") + "skipping sub-folders");
            hopImport.setSkippingFolders(skippingFolders);
        }
        hopImport.setTargetConfigFilename(targetConfigFilename);
        // Allow plugins to modify the elements loaded so far, before a pipeline or workflow is even
        // loaded
        // 
        ExtensionPointHandler.callExtensionPoint(log, variables, HopExtensionPoint.HopImportStart.id, this);
        // Handle the options of the configuration plugins
        // 
        Map<String, Object> mixins = cmd.getMixins();
        for (String key : mixins.keySet()) {
            Object mixin = mixins.get(key);
            if (mixin instanceof IConfigOptions) {
                IConfigOptions configOptions = (IConfigOptions) mixin;
                configOptions.handleOption(log, this, variables);
            }
        }
        // Text version of a progress monitor...
        // 
        IProgressMonitor monitor = new LogProgressMonitor(log);
        // Run the import...
        // 
        hopImport.runImport(monitor);
        // Print the report...
        // 
        log.logBasic(Const.CR);
        log.logBasic(hopImport.getImportReport());
        ExtensionPointHandler.callExtensionPoint(log, variables, HopExtensionPoint.HopImportEnd.id, this);
    } catch (Exception e) {
        throw new ExecutionException(cmd, "There was an error during import", e);
    }
}
Also used : IConfigOptions(org.apache.hop.core.config.plugin.IConfigOptions) IProgressMonitor(org.apache.hop.core.IProgressMonitor) ILogChannel(org.apache.hop.core.logging.ILogChannel) LogChannel(org.apache.hop.core.logging.LogChannel) ExecutionException(picocli.CommandLine.ExecutionException) LogProgressMonitor(org.apache.hop.core.LogProgressMonitor) HopException(org.apache.hop.core.exception.HopException) ParameterException(picocli.CommandLine.ParameterException) ExecutionException(picocli.CommandLine.ExecutionException) IOException(java.io.IOException)

Example 4 with IConfigOptions

use of org.apache.hop.core.config.plugin.IConfigOptions in project hop by apache.

the class HopServer method main.

public static void main(String[] args) {
    String[] arguments = Stream.of(args).flatMap(a -> Stream.of(a.split("(?=--)"))).filter(a -> !a.isEmpty()).toArray(String[]::new);
    HopServer hopServer = new HopServer();
    try {
        // Create the command line options...
        // 
        picocli.CommandLine cmd = new picocli.CommandLine(hopServer);
        // Apply the system properties to the JVM
        // 
        hopServer.applySystemProperties();
        // Initialize the Hop environment: load plugins and more
        // 
        HopClientEnvironment.getInstance().setClient(HopClientEnvironment.ClientType.SERVER);
        HopEnvironment.init();
        // Picks up the system settings in the variables
        // 
        hopServer.buildVariableSpace();
        // Clear the jar file cache so that we don't waste memory...
        // 
        JarCache.getInstance().clear();
        // Set up the metadata to use
        // 
        hopServer.metadataProvider = HopMetadataUtil.getStandardHopMetadataProvider(hopServer.variables);
        // Now add server configuration plugins...
        // 
        List<IPlugin> configPlugins = PluginRegistry.getInstance().getPlugins(ConfigPluginType.class);
        for (IPlugin configPlugin : configPlugins) {
            // Load only the plugins of the "run" category
            if (ConfigPlugin.CATEGORY_SERVER.equals(configPlugin.getCategory())) {
                IConfigOptions configOptions = PluginRegistry.getInstance().loadClass(configPlugin, IConfigOptions.class);
                cmd.addMixin(configPlugin.getIds()[0], configOptions);
            }
        }
        hopServer.setCmd(cmd);
        // Add optional metadata folder (legacy)
        // 
        hopServer.addMetadataFolderProvider();
        // This will calculate the option values and put them in HopRun or the plugin classes
        // 
        picocli.CommandLine.ParseResult parseResult = cmd.parseArgs(arguments);
        if (picocli.CommandLine.printHelpIfRequested(parseResult)) {
            printExtraUsageExamples();
            System.exit(1);
        } else {
            hopServer.run();
            // If we exit now it's because the server was stopped and this is not an error
            // 
            System.exit(0);
        }
    } catch (picocli.CommandLine.ParameterException e) {
        System.err.println(e.getMessage());
        hopServer.cmd.usage(System.err);
        printExtraUsageExamples();
        System.exit(9);
    } catch (picocli.CommandLine.ExecutionException e) {
        System.err.println("Error found during execution!");
        System.err.println(Const.getStackTracker(e));
        System.exit(1);
    } catch (Exception e) {
        System.err.println("General error found, something went horribly wrong!");
        System.err.println(Const.getStackTracker(e));
        System.exit(2);
    }
}
Also used : JarCache(org.apache.hop.core.plugins.JarCache) StringUtils(org.apache.commons.lang.StringUtils) Utils(org.apache.hop.core.util.Utils) Parameters(picocli.CommandLine.Parameters) IVariables(org.apache.hop.core.variables.IVariables) XmlHandler(org.apache.hop.core.xml.XmlHandler) Date(java.util.Date) HopException(org.apache.hop.core.exception.HopException) Encr(org.apache.hop.core.encryption.Encr) Variables(org.apache.hop.core.variables.Variables) TransformStatus(org.apache.hop.pipeline.transform.TransformStatus) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) HopClientEnvironment(org.apache.hop.core.HopClientEnvironment) IConfigOptions(org.apache.hop.core.config.plugin.IConfigOptions) JSONConfiguration(com.sun.jersey.api.json.JSONConfiguration) Document(org.w3c.dom.Document) Node(org.w3c.dom.Node) Map(java.util.Map) WebResource(com.sun.jersey.api.client.WebResource) ExtensionPointHandler(org.apache.hop.core.extension.ExtensionPointHandler) CommandLine(picocli.CommandLine) HopEnvironment(org.apache.hop.core.HopEnvironment) HopMetadataUtil(org.apache.hop.metadata.util.HopMetadataUtil) HopVfs(org.apache.hop.core.vfs.HopVfs) ConfigPlugin(org.apache.hop.core.config.plugin.ConfigPlugin) ILogChannel(org.apache.hop.core.logging.ILogChannel) BaseMessages(org.apache.hop.i18n.BaseMessages) MultiMetadataProvider(org.apache.hop.metadata.serializer.multi.MultiMetadataProvider) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) ConfigPluginType(org.apache.hop.core.config.plugin.ConfigPluginType) FileObject(org.apache.commons.vfs2.FileObject) Const(org.apache.hop.core.Const) JsonMetadataProvider(org.apache.hop.metadata.serializer.json.JsonMetadataProvider) IHasHopMetadataProvider(org.apache.hop.metadata.api.IHasHopMetadataProvider) LogChannel(org.apache.hop.core.logging.LogChannel) HTTPBasicAuthFilter(com.sun.jersey.api.client.filter.HTTPBasicAuthFilter) List(java.util.List) Stream(java.util.stream.Stream) Client(com.sun.jersey.api.client.Client) LogLevel(org.apache.hop.core.logging.LogLevel) Result(org.apache.hop.core.Result) PluginRegistry(org.apache.hop.core.plugins.PluginRegistry) VisibleForTesting(com.google.common.annotations.VisibleForTesting) HopExtensionPoint(org.apache.hop.core.extension.HopExtensionPoint) IPlugin(org.apache.hop.core.plugins.IPlugin) HopException(org.apache.hop.core.exception.HopException) IPlugin(org.apache.hop.core.plugins.IPlugin) CommandLine(picocli.CommandLine) IConfigOptions(org.apache.hop.core.config.plugin.IConfigOptions) CommandLine(picocli.CommandLine)

Example 5 with IConfigOptions

use of org.apache.hop.core.config.plugin.IConfigOptions in project hop by apache.

the class HopConfig method main.

public static void main(String[] args) {
    HopConfig hopConfig = new HopConfig();
    try {
        HopEnvironment.init();
        CommandLine cmd = new CommandLine(hopConfig);
        List<IPlugin> configPlugins = PluginRegistry.getInstance().getPlugins(ConfigPluginType.class);
        for (IPlugin configPlugin : configPlugins) {
            // Load only the plugins of the "config" category
            if (ConfigPlugin.CATEGORY_CONFIG.equals(configPlugin.getCategory())) {
                IConfigOptions configOptions = PluginRegistry.getInstance().loadClass(configPlugin, IConfigOptions.class);
                cmd.addMixin(configPlugin.getIds()[0], configOptions);
            }
        }
        hopConfig.setCmd(cmd);
        CommandLine.ParseResult parseResult = cmd.parseArgs(args);
        if (CommandLine.printHelpIfRequested(parseResult)) {
            System.exit(1);
        } else {
            hopConfig.run();
            System.exit(0);
        }
    } catch (ParameterException e) {
        System.err.println(e.getMessage());
        hopConfig.cmd.usage(System.err);
        e.getCommandLine().usage(System.err);
        System.exit(9);
    } catch (ExecutionException e) {
        System.err.println("Error found during execution!");
        System.err.println(Const.getStackTracker(e));
        System.exit(1);
    } catch (Exception e) {
        System.err.println("General error found, something went horribly wrong!");
        System.err.println(Const.getStackTracker(e));
        System.exit(2);
    }
}
Also used : CommandLine(picocli.CommandLine) IConfigOptions(org.apache.hop.core.config.plugin.IConfigOptions) ParameterException(picocli.CommandLine.ParameterException) ExecutionException(picocli.CommandLine.ExecutionException) HopException(org.apache.hop.core.exception.HopException) ParameterException(picocli.CommandLine.ParameterException) ExecutionException(picocli.CommandLine.ExecutionException) IPlugin(org.apache.hop.core.plugins.IPlugin)

Aggregations

IConfigOptions (org.apache.hop.core.config.plugin.IConfigOptions)10 HopException (org.apache.hop.core.exception.HopException)10 ExecutionException (picocli.CommandLine.ExecutionException)8 ParameterException (picocli.CommandLine.ParameterException)8 ILogChannel (org.apache.hop.core.logging.ILogChannel)6 LogChannel (org.apache.hop.core.logging.LogChannel)6 IPlugin (org.apache.hop.core.plugins.IPlugin)6 CommandLine (picocli.CommandLine)6 IOException (java.io.IOException)4 PluginRegistry (org.apache.hop.core.plugins.PluginRegistry)3 FileObject (org.apache.commons.vfs2.FileObject)2 HopPluginException (org.apache.hop.core.exception.HopPluginException)2 UnknownParamException (org.apache.hop.core.parameters.UnknownParamException)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Client (com.sun.jersey.api.client.Client)1 WebResource (com.sun.jersey.api.client.WebResource)1 ClientConfig (com.sun.jersey.api.client.config.ClientConfig)1 DefaultClientConfig (com.sun.jersey.api.client.config.DefaultClientConfig)1 HTTPBasicAuthFilter (com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)1 JSONConfiguration (com.sun.jersey.api.json.JSONConfiguration)1