├── .gitattributes ├── .github └── CODEOWNERS ├── .gitignore ├── README.md ├── kettle-sdk-database-plugin ├── .gitignore ├── demo_transform │ ├── demo_database.ktr │ └── small_dataset.csv ├── pom.xml └── src │ ├── main │ ├── assembly │ │ └── assembly.xml │ └── java │ │ └── org │ │ └── pentaho │ │ └── di │ │ └── sdk │ │ └── samples │ │ └── databases │ │ └── demo │ │ └── DemoDatabaseMeta.java │ └── test │ └── java │ └── org │ └── pentaho │ └── di │ └── sdk │ └── samples │ └── databases │ └── demo │ ├── DemoDatabaseMetaTest.java │ └── DemoDatabaseTest.java ├── kettle-sdk-embedding-samples ├── .gitignore ├── etl │ ├── capturing_rows.ktr │ ├── parameterized_job.kjb │ └── parameterized_transformation.ktr ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── pentaho │ │ └── di │ │ └── sdk │ │ └── samples │ │ ├── carte │ │ ├── AbstractSample.java │ │ ├── AllocateServerSocketSample.java │ │ ├── CleanupTransSample.java │ │ ├── ExecuteTransSample.java │ │ ├── GetJobImageSample.java │ │ ├── GetJobStatusSample.java │ │ ├── GetSlavesSample.java │ │ ├── GetStatusSample.java │ │ ├── GetTransImageSample.java │ │ ├── GetTransStatusSample.java │ │ ├── ListServerSocketSample.java │ │ ├── NextSequenceSample.java │ │ ├── PauseTransSample.java │ │ ├── PrepareExecutionTransSample.java │ │ ├── RegisterJobSample.java │ │ ├── RegisterPackageSample.java │ │ ├── RegisterSlaveSample.java │ │ ├── RegisterTransSample.java │ │ ├── RemoveJobSample.java │ │ ├── RemoveTransSample.java │ │ ├── RunJobSample.java │ │ ├── RunTransSample.java │ │ ├── SniffStepSample.java │ │ ├── StartExecutionTransSample.java │ │ ├── StartJobSample.java │ │ ├── StartTransSample.java │ │ ├── StopJobSample.java │ │ └── StopTransSample.java │ │ └── embedding │ │ ├── CapturingTransformationRows.java │ │ ├── GeneratingJobs.java │ │ ├── GeneratingTransformations.java │ │ ├── RunningJobs.java │ │ └── RunningTransformations.java │ └── test │ └── java │ └── org │ └── pentaho │ └── di │ └── sdk │ └── samples │ ├── carte │ ├── BaseCarteServletTest.java │ ├── GetStatusSampleTest.java │ ├── JobServletsTest.java │ └── TransServletsTest.java │ └── embedding │ ├── CapturingTransformationRowsTest.java │ ├── GeneratingJobsTest.java │ ├── GeneratingTransformationsTest.java │ ├── RunningJobsTest.java │ └── RunningTransformationsTest.java ├── kettle-sdk-jobentry-plugin ├── .classpath ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── assembly │ │ └── assembly.xml │ ├── java │ │ └── org │ │ │ └── pentaho │ │ │ └── di │ │ │ └── sdk │ │ │ └── samples │ │ │ └── jobentries │ │ │ └── demo │ │ │ ├── JobEntryDemo.java │ │ │ └── JobEntryDemoDialog.java │ └── resources │ │ └── org │ │ └── pentaho │ │ └── di │ │ └── sdk │ │ └── samples │ │ └── jobentries │ │ └── demo │ │ ├── messages │ │ └── messages_en_US.properties │ │ └── resources │ │ ├── demo.png │ │ └── demo.svg │ └── test │ └── java │ └── org │ └── pentaho │ └── di │ └── sdk │ └── samples │ └── jobentries │ └── demo │ ├── JobEntryDemoLoadSaveTest.java │ └── JobEntryDemoTest.java ├── kettle-sdk-partitioner-plugin ├── .gitignore ├── demo_transform │ └── partitioning_demo.ktr ├── pom.xml └── src │ ├── main │ ├── assembly │ │ └── assembly.xml │ └── java │ │ └── org │ │ └── pentaho │ │ └── di │ │ └── sdk │ │ └── samples │ │ └── partitioners │ │ └── demo │ │ ├── DemoPartitioner.java │ │ └── DemoPartitionerDialog.java │ └── test │ └── java │ └── org │ └── pentaho │ └── di │ └── sdk │ └── samples │ └── partitioners │ └── demo │ └── DemoPartitionerTest.java ├── kettle-sdk-plugin-assembly ├── assembly │ └── assembly.xml ├── pom.xml └── resources │ └── PDI_Icon_Guide.ai ├── kettle-sdk-step-plugin ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── assembly │ │ └── assembly.xml │ ├── java │ │ └── org │ │ │ └── pentaho │ │ │ └── di │ │ │ └── sdk │ │ │ └── samples │ │ │ └── steps │ │ │ └── demo │ │ │ ├── DemoStep.java │ │ │ ├── DemoStepData.java │ │ │ ├── DemoStepDialog.java │ │ │ └── DemoStepMeta.java │ └── resources │ │ └── org │ │ └── pentaho │ │ └── di │ │ └── sdk │ │ └── samples │ │ └── steps │ │ └── demo │ │ ├── messages │ │ └── messages_en_US.properties │ │ └── resources │ │ ├── demo.png │ │ └── demo.svg │ └── test │ └── java │ └── org │ └── pentaho │ └── di │ └── sdk │ └── samples │ └── steps │ └── demo │ ├── DemoStepDataTest.java │ ├── DemoStepMetaTest.java │ └── DemoStepTest.java └── pom.xml /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | # * text=auto 3 | 4 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @pentaho/sp-branch-write -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | dist/ 3 | js-lib/ 4 | lib/ 5 | test-lib/ 6 | eclipse-bin/ 7 | target/ 8 | override.properties 9 | testdata.log 10 | testdata.properties 11 | testdata.script 12 | .classpath 13 | .project 14 | .DS_Store 15 | projects/ 16 | plugins/ 17 | build-res/dojo-* 18 | build-res/module-scripts/ 19 | *.class 20 | *.jar 21 | *.war 22 | *.ear 23 | *.iml 24 | .idea 25 | *.prefs 26 | *.classpath 27 | .idea/ 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PDI SDK Samples 2 | 3 | ### Pre-requisites for building the project: 4 | * Maven, version 3+ 5 | * Java JDK 11 6 | * This [settings.xml](https://github.com/pentaho/maven-parent-poms/blob/master/maven-support-files/settings.xml) 7 | in your /.m2 directory 8 | 9 | ## Overview 10 | 11 | This project contains a series of examples demonstrating various use-cases for extended and embedding PDI functionality. 12 | 13 | * PDI Transformation Step 14 | * PDI Job Entry 15 | * PDI Database Dialect 16 | * PDI Transformation Hop Partitioner 17 | * Embedded PDI Features 18 | * Creating Jobs or Transformations in Java 19 | * Executing Jobs or Transformations in Java 20 | * Interacting with a Carte Web Server via APIs 21 | 22 | ## Building 23 | 24 | From the main directory, or any of the module sub-directories, run `mvn clean package site`. 25 | 26 | For the Step, Job Entry, Database Dialect, and Hop Partitioner samples, a plugin zip file will be generated that can be unzipped into a PDI Client for testing. Reports are also generated, covering topics such as unit test results, code coverage statistics, and adherence to code style rules. 27 | 28 | The examples provided in the embedded module can be run directly from a Java IDE or command-line. 29 | 30 | The generating examples needs to have a `plugins` folder on the root folder, containing any plugin jars used, currently there is a need to add 31 | the `pdi-core-plugins-impl.jar` 32 | 33 | ``` 34 | pdi-sdk-plugins/ 35 | ├── kettle-sdk-database-plugin 36 | ├── kettle-sdk-embedding-samples 37 | ├── kettle-sdk-jobentry-plugin 38 | ├── kettle-sdk-partitioner-plugin 39 | ├── kettle-sdk-plugin-assembly 40 | ├── kettle-sdk-step-plugin 41 | └── plugins --> add any plugin's jars needed for embedding samples 42 | ``` -------------------------------------------------------------------------------- /kettle-sdk-database-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /eclipse/ -------------------------------------------------------------------------------- /kettle-sdk-database-plugin/demo_transform/small_dataset.csv: -------------------------------------------------------------------------------- 1 | id;name 2 | 1;Steve 3 | 2;Clara 4 | 3;Megan -------------------------------------------------------------------------------- /kettle-sdk-database-plugin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pentaho-kettle 7 | kettle-sdk-plugin-parent 8 | 10.3.0.0-SNAPSHOT 9 | 10 | kettle-sdk-database-plugin 11 | 10.3.0.0-SNAPSHOT 12 | Pentaho Data Integration SDK Database Plugin 13 | 14 | 1.0.29 15 | 16 | 17 | 18 | pentaho-kettle 19 | kettle-core 20 | ${pdi.version} 21 | provided 22 | 23 | 24 | net.sourceforge.csvjdbc 25 | csvjdbc 26 | ${csvjdbc.version} 27 | 28 | 29 | junit 30 | junit 31 | ${junit.version} 32 | test 33 | 34 | 35 | org.mockito 36 | mockito-core 37 | ${mockito.version} 38 | test 39 | 40 | 41 | pentaho-kettle 42 | kettle-core 43 | ${project.version} 44 | tests 45 | test 46 | 47 | 48 | org.apache.logging.log4j 49 | log4j-core 50 | ${log4j.version} 51 | test 52 | 53 | 54 | 55 | 56 | 57 | maven-assembly-plugin 58 | 59 | 60 | distro-assembly 61 | package 62 | 63 | single 64 | 65 | 66 | false 67 | 68 | src/main/assembly/assembly.xml 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /kettle-sdk-database-plugin/src/main/assembly/assembly.xml: -------------------------------------------------------------------------------- 1 | 5 | bin 6 | 7 | zip 8 | 9 | 10 | 11 | ${project.build.directory} 12 | / 13 | 14 | *.jar 15 | 16 | 17 | 18 | 19 | 20 | lib/ 21 | false 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /kettle-sdk-database-plugin/src/test/java/org/pentaho/di/sdk/samples/databases/demo/DemoDatabaseMetaTest.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.databases.demo; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | import java.io.File; 18 | import org.apache.commons.vfs2.FileObject; 19 | import org.apache.commons.vfs2.FileSystemException; 20 | import org.junit.Test; 21 | import org.pentaho.di.core.Const; 22 | import org.pentaho.di.core.exception.KettleException; 23 | import org.pentaho.di.core.vfs.KettleVFS; 24 | 25 | public class DemoDatabaseMetaTest { 26 | 27 | /** 28 | * Test to see that the class is in the class path and returns the correct driver information 29 | */ 30 | @Test 31 | public void testDriverClass(){ 32 | DemoDatabaseMeta dbMeta = new DemoDatabaseMeta(); 33 | assertEquals( "org.relique.jdbc.csv.CsvDriver", dbMeta.getDriverClass() ); 34 | } 35 | 36 | @Test 37 | public void testGetUrl() throws KettleException, FileSystemException { 38 | final String prefix = "jdbc:relique:csv:"; 39 | DemoDatabaseMeta dbMeta = new DemoDatabaseMeta(); 40 | 41 | // Test working directory 42 | assertEquals( prefix + System.getProperty( "user.dir" ), dbMeta.getURL( null, null, "" ) ); 43 | 44 | // Test local file path 45 | String url = dbMeta.getURL( null, null, new File( "target" ).getAbsolutePath() ); 46 | assertEquals( prefix + System.getProperty( "user.dir" ) + Const.FILE_SEPARATOR + "target", url ); 47 | 48 | // Test VFS 49 | FileObject vfsFile = KettleVFS.getFileObject( System.getProperty( "user.dir" ) ); 50 | url = dbMeta.getURL( null, null, vfsFile.getURL().toString() ); 51 | assertEquals( prefix + System.getProperty( "user.dir" ), url ); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /kettle-sdk-database-plugin/src/test/java/org/pentaho/di/sdk/samples/databases/demo/DemoDatabaseTest.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.databases.demo; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | import static org.junit.Assert.assertNotNull; 18 | import static org.junit.Assert.assertNull; 19 | 20 | import java.sql.ResultSet; 21 | import java.sql.SQLException; 22 | 23 | import org.junit.BeforeClass; 24 | import org.junit.Test; 25 | import org.pentaho.di.core.KettleClientEnvironment; 26 | import org.pentaho.di.core.database.Database; 27 | import org.pentaho.di.core.database.DatabaseMeta; 28 | import org.pentaho.di.core.exception.KettleDatabaseException; 29 | import org.pentaho.di.core.exception.KettleException; 30 | import org.pentaho.di.core.logging.LoggingObject; 31 | import org.pentaho.di.core.plugins.DatabasePluginType; 32 | import org.pentaho.di.core.plugins.PluginRegistry; 33 | import org.pentaho.di.core.row.RowMetaInterface; 34 | 35 | public class DemoDatabaseTest { 36 | 37 | @BeforeClass 38 | public static void setUpOnce() throws KettleException { 39 | // Register custom DatabaseMeta class 40 | DatabasePluginType dbPluginType = (DatabasePluginType) PluginRegistry.getInstance().getPluginType( DatabasePluginType.class ); 41 | dbPluginType.registerCustom( DemoDatabaseMeta.class, null, "CSVJDBC", "CsvJdbc", null, null ); 42 | 43 | KettleClientEnvironment.init(); 44 | } 45 | 46 | @Test 47 | public void testReadDataIT() throws KettleDatabaseException, SQLException { 48 | DemoDatabaseMeta demoMeta = new DemoDatabaseMeta(); 49 | demoMeta.setPluginId( "CSVJDBC" ); 50 | DatabaseMeta dbMeta = new DatabaseMeta(); 51 | dbMeta.setDatabaseInterface( demoMeta ); 52 | dbMeta.addExtraOption( "CSVJDBC", "separator", ";" ); 53 | dbMeta.addExtraOption( "CSVJDBC", "columnTypes.small_dataset", "Integer,String" ); 54 | dbMeta.setDBName( "demo_transform" ); 55 | 56 | Database db = new Database( new LoggingObject( this ), dbMeta ); 57 | db.connect(); 58 | ResultSet result = db.openQuery( "SELECT * FROM small_dataset" ); 59 | assertNotNull( result ); 60 | 61 | Object[] row = db.getRow( result ); 62 | RowMetaInterface meta = db.getMetaFromRow( row, result.getMetaData() ); 63 | assertNotNull( row ); 64 | assertNotNull( meta ); 65 | assertEquals( 2, meta.size() ); 66 | assertEquals( 1L, row[0] ); 67 | assertEquals( "Steve", row[1] ); 68 | 69 | row = db.getRow( result ); 70 | assertNotNull( row ); 71 | assertEquals( 2L, row[0] ); 72 | assertEquals( "Clara", row[1] ); 73 | System.out.println( row[0] ); 74 | 75 | row = db.getRow( result ); 76 | assertNotNull( row ); 77 | assertEquals( 3L, row[0] ); 78 | assertEquals( "Megan", row[1] ); 79 | 80 | row = db.getRow( result ); 81 | assertNull( row ); 82 | db.disconnect(); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pentaho-kettle 7 | kettle-sdk-plugin-parent 8 | 10.3.0.0-SNAPSHOT 9 | 10 | kettle-sdk-embedding-samples 11 | 10.3.0.0-SNAPSHOT 12 | Pentaho Data Integration SDK Embedding Samples 13 | 14 | 1.19.1 15 | 1.1.1 16 | 17 | 18 | 19 | pentaho-kettle 20 | kettle-core 21 | ${pdi.version} 22 | 23 | 24 | xercesImpl 25 | xerces 26 | 27 | 28 | commons-httpclient 29 | commons-httpclient 30 | 31 | 32 | 33 | 34 | pentaho-kettle 35 | kettle-engine 36 | ${pdi.version} 37 | 38 | 39 | org.pentaho.di.plugins 40 | pdi-core-plugins-impl 41 | ${pdi.version} 42 | 43 | 44 | org.apache.httpcomponents 45 | httpclient 46 | 47 | 48 | org.apache.httpcomponents 49 | httpcore 50 | 51 | 52 | junit 53 | junit 54 | ${junit.version} 55 | test 56 | 57 | 58 | org.mockito 59 | mockito-core 60 | ${mockito.version} 61 | test 62 | 63 | 64 | xerces 65 | xercesImpl 66 | test 67 | 68 | 69 | * 70 | * 71 | 72 | 73 | 74 | 75 | commons-cli 76 | commons-cli 77 | 1.3.1 78 | test 79 | 80 | 81 | com.sun.jersey 82 | jersey-core 83 | ${jersey.version} 84 | test 85 | 86 | 87 | com.sun.jersey 88 | jersey-client 89 | ${jersey.version} 90 | test 91 | 92 | 93 | com.sun.jersey 94 | jersey-bundle 95 | ${jersey.version} 96 | test 97 | 98 | 99 | javax.ws.rs 100 | jsr311-api 101 | ${jsr311-api.version} 102 | test 103 | 104 | 105 | javax.servlet 106 | javax.servlet-api 107 | 3.1.0 108 | test 109 | 110 | 111 | org.eclipse.jetty 112 | jetty-server 113 | test 114 | 115 | 116 | org.eclipse.jetty 117 | jetty-servlet 118 | test 119 | 120 | 121 | pentaho-kettle 122 | kettle-core 123 | ${project.version} 124 | tests 125 | test 126 | 127 | 128 | 129 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/carte/AbstractSample.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | /** 17 | * Created by Yury_Bakhmutski on 6/27/2017. 18 | */ 19 | public abstract class AbstractSample { 20 | protected static String host; 21 | protected static int port; 22 | protected static String user; 23 | protected static String password; 24 | 25 | protected static void init( String host, int port, String user, String password ) { 26 | AbstractSample.host = host; 27 | AbstractSample.port = port; 28 | AbstractSample.user = user; 29 | AbstractSample.password = password; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/carte/AllocateServerSocketSample.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import org.apache.commons.codec.binary.Base64; 17 | import org.apache.http.HttpResponse; 18 | import org.apache.http.HttpStatus; 19 | import org.apache.http.client.HttpClient; 20 | import org.apache.http.client.methods.HttpGet; 21 | import org.apache.http.client.protocol.HttpClientContext; 22 | import org.apache.http.message.BasicHeader; 23 | import org.pentaho.di.core.Const; 24 | import org.pentaho.di.core.util.HttpClientManager; 25 | import org.pentaho.di.core.util.HttpClientUtil; 26 | import org.pentaho.di.www.AllocateServerSocketServlet; 27 | 28 | public class AllocateServerSocketSample extends AbstractSample { 29 | 30 | public static void main( String[] args ) throws Exception { 31 | if ( args.length < 5 ) { 32 | System.out.println( " You must specify the following parameters Carte_host Carte_port " 33 | + "Carte_login Carte_password range_start [host_id cluster_id trans_id source_slave " 34 | + "source_step source_copy target_slave target_step target_copies]" ); 35 | System.out.println( " For example 127.0.0.1 8088 cluster cluster 100 " ); 36 | System.exit( 1 ); 37 | } 38 | init( args[ 0 ], Integer.parseInt( args[ 1 ] ), args[ 2 ], args[ 3 ] ); 39 | // building target url 40 | String srcHost = ( args.length > 5 ) ? args[ 5 ] : "localhost"; 41 | String clusterId = ( args.length > 6 ) ? args[ 6 ] : "my_cluster"; 42 | String transName = ( args.length > 7 ) ? args[ 7 ] : "my_trans"; 43 | String sourceSlave = ( args.length > 8 ) ? args[ 8 ] : "slave_1"; 44 | String sourceStep = ( args.length > 9 ) ? args[ 9 ] : "200"; 45 | String sourceCopy = ( args.length > 10 ) ? args[ 10 ] : "1"; 46 | String targetSlave = ( args.length > 11 ) ? args[ 11 ] : "slave_2"; 47 | String targetStep = ( args.length > 12 ) ? args[ 12 ] : "50"; 48 | String targetCopy = ( args.length > 13 ) ? args[ 13 ] : "1"; 49 | String realHostname = args[ 0 ]; 50 | String port = args[ 1 ]; 51 | String rangeStart = args[ 4 ]; 52 | String urlString = getUrlString( realHostname, port, rangeStart, srcHost, clusterId, transName, sourceSlave, 53 | sourceStep, sourceCopy, targetSlave, targetStep, targetCopy ); 54 | 55 | //building auth token 56 | String auth = getAuthString( args[ 2 ], args[ 3 ] ); 57 | 58 | //adding binary to servlet 59 | allocateServerSocket( urlString, auth ); 60 | } 61 | 62 | 63 | public static void allocateServerSocket( String urlString, String authentication ) throws Exception { 64 | HttpGet method = new HttpGet( urlString ); 65 | HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); 66 | method.addHeader( new BasicHeader( "Content-Type", "text/xml;charset=UTF-8" ) ); 67 | //adding authorization token 68 | if ( authentication != null ) { 69 | method.addHeader( new BasicHeader( "Authorization", authentication ) ); 70 | } 71 | 72 | //executing method 73 | HttpClient client = HttpClientManager.getInstance().createDefaultClient(); 74 | HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); 75 | int code = httpResponse.getStatusLine().getStatusCode(); 76 | String response = HttpClientUtil.responseToString( httpResponse ); 77 | method.releaseConnection(); 78 | if ( code >= HttpStatus.SC_BAD_REQUEST ) { 79 | System.out.println( "Error occurred during ports allocation." ); 80 | } 81 | System.out.println( "Server response:" ); 82 | System.out.println( response ); 83 | } 84 | 85 | public static String getUrlString( String realHostname, String port, String rangeStart, String srcHost, 86 | String clusterId, String transName, String sourceSlave, String sourceStep, 87 | String sourceCopy, 88 | String targetSlave, String targetStep, String targetCopy ) { 89 | String url = "http://" + realHostname + ":" + port + AllocateServerSocketServlet.CONTEXT_PATH 90 | + "/?xml=Y&rangeStart=" + rangeStart + "&host=" + srcHost + "&id=" + clusterId + "&trans=" 91 | + transName + "&sourceSlave=" + sourceSlave + "&sourceStep=" + sourceStep + "&sourceCopy=" 92 | + sourceCopy + "&targetSlave=" + targetSlave + "&targetStep=" + targetStep + "&targetCopy=" + targetCopy; 93 | return Const.replace( url, " ", "%20" ); 94 | } 95 | 96 | public static String getAuthString( String user, String pass ) { 97 | String plainAuth = user + ":" + pass; 98 | String auth = "Basic " + Base64.encodeBase64String( plainAuth.getBytes() ); 99 | return auth; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/carte/CleanupTransSample.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import org.apache.commons.codec.binary.Base64; 17 | import org.apache.http.HttpResponse; 18 | import org.apache.http.HttpStatus; 19 | import org.apache.http.client.HttpClient; 20 | import org.apache.http.client.methods.HttpGet; 21 | import org.apache.http.client.protocol.HttpClientContext; 22 | import org.apache.http.message.BasicHeader; 23 | import org.pentaho.di.core.Const; 24 | import org.pentaho.di.core.util.HttpClientManager; 25 | import org.pentaho.di.core.util.HttpClientUtil; 26 | import org.pentaho.di.www.CleanupTransServlet; 27 | 28 | public class CleanupTransSample extends AbstractSample { 29 | 30 | public static void main( String[] args ) throws Exception { 31 | if ( args.length < 5 ) { 32 | System.out.println( " You must specify the following parameters Carte_host Carte_port " 33 | + "Carte_login Carte_password job_name" ); 34 | System.out.println( " For example 127.0.0.1 8088 cluster cluster my_trans" ); 35 | System.exit( 1 ); 36 | } 37 | init( args[ 0 ], Integer.parseInt( args[ 1 ] ), args[ 2 ], args[ 3 ] ); 38 | // building target url 39 | String urlString = getUrlString( args[ 0 ], args[ 1 ], args[ 4 ] ); 40 | 41 | //building auth token 42 | String auth = getAuthString( args[ 2 ], args[ 3 ] ); 43 | 44 | //adding binary to servlet 45 | String response = sendCleanupTransRequest( urlString, auth ); 46 | if ( response != null ) { 47 | System.out.println( "Server response:" ); 48 | System.out.println( response ); 49 | } 50 | } 51 | 52 | public static String sendCleanupTransRequest( String urlString, String authentication ) throws Exception { 53 | HttpGet method = new HttpGet( urlString ); 54 | HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); 55 | //adding authorization token 56 | if ( authentication != null ) { 57 | method.addHeader( new BasicHeader( "Authorization", authentication ) ); 58 | } 59 | 60 | //executing method 61 | HttpClient client = HttpClientManager.getInstance().createDefaultClient(); 62 | HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); 63 | int code = httpResponse.getStatusLine().getStatusCode(); 64 | String response = HttpClientUtil.responseToString( httpResponse ); 65 | method.releaseConnection(); 66 | if ( code >= HttpStatus.SC_BAD_REQUEST ) { 67 | System.out.println( "Error occurred during transformation preparation for execution." ); 68 | return null; 69 | } 70 | return response; 71 | } 72 | 73 | public static String getUrlString( String realHostname, String port, String transName ) { 74 | String url = "http://" + realHostname + ":" + port + CleanupTransServlet.CONTEXT_PATH + "?xml=Y&name=" + transName; 75 | return Const.replace( url, " ", "%20" ); 76 | } 77 | 78 | public static String getAuthString( String user, String pass ) { 79 | String plainAuth = user + ":" + pass; 80 | String auth = "Basic " + Base64.encodeBase64String( plainAuth.getBytes() ); 81 | return auth; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/carte/ExecuteTransSample.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import org.apache.commons.codec.binary.Base64; 17 | import org.apache.http.HttpResponse; 18 | import org.apache.http.HttpStatus; 19 | import org.apache.http.client.HttpClient; 20 | import org.apache.http.client.methods.HttpGet; 21 | import org.apache.http.client.protocol.HttpClientContext; 22 | import org.apache.http.message.BasicHeader; 23 | import org.pentaho.di.core.Const; 24 | import org.pentaho.di.core.util.HttpClientManager; 25 | import org.pentaho.di.core.util.HttpClientUtil; 26 | import org.pentaho.di.www.ExecuteTransServlet; 27 | 28 | public class ExecuteTransSample extends AbstractSample { 29 | 30 | public static void main( String[] args ) throws Exception { 31 | if ( args.length < 8 ) { 32 | System.out.println( " You must specify the following parameters Carte_host Carte_port " 33 | + "Carte_login Carte_password di_repository_id di_repository_username di_repository_password " 34 | + "full_trans_path [log_level]" ); 35 | System.out.println( " For example 127.0.0.1 8088 cluster cluster di user password home/admin/my_trans " ); 36 | System.exit( 1 ); 37 | } 38 | init( args[ 0 ], Integer.parseInt( args[ 1 ] ), args[ 2 ], args[ 3 ] ); 39 | // building target url 40 | String logLevel = ( args.length > 8 ) ? args[ 8 ] : "Debug"; 41 | String serviceAndArguments = "/?rep=" + args[ 4 ] + "&user=" + args[ 5 ] + "&pass=" 42 | + args[ 6 ] + "&trans=" + args[ 7 ] + "&level=" + logLevel; 43 | 44 | serviceAndArguments = Const.replace( serviceAndArguments, " ", "%20" ); 45 | serviceAndArguments = Const.replace( serviceAndArguments, "/", "%2F" ); 46 | 47 | String urlString = "http://" + host + ":" + port + ExecuteTransServlet.CONTEXT_PATH + serviceAndArguments; 48 | 49 | //building auth token 50 | String plainAuth = args[ 2 ] + ":" + args[ 3 ]; 51 | String auth = "Basic " + Base64.encodeBase64String( plainAuth.getBytes() ); 52 | 53 | //adding binary to servlet 54 | sendExecuteRequest( urlString, auth ); 55 | } 56 | 57 | public static void sendExecuteRequest( String urlString, String authentication ) throws Exception { 58 | HttpGet method = new HttpGet( urlString ); 59 | HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); 60 | method.addHeader( new BasicHeader( "Content-Type", "text/xml;charset=UTF-8" ) ); 61 | //adding authorization token 62 | if ( authentication != null ) { 63 | method.addHeader( new BasicHeader( "Authorization", authentication ) ); 64 | } 65 | 66 | //executing method 67 | HttpClient client = HttpClientManager.getInstance().createDefaultClient(); 68 | HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); 69 | int code = httpResponse.getStatusLine().getStatusCode(); 70 | String response = HttpClientUtil.responseToString( httpResponse ); 71 | method.releaseConnection(); 72 | if ( code >= HttpStatus.SC_BAD_REQUEST ) { 73 | System.out.println( "Error occurred during transformation execution." ); 74 | } 75 | System.out.println( "Server response (expected to be empty):" ); 76 | System.out.println( response ); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/carte/GetJobImageSample.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import org.apache.commons.codec.binary.Base64; 17 | import org.apache.http.HttpResponse; 18 | import org.apache.http.HttpStatus; 19 | import org.apache.http.client.HttpClient; 20 | import org.apache.http.client.methods.HttpGet; 21 | import org.apache.http.client.protocol.HttpClientContext; 22 | import org.apache.http.message.BasicHeader; 23 | import org.pentaho.di.core.Const; 24 | import org.pentaho.di.core.util.HttpClientManager; 25 | import org.pentaho.di.core.util.HttpClientUtil; 26 | import org.pentaho.di.www.GetJobImageServlet; 27 | 28 | import java.io.FileOutputStream; 29 | 30 | public class GetJobImageSample extends AbstractSample { 31 | 32 | public static void main( String[] args ) throws Exception { 33 | if ( args.length < 6 ) { 34 | System.out.println( " You must specify the following parameters Carte_host Carte_port " 35 | + "Carte_login Carte_password job_name full_ouput_filepath" ); 36 | System.out.println( " For example 127.0.0.1 8088 cluster cluster dummy_job d:\\1.png" ); 37 | System.exit( 1 ); 38 | } 39 | init( args[ 0 ], Integer.parseInt( args[ 1 ] ), args[ 2 ], args[ 3 ] ); 40 | // building target url 41 | String urlString = getUrlString( args[ 0 ], args[ 1 ], args[ 4 ] ); 42 | 43 | //building auth token 44 | String auth = getAuthString( args[ 2 ], args[ 3 ] ); 45 | 46 | //adding binary to servlet 47 | String filename = args[ 5 ]; 48 | if ( sendGetImageRequest( urlString, auth, filename ) ) { 49 | System.out.println( "Image was stored to " + filename ); 50 | } 51 | } 52 | 53 | public static boolean sendGetImageRequest( String urlString, String authentication, String fileName ) 54 | throws Exception { 55 | HttpGet method = new HttpGet( urlString ); 56 | HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); 57 | //adding authorization token 58 | if ( authentication != null ) { 59 | method.addHeader( new BasicHeader( "Authorization", authentication ) ); 60 | } 61 | 62 | //executing method 63 | HttpClient client = HttpClientManager.getInstance().createDefaultClient(); 64 | HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); 65 | int code = httpResponse.getStatusLine().getStatusCode(); 66 | byte[] response = HttpClientUtil.responseToByteArray( httpResponse ); 67 | method.releaseConnection(); 68 | if ( code >= HttpStatus.SC_BAD_REQUEST ) { 69 | System.out.println( "Error occurred during getting job image." ); 70 | return false; 71 | } 72 | 73 | FileOutputStream fos = null; 74 | try { 75 | fos = new FileOutputStream( fileName ); 76 | fos.write( response ); 77 | fos.flush(); 78 | } finally { 79 | fos.close(); 80 | } 81 | return true; 82 | } 83 | 84 | public static String getUrlString( String realHostname, String port, String jobName ) { 85 | String url = "http://" + realHostname + ":" + port + GetJobImageServlet.CONTEXT_PATH + "?name=" + jobName; 86 | return Const.replace( url, " ", "%20" ); 87 | } 88 | 89 | public static String getAuthString( String user, String pass ) { 90 | String plainAuth = user + ":" + pass; 91 | String auth = "Basic " + Base64.encodeBase64String( plainAuth.getBytes() ); 92 | return auth; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/carte/GetJobStatusSample.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import org.apache.commons.codec.binary.Base64; 17 | import org.apache.http.HttpResponse; 18 | import org.apache.http.HttpStatus; 19 | import org.apache.http.client.HttpClient; 20 | import org.apache.http.client.methods.HttpGet; 21 | import org.apache.http.client.protocol.HttpClientContext; 22 | import org.apache.http.message.BasicHeader; 23 | import org.pentaho.di.core.Const; 24 | import org.pentaho.di.core.util.HttpClientManager; 25 | import org.pentaho.di.core.util.HttpClientUtil; 26 | import org.pentaho.di.www.GetJobStatusServlet; 27 | 28 | public class GetJobStatusSample extends AbstractSample { 29 | 30 | public static void main( String[] args ) throws Exception { 31 | if ( args.length < 5 ) { 32 | System.out.println( " You must specify the following parameters Carte_host Carte_port " 33 | + "Carte_login Carte_password job_name" ); 34 | System.out.println( " For example 127.0.0.1 8088 cluster cluster my_job" ); 35 | System.exit( 1 ); 36 | } 37 | init( args[ 0 ], Integer.parseInt( args[ 1 ] ), args[ 2 ], args[ 3 ] ); 38 | // building target url 39 | String urlString = getUrlString( args[ 0 ], args[ 1 ], args[ 4 ] ); 40 | 41 | // building auth token 42 | String auth = getAuthString( args[ 2 ], args[ 3 ] ); 43 | 44 | // get job status 45 | String response = sendGetJobStatusRequest( urlString, auth ); 46 | if ( response != null ) { 47 | System.out.println( "Server response:" ); 48 | System.out.println( response ); 49 | } 50 | } 51 | 52 | public static String sendGetJobStatusRequest( String urlString, String authentication ) throws Exception { 53 | HttpGet method = new HttpGet( urlString ); 54 | HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); 55 | //adding authorization token 56 | if ( authentication != null ) { 57 | method.addHeader( new BasicHeader( "Authorization", authentication ) ); 58 | } 59 | 60 | //executing method 61 | HttpClient client = HttpClientManager.getInstance().createDefaultClient(); 62 | HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); 63 | int code = httpResponse.getStatusLine().getStatusCode(); 64 | String response = HttpClientUtil.responseToString( httpResponse ); 65 | method.releaseConnection(); 66 | if ( code >= HttpStatus.SC_INTERNAL_SERVER_ERROR ) { 67 | System.out.println( "Error occurred during getting job status." ); 68 | return null; 69 | } 70 | return response; 71 | } 72 | 73 | public static String getUrlString( String realHostname, String port, String job_name ) { 74 | String urlString = "http://" + realHostname + ":" + port 75 | + GetJobStatusServlet.CONTEXT_PATH + "/?xml=Y&name=" + job_name; 76 | urlString = Const.replace( urlString, " ", "%20" ); 77 | return urlString; 78 | } 79 | 80 | public static String getAuthString( String user, String pass ) { 81 | String plainAuth = user + ":" + pass; 82 | String auth = "Basic " + Base64.encodeBase64String( plainAuth.getBytes() ); 83 | return auth; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/carte/GetSlavesSample.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import org.apache.commons.codec.binary.Base64; 17 | import org.apache.http.HttpResponse; 18 | import org.apache.http.HttpStatus; 19 | import org.apache.http.client.HttpClient; 20 | import org.apache.http.client.methods.HttpGet; 21 | import org.apache.http.client.protocol.HttpClientContext; 22 | import org.apache.http.message.BasicHeader; 23 | import org.pentaho.di.core.util.HttpClientManager; 24 | import org.pentaho.di.core.util.HttpClientUtil; 25 | import org.pentaho.di.www.GetSlavesServlet; 26 | 27 | public class GetSlavesSample extends AbstractSample { 28 | 29 | public static void main( String[] args ) throws Exception { 30 | if ( args.length < 4 ) { 31 | System.out.println( " You must specify the following parameters Carte_host Carte_port " 32 | + "Carte_login Carte_password" ); 33 | System.out.println( " For example 127.0.0.1 8088 cluster cluster" ); 34 | System.exit( 1 ); 35 | } 36 | init( args[ 0 ], Integer.parseInt( args[ 1 ] ), args[ 2 ], args[ 3 ] ); 37 | // building target url 38 | String urlString = getUrlString( args[ 0 ], args[ 1 ] ); 39 | 40 | //building auth token 41 | String auth = getAuthString( args[ 2 ], args[ 3 ] ); 42 | 43 | //adding binary to servlet 44 | sendGetSlavesRequest( urlString, auth ); 45 | } 46 | 47 | public static void sendGetSlavesRequest( String urlString, String authentication ) throws Exception { 48 | HttpGet method = new HttpGet( urlString ); 49 | HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); 50 | //adding authorization token 51 | if ( authentication != null ) { 52 | method.addHeader( new BasicHeader( "Authorization", authentication ) ); 53 | } 54 | 55 | //executing method 56 | HttpClient client = HttpClientManager.getInstance().createDefaultClient(); 57 | HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); 58 | int code = httpResponse.getStatusLine().getStatusCode(); 59 | String response = HttpClientUtil.responseToString( httpResponse ); 60 | method.releaseConnection(); 61 | if ( code >= HttpStatus.SC_BAD_REQUEST ) { 62 | System.out.println( "Error occurred during getting slave servers." ); 63 | } 64 | System.out.println( "Server response:" ); 65 | System.out.println( response ); 66 | } 67 | 68 | public static String getUrlString( String realHostname, String port ) { 69 | String urlString = "http://" + realHostname + ":" + port + GetSlavesServlet.CONTEXT_PATH; 70 | return urlString; 71 | } 72 | 73 | public static String getAuthString( String user, String pass ) { 74 | String plainAuth = user + ":" + pass; 75 | String auth = "Basic " + Base64.encodeBase64String( plainAuth.getBytes() ); 76 | return auth; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/carte/GetStatusSample.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import org.apache.commons.codec.binary.Base64; 17 | import org.apache.http.HttpResponse; 18 | import org.apache.http.HttpStatus; 19 | import org.apache.http.client.HttpClient; 20 | import org.apache.http.client.methods.HttpGet; 21 | import org.apache.http.client.protocol.HttpClientContext; 22 | import org.apache.http.message.BasicHeader; 23 | import org.pentaho.di.core.Const; 24 | import org.pentaho.di.core.util.HttpClientManager; 25 | import org.pentaho.di.core.util.HttpClientUtil; 26 | import org.pentaho.di.www.GetStatusServlet; 27 | 28 | public class GetStatusSample extends AbstractSample { 29 | 30 | public static void main( String[] args ) throws Exception { 31 | if ( args.length < 4 ) { 32 | System.out.println( " You must specify the following parameters Carte_host Carte_port " 33 | + "Carte_login Carte_password" ); 34 | System.out.println( " For example 127.0.0.1 8088 cluster cluster" ); 35 | System.exit( 1 ); 36 | } 37 | init( args[ 0 ], Integer.parseInt( args[ 1 ] ), args[ 2 ], args[ 3 ] ); 38 | // building target url 39 | String urlString = getUrlString( args[ 0 ], args[ 1 ] ); 40 | 41 | //building auth token 42 | String auth = getAuthString( args[ 2 ], args[ 3 ] ); 43 | 44 | String response = sendGetStatusRequest( urlString, auth ); 45 | if ( response != null ) { 46 | System.out.println( "Server response:" ); 47 | System.out.println( response ); 48 | } 49 | } 50 | 51 | public static String sendGetStatusRequest( String urlString, String authentication ) throws Exception { 52 | HttpGet method = new HttpGet( urlString ); 53 | HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); 54 | //adding authorization token 55 | if ( authentication != null ) { 56 | method.addHeader( new BasicHeader( "Authorization", authentication ) ); 57 | } 58 | 59 | //executing method 60 | HttpClient client = HttpClientManager.getInstance().createDefaultClient(); 61 | HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); 62 | int code = httpResponse.getStatusLine().getStatusCode(); 63 | String response = HttpClientUtil.responseToString( httpResponse ); 64 | method.releaseConnection(); 65 | if ( code >= HttpStatus.SC_BAD_REQUEST ) { 66 | System.out.println( "Error occurred during getting server status." ); 67 | return null; 68 | } 69 | method.releaseConnection(); 70 | return response; 71 | } 72 | 73 | public static String getUrlString( String realHostname, String port ) { 74 | String urlString = "http://" + realHostname + ":" + port + GetStatusServlet.CONTEXT_PATH 75 | + "?xml=Y"; 76 | urlString = Const.replace( urlString, " ", "%20" ); 77 | return urlString; 78 | } 79 | 80 | public static String getAuthString( String username, String password ) { 81 | String plainAuth = username + ":" + password; 82 | String auth = "Basic " + Base64.encodeBase64String( plainAuth.getBytes() ); 83 | return auth; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/carte/GetTransImageSample.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import org.apache.commons.codec.binary.Base64; 17 | import org.apache.http.HttpResponse; 18 | import org.apache.http.HttpStatus; 19 | import org.apache.http.client.HttpClient; 20 | import org.apache.http.client.methods.HttpGet; 21 | import org.apache.http.client.protocol.HttpClientContext; 22 | import org.apache.http.message.BasicHeader; 23 | import org.pentaho.di.core.Const; 24 | import org.pentaho.di.core.util.HttpClientManager; 25 | import org.pentaho.di.core.util.HttpClientUtil; 26 | import org.pentaho.di.www.GetTransImageServlet; 27 | 28 | import java.io.FileOutputStream; 29 | 30 | public class GetTransImageSample extends AbstractSample { 31 | public static void main( String[] args ) throws Exception { 32 | if ( args.length < 6 ) { 33 | System.out.println( " You must specify the following parameters Carte_host Carte_port " 34 | + "Carte_login Carte_password job_name full_ouput_filepath" ); 35 | System.out.println( " For example 127.0.0.1 8088 cluster cluster dummy_job d:\\1.png" ); 36 | System.exit( 1 ); 37 | } 38 | init( args[ 0 ], Integer.parseInt( args[ 1 ] ), args[ 2 ], args[ 3 ] ); 39 | // building target url 40 | String realHostname = args[ 0 ]; 41 | String port = args[ 1 ]; 42 | String urlString = "http://" + realHostname + ":" + port + GetTransImageServlet.CONTEXT_PATH + "?name=" + args[ 4 ]; 43 | urlString = Const.replace( urlString, " ", "%20" ); 44 | 45 | //building auth token 46 | String plainAuth = args[ 2 ] + ":" + args[ 3 ]; 47 | String auth = "Basic " + Base64.encodeBase64String( plainAuth.getBytes() ); 48 | 49 | sendGetImageRequest( urlString, auth, args[ 5 ] ); 50 | } 51 | 52 | public static void sendGetImageRequest( String urlString, String authentication, String fileName ) throws Exception { 53 | HttpGet method = new HttpGet( urlString ); 54 | HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); 55 | //adding authorization token 56 | if ( authentication != null ) { 57 | method.addHeader( new BasicHeader( "Authorization", authentication ) ); 58 | } 59 | 60 | //executing method 61 | HttpClient client = HttpClientManager.getInstance().createDefaultClient(); 62 | HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); 63 | int code = httpResponse.getStatusLine().getStatusCode(); 64 | byte[] response = HttpClientUtil.responseToByteArray( httpResponse ); 65 | method.releaseConnection(); 66 | if ( code >= HttpStatus.SC_BAD_REQUEST ) { 67 | System.out.println( "Error occurred during getting transformation image." ); 68 | } 69 | System.out.println( "Image was stored to " + fileName ); 70 | FileOutputStream fos = null; 71 | try { 72 | fos = new FileOutputStream( fileName ); 73 | fos.write( response ); 74 | fos.flush(); 75 | } finally { 76 | fos.close(); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/carte/GetTransStatusSample.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import org.apache.commons.codec.binary.Base64; 17 | import org.apache.http.HttpResponse; 18 | import org.apache.http.HttpStatus; 19 | import org.apache.http.client.HttpClient; 20 | import org.apache.http.client.methods.HttpGet; 21 | import org.apache.http.client.protocol.HttpClientContext; 22 | import org.apache.http.message.BasicHeader; 23 | import org.pentaho.di.core.Const; 24 | import org.pentaho.di.core.util.HttpClientManager; 25 | import org.pentaho.di.core.util.HttpClientUtil; 26 | import org.pentaho.di.www.GetTransStatusServlet; 27 | 28 | public class GetTransStatusSample extends AbstractSample { 29 | 30 | public static void main( String[] args ) throws Exception { 31 | if ( args.length < 5 ) { 32 | System.out.println( " You must specify the following parameters Carte_host Carte_port " 33 | + "Carte_login Carte_password job_name" ); 34 | System.out.println( " For example 127.0.0.1 8088 cluster cluster my_job" ); 35 | System.exit( 1 ); 36 | } 37 | init( args[ 0 ], Integer.parseInt( args[ 1 ] ), args[ 2 ], args[ 3 ] ); 38 | // building target url 39 | String realHostname = args[ 0 ]; 40 | String port = args[ 1 ]; 41 | 42 | String urlString = "http://" + realHostname + ":" + port + GetTransStatusServlet.CONTEXT_PATH 43 | + "?xml=Y&name=" + args[ 4 ]; 44 | urlString = Const.replace( urlString, " ", "%20" ); 45 | 46 | //building auth token 47 | String plainAuth = args[ 2 ] + ":" + args[ 3 ]; 48 | String auth = "Basic " + Base64.encodeBase64String( plainAuth.getBytes() ); 49 | 50 | sendGetTransStatusRequest( urlString, auth ); 51 | } 52 | 53 | public static void sendGetTransStatusRequest( String urlString, String authentication ) throws Exception { 54 | HttpGet method = new HttpGet( urlString ); 55 | HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); 56 | //adding authorization token 57 | if ( authentication != null ) { 58 | method.addHeader( new BasicHeader( "Authorization", authentication ) ); 59 | } 60 | 61 | //executing method 62 | HttpClient client = HttpClientManager.getInstance().createDefaultClient(); 63 | HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); 64 | int code = httpResponse.getStatusLine().getStatusCode(); 65 | String response = HttpClientUtil.responseToString( httpResponse ); 66 | method.releaseConnection(); 67 | if ( code >= HttpStatus.SC_BAD_REQUEST ) { 68 | System.out.println( "Error occurred during getting job status." ); 69 | } 70 | System.out.println( "Server response:" ); 71 | System.out.println( response ); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/carte/ListServerSocketSample.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import org.apache.commons.codec.binary.Base64; 17 | import org.apache.http.HttpResponse; 18 | import org.apache.http.HttpStatus; 19 | import org.apache.http.client.HttpClient; 20 | import org.apache.http.client.methods.HttpGet; 21 | import org.apache.http.client.protocol.HttpClientContext; 22 | import org.apache.http.message.BasicHeader; 23 | import org.pentaho.di.core.Const; 24 | import org.pentaho.di.core.util.HttpClientManager; 25 | import org.pentaho.di.core.util.HttpClientUtil; 26 | import org.pentaho.di.www.ListServerSocketServlet; 27 | 28 | public class ListServerSocketSample extends AbstractSample { 29 | 30 | public static void main( String[] args ) throws Exception { 31 | if ( args.length < 5 ) { 32 | System.out.println( " You must specify the following parameters Carte_host Carte_port " 33 | + "Carte_login Carte_password host" ); 34 | System.out.println( " For example 127.0.0.1 8088 cluster cluster 127.0.0.1" ); 35 | System.exit( 1 ); 36 | } 37 | init( args[ 0 ], Integer.parseInt( args[ 1 ] ), args[ 2 ], args[ 3 ] ); 38 | // building target url 39 | String realHostname = args[ 0 ]; 40 | String port = args[ 1 ]; 41 | 42 | String urlString = "http://" + realHostname + ":" + port + ListServerSocketServlet.CONTEXT_PATH 43 | + "?host=" + args[ 4 ]; 44 | urlString = Const.replace( urlString, " ", "%20" ); 45 | 46 | //building auth token 47 | String plainAuth = args[ 2 ] + ":" + args[ 3 ]; 48 | String auth = "Basic " + Base64.encodeBase64String( plainAuth.getBytes() ); 49 | 50 | //adding binary to servlet 51 | sendListServerSocketRequest( urlString, auth ); 52 | } 53 | 54 | public static void sendListServerSocketRequest( String urlString, String authentication ) throws Exception { 55 | HttpGet method = new HttpGet( urlString ); 56 | HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); 57 | //adding authorization token 58 | if ( authentication != null ) { 59 | method.addHeader( new BasicHeader( "Authorization", authentication ) ); 60 | } 61 | 62 | //executing method 63 | HttpClient client = HttpClientManager.getInstance().createDefaultClient(); 64 | HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); 65 | int code = httpResponse.getStatusLine().getStatusCode(); 66 | String response = HttpClientUtil.responseToString( httpResponse ); 67 | method.releaseConnection(); 68 | if ( code >= HttpStatus.SC_BAD_REQUEST ) { 69 | System.out.println( "Error occurred during getting allocated sockets." ); 70 | } 71 | System.out.println( "Server response:" ); 72 | System.out.println( response ); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/carte/NextSequenceSample.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import org.apache.commons.codec.binary.Base64; 17 | import org.apache.http.HttpResponse; 18 | import org.apache.http.HttpStatus; 19 | import org.apache.http.client.HttpClient; 20 | import org.apache.http.client.methods.HttpGet; 21 | import org.apache.http.client.protocol.HttpClientContext; 22 | import org.apache.http.message.BasicHeader; 23 | import org.pentaho.di.core.Const; 24 | import org.pentaho.di.core.util.HttpClientManager; 25 | import org.pentaho.di.core.util.HttpClientUtil; 26 | import org.pentaho.di.www.NextSequenceValueServlet; 27 | 28 | public class NextSequenceSample extends AbstractSample { 29 | 30 | public static void main( String[] args ) throws Exception { 31 | if ( args.length < 5 ) { 32 | System.out.println( " You must specify the following parameters Carte_host Carte_port " 33 | + "Carte_login Carte_password job_name" ); 34 | System.out.println( " For example 127.0.0.1 8088 cluster cluster my_sequense" ); 35 | System.exit( 1 ); 36 | } 37 | init( args[ 0 ], Integer.parseInt( args[ 1 ] ), args[ 2 ], args[ 3 ] ); 38 | // building target url 39 | String urlString = getUrlString( args[ 0 ], args[ 1 ], args[ 4 ] ); 40 | 41 | //building auth token 42 | String auth = getAuthString( args[ 2 ], args[ 3 ] ); 43 | 44 | //adding binary to servlet 45 | String response = sendNextSequenceRequest( urlString, auth ); 46 | if ( response != null ) { 47 | System.out.println( "Server response:" ); 48 | System.out.println( response ); 49 | } 50 | } 51 | 52 | public static String sendNextSequenceRequest( String urlString, String authentication ) throws Exception { 53 | HttpGet method = new HttpGet( urlString ); 54 | HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); 55 | //adding authorization token 56 | if ( authentication != null ) { 57 | method.addHeader( new BasicHeader( "Authorization", authentication ) ); 58 | } 59 | 60 | //executing method 61 | HttpClient client = HttpClientManager.getInstance().createDefaultClient(); 62 | HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); 63 | int code = httpResponse.getStatusLine().getStatusCode(); 64 | String response = HttpClientUtil.responseToString( httpResponse ); 65 | method.releaseConnection(); 66 | if ( code >= HttpStatus.SC_BAD_REQUEST ) { 67 | System.out.println( "Error occurred during sequense allocation. " 68 | + "Most probably you don't have the sequence configured for your Carte server." ); 69 | return null; 70 | } 71 | return response; 72 | } 73 | 74 | public static String getUrlString( String realHostname, String port, String sequenceName ) { 75 | String url = "http://" + realHostname + ":" + port + NextSequenceValueServlet.CONTEXT_PATH 76 | + "?name=" + sequenceName; 77 | return Const.replace( url, " ", "%20" ); 78 | } 79 | 80 | public static String getAuthString( String user, String pass ) { 81 | String plainAuth = user + ":" + pass; 82 | String auth = "Basic " + Base64.encodeBase64String( plainAuth.getBytes() ); 83 | return auth; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/carte/PauseTransSample.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import org.apache.commons.codec.binary.Base64; 17 | import org.apache.http.HttpResponse; 18 | import org.apache.http.HttpStatus; 19 | import org.apache.http.client.HttpClient; 20 | import org.apache.http.client.methods.HttpGet; 21 | import org.apache.http.client.protocol.HttpClientContext; 22 | import org.apache.http.message.BasicHeader; 23 | import org.pentaho.di.core.Const; 24 | import org.pentaho.di.core.util.HttpClientManager; 25 | import org.pentaho.di.core.util.HttpClientUtil; 26 | import org.pentaho.di.www.PauseTransServlet; 27 | 28 | public class PauseTransSample extends AbstractSample { 29 | 30 | public static void main( String[] args ) throws Exception { 31 | if ( args.length < 5 ) { 32 | System.out.println( " You must specify the following parameters Carte_host Carte_port " 33 | + "Carte_login Carte_password job_name" ); 34 | System.out.println( " For example 127.0.0.1 8088 cluster cluster my_trans" ); 35 | System.exit( 1 ); 36 | } 37 | init( args[ 0 ], Integer.parseInt( args[ 1 ] ), args[ 2 ], args[ 3 ] ); 38 | // building target url 39 | String urlString = getUrlString( args[ 0 ], args[ 1 ], args[ 4 ] ); 40 | 41 | //building auth token 42 | String auth = getAuthString( args[ 2 ], args[ 3 ] ); 43 | 44 | //adding binary to servlet 45 | String response = sendPauseTransRequest( urlString, auth ); 46 | if ( response != null ) { 47 | System.out.println( "Server response:" ); 48 | System.out.println( response ); 49 | } 50 | } 51 | 52 | public static String sendPauseTransRequest( String urlString, String authentication ) throws Exception { 53 | HttpGet method = new HttpGet( urlString ); 54 | HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); 55 | //adding authorization token 56 | if ( authentication != null ) { 57 | method.addHeader( new BasicHeader( "Authorization", authentication ) ); 58 | } 59 | 60 | //executing method 61 | HttpClient client = HttpClientManager.getInstance().createDefaultClient(); 62 | HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); 63 | int code = httpResponse.getStatusLine().getStatusCode(); 64 | String response = HttpClientUtil.responseToString( httpResponse ); 65 | method.releaseConnection(); 66 | if ( code >= HttpStatus.SC_BAD_REQUEST ) { 67 | System.out.println( "Error occurred during pausing transformation." ); 68 | return null; 69 | } 70 | return response; 71 | } 72 | 73 | public static String getUrlString( String realHostname, String port, String transName ) { 74 | String url = "http://" + realHostname + ":" + port + PauseTransServlet.CONTEXT_PATH 75 | + "?xml=Y&name=" + transName; 76 | return Const.replace( url, " ", "%20" ); 77 | } 78 | 79 | public static String getAuthString( String user, String pass ) { 80 | String plainAuth = user + ":" + pass; 81 | String auth = "Basic " + Base64.encodeBase64String( plainAuth.getBytes() ); 82 | return auth; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/carte/PrepareExecutionTransSample.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import org.apache.commons.codec.binary.Base64; 17 | import org.apache.http.HttpResponse; 18 | import org.apache.http.HttpStatus; 19 | import org.apache.http.client.HttpClient; 20 | import org.apache.http.client.methods.HttpGet; 21 | import org.apache.http.client.protocol.HttpClientContext; 22 | import org.apache.http.message.BasicHeader; 23 | import org.pentaho.di.core.Const; 24 | import org.pentaho.di.core.util.HttpClientManager; 25 | import org.pentaho.di.core.util.HttpClientUtil; 26 | import org.pentaho.di.www.PrepareExecutionTransServlet; 27 | 28 | public class PrepareExecutionTransSample extends AbstractSample { 29 | public static void main( String[] args ) throws Exception { 30 | if ( args.length < 5 ) { 31 | System.out.println( " You must specify the following parameters Carte_host Carte_port " 32 | + "Carte_login Carte_password trans_name" ); 33 | System.out.println( " For example 127.0.0.1 8088 cluster cluster dummy_trans" ); 34 | System.exit( 1 ); 35 | } 36 | init( args[ 0 ], Integer.parseInt( args[ 1 ] ), args[ 2 ], args[ 3 ] ); 37 | // building target url 38 | String urlString = getUrlString( args[ 0 ], args[ 1 ], args[ 4 ] ); 39 | 40 | //building auth token 41 | String auth = getAuthString( args[ 2 ], args[ 3 ] ); 42 | 43 | String response = sendPrepareExecutionTransRequest( urlString, auth ); 44 | if ( response != null ) { 45 | System.out.println( "Server response:" ); 46 | System.out.println( response ); 47 | } 48 | } 49 | 50 | public static String sendPrepareExecutionTransRequest( String urlString, String authentication ) throws Exception { 51 | HttpGet method = new HttpGet( urlString ); 52 | HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); 53 | //adding authorization token 54 | if ( authentication != null ) { 55 | method.addHeader( new BasicHeader( "Authorization", authentication ) ); 56 | } 57 | 58 | //executing method 59 | HttpClient client = HttpClientManager.getInstance().createDefaultClient(); 60 | HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); 61 | int code = httpResponse.getStatusLine().getStatusCode(); 62 | String response = HttpClientUtil.responseToString( httpResponse ); 63 | method.releaseConnection(); 64 | if ( code >= HttpStatus.SC_BAD_REQUEST ) { 65 | System.out.println( "Error occurred during preparing transformation execution." ); 66 | return null; 67 | } 68 | return response; 69 | } 70 | 71 | public static String getUrlString( String realHostname, String port, String jobName ) { 72 | String url = "http://" + realHostname + ":" + port + PrepareExecutionTransServlet.CONTEXT_PATH 73 | + "?xml=Y&name=" + jobName; 74 | return Const.replace( url, " ", "%20" ); 75 | } 76 | 77 | public static String getAuthString( String user, String pass ) { 78 | String plainAuth = user + ":" + pass; 79 | String auth = "Basic " + Base64.encodeBase64String( plainAuth.getBytes() ); 80 | return auth; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/carte/RegisterJobSample.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import org.apache.commons.codec.binary.Base64; 17 | import org.apache.http.HttpResponse; 18 | import org.apache.http.HttpStatus; 19 | import org.apache.http.client.HttpClient; 20 | import org.apache.http.client.methods.HttpPost; 21 | import org.apache.http.client.protocol.HttpClientContext; 22 | import org.apache.http.entity.ByteArrayEntity; 23 | import org.apache.http.message.BasicHeader; 24 | import org.pentaho.di.core.KettleEnvironment; 25 | import org.pentaho.di.core.util.HttpClientManager; 26 | import org.pentaho.di.core.util.HttpClientUtil; 27 | import org.pentaho.di.job.JobConfiguration; 28 | import org.pentaho.di.job.JobExecutionConfiguration; 29 | import org.pentaho.di.job.JobMeta; 30 | import org.pentaho.di.www.RegisterJobServlet; 31 | 32 | public class RegisterJobSample extends AbstractSample { 33 | 34 | public static void main( String[] args ) throws Exception { 35 | if ( args.length != 5 ) { 36 | System.out.println( " You must specify the following parameters Carte_host Carte_port " 37 | + "Carte_login Carte_password path_to_job" ); 38 | System.out.println( " For example 127.0.0.1 8088 cluster cluster d:\\work\\dummy-job.kjb " ); 39 | System.exit( 1 ); 40 | } 41 | init( args[ 0 ], Integer.parseInt( args[ 1 ] ), args[ 2 ], args[ 3 ] ); 42 | // building target url 43 | String urlString = getUrlString( args[ 0 ], args[ 1 ] ); 44 | 45 | //building auth token 46 | String auth = getAuthString( args[ 2 ], args[ 3 ] ); 47 | 48 | //adding binary to servlet 49 | String response = addJobToServlet( urlString, buildJobConfig( args[ 4 ] ), auth ); 50 | 51 | if ( response != null ) { 52 | System.out.println( "Server response:" ); 53 | System.out.println( response ); 54 | } 55 | } 56 | 57 | public static String buildJobConfig( String jobname ) throws Exception { 58 | String xml = null; 59 | KettleEnvironment.init(); 60 | JobMeta jm = new JobMeta( jobname, null ); 61 | JobConfiguration jc = new JobConfiguration( jm, new JobExecutionConfiguration() ); 62 | xml = jc.getXML(); 63 | return xml; 64 | } 65 | 66 | public static String addJobToServlet( String urlString, String xml, String authentication ) throws Exception { 67 | HttpPost method = new HttpPost( urlString ); 68 | method.setEntity( new ByteArrayEntity( xml.getBytes( "UTF-8" ) ) ); 69 | HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); 70 | method.addHeader( new BasicHeader( "Content-Type", "text/xml;charset=UTF-8" ) ); 71 | //adding authorization token 72 | if ( authentication != null ) { 73 | method.addHeader( new BasicHeader( "Authorization", authentication ) ); 74 | } 75 | 76 | //executing method 77 | HttpClient client = HttpClientManager.getInstance().createDefaultClient(); 78 | HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); 79 | int code = httpResponse.getStatusLine().getStatusCode(); 80 | String response = HttpClientUtil.responseToString( httpResponse ); 81 | method.releaseConnection(); 82 | if ( code >= HttpStatus.SC_BAD_REQUEST ) { 83 | System.out.println( "Error occurred during job submission." ); 84 | return null; 85 | } 86 | return response; 87 | } 88 | 89 | public static String getUrlString( String realHostname, String port ) { 90 | return "http://" + realHostname + ":" + port + RegisterJobServlet.CONTEXT_PATH + "/?xml=Y"; 91 | } 92 | 93 | public static String getAuthString( String user, String pass ) { 94 | String plainAuth = user + ":" + pass; 95 | String auth = "Basic " + Base64.encodeBase64String( plainAuth.getBytes() ); 96 | return auth; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/carte/RegisterPackageSample.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import org.apache.commons.codec.binary.Base64; 17 | import org.apache.http.HttpResponse; 18 | import org.apache.http.HttpStatus; 19 | import org.apache.http.client.HttpClient; 20 | import org.apache.http.client.methods.HttpPost; 21 | import org.apache.http.client.protocol.HttpClientContext; 22 | import org.apache.http.entity.InputStreamEntity; 23 | import org.apache.http.message.BasicHeader; 24 | import org.pentaho.di.core.Const; 25 | import org.pentaho.di.core.util.HttpClientManager; 26 | import org.pentaho.di.core.util.HttpClientUtil; 27 | import org.pentaho.di.www.RegisterPackageServlet; 28 | 29 | import java.io.FileInputStream; 30 | import java.io.InputStream; 31 | import java.io.UnsupportedEncodingException; 32 | import java.net.URLEncoder; 33 | 34 | public class RegisterPackageSample extends AbstractSample { 35 | 36 | public static void main( String[] args ) throws Exception { 37 | if ( args.length != 7 ) { 38 | System.out.println( " You must specify the following parameters Carte_host Carte_port " 39 | + "Carte_login Carte_password Trans_or_job Trans_or_job_name path_to_zip" ); 40 | System.out.println( " For example 127.0.0.1 8088 cluster cluster trans dummy-trans.ktr d:\\work\\export.zip " ); 41 | System.exit( 1 ); 42 | } 43 | init( args[ 0 ], Integer.parseInt( args[ 1 ] ), args[ 2 ], args[ 3 ] ); 44 | // building target url 45 | String urlString = getUrlString( args[ 0 ], args[ 1 ], args[ 4 ], args[ 5 ] ); 46 | 47 | //building auth token 48 | String auth = getAuthString( args[ 2 ], args[ 3 ] ); 49 | 50 | // Open input stream to package 51 | FileInputStream is = new FileInputStream( args[ 6 ] ); 52 | 53 | //adding packing to servlet 54 | addPackageToServlet( urlString, is, auth ); 55 | 56 | // Close input stream 57 | is.close(); 58 | } 59 | 60 | public static void addPackageToServlet( String urlString, InputStream is, String authentication ) throws Exception { 61 | HttpPost method = new HttpPost( urlString ); 62 | method.setEntity( new InputStreamEntity( is ) ); 63 | HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); 64 | method.addHeader( new BasicHeader( "Content-Type", "binary/zip" ) ); 65 | //adding authorization token 66 | if ( authentication != null ) { 67 | method.addHeader( new BasicHeader( "Authorization", authentication ) ); 68 | } 69 | 70 | //executing method 71 | HttpClient client = HttpClientManager.getInstance().createDefaultClient(); 72 | HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); 73 | int code = httpResponse.getStatusLine().getStatusCode(); 74 | String response = HttpClientUtil.responseToString( httpResponse ); 75 | method.releaseConnection(); 76 | if ( code >= HttpStatus.SC_BAD_REQUEST ) { 77 | System.out.println( "Error occurred during export submission." ); 78 | } 79 | System.out.println( "Server response:" ); 80 | System.out.println( response ); 81 | } 82 | 83 | public static String getUrlString( String realHostname, String port, String type, String load ) 84 | throws UnsupportedEncodingException { 85 | String url = "http://" + realHostname + ":" + port + RegisterPackageServlet.CONTEXT_PATH 86 | + "/?type=" + type + "&load=" + URLEncoder.encode( load, "UTF-8" ); 87 | return Const.replace( url, " ", "%20" ); 88 | } 89 | 90 | public static String getAuthString( String user, String pass ) { 91 | String plainAuth = user + ":" + pass; 92 | String auth = "Basic " + Base64.encodeBase64String( plainAuth.getBytes() ); 93 | return auth; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/carte/RegisterSlaveSample.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import org.apache.commons.codec.binary.Base64; 17 | import org.apache.commons.lang.StringEscapeUtils; 18 | import org.apache.http.HttpResponse; 19 | import org.apache.http.HttpStatus; 20 | import org.apache.http.client.HttpClient; 21 | import org.apache.http.client.methods.HttpPost; 22 | import org.apache.http.client.protocol.HttpClientContext; 23 | import org.apache.http.entity.ByteArrayEntity; 24 | import org.apache.http.message.BasicHeader; 25 | import org.pentaho.di.core.Const; 26 | import org.pentaho.di.core.util.HttpClientManager; 27 | import org.pentaho.di.core.util.HttpClientUtil; 28 | import org.pentaho.di.www.RegisterSlaveServlet; 29 | 30 | import java.text.SimpleDateFormat; 31 | import java.util.Date; 32 | 33 | public class RegisterSlaveSample extends AbstractSample { 34 | public static void main( String[] args ) throws Exception { 35 | if ( args.length < 9 ) { 36 | System.out.println( " You must specify the following parameters Carte_host Carte_port " 37 | + "Carte_login Carte_password server_name host port username password" ); 38 | System.out.println( " For example 127.0.0.1 8088 cluster cluster my-localhost localhost 9100 cluster cluster" ); 39 | System.exit( 1 ); 40 | } 41 | init( args[ 0 ], Integer.parseInt( args[ 1 ] ), args[ 2 ], args[ 3 ] ); 42 | // building target url 43 | String urlString = getUrlString( args[ 0 ], args[ 1 ] ); 44 | 45 | //building auth token 46 | String auth = getAuthString( args[ 2 ], args[ 3 ] ); 47 | 48 | String xml = generateSlaveDetectionXML( args[ 4 ], args[ 5 ], args[ 6 ], args[ 7 ], args[ 8 ] ); 49 | String response = sendRegisterSlaveRequest( urlString, auth, xml ); 50 | if ( response != null ) { 51 | System.out.println( "Server response:" ); 52 | System.out.println( response ); 53 | } 54 | } 55 | 56 | public static String sendRegisterSlaveRequest( String urlString, String authentication, String xml ) 57 | throws Exception { 58 | HttpPost method = new HttpPost( urlString ); 59 | method.setEntity( new ByteArrayEntity( xml.getBytes( "UTF-8" ) ) ); 60 | HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); 61 | //adding authorization token 62 | if ( authentication != null ) { 63 | method.addHeader( new BasicHeader( "Authorization", authentication ) ); 64 | } 65 | 66 | //executing method 67 | HttpClient client = HttpClientManager.getInstance().createDefaultClient(); 68 | HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); 69 | int code = httpResponse.getStatusLine().getStatusCode(); 70 | String response = HttpClientUtil.responseToString( httpResponse ); 71 | method.releaseConnection(); 72 | if ( code >= HttpStatus.SC_BAD_REQUEST ) { 73 | System.out.println( "Error occurred during registering slave." ); 74 | return null; 75 | } 76 | return response; 77 | } 78 | 79 | public static String generateSlaveDetectionXML( String name, String host, String port, 80 | String userName, String pass ) { 81 | String lastActiveDate = new SimpleDateFormat( "yyyy/MM/dd HH:mm:ss.SSS" ).format( new Date() ); 82 | String xml = "" 83 | + " " 84 | + " " + StringEscapeUtils.escapeXml( name ) + "" 85 | + " " + host + "" 86 | + " " + port + "" 87 | + " " 88 | + " " + userName + "" 89 | + " " + pass + "" 90 | + " " 91 | + " " 92 | + " " 93 | + " N" 94 | + " " 95 | + " Y" 96 | + " " + StringEscapeUtils.escapeXml( lastActiveDate ) + "" 97 | + " " 98 | + ""; 99 | return xml; 100 | } 101 | 102 | public static String getUrlString( String realHostname, String port ) { 103 | String url = "http://" + realHostname + ":" + port + RegisterSlaveServlet.CONTEXT_PATH + "/"; 104 | return Const.replace( url, " ", "%20" ); 105 | } 106 | 107 | public static String getAuthString( String user, String pass ) { 108 | String plainAuth = user + ":" + pass; 109 | String auth = "Basic " + Base64.encodeBase64String( plainAuth.getBytes() ); 110 | return auth; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/carte/RegisterTransSample.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import org.apache.commons.codec.binary.Base64; 17 | import org.apache.http.HttpResponse; 18 | import org.apache.http.HttpStatus; 19 | import org.apache.http.client.HttpClient; 20 | import org.apache.http.client.methods.HttpPost; 21 | import org.apache.http.client.protocol.HttpClientContext; 22 | import org.apache.http.entity.ByteArrayEntity; 23 | import org.apache.http.message.BasicHeader; 24 | import org.pentaho.di.core.Const; 25 | import org.pentaho.di.core.KettleEnvironment; 26 | import org.pentaho.di.core.util.HttpClientManager; 27 | import org.pentaho.di.core.util.HttpClientUtil; 28 | import org.pentaho.di.trans.TransConfiguration; 29 | import org.pentaho.di.trans.TransExecutionConfiguration; 30 | import org.pentaho.di.trans.TransMeta; 31 | import org.pentaho.di.www.RegisterTransServlet; 32 | 33 | public class RegisterTransSample extends AbstractSample { 34 | 35 | public static void main( String[] args ) throws Exception { 36 | if ( args.length != 5 ) { 37 | System.out.println( " You must specify the following parameters Carte_host Carte_port " 38 | + "Carte_login Carte_password path_to_trans" ); 39 | System.out.println( " For example 127.0.0.1 8088 cluster cluster d:\\work\\dummy-trans.ktr " ); 40 | System.exit( 1 ); 41 | } 42 | init( args[ 0 ], Integer.parseInt( args[ 1 ] ), args[ 2 ], args[ 3 ] ); 43 | // building target url 44 | String urlString = getUrlString( args[ 0 ], args[ 1 ] ); 45 | 46 | //building auth token 47 | String auth = getAuthString( args[ 2 ], args[ 3 ] ); 48 | 49 | //adding binary to servlet 50 | String response = addTransToServlet( urlString, buildTransConfig( args[ 4 ] ), auth ); 51 | if ( response != null ) { 52 | System.out.println( "Server response:" ); 53 | System.out.println( response ); 54 | } 55 | } 56 | 57 | public static String buildTransConfig( String transname ) throws Exception { 58 | String xml = null; 59 | KettleEnvironment.init(); 60 | TransMeta tm = new TransMeta( transname ); 61 | TransConfiguration tc = new TransConfiguration( tm, new TransExecutionConfiguration() ); 62 | xml = tc.getXML(); 63 | return xml; 64 | } 65 | 66 | public static String addTransToServlet( String urlString, String xml, String authentication ) throws Exception { 67 | HttpPost method = new HttpPost( urlString ); 68 | method.setEntity( new ByteArrayEntity( xml.getBytes( "UTF-8" ) ) ); 69 | HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); 70 | method.addHeader( new BasicHeader( "Content-Type", "text/xml;charset=UTF-8" ) ); 71 | //adding authorization token 72 | if ( authentication != null ) { 73 | method.addHeader( new BasicHeader( "Authorization", authentication ) ); 74 | } 75 | 76 | //executing method 77 | HttpClient client = HttpClientManager.getInstance().createDefaultClient(); 78 | HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); 79 | int code = httpResponse.getStatusLine().getStatusCode(); 80 | String response = HttpClientUtil.responseToString( httpResponse ); 81 | method.releaseConnection(); 82 | if ( code >= HttpStatus.SC_BAD_REQUEST ) { 83 | System.out.println( "Error occurred during transformation submission." ); 84 | return null; 85 | } 86 | return response; 87 | } 88 | 89 | public static String getUrlString( String realHostname, String port ) { 90 | String url = "http://" + realHostname + ":" + port + RegisterTransServlet.CONTEXT_PATH + "?xml=Y"; 91 | return Const.replace( url, " ", "%20" ); 92 | } 93 | 94 | public static String getAuthString( String user, String pass ) { 95 | String plainAuth = user + ":" + pass; 96 | String auth = "Basic " + Base64.encodeBase64String( plainAuth.getBytes() ); 97 | return auth; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/carte/RemoveJobSample.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import org.apache.commons.codec.binary.Base64; 17 | import org.apache.http.HttpResponse; 18 | import org.apache.http.HttpStatus; 19 | import org.apache.http.client.HttpClient; 20 | import org.apache.http.client.methods.HttpGet; 21 | import org.apache.http.client.protocol.HttpClientContext; 22 | import org.apache.http.message.BasicHeader; 23 | import org.pentaho.di.core.Const; 24 | import org.pentaho.di.core.util.HttpClientManager; 25 | import org.pentaho.di.core.util.HttpClientUtil; 26 | import org.pentaho.di.www.RemoveJobServlet; 27 | 28 | public class RemoveJobSample extends AbstractSample { 29 | public static void main( String[] args ) throws Exception { 30 | if ( args.length < 5 ) { 31 | System.out.println( " You must specify the following parameters Carte_host Carte_port " 32 | + "Carte_login Carte_password job_name" ); 33 | System.out.println( " For example 127.0.0.1 8088 cluster cluster dummy_job" ); 34 | System.exit( 1 ); 35 | } 36 | init( args[ 0 ], Integer.parseInt( args[ 1 ] ), args[ 2 ], args[ 3 ] ); 37 | // building target url 38 | String urlString = getUrlString( args[ 0 ], args[ 1 ], args[ 4 ] ); 39 | 40 | //building auth token 41 | String auth = getAuthString( args[ 2 ], args[ 3 ] ); 42 | 43 | String response = sendRemoveJobRequest( urlString, auth ); 44 | if ( response != null ) { 45 | System.out.println( "Server response:" ); 46 | System.out.println( response ); 47 | } 48 | } 49 | 50 | public static String sendRemoveJobRequest( String urlString, String authentication ) throws Exception { 51 | HttpGet method = new HttpGet( urlString ); 52 | HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); 53 | //adding authorization token 54 | if ( authentication != null ) { 55 | method.addHeader( new BasicHeader( "Authorization", authentication ) ); 56 | } 57 | 58 | //executing method 59 | HttpClient client = HttpClientManager.getInstance().createDefaultClient(); 60 | HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); 61 | int code = httpResponse.getStatusLine().getStatusCode(); 62 | String response = HttpClientUtil.responseToString( httpResponse ); 63 | method.releaseConnection(); 64 | if ( code >= HttpStatus.SC_BAD_REQUEST ) { 65 | System.out.println( "Error occurred during removing job." ); 66 | return null; 67 | } 68 | return response; 69 | } 70 | 71 | public static String getUrlString( String realHostname, String port, String job_name ) { 72 | String urlString = "http://" + realHostname + ":" + port 73 | + RemoveJobServlet.CONTEXT_PATH + "/?xml=Y&name=" + job_name; 74 | urlString = Const.replace( urlString, " ", "%20" ); 75 | return urlString; 76 | } 77 | 78 | public static String getAuthString( String user, String pass ) { 79 | String plainAuth = user + ":" + pass; 80 | String auth = "Basic " + Base64.encodeBase64String( plainAuth.getBytes() ); 81 | return auth; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/carte/RemoveTransSample.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import org.apache.commons.codec.binary.Base64; 17 | import org.apache.http.HttpResponse; 18 | import org.apache.http.HttpStatus; 19 | import org.apache.http.client.HttpClient; 20 | import org.apache.http.client.methods.HttpGet; 21 | import org.apache.http.client.protocol.HttpClientContext; 22 | import org.apache.http.message.BasicHeader; 23 | import org.pentaho.di.core.Const; 24 | import org.pentaho.di.core.util.HttpClientManager; 25 | import org.pentaho.di.core.util.HttpClientUtil; 26 | import org.pentaho.di.www.RegisterSlaveServlet; 27 | 28 | public class RemoveTransSample extends AbstractSample { 29 | public static void main( String[] args ) throws Exception { 30 | if ( args.length < 5 ) { 31 | System.out.println( " You must specify the following parameters Carte_host Carte_port " 32 | + "Carte_login Carte_password trans_name" ); 33 | System.out.println( " For example 127.0.0.1 8088 cluster cluster dummy_trans" ); 34 | System.exit( 1 ); 35 | } 36 | init( args[ 0 ], Integer.parseInt( args[ 1 ] ), args[ 2 ], args[ 3 ] ); 37 | // building target url 38 | String urlString = getUrlString( args[ 0 ], args[ 1 ], args[ 4 ] ); 39 | 40 | //building auth token 41 | String auth = getAuthString( args[ 2 ], args[ 3 ] ); 42 | 43 | String response = sendRemoveTransRequest( urlString, auth ); 44 | if ( response != null ) { 45 | System.out.println( "Server response:" ); 46 | System.out.println( response ); 47 | } 48 | } 49 | 50 | public static String sendRemoveTransRequest( String urlString, String authentication ) throws Exception { 51 | HttpGet method = new HttpGet( urlString ); 52 | HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); 53 | //adding authorization token 54 | if ( authentication != null ) { 55 | method.addHeader( new BasicHeader( "Authorization", authentication ) ); 56 | } 57 | 58 | //executing method 59 | HttpClient client = HttpClientManager.getInstance().createDefaultClient(); 60 | HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); 61 | int code = httpResponse.getStatusLine().getStatusCode(); 62 | String response = HttpClientUtil.responseToString( httpResponse ); 63 | method.releaseConnection(); 64 | if ( code >= HttpStatus.SC_BAD_REQUEST ) { 65 | System.out.println( "Error occurred during removing transformation." ); 66 | return null; 67 | } 68 | return response; 69 | } 70 | 71 | public static String getUrlString( String realHostname, String port, String transName ) { 72 | String url = "http://" + realHostname + ":" + port + RegisterSlaveServlet.CONTEXT_PATH 73 | + "?xml=Y&name=" + transName; 74 | return Const.replace( url, " ", "%20" ); 75 | } 76 | 77 | public static String getAuthString( String user, String pass ) { 78 | String plainAuth = user + ":" + pass; 79 | String auth = "Basic " + Base64.encodeBase64String( plainAuth.getBytes() ); 80 | return auth; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/carte/RunJobSample.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import org.apache.commons.codec.binary.Base64; 17 | import org.apache.http.HttpResponse; 18 | import org.apache.http.HttpStatus; 19 | import org.apache.http.client.HttpClient; 20 | import org.apache.http.client.methods.HttpGet; 21 | import org.apache.http.client.protocol.HttpClientContext; 22 | import org.apache.http.message.BasicHeader; 23 | import org.pentaho.di.core.Const; 24 | import org.pentaho.di.core.util.HttpClientManager; 25 | import org.pentaho.di.core.util.HttpClientUtil; 26 | import org.pentaho.di.www.RunJobServlet; 27 | 28 | import java.io.UnsupportedEncodingException; 29 | import java.net.URLEncoder; 30 | 31 | public class RunJobSample extends AbstractSample { 32 | public static void main( String[] args ) throws Exception { 33 | if ( args.length < 6 ) { 34 | System.out.println( " You must specify the following parameters Carte_host Carte_port " 35 | + "Carte_login Carte_password full_job_path log_level" ); 36 | System.out.println( " For example 127.0.0.1 8088 cluster cluster home/admin/dummy_job Debug" ); 37 | System.exit( 1 ); 38 | } 39 | init( args[ 0 ], Integer.parseInt( args[ 1 ] ), args[ 2 ], args[ 3 ] ); 40 | // building target url 41 | String urlString = getUrlString( args[ 0 ], args[ 1 ], args[ 4 ], args[ 5 ] ); 42 | 43 | //building auth token 44 | String auth = getAuthString( args[ 2 ], args[ 3 ] ); 45 | 46 | String response = sendRunJobRequest( urlString, auth ); 47 | if ( response != null ) { 48 | System.out.println( "Server response:" ); 49 | System.out.println( response ); 50 | } 51 | } 52 | 53 | public static String sendRunJobRequest( String urlString, String authentication ) throws Exception { 54 | HttpGet method = new HttpGet( urlString ); 55 | HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); 56 | //adding authorization token 57 | if ( authentication != null ) { 58 | method.addHeader( new BasicHeader( "Authorization", authentication ) ); 59 | } 60 | 61 | //executing method 62 | HttpClient client = HttpClientManager.getInstance().createDefaultClient(); 63 | HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); 64 | int code = httpResponse.getStatusLine().getStatusCode(); 65 | String response = HttpClientUtil.responseToString( httpResponse ); 66 | method.releaseConnection(); 67 | if ( code >= HttpStatus.SC_BAD_REQUEST ) { 68 | System.out.println( "Error occurred during stopping transformation." ); 69 | return null; 70 | } 71 | return response; 72 | } 73 | 74 | public static String getUrlString( String realHostname, String port, String jobPath, 75 | String level ) throws UnsupportedEncodingException { 76 | String url = "http://" + realHostname + ":" + port + RunJobServlet.CONTEXT_PATH 77 | + "?job=" + URLEncoder.encode( jobPath, "UTF-8" ) + "&level=" + level; 78 | return Const.replace( url, " ", "%20" ); 79 | } 80 | 81 | public static String getAuthString( String user, String pass ) { 82 | String plainAuth = user + ":" + pass; 83 | String auth = "Basic " + Base64.encodeBase64String( plainAuth.getBytes() ); 84 | return auth; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/carte/RunTransSample.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import org.apache.commons.codec.binary.Base64; 17 | import org.apache.http.HttpResponse; 18 | import org.apache.http.HttpStatus; 19 | import org.apache.http.client.HttpClient; 20 | import org.apache.http.client.methods.HttpGet; 21 | import org.apache.http.client.protocol.HttpClientContext; 22 | import org.apache.http.message.BasicHeader; 23 | import org.pentaho.di.core.Const; 24 | import org.pentaho.di.core.util.HttpClientManager; 25 | import org.pentaho.di.core.util.HttpClientUtil; 26 | import org.pentaho.di.www.RunTransServlet; 27 | 28 | import java.io.UnsupportedEncodingException; 29 | import java.net.URLEncoder; 30 | 31 | public class RunTransSample extends AbstractSample { 32 | public static void main( String[] args ) throws Exception { 33 | if ( args.length < 6 ) { 34 | System.out.println( " You must specify the following parameters Carte_host Carte_port " 35 | + "Carte_login Carte_password full_transformation_path log_level" ); 36 | System.out.println( " For example 127.0.0.1 8088 cluster cluster home/admin/dummy_trans Debug" ); 37 | System.exit( 1 ); 38 | } 39 | init( args[ 0 ], Integer.parseInt( args[ 1 ] ), args[ 2 ], args[ 3 ] ); 40 | // building target url 41 | String urlString = getUrlString( args[ 0 ], args[ 1 ], args[ 4 ], args[ 5 ] ); 42 | 43 | //building auth token 44 | String auth = getAuthString( args[ 2 ], args[ 3 ] ); 45 | 46 | String response = sendRunTransRequest( urlString, auth ); 47 | if ( response != null ) { 48 | System.out.println( "Server response:" ); 49 | System.out.println( response ); 50 | } 51 | } 52 | 53 | public static String sendRunTransRequest( String urlString, String authentication ) throws Exception { 54 | HttpGet method = new HttpGet( urlString ); 55 | HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); 56 | //adding authorization token 57 | if ( authentication != null ) { 58 | method.addHeader( new BasicHeader( "Authorization", authentication ) ); 59 | } 60 | 61 | //executing method 62 | HttpClient client = HttpClientManager.getInstance().createDefaultClient(); 63 | HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); 64 | int code = httpResponse.getStatusLine().getStatusCode(); 65 | String response = HttpClientUtil.responseToString( httpResponse ); 66 | method.releaseConnection(); 67 | if ( code >= HttpStatus.SC_BAD_REQUEST ) { 68 | System.out.println( "Error occurred during stopping transformation." ); 69 | return null; 70 | } 71 | return response; 72 | } 73 | 74 | public static String getUrlString( String realHostname, String port, String transPath, 75 | String level ) throws UnsupportedEncodingException { 76 | String url = "http://" + realHostname + ":" + port + RunTransServlet.CONTEXT_PATH 77 | + "?trans=" + URLEncoder.encode( transPath, "UTF-8" ) + "&level=" + level; 78 | return Const.replace( url, " ", "%20" ); 79 | } 80 | 81 | public static String getAuthString( String user, String pass ) { 82 | String plainAuth = user + ":" + pass; 83 | String auth = "Basic " + Base64.encodeBase64String( plainAuth.getBytes() ); 84 | return auth; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/carte/SniffStepSample.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import org.apache.commons.codec.binary.Base64; 17 | import org.apache.http.HttpResponse; 18 | import org.apache.http.HttpStatus; 19 | import org.apache.http.client.HttpClient; 20 | import org.apache.http.client.methods.HttpGet; 21 | import org.apache.http.client.protocol.HttpClientContext; 22 | import org.apache.http.message.BasicHeader; 23 | import org.pentaho.di.core.Const; 24 | import org.pentaho.di.core.util.HttpClientManager; 25 | import org.pentaho.di.core.util.HttpClientUtil; 26 | import org.pentaho.di.www.SniffStepServlet; 27 | 28 | public class SniffStepSample extends AbstractSample { 29 | public static void main( String[] args ) throws Exception { 30 | if ( args.length < 6 ) { 31 | System.out.println( " You must specify the following parameters Carte_host Carte_port " 32 | + "Carte_login Carte_password trans_name full_step_name" ); 33 | System.out.println( " For example 127.0.0.1 8088 cluster cluster dummy_trans \"Dummy (do nothing)\"" ); 34 | System.exit( 1 ); 35 | } 36 | init( args[ 0 ], Integer.parseInt( args[ 1 ] ), args[ 2 ], args[ 3 ] ); 37 | // building target url 38 | String urlString = getUrlString( args[ 0 ], args[ 1 ], args[ 4 ], args[ 5 ] ); 39 | 40 | //building auth token 41 | String auth = getAuthString( args[ 2 ], args[ 3 ] ); 42 | 43 | String response = sendSniffStepRequest( urlString, auth ); 44 | if ( response != null ) { 45 | System.out.println( "Server response:" ); 46 | System.out.println( response ); 47 | } 48 | } 49 | 50 | public static String sendSniffStepRequest( String urlString, String authentication ) throws Exception { 51 | HttpGet method = new HttpGet( urlString ); 52 | HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); 53 | //adding authorization token 54 | if ( authentication != null ) { 55 | method.addHeader( new BasicHeader( "Authorization", authentication ) ); 56 | } 57 | 58 | //executing method 59 | HttpClient client = HttpClientManager.getInstance().createDefaultClient(); 60 | HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); 61 | int code = httpResponse.getStatusLine().getStatusCode(); 62 | String response = HttpClientUtil.responseToString( httpResponse ); 63 | method.releaseConnection(); 64 | if ( code >= HttpStatus.SC_BAD_REQUEST ) { 65 | System.out.println( "Error occurred during starting job." ); 66 | return null; 67 | } 68 | return response; 69 | } 70 | 71 | public static String getUrlString( String realHostname, String port, String transName, String stepName ) { 72 | String url = "http://" + realHostname + ":" + port + SniffStepServlet.CONTEXT_PATH 73 | + "/?xml=Y&trans=" + transName + "&step=" + stepName; 74 | return Const.replace( url, " ", "%20" ); 75 | } 76 | 77 | public static String getAuthString( String user, String pass ) { 78 | String plainAuth = user + ":" + pass; 79 | String auth = "Basic " + Base64.encodeBase64String( plainAuth.getBytes() ); 80 | return auth; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/carte/StartExecutionTransSample.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import org.apache.commons.codec.binary.Base64; 17 | import org.apache.http.HttpResponse; 18 | import org.apache.http.HttpStatus; 19 | import org.apache.http.client.HttpClient; 20 | import org.apache.http.client.methods.HttpGet; 21 | import org.apache.http.client.protocol.HttpClientContext; 22 | import org.apache.http.message.BasicHeader; 23 | import org.pentaho.di.core.Const; 24 | import org.pentaho.di.core.util.HttpClientManager; 25 | import org.pentaho.di.core.util.HttpClientUtil; 26 | import org.pentaho.di.www.StartExecutionTransServlet; 27 | 28 | public class StartExecutionTransSample extends AbstractSample { 29 | public static void main( String[] args ) throws Exception { 30 | if ( args.length < 5 ) { 31 | System.out.println( " You must specify the following parameters Carte_host Carte_port " 32 | + "Carte_login Carte_password trans_name" ); 33 | System.out.println( " For example 127.0.0.1 8088 cluster cluster dummy_trans" ); 34 | System.exit( 1 ); 35 | } 36 | init( args[ 0 ], Integer.parseInt( args[ 1 ] ), args[ 2 ], args[ 3 ] ); 37 | // building target url 38 | String urlString = getUrlString( args[ 0 ], args[ 1 ], args[ 4 ] ); 39 | 40 | //building auth token 41 | String auth = getAuthString( args[ 2 ], args[ 3 ] ); 42 | 43 | String response = sendStartExecutionTransRequest( urlString, auth ); 44 | if ( response != null ) { 45 | System.out.println( "Server response:" ); 46 | System.out.println( response ); 47 | } 48 | } 49 | 50 | public static String sendStartExecutionTransRequest( String urlString, String authentication ) throws Exception { 51 | HttpGet method = new HttpGet( urlString ); 52 | HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); 53 | //adding authorization token 54 | if ( authentication != null ) { 55 | method.addHeader( new BasicHeader( "Authorization", authentication ) ); 56 | } 57 | 58 | //executing method 59 | HttpClient client = HttpClientManager.getInstance().createDefaultClient(); 60 | HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); 61 | int code = httpResponse.getStatusLine().getStatusCode(); 62 | String response = HttpClientUtil.responseToString( httpResponse ); 63 | method.releaseConnection(); 64 | if ( code >= HttpStatus.SC_BAD_REQUEST ) { 65 | System.out.println( "Error occurred during starting transformation execution." ); 66 | return null; 67 | } 68 | return response; 69 | } 70 | 71 | public static String getUrlString( String realHostname, String port, String transName ) { 72 | String url = "http://" + realHostname + ":" + port + StartExecutionTransServlet.CONTEXT_PATH 73 | + "/?xml=Y&name=" + transName; 74 | return Const.replace( url, " ", "%20" ); 75 | } 76 | 77 | public static String getAuthString( String user, String pass ) { 78 | String plainAuth = user + ":" + pass; 79 | String auth = "Basic " + Base64.encodeBase64String( plainAuth.getBytes() ); 80 | return auth; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/carte/StartJobSample.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import org.apache.commons.codec.binary.Base64; 17 | import org.apache.http.HttpResponse; 18 | import org.apache.http.HttpStatus; 19 | import org.apache.http.client.HttpClient; 20 | import org.apache.http.client.methods.HttpGet; 21 | import org.apache.http.client.protocol.HttpClientContext; 22 | import org.apache.http.message.BasicHeader; 23 | import org.pentaho.di.core.Const; 24 | import org.pentaho.di.core.util.HttpClientManager; 25 | import org.pentaho.di.core.util.HttpClientUtil; 26 | import org.pentaho.di.www.StartJobServlet; 27 | 28 | public class StartJobSample extends AbstractSample { 29 | public static void main( String[] args ) throws Exception { 30 | if ( args.length < 5 ) { 31 | System.out.println( " You must specify the following parameters Carte_host Carte_port " 32 | + "Carte_login Carte_password job_name" ); 33 | System.out.println( " For example 127.0.0.1 8088 cluster cluster dummy_job" ); 34 | System.exit( 1 ); 35 | } 36 | init( args[ 0 ], Integer.parseInt( args[ 1 ] ), args[ 2 ], args[ 3 ] ); 37 | // building target url 38 | String urlString = getUrlString( args[ 0 ], args[ 1 ], args[ 4 ] ); 39 | 40 | //building auth token 41 | String auth = getAuthString( args[ 2 ], args[ 3 ] ); 42 | 43 | String response = sendStartJobRequest( urlString, auth ); 44 | if ( response != null ) { 45 | System.out.println( "Server response:" ); 46 | System.out.println( response ); 47 | } 48 | } 49 | 50 | public static String sendStartJobRequest( String urlString, String authentication ) throws Exception { 51 | HttpGet method = new HttpGet( urlString ); 52 | HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); 53 | //adding authorization token 54 | if ( authentication != null ) { 55 | method.addHeader( new BasicHeader( "Authorization", authentication ) ); 56 | } 57 | 58 | //executing method 59 | HttpClient client = HttpClientManager.getInstance().createDefaultClient(); 60 | HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); 61 | int code = httpResponse.getStatusLine().getStatusCode(); 62 | String response = HttpClientUtil.responseToString( httpResponse ); 63 | method.releaseConnection(); 64 | if ( code >= HttpStatus.SC_BAD_REQUEST ) { 65 | System.out.println( "Error occurred during starting job." ); 66 | return null; 67 | } 68 | return response; 69 | } 70 | 71 | public static String getUrlString( String realHostname, String port, String job_name ) { 72 | String urlString = "http://" + realHostname + ":" + port 73 | + StartJobServlet.CONTEXT_PATH + "/?xml=Y&name=" + job_name; 74 | urlString = Const.replace( urlString, " ", "%20" ); 75 | return urlString; 76 | } 77 | 78 | public static String getAuthString( String user, String pass ) { 79 | String plainAuth = user + ":" + pass; 80 | String auth = "Basic " + Base64.encodeBase64String( plainAuth.getBytes() ); 81 | return auth; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/carte/StartTransSample.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import org.apache.commons.codec.binary.Base64; 17 | import org.apache.http.HttpResponse; 18 | import org.apache.http.HttpStatus; 19 | import org.apache.http.client.HttpClient; 20 | import org.apache.http.client.methods.HttpGet; 21 | import org.apache.http.client.protocol.HttpClientContext; 22 | import org.apache.http.message.BasicHeader; 23 | import org.pentaho.di.core.Const; 24 | import org.pentaho.di.core.util.HttpClientManager; 25 | import org.pentaho.di.core.util.HttpClientUtil; 26 | import org.pentaho.di.www.StartTransServlet; 27 | 28 | public class StartTransSample extends AbstractSample { 29 | public static void main( String[] args ) throws Exception { 30 | if ( args.length < 5 ) { 31 | System.out.println( " You must specify the following parameters Carte_host Carte_port " 32 | + "Carte_login Carte_password trans_name" ); 33 | System.out.println( " For example 127.0.0.1 8088 cluster cluster dummy_trans" ); 34 | System.exit( 1 ); 35 | } 36 | init( args[ 0 ], Integer.parseInt( args[ 1 ] ), args[ 2 ], args[ 3 ] ); 37 | // building target url 38 | String urlString = getUrlString( args[ 0 ], args[ 1 ], args[ 4 ] ); 39 | 40 | //building auth token 41 | String auth = getAuthString( args[ 2 ], args[ 3 ] ); 42 | 43 | String response = sendStartTransRequest( urlString, auth ); 44 | if ( response != null ) { 45 | System.out.println( "Server response:" ); 46 | System.out.println( response ); 47 | } 48 | } 49 | 50 | public static String sendStartTransRequest( String urlString, String authentication ) throws Exception { 51 | HttpGet method = new HttpGet( urlString ); 52 | HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); 53 | //adding authorization token 54 | if ( authentication != null ) { 55 | method.addHeader( new BasicHeader( "Authorization", authentication ) ); 56 | } 57 | 58 | //executing method 59 | HttpClient client = HttpClientManager.getInstance().createDefaultClient(); 60 | HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); 61 | int code = httpResponse.getStatusLine().getStatusCode(); 62 | String response = HttpClientUtil.responseToString( httpResponse ); 63 | method.releaseConnection(); 64 | if ( code >= HttpStatus.SC_BAD_REQUEST ) { 65 | System.out.println( "Error occurred during starting transformation." ); 66 | return null; 67 | } 68 | return response; 69 | } 70 | 71 | public static String getUrlString( String realHostname, String port, String transName ) { 72 | String url = "http://" + realHostname + ":" + port + StartTransServlet.CONTEXT_PATH 73 | + "/?xml=Y&name=" + transName; 74 | return Const.replace( url, " ", "%20" ); 75 | } 76 | 77 | public static String getAuthString( String user, String pass ) { 78 | String plainAuth = user + ":" + pass; 79 | String auth = "Basic " + Base64.encodeBase64String( plainAuth.getBytes() ); 80 | return auth; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/carte/StopJobSample.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import org.apache.commons.codec.binary.Base64; 17 | import org.apache.http.HttpResponse; 18 | import org.apache.http.HttpStatus; 19 | import org.apache.http.client.HttpClient; 20 | import org.apache.http.client.methods.HttpGet; 21 | import org.apache.http.client.protocol.HttpClientContext; 22 | import org.apache.http.message.BasicHeader; 23 | import org.pentaho.di.core.Const; 24 | import org.pentaho.di.core.util.HttpClientManager; 25 | import org.pentaho.di.core.util.HttpClientUtil; 26 | import org.pentaho.di.www.StopJobServlet; 27 | 28 | public class StopJobSample extends AbstractSample { 29 | public static void main( String[] args ) throws Exception { 30 | if ( args.length < 5 ) { 31 | System.out.println( " You must specify the following parameters Carte_host Carte_port " 32 | + "Carte_login Carte_password job_name" ); 33 | System.out.println( " For example 127.0.0.1 8088 cluster cluster dummy_job" ); 34 | System.exit( 1 ); 35 | } 36 | init( args[ 0 ], Integer.parseInt( args[ 1 ] ), args[ 2 ], args[ 3 ] ); 37 | // building target url 38 | String urlString = getUrlString( args[ 0 ], args[ 1 ], args[ 4 ] ); 39 | urlString = Const.replace( urlString, " ", "%20" ); 40 | 41 | //building auth token 42 | String auth = getAuthString( args[ 2 ], args[ 3 ] ); 43 | 44 | String response = sendStopJobRequest( urlString, auth ); 45 | if ( response != null ) { 46 | System.out.println( "Server response:" ); 47 | System.out.println( response ); 48 | } 49 | } 50 | 51 | public static String sendStopJobRequest( String urlString, String authentication ) throws Exception { 52 | HttpGet method = new HttpGet( urlString ); 53 | HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); 54 | //adding authorization token 55 | if ( authentication != null ) { 56 | method.addHeader( new BasicHeader( "Authorization", authentication ) ); 57 | } 58 | 59 | //executing method 60 | HttpClient client = HttpClientManager.getInstance().createDefaultClient(); 61 | HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); 62 | int code = httpResponse.getStatusLine().getStatusCode(); 63 | String response = HttpClientUtil.responseToString( httpResponse ); 64 | method.releaseConnection(); 65 | if ( code >= HttpStatus.SC_BAD_REQUEST ) { 66 | System.out.println( "Error occurred during stopping job." ); 67 | return null; 68 | } 69 | return response; 70 | } 71 | 72 | public static String getUrlString( String realHostname, String port, String jobName ) { 73 | String url = "http://" + realHostname + ":" + port + StopJobServlet.CONTEXT_PATH 74 | + "/?xml=Y&name=" + jobName; 75 | return Const.replace( url, " ", "%20" ); 76 | } 77 | 78 | public static String getAuthString( String user, String pass ) { 79 | String plainAuth = user + ":" + pass; 80 | String auth = "Basic " + Base64.encodeBase64String( plainAuth.getBytes() ); 81 | return auth; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/carte/StopTransSample.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import org.apache.commons.codec.binary.Base64; 17 | import org.apache.http.HttpResponse; 18 | import org.apache.http.HttpStatus; 19 | import org.apache.http.client.HttpClient; 20 | import org.apache.http.client.methods.HttpGet; 21 | import org.apache.http.client.protocol.HttpClientContext; 22 | import org.apache.http.message.BasicHeader; 23 | import org.pentaho.di.core.Const; 24 | import org.pentaho.di.core.util.HttpClientManager; 25 | import org.pentaho.di.core.util.HttpClientUtil; 26 | import org.pentaho.di.www.StopTransServlet; 27 | 28 | public class StopTransSample extends AbstractSample { 29 | public static void main( String[] args ) throws Exception { 30 | if ( args.length < 5 ) { 31 | System.out.println( " You must specify the following parameters Carte_host Carte_port " 32 | + "Carte_login Carte_password trans_name" ); 33 | System.out.println( " For example 127.0.0.1 8088 cluster cluster dummy_trans" ); 34 | System.exit( 1 ); 35 | } 36 | init( args[ 0 ], Integer.parseInt( args[ 1 ] ), args[ 2 ], args[ 3 ] ); 37 | // building target url 38 | String urlString = getUrlString( args[ 0 ], args[ 1 ], args[ 4 ] ); 39 | 40 | //building auth token 41 | String auth = getAuthString( args[ 2 ], args[ 3 ] ); 42 | 43 | String response = sendStopTransRequest( urlString, auth ); 44 | if ( response != null ) { 45 | System.out.println( "Server response:" ); 46 | System.out.println( response ); 47 | } 48 | } 49 | 50 | public static String sendStopTransRequest( String urlString, String authentication ) throws Exception { 51 | HttpGet method = new HttpGet( urlString ); 52 | HttpClientContext context = HttpClientUtil.createPreemptiveBasicAuthentication( host, port, user, password ); 53 | //adding authorization token 54 | if ( authentication != null ) { 55 | method.addHeader( new BasicHeader( "Authorization", authentication ) ); 56 | } 57 | 58 | //executing method 59 | HttpClient client = HttpClientManager.getInstance().createDefaultClient(); 60 | HttpResponse httpResponse = context != null ? client.execute( method, context ) : client.execute( method ); 61 | int code = httpResponse.getStatusLine().getStatusCode(); 62 | String response = HttpClientUtil.responseToString( httpResponse ); 63 | method.releaseConnection(); 64 | if ( code >= HttpStatus.SC_BAD_REQUEST ) { 65 | System.out.println( "Error occurred during stopping transformation." ); 66 | return null; 67 | } 68 | return response; 69 | } 70 | 71 | public static String getUrlString( String realHostname, String port, String transName ) { 72 | String url = "http://" + realHostname + ":" + port + StopTransServlet.CONTEXT_PATH 73 | + "/?xml=Y&name=" + transName; 74 | return Const.replace( url, " ", "%20" ); 75 | } 76 | 77 | public static String getAuthString( String user, String pass ) { 78 | String plainAuth = user + ":" + pass; 79 | String auth = "Basic " + Base64.encodeBase64String( plainAuth.getBytes() ); 80 | return auth; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/embedding/CapturingTransformationRows.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.embedding; 15 | 16 | import java.util.LinkedList; 17 | import java.util.List; 18 | 19 | import org.apache.commons.lang.StringUtils; 20 | import org.pentaho.di.core.KettleEnvironment; 21 | import org.pentaho.di.core.Result; 22 | import org.pentaho.di.core.exception.KettleException; 23 | import org.pentaho.di.core.exception.KettleStepException; 24 | import org.pentaho.di.core.exception.KettleValueException; 25 | import org.pentaho.di.core.logging.LogLevel; 26 | import org.pentaho.di.core.row.RowMetaInterface; 27 | import org.pentaho.di.repository.Repository; 28 | import org.pentaho.di.trans.Trans; 29 | import org.pentaho.di.trans.TransMeta; 30 | import org.pentaho.di.trans.step.RowAdapter; 31 | import org.pentaho.di.trans.step.StepInterface; 32 | 33 | /** 34 | * This class demonstrates how to execute a PDI transformation, and capture the 35 | * output rows of a certain step. 36 | */ 37 | public class CapturingTransformationRows { 38 | 39 | public static CapturingTransformationRows instance; 40 | public List capturedRows; 41 | public RowMetaInterface rowStructure; 42 | 43 | /** 44 | * @param args not used 45 | */ 46 | public static void main( String[] args ) { 47 | 48 | // Kettle Environment must always be initialized first when using PDI 49 | // It bootstraps the PDI engine by loading settings, appropriate plugins 50 | // etc. 51 | try { 52 | KettleEnvironment.init(); 53 | } catch ( KettleException e ) { 54 | e.printStackTrace(); 55 | return; 56 | } 57 | 58 | // Create an instance of this demo class for convenience 59 | instance = new CapturingTransformationRows(); 60 | 61 | // runs the transformation, returning "output" step's rows 62 | instance.runTransformation( "etl/capturing_rows.ktr" ); 63 | } 64 | 65 | /** 66 | * This method executes a transformation defined in a ktr file and captures 67 | * all rows emitted by the step named "output". The rows captured are 68 | * printed to stdout. 69 | * 70 | * It demonstrates the following: 71 | * 72 | * - Executing a transformation definition from a ktr file 73 | * - Capturing rows from a given step in a running transformation 74 | * 75 | * @param filename the file containing the transformation to execute (ktr file) 76 | * @return the transformation rows captured, or null if there was an error 77 | */ 78 | public List runTransformation( String filename ) { 79 | 80 | try { 81 | System.out.println( "***************************************************************************************" ); 82 | System.out.println( "Attempting to run transformation " + filename + " from file system" ); 83 | System.out.println( "***************************************************************************************" ); 84 | 85 | // load transformation definition file 86 | TransMeta transMeta = new TransMeta( filename, (Repository) null ); 87 | 88 | // crate a transformation object 89 | Trans transformation = new Trans( transMeta ); 90 | 91 | // set log level to avoid noise on the log 92 | transformation.setLogLevel( LogLevel.MINIMAL ); 93 | 94 | // preparing the executing initializes all steps 95 | transformation.prepareExecution( new String[0] ); 96 | 97 | // find the "output" step 98 | StepInterface step = transformation.getStepInterface( "output", 0 ); 99 | 100 | // attach adapter receiving row events 101 | RowAdapter rowAdapter = new RowAdapter() { 102 | private boolean firstRow = true; 103 | 104 | public void rowWrittenEvent( RowMetaInterface rowMeta, Object[] row ) throws KettleStepException { 105 | if ( firstRow ) { 106 | firstRow = false; 107 | // a space to keep the captured rows 108 | capturedRows = new LinkedList(); 109 | // keep the row structure for future reference 110 | rowStructure = rowMeta; 111 | // print a header before the first row 112 | System.out.println( StringUtils.join( rowMeta.getFieldNames(), "\t" ) ); 113 | } 114 | try { 115 | // retrieve first field as integer 116 | System.out.print( rowMeta.getInteger( row, 0 ) ); 117 | System.out.print( "\t" ); 118 | // retrieve second field as string 119 | System.out.print( rowMeta.getString( row, 1 ) ); 120 | System.out.print( "\n" ); 121 | 122 | // keep the row 123 | capturedRows.add( row ); 124 | } catch ( KettleValueException e ) { 125 | e.printStackTrace(); 126 | } 127 | } 128 | }; 129 | step.addRowListener( rowAdapter ); 130 | 131 | // after the transformation is prepared for execution it is started by calling startThreads() 132 | System.out.println( "\nStarting transformation\n" ); 133 | transformation.startThreads(); 134 | 135 | // waiting for the transformation to finish 136 | // The row adapter will receive notification of any rows written by the "output" step 137 | transformation.waitUntilFinished(); 138 | 139 | // retrieve the result object, which captures the success of the 140 | // transformation 141 | Result result = transformation.getResult(); 142 | 143 | // report on the outcome of the transformation 144 | String outcome = String.format( "\nTrans %s executed %s\n", filename, 145 | ( result.getNrErrors() == 0 ? "successfully" : "with " + result.getNrErrors() + " errors" ) ); 146 | System.out.println( outcome ); 147 | 148 | return capturedRows; 149 | } catch ( Exception e ) { 150 | // something went wrong, just log and return 151 | e.printStackTrace(); 152 | return null; 153 | } 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/embedding/GeneratingJobs.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.embedding; 15 | 16 | import java.io.File; 17 | 18 | import org.apache.commons.io.FileUtils; 19 | import org.pentaho.di.core.KettleEnvironment; 20 | import org.pentaho.di.core.logging.LogLevel; 21 | import org.pentaho.di.job.JobHopMeta; 22 | import org.pentaho.di.job.JobMeta; 23 | import org.pentaho.di.job.entries.abort.JobEntryAbort; 24 | import org.pentaho.di.job.entries.special.JobEntrySpecial; 25 | import org.pentaho.di.job.entries.success.JobEntrySuccess; 26 | import org.pentaho.di.job.entries.writetolog.JobEntryWriteToLog; 27 | import org.pentaho.di.job.entry.JobEntryCopy; 28 | 29 | /** 30 | * This class demonstrates how to create a PDI job definition 31 | * in code, and save it to a kjb file. 32 | */ 33 | public class GeneratingJobs { 34 | 35 | public static GeneratingJobs instance; 36 | 37 | /** 38 | * @param args not used 39 | */ 40 | public static void main( String[] args ) { 41 | 42 | try { 43 | // Kettle Environment must always be initialized first when using PDI 44 | // It bootstraps the PDI engine by loading settings, appropriate plugins 45 | // etc. 46 | KettleEnvironment.init( false ); 47 | 48 | // Create an instance of this demo class for convenience 49 | instance = new GeneratingJobs(); 50 | 51 | // generates a simple job, returning the JobMeta object describing it 52 | JobMeta jobMeta = instance.generateJob(); 53 | 54 | // get the xml of the definition and save it to a file for inspection in spoon 55 | String outputFilename = "etl/generated_job.kjb"; 56 | System.out.println( "- Saving to " + outputFilename ); 57 | String xml = jobMeta.getXML(); 58 | File file = new File( outputFilename ); 59 | FileUtils.writeStringToFile( file, xml, "UTF-8" ); 60 | 61 | System.out.println( "DONE" ); 62 | } catch ( Exception e ) { 63 | e.printStackTrace(); 64 | return; 65 | } 66 | 67 | } 68 | 69 | /** 70 | * This method generates a job definition from scratch. 71 | * 72 | * It demonstrates the following: 73 | * 74 | * - Creating a new job 75 | * - Creating and connecting job entries 76 | * 77 | * @return the generated job definition 78 | */ 79 | public JobMeta generateJob() { 80 | 81 | try { 82 | System.out.println( "Generating a job definition" ); 83 | 84 | // create empty transformation definition 85 | JobMeta jobMeta = new JobMeta(); 86 | jobMeta.setName( "Generated Demo Job" ); 87 | 88 | // ------------------------------------------------------------------------------------ 89 | // Create start entry and put it into the job 90 | // ------------------------------------------------------------------------------------ 91 | System.out.println( "- Adding Start Entry" ); 92 | 93 | // Create and configure start entry 94 | JobEntrySpecial start = new JobEntrySpecial(); 95 | start.setName( "START" ); 96 | start.setStart( true ); 97 | 98 | // wrap into JobEntryCopy object, which holds generic job entry information 99 | JobEntryCopy startEntry = new JobEntryCopy( start ); 100 | 101 | // place it on Spoon canvas properly 102 | startEntry.setDrawn( true ); 103 | startEntry.setLocation( 100, 100 ); 104 | 105 | jobMeta.addJobEntry( startEntry ); 106 | 107 | // ------------------------------------------------------------------------------------ 108 | // Create "write to log" entry and put it into the job 109 | // ------------------------------------------------------------------------------------ 110 | System.out.println( "- Adding Write To Log Entry" ); 111 | 112 | // Create and configure entry 113 | JobEntryWriteToLog writeToLog = new JobEntryWriteToLog(); 114 | writeToLog.setName( "Output PDI Stats" ); 115 | writeToLog.setLogLevel( LogLevel.MINIMAL ); 116 | writeToLog.setLogSubject( "Logging PDI Build Information:" ); 117 | writeToLog.setLogMessage( "Version: ${Internal.Kettle.Version}\n" 118 | + "Build Date: ${Internal.Kettle.Build.Date}" ); 119 | 120 | // wrap into JobEntryCopy object, which holds generic job entry information 121 | JobEntryCopy writeToLogEntry = new JobEntryCopy( writeToLog ); 122 | 123 | // place it on Spoon canvas properly 124 | writeToLogEntry.setDrawn( true ); 125 | writeToLogEntry.setLocation( 200, 100 ); 126 | 127 | jobMeta.addJobEntry( writeToLogEntry ); 128 | 129 | // connect start entry to logging entry using simple hop 130 | jobMeta.addJobHop( new JobHopMeta( startEntry, writeToLogEntry ) ); 131 | 132 | // ------------------------------------------------------------------------------------ 133 | // Create "success" entry and put it into the job 134 | // ------------------------------------------------------------------------------------ 135 | System.out.println( "- Adding Success Entry" ); 136 | 137 | // crate and configure entry 138 | JobEntrySuccess success = new JobEntrySuccess(); 139 | success.setName( "Success" ); 140 | 141 | // wrap into JobEntryCopy object, which holds generic job entry information 142 | JobEntryCopy successEntry = new JobEntryCopy( success ); 143 | 144 | // place it on Spoon canvas properly 145 | successEntry.setDrawn( true ); 146 | successEntry.setLocation( 400, 100 ); 147 | 148 | jobMeta.addJobEntry( successEntry ); 149 | 150 | // connect logging entry to success entry on TRUE evaluation 151 | JobHopMeta greenHop = new JobHopMeta( writeToLogEntry, successEntry ); 152 | greenHop.setEvaluation( true ); 153 | jobMeta.addJobHop( greenHop ); 154 | 155 | // ------------------------------------------------------------------------------------ 156 | // Create "abort" entry and put it into the job 157 | // ------------------------------------------------------------------------------------ 158 | System.out.println( "- Adding Abort Entry" ); 159 | 160 | // crate and configure entry 161 | JobEntryAbort abort = new JobEntryAbort(); 162 | abort.setName( "Abort Job" ); 163 | 164 | // wrap into JobEntryCopy object, which holds generic job entry information 165 | JobEntryCopy abortEntry = new JobEntryCopy( abort ); 166 | 167 | // place it on Spoon canvas properly 168 | abortEntry.setDrawn( true ); 169 | abortEntry.setLocation( 400, 300 ); 170 | 171 | jobMeta.addJobEntry( abortEntry ); 172 | 173 | // connect logging entry to abort entry on FALSE evaluation 174 | JobHopMeta redHop = new JobHopMeta( writeToLogEntry, abortEntry ); 175 | redHop.setEvaluation( false ); 176 | jobMeta.addJobHop( redHop ); 177 | 178 | return jobMeta; 179 | 180 | } catch ( Exception e ) { 181 | 182 | // something went wrong, just log and return 183 | e.printStackTrace(); 184 | return null; 185 | } 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/main/java/org/pentaho/di/sdk/samples/embedding/GeneratingTransformations.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.embedding; 15 | 16 | import java.io.File; 17 | 18 | import org.apache.commons.io.FileUtils; 19 | import org.pentaho.di.core.KettleEnvironment; 20 | import org.pentaho.di.core.plugins.PluginRegistry; 21 | import org.pentaho.di.core.plugins.StepPluginType; 22 | import org.pentaho.di.trans.TransHopMeta; 23 | import org.pentaho.di.trans.TransMeta; 24 | import org.pentaho.di.trans.step.StepMeta; 25 | import org.pentaho.di.trans.steps.addsequence.AddSequenceMeta; 26 | import org.pentaho.di.trans.steps.dummytrans.DummyTransMeta; 27 | import org.pentaho.di.trans.steps.rowgenerator.RowGeneratorMeta; 28 | 29 | /** 30 | * This class demonstrates how to create a PDI transformation definition 31 | * in code, and save it to a ktr file. 32 | */ 33 | public class GeneratingTransformations { 34 | 35 | public static GeneratingTransformations instance; 36 | 37 | /** 38 | * @param args not used 39 | */ 40 | public static void main( String[] args ) { 41 | 42 | try { 43 | // Kettle Environment must always be initialized first when using PDI 44 | // It bootstraps the PDI engine by loading settings, appropriate plugins 45 | // etc. 46 | KettleEnvironment.init( false ); 47 | 48 | // Create an instance of this demo class for convenience 49 | instance = new GeneratingTransformations(); 50 | 51 | // generates a simple transformation, returning the TransMeta object describing it 52 | TransMeta transMeta = instance.generateTransformation(); 53 | 54 | // get the xml of the definition and save it to a file for inspection in spoon 55 | String outputFilename = "etl/generated_transformation.ktr"; 56 | System.out.println( "- Saving to " + outputFilename ); 57 | String xml = transMeta.getXML(); 58 | File file = new File( outputFilename ); 59 | FileUtils.writeStringToFile( file, xml, "UTF-8" ); 60 | 61 | System.out.println( "DONE" ); 62 | } catch ( Exception e ) { 63 | e.printStackTrace(); 64 | return; 65 | } 66 | } 67 | 68 | /** 69 | * This method generates a transformation definition from scratch. 70 | * 71 | * It demonstrates the following: 72 | * 73 | * - Creating a new transformation 74 | * - Creating and connecting transformation steps 75 | * 76 | * @return the generated transformation definition 77 | */ 78 | public TransMeta generateTransformation() { 79 | try { 80 | System.out.println( "Generating a transformation definition" ); 81 | 82 | // create empty transformation definition 83 | TransMeta transMeta = new TransMeta(); 84 | transMeta.setName( "Generated Demo Transformation" ); 85 | 86 | // The plug-in registry is used to determine the plug-in ID of each step used 87 | PluginRegistry registry = PluginRegistry.getInstance(); 88 | 89 | // ------------------------------------------------------------------------------------ 90 | // Create Row Generator Step and put it into the transformation 91 | // ------------------------------------------------------------------------------------ 92 | System.out.println( "- Adding Row Generator Step" ); 93 | 94 | // Create Step Definition and determine step ID 95 | RowGeneratorMeta rowGeneratorMeta = new RowGeneratorMeta(); 96 | String rowGeneratorPluginId = registry.getPluginId( StepPluginType.class, rowGeneratorMeta ); 97 | 98 | // Step it is configured to generate 5 rows with 2 fields 99 | // field_1: "Hello World" (PDI Type: String) 100 | // field_2: 100 (PDI Type: Integer) 101 | 102 | rowGeneratorMeta.setRowLimit( "5" ); 103 | 104 | rowGeneratorMeta.allocate( 2 ); 105 | rowGeneratorMeta.setFieldName( new String[] { "field_1", "field_2" } ); 106 | rowGeneratorMeta.setFieldType( new String[] { "String", "Integer" } ); 107 | rowGeneratorMeta.setValue( new String[] { "Hello World", "100" } ); 108 | 109 | StepMeta rowGeneratorStepMeta = new StepMeta( rowGeneratorPluginId, "Generate Some Rows", rowGeneratorMeta ); 110 | 111 | // make sure the step appears on the canvas and is properly placed in spoon 112 | rowGeneratorStepMeta.setDraw( true ); 113 | rowGeneratorStepMeta.setLocation( 100, 100 ); 114 | 115 | // include step in transformation 116 | transMeta.addStep( rowGeneratorStepMeta ); 117 | 118 | // ------------------------------------------------------------------------------------ 119 | // Create "Add Sequence" Step and connect it the Row Generator 120 | // ------------------------------------------------------------------------------------ 121 | System.out.println( "- Adding Add Sequence Step" ); 122 | 123 | // Create Step Definition 124 | AddSequenceMeta addSequenceMeta = new AddSequenceMeta(); 125 | String addSequencePluginId = registry.getPluginId( StepPluginType.class, addSequenceMeta ); 126 | 127 | // configure counter options 128 | addSequenceMeta.setDefault(); 129 | addSequenceMeta.setValuename( "counter" ); 130 | addSequenceMeta.setCounterName( "counter_1" ); 131 | addSequenceMeta.setStartAt( 1 ); 132 | addSequenceMeta.setMaxValue( Long.MAX_VALUE ); 133 | addSequenceMeta.setIncrementBy( 1 ); 134 | 135 | StepMeta addSequenceStepMeta = new StepMeta( addSequencePluginId, "Add Counter Field", addSequenceMeta ); 136 | 137 | // make sure the step appears on the canvas and is properly placed in spoon 138 | addSequenceStepMeta.setDraw( true ); 139 | addSequenceStepMeta.setLocation( 300, 100 ); 140 | 141 | // include step in transformation 142 | transMeta.addStep( addSequenceStepMeta ); 143 | 144 | // connect row generator to add sequence step 145 | transMeta.addTransHop( new TransHopMeta( rowGeneratorStepMeta, addSequenceStepMeta ) ); 146 | 147 | // ------------------------------------------------------------------------------------ 148 | // Add a "Dummy" Step and connect it the previous step 149 | // ------------------------------------------------------------------------------------ 150 | System.out.println( "- Adding Dummy Step" ); 151 | // Create Step Definition 152 | DummyTransMeta dummyMeta = new DummyTransMeta(); 153 | String dummyPluginId = registry.getPluginId( StepPluginType.class, dummyMeta ); 154 | 155 | StepMeta dummyStepMeta = new StepMeta( dummyPluginId, "Dummy", dummyMeta ); 156 | 157 | // make sure the step appears alright in spoon 158 | dummyStepMeta.setDraw( true ); 159 | dummyStepMeta.setLocation( 500, 100 ); 160 | 161 | // include step in transformation 162 | transMeta.addStep( dummyStepMeta ); 163 | 164 | // connect row generator to add sequence step 165 | transMeta.addTransHop( new TransHopMeta( addSequenceStepMeta, dummyStepMeta ) ); 166 | 167 | return transMeta; 168 | } catch ( Exception e ) { 169 | // something went wrong, just log and return 170 | e.printStackTrace(); 171 | return null; 172 | } 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/test/java/org/pentaho/di/sdk/samples/carte/BaseCarteServletTest.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import java.io.IOException; 17 | import java.net.ServerSocket; 18 | import java.net.Socket; 19 | 20 | import org.junit.AfterClass; 21 | import org.junit.BeforeClass; 22 | import org.pentaho.di.cluster.SlaveServer; 23 | import org.pentaho.di.www.Carte; 24 | import org.pentaho.di.www.SlaveServerConfig; 25 | 26 | public abstract class BaseCarteServletTest { 27 | 28 | private static SlaveServerConfig carteConfig; 29 | private static Thread carteThread; 30 | public static String hostname = "localhost"; 31 | public static String port; 32 | 33 | public static final String CARTE_USERNAME = "testUser"; 34 | public static final String CARTE_PASSWORD = "testPass"; 35 | 36 | private static SlaveServerConfig getSlaveServerConfig() { 37 | port = String.valueOf( findFreePort() ); 38 | SlaveServer server = new SlaveServer( "testCarte", hostname, port, CARTE_USERNAME, CARTE_PASSWORD ); 39 | SlaveServerConfig config = new SlaveServerConfig( server ); 40 | return config; 41 | } 42 | 43 | /** 44 | * Returns a free port number on localhost. 45 | * 46 | * Heavily inspired from org.eclipse.jdt.launching.SocketUtil (to avoid a dependency to JDT just because of this). 47 | * Slightly improved with close() missing in JDT. And throws exception instead of returning -1. 48 | * 49 | * https://gist.github.com/vorburger/3429822 50 | * 51 | * @return a free port number on localhost 52 | * @throws IllegalStateException if unable to find a free port 53 | */ 54 | private static int findFreePort() { 55 | ServerSocket socket = null; 56 | try { 57 | socket = new ServerSocket( 0 ); 58 | socket.setReuseAddress( true ); 59 | int port = socket.getLocalPort(); 60 | try { 61 | socket.close(); 62 | } catch ( IOException e ) { 63 | // Ignore IOException on close() 64 | } 65 | return port; 66 | } catch ( IOException e ) { 67 | } finally { 68 | if ( socket != null ) { 69 | try { 70 | socket.close(); 71 | } catch ( IOException e ) { 72 | } 73 | } 74 | } 75 | throw new IllegalStateException( "Could not find a free TCP/IP port to start embedded Jetty HTTP Server on" ); 76 | } 77 | 78 | public static boolean serverReady(String host, String port) { 79 | boolean result = false; 80 | Socket s = null; 81 | try { 82 | s = new Socket(host, Integer.valueOf( port ) ); 83 | result = true; 84 | } catch (Exception e) { 85 | result = false; 86 | } finally { 87 | if( s != null ) { 88 | try { 89 | s.close(); 90 | } catch ( Exception e ) { 91 | // Ignore 92 | } 93 | } 94 | } 95 | return result; 96 | } 97 | 98 | @BeforeClass 99 | public static void setUpBeforeClass() throws Exception { 100 | carteConfig = getSlaveServerConfig(); 101 | carteThread = new Thread() { 102 | @Override 103 | public void run() { 104 | try { 105 | Carte.runCarte( carteConfig ); 106 | } catch ( Exception e ) { 107 | System.out.println( e ); 108 | System.exit( 0 ); 109 | } 110 | } 111 | }; 112 | carteThread.start(); 113 | System.out.println( "Started local Carte server on port " + port ); 114 | 115 | // Allow up to 2 seconds for Carte to become available 116 | for ( int i = 0; i < 20; i++ ) { 117 | if ( serverReady( hostname, port ) ) { 118 | break; 119 | } 120 | Thread.sleep( 100 ); 121 | } 122 | } 123 | 124 | @SuppressWarnings( "deprecation" ) 125 | @AfterClass 126 | public static void tearDownAfterClass() { 127 | try { 128 | carteThread.stop(); 129 | } catch ( Exception ignore ) { 130 | // Ignore, just shutting down Carte 131 | } 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/test/java/org/pentaho/di/sdk/samples/carte/GetStatusSampleTest.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | import static org.junit.Assert.assertFalse; 18 | import static org.junit.Assert.assertNotNull; 19 | import static org.junit.Assert.assertTrue; 20 | import static org.junit.Assert.fail; 21 | 22 | import org.junit.Test; 23 | import org.pentaho.di.core.Const; 24 | import org.pentaho.di.core.xml.XMLHandler; 25 | import org.w3c.dom.Node; 26 | 27 | public class GetStatusSampleTest extends BaseCarteServletTest { 28 | 29 | @Test 30 | public void testGetAuthString() { 31 | assertEquals( "Basic YWRtaW46cGFzc3dvcmQ=", GetStatusSample.getAuthString( "admin", "password" ) ); 32 | } 33 | 34 | @Test 35 | public void testGetUrlString() { 36 | assertEquals( "http://sample:1000/kettle/status?xml=Y", GetStatusSample.getUrlString( "sample", "1000" ) ); 37 | } 38 | 39 | @Test 40 | public void testXMLResponse() throws Exception { 41 | String url = GetStatusSample.getUrlString( hostname, port ); 42 | String auth = GetStatusSample.getAuthString( CARTE_USERNAME, CARTE_PASSWORD ); 43 | 44 | String response = GetStatusSample.sendGetStatusRequest( url, auth ); 45 | assertNotNull( response ); 46 | Node result = XMLHandler.getSubNode( XMLHandler.loadXMLString( response ), "serverstatus" ); 47 | 48 | assertEquals( "Online", XMLHandler.getTagValue( result, "statusdesc" ) ); 49 | Long memoryFree = Long.valueOf( XMLHandler.getTagValue( result, "memory_free" ) ); 50 | Long memoryTotal = Long.valueOf( XMLHandler.getTagValue( result, "memory_total" ) ); 51 | assertTrue( memoryFree > 0L ); 52 | assertTrue( memoryTotal > 0L ); 53 | assertTrue( memoryFree < memoryTotal ); 54 | assertTrue( Long.valueOf( XMLHandler.getTagValue( result, "cpu_cores" ) ) > 0L ); 55 | assertTrue( Long.valueOf( XMLHandler.getTagValue( result, "cpu_process_time" ) ) > 0L ); 56 | assertTrue( Long.valueOf( XMLHandler.getTagValue( result, "uptime" ) ) > 0L ); 57 | assertTrue( Long.valueOf( XMLHandler.getTagValue( result, "thread_count" ) ) > 0L ); 58 | try { 59 | Double.valueOf( XMLHandler.getTagValue( result, "load_avg" ) ); 60 | } catch ( NumberFormatException e ) { 61 | fail(); 62 | } 63 | assertFalse( Const.isEmpty( XMLHandler.getTagValue( result, "os_name" ) ) ); 64 | assertFalse( Const.isEmpty( XMLHandler.getTagValue( result, "os_version" ) ) ); 65 | assertFalse( Const.isEmpty( XMLHandler.getTagValue( result, "os_arch" ) ) ); 66 | assertTrue( Const.isEmpty( Const.trim( Const.removeCRLF( XMLHandler.getTagValue( result, "transstatuslist" ) ) ) ) ); 67 | assertTrue( Const.isEmpty( Const.trim( Const.removeCRLF( XMLHandler.getTagValue( result, "jobstatuslist" ) ) ) ) ); 68 | } 69 | 70 | @Test 71 | public void testMain() throws Exception { 72 | GetStatusSample.main( new String[]{ hostname, port, CARTE_USERNAME, CARTE_PASSWORD } ); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/test/java/org/pentaho/di/sdk/samples/carte/JobServletsTest.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | import static org.junit.Assert.assertFalse; 18 | import static org.junit.Assert.assertNotEquals; 19 | import static org.junit.Assert.assertNotNull; 20 | import static org.junit.Assert.assertNull; 21 | import static org.junit.Assert.assertTrue; 22 | import static org.junit.Assert.fail; 23 | 24 | import java.util.UUID; 25 | 26 | import org.junit.Test; 27 | import org.pentaho.di.core.Const; 28 | import org.pentaho.di.core.xml.XMLHandler; 29 | import org.w3c.dom.Node; 30 | 31 | public class JobServletsTest extends BaseCarteServletTest { 32 | 33 | @Test 34 | public void testJobServlets() throws Exception { 35 | 36 | // Add Job 37 | final String jobFile = "etl/parameterized_job.kjb"; 38 | final String jobName = "parameterized_job"; 39 | String xml = RegisterJobSample.buildJobConfig( jobFile ); 40 | assertFalse( Const.isEmpty( xml ) ); 41 | 42 | String addJobUrl = RegisterJobSample.getUrlString( hostname, port ); 43 | String auth = RegisterJobSample.getAuthString( CARTE_USERNAME, CARTE_PASSWORD ); 44 | 45 | String response = RegisterJobSample.addJobToServlet( addJobUrl, xml, auth ); 46 | assertNotNull( response ); 47 | Node result = XMLHandler.getSubNode( XMLHandler.loadXMLString( response ), "webresult" ); 48 | assertEquals( "OK", XMLHandler.getTagValue( result, "result" ) ); 49 | assertTrue( XMLHandler.getTagValue( result, "message" ).contains( jobName ) ); 50 | String jobUUID = XMLHandler.getTagValue( result, "id" ); 51 | try { 52 | UUID.fromString( jobUUID ); 53 | } catch ( IllegalArgumentException iae ) { 54 | fail(); 55 | } 56 | 57 | // Carte Status 58 | String serverStatusUrl = GetStatusSample.getUrlString( hostname, port ); 59 | response = GetStatusSample.sendGetStatusRequest( serverStatusUrl, auth ); 60 | assertNotNull( response ); 61 | result = XMLHandler.getSubNode( XMLHandler.loadXMLString( response ), "serverstatus" ); 62 | result = XMLHandler.getSubNode( result, "jobstatuslist" ); 63 | assertEquals( 1, XMLHandler.countNodes( result, "jobstatus" ) ); 64 | result = XMLHandler.getSubNode( result, "jobstatus" ); 65 | assertEquals( jobName, XMLHandler.getTagValue( result, "jobname" ) ); 66 | assertEquals( jobUUID, XMLHandler.getTagValue( result, "id" ) ); 67 | assertEquals( "Waiting", XMLHandler.getTagValue( result, "status_desc" ) ); 68 | assertTrue( Const.isEmpty( XMLHandler.getTagValue( result, "error_desc" ) ) ); 69 | assertEquals( "0", XMLHandler.getTagValue( result, "first_log_line_nr" ) ); 70 | assertEquals( "0", XMLHandler.getTagValue( result, "last_log_line_nr" ) ); 71 | 72 | // Job Status 73 | String jobStatusUrl = GetJobStatusSample.getUrlString( hostname, port, jobName ); 74 | response = GetJobStatusSample.sendGetJobStatusRequest( jobStatusUrl, auth ); 75 | assertNotNull( response ); 76 | result = XMLHandler.getSubNode( XMLHandler.loadXMLString( response ), "jobstatus" ); 77 | assertEquals( jobName, XMLHandler.getTagValue( result, "jobname" ) ); 78 | assertEquals( jobUUID, XMLHandler.getTagValue( result, "id" ) ); 79 | assertEquals( "Waiting", XMLHandler.getTagValue( result, "status_desc" ) ); 80 | assertTrue( Const.isEmpty( XMLHandler.getTagValue( result, "error_desc" ) ) ); 81 | assertNotNull( XMLHandler.getTagValue( result, "first_log_line_nr" ) ); 82 | assertNotNull( XMLHandler.getTagValue( result, "last_log_line_nr" ) ); 83 | 84 | // Job Status for a job that does not exist 85 | String fakeJobName = UUID.randomUUID().toString(); 86 | assertNotEquals( "The fake job name should not match the real job used for testing", jobName, fakeJobName ); 87 | jobStatusUrl = GetJobStatusSample.getUrlString( hostname, port, fakeJobName ); 88 | response = GetJobStatusSample.sendGetJobStatusRequest( jobStatusUrl, auth ); 89 | assertNotNull( response ); 90 | result = XMLHandler.getSubNode( XMLHandler.loadXMLString( response ), "webresult" ); 91 | assertEquals( "ERROR", XMLHandler.getTagValue( result, "result" ) ); 92 | assertTrue( XMLHandler.getTagValue( result, "message" ).startsWith( "The specified job " ) ); 93 | assertTrue( XMLHandler.getTagValue( result, "message" ).contains( fakeJobName ) ); 94 | assertTrue( XMLHandler.getTagValue( result, "message" ).endsWith( " could not be found" ) ); 95 | assertNull( XMLHandler.getTagValue( result, "id" ) ); 96 | 97 | // Start Job 98 | String jobStartUrl = StartJobSample.getUrlString( hostname, port, jobName ); 99 | response = StartJobSample.sendStartJobRequest( jobStartUrl, auth ); 100 | assertNotNull( response ); 101 | result = XMLHandler.getSubNode( XMLHandler.loadXMLString( response ), "webresult" ); 102 | assertEquals( "OK", XMLHandler.getTagValue( result, "result" ) ); 103 | assertEquals( jobUUID, XMLHandler.getTagValue( result, "id" ) ); 104 | assertTrue( XMLHandler.getTagValue( result, "message" ).startsWith( "Job " ) ); 105 | assertTrue( XMLHandler.getTagValue( result, "message" ).contains( jobName ) ); 106 | assertTrue( XMLHandler.getTagValue( result, "message" ).contains( "was started." ) ); 107 | 108 | Thread.sleep( 500 ); 109 | 110 | // Job Status 111 | jobStatusUrl = GetJobStatusSample.getUrlString( hostname, port, jobName ); 112 | response = GetJobStatusSample.sendGetJobStatusRequest( jobStatusUrl, auth ); 113 | assertNotNull( response ); 114 | result = XMLHandler.getSubNode( XMLHandler.loadXMLString( response ), "jobstatus" ); 115 | assertEquals( jobName, XMLHandler.getTagValue( result, "jobname" ) ); 116 | assertEquals( jobUUID, XMLHandler.getTagValue( result, "id" ) ); 117 | assertEquals( "Finished", XMLHandler.getTagValue( result, "status_desc" ) ); 118 | 119 | // Remove Job 120 | String jobRemoveUrl = RemoveJobSample.getUrlString( hostname, port, jobName ); 121 | response = RemoveJobSample.sendRemoveJobRequest( jobRemoveUrl, auth ); 122 | assertNotNull( response ); 123 | result = XMLHandler.getSubNode( XMLHandler.loadXMLString( response ), "webresult" ); 124 | assertEquals( "OK", XMLHandler.getTagValue( result, "result" ) ); 125 | assertTrue( Const.isEmpty( XMLHandler.getTagValue( result, "message" ) ) ); 126 | assertTrue( Const.isEmpty( XMLHandler.getTagValue( result, "id" ) ) ); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/test/java/org/pentaho/di/sdk/samples/carte/TransServletsTest.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.carte; 15 | 16 | import org.junit.Test; 17 | 18 | public class TransServletsTest extends BaseCarteServletTest { 19 | 20 | @Test 21 | public void testTransServlets() { 22 | 23 | // Add Trans 24 | 25 | // Carte Status 26 | 27 | // Trans Status 28 | 29 | // Start Trans 30 | 31 | // Trans Status 32 | 33 | // Remove Trans 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/test/java/org/pentaho/di/sdk/samples/embedding/CapturingTransformationRowsTest.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.embedding; 15 | 16 | import org.junit.BeforeClass; 17 | import org.junit.Test; 18 | import org.pentaho.di.core.exception.KettleException; 19 | import org.pentaho.di.core.plugins.StepPluginType; 20 | import org.pentaho.di.trans.steps.addsequence.AddSequenceMeta; 21 | 22 | import java.util.List; 23 | 24 | import static java.util.Collections.emptyList; 25 | import static org.junit.Assert.assertFalse; 26 | 27 | public class CapturingTransformationRowsTest { 28 | 29 | @BeforeClass 30 | public static void setUpBeforeClass() throws KettleException { 31 | StepPluginType.getInstance().handlePluginAnnotation( 32 | AddSequenceMeta.class, 33 | AddSequenceMeta.class.getAnnotation( org.pentaho.di.core.annotations.Step.class ), 34 | emptyList(), false, null ); 35 | } 36 | 37 | @Test 38 | public void testRows() { 39 | CapturingTransformationRows.main( new String[ 0 ] ); 40 | List rows = CapturingTransformationRows.instance.capturedRows; 41 | 42 | // make sure some rows were collected 43 | assertFalse( rows.isEmpty() ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/test/java/org/pentaho/di/sdk/samples/embedding/GeneratingJobsTest.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.embedding; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | 18 | import org.junit.BeforeClass; 19 | import org.junit.Test; 20 | import org.pentaho.di.core.KettleEnvironment; 21 | import org.pentaho.di.core.exception.KettleException; 22 | import org.pentaho.di.job.JobMeta; 23 | 24 | public class GeneratingJobsTest { 25 | 26 | @BeforeClass 27 | public static void setUpBeforeClass() throws KettleException { 28 | KettleEnvironment.init( false ); 29 | } 30 | 31 | @Test 32 | public void testGeneratedJob() throws KettleException{ 33 | GeneratingJobs instance = new GeneratingJobs(); 34 | JobMeta jobMeta = instance.generateJob(); 35 | 36 | // make sure the transformation object has 3 steps 37 | assertEquals(jobMeta.getName(), "Generated Demo Job"); 38 | assertEquals(jobMeta.getJobCopies().size(), 4); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/test/java/org/pentaho/di/sdk/samples/embedding/GeneratingTransformationsTest.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.embedding; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | 18 | import org.junit.BeforeClass; 19 | import org.junit.Test; 20 | import org.pentaho.di.core.KettleEnvironment; 21 | import org.pentaho.di.core.exception.KettleException; 22 | import org.pentaho.di.trans.TransMeta; 23 | 24 | public class GeneratingTransformationsTest { 25 | 26 | @BeforeClass 27 | public static void setUpBeforeClass() throws KettleException { 28 | KettleEnvironment.init( false ); 29 | } 30 | 31 | @Test 32 | public void testGeneratedTransform() throws KettleException{ 33 | GeneratingTransformations instance = new GeneratingTransformations(); 34 | TransMeta transMeta = instance.generateTransformation(); 35 | 36 | // make sure the transformation object has 3 steps 37 | assertEquals(transMeta.getName(), "Generated Demo Transformation"); 38 | assertEquals(transMeta.getSteps().size(), 3); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/test/java/org/pentaho/di/sdk/samples/embedding/RunningJobsTest.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.embedding; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | import static org.junit.Assert.assertTrue; 18 | 19 | import org.junit.BeforeClass; 20 | import org.junit.Test; 21 | import org.pentaho.di.core.KettleEnvironment; 22 | import org.pentaho.di.core.exception.KettleException; 23 | import org.pentaho.di.job.Job; 24 | 25 | public class RunningJobsTest { 26 | 27 | @BeforeClass 28 | public static void setUpBeforeClass() throws KettleException { 29 | KettleEnvironment.init( false ); 30 | } 31 | 32 | @Test 33 | public void testRunningTransformations() throws KettleException { 34 | // Create an instance of this demo class for convenience 35 | RunningJobs instance = new RunningJobs(); 36 | 37 | // run a transformation from the file system 38 | Job j = instance.runJobFromFileSystem( "etl/parameterized_job.kjb" ); 39 | 40 | for ( int i = 0; i < 20; i++ ) { 41 | if ( j.getStatus().equals( "Finished" ) ) { 42 | break; 43 | } 44 | try { 45 | Thread.sleep( 100 ); 46 | } catch ( InterruptedException e ) { 47 | // Ignore 48 | } 49 | } 50 | 51 | // A successfully completed job is in finished state 52 | assertEquals( "Finished", j.getStatus() ); 53 | 54 | // A successfully completed job has no errors 55 | assertEquals( 0, j.getResult().getNrErrors() ); 56 | 57 | // And a true grand result 58 | assertTrue( j.getResult().getResult() ); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /kettle-sdk-embedding-samples/src/test/java/org/pentaho/di/sdk/samples/embedding/RunningTransformationsTest.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.embedding; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | 18 | import org.junit.BeforeClass; 19 | import org.junit.Test; 20 | import org.pentaho.di.core.KettleEnvironment; 21 | import org.pentaho.di.core.exception.KettleException; 22 | import org.pentaho.di.trans.Trans; 23 | 24 | public class RunningTransformationsTest { 25 | 26 | @BeforeClass 27 | public static void setUpBeforeClass() throws KettleException { 28 | KettleEnvironment.init( false ); 29 | } 30 | 31 | @Test 32 | public void testRunningTransformations() throws KettleException { 33 | // Create an instance of this demo class for convenience 34 | RunningTransformations instance = new RunningTransformations(); 35 | 36 | // run a transformation from the file system 37 | Trans t = instance.runTransformationFromFileSystem( "etl/parameterized_transformation.ktr" ); 38 | 39 | // A successfully completed transformation is in waiting state 40 | assertEquals( "Finished", t.getStatus() ); 41 | 42 | // A successfully completed transformation has no errors 43 | assertEquals( 0, t.getResult().getNrErrors() ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /kettle-sdk-jobentry-plugin/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /kettle-sdk-jobentry-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /eclipse/ -------------------------------------------------------------------------------- /kettle-sdk-jobentry-plugin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pentaho-kettle 7 | kettle-sdk-plugin-parent 8 | 10.3.0.0-SNAPSHOT 9 | 10 | kettle-sdk-jobentry-plugin 11 | 10.3.0.0-SNAPSHOT 12 | Pentaho Data Integration SDK Job Entry Plugin 13 | 14 | 15 | org.pentaho 16 | pentaho-metadata 17 | ${pentaho-metadata.version} 18 | provided 19 | 20 | 21 | pentaho-kettle 22 | kettle-core 23 | ${pdi.version} 24 | provided 25 | 26 | 27 | pentaho-kettle 28 | kettle-engine 29 | ${pdi.version} 30 | provided 31 | 32 | 33 | pentaho-kettle 34 | kettle-ui-swt 35 | ${pdi.version} 36 | provided 37 | 38 | 39 | pentaho-kettle 40 | kettle-engine 41 | ${pdi.version} 42 | tests 43 | test 44 | 45 | 46 | junit 47 | junit 48 | ${junit.version} 49 | test 50 | 51 | 52 | org.mockito 53 | mockito-core 54 | ${mockito.version} 55 | test 56 | 57 | 58 | pentaho-kettle 59 | kettle-core 60 | ${project.version} 61 | tests 62 | test 63 | 64 | 65 | 66 | 67 | 68 | maven-assembly-plugin 69 | 70 | 71 | distro-assembly 72 | package 73 | 74 | single 75 | 76 | 77 | false 78 | 79 | src/main/assembly/assembly.xml 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /kettle-sdk-jobentry-plugin/src/main/assembly/assembly.xml: -------------------------------------------------------------------------------- 1 | 5 | bin 6 | 7 | zip 8 | 9 | 10 | 11 | ${project.build.directory} 12 | / 13 | 14 | *.jar 15 | 16 | 17 | 18 | 19 | 20 | lib/ 21 | false 22 | runtime 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /kettle-sdk-jobentry-plugin/src/main/resources/org/pentaho/di/sdk/samples/jobentries/demo/messages/messages_en_US.properties: -------------------------------------------------------------------------------- 1 | Demo.Shell.Title=Demo job entry 2 | Demo.Default.Name=Demo 3 | Demo.JobEntryName.Label=Name of demo job entry 4 | Demo.Outcome.Label=Desired outcome 5 | 6 | DemoJobEntry.Name=Demo 7 | DemoJobEntry.TooltipDesc=Demo Job Entry 8 | DemoJobEntry.DocumentationURL=https://help.pentaho.com/Documentation/6.1/0R0/0V0 9 | DemoJobEntry.CasesURL=http://jira.pentaho.com/browse/PDI/ 10 | DemoJobEntry.ForumURL=http://forums.pentaho.com/ -------------------------------------------------------------------------------- /kettle-sdk-jobentry-plugin/src/main/resources/org/pentaho/di/sdk/samples/jobentries/demo/resources/demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pentaho/pdi-sdk-plugins/d61a31fe55505b2a4f16789a1102ce95ba3c2eb9/kettle-sdk-jobentry-plugin/src/main/resources/org/pentaho/di/sdk/samples/jobentries/demo/resources/demo.png -------------------------------------------------------------------------------- /kettle-sdk-jobentry-plugin/src/main/resources/org/pentaho/di/sdk/samples/jobentries/demo/resources/demo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 13 | 14 | 15 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /kettle-sdk-jobentry-plugin/src/test/java/org/pentaho/di/sdk/samples/jobentries/demo/JobEntryDemoLoadSaveTest.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.jobentries.demo; 15 | 16 | import java.util.Arrays; 17 | import java.util.List; 18 | 19 | import org.pentaho.di.job.entry.loadSave.JobEntryLoadSaveTestSupport; 20 | 21 | public class JobEntryDemoLoadSaveTest extends JobEntryLoadSaveTestSupport { 22 | 23 | @Override 24 | protected Class getJobEntryClass() { 25 | return JobEntryDemo.class; 26 | } 27 | 28 | @Override 29 | protected List listCommonAttributes() { 30 | return Arrays.asList( "outcome" ); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /kettle-sdk-jobentry-plugin/src/test/java/org/pentaho/di/sdk/samples/jobentries/demo/JobEntryDemoTest.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.jobentries.demo; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | import static org.junit.Assert.assertFalse; 18 | import static org.junit.Assert.assertNotEquals; 19 | import static org.junit.Assert.assertNotNull; 20 | import static org.junit.Assert.assertTrue; 21 | import static org.junit.Assert.fail; 22 | 23 | import java.util.UUID; 24 | 25 | import org.junit.Test; 26 | import org.pentaho.di.core.Const; 27 | import org.pentaho.di.core.Result; 28 | import org.pentaho.di.core.annotations.JobEntry; 29 | import org.pentaho.di.i18n.BaseMessages; 30 | 31 | public class JobEntryDemoTest { 32 | 33 | @Test 34 | public void testJobEntry(){ 35 | JobEntryDemo m = new JobEntryDemo( "Test Entry" ); 36 | Result r = new Result(); 37 | 38 | // execute with desired outcome: false 39 | m.setOutcome( false ); 40 | m.execute( r, 0 ); 41 | assertFalse( r.getResult() ); 42 | 43 | // execute with desired outcome: true 44 | m.setOutcome( true ); 45 | m.execute( r, 0 ); 46 | assertTrue( r.getResult() ); 47 | } 48 | 49 | @Test 50 | public void testAnnotations() { 51 | JobEntry jobEntryAnnotation = JobEntryDemo.class.getAnnotation( JobEntry.class ); 52 | assertNotNull( jobEntryAnnotation ); 53 | assertFalse( Const.isEmpty( jobEntryAnnotation.id() ) ); 54 | assertFalse( Const.isEmpty( jobEntryAnnotation.name() ) ); 55 | assertFalse( Const.isEmpty( jobEntryAnnotation.description() ) ); 56 | assertFalse( Const.isEmpty( jobEntryAnnotation.image() ) ); 57 | assertFalse( Const.isEmpty( jobEntryAnnotation.categoryDescription() ) ); 58 | assertFalse( Const.isEmpty( jobEntryAnnotation.i18nPackageName() ) ); 59 | assertFalse( Const.isEmpty( jobEntryAnnotation.documentationUrl() ) ); 60 | assertFalse( Const.isEmpty( jobEntryAnnotation.casesUrl() ) ); 61 | assertFalse( Const.isEmpty( jobEntryAnnotation.forumUrl() ) ); 62 | assertEquals( JobEntryDemo.class.getPackage().getName(), jobEntryAnnotation.i18nPackageName() ); 63 | hasi18nValue( jobEntryAnnotation.i18nPackageName(), jobEntryAnnotation.name() ); 64 | hasi18nValue( jobEntryAnnotation.i18nPackageName(), jobEntryAnnotation.description() ); 65 | hasi18nValue( jobEntryAnnotation.i18nPackageName(), jobEntryAnnotation.documentationUrl() ); 66 | hasi18nValue( jobEntryAnnotation.i18nPackageName(), jobEntryAnnotation.casesUrl() ); 67 | hasi18nValue( jobEntryAnnotation.i18nPackageName(), jobEntryAnnotation.forumUrl() ); 68 | } 69 | 70 | private void hasi18nValue( String i18nPackageName, String messageId ) { 71 | String fakeId = UUID.randomUUID().toString(); 72 | String fakeLocalized = BaseMessages.getString( i18nPackageName, fakeId ); 73 | assertEquals( "The way to identify a missing localization key has changed", "!" + fakeId + "!", fakeLocalized ); 74 | 75 | // Real Test 76 | String localized = BaseMessages.getString( i18nPackageName, messageId ); 77 | assertFalse( "No messages bundle entry found for " + messageId, Const.isEmpty( localized ) ); 78 | assertNotEquals( "!" + messageId + "!", localized ); 79 | } 80 | 81 | @Test 82 | public void testGetDialogClassName() { 83 | JobEntryDemo m = new JobEntryDemo( "Test" ); 84 | try { 85 | Class.forName( m.getDialogClassName() ); 86 | } catch ( ClassNotFoundException e ) { 87 | fail(); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /kettle-sdk-partitioner-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /eclipse/ -------------------------------------------------------------------------------- /kettle-sdk-partitioner-plugin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pentaho-kettle 7 | kettle-sdk-plugin-parent 8 | 10.3.0.0-SNAPSHOT 9 | 10 | kettle-sdk-partitioner-plugin 11 | 10.3.0.0-SNAPSHOT 12 | Pentaho Data Integration SDK Partitioner Plugin 13 | 14 | 15 | org.pentaho 16 | pentaho-metadata 17 | ${pentaho-metadata.version} 18 | provided 19 | 20 | 21 | pentaho-kettle 22 | kettle-core 23 | ${pdi.version} 24 | provided 25 | 26 | 27 | pentaho-kettle 28 | kettle-engine 29 | ${pdi.version} 30 | provided 31 | 32 | 33 | pentaho-kettle 34 | kettle-ui-swt 35 | ${pdi.version} 36 | provided 37 | 38 | 39 | pentaho-kettle 40 | kettle-engine 41 | ${pdi.version} 42 | tests 43 | test 44 | 45 | 46 | junit 47 | junit 48 | ${junit.version} 49 | test 50 | 51 | 52 | org.mockito 53 | mockito-core 54 | ${mockito.version} 55 | test 56 | 57 | 58 | 59 | 60 | 61 | maven-assembly-plugin 62 | 63 | 64 | distro-assembly 65 | package 66 | 67 | single 68 | 69 | 70 | false 71 | 72 | src/main/assembly/assembly.xml 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /kettle-sdk-partitioner-plugin/src/main/assembly/assembly.xml: -------------------------------------------------------------------------------- 1 | 5 | bin 6 | 7 | zip 8 | 9 | 10 | 11 | ${project.build.directory} 12 | / 13 | 14 | *.jar 15 | 16 | 17 | 18 | 19 | 20 | lib/ 21 | false 22 | runtime 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /kettle-sdk-partitioner-plugin/src/main/java/org/pentaho/di/sdk/samples/partitioners/demo/DemoPartitioner.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.partitioners.demo; 15 | 16 | import org.pentaho.di.core.Const; 17 | import org.pentaho.di.core.annotations.PartitionerPlugin; 18 | import org.pentaho.di.core.exception.KettleException; 19 | import org.pentaho.di.core.exception.KettleStepException; 20 | import org.pentaho.di.core.exception.KettleXMLException; 21 | import org.pentaho.di.core.row.RowMetaInterface; 22 | import org.pentaho.di.core.xml.XMLHandler; 23 | import org.pentaho.di.repository.ObjectId; 24 | import org.pentaho.di.repository.Repository; 25 | import org.pentaho.di.trans.BasePartitioner; 26 | import org.pentaho.di.trans.Partitioner; 27 | import org.w3c.dom.Node; 28 | 29 | /** 30 | * This class is part of the demo partitioner plug-in implementation. 31 | * It demonstrates the basics of developing a plug-in partitioner for PDI. 32 | * 33 | * This demo partitioner selects a partition based on the length of a 34 | * supplied string field. Longer strings will get increasingly higher 35 | * partition numbers. For string lengths 20 and above, the maximum 36 | * partition number will be used. 37 | * 38 | * This class is the implementation of the Partitioner interface. Implementations 39 | * of this interface are typically based on the BasePartitioner class, which 40 | * provides a default implementation for the interface. 41 | * 42 | * Classes implementing this interface need to: 43 | * 44 | * - keep track of configuration for the partitioning (usually the field to use 45 | * for partitioning + additional configuration if required) 46 | * - implement clone() to create a deep copy of the object 47 | * - decide which partition a row should go to 48 | * - indicate which dialog class is used for configuring the partitioner settings 49 | * - serialize the partitioner configuration to/from XML and repository 50 | * 51 | */ 52 | 53 | @PartitionerPlugin ( 54 | id = "DemoPartitioner", 55 | name = "Demo Partitioner", 56 | description = "Partition by length of string field" 57 | ) 58 | public class DemoPartitioner extends BasePartitioner implements Partitioner { 59 | 60 | /** 61 | * The PKG member is used when looking up internationalized strings. 62 | * The properties file with localized keys is expected to reside in 63 | * {the package of the class specified}/messages/messages_{locale}.properties 64 | */ 65 | private static final Class PKG = DemoPartitionerDialog.class; // for i18n purposes $NON-NLS-1$ 66 | 67 | // the field name to partition on 68 | private String fieldName; 69 | 70 | // the index of the field to partition on 71 | protected int partitionColumnIndex = -1; 72 | 73 | /** 74 | * The No-Arguments constructor of a partitioner 75 | */ 76 | public DemoPartitioner() { 77 | super(); 78 | } 79 | 80 | /** 81 | * The getInstance() method is part of the Partitioner interface and should return 82 | * a new instance of the partitioner, taking over the id and description from the 83 | * object it is called on. 84 | */ 85 | public Partitioner getInstance() { 86 | Partitioner partitioner = new DemoPartitioner(); 87 | partitioner.setId( getId() ); 88 | partitioner.setDescription( getDescription() ); 89 | return partitioner; 90 | } 91 | 92 | /** 93 | * The clone() method is generating a deep copy of a partitioner. This method is called 94 | * when steps are duplicated in Spoon. 95 | */ 96 | public DemoPartitioner clone() { 97 | DemoPartitioner demoPartitioner = (DemoPartitioner) super.clone(); 98 | demoPartitioner.fieldName = fieldName; 99 | 100 | return demoPartitioner; 101 | } 102 | 103 | /** 104 | * This method is called by Spoon to determine which class is used to configure the 105 | * partitioner's settings. 106 | */ 107 | public String getDialogClassName() { 108 | return DemoPartitionerDialog.class.getName(); 109 | } 110 | 111 | /** 112 | * The getPartition() method is used during the execution of the transformation. It is 113 | * implementing the actual partitioning algorithm. 114 | * 115 | * @return the partition number the row should go to 116 | */ 117 | public int getPartition( RowMetaInterface rowMeta, Object[] row ) throws KettleException { 118 | 119 | // init() should be called first, so fields provided by BasePartitioner are guaranteed to be 120 | // initialized 121 | init( rowMeta ); 122 | 123 | // determine the index of the field the partitioner uses for partitioning 124 | if ( partitionColumnIndex < 0 ) { 125 | partitionColumnIndex = rowMeta.indexOfValue( fieldName ); 126 | if ( partitionColumnIndex < 0 ) { 127 | throw new KettleStepException( "Unable to find partitioning field name [" + fieldName + "] in the output row..." + rowMeta ); 128 | } 129 | } 130 | 131 | // get the string representation of the field (conversion to string is done if necessary) 132 | String value = rowMeta.getString( row, partitionColumnIndex ); 133 | 134 | // Determine the length of the string value and cap it at 20 135 | int len = 0; 136 | if ( value != null ) { 137 | len = Math.min( value.length(), 20 ); 138 | } 139 | 140 | // partition based on string length: 141 | // short strings go into partition [0], long strings (20 chars+) go into partition [nrPartitions-1] 142 | // The variable nrPartitions is provided by BasePartitioner 143 | return (int) Math.round( len / 20.0 * ( nrPartitions - 1 ) ); 144 | } 145 | 146 | /** 147 | * This method is called when Spoon needs to display the name 148 | * of the partitioner on dialogs etc. 149 | * 150 | * @return a string containing a descriptive string for the partitioner 151 | */ 152 | public String getDescription() { 153 | String description = "String length based demo partitioner"; 154 | if ( !Const.isEmpty( fieldName ) ) { 155 | description += " (" + fieldName + ")"; 156 | } 157 | return description; 158 | } 159 | 160 | /** 161 | * This method is called by Spoon when a partitioner needs to serialize its configuration to XML. 162 | * The expected return value is an XML fragment consisting of one or more XML tags. 163 | * 164 | * Please use org.pentaho.di.core.xml.XMLHandler to conveniently generate the XML. 165 | * 166 | * @return a string containing the XML serialization of this partitioner 167 | */ 168 | public String getXML() { 169 | StringBuilder xml = new StringBuilder(); 170 | xml.append( " " ).append( XMLHandler.addTagValue( "field_name", fieldName ) ); 171 | return xml.toString(); 172 | } 173 | 174 | public void loadXML( Node partitioningMethodNode ) throws KettleXMLException { 175 | fieldName = XMLHandler.getTagValue( partitioningMethodNode, "field_name" ); 176 | } 177 | 178 | public void saveRep( Repository rep, ObjectId id_transformation, ObjectId id_step ) throws KettleException { 179 | rep.saveStepAttribute( id_transformation, id_step, "PARTITIONING_FIELDNAME", fieldName ); // The fieldname to partition on 180 | } 181 | 182 | public void loadRep( Repository rep, ObjectId id_step ) throws KettleException { 183 | fieldName = rep.getStepAttributeString( id_step, "PARTITIONING_FIELDNAME" ); 184 | } 185 | 186 | public String getFieldName() { 187 | return fieldName; 188 | } 189 | 190 | public void setFieldName( String fieldName ) { 191 | this.fieldName = fieldName; 192 | } 193 | } 194 | -------------------------------------------------------------------------------- /kettle-sdk-partitioner-plugin/src/main/java/org/pentaho/di/sdk/samples/partitioners/demo/DemoPartitionerDialog.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.partitioners.demo; 15 | 16 | import java.util.Arrays; 17 | 18 | import org.eclipse.swt.SWT; 19 | import org.eclipse.swt.custom.CCombo; 20 | import org.eclipse.swt.events.ModifyEvent; 21 | import org.eclipse.swt.events.ModifyListener; 22 | import org.eclipse.swt.events.SelectionAdapter; 23 | import org.eclipse.swt.events.SelectionEvent; 24 | import org.eclipse.swt.events.ShellAdapter; 25 | import org.eclipse.swt.events.ShellEvent; 26 | import org.eclipse.swt.layout.FormAttachment; 27 | import org.eclipse.swt.layout.FormData; 28 | import org.eclipse.swt.layout.FormLayout; 29 | import org.eclipse.swt.widgets.Button; 30 | import org.eclipse.swt.widgets.Display; 31 | import org.eclipse.swt.widgets.Event; 32 | import org.eclipse.swt.widgets.Label; 33 | import org.eclipse.swt.widgets.Listener; 34 | import org.eclipse.swt.widgets.Shell; 35 | import org.pentaho.di.core.Const; 36 | import org.pentaho.di.core.exception.KettleStepException; 37 | import org.pentaho.di.core.row.RowMetaInterface; 38 | import org.pentaho.di.i18n.BaseMessages; 39 | import org.pentaho.di.trans.TransMeta; 40 | import org.pentaho.di.trans.step.BaseStepMeta; 41 | import org.pentaho.di.trans.step.StepDialogInterface; 42 | import org.pentaho.di.trans.step.StepMeta; 43 | import org.pentaho.di.trans.step.StepPartitioningMeta; 44 | import org.pentaho.di.ui.core.dialog.ErrorDialog; 45 | import org.pentaho.di.ui.trans.step.BaseStepDialog; 46 | 47 | public class DemoPartitionerDialog extends BaseStepDialog implements StepDialogInterface { 48 | 49 | /** 50 | * The PKG member is used when looking up internationalized strings. 51 | * The properties file with localized keys is expected to reside in 52 | * {the package of the class specified}/messages/messages_{locale}.properties 53 | */ 54 | private static final Class PKG = DemoPartitionerDialog.class; // for i18n purposes $NON-NLS-1$ 55 | 56 | private StepPartitioningMeta partitioningMeta; 57 | private StepMeta stepMeta; 58 | private DemoPartitioner partitioner; 59 | private String fieldName; 60 | 61 | private Label wlFieldname; 62 | private CCombo wFieldname; 63 | private FormData fdlFieldname, fdFieldname; 64 | 65 | public DemoPartitionerDialog( Shell parent, StepMeta stepMeta, StepPartitioningMeta partitioningMeta, TransMeta transMeta ) { 66 | super( parent, (BaseStepMeta) stepMeta.getStepMetaInterface(), transMeta, partitioningMeta.getPartitioner().getDescription() ); 67 | this.stepMeta = stepMeta; 68 | this.partitioningMeta = partitioningMeta; 69 | partitioner = (DemoPartitioner) partitioningMeta.getPartitioner(); 70 | fieldName = partitioner.getFieldName(); 71 | } 72 | 73 | public String open() { 74 | Shell parent = getParent(); 75 | Display display = parent.getDisplay(); 76 | 77 | shell = new Shell( parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN | SWT.MAX ); 78 | props.setLook( shell ); 79 | setShellImage( shell, stepMeta.getStepMetaInterface() ); 80 | 81 | ModifyListener lsMod = new ModifyListener() { 82 | public void modifyText( ModifyEvent e ) { 83 | partitioningMeta.hasChanged( true ); 84 | } 85 | }; 86 | changed = partitioningMeta.hasChanged(); 87 | 88 | FormLayout formLayout = new FormLayout(); 89 | formLayout.marginWidth = Const.FORM_MARGIN; 90 | formLayout.marginHeight = Const.FORM_MARGIN; 91 | 92 | shell.setLayout( formLayout ); 93 | shell.setText( partitioner.getDescription() ); //$NON-NLS-1$ 94 | 95 | int margin = Const.MARGIN; 96 | 97 | int middle = props.getMiddlePct(); 98 | 99 | wlFieldname = new Label( shell, SWT.RIGHT ); 100 | wlFieldname.setText( "Fieldname" ); //$NON-NLS-1$ 101 | props.setLook( wlFieldname ); 102 | fdlFieldname = new FormData(); 103 | fdlFieldname.left = new FormAttachment( 0, 0 ); 104 | fdlFieldname.right = new FormAttachment( middle, -margin ); 105 | fdlFieldname.top = new FormAttachment( 0, margin ); 106 | wlFieldname.setLayoutData( fdlFieldname ); 107 | wFieldname = new CCombo( shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER ); 108 | wFieldname.setText( fieldName == null ? "" : fieldName ); 109 | props.setLook( wFieldname ); 110 | wFieldname.addModifyListener( lsMod ); 111 | fdFieldname = new FormData(); 112 | fdFieldname.left = new FormAttachment( middle, 0 ); 113 | fdFieldname.top = new FormAttachment( 0, margin ); 114 | fdFieldname.right = new FormAttachment( 100, 0 ); 115 | wFieldname.setLayoutData( fdFieldname ); 116 | 117 | try { 118 | RowMetaInterface inputFields = transMeta.getPrevStepFields( stepMeta ); 119 | if ( inputFields != null ) { 120 | String[] fieldNames = inputFields.getFieldNames(); 121 | Arrays.sort( fieldNames ); 122 | wFieldname.setItems( fieldNames ); 123 | } 124 | } catch ( KettleStepException e ) { 125 | new ErrorDialog( shell, "Error", "Error obtaining list of input fields:", e ); 126 | } 127 | 128 | // Some buttons 129 | wOK = new Button( shell, SWT.PUSH ); 130 | wOK.setText( BaseMessages.getString( PKG, "System.Button.OK" ) ); //$NON-NLS-1$ 131 | wCancel = new Button( shell, SWT.PUSH ); 132 | wCancel.setText( BaseMessages.getString( PKG, "System.Button.Cancel" ) ); //$NON-NLS-1$ 133 | fdOK = new FormData(); 134 | 135 | setButtonPositions( new Button[] { wOK, wCancel }, margin, null ); 136 | 137 | // Add listeners 138 | lsCancel = new Listener() { 139 | public void handleEvent( Event e ) { 140 | cancel(); 141 | } 142 | }; 143 | lsOK = new Listener() { 144 | public void handleEvent( Event e ) { 145 | ok(); 146 | } 147 | }; 148 | 149 | wCancel.addListener( SWT.Selection, lsCancel ); 150 | wOK.addListener( SWT.Selection, lsOK ); 151 | 152 | lsDef = new SelectionAdapter() { 153 | public void widgetDefaultSelected( SelectionEvent e ) { 154 | ok(); 155 | } 156 | }; 157 | 158 | // Detect X or ALT-F4 or something that kills this window... 159 | shell.addShellListener( 160 | new ShellAdapter() { 161 | public void shellClosed( ShellEvent e ) { 162 | cancel(); 163 | } 164 | } 165 | ); 166 | 167 | // Set the shell size, based upon previous time... 168 | setSize(); 169 | getData(); 170 | partitioningMeta.hasChanged( changed ); 171 | 172 | setSize(); 173 | 174 | shell.open(); 175 | while ( !shell.isDisposed() ) { 176 | if ( !display.readAndDispatch() ) { 177 | display.sleep(); 178 | } 179 | } 180 | return stepname; 181 | } 182 | 183 | /** 184 | * Copy information from the meta-data input to the dialog fields. 185 | */ 186 | public void getData() { 187 | wFieldname.setText( fieldName == null ? "" : fieldName ); 188 | } 189 | 190 | private void cancel() { 191 | stepname = null; 192 | partitioningMeta.hasChanged( changed ); 193 | dispose(); 194 | } 195 | 196 | private void ok() { 197 | fieldName = wFieldname.getText(); 198 | partitioner.setFieldName( fieldName ); 199 | dispose(); 200 | } 201 | } 202 | -------------------------------------------------------------------------------- /kettle-sdk-partitioner-plugin/src/test/java/org/pentaho/di/sdk/samples/partitioners/demo/DemoPartitionerTest.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.partitioners.demo; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | 18 | import java.util.Arrays; 19 | import java.util.List; 20 | 21 | import org.junit.Test; 22 | import org.pentaho.di.core.exception.KettleException; 23 | import org.pentaho.di.core.row.RowMeta; 24 | import org.pentaho.di.core.row.value.ValueMetaString; 25 | import org.pentaho.di.trans.LoadSaveTester; 26 | 27 | public class DemoPartitionerTest { 28 | 29 | @Test 30 | public void testPartitionerAlgorithm() throws KettleException { 31 | // create and configure partitioner 32 | DemoPartitioner p = new DemoPartitioner(); 33 | p.setNrPartitions( 3 ); 34 | p.setFieldName( "testfield" ); 35 | 36 | // create row definition 37 | RowMeta rowMeta = new RowMeta(); 38 | rowMeta.addValueMeta( new ValueMetaString( "testfield" ) ); 39 | 40 | // test short string -> partition 0 41 | Object[] row1 = { "a" }; 42 | assertEquals( p.getPartition( rowMeta, row1 ), 0 ); 43 | 44 | // test medium string -> partition 1 45 | Object[] row2 = { "abcdefghijk" }; 46 | assertEquals( p.getPartition( rowMeta, row2 ), 1 ); 47 | 48 | // test long string -> partition 2 49 | Object[] row3 = { "abcdefghijklmnopqrstuvwxyz" }; 50 | assertEquals( p.getPartition( rowMeta, row3 ), 2 ); 51 | } 52 | 53 | @Test 54 | public void testSerialization() throws KettleException { 55 | List attributes = Arrays.asList( "FieldName" ); 56 | 57 | LoadSaveTester tester = new LoadSaveTester( DemoPartitioner.class, attributes ); 58 | 59 | tester.testSerialization(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /kettle-sdk-plugin-assembly/assembly/assembly.xml: -------------------------------------------------------------------------------- 1 | 5 | bin 6 | 7 | zip 8 | 9 | 10 | 11 | resources 12 | 13 | 14 | 15 | ../kettle-sdk-database-plugin 16 | kettle-sdk-database-plugin 17 | 18 | target/ 19 | bin/ 20 | .settings/ 21 | eclipse/ 22 | .classpath 23 | .project 24 | 25 | 26 | 27 | ../kettle-sdk-embedding-samples 28 | kettle-sdk-embedding-samples 29 | 30 | target/ 31 | bin/ 32 | .settings/ 33 | eclipse/ 34 | .classpath 35 | .project 36 | 37 | 38 | 39 | ../kettle-sdk-jobentry-plugin 40 | kettle-sdk-jobentry-plugin 41 | 42 | target/ 43 | bin/ 44 | .settings/ 45 | eclipse/ 46 | .classpath 47 | .project 48 | 49 | 50 | 51 | ../kettle-sdk-partitioner-plugin 52 | kettle-sdk-partitioner-plugin 53 | 54 | target/ 55 | bin/ 56 | .settings/ 57 | eclipse/ 58 | .classpath 59 | .project 60 | 61 | 62 | 63 | ../kettle-sdk-step-plugin 64 | kettle-sdk-step-plugin 65 | 66 | target/ 67 | bin/ 68 | .settings/ 69 | eclipse/ 70 | .classpath 71 | .project 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /kettle-sdk-plugin-assembly/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pentaho-kettle 7 | kettle-sdk-plugin-parent 8 | 10.3.0.0-SNAPSHOT 9 | 10 | kettle-sdk-plugin-assembly 11 | 10.3.0.0-SNAPSHOT 12 | pom 13 | Pentaho Data Integration SDK Plugin Assembly 14 | 15 | verify 16 | 17 | 18 | 19 | 20 | maven-assembly-plugin 21 | 22 | 23 | distro-assembly 24 | package 25 | 26 | single 27 | 28 | 29 | false 30 | 31 | assembly/assembly.xml 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /kettle-sdk-plugin-assembly/resources/PDI_Icon_Guide.ai: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pentaho/pdi-sdk-plugins/d61a31fe55505b2a4f16789a1102ce95ba3c2eb9/kettle-sdk-plugin-assembly/resources/PDI_Icon_Guide.ai -------------------------------------------------------------------------------- /kettle-sdk-step-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /.eclipse/ -------------------------------------------------------------------------------- /kettle-sdk-step-plugin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pentaho-kettle 7 | kettle-sdk-plugin-parent 8 | 10.3.0.0-SNAPSHOT 9 | 10 | kettle-sdk-step-plugin 11 | 10.3.0.0-SNAPSHOT 12 | Pentaho Data Integration SDK Step Plugin 13 | 14 | 15 | org.pentaho 16 | pentaho-metadata 17 | ${pentaho-metadata.version} 18 | provided 19 | 20 | 21 | pentaho-kettle 22 | kettle-core 23 | ${pdi.version} 24 | provided 25 | 26 | 27 | pentaho-kettle 28 | kettle-engine 29 | ${pdi.version} 30 | provided 31 | 32 | 33 | pentaho-kettle 34 | kettle-ui-swt 35 | ${pdi.version} 36 | provided 37 | 38 | 39 | pentaho-kettle 40 | kettle-engine 41 | ${pdi.version} 42 | tests 43 | test 44 | 45 | 46 | junit 47 | junit 48 | ${junit.version} 49 | test 50 | 51 | 52 | org.mockito 53 | mockito-core 54 | ${mockito.version} 55 | test 56 | 57 | 58 | pentaho-kettle 59 | kettle-core 60 | ${project.version} 61 | tests 62 | test 63 | 64 | 65 | 66 | 67 | 68 | maven-assembly-plugin 69 | 70 | 71 | distro-assembly 72 | package 73 | 74 | single 75 | 76 | 77 | false 78 | 79 | src/main/assembly/assembly.xml 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /kettle-sdk-step-plugin/src/main/assembly/assembly.xml: -------------------------------------------------------------------------------- 1 | 5 | bin 6 | 7 | zip 8 | 9 | 10 | 11 | ${project.build.directory} 12 | / 13 | 14 | *.jar 15 | 16 | 17 | 18 | 19 | 20 | lib/ 21 | false 22 | runtime 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /kettle-sdk-step-plugin/src/main/java/org/pentaho/di/sdk/samples/steps/demo/DemoStepData.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.steps.demo; 15 | 16 | import org.pentaho.di.core.row.RowMetaInterface; 17 | import org.pentaho.di.trans.step.BaseStepData; 18 | import org.pentaho.di.trans.step.StepDataInterface; 19 | 20 | /** 21 | * This class is part of the demo step plug-in implementation. 22 | * It demonstrates the basics of developing a plug-in step for PDI. 23 | * 24 | * The demo step adds a new string field to the row stream and sets its 25 | * value to "Hello World!". The user may select the name of the new field. 26 | * 27 | * This class is the implementation of StepDataInterface. 28 | * 29 | * Implementing classes inherit from BaseStepData, which implements the entire 30 | * interface completely. 31 | * 32 | * In addition classes implementing this interface usually keep track of 33 | * per-thread resources during step execution. Typical examples are: 34 | * result sets, temporary data, caching indexes, etc. 35 | * 36 | * The implementation for the demo step stores the output row structure in 37 | * the data class. 38 | * 39 | */ 40 | public class DemoStepData extends BaseStepData implements StepDataInterface { 41 | 42 | RowMetaInterface outputRowMeta; 43 | int outputFieldIndex = -1; 44 | 45 | public DemoStepData() { 46 | super(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /kettle-sdk-step-plugin/src/main/resources/org/pentaho/di/sdk/samples/steps/demo/messages/messages_en_US.properties: -------------------------------------------------------------------------------- 1 | Demo.Shell.Title=Demo step 2 | Demo.FieldName.Label=Output field name 3 | Demo.CheckResult.ReceivingRows.OK=Step is receiving input from other steps. 4 | Demo.CheckResult.ReceivingRows.ERROR=No input received from other steps! 5 | 6 | DemoStep.Name=Demo Step 7 | DemoStep.TooltipDesc=Demo Step Description 8 | DemoStep.DocumentationURL=https://help.pentaho.com/Documentation/6.1/0R0/0V0 9 | DemoStep.CasesURL=http://jira.pentaho.com/browse/PDI/ 10 | DemoStep.ForumURL=http://forums.pentaho.com/ 11 | DemoStep.Linenr=Linenr {0} 12 | DemoStep.Error.NoOutputField=Could not find Output Field in row -------------------------------------------------------------------------------- /kettle-sdk-step-plugin/src/main/resources/org/pentaho/di/sdk/samples/steps/demo/resources/demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pentaho/pdi-sdk-plugins/d61a31fe55505b2a4f16789a1102ce95ba3c2eb9/kettle-sdk-step-plugin/src/main/resources/org/pentaho/di/sdk/samples/steps/demo/resources/demo.png -------------------------------------------------------------------------------- /kettle-sdk-step-plugin/src/main/resources/org/pentaho/di/sdk/samples/steps/demo/resources/demo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 13 | 14 | 15 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /kettle-sdk-step-plugin/src/test/java/org/pentaho/di/sdk/samples/steps/demo/DemoStepDataTest.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.steps.demo; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | import static org.junit.Assert.assertNull; 18 | 19 | import org.junit.Test; 20 | 21 | public class DemoStepDataTest { 22 | 23 | @Test 24 | public void testDefaults() { 25 | DemoStepData data = new DemoStepData(); 26 | assertNull( data.outputRowMeta ); 27 | assertEquals( -1, data.outputFieldIndex ); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /kettle-sdk-step-plugin/src/test/java/org/pentaho/di/sdk/samples/steps/demo/DemoStepTest.java: -------------------------------------------------------------------------------- 1 | /*! ****************************************************************************** 2 | * 3 | * Pentaho 4 | * 5 | * Copyright (C) 2024 by Hitachi Vantara, LLC : http://www.pentaho.com 6 | * 7 | * Use of this software is governed by the Business Source License included 8 | * in the LICENSE.TXT file. 9 | * 10 | * Change Date: 2029-07-20 11 | ******************************************************************************/ 12 | 13 | 14 | package org.pentaho.di.sdk.samples.steps.demo; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | import static org.junit.Assert.assertNotNull; 18 | import static org.junit.Assert.fail; 19 | 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | import java.util.UUID; 23 | 24 | import org.junit.BeforeClass; 25 | import org.junit.Test; 26 | import org.pentaho.di.core.KettleEnvironment; 27 | import org.pentaho.di.core.RowMetaAndData; 28 | import org.pentaho.di.core.exception.KettleException; 29 | import org.pentaho.di.core.row.RowMeta; 30 | import org.pentaho.di.core.row.RowMetaInterface; 31 | import org.pentaho.di.core.row.value.ValueMetaString; 32 | import org.pentaho.di.core.variables.Variables; 33 | import org.pentaho.di.trans.TransMeta; 34 | import org.pentaho.di.trans.TransTestFactory; 35 | 36 | public class DemoStepTest { 37 | 38 | static final String STEP_NAME = "Test Demo Step"; 39 | 40 | @BeforeClass 41 | public static void setUpBeforeClass() throws KettleException { 42 | KettleEnvironment.init( false ); 43 | } 44 | 45 | // If the step does not receive any rows, the transformation should still run successfully 46 | @Test 47 | public void testNoInput() throws KettleException { 48 | DemoStepMeta meta = new DemoStepMeta(); 49 | meta.setOutputField( "aFieldName" ); 50 | TransMeta tm = TransTestFactory.generateTestTransformation( new Variables(), meta, STEP_NAME ); 51 | 52 | List result = TransTestFactory.executeTestTransformation( tm, TransTestFactory.INJECTOR_STEPNAME, 53 | STEP_NAME, TransTestFactory.DUMMY_STEPNAME, new ArrayList() ); 54 | 55 | assertNotNull( result ); 56 | assertEquals( 0, result.size() ); 57 | } 58 | 59 | // If the step receives rows without any fields, there should be a single output field on each row 60 | @Test 61 | public void testInputNoFields() throws KettleException { 62 | DemoStepMeta meta = new DemoStepMeta(); 63 | meta.setOutputField( "aFieldName" ); 64 | TransMeta tm = TransTestFactory.generateTestTransformation( new Variables(), meta, STEP_NAME ); 65 | 66 | List result = TransTestFactory.executeTestTransformation( tm, TransTestFactory.INJECTOR_STEPNAME, 67 | STEP_NAME, TransTestFactory.DUMMY_STEPNAME, generateInputData( 50001, false ) ); 68 | 69 | assertNotNull( result ); 70 | assertEquals( 50001, result.size() ); 71 | for ( int i = 0; i < 50001; i++ ) { 72 | assertEquals( 1, result.get( i ).size() ); 73 | assertEquals( "Hello World!", result.get( i ).getString( 0, "default value" ) ); 74 | } 75 | } 76 | 77 | // If the step receives rows with existing fields, there should be a new field at the end of each output row 78 | @Test 79 | public void testInput() throws KettleException { 80 | DemoStepMeta meta = new DemoStepMeta(); 81 | meta.setOutputField( "aFieldName" ); 82 | TransMeta tm = TransTestFactory.generateTestTransformation( new Variables(), meta, STEP_NAME ); 83 | 84 | List result = TransTestFactory.executeTestTransformation( tm, TransTestFactory.INJECTOR_STEPNAME, 85 | STEP_NAME, TransTestFactory.DUMMY_STEPNAME, generateInputData( 5, true ) ); 86 | 87 | assertNotNull( result ); 88 | assertEquals( 5, result.size() ); 89 | for ( int i = 0; i < 5; i++ ) { 90 | assertEquals( 2, result.get( i ).size() ); 91 | assertEquals( "UUID", result.get( i ).getValueMeta( 0 ).getName() ); 92 | try { 93 | UUID.fromString( result.get( i ).getString(0, "default value" ) ); 94 | } catch ( IllegalArgumentException iae ) { 95 | fail(); // UUID field value was modified unexpectedly 96 | } 97 | assertEquals( "Hello World!", result.get( i ).getString( 1, "default value" ) ); 98 | } 99 | } 100 | 101 | /** 102 | * 103 | * @param rowCount The number of rows that should be returned 104 | * @param hasFields Whether a "UUID" field should be added to each row 105 | * @return A RowMetaAndData object that can be used for input data in a test transformation 106 | */ 107 | public static List generateInputData( int rowCount, boolean hasFields ) { 108 | List retval = new ArrayList(); 109 | RowMetaInterface rowMeta = new RowMeta(); 110 | if ( hasFields ) { 111 | rowMeta.addValueMeta( new ValueMetaString( "UUID" ) ); 112 | } 113 | 114 | for ( int i = 0; i < rowCount; i++ ) { 115 | Object[] data = new Object[0]; 116 | if ( hasFields ) { 117 | data = new Object[] { UUID.randomUUID().toString() }; 118 | } 119 | retval.add( new RowMetaAndData( rowMeta, data ) ); 120 | } 121 | return retval; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.pentaho 7 | pentaho-ce-jar-parent-pom 8 | 10.3.0.0-SNAPSHOT 9 | 10 | pentaho-kettle 11 | kettle-sdk-plugin-parent 12 | 10.3.0.0-SNAPSHOT 13 | pom 14 | Pentaho Data Integration SDK Parent POM 15 | 16 | kettle-sdk-database-plugin 17 | kettle-sdk-embedding-samples 18 | kettle-sdk-jobentry-plugin 19 | kettle-sdk-partitioner-plugin 20 | kettle-sdk-step-plugin 21 | kettle-sdk-plugin-assembly 22 | 23 | 24 | 25 | 26 | 5.10.0 27 | 10.3.0.0-SNAPSHOT 28 | 29 | 10.3.0.0-SNAPSHOT 30 | 31 | 4.13.2 32 | 33 | 34 | 35 | 36 | 37 | pentaho-public 38 | Pentaho Public 39 | https://repo.orl.eng.hitachivantara.com/artifactory/pnt-mvn/ 40 | 41 | true 42 | daily 43 | 44 | 45 | true 46 | interval:15 47 | 48 | 49 | 50 | 51 | 52 | 53 | pentaho-public-plugins 54 | Pentaho Public Plugins 55 | https://repo.orl.eng.hitachivantara.com/artifactory/pnt-mvn/ 56 | 57 | false 58 | 59 | 60 | never 61 | 62 | 63 | 64 | 65 | 66 | 67 | --------------------------------------------------------------------------------