use of org.pentaho.di.trans.TransExecutionConfiguration in project pentaho-kettle by pentaho.
the class AddExportServlet method doGet.
/**
* <div id="mindtouch">
* <h1>/kettle/addExport</h1>
* <a name="POST"></a>
* <h2>POST</h2>
* <p>Returns the list of users in the platform. This list is in an xml format as shown in the example response.
* Uploads and executes previously exported job or transformation.
* Uploads zip file containing job or transformation to be executed and executes it.
* Method relies on the input parameters to find the entity to be executed. The archive is
* transferred within request body.
*
* <code>File url of the executed entity </code> will be returned in the Response object
* or <code>message</code> describing error occurred. To determine if the call is successful
* rely on <code>result</code> parameter in response.</p>
*
* <p><b>Example Request:</b><br />
* <pre function="syntax.xml">
* POST /kettle/addExport/?type=job&load=dummy_job.kjb
* </pre>
* Request body should contain zip file prepared for Carte execution.
* </p>
* <h3>Parameters</h3>
* <table class="pentaho-table">
* <tbody>
* <tr>
* <th>name</th>
* <th>description</th>
* <th>type</th>
* </tr>
* <tr>
* <td>type</td>
* <td>The type of the entity to be executed either <code>job</code> or <code>trans</code>.</td>
* <td>query</td>
* </tr>
* <tr>
* <td>load</td>
* <td>The name of the entity within archive to be executed.</td>
* <td>query</td>
* </tr>
* </tbody>
* </table>
*
* <h3>Response Body</h3>
*
* <table class="pentaho-table">
* <tbody>
* <tr>
* <td align="right">element:</td>
* <td>(custom)</td>
* </tr>
* <tr>
* <td align="right">media types:</td>
* <td>application/xml</td>
* </tr>
* </tbody>
* </table>
* <p>Response wraps file url of the entity that was executed or error stack trace if an error occurred.
* Response has <code>result</code> OK if there were no errors. Otherwise it returns ERROR.</p>
*
* <p><b>Example Response:</b></p>
* <pre function="syntax.xml">
* <?xml version="1.0" encoding="UTF-8"?>
* <webresult>
* <result>OK</result>
* <message>zip:file:///temp/export_ee2a67de-6a72-11e4-82c0-4701a2bac6a5.zip!dummy_job.kjb</message>
* <id>74cf4219-c881-4633-a71a-2ed16b7db7b8</id>
* </webresult>
* </pre>
*
* <h3>Status Codes</h3>
* <table class="pentaho-table">
* <tbody>
* <tr>
* <th>code</th>
* <th>description</th>
* </tr>
* <tr>
* <td>200</td>
* <td>Request was processed and XML response is returned.</td>
* </tr>
* <tr>
* <td>500</td>
* <td>Internal server error occurs during request processing.</td>
* </tr>
* </tbody>
*</table>
*</div>
*/
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 isJob = TYPE_JOB.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 = KettleVFS.createTempFile("export", ".zip", System.getProperty("java.io.tmpdir"));
outputStream = KettleVFS.getOutputStream(tempFile, false);
// Pass the input directly to a temporary file
//
// int size = 0;
int c;
while ((c = in.read()) != -1) {
outputStream.write(c);
// size++;
}
outputStream.flush();
outputStream.close();
// don't close it twice
outputStream = null;
String archiveUrl = tempFile.getName().toString();
String fileUrl = null;
String carteObjectId = null;
SimpleLoggingObject servletLoggingObject = new SimpleLoggingObject(CONTEXT_PATH, LoggingObjectType.CARTE, null);
//
if (!Utils.isEmpty(load)) {
fileUrl = "zip:" + archiveUrl + "!" + load;
if (isJob) {
// Open the job from inside the ZIP archive
//
KettleVFS.getFileObject(fileUrl);
// never with a repository
JobMeta jobMeta = new JobMeta(fileUrl, null);
// Also read the execution configuration information
//
String configUrl = "zip:" + archiveUrl + "!" + Job.CONFIGURATION_IN_EXPORT_FILENAME;
Document configDoc = XMLHandler.loadXMLFile(configUrl);
JobExecutionConfiguration jobExecutionConfiguration = new JobExecutionConfiguration(XMLHandler.getSubNode(configDoc, JobExecutionConfiguration.XML_TAG));
carteObjectId = UUID.randomUUID().toString();
servletLoggingObject.setContainerObjectId(carteObjectId);
servletLoggingObject.setLogLevel(jobExecutionConfiguration.getLogLevel());
Job job = new Job(null, jobMeta, servletLoggingObject);
//
if (jobExecutionConfiguration.isExpandingRemoteJob()) {
job.addDelegationListener(new CarteDelegationHandler(getTransformationMap(), getJobMap()));
}
// store it all in the map...
//
getJobMap().addJob(job.getJobname(), carteObjectId, job, new JobConfiguration(jobMeta, jobExecutionConfiguration));
// Apply the execution configuration...
//
log.setLogLevel(jobExecutionConfiguration.getLogLevel());
job.setArguments(jobExecutionConfiguration.getArgumentStrings());
jobMeta.injectVariables(jobExecutionConfiguration.getVariables());
// Also copy the parameters over...
//
Map<String, String> params = jobExecutionConfiguration.getParams();
for (String param : params.keySet()) {
String value = params.get(param);
jobMeta.setParameterValue(param, value);
}
} else {
// Open the transformation from inside the ZIP archive
//
TransMeta transMeta = new TransMeta(fileUrl);
// Also read the execution configuration information
//
String configUrl = "zip:" + archiveUrl + "!" + Trans.CONFIGURATION_IN_EXPORT_FILENAME;
Document configDoc = XMLHandler.loadXMLFile(configUrl);
TransExecutionConfiguration executionConfiguration = new TransExecutionConfiguration(XMLHandler.getSubNode(configDoc, TransExecutionConfiguration.XML_TAG));
carteObjectId = UUID.randomUUID().toString();
servletLoggingObject.setContainerObjectId(carteObjectId);
servletLoggingObject.setLogLevel(executionConfiguration.getLogLevel());
Trans trans = new Trans(transMeta, servletLoggingObject);
// store it all in the map...
//
getTransformationMap().addTransformation(trans.getName(), carteObjectId, trans, new TransConfiguration(transMeta, executionConfiguration));
}
} else {
fileUrl = archiveUrl;
}
out.println(new WebResult(WebResult.STRING_OK, fileUrl, carteObjectId));
} catch (Exception ex) {
out.println(new WebResult(WebResult.STRING_ERROR, Const.getStackTracker(ex)));
} finally {
if (outputStream != null) {
outputStream.close();
}
}
}
use of org.pentaho.di.trans.TransExecutionConfiguration in project pentaho-kettle by pentaho.
the class AddTransServlet method doGet.
/**
* <div id="mindtouch">
* <h1>/kettle/addTrans</h1>
* <a name="POST"></a>
* <h2>POST</h2>
* <p>Uploads and executes transformation configuration XML file.
* Uploads xml file containing transformation and transformation_execution_configuration
* (wrapped in transformation_configuration tag) to be executed and executes it. Method relies
* on the input parameter to determine if xml or html reply should be produced. The transformation_configuration xml is
* transferred within request body.
*
* <code>transformation name of the executed transformation </code> will be returned in the Response object
* or <code>message</code> describing error occurred. To determine if the call successful or not you should
* rely on <code>result</code> parameter in response.</p>
*
* <p><b>Example Request:</b><br />
* <pre function="syntax.xml">
* POST /kettle/addTrans/?xml=Y
* </pre>
* <p>Request body should contain xml containing transformation_configuration (transformation and
* transformation_execution_configuration wrapped in transformation_configuration tag).</p>
* </p>
* <h3>Parameters</h3>
* <table class="pentaho-table">
* <tbody>
* <tr>
* <th>name</th>
* <th>description</th>
* <th>type</th>
* </tr>
* <tr>
* <td>xml</td>
* <td>Boolean flag set to either <code>Y</code> or <code>N</code> describing if xml or html reply
* should be produced.</td>
* <td>boolean, optional</td>
* </tr>
* </tbody>
* </table>
*
* <h3>Response Body</h3>
*
* <table class="pentaho-table">
* <tbody>
* <tr>
* <td align="right">element:</td>
* <td>(custom)</td>
* </tr>
* <tr>
* <td align="right">media types:</td>
* <td>text/xml, text/html</td>
* </tr>
* </tbody>
* </table>
* <p>Response wraps transformation name that was executed or error stack trace
* if an error occurred. Response has <code>result</code> OK if there were no errors. Otherwise it returns ERROR.</p>
*
* <p><b>Example Response:</b></p>
* <pre function="syntax.xml">
* <?xml version="1.0" encoding="UTF-8"?>
* <webresult>
* <result>OK</result>
* <message>Transformation 'dummy-trans' was added to Carte with id eb4a92ff-6852-4307-9f74-3c74bd61f829</message>
* <id>eb4a92ff-6852-4307-9f74-3c74bd61f829</id>
* </webresult>
* </pre>
*
* <h3>Status Codes</h3>
* <table class="pentaho-table">
* <tbody>
* <tr>
* <th>code</th>
* <th>description</th>
* </tr>
* <tr>
* <td>200</td>
* <td>Request was processed and XML response is returned.</td>
* </tr>
* <tr>
* <td>500</td>
* <td>Internal server error occurs during request processing.</td>
* </tr>
* </tbody>
*</table>
*</div>
*/
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (isJettyMode() && !request.getRequestURI().startsWith(CONTEXT_PATH)) {
return;
}
if (log.isDebug()) {
logDebug("Addition of transformation 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 transformation</TITLE></HEAD>");
out.println("<BODY>");
}
response.setStatus(HttpServletResponse.SC_OK);
String realLogFilename = null;
TransExecutionConfiguration transExecutionConfiguration = null;
try {
// First read the complete transformation 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 transformation configuration
//
TransConfiguration transConfiguration = TransConfiguration.fromXML(xml.toString());
TransMeta transMeta = transConfiguration.getTransMeta();
transExecutionConfiguration = transConfiguration.getTransExecutionConfiguration();
transMeta.setLogLevel(transExecutionConfiguration.getLogLevel());
if (log.isDetailed()) {
logDetailed("Logging level set to " + log.getLogLevel().getDescription());
}
transMeta.injectVariables(transExecutionConfiguration.getVariables());
// Also copy the parameters over...
//
Map<String, String> params = transExecutionConfiguration.getParams();
for (String param : params.keySet()) {
String value = params.get(param);
transMeta.setParameterValue(param, value);
}
// If there was a repository, we know about it at this point in time.
//
final Repository repository = transExecutionConfiguration.getRepository();
String carteObjectId = UUID.randomUUID().toString();
SimpleLoggingObject servletLoggingObject = new SimpleLoggingObject(CONTEXT_PATH, LoggingObjectType.CARTE, null);
servletLoggingObject.setContainerObjectId(carteObjectId);
servletLoggingObject.setLogLevel(transExecutionConfiguration.getLogLevel());
// Create the transformation and store in the list...
//
final Trans trans = new Trans(transMeta, servletLoggingObject);
if (transExecutionConfiguration.isSetLogfile()) {
realLogFilename = transExecutionConfiguration.getLogFileName();
final LogChannelFileWriter logChannelFileWriter;
try {
FileUtil.createParentFolder(AddTransServlet.class, realLogFilename, transExecutionConfiguration.isCreateParentFolder(), trans.getLogChannel(), trans);
logChannelFileWriter = new LogChannelFileWriter(servletLoggingObject.getLogChannelId(), KettleVFS.getFileObject(realLogFilename), transExecutionConfiguration.isSetAppendLogfile());
logChannelFileWriter.startLogging();
trans.addTransListener(new TransAdapter() {
@Override
public void transFinished(Trans trans) throws KettleException {
if (logChannelFileWriter != null) {
logChannelFileWriter.stopLogging();
}
}
});
} catch (KettleException e) {
logError(Const.getStackTracker(e));
}
}
trans.setRepository(repository);
trans.setSocketRepository(getSocketRepository());
getTransformationMap().addTransformation(transMeta.getName(), carteObjectId, trans, transConfiguration);
trans.setContainerObjectId(carteObjectId);
if (repository != null) {
// The repository connection is open: make sure we disconnect from the repository once we
// are done with this transformation.
//
trans.addTransListener(new TransAdapter() {
public void transFinished(Trans trans) {
repository.disconnect();
}
});
}
String message = "Transformation '" + trans.getName() + "' was added to Carte with id " + carteObjectId;
if (useXML) {
// Return the log channel id as well
//
out.println(new WebResult(WebResult.STRING_OK, message, carteObjectId));
} else {
out.println("<H1>" + message + "</H1>");
out.println("<p><a href=\"" + convertContextPath(GetTransStatusServlet.CONTEXT_PATH) + "?name=" + trans.getName() + "&id=" + carteObjectId + "\">Go to the transformation 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.pentaho.di.trans.TransExecutionConfiguration in project pentaho-kettle by pentaho.
the class BaseJobServlet method createTrans.
protected Trans createTrans(TransConfiguration transConfiguration) throws UnknownParamException {
TransMeta transMeta = transConfiguration.getTransMeta();
TransExecutionConfiguration transExecutionConfiguration = transConfiguration.getTransExecutionConfiguration();
transMeta.setLogLevel(transExecutionConfiguration.getLogLevel());
transMeta.injectVariables(transExecutionConfiguration.getVariables());
// Also copy the parameters over...
copyParameters(transMeta, transExecutionConfiguration.getParams());
String carteObjectId = UUID.randomUUID().toString();
SimpleLoggingObject servletLoggingObject = getServletLogging(carteObjectId, transExecutionConfiguration.getLogLevel());
// Create the transformation and store in the list...
final Trans trans = new Trans(transMeta, servletLoggingObject);
trans.setMetaStore(transformationMap.getSlaveServerConfig().getMetaStore());
if (transExecutionConfiguration.isSetLogfile()) {
String realLogFilename = transExecutionConfiguration.getLogFileName();
try {
FileUtil.createParentFolder(AddTransServlet.class, realLogFilename, transExecutionConfiguration.isCreateParentFolder(), trans.getLogChannel(), trans);
final LogChannelFileWriter logChannelFileWriter = new LogChannelFileWriter(servletLoggingObject.getLogChannelId(), KettleVFS.getFileObject(realLogFilename), transExecutionConfiguration.isSetAppendLogfile());
logChannelFileWriter.startLogging();
trans.addTransListener(new TransAdapter() {
@Override
public void transFinished(Trans trans) throws KettleException {
if (logChannelFileWriter != null) {
logChannelFileWriter.stopLogging();
}
}
});
} catch (KettleException e) {
logError(Const.getStackTracker(e));
}
}
// If there was a repository, we know about it at this point in time.
final Repository repository = transExecutionConfiguration.getRepository();
trans.setRepository(repository);
trans.setSocketRepository(getSocketRepository());
trans.setContainerObjectId(carteObjectId);
getTransformationMap().addTransformation(transMeta.getName(), carteObjectId, trans, transConfiguration);
if (repository != null) {
// The repository connection is open: make sure we disconnect from the repository once we
// are done with this transformation.
trans.addTransListener(new TransAdapter() {
public void transFinished(Trans trans) {
repository.disconnect();
}
});
}
final Long passedBatchId = transExecutionConfiguration.getPassedBatchId();
if (passedBatchId != null) {
trans.setPassedBatchId(passedBatchId);
}
return trans;
}
use of org.pentaho.di.trans.TransExecutionConfiguration in project pentaho-kettle by pentaho.
the class RegisterPackageServlet method generateBody.
@Override
WebResult generateBody(HttpServletRequest request, HttpServletResponse response, boolean useXML) throws KettleException, IOException {
FileObject tempFile = KettleVFS.createTempFile("export", ".zip", System.getProperty("java.io.tmpdir"));
OutputStream out = KettleVFS.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 isJob = TYPE_JOB.equalsIgnoreCase(request.getParameter(PARAMETER_TYPE));
String resultId;
if (isJob) {
Node node = getConfigNodeFromZIP(archiveUrl, Job.CONFIGURATION_IN_EXPORT_FILENAME, JobExecutionConfiguration.XML_TAG);
JobExecutionConfiguration jobExecutionConfiguration = new JobExecutionConfiguration(node);
JobMeta jobMeta = new JobMeta(fileUrl, jobExecutionConfiguration.getRepository());
JobConfiguration jobConfiguration = new JobConfiguration(jobMeta, jobExecutionConfiguration);
Job job = createJob(jobConfiguration);
resultId = job.getContainerObjectId();
} else {
Node node = getConfigNodeFromZIP(archiveUrl, Trans.CONFIGURATION_IN_EXPORT_FILENAME, TransExecutionConfiguration.XML_TAG);
TransExecutionConfiguration transExecutionConfiguration = new TransExecutionConfiguration(node);
TransMeta transMeta = new TransMeta(fileUrl, transExecutionConfiguration.getRepository());
TransConfiguration transConfiguration = new TransConfiguration(transMeta, transExecutionConfiguration);
Trans trans = createTrans(transConfiguration);
resultId = trans.getContainerObjectId();
}
return new WebResult(WebResult.STRING_OK, fileUrl, resultId);
}
return null;
}
use of org.pentaho.di.trans.TransExecutionConfiguration in project pentaho-kettle by pentaho.
the class Spoon method replayTransformation.
public void replayTransformation() {
TransExecutionConfiguration tc = this.getTransExecutionConfiguration();
executeFile(tc.isExecutingLocally(), tc.isExecutingRemotely(), tc.isExecutingClustered(), false, false, new Date(), false, false);
}
Aggregations