调试
代码
在远程调用使用carte服务的时候,使用比较多的2个工具类:Trans,Job
下面看一下经常用的Job的远程调用方法:
public static String sendToSlaveServer( JobMeta jobMeta, JobExecutionConfiguration executionConfiguration,
Repository repository, IMetaStore metaStore ) throws KettleException {
String carteObjectId;
// 获取执行服务器
SlaveServer slaveServer = executionConfiguration.getRemoteServer();
...
try {
// Inject certain internal variables to make it more intuitive.
// 拼装参数
for ( String var : Const.INTERNAL_TRANS_VARIABLES ) {
executionConfiguration.getVariables().put( var, jobMeta.getVariable( var ) );
}
for ( String var : Const.INTERNAL_JOB_VARIABLES ) {
executionConfiguration.getVariables().put( var, jobMeta.getVariable( var ) );
}
if ( executionConfiguration.isPassingExport() ) {
// First export the job... slaveServer.getVariable("MASTER_HOST")
//
FileObject tempFile =
KettleVFS.createTempFile( "jobExport", ".zip", System.getProperty( "java.io.tmpdir" ), jobMeta );
TopLevelResource topLevelResource =
ResourceUtil.serializeResourceExportInterface( tempFile.getName().toString(), jobMeta, jobMeta, repository,
metaStore, executionConfiguration.getXML(), CONFIGURATION_IN_EXPORT_FILENAME );
// Send the zip file over to the slave server...
String result =
slaveServer.sendExport( topLevelResource.getArchiveName(), RegisterPackageServlet.TYPE_JOB, topLevelResource
.getBaseResourceName() );
WebResult webResult = WebResult.fromXMLString( result );
if ( !webResult.getResult().equalsIgnoreCase( WebResult.STRING_OK ) ) {
throw new KettleException( "There was an error passing the exported job to the remote server: " + Const.CR
+ webResult.getMessage() );
}
carteObjectId = webResult.getId();
} else {
String xml = new JobConfiguration( jobMeta, executionConfiguration ).getXML();
String reply = slaveServer.sendXML( xml, RegisterJobServlet.CONTEXT_PATH + "/?xml=Y" );
WebResult webResult = WebResult.fromXMLString( reply );
if ( !webResult.getResult().equalsIgnoreCase( WebResult.STRING_OK ) ) {
throw new KettleException( "There was an error posting the job on the remote server: " + Const.CR + webResult
.getMessage() );
}
carteObjectId = webResult.getId();
}
// Start the job
//
String reply =
slaveServer.execService( StartJobServlet.CONTEXT_PATH + "/?name=" + URLEncoder.encode( jobMeta.getName(),
"UTF-8" ) + "&xml=Y&id=" + carteObjectId );
WebResult webResult = WebResult.fromXMLString( reply );
if ( !webResult.getResult().equalsIgnoreCase( WebResult.STRING_OK ) ) {
throw new KettleException( "There was an error starting the job on the remote server: " + Const.CR + webResult
.getMessage() );
}
return carteObjectId;
} catch ( KettleException ke ) {
throw ke;
} catch ( Exception e ) {
throw new KettleException( e );
}
}
从这个方法中我们可以看到,在client端其实是通过slaveserver向carte发送了rest请求,server端使用jersey的jetty容器。
那么也给我们进行二次开发提供了思路,下面我们看看kettle的rest服务是如何开启的:
在engine模块的www包里添加servlet和kettle-servlet.xml添加item