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;
}
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;
}
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);
}
Aggregations