当前位置: 首页> 房产> 家装 > 【FineReport】帆软调用服务器的kettle作业

【FineReport】帆软调用服务器的kettle作业

时间:2025/7/11 23:52:31来源:https://blog.csdn.net/weixin_44786702/article/details/139641167 浏览次数:1次

1、编写自定义函数并编译

package com.fr.function;import ch.ethz.ssh2.ChannelCondition;
import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.Session;
import ch.ethz.ssh2.StreamGobbler;
import com.fr.script.AbstractFunction;import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;import static com.fr.health.constants.ComponentHealthConstants.Status.TIME_OUT;public class CustomSubmitJobCommon extends AbstractFunction {@Overridepublic Object run(Object[] arg0) {return executeRemoteCommandCommon();}private String executeRemoteCommandCommon() {final String ipAddress = "127.0.0.1";     // 远程服务器主机ip final String username = "root";          //用户名final String password = "123456";   // 登录密码final String command = "cd /usr/kettle_task/N_steelmaking/ceshi/cb_ceshiv1 && ./cb_ceshiv1.sh";   //调用kettle作业的命令try{Connection conn = new Connection(ipAddress);conn.connect(); // 连接远程服务器if (!conn.authenticateWithPassword(username, password)) {System.err.printf("Failed to authenticate with username '%s' on server %s.", username, ipAddress);return "用户名或密码错误";}try {Session session = conn.openSession(); // 打开一个会话session.execCommand(command); // 执行cmd命令System.out.println(command);// Capture output and errorsInputStream stdOut = new StreamGobbler(session.getStdout());InputStream stdErr = new StreamGobbler(session.getStderr());// Read and potentially log stdout/stderrprintStream(stdOut, "STDOUT:");printStream(stdErr, "STDERR:");// Wait for the command to finish, with a timeoutint exitStatus = session.waitForCondition(ChannelCondition.EXIT_STATUS, TIME_OUT);if (exitStatus == TIME_OUT) {System.err.println("Command execution timed out.");return "执行失败";}return "执行成功";} finally {conn.close();}} catch (IOException e) {System.err.println("An error occurred during the SSH connection or command execution.");e.printStackTrace();return "连接失败";}}private void printStream(InputStream in, String streamType) {try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {String line;while ((line = reader.readLine()) != null) {System.out.println(streamType + " " + line);}} catch (IOException e) {System.err.println("Error reading from stream: " + e.getMessage());}}public static void main(String[] args) {CustomSubmitJobCommon job = new CustomSubmitJobCommon();System.out.println(job.executeRemoteCommandCommon());}
}

2、新增按钮,并添加点击事件,点击按钮后即可执行命令调用kettle作业。

在这里插入图片描述

关键字:【FineReport】帆软调用服务器的kettle作业

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: