Search in sources :

Example 26 with LogChannelInterface

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

the class StopTransServletIT method testStopTransServletEscapesHtmlWhenTransFound.

@Test
public void testStopTransServletEscapesHtmlWhenTransFound() throws ServletException, IOException {
    KettleLogStore.init();
    HttpServletRequest mockHttpServletRequest = mock(HttpServletRequest.class);
    HttpServletResponse mockHttpServletResponse = mock(HttpServletResponse.class);
    Trans mockTrans = mock(Trans.class);
    TransMeta mockTransMeta = mock(TransMeta.class);
    LogChannelInterface mockChannelInterface = mock(LogChannelInterface.class);
    StringWriter out = new StringWriter();
    PrintWriter printWriter = new PrintWriter(out);
    when(mockHttpServletRequest.getContextPath()).thenReturn(StopTransServlet.CONTEXT_PATH);
    when(mockHttpServletRequest.getParameter(anyString())).thenReturn(ServletTestUtils.BAD_STRING);
    when(mockHttpServletResponse.getWriter()).thenReturn(printWriter);
    when(mockTransformationMap.getTransformation(any(CarteObjectEntry.class))).thenReturn(mockTrans);
    when(mockTrans.getLogChannel()).thenReturn(mockChannelInterface);
    when(mockTrans.getLogChannelId()).thenReturn("test");
    when(mockTrans.getTransMeta()).thenReturn(mockTransMeta);
    when(mockTransMeta.getMaximum()).thenReturn(new Point(10, 10));
    stopTransServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
    assertFalse(ServletTestUtils.hasBadText(ServletTestUtils.getInsideOfTag("H1", out.toString())));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) StringWriter(java.io.StringWriter) TransMeta(org.pentaho.di.trans.TransMeta) HttpServletResponse(javax.servlet.http.HttpServletResponse) Point(org.pentaho.di.core.gui.Point) Trans(org.pentaho.di.trans.Trans) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 27 with LogChannelInterface

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

the class TransformationResource method addTransformation.

@PUT
@Path("/add")
@Produces({ MediaType.APPLICATION_JSON })
public TransformationStatus addTransformation(String xml) {
    TransConfiguration transConfiguration;
    try {
        transConfiguration = TransConfiguration.fromXML(xml.toString());
        TransMeta transMeta = transConfiguration.getTransMeta();
        TransExecutionConfiguration transExecutionConfiguration = transConfiguration.getTransExecutionConfiguration();
        transMeta.setLogLevel(transExecutionConfiguration.getLogLevel());
        LogChannelInterface log = CarteSingleton.getInstance().getLog();
        if (log.isDetailed()) {
            log.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.
        // 
        TransExecutionConfiguration executionConfiguration = transConfiguration.getTransExecutionConfiguration();
        final Repository repository = transConfiguration.getTransExecutionConfiguration().getRepository();
        String carteObjectId = UUID.randomUUID().toString();
        SimpleLoggingObject servletLoggingObject = new SimpleLoggingObject(getClass().getName(), LoggingObjectType.CARTE, null);
        servletLoggingObject.setContainerObjectId(carteObjectId);
        servletLoggingObject.setLogLevel(executionConfiguration.getLogLevel());
        // Create the transformation and store in the list...
        // 
        final Trans trans = new Trans(transMeta, servletLoggingObject);
        trans.setRepository(repository);
        trans.setSocketRepository(CarteSingleton.getInstance().getSocketRepository());
        CarteSingleton.getInstance().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();
                }
            });
        }
        return getTransformationStatus(carteObjectId);
    } catch (KettleException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : TransExecutionConfiguration(org.pentaho.di.trans.TransExecutionConfiguration) KettleException(org.pentaho.di.core.exception.KettleException) Repository(org.pentaho.di.repository.Repository) TransMeta(org.pentaho.di.trans.TransMeta) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) TransConfiguration(org.pentaho.di.trans.TransConfiguration) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Trans(org.pentaho.di.trans.Trans) TransAdapter(org.pentaho.di.trans.TransAdapter) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 28 with LogChannelInterface

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

the class JobEntryWriteToLog method evaluate.

/**
 * Output message to job log.
 */
public boolean evaluate(Result result) {
    LogChannelInterface logChannel = createLogChannel();
    String message = getRealLogMessage();
    // Filter out empty messages and those that are not visible with the job's log level
    if (Utils.isEmpty(message) || !getEntryLogLevel().isVisible(logChannel.getLogLevel())) {
        return true;
    }
    try {
        switch(getEntryLogLevel()) {
            case ERROR:
                logChannel.logError(message + Const.CR);
                break;
            case MINIMAL:
                logChannel.logMinimal(message + Const.CR);
                break;
            case BASIC:
                logChannel.logBasic(message + Const.CR);
                break;
            case DETAILED:
                logChannel.logDetailed(message + Const.CR);
                break;
            case DEBUG:
                logChannel.logDebug(message + Const.CR);
                break;
            case ROWLEVEL:
                logChannel.logRowlevel(message + Const.CR);
                break;
            default:
                // NOTHING
                break;
        }
        return true;
    } catch (Exception e) {
        result.setNrErrors(1);
        log.logError(BaseMessages.getString(PKG, "WriteToLog.Error.Label"), BaseMessages.getString(PKG, "WriteToLog.Error.Description") + " : " + e.toString());
        return false;
    }
}
Also used : LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException)

Example 29 with LogChannelInterface

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

the class Kitchen method main.

public static void main(String[] a) throws Exception {
    final ExecutorService executor = ExecutorUtil.getExecutor();
    final RepositoryPluginType repositoryPluginType = RepositoryPluginType.getInstance();
    final Future<Map.Entry<KettlePluginException, Future<KettleException>>> repositoryRegisterFuture = executor.submit(new Callable<Map.Entry<KettlePluginException, Future<KettleException>>>() {

        @Override
        public Map.Entry<KettlePluginException, Future<KettleException>> call() throws Exception {
            PluginRegistry.addPluginType(repositoryPluginType);
            try {
                KettleClientEnvironment.getInstance().setClient(KettleClientEnvironment.ClientType.KITCHEN);
                KettleClientEnvironment.init();
            } catch (KettlePluginException e) {
                return new AbstractMap.SimpleImmutableEntry<KettlePluginException, Future<KettleException>>(e, null);
            }
            Future<KettleException> kettleEnvironmentInitFuture = executor.submit(new Callable<KettleException>() {

                @Override
                public KettleException call() throws Exception {
                    try {
                        KettleClientEnvironment.getInstance().setClient(KettleClientEnvironment.ClientType.KITCHEN);
                        KettleEnvironment.init();
                    } catch (KettleException e) {
                        return e;
                    }
                    return null;
                }
            });
            return new AbstractMap.SimpleImmutableEntry<KettlePluginException, Future<KettleException>>(null, kettleEnvironmentInitFuture);
        }
    });
    List<String> args = new ArrayList<String>();
    for (int i = 0; i < a.length; i++) {
        if (a[i].length() > 0) {
            args.add(a[i]);
        }
    }
    DelegatingMetaStore metaStore = new DelegatingMetaStore();
    metaStore.addMetaStore(MetaStoreConst.openLocalPentahoMetaStore());
    metaStore.setActiveMetaStoreName(metaStore.getName());
    RepositoryMeta repositoryMeta = null;
    Job job = null;
    StringBuilder optionRepname, optionUsername, optionTrustUser, optionPassword, optionJobname, optionDirname, initialDir;
    StringBuilder optionFilename, optionLoglevel, optionLogfile, optionLogfileOld, optionListdir;
    StringBuilder optionListjobs, optionListrep, optionNorep, optionVersion, optionListParam, optionExport;
    NamedParams optionParams = new NamedParamsDefault();
    NamedParams customOptions = new NamedParamsDefault();
    CommandLineOption maxLogLinesOption = new CommandLineOption("maxloglines", BaseMessages.getString(PKG, "Kitchen.CmdLine.MaxLogLines"), new StringBuilder());
    CommandLineOption maxLogTimeoutOption = new CommandLineOption("maxlogtimeout", BaseMessages.getString(PKG, "Kitchen.CmdLine.MaxLogTimeout"), new StringBuilder());
    CommandLineOption[] options = new CommandLineOption[] { new CommandLineOption("rep", BaseMessages.getString(PKG, "Kitchen.CmdLine.RepName"), optionRepname = new StringBuilder()), new CommandLineOption("user", BaseMessages.getString(PKG, "Kitchen.CmdLine.RepUsername"), optionUsername = new StringBuilder()), new CommandLineOption("trustuser", BaseMessages.getString(PKG, "Kitchen.ComdLine.RepUsername"), optionTrustUser = new StringBuilder()), new CommandLineOption("pass", BaseMessages.getString(PKG, "Kitchen.CmdLine.RepPassword"), optionPassword = new StringBuilder()), new CommandLineOption("job", BaseMessages.getString(PKG, "Kitchen.CmdLine.RepJobName"), optionJobname = new StringBuilder()), new CommandLineOption("dir", BaseMessages.getString(PKG, "Kitchen.CmdLine.RepDir"), optionDirname = new StringBuilder()), new CommandLineOption("file", BaseMessages.getString(PKG, "Kitchen.CmdLine.XMLJob"), optionFilename = new StringBuilder()), new CommandLineOption("level", BaseMessages.getString(PKG, "Kitchen.CmdLine.LogLevel"), optionLoglevel = new StringBuilder()), new CommandLineOption("logfile", BaseMessages.getString(PKG, "Kitchen.CmdLine.LogFile"), optionLogfile = new StringBuilder()), new CommandLineOption("log", BaseMessages.getString(PKG, "Kitchen.CmdLine.LogFileOld"), optionLogfileOld = new StringBuilder(), false, true), new CommandLineOption("listdir", BaseMessages.getString(PKG, "Kitchen.CmdLine.ListDir"), optionListdir = new StringBuilder(), true, false), new CommandLineOption("listjobs", BaseMessages.getString(PKG, "Kitchen.CmdLine.ListJobsDir"), optionListjobs = new StringBuilder(), true, false), new CommandLineOption("listrep", BaseMessages.getString(PKG, "Kitchen.CmdLine.ListAvailableReps"), optionListrep = new StringBuilder(), true, false), new CommandLineOption("norep", BaseMessages.getString(PKG, "Kitchen.CmdLine.NoRep"), optionNorep = new StringBuilder(), true, false), new CommandLineOption("version", BaseMessages.getString(PKG, "Kitchen.CmdLine.Version"), optionVersion = new StringBuilder(), true, false), new CommandLineOption("param", BaseMessages.getString(PKG, "Kitchen.ComdLine.Param"), optionParams, false), new CommandLineOption("listparam", BaseMessages.getString(PKG, "Kitchen.ComdLine.ListParam"), optionListParam = new StringBuilder(), true, false), new CommandLineOption("export", BaseMessages.getString(PKG, "Kitchen.ComdLine.Export"), optionExport = new StringBuilder(), true, false), new CommandLineOption("initialDir", null, initialDir = new StringBuilder(), false, true), new CommandLineOption("custom", BaseMessages.getString(PKG, "Kitchen.ComdLine.Custom"), customOptions, false), maxLogLinesOption, maxLogTimeoutOption };
    if (args.size() == 2) {
        // 2 internal hidden argument (flag and value)
        CommandLineOption.printUsage(options);
        exitJVM(9);
    }
    LogChannelInterface log = new LogChannel(STRING_KITCHEN);
    CommandLineOption.parseArguments(args, options, log);
    configureLogging(maxLogLinesOption, maxLogTimeoutOption);
    String kettleRepname = Const.getEnvironmentVariable("KETTLE_REPOSITORY", null);
    String kettleUsername = Const.getEnvironmentVariable("KETTLE_USER", null);
    String kettlePassword = Const.getEnvironmentVariable("KETTLE_PASSWORD", null);
    if (!Utils.isEmpty(kettleRepname)) {
        optionRepname = new StringBuilder(kettleRepname);
    }
    if (!Utils.isEmpty(kettleUsername)) {
        optionUsername = new StringBuilder(kettleUsername);
    }
    if (!Utils.isEmpty(kettlePassword)) {
        optionPassword = new StringBuilder(kettlePassword);
    }
    if (Utils.isEmpty(optionLogfile) && !Utils.isEmpty(optionLogfileOld)) {
        // if the old style of logging name is filled in, and the new one is not
        // overwrite the new by the old
        optionLogfile = optionLogfileOld;
    }
    Map.Entry<KettlePluginException, Future<KettleException>> repositoryRegisterResults = repositoryRegisterFuture.get();
    // It's a singleton map with one key-value pair (a Pair collection)
    KettlePluginException repositoryRegisterException = repositoryRegisterResults.getKey();
    if (repositoryRegisterException != null) {
        throw repositoryRegisterException;
    }
    Future<KettleException> kettleInitFuture = repositoryRegisterResults.getValue();
    if (!Utils.isEmpty(optionLogfile)) {
        fileAppender = new FileLoggingEventListener(optionLogfile.toString(), true);
        KettleLogStore.getAppender().addLoggingEventListener(fileAppender);
    } else {
        fileAppender = null;
    }
    if (!Utils.isEmpty(optionLoglevel)) {
        log.setLogLevel(LogLevel.getLogLevelForCode(optionLoglevel.toString()));
        log.logMinimal(BaseMessages.getString(PKG, "Kitchen.Log.LogLevel", log.getLogLevel().getDescription()));
    }
    // Start the action...
    // 
    int returnCode = CommandExecutorCodes.Kitchen.SUCCESS.getCode();
    try {
        if (getCommandExecutor() == null) {
            // init
            setCommandExecutor(new KitchenCommandExecutor(PKG, log, kettleInitFuture));
        }
        if (!Utils.isEmpty(optionVersion)) {
            getCommandExecutor().printVersion();
            if (a.length == 1) {
                exitJVM(CommandExecutorCodes.Pan.KETTLE_VERSION_PRINT.getCode());
            }
        }
        returnCode = getCommandExecutor().execute(optionRepname.toString(), optionNorep.toString(), optionUsername.toString(), optionTrustUser.toString(), optionPassword.toString(), optionDirname.toString(), optionFilename.toString(), optionJobname.toString(), optionListjobs.toString(), optionListdir.toString(), optionExport.toString(), initialDir.toString(), optionListrep.toString(), optionListParam.toString(), optionParams, customOptions, args.toArray(new String[args.size()]));
    } catch (Throwable t) {
        t.printStackTrace();
        returnCode = CommandExecutorCodes.Pan.UNEXPECTED_ERROR.getCode();
    } finally {
        if (fileAppender != null) {
            fileAppender.close();
            KettleLogStore.getAppender().removeLoggingEventListener(fileAppender);
        }
    }
    exitJVM(returnCode);
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) NamedParams(org.pentaho.di.core.parameters.NamedParams) RepositoryPluginType(org.pentaho.di.core.plugins.RepositoryPluginType) ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) AbstractMap(java.util.AbstractMap) RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) CommandLineOption(org.pentaho.di.pan.CommandLineOption) Job(org.pentaho.di.job.Job) NamedParamsDefault(org.pentaho.di.core.parameters.NamedParamsDefault) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) FileLoggingEventListener(org.pentaho.di.core.logging.FileLoggingEventListener) LogChannel(org.pentaho.di.core.logging.LogChannel) DelegatingMetaStore(org.pentaho.metastore.stores.delegate.DelegatingMetaStore) KettleException(org.pentaho.di.core.exception.KettleException) ExecutionException(java.util.concurrent.ExecutionException) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Map(java.util.Map) AbstractMap(java.util.AbstractMap)

Example 30 with LogChannelInterface

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

the class ExtensionPointHandlerTest method callExtensionPointTest.

@Test
public void callExtensionPointTest() throws Exception {
    PluginMockInterface pluginInterface = mock(PluginMockInterface.class);
    when(pluginInterface.getName()).thenReturn(TEST_NAME);
    when(pluginInterface.getMainType()).thenReturn((Class) ExtensionPointInterface.class);
    when(pluginInterface.getIds()).thenReturn(new String[] { "testID" });
    ExtensionPointInterface extensionPoint = mock(ExtensionPointInterface.class);
    when(pluginInterface.loadClass(ExtensionPointInterface.class)).thenReturn(extensionPoint);
    PluginRegistry.addPluginType(ExtensionPointPluginType.getInstance());
    PluginRegistry.getInstance().registerPlugin(ExtensionPointPluginType.class, pluginInterface);
    final LogChannelInterface log = mock(LogChannelInterface.class);
    ExtensionPointHandler.callExtensionPoint(log, "noPoint", null);
    verify(extensionPoint, never()).callExtensionPoint(any(LogChannelInterface.class), any());
    ExtensionPointHandler.callExtensionPoint(log, TEST_NAME, null);
    verify(extensionPoint, times(1)).callExtensionPoint(eq(log), isNull());
}
Also used : LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Test(org.junit.Test)

Aggregations

LogChannelInterface (org.pentaho.di.core.logging.LogChannelInterface)65 Test (org.junit.Test)42 HttpServletRequest (javax.servlet.http.HttpServletRequest)27 HttpServletResponse (javax.servlet.http.HttpServletResponse)27 PrintWriter (java.io.PrintWriter)26 Point (org.pentaho.di.core.gui.Point)26 StringWriter (java.io.StringWriter)25 TransMeta (org.pentaho.di.trans.TransMeta)24 Trans (org.pentaho.di.trans.Trans)20 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)16 KettleException (org.pentaho.di.core.exception.KettleException)12 JobMeta (org.pentaho.di.job.JobMeta)12 Job (org.pentaho.di.job.Job)11 ArrayList (java.util.ArrayList)8 LogChannel (org.pentaho.di.core.logging.LogChannel)6 Matchers.anyString (org.mockito.Matchers.anyString)5 Before (org.junit.Before)4 StepInterface (org.pentaho.di.trans.step.StepInterface)4 ServletOutputStream (javax.servlet.ServletOutputStream)3 LoggingObjectInterface (org.pentaho.di.core.logging.LoggingObjectInterface)3