Search in sources :

Example 11 with TransLogTable

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

the class RepositoryTestBase method createTransMeta.

protected TransMeta createTransMeta(final String dbName) throws Exception {
    RepositoryDirectoryInterface rootDir = loadStartDirectory();
    TransMeta transMeta = new TransMeta();
    transMeta.setName(EXP_TRANS_NAME.concat(dbName));
    transMeta.setDescription(EXP_TRANS_DESC);
    transMeta.setExtendedDescription(EXP_TRANS_EXTENDED_DESC);
    transMeta.setRepositoryDirectory(rootDir.findDirectory(DIR_TRANSFORMATIONS));
    transMeta.setTransversion(EXP_TRANS_VERSION);
    transMeta.setTransstatus(EXP_TRANS_STATUS);
    transMeta.setCreatedUser(EXP_TRANS_CREATED_USER);
    transMeta.setCreatedDate(EXP_TRANS_CREATED_DATE);
    transMeta.setModifiedUser(EXP_TRANS_MOD_USER);
    transMeta.setModifiedDate(EXP_TRANS_MOD_DATE);
    transMeta.addParameterDefinition(EXP_TRANS_PARAM_1_NAME, EXP_TRANS_PARAM_1_DEF, EXP_TRANS_PARAM_1_DESC);
    // TODO mlowery other transLogTable fields could be set for testing here
    TransLogTable transLogTable = TransLogTable.getDefault(transMeta, transMeta, new ArrayList<StepMeta>(0));
    transLogTable.setConnectionName(EXP_TRANS_LOG_TABLE_CONN_NAME);
    transLogTable.setLogInterval(EXP_TRANS_LOG_TABLE_INTERVAL);
    transLogTable.setSchemaName(EXP_TRANS_LOG_TABLE_SCHEMA_NAME);
    transLogTable.setLogSizeLimit(EXP_TRANS_LOG_TABLE_SIZE_LIMIT);
    transLogTable.setTableName(EXP_TRANS_LOG_TABLE_TABLE_NAME);
    transLogTable.setTimeoutInDays(EXP_TRANS_LOG_TABLE_TIMEOUT_IN_DAYS);
    transMeta.setTransLogTable(transLogTable);
    // TODO mlowery other perfLogTable fields could be set for testing here
    PerformanceLogTable perfLogTable = PerformanceLogTable.getDefault(transMeta, transMeta);
    perfLogTable.setConnectionName(EXP_TRANS_LOG_TABLE_CONN_NAME);
    perfLogTable.setLogInterval(EXP_TRANS_LOG_TABLE_INTERVAL);
    perfLogTable.setSchemaName(EXP_TRANS_LOG_TABLE_SCHEMA_NAME);
    perfLogTable.setTableName(EXP_TRANS_LOG_TABLE_TABLE_NAME);
    perfLogTable.setTimeoutInDays(EXP_TRANS_LOG_TABLE_TIMEOUT_IN_DAYS);
    transMeta.setPerformanceLogTable(perfLogTable);
    // TODO mlowery other channelLogTable fields could be set for testing here
    ChannelLogTable channelLogTable = ChannelLogTable.getDefault(transMeta, transMeta);
    channelLogTable.setConnectionName(EXP_TRANS_LOG_TABLE_CONN_NAME);
    channelLogTable.setSchemaName(EXP_TRANS_LOG_TABLE_SCHEMA_NAME);
    channelLogTable.setTableName(EXP_TRANS_LOG_TABLE_TABLE_NAME);
    channelLogTable.setTimeoutInDays(EXP_TRANS_LOG_TABLE_TIMEOUT_IN_DAYS);
    transMeta.setChannelLogTable(channelLogTable);
    // TODO mlowery other stepLogTable fields could be set for testing here
    StepLogTable stepLogTable = StepLogTable.getDefault(transMeta, transMeta);
    stepLogTable.setConnectionName(EXP_TRANS_LOG_TABLE_CONN_NAME);
    stepLogTable.setSchemaName(EXP_TRANS_LOG_TABLE_SCHEMA_NAME);
    stepLogTable.setTableName(EXP_TRANS_LOG_TABLE_TABLE_NAME);
    stepLogTable.setTimeoutInDays(EXP_TRANS_LOG_TABLE_TIMEOUT_IN_DAYS);
    transMeta.setStepLogTable(stepLogTable);
    DatabaseMeta dbMeta = createDatabaseMeta(dbName);
    // dbMeta must be saved so that it gets an ID
    repository.save(dbMeta, VERSION_COMMENT_V1, null);
    deleteStack.push(dbMeta);
    transMeta.setMaxDateConnection(dbMeta);
    transMeta.setMaxDateTable(EXP_TRANS_MAX_DATE_TABLE);
    transMeta.setMaxDateField(EXP_TRANS_MAX_DATE_FIELD);
    transMeta.setMaxDateOffset(EXP_TRANS_MAX_DATE_OFFSET);
    transMeta.setMaxDateDifference(EXP_TRANS_MAX_DATE_DIFF);
    transMeta.setSizeRowset(EXP_TRANS_SIZE_ROWSET);
    transMeta.setSleepTimeEmpty(EXP_TRANS_SLEEP_TIME_EMPTY);
    transMeta.setSleepTimeFull(EXP_TRANS_SLEEP_TIME_FULL);
    transMeta.setUsingUniqueConnections(EXP_TRANS_USING_UNIQUE_CONN);
    transMeta.setFeedbackShown(EXP_TRANS_FEEDBACK_SHOWN);
    transMeta.setFeedbackSize(EXP_TRANS_FEEDBACK_SIZE);
    transMeta.setUsingThreadPriorityManagment(EXP_TRANS_USING_THREAD_PRIORITY_MGMT);
    transMeta.setSharedObjectsFile(EXP_TRANS_SHARED_OBJECTS_FILE);
    transMeta.setCapturingStepPerformanceSnapShots(EXP_TRANS_CAPTURE_STEP_PERF_SNAPSHOTS);
    transMeta.setStepPerformanceCapturingDelay(EXP_TRANS_STEP_PERF_CAP_DELAY);
    transMeta.addDependency(new TransDependency(dbMeta, EXP_TRANS_DEP_TABLE_NAME, EXP_TRANS_DEP_FIELD_NAME));
    DatabaseMeta stepDbMeta = createDatabaseMeta(EXP_DBMETA_NAME_STEP.concat(dbName));
    repository.save(stepDbMeta, VERSION_COMMENT_V1, null);
    deleteStack.push(stepDbMeta);
    Condition cond = new Condition();
    StepMeta step1 = createStepMeta1(transMeta, stepDbMeta, cond);
    transMeta.addStep(step1);
    StepMeta step2 = createStepMeta2(stepDbMeta, cond);
    transMeta.addStep(step2);
    transMeta.addTransHop(createTransHopMeta(step1, step2));
    SlaveServer slaveServer = createSlaveServer(dbName);
    PartitionSchema partSchema = createPartitionSchema(dbName);
    // slaveServer, partSchema must be saved so that they get IDs
    repository.save(slaveServer, VERSION_COMMENT_V1, null);
    deleteStack.push(slaveServer);
    repository.save(partSchema, VERSION_COMMENT_V1, null);
    deleteStack.push(partSchema);
    SlaveStepCopyPartitionDistribution slaveStepCopyPartitionDistribution = new SlaveStepCopyPartitionDistribution();
    slaveStepCopyPartitionDistribution.addPartition(EXP_SLAVE_NAME, EXP_PART_SCHEMA_NAME, 0);
    slaveStepCopyPartitionDistribution.setOriginalPartitionSchemas(Arrays.asList(new PartitionSchema[] { partSchema }));
    transMeta.setSlaveStepCopyPartitionDistribution(slaveStepCopyPartitionDistribution);
    transMeta.setSlaveTransformation(EXP_TRANS_SLAVE_TRANSFORMATION);
    return transMeta;
}
Also used : Condition(org.pentaho.di.core.Condition) PerformanceLogTable(org.pentaho.di.core.logging.PerformanceLogTable) SlaveStepCopyPartitionDistribution(org.pentaho.di.trans.SlaveStepCopyPartitionDistribution) PartitionSchema(org.pentaho.di.partition.PartitionSchema) TransMeta(org.pentaho.di.trans.TransMeta) TransDependency(org.pentaho.di.trans.TransDependency) SlaveServer(org.pentaho.di.cluster.SlaveServer) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) ChannelLogTable(org.pentaho.di.core.logging.ChannelLogTable) StepLogTable(org.pentaho.di.core.logging.StepLogTable) TransLogTable(org.pentaho.di.core.logging.TransLogTable)

Example 12 with TransLogTable

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

the class XmlExportHelper method swapTables.

/**
 * When exporting meta we should not export user global parameters.
 * Method makes clone for each table and deletes all global parameters.
 * We have to make clones of each table, because we don't want to change real tables content.
 *
 * @param transMeta
 *              meta, that contains log tables to be refactored before export
 */
public static void swapTables(TransMeta transMeta) {
    TransLogTable transLogTable = transMeta.getTransLogTable();
    if (transLogTable != null) {
        TransLogTable cloneTransLogTable = (TransLogTable) transLogTable.clone();
        cloneTransLogTable.setAllGlobalParametersToNull();
        transMeta.setTransLogTable(cloneTransLogTable);
    }
    StepLogTable stepLogTable = transMeta.getStepLogTable();
    if (stepLogTable != null) {
        StepLogTable cloneStepLogTable = (StepLogTable) stepLogTable.clone();
        cloneStepLogTable.setAllGlobalParametersToNull();
        transMeta.setStepLogTable(cloneStepLogTable);
    }
    PerformanceLogTable performanceLogTable = transMeta.getPerformanceLogTable();
    if (performanceLogTable != null) {
        PerformanceLogTable clonePerformanceLogTable = (PerformanceLogTable) performanceLogTable.clone();
        clonePerformanceLogTable.setAllGlobalParametersToNull();
        transMeta.setPerformanceLogTable(clonePerformanceLogTable);
    }
    ChannelLogTable channelLogTable = transMeta.getChannelLogTable();
    if (channelLogTable != null) {
        ChannelLogTable cloneChannelLogTable = (ChannelLogTable) channelLogTable.clone();
        cloneChannelLogTable.setAllGlobalParametersToNull();
        transMeta.setChannelLogTable(cloneChannelLogTable);
    }
    MetricsLogTable metricsLogTable = transMeta.getMetricsLogTable();
    if (metricsLogTable != null) {
        MetricsLogTable cloneMetricsLogTable = (MetricsLogTable) metricsLogTable.clone();
        cloneMetricsLogTable.setAllGlobalParametersToNull();
        transMeta.setMetricsLogTable(cloneMetricsLogTable);
    }
}
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 13 with TransLogTable

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

the class Trans method beginProcessing.

/**
 * Begin processing. Also handle logging operations related to the start of the transformation
 *
 * @throws KettleTransException the kettle trans exception
 */
public void beginProcessing() throws KettleTransException {
    TransLogTable transLogTable = transMeta.getTransLogTable();
    int intervalInSeconds = Const.toInt(environmentSubstitute(transLogTable.getLogInterval()), -1);
    try {
        String logTable = transLogTable.getActualTableName();
        SimpleDateFormat df = new SimpleDateFormat(REPLAY_DATE_FORMAT);
        log.logDetailed(BaseMessages.getString(PKG, "Trans.Log.TransformationCanBeReplayed") + df.format(currentDate));
        try {
            if (transLogTableDatabaseConnection != null && !Utils.isEmpty(logTable) && !Utils.isEmpty(transMeta.getName())) {
                transLogTableDatabaseConnection.writeLogRecord(transLogTable, LogStatus.START, this, null);
                // 
                if (!transLogTableDatabaseConnection.isAutoCommit()) {
                    transLogTableDatabaseConnection.commitLog(true, transLogTable);
                }
                // 
                if (intervalInSeconds > 0) {
                    final Timer timer = new Timer(getName() + " - interval logging timer");
                    TimerTask timerTask = new TimerTask() {

                        @Override
                        public void run() {
                            try {
                                endProcessing();
                            } catch (Exception e) {
                                log.logError(BaseMessages.getString(PKG, "Trans.Exception.UnableToPerformIntervalLogging"), e);
                                // Also stop the show...
                                // 
                                errors.incrementAndGet();
                                stopAll();
                            }
                        }
                    };
                    timer.schedule(timerTask, intervalInSeconds * 1000, intervalInSeconds * 1000);
                    addTransListener(new TransAdapter() {

                        @Override
                        public void transFinished(Trans trans) {
                            timer.cancel();
                        }
                    });
                }
                // Add a listener to make sure that the last record is also written when transformation finishes...
                // 
                addTransListener(new TransAdapter() {

                    @Override
                    public void transFinished(Trans trans) throws KettleException {
                        try {
                            endProcessing();
                            lastWrittenStepPerformanceSequenceNr = writeStepPerformanceLogRecords(lastWrittenStepPerformanceSequenceNr, LogStatus.END);
                        } catch (KettleException e) {
                            throw new KettleException(BaseMessages.getString(PKG, "Trans.Exception.UnableToPerformLoggingAtTransEnd"), e);
                        }
                    }
                });
            }
            // If we need to write out the step logging information, do so at the end of the transformation too...
            // 
            StepLogTable stepLogTable = transMeta.getStepLogTable();
            if (stepLogTable.isDefined()) {
                addTransListener(new TransAdapter() {

                    @Override
                    public void transFinished(Trans trans) throws KettleException {
                        try {
                            writeStepLogInformation();
                        } catch (KettleException e) {
                            throw new KettleException(BaseMessages.getString(PKG, "Trans.Exception.UnableToPerformLoggingAtTransEnd"), e);
                        }
                    }
                });
            }
            // If we need to write the log channel hierarchy and lineage information, add a listener for that too...
            // 
            ChannelLogTable channelLogTable = transMeta.getChannelLogTable();
            if (channelLogTable.isDefined()) {
                addTransListener(new TransAdapter() {

                    @Override
                    public void transFinished(Trans trans) throws KettleException {
                        try {
                            writeLogChannelInformation();
                        } catch (KettleException e) {
                            throw new KettleException(BaseMessages.getString(PKG, "Trans.Exception.UnableToPerformLoggingAtTransEnd"), e);
                        }
                    }
                });
            }
            // See if we need to write the step performance records at intervals too...
            // 
            PerformanceLogTable performanceLogTable = transMeta.getPerformanceLogTable();
            int perfLogInterval = Const.toInt(environmentSubstitute(performanceLogTable.getLogInterval()), -1);
            if (performanceLogTable.isDefined() && perfLogInterval > 0) {
                final Timer timer = new Timer(getName() + " - step performance log interval timer");
                TimerTask timerTask = new TimerTask() {

                    @Override
                    public void run() {
                        try {
                            lastWrittenStepPerformanceSequenceNr = writeStepPerformanceLogRecords(lastWrittenStepPerformanceSequenceNr, LogStatus.RUNNING);
                        } catch (Exception e) {
                            log.logError(BaseMessages.getString(PKG, "Trans.Exception.UnableToPerformIntervalPerformanceLogging"), e);
                            // Also stop the show...
                            // 
                            errors.incrementAndGet();
                            stopAll();
                        }
                    }
                };
                timer.schedule(timerTask, perfLogInterval * 1000, perfLogInterval * 1000);
                addTransListener(new TransAdapter() {

                    @Override
                    public void transFinished(Trans trans) {
                        timer.cancel();
                    }
                });
            }
        } catch (KettleException e) {
            throw new KettleTransException(BaseMessages.getString(PKG, "Trans.Exception.ErrorWritingLogRecordToTable", logTable), e);
        } finally {
            // 
            if (transLogTableDatabaseConnection != null && (intervalInSeconds <= 0)) {
                transLogTableDatabaseConnection.disconnect();
                transLogTableDatabaseConnection = null;
            }
        }
    } catch (KettleException e) {
        throw new KettleTransException(BaseMessages.getString(PKG, "Trans.Exception.UnableToBeginProcessingTransformation"), e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) PerformanceLogTable(org.pentaho.di.core.logging.PerformanceLogTable) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleTransException(org.pentaho.di.core.exception.KettleTransException) DuplicateParamException(org.pentaho.di.core.parameters.DuplicateParamException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) Timer(java.util.Timer) TimerTask(java.util.TimerTask) ChannelLogTable(org.pentaho.di.core.logging.ChannelLogTable) StepLogTable(org.pentaho.di.core.logging.StepLogTable) TransLogTable(org.pentaho.di.core.logging.TransLogTable) KettleTransException(org.pentaho.di.core.exception.KettleTransException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 14 with TransLogTable

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

the class Trans method getResult.

/**
 * Gets the result of the transformation. The Result object contains such measures as the number of errors, number of
 * lines read/written/input/output/updated/rejected, etc.
 *
 * @return the Result object containing resulting measures from execution of the transformation
 */
public Result getResult() {
    if (steps == null) {
        return null;
    }
    Result result = new Result();
    result.setNrErrors(errors.longValue());
    result.setResult(errors.longValue() == 0);
    TransLogTable transLogTable = transMeta.getTransLogTable();
    for (int i = 0; i < steps.size(); i++) {
        StepMetaDataCombi sid = steps.get(i);
        StepInterface step = sid.step;
        result.setNrErrors(result.getNrErrors() + sid.step.getErrors());
        result.getResultFiles().putAll(step.getResultFiles());
        if (step.isSafeStopped()) {
            result.setSafeStop(step.isSafeStopped());
        }
        if (step.getStepname().equals(transLogTable.getSubjectString(TransLogTable.ID.LINES_READ))) {
            result.setNrLinesRead(result.getNrLinesRead() + step.getLinesRead());
        }
        if (step.getStepname().equals(transLogTable.getSubjectString(TransLogTable.ID.LINES_INPUT))) {
            result.setNrLinesInput(result.getNrLinesInput() + step.getLinesInput());
        }
        if (step.getStepname().equals(transLogTable.getSubjectString(TransLogTable.ID.LINES_WRITTEN))) {
            result.setNrLinesWritten(result.getNrLinesWritten() + step.getLinesWritten());
        }
        if (step.getStepname().equals(transLogTable.getSubjectString(TransLogTable.ID.LINES_OUTPUT))) {
            result.setNrLinesOutput(result.getNrLinesOutput() + step.getLinesOutput());
        }
        if (step.getStepname().equals(transLogTable.getSubjectString(TransLogTable.ID.LINES_UPDATED))) {
            result.setNrLinesUpdated(result.getNrLinesUpdated() + step.getLinesUpdated());
        }
        if (step.getStepname().equals(transLogTable.getSubjectString(TransLogTable.ID.LINES_REJECTED))) {
            result.setNrLinesRejected(result.getNrLinesRejected() + step.getLinesRejected());
        }
    }
    result.setRows(resultRows);
    if (!Utils.isEmpty(resultFiles)) {
        result.setResultFiles(new HashMap<String, ResultFile>());
        for (ResultFile resultFile : resultFiles) {
            result.getResultFiles().put(resultFile.toString(), resultFile);
        }
    }
    result.setStopped(isStopped());
    result.setLogChannelId(log.getLogChannelId());
    return result;
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) TransLogTable(org.pentaho.di.core.logging.TransLogTable) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ResultFile(org.pentaho.di.core.ResultFile) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) WebResult(org.pentaho.di.www.WebResult) Result(org.pentaho.di.core.Result)

Example 15 with TransLogTable

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

the class SpoonExportXmlTest method initTables.

private void initTables(TransMeta transMeta) {
    TransLogTable transLogTable = TransLogTable.getDefault(mockedVariableSpace, mockedHasDbInterface, null);
    initTableWithSampleParams(transLogTable);
    transLogTable.setLogInterval(GLOBAL_PARAM);
    transLogTable.setLogSizeLimit(GLOBAL_PARAM);
    transMeta.setTransLogTable(transLogTable);
    StepLogTable stepLogTable = StepLogTable.getDefault(mockedVariableSpace, mockedHasDbInterface);
    initTableWithSampleParams(stepLogTable);
    transMeta.setStepLogTable(stepLogTable);
    PerformanceLogTable performanceLogTable = PerformanceLogTable.getDefault(mockedVariableSpace, mockedHasDbInterface);
    initTableWithSampleParams(performanceLogTable);
    performanceLogTable.setLogInterval(GLOBAL_PARAM);
    transMeta.setPerformanceLogTable(performanceLogTable);
    ChannelLogTable channelLogTable = ChannelLogTable.getDefault(mockedVariableSpace, mockedHasDbInterface);
    initTableWithSampleParams(channelLogTable);
    transMeta.setChannelLogTable(channelLogTable);
    MetricsLogTable metricsLogTable = MetricsLogTable.getDefault(mockedVariableSpace, mockedHasDbInterface);
    initTableWithSampleParams(metricsLogTable);
    transMeta.setMetricsLogTable(metricsLogTable);
}
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)

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