diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index d1ff3f7e..8e68fb09 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -1,2 +1,4 @@ eclipse.preferences.version=1 encoding//WebContent/WEB-INF/config/config.properties=UTF-8 +encoding//src/com/platform/controller/DataModelController.java=UTF-8 +encoding/<project>=UTF-8 diff --git a/WebContent/WEB-INF/lib/commons-beanutils-1.7.0.jar b/WebContent/WEB-INF/lib/commons-beanutils-1.7.0.jar new file mode 100644 index 00000000..b1b89c9c Binary files /dev/null and b/WebContent/WEB-INF/lib/commons-beanutils-1.7.0.jar differ diff --git a/WebContent/WEB-INF/lib/commons-collections-3.2.jar b/WebContent/WEB-INF/lib/commons-collections-3.2.jar new file mode 100644 index 00000000..75580be2 Binary files /dev/null and b/WebContent/WEB-INF/lib/commons-collections-3.2.jar differ diff --git a/WebContent/WEB-INF/lib/ezmorph-1.0.4.jar b/WebContent/WEB-INF/lib/ezmorph-1.0.4.jar new file mode 100644 index 00000000..7625af67 Binary files /dev/null and b/WebContent/WEB-INF/lib/ezmorph-1.0.4.jar differ diff --git a/WebContent/WEB-INF/lib/ganymed-ssh2-build209.jar b/WebContent/WEB-INF/lib/ganymed-ssh2-build209.jar new file mode 100644 index 00000000..95f233ce Binary files /dev/null and b/WebContent/WEB-INF/lib/ganymed-ssh2-build209.jar differ diff --git a/WebContent/WEB-INF/lib/json-lib-2.2.2-jdk15.jar b/WebContent/WEB-INF/lib/json-lib-2.2.2-jdk15.jar new file mode 100644 index 00000000..27e7c7cc Binary files /dev/null and b/WebContent/WEB-INF/lib/json-lib-2.2.2-jdk15.jar differ diff --git a/src/META-INF/persistence.xml b/src/META-INF/persistence.xml new file mode 100644 index 00000000..2ad4aeca --- /dev/null +++ b/src/META-INF/persistence.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8"?> +<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> + <persistence-unit name="aggregation-platform"> + </persistence-unit> +</persistence> diff --git a/src/com/base/BaseController.java b/src/com/base/BaseController.java new file mode 100644 index 00000000..a9fd417a --- /dev/null +++ b/src/com/base/BaseController.java @@ -0,0 +1,63 @@ +/** + * 文件名 : BaseController.java + * 版权 : XX科技有限公司。 + * 描述 : <描述> + * 修改时间:2016年9月7日 + * 修改内容:<修改内容> + */ +package com.base; + +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; +import org.springframework.web.bind.annotation.ExceptionHandler; + +import com.platform.utils.Configs; + +/** + * <一句话功能简述> + * <功能详细描述> + * @author chen + * @version [版本号,2016年9月7日] + * @see [相关类/方法] + * @since [产品/模块版本] + */ +public class BaseController { + + /** log4j */ + public static Logger log = Logger.getRootLogger(); + + /** + * <一句话功能简述> 基于@ExceptionHandler异常处理----全局异常处理 + * <功能详细描述> + * @param request + * @param ex 异常 + * @return + * @see [类、类#方法、类#成员] + */ + @ExceptionHandler + public Object exp(HttpServletRequest request, HttpServletResponse response,Exception ex) { + System.out.println("URI"+request.getRequestURI()); + request.setAttribute("ex", ex); + System.err.println("BaseController --exp "); + // 根据不同错误转向不同页面 + if(ex instanceof CustomException) { + CustomException cuse = (CustomException) ex; + Map<String, String> errmsg = new HashMap<>(); + errmsg.put("code", cuse.getCode()); + errmsg.put("msg", cuse.getMsg()); + log.error(cuse.getCode()); + response.setStatus(500); + return response; + } else { + //其他错误则 调到指定页面 + log.error(Configs.GLOBAL_EXP_NOT_CUSTOM, ex); + response.setStatus(500); + return response; + } + } +} \ No newline at end of file diff --git a/src/com/base/Constant.java b/src/com/base/Constant.java new file mode 100644 index 00000000..4d336465 --- /dev/null +++ b/src/com/base/Constant.java @@ -0,0 +1,23 @@ +package com.base; + +/** + * <一句话功能简述> + * <功能详细描述> + * @author chen + * @version [版本号,2016年9月8日] + * @see [相关类/方法] + * @since [产品/模块版本] + */ +public class Constant { + + /** 国际话配置文件文件-i18n.properties */ + public static String I18N_PROPERTIES_FIEL_PATH = "/com/base/i18n.properties"; + + /** WritefileThread-线程睡眠时间--3000 */ + public final static long THREAD_SLEEP_WRITEFILETHREAD = 3000; + + /** CustomException记录报异常的对象的对象个数--10 */ + public final static int CustomException_log_object_size = 10; + + +} diff --git a/src/com/base/Custom4exception.java b/src/com/base/Custom4exception.java new file mode 100644 index 00000000..2aeba6c6 --- /dev/null +++ b/src/com/base/Custom4exception.java @@ -0,0 +1,20 @@ +package com.base; + +/** + * <一句话功能简述> 异常常量编码 + * <功能详细描述> + * @author chen + * @version [版本号,2016年9月8日] + * @see [相关类/方法] + * @since [产品/模块版本] + */ +public class Custom4exception { + //3003001001 : 第一位:标识异常, 第二到第四位:标识模块,第五道第七位:标识类别,第八道第十位标识具体异常 + /**eg + * 3:异常 + * 003:虚拟机模块 + * 001:软件依赖虚拟机资源类别 + * 001:启动异常 + */ + +} diff --git a/src/com/base/CustomException.java b/src/com/base/CustomException.java new file mode 100644 index 00000000..42b44cfb --- /dev/null +++ b/src/com/base/CustomException.java @@ -0,0 +1,124 @@ +package com.base; + +import org.apache.log4j.Logger; + +/** + * <一句话功能简述> + * <功能详细描述> + * @author chen + * @version [版本号,2016年9月8日] + * @see [相关类/方法] + * @since [产品/模块版本] + */ +@SuppressWarnings("serial") +public class CustomException extends Exception { + + /** log4j */ + public static Logger log = Logger.getRootLogger(); + + /** 自定义异常信息-错误信息 */ + private String msg; + + /** 自定义异常信息-错误代码 */ + private String code; + + /** 操作对象 */ + private Object[] objArray; + + /** 异常 */ + private Throwable cause; + + public CustomException() { + super(); + } + + /** + * @功能 将异常记录进文件 + * @param code 异常编码 + * @param msg 自定义异常信息 + * @param e + * @param obj + */ + public CustomException(String code,Exception e,Object... obj) { + super(code); + StringBuffer sbuf= new StringBuffer(); + sbuf.append(msg); + this.code = code; + sbuf.append(code); + sbuf.append("\r\n"); + msg = Resource.getProperties().get(code); + // 记录自定义的 异常 + if (null != msg) { + sbuf.append(msg); + sbuf.append("\r\n"); + } + // 记录原始的异常 + if (null != e) { + StackTraceElement[] array = e.getStackTrace(); + cause = e.getCause(); + for (StackTraceElement stackTraceElement : array) { + sbuf.append(stackTraceElement.toString()); + sbuf.append("\r\n"); + } + } + //记录 出现异常时 当前的对象 + if (null != obj) { + Object[] array = obj; + sbuf.append("Object[] size : "); + sbuf.append(array.length); + int forSize = 0; + if (Constant.CustomException_log_object_size < array.length) { + forSize = Constant.CustomException_log_object_size; + } + else { + forSize = array.length; + } + for (int i = 0; i < forSize; i++) { + sbuf.append(array[i]); + sbuf.append("\r\n"); + } + sbuf.append("......"); + sbuf.append("\r\n"); + } + else { + sbuf.append("null"); + sbuf.append("\r\n"); + } + + sbuf.append("\r\n"); + // 是否 写入 文件 + log.error(sbuf.toString()); + } + + /** + * @功能 获得msg + * @return msg + */ + public String getMsg() { + return msg; + } + + + /** + * @return the code + */ + public String getCode() { + return code; + } + + /** + * @功能 获得objArray + * @return objArray + */ + public Object[] getObjArray() { + return objArray; + } + + /** + * @功能 获得cause + * @return cause + */ + public Throwable getCause() { + return cause; + } +} diff --git a/src/com/base/Resource.java b/src/com/base/Resource.java new file mode 100644 index 00000000..0b900bfe --- /dev/null +++ b/src/com/base/Resource.java @@ -0,0 +1,79 @@ +package com.base; + +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Properties; + +import com.base.Constant; + +public class Resource { + + private static Map<String, String> properties = new HashMap<>(); + + static{ + // 读取 properties文件 +// readPropertiesFile(Constant.SYSTEM_PROPERTIES_FIEL_PATH); + readPropertiesFile4Chinese(Constant.I18N_PROPERTIES_FIEL_PATH); + + } + + /** + * @功能 读取配置(解决中文乱码) + * @param filename "/com/utils/exception/i18n.properties" 的格式 + */ + public static void readPropertiesFile4Chinese(String filename) { + Properties pro = new Properties(); + try { + // 读取属性文件 XXXX.properties(Reader。writer解决中文乱码) +// InputStreamReader in= new InputStreamReader(Resource.class.getClassLoader().getResourceAsStream(filename), "UTF-8"); + InputStreamReader in= new InputStreamReader(Resource.class.getResourceAsStream(filename), "UTF-8"); + BufferedReader bf = new BufferedReader(in); + // InputStreamReader in = new BufferedInputStream(new FileInputStream(filename)); + pro.load(bf); // /加载属性列表 + Iterator<String> it = pro.stringPropertyNames().iterator(); + while (it.hasNext()) { + String key = it.next(); + properties.put(key, pro.getProperty(key)); + } + in.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * @功能 获得properties + * @return properties + */ + public static Map<String, String> getProperties() { + return properties; + } + + /** + * @功能 读取配置 + * @param filename 文件绝对路径 + */ + public static void readPropertiesFile(String filename) { + Properties pro = new Properties(); + try { + // 读取属性文件 XXXX.properties( 中文会 乱码) + BufferedInputStream bf = new BufferedInputStream(new FileInputStream(filename)); + pro.load(bf); // /加载属性列表 + Iterator<String> it = pro.stringPropertyNames().iterator(); + while (it.hasNext()) { + String key = it.next(); + properties.put(key, pro.getProperty(key)); + } + bf.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + +} diff --git a/src/com/base/i18n.properties b/src/com/base/i18n.properties new file mode 100644 index 00000000..e69de29b diff --git a/src/com/dao/mapper/config-details-mapper.xml b/src/com/dao/mapper/config-details-mapper.xml index afbe9f85..439d4f98 100644 --- a/src/com/dao/mapper/config-details-mapper.xml +++ b/src/com/dao/mapper/config-details-mapper.xml @@ -4,16 +4,143 @@ PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN" "http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd"> <mapper namespace="com.platform.dao.GatherOracleDao"> - <resultMap type="GatherOracleInfo" id="getEntityBytext"> - <id property="_id" column="id" javaType="int" jdbcType="INTEGER" /> + <resultMap type="com.platform.entities.GatherOracleInfo" id="getEntityBytext"> + <id property="id" column="id" javaType="int" jdbcType="INTEGER" /> <result property="port" column="service_port" javaType="int" jdbcType="INTEGER"/> <result property="ip" column="service_ip" javaType="string" jdbcType="VARCHAR"/> <result property="name" column="service_name" javaType="string" jdbcType="VARCHAR"/> <result property="user" column="service_user" javaType="string" jdbcType="VARCHAR"/> <result property="password" column="service_password" javaType="string" jdbcType="VARCHAR"/> - <result property="database" column="service_database" javaType="string" jdbcType="VARCHAR"/> + <result property="databaseName" column="service_database" javaType="string" jdbcType="VARCHAR"/> <result property="tableName" column="service_table" javaType="string" jdbcType="VARCHAR"/> <result property="suffix" column="service_suffix" javaType="string" jdbcType="VARCHAR"/> <result property="status" column="service_status" javaType="string" jdbcType="VARCHAR"/> + <result property="remove" column="remove" jdbcType="CHAR"/> </resultMap> + <sql id="baseOracleInfo"> + id id, service_port port, service_ip ip, service_name name, service_user user, service_password password, service_database databaseName, service_table tableName, service_suffix suffix, service_status status + </sql> + + <select id="selectAllOracle" resultType="com.platform.entities.GatherOracleInfo"> + SELECT + <include refid="baseOracleInfo" /> + FROM services_info + WHERE remove = "0" + </select> + + <insert id="insertOracle" parameterType="com.platform.entities.GatherOracleInfo"> + INSERT INTO + services_info( + <trim suffixOverrides=","> + <if test="port > 0"> + service_port, + </if> + <if test="ip != null and ip != ''"> + service_ip, + </if> + <if test="name != null and name != ''"> + service_name, + </if> + <if test="user != null and user != ''"> + service_user, + </if> + <if test="password != null and password != ''"> + service_password, + </if> + <if test="databaseName != null and databaseName != ''"> + service_database, + </if> + <if test="tableName != null and tableName != ''"> + service_table, + </if> + <if test="suffix != null and suffix != ''"> + service_suffix, + </if> + <if test="status != null and status != ''"> + service_status, + </if> + </trim> + ) + VALUES( + <trim suffixOverrides=","> + <if test="port > 0"> + #{port}, + </if> + <if test="ip != null and ip != ''"> + #{ip}, + </if> + <if test="name != null and name != ''"> + #{name}, + </if> + <if test="user != null and user != ''"> + #{user}, + </if> + <if test="password != null and password != ''"> + #{password}, + </if> + <if test="databaseName != null and databaseName != ''"> + #{databaseName}, + </if> + <if test="tableName != null and tableName != ''"> + #{tableName}, + </if> + <if test="suffix != null and suffix != ''"> + #{suffix}, + </if> + <if test="status != null and status != ''"> + #{status}, + </if> + </trim> + ) + </insert> + + <delete id="deleteOracleById" parameterType="java.lang.Integer"> + DELETE FROM services_info + <where> + id =#{id} + </where> + </delete> + + <update id="updateOracleById" parameterType="com.platform.entities.GatherOracleInfo"> + UPDATE + services_info + <set > + <trim suffixOverrides=","> + <if test="name != null and name != ''"> + service_name = #{name}, + </if> + <if test="ip != null and ip != ''"> + service_ip = #{ip}, + </if> + <if test="port > 0"> + service_port= #{port}, + </if> + <if test="user != null and user != ''"> + service_user= #{user}, + </if> + <if test="password != null and password != ''"> + service_password= #{password}, + </if> + <if test="databaseName != null and databaseName != ''"> + service_database= #{databaseName}, + </if> + <if test="tableName != null and tableName != ''"> + service_table= #{tableName}, + </if> + <if test="suffix != null and suffix != ''"> + service_suffix= #{suffix}, + </if> + <if test="status != null and status != ''"> + service_status= #{status}, + </if> + <if test="remove != null and remove != ''"> + remove= #{remove}, + </if> + </trim> + </set> + <where> + id = #{id} + </where> + </update> + </mapper> \ No newline at end of file diff --git a/src/com/platform/controller/DataModelController.java b/src/com/platform/controller/DataModelController.java index 8e30cce0..29414e6d 100644 --- a/src/com/platform/controller/DataModelController.java +++ b/src/com/platform/controller/DataModelController.java @@ -10,28 +10,42 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import net.sf.json.JSONObject; + import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; +import com.base.BaseController; +import com.platform.entities.DataInfoEntity; import com.platform.entities.FolderNode; import com.platform.entities.GatherOracleInfo; -import com.platform.entities.OracleConnectorParams; import com.platform.entities.PagerOptions; +import com.platform.entities.VolumeEntity; import com.platform.service.DataInfoService; +import com.platform.service.IGfsService; +import com.platform.service.IMySqlService; +import com.platform.service.IOracleExtractService; import com.platform.service.OracleStatusService; -import com.platform.test.Brick; -import com.platform.test.FolderReader; -import com.platform.test.Volume; import com.platform.utils.Configs; import com.platform.utils.UtilsHelper; @Controller -public class DataModelController { +public class DataModelController extends BaseController{ @Resource(name = "dataInfoService") private DataInfoService dfs; + + @Resource(name = "gfsService") + private IGfsService gfsService; + + @Resource(name = "mySqlService") + private IMySqlService mySqlService; + + @Resource(name = "OracleExtract") + private IOracleExtractService OracleExtract; public void setDfsImp(DataInfoService dfs) { this.dfs = dfs; @@ -44,7 +58,7 @@ public class DataModelController { Map<String, String[]> paramMap = res.getParameterMap(); Set<String> keySet = paramMap.keySet(); Map<String, String> params = new HashMap<String, String>(); - StringBuffer sb = new StringBuffer().append("��ǰ���������:{"); + StringBuffer sb = new StringBuffer().append("锟斤拷前锟斤拷锟斤拷锟斤拷锟斤拷锟�:{"); for (String str : keySet) { String value = paramMap.get(str)[0]; if (StringUtils.isNotEmpty(value)) { @@ -75,7 +89,7 @@ public class DataModelController { String[] oraclesName = paramMap.get("oracleName"); if (oraclesName != null) for (String rcName : oraclesName) { - Configs.CONSOLE_LOGGER.info("ִ�к�̨���ݿ�����\t" + rcName); + Configs.CONSOLE_LOGGER.info("杩炴帴鎴愬姛\t" + rcName); new OracleStatusService().connectToOracle(rcName); } } @@ -88,52 +102,119 @@ public class DataModelController { String operate = paramMap.get("operation")[0]; if (null != oraclesName) { for (String rcName : oraclesName) { - Configs.CONSOLE_LOGGER.info("ȡ����̨���ݿ�����:\t" + rcName); + Configs.CONSOLE_LOGGER.info("杩炴帴鎴愬姛:\t" + rcName); new OracleStatusService().cancelToOracle(rcName, operate); } } } - @RequestMapping("/extractOracleData") + @RequestMapping("/oracle/{name}/extract") public void extractOracleData(HttpServletRequest res, - HttpServletResponse req) { - + HttpServletResponse req, String name) throws Exception { + System.out.println("------extract-------"); + System.out.println(name); + Map<String, String[]> paramMap = res.getParameterMap(); + //姹囨�诲簱 瀵硅薄淇℃伅--甯︽湁tableName- + String[] nodes = paramMap.get("target"); + Map map = null; + for (String string : nodes) { + JSONObject jsonobject = JSONObject.fromObject(string); + map = jsonobject; + System.out.println(map); + } + + // 閲囬泦搴撳璞�--(澶氫釜閲囬泦搴撴娊鍙栧埌1涓眹鎬诲簱鐨�1涓猼ableName涓�) + String[] inneed = paramMap.get("inneed"); + List<Map<String, String>> colleclist = new ArrayList<Map<String,String>>(); + for (String string : nodes) { + JSONObject jsonobject = JSONObject.fromObject(string); + Map inneedMap = jsonobject; + colleclist.add(inneedMap); + } + OracleExtract.extractOracle(name, colleclist, map); + } @RequestMapping("/volume/list") @ResponseBody - public Volume getFolder(HttpServletRequest res, HttpServletResponse req) { + public List<VolumeEntity> getFolder(HttpServletRequest res, HttpServletResponse req) throws Exception { System.out.println("get Request"); - Brick brick1 = new Brick("192.168.0.101", "D:/bootstrap"); - Brick brick2 = new Brick("192.168.0.103", "D:\book"); - List<Brick> bricks = new ArrayList<Brick>(); - bricks.add(brick1); - bricks.add(brick2); - List<FolderNode> folderNodes = new ArrayList<>(); - folderNodes - .add(FolderReader - .reader("C:\\Users\\wuming\\workspace\\data-aggregation-platform")); - Volume volume = new Volume("volume", 1555551024, 153561024, bricks, - folderNodes); - return volume; +// Brick brick1 = new Brick("192.168.0.101", "D:/bootstrap"); +// Brick brick2 = new Brick("192.168.0.103", "D:\book"); +// List<Brick> bricks = new ArrayList<Brick>(); +// bricks.add(brick1); +// bricks.add(brick2); + List<VolumeEntity> result = gfsService.getAllVolumes(); + return result; } - - @RequestMapping("/oracle/list/") + + @RequestMapping(value = "/volume/{name}/move", method= RequestMethod.POST) @ResponseBody - public List<OracleConnectorParams> getOracleInfo(HttpServletRequest res, - HttpServletResponse req) { - List<OracleConnectorParams> orpinfo = new ArrayList<OracleConnectorParams>(); - //������-------------------- - OracleConnectorParams oracleConnectorParams1 = new GatherOracleInfo("1530", "192.168.0.115", "���ܿ�1", "System", "oracle", "orcl", 0, "TS_JSSJBS","_20152016", 0); - OracleConnectorParams oracleConnectorParams2= new GatherOracleInfo("1521", "192.168.0.110", "���ܿ�2", "System", "oracle", "orcl", 1, "TS_JSSJBS","_20152016", 1); - OracleConnectorParams oracleConnectorParams3 = new GatherOracleInfo("1530", "192.168.0.123", "���ܿ�3", "System", "oracle", "orcl", 2, "TS_JSSJBS","_20152016", 2); - OracleConnectorParams oracleConnectorParams4= new GatherOracleInfo("1521", "192.168.0.120", "���ܿ�4", "System", "oracle", "orcl", 3, "TS_JSSJBS","_20152016", 3); - orpinfo.add(oracleConnectorParams1); - orpinfo.add(oracleConnectorParams2); - orpinfo.add(oracleConnectorParams3); - orpinfo.add(oracleConnectorParams4); - //--------------------------------- - return orpinfo; + public Object move(HttpServletRequest res, HttpServletResponse req, String name, + FolderNode selectNode, DataInfoEntity selectItems) throws Exception { + System.out.println("get Request"); + Map<String, String[]> paramMap = res.getParameterMap(); +// System.out.println(paramMap); + String[] nodes = paramMap.get("selectNode"); + Map map = null; + for (String string : nodes) { + System.out.println(string); + JSONObject jsonobject = JSONObject.fromObject(string); + map = jsonobject; + } + List<String> listItemPath = new ArrayList<String>(); + String[] items = paramMap.get("selectItems"); + System.out.println("selectItems"); + for (String string : items) { + System.out.println(string); + JSONObject jsobj = JSONObject.fromObject(string); + Map itemmap = jsobj; + listItemPath.add((String)itemmap.get("dataPath")); + } + + System.out.println(name); + System.out.println(nodes); + System.out.println(selectItems); + System.out.println("--------------"); + int result = gfsService.copyFolder(listItemPath, (String)map.get("name"), "app"); + return result; + } + + @RequestMapping("/oracle/list") + @ResponseBody + public List<GatherOracleInfo> getOracleInfo(HttpServletRequest res, + HttpServletResponse req) throws Exception { + + List<GatherOracleInfo> result = mySqlService.findAllMySql(); + System.out.println("----------getOracleInfo-----------------------"); + return result; + } + + @RequestMapping("/oracle/{id}/delete") + @ResponseBody + public void deleteOracleInfo(HttpServletRequest res, + HttpServletResponse req, int id) throws Exception { + + mySqlService.deleteMySql(id); + System.out.println("----------deleteOracleInfo-----------------------"); + } + + @RequestMapping("/oracle/{id}/insert") + @ResponseBody + public void insertOracleInfo(HttpServletRequest res, + HttpServletResponse req, GatherOracleInfo oracle) throws Exception { + + mySqlService.insertOracle(oracle); + System.out.println("----------insertOracleInfo-----------------------"); + } + + @RequestMapping("/oracle/{id}/update") + @ResponseBody + public void updateOracleInfo(HttpServletRequest res, + HttpServletResponse req, GatherOracleInfo oracle) throws Exception { + + mySqlService.updateOracle(oracle); + System.out.println("----------updateOracleInfo-----------------------"); } @RequestMapping("/oracle/delete/") diff --git a/src/com/platform/controller/DefaultController.java b/src/com/platform/controller/DefaultController.java index 4722c5d6..1d738507 100644 --- a/src/com/platform/controller/DefaultController.java +++ b/src/com/platform/controller/DefaultController.java @@ -4,6 +4,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; @@ -11,18 +12,19 @@ import com.platform.utils.Configs; @Controller public class DefaultController { + @RequestMapping("/") public ModelAndView defaultHandler(HttpServletRequest req, HttpServletResponse res){ - //������ƥ������� + //处理不匹配的请求 System.out.println("index"); return new ModelAndView("index"); - } @RequestMapping("/test") - public void test(HttpServletRequest req, HttpServletResponse res){ + public ModelMap test(HttpServletRequest req, HttpServletResponse res){ //System.out.println(Class.class.getClass().getResource("/").getPath()); System.out.println(Configs.EXTRACT_LOG_LOCALTION); + return new ModelMap(); } } diff --git a/src/com/platform/controller/FolderController.java b/src/com/platform/controller/FolderController.java new file mode 100644 index 00000000..4e817bd4 --- /dev/null +++ b/src/com/platform/controller/FolderController.java @@ -0,0 +1,82 @@ + +package com.platform.controller; + +import java.util.Date; +import java.util.List; + +import javax.annotation.Resource; + +import oracle.sql.DATE; + +import org.springframework.stereotype.Controller; +import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +import com.base.BaseController; +import com.base.CustomException; +import com.platform.entities.GfsFolderEntity; +import com.platform.entities.VolumeEntity; +import com.platform.glusterfs.VolumeInfo; +import com.platform.service.IGfsService; + + +/** + * <一句话功能简述> + * <功能详细描述> + * @author chen + * @version [版本号,2016年9月8日] + * @see [相关类/方法] + * @since [产品/模块版本] + */ +@Controller +@RequestMapping("") +public class FolderController extends BaseController { + + @Resource(name = "gfsService") + private IGfsService gfsService; + + @RequestMapping(value="/getAllSubPathByPath", method= RequestMethod.POST) + public Object getAllSubPathByPath(String path) throws Exception { + System.out.println(path); + Object result = null; + if (null != path && !"".equals(path)) { + System.out.println(path); + result = gfsService.getFolder(path); + } + return result; + } + +// /** +// * <一句话功能简述> 查询集群中所有的 volume 及其 信息 +// * <功能详细描述> +// * @return +// * @throws Exception +// * @see [类、类#方法、类#成员] +// */ +// @RequestMapping(value="/volume/list", method= RequestMethod.POST) +// public Object getVolums() throws Exception{ +// System.out.println("----------------------------------"); +// long a = new Date().getTime(); +// List<VolumeEntity> result = gfsService.getAllVolumes(); +// System.out.println("----------------------------------"); +// System.out.println(new Date().getTime()-a); +// return result; +// } +// + /** + * <一句话功能简述> 查询集群中所有的 volume 及其 信息 + * <功能详细描述> + * @param volumeName "/home/gfs_ftp_point" "/home/v1_point" + * @return + * @throws Exception + * @see [类、类#方法、类#成员] + */ + + @RequestMapping(value="/volume/findByName", method= RequestMethod.POST) + public Object getVolumByName(String volumeName) throws Exception{ + VolumeEntity result = gfsService.getOneVolume(volumeName); + return result; + } + +} diff --git a/src/com/platform/controller/SetGlusterfsController.java b/src/com/platform/controller/SetGlusterfsController.java new file mode 100644 index 00000000..481331dd --- /dev/null +++ b/src/com/platform/controller/SetGlusterfsController.java @@ -0,0 +1,45 @@ + +/** + * 文件名 : SetGlusterfs.java + * 版权 : <版权/公司名> + * 描述 : <描述> + * @author liliy + * 版本 : <版本> + * 修改时间: 2016年9月8日 + * 修改内容: <修改内容> + */ +package com.platform.controller; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * <一句话功能简述> + * <功能详细描述> + * @author liliy + * @version [版本号,2016年9月8日] + * @see [相关类/方法] + * @since [产品/模块版本] + */ +@Controller +public class SetGlusterfsController { + @RequestMapping("/tes") + public Object defaultHandler(HttpServletRequest req, HttpServletResponse request) { + //���?ƥ������� + try { + + System.out.println("fsdfds"); + + return "listAll"; + } catch (Exception e) { + e.printStackTrace(); + + return "result"; + } + + + } +} diff --git a/src/com/platform/controller/ShowGlusterfsController.java b/src/com/platform/controller/ShowGlusterfsController.java new file mode 100644 index 00000000..83f6e468 --- /dev/null +++ b/src/com/platform/controller/ShowGlusterfsController.java @@ -0,0 +1,44 @@ + +/** + * 文件名 : ShowGlusterfsController.java + * 版权 : <版权/公司名> + * 描述 : <描述> + * @author liliy + * 版本 : <版本> + * 修改时间: 2016年9月8日 + * 修改内容: <修改内容> + */ +package com.platform.controller; + +import java.util.List; +import java.util.Map; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +import com.platform.glusterfs.ClusterInfo; + +/** + * <一句话功能简述> + * <功能详细描述> + * @author liliy + * @version [版本号,2016年9月8日] + * @see [相关类/方法] + * @since [产品/模块版本] + */ +@Controller +public class ShowGlusterfsController { + /** + * <一句话功能简述> + * <功能详细描述> + * @return + * @see [类、类#方法、类#成员] + */ + @RequestMapping("/showPeerStatus") + public Map<String,String> showPeerStatus(){ + Map<String, String> peer_status=new ClusterInfo().showClusterInfo(); + return peer_status; + } + + +} diff --git a/src/com/platform/dao/EncodeInfoDao.java b/src/com/platform/dao/EncodeInfoDao.java index 69bfd819..a877f5f3 100644 --- a/src/com/platform/dao/EncodeInfoDao.java +++ b/src/com/platform/dao/EncodeInfoDao.java @@ -12,7 +12,7 @@ import org.springframework.stereotype.Repository; import com.platform.entities.EncodedInfoEntity; /** - * ���ݿ����: ʵ������ɾ���ġ��� + * 数据库操作: 实现增、删、改、查 * * @author wuming * @@ -21,49 +21,49 @@ import com.platform.entities.EncodedInfoEntity; public interface EncodeInfoDao { /** - * ��ȡ��ѯ���µ�����ʵ�壨��������/ϵͳ����Ϣ + * 获取查询表下的所有实体(行政区划/系统)信息 * * @param tableName - * ��ѯ�ı��� - * @return ����ʵ����Ϣ:���ƺͱ��� + * 查询的表名 + * @return 所有实体信息:名称和编码 */ @Select("SELECT code, name FROM ${tableName}") public List<EncodedInfoEntity> getAllEntityInfo( @Param("tableName") String tableName); /** - * ����ʵ�壨��������/ϵͳ�������Ʋ�ѯ���� + * 根据实体(行政区划/系统)的名称查询编码 * * @param code - * ʵ����� + * 实体编码 * @param tableName - * ��ѯ�ı��� - * @return ��������������ѯ������ֻ��һ����¼ + * 查询的表名 + * @return 编码是主键,查询结果最多只有一条记录 */ @Select("SELECT name FROM ${tableName} WHERE code = #{code}") public String getEncodeNameByCode(@Param("code") String code, @Param("tableName") String tableName); /** - * ����ʵ�壨��������/ϵͳ���ı����ѯ���� + * 根据实体(行政区划/系统)的编码查询名称 * * @param name - * ʵ������ + * 实体名称 * @param tableName - * ��ѯ�ı��� - * @return ���Ʋ�����������ѯ������ܻ��ж�� + * 查询的表名 + * @return 名称不是主键,查询结果可能会有多个 */ @Select("SELECT code FROM ${tableName} WHERE name = #{name}") public List<String> getEncodeCodeByName(@Param("name") String name, @Param("tableName") String tableName); /** - * ����ʵ�壨��������/ϵͳ���ı��룬����ʵ������� + * 根据实体(行政区划/系统)的编码,更新实体的名称 * * @param code - * ϵͳ���� + * 系统编码 * @param tableName - * ��ѯ�ı��� + * 查询的表名 * @return */ @Update("UPDATE ${tableName} SET name = #{name} WHERE code = #{code}") @@ -71,12 +71,12 @@ public interface EncodeInfoDao { @Param("name") String name, @Param("tableName") String tableName); /** - * ����в���ʵ�壨��������/ϵͳ����Ϣ + * 向表中插入实体(行政区划/系统)信息 * * @param efe - * �����ʵ����Ϣ + * 插入的实体信息 * @param tableName - * ���� + * 表名 * @return */ @Insert("INSERT INTO ${tableName} (code, name) VALUES (#{efe.code}, #{efe.name})") @@ -84,12 +84,12 @@ public interface EncodeInfoDao { @Param("tableName") String tableName); /** - * ɾ�����е�ʵ�壨��������/ϵͳ�� + * 删除表中的实体(行政区划/系统) * * @param code - * ʵ��ı��� + * 实体的编码 * @param tableName - * ���� + * 表名 * @return */ @Delete("DELETE FROM ${tableName} WHERE code = #{code}") diff --git a/src/com/platform/dao/GatherOracleDao.java b/src/com/platform/dao/GatherOracleDao.java index f431bcfc..43852cac 100644 --- a/src/com/platform/dao/GatherOracleDao.java +++ b/src/com/platform/dao/GatherOracleDao.java @@ -1,5 +1,39 @@ package com.platform.dao; +import java.util.List; + +import org.springframework.stereotype.Repository; + +import com.platform.entities.GatherOracleInfo; + +@Repository(value = "gatherOracleDao") public interface GatherOracleDao { + + /** + * @return 查询所有的oracle记录 + * @throws Exception 异常 + */ + public List<GatherOracleInfo> selectAllOracle() throws Exception; + + /** + * @param id + * @return + * @throws Exception + */ + public int deleteOracleById(int id) throws Exception; + + /** + * @param oracle + * @return + * @throws Exception + */ + public int insertOracle(GatherOracleInfo oracle) throws Exception; + + /** + * @param oracle + * @return + * @throws Exception + */ + public int updateOracleById(GatherOracleInfo oracle) throws Exception; } diff --git a/src/com/platform/entities/Brick.java b/src/com/platform/entities/Brick.java new file mode 100644 index 00000000..8bda2cab --- /dev/null +++ b/src/com/platform/entities/Brick.java @@ -0,0 +1,58 @@ + +/** + * 文件名 : Brick.java + * 版权 : <版权/公司名> + * 描述 : <描述> + * @author chen + * 版本 : <版本> + * 修改时间: 2016年9月9日 + * 修改内容: <修改内容> + */ +package com.platform.entities; + +/** + * <一句话功能简述> volume 下的 块 对象 + * <功能详细描述> + * @author chen + * @version [版本号,2016年9月9日] + * @see [相关类/方法] + * @since [产品/模块版本] + */ + +public class Brick { + + /** ip */ + private String ip; + + /** 路径 */ + private String path; + + /** + * @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; + } + +} diff --git a/src/com/platform/entities/DataInfoEntity.java b/src/com/platform/entities/DataInfoEntity.java index d3581c89..3db92f4a 100644 --- a/src/com/platform/entities/DataInfoEntity.java +++ b/src/com/platform/entities/DataInfoEntity.java @@ -1,27 +1,27 @@ package com.platform.entities; /** - * ������Ϣʵ���� + * 数据信息实体类 * * @author wuming * */ public class DataInfoEntity { private int id; - private String regionalismCode; // ������������ - private String cityName; // �� - private String districtName; // ���� - private int systemCode; // ϵͳ���� - private String systemName; // ϵͳ���� - private String dataType; // �������ͣ�����\�籣\... - private int dataVersion; // ���ݰ汾 - private String submittedBatch; // �ϱ����� - private String dataPath; // ����·�� - private String collectingTime; // �ɼ�ʱ�� - private String collectorContacts; // �ɼ��˵���ϵ - private String charset; // ���ݵ��ַ����� - private String collectorName; // �ɼ������� - private String year; // ������� + private String regionalismCode; // 行政区划编码 + private String cityName; // 市 + private String districtName; // 区县 + private int systemCode; // 系统编码 + private String systemName; // 系统名称 + private String dataType; // 数据类型:财政\社保\... + private int dataVersion; // 数据版本 + private String submittedBatch; // 上报批次 + private String dataPath; // 数据路径 + private String collectingTime; // 采集时间 + private String collectorContacts; // 采集人的联系 + private String charset; // 数据的字符编码 + private String collectorName; // 采集人姓名 + private String year; // 数据年度 public DataInfoEntity() { } diff --git a/src/com/platform/entities/EncodedInfoEntity.java b/src/com/platform/entities/EncodedInfoEntity.java index fa6b934c..3f2f425e 100644 --- a/src/com/platform/entities/EncodedInfoEntity.java +++ b/src/com/platform/entities/EncodedInfoEntity.java @@ -2,14 +2,14 @@ package com.platform.entities; /** * - * ������Ϣʵ�� - * ��������/ϵͳ��Ϣ + * 编码信息实体 + * 行政区划/系统信息 * @author wuming * */ public class EncodedInfoEntity { - private String name; //���� - private String code; //���� + private String name; //名称 + private String code; //编码 public EncodedInfoEntity() {} diff --git a/src/com/platform/entities/FolderNode.java b/src/com/platform/entities/FolderNode.java index 5dc650b3..8f584d77 100644 --- a/src/com/platform/entities/FolderNode.java +++ b/src/com/platform/entities/FolderNode.java @@ -4,24 +4,45 @@ import java.util.List; public class FolderNode { private String name; + private int isFolder; // 1 is file and other integer is folder show children number private String path; - private List<FolderNode> childNodes; + private List<FolderNode> childNodes; - public FolderNode(String name, String path, List<FolderNode> childNodes) { - super(); + public FolderNode() { + // TODO Auto-generated constructor stub + } + + public FolderNode(String name) { this.name = name; - this.path = path; - this.childNodes = childNodes; + } + + public FolderNode(String name, int isFolder) { + this.name = name; + this.isFolder = isFolder; } public String getName() { return name; - } + } public void setName(String name) { this.name = name; } + /** + * @return the isFolder + */ + public int getIsFolder() { + return isFolder; + } + + /** + * @param isFolder the isFolder to set + */ + public void setIsFolder(int isFolder) { + this.isFolder = isFolder; + } + public String getPath() { return path; } diff --git a/src/com/platform/entities/GatherOracleInfo.java b/src/com/platform/entities/GatherOracleInfo.java index 11b7caa1..4ceca3b4 100644 --- a/src/com/platform/entities/GatherOracleInfo.java +++ b/src/com/platform/entities/GatherOracleInfo.java @@ -1,6 +1,25 @@ package com.platform.entities; +import com.platform.entities.OracleConnectorParams; + public class GatherOracleInfo extends OracleConnectorParams { + + private String tableName; + + private String suffix; + + private int id; + + private String remove; + + /** + * 0:未知状态, 1:连接成功 ,2:在使用 ,3 :失败 + */ + private int status; + + public GatherOracleInfo() { + super(); + } public GatherOracleInfo(String port, String ip, String name, String user, String password, String database) { @@ -13,17 +32,12 @@ public class GatherOracleInfo extends OracleConnectorParams { super(port, ip, name, user, password, database); this.tableName = tableName; this.suffix = suffix; - this._id=_id; + this.id=_id; this.status = status; } - private String tableName; - - private String suffix; - private int _id; - private int status; //oracle����״̬ ; 0��δ����; 1�����ӳɹ� ; 2��ʹ����; 3����ʧ��. public String getTableName() { return tableName; @@ -41,12 +55,12 @@ public class GatherOracleInfo extends OracleConnectorParams { this.suffix = suffix; } - public int get_id() { - return _id; + public int getId() { + return id; } - public void set_id(int _id) { - this._id = _id; + public void setId(int id) { + this.id = id; } public int getStatus() { @@ -55,6 +69,14 @@ public class GatherOracleInfo extends OracleConnectorParams { public void setStatus(int status) { this.status = status; + } + + public String getRemove() { + return remove; + } + + public void setRemove(String remove) { + this.remove = remove; } } diff --git a/src/com/platform/entities/GfsFolderEntity.java b/src/com/platform/entities/GfsFolderEntity.java new file mode 100644 index 00000000..13429ddf --- /dev/null +++ b/src/com/platform/entities/GfsFolderEntity.java @@ -0,0 +1,77 @@ + +/** + * 文件名 : GfsPathModel.java + * 版权 : <版权/公司名> + * 描述 : <描述> + * @author chen + * 版本 : <版本> + * 修改时间: 2016年9月8日 + * 修改内容: <修改内容> + */ +package com.platform.entities; + +import java.util.List; + +/** + * <一句话功能简述> + * <功能详细描述> + * @author chen + * @version [版本号,2016年9月8日] + * @see [相关类/方法] + * @since [产品/模块版本] + */ + +public class GfsFolderEntity { + + /** 当前路径 */ + private String path; + + /** 当前路径 */ + private String name; + + /** 子目录 */ + private List<GfsFolderEntity> children; + + /** + * @return the path + */ + public String getPath() { + return path; + } + + /** + * @param path the path to set + */ + public void setPath(String path) { + this.path = path; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the children + */ + public List<GfsFolderEntity> getChildren() { + return children; + } + + /** + * @param children the children to set + */ + public void setChildren(List<GfsFolderEntity> children) { + this.children = children; + } + +} diff --git a/src/com/platform/entities/OracleConnectorParams.java b/src/com/platform/entities/OracleConnectorParams.java index b265f407..cbb1d3a6 100644 --- a/src/com/platform/entities/OracleConnectorParams.java +++ b/src/com/platform/entities/OracleConnectorParams.java @@ -11,7 +11,11 @@ public class OracleConnectorParams { private String name; private String user; private String password; - private String database; + private String databaseName; + + public OracleConnectorParams() { + // TODO Auto-generated constructor stub + } public OracleConnectorParams(String port, String ip, String name) { maybeInit(); @@ -27,7 +31,7 @@ public class OracleConnectorParams { this.name = name; this.user = user; this.password = password; - this.database = database; + this.databaseName = database; } private void maybeInit() { @@ -35,7 +39,7 @@ public class OracleConnectorParams { Configs.CONFIG_LOCALTION).getProperties(); this.user = properties.getProperty("collect-user"); this.password = properties.getProperty("collect-password"); - this.database = properties.getProperty("collect-database"); + this.databaseName = properties.getProperty("collect-database"); } public String getPort() { @@ -78,12 +82,12 @@ public class OracleConnectorParams { this.password = password; } - public String getDatabase() { - return database; + public String getDatabaseName() { + return databaseName; } - public void setDatabase(String database) { - this.database = database; + public void setDatabaseName(String databaseName) { + this.databaseName = databaseName; } } diff --git a/src/com/platform/entities/PagerOptions.java b/src/com/platform/entities/PagerOptions.java index 046a90cd..f347488f 100644 --- a/src/com/platform/entities/PagerOptions.java +++ b/src/com/platform/entities/PagerOptions.java @@ -1,29 +1,29 @@ package com.platform.entities; public class PagerOptions { - private Integer currentPageNum; //��ǰҳ�� + private Integer currentPageNum; //当前页码 - private String dataType; //�������� + private String dataType; //数据类型 - private String submittedBatch; //�������� + private String submittedBatch; //数据批次 - private String cityName; //�������� + private String cityName; //城市名称 - private String districtName; //������ + private String districtName; //区县名 - private Integer dataVersion; //���ݰ汾 + private Integer dataVersion; //数据版本 - private String systemName; //ϵͳ���� + private String systemName; //系统名称 - private String dataYear; // ������� + private String dataYear; // 数据年度 - private Integer limit; //һ�β�ѯ���ؼ�¼���� + private Integer limit; //一次查询返回记录条数 - private Integer offset; // ��ѯƫ��������ʼid + private Integer offset; // 查询偏移量:起始id - private Integer totalLimit; //��ǰҳǰ�����ж��������� + private Integer totalLimit; //当前页前面已有多少条数据 - private Integer priorTableSize; //ǰһ�β���һҳ��ʾ���������� + private Integer priorTableSize; //前一次操作一页显示的数据条数 public Integer getCurrentPageNum() { return currentPageNum; diff --git a/src/com/platform/entities/VolumeEntity.java b/src/com/platform/entities/VolumeEntity.java new file mode 100644 index 00000000..84455003 --- /dev/null +++ b/src/com/platform/entities/VolumeEntity.java @@ -0,0 +1,129 @@ + +/** + * 文件名 : VolumeEntity.java + * 版权 : <版权/公司名> + * 描述 : <描述> + * @author chen + * 版本 : <版本> + * 修改时间: 2016年9月9日 + * 修改内容: <修改内容> + */ +package com.platform.entities; + +import java.util.ArrayList; +import java.util.List; + +/** + * <一句话功能简述> gfs的 volume 对象 + * <功能详细描述> + * @author chen + * @version [版本号,2016年9月9日] + * @see [相关类/方法] + * @since [产品/模块版本] + */ + +public class VolumeEntity { + + /** volume总大小 */ + private double allSize; + + /** volume已使用大小 */ + private double usedSize; + + /** volume名称 */ + private String name; + + /** 挂载点 */ + private String path; + + /** volume树形目录 */ + private FolderNode folder; + + /** volume的 块 */ + private List<Brick> brick = new ArrayList<Brick>(); + + /** + * @return the allSize + */ + public double getAllSize() { + return allSize; + } + + /** + * @param allSize the allSize to set + */ + public void setAllSize(double allSize) { + this.allSize = allSize; + } + + /** + * @return the usedSize + */ + public double getUsedSize() { + return usedSize; + } + + /** + * @param usedSize the usedSize to set + */ + public void setUsedSize(double usedSize) { + this.usedSize = usedSize; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the path + */ + public String getPath() { + return path; + } + + /** + * @param path the path to set + */ + public void setPath(String path) { + this.path = path; + } + + /** + * @return the folder + */ + public FolderNode getFolder() { + return folder; + } + + /** + * @param folder the folder to set + */ + public void setFolder(FolderNode folder) { + this.folder = folder; + } + + /** + * @return the brick + */ + public List<Brick> getBrick() { + return brick; + } + + /** + * @param brick the brick to set + */ + public void setBrick(List<Brick> brick) { + this.brick = brick; + } + +} diff --git a/src/com/platform/glusterfs/ClusterInfo.java b/src/com/platform/glusterfs/ClusterInfo.java new file mode 100644 index 00000000..c23145e2 --- /dev/null +++ b/src/com/platform/glusterfs/ClusterInfo.java @@ -0,0 +1,86 @@ +package com.platform.glusterfs; + + + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.log4j.Logger; +import org.apache.log4j.PropertyConfigurator; + +import com.platform.utils.Constant; + +public class ClusterInfo { + public static Logger log = Logger.getLogger(ClusterInfo.class); + + public Map<String, String> showClusterInfo() { + log.info("get cluster info"); + Map<String, String> peerIps = new HashMap<String, String>(); + + /* + String command = "echo \"" + Constant.rootPasswd + "\"|sudo -S gluster peer status"; + RunCommand runCommand = new RunCommand(); + List<String> reStrings = runCommand.runCommandWait(command); + */ + List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, Constant.port, Constant.glusterPeerStatus); + if (reStrings == null) { + log.error("1101 command get result is null"); + return null; + } + if (reStrings.size() == 0) { + log.error("1102 command get result is nothing"); + return null; + } + + if (!(reStrings.get(0).split(":")[0].contains("Number of Peers"))) { + + log.error("1103 get result string wrong"); + return null; + } + + + // System.out.print(reStrings.get(0)); + + int flag = 0; + String ipString = ""; + String state = ""; + for (Iterator it2 = reStrings.iterator(); it2.hasNext();) { + String line = (String) it2.next(); + line=line.replaceAll(" +", " "); + String keyValue[] = line.split(":"); + if (keyValue[0].equals("Hostname")) { + + if (keyValue.length < 2) { + log.error("1105 command get result is wrong"); + continue; + } + + ipString = keyValue[1].replaceAll(" ", ""); + flag = 1; + } else if (flag == 1 && keyValue[0].equals("State")) { + + if (keyValue.length < 2) { + log.error("1106 command get result is wrong"); + continue; + } + + state = keyValue[1].replaceAll(" ", ""); + flag = 0; + peerIps.put(ipString, state); + } + + } + return peerIps; + } + + + + public static void main(String[] args) { + PropertyConfigurator.configure("log4j.properties"); + System.out.println(new ClusterInfo().showClusterInfo()); + } +} diff --git a/src/com/platform/glusterfs/CopyData.java b/src/com/platform/glusterfs/CopyData.java new file mode 100644 index 00000000..6fd1e357 --- /dev/null +++ b/src/com/platform/glusterfs/CopyData.java @@ -0,0 +1,80 @@ +package com.platform.glusterfs; + +import java.util.List; + +import java.util.Map; + +import org.apache.log4j.Logger; +import org.apache.log4j.PropertyConfigurator; +import org.junit.Test; + +import com.platform.utils.Constant; + + +/** + * <一句话功能简述> 复制数据 + * <功能详细描述> + * @author chen + * @version [版本号,2016年9月8日] + * @see [相关类/方法] + * @since [产品/模块版本] + */ + +public class CopyData { + public static Logger log = Logger.getLogger(CopyData.class); + + public int copyVolumeFiles(String sourceVolumeName, String destVolumeName, String fileName) { + log.info("start copy " + fileName + " from " + sourceVolumeName + " to " + destVolumeName); + int status = -1; + /** + * get mount point of volumeName + */ + + String sourceFolderName = sourceVolumeName; + String destFolderName = destVolumeName; + status = copyFolderFiles(sourceFolderName, destFolderName, fileName); + return status; + } + + /** + * -1 :error; -2: the filename is not exists ;-3 :destFolderName ; 1: right + * not exists + * + * @param folderName + * @param fileName + * @return + */ + public int copyFolderFiles(String sourceFolderName, String destFolderName, String fileName) { + int progress=0; + log.info("start copy " + fileName + " from " + sourceFolderName + " to " + destFolderName); + ShowData showData=new ShowData(); + Map<String,String> reStrings=showData.showFolderData(destFolderName); + if(reStrings==null){ + log.info("3201 "+destFolderName+" is not exists"); + return -3; + } + + reStrings=showData.showFolderData(sourceFolderName+"/"+fileName); + if(reStrings==null){ + log.info("3202 "+sourceFolderName+"/"+fileName+" is not exists"); + return -2; + } + String command = "cp -r " + sourceFolderName + "/" + fileName+" "+destFolderName; + /* + * RunCommand runCommand = new RunCommand(); + + List<String> reStrings = runCommand.runCommandWait(command); + */ + Constant.ganymedSSH.execCmdNoWaitAcquiescent(command); + + log.info("copy " + sourceFolderName +"/" + fileName+ " to " + destFolderName + " running"); + return 1; + } + + + @Test + public void testCopyFolderFiles() { + PropertyConfigurator.configure("log4j.properties"); + copyFolderFiles("/home", "/home/ubuntu", "system_data"); + } +} diff --git a/src/com/platform/glusterfs/GetTreeData.java b/src/com/platform/glusterfs/GetTreeData.java new file mode 100644 index 00000000..ec40e7f6 --- /dev/null +++ b/src/com/platform/glusterfs/GetTreeData.java @@ -0,0 +1,80 @@ +package com.platform.glusterfs; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.apache.log4j.PropertyConfigurator; +import org.junit.Test; +import org.springframework.stereotype.Service; + +import com.platform.entities.FolderNode; + +/** + * <一句话功能简述> 获得GFS某个目录下的子目录 + * <功能详细描述> + * @author chen + * @version [版本号,2016年9月8日] + * @see [相关类/方法] + * @since [产品/模块版本] + */ +public class GetTreeData { + ShowData showData = new ShowData(); + + /** + * <一句话功能简述> 获得所以子目录 + * <功能详细描述> + * @param name + * @return + * @see [类、类#方法、类#成员] + */ + public FolderNode getDatas(String name) { + FolderNode fileNode = new FolderNode(name); + Map<String, String> files = showData.showFolderData(name); + if(files==null || files.size()==0){ + return fileNode; + } + fileNode.setIsFolder(files.size()); + List<FolderNode> list = new ArrayList<FolderNode>(); + fileNode.setChildNodes(list); + for (Map.Entry<String, String> entry : files.entrySet()) { + int number = Integer.parseInt(entry.getValue()); + if ("app".equals(entry.getKey())) { + continue; + } + if (number == 1) { + fileNode.getChildNodes().add(new FolderNode(entry.getKey(), number)); + } + if (number > 1) { + FolderNode temp=getDatas(name+"/"+entry.getKey()); + fileNode.getChildNodes().add(temp); + } + } + + return fileNode; + } + +// public static void main(String[] args) { +// GetTreeData getTreeData=new GetTreeData(); +// FileOrFolder 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; +// } +//} + diff --git a/src/com/platform/glusterfs/RemoveData.java b/src/com/platform/glusterfs/RemoveData.java new file mode 100644 index 00000000..2297ed03 --- /dev/null +++ b/src/com/platform/glusterfs/RemoveData.java @@ -0,0 +1,98 @@ +package com.platform.glusterfs; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.log4j.Logger; +import org.apache.log4j.PropertyConfigurator; +import org.junit.Test; + +import com.platform.utils.Constant; + + + +public class RemoveData { + + public static Logger log = Logger.getLogger ( RemoveData.class); + public int deleteVolumeFiles(String volumeName,String fileName){ + log.info("start delete "+volumeName+" "+fileName); + int status=-1; + /** + * get mount point of volumeName + */ + String folderName=volumeName; + + status=deleteFolderFiles(folderName,fileName); + return status; + } + + /** + * -1 :error; 0: the filename is not exists ; 1: right + * @param folderName + * @param fileName + * @return + */ + public int deleteFolderFiles(String folderName,String fileName){ + log.info("start delete "+folderName+"/"+fileName); + + ShowData showData=new ShowData(); + Map<String,String> reStrings=showData.showFolderData(folderName+"/"+fileName); + + if(reStrings==null){ + log.error("3301 "+folderName+"/"+fileName+" is not exists"); + return -1; + } + + String command="rm -r "+folderName+"/"+fileName; + +// int status=runCommand.runCommand(command); + Constant.ganymedSSH.execCmdNoWaitAcquiescent(command); + + log.info("delete "+folderName+" "+fileName+" running"); + return 1; + } + + public int getFolderSize(String name) { + log.info("get "+name+" size"); + String command="du -k -d 0 "+name; + /* + * RunCommand runCommand=new RunCommand(); + + List<String> reStrings=runCommand.runCommandWait(command); + */ + List<String> reStrings=Constant.ganymedSSH.execCmdWaitAcquiescent(command); + + if(reStrings==null){ + log.error("3302 the "+command+" return error"); + return -1; + } + if(reStrings.size()<1){ + log.error("3303 the "+command+" return error"); + return -1; + } + + if(reStrings.size()==1 && reStrings.get(0).contains("No such file or directory")){ + log.info("3304 "+name+" is not exists"); + return 0; + } + String strSize=(reStrings.get(0).split("\t"))[0]; + int size=Integer.parseInt(strSize); + log.info(name +" size is "+size); + return size; + } + +// @Test + public void test_getFolderSize() { + PropertyConfigurator.configure("log4j.properties"); + getFolderSize("/home/ubuntu"); + } + + @Test + public void testDeleteFolderFiles() { + PropertyConfigurator.configure("log4j.properties"); + deleteFolderFiles("/home/ubuntu","system_data"); + } + +} diff --git a/src/com/platform/glusterfs/SetCluster.java b/src/com/platform/glusterfs/SetCluster.java new file mode 100644 index 00000000..ccc3a76f --- /dev/null +++ b/src/com/platform/glusterfs/SetCluster.java @@ -0,0 +1,5 @@ +package com.platform.glusterfs; + +public class SetCluster { + +} diff --git a/src/com/platform/glusterfs/SetVolume.java b/src/com/platform/glusterfs/SetVolume.java new file mode 100644 index 00000000..d6be2d41 --- /dev/null +++ b/src/com/platform/glusterfs/SetVolume.java @@ -0,0 +1,493 @@ + +/** + * @author 李乾坤 + * 进行volume的一系列操作,如创建、开启停止volume,为volume添加或删除brick + */ +package com.platform.glusterfs; + + + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.log4j.Logger; +import org.apache.log4j.PropertyConfigurator; + +import com.platform.utils.Constant; + + + +public class SetVolume { + public static Logger log = Logger.getLogger(SetVolume.class); + + /* + * 创建volume 返回值:创建并挂载成功 1 + * + */ + public int createVolume(String volumeName, int count, String type, List bricks, String mountPoint) { + log.info("Creat new volume"); + + // 判断创建volume的条件是否满足 + int able = isAbleCreateVolume(volumeName, count, type, bricks, mountPoint); + + if (able == 1) { + String command = null; + // 将brics从List变量中提取出来并连接成可以在命令行中使用的格式 + String commandarg = concat(bricks); + + /* + * verify the type + */ + if (type.equals(Constant.distributed)) { + command = "gluster volume create " + volumeName + " " + commandarg + "force"; + } else if (type.equals(Constant.replica) || type.equals(Constant.stripe)) { + command = "gluster volume create " + volumeName + " " + type + " " + count + " " + commandarg + "force"; + } + + // 执行命令 + List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, + Constant.port, command); + + // 创建成功时返回信息格式:volume create: volumename success: + if (reStrings == null || reStrings.size() == 0) { + log.error("3106 " + command + " run return error"); + return -7; + } + if (reStrings.get(0).contains("volume create: " + volumeName + ": " + "success:")) { + log.info("create volume "+volumeName+" successed!"); + // 创建成功则启动并进行挂载 + if (startVolume(volumeName) == 0) { + log.info("start volume "+volumeName+" successed!"); + if ((new ShowData().showFolderData(mountPoint)) == null) { + Constant.ganymedSSH.execCmdWaitAcquiescent("mkdir " + mountPoint); + } + // 进行挂载 + String command3 = "mount -t glusterfs " + Constant.hostIp + ":/" + volumeName + " " + mountPoint; + List<String> reStrings3 = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, + Constant.rootPasswd, Constant.port, command3); + + // 这里需要添加解析挂载命令返回字符串的语句,由于我的系统有问题,导致挂载成功后返回WARNING: getfattr + // not found, certain checks will be skipped.. + // 所以这句代码未经测试 + // 成功挂载时没有任何返回信息 + if (reStrings3.size() == 0 || reStrings.get(0).contains("GlusterFS is already mounted")) + { + log.info("mount point successed!"); + return 1; + } + } + } else { + log.error("3104 volume create failed with error" + reStrings.get(0)); + // System.out.println(reStrings.get(0)); + return -7; + } + return 1; + } else { + log.error("给出的参数不满足创建条件"); + // System.out.println("给出的参数不满足创建条件"); + return able; + } + + } + + /** + * 删除volume + * + * @param volumeName + * @return 1 表示成功 ;-1表示volume name不存在;-2表示停止volume 失败 + */ + public int deleteVolume(String volumeName) { + int status = 0; + List<String> volumeNames = new VolumeInfo().showAllVolumeName(); + if (!volumeNames.contains(volumeName)) { + log.error("3801 " + volumeName + " is not exists !"); + return -1; + } + + String mountPoint = new VolumeInfo().getVolumeMountPoint(volumeName); + if (stopVolume(volumeName) != 0) { + log.error("3802 " + volumeName + " stop failed !"); + return -2; + } + log.info("stop "+volumeName+" successed!"); + if (mountPoint != null) { + String command = "umount " + mountPoint; + Constant.ganymedSSH.execCmdNoWaitAcquiescent(command); + log.info("umount "+mountPoint+" successed!"); + } + String command="echo -e \"y\"| gluster volume delete "+volumeName; + List<String> reStrings=Constant.ganymedSSH.execCmdWaitAcquiescent(command); + if(reStrings==null || reStrings.size()>0 || !(reStrings.get(0).contains("volume delete: "+volumeName+": success"))){ + log.error("3803 : delete volume "+volumeName+" failed !"); + return -3; + } + log.info("delete "+volumeName+" successed!"); + return 1; + } + + /* + * 为指定的volume添加brick,参数中需要指定类型、数量等 返回值:1成功 ;其他失败 + * 过程中需要先检查volume是否存在,还需检查给出的brick数量与类型、count是否相符 + */ + public int addBrickVolume(String volumeName, List<String> brickName, int count, String type) { + // 检查是否满足添加bricks的条件 + int able = isAble(volumeName, count, type, brickName); + if (able != 1) { + return able; + } + + String command = ""; + log.info("add brick to the specified volume"); + + String brick = concat(brickName); + + if (type.equals(Constant.distributed)) + command = "gluster volume add-brick " + volumeName + " " + brick + "force"; + else if (type.equals(Constant.replica)) + command = "gluster volume add-brick " + volumeName + " " + "replica " + count + " " + brick + "force"; + else if (type.equals(Constant.stripe)) + command = "gluster volume add-brick " + volumeName + " " + "stripe " + count + " " + brick + "force"; + + List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, + Constant.port, command); + + // 添加成功的返回信息是:volume add-brick: success + if (reStrings != null && reStrings.size() > 0 && reStrings.get(0).contains("volume add-brick: success")) { + 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"); + return -5; + } + } + + /* + * 为指定的volume删除brick,参数中需要指定类型、数量等 返回值:1 成功 ;其他 失败 + * 过程中需要先检查volume是否存在,还需检查给出的brick数量与类型、count是否相符 + */ + public int deleteBrickVolume(String volumeName, List<String> brickName, int count, String type) { + int able = isAble(volumeName, count, type, brickName); + + if (able != 1) { + return able; + } + String command = null; + + log.info("delete brick of the specified volume"); + + String brick = concat(brickName); + + if (type.equals(Constant.distributed)) { + command = "echo -e \"y\" | gluster volume remove-brick " + volumeName + " " + brick + " force"; + } else if (type.equals(Constant.replica)) { + command = "echo -e \"y\" | gluster volume remove-brick " + volumeName + " repli " + count + " " + brick + + " force"; + } else if (type.equals(Constant.stripe)) { + command = "echo -e \"y\" | gluster volume remove-brick " + volumeName + " stripe " + count + " " + brick + + " force"; + } + + if (command == null) { + log.error("3305 remove brick failed,please check the system"); + return -5; + } + log.info("即将执行删除命令"); + List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, + Constant.port, command); + // System.out.println(reStrings); + log.info("删除命令执行完毕"); + + // 删除成功的返回信息是“volume remove-brick: success” + if (reStrings.get(0).contains("volume remove-brick: success")) { + { + log.info("删除brick成功"); + return 1; + } + } else { + log.error("3305 remove brick failed,please check the system"); + + return -5; + } + + } + + /* + * 停止指定volume 参数中需给出volume的名字 返回值: 0 成功 -1 失败 + * 需要先检查volume是否存在,然后判断volume的状态是否已经是停止状态 + */ + public int stopVolume(String volumeName) { + log.info("stop volume"); + + // 首先需要判断volume是否存在,调用其他函数返回所有volume的名字 + boolean volumeExist = false; + + List<String> volume = new VolumeInfo().showAllVolumeName(); + for (String temp : volume) { + if (temp.equals(volumeName)) { + volumeExist = true; + break; + } + } + + if (!volumeExist) { + // volume不存在 + log.error("3501 the volume doesnot exist"); + System.out.println("3501 the volume doesnot exist"); + return -1; + } else { + // volume存在,则需判断volume的状态是否已经为“stop” + if (new VolumeInfo().getVolumeStatus(volumeName).equals("Stopped")) { + log.error("3502 the volume is already stoped"); + System.out.println("3502 the volume is already stoped"); + return -1; + } else { + String command = "echo -e \"y\"| gluster volume stop " + volumeName; + List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, + Constant.port, command); + + // 标记操作结果:operation = 1 操作成功 + // operation = 0 操作失败 + int operation = 0; + for (String temp2 : reStrings) { + if (temp2.contains("volume stop: " + volumeName + ": " + "success")) { + operation = 1; + break; + } + System.out.println("operation: " + operation); + } + + 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 失败 + * 需要先检查volume是否存在,然后判断volume的状态是否已经是开启状态 + */ + public int startVolume(String volumeName) { + log.info("start volume"); + boolean volumeExist = false; + List<String> volume = new VolumeInfo().showAllVolumeName(); + + for (String temp : volume) { + if (temp.equals(volumeName)) { + volumeExist = true; + break; + } + } + + if (volumeExist) { + if (!(new VolumeInfo().getVolumeStatus(volumeName).equals("Started"))) { + String command = "gluster volume start " + volumeName; + + int operation = 0; + + // 执行命令 + List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, + Constant.port, command); + for (String temp2 : reStrings) { + if (temp2.equals("volume start: " + volumeName + ": " + "success")) { + operation = 1; + } + } + + if (operation == 1) { + return 0; + } else { + log.error("3602 start volume failed"); + System.out.println("3602 start volume failed"); + return -1; + } + } else { + log.error("volume已经开启"); + System.out.println("volume已经开启"); + return -1; + } + } else { + log.error("3601 the volume does not exist"); + // System.out.println("3601 the volume does not exist"); + return -1; + } + } + + // 需要将存于List变量中的brick的位置组装成可以在glusterfs命令行中直接使用的格式 + public String concat(List<String> brickName) { + StringBuffer result = new StringBuffer(); + int len = brickName.size(); + for (int i = 0; i < len; i++) { + result.append(brickName.get(i)); + result.append(" "); + } + return result.toString(); + } + + /* + * 只在创建volume时使用此函数 创建volume时对不同数据卷,brick的数量需要满足和count的关系 + * 首先判断它们是否满足关系,在不满足的关系的情况下是肯定无法完成操作的 1:可以创建 ;-1:brick的ip不在集群中或者未连接; -2 -3 + * -4 :类型与brick数目不匹配 ; -5 :volumeName 已经存在;-6:挂载点存在且不为空,不能作为挂载点; -7:未知错误 + */ + public int isAbleCreateVolume(String volumeName, int count, String type, List<String> bricks, String mountPoint) { + int status = 0; + + int length = bricks.size(); + + if (type.equals(Constant.distributed)) { + if (count != 0) { + log.error("3101 the kind of distributed requires the arg of count to be 0"); + return -2; + } + } + if (type.equals(Constant.stripe)) { + if (length % count != 0) { + log.error("3102 the number of bricks should be the same as or the times of the stripe count"); + return -3; + } + } + if (type.equals(Constant.replica)) { + if ((length % count) != 0) { + log.error( + "3103 the number of bricks should be the same as the replicate count or the times of replicate count"); + return -4; + } + } + + Map peer_status = new ClusterInfo().showClusterInfo(); + 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"); + return -1; + } + + } + + List<String> volumeNames = new VolumeInfo().showAllVolumeName(); + if(volumeNames==null){ + log.error("3108 showAllVolumeName return error"); + return -7; + } + if (volumeNames.contains(volumeName)) { + log.error("3106 " + volumeName + " is already exists! "); + return -5; + } + + Map datas = new ShowData().showFolderData(mountPoint); + if (datas != null && datas.size() > 0) { + log.error("3107 " + mountPoint + " is not exists or not empty ! "); + return -6; + } + return 1; + } + + /** + * 添加或删除volume的brick时,首先需要判断volume是否存在,然后需要判断volume类型、count及brick数目 + * + * @param volumeName + * @param count + * @param type + * @param bricks + * @return 1 满足条件,可以添加;-1 :volume name is not exists;-2,-3,-4 类型与brick数量不匹配; + */ + public int isAble(String volumeName, int count, String type, List bricks) { + List<String> volumeNames = new VolumeInfo().showAllVolumeName(); + + if (!volumeNames.contains(volumeName)) { + log.error("3201:" + volumeName + " is not exists! "); + return -1; + } + + int length = bricks.size(); + if (type.equals("distribute")) { + if (count == 0) + 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 + // arg of count to be 0"); + return -2; + } + } + + if (type.equals("stripe")) { + if (length % count == 0) + 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 + // same as or the times of the stripe count"); + return -3; + + } + } + if (type.equals("replicate")) { + if ((length % count) == 0) + 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 -4; + } + } + + return 1; + } + + public static void main(String[] args) { + SetVolume setVolume = new SetVolume(); + int operation = 0; + PropertyConfigurator.configure("log4j.properties"); + // TODO Auto-generated method stub + // 测试创建volume的代码 + + List<String> bricksToCreate = new ArrayList<String>(); + bricksToCreate.add("192.168.0.110:/v1"); + bricksToCreate.add("192.168.0.116:/v1"); + operation = setVolume.createVolume("v1", 0, "distributed", bricksToCreate, "/home/v1_point"); +// operation = setVolume.deleteVolume("v3"); + // + // // 以下是测试添加brick的代码 + // + // List<String> bricksToAdd = new ArrayList<String>(); + // bricksToAdd.add("192.168.191.23:/v3"); + // operation = setVolume.addBrickVolume("v3", bricksToAdd, 0, + // "distribute"); + // System.out.println(operation); + + // 以下代码是测试删除brick的代码 + // List<String> bricksToAdd= new ArrayList<String>(); + // bricksToAdd.add("192.168.191.23:/v3"); + // operation = + // setVolume.deleteBrickVolume("v3",bricksToAdd,0,"distribute"); + // System.out.println(operation); + // 以下是测试start volume的代码 + // String volumeToStart = "testcreate" ; + // int startOperation = startVolume(volumeToStart); + // System.out.println(startOperation); + // 以下是测试stop volume + String volumeToStop = "v3"; + // int startOperation = setVolume.stopVolume(volumeToStop); + // 以下是测试创建volume并完成挂载的代码 + // List<String> bricksToCreate= new ArrayList<String>(); + // 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); + } +} diff --git a/src/com/platform/glusterfs/ShowData.java b/src/com/platform/glusterfs/ShowData.java new file mode 100644 index 00000000..919f7c7a --- /dev/null +++ b/src/com/platform/glusterfs/ShowData.java @@ -0,0 +1,104 @@ +package com.platform.glusterfs; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.log4j.Logger; + + +import org.apache.log4j.PropertyConfigurator; +import org.junit.Test; + +import com.platform.utils.Constant; + + +public class ShowData { + + 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 + * @return + */ + + + public Map<String,String> showVolumeFiles(String volumeName){ + log.info("start show the data"); + Map<String,String> data_type=new HashMap<String, String>(); + /** + * get mount point of volumeName + */ + String folderName=volumeName; + + 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 + + + * @param FolderName + * @return + */ + 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; + + /* + 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){ + log.error("2101 command get result is null"); + return null; + } + if(reStrings.size()==0){ + 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"); + return null; + } + /** + * remove first line total number + */ + reStrings.remove(0); + + for(Iterator it2 = reStrings.iterator();it2.hasNext();){ + String line=(String)it2.next(); + line=line.replaceAll(" +", " "); + String keyValue[]=line.split(" "); + if(keyValue.length<9){ + log.error("2104 "+line+" length is short"); + continue; + } + + data_type.put(keyValue[8], keyValue[1]); + + } + log.info(" get "+folderName+" data successed"); + return data_type; + } + + + /** + * + * <一句话功能简述> + * <功能详细描述> + * @see [类、类#方法、类#成员] + */ + @Test + public void testShowData(){ + + System.out.println(showFolderData("/home")); + + } +} \ No newline at end of file diff --git a/src/com/platform/glusterfs/SizeInfo.java b/src/com/platform/glusterfs/SizeInfo.java new file mode 100644 index 00000000..1aad2969 --- /dev/null +++ b/src/com/platform/glusterfs/SizeInfo.java @@ -0,0 +1,93 @@ +package com.platform.glusterfs; + + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.log4j.Logger; +import org.apache.log4j.PropertyConfigurator; + +import com.platform.utils.Constant; + +public class SizeInfo { + public static Logger log = Logger.getLogger(ClusterInfo.class); + VolumeInfo volumeInfo = new VolumeInfo(); + + /** + * 获取集群�?��volume size + * 返回值:-1:错�? 0:没有volume long:size大小 + * @return + */ + public long showAllSize() { + log.info("get AllSize "); + List<String> volumeNames = volumeInfo.showAllVolumeName(); + if (volumeNames == null) { + log.error("1201 showAllVolumeName error"); + return -1; + } + if (volumeNames.size() == 0) { + log.error("1202 It is not exist any volume"); + return 0; + } + List<String> reStrings = null; + long size = 0L; + + for (String str : volumeNames) { + String command = "df |grep " + str + "|awk \'{print $2}\'"; + reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, Constant.port, + command); + if (reStrings.isEmpty()) { + log.error("1203 The brick is unmount"); + } else { + size += Long.parseLong(reStrings.get(0)); + } + + } + + return size; + } + /** + * 返回集群已用大小 + * @return + * 返回值:-1:错�? 0:没有volume long:size大小 + */ + public long showUseSize() { + log.info("get UseSize "); + + List<String> volumeNames = volumeInfo.showAllVolumeName(); + List<String> reStrings = null; + long size = 0L; + if (volumeNames == null) { + log.error("1201 showAllVolumeName error"); + return -1; + } + if (volumeNames.size() == 0) { + log.error("1202 It is not exist any volume"); + return 0; + } + + for (String str : volumeNames) { + String command = "df |grep " + str + "|awk \'{print $3}\'"; + reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, + Constant.port, command); + if (reStrings.isEmpty()) { + log.error("1202 The brick is unmount"); + } else { + size += Integer.valueOf(reStrings.get(0)); + } + + } + + return size; + } + + public static void main(String[] args) { + PropertyConfigurator.configure("log4j.properties"); + System.out.println(new SizeInfo().showAllSize()); + System.out.println(new SizeInfo().showUseSize()); + } +} \ No newline at end of file diff --git a/src/com/platform/glusterfs/VolumeInfo.java b/src/com/platform/glusterfs/VolumeInfo.java new file mode 100644 index 00000000..af6a37d6 --- /dev/null +++ b/src/com/platform/glusterfs/VolumeInfo.java @@ -0,0 +1,271 @@ +package com.platform.glusterfs; + + + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.log4j.Logger; +import org.apache.log4j.PropertyConfigurator; + +import com.platform.utils.Constant; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +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>(); + + /* + * String command = "echo \"" + Constant.rootPasswd + + * "\" |sudo -S gluster volume info|grep ^Volume.Name"; RunCommand + * runCommand = new RunCommand(); List<String> reStrings = + * runCommand.runCommandWait(command); + */ + List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, + Constant.port, Constant.glusterVolumeInfo + "|grep ^Volume.Name"); + // System.out.println(reStrings); + if(reStrings==null){ + log.error("1401 get result is null"); + return null; + } + if(reStrings.size()==0){ + log.error("1402 get result is nothing"); + return null; + } + if(reStrings.get(0).contains(Constant.noVolume)){ + reStrings.clear(); + return reStrings; + } + if (!(reStrings.get(0).split(":")[0].contains("Volume Name"))) { + log.error("1403 get result string wrong"); + return null; + } + + String nameInfo = ""; + for (Iterator it = reStrings.iterator(); it.hasNext();) { + String line = (String) it.next(); + String str[] = line.split(":"); + volNames.add(str[1].replaceAll(" ", "")); + } + return volNames; + + } + + public String getVolumeType(String volumeName) { + log.info("get volume type"); + String volType = ""; + + /* + * ======= + * + * >>>>>>> origin/AlexKie String command = "echo \"" + + * Constant.rootPasswd + "\" |sudo -S gluster volume info " + + * volumeName + "|grep ^Type"; RunCommand runCommand = new RunCommand(); + * List<String> reStrings = runCommand.runCommandWait(command); <<<<<<< + * HEAD + */ + List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, + Constant.port, Constant.glusterVolumeInfo + volumeName + "|grep ^Type"); + // System.out.println(reStrings); + if(reStrings==null){ + log.error("1501 get result is null"); + return null; + } + if(reStrings.size()==0){ + log.error("1502 get result is nothing"); + return null; + } + if (!(reStrings.get(0).split(":")[0].contains("Type"))) { + log.error("1503 get result string wrong"); + return null; + } + + // System.out.println(reStrings); + + for (Iterator it = reStrings.iterator(); it.hasNext();) { + String line = (String) it.next(); + String str[] = line.split(":"); + volType = str[1]; + } + volType=volType.replaceAll(" ", ""); + return volType; + } + + public String getVolumeStatus(String volumeName) { + log.info("get volume status"); + String volStatus = ""; + + /* + * ======= + * + * >>>>>>> origin/AlexKie String command = "echo \"" + + * Constant.rootPasswd + "\" |sudo -S gluster volume info " + + * volumeName + "|grep ^Status"; RunCommand runCommand = new + * RunCommand(); List<String> reStrings = + * runCommand.runCommandWait(command); <<<<<<< HEAD + */ + List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, + Constant.port, Constant.glusterVolumeInfo + "|grep ^Status"); + // System.out.println(reStrings); + if(reStrings==null){ + log.error("1701 get result is null"); + return null; + } + if(reStrings.size()==0){ + log.error("1702 get result is nothing"); + return null; + } + if (!(reStrings.get(0).split(":")[0].contains("Status"))) { + log.error("1703 get result string wrong"); + return null; + } + + for (Iterator it = reStrings.iterator(); it.hasNext();) { + String line = (String) it.next(); + String str[] = line.split(":"); + volStatus = str[1].replaceAll(" ", ""); + } + + return volStatus; + } + + public Double getVolumeAllSize(String volumeName) { + log.info("get volume allSize"); + Double allSize = null; + /* + * ======= // waiting for testing... public Double + * getVolumeAllSize(String volumeName) { log.info("get volume allSize"); + * Double allSize = null; + * + * >>>>>>> origin/AlexKie String command = "echo \"" + + * Constant.rootPasswd + "\" |sudo -S df -h|grep " + volumeName + + * "|awk '{print $2}'"; RunCommand runCommand = new RunCommand(); + * List<String> reStrings = runCommand.runCommandWait(command); <<<<<<< + * HEAD + */ + List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, + Constant.port, Constant.df + "|grep " + volumeName + "|awk '{print $2}'"); + // System.out.println(reStrings); + if(reStrings==null){ + log.error("1801 get result is null"); + return null; + } + if(reStrings.size()==0){ + log.error("1802 get result is nothing"); + return null; + } + char flag = reStrings.get(0).trim().toCharArray()[0]; + if (flag < 48 || flag > 57) { + log.error("1803 get result string wrong"); + return null; + } + + for (Iterator it = reStrings.iterator(); it.hasNext();) { + String line = (String) it.next(); + String str[] = line.split("[^0-9]"); + allSize = Double.parseDouble(str[0]); + } + + return allSize; + } + + public Double getVolumeUseSize(String volumeName) { + log.info("get volume used size"); + Double usedSize = null; + + /* + * ======= + * + * >>>>>>> origin/AlexKie String command = "echo \"" + + * Constant.rootPasswd + "\" |sudo -S df -h|grep " + volumeName + + * "|awk '{print $3}'"; RunCommand runCommand = new RunCommand(); + * List<String> reStrings = runCommand.runCommandWait(command); <<<<<<< + * HEAD + */ + 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); + 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; + } + char flag = reStrings.get(0).trim().toCharArray()[0]; + if (flag < 48 || flag > 57) { + log.error("1903 get result string wrong"); + return null; + } + + for (Iterator it = reStrings.iterator(); it.hasNext();) { + String line = (String) it.next(); + String str[] = line.split("[^0-9]"); + + usedSize = Double.parseDouble(str[0]); + } + + return usedSize; + } + + public String getVolumeMountPoint(String volumeName) { + log.info("get volume mountPoint"); + // String mountPoint = ""; + + /* + * ======= + * + * >>>>>>> origin/AlexKie String command = "echo \"" + + * Constant.rootPasswd + "\" |sudo -S df -h|grep " + volumeName + + * "|awk '{print $6}'"; RunCommand runCommand = new RunCommand(); + * List<String> reStrings = runCommand.runCommandWait(command); <<<<<<< + * HEAD + */ + List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, + Constant.port, Constant.df + "|grep " + volumeName + "|awk '{print $6}'"); + // System.out.println(reStrings); + if(reStrings==null){ + log.error("11001 get result string wrong"); + return null; + } + if(reStrings.size()==0){ + log.error("11002 "+volumeName+" is no mountpoint"); + return null; + } + + char flag = reStrings.get(0).trim().toCharArray()[0]; + if (flag != '/') { + log.error("11003 get result string wrong"); + return null; + } + + Iterator it = reStrings.iterator(); + String mountPoint = (String) it.next(); + mountPoint=mountPoint.replaceAll(" ", ""); + return mountPoint; + } + + public static void main(String[] args) { + PropertyConfigurator.configure("log4j.properties"); + + System.out.println(new VolumeInfo().showAllVolumeName()); + System.out.println(new VolumeInfo().getVolumeType("v1")); + + System.out.println(new VolumeInfo().getVolumeStatus("v1")); + System.out.println(new VolumeInfo().getVolumeMountPoint("v1")); + + System.out.println(new VolumeInfo().getVolumeAllSize("v1")); + System.out.println(new VolumeInfo().getVolumeUseSize("v1")); + + } +} diff --git a/src/com/platform/oracle/OracleConnector.java b/src/com/platform/oracle/OracleConnector.java index 28d24135..90f29a7d 100644 --- a/src/com/platform/oracle/OracleConnector.java +++ b/src/com/platform/oracle/OracleConnector.java @@ -14,7 +14,7 @@ public class OracleConnector { static { try { Class.forName("oracle.jdbc.driver.OracleDriver"); - Configs.CONSOLE_LOGGER.info("Oracle�������سɹ�"); + Configs.CONSOLE_LOGGER.info("Oracle驱动加载成功"); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -59,10 +59,10 @@ public class OracleConnector { } /** - * ִ�ж�oracle���ݿ������ɾ + * 执行对oracle数据库的增、删 * @param conn * @param sql - * @return �Ƿ�ִ�гɹ� + * @return 是否执行成功 */ public boolean execOracleSQL(Connection conn, String sql) { boolean flag = false; diff --git a/src/com/platform/service/DataInfoServiceImp.java b/src/com/platform/service/DataInfoServiceImp.java index 3c89b60e..124e0aca 100644 --- a/src/com/platform/service/DataInfoServiceImp.java +++ b/src/com/platform/service/DataInfoServiceImp.java @@ -24,12 +24,12 @@ public class DataInfoServiceImp implements DataInfoService { public ModelMap getPagerTableData(PagerOptions pagerOptions) { // TODO Auto-generated method stub ModelMap modelMap = new ModelMap(); - int count = dfdDao.getLimitedDataCount(pagerOptions); //��ȡ�ܼ�¼���� + int count = dfdDao.getLimitedDataCount(pagerOptions); //获取总记录条数 int offset = 0; if (pagerOptions.getCurrentPageNum() > 1) { pagerOptions.setTotalLimit((pagerOptions.getCurrentPageNum() - 1) * pagerOptions.getPriorTableSize()); - offset = dfdDao.getLimitedBeginId(pagerOptions); //��ȡ��ʼ��ѯid + offset = dfdDao.getLimitedBeginId(pagerOptions); //获取起始查询id System.out.println(offset); } pagerOptions.setOffset(offset + 1); @@ -46,11 +46,11 @@ public class DataInfoServiceImp implements DataInfoService { for(String idx: id){ List<String> paths = dfdDao.getIdIsExist(Integer.parseInt(idx)); if(paths.size()>0){ - //ɾ���ļ����� + //删除文件操作 for (int i = 0; i < paths.size(); i++) { System.out.println(paths.get(i)); } - //ɾ�����ݿ��¼ + //删除数据库记录 //dfdDao.deleteRow(idx); } } diff --git a/src/com/platform/service/EncodeInfoService.java b/src/com/platform/service/EncodeInfoService.java index 8ef13844..36a200bc 100644 --- a/src/com/platform/service/EncodeInfoService.java +++ b/src/com/platform/service/EncodeInfoService.java @@ -5,7 +5,7 @@ import java.util.List; import com.platform.entities.EncodedInfoEntity; /** - * ���ݿ�ҵ���������ӿ� + * 数据库业务逻辑处理接口 * * @author wuming * diff --git a/src/com/platform/service/EncodeInfoServiceImpl.java b/src/com/platform/service/EncodeInfoServiceImpl.java index 3e5fe735..8492485d 100644 --- a/src/com/platform/service/EncodeInfoServiceImpl.java +++ b/src/com/platform/service/EncodeInfoServiceImpl.java @@ -10,7 +10,7 @@ import com.platform.dao.EncodeInfoDao; import com.platform.entities.EncodedInfoEntity; /** - * ҵ�����ľ���ʵ���� + * 业务逻辑的具体实现类 * * @author wuming * @@ -26,7 +26,7 @@ public class EncodeInfoServiceImpl implements EncodeInfoService { } /** - * ���ݴ��ݵ�tableName������ȡ��Ӧʵ����Ϣ����������/ϵͳ�� + * 根据传递的tableName参数获取对应实体信息(行政区划/系统) */ @Override public List<EncodedInfoEntity> getAllEncodeInfo(String tableName) { @@ -35,7 +35,7 @@ public class EncodeInfoServiceImpl implements EncodeInfoService { } /** - * �������� + * 测试事物 */ @Override public int deleteEncodeByCode(String code, String tableName) { diff --git a/src/com/platform/service/IGfsService.java b/src/com/platform/service/IGfsService.java new file mode 100644 index 00000000..0b9d9841 --- /dev/null +++ b/src/com/platform/service/IGfsService.java @@ -0,0 +1,72 @@ + +/** + * 文件名 : IGfsService.java + * 版权 : <版权/公司名> + * 描述 : <描述> + * @author chen + * 版本 : <版本> + * 修改时间: 2016年9月8日 + * 修改内容: <修改内容> + */ +package com.platform.service; + +import java.util.List; + +import com.platform.entities.FolderNode; +import com.platform.entities.VolumeEntity; + +/** + * <一句话功能简述> + * <功能详细描述> + * @author chen + * @version [版本号,2016年9月8日] + * @see [相关类/方法] + * @since [产品/模块版本] + */ + +public interface IGfsService { + + /** + * <一句话功能简述> 查找path,的所有子目录 + * <功能详细描述> + * @param path + * @return + * @throws Exception + * @see [类、类#方法、类#成员] + */ + public FolderNode getFolder(String path) throws Exception; + + /** + * <一句话功能简述> 复制path,的所有子目录 + * <功能详细描述> + * @param srcPath + * @param dstPath + * @return + * @throws Exception + * @see [类、类#方法、类#成员] + */ + public int copyFolder(List<String> srcFolders, String dstFolder, String name) throws Exception; + + /** + * <一句话功能简述> 获得volume下的 name \ allsize \ usedsize \ folderTree \ brick + * <功能详细描述> + * @return + * @throws Exception + * @see [类、类#方法、类#成员] + */ + public List<VolumeEntity> getAllVolumes() throws Exception; + + /** + * <一句话功能简述> + * <功能详细描述> + * @return + * @throws Exception + * @see [类、类#方法、类#成员] + */ + public VolumeEntity getOneVolume(String volumeName) throws Exception; + + public int moveData(String volumeName, String srcPath, String dstPath) throws Exception; + + public int deleteData(String volumeName, String srcPath) throws Exception; + +} diff --git a/src/com/platform/service/IMySqlService.java b/src/com/platform/service/IMySqlService.java new file mode 100644 index 00000000..4ab96ab0 --- /dev/null +++ b/src/com/platform/service/IMySqlService.java @@ -0,0 +1,25 @@ +package com.platform.service; + +import java.util.List; + +import com.platform.entities.GatherOracleInfo; + +public interface IMySqlService { + + /** + * @return 查询 + * @throws Exception + */ + public List<GatherOracleInfo> findAllMySql() throws Exception; + + /** 删除 + * @return + * @throws Exception + */ + public int deleteMySql(int id) throws Exception; + + public int insertOracle(GatherOracleInfo oracle) throws Exception; + + public int updateOracle(GatherOracleInfo oracle) throws Exception; + +} diff --git a/src/com/platform/service/IOracleExtractService.java b/src/com/platform/service/IOracleExtractService.java new file mode 100644 index 00000000..be02d6d9 --- /dev/null +++ b/src/com/platform/service/IOracleExtractService.java @@ -0,0 +1,17 @@ +package com.platform.service; + +import java.util.List; +import java.util.Map; + +public interface IOracleExtractService { + + /** 抽取数据库 + * @param name + * @param dataInfo //采集库连接参数 + * @param oracleConnect + * @return + * @throws Exception + */ + public boolean extractOracle(String name, List<Map<String, String>> dataInfo, Map<String, String> oracleConnect) throws Exception; + +} diff --git a/src/com/platform/service/OracleExtractHelper.java b/src/com/platform/service/OracleExtractHelper.java index dd8eb368..2a7b89ed 100644 --- a/src/com/platform/service/OracleExtractHelper.java +++ b/src/com/platform/service/OracleExtractHelper.java @@ -1,9 +1,10 @@ package com.platform.service; +import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; -import com.mysql.jdbc.Connection; +import com.platform.entities.GatherOracleInfo; import com.platform.entities.OracleConnectorParams; import com.platform.oracle.OracleConnector; import com.platform.utils.Configs; @@ -14,11 +15,11 @@ public class OracleExtractHelper { private OracleConnector oConnector; /** - * �ж�dblink�Ƿ��Ѿ����� + * 判断dblink是否已经存在 * * @param conn * @param linkName - * dblink������ + * dblink的名称 * @return */ private boolean hasSameNameDBLink(Connection conn, String linkName) { @@ -37,25 +38,26 @@ public class OracleExtractHelper { } /** - * ����dblink + * 创建dblink * - * @param conn - * @param oc - * dblink���Ӳ���ʵ�� + * @param conn 汇总库的连接 + * @param oc 采集库 + * dblink连接参数实体 */ public void createDBLink(Connection conn, OracleConnectorParams oc) { String linkName = "LinkTo" + oc.getName(); - String sql = "CREATE PUBLIC DATABASE LINK LinkTo" + String sql = "CREATE PUBLIC DATABASE LINK " + linkName + " CONNECT TO " - + "IDENTIFIED BY " + + oc.getUser() + + " IDENTIFIED BY " + oc.getPassword() + " USING '(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = " + oc.getIp() + ")(PORT = " + oc.getPort() - + ")))(CONNECT_DATA =(SERVICE_NAME =" + oc.getDatabase() + + ")))(CONNECT_DATA =(SERVICE_NAME =" + oc.getDatabaseName() + ")))';"; if (null != oc) { - if (hasSameNameDBLink(conn, linkName)) { // ���dblink�Ѿ�����,��ɾ��dblink���ڴ���dblink + if (hasSameNameDBLink(conn, linkName)) { // 如果dblink已经存在,先删除dblink,在创建dblink String deleteSql = "DROP PUBLIC DATABASE LINK LinkTo" + linkName; FileOperateHelper @@ -67,13 +69,13 @@ public class OracleExtractHelper { + oc.getName(), sql); oConnector.execOracleSQL(conn, sql); } else { - Configs.CONSOLE_LOGGER.error("ɾ�����е�DBLinkʧ��,�������µ�DBLink!"); + Configs.CONSOLE_LOGGER.error("删除已有的DBLink失败,无法创建新的DBLink!"); FileOperateHelper.fileWrite(Configs.EXTRACT_LOG_LOCALTION - + oc.getName(), "ɾ�����е�DBLinkʧ��,�������µ�DBLink!"); + + oc.getName(), "删除已有的DBLink失败,无法创建新的DBLink!"); } } else { - // ������dblink + // 否则,创建dblink oConnector.execOracleSQL(conn, sql); FileOperateHelper.fileWrite( Configs.EXTRACT_LOG_LOCALTION + oc.getName(), sql); @@ -82,13 +84,13 @@ public class OracleExtractHelper { } /** - * �������ռ� + * 创建表空间 * - * @param conn - * @param oc + * @param conn 汇总库连接 + * @param oc 汇总库信息 * @return */ - public boolean createTableSpace(Connection conn, OracleConnectorParams oc) { + public boolean createTableSpace(Connection conn, GatherOracleInfo oc) { String tmpSql = "select TABLESPACE_NAME from dba_tablespaces where TABLESPACE_NAME = '" + Configs.GATHER_TABLESPACE_NAME + "'"; if (oConnector.execOracleSQL(conn, tmpSql)) { @@ -103,12 +105,12 @@ public class OracleExtractHelper { } /** - * �����û�����Ȩ + * 创建用户并授权 * - * @param conn - * @param oc + * @param conn 汇总库连接 + * @param oc 汇总库信息 */ - public void createUser(Connection conn, OracleConnectorParams oc) { + public void createUser(Connection conn, GatherOracleInfo oc) { String strTUser = oc.getName() + Configs.TABLE_SUFFIX; String sql = "Create user " + strTUser + " default tablespace " + Configs.GATHER_TABLESPACE_NAME + " identified by " @@ -119,10 +121,10 @@ public class OracleExtractHelper { } /** - * ִ�л��ܲ��� + * 执行汇总操作 * - * @param conn - * @param oc + * @param conn 汇总库连接 + * @param oc 采集库 */ public void extractColleDB(Connection conn, OracleConnectorParams oc) { String strTUser = oc.getName() + Configs.TABLE_SUFFIX; diff --git a/src/com/platform/service/OracleExtractService.java b/src/com/platform/service/OracleExtractService.java index cd64be1f..9b858706 100644 --- a/src/com/platform/service/OracleExtractService.java +++ b/src/com/platform/service/OracleExtractService.java @@ -6,7 +6,7 @@ import com.platform.entities.OracleConnectorParams; import com.platform.oracle.OracleConnector; import com.platform.utils.Configs; -public class OracleExtractService implements Runnable { +public class OracleExtractService extends Thread implements Runnable { private OracleConnectorParams ocp; private java.sql.Connection conn; @@ -15,11 +15,10 @@ public class OracleExtractService implements Runnable { String url = ""; this.conn=OracleConnector.ConnectionBuilder(url, Configs.GATHER_USER_NAME, Configs.GATHER_USER_PASSWORD); } - @Override public void run() { // TODO Auto-generated method stub - } + } } diff --git a/src/com/platform/service/OracleStatusService.java b/src/com/platform/service/OracleStatusService.java index 158eaf3f..adb7ea00 100644 --- a/src/com/platform/service/OracleStatusService.java +++ b/src/com/platform/service/OracleStatusService.java @@ -17,9 +17,9 @@ import com.platform.utils.Configs; public class OracleStatusService { private static Map<String, Timer> alliveTask = new Hashtable<String, Timer>(); - public final static int EXEC_TIME = 10;// ���Ӷ��ٴκɹ���ȡ������ - public final static long INTERVAL_TIME = 60 * 1000;// ÿ�����ٺ���ִ��һ���������� - public final static long DELAY_TIME = 0; // �ӳٶ������ִ�� + public final static int EXEC_TIME = 10;// 连接多少次后不成功,取消链接 + public final static long INTERVAL_TIME = 60 * 1000;// 每隔多少毫秒执行一次连接任务 + public final static long DELAY_TIME = 0; // 延迟多少秒后执行 public void connectToOracle(String replicasName) { SimpleKubeClient sKubeClient = new SimpleKubeClient(); @@ -55,7 +55,7 @@ public class OracleStatusService { } /** - * ȡ�����Ƴ�ָ����ʱ���� + * 取消并移除指定定时任务 * * * @param taskName @@ -73,7 +73,7 @@ public class OracleStatusService { } /** - * ��ն�ʱ���� + * 清空定时任务 */ public void cleanUpAlliveTask() { Iterator<Map.Entry<String, Timer>> iterator = alliveTask.entrySet() @@ -86,7 +86,7 @@ public class OracleStatusService { } /** - * ����oracle������ + * 链接oracle任务类 * * @author wuming * @@ -111,17 +111,17 @@ public class OracleStatusService { client.updateOrAddReplicasLabelById(taskName, "status", "1"); } else { String url = "jdbc:oracle:thin:@" + ocp.getIp() + ":" - + ocp.getPort() + ":" + ocp.getDatabase(); + + ocp.getPort() + "/" + ocp.getDatabaseName(); boolean flag = OracleConnector.canConnect(url, ocp.getUser(), ocp.getPassword()); - String message = "ʧ��"; + String message = "失败"; if (flag && alliveTask.containsKey(taskName)) { client.updateOrAddReplicasLabelById(taskName, "status", "2"); - message = "�ɹ�"; - killAlliveTask(taskName); // ���ӳɹ���ȡ������ + message = "成功"; + killAlliveTask(taskName); // 连接成功,取消连接 } - Configs.CONSOLE_LOGGER.info("���ӵ����ݿ���� " + taskName - + "\t[���ӽ���� " + message + "]"); + Configs.CONSOLE_LOGGER.info("连接到数据库服务: " + taskName + + "\t[连接结果: " + message + "]"); } count++; } diff --git a/src/com/platform/service/impl/GfsServiceImpl.java b/src/com/platform/service/impl/GfsServiceImpl.java new file mode 100644 index 00000000..89bb3714 --- /dev/null +++ b/src/com/platform/service/impl/GfsServiceImpl.java @@ -0,0 +1,122 @@ + +/** + * 文件名 : GfsServiceImpl.java + * 版权 : <版权/公司名> + * 描述 : <描述> + * @author chen + * 版本 : <版本> + * 修改时间: 2016年9月8日 + * 修改内容: <修改内容> + */ +package com.platform.service.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.stereotype.Service; + +import com.platform.entities.FolderNode; +import com.platform.entities.VolumeEntity; +import com.platform.glusterfs.CopyData; +import com.platform.glusterfs.GetTreeData; +import com.platform.glusterfs.VolumeInfo; +import com.platform.service.IGfsService; +import com.platform.utils.CacheTreeData; +import com.platform.utils.VolumeThread; +import com.platform.utils.getTreeDataByPath; + +/** + * <一句话功能简述> gfs功能实现类 + * <功能详细描述> + * @author chen + * @version [版本号,2016年9月8日] + * @see [相关类/方法] + * @since [产品/模块版本] + */ +@Service(value = "gfsService") +public class GfsServiceImpl implements IGfsService { + + /** gfs目录树形查询 */ + private getTreeDataByPath getFolder = new getTreeDataByPath(); + + /** 数据迁移实现 */ + private CopyData copydata = new CopyData(); + + /** Volume信息查询 */ + private VolumeInfo volumeInfo = new VolumeInfo(); + + @Override + 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 { + int status = 0 ; + if (null != srcFolders) { + + for (String string : srcFolders) { + status = copydata.copyFolderFiles(string, dstFolder, name); + } + } + return status; + } + + /* (non-Javadoc) + * @see com.platform.service.IGfsService#getAllVolume() + */ + @Override + public List<VolumeEntity> getAllVolumes() throws Exception { + List<VolumeEntity> volumeList = new ArrayList<>(); + List<String> volumeNameList = volumeInfo.showAllVolumeName(); + for (String volumeName : volumeNameList) { + VolumeEntity volume = new VolumeEntity(); + volume.setName(volumeName); + String path = volumeInfo.getVolumeMountPoint(volumeName); + volume.setPath(path); + volume.setAllSize(volumeInfo.getVolumeAllSize(volumeName)); + volume.setUsedSize(volumeInfo.getVolumeUseSize(volumeName)); + //TODO +// volume.setBrick(brick); + if (null != volume.getPath()) { +// volume.setFolder(gfsTree.getDatas(volume.getPath())); + volume.setFolder(getFolder(path)); + } + volumeList.add(volume); + } + + return volumeList; + } + + @Override + public VolumeEntity getOneVolume(String volumeName) throws Exception { + VolumeEntity volume = new VolumeEntity(); + volume.setName(volumeName); + String path = volumeInfo.getVolumeMountPoint(volumeName); + volume.setPath(path); +// volume.setAllSize(volumeInfo.getVolumeAllSize(volumeName)); +// volume.setUsedSize(volumeInfo.getVolumeUseSize(volumeName)); +// volume.setBrick(brick); + if (null != volume.getPath()) { + volume.setFolder(getFolder(path)); + } + 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; + } + +} diff --git a/src/com/platform/service/impl/MySqlServiceImpl.java b/src/com/platform/service/impl/MySqlServiceImpl.java new file mode 100644 index 00000000..b880b9c0 --- /dev/null +++ b/src/com/platform/service/impl/MySqlServiceImpl.java @@ -0,0 +1,56 @@ +package com.platform.service.impl; + +import java.util.List; + +import javax.annotation.Resource; + +import org.springframework.stereotype.Service; + +import com.platform.dao.GatherOracleDao; +import com.platform.entities.GatherOracleInfo; +import com.platform.service.IMySqlService; + +@Service(value = "mySqlService") +public class MySqlServiceImpl implements IMySqlService{ + + @Resource(name = "gatherOracleDao") + private GatherOracleDao gatherOracleDao; + + @Override + public List<GatherOracleInfo> findAllMySql() throws Exception { + List<GatherOracleInfo> result = gatherOracleDao.selectAllOracle(); + return result; + } + + @Override + public int deleteMySql(int id) throws Exception { + + int result = 0; + if (id > 0) { +// result = gatherOracleDao.deleteOracleById(id); + GatherOracleInfo oracle = new GatherOracleInfo(); + oracle.setId(id); + oracle.setRemove("1"); + result = gatherOracleDao.updateOracleById(oracle ); + } + return result; + } + + public int insertOracle(GatherOracleInfo oracle) throws Exception { + int result = gatherOracleDao.insertOracle(oracle); + return result; + } + + @Override + public int updateOracle(GatherOracleInfo oracle) throws Exception { + int result; + if (oracle.getId() > 0) { + result = gatherOracleDao.updateOracleById(oracle); + } + else { + result = gatherOracleDao.insertOracle(oracle); + } + return result; + } + +} diff --git a/src/com/platform/service/impl/OracleExtractServiceImpl.java b/src/com/platform/service/impl/OracleExtractServiceImpl.java new file mode 100644 index 00000000..9d2a36e5 --- /dev/null +++ b/src/com/platform/service/impl/OracleExtractServiceImpl.java @@ -0,0 +1,63 @@ +package com.platform.service.impl; + +import java.sql.Connection; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.springframework.stereotype.Service; + +import com.platform.entities.DataInfoEntity; +import com.platform.entities.GatherOracleInfo; +import com.platform.entities.OracleConnectorParams; +import com.platform.oracle.OracleConnector; +import com.platform.service.IOracleExtractService; +import com.platform.service.OracleExtractHelper; +import com.platform.utils.Bean2MapUtils; + +@Service(value = "OracleExtract") +public class OracleExtractServiceImpl implements IOracleExtractService { + + /** + * 抽取 + */ + private OracleExtractHelper oracleExtract = new OracleExtractHelper(); + + /** + * 数据库连接实现类 + */ + private OracleConnector connect = new OracleConnector(); + + @Override + public boolean extractOracle(String name, List<Map<String, String>> dataInfoMap, + Map<String, String> oracleConnect) throws Exception { + boolean isSuccess = false; + try{ + //map转 bean(汇总库信息-带tableName的) + GatherOracleInfo oracleModel = (GatherOracleInfo) Bean2MapUtils.convertMap(GatherOracleInfo.class, oracleConnect); + + //采集库连接参数 + List<OracleConnectorParams> datainfos = new ArrayList<OracleConnectorParams>(); + for (Map<String, String> map : dataInfoMap) { + OracleConnectorParams dataInfoEntity = (OracleConnectorParams) Bean2MapUtils.convertMap(OracleConnectorParams.class, oracleConnect); + datainfos.add(dataInfoEntity); + } + + Connection conn = OracleConnector.ConnectionBuilder("jdbc:oracle:thin:@" + oracleModel.getIp() + ":" + oracleModel.getPort() + "/" + + oracleModel.getDatabaseName(), oracleModel.getUser(), oracleModel.getPassword()); + + for (OracleConnectorParams collectOracle : datainfos) { + + oracleExtract.createDBLink(conn, collectOracle); + oracleExtract.createTableSpace(conn, oracleModel); + oracleExtract.createUser(conn, oracleModel); + oracleExtract.extractColleDB(conn, collectOracle); + } + isSuccess = true; + }catch(Exception e){ + + } + return false; + } + +} diff --git a/src/com/platform/utils/Bean2MapUtils.java b/src/com/platform/utils/Bean2MapUtils.java new file mode 100644 index 00000000..7fea556d --- /dev/null +++ b/src/com/platform/utils/Bean2MapUtils.java @@ -0,0 +1,87 @@ +package com.platform.utils; + +import java.beans.BeanInfo; +import java.beans.IntrospectionException; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +public class Bean2MapUtils { + + /** + * 将一个 Map 对象转化为一个 JavaBean + * @param type 要转化的类型 + * @param map 包含属性值的 map + * @return 转化出来的 JavaBean 对象 + * @throws IntrospectionException + * 如果分析类属性失败 + * @throws IllegalAccessException + * 如果实例化 JavaBean 失败 + * @throws InstantiationException + * 如果实例化 JavaBean 失败 + * @throws InvocationTargetException + * 如果调用属性的 setter 方法失败 + */ + public static Object convertMap(Class type, Map map) + throws IntrospectionException, IllegalAccessException, + InstantiationException, InvocationTargetException { + BeanInfo beanInfo = Introspector.getBeanInfo(type); // 获取类属性 + Object obj = type.newInstance(); // 创建 JavaBean 对象 + + // 给 JavaBean 对象的属性赋值 + PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); + for (int i = 0; i< propertyDescriptors.length; i++) { + PropertyDescriptor descriptor = propertyDescriptors[i]; + String propertyName = descriptor.getName(); + try{ + if (map.containsKey(propertyName)) { + // 下面一句可以 try 起来,这样当一个属性赋值失败的时候就不会影响其他属性赋值。 + Object value = map.get(propertyName); + + Object[] args = new Object[1]; + args[0] = value; + + descriptor.getWriteMethod().invoke(obj, args); + } + } + catch(Exception e){ + + } + } + return obj; + } + + /** + * 将一个 JavaBean 对象转化为一个 Map + * @param bean 要转化的JavaBean 对象 + * @return 转化出来的 Map 对象 + * @throws IntrospectionException 如果分析类属性失败 + * @throws IllegalAccessException 如果实例化 JavaBean 失败 + * @throws InvocationTargetException 如果调用属性的 setter 方法失败 + */ + public static Map convertBean(Object bean) + throws IntrospectionException, IllegalAccessException, InvocationTargetException { + Class type = bean.getClass(); + Map returnMap = new HashMap(); + BeanInfo beanInfo = Introspector.getBeanInfo(type); + + PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); + for (int i = 0; i< propertyDescriptors.length; i++) { + PropertyDescriptor descriptor = propertyDescriptors[i]; + String propertyName = descriptor.getName(); + if (!propertyName.equals("class")) { + Method readMethod = descriptor.getReadMethod(); + Object result = readMethod.invoke(bean, new Object[0]); + if (result != null) { + returnMap.put(propertyName, result); + } else { + returnMap.put(propertyName, ""); + } + } + } + return returnMap; + } +} diff --git a/src/com/platform/utils/CacheTreeData.java b/src/com/platform/utils/CacheTreeData.java new file mode 100644 index 00000000..80246a6d --- /dev/null +++ b/src/com/platform/utils/CacheTreeData.java @@ -0,0 +1,18 @@ +package com.platform.utils; + +import com.platform.entities.FolderNode; + +public class CacheTreeData { + + private static FolderNode folders = null; + + public static FolderNode getFolders() { + return folders; + } + + public static void setFolders(FolderNode folders) { + CacheTreeData.folders = folders; + } + + +} diff --git a/src/com/platform/utils/ConfigLoder.java b/src/com/platform/utils/ConfigLoder.java index fe3ef0f9..ce3b30a0 100644 --- a/src/com/platform/utils/ConfigLoder.java +++ b/src/com/platform/utils/ConfigLoder.java @@ -29,7 +29,7 @@ public class ConfigLoder { } /** - * ��ȡ��Property�е�����ֵ + * 读取文Property中的属性值 * * @param key * @return diff --git a/src/com/platform/utils/ConfigPropertyReader.java b/src/com/platform/utils/ConfigPropertyReader.java index 7f9df866..d2a3bd9b 100644 --- a/src/com/platform/utils/ConfigPropertyReader.java +++ b/src/com/platform/utils/ConfigPropertyReader.java @@ -29,7 +29,7 @@ public class ConfigPropertyReader { } /** - * ��ȡ��Property�е�����ֵ + * 读取文Property中的属性值 * * @param key * @return diff --git a/src/com/platform/utils/Configs.java b/src/com/platform/utils/Configs.java index 87ee6c2e..bb2afede 100644 --- a/src/com/platform/utils/Configs.java +++ b/src/com/platform/utils/Configs.java @@ -3,6 +3,13 @@ package com.platform.utils; import org.apache.log4j.Logger; public class Configs { + + /** 全局自定义异常--编码 */ + public static final String GLOBAL_EXP_CUSTOM = "3001001001"; + + /** 全局非自定义异常--编码 */ + public static final String GLOBAL_EXP_NOT_CUSTOM = "3001001002"; + public static final String CONFIG_LOCALTION = "WebContent/WEB-INF/config/config.properties"; public static final Logger CONSOLE_LOGGER = Logger.getLogger("console"); @@ -14,32 +21,32 @@ public class Configs { public static final Logger LOGGER = Logger.getLogger(Configs.class); - public static String KUBE_MASTER_URL = "http://192.168.0.113:8080/"; // kubernetes��Ⱥ��maser + public static String KUBE_MASTER_URL = "http://192.168.0.113:8080/"; // kubernetes集群的maser // URl - public static int ORACLE_DEFAULT_PORT = 1521; // oracle��Ĭ�϶˿ں� + public static int ORACLE_DEFAULT_PORT = 1521; // oracle的默认端口号 - public static String COLLECT_USER_NAME = "system"; //�ɼ�ͳһ�ĵ����û��� + public static String COLLECT_USER_NAME = "system"; //采集统一的登入用户名 - public static String COLLECT_PASSWORD = "oracle"; //�ɼ�ͳһ�ĵ������� + public static String COLLECT_PASSWORD = "oracle"; //采集统一的登入密码 - public static String COLLECT_SERVICE_NAME = "orcl"; //�ɼ���ͳһ�ķ����� + public static String COLLECT_SERVICE_NAME = "orcl"; //采集库统一的服务名 - public static String GATHER_PORT ="1521"; //���ܿ�Ķ˿ں� + public static String GATHER_PORT ="1521"; //汇总库的端口号 - public static String GATHER_USER_NAME = "system"; //���ܿ�ĵ����û��� + public static String GATHER_USER_NAME = "system"; //汇总库的登入用户名 - public static String GATHER_USER_PASSWORD = "1"; //���ܿ�ĵ������� + public static String GATHER_USER_PASSWORD = "1"; //汇总库的登入密码 - public static String GATHER_SERVICE_NAME = "orcl"; //���ܿ�ķ����� + public static String GATHER_SERVICE_NAME = "orcl"; //汇总库的服务名 - public static String TABLE_SUFFIX = "_20152016"; //���ܿ���ܱ��ĺ��� + public static String TABLE_SUFFIX = "_20152016"; //汇总库汇总表的后缀名 - public static String EXTRACT_LOG_LOCALTION = "/home/log"; //���ݻ�����־����λ�� + public static String EXTRACT_LOG_LOCALTION = "/home/log"; //数据汇总日志保存位置 - public static String GATHER_TABLESPACE_NAME=""; //���ռ��� + public static String GATHER_TABLESPACE_NAME=""; //表空间名 - public static String GATHER_TABLESPACE_PATH=""; //���ռ�·�� + public static String GATHER_TABLESPACE_PATH=""; //表空间路径 - public static String GATHER_TABLE_PASSWORD=""; //�������� + public static String GATHER_TABLE_PASSWORD=""; //登入密码 } diff --git a/src/com/platform/utils/ConfigsLoader.java b/src/com/platform/utils/ConfigsLoader.java index 1b1c1959..b47695d6 100644 --- a/src/com/platform/utils/ConfigsLoader.java +++ b/src/com/platform/utils/ConfigsLoader.java @@ -11,18 +11,19 @@ public class ConfigsLoader implements ServletContextListener { @Override public void contextDestroyed(ServletContextEvent sEvent) { // TODO Auto-generated method stub - Configs.CONSOLE_LOGGER.info("ϵͳֹͣ.."); + Configs.CONSOLE_LOGGER.info("系统停止.."); } @SuppressWarnings("static-access") @Override public void contextInitialized(ServletContextEvent sEvent) { // TODO Auto-generated method stub - Configs.CONSOLE_LOGGER.info("ϵͳ��ʼ��.."); + Configs.CONSOLE_LOGGER.info("系统初始化.."); String contextPath = sEvent.getServletContext().getRealPath("/") + "WEB-INF/config/config.properties"; this.cReader = ConfigPropertyReader.Builder(contextPath); init(); + new VolumeThread("").start(); } public static void init() { diff --git a/src/com/platform/utils/Constant.java b/src/com/platform/utils/Constant.java new file mode 100644 index 00000000..5e3ceef0 --- /dev/null +++ b/src/com/platform/utils/Constant.java @@ -0,0 +1,24 @@ +package com.platform.utils; + +import java.util.List; + +public class Constant { + public static String rootUser = "root"; + public static String rootPasswd = "root"; + public static String hostIp = "192.168.0.116"; + public static int port = 22; + public static String glusterPeerStatus = "gluster peer status"; + public static String glusterVolumeInfo = "gluster volume info "; + public static String df = "df -k "; + public static String peerincluster_connected="PeerinCluster(Connected)"; + public static String distributed="distributed"; + public static String replica="replica"; + public static String stripe="stripe"; + public static String noVolume="No volumes present"; + public static GanymedSSH ganymedSSH=new GanymedSSH(hostIp, rootUser, rootPasswd, port); + + /** + * volume 获取的线程休眠时间 + */ + public final static int get_volume_sleep_time = 300000; +} diff --git a/src/com/platform/utils/DateHandle.java b/src/com/platform/utils/DateHandle.java new file mode 100644 index 00000000..90ebb9d7 --- /dev/null +++ b/src/com/platform/utils/DateHandle.java @@ -0,0 +1,9 @@ +package com.platform.utils; +import java.util.Date; +import java.text.SimpleDateFormat; +public class DateHandle { +public static String getNow() { + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式 + return df.format(new Date());// new Date()为获取当前系统时�? +} +} diff --git a/src/com/platform/utils/FileOperateHelper.java b/src/com/platform/utils/FileOperateHelper.java index 31827547..b2b9fa9b 100644 --- a/src/com/platform/utils/FileOperateHelper.java +++ b/src/com/platform/utils/FileOperateHelper.java @@ -8,7 +8,7 @@ import java.io.IOException; import java.io.InputStreamReader; /** - * �ļ���д���������� + * 文件读写操作帮助类 * * @author wuming * @@ -16,7 +16,7 @@ import java.io.InputStreamReader; public class FileOperateHelper { /** - * ���ӵķ�ʽ����Ϣд���ļ� + * 以追加的方式将信息写入文件 * * @param path * @param message @@ -27,7 +27,7 @@ public class FileOperateHelper { File file = new File(path); if (file.exists()) file.createNewFile(); - FileOutputStream out = new FileOutputStream(file, true); // ����ӷ�ʽ��true + FileOutputStream out = new FileOutputStream(file, true); // 如果追加方式用true StringBuffer sb = new StringBuffer(); sb.append(message).append("\n"); out.write(sb.toString().getBytes("utf-8")); @@ -37,7 +37,7 @@ public class FileOperateHelper { } /** - * �ļ���ȡ���� + * 文件读取方法 * @param path * @return */ diff --git a/src/com/platform/utils/GanymedSSH.java b/src/com/platform/utils/GanymedSSH.java new file mode 100644 index 00000000..54a7a84e --- /dev/null +++ b/src/com/platform/utils/GanymedSSH.java @@ -0,0 +1,265 @@ +package com.platform.utils; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.log4j.Logger; +import org.apache.log4j.PropertyConfigurator; + +import ch.ethz.ssh2.Connection; +import ch.ethz.ssh2.Session; +import ch.ethz.ssh2.StreamGobbler; + +import ch.ethz.ssh2.*; + + + +public class GanymedSSH { + public static Logger log = Logger.getLogger(GanymedSSH.class); + Connection conn; + + public boolean status = true;// 锟角凤拷锟斤拷锟街达拷锟斤拷锟斤拷锟阶刺� + + public GanymedSSH() { + // TODO Auto-generated constructor stub + + } + + public GanymedSSH(String host, String username, String password, int port) { + // TODO Auto-generated constructor stub + try { + conn = getOpenedConnection(host, username, password, port); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + + public Connection getOpenedConnection(String host, String username, String password, int port) + throws IOException { + + conn = new Connection(host, port); + conn.connect(); // make sure the connection is opened + boolean isAuthenticated = conn.authenticateWithPassword(username, password); + if (isAuthenticated == false) + throw new IOException("Authentication failed."); + return conn; + } + + public void execCmdNoWaitAcquiescent(String cmd) { + String host=Constant.hostIp; + String username=Constant.rootUser; + String password=Constant.rootPasswd; + int port=Constant.port; + + Session sess = null; + try { + conn = getOpenedConnection(host, username, password, port); + sess = conn.openSession(); + // 执锟斤拷cmd + sess.execCommand(cmd); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + sess.close(); + + } + } + + public void execCmdNoWait(String host, String username, String password, int port, String cmd) { + + Session sess = null; + try { + conn = getOpenedConnection(host, username, password, port); + sess = conn.openSession(); + // 执锟斤拷cmd + sess.execCommand(cmd); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + sess.close(); + + } + } + + public List<String> execCmdWaitAcquiescent(String cmd) { + String host=Constant.hostIp; + String username=Constant.rootUser; + String password=Constant.rootPasswd; + int port=Constant.port; + List<String> reStrings = new ArrayList<String>(); + + Session sess = null; + try { + + sess = conn.openSession(); + // 执锟斤拷cmd + sess.execCommand(cmd); + + InputStream stdout = new StreamGobbler(sess.getStdout()); + InputStream stderr = new StreamGobbler(sess.getStderr()); + BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(stdout)); + BufferedReader stderrReader = new BufferedReader(new InputStreamReader(stderr)); + while (true) { + String line = stdoutReader.readLine(); + + if (line != null) { +// System.out.println(line); + reStrings.add(line); + } else { + break; + } + } + + while (true) { + String line = stderrReader.readLine(); + + if (line != null) { +// System.out.println(line); + reStrings.add(line); + } else { + break; + } + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + sess.close(); + + } + return reStrings; + } + + public List<String> execCmdWait(String host, String username, String password, int port, String cmd) { + List<String> reStrings = new ArrayList<String>(); + + Session sess = null; + try { + + sess = conn.openSession(); + // 执锟斤拷cmd + sess.execCommand(cmd); + + InputStream stdout = new StreamGobbler(sess.getStdout()); + InputStream stderr = new StreamGobbler(sess.getStderr()); + BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(stdout)); + BufferedReader stderrReader = new BufferedReader(new InputStreamReader(stderr)); + while (true) { + String line = stdoutReader.readLine(); + + if (line != null) { +// System.out.println(line); + reStrings.add(line); + } else { + break; + } + } + + while (true) { + String line = stderrReader.readLine(); + + if (line != null) { +// System.out.println(line); + reStrings.add(line); + } else { + break; + } + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + sess.close(); + + } + 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>(); + + + Session sess = null; + try { + + sess = conn.openSession(); + // 执锟斤拷cmd + sess.execCommand(cmd); + InputStream stdout = new StreamGobbler(sess.getStdout()); + + @SuppressWarnings("resource") + BufferedReader br = new BufferedReader(new InputStreamReader(stdout)); + while (true) { + String line = br.readLine(); + if (line != null) { + String[] lines = line.split(" "); + String key = lines[1].replace(prefix, ""); + String value = lines[0]; + md5.put(key, value); + // System.out.println(key+"\t"+value); + } else { + break; + } + + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + sess.close(); + + } + return md5; + } + + public String execGetSize(String cmd) { + status = false; + String str_size = "0"; + Session sess = null; + try { + + // 执锟斤拷cmd + sess = conn.openSession(); + sess.execCommand(cmd); + InputStream stdout = new StreamGobbler(sess.getStdout()); + + @SuppressWarnings("resource") + BufferedReader br = new BufferedReader(new InputStreamReader(stdout)); + while (true) { + String line = br.readLine(); + if (line != null) { + // String[] lines=line.split(" "); + // str_size=lines[0]; + + str_size = line; + } else { + break; + } + + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + sess.close(); + } + status = true; + return str_size; + } + public static void main(String[] args) { + PropertyConfigurator.configure("log4j.properties"); + } + +} diff --git a/src/com/platform/utils/RunCommand.java b/src/com/platform/utils/RunCommand.java new file mode 100644 index 00000000..66292a2a --- /dev/null +++ b/src/com/platform/utils/RunCommand.java @@ -0,0 +1,60 @@ +package com.platform.utils; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; +import org.apache.log4j.*; + +public class RunCommand { + + + public static Logger log = Logger.getLogger(RunCommand.class); + + public List<String> runCommandWait(String command) { + List<String> reStrings = null; + String cmds[] = { "/bin/bash", "-c", command }; + try { + Process ps = Runtime.getRuntime().exec(cmds); + ps.waitFor(); + BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream())); + reStrings = new ArrayList<String>(); + String line; + while ((line = br.readLine()) != null) { + reStrings.add(line); + // System.out.println(line); + } + + br = new BufferedReader(new InputStreamReader(ps.getErrorStream())); + reStrings = new ArrayList<String>(); + + while ((line = br.readLine()) != null) { + reStrings.add(line); + // System.out.println(line); + } + } catch (Exception e) { + + log.error("0001 runCommandWait is error"); + + e.printStackTrace(); + } + return reStrings; + } + + public int runCommand(String command) { + List<String> reStrings = null; + String cmds[] = { "/bin/bash", "-c", command }; + try { + Process ps = Runtime.getRuntime().exec(cmds); + } catch (Exception e) { + + log.error("0002 runCommand execute " + command + " is error"); + + e.printStackTrace(); + return -1; + } + return 1; + } + + +} diff --git a/src/com/platform/utils/TestSupport.java b/src/com/platform/utils/TestSupport.java new file mode 100644 index 00000000..74d938cb --- /dev/null +++ b/src/com/platform/utils/TestSupport.java @@ -0,0 +1,14 @@ +package com.platform.utils; + +import java.util.ArrayList; +import java.util.List; + +public class TestSupport { +public List<String> strToList(String str) { + List<String> reStrings=new ArrayList<String>(); + for(String one:str.split("\n")){ + reStrings.add(one); + } + return reStrings; +} +} diff --git a/src/com/platform/utils/UtilsHelper.java b/src/com/platform/utils/UtilsHelper.java index 348f7a54..3da84c22 100644 --- a/src/com/platform/utils/UtilsHelper.java +++ b/src/com/platform/utils/UtilsHelper.java @@ -23,7 +23,7 @@ public class UtilsHelper { for (Field fs : fileds) { String fieldName = fs.getName(); String fieldType = fs.getGenericType().toString() - .replace("class ", ""); // ���type�������ͣ���ǰ�����"class "����������� + .replace("class ", ""); // 如果type是类类型,则前面包含"class ",后面跟类名 if (paramMap.containsKey(fieldName)) { Method method = clazz.getDeclaredMethod( getAttributeSetName(fs), Class.forName(fieldType)); @@ -72,11 +72,11 @@ public class UtilsHelper { } /** - * ��������{@fs}��set���������� + * 生成属性{@fs}的set方法的名字 * * @param fs - * ���Զ��� - * @return set���������� + * 属性对象 + * @return set方法的名字 */ private static String getAttributeSetName(Field fs) { String fieldName = fs.getName(); diff --git a/src/com/platform/utils/VolumeThread.java b/src/com/platform/utils/VolumeThread.java new file mode 100644 index 00000000..05357c8f --- /dev/null +++ b/src/com/platform/utils/VolumeThread.java @@ -0,0 +1,52 @@ +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; + } + +} diff --git a/src/com/platform/utils/getTreeDataByPath.java b/src/com/platform/utils/getTreeDataByPath.java new file mode 100644 index 00000000..27841183 --- /dev/null +++ b/src/com/platform/utils/getTreeDataByPath.java @@ -0,0 +1,42 @@ +package com.platform.utils; + +import java.util.List; + +import com.platform.entities.FolderNode; + +public class getTreeDataByPath { + + /** + * @param path + * @return + */ + public FolderNode findByPath(String path) { + FolderNode folderNode = CacheTreeData.getFolders(); + if (null == folderNode) { + return null; + } + FolderNode folder = getFolder(folderNode, path); + return folder; + } + + /** + * @param f + * @return + */ + private FolderNode getFolder(FolderNode f, String path){ + FolderNode result = null; + if(path.equals(f.getPath())){ + return f; + } + List<FolderNode> folds = f.getChildNodes(); + if (null != folds) { + for (FolderNode folderNode : folds) { + result = getFolder(folderNode, path); + if (null != result) { + break; + } + } + } + return result; + } +} diff --git a/test/com/platform/test/FolderReader.java b/test/com/platform/test/FolderReader.java index cb2f440a..5aa5eee7 100644 --- a/test/com/platform/test/FolderReader.java +++ b/test/com/platform/test/FolderReader.java @@ -21,8 +21,8 @@ public class FolderReader { childrens.add(children); } } - folderNode = new FolderNode(file.getName(), file.getAbsolutePath(), - childrens); + /*folderNode = new FolderNode(file.getName(), file.getAbsolutePath(), + childrens);*/ } return folderNode; }