修复启动oracle服务,测试连接oracle的Bub

web_backend_develope
wu ming 9 years ago
commit 608e658d3a

@ -2,11 +2,6 @@
<classpath> <classpath>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/> <classpathentry kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/Java">
<attributes>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v7.0"> <classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v7.0">
<attributes> <attributes>
<attribute name="owner.project.facets" value="jst.web"/> <attribute name="owner.project.facets" value="jst.web"/>
@ -14,5 +9,6 @@
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/> <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/> <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/Java"/>
<classpathentry kind="output" path="build/classes"/> <classpathentry kind="output" path="build/classes"/>
</classpath> </classpath>

@ -4,7 +4,7 @@
# 驱动程序 # 驱动程序
jdbc.mysql.driver=com.mysql.jdbc.Driver jdbc.mysql.driver=com.mysql.jdbc.Driver
# 连接url # 连接url
jdbc.mysql.url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true jdbc.mysql.url=jdbc:mysql://192.168.0.101:3306/test?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true
# 用户名 # 用户名
jdbc.mysql.username=root jdbc.mysql.username=root
# 密码 # 密码

@ -21,6 +21,7 @@
<url-pattern>/*</url-pattern> <url-pattern>/*</url-pattern>
</filter-mapping> </filter-mapping>
<!-- spring配置文件 --> <!-- spring配置文件 -->
<context-param> <context-param>
<param-name>contextConfigLocation</param-name> <param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/config/spring-applicationContext.xml</param-value> <param-value>WEB-INF/config/spring-applicationContext.xml</param-value>
@ -46,7 +47,7 @@
</servlet> </servlet>
<servlet-mapping> <servlet-mapping>
<servlet-name>springmvc</servlet-name> <servlet-name>springmvc</servlet-name>
<url-pattern>/*</url-pattern> <url-pattern>/</url-pattern>
</servlet-mapping> </servlet-mapping>
<!-- log4j配置文件 --> <!-- log4j配置文件 -->
@ -59,7 +60,7 @@
</listener> </listener>
<!-- 防止Spring内存溢出监听器 --> <!-- 防止Spring内存溢出监听器 -->
<listener> <!-- <listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class> <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener> </listener> -->
</web-app> </web-app>

@ -0,0 +1,151 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
"http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">
<mapper namespace="com.platform.dao.DataInfoMoveTmpDao">
<resultMap id="getEntityByText" type="com.platform.entities.DataInfoEntityMoveTmp">
<id property="id" column="id" javaType="int" jdbcType="INTEGER" />
<result property="regionalismCode" column="regionalism_code"
javaType="string" jdbcType="VARCHAR" />
<result property="cityName" column="city_name" javaType="string"
jdbcType="VARCHAR" />
<result property="districtName" column="district_name"
javaType="string" jdbcType="VARCHAR" />
<result property="systemCode" column="system_code" javaType="int"
jdbcType="INTEGER" />
<result property="systemName" column="system_name" javaType="string"
jdbcType="VARCHAR" />
<result property="dataType" column="data_type" javaType="string"
jdbcType="VARCHAR" />
<result property="dataVersion" column="data_version" javaType="int"
jdbcType="INTEGER" />
<result property="submittedBatch" column="submitted_batch"
javaType="string" jdbcType="VARCHAR" />
<result property="dataPath" column="data_path" javaType="string"
jdbcType="VARCHAR" />
<result property="charset" column="data_charset" javaType="string"
jdbcType="VARCHAR" />
<result property="collectingTime" column="collection_time"
javaType="string" jdbcType="DATE" />
<result property="collectorContacts" column="collector_contacts"
javaType="string" jdbcType="VARCHAR" />
<result property="collectorName" column="collector_name"
javaType="string" jdbcType="VARCHAR" />
<result property="year" column="data_year" javaType="string"
jdbcType="VARCHAR" />
<result property="dstPath" column="dst_path" javaType="string"
jdbcType="VARCHAR" />
<result property="completeStatus" column="complete_status" javaType="string"
jdbcType="VARCHAR" />
<result property="rate" column="rate" javaType="int"
jdbcType="INTEGER" />
</resultMap>
<!-- 获取数据全部记录信息 -->
<select id="findAll" parameterType="" resultMap="getEntityByText">
SELECT
a.id,a.regionalism_code,b.city_name,b.district_name, a.system_code,b.system_name,b.data_type,b.data_version,b.submitted_batch,
b.data_path,b.data_charset,b.collection_time,b.collector_name,b.collector_contacts,b.data_year,a.dst_path,a.complete_status,a.rate
FROM
move_data_tmp a LEFT JOIN data_details b
ON a.system_code = b.system_code AND a.regionalism_code = b.regionalism_code;
</select>
<update id="update" parameterType="com.platform.entities.DataInfoEntityMoveTmp">
UPDATE
move_data_tmp
<set >
<trim suffixOverrides=",">
<if test="regionalismCode != null and regionalismCode != ''">
regionalism_code = #{regionalismCode},
</if>
<if test="systemCode != null and systemCode != ''">
system_code= #{systemCode},
</if>
<if test="dstPath != null and dstPath != ''">
dst_path= #{dstPath},
</if>
<if test="completeStatus != null and completeStatus != ''">
complete_status= #{completeStatus},
</if>
rate= #{rate}
</trim>
</set>
<where>
id = #{id}
</where>
</update>
<insert id="save" parameterType="">
INSERT INTO
move_data_tmp(
<trim suffixOverrides=",">
<if test="id > 0">
id,
</if>
<if test="regionalismCode != null and regionalismCode != ''">
regionalism_code,
</if>
<if test="systemCode != null and systemCode != ''">
system_code,
</if>
<if test="dstPath != null and dstPath != ''">
dst_path,
</if>
<if test="completeStatus != null and completeStatus != ''">
complete_status,
</if>
rate
</trim>
)
VALUES(
<trim suffixOverrides=",">
<if test="id > 0">
id,
</if>
<if test="regionalismCode != null and regionalismCode != ''">
#{regionalismCode},
</if>
<if test="systemCode != null and systemCode != ''">
#{systemCode},
</if>
<if test="dstPath != null and dstPath != ''">
#{dstPath},
</if>
<if test="completeStatus != null and completeStatus != ''">
#{completeStatus},
</if>
#{rate}
</trim>
)
</insert>
<delete id="remove" parameterType="java.lang.INTEGER">
DELETE FROM
move_data_tmp
WHERE
id = #{id}
</delete>
<!-- 获取数据符合筛选条件的总记录条数 -->
<select id="getLimitedDataCount" resultType="java.lang.Integer"
parameterType="PagerOptions">
SELECT COUNT(id) FROM move_data_tmp
<if test="PagerOptions!=null">
<where>
<include refid="conditionsFilters" />
</where>
</if>
</select>
<!-- 获取数据查询的起始di -->
<select id="getLimitedBeginId" resultType="java.lang.Integer"
parameterType="PagerOptions">
SELECT MAX(idx) FROM (SELECT id idx FROM move_data_tmp
ORDER BY id LIMIT 0,#{PagerOptions.totalLimit}) AS TEMP
</select>
</mapper>

@ -58,7 +58,7 @@ public class DataModelController extends BaseController{
Map<String, String[]> paramMap = res.getParameterMap(); Map<String, String[]> paramMap = res.getParameterMap();
Set<String> keySet = paramMap.keySet(); Set<String> keySet = paramMap.keySet();
Map<String, String> params = new HashMap<String, String>(); Map<String, String> params = new HashMap<String, String>();
StringBuffer sb = new StringBuffer().append("锟斤拷前锟斤拷锟斤拷锟斤拷锟斤拷锟<EFBFBD>:{"); StringBuffer sb = new StringBuffer().append("<EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:{");
for (String str : keySet) { for (String str : keySet) {
String value = paramMap.get(str)[0]; String value = paramMap.get(str)[0];
if (StringUtils.isNotEmpty(value)) { if (StringUtils.isNotEmpty(value)) {
@ -89,7 +89,7 @@ public class DataModelController extends BaseController{
String[] oraclesName = paramMap.get("oracleName"); String[] oraclesName = paramMap.get("oracleName");
if (oraclesName != null) if (oraclesName != null)
for (String rcName : oraclesName) { for (String rcName : oraclesName) {
Configs.CONSOLE_LOGGER.info("杩炴帴鎴愬姛\t" + rcName); Configs.CONSOLE_LOGGER.info("连接成功\t" + rcName);
new OracleStatusService().connectToOracle(rcName); new OracleStatusService().connectToOracle(rcName);
} }
} }
@ -102,19 +102,20 @@ public class DataModelController extends BaseController{
String operate = paramMap.get("operation")[0]; String operate = paramMap.get("operation")[0];
if (null != oraclesName) { if (null != oraclesName) {
for (String rcName : oraclesName) { for (String rcName : oraclesName) {
Configs.CONSOLE_LOGGER.info("杩炴帴鎴愬姛:\t" + rcName); Configs.CONSOLE_LOGGER.info("连接成功:\t" + rcName);
new OracleStatusService().cancelToOracle(rcName, operate); new OracleStatusService().cancelToOracle(rcName, operate);
} }
} }
} }
@SuppressWarnings({ "unchecked", "unused", "rawtypes" })
@RequestMapping("/oracle/{name}/extract") @RequestMapping("/oracle/{name}/extract")
public void extractOracleData(HttpServletRequest res, public void extractOracleData(HttpServletRequest res,
HttpServletResponse req, String name) throws Exception { HttpServletResponse req, String name) throws Exception {
System.out.println("------extract-------"); System.out.println("------extract-------");
System.out.println(name); System.out.println(name);
Map<String, String[]> paramMap = res.getParameterMap(); Map<String, String[]> paramMap = res.getParameterMap();
//姹囨<EFBFBD>诲簱 瀵硅薄淇℃伅--甯︽湁tableName- //汇总库 对象信息--带有tableName-
String[] nodes = paramMap.get("target"); String[] nodes = paramMap.get("target");
Map map = null; Map map = null;
for (String string : nodes) { for (String string : nodes) {
@ -123,7 +124,7 @@ public class DataModelController extends BaseController{
System.out.println(map); System.out.println(map);
} }
// 閲囬泦搴撳璞<EFBFBD>--(澶氫釜閲囬泦搴撴娊鍙栧埌1涓眹鎬诲簱鐨<E7B0B1>1涓猼ableName涓<65>) // 采集库对象--(多个采集库抽取到1个汇总库的1个tableName下)
String[] inneed = paramMap.get("inneed"); String[] inneed = paramMap.get("inneed");
List<Map<String, String>> colleclist = new ArrayList<Map<String,String>>(); List<Map<String, String>> colleclist = new ArrayList<Map<String,String>>();
for (String string : nodes) { for (String string : nodes) {
@ -148,6 +149,7 @@ public class DataModelController extends BaseController{
return result; return result;
} }
@SuppressWarnings("rawtypes")
@RequestMapping(value = "/volume/{name}/move", method= RequestMethod.POST) @RequestMapping(value = "/volume/{name}/move", method= RequestMethod.POST)
@ResponseBody @ResponseBody
public Object move(HttpServletRequest res, HttpServletResponse req, String name, public Object move(HttpServletRequest res, HttpServletResponse req, String name,
@ -176,7 +178,7 @@ public class DataModelController extends BaseController{
System.out.println(nodes); System.out.println(nodes);
System.out.println(selectItems); System.out.println(selectItems);
System.out.println("--------------"); System.out.println("--------------");
int result = gfsService.copyFolder(listItemPath, (String)map.get("name"), "app"); int result = gfsService.copyFolder(listItemPath, (String)map.get("path"), "app");
return result; return result;
} }
@ -216,13 +218,4 @@ public class DataModelController extends BaseController{
mySqlService.updateOracle(oracle); mySqlService.updateOracle(oracle);
System.out.println("----------updateOracleInfo-----------------------"); System.out.println("----------updateOracleInfo-----------------------");
} }
@RequestMapping("/oracle/delete/")
public void deleteOracleInfo(HttpServletRequest res,
HttpServletResponse req){
Map<String, String[]> paramMap = res.getParameterMap();
String[] oraclesName = paramMap.get("param");
for(String str: oraclesName)
System.out.println(str);
}
} }

@ -0,0 +1,28 @@
package com.platform.controller;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.base.BaseController;
@Controller
public class TaskModelController extends BaseController{
@RequestMapping("/task/transfer/list")
@ResponseBody
public List<Integer> getTransferTask(HttpServletRequest res, HttpServletResponse req) {
List<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(2);
list.add(3);
list.add(4);
return list;
}
}

@ -0,0 +1,28 @@
package com.platform.dao;
import java.util.List;
import org.springframework.stereotype.Repository;
import com.platform.entities.DataInfoEntityMoveTmp;
/**
* @author chen
*
*/
@Repository(value = "dataInfoMoveTmpDao")
public interface DataInfoMoveTmpDao {
/**
* @return
* @throws Exception
*/
List<DataInfoEntityMoveTmp> findAll() throws Exception;
int update(DataInfoEntityMoveTmp data) throws Exception;
int save(DataInfoEntityMoveTmp data) throws Exception;
int remove(DataInfoEntityMoveTmp data) throws Exception;
}

@ -1,58 +1,93 @@
/** /**
* : Brick.java * : Brick.java
* : </> * : </>
* : <> * : <>
* @author chen * @author chen
* : <> * : <>
* 201699 * 201699
* <> * <>
*/ */
package com.platform.entities; package com.platform.entities;
/** /**
* <> volume * <> volume
* <> * <>
* @author chen * @author chen
* @version [201699] * @version [201699]
* @see [/] * @see [/]
* @since [/] * @since [/]
*/ */
public class Brick { public class Brick {
/** ip */ /** volume总大小 */
private String ip; private double availableSize;
/** 路径 */ /** volume已使用大小 */
private String path; private double usedSize;
/** /** ip */
* @return the ip private String ip;
*/
public String getIp() { /** 路径 */
return ip; private String path;
}
/**
/** * @return the availableSize
* @param ip the ip to set */
*/ public double getAvailableSize() {
public void setIp(String ip) { return availableSize;
this.ip = ip; }
}
/**
/** * @param availableSize the availableSize to set
* @return the path */
*/ public void setAvailableSize(double availableSize) {
public String getPath() { this.availableSize = availableSize;
return path; }
}
/**
/** * @return the usedSize
* @param path the path to set */
*/ public double getUsedSize() {
public void setPath(String path) { return usedSize;
this.path = path; }
}
/**
} * @param usedSize the usedSize to set
*/
public void setUsedSize(double usedSize) {
this.usedSize = usedSize;
}
/**
* @return the ip
*/
public String getIp() {
return ip;
}
/**
* @param ip the ip to set
*/
public void setIp(String ip) {
this.ip = ip;
}
/**
* @return the path
*/
public String getPath() {
return path;
}
/**
* @param path the path to set
*/
public void setPath(String path) {
this.path = path;
}
}

@ -0,0 +1,54 @@
package com.platform.entities;
public class DataInfoEntityMoveTmp extends DataInfoEntity {
private String dstPath;
private String completeStatus;
private int rate;
/**
* @return the dstPath
*/
public String getDstPath() {
return dstPath;
}
/**
* @param dstPath the dstPath to set
*/
public void setDstPath(String dstPath) {
this.dstPath = dstPath;
}
/**
* @return the completeStatus
*/
public String getCompleteStatus() {
return completeStatus;
}
/**
* @param completeStatus the completeStatus to set
*/
public void setCompleteStatus(String completeStatus) {
this.completeStatus = completeStatus;
}
/**
* @return the rate
*/
public int getRate() {
return rate;
}
/**
* @param rate the rate to set
*/
public void setRate(int rate) {
this.rate = rate;
}
}

@ -1,86 +1,110 @@
package com.platform.glusterfs; package com.platform.glusterfs;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator; import org.apache.log4j.PropertyConfigurator;
import com.platform.utils.Constant; import com.platform.utils.Constant;
public class ClusterInfo { /**
public static Logger log = Logger.getLogger(ClusterInfo.class); *
* nullmapipip
public Map<String, String> showClusterInfo() { * ipPeerinCluster(Connected)
log.info("get cluster info"); * ipPeerinCluster(Disconnected)
Map<String, String> peerIps = new HashMap<String, String>(); * @author liliy
* @version [2016912]
/* * @see [/]
String command = "echo \"" + Constant.rootPasswd + "\"|sudo -S gluster peer status"; * @since [/]
RunCommand runCommand = new RunCommand(); */
List<String> reStrings = runCommand.runCommandWait(command); public class ClusterInfo {
*/ public static Logger log = Logger.getLogger(ClusterInfo.class);
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, Constant.port, Constant.glusterPeerStatus);
if (reStrings == null) { public Map<String, String> showClusterInfo() {
log.error("1101 command get result is null"); log.info("get cluster info");
return null; Map<String, String> peerIps = new HashMap<String, String>();
}
if (reStrings.size() == 0) { List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, Constant.port, Constant.glusterPeerStatus);
log.error("1102 command get result is nothing"); if (reStrings == null) {
return null; log.error("1101 command get result is null");
} return null;
}
if (!(reStrings.get(0).split(":")[0].contains("Number of Peers"))) { if (reStrings.size() == 0) {
log.error("1102 command get result is nothing");
log.error("1103 get result string wrong"); return null;
return null; }
}
if (!(reStrings.get(0).split(":")[0].contains("Number of Peers"))) {
// System.out.print(reStrings.get(0)); log.error("1103 get result string wrong");
return null;
int flag = 0; }
String ipString = "";
String state = "";
for (Iterator it2 = reStrings.iterator(); it2.hasNext();) { // System.out.print(reStrings.get(0));
String line = (String) it2.next();
line=line.replaceAll(" +", " "); int flag = 0;
String keyValue[] = line.split(":"); String ipString = "";
if (keyValue[0].equals("Hostname")) { String state = "";
for (Iterator it2 = reStrings.iterator(); it2.hasNext();) {
if (keyValue.length < 2) { String line = (String) it2.next();
log.error("1105 command get result is wrong"); line=line.replaceAll(" +", " ");
continue; String keyValue[] = line.split(":");
} if (keyValue[0].equals("Hostname")) {
ipString = keyValue[1].replaceAll(" ", ""); if (keyValue.length < 2) {
flag = 1; log.error("1105 command get result is wrong");
} else if (flag == 1 && keyValue[0].equals("State")) { continue;
}
if (keyValue.length < 2) {
log.error("1106 command get result is wrong"); ipString = keyValue[1].replaceAll(" ", "");
continue; flag = 1;
} } else if (flag == 1 && keyValue[0].equals("State")) {
state = keyValue[1].replaceAll(" ", ""); if (keyValue.length < 2) {
flag = 0; log.error("1106 command get result is wrong");
peerIps.put(ipString, state); continue;
} }
} state = keyValue[1].replaceAll(" ", "");
return peerIps; flag = 0;
} peerIps.put(ipString, state);
}
}
public static void main(String[] args) { return peerIps;
PropertyConfigurator.configure("log4j.properties"); }
System.out.println(new ClusterInfo().showClusterInfo());
} /**
} * ipip
* ipnull
* ipPeerinCluster(Connected)
* ipPeerinCluster(Disconnected)
* @param peerip
* @return
* @see [##]
*/
public String getPeerStatus(String peerip){
Map<String, String> peerIps=showClusterInfo();
if(peerIps==null || peerIps.size()==0){
return null;
}
if(!peerIps.containsKey(peerip)){
return Constant.peerincluster_disconnected;
}
return peerIps.get(peerip);
}
public static void main(String[] args) {
PropertyConfigurator.configure("log4j.properties");
System.out.println(new ClusterInfo().showClusterInfo());
}
}

@ -1,80 +1,120 @@
package com.platform.glusterfs; package com.platform.glusterfs;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.log4j.PropertyConfigurator; import org.junit.Test;
import org.junit.Test;
import org.springframework.stereotype.Service; import com.platform.entities.FolderNode;
import com.platform.utils.Constant;
import com.platform.entities.FolderNode; import com.platform.utils.FileOperateHelper;
/** /**
* <> GFS * <> GFS
* <> * <>
* @author chen * @author chen
* @version [201698] * @version [201698]
* @see [/] * @see [/]
* @since [/] * @since [/]
*/ */
public class GetTreeData { public class GetTreeData {
ShowData showData = new ShowData(); ShowData showData = new ShowData();
/** /**
* <> * <>
* <> * <>
* @param name * @param name
* @return * @return
* @see [##] * @see [##]
*/ */
public FolderNode getDatas(String name) { public FolderNode getDatas(String name) {
FolderNode fileNode = new FolderNode(name); String names[]=name.split("/");
Map<String, String> files = showData.showFolderData(name); String only_name=names[names.length-1];
if(files==null || files.size()==0){ FolderNode fileNode = new FolderNode(only_name);
return fileNode; fileNode.setPath(name);
} Map<String, String> files = showData.showFolderData(name);
fileNode.setIsFolder(files.size()); if(files==null || files.size()==0){
List<FolderNode> list = new ArrayList<FolderNode>(); return fileNode;
fileNode.setChildNodes(list); }
for (Map.Entry<String, String> entry : files.entrySet()) { fileNode.setIsFolder(files.size());
int number = Integer.parseInt(entry.getValue()); List<FolderNode> list = new ArrayList<FolderNode>();
if ("app".equals(entry.getKey())) { fileNode.setChildNodes(list);
continue; for (Map.Entry<String, String> entry : files.entrySet()) {
} if(entry.getKey().equals("app")){
if (number == 1) { continue;
fileNode.getChildNodes().add(new FolderNode(entry.getKey(), number)); }
} int number = Integer.parseInt(entry.getValue());
if (number > 1) { if (number == 1) {
FolderNode temp=getDatas(name+"/"+entry.getKey()); fileNode.getChildNodes().add(new FolderNode(entry.getKey(), number));
fileNode.getChildNodes().add(temp); }
} if (number > 1) {
} FolderNode temp=getDatas(name+"/"+entry.getKey());
fileNode.getChildNodes().add(temp);
return fileNode; }
} }
// public static void main(String[] args) { return fileNode;
// GetTreeData getTreeData=new GetTreeData(); }
// FileOrFolder fileOrFolder=getTreeData.getDatas("/home");
// System.out.println(fileOrFolder); /**
// } * <>
} * <>
* @param name
//class FileOrFolder { * @return
// String name; * @see [##]
// int isFolder; // 1 is file and other integer is folder show children number */
// List<FileOrFolder> children; public FolderNode getDatasWithShell(String name) {
// if(name.endsWith("/")){
// public FileOrFolder(String name) { name=name.substring(0, name.length());
// // TODO Auto-generated constructor stub }
// this.name = name; String names[]=name.split("/");
// } String only_name=names[names.length-1];
// FolderNode fileNode = new FolderNode(name);
// public FileOrFolder(String name, int isFolder) { fileNode.setPath(name);
// // TODO Auto-generated constructor stub
// this.name = name; String shellComment=new FileOperateHelper().fileReaderAndendline(Constant.fileGetTreeData);
// this.isFolder = isFolder; String sh_path="/getTreedata.sh";
// } String cmd="echo -e "+shellComment+" > "+sh_path+" & chmod +x "+sh_path;
//} Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
// Map<String, String> files = showData.showFolderData(name);
List<String> files=Constant.ganymedSSH.execCmdWaitAcquiescent(sh_path+" "+name);
if(files==null){
return null;
}
if(files.size()==0){
return fileNode;
}
for(String file:files){
}
return fileNode;
}
@Test
public void test_getTreeData() {
GetTreeData getTreeData=new GetTreeData();
FolderNode fileOrFolder=getTreeData.getDatas("/home");
System.out.println(fileOrFolder);
}
}
/*
class FileOrFolder {
String name;
int isFolder; // 1 is file and other integer is folder show children number
List<FileOrFolder> children;
public FileOrFolder(String name) {
// TODO Auto-generated constructor stub
this.name = name;
}
public FileOrFolder(String name, int isFolder) {
// TODO Auto-generated constructor stub
this.name = name;
this.isFolder = isFolder;
}
}
*/

@ -1,5 +1,11 @@
package com.platform.glusterfs; package com.platform.glusterfs;
public class SetCluster { import org.apache.log4j.Logger;
} public class SetCluster {
public static Logger log = Logger.getLogger ( SetCluster.class);
public int addPeer(String peerip){
return 0;
}
}

@ -1,493 +1,498 @@
/** /**
* @author * @author
* volumevolumevolumebrick * volumevolumevolumebrick
*/ */
package com.platform.glusterfs; package com.platform.glusterfs;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator; import org.apache.log4j.PropertyConfigurator;
import com.platform.utils.Constant; import com.platform.utils.Constant;
public class SetVolume { public class SetVolume {
public static Logger log = Logger.getLogger(SetVolume.class); public static Logger log = Logger.getLogger(SetVolume.class);
/* /*
* volume 1 * volume 1
* *
*/ */
public int createVolume(String volumeName, int count, String type, List bricks, String mountPoint) { public int createVolume(String volumeName, int count, String type, List bricks, String mountPoint) {
log.info("Creat new volume"); log.info("Creat new volume");
// 判断创建volume的条件是否满足 // 判断创建volume的条件是否满足
int able = isAbleCreateVolume(volumeName, count, type, bricks, mountPoint); int able = isAbleCreateVolume(volumeName, count, type, bricks, mountPoint);
if (able == 1) { if (able == 1) {
String command = null; String command = null;
// 将brics从List变量中提取出来并连接成可以在命令行中使用的格式 // 将brics从List变量中提取出来并连接成可以在命令行中使用的格式
String commandarg = concat(bricks); String commandarg = concat(bricks);
/* /*
* verify the type * verify the type
*/ */
if (type.equals(Constant.distributed)) { if (type.equals(Constant.distributed)) {
command = "gluster volume create " + volumeName + " " + commandarg + "force"; command = "gluster volume create " + volumeName + " " + commandarg + "force";
} else if (type.equals(Constant.replica) || type.equals(Constant.stripe)) { } else if (type.equals(Constant.replica) || type.equals(Constant.stripe)) {
command = "gluster volume create " + volumeName + " " + type + " " + count + " " + commandarg + "force"; command = "gluster volume create " + volumeName + " " + type + " " + count + " " + commandarg + "force";
} }
// 执行命令 // 执行命令
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd,
Constant.port, command); Constant.port, command);
// 创建成功时返回信息格式volume create: volumename success: // 创建成功时返回信息格式volume create: volumename success:
if (reStrings == null || reStrings.size() == 0) { if (reStrings == null || reStrings.size() == 0) {
log.error("3106 " + command + " run return error"); log.error("3106 " + command + " run return error");
return -7; return -7;
} }
if (reStrings.get(0).contains("volume create: " + volumeName + ": " + "success:")) { if (reStrings.get(0).contains("volume create: " + volumeName + ": " + "success:")) {
log.info("create volume "+volumeName+" successed!"); log.info("create volume "+volumeName+" successed!");
// 创建成功则启动并进行挂载 // 创建成功则启动并进行挂载
if (startVolume(volumeName) == 0) { if (startVolume(volumeName) == 0) {
log.info("start volume "+volumeName+" successed!"); log.info("start volume "+volumeName+" successed!");
if ((new ShowData().showFolderData(mountPoint)) == null) { if ((new ShowData().showFolderData(mountPoint)) == null) {
Constant.ganymedSSH.execCmdWaitAcquiescent("mkdir " + mountPoint); Constant.ganymedSSH.execCmdWaitAcquiescent("mkdir " + mountPoint);
} }
// 进行挂载 // 进行挂载
String command3 = "mount -t glusterfs " + Constant.hostIp + ":/" + volumeName + " " + mountPoint; String command3 = "mount -t glusterfs " + Constant.hostIp + ":/" + volumeName + " " + mountPoint;
List<String> reStrings3 = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, List<String> reStrings3 = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser,
Constant.rootPasswd, Constant.port, command3); Constant.rootPasswd, Constant.port, command3);
// 这里需要添加解析挂载命令返回字符串的语句由于我的系统有问题导致挂载成功后返回WARNING: getfattr // 这里需要添加解析挂载命令返回字符串的语句由于我的系统有问题导致挂载成功后返回WARNING: getfattr
// not found, certain checks will be skipped.. // not found, certain checks will be skipped..
// 所以这句代码未经测试 // 所以这句代码未经测试
// 成功挂载时没有任何返回信息 // 成功挂载时没有任何返回信息
if (reStrings3.size() == 0 || reStrings.get(0).contains("GlusterFS is already mounted")) if (reStrings3.size() == 0 || reStrings.get(0).contains("GlusterFS is already mounted"))
{ {
log.info("mount point successed!"); log.info("mount point successed!");
return 1; return 1;
} }
} }
} else { } else {
log.error("3104 volume create failed with error" + reStrings.get(0)); log.error("3104 volume create failed with error" + reStrings.get(0));
// System.out.println(reStrings.get(0)); // System.out.println(reStrings.get(0));
return -7; return -7;
} }
return 1; return 1;
} else { } else {
log.error("给出的参数不满足创建条件"); log.error("给出的参数不满足创建条件");
// System.out.println("给出的参数不满足创建条件"); // System.out.println("给出的参数不满足创建条件");
return able; return able;
} }
} }
/** /**
* volume * volume
* *
* @param volumeName * @param volumeName
* @return 1 -1volume name-2volume * @return 1 -1volume name-2volume
*/ */
public int deleteVolume(String volumeName) { public int deleteVolume(String volumeName) {
int status = 0; int status = 0;
List<String> volumeNames = new VolumeInfo().showAllVolumeName(); List<String> volumeNames = new VolumeInfo().showAllVolumeName();
if (!volumeNames.contains(volumeName)) { if (!volumeNames.contains(volumeName)) {
log.error("3801 " + volumeName + " is not exists !"); log.error("3801 " + volumeName + " is not exists !");
return -1; return -1;
} }
String mountPoint = new VolumeInfo().getVolumeMountPoint(volumeName); List<String> mountPoints = new VolumeInfo().getVolumeMountPoint(volumeName);
if (stopVolume(volumeName) != 0) { if (stopVolume(volumeName) != 0) {
log.error("3802 " + volumeName + " stop failed !"); log.error("3802 " + volumeName + " stop failed !");
return -2; return -2;
} }
log.info("stop "+volumeName+" successed!"); log.info("stop "+volumeName+" successed!");
if (mountPoint != null) { if (null == mountPoints) {
String command = "umount " + mountPoint; return -2;
Constant.ganymedSSH.execCmdNoWaitAcquiescent(command); }
log.info("umount "+mountPoint+" successed!"); for(String mountPoint:mountPoints){
} if (mountPoint != null) {
String command="echo -e \"y\"| gluster volume delete "+volumeName; String command = "umount -l " + mountPoint;
List<String> reStrings=Constant.ganymedSSH.execCmdWaitAcquiescent(command); Constant.ganymedSSH.execCmdNoWaitAcquiescent(command);
if(reStrings==null || reStrings.size()>0 || !(reStrings.get(0).contains("volume delete: "+volumeName+": success"))){ log.info("umount "+mountPoint+" successed!");
log.error("3803 : delete volume "+volumeName+" failed !"); }
return -3; }
} String command="echo -e \"y\"| gluster volume delete "+volumeName;
log.info("delete "+volumeName+" successed!"); List<String> reStrings=Constant.ganymedSSH.execCmdWaitAcquiescent(command);
return 1; if(reStrings==null || reStrings.size()>0 || !(reStrings.get(0).contains("volume delete: "+volumeName+": success"))){
} log.error("3803 : delete volume "+volumeName+" failed !");
return -3;
/* }
* volumebrick, 1 ; log.info("delete "+volumeName+" successed!");
* volumebrickcount return 1;
*/ }
public int addBrickVolume(String volumeName, List<String> brickName, int count, String type) {
// 检查是否满足添加bricks的条件 /*
int able = isAble(volumeName, count, type, brickName); * volumebrick, 1 ;
if (able != 1) { * volumebrickcount
return able; */
} public int addBrickVolume(String volumeName, List<String> brickName, int count, String type) {
// 检查是否满足添加bricks的条件
String command = ""; int able = isAble(volumeName, count, type, brickName);
log.info("add brick to the specified volume"); if (able != 1) {
return able;
String brick = concat(brickName); }
if (type.equals(Constant.distributed)) String command = "";
command = "gluster volume add-brick " + volumeName + " " + brick + "force"; log.info("add brick to the specified volume");
else if (type.equals(Constant.replica))
command = "gluster volume add-brick " + volumeName + " " + "replica " + count + " " + brick + "force"; String brick = concat(brickName);
else if (type.equals(Constant.stripe))
command = "gluster volume add-brick " + volumeName + " " + "stripe " + count + " " + brick + "force"; if (type.equals(Constant.distributed))
command = "gluster volume add-brick " + volumeName + " " + brick + "force";
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, else if (type.equals(Constant.replica))
Constant.port, command); command = "gluster volume add-brick " + volumeName + " " + "replica " + count + " " + brick + "force";
else if (type.equals(Constant.stripe))
// 添加成功的返回信息是volume add-brick: success command = "gluster volume add-brick " + volumeName + " " + "stripe " + count + " " + brick + "force";
if (reStrings != null && reStrings.size() > 0 && reStrings.get(0).contains("volume add-brick: success")) {
log.info("添加brick成功"); List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd,
return 1; Constant.port, command);
} else {
log.error("3205 add brick failed,please check the system"); // 添加成功的返回信息是volume add-brick: success
// System.out.println("3202 add brick failed,please check the system"); if (reStrings != null && reStrings.size() > 0 && reStrings.get(0).contains("volume add-brick: success")) {
return -5; log.info("添加brick成功");
} return 1;
} } else {
log.error("3205 add brick failed,please check the system");
/* // System.out.println("3202 add brick failed,please check the system");
* volumebrick, 1 ; return -5;
* volumebrickcount }
*/ }
public int deleteBrickVolume(String volumeName, List<String> brickName, int count, String type) {
int able = isAble(volumeName, count, type, brickName); /*
* volumebrick, 1 ;
if (able != 1) { * volumebrickcount
return able; */
} public int deleteBrickVolume(String volumeName, List<String> brickName, int count, String type) {
String command = null; int able = isAble(volumeName, count, type, brickName);
log.info("delete brick of the specified volume"); if (able != 1) {
return able;
String brick = concat(brickName); }
String command = null;
if (type.equals(Constant.distributed)) {
command = "echo -e \"y\" | gluster volume remove-brick " + volumeName + " " + brick + " force"; log.info("delete brick of the specified volume");
} else if (type.equals(Constant.replica)) {
command = "echo -e \"y\" | gluster volume remove-brick " + volumeName + " repli " + count + " " + brick String brick = concat(brickName);
+ " force";
} else if (type.equals(Constant.stripe)) { if (type.equals(Constant.distributed)) {
command = "echo -e \"y\" | gluster volume remove-brick " + volumeName + " stripe " + count + " " + brick command = "echo -e \"y\" | gluster volume remove-brick " + volumeName + " " + brick + " force";
+ " force"; } else if (type.equals(Constant.replica)) {
} command = "echo -e \"y\" | gluster volume remove-brick " + volumeName + " repli " + count + " " + brick
+ " force";
if (command == null) { } else if (type.equals(Constant.stripe)) {
log.error("3305 remove brick failed,please check the system"); command = "echo -e \"y\" | gluster volume remove-brick " + volumeName + " stripe " + count + " " + brick
return -5; + " force";
} }
log.info("即将执行删除命令");
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, if (command == null) {
Constant.port, command); log.error("3305 remove brick failed,please check the system");
// System.out.println(reStrings); return -5;
log.info("删除命令执行完毕"); }
log.info("即将执行删除命令");
// 删除成功的返回信息是“volume remove-brick: success” List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd,
if (reStrings.get(0).contains("volume remove-brick: success")) { Constant.port, command);
{ // System.out.println(reStrings);
log.info("删除brick成功"); log.info("删除命令执行完毕");
return 1;
} // 删除成功的返回信息是“volume remove-brick: success”
} else { if (reStrings.get(0).contains("volume remove-brick: success")) {
log.error("3305 remove brick failed,please check the system"); {
log.info("删除brick成功");
return -5; return 1;
} }
} else {
} log.error("3305 remove brick failed,please check the system");
/* return -5;
* volume volume 0 -1 }
* volumevolume
*/ }
public int stopVolume(String volumeName) {
log.info("stop volume"); /*
* volume volume 0 -1
// 首先需要判断volume是否存在调用其他函数返回所有volume的名字 * volumevolume
boolean volumeExist = false; */
public int stopVolume(String volumeName) {
List<String> volume = new VolumeInfo().showAllVolumeName(); log.info("stop volume");
for (String temp : volume) {
if (temp.equals(volumeName)) { // 首先需要判断volume是否存在调用其他函数返回所有volume的名字
volumeExist = true; boolean volumeExist = false;
break;
} List<String> volume = new VolumeInfo().showAllVolumeName();
} for (String temp : volume) {
if (temp.equals(volumeName)) {
if (!volumeExist) { volumeExist = true;
// volume不存在 break;
log.error("3501 the volume doesnot exist"); }
System.out.println("3501 the volume doesnot exist"); }
return -1;
} else { if (!volumeExist) {
// volume存在则需判断volume的状态是否已经为“stop” // volume不存在
if (new VolumeInfo().getVolumeStatus(volumeName).equals("Stopped")) { log.error("3501 the volume doesnot exist");
log.error("3502 the volume is already stoped"); System.out.println("3501 the volume doesnot exist");
System.out.println("3502 the volume is already stoped"); return -1;
return -1; } else {
} else { // volume存在则需判断volume的状态是否已经为“stop”
String command = "echo -e \"y\"| gluster volume stop " + volumeName; if (new VolumeInfo().getVolumeStatus(volumeName).equals("Stopped")) {
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, log.error("3502 the volume is already stoped");
Constant.port, command); System.out.println("3502 the volume is already stoped");
return -1;
// 标记操作结果operation = 1 操作成功 } else {
// operation = 0 操作失败 String command = "echo -e \"y\"| gluster volume stop " + volumeName;
int operation = 0; List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd,
for (String temp2 : reStrings) { Constant.port, command);
if (temp2.contains("volume stop: " + volumeName + ": " + "success")) {
operation = 1; // 标记操作结果operation = 1 操作成功
break; // operation = 0 操作失败
} int operation = 0;
System.out.println("operation: " + operation); for (String temp2 : reStrings) {
} if (temp2.contains("volume stop: " + volumeName + ": " + "success")) {
operation = 1;
if (operation == 1) { break;
return 0; }
} else { System.out.println("operation: " + operation);
log.error("3503 stop " + volumeName + " failed"); }
System.out.println("3503 stop " + volumeName + " failed");
return -1; if (operation == 1) {
} return 0;
} else {
} log.error("3503 stop " + volumeName + " failed");
} System.out.println("3503 stop " + volumeName + " failed");
} return -1;
}
/*
* volume volume 0 -1 }
* volumevolume }
*/ }
public int startVolume(String volumeName) {
log.info("start volume"); /*
boolean volumeExist = false; * volume volume 0 -1
List<String> volume = new VolumeInfo().showAllVolumeName(); * volumevolume
*/
for (String temp : volume) { public int startVolume(String volumeName) {
if (temp.equals(volumeName)) { log.info("start volume");
volumeExist = true; boolean volumeExist = false;
break; List<String> volume = new VolumeInfo().showAllVolumeName();
}
} for (String temp : volume) {
if (temp.equals(volumeName)) {
if (volumeExist) { volumeExist = true;
if (!(new VolumeInfo().getVolumeStatus(volumeName).equals("Started"))) { break;
String command = "gluster volume start " + volumeName; }
}
int operation = 0;
if (volumeExist) {
// 执行命令 if (!(new VolumeInfo().getVolumeStatus(volumeName).equals("Started"))) {
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, String command = "gluster volume start " + volumeName;
Constant.port, command);
for (String temp2 : reStrings) { int operation = 0;
if (temp2.equals("volume start: " + volumeName + ": " + "success")) {
operation = 1; // 执行命令
} List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd,
} Constant.port, command);
for (String temp2 : reStrings) {
if (operation == 1) { if (temp2.equals("volume start: " + volumeName + ": " + "success")) {
return 0; operation = 1;
} else { }
log.error("3602 start volume failed"); }
System.out.println("3602 start volume failed");
return -1; if (operation == 1) {
} return 0;
} else { } else {
log.error("volume已经开启"); log.error("3602 start volume failed");
System.out.println("volume已经开启"); System.out.println("3602 start volume failed");
return -1; return -1;
} }
} else { } else {
log.error("3601 the volume does not exist"); log.error("volume已经开启");
// System.out.println("3601 the volume does not exist"); System.out.println("volume已经开启");
return -1; return -1;
} }
} } else {
log.error("3601 the volume does not exist");
// 需要将存于List变量中的brick的位置组装成可以在glusterfs命令行中直接使用的格式 // System.out.println("3601 the volume does not exist");
public String concat(List<String> brickName) { return -1;
StringBuffer result = new StringBuffer(); }
int len = brickName.size(); }
for (int i = 0; i < len; i++) {
result.append(brickName.get(i)); // 需要将存于List变量中的brick的位置组装成可以在glusterfs命令行中直接使用的格式
result.append(" "); public String concat(List<String> brickName) {
} StringBuffer result = new StringBuffer();
return result.toString(); int len = brickName.size();
} for (int i = 0; i < len; i++) {
result.append(brickName.get(i));
/* result.append(" ");
* volume使 volumebrickcount }
* 1: ;-1brickip; -2 -3 return result.toString();
* -4 :brick ; -5 :volumeName -6 -7 }
*/
public int isAbleCreateVolume(String volumeName, int count, String type, List<String> bricks, String mountPoint) { /*
int status = 0; * volume使 volumebrickcount
* 1: ;-1brickip; -2 -3
int length = bricks.size(); * -4 :brick ; -5 :volumeName -6 -7
*/
if (type.equals(Constant.distributed)) { public int isAbleCreateVolume(String volumeName, int count, String type, List<String> bricks, String mountPoint) {
if (count != 0) { int status = 0;
log.error("3101 the kind of distributed requires the arg of count to be 0");
return -2; int length = bricks.size();
}
} if (type.equals(Constant.distributed)) {
if (type.equals(Constant.stripe)) { if (count != 0) {
if (length % count != 0) { log.error("3101 the kind of distributed requires the arg of count to be 0");
log.error("3102 the number of bricks should be the same as or the times of the stripe count"); return -2;
return -3; }
} }
} if (type.equals(Constant.stripe)) {
if (type.equals(Constant.replica)) { if (length % count != 0) {
if ((length % count) != 0) { log.error("3102 the number of bricks should be the same as or the times of the stripe count");
log.error( return -3;
"3103 the number of bricks should be the same as the replicate count or the times of replicate count"); }
return -4; }
} if (type.equals(Constant.replica)) {
} if ((length % count) != 0) {
log.error(
Map peer_status = new ClusterInfo().showClusterInfo(); "3103 the number of bricks should be the same as the replicate count or the times of replicate count");
peer_status.put(Constant.hostIp, Constant.peerincluster_connected); return -4;
for (String brick : bricks) { }
brick = brick.split(":")[0]; }
if (!(peer_status.containsKey(brick) && peer_status.get(brick).equals(Constant.peerincluster_connected))) {
log.error("3105 birck " + brick + " ip is not in cluster"); Map peer_status = new ClusterInfo().showClusterInfo();
return -1; peer_status.put(Constant.hostIp, Constant.peerincluster_connected);
} for (String brick : bricks) {
brick = brick.split(":")[0];
} if (!(peer_status.containsKey(brick) && peer_status.get(brick).equals(Constant.peerincluster_connected))) {
log.error("3105 birck " + brick + " ip is not in cluster");
List<String> volumeNames = new VolumeInfo().showAllVolumeName(); return -1;
if(volumeNames==null){ }
log.error("3108 showAllVolumeName return error");
return -7; }
}
if (volumeNames.contains(volumeName)) { List<String> volumeNames = new VolumeInfo().showAllVolumeName();
log.error("3106 " + volumeName + " is already exists! "); if(volumeNames==null){
return -5; log.error("3108 showAllVolumeName return error");
} return -7;
}
Map datas = new ShowData().showFolderData(mountPoint); if (volumeNames.contains(volumeName)) {
if (datas != null && datas.size() > 0) { log.error("3106 " + volumeName + " is already exists! ");
log.error("3107 " + mountPoint + " is not exists or not empty ! "); return -5;
return -6; }
}
return 1; Map datas = new ShowData().showFolderData(mountPoint);
} if (datas != null && datas.size() > 0) {
log.error("3107 " + mountPoint + " is not exists or not empty ! ");
/** return -6;
* volumebrickvolumevolumecountbrick }
* return 1;
* @param volumeName }
* @param count
* @param type /**
* @param bricks * volumebrickvolumevolumecountbrick
* @return 1 ;-1 :volume name is not exists;-2,-3,-4 brick *
*/ * @param volumeName
public int isAble(String volumeName, int count, String type, List bricks) { * @param count
List<String> volumeNames = new VolumeInfo().showAllVolumeName(); * @param type
* @param bricks
if (!volumeNames.contains(volumeName)) { * @return 1 ;-1 :volume name is not exists;-2,-3,-4 brick
log.error("3201" + volumeName + " is not exists! "); */
return -1; public int isAble(String volumeName, int count, String type, List bricks) {
} List<String> volumeNames = new VolumeInfo().showAllVolumeName();
int length = bricks.size(); if (!volumeNames.contains(volumeName)) {
if (type.equals("distribute")) { log.error("3201" + volumeName + " is not exists! ");
if (count == 0) return -1;
return 1; }
else {
log.error("3202 the kind of distributed requires the arg of count to be 0"); int length = bricks.size();
// System.out.println(" the kind of distributed requires the if (type.equals("distribute")) {
// arg of count to be 0"); if (count == 0)
return -2; return 1;
} else {
} log.error("3202 the kind of distributed requires the arg of count to be 0");
// System.out.println(" the kind of distributed requires the
if (type.equals("stripe")) { // arg of count to be 0");
if (length % count == 0) return -2;
return 1; }
else { }
log.error("3203 the number of bricks should be the same as or the times of the stripe count");
// System.out.println(" the number of bricks should be the if (type.equals("stripe")) {
// same as or the times of the stripe count"); if (length % count == 0)
return -3; return 1;
else {
} log.error("3203 the number of bricks should be the same as or the times of the stripe count");
} // System.out.println(" the number of bricks should be the
if (type.equals("replicate")) { // same as or the times of the stripe count");
if ((length % count) == 0) return -3;
return 1;
else { }
log.error( }
"3204 the number of bricks should be the same as the replicate count or the times of replicate count"); if (type.equals("replicate")) {
if ((length % count) == 0)
return -4; return 1;
} else {
} log.error(
"3204 the number of bricks should be the same as the replicate count or the times of replicate count");
return 1;
} return -4;
}
public static void main(String[] args) { }
SetVolume setVolume = new SetVolume();
int operation = 0; return 1;
PropertyConfigurator.configure("log4j.properties"); }
// TODO Auto-generated method stub
// 测试创建volume的代码 public static void main(String[] args) {
SetVolume setVolume = new SetVolume();
List<String> bricksToCreate = new ArrayList<String>(); int operation = 0;
bricksToCreate.add("192.168.0.110:/v1"); PropertyConfigurator.configure("log4j.properties");
bricksToCreate.add("192.168.0.116:/v1"); // TODO Auto-generated method stub
operation = setVolume.createVolume("v1", 0, "distributed", bricksToCreate, "/home/v1_point"); // 测试创建volume的代码
// operation = setVolume.deleteVolume("v3");
// List<String> bricksToCreate = new ArrayList<String>();
// // 以下是测试添加brick的代码 bricksToCreate.add("192.168.0.110:/v1");
// bricksToCreate.add("192.168.0.116:/v1");
// List<String> bricksToAdd = new ArrayList<String>(); operation = setVolume.createVolume("v1", 0, "distributed", bricksToCreate, "/home/v1_point");
// bricksToAdd.add("192.168.191.23:/v3"); // operation = setVolume.deleteVolume("v3");
// operation = setVolume.addBrickVolume("v3", bricksToAdd, 0, //
// "distribute"); // // 以下是测试添加brick的代码
// System.out.println(operation); //
// List<String> bricksToAdd = new ArrayList<String>();
// 以下代码是测试删除brick的代码 // bricksToAdd.add("192.168.191.23:/v3");
// List<String> bricksToAdd= new ArrayList<String>(); // operation = setVolume.addBrickVolume("v3", bricksToAdd, 0,
// bricksToAdd.add("192.168.191.23:/v3"); // "distribute");
// operation = // System.out.println(operation);
// setVolume.deleteBrickVolume("v3",bricksToAdd,0,"distribute");
// System.out.println(operation); // 以下代码是测试删除brick的代码
// 以下是测试start volume的代码 // List<String> bricksToAdd= new ArrayList<String>();
// String volumeToStart = "testcreate" ; // bricksToAdd.add("192.168.191.23:/v3");
// int startOperation = startVolume(volumeToStart); // operation =
// System.out.println(startOperation); // setVolume.deleteBrickVolume("v3",bricksToAdd,0,"distribute");
// 以下是测试stop volume // System.out.println(operation);
String volumeToStop = "v3"; // 以下是测试start volume的代码
// int startOperation = setVolume.stopVolume(volumeToStop); // String volumeToStart = "testcreate" ;
// 以下是测试创建volume并完成挂载的代码 // int startOperation = startVolume(volumeToStart);
// List<String> bricksToCreate= new ArrayList<String>(); // System.out.println(startOperation);
// bricksToCreate.add("192.168.214.135:/home/create"); // 以下是测试stop volume
// bricksToCreate.add("192.168.214.138:/home/create"); String volumeToStop = "v3";
// // int startOperation = setVolume.stopVolume(volumeToStop);
// int operation = // 以下是测试创建volume并完成挂载的代码
// createVolume("createAndmount",0,"distribute",bricksToCreate,"/mnt/create"); // List<String> bricksToCreate= new ArrayList<String>();
// System.out.println(operation); // bricksToCreate.add("192.168.214.135:/home/create");
} // bricksToCreate.add("192.168.214.138:/home/create");
} //
// int operation =
// createVolume("createAndmount",0,"distribute",bricksToCreate,"/mnt/create");
// System.out.println(operation);
}
}

@ -1,104 +1,105 @@
package com.platform.glusterfs; package com.platform.glusterfs;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator; import org.apache.log4j.PropertyConfigurator;
import org.junit.Test; import org.junit.Test;
import com.platform.utils.Constant; import com.platform.utils.Constant;
public class ShowData { public class ShowData {
public static Logger log = Logger.getLogger ( ShowData.class); public static Logger log = Logger.getLogger ( ShowData.class);
/**
* get the data of volumeName Map<string s1,string s2> s1 is data name and s2 is type file or folder /**
* @param volumeName * get the data of volumeName Map<string s1,string s2> s1 is data name and s2 is type file or folder
* @return * <>
*/ * @param volumeName
* @return
* @see [##]
public Map<String,String> showVolumeFiles(String volumeName){ */
log.info("start show the data"); public Map<String,String> showVolumeFiles(String volumeName){
Map<String,String> data_type=new HashMap<String, String>(); log.info("start show the data");
/** Map<String,String> data_type=new HashMap<String, String>();
* get mount point of volumeName /**
*/ * get mount point of volumeName
String folderName=volumeName; */
String folderName=volumeName;
data_type=showFolderData(volumeName);
return data_type; data_type=showFolderData(volumeName);
} return data_type;
/** }
* get the data of folder name /**
* Map<String,String> is folder name and type 1 is file and others is folder * get the data of folder name
* Map<String,String> is folder name and type 1 is file and others is folder
* @param FolderName
* @return * @param FolderName
*/ * @return
public Map<String,String> showFolderData(String folderName){ */
log.info(" start get "+folderName+" data"); public Map<String,String> showFolderData(String folderName){
log.info(" start get "+folderName+" data");
Map<String,String> data_type=new HashMap<String, String>();
String command="ls -l "+folderName; Map<String,String> data_type=new HashMap<String, String>();
String command="ls -l "+folderName;
/*
RunCommand runCommand=new RunCommand(); /*
List<String> reStrings=runCommand.runCommandWait(command); RunCommand runCommand=new RunCommand();
*/ List<String> reStrings=runCommand.runCommandWait(command);
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, Constant.port, command); */
if(reStrings==null){ List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, Constant.port, command);
log.error("2101 command get result is null"); if(reStrings==null){
return null; log.error("2101 command get result is null");
} return null;
if(reStrings.size()==0){ }
log.info("2102 the folder is empty"); if(reStrings.size()==0){
return data_type; log.info("2102 the folder is empty");
} return data_type;
if(reStrings.get(0).contains("No such file or directory")){ }
log.info("2103 the "+folderName+" is not exists"); if(reStrings.get(0).contains("No such file or directory")){
return null; log.info("2103 the "+folderName+" is not exists");
} return null;
/** }
* remove first line total number /**
*/ * remove first line total number
reStrings.remove(0); */
reStrings.remove(0);
for(Iterator it2 = reStrings.iterator();it2.hasNext();){
String line=(String)it2.next(); for(Iterator it2 = reStrings.iterator();it2.hasNext();){
line=line.replaceAll(" +", " "); String line=(String)it2.next();
String keyValue[]=line.split(" "); line=line.replaceAll(" +", " ");
if(keyValue.length<9){ String keyValue[]=line.split(" ");
log.error("2104 "+line+" length is short"); if(keyValue.length<9){
continue; log.error("2104 "+line+" length is short");
} continue;
}
data_type.put(keyValue[8], keyValue[1]);
data_type.put(keyValue[8], keyValue[1]);
}
log.info(" get "+folderName+" data successed"); }
return data_type; log.info(" get "+folderName+" data successed");
} return data_type;
}
/**
* /**
* <> *
* <> * <>
* @see [##] * <>
*/ * @see [##]
@Test */
public void testShowData(){ @Test
public void testShowData(){
System.out.println(showFolderData("/home"));
System.out.println(showFolderData("/home"));
}
}
} }

@ -1,271 +1,334 @@
package com.platform.glusterfs; package com.platform.glusterfs;
import java.io.File;
import java.util.ArrayList;
import java.io.File; import java.util.HashMap;
import java.util.ArrayList; import java.util.Iterator;
import java.util.HashMap; import java.util.List;
import java.util.Iterator; import java.util.Map;
import java.util.List;
import java.util.Map; import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.Logger; import org.junit.Test;
import org.apache.log4j.PropertyConfigurator; import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;
import com.platform.utils.Constant; import com.platform.utils.Constant;
import com.platform.utils.GanymedSSH;
import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class VolumeInfo {
public static Logger log = Logger.getLogger(VolumeInfo.class); public class VolumeInfo {
public static Logger log = Logger.getLogger(VolumeInfo.class);
public List<String> showAllVolumeName() {
log.info("get volume name"); /**
List<String> volNames = new ArrayList<String>(); * volume
* <>
/* * @return
* String command = "echo \"" + Constant.rootPasswd + * @see [##]
* "\" |sudo -S gluster volume info|grep ^Volume.Name"; RunCommand */
* runCommand = new RunCommand(); List<String> reStrings = public List<String> showAllVolumeName() {
* runCommand.runCommandWait(command); log.info("get volume name");
*/ List<String> volNames = new ArrayList<String>();
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd,
Constant.port, Constant.glusterVolumeInfo + "|grep ^Volume.Name"); /*
// System.out.println(reStrings); * String command = "echo \"" + Constant.rootPasswd +
if(reStrings==null){ * "\" |sudo -S gluster volume info|grep ^Volume.Name"; RunCommand
log.error("1401 get result is null"); * runCommand = new RunCommand(); List<String> reStrings =
return null; * runCommand.runCommandWait(command);
} */
if(reStrings.size()==0){ List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser,
log.error("1402 get result is nothing"); Constant.rootPasswd, Constant.port, Constant.glusterVolumeInfo + "|grep ^Volume.Name");
return null; // System.out.println(reStrings);
} if (reStrings == null) {
if(reStrings.get(0).contains(Constant.noVolume)){ log.error("1401 get result is null");
reStrings.clear(); return null;
return reStrings; }
} if (reStrings.size() == 0) {
if (!(reStrings.get(0).split(":")[0].contains("Volume Name"))) { log.error("1402 get result is nothing");
log.error("1403 get result string wrong"); return null;
return null; }
} if (reStrings.get(0).contains(Constant.noVolume)) {
reStrings.clear();
String nameInfo = ""; return reStrings;
for (Iterator it = reStrings.iterator(); it.hasNext();) { }
String line = (String) it.next(); if (!(reStrings.get(0).split(":")[0].contains("Volume Name"))) {
String str[] = line.split(":"); log.error("1403 get result string wrong");
volNames.add(str[1].replaceAll(" ", "")); return null;
} }
return volNames;
String nameInfo = "";
} for (Iterator it = reStrings.iterator(); it.hasNext();) {
String line = (String) it.next();
public String getVolumeType(String volumeName) { String str[] = line.split(":");
log.info("get volume type"); volNames.add(str[1].replaceAll(" ", ""));
String volType = ""; }
return volNames;
/*
* ======= }
*
* >>>>>>> origin/AlexKie String command = "echo \"" + /**
* Constant.rootPasswd + "\" |sudo -S gluster volume info " + * volumevolume
* volumeName + "|grep ^Type"; RunCommand runCommand = new RunCommand(); * <>
* List<String> reStrings = runCommand.runCommandWait(command); <<<<<<< * @param volumeName
* HEAD * @return
*/ * @see [##]
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, */
Constant.port, Constant.glusterVolumeInfo + volumeName + "|grep ^Type"); public String getVolumeType(String volumeName) {
// System.out.println(reStrings); log.info("get volume type");
if(reStrings==null){ String volType = "";
log.error("1501 get result is null");
return null; List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser,
} Constant.rootPasswd, Constant.port, Constant.glusterVolumeInfo + volumeName + "|grep ^Type");
if(reStrings.size()==0){ // System.out.println(reStrings);
log.error("1502 get result is nothing"); if (reStrings == null) {
return null; log.error("1501 get result is null");
} return null;
if (!(reStrings.get(0).split(":")[0].contains("Type"))) { }
log.error("1503 get result string wrong"); if (reStrings.size() == 0) {
return null; log.error("1502 get result is nothing");
} return null;
}
// System.out.println(reStrings); if (!(reStrings.get(0).split(":")[0].contains("Type"))) {
log.error("1503 get result string wrong");
for (Iterator it = reStrings.iterator(); it.hasNext();) { return null;
String line = (String) it.next(); }
String str[] = line.split(":");
volType = str[1]; // System.out.println(reStrings);
}
volType=volType.replaceAll(" ", ""); for (Iterator it = reStrings.iterator(); it.hasNext();) {
return volType; String line = (String) it.next();
} String str[] = line.split(":");
volType = str[1];
public String getVolumeStatus(String volumeName) { }
log.info("get volume status"); volType = volType.replaceAll(" ", "");
String volStatus = ""; return volType;
}
/*
* ======= public String getVolumeStatus(String volumeName) {
* log.info("get volume status");
* >>>>>>> origin/AlexKie String command = "echo \"" + String volStatus = "";
* Constant.rootPasswd + "\" |sudo -S gluster volume info " + List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser,
* volumeName + "|grep ^Status"; RunCommand runCommand = new Constant.rootPasswd, Constant.port, Constant.glusterVolumeInfo + "|grep ^Status");
* RunCommand(); List<String> reStrings = // System.out.println(reStrings);
* runCommand.runCommandWait(command); <<<<<<< HEAD if (reStrings == null) {
*/ log.error("1701 get result is null");
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, return null;
Constant.port, Constant.glusterVolumeInfo + "|grep ^Status"); }
// System.out.println(reStrings); if (reStrings.size() == 0) {
if(reStrings==null){ log.error("1702 get result is nothing");
log.error("1701 get result is null"); return null;
return null; }
} if (!(reStrings.get(0).split(":")[0].contains("Status"))) {
if(reStrings.size()==0){ log.error("1703 get result string wrong");
log.error("1702 get result is nothing"); return null;
return null; }
}
if (!(reStrings.get(0).split(":")[0].contains("Status"))) { for (Iterator it = reStrings.iterator(); it.hasNext();) {
log.error("1703 get result string wrong"); String line = (String) it.next();
return null; String str[] = line.split(":");
} volStatus = str[1].replaceAll(" ", "");
}
for (Iterator it = reStrings.iterator(); it.hasNext();) { return volStatus;
String line = (String) it.next(); }
String str[] = line.split(":");
volStatus = str[1].replaceAll(" ", ""); public Double getVolumeAllSize(String volumeName) {
} log.info("get volume allSize");
Double allSize = null;
return volStatus; /*
} * ======= // waiting for testing... public Double
* getVolumeAllSize(String volumeName) { log.info("get volume allSize");
public Double getVolumeAllSize(String volumeName) { * Double allSize = null;
log.info("get volume allSize"); *
Double allSize = null; * >>>>>>> origin/AlexKie String command = "echo \"" +
/* * Constant.rootPasswd + "\" |sudo -S df -h|grep " + volumeName +
* ======= // waiting for testing... public Double * "|awk '{print $2}'"; RunCommand runCommand = new RunCommand();
* getVolumeAllSize(String volumeName) { log.info("get volume allSize"); * List<String> reStrings = runCommand.runCommandWait(command); <<<<<<<
* Double allSize = null; * HEAD
* */
* >>>>>>> origin/AlexKie String command = "echo \"" + List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd,
* Constant.rootPasswd + "\" |sudo -S df -h|grep " + volumeName + Constant.port, Constant.df + "|grep " + volumeName + "|awk '{print $2}'");
* "|awk '{print $2}'"; RunCommand runCommand = new RunCommand(); // System.out.println(reStrings);
* List<String> reStrings = runCommand.runCommandWait(command); <<<<<<< if(reStrings==null){
* HEAD log.error("1801 get result is null");
*/ return null;
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, }
Constant.port, Constant.df + "|grep " + volumeName + "|awk '{print $2}'"); if(reStrings.size()==0){
// System.out.println(reStrings); log.error("1802 get result is nothing");
if(reStrings==null){ return null;
log.error("1801 get result is null"); }
return null; char flag = reStrings.get(0).trim().toCharArray()[0];
} if (flag < 48 || flag > 57) {
if(reStrings.size()==0){ log.error("1803 get result string wrong");
log.error("1802 get result is nothing"); return null;
return null; }
}
char flag = reStrings.get(0).trim().toCharArray()[0]; for (Iterator it = reStrings.iterator(); it.hasNext();) {
if (flag < 48 || flag > 57) { String line = (String) it.next();
log.error("1803 get result string wrong"); String str[] = line.split("[^0-9]");
return null; allSize = Double.parseDouble(str[0]);
} }
for (Iterator it = reStrings.iterator(); it.hasNext();) { return allSize;
String line = (String) it.next(); }
String str[] = line.split("[^0-9]");
allSize = Double.parseDouble(str[0]); public Double getVolumeUseSize(String volumeName) {
} log.info("get volume used size");
Double usedSize = null;
return allSize;
} List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser,
Constant.rootPasswd, Constant.port, Constant.df + "|grep " + volumeName + "|awk '{print $3}'");
public Double getVolumeUseSize(String volumeName) { // System.out.println(reStrings);
log.info("get volume used size"); if (reStrings == null) {
Double usedSize = null; log.error("1901 get result is null");
return null;
/* }
* ======= if (reStrings.size() == 0) {
* log.error("1902 get result is nothing");
* >>>>>>> origin/AlexKie String command = "echo \"" + return null;
* Constant.rootPasswd + "\" |sudo -S df -h|grep " + volumeName + }
* "|awk '{print $3}'"; RunCommand runCommand = new RunCommand(); char flag = reStrings.get(0).trim().toCharArray()[0];
* List<String> reStrings = runCommand.runCommandWait(command); <<<<<<< if (flag < 48 || flag > 57) {
* HEAD log.error("1903 get result string wrong");
*/ return null;
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, }
Constant.port, Constant.df + "|grep " + volumeName + "|awk '{print $3}'");
// System.out.println(reStrings); for (Iterator it = reStrings.iterator(); it.hasNext();) {
if(reStrings==null){ String line = (String) it.next();
log.error("1901 get result is null"); String str[] = line.split("[^0-9]");
return null;
} usedSize = Double.parseDouble(str[0]);
if(reStrings.size()==0){ }
log.error("1902 get result is nothing");
return null; return usedSize;
} }
char flag = reStrings.get(0).trim().toCharArray()[0];
if (flag < 48 || flag > 57) { /**
log.error("1903 get result string wrong"); * @param volumeName
return null; * @return String ipAndpath[] = brick.split(":");
} String ip = ipAndpath[0];
String path = ipAndpath[1];
for (Iterator it = reStrings.iterator(); it.hasNext();) { */
String line = (String) it.next(); public List<String> getVolumeBricks(String volumeName) {
String str[] = line.split("[^0-9]"); log.info("get volume bricks");
usedSize = Double.parseDouble(str[0]); String cmd = "gluster volume info " + volumeName + " |grep ^Brick'[0-9]\\+' |awk '{print $2}'";
} List<String> reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
// System.out.println(reStrings);
return usedSize; if (reStrings == null) {
} log.error("1601 get volume bricks wrong");
return null;
public String getVolumeMountPoint(String volumeName) { }
log.info("get volume mountPoint");
// String mountPoint = ""; return reStrings;
}
/*
* ======= public List<String> getVolumeMountPoint(String volumeName) {
* log.info("get volume MountPoint");
* >>>>>>> origin/AlexKie String command = "echo \"" +
* Constant.rootPasswd + "\" |sudo -S df -h|grep " + volumeName + List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd,
* "|awk '{print $6}'"; RunCommand runCommand = new RunCommand(); Constant.port, Constant.df + "|grep " + volumeName + "|awk '{print $6}'");
* List<String> reStrings = runCommand.runCommandWait(command); <<<<<<< // System.out.println(reStrings);
* HEAD if(reStrings==null){
*/ log.error("11001 get result string wrong");
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, return null;
Constant.port, Constant.df + "|grep " + volumeName + "|awk '{print $6}'"); }
// System.out.println(reStrings); if(reStrings.size()==0){
if(reStrings==null){ log.error("11002 "+volumeName+" is no mountpoint");
log.error("11001 get result string wrong"); return null;
return null; }
}
if(reStrings.size()==0){ char flag = reStrings.get(0).trim().toCharArray()[0];
log.error("11002 "+volumeName+" is no mountpoint"); if (flag != '/') {
return null; log.error("11003 get result string wrong");
} return null;
}
char flag = reStrings.get(0).trim().toCharArray()[0]; List<String> mountPoints = new ArrayList<>();
if (flag != '/') { for(String mountPoint:reStrings){
log.error("11003 get result string wrong"); mountPoint=mountPoint.replaceAll(" ", "");
return null; mountPoints.add(mountPoint);
} }
return mountPoints;
Iterator it = reStrings.iterator(); }
String mountPoint = (String) it.next();
mountPoint=mountPoint.replaceAll(" ", ""); public Map<String, Double> getVolumebricksDataSize(String volumeName) {
return mountPoint; List<String> bricks = getVolumeBricks(volumeName);
} Map<String, Double> brick_size = new HashMap<>();
if (bricks == null) {
public static void main(String[] args) { return null;
PropertyConfigurator.configure("log4j.properties"); }
for (String brick : bricks) {
System.out.println(new VolumeInfo().showAllVolumeName()); String ipAndpath[] = brick.split(":");
System.out.println(new VolumeInfo().getVolumeType("v1")); String ip = ipAndpath[0];
String path = ipAndpath[1];
System.out.println(new VolumeInfo().getVolumeStatus("v1")); String cmd = "du -d 0 " + path + "|awk '{print $1}'";
System.out.println(new VolumeInfo().getVolumeMountPoint("v1")); List<String> reStrings = Constant.ganymedSSH.execCmdWait(ip, Constant.rootUser, Constant.rootPasswd,
Constant.port, cmd);
System.out.println(new VolumeInfo().getVolumeAllSize("v1")); // System.out.println(reStrings);
System.out.println(new VolumeInfo().getVolumeUseSize("v1")); if (reStrings == null) {
log.error("1901 get result is null");
} return null;
} }
if (reStrings.size() == 0) {
log.error("1902 get result is nothing");
return null;
}
Pattern pattern = Pattern.compile("[0-9]*");
Matcher isNum = pattern.matcher(reStrings.get(0));
if (!isNum.matches()) {
log.error("1903 " + reStrings.get(0) + " is unexpect");
return null;
}
brick_size.put(brick, Double.parseDouble(reStrings.get(0)));
}
return brick_size;
}
public Map<String, Double> getVolumebricksAvailableSize(String volumeName) {
List<String> bricks = getVolumeBricks(volumeName);
Map<String, Double> brick_size = new HashMap<>();
if (bricks == null) {
return null;
}
for (String brick : bricks) {
String ipAndpath[] = brick.split(":");
String ip = ipAndpath[0];
String path = ipAndpath[1];
String cmd = "df " + path + "|awk '{print $4}'";
List<String> reStrings = Constant.ganymedSSH.execCmdWait(ip, Constant.rootUser, Constant.rootPasswd,
Constant.port, cmd);
// System.out.println(reStrings);
if (reStrings == null) {
log.error("1901 get result is null");
return null;
}
if (reStrings.size() == 0) {
log.error("1902 get result is nothing");
return null;
}
Pattern pattern = Pattern.compile("[0-9]*");
Matcher isNum = pattern.matcher(reStrings.get(1));
if (!isNum.matches()) {
log.error("1903 " + reStrings.get(1) + " is unexpect");
return null;
}
brick_size.put(brick, Double.parseDouble(reStrings.get(1)));
}
return brick_size;
}
@Test
public void test_getVolumebricksDataSize() {
System.out.println(getVolumebricksDataSize("gfs_ftp"));
}
@Test
public void test_getVolumebricksAvailableSize() {
System.out.println(getVolumebricksAvailableSize("gfs_ftp"));
}
// @Test
public void test_getVolumeBricks() {
getVolumeBricks("gfs_ftp");
}
}

@ -44,6 +44,7 @@ public class DataInfoServiceImp implements DataInfoService {
public void deleteData(String[] id) { public void deleteData(String[] id) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
for(String idx: id){ for(String idx: id){
//数据在不在?
List<String> paths = dfdDao.getIdIsExist(Integer.parseInt(idx)); List<String> paths = dfdDao.getIdIsExist(Integer.parseInt(idx));
if(paths.size()>0){ if(paths.size()>0){
//删除文件操作 //删除文件操作

@ -1,122 +1,149 @@
/** /**
* : GfsServiceImpl.java * : GfsServiceImpl.java
* : </> * : </>
* : <> * : <>
* @author chen * @author chen
* : <> * : <>
* 201698 * 201698
* <> * <>
*/ */
package com.platform.service.impl; package com.platform.service.impl;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Service;
import org.springframework.stereotype.Service;
import com.platform.entities.FolderNode;
import com.platform.entities.VolumeEntity; import com.platform.entities.Brick;
import com.platform.glusterfs.CopyData; import com.platform.entities.FolderNode;
import com.platform.glusterfs.GetTreeData; import com.platform.entities.VolumeEntity;
import com.platform.glusterfs.VolumeInfo; import com.platform.glusterfs.CopyData;
import com.platform.service.IGfsService; import com.platform.glusterfs.GetTreeData;
import com.platform.utils.CacheTreeData; import com.platform.glusterfs.VolumeInfo;
import com.platform.utils.VolumeThread; import com.platform.service.IGfsService;
import com.platform.utils.getTreeDataByPath; import com.platform.utils.CacheTreeData;
import com.platform.utils.ThreadVolume;
/** import com.platform.utils.getTreeDataByPath;
* <> gfs
* <> /**
* @author chen * <> gfs
* @version [201698] * <>
* @see [/] * @author chen
* @since [/] * @version [201698]
*/ * @see [/]
@Service(value = "gfsService") * @since [/]
public class GfsServiceImpl implements IGfsService { */
@Service(value = "gfsService")
/** gfs目录树形查询 */ public class GfsServiceImpl implements IGfsService {
private getTreeDataByPath getFolder = new getTreeDataByPath();
/** gfs目录树形查询 */
/** 数据迁移实现 */ private getTreeDataByPath getFolder = new getTreeDataByPath();
private CopyData copydata = new CopyData();
/** 数据迁移实现 */
/** Volume信息查询 */ private CopyData copydata = new CopyData();
private VolumeInfo volumeInfo = new VolumeInfo();
/** Volume信息查询 */
@Override private VolumeInfo volumeInfo = new VolumeInfo();
public FolderNode getFolder(String path) {
FolderNode result = getFolder.findByPath(path); @Override
return result; public FolderNode getFolder(String path) {
} FolderNode result = getFolder.findByPath(path);
return result;
@Override }
public int copyFolder(List<String> srcFolders, String dstFolder, String name)
throws Exception { @Override
int status = 0 ; public int copyFolder(List<String> srcFolders, String dstFolder, String name)
if (null != srcFolders) { throws Exception {
int status = 0 ;
for (String string : srcFolders) { if (null != srcFolders) {
status = copydata.copyFolderFiles(string, dstFolder, name);
} for (String string : srcFolders) {
} status = copydata.copyFolderFiles(string, dstFolder, name);
return status; }
} }
return status;
/* (non-Javadoc) }
* @see com.platform.service.IGfsService#getAllVolume()
*/ /* (non-Javadoc)
@Override * @see com.platform.service.IGfsService#getAllVolume()
public List<VolumeEntity> getAllVolumes() throws Exception { */
List<VolumeEntity> volumeList = new ArrayList<>(); @Override
List<String> volumeNameList = volumeInfo.showAllVolumeName(); public List<VolumeEntity> getAllVolumes() throws Exception {
for (String volumeName : volumeNameList) { List<VolumeEntity> volumeList = new ArrayList<>();
VolumeEntity volume = new VolumeEntity(); List<String> volumeNameList = volumeInfo.showAllVolumeName();
volume.setName(volumeName); if (null == volumeNameList) {
String path = volumeInfo.getVolumeMountPoint(volumeName); return null;
volume.setPath(path); }
volume.setAllSize(volumeInfo.getVolumeAllSize(volumeName)); for (String volumeName : volumeNameList) {
volume.setUsedSize(volumeInfo.getVolumeUseSize(volumeName)); VolumeEntity volume = new VolumeEntity();
//TODO volume.setName(volumeName);
// volume.setBrick(brick); List<String> path = volumeInfo.getVolumeMountPoint(volumeName);
if (null != volume.getPath()) { //默认加载第一个路径
// volume.setFolder(gfsTree.getDatas(volume.getPath())); if (null != path && path.size() > 0) {
volume.setFolder(getFolder(path)); volume.setPath(path.get(0));
} }
volumeList.add(volume); volume.setAllSize(volumeInfo.getVolumeAllSize(volumeName));
} volume.setUsedSize(volumeInfo.getVolumeUseSize(volumeName));
//TODO 查询brick--
return volumeList; //返回 ip:path
} List<String> brickStrs = volumeInfo.getVolumeBricks(volumeName);
//brick已用大小
@Override Map<String, Double> usedSize = volumeInfo.getVolumebricksDataSize(volumeName);
public VolumeEntity getOneVolume(String volumeName) throws Exception { Map<String, Double> availableSize = volumeInfo.getVolumebricksAvailableSize(volumeName);
VolumeEntity volume = new VolumeEntity(); List<Brick> brickList = new ArrayList<Brick>();
volume.setName(volumeName); for (String brickIpPath : brickStrs) {
String path = volumeInfo.getVolumeMountPoint(volumeName); Brick b = new Brick();
volume.setPath(path); String ipAndpath[] = brickIpPath.split(":");
// volume.setAllSize(volumeInfo.getVolumeAllSize(volumeName)); String brickip = ipAndpath[0];
// volume.setUsedSize(volumeInfo.getVolumeUseSize(volumeName)); String brickpath = ipAndpath[1];
// volume.setBrick(brick); //iP , path ,
if (null != volume.getPath()) { b.setIp(brickip);
volume.setFolder(getFolder(path)); b.setPath(brickpath);
} b.setAvailableSize(availableSize.get(brickIpPath));
return volume; b.setUsedSize(usedSize.get(brickIpPath));
} brickList.add(b);
}
@Override volume.setBrick(brickList);
public int moveData(String volumeName, String srcPath, String dstPath) if (null != volume.getPath()) {
throws Exception { // 获得 folder 目录
volume.setFolder(getFolder(volume.getPath()));
int result = copydata.copyFolderFiles(srcPath, dstPath, "app"); }
return result; volumeList.add(volume);
} }
return volumeList;
@Override }
public int deleteData(String volumeName, String srcPath) throws Exception {
// TODO Auto-generated method stub @Override
return 0; public VolumeEntity getOneVolume(String volumeName) throws Exception {
} 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.getVolumeAllSize(volumeName));
volume.setUsedSize(volumeInfo.getVolumeUseSize(volumeName));
// volume.setBrick(brick);
if (null != volume.getPath()) {
volume.setFolder(getFolder(path.get(0)));
}
return volume;
}
@Override
public int moveData(String volumeName, String srcPath, String dstPath)
throws Exception {
int result = copydata.copyFolderFiles(srcPath, dstPath, "app");
return result;
}
@Override
public int deleteData(String volumeName, String srcPath) throws Exception {
// TODO Auto-generated method stub
return 0;
}
}

@ -1,18 +1,19 @@
package com.platform.utils; package com.platform.utils;
import com.platform.entities.FolderNode; import java.util.List;
public class CacheTreeData { import com.platform.entities.FolderNode;
private static FolderNode folders = null; public class CacheTreeData {
public static FolderNode getFolders() { private static List<FolderNode> folders = null;
return folders;
} public static List<FolderNode> getFolders() {
return folders;
public static void setFolders(FolderNode folders) { }
CacheTreeData.folders = folders;
} public static void setFolders(List<FolderNode> folders) {
CacheTreeData.folders = folders;
}
}
}

@ -1,74 +1,74 @@
package com.platform.utils; package com.platform.utils;
import java.util.Properties; import java.util.Properties;
import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener; import javax.servlet.ServletContextListener;
public class ConfigsLoader implements ServletContextListener { public class ConfigsLoader implements ServletContextListener {
private static ConfigPropertyReader cReader = null; private static ConfigPropertyReader cReader = null;
@Override @Override
public void contextDestroyed(ServletContextEvent sEvent) { public void contextDestroyed(ServletContextEvent sEvent) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
Configs.CONSOLE_LOGGER.info("系统停止.."); Configs.CONSOLE_LOGGER.info("系统停止..");
} }
@SuppressWarnings("static-access") @SuppressWarnings("static-access")
@Override @Override
public void contextInitialized(ServletContextEvent sEvent) { public void contextInitialized(ServletContextEvent sEvent) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
Configs.CONSOLE_LOGGER.info("系统初始化.."); Configs.CONSOLE_LOGGER.info("系统初始化..");
String contextPath = sEvent.getServletContext().getRealPath("/") String contextPath = sEvent.getServletContext().getRealPath("/")
+ "WEB-INF/config/config.properties"; + "WEB-INF/config/config.properties";
this.cReader = ConfigPropertyReader.Builder(contextPath); this.cReader = ConfigPropertyReader.Builder(contextPath);
init(); init();
new VolumeThread("").start(); new ThreadVolume("").start();
} }
public static void init() { public static void init() {
Properties properties = cReader.getProperties(); Properties properties = cReader.getProperties();
Configs.KUBE_MASTER_URL = properties.getProperty("kubeMasterUrl"); Configs.KUBE_MASTER_URL = properties.getProperty("kubeMasterUrl");
Configs.COLLECT_USER_NAME = properties.getProperty("collect-user-name"); Configs.COLLECT_USER_NAME = properties.getProperty("collect-user-name");
Configs.COLLECT_PASSWORD = properties.getProperty("collect-password"); Configs.COLLECT_PASSWORD = properties.getProperty("collect-password");
Configs.COLLECT_SERVICE_NAME = properties Configs.COLLECT_SERVICE_NAME = properties
.getProperty("collect-service-name"); .getProperty("collect-service-name");
Configs.GATHER_USER_NAME = properties.getProperty("gather-user-name"); Configs.GATHER_USER_NAME = properties.getProperty("gather-user-name");
Configs.GATHER_USER_PASSWORD = properties Configs.GATHER_USER_PASSWORD = properties
.getProperty("gather-user-password"); .getProperty("gather-user-password");
Configs.GATHER_PORT = properties.getProperty("gather-port"); Configs.GATHER_PORT = properties.getProperty("gather-port");
Configs.GATHER_SERVICE_NAME = properties Configs.GATHER_SERVICE_NAME = properties
.getProperty("gather-service-name"); .getProperty("gather-service-name");
Configs.TABLE_SUFFIX = properties.getProperty("table-suffix"); Configs.TABLE_SUFFIX = properties.getProperty("table-suffix");
Configs.EXTRACT_LOG_LOCALTION = properties Configs.EXTRACT_LOG_LOCALTION = properties
.getProperty("extract-log-localtion"); .getProperty("extract-log-localtion");
Configs.GATHER_TABLESPACE_NAME = properties Configs.GATHER_TABLESPACE_NAME = properties
.getProperty("gather-tablespace-name"); .getProperty("gather-tablespace-name");
Configs.GATHER_TABLESPACE_PATH = properties Configs.GATHER_TABLESPACE_PATH = properties
.getProperty("gather-tablespace-path"); .getProperty("gather-tablespace-path");
Configs.GATHER_TABLE_PASSWORD=properties.getProperty("gather-table-user-password"); Configs.GATHER_TABLE_PASSWORD=properties.getProperty("gather-table-user-password");
} }
public ConfigPropertyReader getcReader() { public ConfigPropertyReader getcReader() {
return cReader; return cReader;
} }
@SuppressWarnings("static-access") @SuppressWarnings("static-access")
public void setcReader(ConfigPropertyReader cReader) { public void setcReader(ConfigPropertyReader cReader) {
this.cReader = cReader; this.cReader = cReader;
} }
} }

@ -1,24 +1,32 @@
package com.platform.utils; package com.platform.utils;
import java.util.List;
public class Constant {
public class Constant { public static String rootUser = "root";
public static String rootUser = "root"; public static String rootPasswd = "root";
public static String rootPasswd = "root"; public static String hostIp = "192.168.0.110";
public static String hostIp = "192.168.0.116"; // public static String hostIp = "192.168.1.105";
public static int port = 22; public static int port = 22;
public static String glusterPeerStatus = "gluster peer status"; public static String glusterPeerStatus = "gluster peer status";
public static String glusterVolumeInfo = "gluster volume info "; public static String glusterVolumeInfo = "gluster volume info ";
public static String df = "df -k "; public static String df = "df -k ";
public static String peerincluster_connected="PeerinCluster(Connected)"; public static String peerincluster_connected="PeerinCluster(Connected)";
public static String distributed="distributed"; public static String peerincluster_disconnected="PeerinCluster(Disconnected)";
public static String replica="replica"; public static String distributed="distributed";
public static String stripe="stripe"; public static String replica="replica";
public static String noVolume="No volumes present"; public static String stripe="stripe";
public static GanymedSSH ganymedSSH=new GanymedSSH(hostIp, rootUser, rootPasswd, port); public static String noVolume="No volumes present";
public static GanymedSSH ganymedSSH=new GanymedSSH(hostIp, rootUser, rootPasswd, port);
/** public static String fileGetTreeData="./WEB-INF/config/getTreedata.sh";
* volume 线
*/ /**
public final static int get_volume_sleep_time = 300000; * volume 线
} */
public final static int get_volume_sleep_time = 300000;
/**
* volume 线
*/
public final static int update_dataInfo_sleep_time = 3000;
}

@ -59,4 +59,28 @@ public class FileOperateHelper {
} }
return sb.toString(); return sb.toString();
} }
/**
*
* @param path
* @return
*/
@SuppressWarnings("resource")
public static String fileReaderAndendline(String path) {
StringBuffer sb = new StringBuffer();
String tempString = "";
try {
File file = new File(path);
if (!file.exists())
return "";
FileInputStream fis = new FileInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
while ((tempString = br.readLine()) != null) {
sb.append(tempString+"\n");
}
} catch (Exception e) {
// TODO: handle exception
}
return sb.toString();
}
} }

@ -1,265 +1,267 @@
package com.platform.utils; package com.platform.utils;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator; import org.apache.log4j.PropertyConfigurator;
import ch.ethz.ssh2.Connection; import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.Session; import ch.ethz.ssh2.Session;
import ch.ethz.ssh2.StreamGobbler; import ch.ethz.ssh2.StreamGobbler;
import ch.ethz.ssh2.*; import ch.ethz.ssh2.*;
public class GanymedSSH { public class GanymedSSH {
public static Logger log = Logger.getLogger(GanymedSSH.class); public static Logger log = Logger.getLogger(GanymedSSH.class);
Connection conn; Connection conn;
public boolean status = true;// 锟角凤拷锟斤拷锟街达拷锟斤拷锟斤拷锟阶刺<E998B6> public boolean status = true;// 锟角凤拷锟斤拷锟街达拷锟斤拷锟斤拷锟阶刺<E998B6>
public GanymedSSH() { public GanymedSSH() {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
public GanymedSSH(String host, String username, String password, int port) { public GanymedSSH(String host, String username, String password, int port) {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
try { try {
conn = getOpenedConnection(host, username, password, port); conn = getOpenedConnection(host, username, password, port);
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
} }
public Connection getOpenedConnection(String host, String username, String password, int port) public Connection getOpenedConnection(String host, String username, String password, int port)
throws IOException { throws IOException {
conn = new Connection(host, port); conn = new Connection(host, port);
conn.connect(); // make sure the connection is opened conn.connect(); // make sure the connection is opened
boolean isAuthenticated = conn.authenticateWithPassword(username, password); boolean isAuthenticated = conn.authenticateWithPassword(username, password);
if (isAuthenticated == false) if (isAuthenticated == false)
throw new IOException("Authentication failed."); throw new IOException("Authentication failed.");
return conn; return conn;
} }
public void execCmdNoWaitAcquiescent(String cmd) { public void execCmdNoWaitAcquiescent(String cmd) {
String host=Constant.hostIp; String host=Constant.hostIp;
String username=Constant.rootUser; String username=Constant.rootUser;
String password=Constant.rootPasswd; String password=Constant.rootPasswd;
int port=Constant.port; int port=Constant.port;
Session sess = null; Session sess = null;
try { try {
conn = getOpenedConnection(host, username, password, port); conn = getOpenedConnection(host, username, password, port);
sess = conn.openSession(); sess = conn.openSession();
// 执锟斤拷cmd // 执锟斤拷cmd
sess.execCommand(cmd); sess.execCommand(cmd);
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
sess.close(); sess.close();
} }
} }
public void execCmdNoWait(String host, String username, String password, int port, String cmd) { public void execCmdNoWait(String host, String username, String password, int port, String cmd) {
Session sess = null; Session sess = null;
try { try {
conn = getOpenedConnection(host, username, password, port); conn = getOpenedConnection(host, username, password, port);
sess = conn.openSession(); sess = conn.openSession();
// 执锟斤拷cmd // 执锟斤拷cmd
sess.execCommand(cmd); sess.execCommand(cmd);
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
sess.close(); sess.close();
} }
} }
public List<String> execCmdWaitAcquiescent(String cmd) { public List<String> execCmdWaitAcquiescent(String cmd) {
String host=Constant.hostIp; String host=Constant.hostIp;
String username=Constant.rootUser; String username=Constant.rootUser;
String password=Constant.rootPasswd; String password=Constant.rootPasswd;
int port=Constant.port; int port=Constant.port;
List<String> reStrings = new ArrayList<String>(); List<String> reStrings = new ArrayList<String>();
Session sess = null; Session sess = null;
try { try {
sess = conn.openSession(); sess = conn.openSession();
// 执锟斤拷cmd // 执锟斤拷cmd
sess.execCommand(cmd); sess.execCommand(cmd);
InputStream stdout = new StreamGobbler(sess.getStdout()); InputStream stdout = new StreamGobbler(sess.getStdout());
InputStream stderr = new StreamGobbler(sess.getStderr()); InputStream stderr = new StreamGobbler(sess.getStderr());
BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(stdout)); BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(stdout));
BufferedReader stderrReader = new BufferedReader(new InputStreamReader(stderr)); BufferedReader stderrReader = new BufferedReader(new InputStreamReader(stderr));
while (true) { while (true) {
String line = stdoutReader.readLine(); String line = stdoutReader.readLine();
if (line != null) { if (line != null) {
// System.out.println(line); // System.out.println(line);
reStrings.add(line); reStrings.add(line);
} else { } else {
break; break;
} }
} }
if(reStrings.size()==0){
while (true) { while (true) {
String line = stderrReader.readLine(); String line = stderrReader.readLine();
if (line != null) { if (line != null) {
// System.out.println(line); // System.out.println(line);
reStrings.add(line); reStrings.add(line);
} else { } else {
break; break;
} }
} }
} catch (IOException e) { }
// TODO Auto-generated catch block } catch (IOException e) {
e.printStackTrace(); // TODO Auto-generated catch block
} finally { e.printStackTrace();
sess.close(); } finally {
sess.close();
}
return reStrings; }
} return reStrings;
}
public List<String> execCmdWait(String host, String username, String password, int port, String cmd) {
List<String> reStrings = new ArrayList<String>(); public List<String> execCmdWait(String host, String username, String password, int port, String cmd) {
List<String> reStrings = new ArrayList<String>();
Session sess = null;
try { Session sess = null;
try {
sess = conn.openSession();
// 执锟斤拷cmd sess = conn.openSession();
sess.execCommand(cmd); // 执锟斤拷cmd
sess.execCommand(cmd);
InputStream stdout = new StreamGobbler(sess.getStdout());
InputStream stderr = new StreamGobbler(sess.getStderr()); InputStream stdout = new StreamGobbler(sess.getStdout());
BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(stdout)); InputStream stderr = new StreamGobbler(sess.getStderr());
BufferedReader stderrReader = new BufferedReader(new InputStreamReader(stderr)); BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(stdout));
while (true) { BufferedReader stderrReader = new BufferedReader(new InputStreamReader(stderr));
String line = stdoutReader.readLine(); while (true) {
String line = stdoutReader.readLine();
if (line != null) {
// System.out.println(line); if (line != null) {
reStrings.add(line); // System.out.println(line);
} else { reStrings.add(line);
break; } else {
} break;
} }
}
while (true) { if(reStrings.size()==0){
String line = stderrReader.readLine(); while (true) {
String line = stderrReader.readLine();
if (line != null) {
// System.out.println(line); if (line != null) {
reStrings.add(line); // System.out.println(line);
} else { reStrings.add(line);
break; } else {
} break;
} }
} catch (IOException e) { }
// TODO Auto-generated catch block }
e.printStackTrace(); } catch (IOException e) {
} finally { // TODO Auto-generated catch block
sess.close(); e.printStackTrace();
} finally {
} sess.close();
return reStrings;
} }
return reStrings;
public Map<String, String> execMD5cmd(String host, String username, String password, int port, String cmd, }
String prefix) {
Map<String, String> md5 = new HashMap<String, String>(); public Map<String, String> execMD5cmd(String host, String username, String password, int port, String cmd,
String prefix) {
Map<String, String> md5 = new HashMap<String, String>();
Session sess = null;
try {
Session sess = null;
sess = conn.openSession(); try {
// 执锟斤拷cmd
sess.execCommand(cmd); sess = conn.openSession();
InputStream stdout = new StreamGobbler(sess.getStdout()); // 执锟斤拷cmd
sess.execCommand(cmd);
@SuppressWarnings("resource") InputStream stdout = new StreamGobbler(sess.getStdout());
BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
while (true) { @SuppressWarnings("resource")
String line = br.readLine(); BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
if (line != null) { while (true) {
String[] lines = line.split(" "); String line = br.readLine();
String key = lines[1].replace(prefix, ""); if (line != null) {
String value = lines[0]; String[] lines = line.split(" ");
md5.put(key, value); String key = lines[1].replace(prefix, "");
// System.out.println(key+"\t"+value); String value = lines[0];
} else { md5.put(key, value);
break; // System.out.println(key+"\t"+value);
} } else {
break;
} }
} catch (IOException e) {
// TODO Auto-generated catch block }
e.printStackTrace(); } catch (IOException e) {
} finally { // TODO Auto-generated catch block
sess.close(); e.printStackTrace();
} finally {
} sess.close();
return md5;
} }
return md5;
public String execGetSize(String cmd) { }
status = false;
String str_size = "0"; public String execGetSize(String cmd) {
Session sess = null; status = false;
try { String str_size = "0";
Session sess = null;
// 执锟斤拷cmd try {
sess = conn.openSession();
sess.execCommand(cmd); // 执锟斤拷cmd
InputStream stdout = new StreamGobbler(sess.getStdout()); sess = conn.openSession();
sess.execCommand(cmd);
@SuppressWarnings("resource") InputStream stdout = new StreamGobbler(sess.getStdout());
BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
while (true) { @SuppressWarnings("resource")
String line = br.readLine(); BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
if (line != null) { while (true) {
// String[] lines=line.split(" "); String line = br.readLine();
// str_size=lines[0]; if (line != null) {
// String[] lines=line.split(" ");
str_size = line; // str_size=lines[0];
} else {
break; str_size = line;
} } else {
break;
} }
} catch (IOException e) {
// TODO Auto-generated catch block }
e.printStackTrace(); } catch (IOException e) {
} finally { // TODO Auto-generated catch block
sess.close(); e.printStackTrace();
} } finally {
status = true; sess.close();
return str_size; }
} status = true;
public static void main(String[] args) { return str_size;
PropertyConfigurator.configure("log4j.properties"); }
} public static void main(String[] args) {
PropertyConfigurator.configure("log4j.properties");
} }
}

@ -0,0 +1,31 @@
package com.platform.utils;
public class ThreadMoveData extends Thread {
/**
* : --
*/
public ThreadMoveData() {
// TODO Auto-generated constructor stub
}
/* (non-Javadoc)
* @see java.lang.Thread#run()
*
*/
@Override
public void run() {
// TODO Auto-generated method stub
super.run();
//查询 表 move_data_tmp
try {
Thread.sleep(Constant.update_dataInfo_sleep_time);
} catch (InterruptedException e) {
}
}
}

@ -0,0 +1,73 @@
package com.platform.utils;
import java.util.ArrayList;
import java.util.List;
import com.platform.entities.FolderNode;
import com.platform.entities.VolumeEntity;
import com.platform.glusterfs.GetTreeData;
import com.platform.glusterfs.VolumeInfo;
public class ThreadVolume extends Thread implements Runnable{
/**
* --
*/
private static String pointPath = "/home";
/** Volume信息查询 */
private VolumeInfo volumeInfo = new VolumeInfo();
public ThreadVolume() {
// TODO Auto-generated constructor stub
}
public ThreadVolume(String path) {
if (null != path && !"".equals(path.trim())) {
ThreadVolume.pointPath = path;
}
}
/** gfs目录树形展示 */
private GetTreeData gfsTree = new GetTreeData();
@Override
public void run() {
super.run();
while(true){
List<FolderNode> folderlist = new ArrayList<FolderNode>();
//查询 volume name
List<String> volumeNameList = volumeInfo.showAllVolumeName();
if (null != volumeNameList) {
for (String volumeName : volumeNameList) {
VolumeEntity volume = new VolumeEntity();
volume.setName(volumeName);
List<String> path = volumeInfo.getVolumeMountPoint(volumeName);
//默认加载第一个路径
if (null != path && path.size() > 0) {
//装入 folder
//查询 每个 volume 下的 folder
FolderNode foldertmp = gfsTree.getDatas(path.get(0));
folderlist.add(foldertmp);
}
}
}
//TODO 更新folder 目录
CacheTreeData.setFolders(folderlist);
try {
Thread.sleep(Constant.get_volume_sleep_time);
} catch (InterruptedException e) {
}
}
}
public static String getPointPath() {
return pointPath;
}
public static void setPointPath(String pointPath) {
ThreadVolume.pointPath = pointPath;
}
}

@ -1,52 +0,0 @@
package com.platform.utils;
import java.util.List;
import com.platform.entities.FolderNode;
import com.platform.glusterfs.GetTreeData;
import com.platform.glusterfs.VolumeInfo;
public class VolumeThread extends Thread implements Runnable{
/**
*
*/
private static String pointPath = "/home";
public VolumeThread() {
// TODO Auto-generated constructor stub
}
public VolumeThread(String path) {
if (null != path && !"".equals(path.trim())) {
VolumeThread.pointPath = path;
}
}
/** gfs目录树形展示 */
private GetTreeData gfsTree = new GetTreeData();
@Override
public void run() {
super.run();
while(true){
FolderNode folders = gfsTree.getDatas(pointPath);
//TODO
CacheTreeData.setFolders(folders);
try {
Thread.sleep(Constant.get_volume_sleep_time);
} catch (InterruptedException e) {
}
}
}
public static String getPointPath() {
return pointPath;
}
public static void setPointPath(String pointPath) {
VolumeThread.pointPath = pointPath;
}
}

@ -11,11 +11,17 @@ public class getTreeDataByPath {
* @return * @return
*/ */
public FolderNode findByPath(String path) { public FolderNode findByPath(String path) {
FolderNode folderNode = CacheTreeData.getFolders(); List<FolderNode> folderNodelist = CacheTreeData.getFolders();
if (null == folderNode) { if (null == folderNodelist) {
return null; return null;
} }
FolderNode folder = getFolder(folderNode, path); FolderNode folder = null;
for (FolderNode folderNode : folderNodelist) {
folder = getFolder(folderNode, path);
if (null != folder) {
break;
}
}
return folder; return folder;
} }

@ -21,8 +21,6 @@ public class FolderReader {
childrens.add(children); childrens.add(children);
} }
} }
/*folderNode = new FolderNode(file.getName(), file.getAbsolutePath(),
childrens);*/
} }
return folderNode; return folderNode;
} }

Loading…
Cancel
Save