diff --git a/.classpath b/.classpath
index bb13dba0..84b01679 100644
--- a/.classpath
+++ b/.classpath
@@ -3,8 +3,17 @@
-
+
+
+
+
+
+
+
+
+
+
diff --git a/src/com/platform/controller/VolumeController.java b/src/com/platform/controller/VolumeController.java
index 4f94761a..0d6600f2 100644
--- a/src/com/platform/controller/VolumeController.java
+++ b/src/com/platform/controller/VolumeController.java
@@ -17,6 +17,8 @@ import com.platform.entities.VolumeForm;
import com.platform.entities.VolumeInitEntity;
import com.platform.service.IVolumeService;
import com.platform.utils.Configs;
+import com.platform.utils.ThreadVolume;
+import com.platform.utils.ThreadVolumeImm;
@Controller
public class VolumeController extends BaseController{
@@ -34,6 +36,7 @@ public class VolumeController extends BaseController{
Configs.CONSOLE_LOGGER.error("/oracle/{name}/extract");
volumeService.save(form);
req.setStatus(200);
+ new ThreadVolumeImm("ThreadVolumeImm-in-VolumeController-update").start();
}
@RequestMapping(value = "/volume/delete", method = RequestMethod.POST)
@@ -43,6 +46,7 @@ public class VolumeController extends BaseController{
Configs.CONSOLE_LOGGER.error("/oracle/{name}/extract");
volumeService.delete(entity);
req.setStatus(200);
+ new ThreadVolumeImm("ThreadVolumeImm-in-VolumeController-delete").start();
}
diff --git a/src/com/platform/entities/VolumeEntity.java b/src/com/platform/entities/VolumeEntity.java
index 450b7154..b562e9c1 100644
--- a/src/com/platform/entities/VolumeEntity.java
+++ b/src/com/platform/entities/VolumeEntity.java
@@ -37,7 +37,7 @@ public class VolumeEntity {
private String path;
/** * exist,正常返回状态Started,Stopped,Created */
- private String status;
+ private boolean status;
private String type;
@@ -103,17 +103,18 @@ public class VolumeEntity {
this.path = path;
}
+
/**
* @return the status
*/
- public String getStatus() {
+ public boolean isStatus() {
return status;
}
/**
* @param status the status to set
*/
- public void setStatus(String status) {
+ public void setStatus(boolean status) {
this.status = status;
}
diff --git a/src/com/platform/glusterfs/ClusterInfo.java b/src/com/platform/glusterfs/ClusterInfo.java
index 47e5919d..3f0eefd3 100644
--- a/src/com/platform/glusterfs/ClusterInfo.java
+++ b/src/com/platform/glusterfs/ClusterInfo.java
@@ -41,7 +41,7 @@ public class ClusterInfo {
public Map showClusterInfo() {
log.info("get cluster info");
Map peerIps = new HashMap();
-
+ peerIps.put(Constant.hostIp, Constant.peerincluster_connected);
List reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(Constant.glusterPeerStatus);
if (reStrings == null) {
log.error("1101 command get result is null");
diff --git a/src/com/platform/service/impl/MySqlServiceImpl.java b/src/com/platform/service/impl/MySqlServiceImpl.java
index 7efaa3f8..5f3d1a44 100644
--- a/src/com/platform/service/impl/MySqlServiceImpl.java
+++ b/src/com/platform/service/impl/MySqlServiceImpl.java
@@ -1,5 +1,6 @@
package com.platform.service.impl;
+import java.sql.Connection;
import java.util.List;
import javax.annotation.Resource;
@@ -8,6 +9,7 @@ import org.springframework.stereotype.Service;
import com.platform.dao.GatherOracleDao;
import com.platform.entities.GatherOracleInfo;
+import com.platform.oracle.OracleConnector;
import com.platform.service.IMySqlService;
@Service(value = "mySqlService")
@@ -37,12 +39,20 @@ public class MySqlServiceImpl implements IMySqlService{
}
public int insertOracle(GatherOracleInfo oracle) throws Exception {
+ //TODO 连接oracle,
int result = gatherOracleDao.insertOracle(oracle);
return result;
}
@Override
public int updateOracle(GatherOracleInfo oracle) throws Exception {
+ int status = 1;
+ Connection conn = null /*OracleConnector.ConnectionBuilder("jdbc:oracle:thin:@" + oracle.getIp() + ":" + oracle.getPort() + ":"
+ + oracle.getDatabaseName(), oracle.getUser(), oracle.getPassword())*/;
+ if (null == conn) {
+ status = 0;
+ }
+ oracle.setStatus(status);
int result;
if (oracle.getId() > 0) {
result = gatherOracleDao.updateOracleById(oracle);
diff --git a/src/com/platform/service/impl/VolumeServiceImpl.java b/src/com/platform/service/impl/VolumeServiceImpl.java
index 3e41d5ee..1884d8c9 100644
--- a/src/com/platform/service/impl/VolumeServiceImpl.java
+++ b/src/com/platform/service/impl/VolumeServiceImpl.java
@@ -55,10 +55,29 @@ public class VolumeServiceImpl implements IVolumeService {
}
boolean isContinue = true;
- //TODO 对比volume信息--原数据没有该volume,则新增volume:
+ // 对比volume信息--原数据没有该volume,则新增volume:
for (VolumeEntity add : addVolumes) {
+ List bristr = new ArrayList();
+ if (null == add.getName() || "".equals(add.getName())) {
+ continue;
+ }
+ if (null == add.getPath() || "".equals(add.getPath())) {
+ continue;
+ }
+ for ( Brick bri : add.getBrick()) {
+ if (null == bri.getIp() || "".equals(bri.getIp())) {
+ continue;
+ }
+ if (null == bri.getPath() || "".equals(bri.getPath())) {
+ continue;
+ }
+ bristr.add(bri.getIp()+":"+bri.getPath());
+ };
+
//创建volume
- volumeService.createVolume(add.getName(), 0, "distributed", add.getBrick(), add.getPath());
+ if (bristr.size() > 0) {
+ volumeService.createVolume(add.getName(), 0, "distributed", bristr, add.getPath());
+ }
//记录volume信息,
VolumeInitEntity volInSql = new VolumeInitEntity();
volInSql.setName(add.getName());
@@ -74,23 +93,27 @@ public class VolumeServiceImpl implements IVolumeService {
Map serverMap = new HashMap();
for (Brick brick : newBricks) {
//IP + path 才 确认唯一的 brick
- newMap.put(brick.getIp() + ":" + brick.getPath(), brick);
+ newMap.put(brick.getIp().trim() + ":" + brick.getPath().trim(), null);
}
for (Brick brick : serverBricks) {
- serverMap.put(brick.getIp() + ":" + brick.getPath(), brick);
+ serverMap.put(brick.getIp().trim() + ":" + brick.getPath().trim(), null);
}
// ----对比volume信息--原数据有该volume,则对比brick信息,确认那几个brick是新增的,那几个brick是待删除的----start
Set newBrickKeys = newMap.keySet();
Set serverBrickKeys = serverMap.keySet();
//新增的Brick的 Keys
- newBrickKeys.removeAll(serverBrickKeys);
List newKeys = new ArrayList();
+ newBrickKeys.removeAll(serverBrickKeys);
newKeys.addAll(newBrickKeys);
// 新增brick s,
if (newKeys.size() > 0) {
volumeService.addBrickVolume(entity.getName(), newKeys, 0, "distributed");
}
//待删除的Brick的 Keys
+ for (Brick brick : newBricks) {
+ //IP + path 才 确认唯一的 brick
+ newMap.put(brick.getIp().trim() + ":" + brick.getPath().trim(), null);
+ }
newBrickKeys = newMap.keySet();
serverBrickKeys.removeAll(newBrickKeys);
List deleteKeys = new ArrayList();
@@ -102,11 +125,11 @@ public class VolumeServiceImpl implements IVolumeService {
// ---对比volume信息--原数据有该volume,则对比brick信息,确认那几个brick是新增的,那几个brick是待删除的----- end
//TODO 查看状态 状态Started,Stopped,Created
- if (!volumeTmp.getStatus().equals(entity.getStatus())) {
- if ("Started".equals(entity.getStatus())) {
+ if (volumeTmp.isStatus() != entity.isStatus()) {
+ if (entity.isStatus()) {
this.start(entity);
}
- else if ("Stopped".equals(entity.getStatus())) {
+ else{
this.stop(entity);
}
}
diff --git a/src/com/platform/utils/CacheTreeData.java b/src/com/platform/utils/CacheTreeData.java
index 742df9a2..18bde5ce 100644
--- a/src/com/platform/utils/CacheTreeData.java
+++ b/src/com/platform/utils/CacheTreeData.java
@@ -16,7 +16,7 @@ public class CacheTreeData {
return folders;
}
- public static void setFolders(List folders) {
+ public synchronized static void setFolders(List folders) {
CacheTreeData.folders = folders;
}
@@ -30,7 +30,7 @@ public class CacheTreeData {
/**
* @param volumeList the volumeList to set
*/
- public static void setVolumeList(List volumeList) {
+ public synchronized static void setVolumeList(List volumeList) {
CacheTreeData.volumeList = volumeList;
}
diff --git a/src/com/platform/utils/ConfigsLoader.java b/src/com/platform/utils/ConfigsLoader.java
index 06ccad04..6976a098 100644
--- a/src/com/platform/utils/ConfigsLoader.java
+++ b/src/com/platform/utils/ConfigsLoader.java
@@ -23,7 +23,7 @@ public class ConfigsLoader implements ServletContextListener {
+ "WEB-INF/config/config.properties";
this.cReader = ConfigPropertyReader.Builder(contextPath);
init();
- new ThreadVolume("").start();
+ new ThreadVolume("ThreadVolume-in-ConfigsLoader").start();
}
public static void init() {
diff --git a/src/com/platform/utils/Constant.java b/src/com/platform/utils/Constant.java
index 8cedabfc..00ccccd4 100644
--- a/src/com/platform/utils/Constant.java
+++ b/src/com/platform/utils/Constant.java
@@ -1,49 +1,49 @@
-
-package com.platform.utils;
-
-
-public class Constant {
- public static String rootUser = "root";
- public static String rootPasswd = "root";
-// public static String hostIp = "192.168.191.23";
- public static String hostIp = "";
- public static int port = 22;
- public static String glusterPeerStatus = "gluster peer status";
- public static String glusterVolumeInfo = "gluster volume info ";
- public static String df = "df -k ";
- public static String peerincluster_connected = "PeerinCluster(Connected)";
- public static String peerincluster_disconnected = "PeerinCluster(Disconnected)";
- public static String peerNotinCluster = "PeerNotinCluster";
- public static String distributed = "distributed";
- public static String replica = "replica";
- public static String stripe = "stripe";
- public static String noVolume = "No volumes present";
- public static String success = "success";
- public static String failed = "failed";
- public static String noSuchFile = "No such file or directory";
- public static GanymedSSH ganymedSSH = null;
- public static String fileGetTreeData = "WebContent\\WEB-INF\\config\\getTreedata.sh";
- public static String AutoMountfile="/gfsAutoMount/AutoRun.sh";
- public static String MountRecord="/gfsAutoMount/mountPoint.record";
- public static String strGetTreeData = "function ergodic(){\n "
- + "for file in \\`ls \\$1\\`\n do\n if [ \"\\$file\" != \"app\" -a -d \\$1\\\"/\\\"\\$file ]\n "
- + "then\n ergodic \\$1\"/\"\\$file\n else\n local path=\\$1\"/\"\\$file\n "
- + "echo \\$path \n fi\n done\n}\n\nIFS=\\$\\'\\n\\' "
- + "#这个必须要,否则会在文件名中有空格时出错\nINIT_PATH=\".\";\nergodic \\$1\n";
-
- /**
- * volume 获取的线程休眠时间
- */
- public final static int moveFileMaxNum = 1;
-
- /**
- * volume 获取的线程休眠时间
- */
- public final static int get_volume_sleep_time = 10000;
-
- /**
- * volume 获取的线程休眠时间
- */
- public final static int update_dataInfo_sleep_time = 1500;
-
-}
+
+package com.platform.utils;
+
+
+public class Constant {
+ public static String rootUser = "root";
+ public static String rootPasswd = "root";
+// public static String hostIp = "192.168.191.23";
+ public static String hostIp = "";
+ public static int port = 22;
+ public static String glusterPeerStatus = "gluster peer status";
+ public static String glusterVolumeInfo = "gluster volume info ";
+ public static String df = "df -k ";
+ public static String peerincluster_connected = "PeerinCluster(Connected)";
+ public static String peerincluster_disconnected = "PeerinCluster(Disconnected)";
+ public static String peerNotinCluster = "PeerNotinCluster";
+ public static String distributed = "distributed";
+ public static String replica = "replica";
+ public static String stripe = "stripe";
+ public static String noVolume = "No volumes present";
+ public static String success = "success";
+ public static String failed = "failed";
+ public static String noSuchFile = "No such file or directory";
+ public static GanymedSSH ganymedSSH = null;
+ public static String fileGetTreeData = "WebContent\\WEB-INF\\config\\getTreedata.sh";
+ public static String AutoMountfile="/gfsAutoMount/AutoRun.sh";
+ public static String MountRecord="/gfsAutoMount/mountPoint.record";
+ public static String strGetTreeData = "function ergodic(){\n "
+ + "for file in \\`ls \\$1\\`\n do\n if [ \"\\$file\" != \"app\" -a -d \\$1\\\"/\\\"\\$file ]\n "
+ + "then\n ergodic \\$1\"/\"\\$file\n else\n local path=\\$1\"/\"\\$file\n "
+ + "echo \\$path \n fi\n done\n}\n\nIFS=\\$\\'\\n\\' "
+ + "#这个必须要,否则会在文件名中有空格时出错\nINIT_PATH=\".\";\nergodic \\$1\n";
+
+ /**
+ * volume 获取的线程休眠时间
+ */
+ public final static int moveFileMaxNum = 1;
+
+ /**
+ * volume 获取的线程休眠时间
+ */
+ public final static int get_volume_sleep_time = 10000;
+
+ /**
+ * volume 获取的线程休眠时间
+ */
+ public final static int update_dataInfo_sleep_time = 1500;
+
+}
diff --git a/src/com/platform/utils/GanymedSSH.java b/src/com/platform/utils/GanymedSSH.java
index 91e05582..a2fa59e3 100644
--- a/src/com/platform/utils/GanymedSSH.java
+++ b/src/com/platform/utils/GanymedSSH.java
@@ -88,7 +88,7 @@ public class GanymedSSH {
new_conn = getOpenedConnection(host, username, password, port);
otherConns.put(host, new_conn);
}
- sess = new_conn.openSession();
+ sess = conn.openSession();
// 执锟斤拷cmd
sess.execCommand(cmd);
} catch (IOException e) {
@@ -109,7 +109,7 @@ public class GanymedSSH {
Session sess = null;
try {
-
+// conn = getOpenedConnection(host, username, password, port);
sess = conn.openSession();
// 执锟斤拷cmd
sess.execCommand(cmd);
@@ -141,7 +141,7 @@ public class GanymedSSH {
}
}
}
- } catch (Exception e) {
+ } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
@@ -164,6 +164,7 @@ public class GanymedSSH {
new_conn = getOpenedConnection(host, username, password, port);
otherConns.put(host, new_conn);
}
+ sess = conn.openSession();
// 执锟斤拷cmd
sess.execCommand(cmd);
diff --git a/src/com/platform/utils/ThreadVolume.java b/src/com/platform/utils/ThreadVolume.java
index ed7cf144..38c33770 100644
--- a/src/com/platform/utils/ThreadVolume.java
+++ b/src/com/platform/utils/ThreadVolume.java
@@ -15,111 +15,49 @@ import com.platform.glusterfs.ClusterInfo;
import com.platform.glusterfs.GetTreeData;
import com.platform.glusterfs.VolumeInfo;
-public class ThreadVolume extends Thread implements Runnable{
-
+public class ThreadVolume extends Thread {
+
/**
* 挂载点路径 -- 暂时无用的
*/
private static String pointPath = "/home";
-
- /** Volume信息查询 */
+
+ /** Volume信息查询 */
private VolumeInfo volumeInfo = new VolumeInfo();
-
+
private ClusterInfo cluster = new ClusterInfo();
-
+
public ThreadVolume() {
// TODO Auto-generated constructor stub
}
-
- public ThreadVolume(String path) {
+
+ public ThreadVolume(String name) {
+ setName(name);
+ }
+
+ public ThreadVolume(String name, String path) {
if (null != path && !"".equals(path.trim())) {
ThreadVolume.pointPath = path;
}
}
-
- /** gfs目录树形展示 */
+
+ /** gfs目录树形展示 */
private GetTreeData gfsTree = new GetTreeData();
-
+
@Override
public void run() {
super.run();
- while(true){
- List folderlist = new ArrayList();
- List volumeList = new ArrayList();
- // brick状态 map集合
- Map brickStatusMap = cluster.showClusterInfo();
-
- //查询 volume name
- List volumeNameList = volumeInfo.showAllVolumeName();
- if (null != volumeNameList) {
- for (String volumeName : volumeNameList) {
- try {
- VolumeEntity volume = new VolumeEntity();
- volume.setName(volumeName);
- List path = volumeInfo.getVolumeMountPoint(volumeName);
- //默认加载第一个路径
- if (null != path && path.size() > 0) {
- volume.setPath(path.get(0));
- }
- volume.setAllSize(volumeInfo.getVolumeAvailableSize(volumeName)+volumeInfo.getVolumeUseSize(volumeName));
- volume.setStatus(volumeInfo.getVolumeStatus(volumeName));
- volume.setUsedSize(volumeInfo.getVolumeUseSize(volumeName));
- volume.setType(volumeInfo.getVolumeType(volumeName));
- //TODO 查询brick--
- //返回 ip:path
- List brickStrs = volumeInfo.getVolumeBricks(volumeName);
- //brick已用大小:
- Map usedSize = volumeInfo.getVolumebricksDataSize(volumeName);
- Map availableSize = volumeInfo.getVolumebricksAvailableSize(volumeName);
-
- List brickList = new ArrayList();
- for (String brickIpPath : brickStrs) {
- Brick b = new Brick();
- String ipAndpath[] = brickIpPath.split(":");
- String brickip = ipAndpath[0];
- String brickpath = ipAndpath[1];
- //iP , path ,
- b.setIp(brickip);
- if(brickStatusMap==null || brickStatusMap.size()==0){
- b.setStatus(false);
- }else if (brickStatusMap.containsKey(brickip)) {
- b.setStatus(true);
- }
- else {
- b.setStatus(false);
- }
- b.setPath(brickpath);
- b.setAvailableSize(availableSize.get(brickIpPath));
- b.setUsedSize(usedSize.get(brickIpPath));
- brickList.add(b);
- }
- volume.setBrick(brickList);
-
-
- //默认加载第一个路径
- if (null != path && path.size() > 0) {
- //装入 folder:
- //查询 每个 volume 下的 folder
- FolderNode foldertmp = gfsTree.getDatas(path.get(0));
- folderlist.add(foldertmp);
- }
- volumeList.add(volume);
- }catch (Exception e) {
- new CustomException(Custom4exception.threadVolume_class_Except,e);
- }
- }
- }
- //TODO 更新folder 目录
- CacheTreeData.setFolders(folderlist);
- CacheTreeData.setVolumeList(volumeList);
- try {
- Thread.sleep(Constant.get_volume_sleep_time);
- } catch (InterruptedException e) {
- new CustomException(Custom4exception.threadVolume_Thread_Except,e);
- }
-
+ while (true) {
+ try {
+ getVolumeMsg();
+ Thread.sleep(Constant.get_volume_sleep_time);
+ } catch (InterruptedException e) {
+ new CustomException(
+ Custom4exception.threadVolume_Thread_Except, e);
+ }
+
}
-
+
}
public static String getPointPath() {
@@ -129,5 +67,88 @@ public class ThreadVolume extends Thread implements Runnable{
public static void setPointPath(String pointPath) {
ThreadVolume.pointPath = pointPath;
}
-
+
+ public void getVolumeMsg() {
+ List folderlist = new ArrayList();
+ List volumeList = new ArrayList();
+ // brick状态 map集合
+ Map brickStatusMap = cluster.showClusterInfo();
+
+ // 查询 volume name
+ List volumeNameList = volumeInfo.showAllVolumeName();
+ if (null != volumeNameList) {
+ for (String volumeName : volumeNameList) {
+ try {
+ VolumeEntity volume = new VolumeEntity();
+ volume.setName(volumeName);
+ List path = volumeInfo
+ .getVolumeMountPoint(volumeName);
+ // 默认加载第一个路径
+ if (null != path && path.size() > 0) {
+ volume.setPath(path.get(0));
+ }
+ volume.setAllSize(volumeInfo
+ .getVolumeAvailableSize(volumeName)
+ + volumeInfo.getVolumeUseSize(volumeName));
+ // 状态Started,Stopped,Created
+ String status = volumeInfo.getVolumeStatus(volumeName);
+ if ("Started".equals(status)) {
+ volume.setStatus(true);
+ } else {
+ volume.setStatus(false);
+ }
+ volume.setUsedSize(volumeInfo.getVolumeUseSize(volumeName));
+ volume.setType(volumeInfo.getVolumeType(volumeName));
+ // TODO 查询brick--
+ // 返回 ip:path
+ List brickStrs = volumeInfo
+ .getVolumeBricks(volumeName);
+ // brick已用大小:
+ Map usedSize = volumeInfo
+ .getVolumebricksDataSize(volumeName);
+ Map availableSize = volumeInfo
+ .getVolumebricksAvailableSize(volumeName);
+
+ List brickList = new ArrayList();
+ for (String brickIpPath : brickStrs) {
+ Brick b = new Brick();
+ String ipAndpath[] = brickIpPath.split(":");
+ String brickip = ipAndpath[0];
+ String brickpath = ipAndpath[1];
+ // iP , path ,
+ b.setIp(brickip);
+ if (brickStatusMap == null
+ || brickStatusMap.size() == 0) {
+ b.setStatus(false);
+ } else if (brickStatusMap.containsKey(brickip)) {
+ b.setStatus(true);
+ } else {
+ b.setStatus(false);
+ }
+ b.setPath(brickpath);
+ b.setAvailableSize(availableSize.get(brickIpPath));
+ b.setUsedSize(usedSize.get(brickIpPath));
+ brickList.add(b);
+ }
+ volume.setBrick(brickList);
+
+ // 默认加载第一个路径
+ if (null != path && path.size() > 0) {
+ // 装入 folder:
+ // 查询 每个 volume 下的 folder
+ FolderNode foldertmp = gfsTree.getDatas(path.get(0));
+ folderlist.add(foldertmp);
+ }
+ volumeList.add(volume);
+ } catch (Exception e) {
+ new CustomException(
+ Custom4exception.threadVolume_class_Except, e);
+ }
+ }
+ }
+ // TODO 更新folder 目录
+ CacheTreeData.setFolders(folderlist);
+ CacheTreeData.setVolumeList(volumeList);
+ }
+
}
diff --git a/src/com/platform/utils/ThreadVolumeImm.java b/src/com/platform/utils/ThreadVolumeImm.java
new file mode 100644
index 00000000..beaa5613
--- /dev/null
+++ b/src/com/platform/utils/ThreadVolumeImm.java
@@ -0,0 +1,18 @@
+package com.platform.utils;
+
+public class ThreadVolumeImm extends Thread{
+
+ public ThreadVolumeImm() {
+ // TODO Auto-generated constructor stub
+ }
+
+ public ThreadVolumeImm(String name) {
+ setName(name);
+ }
+
+ @Override
+ public void run() {
+ new ThreadVolume().getVolumeMsg();
+ }
+
+}