Search in sources :

Example 1 with WorkflowRunConfiguration

use of org.apache.hop.workflow.config.WorkflowRunConfiguration in project hop by apache.

the class WorkflowEngineFactory method createWorkflowEngine.

public static final <T extends WorkflowMeta> IWorkflowEngine<T> createWorkflowEngine(IVariables variables, String runConfigurationName, IHopMetadataProvider metadataProvider, T workflowMeta, ILoggingObject parentLogging) throws HopException {
    if (StringUtils.isEmpty(runConfigurationName)) {
        throw new HopException("You need to specify a workflow run configuration to execute this workflow");
    }
    WorkflowRunConfiguration runConfiguration;
    try {
        runConfiguration = metadataProvider.getSerializer(WorkflowRunConfiguration.class).load(runConfigurationName);
    } catch (Exception e) {
        throw new HopException("Error loading workflow run configuration '" + runConfigurationName + "'", e);
    }
    if (runConfiguration == null) {
        throw new HopException("Workflow run configuration '" + runConfigurationName + "' could not be found");
    }
    IWorkflowEngine<T> workflowEngine = createWorkflowEngine(runConfiguration, workflowMeta, parentLogging);
    // Copy the variables from the metadata
    // 
    workflowEngine.initializeFrom(variables);
    workflowEngine.setInternalHopVariables();
    // Copy the parameters from the metadata...
    // 
    workflowEngine.copyParametersFromDefinitions(workflowMeta);
    // Pass the metadata providers around to make sure
    // 
    workflowEngine.setMetadataProvider(metadataProvider);
    workflowMeta.setMetadataProvider(metadataProvider);
    return workflowEngine;
}
Also used : WorkflowRunConfiguration(org.apache.hop.workflow.config.WorkflowRunConfiguration) HopException(org.apache.hop.core.exception.HopException) HopException(org.apache.hop.core.exception.HopException)

Example 2 with WorkflowRunConfiguration

use of org.apache.hop.workflow.config.WorkflowRunConfiguration in project hop by apache.

the class ProjectsGuiPlugin method addNewProject.

@GuiToolbarElement(root = HopGui.ID_MAIN_TOOLBAR, id = ID_TOOLBAR_PROJECT_ADD, toolTip = "i18n::HopGui.Toolbar.Project.Add.Tooltip", image = "project-add.svg")
public void addNewProject() {
    HopGui hopGui = HopGui.getInstance();
    IVariables variables = hopGui.getVariables();
    try {
        ProjectsConfig config = ProjectsConfigSingleton.getConfig();
        String standardProjectsFolder = variables.resolve(config.getStandardProjectsFolder());
        String defaultProjectConfigFilename = variables.resolve(config.getDefaultProjectConfigFile());
        ProjectConfig projectConfig = new ProjectConfig("", standardProjectsFolder, defaultProjectConfigFilename);
        Project project = new Project();
        project.setParentProjectName(config.getStandardParentProject());
        ProjectDialog projectDialog = new ProjectDialog(hopGui.getShell(), project, projectConfig, variables, false);
        String projectName = projectDialog.open();
        if (projectName != null) {
            config.addProjectConfig(projectConfig);
            HopConfig.getInstance().saveToFile();
            // Save the project-config.json file as well in the project itself
            // 
            FileObject configFile = HopVfs.getFileObject(projectConfig.getActualProjectConfigFilename(variables));
            if (!configFile.exists()) {
                // Create the empty configuration file if it does not exists
                project.saveToFile();
            } else {
                // If projects exists load configuration
                MessageBox box = new MessageBox(hopGui.getShell(), SWT.ICON_QUESTION | SWT.OK);
                box.setText(BaseMessages.getString(PKG, "ProjectGuiPlugin.ProjectExists.Dialog.Header"));
                box.setMessage(BaseMessages.getString(PKG, "ProjectGuiPlugin.ProjectExists.Dialog.Message"));
                box.open();
                project.readFromFile();
            }
            refreshProjectsList();
            selectProjectInList(projectName);
            enableHopGuiProject(projectName, project, null);
            // Now see if these project contains any local run configurations.
            // If not we can add those automatically
            // 
            // First pipeline
            // 
            IHopMetadataSerializer<PipelineRunConfiguration> prcSerializer = hopGui.getMetadataProvider().getSerializer(PipelineRunConfiguration.class);
            List<PipelineRunConfiguration> pipelineRunConfigs = prcSerializer.loadAll();
            boolean localFound = false;
            for (PipelineRunConfiguration pipelineRunConfig : pipelineRunConfigs) {
                if (pipelineRunConfig.getEngineRunConfiguration() instanceof LocalPipelineRunConfiguration) {
                    localFound = true;
                }
            }
            if (!localFound) {
                PipelineExecutionConfigurationDialog.createLocalPipelineConfiguration(hopGui.getShell(), prcSerializer);
            }
            // Then the local workflow runconfig
            // 
            IHopMetadataSerializer<WorkflowRunConfiguration> wrcSerializer = hopGui.getMetadataProvider().getSerializer(WorkflowRunConfiguration.class);
            localFound = false;
            List<WorkflowRunConfiguration> workflowRunConfigs = wrcSerializer.loadAll();
            for (WorkflowRunConfiguration workflowRunConfig : workflowRunConfigs) {
                if (workflowRunConfig.getEngineRunConfiguration() instanceof LocalWorkflowRunConfiguration) {
                    localFound = true;
                }
            }
            if (!localFound) {
                MessageBox box = new MessageBox(HopGui.getInstance().getShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION);
                box.setText(BaseMessages.getString(PKG, "ProjectGuiPlugin.LocalWFRunConfig.Dialog.Header"));
                box.setMessage(BaseMessages.getString(PKG, "ProjectGuiPlugin.LocalWFRunConfig.Dialog.Message"));
                int anwser = box.open();
                if ((anwser & SWT.YES) != 0) {
                    LocalWorkflowRunConfiguration localWorkflowRunConfiguration = new LocalWorkflowRunConfiguration();
                    localWorkflowRunConfiguration.setEnginePluginId("Local");
                    WorkflowRunConfiguration local = new WorkflowRunConfiguration("local", BaseMessages.getString(PKG, "ProjectGuiPlugin.LocalWFRunConfigDescription.Text"), localWorkflowRunConfiguration);
                    wrcSerializer.save(local);
                }
            }
            // Ask to put the project in a lifecycle environment
            // 
            MessageBox box = new MessageBox(HopGui.getInstance().getShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION);
            box.setText(BaseMessages.getString(PKG, "ProjectGuiPlugin.Lifecycle.Dialog.Header"));
            box.setMessage(BaseMessages.getString(PKG, "ProjectGuiPlugin.Lifecycle.Dialog.Message1") + Const.CR + BaseMessages.getString(PKG, "ProjectGuiPlugin.Lifecycle.Dialog.Message2"));
            int anwser = box.open();
            if ((anwser & SWT.YES) != 0) {
                addNewEnvironment();
            }
        }
    } catch (Exception e) {
        new ErrorDialog(hopGui.getShell(), BaseMessages.getString(PKG, "ProjectGuiPlugin.AddProject.Error.Dialog.Header"), BaseMessages.getString(PKG, "ProjectGuiPlugin.AddProject.Error.Dialog.Message"), e);
    }
}
Also used : ProjectDialog(org.apache.hop.projects.project.ProjectDialog) LocalPipelineRunConfiguration(org.apache.hop.pipeline.engines.local.LocalPipelineRunConfiguration) PipelineRunConfiguration(org.apache.hop.pipeline.config.PipelineRunConfiguration) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) HopExtensionPoint(org.apache.hop.core.extension.HopExtensionPoint) HopException(org.apache.hop.core.exception.HopException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) MessageBox(org.eclipse.swt.widgets.MessageBox) LocalPipelineRunConfiguration(org.apache.hop.pipeline.engines.local.LocalPipelineRunConfiguration) ProjectConfig(org.apache.hop.projects.project.ProjectConfig) LocalWorkflowRunConfiguration(org.apache.hop.workflow.engines.local.LocalWorkflowRunConfiguration) Project(org.apache.hop.projects.project.Project) LocalWorkflowRunConfiguration(org.apache.hop.workflow.engines.local.LocalWorkflowRunConfiguration) WorkflowRunConfiguration(org.apache.hop.workflow.config.WorkflowRunConfiguration) IVariables(org.apache.hop.core.variables.IVariables) ProjectsConfig(org.apache.hop.projects.config.ProjectsConfig) FileObject(org.apache.commons.vfs2.FileObject) HopGui(org.apache.hop.ui.hopgui.HopGui) GuiToolbarElement(org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement)

Example 3 with WorkflowRunConfiguration

use of org.apache.hop.workflow.config.WorkflowRunConfiguration in project hop by apache.

the class ActionWorkflowGuiPlugin method copyAsActionToClipboard.

@GuiContextAction(id = "workflow-graph-workflow-copy-action", parentId = HopGuiWorkflowContext.CONTEXT_ID, type = GuiActionType.Modify, name = "Copy as workflow action", tooltip = "Copy this workflow as an action so you can paste it in another workflow", image = "ui/images/copy.svg", category = "Basic", categoryOrder = "1")
public void copyAsActionToClipboard(HopGuiWorkflowContext context) {
    WorkflowMeta workflowMeta = context.getWorkflowMeta();
    HopGuiWorkflowGraph workflowGraph = context.getWorkflowGraph();
    HopGui hopGui = workflowGraph.getHopGui();
    IVariables variables = workflowGraph.getVariables();
    ActionWorkflow actionWorkflow = new ActionWorkflow(workflowMeta.getName());
    HopGuiFileOpenedExtension ext = new HopGuiFileOpenedExtension(null, variables, workflowMeta.getFilename());
    // 
    try {
        ExtensionPointHandler.callExtensionPoint(LogChannel.UI, variables, HopGuiExtensionPoint.HopGuiFileOpenedDialog.id, ext);
    } catch (Exception xe) {
        LogChannel.UI.logError("Error handling extension point 'HopGuiFileOpenDialog'", xe);
    }
    actionWorkflow.setFileName(ext.filename);
    // 
    try {
        IHopMetadataProvider metadataProvider = workflowGraph.getHopGui().getMetadataProvider();
        IHopMetadataSerializer<WorkflowRunConfiguration> serializer = metadataProvider.getSerializer(WorkflowRunConfiguration.class);
        List<String> configNames = serializer.listObjectNames();
        if (!configNames.isEmpty()) {
            if (configNames.size() == 1) {
                actionWorkflow.setRunConfiguration(configNames.get(0));
            } else {
                EnterSelectionDialog dialog = new EnterSelectionDialog(workflowGraph.getShell(), configNames.toArray(new String[0]), "Select run configuration", "Select the workflow run configuration to use in the action:");
                String configName = dialog.open();
                if (configName != null) {
                    actionWorkflow.setRunConfiguration(configName);
                }
            }
        }
    } catch (Exception e) {
        new ErrorDialog(workflowGraph.getShell(), "Error", "Error selecting workflow run configurations", e);
    }
    ActionMeta actionMeta = new ActionMeta(actionWorkflow);
    StringBuilder xml = new StringBuilder(5000).append(XmlHandler.getXmlHeader());
    xml.append(XmlHandler.openTag(HopGuiWorkflowClipboardDelegate.XML_TAG_WORKFLOW_ACTIONS)).append(Const.CR);
    xml.append(XmlHandler.openTag(HopGuiWorkflowClipboardDelegate.XML_TAG_ACTIONS)).append(Const.CR);
    xml.append(actionMeta.getXml());
    xml.append(XmlHandler.closeTag(HopGuiWorkflowClipboardDelegate.XML_TAG_ACTIONS)).append(Const.CR);
    xml.append(XmlHandler.closeTag(HopGuiWorkflowClipboardDelegate.XML_TAG_WORKFLOW_ACTIONS)).append(Const.CR);
    workflowGraph.workflowClipboardDelegate.toClipboard(xml.toString());
}
Also used : ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) WorkflowMeta(org.apache.hop.workflow.WorkflowMeta) WorkflowRunConfiguration(org.apache.hop.workflow.config.WorkflowRunConfiguration) HopGuiWorkflowGraph(org.apache.hop.ui.hopgui.file.workflow.HopGuiWorkflowGraph) ActionMeta(org.apache.hop.workflow.action.ActionMeta) IVariables(org.apache.hop.core.variables.IVariables) IHopMetadataProvider(org.apache.hop.metadata.api.IHopMetadataProvider) HopGuiFileOpenedExtension(org.apache.hop.ui.hopgui.delegates.HopGuiFileOpenedExtension) EnterSelectionDialog(org.apache.hop.ui.core.dialog.EnterSelectionDialog) HopGui(org.apache.hop.ui.hopgui.HopGui) GuiContextAction(org.apache.hop.core.action.GuiContextAction)

Example 4 with WorkflowRunConfiguration

use of org.apache.hop.workflow.config.WorkflowRunConfiguration in project hop by apache.

the class WorkflowExecutionConfigurationDialog method getInfo.

@Override
public boolean getInfo() {
    try {
        IHopMetadataSerializer<WorkflowRunConfiguration> serializer = hopGui.getMetadataProvider().getSerializer(WorkflowRunConfiguration.class);
        // 
        if (serializer.listObjectNames().isEmpty()) {
            String name = createLocalWorkflowConfiguration(shell, serializer);
            wRunConfiguration.setText(name);
        }
        String runConfigurationName = wRunConfiguration.getText();
        if (StringUtils.isEmpty(runConfigurationName)) {
            MessageBox box = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
            box.setText(BaseMessages.getString(PKG, "WorkflowExecutionConfigurationDialog.NoRunConfigurationSpecified.Title"));
            box.setMessage(BaseMessages.getString(PKG, "WorkflowExecutionConfigurationDialog.NoRunConfigurationSpecified.Message"));
            box.open();
            return false;
        }
        if (!serializer.exists(runConfigurationName)) {
            MessageBox box = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
            box.setText(BaseMessages.getString(PKG, "WorkflowExecutionConfigurationDialog.RunConfigurationDoesNotExist.Title"));
            box.setMessage(BaseMessages.getString(PKG, "WorkflowExecutionConfigurationDialog.RunConfigurationDoesNotExist.Message", runConfigurationName));
            box.open();
            return false;
        }
        getConfiguration().setRunConfiguration(runConfigurationName);
        AuditManagerGuiUtil.addLastUsedValue(AUDIT_LIST_TYPE_LAST_USED_RUN_CONFIGURATIONS, runConfigurationName);
        if (StringUtils.isNotEmpty(abstractMeta.getName())) {
            Map<String, String> usageMap = AuditManagerGuiUtil.getUsageMap(MAP_TYPE_WORKFLOW_RUN_CONFIG_USAGE);
            usageMap.put(abstractMeta.getName(), runConfigurationName);
            usageMap.put("LOG_LEVEL", String.valueOf(wLogLevel.getSelectionIndex()));
            AuditManagerGuiUtil.saveUsageMap(MAP_TYPE_WORKFLOW_RUN_CONFIG_USAGE, usageMap);
        }
        // various settings
        // 
        configuration.setClearingLog(wClearLog.getSelection());
        configuration.setLogLevel(LogLevel.values()[wLogLevel.getSelectionIndex()]);
        String startActionName = null;
        if (!Utils.isEmpty(wStartAction.getText()) && wStartAction.getSelectionIndex() >= 0) {
            ActionMeta action = ((WorkflowMeta) abstractMeta).getActions().get(wStartAction.getSelectionIndex());
            startActionName = action.getName();
        }
        getConfiguration().setStartActionName(startActionName);
        // The lower part of the dialog...
        getInfoParameters();
        getInfoVariables();
        return true;
    } catch (Exception e) {
        new ErrorDialog(shell, "Error in settings", "There is an error in the dialog settings", e);
    }
    return false;
}
Also used : LocalWorkflowRunConfiguration(org.apache.hop.workflow.engines.local.LocalWorkflowRunConfiguration) WorkflowRunConfiguration(org.apache.hop.workflow.config.WorkflowRunConfiguration) ActionMeta(org.apache.hop.workflow.action.ActionMeta) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) HopException(org.apache.hop.core.exception.HopException)

Example 5 with WorkflowRunConfiguration

use of org.apache.hop.workflow.config.WorkflowRunConfiguration in project hop by apache.

the class WorkflowExecutionConfigurationDialog method createLocalWorkflowConfiguration.

public static final String createLocalWorkflowConfiguration(Shell shell, IHopMetadataSerializer<WorkflowRunConfiguration> prcSerializer) {
    try {
        MessageBox box = new MessageBox(HopGui.getInstance().getShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION);
        box.setText(BaseMessages.getString(PKG, "WorkflowExecutionConfigurationDialog.NoRunConfigurationDefined.Title"));
        box.setMessage(BaseMessages.getString(PKG, "WorkflowExecutionConfigurationDialog.NoRunConfigurationDefined.Message"));
        int answer = box.open();
        if ((answer & SWT.YES) != 0) {
            LocalWorkflowRunConfiguration localWorkflowRunConfiguration = new LocalWorkflowRunConfiguration();
            localWorkflowRunConfiguration.setEnginePluginId("Local");
            WorkflowRunConfiguration local = new WorkflowRunConfiguration("local", BaseMessages.getString(PKG, "WorkflowExecutionConfigurationDialog.LocalRunConfiguration.Description"), localWorkflowRunConfiguration);
            prcSerializer.save(local);
            return local.getName();
        }
    } catch (Exception e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "WorkflowExecutionConfigurationDialog.ErrorSavingRunConfiguration.Title"), BaseMessages.getString(PKG, "WorkflowExecutionConfigurationDialog.ErrorSavingRunConfiguration.Message"), e);
    }
    return null;
}
Also used : LocalWorkflowRunConfiguration(org.apache.hop.workflow.engines.local.LocalWorkflowRunConfiguration) LocalWorkflowRunConfiguration(org.apache.hop.workflow.engines.local.LocalWorkflowRunConfiguration) WorkflowRunConfiguration(org.apache.hop.workflow.config.WorkflowRunConfiguration) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) HopExtensionPoint(org.apache.hop.core.extension.HopExtensionPoint) HopException(org.apache.hop.core.exception.HopException)

Aggregations

WorkflowRunConfiguration (org.apache.hop.workflow.config.WorkflowRunConfiguration)6 HopException (org.apache.hop.core.exception.HopException)4 ErrorDialog (org.apache.hop.ui.core.dialog.ErrorDialog)4 LocalWorkflowRunConfiguration (org.apache.hop.workflow.engines.local.LocalWorkflowRunConfiguration)3 HopExtensionPoint (org.apache.hop.core.extension.HopExtensionPoint)2 IVariables (org.apache.hop.core.variables.IVariables)2 HopGui (org.apache.hop.ui.hopgui.HopGui)2 ActionMeta (org.apache.hop.workflow.action.ActionMeta)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 FileObject (org.apache.commons.vfs2.FileObject)1 GuiContextAction (org.apache.hop.core.action.GuiContextAction)1 GuiToolbarElement (org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement)1 IHopMetadataProvider (org.apache.hop.metadata.api.IHopMetadataProvider)1 PipelineRunConfiguration (org.apache.hop.pipeline.config.PipelineRunConfiguration)1 LocalPipelineRunConfiguration (org.apache.hop.pipeline.engines.local.LocalPipelineRunConfiguration)1 ProjectsConfig (org.apache.hop.projects.config.ProjectsConfig)1 Project (org.apache.hop.projects.project.Project)1 ProjectConfig (org.apache.hop.projects.project.ProjectConfig)1