From eed67d9babee68657ba5af52cbf2bcfbe43413ca Mon Sep 17 00:00:00 2001 From: linzehao Date: Thu, 21 Mar 2024 00:27:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=EF=BC=9A=E6=B8=85=E7=90=86ss?= =?UTF-8?q?h=E7=9B=B8=E5=85=B3=E6=B5=8B=E8=AF=95=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/dromara/cloudeon/test/ShellTest.java | 40 ------- .../org/dromara/cloudeon/test/SshTest.java | 105 ------------------ 2 files changed, 145 deletions(-) delete mode 100644 cloudeon-server/src/test/java/org/dromara/cloudeon/test/ShellTest.java delete mode 100644 cloudeon-server/src/test/java/org/dromara/cloudeon/test/SshTest.java diff --git a/cloudeon-server/src/test/java/org/dromara/cloudeon/test/ShellTest.java b/cloudeon-server/src/test/java/org/dromara/cloudeon/test/ShellTest.java deleted file mode 100644 index 4ee3dc40..00000000 --- a/cloudeon-server/src/test/java/org/dromara/cloudeon/test/ShellTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.dromara.cloudeon.test; - -import org.dromara.cloudeon.utils.ShellUtils; -import lombok.extern.slf4j.Slf4j; -import org.assertj.core.util.Lists; -import org.junit.jupiter.api.Test; - -@Slf4j -public class ShellTest { - - @Test - public void cpu() { - - System.out.println(ShellUtils.builder().logger(log).build().getCpuArchitecture()); - } - - @Test - public void exec() { - -// System.out.println(ShellUtils.builder().logger(log).build().exceShell("echo mntr | nc localhost 2181")); - System.out.println("====================="); - System.out.println(ShellUtils.builder().build().execWithStatus("/Users/huzekang/cdh5.16/zookeeper-3.4.5-cdh5.16.2/", Lists.newArrayList("sh", "1.sh"), 100000)); - } -} diff --git a/cloudeon-server/src/test/java/org/dromara/cloudeon/test/SshTest.java b/cloudeon-server/src/test/java/org/dromara/cloudeon/test/SshTest.java deleted file mode 100644 index ccb963fe..00000000 --- a/cloudeon-server/src/test/java/org/dromara/cloudeon/test/SshTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.dromara.cloudeon.test; - -import org.dromara.cloudeon.utils.SshUtils; -import com.jcraft.jsch.Channel; -import com.jcraft.jsch.JSch; -import com.jcraft.jsch.JSchException; -import com.jcraft.jsch.Session; -import lombok.extern.slf4j.Slf4j; -import org.apache.sshd.client.session.ClientSession; -import org.apache.sshd.sftp.client.SftpClientFactory; -import org.apache.sshd.sftp.client.fs.SftpFileSystem; -import org.junit.jupiter.api.Test; - -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; - -@Slf4j -public class SshTest { - - - @Test - public void execCmdWithResult() throws IOException { - ClientSession session = SshUtils.openConnectionByPassword( - "10.81.16.19", - 22, - "root", - "Ltcyhlwylym@admin2021zi!"); - -// SshUtils.uploadFile(session,"/opt/edp/ZOOKEEPER1/conf", "/Users/huzekang/Downloads/apache-zookeeper-3.6.3-bin.tar.gz"); -// SshUtils.uploadLocalDirToRemote(session,"/opt/edp/ZOOKEEPER1/conf","/Volumes/Samsung_T5/opensource/e-mapreduce/work/ZOOKEEPER1/fl001/conf"); - } - - @Test - public void upload() throws IOException { - ClientSession session = SshUtils.openConnectionByPassword( - "10.81.16.19", - 22, - "root", - "Ltcyhlwylym@admin2021zi!"); - - SftpFileSystem fileSystem; - try { - fileSystem = SftpClientFactory.instance().createSftpFileSystem(session); - } catch (IOException e) { - e.printStackTrace(); - throw new RuntimeException("打开sftp失败:"+e); - } -// SshUtils.uploadLocalDirToRemote("/tmp/test/", "/Volumes/Samsung_T5/opensource/e-mapreduce/cloudeon-stack/UDH-1.0.0", fileSystem); - SshUtils.uploadFile("/tmp/test/", "/Volumes/Samsung_T5/opensource/e-mapreduce/remote-script/check.sh", fileSystem); - - - } - - - - @Test - public void ssh2GetLog2() throws IOException, JSchException { - - JSch jsch = new JSch(); - Session session = jsch.getSession("root", "10.81.16.19", 22); - session.setConfig("StrictHostKeyChecking", "no"); - session.setPassword("Ltcyhlwylym@admin2021zi!"); - session.connect(); - - Channel channel = session.openChannel("exec"); - ((com.jcraft.jsch.ChannelExec) channel).setCommand("tail -f /opt/edp/monitor1/log/grafana.log\n"); - - InputStream in = channel.getInputStream(); - channel.connect(); - - FileWriter writer = new FileWriter("/Volumes/Samsung_T5/opensource/e-mapreduce/file.txt"); - byte[] buffer = new byte[1024]; - while (true) { - int n = in.read(buffer); - if (n < 0) { - break; - } - writer.write(new String(buffer, 0, n)); - writer.flush(); - } - channel.disconnect(); - session.disconnect(); - } - - - - -}