public Result getResult() { return trans.getResult(); }
@Before public void beforeTest() throws KettleException { meta = new TransMeta(); trans = new Trans( meta ); trans.setLog( Mockito.mock( LogChannelInterface.class ) ); trans.prepareExecution( null ); trans.startThreads(); }
public Optional<Result> execute( List<RowMetaAndData> rows ) throws KettleException { if ( rows.isEmpty() || stopped ) { return Optional.empty(); } Trans subtrans = this.createSubtrans(); running.add( subtrans ); parentTrans.addActiveSubTransformation( subTransName, subtrans ); // Pass parameter values passParametersToTrans( subtrans, rows.get( 0 ) ); Result result = new Result(); result.setRows( rows ); subtrans.setPreviousResult( result ); subtrans.prepareExecution( this.parentTrans.getArguments() ); List<RowMetaAndData> rowMetaAndData = new ArrayList<>(); subtrans.getSteps().stream() .filter( c -> c.step.getStepname().equalsIgnoreCase( subStep ) ) .findFirst() .ifPresent( c -> c.step.addRowListener( new RowAdapter() { @Override public void rowWrittenEvent( RowMetaInterface rowMeta, Object[] row ) { rowMetaAndData.add( new RowMetaAndData( rowMeta, row ) ); } } ) ); subtrans.startThreads(); subtrans.waitUntilFinished(); updateStatuses( subtrans ); running.remove( subtrans ); Result subtransResult = subtrans.getResult(); subtransResult.setRows( rowMetaAndData ); return Optional.of( subtransResult ); }
protected void executeTrans( Trans trans ) throws KettleException { trans.prepareExecution( null ); trans.startThreads(); trans.waitUntilFinished(); }
/** * Executes the transformation. This method will prepare the transformation for execution and then start all the * threads associated with the transformation and its steps. * * @param arguments the arguments * @throws KettleException if the transformation could not be prepared (initialized) */ public void execute( String[] arguments ) throws KettleException { prepareExecution( arguments ); startThreads(); }
private void waitUntilFinished( Trans trans, final long waitMillis ) { if ( trans != null && trans.isRunning() ) { trans.waitUntilFinished(); for ( int i = 0; i < 100; i++ ) { if ( !trans.isRunning() ) { break; } try { Thread.sleep( waitMillis ); } catch ( Exception e ) { break; } } } } }
VariableSpace runTimeVariables, VariableSpace runTimeParameters ) throws KettleException { Trans trans = new Trans( transMeta ); trans.initializeVariablesFrom( runTimeVariables ); if ( runTimeParameters != null ) { for ( String param : trans.listParameters() ) { String value = runTimeParameters.getVariable( param ); if ( value != null ) { trans.setParameterValue( param, value ); transMeta.setParameterValue( param, value ); trans.prepareExecution( null ); StepInterface si = trans.getStepInterface( dummyStepname, 0 ); RowStepCollector dummyRc = new RowStepCollector(); si.addRowListener( dummyRc ); RowProducer rp = trans.addRowProducer( injectorStepname, 0 ); trans.startThreads(); trans.waitUntilFinished(); if ( trans.getResult().getNrErrors() > 0 ) { throw new KettleException( "Test transformation finished with errors. Check the log." );
singleThreaderData.mappingTrans = new Trans( singleThreaderData.mappingTransMeta, getTrans() ); .activateParams( getData().mappingTrans, getData().mappingTrans, this, getData().mappingTrans.listParameters(), meta.getParameters(), meta.getParameterValues() ); getData().mappingTrans.activateParameters(); singleThreaderData.mappingTrans.getTransMeta().setUsingThreadPriorityManagment( false ); singleThreaderData.mappingTrans.setParentTrans( getTrans() ); singleThreaderData.mappingTrans.setSafeModeEnabled( getTrans().isSafeModeEnabled() ); singleThreaderData.mappingTrans.setGatheringMetrics( getTrans().isGatheringMetrics() ); singleThreaderData.mappingTrans.setMappingStepName( getStepname() ); singleThreaderData.mappingTrans.prepareExecution( null ); (MappingInputData) singleThreaderData.mappingTrans.findDataInterface( singleThreaderData.injectStepMeta.getName() ); mappingInputData.sourceSteps = new StepInterface[0]; mappingInputData.valueRenames = new ArrayList<MappingValueRename>(); singleThreaderData.rowProducer = singleThreaderData.mappingTrans.addRowProducer( meta.getInjectStep(), 0 ); StepInterface retrieveStep = singleThreaderData.mappingTrans.getStepInterface( meta.getRetrieveStep(), 0 ); retrieveStep.addRowListener( new RowAdapter() { @Override singleThreaderData.mappingTrans.startThreads();
List<RowMetaAndData> inputData ) throws KettleException { Trans trans = new Trans( transMeta ); trans.prepareExecution( null ); StepInterface si = trans.getStepInterface( dummyStepname, 0 ); RowStepCollector dummyRc = new RowStepCollector(); si.addRowListener( dummyRc ); StepInterface junit = trans.getStepInterface( testStepname, 0 ); RowStepCollector dummyJu = new RowStepCollector(); junit.addRowListener( dummyJu ); StepInterface er = trans.getStepInterface( errorStepName, 0 ); RowStepCollector erColl = new RowStepCollector(); er.addRowListener( erColl ); RowProducer rp = trans.addRowProducer( injectorStepname, 0 ); trans.startThreads(); trans.waitUntilFinished(); if ( trans.getResult().getNrErrors() > 0 ) { throw new KettleException( "Test transformation finished with errors. Check the log." );
Trans transformation = new Trans( transMeta ); transformation.setLogLevel( LogLevel.MINIMAL ); transformation.prepareExecution( new String[0] ); StepInterface step = transformation.getStepInterface( "output", 0 ); transformation.startThreads(); transformation.waitUntilFinished(); Result result = transformation.getResult();
getTrans().addActiveSubTransformation( getStepname(), executorTrans ); executorTrans.setPreviousResult( result ); executorTrans.prepareExecution( getTrans().getArguments() ); executorTrans.startThreads(); for ( DelegationListener delegationListener : getTrans().getDelegationListeners() ) { executorTrans.waitUntilFinished(); result = executorTrans.getResult(); } catch ( KettleException e ) { log.logError( "An error occurred executing the transformation: ", e ); getTrans().safeStop();
@Before public void setUp() throws Exception { executor = StepMockUtil.getStep( TransExecutor.class, TransExecutorMeta.class, "TransExecutorUnitTest" ); executor = spy( executor ); TransMeta internalTransMeta = mock( TransMeta.class ); doReturn( internalTransMeta ).when( executor ).loadExecutorTransMeta(); internalTrans = spy( new Trans() ); internalTrans.setLog( mock( LogChannelInterface.class ) ); doNothing().when( internalTrans ).prepareExecution( any( String[].class ) ); doNothing().when( internalTrans ).startThreads(); doNothing().when( internalTrans ).waitUntilFinished(); doNothing().when( executor ).discardLogLines( any( TransExecutorData.class ) ); doReturn( internalTrans ).when( executor ).createInternalTrans(); internalResult = new Result(); doReturn( internalResult ).when( internalTrans ).getResult(); meta = new TransExecutorMeta(); data = new TransExecutorData(); }
injectTrans.setParentTrans( getTrans() ); injectTrans.setMetaStore( getMetaStore() ); if ( getTrans().getParentJob() != null ) { injectTrans.setParentJob( getTrans().getParentJob() ); // See PDI-13224 getTrans().addTransStoppedListener( new TransStoppedListener() { public void transStopped( Trans parentTrans ) { injectTrans.stopAll(); injectTrans.prepareExecution( null ); rowProducer = injectTrans.addRowProducer( data.streamingTargetStepname, 0 ); getTrans().addActiveSubTransformation( getStepname(), injectTrans ); StepInterface stepInterface = injectTrans.getStepInterface( meta.getSourceStepName(), 0 ); if ( stepInterface == null ) { throw new KettleException( "Unable to find step '" + meta.getSourceStepName() + "' to read from." ); injectTrans.startThreads(); while ( !injectTrans.isFinished() && !injectTrans.isStopped() && !isStopped() ) { copyResult( injectTrans );
final Trans trans = new Trans( previewTransMeta ); trans.prepareExecution( null ); StepInterface step = trans.getRunThread( stepname, 0 ); step.addRowListener( new RowAdapter() { @Override trans.startThreads(); trans.waitUntilFinished(); if ( trans.getErrors() > 0 ) { StringBuffer log = KettleLogStore.getAppender().getBuffer( trans.getLogChannelId(), false ); buffer.append( log ); KettleLogStore.discardLines( trans.getLogChannelId(), false ); LoggingRegistry.getInstance().removeIncludingChildren( trans.getLogChannelId() );
String message; if ( isRunning() ) { if ( isStopped() ) { message = STRING_HALTING; } else { if ( isPaused() ) { message = STRING_PAUSED; } else { } else if ( isFinished() ) { message = STRING_FINISHED; if ( getResult().getNrErrors() > 0 ) { message += " (with errors)"; } else if ( isStopped() ) { message = STRING_STOPPED; } else if ( isPreparing() ) { message = STRING_PREPARING; } else if ( isInitializing() ) { message = STRING_INITIALIZING; } else {
@Test public void doesNotWriteRowOnTimeWhenStopped() throws KettleException, InterruptedException { TransMeta transMeta = new TransMeta( getClass().getResource( "safe-stop.ktr" ).getPath() ); Trans trans = new Trans( transMeta ); trans.prepareExecution( new String[] {} ); trans.getSteps().get( 1 ).step.addRowListener( new RowAdapter() { @Override public void rowWrittenEvent( RowMetaInterface rowMeta, Object[] row ) throws KettleStepException { trans.safeStop(); } } ); trans.startThreads(); trans.waitUntilFinished(); assertEquals( 1, trans.getSteps().get( 0 ).step.getLinesWritten() ); assertEquals( 1, trans.getSteps().get( 1 ).step.getLinesRead() ); } }
TransPreviewFactory.generatePreviewTransformation( null, (StepMetaInterface) meta, "data_sync" ); final Trans trans = new Trans( previewMeta ); trans.prepareExecution( null ); trans.startThreads(); while ( !trans.isFinished() ) { trans.stopAll();
@VisibleForTesting Trans createInternalTrans() throws KettleException { Trans executorTrans = new Trans( getData().getExecutorTransMeta(), this ); executorTrans.setParentTrans( getTrans() ); executorTrans.setRepository( getTrans().getRepository() ); executorTrans.setLogLevel( getLogLevel() ); executorTrans.setArguments( getTrans().getArguments() ); executorTrans.setInternalKettleVariables( this ); executorTrans.setPreview( getTrans().isPreview() ); TransStepUtil.initServletConfig( getTrans(), executorTrans ); return executorTrans; }
/** * PDI-14948 - Execution of trans with no steps never ends */ @Test ( timeout = 1000 ) public void transWithNoStepsIsNotEndless() throws Exception { Trans transWithNoSteps = new Trans( new TransMeta() ); transWithNoSteps = spy( transWithNoSteps ); transWithNoSteps.prepareExecution( new String[] {} ); transWithNoSteps.startThreads(); // check trans lifecycle is not corrupted verify( transWithNoSteps ).fireTransStartedListeners(); verify( transWithNoSteps ).fireTransFinishedListeners(); }
public void dispose( StepMetaInterface smi, StepDataInterface sdi ) { // Close the running transformation if ( getData().wasStarted ) { if ( !getData().mappingTrans.isFinished() ) { // Wait until the child transformation has finished. getData().mappingTrans.waitUntilFinished(); } // Remove it from the list of active sub-transformations... // getTrans().removeActiveSubTransformation( getStepname() ); // See if there was an error in the sub-transformation, in that case, flag error etc. if ( getData().mappingTrans.getErrors() > 0 ) { logError( BaseMessages.getString( PKG, "SimpleMapping.Log.ErrorOccurredInSubTransformation" ) ); setErrors( 1 ); } } super.dispose( smi, sdi ); }