From c647b8123410cf8e486dc9f63fae963858f6470b Mon Sep 17 00:00:00 2001 From: lily Date: Wed, 28 Sep 2016 10:56:57 +0800 Subject: [PATCH] back --- src/com/platform/glusterfs/ClusterInfo.java | 40 +++++++++++---------- src/com/platform/glusterfs/VolumeInfo.java | 5 ++- src/com/platform/utils/ConfigsLoader.java | 2 +- src/com/platform/utils/GanymedSSH.java | 15 +++++--- 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/com/platform/glusterfs/ClusterInfo.java b/src/com/platform/glusterfs/ClusterInfo.java index 8b418e58..017efe41 100644 --- a/src/com/platform/glusterfs/ClusterInfo.java +++ b/src/com/platform/glusterfs/ClusterInfo.java @@ -39,7 +39,7 @@ public class ClusterInfo { * @see [类、类#方法、类#成员] */ public Map showClusterInfo() { - log.info("get cluster info"); +// log.info("get cluster info"); Map peerIps = new HashMap(); List reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(Constant.glusterPeerStatus); @@ -90,24 +90,28 @@ public class ClusterInfo { } } - for (Map.Entry entry:peerIps.entrySet()){ - String key=entry.getKey(); - String value=entry.getValue(); - if(Constant.ganymedSSH.otherConns==null){ - Constant.ganymedSSH.otherConns=new HashMap(); - } - if(!Constant.ganymedSSH.otherConns.containsKey(key)){ - Connection connection=null; - try { - connection = Constant.ganymedSSH.getOpenedConnection(key, Constant.rootUser, Constant.rootPasswd, Constant.port); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - Constant.ganymedSSH.otherConns.put(key,connection); - } - } peerIps.put(Constant.hostIp, Constant.peerincluster_connected); +// for (Map.Entry entry:peerIps.entrySet()){ +// String key=entry.getKey(); +// if(key.equals(Constant.hostIp)){ +// continue; +// } +// String value=entry.getValue(); +// if(Constant.ganymedSSH.otherConns==null){ +// Constant.ganymedSSH.otherConns=new HashMap(); +// } +// if(!Constant.ganymedSSH.otherConns.containsKey(key)){ +// Connection connection=null; +// try { +// connection = Constant.ganymedSSH.getOpenedConnection(key, Constant.rootUser, Constant.rootPasswd, Constant.port); +// } catch (IOException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } +// Constant.ganymedSSH.otherConns.put(key,connection); +// } +// } + return peerIps; } diff --git a/src/com/platform/glusterfs/VolumeInfo.java b/src/com/platform/glusterfs/VolumeInfo.java index d090b21e..34d2e2c8 100644 --- a/src/com/platform/glusterfs/VolumeInfo.java +++ b/src/com/platform/glusterfs/VolumeInfo.java @@ -37,7 +37,7 @@ public class VolumeInfo { * @see [类、类#方法、类#成员] */ public List showAllVolumeName() { - log.info(Constant.ganymedSSH+"get volume name"); +// log.info(Constant.ganymedSSH+"get volume name"); List volNames = new ArrayList(); /* @@ -46,8 +46,7 @@ public class VolumeInfo { * runCommand = new RunCommand(); List reStrings = * runCommand.runCommandWait(command); */ - Constant.ganymedSSH - .execCmdNoWaitAcquiescent("mkdir /home/test111111"); + List reStrings = Constant.ganymedSSH .execCmdWaitAcquiescent(Constant.glusterVolumeInfo + "|grep ^Volume.Name"); // System.out.println(reStrings); diff --git a/src/com/platform/utils/ConfigsLoader.java b/src/com/platform/utils/ConfigsLoader.java index 4b0f703f..342f493d 100644 --- a/src/com/platform/utils/ConfigsLoader.java +++ b/src/com/platform/utils/ConfigsLoader.java @@ -68,7 +68,7 @@ public class ConfigsLoader implements ServletContextListener { Constant.hostIp=properties.getProperty("gfs_control_ip").trim(); Constant.rootPasswd=properties.getProperty("gfs_control_rootPassWd").trim(); Constant.ganymedSSH = new GanymedSSH(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, Constant.port); - Constant.ganymedSSH.otherConns=new HashMap(); + } public ConfigPropertyReader getcReader() { diff --git a/src/com/platform/utils/GanymedSSH.java b/src/com/platform/utils/GanymedSSH.java index a2fa59e3..0571fc59 100644 --- a/src/com/platform/utils/GanymedSSH.java +++ b/src/com/platform/utils/GanymedSSH.java @@ -36,6 +36,7 @@ public class GanymedSSH { // TODO Auto-generated constructor stub try { conn = getOpenedConnection(host, username, password, port); + otherConns=new HashMap(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -81,14 +82,17 @@ public class GanymedSSH { Session sess = null; Connection new_conn; try { - if(otherConns.containsKey(host) && otherConns.get(host)!=null){ + if(Constant.hostIp.equals(host)){ + new_conn=conn; + } + else if(otherConns.containsKey(host) && otherConns.get(host)!=null){ new_conn=otherConns.get(host); } else{ new_conn = getOpenedConnection(host, username, password, port); otherConns.put(host, new_conn); } - sess = conn.openSession(); + sess = new_conn.openSession(); // 执锟斤拷cmd sess.execCommand(cmd); } catch (IOException e) { @@ -157,14 +161,17 @@ public class GanymedSSH { Session sess = null; Connection new_conn; try { - if(otherConns.containsKey(host) && otherConns.get(host)!=null){ + if(Constant.hostIp.equals(host)){ + new_conn=conn; + } + else if(otherConns.containsKey(host) && otherConns.get(host)!=null){ new_conn=otherConns.get(host); } else{ new_conn = getOpenedConnection(host, username, password, port); otherConns.put(host, new_conn); } - sess = conn.openSession(); + sess = new_conn.openSession(); // 执锟斤拷cmd sess.execCommand(cmd);