/** * Uses a trans variable called "engine" to determine which engine to use. */ private Predicate<PluginInterface> useThisEngine() { return plugin -> Arrays.stream( plugin.getIds() ) .filter( id -> id.equals( ( transMeta.getVariable( "engine" ) ) ) ) .findAny() .isPresent(); }
public int getFlushInterval( ) { String var = getTransMeta().getVariable( "KETTLE_FILE_OUTPUT_MAX_STREAM_LIFE" ); int flushInterval = 0; if ( var != null ) { try { flushInterval = Integer.parseInt( var ); } catch ( Exception ex ) { // Do nothing } } return flushInterval; }
public int getMaxOpenFiles( ) { String var = getTransMeta().getVariable( "KETTLE_FILE_OUTPUT_MAX_STREAM_COUNT" ); int maxStreamCount = 0; if ( var != null ) { try { maxStreamCount = Integer.parseInt( var ); } catch ( Exception ex ) { // Do nothing } } return maxStreamCount; }
/** * Gets the size of the rowsets. * * @return Returns the size of the rowsets. */ public int getSizeRowset() { String rowSetSize = getVariable( Const.KETTLE_TRANS_ROWSET_SIZE ); int altSize = Const.toInt( rowSetSize, 0 ); if ( altSize > 0 ) { return altSize; } else { return sizeRowset; } }
/** * Creates the appropriate trans. Either * 1) A {@link TransWebSocketEngineAdapter} wrapping an Engine * if an alternate execution engine has been selected * 2) A legacy {@link Trans} otherwise. */ public Trans get() { if ( Utils.isEmpty( transMeta.getVariable( "engine" ) ) ) { log.logBasic( "Using legacy execution engine" ); return fallbackSupplier.get(); } Variables variables = new Variables(); variables.initializeVariablesFrom( null ); String protocol = transMeta.getVariable( "engine.protocol" ); String host = transMeta.getVariable( "engine.host" ); String port = transMeta.getVariable( "engine.port" ); //default value for ssl for now false boolean ssl = "https".equalsIgnoreCase( protocol ) || "wss".equalsIgnoreCase( protocol ); return new TransWebSocketEngineAdapter( transMeta, host, port, ssl ); }
public void getUsedVariables( TransMeta transMeta ) { Properties sp = new Properties(); VariableSpace space = Variables.getADefaultVariableSpace(); String[] keys = space.listVariables(); for ( int i = 0; i < keys.length; i++ ) { sp.put( keys[i], space.getVariable( keys[i] ) ); } List<String> vars = transMeta.getUsedVariables(); if ( vars != null && vars.size() > 0 ) { HashMap<String, String> newVariables = new HashMap<String, String>(); for ( int i = 0; i < vars.size(); i++ ) { String varname = vars.get( i ); if ( !varname.startsWith( Const.INTERNAL_VARIABLE_PREFIX ) ) { newVariables.put( varname, Const.NVL( variables.get( varname ), sp.getProperty( varname, "" ) ) ); } } // variables.clear(); variables.putAll( newVariables ); } // Also add the internal job variables if these are set... // for ( String variableName : Const.INTERNAL_JOB_VARIABLES ) { String value = transMeta.getVariable( variableName ); if ( !Utils.isEmpty( value ) ) { variables.put( variableName, value ); } } }
public void getAllVariables( TransMeta transMeta ) { Properties sp = new Properties(); VariableSpace space = Variables.getADefaultVariableSpace(); String[] keys = space.listVariables(); for ( int i = 0; i < keys.length; i++ ) { sp.put( keys[i], space.getVariable( keys[i] ) ); } String[] vars = transMeta.listVariables(); if ( vars != null && vars.length > 0 ) { HashMap<String, String> newVariables = new HashMap<String, String>(); for ( int i = 0; i < vars.length; i++ ) { String varname = vars[i]; newVariables.put( varname, Const.NVL( variables.get( varname ), sp.getProperty( varname, "" ) ) ); } // variables.clear(); variables.putAll( newVariables ); } // Also add the internal job variables if these are set... // for ( String variableName : Const.INTERNAL_JOB_VARIABLES ) { String value = transMeta.getVariable( variableName ); if ( !Utils.isEmpty( value ) ) { variables.put( variableName, value ); } } }
@Test public void testWebsocketVersion() throws KettleException { props.setProperty( "KETTLE_AEL_PDI_DAEMON_VERSION", "2.0" ); when( meta.getVariable( "engine" ) ).thenReturn( "spark" ); when( meta.getVariable( "engine.host" ) ).thenReturn( "hostname" ); when( meta.getVariable( "engine.port" ) ).thenReturn( "8080" ); when( meta.nrTransHops() ).thenReturn( 0 ); when( meta.getTransHop( 0 ) ).thenReturn( transHopMeta ); when( meta.realClone( false ) ).thenReturn( meta ); when( transHopMeta.isEnabled() ).thenReturn( false ); transSupplier = new TransSupplier( meta, log, fallbackSupplier ); Trans transRet = transSupplier.get(); assertTrue( transRet instanceof TransWebSocketEngineAdapter ); }
@Test( expected = RuntimeException.class ) public void testInvalidEngine() throws KettleException { props.setProperty( "KETTLE_AEL_PDI_DAEMON_VERSION", "1.0" ); when( meta.getVariable( "engine" ) ).thenReturn( "invalidEngine" ); transSupplier = new TransSupplier( meta, log, fallbackSupplier ); transSupplier.get(); } }
@Test public void testNewTransformationsWithContainerObjectId() throws Exception { TransMeta meta = mock( TransMeta.class ); doReturn( new String[] { "X", "Y", "Z" } ).when( meta ).listVariables(); doReturn( new String[] { "A", "B", "C" } ).when( meta ).listParameters(); doReturn( "XYZ" ).when( meta ).getVariable( anyString() ); doReturn( "" ).when( meta ).getParameterDescription( anyString() ); doReturn( "" ).when( meta ).getParameterDefault( anyString() ); doReturn( "ABC" ).when( meta ).getParameterValue( anyString() ); String carteId = UUID.randomUUID().toString(); doReturn( carteId ).when( meta ).getContainerObjectId(); Trans trans = new Trans( meta ); assertEquals( carteId, trans.getContainerObjectId() ); }
/** * This test demonstrates the issue fixed in PDI-17436. * When a job is scheduled twice, it gets the same log channel Id and both logs get merged */ @Test public void testTwoTransformationsGetSameLogChannelId() throws Exception { TransMeta meta = mock( TransMeta.class ); doReturn( new String[] { "X", "Y", "Z" } ).when( meta ).listVariables(); doReturn( new String[] { "A", "B", "C" } ).when( meta ).listParameters(); doReturn( "XYZ" ).when( meta ).getVariable( anyString() ); doReturn( "" ).when( meta ).getParameterDescription( anyString() ); doReturn( "" ).when( meta ).getParameterDefault( anyString() ); doReturn( "ABC" ).when( meta ).getParameterValue( anyString() ); Trans trans1 = new Trans( meta ); Trans trans2 = new Trans( meta ); assertEquals( trans1.getLogChannelId(), trans2.getLogChannelId() ); }
/** * This test demonstrates the fix for PDI-17436. * Two schedules -> two Carte object Ids -> two log channel Ids */ @Test public void testTwoTransformationsGetDifferentLogChannelIdWithDifferentCarteId() throws Exception { TransMeta meta1 = mock( TransMeta.class ); doReturn( new String[] { "X", "Y", "Z" } ).when( meta1 ).listVariables(); doReturn( new String[] { "A", "B", "C" } ).when( meta1 ).listParameters(); doReturn( "XYZ" ).when( meta1 ).getVariable( anyString() ); doReturn( "" ).when( meta1 ).getParameterDescription( anyString() ); doReturn( "" ).when( meta1 ).getParameterDefault( anyString() ); doReturn( "ABC" ).when( meta1 ).getParameterValue( anyString() ); TransMeta meta2 = mock( TransMeta.class ); doReturn( new String[] { "X", "Y", "Z" } ).when( meta2 ).listVariables(); doReturn( new String[] { "A", "B", "C" } ).when( meta2 ).listParameters(); doReturn( "XYZ" ).when( meta2 ).getVariable( anyString() ); doReturn( "" ).when( meta2 ).getParameterDescription( anyString() ); doReturn( "" ).when( meta2 ).getParameterDefault( anyString() ); doReturn( "ABC" ).when( meta2 ).getParameterValue( anyString() ); String carteId1 = UUID.randomUUID().toString(); String carteId2 = UUID.randomUUID().toString(); doReturn( carteId1 ).when( meta1 ).getContainerObjectId(); doReturn( carteId2 ).when( meta2 ).getContainerObjectId(); Trans trans1 = new Trans( meta1 ); Trans trans2 = new Trans( meta2 ); assertNotEquals( trans1.getContainerObjectId(), trans2.getContainerObjectId() ); assertNotEquals( trans1.getLogChannelId(), trans2.getLogChannelId() ); }
doReturn( "1" ).when( transMeta ).getVariable( Const.INTERNAL_VARIABLE_SLAVE_SERVER_NUMBER ); doReturn( "2" ).when( transMeta ).getVariable( Const.INTERNAL_VARIABLE_CLUSTER_SIZE ); doReturn( "Y" ).when( transMeta ).getVariable( Const.INTERNAL_VARIABLE_CLUSTER_MASTER ); doReturn( stepMeta ).when( transMeta ).findStep( STEP_NAME );
@Test @PrepareForTest( StepWithMappingMeta.class ) public void loadMappingMetaTest_PathShouldBeTakenFromParentTrans() throws Exception { String fileName = "subtrans-executor-sub.ktr"; Path parentFolder = Paths.get( getClass().getResource( "subtrans-executor-sub.ktr" ).toURI() ).getParent(); //we have transformation VariableSpace variables = new Variables(); variables.setVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY, parentFolder.toString() ); TransMeta parentTransMeta = new TransMeta( variables ); //we have step in this transformation StepMeta stepMeta = new StepMeta(); stepMeta.setParentTransMeta( parentTransMeta ); //attach the executor to step which was described above StepWithMappingMeta mappingMetaMock = mock( StepWithMappingMeta.class ); when( mappingMetaMock.getSpecificationMethod() ).thenReturn( ObjectLocationSpecificationMethod.FILENAME ); when( mappingMetaMock.getFileName() ).thenReturn( "${" + Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY + "}/" + fileName ); when( mappingMetaMock.getParentStepMeta() ).thenReturn( stepMeta ); //we will try to load the subtras which was linked at the step metas TransMeta transMeta = StepWithMappingMeta.loadMappingMeta( mappingMetaMock, null, null, variables, true ); StringBuilder expected = new StringBuilder( parentFolder.toUri().toString() ); /** * we need to remove "/" at the end of expected string because during load the trans from file * internal variables will be replaced by uri from kettle vfs * check the follow points * {@link org.pentaho.di.trans.TransMeta#setInternalFilenameKettleVariables(VariableSpace)} * */ Assert.assertEquals( expected.deleteCharAt( expected.length() - 1 ).toString(), transMeta.getVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY ) ); }
@Test public void testSetInternalEntryCurrentDirectoryWithRepository( ) { TransMeta transMetaTest = new TransMeta( ); RepositoryDirectoryInterface path = mock( RepositoryDirectoryInterface.class ); when( path.getPath() ).thenReturn( "aPath" ); transMetaTest.setRepository( mock( Repository.class ) ); transMetaTest.setRepositoryDirectory( path ); transMetaTest.setVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY, "Original value defined at run execution" ); transMetaTest.setVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_DIRECTORY, "file:///C:/SomeFilenameDirectory" ); transMetaTest.setVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_REPOSITORY_DIRECTORY, "/SomeRepDirectory" ); transMetaTest.setInternalEntryCurrentDirectory(); assertEquals( "/SomeRepDirectory", transMetaTest.getVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY ) ); }
@Test @PrepareForTest( StepWithMappingMeta.class ) public void activateParamsTest() throws Exception { String childParam = "childParam"; String childValue = "childValue"; String paramOverwrite = "paramOverwrite"; String parentValue = "parentValue"; String stepValue = "stepValue"; VariableSpace parent = new Variables(); parent.setVariable( paramOverwrite, parentValue ); TransMeta childVariableSpace = new TransMeta(); childVariableSpace.addParameterDefinition( childParam, "", "" ); childVariableSpace.setParameterValue( childParam, childValue ); String[] parameters = childVariableSpace.listParameters(); StepWithMappingMeta.activateParams( childVariableSpace, childVariableSpace, parent, parameters, new String[] { childParam, paramOverwrite }, new String[] { childValue, stepValue } ); Assert.assertEquals( childValue, childVariableSpace.getVariable( childParam ) ); // the step parameter prevails Assert.assertEquals( stepValue, childVariableSpace.getVariable( paramOverwrite ) ); }
@Test @PrepareForTest( StepWithMappingMeta.class ) public void activateParamsWithFalsePassParametersFlagTest() throws Exception { String childParam = "childParam"; String childValue = "childValue"; String paramOverwrite = "paramOverwrite"; String parentValue = "parentValue"; String stepValue = "stepValue"; String parentAndChildParameter = "parentAndChildParameter"; VariableSpace parent = new Variables(); parent.setVariable( paramOverwrite, parentValue ); parent.setVariable( parentAndChildParameter, parentValue ); TransMeta childVariableSpace = new TransMeta(); childVariableSpace.addParameterDefinition( childParam, "", "" ); childVariableSpace.setParameterValue( childParam, childValue ); childVariableSpace.addParameterDefinition( parentAndChildParameter, "", "" ); childVariableSpace.setParameterValue( parentAndChildParameter, childValue ); String[] parameters = childVariableSpace.listParameters(); StepWithMappingMeta.activateParams( childVariableSpace, childVariableSpace, parent, parameters, new String[] { childParam, paramOverwrite }, new String[] { childValue, stepValue }, false ); Assert.assertEquals( childValue, childVariableSpace.getVariable( childParam ) ); // the step parameter prevails Assert.assertEquals( stepValue, childVariableSpace.getVariable( paramOverwrite ) ); Assert.assertEquals( childValue, childVariableSpace.getVariable( parentAndChildParameter ) ); }
@Test @PrepareForTest( StepWithMappingMeta.class ) public void activateParamsWithTruePassParametersFlagTest() throws Exception { String childParam = "childParam"; String childValue = "childValue"; String paramOverwrite = "paramOverwrite"; String parentValue = "parentValue"; String stepValue = "stepValue"; String parentAndChildParameter = "parentAndChildParameter"; VariableSpace parent = new Variables(); parent.setVariable( paramOverwrite, parentValue ); parent.setVariable( parentAndChildParameter, parentValue ); TransMeta childVariableSpace = new TransMeta(); childVariableSpace.addParameterDefinition( childParam, "", "" ); childVariableSpace.setParameterValue( childParam, childValue ); childVariableSpace.addParameterDefinition( parentAndChildParameter, "", "" ); childVariableSpace.setParameterValue( parentAndChildParameter, childValue ); String[] parameters = childVariableSpace.listParameters(); StepWithMappingMeta.activateParams( childVariableSpace, childVariableSpace, parent, parameters, new String[] { childParam, paramOverwrite }, new String[] { childValue, stepValue }, true ); //childVariableSpace.setVariable( parentAndChildParameter, parentValue); Assert.assertEquals( childValue, childVariableSpace.getVariable( childParam ) ); // the step parameter prevails Assert.assertEquals( stepValue, childVariableSpace.getVariable( paramOverwrite ) ); Assert.assertEquals( parentValue, childVariableSpace.getVariable( parentAndChildParameter ) ); }
@Test public void testSetInternalEntryCurrentDirectoryWithoutFilenameOrRepository( ) { TransMeta transMetaTest = new TransMeta( ); transMetaTest.setVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY, "Original value defined at run execution" ); transMetaTest.setVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_DIRECTORY, "file:///C:/SomeFilenameDirectory" ); transMetaTest.setVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_REPOSITORY_DIRECTORY, "/SomeRepDirectory" ); transMetaTest.setInternalEntryCurrentDirectory(); assertEquals( "Original value defined at run execution", transMetaTest.getVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY ) ); } }
@Test public void testSetInternalEntryCurrentDirectoryWithFilename( ) { TransMeta transMetaTest = new TransMeta( ); transMetaTest.setFilename( "hasFilename" ); transMetaTest.setVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY, "Original value defined at run execution" ); transMetaTest.setVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_FILENAME_DIRECTORY, "file:///C:/SomeFilenameDirectory" ); transMetaTest.setVariable( Const.INTERNAL_VARIABLE_TRANSFORMATION_REPOSITORY_DIRECTORY, "/SomeRepDirectory" ); transMetaTest.setInternalEntryCurrentDirectory(); assertEquals( "file:///C:/SomeFilenameDirectory", transMetaTest.getVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY ) ); }