Search in sources :

Example 1 with LoggingObject

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

the class XulDatabaseExplorerController method dataProfile.

public void dataProfile() {
    if (model.getTable() == null) {
        return;
    }
    Shell dbShell = (Shell) dbExplorerDialog.getRootObject();
    try {
        TransProfileFactory profileFactory = new TransProfileFactory(this.model.getDatabaseMeta(), getSchemaAndTable(this.model));
        TransMeta transMeta = profileFactory.generateTransformation(new LoggingObject(model.getTable()));
        TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog(dbShell, transMeta, new String[] { TransProfileFactory.RESULT_STEP_NAME }, new int[] { 25000 });
        progressDialog.open();
        if (!progressDialog.isCancelled()) {
            Trans trans = progressDialog.getTrans();
            String loggingText = progressDialog.getLoggingText();
            if (trans.getResult() != null && trans.getResult().getNrErrors() > 0) {
                EnterTextDialog etd = new EnterTextDialog(dbShell, BaseMessages.getString(PKG, "System.Dialog.PreviewError.Title"), BaseMessages.getString(PKG, "System.Dialog.PreviewError.Message"), loggingText, true);
                etd.setReadOnly();
                etd.open();
            }
            PreviewRowsDialog prd = new PreviewRowsDialog(dbShell, transMeta, SWT.NONE, TransProfileFactory.RESULT_STEP_NAME, progressDialog.getPreviewRowsMeta(TransProfileFactory.RESULT_STEP_NAME), progressDialog.getPreviewRows(TransProfileFactory.RESULT_STEP_NAME), loggingText);
            prd.open();
        }
    } catch (Exception e) {
        new ErrorDialog(this.dbExplorerDialog.getShell(), BaseMessages.getString(PKG, "DatabaseExplorerDialog.UnexpectedProfilingError.Title"), BaseMessages.getString(PKG, "DatabaseExplorerDialog.UnexpectedProfilingError.Message"), e);
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) TransPreviewProgressDialog(org.pentaho.di.ui.trans.dialog.TransPreviewProgressDialog) TransMeta(org.pentaho.di.trans.TransMeta) TransProfileFactory(org.pentaho.di.trans.TransProfileFactory) LoggingObject(org.pentaho.di.core.logging.LoggingObject) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) PreviewRowsDialog(org.pentaho.di.ui.core.dialog.PreviewRowsDialog) Trans(org.pentaho.di.trans.Trans) XulException(org.pentaho.ui.xul.XulException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException)

Example 2 with LoggingObject

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

the class SubtransExecutorTest method stopsAll.

@Test
public void stopsAll() throws KettleException {
    TransMeta parentMeta = new TransMeta(this.getClass().getResource("subtrans-executor-parent.ktr").getPath(), new Variables());
    TransMeta subMeta = new TransMeta(this.getClass().getResource("subtrans-executor-sub.ktr").getPath(), new Variables());
    LoggingObjectInterface loggingObject = new LoggingObject("anything");
    Trans parentTrans = new Trans(parentMeta, loggingObject);
    SubtransExecutor subtransExecutor = new SubtransExecutor("subtransname", parentTrans, subMeta, true, new TransExecutorParameters(), "");
    subtransExecutor.running = Mockito.spy(subtransExecutor.running);
    RowMetaInterface rowMeta = parentMeta.getStepFields("Data Grid");
    List<RowMetaAndData> rows = Arrays.asList(new RowMetaAndData(rowMeta, "Pentaho", 1L), new RowMetaAndData(rowMeta, "Pentaho", 2L), new RowMetaAndData(rowMeta, "Pentaho", 3L), new RowMetaAndData(rowMeta, "Pentaho", 4L));
    subtransExecutor.execute(rows);
    verify(subtransExecutor.running).add(any());
    subtransExecutor.stop();
    assertTrue(subtransExecutor.running.isEmpty());
}
Also used : Variables(org.pentaho.di.core.variables.Variables) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) LoggingObject(org.pentaho.di.core.logging.LoggingObject) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) LoggingObjectInterface(org.pentaho.di.core.logging.LoggingObjectInterface) TransExecutorParameters(org.pentaho.di.trans.steps.transexecutor.TransExecutorParameters) Test(org.junit.Test)

Example 3 with LoggingObject

use of org.pentaho.di.core.logging.LoggingObject in project pentaho-platform by pentaho.

the class Custom1 method execSQL.

@SuppressWarnings("unused")
private void execSQL(TransMeta transMeta, String targetDatabaseName) throws KettleStepException, KettleDatabaseException {
    // OK, What's the SQL we need to execute to generate the target table?
    String sql = transMeta.getSQLStatementsString();
    // Execute the SQL on the target table:
    Database targetDatabase = new Database(new LoggingObject("Custom1"), transMeta.findDatabase(targetDatabaseName));
    targetDatabase.connect();
    targetDatabase.execStatements(sql);
}
Also used : Database(org.pentaho.di.core.database.Database) LoggingObject(org.pentaho.di.core.logging.LoggingObject)

Example 4 with LoggingObject

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

the class ValueMetaBaseTest method testValueMetaBaseOnlyHasOneLogger.

@Test
public void testValueMetaBaseOnlyHasOneLogger() throws NoSuchFieldException, IllegalAccessException {
    Field log = ValueMetaBase.class.getDeclaredField("log");
    assertTrue(Modifier.isStatic(log.getModifiers()));
    assertTrue(Modifier.isFinal(log.getModifiers()));
    log.setAccessible(true);
    try {
        assertEquals(LoggingRegistry.getInstance().findExistingLoggingSource(new LoggingObject("ValueMetaBase")).getLogChannelId(), ((LogChannelInterface) log.get(null)).getLogChannelId());
    } finally {
        log.setAccessible(false);
    }
}
Also used : Field(java.lang.reflect.Field) LoggingObject(org.pentaho.di.core.logging.LoggingObject) Test(org.junit.Test)

Example 5 with LoggingObject

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

the class SubtransExecutorTest method testRunsATrans.

@Test
public void testRunsATrans() throws Exception {
    TransMeta parentMeta = new TransMeta(this.getClass().getResource("subtrans-executor-parent.ktr").getPath(), new Variables());
    TransMeta subMeta = new TransMeta(this.getClass().getResource("subtrans-executor-sub.ktr").getPath(), new Variables());
    LoggingObjectInterface loggingObject = new LoggingObject("anything");
    Trans parentTrans = spy(new Trans(parentMeta, loggingObject));
    SubtransExecutor subtransExecutor = new SubtransExecutor("subtransname", parentTrans, subMeta, true, new TransExecutorParameters(), "Group By");
    RowMetaInterface rowMeta = parentMeta.getStepFields("Data Grid");
    List<RowMetaAndData> rows = Arrays.asList(new RowMetaAndData(rowMeta, "Pentaho", 1L), new RowMetaAndData(rowMeta, "Pentaho", 2L), new RowMetaAndData(rowMeta, "Pentaho", 3L), new RowMetaAndData(rowMeta, "Pentaho", 4L));
    Optional<Result> optionalResult = subtransExecutor.execute(rows);
    assertEquals(1, optionalResult.orElseThrow(AssertionError::new).getRows().size());
    verify(this.logChannel).logBasic(Const.CR + "------------> Linenr 1------------------------------" + Const.CR + "name = Pentaho" + Const.CR + "sum = 10" + Const.CR + Const.CR + "====================");
    Map<String, StepStatus> statuses = subtransExecutor.getStatuses();
    assertEquals(3, statuses.size());
    List<StepStatus> statusList = new ArrayList<>(statuses.values());
    assertEquals("Get rows from result", statusList.get(0).getStepname());
    assertEquals("Group by", statusList.get(1).getStepname());
    assertEquals("Write to log", statusList.get(2).getStepname());
    for (Map.Entry<String, StepStatus> entry : statuses.entrySet()) {
        StepStatus statusSpy = spy(entry.getValue());
        statuses.put(entry.getKey(), statusSpy);
    }
    subtransExecutor.execute(rows);
    for (Map.Entry<String, StepStatus> entry : statuses.entrySet()) {
        verify(entry.getValue()).updateAll(any());
    }
    verify(parentTrans, atLeastOnce()).addActiveSubTransformation(eq("subtransname"), any(Trans.class));
}
Also used : ArrayList(java.util.ArrayList) LoggingObject(org.pentaho.di.core.logging.LoggingObject) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepStatus(org.pentaho.di.trans.step.StepStatus) Result(org.pentaho.di.core.Result) Variables(org.pentaho.di.core.variables.Variables) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) LoggingObjectInterface(org.pentaho.di.core.logging.LoggingObjectInterface) TransExecutorParameters(org.pentaho.di.trans.steps.transexecutor.TransExecutorParameters) Map(java.util.Map) Test(org.junit.Test)

Aggregations

LoggingObject (org.pentaho.di.core.logging.LoggingObject)6 Test (org.junit.Test)4 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)3 LoggingObjectInterface (org.pentaho.di.core.logging.LoggingObjectInterface)3 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)3 Variables (org.pentaho.di.core.variables.Variables)3 TransExecutorParameters (org.pentaho.di.trans.steps.transexecutor.TransExecutorParameters)3 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Shell (org.eclipse.swt.widgets.Shell)1 Result (org.pentaho.di.core.Result)1 Database (org.pentaho.di.core.database.Database)1 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)1 Trans (org.pentaho.di.trans.Trans)1 TransMeta (org.pentaho.di.trans.TransMeta)1 TransProfileFactory (org.pentaho.di.trans.TransProfileFactory)1 StepStatus (org.pentaho.di.trans.step.StepStatus)1 EnterTextDialog (org.pentaho.di.ui.core.dialog.EnterTextDialog)1 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)1