// Path: src/main/cn/ict/zyq/bestConf/cluster/Interface/SystemOperation.java
// public interface SystemOperation {
//     void initial(String server, String username, String password, String shellsPath, int timeout, int maxRoundConnection, int sshReconnectWatingtime);
// 	void start();
// 	void shutdown();
// 	void stopSystem();
// 	boolean isClosed();
// 	boolean isStarted();
// 	void terminateSystem();
// }


import ch.ethz.ssh2.StreamGobbler;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import cn.ict.zyq.bestConf.cluster.Interface.SystemOperation;
import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.Session;

	@Override
	public void initial(String server, String username, String password, String shellsPath, int timeout, int maxRoundConnection, int sshReconnectWatingtime) {
		this.server = server;
		this.username = username;
		this.password = password;
		DeducingErrorTime = timeout;
		this.maxRoundConnection = maxRoundConnection;
		this.sshReconnectWatingtime = sshReconnectWatingtime;
		shellofStart = shellsPath + "/start.sh";
		shellofStop = "cd " + shellsPath + ";./stop.sh";
		shellofisStarted = "cd " + shellsPath + ";./isStart.sh";
		shellofisClosed = "cd " + shellsPath + ";./isClosed.sh";
		shellofTerminate = "cd " + shellsPath + ";./terminateSystem.sh";
		
	}
    public Connection getConnection(){
    	int round = 0;
    	while(round<maxRoundConnection){
    		try{
    			connection = new Connection(server);
    			connection.connect();
    			boolean isAuthenticated = connection.authenticateWithPassword(username, password);
    			if (isAuthenticated == false) {
    				throw new IOException("Authentication failed...");
    			}
    			break;
    		}catch (Exception e) {
    			e.printStackTrace();
    			connection.close();
    			connection = null;

// Path: src/main/cn/ict/zyq/bestConf/cluster/Interface/SystemOperation.java
// public interface SystemOperation {
//     void initial(String server, String username, String password, String shellsPath, int timeout, int maxRoundConnection, int sshReconnectWatingtime);
// 	void start();
// 	void shutdown();
// 	void stopSystem();
// 	boolean isClosed();
// 	boolean isStarted();
// 	void terminateSystem();
// }


// Path: src/main/cn/ict/zyq/bestConf/cluster/InterfaceImpl/SUTSystemOperation.java
import ch.ethz.ssh2.StreamGobbler;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import cn.ict.zyq.bestConf.cluster.Interface.SystemOperation;
import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.Session;

	@Override
	public void initial(String server, String username, String password, String shellsPath, int timeout, int maxRoundConnection, int sshReconnectWatingtime) {
		this.server = server;
		this.username = username;
		this.password = password;
		DeducingErrorTime = timeout;
		this.maxRoundConnection = maxRoundConnection;
		this.sshReconnectWatingtime = sshReconnectWatingtime;
		shellofStart = shellsPath + "/start.sh";
		shellofStop = "cd " + shellsPath + ";./stop.sh";
		shellofisStarted = "cd " + shellsPath + ";./isStart.sh";
		shellofisClosed = "cd " + shellsPath + ";./isClosed.sh";
		shellofTerminate = "cd " + shellsPath + ";./terminateSystem.sh";
		
	}
    public Connection getConnection(){
    	int round = 0;
    	while(round<maxRoundConnection){
    		try{
    			connection = new Connection(server);
    			connection.connect();
    			boolean isAuthenticated = connection.authenticateWithPassword(username, password);
    			if (isAuthenticated == false) {
    				throw new IOException("Authentication failed...");
    			}
    			break;
    		}catch (Exception e) {
    			e.printStackTrace();
    			connection.close();
    			connection = null;

    			System.err.println("================= connection is null in round "+round);
