reset add md5checkout

glusterfs-api
lily 9 years ago
parent 6ce9f75ee7
commit 48ae986d5c

@ -2,6 +2,7 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<<<<<<< HEAD
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/MyEclipse Tomcat v7.0">
@ -10,10 +11,19 @@
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
=======
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v7.0">
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275
<attributes>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<<<<<<< HEAD
<classpathentry kind="lib" path="D:/Program Files/apache-tomcat-7.0.70/lib/servlet-api.jar"/>
=======
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/com.sun.java.jdk7.win32.x86_64_1.7.0.u45"/>
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275
<classpathentry kind="output" path="build/classes"/>
</classpath>

4
.gitignore vendored

@ -1,2 +1,6 @@
<<<<<<< HEAD
/target/
/build
=======
build/
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275

@ -44,7 +44,7 @@ extract-log-localtion=/home/log/
gather-tablespace-name=TS_TTSSS
gather-tablespace-path=
gather-table-user-password=
kubeMasterUrl=http://192.168.0.116:8080/
kubeMasterUrl=http://192.168.0.110:8080/
collect-user-name=system
collect-password=oracle
collect-service-name=orcl

@ -7,8 +7,10 @@
<typeAlias alias="EncodedInfoEntity" type="com.platform.entities.EncodedInfoEntity" />
<typeAlias alias="DataInfoEntity" type="com.platform.entities.DataInfoEntity" />
<typeAlias alias="PagerOptions" type="com.platform.entities.PagerOptions"/>
<typeAlias alias="GatherOracleInfo" type="com.platform.entities.GatherOracleInfo"/>
</typeAliases>
<mappers>
<mapper resource="com/dao/mapper/data-detaisl-mapper.xml" />
<mapper resource="com/dao/mapper/data-details-mapper.xml" />
<mapper resource="com/dao/mapper/config-details-mapper.xml"/>
</mappers>
</configuration>

@ -59,7 +59,7 @@
</listener>
<!-- 防止Spring内存溢出监听器 -->
<listener>
<!-- <listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
</listener> -->
</web-app>

@ -1,37 +0,0 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>extendGlusterfs</groupId>
<artifactId>extendGlusterfs</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>extendGlusterfs</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/ch.ethz.ganymed/ganymed-ssh2 -->
<dependency>
<groupId>ch.ethz.ganymed</groupId>
<artifactId>ganymed-ssh2</artifactId>
<version>build209</version>
</dependency>
</dependencies>
</project>

@ -1,3 +1,4 @@
/**
* BaseController.java
* : XX
@ -60,4 +61,68 @@ public class BaseController {
return response;
}
}
=======
/**
* BaseController.java
* : XX
* : <>
* 201697
* <>
*/
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 [201697]
* @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;
}
}
}

@ -1,3 +1,4 @@
package com.base;
import org.apache.log4j.Logger;
@ -122,3 +123,129 @@ public class CustomException extends Exception {
return cause;
}
}
=======
package com.base;
import org.apache.log4j.Logger;
/**
* <>
* <>
* @author chen
* @version [201698]
* @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;
}
}

@ -0,0 +1,146 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
"http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">
<mapper namespace="com.platform.dao.GatherOracleDao">
<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="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>

@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
"http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">
<mapper namespace="com.platform.dao.DataInfoDao">
<resultMap id="getEntityByText" type="DataInfoEntity">
<id property="id" column="id" javaType="int" jdbcType="INTEGER" />
<result property="regionalismCode" column="regionalism_code"
javaType="string" jdbcType="VARCHAR" />
<result property="cityName" column="city_name" javaType="string"
jdbcType="VARCHAR" />
<result property="districtName" column="district_name"
javaType="string" jdbcType="VARCHAR" />
<result property="systemCode" column="system_code" javaType="int"
jdbcType="INTEGER" />
<result property="systemName" column="system_name" javaType="string"
jdbcType="VARCHAR" />
<result property="dataType" column="data_type" javaType="string"
jdbcType="VARCHAR" />
<result property="dataVersion" column="data_version" javaType="int"
jdbcType="INTEGER" />
<result property="submittedBatch" column="submitted_batch"
javaType="string" jdbcType="VARCHAR" />
<result property="dataPath" column="data_path" javaType="string"
jdbcType="VARCHAR" />
<result property="charset" column="data_charset" javaType="string"
jdbcType="VARCHAR" />
<result property="collectingTime" column="collection_time"
javaType="string" jdbcType="DATE" />
<result property="collectorContacts" column="collector_contacts"
javaType="string" jdbcType="VARCHAR" />
<result property="collectorName" column="collector_name"
javaType="string" jdbcType="VARCHAR" />
<result property="year" column="data_year" javaType="string"
jdbcType="VARCHAR" />
</resultMap>
<sql id="conditionsFilters">
<if test="PagerOptions.dataType!=null">
and data_details.data_type=#{PagerOptions.dataType}
</if>
<if test="PagerOptions.submittedBatch!=null">
and
data_details.submitted_batch=#{PagerOptions.submittedBatch}
</if>
<if test="PagerOptions.cityName!=null">
and data_details.city_name=#{PagerOptions.cityName}
</if>
<if test="PagerOptions.districtName!=null">
and
data_details.district_name=#{PagerOptions.districtName}
</if>
<if test="PagerOptions.dataVersion !=null">
and data_details.data_version=#{PagerOptions.dataVersion}
</if>
<if test="PagerOptions.systemName !=null">
and data_details=#{PagerOptions.systemName}
</if>
<if test="PagerOptions.dataYear !=null">
and data_details.data_year=#{PagerOptions.dataYear}
</if>
</sql>
<!-- 获取数据符合筛选条件的全部记录信息 -->
<select id="getLimitedDataInfoEntities" parameterType="PagerOptions"
resultMap="getEntityByText">
SELECT
id,regionalism_code,city_name,district_name,system_code,system_name,data_type,data_version,submitted_batch,data_path,data_charset,collection_time,collector_name,collector_contacts,data_year
FROM data_details
<if test="PagerOptions!=null">
<where>
<include refid="conditionsFilters" />
<choose>
<when test="PagerOptions.offset > 0">
and data_details.id>= #{PagerOptions.offset}
</when>
<otherwise>
and data_details.id>=0
</otherwise>
</choose>
</where>
ORDER BY data_details.id
<if test="PagerOptions.limit > 0">
LIMIT #{PagerOptions.limit}
</if>
</if>
</select>
<!-- 获取数据符合筛选条件的总记录条数 -->
<select id="getLimitedDataCount" resultType="java.lang.Integer"
parameterType="PagerOptions">
SELECT COUNT(id) FROM data_details
<if test="PagerOptions!=null">
<where>
<include refid="conditionsFilters" />
</where>
</if>
</select>
<!-- 获取数据查询的起始di -->
<select id="getLimitedBeginId" resultType="java.lang.Integer"
parameterType="PagerOptions">
SELECT MAX(idx) FROM (SELECT id idx FROM data_details
ORDER BY id LIMIT 0,#{PagerOptions.totalLimit}) AS TEMP
</select>
</mapper>

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

@ -1,3 +1,4 @@
<<<<<<< HEAD
package com.platform.controller;
import java.util.HashMap;
@ -97,3 +98,233 @@ public class DataModelController {
System.out.println("ooooooooo");
}
}
=======
package com.platform.controller;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
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.OracleExtractHelper;
import com.platform.service.OracleStatusService;
import com.platform.service.impl.MySqlServiceImpl;
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 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;
}
@RequestMapping("/data.json")
@ResponseBody
public ModelMap getAllDataToJson(HttpServletRequest res,
HttpServletResponse req) {
Map<String, String[]> paramMap = res.getParameterMap();
Set<String> keySet = paramMap.keySet();
Map<String, String> params = new HashMap<String, String>();
StringBuffer sb = new StringBuffer().append("<22><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:{");
for (String str : keySet) {
String value = paramMap.get(str)[0];
if (StringUtils.isNotEmpty(value)) {
params.put(str, value);
sb.append(str).append(":").append(value).append(",");
} else {
sb.append(str).append(":").append("null").append(",");
}
}
Configs.CONSOLE_LOGGER.info(sb.deleteCharAt(sb.length() - 1)
.append("}").toString());
PagerOptions pagerOptions = (PagerOptions) UtilsHelper
.newObjAndSetAttrsByClass(PagerOptions.class, params);
return dfs.getPagerTableData(pagerOptions);
}
@RequestMapping("/delete/data")
public void deleteData(HttpServletRequest res, HttpServletResponse req) {
Map<String, String[]> paramMap = res.getParameterMap();
String[] data = paramMap.get("data");
dfs.deleteData(data);
}
@RequestMapping("/connectOracle")
public void connectOracle(HttpServletRequest res, HttpServletResponse req) {
Map<String, String[]> paramMap = res.getParameterMap();
String[] oraclesName = paramMap.get("oracleName");
if (oraclesName != null)
for (String rcName : oraclesName) {
Configs.CONSOLE_LOGGER.info("连接成功\t" + rcName);
new OracleStatusService().connectToOracle(rcName);
}
}
@RequestMapping("/cancelOracleConection")
public void cancelOracleConnection(HttpServletRequest res,
HttpServletResponse req) {
Map<String, String[]> paramMap = res.getParameterMap();
String[] oraclesName = paramMap.get("oracleName");
String operate = paramMap.get("operation")[0];
if (null != oraclesName) {
for (String rcName : oraclesName) {
Configs.CONSOLE_LOGGER.info("连接成功:\t" + rcName);
new OracleStatusService().cancelToOracle(rcName, operate);
}
}
}
@RequestMapping("/oracle/{name}/extract")
public void extractOracleData(HttpServletRequest res,
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个tableName下)
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 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<VolumeEntity> result = gfsService.getAllVolumes();
return result;
}
@RequestMapping(value = "/volume/{name}/move", method= RequestMethod.POST)
@ResponseBody
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("path"), "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-----------------------");
}
}
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275

@ -1,3 +1,4 @@
<<<<<<< HEAD
package com.platform.controller;
import javax.servlet.http.HttpServletRequest;
@ -28,3 +29,35 @@ public class DefaultController {
}
}
=======
package com.platform.controller;
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;
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 ModelMap test(HttpServletRequest req, HttpServletResponse res){
//System.out.println(Class.class.getClass().getResource("/").getPath());
System.out.println(Configs.EXTRACT_LOG_LOCALTION);
return new ModelMap();
}
}
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275

@ -1,15 +1,34 @@
package com.platform.controller;
<<<<<<< HEAD
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
=======
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;
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275
import com.base.BaseController;
import com.base.CustomException;
import com.platform.entities.GfsFolderEntity;
<<<<<<< HEAD
=======
import com.platform.entities.VolumeEntity;
import com.platform.glusterfs.VolumeInfo;
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275
import com.platform.service.IGfsService;
@ -22,13 +41,21 @@ import com.platform.service.IGfsService;
* @since [/]
*/
@Controller
<<<<<<< HEAD
@RequestMapping("/folder")
=======
@RequestMapping("")
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275
public class FolderController extends BaseController {
@Resource(name = "gfsService")
private IGfsService gfsService;
<<<<<<< HEAD
@RequestMapping("/getAllSubPathByPath")
=======
@RequestMapping(value="/getAllSubPathByPath", method= RequestMethod.POST)
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275
public Object getAllSubPathByPath(String path) throws Exception {
System.out.println(path);
Object result = null;
@ -39,6 +66,7 @@ public class FolderController extends BaseController {
return result;
}
<<<<<<< HEAD
@RequestMapping("/copyFolder")
public Object copyFolder(String srcpath, String dstPath, String name) throws Exception {
// -1 :error; -2: the filename is not exists ;-3 :destFolderName ; 1: right
@ -51,6 +79,38 @@ public class FolderController extends BaseController {
obj = "err";
}
return obj;
=======
// /**
// * <一句话功能简述> 查询集群中所有的 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;
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275
}
}

@ -13,12 +13,19 @@ package com.platform.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
<<<<<<< HEAD
import org.apache.log4j.Logger;
=======
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/**
<<<<<<< HEAD
*
=======
* <>
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275
* <>
* @author liliy
* @version [201698]
@ -27,6 +34,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
*/
@Controller
public class SetGlusterfsController {
<<<<<<< HEAD
public static Logger log = Logger.getLogger(SetGlusterfsController.class);
@RequestMapping("")
@ -35,4 +43,22 @@ public class SetGlusterfsController {
}
=======
@RequestMapping("/tes")
public Object defaultHandler(HttpServletRequest req, HttpServletResponse request) {
//<2F><><EFBFBD><><C6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
try {
System.out.println("fsdfds");
return "listAll";
} catch (Exception e) {
e.printStackTrace();
return "result";
}
}
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275
}

@ -10,19 +10,31 @@
*/
package com.platform.controller;
<<<<<<< HEAD
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
=======
import java.util.List;
import java.util.Map;
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.platform.glusterfs.ClusterInfo;
<<<<<<< HEAD
import com.platform.glusterfs.VolumeInfo;
/**
*
=======
/**
* <>
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275
* <>
* @author liliy
* @version [201698]
@ -31,9 +43,14 @@ import com.platform.glusterfs.VolumeInfo;
*/
@Controller
public class ShowGlusterfsController {
<<<<<<< HEAD
public static Logger log = Logger.getLogger(ShowGlusterfsController.class);
/**
*
=======
/**
* <>
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275
* <>
* @return
* @see [##]
@ -44,6 +61,7 @@ public class ShowGlusterfsController {
return peer_status;
}
<<<<<<< HEAD
/**
* <>
* <>
@ -71,5 +89,7 @@ public class ShowGlusterfsController {
}
=======
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275
}

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

@ -0,0 +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;
}

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

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

@ -8,6 +8,12 @@ public class FolderNode {
private String path;
private List<FolderNode> childNodes;
<<<<<<< HEAD
=======
public FolderNode() {
// TODO Auto-generated constructor stub
}
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275
public FolderNode(String name) {
this.name = name;

@ -0,0 +1,82 @@
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) {
super(port, ip, name, user, password, database);
// TODO Auto-generated constructor stub
}
public GatherOracleInfo(String port, String ip, String name, String user,
String password, String database, int _id, String tableName, String suffix, int status) {
super(port, ip, name, user, password, database);
this.tableName = tableName;
this.suffix = suffix;
this.id=_id;
this.status = status;
}
public String getTableName() {
return tableName;
}
public void setTableName(String tableName) {
this.tableName = tableName;
}
public String getSuffix() {
return suffix;
}
public void setSuffix(String suffix) {
this.suffix = suffix;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getRemove() {
return remove;
}
public void setRemove(String remove) {
this.remove = remove;
}
}

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

@ -0,0 +1,129 @@
/**
* : VolumeEntity.java
* : </>
* : <>
* @author chen
* : <>
* 201699
* <>
*/
package com.platform.entities;
import java.util.ArrayList;
import java.util.List;
/**
* <> gfs volume
* <>
* @author chen
* @version [201699]
* @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;
}
}

@ -1,3 +1,4 @@
package com.platform.glusterfs;
@ -108,3 +109,115 @@ public class ClusterInfo {
System.out.println(new ClusterInfo().showClusterInfo());
}
}
=======
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;
/**
*
* nullmapipip
* ipPeerinCluster(Connected)
* ipPeerinCluster(Disconnected)
* @author liliy
* @version [2016912]
* @see [/]
* @since [/]
*/
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>();
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;
}
/**
* ipip
* ipnull
* ipPeerinCluster(Connected)
* ipPeerinCluster(Disconnected)
* @param peerip
* @return
* @see [##]
*/
public String getPeerStatus(String peerip){
Map<String, String> peerIps=showClusterInfo();
if(peerIps==null || peerIps.size()==0){
return null;
}
if(!peerIps.containsKey(peerip)){
return Constant.peerincluster_disconnected;
}
return peerIps.get(peerip);
}
public static void main(String[] args) {
PropertyConfigurator.configure("log4j.properties");
System.out.println(new ClusterInfo().showClusterInfo());
}
}

@ -1,3 +1,4 @@
<<<<<<< HEAD
package com.platform.glusterfs;
import java.util.List;
@ -78,3 +79,85 @@ public class CopyData {
copyFolderFiles("/home", "/home/ubuntu", "system_data");
}
}
=======
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 [201698]
* @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");
}
}
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275

@ -1,3 +1,4 @@
<<<<<<< HEAD
package com.platform.glusterfs;
@ -122,3 +123,125 @@ class FileOrFolder {
}
*/
=======
package com.platform.glusterfs;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import com.platform.entities.FolderNode;
import com.platform.utils.Constant;
import com.platform.utils.FileOperateHelper;
/**
* <> GFS
* <>
* @author chen
* @version [201698]
* @see [/]
* @since [/]
*/
public class GetTreeData {
ShowData showData = new ShowData();
/**
* <>
* <>
* @param name
* @return
* @see [##]
*/
public FolderNode getDatas(String name) {
String names[]=name.split("/");
String only_name=names[names.length-1];
FolderNode fileNode = new FolderNode(only_name);
fileNode.setPath(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()) {
if(entry.getKey().equals("app")){
continue;
}
int number = Integer.parseInt(entry.getValue());
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;
}
/**
* <>
* <>
* @param name
* @return
* @see [##]
*/
public FolderNode getDatasWithShell(String name) {
if(name.endsWith("/")){
name=name.substring(0, name.length());
}
String names[]=name.split("/");
String only_name=names[names.length-1];
FolderNode fileNode = new FolderNode(name);
fileNode.setPath(name);
String shellComment=new FileOperateHelper().fileReaderAndendline(Constant.fileGetTreeData);
String sh_path="/getTreedata.sh";
String cmd="echo -e "+shellComment+" > "+sh_path+" & chmod +x "+sh_path;
Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
// Map<String, String> files = showData.showFolderData(name);
List<String> files=Constant.ganymedSSH.execCmdWaitAcquiescent(sh_path+" "+name);
if(files==null){
return null;
}
if(files.size()==0){
return fileNode;
}
for(String file:files){
}
return fileNode;
}
@Test
public void test_getTreeData() {
GetTreeData getTreeData=new GetTreeData();
FolderNode fileOrFolder=getTreeData.getDatas("/home");
System.out.println(fileOrFolder);
}
}
/*
class FileOrFolder {
String name;
int isFolder; // 1 is file and other integer is folder show children number
List<FileOrFolder> children;
public FileOrFolder(String name) {
// TODO Auto-generated constructor stub
this.name = name;
}
public FileOrFolder(String name, int isFolder) {
// TODO Auto-generated constructor stub
this.name = name;
this.isFolder = isFolder;
}
}
*/
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275

@ -1,3 +1,4 @@
<<<<<<< HEAD
package com.platform.glusterfs;
import java.util.List;
@ -63,3 +64,16 @@ public class SetCluster {
return 0;
}
}
=======
package com.platform.glusterfs;
import org.apache.log4j.Logger;
public class SetCluster {
public static Logger log = Logger.getLogger ( SetCluster.class);
public int addPeer(String peerip){
return 0;
}
}
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275

@ -1,3 +1,4 @@
<<<<<<< HEAD
/**
* @author
@ -493,3 +494,503 @@ public class SetVolume {
// System.out.println(operation);
}
}
=======
/**
* @author
* volumevolumevolumebrick
*/
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 -1volume name-2volume
*/
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;
}
List<String> mountPoints = new VolumeInfo().getVolumeMountPoint(volumeName);
if (stopVolume(volumeName) != 0) {
log.error("3802 " + volumeName + " stop failed !");
return -2;
}
log.info("stop "+volumeName+" successed!");
if (null == mountPoints) {
return -2;
}
for(String mountPoint:mountPoints){
if (mountPoint != null) {
String command = "umount -l " + 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;
}
/*
* volumebrick, 1 ;
* volumebrickcount
*/
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;
}
}
/*
* volumebrick, 1 ;
* volumebrickcount
*/
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
* volumevolume
*/
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
* volumevolume
*/
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使 volumebrickcount
* 1: ;-1brickip; -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;
}
/**
* volumebrickvolumevolumecountbrick
*
* @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);
}
}
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275

@ -1,3 +1,4 @@
<<<<<<< HEAD
package com.platform.glusterfs;
import java.util.HashMap;
@ -129,4 +130,110 @@ public class ShowData {
System.out.println(getFolderSize("/home/ubuntu"));
}
=======
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
* @see [##]
*/
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"));
}
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275
}

@ -1,3 +1,4 @@
<<<<<<< HEAD
package com.platform.glusterfs;
import java.io.File;
@ -323,3 +324,339 @@ public class VolumeInfo {
System.out.println(getVolumeMountPoint("v1"));
}
}
=======
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 org.junit.Test;
import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;
import com.platform.utils.Constant;
import com.platform.utils.GanymedSSH;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class VolumeInfo {
public static Logger log = Logger.getLogger(VolumeInfo.class);
/**
* volume
* <>
* @return
* @see [##]
*/
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;
}
/**
* volumevolume
* <>
* @param volumeName
* @return
* @see [##]
*/
public String getVolumeType(String volumeName) {
log.info("get volume type");
String volType = "";
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 = "";
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;
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;
}
/**
* @param volumeName
* @return String ipAndpath[] = brick.split(":");
String ip = ipAndpath[0];
String path = ipAndpath[1];
*/
public List<String> getVolumeBricks(String volumeName) {
log.info("get volume bricks");
String cmd = "gluster volume info " + volumeName + " |grep ^Brick'[0-9]\\+' |awk '{print $2}'";
List<String> reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
// System.out.println(reStrings);
if (reStrings == null) {
log.error("1601 get volume bricks wrong");
return null;
}
return reStrings;
}
public List<String> getVolumeMountPoint(String volumeName) {
log.info("get volume MountPoint");
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;
}
List<String> mountPoints = new ArrayList<>();
for(String mountPoint:reStrings){
mountPoint=mountPoint.replaceAll(" ", "");
mountPoints.add(mountPoint);
}
return mountPoints;
}
public Map<String, Double> getVolumebricksDataSize(String volumeName) {
List<String> bricks = getVolumeBricks(volumeName);
Map<String, Double> brick_size = new HashMap<>();
if (bricks == null) {
return null;
}
for (String brick : bricks) {
String ipAndpath[] = brick.split(":");
String ip = ipAndpath[0];
String path = ipAndpath[1];
String cmd = "du -d 0 " + path + "|awk '{print $1}'";
List<String> reStrings = Constant.ganymedSSH.execCmdWait(ip, Constant.rootUser, Constant.rootPasswd,
Constant.port, cmd);
// System.out.println(reStrings);
if (reStrings == null) {
log.error("1901 get result is null");
return null;
}
if (reStrings.size() == 0) {
log.error("1902 get result is nothing");
return null;
}
Pattern pattern = Pattern.compile("[0-9]*");
Matcher isNum = pattern.matcher(reStrings.get(0));
if (!isNum.matches()) {
log.error("1903 " + reStrings.get(0) + " is unexpect");
return null;
}
brick_size.put(brick, Double.parseDouble(reStrings.get(0)));
}
return brick_size;
}
public Map<String, Double> getVolumebricksAvailableSize(String volumeName) {
List<String> bricks = getVolumeBricks(volumeName);
Map<String, Double> brick_size = new HashMap<>();
if (bricks == null) {
return null;
}
for (String brick : bricks) {
String ipAndpath[] = brick.split(":");
String ip = ipAndpath[0];
String path = ipAndpath[1];
String cmd = "df " + path + "|awk '{print $4}'";
List<String> reStrings = Constant.ganymedSSH.execCmdWait(ip, Constant.rootUser, Constant.rootPasswd,
Constant.port, cmd);
// System.out.println(reStrings);
if (reStrings == null) {
log.error("1901 get result is null");
return null;
}
if (reStrings.size() == 0) {
log.error("1902 get result is nothing");
return null;
}
Pattern pattern = Pattern.compile("[0-9]*");
Matcher isNum = pattern.matcher(reStrings.get(1));
if (!isNum.matches()) {
log.error("1903 " + reStrings.get(1) + " is unexpect");
return null;
}
brick_size.put(brick, Double.parseDouble(reStrings.get(1)));
}
return brick_size;
}
@Test
public void test_getVolumebricksDataSize() {
System.out.println(getVolumebricksDataSize("gfs_ftp"));
}
@Test
public void test_getVolumebricksAvailableSize() {
System.out.println(getVolumebricksAvailableSize("gfs_ftp"));
}
// @Test
public void test_getVolumeBricks() {
getVolumeBricks("gfs_ftp");
}
}
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275

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

@ -10,7 +10,14 @@
*/
package com.platform.service;
<<<<<<< HEAD
import com.platform.entities.FolderNode;
=======
import java.util.List;
import com.platform.entities.FolderNode;
import com.platform.entities.VolumeEntity;
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275
/**
* <>
@ -42,6 +49,32 @@ public interface IGfsService {
* @throws Exception
* @see [##]
*/
<<<<<<< HEAD
public int copyFolder(String src, String dst, String name) throws Exception;
=======
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;
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275
}

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

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

@ -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;
@ -39,20 +40,26 @@ public class OracleExtractHelper {
/**
* dblink
*
<<<<<<< HEAD
* @param conn
* @param oc
=======
* @param conn
* @param oc
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275
* 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
@ -84,11 +91,11 @@ 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)) {
@ -105,10 +112,10 @@ 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 "
@ -121,8 +128,8 @@ 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;

@ -111,7 +111,7 @@ 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 = "失败";

@ -1,3 +1,4 @@
<<<<<<< HEAD
/**
* : GfsServiceImpl.java
@ -46,3 +47,154 @@ public class GfsServiceImpl implements IGfsService {
}
}
=======
/**
* : GfsServiceImpl.java
* : </>
* : <>
* @author chen
* : <>
* 201698
* <>
*/
package com.platform.service.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Service;
import com.platform.entities.Brick;
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.ThreadVolume;
import com.platform.utils.getTreeDataByPath;
/**
* <> gfs
* <>
* @author chen
* @version [201698]
* @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();
if (null == volumeNameList) {
return null;
}
for (String volumeName : volumeNameList) {
VolumeEntity volume = new VolumeEntity();
volume.setName(volumeName);
List<String> path = volumeInfo.getVolumeMountPoint(volumeName);
//默认加载第一个路径
if (null != path && path.size() > 0) {
volume.setPath(path.get(0));
}
volume.setAllSize(volumeInfo.getVolumeAllSize(volumeName));
volume.setUsedSize(volumeInfo.getVolumeUseSize(volumeName));
//TODO 查询brick--
//返回 ip:path
List<String> brickStrs = volumeInfo.getVolumeBricks(volumeName);
//brick已用大小
Map<String, Double> usedSize = volumeInfo.getVolumebricksDataSize(volumeName);
Map<String, Double> availableSize = volumeInfo.getVolumebricksAvailableSize(volumeName);
List<Brick> brickList = new ArrayList<Brick>();
for (String brickIpPath : brickStrs) {
Brick b = new Brick();
String ipAndpath[] = brickIpPath.split(":");
String brickip = ipAndpath[0];
String brickpath = ipAndpath[1];
//iP , path ,
b.setIp(brickip);
b.setPath(brickpath);
b.setAvailableSize(availableSize.get(brickIpPath));
b.setUsedSize(usedSize.get(brickIpPath));
brickList.add(b);
}
volume.setBrick(brickList);
if (null != volume.getPath()) {
// 获得 folder 目录
volume.setFolder(getFolder(volume.getPath()));
}
volumeList.add(volume);
}
return volumeList;
}
@Override
public VolumeEntity getOneVolume(String volumeName) throws Exception {
VolumeEntity volume = new VolumeEntity();
volume.setName(volumeName);
List<String> path = volumeInfo.getVolumeMountPoint(volumeName);
if (null != path && path.size() > 0) {
volume.setPath(path.get(0));
}
volume.setAllSize(volumeInfo.getVolumeAllSize(volumeName));
volume.setUsedSize(volumeInfo.getVolumeUseSize(volumeName));
// volume.setBrick(brick);
if (null != volume.getPath()) {
volume.setFolder(getFolder(path.get(0)));
}
return volume;
}
@Override
public int moveData(String volumeName, String srcPath, String dstPath)
throws Exception {
int result = copydata.copyFolderFiles(srcPath, dstPath, "app");
return result;
}
@Override
public int deleteData(String volumeName, String srcPath) throws Exception {
// TODO Auto-generated method stub
return 0;
}
}
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275

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

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

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

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

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

@ -1,3 +1,4 @@
<<<<<<< HEAD
package com.platform.utils;
import java.util.List;
@ -28,3 +29,38 @@ public class Constant {
+ "echo \\$path \n fi\n done\n}\n\nIFS=\\$\\'\\n\\' "
+ "#这个必须要,否则会在文件名中有空格时出错\nINIT_PATH=\".\";\nergodic \\$1\n";
}
=======
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 String hostIp = "192.168.1.105";
public static int port = 22;
public static String glusterPeerStatus = "gluster peer status";
public static String glusterVolumeInfo = "gluster volume info ";
public static String df = "df -k ";
public static String peerincluster_connected="PeerinCluster(Connected)";
public static String peerincluster_disconnected="PeerinCluster(Disconnected)";
public static String 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);
public static String fileGetTreeData="./WEB-INF/config/getTreedata.sh";
/**
* volume 线
*/
public final static int get_volume_sleep_time = 300000;
/**
* volume 线
*/
public final static int update_dataInfo_sleep_time = 3000;
}
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275

@ -67,14 +67,23 @@ public class FileOperateHelper {
* @param path
* @return
*/
<<<<<<< HEAD
public String fileReaderAndendline(String path) {
=======
@SuppressWarnings("resource")
public static String fileReaderAndendline(String path) {
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275
StringBuffer sb = new StringBuffer();
String tempString = "";
try {
File file = new File(path);
if (!file.exists())
<<<<<<< HEAD
return "";
=======
return "";
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275
FileInputStream fis = new FileInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
while ((tempString = br.readLine()) != null) {
@ -85,10 +94,13 @@ public class FileOperateHelper {
}
return sb.toString();
}
<<<<<<< HEAD
@Test
public void test_fileReaderAndendline(){
System.out.println(System.getProperty("user.dir"));
System.out.println(fileReaderAndendline(Constant.fileGetTreeData));
}
=======
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275
}

@ -1,3 +1,4 @@
<<<<<<< HEAD
package com.platform.utils;
import java.io.BufferedReader;
@ -265,3 +266,272 @@ public class GanymedSSH {
}
}
=======
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;// 锟角凤拷锟斤拷锟街达拷锟斤拷锟斤拷锟阶刺<E998B6>
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;
}
}
if(reStrings.size()==0){
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;
}
}
if(reStrings.size()==0){
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");
}
}
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275

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

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

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

@ -0,0 +1,48 @@
package com.platform.utils;
import java.util.List;
import com.platform.entities.FolderNode;
public class getTreeDataByPath {
/**
* @param path
* @return
*/
public FolderNode findByPath(String path) {
List<FolderNode> folderNodelist = CacheTreeData.getFolders();
if (null == folderNodelist) {
return null;
}
FolderNode folder = null;
for (FolderNode folderNode : folderNodelist) {
folder = getFolder(folderNode, path);
if (null != folder) {
break;
}
}
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;
}
}

@ -0,0 +1,26 @@
package com.platform.test;
public class Brick {
private String ip;
private String path;
public Brick(String ip, String path) {
super();
this.ip = ip;
this.path = path;
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
}

@ -0,0 +1,37 @@
package com.platform.test;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import com.platform.entities.FolderNode;
public class FolderReader {
public static FolderNode reader(String path) {
FolderNode folderNode = null;
File file = new File(path);
if (file.exists()) {
List<FolderNode> childrens = new ArrayList<FolderNode>();
if (file.isDirectory()) {
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
FolderNode children = reader(files[i].getAbsolutePath());
if (children != null)
childrens.add(children);
}
}
// folderNode = new FolderNode(file.getName(), file.getAbsolutePath(),
// childrens);
}
return folderNode;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
FolderReader folderReader = new FolderReader();
FolderNode folderNode = folderReader.reader("D:/bootstrap");
//folderReader.print(folderNode);
}
}

@ -0,0 +1,64 @@
package com.platform.test;
import java.util.List;
import com.platform.entities.FolderNode;
public class Volume {
private String name;
private long totalSize;
private long usedSize;
private List<Brick> bricks;
private List<FolderNode> folderNode;
public Volume(String volume, long totalSize, long usedSize,
List<Brick> bricks, List<FolderNode> folderNode) {
super();
this.name = volume;
this.totalSize = totalSize;
this.usedSize = usedSize;
this.bricks = bricks;
this.folderNode = folderNode;
}
public String getVolume() {
return name;
}
public void setVolume(String name) {
this.name = name;
}
public long getTotalSize() {
return totalSize;
}
public void setTotalSize(long totalSize) {
this.totalSize = totalSize;
}
public long getUsedSize() {
return usedSize;
}
public void setUsedSize(long usedSize) {
this.usedSize = usedSize;
}
public List<Brick> getBricks() {
return bricks;
}
public void setBricks(List<Brick> bricks) {
this.bricks = bricks;
}
public List<FolderNode> getFolderNode() {
return folderNode;
}
public void setFolderNode(List<FolderNode> folderNode) {
this.folderNode = folderNode;
}
}
Loading…
Cancel
Save