use of org.pentaho.di.core.logging.LogLevel in project pentaho-platform by pentaho.
the class KettleComponent method executeTransformation.
private boolean executeTransformation(final TransMeta transMeta) {
boolean success = true;
Trans trans = null;
try {
if (transMeta != null) {
try {
trans = new Trans(transMeta);
} catch (Exception e) {
throw new KettleComponentException(Messages.getInstance().getErrorString("Kettle.ERROR_0010_BAD_TRANSFORMATION_METADATA"), // $NON-NLS-1$
e);
}
}
if (trans == null) {
throw new KettleComponentException(Messages.getInstance().getErrorString(// $NON-NLS-1$
"Kettle.ERROR_0010_BAD_TRANSFORMATION_METADATA"));
}
// Remember where to get our execution logging from
//
logChannelId = trans.getLogChannelId();
// OK, we have the transformation, now run it!
if (!customizeTrans(trans)) {
throw new KettleComponentException(Messages.getInstance().getErrorString(// $NON-NLS-1$
"Kettle.ERROR_0028_CUSTOMIZATION_FUNCITON_FAILED"));
}
// $NON-NLS-1$
debug(Messages.getInstance().getString("Kettle.DEBUG_PREPARING_TRANSFORMATION"));
try {
LogLevel lvl = getLogLevel();
trans.setLogLevel(lvl);
trans.prepareExecution(transMeta.getArguments());
} catch (Exception e) {
throw new KettleComponentException(Messages.getInstance().getErrorString("Kettle.ERROR_0011_TRANSFORMATION_PREPARATION_FAILED"), // $NON-NLS-1$
e);
}
String stepName = null;
String outputName = null;
try {
// $NON-NLS-1$
debug(Messages.getInstance().getString("Kettle.DEBUG_FINDING_STEP_IMPORTER"));
stepName = getMonitorStepName();
outputName = getTransformSuccessOutputName();
if (outputName != null) {
registerAsStepListener(stepName, trans);
}
} catch (Exception e) {
throw new KettleComponentException(Messages.getInstance().getErrorString("Kettle.ERROR_0012_ROW_LISTENER_CREATE_FAILED"), // $NON-NLS-1$
e);
}
try {
// $NON-NLS-1$
debug(Messages.getInstance().getString("Kettle.DEBUG_STARTING_TRANSFORMATION"));
trans.startThreads();
} catch (Exception e) {
throw new KettleComponentException(Messages.getInstance().getErrorString("Kettle.ERROR_0013_TRANSFORMATION_START_FAILED"), // $NON-NLS-1$
e);
}
try {
// It's running in a separate thread to allow monitoring,
// etc.
// $NON-NLS-1$
debug(Messages.getInstance().getString("Kettle.DEBUG_TRANSFORMATION_RUNNING"));
trans.waitUntilFinished();
cleanLogChannel(trans);
trans.cleanup();
} catch (Exception e) {
throw new KettleComponentException(Messages.getInstance().getErrorString("Kettle.ERROR_0014_ERROR_DURING_EXECUTE"), // $NON-NLS-1$
e);
}
// Dump the Kettle log...
debug(getKettleLog(false));
// Build written row output
if (results != null) {
if (outputName != null) {
setOutputValue(outputName, results);
}
if (isDefinedOutput(TRANSFORM_SUCCESS_COUNT_OUTPUT)) {
setOutputValue(TRANSFORM_SUCCESS_COUNT_OUTPUT, results.getRowCount());
}
}
// Build error row output
if (errorResults != null) {
if (isDefinedOutput(TRANSFORM_ERROR_OUTPUT)) {
setOutputValue(TRANSFORM_ERROR_OUTPUT, errorResults);
}
if (isDefinedOutput(TRANSFORM_ERROR_COUNT_OUTPUT)) {
setOutputValue(TRANSFORM_ERROR_COUNT_OUTPUT, errorResults.getRowCount());
}
}
} catch (KettleComponentException e) {
success = false;
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("Kettle.ERROR_0008_ERROR_RUNNING", e.toString()), e);
}
prepareKettleOutput(trans);
return success;
}
use of org.pentaho.di.core.logging.LogLevel in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceTestModelTest method testGetAllLogLevels.
@Test
public void testGetAllLogLevels() throws Exception {
LogLevel[] levels = LogLevel.values();
List<String> levelValues = model.getAllLogLevels();
assertNotNull(levelValues);
assertEquals(levels.length, levelValues.size());
for (LogLevel level : levels) {
assertTrue(levelValues.contains(level.getDescription()));
}
}
use of org.pentaho.di.core.logging.LogLevel in project pentaho-cassandra-plugin by pentaho.
the class StepMockHelper method redirectLog.
/**
* In case you need to use log methods during the tests
* use redirectLog method after creating new StepMockHelper object.
* Examples:
* stepMockHelper.redirectLog( System.out, LogLevel.ROWLEVEL );
* stepMockHelper.redirectLog( new FileOutputStream("log.txt"), LogLevel.BASIC );
*/
public void redirectLog(final OutputStream out, LogLevel channelLogLevel) {
final LogChannel log = spy(new LogChannel(this.getClass().getName(), true));
log.setLogLevel(channelLogLevel);
when(logChannelInterfaceFactory.create(any(), any(LoggingObjectInterface.class))).thenReturn(log);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
LogLevel logLevel = (LogLevel) args[1];
LogLevel channelLogLevel = log.getLogLevel();
if (!logLevel.isVisible(channelLogLevel)) {
// not for our eyes.
return null;
}
if (channelLogLevel.getLevel() >= logLevel.getLevel()) {
LogMessageInterface logMessage = (LogMessageInterface) args[0];
out.write(logMessage.getMessage().getBytes());
out.write('\n');
out.write('\r');
out.flush();
return true;
}
return false;
}
}).when(log).println((LogMessageInterface) anyObject(), (LogLevel) anyObject());
}
use of org.pentaho.di.core.logging.LogLevel in project pentaho-kettle by pentaho.
the class ExecuteJobServlet method doGet.
/**
* <div id="mindtouch">
* <h1>/kettle/executeJob</h1>
* <a name="GET"></a>
* <h2>GET</h2>
* <p>Executes job from the specified repository.
* Connects to the repository provided as a parameter, loads the job from it and executes it.
* Empty response is returned or response contains output of an error happened during the job execution.
* Response contains <code>ERROR</code> result if error happened during job execution.</p>
*
* <p><b>Example Request:</b><br />
* <pre function="syntax.xml">
* GET /kettle/executeJob/?rep=my_repository&user=my_user&pass=my_password&job=my_job&level=INFO
* </pre>
*
* </p>
* <h3>Parameters</h3>
* <table class="pentaho-table">
* <tbody>
* <tr>
* <th>name</th>
* <th>description</th>
* <th>type</th>
* </tr>
* <tr>
* <td>rep</td>
* <td>Repository id to connect to.</td>
* <td>query</td>
* </tr>
* <tr>
* <td>user</td>
* <td>User name to be used to connect to repository.</td>
* <td>query</td>
* </tr>
* <tr>
* <td>pass</td>
* <td>User password to be used to connect to repository.</td>
* <td>query</td>
* </tr>
* <tr>
* <td>job</td>
* <td>Job name to be loaded and executed.</td>
* <td>query</td>
* </tr>
* <tr>
* <td>level</td>
* <td>Logging level to be used for job execution (i.e. Debug).</td>
* <td>query</td>
* </tr>
* <tr>
* <td>*any name*</td>
* <td>All the other parameters will be sent to the job for using as variables.
* When necessary you can add custom parameters to the request.
* They will be used to set the job variables values.</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 contains error output of the job executed or Carte object Id
* if the execution was successful.</p>
*
* <p><b>Example Error Response:</b></p>
* <pre function="syntax.xml">
* <webresult>
* <result>OK</result>
* <message>Job started</message>
* <id>74d96aa6-f29a-4bac-a26a-06a8c8f107e5</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.</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.getContextPath().startsWith(CONTEXT_PATH)) {
return;
}
if (log.isDebug()) {
logDebug(BaseMessages.getString(PKG, "ExecuteJobServlet.Log.ExecuteJobRequested"));
}
// Options taken from PAN
//
String[] knownOptions = new String[] { "rep", "user", "pass", "job", "level" };
String repOption = request.getParameter("rep");
String userOption = request.getParameter("user");
String passOption = Encr.decryptPasswordOptionallyEncrypted(request.getParameter("pass"));
String jobOption = request.getParameter("job");
String levelOption = request.getParameter("level");
response.setStatus(HttpServletResponse.SC_OK);
String encoding = System.getProperty("KETTLE_DEFAULT_SERVLET_ENCODING", null);
if (encoding != null && !Utils.isEmpty(encoding.trim())) {
response.setCharacterEncoding(encoding);
response.setContentType("text/html; charset=" + encoding);
}
PrintWriter out = response.getWriter();
try {
final Repository repository = openRepository(repOption, userOption, passOption);
final JobMeta jobMeta = loadJob(repository, jobOption);
// Set the servlet parameters as variables in the job
//
String[] parameters = jobMeta.listParameters();
Enumeration<?> parameterNames = request.getParameterNames();
while (parameterNames.hasMoreElements()) {
String parameter = (String) parameterNames.nextElement();
String[] values = request.getParameterValues(parameter);
//
if (Const.indexOfString(parameter, knownOptions) < 0) {
//
if (Const.indexOfString(parameter, parameters) < 0) {
jobMeta.setVariable(parameter, values[0]);
} else {
jobMeta.setParameterValue(parameter, values[0]);
}
}
}
JobExecutionConfiguration jobExecutionConfiguration = new JobExecutionConfiguration();
LogLevel logLevel = LogLevel.getLogLevelForCode(levelOption);
jobExecutionConfiguration.setLogLevel(logLevel);
JobConfiguration jobConfiguration = new JobConfiguration(jobMeta, jobExecutionConfiguration);
String carteObjectId = UUID.randomUUID().toString();
SimpleLoggingObject servletLoggingObject = new SimpleLoggingObject(CONTEXT_PATH, LoggingObjectType.CARTE, null);
servletLoggingObject.setContainerObjectId(carteObjectId);
servletLoggingObject.setLogLevel(logLevel);
// Create the job and store in the list...
//
final Job job = new Job(repository, jobMeta, servletLoggingObject);
job.setRepository(repository);
job.setSocketRepository(getSocketRepository());
getJobMap().addJob(jobMeta.getName(), carteObjectId, job, jobConfiguration);
job.setContainerObjectId(carteObjectId);
if (repository != null) {
// The repository connection is open: make sure we disconnect from the repository once we
// are done with this job.
//
job.addJobListener(new JobAdapter() {
public void jobFinished(Job job) {
repository.disconnect();
}
});
}
try {
runJob(job);
WebResult webResult = new WebResult(WebResult.STRING_OK, "Job started", carteObjectId);
out.println(webResult.getXML());
out.flush();
} catch (Exception executionException) {
String logging = KettleLogStore.getAppender().getBuffer(job.getLogChannelId(), false).toString();
throw new KettleException("Error executing job: " + logging, executionException);
}
} catch (Exception ex) {
out.println(new WebResult(WebResult.STRING_ERROR, BaseMessages.getString(PKG, "ExecuteJobServlet.Error.UnexpectedError", Const.CR + Const.getStackTracker(ex))));
}
}
use of org.pentaho.di.core.logging.LogLevel in project pentaho-kettle by pentaho.
the class ExecuteTransServlet method doGet.
/**
* <div id="mindtouch">
* <h1>/kettle/executeTrans</h1>
* <a name="GET"></a>
* <h2>GET</h2>
* <p>Executes transformation from the specified repository.
* Connects to the repository provided as a parameter, loads the transformation from it and executes it.
* Empty response is returned or response contains output of an error happened during the transformation execution.
* Response contains <code>ERROR</code> result if error happened during transformation execution.</p>
*
* <p><b>Example Request:</b><br />
* <pre function="syntax.xml">
* GET /kettle/executeTrans/?rep=my_repository&user=my_user&pass=my_password&trans=my_trans&level=INFO
* </pre>
*
* </p>
* <h3>Parameters</h3>
* <table class="pentaho-table">
* <tbody>
* <tr>
* <th>name</th>
* <th>description</th>
* <th>type</th>
* </tr>
* <tr>
* <td>rep</td>
* <td>Repository id to connect to.</td>
* <td>query</td>
* </tr>
* <tr>
* <td>user</td>
* <td>User name to be used to connect to repository.</td>
* <td>query</td>
* </tr>
* <tr>
* <td>pass</td>
* <td>User password to be used to connect to repository.</td>
* <td>query</td>
* </tr>
* <tr>
* <td>trans</td>
* <td>Transfromation name to be loaded and executed.</td>
* <td>query</td>
* </tr>
* <tr>
* <td>level</td>
* <td>Logging level to be used for transformation execution (i.e. Debug).</td>
* <td>query</td>
* </tr>
* <tr>
* <td>*any name*</td>
* <td>All the other parameters will be sent to the transformation for using as variables.
* When necessary you can add custom parameters to the request.
* They will be used to set the transformation variables values..</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 contains error output of the transformation executed or nothing
* if the execution was successful.</p>
*
* <p><b>Example Error Response:</b></p>
* <pre function="syntax.xml">
* <webresult>
* <result>ERROR</result>
* <message>Unexpected error executing the transformation:
* 
org.pentaho.di.core.exception.KettleException:
* 
Unable to find transformation 'dummy-trans.ktr' in directory
* :/home/admin

 at
* org.pentaho.di.www.ExecuteTransServlet.loadTransformation(ExecuteTransServlet.java:214)

* at org.pentaho.di.www.ExecuteTransServlet.doGet(ExecuteTransServlet.java:104)

* at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)

* at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)

* at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)

* at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)

* at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)

* at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)

* at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)

* at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)

* at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)

* at org.mortbay.jetty.Server.handle(Server.java:326)

* at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:536)

* at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:915)

* at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:539)

* at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)

* at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:405)

* at org.mortbay.jetty.bio.SocketConnector$Connection.run(SocketConnector.java:228)

* at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

* </message>
* <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.</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.getContextPath().startsWith(CONTEXT_PATH)) {
return;
}
if (log.isDebug()) {
logDebug(BaseMessages.getString(PKG, "ExecuteTransServlet.Log.ExecuteTransRequested"));
}
// Options taken from PAN
//
String[] knownOptions = new String[] { "rep", "user", "pass", "trans", "level" };
String repOption = request.getParameter("rep");
String userOption = request.getParameter("user");
String passOption = Encr.decryptPasswordOptionallyEncrypted(request.getParameter("pass"));
String transOption = request.getParameter("trans");
String levelOption = request.getParameter("level");
response.setStatus(HttpServletResponse.SC_OK);
String encoding = System.getProperty("KETTLE_DEFAULT_SERVLET_ENCODING", null);
if (encoding != null && !Utils.isEmpty(encoding.trim())) {
response.setCharacterEncoding(encoding);
response.setContentType("text/html; charset=" + encoding);
}
PrintWriter out = response.getWriter();
try {
final Repository repository = openRepository(repOption, userOption, passOption);
final TransMeta transMeta = loadTransformation(repository, transOption);
// Set the servlet parameters as variables in the transformation
//
String[] parameters = transMeta.listParameters();
Enumeration<?> parameterNames = request.getParameterNames();
while (parameterNames.hasMoreElements()) {
String parameter = (String) parameterNames.nextElement();
String[] values = request.getParameterValues(parameter);
//
if (Const.indexOfString(parameter, knownOptions) < 0) {
//
if (Const.indexOfString(parameter, parameters) < 0) {
transMeta.setVariable(parameter, values[0]);
} else {
transMeta.setParameterValue(parameter, values[0]);
}
}
}
TransExecutionConfiguration transExecutionConfiguration = new TransExecutionConfiguration();
LogLevel logLevel = LogLevel.getLogLevelForCode(levelOption);
transExecutionConfiguration.setLogLevel(logLevel);
TransConfiguration transConfiguration = new TransConfiguration(transMeta, transExecutionConfiguration);
String carteObjectId = UUID.randomUUID().toString();
SimpleLoggingObject servletLoggingObject = new SimpleLoggingObject(CONTEXT_PATH, LoggingObjectType.CARTE, null);
servletLoggingObject.setContainerObjectId(carteObjectId);
servletLoggingObject.setLogLevel(logLevel);
// Create the transformation and store in the list...
//
final Trans trans = new Trans(transMeta, servletLoggingObject);
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();
}
});
}
// Pass the servlet print writer to the transformation...
//
trans.setServletPrintWriter(out);
trans.setServletReponse(response);
trans.setServletRequest(request);
try {
// Execute the transformation...
//
executeTrans(trans);
out.flush();
} catch (Exception executionException) {
String logging = KettleLogStore.getAppender().getBuffer(trans.getLogChannelId(), false).toString();
throw new KettleException("Error executing transformation: " + logging, executionException);
}
} catch (Exception ex) {
out.println(new WebResult(WebResult.STRING_ERROR, BaseMessages.getString(PKG, "ExecuteTransServlet.Error.UnexpectedError", Const.CR + Const.getStackTracker(ex))));
}
}
Aggregations