Search in sources :

Example 6 with WorkflowExecutionConfiguration

use of org.apache.hop.workflow.WorkflowExecutionConfiguration in project hop by apache.

the class BaseWorkflowServlet method createWorkflow.

protected IWorkflowEngine<WorkflowMeta> createWorkflow(WorkflowConfiguration workflowConfiguration) throws HopException, HopException, ParseException {
    WorkflowExecutionConfiguration workflowExecutionConfiguration = workflowConfiguration.getWorkflowExecutionConfiguration();
    IHopMetadataProvider metadataProvider = new MultiMetadataProvider(variables, getServerConfig().getMetadataProvider(), workflowConfiguration.getMetadataProvider());
    WorkflowMeta workflowMeta = workflowConfiguration.getWorkflowMeta();
    String serverObjectId = UUID.randomUUID().toString();
    SimpleLoggingObject servletLoggingObject = getServletLogging(serverObjectId, workflowExecutionConfiguration.getLogLevel());
    // Create the workflow and store in the list...
    // 
    String runConfigurationName = workflowExecutionConfiguration.getRunConfiguration();
    final IWorkflowEngine<WorkflowMeta> workflow = WorkflowEngineFactory.createWorkflowEngine(variables, runConfigurationName, metadataProvider, workflowMeta, servletLoggingObject);
    // Setting variables
    workflow.initializeFrom(null);
    workflow.getWorkflowMeta().setMetadataProvider(metadataProvider);
    workflow.getWorkflowMeta().setInternalHopVariables(workflow);
    workflow.setVariables(workflowConfiguration.getWorkflowExecutionConfiguration().getVariablesMap());
    copyWorkflowParameters(workflow, workflowExecutionConfiguration.getParametersMap());
    // Check if there is a starting point specified.
    String startActionName = workflowExecutionConfiguration.getStartActionName();
    if (startActionName != null && !startActionName.isEmpty()) {
        ActionMeta startActionMeta = workflowMeta.findAction(startActionName);
        workflow.setStartActionMeta(startActionMeta);
    }
    getWorkflowMap().addWorkflow(workflow.getWorkflowName(), serverObjectId, workflow, workflowConfiguration);
    // Remember the generated container ID
    // 
    workflow.setContainerId(serverObjectId);
    return workflow;
}
Also used : ActionMeta(org.apache.hop.workflow.action.ActionMeta) IHopMetadataProvider(org.apache.hop.metadata.api.IHopMetadataProvider) SimpleLoggingObject(org.apache.hop.core.logging.SimpleLoggingObject) WorkflowExecutionConfiguration(org.apache.hop.workflow.WorkflowExecutionConfiguration) MultiMetadataProvider(org.apache.hop.metadata.serializer.multi.MultiMetadataProvider) WorkflowMeta(org.apache.hop.workflow.WorkflowMeta)

Example 7 with WorkflowExecutionConfiguration

use of org.apache.hop.workflow.WorkflowExecutionConfiguration in project hop by apache.

the class RegisterPackageServlet method generateBody.

@Override
WebResult generateBody(HttpServletRequest request, HttpServletResponse response, boolean useXML, IVariables variables) throws HopException, IOException, HopException, ParseException {
    FileObject tempFile = HopVfs.createTempFile("export", ".zip", System.getProperty("java.io.tmpdir"));
    OutputStream out = HopVfs.getOutputStream(tempFile, false);
    IOUtils.copy(request.getInputStream(), out);
    out.flush();
    IOUtils.closeQuietly(out);
    String archiveUrl = tempFile.getName().toString();
    // the resource to load
    String load = request.getParameter(PARAMETER_LOAD);
    if (!Utils.isEmpty(load)) {
        String fileUrl = MessageFormat.format(ZIP_CONT, archiveUrl, load);
        boolean isWorkflow = TYPE_WORKFLOW.equalsIgnoreCase(request.getParameter(PARAMETER_TYPE));
        String resultId;
        String metaStoreJson = getMetaStoreJsonFromZIP(archiveUrl);
        SerializableMetadataProvider metadataProvider = new SerializableMetadataProvider(metaStoreJson);
        if (isWorkflow) {
            Node node = getConfigNodeFromZIP(archiveUrl, Workflow.CONFIGURATION_IN_EXPORT_FILENAME, WorkflowExecutionConfiguration.XML_TAG);
            WorkflowExecutionConfiguration workflowExecutionConfiguration = new WorkflowExecutionConfiguration(node);
            WorkflowMeta workflowMeta = new WorkflowMeta(fileUrl);
            WorkflowConfiguration workflowConfiguration = new WorkflowConfiguration(workflowMeta, workflowExecutionConfiguration, metadataProvider);
            IWorkflowEngine<WorkflowMeta> workflow = createWorkflow(workflowConfiguration);
            resultId = workflow.getContainerId();
        } else {
            Node node = getConfigNodeFromZIP(archiveUrl, Pipeline.CONFIGURATION_IN_EXPORT_FILENAME, PipelineExecutionConfiguration.XML_TAG);
            PipelineExecutionConfiguration pipelineExecutionConfiguration = new PipelineExecutionConfiguration(node);
            PipelineMeta pipelineMeta = new PipelineMeta(fileUrl, metadataProvider, true, Variables.getADefaultVariableSpace());
            PipelineConfiguration pipelineConfiguration = new PipelineConfiguration(pipelineMeta, pipelineExecutionConfiguration, metadataProvider);
            IPipelineEngine<PipelineMeta> pipeline = createPipeline(pipelineConfiguration);
            resultId = pipeline.getContainerId();
        }
        return new WebResult(WebResult.STRING_OK, fileUrl, resultId);
    }
    return null;
}
Also used : OutputStream(java.io.OutputStream) Node(org.w3c.dom.Node) PipelineConfiguration(org.apache.hop.pipeline.PipelineConfiguration) WorkflowExecutionConfiguration(org.apache.hop.workflow.WorkflowExecutionConfiguration) WorkflowMeta(org.apache.hop.workflow.WorkflowMeta) PipelineMeta(org.apache.hop.pipeline.PipelineMeta) WorkflowConfiguration(org.apache.hop.workflow.WorkflowConfiguration) SerializableMetadataProvider(org.apache.hop.core.metadata.SerializableMetadataProvider) FileObject(org.apache.commons.vfs2.FileObject) PipelineExecutionConfiguration(org.apache.hop.pipeline.PipelineExecutionConfiguration)

Example 8 with WorkflowExecutionConfiguration

use of org.apache.hop.workflow.WorkflowExecutionConfiguration in project hop by apache.

the class WorkflowResource method addJob.

@PUT
@Path("/add")
@Produces({ MediaType.APPLICATION_JSON })
public WorkflowStatus addJob(String xml) {
    // Parse the XML, create a workflow configuration
    // 
    WorkflowConfiguration workflowConfiguration;
    try {
        // TODO
        IVariables variables = Variables.getADefaultVariableSpace();
        workflowConfiguration = WorkflowConfiguration.fromXml(xml, variables);
        IHopMetadataProvider metadataProvider = new MultiMetadataProvider(variables, HopServerSingleton.getHopServer().getMetadataProvider(), workflowConfiguration.getMetadataProvider());
        WorkflowMeta workflowMeta = workflowConfiguration.getWorkflowMeta();
        WorkflowExecutionConfiguration workflowExecutionConfiguration = workflowConfiguration.getWorkflowExecutionConfiguration();
        String serverObjectId = UUID.randomUUID().toString();
        SimpleLoggingObject servletLoggingObject = new SimpleLoggingObject(getClass().getName(), LoggingObjectType.HOP_SERVER, null);
        servletLoggingObject.setContainerObjectId(serverObjectId);
        servletLoggingObject.setLogLevel(workflowExecutionConfiguration.getLogLevel());
        // Create the workflow and store in the list...
        // 
        String runConfigurationName = workflowConfiguration.getWorkflowExecutionConfiguration().getRunConfiguration();
        final IWorkflowEngine<WorkflowMeta> workflow = WorkflowEngineFactory.createWorkflowEngine(variables, runConfigurationName, metadataProvider, workflowMeta, servletLoggingObject);
        // Setting variables
        // 
        workflow.initializeFrom(null);
        workflow.getWorkflowMeta().setInternalHopVariables(workflow);
        workflow.setVariables(workflowConfiguration.getWorkflowExecutionConfiguration().getVariablesMap());
        // Also copy the parameters over...
        // 
        workflow.copyParametersFromDefinitions(workflowMeta);
        workflow.clearParameterValues();
        String[] parameterNames = workflow.listParameters();
        for (int idx = 0; idx < parameterNames.length; idx++) {
            // Grab the parameter value set in the action
            // 
            String thisValue = workflowExecutionConfiguration.getParametersMap().get(parameterNames[idx]);
            if (!Utils.isEmpty(thisValue)) {
                // Set the value as specified by the user in the action
                // 
                workflow.setParameterValue(parameterNames[idx], thisValue);
            }
        }
        workflow.activateParameters(workflow);
        HopServerSingleton.getInstance().getWorkflowMap().addWorkflow(workflow.getWorkflowName(), serverObjectId, workflow, workflowConfiguration);
        return getWorkflowStatus(serverObjectId);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : WorkflowConfiguration(org.apache.hop.workflow.WorkflowConfiguration) IVariables(org.apache.hop.core.variables.IVariables) IHopMetadataProvider(org.apache.hop.metadata.api.IHopMetadataProvider) SimpleLoggingObject(org.apache.hop.core.logging.SimpleLoggingObject) WorkflowExecutionConfiguration(org.apache.hop.workflow.WorkflowExecutionConfiguration) MultiMetadataProvider(org.apache.hop.metadata.serializer.multi.MultiMetadataProvider) WorkflowMeta(org.apache.hop.workflow.WorkflowMeta)

Aggregations

WorkflowExecutionConfiguration (org.apache.hop.workflow.WorkflowExecutionConfiguration)8 WorkflowMeta (org.apache.hop.workflow.WorkflowMeta)7 SimpleLoggingObject (org.apache.hop.core.logging.SimpleLoggingObject)5 WorkflowConfiguration (org.apache.hop.workflow.WorkflowConfiguration)5 IOException (java.io.IOException)4 MultiMetadataProvider (org.apache.hop.metadata.serializer.multi.MultiMetadataProvider)4 OutputStream (java.io.OutputStream)3 SerializableMetadataProvider (org.apache.hop.core.metadata.SerializableMetadataProvider)3 IHopMetadataProvider (org.apache.hop.metadata.api.IHopMetadataProvider)3 InputStream (java.io.InputStream)2 PrintWriter (java.io.PrintWriter)2 ServletException (javax.servlet.ServletException)2 FileObject (org.apache.commons.vfs2.FileObject)2 HopException (org.apache.hop.core.exception.HopException)2 UnknownParamException (org.apache.hop.core.parameters.UnknownParamException)2 IVariables (org.apache.hop.core.variables.IVariables)2 PipelineConfiguration (org.apache.hop.pipeline.PipelineConfiguration)2 PipelineExecutionConfiguration (org.apache.hop.pipeline.PipelineExecutionConfiguration)2 PipelineMeta (org.apache.hop.pipeline.PipelineMeta)2 ActionMeta (org.apache.hop.workflow.action.ActionMeta)2