Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.java.nemonix;
- import net.schmizz.sshj.SSHClient;
- import net.schmizz.sshj.common.IOUtils;
- import net.schmizz.sshj.connection.ConnectionException;
- import net.schmizz.sshj.connection.channel.direct.Session;
- import net.schmizz.sshj.sftp.SFTPClient;
- import net.schmizz.sshj.transport.TransportException;
- import net.schmizz.sshj.transport.verification.PromiscuousVerifier;
- import net.schmizz.sshj.xfer.FileSystemFile;
- import org.apache.commons.io.FileUtils;
- import org.apache.commons.net.ftp.FTP;
- import org.apache.commons.net.ftp.FTPClient;
- import javax.swing.*;
- import java.io.*;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.HashMap;
- import java.util.Locale;
- import java.util.concurrent.BrokenBarrierException;
- import java.util.concurrent.CyclicBarrier;
- import java.util.concurrent.TimeUnit;
- public class Linpack {
- private HashMap<String, Session> sessions = new HashMap<>();
- private HashMap<String, String> ips;
- public Setup setup;
- private final ArrayList<String> installLinpack = new ArrayList<>(Arrays.asList("tar xfv l_mklb_p_2020.2.001.tgz", "tar xfv l_mpi_2019.8.254.tgz", "cd l_mpi_2019.8.254", "./install.sh", " ", "q", "accept", "1", "1", "1", "1"));
- private final ArrayList<String> executeLinpack = new ArrayList<>(Arrays.asList("cd", "cd l_mklb_p_2020.2.001/benchmarks_2020/linux/mkl/benchmarks/mp_linpack; ln -s /opt/intel/compilers_and_libraries_2020.2.254/linux/mpi/intel64/bin/mpirun /bin/mpirun", "ln -s /opt/intel/compilers_and_libraries_2020.2.254/linux/mpi/intel64/bin/mpivars.sh /bin/mpivars.sh", "cd", "cd l_mklb_p_2020.2.001/benchmarks_2020/linux/mkl/benchmarks/linpack", "./runme_xeon64"));
- public Linpack(Setup setup) {
- this.setup = setup;
- }
- public void startLinpack() {
- ips = setup.getIPsByMAC();
- File mklb = new File(new JFileChooser().getFileSystemView().getDefaultDirectory()+"\\NX_SystemSetup\\data\\linpack\\l_mklb_p_2020.2.001.tgz");
- File mpi = new File(new JFileChooser().getFileSystemView().getDefaultDirectory()+"\\NX_SystemSetup\\data\\linpack\\l_mpi_2019.8.254.tgz");
- File lininput = new File(new JFileChooser().getFileSystemView().getDefaultDirectory()+"\\NX_SystemSetup\\data\\linpack\\lininput_xeon64");
- CyclicBarrier gate = new CyclicBarrier(ips.size()+1);
- ArrayList<Thread> threads = new ArrayList<>();
- for(String ip : ips.keySet()) {
- Thread t = new Thread(() -> {
- //System.out.println("Uploading file mklb to " + ips.get(ip));
- uploadFile(ips.get(ip), mklb, "/root/");
- uploadFile(ips.get(ip), mpi, "/root/");
- try {
- gate.await();
- } catch (InterruptedException | BrokenBarrierException e) {
- setup.writeErrorLog(e);
- }
- });
- threads.add(t);
- }
- for(Thread t : threads) t.start();
- threads.clear();
- try {
- gate.await();
- } catch (InterruptedException | BrokenBarrierException e) {
- setup.writeErrorLog(e);
- }
- for(String command : installLinpack) {
- executeCommand("192.168.4.55", command);
- }
- gate.reset();
- for(String ip : ips.keySet()) {
- Thread t = new Thread(() -> {
- for(String command : installLinpack) {
- executeCommand(ips.get(ip), command);
- }
- try {
- gate.await();
- } catch (InterruptedException | BrokenBarrierException e) {
- setup.writeErrorLog(e);
- }
- });
- threads.add(t);
- }
- for(Thread t : threads) t.start();
- threads.clear();
- String configFileName = getLinpackConfigFileName(setup.getTemplate().getName(), setup.getVersion());
- File config = new File(new JFileChooser().getFileSystemView().getDefaultDirectory()+"\\NX_SystemSetup\\data\\linpack\\" + configFileName);
- try {
- FileUtils.copyFile(config, lininput);
- } catch (IOException e) {
- setup.writeErrorLog(e);
- }
- for(String ip : ips.keySet()) {
- Thread t = new Thread(() -> {
- uploadFile(ips.get(ip), lininput, "l_mklb_p_2020.2.001/benchmarks_2020/linux/mkl/benchmarks/linpack/");
- try {
- gate.await();
- } catch (InterruptedException | BrokenBarrierException e) {
- setup.writeErrorLog(e);
- }
- });
- threads.add(t);
- }
- try {
- gate.await();
- } catch (InterruptedException | BrokenBarrierException e) {
- setup.writeErrorLog(e);
- }
- gate.reset();
- for(Thread t : threads) t.start();
- threads.clear();
- try {
- gate.await();
- } catch (InterruptedException | BrokenBarrierException e) {
- setup.writeErrorLog(e);
- }
- for(String ip : ips.keySet()) {
- Thread t = new Thread(() -> {
- for(String command : executeLinpack) {
- executeCommand(ips.get(ip), command);
- }
- });
- threads.add(t);
- }
- for(Thread t : threads) t.start();
- threads.clear();
- }
- public void executeCommand(String ip, String command) {
- StringBuilder test = new StringBuilder();
- final SSHClient sshClient = new SSHClient();
- sshClient.addHostKeyVerifier(new PromiscuousVerifier());
- Session session = null;
- try {
- sshClient.connect(ip);
- sshClient.authPassword("root", "admin");
- session = sshClient.startSession();
- final Session.Command cmd = session.exec(command);
- test.append(IOUtils.readFully(cmd.getInputStream()));
- cmd.join(5, TimeUnit.SECONDS);
- test.append("\n** exit status: ").append(cmd.getExitStatus());
- System.out.println(test);
- } catch (TransportException | ConnectionException e) {
- setup.writeErrorLog(e);
- System.out.println("SSH Error");
- } catch (IOException e) {
- setup.writeErrorLog(e);
- } finally {
- try {
- if (session != null) {
- session.close();
- }
- } catch (TransportException | ConnectionException e) {
- setup.writeErrorLog(e);
- }
- try {
- sshClient.disconnect();
- } catch (IOException e) {
- setup.writeErrorLog(e);
- }
- }
- }
- public void uploadFile(String ip, File file, String dest) {
- SSHClient sshClient = new SSHClient();
- sshClient.addHostKeyVerifier(new PromiscuousVerifier());
- try {
- sshClient.connect(ip);
- sshClient.authPassword("root", "admin");
- try {
- //sshClient.authPublickey(System.getProperty("user.name"));
- final String src = file.getAbsolutePath();
- try (SFTPClient sftp = sshClient.newSFTPClient()) {
- sftp.put(new FileSystemFile(src), dest);
- }
- } finally {
- sshClient.disconnect();
- }
- } catch (IOException e) {
- setup.writeErrorLog(e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment