Search in sources :

Example 6 with WorkflowConfiguration

use of org.apache.hop.workflow.WorkflowConfiguration 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 7 with WorkflowConfiguration

use of org.apache.hop.workflow.WorkflowConfiguration 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)

Example 8 with WorkflowConfiguration

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

the class WorkflowResource method startJob.

// change from GET to UPDATE/POST for proper REST method
@GET
@Path("/start/{id : .+}")
@Produces({ MediaType.APPLICATION_JSON })
public WorkflowStatus startJob(@PathParam("id") String id) {
    IWorkflowEngine<WorkflowMeta> workflow = HopServerResource.getWorkflow(id);
    HopServerObjectEntry entry = HopServerResource.getHopServerObjectEntry(id);
    if (workflow.isInitialized() && !workflow.isActive()) {
        // 
        synchronized (this) {
            WorkflowConfiguration workflowConfiguration = HopServerSingleton.getInstance().getWorkflowMap().getConfiguration(entry);
            IHopMetadataProvider metadataProvider = new MultiMetadataProvider(HopServerSingleton.getHopServerConfig().getVariables(), HopServerSingleton.getHopServer().getMetadataProvider(), workflowConfiguration.getMetadataProvider());
            String serverObjectId = UUID.randomUUID().toString();
            SimpleLoggingObject servletLoggingObject = new SimpleLoggingObject(getClass().getName(), LoggingObjectType.HOP_SERVER, null);
            servletLoggingObject.setContainerObjectId(serverObjectId);
            String runConfigurationName = workflowConfiguration.getWorkflowExecutionConfiguration().getRunConfiguration();
            try {
                IVariables variables = Variables.getADefaultVariableSpace();
                IWorkflowEngine<WorkflowMeta> newWorkflow = WorkflowEngineFactory.createWorkflowEngine(variables, runConfigurationName, metadataProvider, workflow.getWorkflowMeta(), servletLoggingObject);
                newWorkflow.setLogLevel(workflow.getLogLevel());
                // Discard old log lines from the old workflow
                // 
                HopLogStore.discardLines(workflow.getLogChannelId(), true);
                HopServerSingleton.getInstance().getWorkflowMap().replaceWorkflow(workflow, newWorkflow, workflowConfiguration);
                workflow = newWorkflow;
            } catch (Exception e) {
                throw new RuntimeException("Unable to instantiate new workflow", e);
            }
        }
    }
    final IWorkflowEngine<WorkflowMeta> finalWorkflow = workflow;
    // Simply start the workflow in the background in a new thread.
    // This will allow us to work asynchronously
    // 
    new Thread(() -> finalWorkflow.startExecution()).start();
    return getWorkflowStatus(id);
}
Also used : WorkflowConfiguration(org.apache.hop.workflow.WorkflowConfiguration) IVariables(org.apache.hop.core.variables.IVariables) IHopMetadataProvider(org.apache.hop.metadata.api.IHopMetadataProvider) HopServerObjectEntry(org.apache.hop.www.HopServerObjectEntry) SimpleLoggingObject(org.apache.hop.core.logging.SimpleLoggingObject) WorkflowMeta(org.apache.hop.workflow.WorkflowMeta) MultiMetadataProvider(org.apache.hop.metadata.serializer.multi.MultiMetadataProvider)

Aggregations

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