public synchronized void registerJob( Job job, JobConfiguration jobConfiguration ) { job.setContainerObjectId( UUID.randomUUID().toString() ); CarteObjectEntry entry = new CarteObjectEntry( job.getJobMeta().getName(), job.getContainerObjectId() ); jobMap.put( entry, job ); configurationMap.put( entry, jobConfiguration ); }
@Override public synchronized void jobDelegationStarted( Job delegatedJob, JobExecutionConfiguration jobExecutionConfiguration ) { JobConfiguration jc = new JobConfiguration( delegatedJob.getJobMeta(), jobExecutionConfiguration ); jobMap.registerJob( delegatedJob, jc ); delegatedJob.addDelegationListener( this ); }
RepositoryDirectoryInterface directory = null; if ( repository != null && specificationMethod.equals( ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME ) && job != null && job.getJobMeta() != null && job.getJobMeta().getRepositoryDirectory() != null ) { directory = job.getJobMeta().getRepositoryDirectory(); } else if ( job != null && repository == null && specificationMethod.equals( ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME ) ) { filename = job.getFilename(); } else if ( job != null && job.getJobMeta() != null && repository != null && specificationMethod.equals( ObjectLocationSpecificationMethod.FILENAME ) ) { directory = job.getJobMeta().getRepositoryDirectory(); } else if ( job != null && filename == null ) { filename = job.getFilename();
private void copyJobParameters( Job job, Map<String, String> params ) throws UnknownParamException { JobMeta jobMeta = job.getJobMeta(); // Also copy the parameters over... job.copyParametersFrom( jobMeta ); job.clearParameters(); String[] parameterNames = job.listParameters(); for ( String parameterName : parameterNames ) { // Grab the parameter value set in the job entry String thisValue = params.get( parameterName ); if ( !StringUtils.isBlank( thisValue ) ) { // Set the value as specified by the user in the job entry jobMeta.setParameterValue( parameterName, thisValue ); } } jobMeta.activateParameters(); }
@Test public void testRunWithException() throws Exception { when( mockJob.isStopped() ).thenReturn( false ); when( mockJob.getParentJob() ).thenReturn( parentJob ); when( mockJob.getJobMeta() ).thenReturn( mockJobMeta ); when( parentJob.isStopped() ).thenReturn( false ); doThrow( KettleException.class ).when( mockJob ).execute( anyInt(), any( Result.class ) ); jobRunner.run(); verify( mockResult, times( 1 ) ).setNrErrors( Mockito.anyInt() ); //[PDI-14981] catch more general exception to prevent thread hanging doThrow( Exception.class ).when( mockJob ).fireJobFinishListeners(); jobRunner.run(); }
private void emergencyWriteJobTracker( Result res ) { JobEntryResult jerFinalResult = new JobEntryResult( res, this.getLogChannelId(), BaseMessages.getString( PKG, "Job.Comment.JobFinished" ), null, null, 0, null ); JobTracker finalTrack = new JobTracker( this.getJobMeta(), jerFinalResult ); // jobTracker is up to date too. this.jobTracker.addJobTracker( finalTrack ); }
@Test public void testRun() throws Exception { // Call all the NO-OP paths when( mockJob.isStopped() ).thenReturn( true ); jobRunner.run(); when( mockJob.isStopped() ).thenReturn( false ); when( mockJob.getParentJob() ).thenReturn( null ); when( mockJob.getJobMeta() ).thenReturn( mockJobMeta ); jobRunner.run(); when( parentJob.isStopped() ).thenReturn( true ); when( mockJob.getParentJob() ).thenReturn( parentJob ); jobRunner.run(); when( parentJob.isStopped() ).thenReturn( false ); when( mockJob.execute( Mockito.anyInt(), Mockito.any( Result.class ) ) ).thenReturn( mockResult ); jobRunner.run(); }
@Test @PrepareForTest( { Encode.class } ) public void testStopJobServletEscapesHtmlWhenTransFound() throws ServletException, IOException { KettleLogStore.init(); HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class ); HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class ); Job mockJob = mock( Job.class ); JobMeta mockJobMeta = mock( JobMeta.class ); LogChannelInterface mockLogChannelInterface = mock( LogChannelInterface.class ); mockJob.setName( ServletTestUtils.BAD_STRING_TO_TEST ); StringWriter out = new StringWriter(); PrintWriter printWriter = new PrintWriter( out ); PowerMockito.spy( Encode.class ); when( mockHttpServletRequest.getContextPath() ).thenReturn( StopJobServlet.CONTEXT_PATH ); when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST ); when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter ); when( mockJobMap.getJob( any( CarteObjectEntry.class ) ) ).thenReturn( mockJob ); when( mockJob.getLogChannelId() ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST ); when( mockJob.getLogChannel() ).thenReturn( mockLogChannelInterface ); when( mockJob.getJobMeta() ).thenReturn( mockJobMeta ); when( mockJobMeta.getMaximum() ).thenReturn( new Point( 10, 10 ) ); stopJobServlet.doGet( mockHttpServletRequest, mockHttpServletResponse ); assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H1", out.toString() ) ) ); PowerMockito.verifyStatic( atLeastOnce() ); Encode.forHtml( anyString() ); } }
@Test @PrepareForTest( { Encode.class } ) public void testRemoveJobServletEscapesHtmlWhenTransFound() throws ServletException, IOException { KettleLogStore.init(); HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class ); HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class ); Job mockJob = mock( Job.class ); JobMeta mockJobMeta = mock( JobMeta.class ); LogChannelInterface mockLogChannelInterface = mock( LogChannelInterface.class ); mockJob.setName( ServletTestUtils.BAD_STRING_TO_TEST ); StringWriter out = new StringWriter(); PrintWriter printWriter = new PrintWriter( out ); PowerMockito.spy( Encode.class ); when( mockHttpServletRequest.getContextPath() ).thenReturn( RemoveJobServlet.CONTEXT_PATH ); when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST ); when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter ); when( mockJobMap.getJob( any( CarteObjectEntry.class ) ) ).thenReturn( mockJob ); when( mockJob.getLogChannelId() ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST ); when( mockJob.getLogChannel() ).thenReturn( mockLogChannelInterface ); when( mockJob.getJobMeta() ).thenReturn( mockJobMeta ); when( mockJobMeta.getMaximum() ).thenReturn( new Point( 10, 10 ) ); removeJobServlet.doGet( mockHttpServletRequest, mockHttpServletResponse ); assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H3", out.toString() ) ) ); PowerMockito.verifyStatic( atLeastOnce() ); Encode.forHtml( anyString() ); } }
@Test @PrepareForTest( { Encode.class } ) public void testStartJobServletEscapesHtmlWhenTransFound() throws ServletException, IOException { KettleLogStore.init(); HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class ); HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class ); Job mockJob = mock( Job.class ); JobMeta mockJobMeta = mock( JobMeta.class ); LogChannelInterface mockLogChannelInterface = mock( LogChannelInterface.class ); mockJob.setName( ServletTestUtils.BAD_STRING_TO_TEST ); StringWriter out = new StringWriter(); PrintWriter printWriter = new PrintWriter( out ); PowerMockito.spy( Encode.class ); when( mockHttpServletRequest.getContextPath() ).thenReturn( StartJobServlet.CONTEXT_PATH ); when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST ); when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter ); when( mockJobMap.getJob( any( CarteObjectEntry.class ) ) ).thenReturn( mockJob ); when( mockJob.getLogChannelId() ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST ); when( mockJob.getLogChannel() ).thenReturn( mockLogChannelInterface ); when( mockJob.getJobMeta() ).thenReturn( mockJobMeta ); when( mockJobMeta.getMaximum() ).thenReturn( new Point( 10, 10 ) ); startJobServlet.doGet( mockHttpServletRequest, mockHttpServletResponse ); assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H1", out.toString() ) ) ); PowerMockito.verifyStatic( atLeastOnce() ); Encode.forHtml( anyString() ); } }
@Test @PrepareForTest( { Encode.class, Job.class } ) public void testGetJobStatusServletEscapesHtmlWhenTransFound() throws ServletException, IOException { KettleLogStore.init(); HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class ); HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class ); Job mockJob = PowerMockito.mock( Job.class ); JobMeta mockJobMeta = mock( JobMeta.class ); LogChannelInterface mockLogChannelInterface = mock( LogChannelInterface.class ); StringWriter out = new StringWriter(); PrintWriter printWriter = new PrintWriter( out ); PowerMockito.spy( Encode.class ); when( mockHttpServletRequest.getContextPath() ).thenReturn( GetJobStatusServlet.CONTEXT_PATH ); when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST ); when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter ); when( mockJobMap.getJob( any( CarteObjectEntry.class ) ) ).thenReturn( mockJob ); PowerMockito.when( mockJob.getJobname() ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST ); PowerMockito.when( mockJob.getLogChannel() ).thenReturn( mockLogChannelInterface ); PowerMockito.when( mockJob.getJobMeta() ).thenReturn( mockJobMeta ); PowerMockito.when( mockJobMeta.getMaximum() ).thenReturn( new Point( 10, 10 ) ); getJobStatusServlet.doGet( mockHttpServletRequest, mockHttpServletResponse ); assertFalse( out.toString().contains( ServletTestUtils.BAD_STRING_TO_TEST ) ); PowerMockito.verifyStatic( atLeastOnce() ); Encode.forHtml( anyString() ); }
@Before public void setUp() throws Exception { job = new Job( null, new JobMeta() ); entry = new JobEntryFolderIsEmpty(); job.getJobMeta().addJobEntry( new JobEntryCopy( entry ) ); entry.setParentJob( job ); JobMeta mockJobMeta = mock( JobMeta.class ); entry.setParentJobMeta( mockJobMeta ); job.setStopped( false ); File dir = Files.createTempDirectory( "dir", new FileAttribute<?>[0] ).toFile(); dir.deleteOnExit(); emptyDir = dir.getPath(); dir = Files.createTempDirectory( "dir", new FileAttribute<?>[0] ).toFile(); dir.deleteOnExit(); nonEmptyDir = dir.getPath(); File file = File.createTempFile( "existingFile", "ext", dir ); file.deleteOnExit(); }
@Test public void recordsCleanUpMethodIsCalled_JobEntryLogTable() throws Exception { JobEntryLogTable jobEntryLogTable = JobEntryLogTable.getDefault( mockedVariableSpace, hasDatabasesInterface ); setAllTableParamsDefault( jobEntryLogTable ); JobMeta jobMeta = new JobMeta( ); jobMeta.setJobEntryLogTable( jobEntryLogTable ); when( mockedJob.getJobMeta() ).thenReturn( jobMeta ); doCallRealMethod().when( mockedJob ).writeJobEntryLogInformation(); mockedJob.writeJobEntryLogInformation(); verify( mockedDataBase ).cleanupLogRecords( jobEntryLogTable ); }
@Override public void callExtensionPoint( LogChannelInterface log, Object object ) throws KettleException { if ( !( object instanceof JobExecutionExtension ) ) { return; } JobExecutionExtension extension = (JobExecutionExtension) object; Job job = extension.job; JobMeta jobMeta = job.getJobMeta(); final EmbeddedMetaStore embeddedMetaStore = jobMeta.getEmbeddedMetaStore(); RunConfigurationManager embeddedRunConfigurationManager = EmbeddedRunConfigurationManager.build( embeddedMetaStore ); //will load and save to meta all run configurations for ( JobEntryTrans trans : job.getActiveJobEntryTransformations().values() ) { RunConfiguration loadedRunConfiguration = runConfigurationManager.load( jobMeta.environmentSubstitute( trans.getRunConfiguration() ) ); embeddedRunConfigurationManager.save( loadedRunConfiguration ); } for ( JobEntryJob subJob : job.getActiveJobEntryJobs().values() ) { RunConfiguration loadedRunConfiguration = runConfigurationManager.load( jobMeta.environmentSubstitute( subJob.getRunConfiguration() ) ); embeddedRunConfigurationManager.save( loadedRunConfiguration ); } }
@Before public void setUp() throws Exception { job = new Job( null, new JobMeta() ); entry = new JobEntryFilesExist(); job.getJobMeta().addJobEntry( new JobEntryCopy( entry ) ); entry.setParentJob( job ); JobMeta mockJobMeta = mock( JobMeta.class ); entry.setParentJobMeta( mockJobMeta ); job.setStopped( false ); existingFile1 = TestUtils.createRamFile( getClass().getSimpleName() + "/existingFile1.ext", entry ); existingFile2 = TestUtils.createRamFile( getClass().getSimpleName() + "/existingFile2.ext", entry ); }
/** * Write job entry log information. * * @throws KettleException * the kettle exception */ protected void writeJobEntryLogInformation() throws KettleException { Database db = null; JobEntryLogTable jobEntryLogTable = getJobMeta().getJobEntryLogTable(); try { db = createDataBase( jobEntryLogTable.getDatabaseMeta() ); db.shareVariablesWith( this ); db.connect(); db.setCommit( logCommitSize ); for ( JobEntryCopy copy : getJobMeta().getJobCopies() ) { db.writeLogRecord( jobEntryLogTable, LogStatus.START, copy, this ); } db.cleanupLogRecords( jobEntryLogTable ); } catch ( Exception e ) { throw new KettleException( BaseMessages.getString( PKG, "Job.Exception.UnableToJobEntryInformationToLogTable" ), e ); } finally { if ( !db.isAutoCommit() ) { db.commitLog( true, jobEntryLogTable ); } db.disconnect(); } }
@Before public void setUp() { Job parentJob = new Job( null, new JobMeta() ); jobEntry = spy( new JobEntryColumnsExist( "" ) ); parentJob.getJobMeta().addJobEntry( new JobEntryCopy( jobEntry ) ); parentJob.setStopped( false ); jobEntry.setParentJob( parentJob ); parentJob.setLogLevel( LogLevel.NOTHING ); DatabaseMeta dbMeta = mock( DatabaseMeta.class ); jobEntry.setDatabase( dbMeta ); db = spy( new Database( jobEntry, dbMeta ) ); jobEntry.setParentJob( parentJob ); jobEntry.setTablename( TABLENAME ); jobEntry.setArguments( COLUMNS ); jobEntry.setSchemaname( SCHEMANAME ); }
@Before public void setUp() throws Exception { job = new Job( null, new JobMeta() ); entry = new JobEntrySetVariables(); job.getJobMeta().addJobEntry( new JobEntryCopy( entry ) ); entry.setParentJob( job ); job.setStopped( false ); }
@Before public void setUp() throws Exception { MockDriver.registerInstance(); Job job = new Job( null, new JobMeta() ); entry = new JobEntryEvalTableContent(); job.getJobMeta().addJobEntry( new JobEntryCopy( entry ) ); entry.setParentJob( job ); job.setStopped( false ); DatabaseMeta dbMeta = new DatabaseMeta(); dbMeta.setDatabaseType( "mock-db" ); entry.setDatabase( dbMeta ); }
@Before public void setUp() throws Exception { job = new Job( null, new JobMeta() ); entry = new MockedJobEntryFTP(); job.getJobMeta().addJobEntry( new JobEntryCopy( entry ) ); entry.setParentJob( job ); job.setStopped( false ); entry.setServerName( "some.server" ); entry.setUserName( "anonymous" ); entry.setFtpDirectory( "." ); entry.setWildcard( "robots.txt" ); entry.setBinaryMode( false ); entry.setSuccessCondition( "success_if_no_errors" ); existingDir = TestUtils.createTempDir(); }