use of org.apache.hop.core.logging.SimpleLoggingObject in project hop by apache.
the class AddExportServlet method doGet.
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (isJettyMode() && !request.getRequestURI().startsWith(CONTEXT_PATH)) {
return;
}
if (log.isDebug()) {
logDebug("Addition of export requested");
}
PrintWriter out = response.getWriter();
// read from the client
InputStream in = request.getInputStream();
if (log.isDetailed()) {
logDetailed("Encoding: " + request.getCharacterEncoding());
}
boolean isWorkflow = TYPE_WORKFLOW.equalsIgnoreCase(request.getParameter(PARAMETER_TYPE));
// the resource to load
String load = request.getParameter(PARAMETER_LOAD);
response.setContentType("text/xml");
out.print(XmlHandler.getXmlHeader());
response.setStatus(HttpServletResponse.SC_OK);
OutputStream outputStream = null;
try {
FileObject tempFile = HopVfs.createTempFile("export", ".zip", System.getProperty("java.io.tmpdir"));
outputStream = HopVfs.getOutputStream(tempFile, false);
// Pass the input directly to a temporary file
//
int c;
while ((c = in.read()) != -1) {
outputStream.write(c);
}
outputStream.flush();
outputStream.close();
// don't close it twice
outputStream = null;
String archiveUrl = tempFile.getName().toString();
String fileUrl = null;
String serverObjectId = null;
SimpleLoggingObject servletLoggingObject = new SimpleLoggingObject(CONTEXT_PATH, LoggingObjectType.HOP_SERVER, null);
//
if (!Utils.isEmpty(load)) {
String metaStoreJson = RegisterPackageServlet.getMetaStoreJsonFromZIP("zip:" + archiveUrl + "!metadata.json");
SerializableMetadataProvider metadataProvider = new SerializableMetadataProvider(metaStoreJson);
fileUrl = "zip:" + archiveUrl + "!" + load;
if (isWorkflow) {
// Open the workflow from inside the ZIP archive
//
HopVfs.getFileObject(fileUrl);
WorkflowMeta workflowMeta = new WorkflowMeta(fileUrl);
// Also read the execution configuration information
//
String configUrl = "zip:" + archiveUrl + "!" + Workflow.CONFIGURATION_IN_EXPORT_FILENAME;
Document configDoc = XmlHandler.loadXmlFile(configUrl);
WorkflowExecutionConfiguration workflowExecutionConfiguration = new WorkflowExecutionConfiguration(XmlHandler.getSubNode(configDoc, WorkflowExecutionConfiguration.XML_TAG));
serverObjectId = UUID.randomUUID().toString();
servletLoggingObject.setContainerObjectId(serverObjectId);
servletLoggingObject.setLogLevel(workflowExecutionConfiguration.getLogLevel());
String runConfigurationName = workflowExecutionConfiguration.getRunConfiguration();
// Inflate the metadata and simply store it into the workflow metadata
//
workflowMeta.setMetadataProvider(metadataProvider);
final IWorkflowEngine<WorkflowMeta> workflow = WorkflowEngineFactory.createWorkflowEngine(variables, runConfigurationName, metadataProvider, workflowMeta, servletLoggingObject);
// store it all in the map...
//
getWorkflowMap().addWorkflow(workflow.getWorkflowName(), serverObjectId, workflow, new WorkflowConfiguration(workflowMeta, workflowExecutionConfiguration, metadataProvider));
// Apply the execution configuration...
//
log.setLogLevel(workflowExecutionConfiguration.getLogLevel());
} else {
// Read the execution configuration information
//
String configUrl = "zip:" + archiveUrl + "!" + Pipeline.CONFIGURATION_IN_EXPORT_FILENAME;
Document configDoc = XmlHandler.loadXmlFile(configUrl);
PipelineExecutionConfiguration executionConfiguration = new PipelineExecutionConfiguration(XmlHandler.getSubNode(configDoc, PipelineExecutionConfiguration.XML_TAG));
// Open the pipeline from inside the ZIP archive
//
PipelineMeta pipelineMeta = new PipelineMeta(fileUrl, metadataProvider, true, Variables.getADefaultVariableSpace());
serverObjectId = UUID.randomUUID().toString();
servletLoggingObject.setContainerObjectId(serverObjectId);
servletLoggingObject.setLogLevel(executionConfiguration.getLogLevel());
String runConfigurationName = executionConfiguration.getRunConfiguration();
IPipelineEngine<PipelineMeta> pipeline = PipelineEngineFactory.createPipelineEngine(variables, runConfigurationName, metadataProvider, pipelineMeta);
pipeline.setParent(servletLoggingObject);
// store it all in the map...
//
getPipelineMap().addPipeline(pipeline.getPipelineMeta().getName(), serverObjectId, pipeline, new PipelineConfiguration(pipelineMeta, executionConfiguration, metadataProvider));
}
} else {
fileUrl = archiveUrl;
}
out.println(new WebResult(WebResult.STRING_OK, fileUrl, serverObjectId));
} catch (Exception ex) {
out.println(new WebResult(WebResult.STRING_ERROR, Const.getStackTracker(ex)));
} finally {
if (outputStream != null) {
outputStream.close();
}
}
}
use of org.apache.hop.core.logging.SimpleLoggingObject in project hop by apache.
the class AddPipelineServlet method doGet.
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (isJettyMode() && !request.getRequestURI().startsWith(CONTEXT_PATH)) {
return;
}
if (log.isDebug()) {
logDebug("Addition of pipeline requested");
}
boolean useXML = "Y".equalsIgnoreCase(request.getParameter("xml"));
PrintWriter out = response.getWriter();
BufferedReader in = request.getReader();
if (log.isDetailed()) {
logDetailed("Encoding: " + request.getCharacterEncoding());
}
if (useXML) {
response.setContentType("text/xml");
out.print(XmlHandler.getXmlHeader());
} else {
response.setContentType("text/html");
out.println("<HTML>");
out.println("<HEAD><TITLE>Add pipeline</TITLE></HEAD>");
out.println("<BODY>");
}
response.setStatus(HttpServletResponse.SC_OK);
String realLogFilename = null;
PipelineExecutionConfiguration pipelineExecutionConfiguration = null;
try {
// First read the complete pipeline in memory from the request
//
StringBuilder xml = new StringBuilder(request.getContentLength());
int c;
while ((c = in.read()) != -1) {
xml.append((char) c);
}
// Parse the XML, create a pipeline configuration
//
PipelineConfiguration pipelineConfiguration = PipelineConfiguration.fromXml(xml.toString());
PipelineMeta pipelineMeta = pipelineConfiguration.getPipelineMeta();
pipelineExecutionConfiguration = pipelineConfiguration.getPipelineExecutionConfiguration();
if (log.isDetailed()) {
logDetailed("Logging level set to " + log.getLogLevel().getDescription());
}
String serverObjectId = UUID.randomUUID().toString();
SimpleLoggingObject servletLoggingObject = new SimpleLoggingObject(CONTEXT_PATH, LoggingObjectType.HOP_SERVER, null);
servletLoggingObject.setContainerObjectId(serverObjectId);
servletLoggingObject.setLogLevel(pipelineExecutionConfiguration.getLogLevel());
IHopMetadataProvider metadataProvider = new MultiMetadataProvider(variables, getServerConfig().getMetadataProvider(), pipelineConfiguration.getMetadataProvider());
String runConfigurationName = pipelineExecutionConfiguration.getRunConfiguration();
final IPipelineEngine<PipelineMeta> pipeline = PipelineEngineFactory.createPipelineEngine(variables, runConfigurationName, metadataProvider, pipelineMeta);
pipeline.setParent(servletLoggingObject);
if (pipelineExecutionConfiguration.isSetLogfile()) {
realLogFilename = pipelineExecutionConfiguration.getLogFileName();
final LogChannelFileWriter logChannelFileWriter;
try {
FileUtil.createParentFolder(AddPipelineServlet.class, realLogFilename, pipelineExecutionConfiguration.isCreateParentFolder(), pipeline.getLogChannel());
logChannelFileWriter = new LogChannelFileWriter(servletLoggingObject.getLogChannelId(), HopVfs.getFileObject(realLogFilename), pipelineExecutionConfiguration.isSetAppendLogfile());
logChannelFileWriter.startLogging();
pipeline.addExecutionFinishedListener(pipelineEngine -> {
if (logChannelFileWriter != null) {
logChannelFileWriter.stopLogging();
}
});
} catch (HopException e) {
logError(Const.getStackTracker(e));
}
}
getPipelineMap().addPipeline(pipelineMeta.getName(), serverObjectId, pipeline, pipelineConfiguration);
pipeline.setContainerId(serverObjectId);
String message = "Pipeline '" + pipeline.getPipelineMeta().getName() + "' was added to HopServer with id " + serverObjectId;
if (useXML) {
// Return the log channel id as well
//
out.println(new WebResult(WebResult.STRING_OK, message, serverObjectId));
} else {
out.println("<H1>" + message + "</H1>");
out.println("<p><a href=\"" + convertContextPath(GetPipelineStatusServlet.CONTEXT_PATH) + "?name=" + pipeline.getPipelineMeta().getName() + "&id=" + serverObjectId + "\">Go to the pipeline status page</a><p>");
}
} catch (Exception ex) {
if (useXML) {
out.println(new WebResult(WebResult.STRING_ERROR, Const.getStackTracker(ex)));
} else {
out.println("<p>");
out.println("<pre>");
ex.printStackTrace(out);
out.println("</pre>");
}
}
if (!useXML) {
out.println("<p>");
out.println("</BODY>");
out.println("</HTML>");
}
}
use of org.apache.hop.core.logging.SimpleLoggingObject in project hop by apache.
the class AddWorkflowServlet method doGet.
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (isJettyMode() && !request.getRequestURI().startsWith(CONTEXT_PATH)) {
return;
}
if (log.isDebug()) {
logDebug("Addition of workflow requested");
}
boolean useXML = "Y".equalsIgnoreCase(request.getParameter("xml"));
PrintWriter out = response.getWriter();
// read from the client
BufferedReader in = request.getReader();
if (log.isDetailed()) {
logDetailed("Encoding: " + request.getCharacterEncoding());
}
if (useXML) {
response.setContentType("text/xml");
out.print(XmlHandler.getXmlHeader());
} else {
response.setContentType("text/html");
out.println("<HTML>");
out.println("<HEAD><TITLE>Add workflow</TITLE></HEAD>");
out.println("<BODY>");
}
response.setStatus(HttpServletResponse.SC_OK);
try {
// First read the complete pipeline in memory from the request
int c;
StringBuilder xml = new StringBuilder();
while ((c = in.read()) != -1) {
xml.append((char) c);
}
// Parse the XML, create a workflow configuration
//
WorkflowConfiguration workflowConfiguration = WorkflowConfiguration.fromXml(xml.toString(), variables);
IHopMetadataProvider metadataProvider = new MultiMetadataProvider(variables, getServerConfig().getMetadataProvider(), workflowConfiguration.getMetadataProvider());
WorkflowMeta workflowMeta = workflowConfiguration.getWorkflowMeta();
WorkflowExecutionConfiguration workflowExecutionConfiguration = workflowConfiguration.getWorkflowExecutionConfiguration();
String serverObjectId = UUID.randomUUID().toString();
SimpleLoggingObject servletLoggingObject = new SimpleLoggingObject(CONTEXT_PATH, LoggingObjectType.HOP_SERVER, null);
servletLoggingObject.setContainerObjectId(serverObjectId);
servletLoggingObject.setLogLevel(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().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);
// 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);
String message = "Workflow '" + workflow.getWorkflowName() + "' was added to the list with id " + serverObjectId;
if (useXML) {
out.println(new WebResult(WebResult.STRING_OK, message, serverObjectId));
} else {
out.println("<H1>" + message + "</H1>");
out.println("<p><a href=\"" + convertContextPath(GetWorkflowStatusServlet.CONTEXT_PATH) + "?name=" + workflow.getWorkflowName() + "&id=" + serverObjectId + "\">Go to the workflow status page</a><p>");
}
} catch (Exception ex) {
if (useXML) {
out.println(new WebResult(WebResult.STRING_ERROR, Const.getStackTracker(ex)));
} else {
out.println("<p>");
out.println("<pre>");
ex.printStackTrace(out);
out.println("</pre>");
}
}
if (!useXML) {
out.println("<p>");
out.println("</BODY>");
out.println("</HTML>");
}
}
use of org.apache.hop.core.logging.SimpleLoggingObject in project hop by apache.
the class BaseWorkflowServlet method getServletLogging.
private SimpleLoggingObject getServletLogging(final String serverObjectId, final LogLevel level) {
SimpleLoggingObject servletLoggingObject = new SimpleLoggingObject(getContextPath(), LoggingObjectType.HOP_SERVER, null);
servletLoggingObject.setContainerObjectId(serverObjectId);
servletLoggingObject.setLogLevel(level);
return servletLoggingObject;
}
use of org.apache.hop.core.logging.SimpleLoggingObject in project hop by apache.
the class WebServiceServlet method doGet.
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (isJettyMode() && !request.getContextPath().startsWith(CONTEXT_PATH)) {
return;
}
if (log.isDebug()) {
logDebug(BaseMessages.getString(PKG, "WebServiceServlet.Log.WebServiceRequested"));
}
IVariables variables = pipelineMap.getHopServerConfig().getVariables();
IHopMetadataProvider metadataProvider = pipelineMap.getHopServerConfig().getMetadataProvider();
String webServiceName = request.getParameter("service");
if (StringUtils.isEmpty(webServiceName)) {
throw new ServletException("Please specify a service parameter pointing to the name of the web service object");
}
try {
IHopMetadataSerializer<WebService> serializer = metadataProvider.getSerializer(WebService.class);
WebService webService = serializer.load(webServiceName);
if (webService == null) {
throw new HopException("Unable to find web service '" + webServiceName + "'. You can set the metadata_folder in the Hop server XML configuration");
}
if (!webService.isEnabled()) {
throw new HopException("Web service '" + webServiceName + "' is disabled.");
}
String filename = variables.resolve(webService.getFilename());
String transformName = variables.resolve(webService.getTransformName());
String fieldName = variables.resolve(webService.getFieldName());
String contentType = variables.resolve(webService.getContentType());
if (StringUtils.isEmpty(contentType)) {
response.setContentType("text/plain");
} else {
response.setContentType(contentType);
}
response.setCharacterEncoding(Const.XML_ENCODING);
String serverObjectId = UUID.randomUUID().toString();
SimpleLoggingObject servletLoggingObject = new SimpleLoggingObject(CONTEXT_PATH, LoggingObjectType.HOP_SERVER, null);
servletLoggingObject.setContainerObjectId(serverObjectId);
// Load and start the pipeline
// Output the data to the response output stream...
//
PipelineMeta pipelineMeta = new PipelineMeta(filename, metadataProvider, true, variables);
LocalPipelineEngine pipeline = new LocalPipelineEngine(pipelineMeta, variables, servletLoggingObject);
pipeline.setContainerId(serverObjectId);
// Set all the other parameters as variables/parameters...
//
String[] pipelineParameters = pipelineMeta.listParameters();
pipeline.copyParametersFromDefinitions(pipelineMeta);
for (String requestParameter : request.getParameterMap().keySet()) {
if ("service".equals(requestParameter)) {
continue;
}
String requestParameterValue = request.getParameter(requestParameter);
if (Const.indexOfString(requestParameter, pipelineParameters) < 0) {
pipeline.setVariable(requestParameter, Const.NVL(requestParameterValue, ""));
} else {
pipeline.setParameterValue(requestParameter, Const.NVL(requestParameterValue, ""));
}
}
pipeline.activateParameters(pipeline);
//
if (webService.isListingStatus()) {
PipelineExecutionConfiguration pipelineExecutionConfiguration = new PipelineExecutionConfiguration();
PipelineConfiguration pipelineConfiguration = new PipelineConfiguration(pipelineMeta, pipelineExecutionConfiguration, new SerializableMetadataProvider(metadataProvider));
getPipelineMap().addPipeline(pipelineMeta.getName(), serverObjectId, pipeline, pipelineConfiguration);
}
// Allocate the threads...
pipeline.prepareExecution();
final OutputStream outputStream = response.getOutputStream();
// Add the row listener to the transform/field...
// TODO: add to all copies
//
IEngineComponent component = pipeline.findComponent(transformName, 0);
component.addRowListener(new RowAdapter() {
@Override
public void rowWrittenEvent(IRowMeta rowMeta, Object[] row) throws HopTransformException {
try {
String outputString = rowMeta.getString(row, fieldName, "");
outputStream.write(outputString.getBytes(StandardCharsets.UTF_8));
outputStream.flush();
} catch (HopValueException e) {
throw new HopTransformException("Error getting output field '" + fieldName + " from row: " + rowMeta.toStringMeta(), e);
} catch (IOException e) {
throw new HopTransformException("Error writing output of '" + fieldName + "'", e);
}
}
});
pipeline.startThreads();
pipeline.waitUntilFinished();
response.setStatus(HttpServletResponse.SC_OK);
} catch (Exception e) {
throw new ServletException("Error producing web service output", e);
}
}
Aggregations