Merge branch 'web_backend_develope' of https://git.trustie.net/fhx569287825/aggregation-platform into web_backend_develope

web_backend_develope
lily 9 years ago
commit 4002c4d74d

@ -3,8 +3,17 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v7.0"/>
<classpathentry kind="con" path="com.genuitec.runtime.library/com.genuitec.generic_6.0">
<attributes>
<attribute name="owner.project.facets" value="jst.web"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="build/classes"/>
</classpath>

@ -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();
}

@ -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;
}

@ -41,7 +41,7 @@ public class ClusterInfo {
public Map<String, String> showClusterInfo() {
log.info("get cluster info");
Map<String, String> peerIps = new HashMap<String, String>();
peerIps.put(Constant.hostIp, Constant.peerincluster_connected);
List<String> reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(Constant.glusterPeerStatus);
if (reStrings == null) {
log.error("1101 command get result is null");

@ -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);

@ -55,10 +55,29 @@ public class VolumeServiceImpl implements IVolumeService {
}
boolean isContinue = true;
//TODO 对比volume信息--原数据没有该volume则新增volume:
// 对比volume信息--原数据没有该volume则新增volume:
for (VolumeEntity add : addVolumes) {
List<String> bristr = new ArrayList<String>();
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<String, Brick> serverMap = new HashMap<String, Brick>();
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<String> newBrickKeys = newMap.keySet();
Set<String> serverBrickKeys = serverMap.keySet();
//新增的Brick的 Keys
newBrickKeys.removeAll(serverBrickKeys);
List<String> newKeys = new ArrayList<String>();
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<String> deleteKeys = new ArrayList<String>();
@ -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);
}
}

@ -16,7 +16,7 @@ public class CacheTreeData {
return folders;
}
public static void setFolders(List<FolderNode> folders) {
public synchronized static void setFolders(List<FolderNode> folders) {
CacheTreeData.folders = folders;
}
@ -30,7 +30,7 @@ public class CacheTreeData {
/**
* @param volumeList the volumeList to set
*/
public static void setVolumeList(List<VolumeEntity> volumeList) {
public synchronized static void setVolumeList(List<VolumeEntity> volumeList) {
CacheTreeData.volumeList = volumeList;
}

@ -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() {

@ -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;
}

@ -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);

@ -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<FolderNode> folderlist = new ArrayList<FolderNode>();
List<VolumeEntity> volumeList = new ArrayList<VolumeEntity>();
// brick状态 map集合
Map<String, String> brickStatusMap = cluster.showClusterInfo();
//查询 volume name
List<String> volumeNameList = volumeInfo.showAllVolumeName();
if (null != volumeNameList) {
for (String volumeName : volumeNameList) {
try {
VolumeEntity volume = new VolumeEntity();
volume.setName(volumeName);
List<String> 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<String> brickStrs = volumeInfo.getVolumeBricks(volumeName);
//brick已用大小
Map<String, Double> usedSize = volumeInfo.getVolumebricksDataSize(volumeName);
Map<String, Double> availableSize = volumeInfo.getVolumebricksAvailableSize(volumeName);
List<Brick> brickList = new ArrayList<Brick>();
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<FolderNode> folderlist = new ArrayList<FolderNode>();
List<VolumeEntity> volumeList = new ArrayList<VolumeEntity>();
// brick状态 map集合
Map<String, String> brickStatusMap = cluster.showClusterInfo();
// 查询 volume name
List<String> volumeNameList = volumeInfo.showAllVolumeName();
if (null != volumeNameList) {
for (String volumeName : volumeNameList) {
try {
VolumeEntity volume = new VolumeEntity();
volume.setName(volumeName);
List<String> 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<String> brickStrs = volumeInfo
.getVolumeBricks(volumeName);
// brick已用大小
Map<String, Double> usedSize = volumeInfo
.getVolumebricksDataSize(volumeName);
Map<String, Double> availableSize = volumeInfo
.getVolumebricksAvailableSize(volumeName);
List<Brick> brickList = new ArrayList<Brick>();
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);
}
}

@ -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();
}
}
Loading…
Cancel
Save