@Override public void rowWrittenEvent( RowMetaInterface rowMeta, Object[] row ) throws KettleStepException { trans.safeStop(); } } );
@GET @Path( "/safeStop/{id : .+}" ) @Produces( { MediaType.APPLICATION_JSON } ) public TransformationStatus safeStopTransformation( @PathParam( "id" ) String id ) { CarteResource.getTransformation( id ).safeStop(); return getTransformationStatus( id ); }
public void safeStop() { if ( running && !halting ) { halting = true; safeStopping = true; trans.safeStop(); log.logMinimal( BaseMessages.getString( PKG, "TransLog.Log.TransformationSafeStopped" ) ); initialized = false; halted = false; setControlStates(); transMeta.setInternalKettleVariables(); // set the original vars back as they may be changed by a mapping } }
@Override public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException { Preconditions.checkArgument( first, BaseMessages.getString( PKG, "BaseStreamStep.ProcessRowsError" ) ); Preconditions.checkNotNull( source ); Preconditions.checkNotNull( window ); try { source.open(); bufferStream().forEach( result -> { if ( result.isSafeStop() ) { getTrans().safeStop(); } putRows( result.getRows() ); } ); super.setOutputDone(); } finally { // Needed for when an Abort Step is used. source.close(); } return false; }
@Test @PrepareForTest( { Encode.class } ) public void testWillStopInputStepsOnly() throws ServletException, IOException { KettleLogStore.init(); HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class ); HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class ); Trans mockTrans = mock( Trans.class ); TransMeta mockTransMeta = mock( TransMeta.class ); LogChannelInterface mockChannelInterface = mock( LogChannelInterface.class ); StringWriter out = new StringWriter(); PrintWriter printWriter = new PrintWriter( out ); when( mockHttpServletRequest.getContextPath() ).thenReturn( StopTransServlet.CONTEXT_PATH ); when( mockHttpServletRequest.getParameter( "inputOnly" ) ).thenReturn( "Y" ); when( mockHttpServletRequest.getParameter( "name" ) ).thenReturn( "test" ); when( mockHttpServletRequest.getParameter( "id" ) ).thenReturn( "123" ); when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter ); when( mockTransformationMap.getTransformation( any( CarteObjectEntry.class ) ) ).thenReturn( mockTrans ); when( mockTrans.getLogChannel() ).thenReturn( mockChannelInterface ); when( mockTrans.getLogChannelId() ).thenReturn( "test" ); when( mockTrans.getTransMeta() ).thenReturn( mockTransMeta ); stopTransServlet.doGet( mockHttpServletRequest, mockHttpServletResponse ); Mockito.verify( mockTrans ).safeStop(); } }
@Test public void safeStopStopsInputStepsRightAway() throws KettleException { trans.setSteps( of( combi( stepMock, data, stepMeta ) ) ); when( transMeta.findPreviousSteps( stepMeta, true ) ).thenReturn( emptyList() ); trans.transMeta = transMeta; trans.safeStop(); verifyStopped( stepMock, 1 ); }
@Test public void safeLetsNonInputStepsKeepRunning() throws KettleException { trans.setSteps( of( combi( stepMock, data, stepMeta ), combi( stepMock2, data2, stepMeta2 ) ) ); when( transMeta.findPreviousSteps( stepMeta, true ) ).thenReturn( emptyList() ); // stepMeta2 will have stepMeta as previous, so is not an input step when( transMeta.findPreviousSteps( stepMeta2, true ) ).thenReturn( of( stepMeta ) ); trans.transMeta = transMeta; trans.safeStop(); verifyStopped( stepMock, 1 ); // non input step shouldn't have stop called verifyStopped( stepMock2, 0 ); }
trans.safeStop(); } else { trans.stopAll();
@Test public void testSafeStop() throws Exception { prepareOneRowForExecutor(); meta.setGroupSize( "1" ); data.groupSize = 1; internalResult.setSafeStop( true ); executor.init( meta, data ); executor.setInputRowMeta( new RowMeta() ); assertTrue( executor.processRow( meta, data ) ); verify( executor.getTrans() ).safeStop(); verify( executor.getTrans(), never() ).stopAll(); }
@Test public void testAbortWithError() throws Exception { prepareOneRowForExecutor(); meta.setGroupSize( "1" ); data.groupSize = 1; internalResult.setSafeStop( false ); internalResult.setNrErrors( 1 ); executor.init( meta, data ); executor.setInputRowMeta( new RowMeta() ); assertTrue( executor.processRow( meta, data ) ); verify( executor.getTrans(), never() ).safeStop(); verify( executor.getTrans(), never() ).stopAll(); } }
getTrans().safeStop(); } else { if ( meta.isAbortWithError() ) {
getTrans().safeStop();