Search in sources :

Example 1 with LogLevel

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;
}
Also used : Trans(org.pentaho.di.trans.Trans) KettleException(org.pentaho.di.core.exception.KettleException) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) LogLevel(org.pentaho.di.core.logging.LogLevel)

Example 2 with LogLevel

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()));
    }
}
Also used : LogLevel(org.pentaho.di.core.logging.LogLevel) Test(org.junit.Test)

Example 3 with LogLevel

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());
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) LogMessageInterface(org.pentaho.di.core.logging.LogMessageInterface) LogChannel(org.pentaho.di.core.logging.LogChannel) Matchers.anyObject(org.mockito.Matchers.anyObject) LoggingObjectInterface(org.pentaho.di.core.logging.LoggingObjectInterface) LogLevel(org.pentaho.di.core.logging.LogLevel)

Example 4 with LogLevel

use of org.pentaho.di.core.logging.LogLevel in project pentaho-kettle by pentaho.

the class RepositoriesMeta method clear.

public void clear() {
    errorMessage = null;
    databases = new ArrayList<DatabaseMeta>();
    repositories = new ArrayList<RepositoryMeta>();
    LogLevel level = null;
    if (log != null) {
        level = log.getLogLevel();
    }
    setLog(newLogChannel());
    if (level != null) {
        log.setLogLevel(level);
    }
}
Also used : KettleDatabaseRepositoryMeta(org.pentaho.di.repository.kdr.KettleDatabaseRepositoryMeta) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) LogLevel(org.pentaho.di.core.logging.LogLevel)

Example 5 with LogLevel

use of org.pentaho.di.core.logging.LogLevel in project pentaho-kettle by pentaho.

the class RunTransServlet method doGet.

/**
 * <div id="mindtouch">
 *    <h1>/kettle/runTrans</h1>
 *    <a name="GET"></a>
 *    <h2>GET</h2>
 *    <p>Execute transformation from enterprise repository. Repository should be configured in Carte xml file.
 *  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/runTrans?trans=home%2Fadmin%2Fdummy-trans&level=Debug
 *    </pre>
 *
 *    </p>
 *    <h3>Parameters</h3>
 *    <table class="pentaho-table">
 *    <tbody>
 *    <tr>
 *      <th>name</th>
 *      <th>description</th>
 *      <th>type</th>
 *    </tr>
 *    <tr>
 *    <td>trans</td>
 *    <td>Full path to the transformation in repository.</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>
 *    </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</td>
 *      </tr>
 *    </tbody>
 *  </table>
 *    <p>Response contains result of the operation. It is either <code>OK</code> or <code>ERROR</code>.
 *     If an error occurred during transformation execution, response also contains information about the error.</p>
 *
 *    <p><b>Example Response:</b></p>
 *    <pre function="syntax.xml">
 *    <webresult>
 *      <result>OK</result>
 *      <message>Transformation started</message>
 *      <id>7c082e8f-b4fe-40bc-b424-e0f881a61874</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, "RunTransServlet.Log.RunTransRequested"));
    }
    // Options taken from PAN
    // 
    String[] knownOptions = new String[] { "trans", "level" };
    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 = transformationMap.getSlaveServerConfig().getRepository();
        final TransMeta transMeta = loadTrans(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 = createTrans(transMeta, servletLoggingObject);
        // Pass information
        // 
        trans.setRepository(repository);
        trans.setServletPrintWriter(out);
        trans.setServletReponse(response);
        trans.setServletRequest(request);
        // Setting variables
        // 
        trans.initializeVariablesFrom(null);
        trans.getTransMeta().setInternalKettleVariables(trans);
        trans.injectVariables(transConfiguration.getTransExecutionConfiguration().getVariables());
        // Also copy the parameters over...
        // 
        trans.copyParametersFrom(transMeta);
        /*
       * String[] parameterNames = job.listParameters(); for (int idx = 0; idx < parameterNames.length; idx++) { // Grab
       * the parameter value set in the job entry // String thisValue =
       * jobExecutionConfiguration.getParams().get(parameterNames[idx]); if (!Utils.isEmpty(thisValue)) { // Set the
       * value as specified by the user in the job entry // jobMeta.setParameterValue(parameterNames[idx], thisValue); }
       * }
       */
        transMeta.activateParameters();
        trans.setSocketRepository(getSocketRepository());
        getTransformationMap().addTransformation(trans.getName(), carteObjectId, trans, transConfiguration);
        // DO NOT disconnect from the shared repository connection when the job finishes.
        // 
        String message = "Transformation '" + trans.getName() + "' was added to the list with id " + carteObjectId;
        logBasic(message);
        try {
            // Execute the transformation...
            // 
            trans.execute(null);
            finishProcessing(trans, out);
        } 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, "RunTransServlet.Error.UnexpectedError", Const.CR + Const.getStackTracker(ex))));
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) TransMeta(org.pentaho.di.trans.TransMeta) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) TransConfiguration(org.pentaho.di.trans.TransConfiguration) LogLevel(org.pentaho.di.core.logging.LogLevel) ServletException(javax.servlet.ServletException) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException) TransExecutionConfiguration(org.pentaho.di.trans.TransExecutionConfiguration) Repository(org.pentaho.di.repository.Repository) Trans(org.pentaho.di.trans.Trans) PrintWriter(java.io.PrintWriter)

Aggregations

LogLevel (org.pentaho.di.core.logging.LogLevel)20 KettleException (org.pentaho.di.core.exception.KettleException)9 Job (org.pentaho.di.job.Job)5 IOException (java.io.IOException)4 PrintWriter (java.io.PrintWriter)4 ServletException (javax.servlet.ServletException)4 DefaultLogLevel (org.pentaho.di.core.logging.DefaultLogLevel)4 SimpleLoggingObject (org.pentaho.di.core.logging.SimpleLoggingObject)4 UnknownParamException (org.pentaho.di.core.parameters.UnknownParamException)4 Repository (org.pentaho.di.repository.Repository)4 ArrayList (java.util.ArrayList)3 ResultFile (org.pentaho.di.core.ResultFile)3 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)3 LogChannel (org.pentaho.di.core.logging.LogChannel)3 LogMessageInterface (org.pentaho.di.core.logging.LogMessageInterface)3 JobExecutionConfiguration (org.pentaho.di.job.JobExecutionConfiguration)3 JobMeta (org.pentaho.di.job.JobMeta)3 Trans (org.pentaho.di.trans.Trans)3 ExecutionException (java.util.concurrent.ExecutionException)2 Matchers.anyObject (org.mockito.Matchers.anyObject)2