Search in sources :

Example 6 with TransLogTable

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

the class SpoonExportXmlTest method savingTransToXmlNotChangesLogTables.

@Test
public void savingTransToXmlNotChangesLogTables() {
    TransMeta transMeta = new TransMeta();
    initTables(transMeta);
    TransLogTable originTransLogTable = transMeta.getTransLogTable();
    StepLogTable originStepLogTable = transMeta.getStepLogTable();
    PerformanceLogTable originPerformanceLogTable = transMeta.getPerformanceLogTable();
    ChannelLogTable originChannelLogTable = transMeta.getChannelLogTable();
    MetricsLogTable originMetricsLogTable = transMeta.getMetricsLogTable();
    when(spoon.getActiveTransformation()).thenReturn(transMeta);
    when(spoon.saveXMLFile(any(TransMeta.class), anyBoolean())).thenReturn(true);
    when(spoon.saveXMLFile(anyBoolean())).thenCallRealMethod();
    spoon.saveXMLFile(true);
    tablesCommonValuesEqual(originTransLogTable, transMeta.getTransLogTable());
    assertEquals(originTransLogTable.getLogInterval(), transMeta.getTransLogTable().getLogInterval());
    assertEquals(originTransLogTable.getLogSizeLimit(), transMeta.getTransLogTable().getLogSizeLimit());
    tablesCommonValuesEqual(originStepLogTable, transMeta.getStepLogTable());
    tablesCommonValuesEqual(originPerformanceLogTable, transMeta.getPerformanceLogTable());
    assertEquals(originPerformanceLogTable.getLogInterval(), transMeta.getPerformanceLogTable().getLogInterval());
    tablesCommonValuesEqual(originChannelLogTable, transMeta.getChannelLogTable());
    tablesCommonValuesEqual(originMetricsLogTable, transMeta.getMetricsLogTable());
}
Also used : PerformanceLogTable(org.pentaho.di.core.logging.PerformanceLogTable) MetricsLogTable(org.pentaho.di.core.logging.MetricsLogTable) ChannelLogTable(org.pentaho.di.core.logging.ChannelLogTable) StepLogTable(org.pentaho.di.core.logging.StepLogTable) TransMeta(org.pentaho.di.trans.TransMeta) TransLogTable(org.pentaho.di.core.logging.TransLogTable) Test(org.junit.Test)

Example 7 with TransLogTable

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

the class Spoon method saveTransAsXmlFile.

private boolean saveTransAsXmlFile(TransMeta transMeta, boolean export) {
    TransLogTable origTransLogTable = transMeta.getTransLogTable();
    StepLogTable origStepLogTable = transMeta.getStepLogTable();
    PerformanceLogTable origPerformanceLogTable = transMeta.getPerformanceLogTable();
    ChannelLogTable origChannelLogTable = transMeta.getChannelLogTable();
    MetricsLogTable origMetricsLogTable = transMeta.getMetricsLogTable();
    try {
        XmlExportHelper.swapTables(transMeta);
        return saveXMLFile(transMeta, export);
    } finally {
        transMeta.setTransLogTable(origTransLogTable);
        transMeta.setStepLogTable(origStepLogTable);
        transMeta.setPerformanceLogTable(origPerformanceLogTable);
        transMeta.setChannelLogTable(origChannelLogTable);
        transMeta.setMetricsLogTable(origMetricsLogTable);
    }
}
Also used : PerformanceLogTable(org.pentaho.di.core.logging.PerformanceLogTable) MetricsLogTable(org.pentaho.di.core.logging.MetricsLogTable) ChannelLogTable(org.pentaho.di.core.logging.ChannelLogTable) StepLogTable(org.pentaho.di.core.logging.StepLogTable) TransLogTable(org.pentaho.di.core.logging.TransLogTable)

Example 8 with TransLogTable

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

the class KettleDatabaseRepositoryTransDelegate method loadRepTrans.

/**
 * Load the transformation name & other details from a repository.
 */
private void loadRepTrans(TransMeta transMeta) throws KettleException {
    try {
        RowMetaAndData r = getTransformation(transMeta.getObjectId());
        if (r != null) {
            transMeta.setName(r.getString(KettleDatabaseRepository.FIELD_TRANSFORMATION_NAME, null));
            // Trans description
            transMeta.setDescription(r.getString(KettleDatabaseRepository.FIELD_TRANSFORMATION_DESCRIPTION, null));
            transMeta.setExtendedDescription(r.getString(KettleDatabaseRepository.FIELD_TRANSFORMATION_EXTENDED_DESCRIPTION, null));
            transMeta.setTransversion(r.getString(KettleDatabaseRepository.FIELD_TRANSFORMATION_TRANS_VERSION, null));
            transMeta.setTransstatus((int) r.getInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_TRANS_STATUS, -1L));
            TransLogTable logTable = transMeta.getTransLogTable();
            logTable.findField(TransLogTable.ID.LINES_READ).setSubject(StepMeta.findStep(transMeta.getSteps(), new LongObjectId(r.getInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_STEP_READ, -1L))));
            logTable.findField(TransLogTable.ID.LINES_READ).setSubject(StepMeta.findStep(transMeta.getSteps(), new LongObjectId(r.getInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_STEP_WRITE, -1L))));
            logTable.findField(TransLogTable.ID.LINES_READ).setSubject(StepMeta.findStep(transMeta.getSteps(), new LongObjectId(r.getInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_STEP_INPUT, -1L))));
            logTable.findField(TransLogTable.ID.LINES_READ).setSubject(StepMeta.findStep(transMeta.getSteps(), new LongObjectId(r.getInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_STEP_OUTPUT, -1L))));
            logTable.findField(TransLogTable.ID.LINES_READ).setSubject(StepMeta.findStep(transMeta.getSteps(), new LongObjectId(r.getInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_STEP_UPDATE, -1L))));
            long id_rejected = getTransAttributeInteger(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_ID_STEP_REJECTED);
            if (id_rejected > 0) {
                logTable.findField(TransLogTable.ID.LINES_REJECTED).setSubject(StepMeta.findStep(transMeta.getSteps(), new LongObjectId(id_rejected)));
            }
            DatabaseMeta logDb = DatabaseMeta.findDatabase(transMeta.getDatabases(), new LongObjectId(r.getInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_DATABASE_LOG, -1L)));
            if (logDb != null) {
                logTable.setConnectionName(logDb.getName());
            // TODO: save/load name as a string, allow variables!
            }
            logTable.setTableName(r.getString(KettleDatabaseRepository.FIELD_TRANSFORMATION_TABLE_NAME_LOG, null));
            logTable.setBatchIdUsed(r.getBoolean(KettleDatabaseRepository.FIELD_TRANSFORMATION_USE_BATCHID, false));
            logTable.setLogFieldUsed(r.getBoolean(KettleDatabaseRepository.FIELD_TRANSFORMATION_USE_LOGFIELD, false));
            transMeta.setMaxDateConnection(DatabaseMeta.findDatabase(transMeta.getDatabases(), new LongObjectId(r.getInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_DATABASE_MAXDATE, -1L))));
            transMeta.setMaxDateTable(r.getString(KettleDatabaseRepository.FIELD_TRANSFORMATION_TABLE_NAME_MAXDATE, null));
            transMeta.setMaxDateField(r.getString(KettleDatabaseRepository.FIELD_TRANSFORMATION_FIELD_NAME_MAXDATE, null));
            transMeta.setMaxDateOffset(r.getNumber(KettleDatabaseRepository.FIELD_TRANSFORMATION_OFFSET_MAXDATE, 0.0));
            transMeta.setMaxDateDifference(r.getNumber(KettleDatabaseRepository.FIELD_TRANSFORMATION_DIFF_MAXDATE, 0.0));
            transMeta.setCreatedUser(r.getString(KettleDatabaseRepository.FIELD_TRANSFORMATION_CREATED_USER, null));
            transMeta.setCreatedDate(r.getDate(KettleDatabaseRepository.FIELD_TRANSFORMATION_CREATED_DATE, null));
            transMeta.setModifiedUser(r.getString(KettleDatabaseRepository.FIELD_TRANSFORMATION_MODIFIED_USER, null));
            transMeta.setModifiedDate(r.getDate(KettleDatabaseRepository.FIELD_TRANSFORMATION_MODIFIED_DATE, null));
            // Optional:
            transMeta.setSizeRowset(Const.ROWS_IN_ROWSET);
            Long val_size_rowset = r.getInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_SIZE_ROWSET);
            if (val_size_rowset != null) {
                transMeta.setSizeRowset(val_size_rowset.intValue());
            }
            long id_directory = r.getInteger(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_DIRECTORY, -1L);
            if (id_directory >= 0) {
                if (log.isDetailed()) {
                    log.logDetailed("ID_DIRECTORY=" + id_directory);
                }
                // always reload the folder structure
                // 
                transMeta.setRepositoryDirectory(repository.loadRepositoryDirectoryTree().findDirectory(new LongObjectId(id_directory)));
            }
            transMeta.setUsingUniqueConnections(getTransAttributeBoolean(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_UNIQUE_CONNECTIONS));
            transMeta.setFeedbackShown(!"N".equalsIgnoreCase(getTransAttributeString(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_FEEDBACK_SHOWN)));
            transMeta.setFeedbackSize((int) getTransAttributeInteger(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_FEEDBACK_SIZE));
            transMeta.setUsingThreadPriorityManagment(!"N".equalsIgnoreCase(getTransAttributeString(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_USING_THREAD_PRIORITIES)));
            // Performance monitoring for steps...
            // 
            transMeta.setCapturingStepPerformanceSnapShots(getTransAttributeBoolean(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_CAPTURE_STEP_PERFORMANCE));
            transMeta.setStepPerformanceCapturingDelay(getTransAttributeInteger(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_STEP_PERFORMANCE_CAPTURING_DELAY));
            transMeta.setStepPerformanceCapturingSizeLimit(getTransAttributeString(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_STEP_PERFORMANCE_CAPTURING_SIZE_LIMIT));
            transMeta.getPerformanceLogTable().setTableName(getTransAttributeString(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_STEP_PERFORMANCE_LOG_TABLE));
            transMeta.getTransLogTable().setLogSizeLimit(getTransAttributeString(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_LOG_SIZE_LIMIT));
            transMeta.getTransLogTable().setLogInterval(getTransAttributeString(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_LOG_INTERVAL));
            transMeta.setTransformationType(TransformationType.getTransformationTypeByCode(getTransAttributeString(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_TRANSFORMATION_TYPE)));
            transMeta.setSleepTimeEmpty((int) getTransAttributeInteger(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_SLEEP_TIME_EMPTY));
            transMeta.setSleepTimeFull((int) getTransAttributeInteger(transMeta.getObjectId(), 0, KettleDatabaseRepository.TRANS_ATTRIBUTE_SLEEP_TIME_FULL));
            loadRepParameters(transMeta);
        }
    } catch (KettleDatabaseException dbe) {
        throw new KettleException(BaseMessages.getString(PKG, "TransMeta.Exception.UnableToLoadTransformationInfoFromRepository"), dbe);
    } finally {
        transMeta.initializeVariablesFrom(null);
        transMeta.setInternalKettleVariables();
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) TransLogTable(org.pentaho.di.core.logging.TransLogTable) LongObjectId(org.pentaho.di.repository.LongObjectId) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta)

Example 9 with TransLogTable

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

the class TransformationHasTransLogConfiguredImportRule method verifyRule.

@Override
public List<ImportValidationFeedback> verifyRule(Object subject) {
    List<ImportValidationFeedback> feedback = new ArrayList<ImportValidationFeedback>();
    if (!isEnabled()) {
        return feedback;
    }
    if (!(subject instanceof TransMeta)) {
        return feedback;
    }
    TransMeta transMeta = (TransMeta) subject;
    TransLogTable transLogTable = transMeta.getTransLogTable();
    if (!transLogTable.isDefined()) {
        feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.ERROR, "The logging table is not defined"));
    } else {
        if (!Utils.isEmpty(schemaName)) {
            if (schemaName.equals(transLogTable.getSchemaName())) {
                feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.APPROVAL, "The schema name is set to: " + schemaName));
            } else {
                feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.ERROR, "The schema name is not set to: " + schemaName));
            }
        }
        if (!Utils.isEmpty(tableName)) {
            if (tableName.equals(transLogTable.getTableName())) {
                feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.APPROVAL, "The table name is set to: " + tableName));
            } else {
                feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.ERROR, "The table name is not set to: " + tableName));
            }
        }
        if (!Utils.isEmpty(connectionName)) {
            if (connectionName.equals(transLogTable.getDatabaseMeta().getName())) {
                feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.APPROVAL, "The database connection used for logging is: " + connectionName));
            } else {
                feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.ERROR, "The database connection used for logging is not: " + connectionName));
            }
        }
        if (feedback.isEmpty()) {
            feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.APPROVAL, "The logging table is correctly defined"));
        }
    }
    return feedback;
}
Also used : ImportValidationFeedback(org.pentaho.di.imp.rule.ImportValidationFeedback) ArrayList(java.util.ArrayList) TransMeta(org.pentaho.di.trans.TransMeta) TransLogTable(org.pentaho.di.core.logging.TransLogTable)

Example 10 with TransLogTable

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

the class TransTest method testEndProcessing_StatusCalculation_Base.

/**
 * <p>PDI-18458: A Stopped transformation would be logged as 'Running'.</p>
 * <p>Base for the testEndProcessing_StatusCalculation's tests.</p>
 *
 * @return the mocked {@link Database} object used on the test
 *
 * @see #testEndProcessing_StatusCalculation_Finished()
 * @see #testEndProcessing_StatusCalculation_Paused()
 * @see #testEndProcessing_StatusCalculation_Running()
 * @see #testEndProcessing_StatusCalculation_Stopped()
 */
private Database testEndProcessing_StatusCalculation_Base() throws Exception {
    TransLogTable transLogTable = spy(new TransLogTable(null, null, null));
    doReturn("AnActualTableNametransLogTable").when(transLogTable).getActualTableName();
    doReturn("AnActualConnectionName").when(transLogTable).getActualConnectionName();
    doReturn("AnActualSchemaName").when(transLogTable).getActualSchemaName();
    DatabaseMeta databaseMeta = mock(DatabaseMeta.class);
    doReturn(databaseMeta).when(transLogTable).getDatabaseMeta();
    doReturn(transLogTable).when(meta).getTransLogTable();
    doReturn(false).when(transLogTable).isBatchIdUsed();
    doReturn("MetaName").when(meta).getName();
    Database database = mock(Database.class);
    PowerMockito.whenNew(Database.class).withAnyArguments().thenReturn(database);
    doNothing().when(database).connect();
    trans.calculateBatchIdAndDateRange();
    trans.beginProcessing();
    return database;
}
Also used : Database(org.pentaho.di.core.database.Database) TransLogTable(org.pentaho.di.core.logging.TransLogTable) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta)

Aggregations

TransLogTable (org.pentaho.di.core.logging.TransLogTable)15 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)6 ChannelLogTable (org.pentaho.di.core.logging.ChannelLogTable)6 PerformanceLogTable (org.pentaho.di.core.logging.PerformanceLogTable)6 StepLogTable (org.pentaho.di.core.logging.StepLogTable)6 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)5 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)5 KettleException (org.pentaho.di.core.exception.KettleException)4 MetricsLogTable (org.pentaho.di.core.logging.MetricsLogTable)4 TransMeta (org.pentaho.di.trans.TransMeta)4 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)3 Database (org.pentaho.di.core.database.Database)3 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)3 KettleTransException (org.pentaho.di.core.exception.KettleTransException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Date (java.util.Date)2 KettleFileException (org.pentaho.di.core.exception.KettleFileException)2 KettleValueException (org.pentaho.di.core.exception.KettleValueException)2 DuplicateParamException (org.pentaho.di.core.parameters.DuplicateParamException)2 UnknownParamException (org.pentaho.di.core.parameters.UnknownParamException)2