Search in sources :

Example 6 with JobLogTable

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

the class JobDelegateTest method testElementToDataNodeSavesCopyAttributes.

@Test
public void testElementToDataNodeSavesCopyAttributes() throws KettleException {
    JobMeta mockJobMeta = mock(JobMeta.class);
    IUnifiedRepository mockUnifiedRepository = mock(IUnifiedRepository.class);
    JobDelegate jobDelegate = new JobDelegate(mockPurRepository, mockUnifiedRepository);
    JobLogTable mockJobLogTable = mock(JobLogTable.class);
    JobEntryCopy mockJobEntryCopy = mock(JobEntryCopy.class);
    Map<String, Map<String, String>> attributes = new HashMap<String, Map<String, String>>();
    Map<String, String> group = new HashMap<String, String>();
    final String mockGroup = "MOCK_GROUP";
    final String mockProperty = "MOCK_PROPERTY";
    final String mockValue = "MOCK_VALUE";
    group.put(mockProperty, mockValue);
    attributes.put(mockGroup, group);
    when(mockJobEntryCopy.getAttributesMap()).thenReturn(attributes);
    JobEntryBaseAndInterface mockJobEntry = mock(JobEntryBaseAndInterface.class);
    when(mockJobMeta.listParameters()).thenReturn(new String[] {});
    when(mockJobMeta.getJobLogTable()).thenReturn(mockJobLogTable);
    when(mockJobMeta.nrJobEntries()).thenReturn(1);
    when(mockJobMeta.getJobEntry(0)).thenReturn(mockJobEntryCopy);
    when(mockJobEntryCopy.getName()).thenReturn("MOCK_NAME");
    when(mockJobEntryCopy.getLocation()).thenReturn(new Point(0, 0));
    when(mockJobEntryCopy.getEntry()).thenReturn(mockJobEntry);
    DataNode dataNode = jobDelegate.elementToDataNode(mockJobMeta);
    DataNode groups = dataNode.getNode("entries").getNodes().iterator().next().getNode(AttributesMapUtil.NODE_ATTRIBUTE_GROUPS);
    DataNode mockGroupNode = groups.getNode(mockGroup);
    assertEquals(mockValue, mockGroupNode.getProperty(mockProperty).getString());
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) JobLogTable(org.pentaho.di.core.logging.JobLogTable) HashMap(java.util.HashMap) Point(org.pentaho.di.core.gui.Point) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) HashMap(java.util.HashMap) Map(java.util.Map) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Example 7 with JobLogTable

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

the class JobTest method recordsCleanUpMethodIsCalled_JobLogTable.

@Test
public void recordsCleanUpMethodIsCalled_JobLogTable() throws Exception {
    JobLogTable jobLogTable = JobLogTable.getDefault(mockedVariableSpace, hasDatabasesInterface);
    setAllTableParamsDefault(jobLogTable);
    doCallRealMethod().when(mockedJob).writeLogTableInformation(jobLogTable, LogStatus.END);
    mockedJob.writeLogTableInformation(jobLogTable, LogStatus.END);
    verify(mockedDataBase).cleanupLogRecords(jobLogTable);
}
Also used : JobLogTable(org.pentaho.di.core.logging.JobLogTable) Test(org.junit.Test)

Example 8 with JobLogTable

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

the class Job method endProcessing.

// 
// Handle logging at end
/**
 * End processing.
 *
 * @return true, if successful
 * @throws KettleJobException
 *           the kettle job exception
 */
private boolean endProcessing() throws KettleJobException {
    LogStatus status;
    if (!isActive()) {
        if (isStopped()) {
            status = LogStatus.STOP;
        } else {
            status = LogStatus.END;
        }
    } else {
        status = LogStatus.RUNNING;
    }
    try {
        if (errors.get() == 0 && result != null && !result.getResult()) {
            errors.incrementAndGet();
        }
        logDate = new Date();
        /*
       * Sums errors, read, written, etc.
       */
        JobLogTable jobLogTable = jobMeta.getJobLogTable();
        if (jobLogTable.isDefined()) {
            writeLogTableInformation(jobLogTable, status);
        }
        return true;
    } catch (Exception e) {
        // In case something else goes wrong.
        throw new KettleJobException(e);
    }
}
Also used : LogStatus(org.pentaho.di.core.logging.LogStatus) JobLogTable(org.pentaho.di.core.logging.JobLogTable) Date(java.util.Date) DuplicateParamException(org.pentaho.di.core.parameters.DuplicateParamException) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) KettleJobException(org.pentaho.di.core.exception.KettleJobException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) KettleJobException(org.pentaho.di.core.exception.KettleJobException)

Example 9 with JobLogTable

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

the class RepositoryTestBase method createJobMeta.

protected JobMeta createJobMeta(String jobName) throws Exception {
    RepositoryDirectoryInterface rootDir = loadStartDirectory();
    JobMeta jobMeta = new JobMeta();
    jobMeta.setName(jobName);
    jobMeta.setDescription(EXP_JOB_DESC);
    jobMeta.setExtendedDescription(EXP_JOB_EXTENDED_DESC);
    jobMeta.setRepositoryDirectory(rootDir.findDirectory(DIR_JOBS));
    jobMeta.setJobversion(EXP_JOB_VERSION);
    jobMeta.setJobstatus(EXP_JOB_STATUS);
    jobMeta.setCreatedUser(EXP_JOB_CREATED_USER);
    jobMeta.setCreatedDate(EXP_JOB_CREATED_DATE);
    jobMeta.setModifiedUser(EXP_JOB_MOD_USER);
    jobMeta.setModifiedDate(EXP_JOB_MOD_DATE);
    jobMeta.addParameterDefinition(EXP_JOB_PARAM_1_NAME, EXP_JOB_PARAM_1_DEF, EXP_JOB_PARAM_1_DESC);
    // TODO mlowery other jobLogTable fields could be set for testing here
    JobLogTable jobLogTable = JobLogTable.getDefault(jobMeta, jobMeta);
    jobLogTable.setConnectionName(EXP_JOB_LOG_TABLE_CONN_NAME);
    jobLogTable.setLogInterval(EXP_JOB_LOG_TABLE_INTERVAL);
    jobLogTable.setSchemaName(EXP_JOB_LOG_TABLE_SCHEMA_NAME);
    jobLogTable.setLogSizeLimit(EXP_JOB_LOG_TABLE_SIZE_LIMIT);
    jobLogTable.setTableName(EXP_JOB_LOG_TABLE_TABLE_NAME);
    jobLogTable.setTimeoutInDays(EXP_JOB_LOG_TABLE_TIMEOUT_IN_DAYS);
    jobMeta.setJobLogTable(jobLogTable);
    // TODO mlowery other jobEntryLogTable fields could be set for testing here
    JobEntryLogTable jobEntryLogTable = JobEntryLogTable.getDefault(jobMeta, jobMeta);
    jobEntryLogTable.setConnectionName(EXP_JOB_LOG_TABLE_CONN_NAME);
    jobEntryLogTable.setSchemaName(EXP_JOB_LOG_TABLE_SCHEMA_NAME);
    jobEntryLogTable.setTableName(EXP_JOB_LOG_TABLE_TABLE_NAME);
    jobEntryLogTable.setTimeoutInDays(EXP_JOB_LOG_TABLE_TIMEOUT_IN_DAYS);
    jobMeta.setJobEntryLogTable(jobEntryLogTable);
    // TODO mlowery other channelLogTable fields could be set for testing here
    ChannelLogTable channelLogTable = ChannelLogTable.getDefault(jobMeta, jobMeta);
    channelLogTable.setConnectionName(EXP_JOB_LOG_TABLE_CONN_NAME);
    channelLogTable.setSchemaName(EXP_JOB_LOG_TABLE_SCHEMA_NAME);
    channelLogTable.setTableName(EXP_JOB_LOG_TABLE_TABLE_NAME);
    channelLogTable.setTimeoutInDays(EXP_JOB_LOG_TABLE_TIMEOUT_IN_DAYS);
    jobMeta.setChannelLogTable(channelLogTable);
    jobMeta.setBatchIdPassed(EXP_JOB_BATCH_ID_PASSED);
    jobMeta.setSharedObjectsFile(EXP_JOB_SHARED_OBJECTS_FILE);
    DatabaseMeta entryDbMeta = createDatabaseMeta(EXP_DBMETA_NAME_JOB.concat(jobName));
    repository.save(entryDbMeta, VERSION_COMMENT_V1, null);
    deleteStack.push(entryDbMeta);
    JobEntryCopy jobEntryCopy1 = createJobEntry1Copy(entryDbMeta);
    jobMeta.addJobEntry(jobEntryCopy1);
    JobEntryCopy jobEntryCopy2 = createJobEntry2Copy(entryDbMeta);
    jobMeta.addJobEntry(jobEntryCopy2);
    jobMeta.addJobHop(createJobHopMeta(jobEntryCopy1, jobEntryCopy2));
    jobMeta.addNote(createNotePadMeta(jobName));
    return jobMeta;
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobLogTable(org.pentaho.di.core.logging.JobLogTable) ChannelLogTable(org.pentaho.di.core.logging.ChannelLogTable) JobEntryLogTable(org.pentaho.di.core.logging.JobEntryLogTable) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta)

Example 10 with JobLogTable

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

the class JobDelegateTest method testDataNodeToElementCopiesAttributesToJobEntryCopyAndJobEntry.

@Test
public void testDataNodeToElementCopiesAttributesToJobEntryCopyAndJobEntry() throws KettleException {
    IUnifiedRepository mockUnifiedRepository = mock(IUnifiedRepository.class);
    JobDelegate jobDelegate = new JobDelegate(mockPurRepository, mockUnifiedRepository);
    DataNode mockDataNode = mock(DataNode.class);
    DataNode entriesNode = addSubnode(mockDataNode, JobDelegate.NODE_ENTRIES);
    DataNode copyNode = mock(DataNode.class);
    setNodes(entriesNode, JobDelegate.PROP_NR_JOB_ENTRY_COPIES, Arrays.asList(copyNode));
    DataNode nodeCustom = addSubnode(copyNode, JobDelegate.NODE_CUSTOM);
    DataNode notesNode = addSubnode(mockDataNode, JobDelegate.NODE_NOTES);
    DataNode hopsNode = addSubnode(mockDataNode, JobDelegate.NODE_HOPS);
    DataNode paramsNode = addSubnode(mockDataNode, JobDelegate.NODE_PARAMETERS);
    DataNode groupsNode = addSubnode(copyNode, AttributesMapUtil.NODE_ATTRIBUTE_GROUPS);
    DataNode groupNode = mock(DataNode.class);
    setNodes(groupsNode, null, Arrays.asList(groupNode));
    JobMeta mockJobMeta = mock(JobMeta.class);
    JobLogTable mockJobLogTable = mock(JobLogTable.class);
    List<JobEntryCopy> jobCopies = new ArrayList<JobEntryCopy>();
    DataProperty mockDataProperty = mock(DataProperty.class);
    List<DataProperty> dataProperties = Arrays.asList(mockDataProperty);
    setProperty(mockDataNode, JobDelegate.PROP_JOB_STATUS, 0L);
    setProperty(mockDataNode, JobDelegate.PROP_USE_BATCH_ID, false);
    setProperty(mockDataNode, JobDelegate.PROP_PASS_BATCH_ID, false);
    setProperty(mockDataNode, JobDelegate.PROP_USE_LOGFIELD, false);
    setProperty(copyNode, JobDelegate.PROP_JOBENTRY_TYPE, "WRITE_TO_LOG");
    when(copyNode.getId()).thenReturn("COPYNODE_ID");
    setProperty(copyNode, JobDelegate.PROP_NR, 0L);
    setProperty(copyNode, JobDelegate.PROP_GUI_LOCATION_X, 0L);
    setProperty(copyNode, JobDelegate.PROP_GUI_LOCATION_Y, 0L);
    setProperty(copyNode, JobDelegate.PROP_GUI_DRAW, false);
    setProperty(copyNode, JobDelegate.PROP_PARALLEL, false);
    setProperty(nodeCustom, "logmessage_#_0", (String) null);
    setNodes(notesNode, JobDelegate.PROP_NR_NOTES, Arrays.<DataNode>asList());
    setNodes(hopsNode, JobDelegate.PROP_NR_HOPS, Arrays.<DataNode>asList());
    setProperty(paramsNode, JobDelegate.PROP_NR_PARAMETERS, 0L);
    when(mockJobMeta.getJobCopies()).thenReturn(jobCopies);
    when(mockJobMeta.getJobLogTable()).thenReturn(mockJobLogTable);
    when(groupNode.getName()).thenReturn("GROUP_NODE_NAME");
    when(groupNode.getProperties()).thenReturn(dataProperties);
    when(mockDataProperty.getName()).thenReturn("MOCK_PROPERTY");
    when(mockDataProperty.getString()).thenReturn("MOCK_VALUE");
    jobDelegate.dataNodeToElement(mockDataNode, mockJobMeta);
    assertEquals(jobCopies.get(0).getAttributesMap(), ((JobEntryBase) jobCopies.get(0).getEntry()).getAttributesMap());
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobLogTable(org.pentaho.di.core.logging.JobLogTable) DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) ArrayList(java.util.ArrayList) DataProperty(org.pentaho.platform.api.repository2.unified.data.node.DataProperty) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Aggregations

JobLogTable (org.pentaho.di.core.logging.JobLogTable)15 ChannelLogTable (org.pentaho.di.core.logging.ChannelLogTable)8 JobEntryLogTable (org.pentaho.di.core.logging.JobEntryLogTable)8 JobMeta (org.pentaho.di.job.JobMeta)7 Test (org.junit.Test)5 LogTableInterface (org.pentaho.di.core.logging.LogTableInterface)4 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)4 ArrayList (java.util.ArrayList)3 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)3 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)3 DataNode (org.pentaho.platform.api.repository2.unified.data.node.DataNode)3 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)2 KettleException (org.pentaho.di.core.exception.KettleException)2 KettleJobException (org.pentaho.di.core.exception.KettleJobException)2 KettleValueException (org.pentaho.di.core.exception.KettleValueException)2 Point (org.pentaho.di.core.gui.Point)2 DuplicateParamException (org.pentaho.di.core.parameters.DuplicateParamException)2