Compare commits

...

No commits in common. "web_chenlw_utf8" and "master" have entirely different histories.

111 changed files with 290 additions and 3845 deletions

View File

@ -2,17 +2,18 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<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">
<attributes>
<attribute name="owner.project.facets" value="jst.web;#system#"/>
</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.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/Java">
<attributes>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v7.0">
<attributes>
<attribute name="owner.project.facets" value="jst.web"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/junit-4.12.jar"/>
<classpathentry kind="output" path="build/classes"/>
</classpath>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>data_manager_backend</name>
<name>data-aggregation-platform</name>
<comment></comment>
<projects>
</projects>
@ -25,11 +25,6 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.genuitec.eclipse.ast.deploy.core.DeploymentBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>

View File

@ -1,3 +0,0 @@
eclipse.preferences.version=1
performed.operation.correct.unbound.jre=1.0
performed.operation.resolve.unknown.runtime=1.0

View File

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="data_manager_backend">
<wb-module deploy-name="data-aggregation-platform">
<wb-resource deploy-path="/" source-path="/WebContent" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/test"/>
<property name="java-output-path" value="/data_manager_backend/build/classes"/>
<property name="java-output-path" value="/data-aggregation-platform/build/classes"/>
<property name="context-root" value="/"/>
</wb-module>
</project-modules>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<runtime name="MyEclipse Tomcat v7.0"/>
<runtime name="Apache Tomcat v7.0"/>
<fixed facet="java"/>
<fixed facet="wst.jsdt.web"/>
<fixed facet="jst.web"/>

View File

@ -1,10 +1,10 @@
#=============================================================================================================
# MySQL
# MySQL连接配置
#=============================================================================================================
# 驱动程序
jdbc.mysql.driver=com.mysql.jdbc.Driver
# 连接url
jdbc.mysql.url=jdbc:mysql://192.168.0.101:3306/test?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true
jdbc.mysql.url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true
# 用户名
jdbc.mysql.username=root
# 密码
@ -13,14 +13,15 @@ jdbc.mysql.password=root
#=============================================================================================================
# Oracle 连接配置
#=============================================================================================================
# hui用户名
gather-user-name=system
# 驱动程序
jdbc.oracle.driver=oracle.jdbc.driver.OracleDriver
# 连接url
jdbc.oracle.url=jdbc:oracle:thin:@localhost:1521:orcl;
# 用户名
jdbc.oracle.username=system
# 密码
gather-user-password=oracle
#
gather-port=1521
#
gather-service-name=orcl
jdbc.oracle.password=oracle
#=============================================================================================================
# 数据库公共配置
#=============================================================================================================
@ -35,16 +36,4 @@ jdbc.removeAbandonedTimeout=600
jdbc.testWhileIdle=true
jdbc.timeBetweenEvictionRunsMillis=60000
jdbc.numTestsPerEvictionRun=20
jdbc.minEvictableIdleTimeMillis=300000
#==============================================================================================================
#
#==============================================================================================================
table-suffix=_20152016
extract-log-localtion=/home/log/
gather-tablespace-name=TS_TTSSS
gather-tablespace-path=
gather-table-user-password=
kubeMasterUrl=http://192.168.0.116:8080/
collect-user-name=system
collect-password=oracle
collect-service-name=orcl
jdbc.minEvictableIdleTimeMillis=300000

View File

@ -3,7 +3,7 @@
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>javaBackend</display-name>
<display-name>MyFirstTest</display-name>
<welcome-file-list>
<welcome-file>/index.html</welcome-file>
</welcome-file-list>
@ -20,7 +20,7 @@
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- spring配置文件 -->
<!-- spring配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/config/spring-applicationContext.xml</param-value>
@ -29,10 +29,6 @@
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>com.platform.utils.ConfigsLoader</listener-class>
</listener>
<!-- springmv的配置文件 -->
<servlet>
<servlet-name>springmvc</servlet-name>
@ -42,22 +38,22 @@
<param-value>/WEB-INF/config/springmvc-applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<!-- log4j配置文件 -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/config/log4j-config.xml</param-value>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/config/log4j-config.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<!-- 防止Spring内存溢出监听器 -->
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>

23
WebContent/index.html Normal file
View File

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$(function(){
$("#btn").{"name":"伍名"}click(function(){
$.post("json",function(data){
alert(data);
});
});
});
</script>
</head>
<body>
<form action="hello" method="post">
name:<input type="text" name="name">
<input type="submit" value="submit">
</form>
</body>
</html>

View File

@ -1 +0,0 @@
/com/

View File

@ -36,43 +36,35 @@ PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
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" />
<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">
and
data_details.data_version=#{PagerOptions.dataVersion}
</if>
<if test="PagerOptions.systemName">
and data_details=#{PagerOptions.systemName}
</if>
<if test="PagerOptions.dataYear">
and data_details.data_year=#{PagerOptions.dataYear}
</if>
<choose>
<when test="PagerOptions.offset > 0">
and data_details.id>= #{PagerOptions.offset}
<when test="PagerOptions.idIndex>0">
and data_details.id>=#{idIndex}
</when>
<otherwise>
and data_details.id>=0
@ -80,29 +72,22 @@ PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
</choose>
</where>
ORDER BY data_details.id
<if test="PagerOptions.limit > 0">
LIMIT #{PagerOptions.limit}
</if>
<if test="PagerOptions.limit">LIMIT #{PagerOptions.limit}</if>
</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
<include refid="conditionsFilters" />
</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
<include refid="conditionsFilters" />
</select>
</mapper>

View File

@ -1,63 +0,0 @@
/**
* 文件名 BaseController.java
* 版权 : XX科技有限公司
* 描述 : <描述>
* 修改时间2016年9月7日
* 修改内容<修改内容>
*/
package com.base;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.ExceptionHandler;
import com.platform.utils.Configs;
/**
* <一句话功能简述>
* <功能详细描述>
* @author chen
* @version [版本号2016年9月7日]
* @see [相关类/方法]
* @since [产品/模块版本]
*/
public class BaseController {
/** log4j */
public static Logger log = Logger.getRootLogger();
/**
* <一句话功能简述> 基于@ExceptionHandler异常处理----全局异常处理
* <功能详细描述>
* @param request
* @param ex 异常
* @return
* @see [#方法#成员]
*/
@ExceptionHandler
public Object exp(HttpServletRequest request, HttpServletResponse response,Exception ex) {
System.out.println("URI"+request.getRequestURI());
request.setAttribute("ex", ex);
System.err.println("BaseController --exp ");
// 根据不同错误转向不同页面
if(ex instanceof CustomException) {
CustomException cuse = (CustomException) ex;
Map<String, String> errmsg = new HashMap<>();
errmsg.put("code", cuse.getCode());
errmsg.put("msg", cuse.getMsg());
log.error(cuse.getCode());
response.setStatus(500);
return response;
} else {
//其他错误则 调到指定页面
log.error(Configs.GLOBAL_EXP_NOT_CUSTOM, ex);
response.setStatus(500);
return response;
}
}
}

View File

@ -1,23 +0,0 @@
package com.base;
/**
* <一句话功能简述>
* <功能详细描述>
* @author chen
* @version [版本号2016年9月8日]
* @see [相关类/方法]
* @since [产品/模块版本]
*/
public class Constant {
/** 国际话配置文件文件-i18n.properties */
public static String I18N_PROPERTIES_FIEL_PATH = "/com/base/i18n.properties";
/** WritefileThread-线程睡眠时间--3000 */
public final static long THREAD_SLEEP_WRITEFILETHREAD = 3000;
/** CustomException记录报异常的对象的对象个数--10 */
public final static int CustomException_log_object_size = 10;
}

View File

@ -1,20 +0,0 @@
package com.base;
/**
* <一句话功能简述> 异常常量编码
* <功能详细描述>
* @author chen
* @version [版本号2016年9月8日]
* @see [相关类/方法]
* @since [产品/模块版本]
*/
public class Custom4exception {
//3003001001 : 第一位标识异常 第二到第四位标识模块第五道第七位标识类别第八道第十位标识具体异常
/**eg
* 3异常
* 003虚拟机模块
* 001软件依赖虚拟机资源类别
* 001启动异常
*/
}

View File

@ -1,124 +0,0 @@
package com.base;
import org.apache.log4j.Logger;
/**
* <一句话功能简述>
* <功能详细描述>
* @author chen
* @version [版本号2016年9月8日]
* @see [相关类/方法]
* @since [产品/模块版本]
*/
@SuppressWarnings("serial")
public class CustomException extends Exception {
/** log4j */
public static Logger log = Logger.getRootLogger();
/** 自定义异常信息-错误信息 */
private String msg;
/** 自定义异常信息-错误代码 */
private String code;
/** 操作对象 */
private Object[] objArray;
/** 异常 */
private Throwable cause;
public CustomException() {
super();
}
/**
* @功能 将异常记录进文件
* @param code 异常编码
* @param msg 自定义异常信息
* @param e
* @param obj
*/
public CustomException(String code,Exception e,Object... obj) {
super(code);
StringBuffer sbuf= new StringBuffer();
sbuf.append(msg);
this.code = code;
sbuf.append(code);
sbuf.append("\r\n");
msg = Resource.getProperties().get(code);
// 记录自定义的 异常
if (null != msg) {
sbuf.append(msg);
sbuf.append("\r\n");
}
// 记录原始的异常
if (null != e) {
StackTraceElement[] array = e.getStackTrace();
cause = e.getCause();
for (StackTraceElement stackTraceElement : array) {
sbuf.append(stackTraceElement.toString());
sbuf.append("\r\n");
}
}
//记录 出现异常时 当前的对象
if (null != obj) {
Object[] array = obj;
sbuf.append("Object[] size : ");
sbuf.append(array.length);
int forSize = 0;
if (Constant.CustomException_log_object_size < array.length) {
forSize = Constant.CustomException_log_object_size;
}
else {
forSize = array.length;
}
for (int i = 0; i < forSize; i++) {
sbuf.append(array[i]);
sbuf.append("\r\n");
}
sbuf.append("......");
sbuf.append("\r\n");
}
else {
sbuf.append("null");
sbuf.append("\r\n");
}
sbuf.append("\r\n");
// 是否 写入 文件
log.error(sbuf.toString());
}
/**
* @功能 获得msg
* @return msg
*/
public String getMsg() {
return msg;
}
/**
* @return the code
*/
public String getCode() {
return code;
}
/**
* @功能 获得objArray
* @return objArray
*/
public Object[] getObjArray() {
return objArray;
}
/**
* @功能 获得cause
* @return cause
*/
public Throwable getCause() {
return cause;
}
}

View File

@ -1,79 +0,0 @@
package com.base;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import com.base.Constant;
public class Resource {
private static Map<String, String> properties = new HashMap<>();
static{
// 读取 properties文件
// readPropertiesFile(Constant.SYSTEM_PROPERTIES_FIEL_PATH);
readPropertiesFile4Chinese(Constant.I18N_PROPERTIES_FIEL_PATH);
}
/**
* @功能 读取配置解决中文乱码
* @param filename "/com/utils/exception/i18n.properties" 的格式
*/
public static void readPropertiesFile4Chinese(String filename) {
Properties pro = new Properties();
try {
// 读取属性文件 XXXX.propertiesReaderwriter解决中文乱码
// InputStreamReader in= new InputStreamReader(Resource.class.getClassLoader().getResourceAsStream(filename), "UTF-8");
InputStreamReader in= new InputStreamReader(Resource.class.getResourceAsStream(filename), "UTF-8");
BufferedReader bf = new BufferedReader(in);
// InputStreamReader in = new BufferedInputStream(new FileInputStream(filename));
pro.load(bf); // /加载属性列表
Iterator<String> it = pro.stringPropertyNames().iterator();
while (it.hasNext()) {
String key = it.next();
properties.put(key, pro.getProperty(key));
}
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* @功能 获得properties
* @return properties
*/
public static Map<String, String> getProperties() {
return properties;
}
/**
* @功能 读取配置
* @param filename 文件绝对路径
*/
public static void readPropertiesFile(String filename) {
Properties pro = new Properties();
try {
// 读取属性文件 XXXX.properties 中文会 乱码
BufferedInputStream bf = new BufferedInputStream(new FileInputStream(filename));
pro.load(bf); // /加载属性列表
Iterator<String> it = pro.stringPropertyNames().iterator();
while (it.hasNext()) {
String key = it.next();
properties.put(key, pro.getProperty(key));
}
bf.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -36,43 +36,35 @@ PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
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" />
<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">
and
data_details.data_version=#{PagerOptions.dataVersion}
</if>
<if test="PagerOptions.systemName">
and data_details=#{PagerOptions.systemName}
</if>
<if test="PagerOptions.dataYear">
and data_details.data_year=#{PagerOptions.dataYear}
</if>
<choose>
<when test="PagerOptions.offset > 0">
and data_details.id>= #{PagerOptions.offset}
<when test="PagerOptions.idIndex>0">
and data_details.id>=#{idIndex}
</when>
<otherwise>
and data_details.id>=0
@ -80,29 +72,22 @@ PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
</choose>
</where>
ORDER BY data_details.id
<if test="PagerOptions.limit > 0">
LIMIT #{PagerOptions.limit}
</if>
<if test="PagerOptions.limit">LIMIT #{PagerOptions.limit}</if>
</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
<include refid="conditionsFilters" />
</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
<include refid="conditionsFilters" />
</select>
</mapper>

View File

@ -1,6 +1,5 @@
package com.platform.controller;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@ -8,7 +7,6 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
@ -16,8 +14,6 @@ import org.springframework.web.bind.annotation.ResponseBody;
import com.platform.entities.PagerOptions;
import com.platform.service.DataInfoService;
import com.platform.service.OracleStatusService;
import com.platform.utils.Configs;
import com.platform.utils.UtilsHelper;
@Controller
@ -31,69 +27,12 @@ public class DataModelController {
@RequestMapping("/data.json")
@ResponseBody
public ModelMap getAllDataToJson(HttpServletRequest res,
HttpServletResponse req) {
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("当前的请求参数:{");
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(",");
}
Set<String> keySet= paramMap.keySet();
for(String str: keySet){
System.out.println(str+":"+paramMap.get(str));
}
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("/extractOracleData")
public void extractOracleData(HttpServletRequest res,
HttpServletResponse req) {
}
@RequestMapping("/getFolder")
public void getFolder(HttpServletRequest res, HttpServletResponse req) {
System.out.println("ooooooooo");
return dfs.getPagerTableData((PagerOptions) UtilsHelper.newObjAndSetAttrsByClass(PagerOptions.class, res));
}
}

View File

@ -7,23 +7,12 @@ import org.springframework.stereotype.Controller;
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");
//处理不匹配的请求
System.out.println("index");
return new ModelAndView("index");
}
@RequestMapping("/test")
public void test(HttpServletRequest req, HttpServletResponse res){
//System.out.println(Class.class.getClass().getResource("/").getPath());
System.out.println(Configs.EXTRACT_LOG_LOCALTION);
}
}

View File

@ -1,57 +0,0 @@
package com.platform.controller;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import com.base.BaseController;
import com.base.CustomException;
import com.platform.entities.GfsFolderEntity;
import com.platform.service.IGfsService;
/**
* <一句话功能简述>
* <功能详细描述>
* @author chen
* @version [版本号2016年9月8日]
* @see [相关类/方法]
* @since [产品/模块版本]
*/
@Controller
@RequestMapping("/folder")
public class FolderController extends BaseController {
@Resource(name = "gfsService")
private IGfsService gfsService;
@RequestMapping("/getAllSubPathByPath")
public Object getAllSubPathByPath(String path) throws Exception {
System.out.println(path);
Object result = null;
if (null != path && !"".equals(path)) {
System.out.println(path);
result = gfsService.getFolder(path);
throw new CustomException("3211", null);
}
return result;
}
@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
int result = gfsService.copyFolder(srcpath, dstPath, name);
System.out.println(srcpath);
System.out.println(dstPath);
String obj = "right";
if (1 != result) {
obj = "err";
}
return obj;
}
}

View File

@ -1,45 +0,0 @@
/**
* 文件名 : SetGlusterfs.java
* 版权 : <版权/公司名>
* 描述 : <描述>
* @author liliy
* 版本 : <版本>
* 修改时间 2016年9月8日
* 修改内容 <修改内容>
*/
package com.platform.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* <一句话功能简述>
* <功能详细描述>
* @author liliy
* @version [版本号2016年9月8日]
* @see [相关类/方法]
* @since [产品/模块版本]
*/
@Controller
public class SetGlusterfsController {
@RequestMapping("/tes")
public Object defaultHandler(HttpServletRequest req, HttpServletResponse request) {
//<EFBFBD><EFBFBD><EFBFBD>?ƥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
try {
System.out.println("fsdfds");
return "listAll";
} catch (Exception e) {
e.printStackTrace();
return "result";
}
}
}

View File

@ -1,44 +0,0 @@
/**
* 文件名 : ShowGlusterfsController.java
* 版权 : <版权/公司名>
* 描述 : <描述>
* @author liliy
* 版本 : <版本>
* 修改时间 2016年9月8日
* 修改内容 <修改内容>
*/
package com.platform.controller;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.platform.glusterfs.ClusterInfo;
/**
* <一句话功能简述>
* <功能详细描述>
* @author liliy
* @version [版本号2016年9月8日]
* @see [相关类/方法]
* @since [产品/模块版本]
*/
@Controller
public class ShowGlusterfsController {
/**
* <一句话功能简述>
* <功能详细描述>
* @return
* @see [#方法#成员]
*/
@RequestMapping("/showPeerStatus")
public Map<String,String> showPeerStatus(){
Map<String, String> peer_status=new ClusterInfo().showClusterInfo();
return peer_status;
}
}

View File

@ -2,19 +2,30 @@ package com.platform.dao;
import java.util.List;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import com.platform.entities.DataInfoEntity;
import com.platform.entities.PagerOptions;
@Repository(value = "dataInfoDao")
public interface DataInfoDao {
int getLimitedDataCount(@Param("PagerOptions")PagerOptions pagerOptions);
public List<DataInfoEntity> getLimitedDataInfoEntities(
@Param(value = "PagerOptions") PagerOptions pagerOptions);
int getLimitedBeginId(@Param("PagerOptions")PagerOptions pagerOptions);
List<DataInfoEntity> getLimitedDataInfoEntities(@Param("PagerOptions")PagerOptions pagerOptions);
List<String> getIdIsExist(int parseInt);
public int getLimitedDataCount(
@Param(value = "PagerOptions") PagerOptions pagerOptions);
@Insert("INSERT INTO data_info(regionalism_code, system_code, data_type, data_version, submitted_batch, data_path, collection_time, data_charset)"
+ " values(#{regionalismCcode},#{systemCcode},#{dataType},#{dataVersion},#{submittedBbatch},#{dataPath},#{collectionTime},#{dataCharset})")
public int inserRecode(@Param("regionalismCcode") String regionalismCcode,
@Param("systemCcode") int systemCcode,
@Param("dataType") String dataType,
@Param("dataVersion") int dataVersion,
@Param("submittedBbatch") String submittedBbatch,
@Param("dataPath") String dataPath,
@Param("collectionTime") String collectionTime,
@Param("dataCharset") String dataCharset);
}

View File

@ -12,7 +12,7 @@ import org.springframework.stereotype.Repository;
import com.platform.entities.EncodedInfoEntity;
/**
* 数据库操作: 实现增
* 数据库操作: 实现增
*
* @author wuming
*
@ -21,49 +21,49 @@ import com.platform.entities.EncodedInfoEntity;
public interface EncodeInfoDao {
/**
* 获取查询表下的所有实体行政区划/系统信息
* 获取查询表下的所有实体行政区划/系统信息
*
* @param tableName
* 查询的表名
* @return 所有实体信息:名称和编码
* 查询的表名
* @return 所有实体信息:名称和编码
*/
@Select("SELECT code, name FROM ${tableName}")
public List<EncodedInfoEntity> getAllEntityInfo(
@Param("tableName") String tableName);
/**
* 根据实体行政区划/系统的名称查询编码
* 根据实体行政区划/系统的名称查询编码
*
* @param code
* 实体编码
* 实体编码
* @param tableName
* 查询的表名
* @return 编码是主键查询结果最多只有一条记录
* 查询的表名
* @return 编码是主键查询结果最多只有一条记录
*/
@Select("SELECT name FROM ${tableName} WHERE code = #{code}")
public String getEncodeNameByCode(@Param("code") String code,
@Param("tableName") String tableName);
/**
* 根据实体行政区划/系统的编码查询名称
* 根据实体行政区划/系统的编码查询名称
*
* @param name
* 实体名称
* 实体名称
* @param tableName
* 查询的表名
* @return 名称不是主键查询结果可能会有多个
* 查询的表名
* @return 名称不是主键查询结果可能会有多个
*/
@Select("SELECT code FROM ${tableName} WHERE name = #{name}")
public List<String> getEncodeCodeByName(@Param("name") String name,
@Param("tableName") String tableName);
/**
* 根据实体行政区划/系统的编码更新实体的名称
* 根据实体行政区划/系统的编码更新实体的名称
*
* @param code
* 系统编码
* 系统编码
* @param tableName
* 查询的表名
* 查询的表名
* @return
*/
@Update("UPDATE ${tableName} SET name = #{name} WHERE code = #{code}")
@ -71,12 +71,12 @@ public interface EncodeInfoDao {
@Param("name") String name, @Param("tableName") String tableName);
/**
* 向表中插入实体行政区划/系统信息
* 向表中插入实体行政区划/系统信息
*
* @param efe
* 插入的实体信息
* 插入的实体信息
* @param tableName
* 表名
* 表名
* @return
*/
@Insert("INSERT INTO ${tableName} (code, name) VALUES (#{efe.code}, #{efe.name})")
@ -84,12 +84,12 @@ public interface EncodeInfoDao {
@Param("tableName") String tableName);
/**
* 删除表中的实体行政区划/系统
* 删除表中的实体行政区划/系统
*
* @param code
* 实体的编码
* 实体的编码
* @param tableName
* 表名
* 表名
* @return
*/
@Delete("DELETE FROM ${tableName} WHERE code = #{code}")

View File

@ -1,27 +1,27 @@
package com.platform.entities;
/**
* 数据信息实体类
* 数据信息实体类
*
* @author wuming
*
*/
public class DataInfoEntity {
private int id;
private String regionalismCode; // 行政区划编码
private String cityName; //
private String districtName; // 区县
private int systemCode; // 系统编码
private String systemName; // 系统名称
private String dataType; // 数据类型财政\社保\...
private int dataVersion; // 数据版本
private String submittedBatch; // 上报批次
private String dataPath; // 数据路径
private String collectingTime; // 采集时间
private String collectorContacts; // 采集人的联系
private String charset; // 数据的字符编码
private String collectorName; // 采集人姓名
private String year; // 数据年度
private String regionalismCode; // 行政区划编码
private String cityName; //
private String districtName; // 区县
private int systemCode; // 系统编码
private String systemName; // 系统名称
private String dataType; // 数据类型财政\社保\...
private int dataVersion; // 数据版本
private String submittedBatch; // 上报批次
private String dataPath; // 数据路径
private String collectingTime; // 采集时间
private String collectorContacts; // 采集人的联系
private String charset; // 数据的字符编码
private String collectorName; // 采集人姓名
private String year; // 数据年度
public DataInfoEntity() {
}

View File

@ -2,14 +2,14 @@ package com.platform.entities;
/**
*
* 编码信息实体
* 行政区划/系统信息
* 编码信息实体
* 行政区划/系统信息
* @author wuming
*
*/
public class EncodedInfoEntity {
private String name; //名称
private String code; //编码
private String name; //名称
private String code; //编码
public EncodedInfoEntity() {}

View File

@ -1,59 +0,0 @@
package com.platform.entities;
import java.util.List;
public class FolderNode {
private String name;
private int isFolder; // 1 is file and other integer is folder show children number
private String path;
private List<FolderNode> childNodes;
public FolderNode(String name) {
this.name = name;
}
public FolderNode(String name, int isFolder) {
this.name = name;
this.isFolder = isFolder;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
/**
* @return the isFolder
*/
public int getIsFolder() {
return isFolder;
}
/**
* @param isFolder the isFolder to set
*/
public void setIsFolder(int isFolder) {
this.isFolder = isFolder;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public List<FolderNode> getChildNodes() {
return childNodes;
}
public void setChildNodes(List<FolderNode> childNodes) {
this.childNodes = childNodes;
}
}

View File

@ -1,77 +0,0 @@
/**
* 文件名 : GfsPathModel.java
* 版权 : <版权/公司名>
* 描述 : <描述>
* @author chen
* 版本 : <版本>
* 修改时间 2016年9月8日
* 修改内容 <修改内容>
*/
package com.platform.entities;
import java.util.List;
/**
* <一句话功能简述>
* <功能详细描述>
* @author chen
* @version [版本号2016年9月8日]
* @see [相关类/方法]
* @since [产品/模块版本]
*/
public class GfsFolderEntity {
/** 当前路径 */
private String path;
/** 当前路径 */
private String name;
/** 子目录 */
private List<GfsFolderEntity> children;
/**
* @return the path
*/
public String getPath() {
return path;
}
/**
* @param path the path to set
*/
public void setPath(String path) {
this.path = path;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the children
*/
public List<GfsFolderEntity> getChildren() {
return children;
}
/**
* @param children the children to set
*/
public void setChildren(List<GfsFolderEntity> children) {
this.children = children;
}
}

View File

@ -1,89 +0,0 @@
package com.platform.entities;
import java.util.Properties;
import com.platform.utils.ConfigPropertyReader;
import com.platform.utils.Configs;
public class OracleConnectorParams {
private String port;
private String ip;
private String name;
private String user;
private String password;
private String database;
public OracleConnectorParams(String port, String ip, String name) {
maybeInit();
this.port = port;
this.ip = ip;
this.name = name;
}
public OracleConnectorParams(String port, String ip, String name,
String user, String password, String database) {
this.port = port;
this.ip = ip;
this.name = name;
this.user = user;
this.password = password;
this.database = database;
}
private void maybeInit() {
Properties properties = ConfigPropertyReader.Builder(
Configs.CONFIG_LOCALTION).getProperties();
this.user = properties.getProperty("collect-user");
this.password = properties.getProperty("collect-password");
this.database = properties.getProperty("collect-database");
}
public String getPort() {
return port;
}
public void setPort(String port) {
this.port = port;
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getDatabase() {
return database;
}
public void setDatabase(String database) {
this.database = database;
}
}

View File

@ -1,36 +1,30 @@
package com.platform.entities;
public class PagerOptions {
private Integer currentPageNum; //当前页码
private int idIndex;
private String dataType; //数据类型
private String dataType;
private String submittedBatch; //数据批次
private String cityName; //城市名称
private String submittedBatch;
private String districtName; //区县名
private String cityName;
private Integer dataVersion; //数据版本
private String districtName;
private String systemName; //系统名称
private int dataVersion;
private String dataYear; // 数据年度
private String systemName;
private Integer limit; //一次查询返回记录条数
private String dataYear;
private Integer offset; // 查询偏移量起始id
private Integer totalLimit; //当前页前面已有多少条数据
private Integer priorTableSize; //前一次操作一页显示的数据条数
private int limit;
public Integer getCurrentPageNum() {
return currentPageNum;
public int getIdIndex() {
return idIndex;
}
public void setCurrentPageNum(Integer currentPageNum) {
this.currentPageNum = currentPageNum;
public void setIdIndex(int idIndex) {
this.idIndex = idIndex;
}
public String getDataType() {
@ -65,11 +59,11 @@ public class PagerOptions {
this.districtName = districtName;
}
public Integer getDataVersion() {
public int getDataVersion() {
return dataVersion;
}
public void setDataVersion(Integer dataVersion) {
public void setDataVersion(int dataVersion) {
this.dataVersion = dataVersion;
}
@ -89,36 +83,12 @@ public class PagerOptions {
this.dataYear = dataYear;
}
public Integer getLimit() {
public int getLimit() {
return limit;
}
public void setLimit(Integer limit) {
public void setLimit(int limit) {
this.limit = limit;
}
public Integer getOffset() {
return offset;
}
public void setOffset(Integer offset) {
this.offset = offset;
}
public Integer getTotalLimit() {
return totalLimit;
}
public void setTotalLimit(Integer totalLimit) {
this.totalLimit = totalLimit;
}
public Integer getPriorTableSize() {
return priorTableSize;
}
public void setPriorTableSize(Integer priorTableSize) {
this.priorTableSize = priorTableSize;
}
}

View File

@ -1,44 +0,0 @@
package com.platform.entities;
public class SimpleConfigParamsBean {
private String masterUrl;
private String oracleUserName;
private String oraclePassword;
private String oracleDBName;
public String getMasterUrl() {
return masterUrl;
}
public void setMasterUrl(String masterUrl) {
this.masterUrl = masterUrl;
}
public String getOracleUserName() {
return oracleUserName;
}
public void setOracleUserName(String oracleUserName) {
this.oracleUserName = oracleUserName;
}
public String getOraclePassword() {
return oraclePassword;
}
public void setOraclePassword(String oraclePassword) {
this.oraclePassword = oraclePassword;
}
public String getOracleDBName() {
return oracleDBName;
}
public void setOracleDBName(String oracleDBName) {
this.oracleDBName = oracleDBName;
}
}

View File

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

View File

@ -1,78 +0,0 @@
package com.platform.glusterfs;
import java.util.Map;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.junit.Test;
import com.platform.utils.Constant;
/**
* <一句话功能简述> 复制数据
* <功能详细描述>
* @author chen
* @version [版本号2016年9月8日]
* @see [相关类/方法]
* @since [产品/模块版本]
*/
public class CopyData {
public static Logger log = Logger.getLogger(CopyData.class);
public int copyVolumeFiles(String sourceVolumeName, String destVolumeName, String fileName) {
log.info("start copy " + fileName + " from " + sourceVolumeName + " to " + destVolumeName);
int status = -1;
/**
* get mount point of volumeName
*/
String sourceFolderName = sourceVolumeName;
String destFolderName = destVolumeName;
status = copyFolderFiles(sourceFolderName, destFolderName, fileName);
return status;
}
/**
* -1 :error; -2: the filename is not exists ;-3 :destFolderName ; 1: right
* not exists
*
* @param folderName
* @param fileName
* @return
*/
public int copyFolderFiles(String sourceFolderName, String destFolderName, String fileName) {
int progress=0;
log.info("start copy " + fileName + " from " + sourceFolderName + " to " + destFolderName);
ShowData showData=new ShowData();
Map<String,String> reStrings=showData.showFolderData(destFolderName);
if(reStrings==null){
log.info("3201 "+destFolderName+" is not exists");
return -3;
}
reStrings=showData.showFolderData(sourceFolderName+"/"+fileName);
if(reStrings==null){
log.info("3202 "+sourceFolderName+"/"+fileName+" is not exists");
return -2;
}
String command = "cp -r " + sourceFolderName + "/" + fileName+" "+destFolderName;
/*
* RunCommand runCommand = new RunCommand();
List<String> reStrings = runCommand.runCommandWait(command);
*/
Constant.ganymedSSH.execCmdNoWaitAcquiescent(command);
log.info("copy " + sourceFolderName +"/" + fileName+ " to " + destFolderName + " running");
return 1;
}
@Test
public void testCopyFolderFiles() {
PropertyConfigurator.configure("log4j.properties");
copyFolderFiles("/home", "/home/ubuntu", "system_data");
}
}

View File

@ -1,78 +0,0 @@
package com.platform.glusterfs;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.log4j.PropertyConfigurator;
import org.junit.Test;
import org.springframework.stereotype.Service;
import com.platform.entities.FolderNode;
/**
* <一句话功能简述> 获得GFS某个目录下的子目录
* <功能详细描述>
* @author chen
* @version [版本号2016年9月8日]
* @see [相关类/方法]
* @since [产品/模块版本]
*/
public class GetTreeData {
ShowData showData = new ShowData();
/**
* <一句话功能简述> 获得所以子目录
* <功能详细描述>
* @param name
* @return
* @see [#方法#成员]
*/
public FolderNode getDatas(String name) {
FolderNode fileNode = new FolderNode(name);
Map<String, String> files = showData.showFolderData(name);
if(files==null || files.size()==0){
return fileNode;
}
fileNode.setIsFolder(files.size());
List<FolderNode> list = new ArrayList<FolderNode>();
fileNode.setChildNodes(list);
for (Map.Entry<String, String> entry : files.entrySet()) {
int number = Integer.parseInt(entry.getValue());
if (number == 1) {
fileNode.getChildNodes().add(new FolderNode(entry.getKey(), number));
}
if (number > 1) {
FolderNode temp=getDatas(name+"/"+entry.getKey());
fileNode.getChildNodes().add(temp);
}
}
return fileNode;
}
// public static void main(String[] args) {
// GetTreeData getTreeData=new GetTreeData();
// FileOrFolder fileOrFolder=getTreeData.getDatas("/home");
// System.out.println(fileOrFolder);
// }
}
//class FileOrFolder {
// String name;
// int isFolder; // 1 is file and other integer is folder show children number
// List<FileOrFolder> children;
//
// public FileOrFolder(String name) {
// // TODO Auto-generated constructor stub
// this.name = name;
// }
//
// public FileOrFolder(String name, int isFolder) {
// // TODO Auto-generated constructor stub
// this.name = name;
// this.isFolder = isFolder;
// }
//}

View File

@ -1,98 +0,0 @@
package com.platform.glusterfs;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.junit.Test;
import com.platform.utils.Constant;
public class RemoveData {
public static Logger log = Logger.getLogger ( RemoveData.class);
public int deleteVolumeFiles(String volumeName,String fileName){
log.info("start delete "+volumeName+" "+fileName);
int status=-1;
/**
* get mount point of volumeName
*/
String folderName=volumeName;
status=deleteFolderFiles(folderName,fileName);
return status;
}
/**
* -1 :error; 0: the filename is not exists ; 1: right
* @param folderName
* @param fileName
* @return
*/
public int deleteFolderFiles(String folderName,String fileName){
log.info("start delete "+folderName+"/"+fileName);
ShowData showData=new ShowData();
Map<String,String> reStrings=showData.showFolderData(folderName+"/"+fileName);
if(reStrings==null){
log.error("3301 "+folderName+"/"+fileName+" is not exists");
return -1;
}
String command="rm -r "+folderName+"/"+fileName;
// int status=runCommand.runCommand(command);
Constant.ganymedSSH.execCmdNoWaitAcquiescent(command);
log.info("delete "+folderName+" "+fileName+" running");
return 1;
}
public int getFolderSize(String name) {
log.info("get "+name+" size");
String command="du -k -d 0 "+name;
/*
* RunCommand runCommand=new RunCommand();
List<String> reStrings=runCommand.runCommandWait(command);
*/
List<String> reStrings=Constant.ganymedSSH.execCmdWaitAcquiescent(command);
if(reStrings==null){
log.error("3302 the "+command+" return error");
return -1;
}
if(reStrings.size()<1){
log.error("3303 the "+command+" return error");
return -1;
}
if(reStrings.size()==1 && reStrings.get(0).contains("No such file or directory")){
log.info("3304 "+name+" is not exists");
return 0;
}
String strSize=(reStrings.get(0).split("\t"))[0];
int size=Integer.parseInt(strSize);
log.info(name +" size is "+size);
return size;
}
// @Test
public void test_getFolderSize() {
PropertyConfigurator.configure("log4j.properties");
getFolderSize("/home/ubuntu");
}
@Test
public void testDeleteFolderFiles() {
PropertyConfigurator.configure("log4j.properties");
deleteFolderFiles("/home/ubuntu","system_data");
}
}

View File

@ -1,5 +0,0 @@
package com.platform.glusterfs;
public class SetCluster {
}

View File

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

View File

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

View File

@ -1,93 +0,0 @@
package com.platform.glusterfs;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import com.platform.utils.Constant;
public class SizeInfo {
public static Logger log = Logger.getLogger(ClusterInfo.class);
VolumeInfo volumeInfo = new VolumeInfo();
/**
* 获取集群<EFBFBD>?<EFBFBD><EFBFBD>volume size
* 返回值-1<EFBFBD>? 0没有volume longsize大小
* @return
*/
public long showAllSize() {
log.info("get AllSize ");
List<String> volumeNames = volumeInfo.showAllVolumeName();
if (volumeNames == null) {
log.error("1201 showAllVolumeName error");
return -1;
}
if (volumeNames.size() == 0) {
log.error("1202 It is not exist any volume");
return 0;
}
List<String> reStrings = null;
long size = 0L;
for (String str : volumeNames) {
String command = "df |grep " + str + "|awk \'{print $2}\'";
reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, Constant.port,
command);
if (reStrings.isEmpty()) {
log.error("1203 The brick is unmount");
} else {
size += Long.parseLong(reStrings.get(0));
}
}
return size;
}
/**
* 返回集群已用大小
* @return
* 返回值-1<EFBFBD>? 0没有volume longsize大小
*/
public long showUseSize() {
log.info("get UseSize ");
List<String> volumeNames = volumeInfo.showAllVolumeName();
List<String> reStrings = null;
long size = 0L;
if (volumeNames == null) {
log.error("1201 showAllVolumeName error");
return -1;
}
if (volumeNames.size() == 0) {
log.error("1202 It is not exist any volume");
return 0;
}
for (String str : volumeNames) {
String command = "df |grep " + str + "|awk \'{print $3}\'";
reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd,
Constant.port, command);
if (reStrings.isEmpty()) {
log.error("1202 The brick is unmount");
} else {
size += Integer.valueOf(reStrings.get(0));
}
}
return size;
}
public static void main(String[] args) {
PropertyConfigurator.configure("log4j.properties");
System.out.println(new SizeInfo().showAllSize());
System.out.println(new SizeInfo().showUseSize());
}
}

View File

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

View File

@ -1,154 +0,0 @@
package com.platform.kubernetes;
import io.fabric8.kubernetes.api.model.Container;
import io.fabric8.kubernetes.api.model.ContainerPort;
import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.api.model.ReplicationController;
import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.ConfigBuilder;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.platform.utils.Configs;
import com.platform.utils.UtilsHelper;
public class SimpleKubeClient {
private KubernetesClient client;
private final static String DEFAULT_NAMESPACE = "default";
public SimpleKubeClient() {
this.client = new DefaultKubernetesClient(Configs.KUBE_MASTER_URL);
}
public SimpleKubeClient(String masterUrl) {
this.client = new DefaultKubernetesClient(masterUrl);
}
public SimpleKubeClient(Config config) {
Config cf = config;
if (null == config) {
cf = new ConfigBuilder().withMasterUrl(Configs.KUBE_MASTER_URL).build();
}
this.client = new DefaultKubernetesClient(cf);
}
public void updateOrAddReplicasLabelById(String namespace,
String resourceId, String key, String value) {
KubernetesClient kubeClient = client;
if (checkClientNull())
kubeClient = new DefaultKubernetesClient(Configs.KUBE_MASTER_URL);
kubeClient.replicationControllers().inNamespace(namespace)
.withName(resourceId).edit().editMetadata()
.addToLabels(key, value).endMetadata().done();
}
public void updateOrAddReplicasLabelByEntity(String namespace,
ReplicationController replicas, String key, String value) {
updateOrAddReplicasLabelById(namespace, replicas.getMetadata()
.getName(), key, value);
}
public void updateOrAddReplicasLabelById(String resourceId, String key,
String value) {
updateOrAddReplicasLabelById(DEFAULT_NAMESPACE, resourceId, key, value);
}
public void updateOrAddReplicasLabelByEntity(
ReplicationController replicas, String key, String value) {
updateOrAddReplicasLabelByEntity(DEFAULT_NAMESPACE, replicas, key,
value);
}
@SuppressWarnings("resource")
public ReplicationController getReplicationController(String namespace,
String replicasName) {
KubernetesClient kubeClient = client;
if (checkClientNull())
kubeClient = new DefaultKubernetesClient(Configs.KUBE_MASTER_URL);
return kubeClient.replicationControllers().inNamespace(namespace)
.withName(replicasName).get();
}
public ReplicationController getReplicationController(String replicasName) {
return getReplicationController(DEFAULT_NAMESPACE, replicasName);
}
@SuppressWarnings("resource")
public List<Pod> getPodsForApplicaList(ReplicationController rc) {
Map<String, String> selector = rc.getSpec().getSelector();
KubernetesClient kubeClient = client;
if (checkClientNull())
kubeClient = new DefaultKubernetesClient(Configs.KUBE_MASTER_URL);
List<Pod> podList = kubeClient.pods()
.inNamespace(rc.getMetadata().getNamespace()).list().getItems();
return getPods(podList, selector);
}
private boolean checkClientNull() {
return null == client;
}
public List<Pod> getPods(List<Pod> pods, Map<String, String> selector) {
List<Pod> result = new ArrayList<Pod>();
for (int i = 0; i < pods.size(); i++)
if (UtilsHelper.isSubMap(getLabels(pods.get(i)), selector))
result.add(pods.get(i));
return result;
}
private Map<String, String> getLabels(Pod pod) {
return pod.getMetadata().getLabels();
}
public KubernetesClient getClient() {
// TODO Auto-generated method stub
return client;
}
public int getPodContainerport(Pod pod) {
int port = Configs.ORACLE_DEFAULT_PORT;
List<Container> containers = pod.getSpec().getContainers();
if (null != containers && containers.size() > 0) {
List<ContainerPort> ports = containers.get(0).getPorts();
if (null != ports && ports.size() > 0)
port = ports.get(0).getHostPort();
}
return port;
}
public String getPodHostIp(Pod pod) {
return pod.getSpec().getNodeName();
}
@SuppressWarnings("resource")
public Map<String, ReplicationController> getReplicationControllerList(
String namespace) {
KubernetesClient kubeClient = client;
Map<String, ReplicationController> rcMap = new HashMap<String, ReplicationController>();
if (checkClientNull())
kubeClient = new DefaultKubernetesClient(Configs.KUBE_MASTER_URL);
List<ReplicationController> replicasList = kubeClient
.replicationControllers().list().getItems();
if (replicasList != null)
for (int i = 0; i < replicasList.size(); i++) {
ReplicationController rController = replicasList.get(i);
rcMap.put(rController.getMetadata().getName(), rController);
}
return rcMap;
}
public Map<String, ReplicationController> getReplicationControllerList() {
return getReplicationControllerList(DEFAULT_NAMESPACE);
}
public void close() {
if (!checkClientNull())
client.close();
}
}

View File

@ -0,0 +1,8 @@
/**
*
*/
/**
* @author wuming
*
*/
package com.platform.kubernetes;

View File

@ -1,79 +0,0 @@
package com.platform.oracle;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.validation.constraints.Pattern.Flag;
import com.platform.utils.Configs;
public class OracleConnector {
static {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Configs.CONSOLE_LOGGER.info("Oracle驱动加载成功");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static Connection ConnectionBuilder(String url, String user,
String password) {
Connection conn = null;
try {
conn = DriverManager.getConnection(url, user, password);
} catch (SQLException e) {
return conn;
}
return conn;
}
public static boolean canConnect(String url, String user, String password) {
return (null != ConnectionBuilder(url, user, password));
}
public ResultSet getSQLExecResultSet(Connection conn, String sql) {
ResultSet resultSet = null;
try {
Statement statement = conn
.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
resultSet = statement.executeQuery(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return resultSet;
}
public ResultSet getSQLExecResultSet(String url, String user,
String password, String sql) {
return getSQLExecResultSet(ConnectionBuilder(url, user, password), sql);
}
/**
* 执行对oracle数据库的增
* @param conn
* @param sql
* @return 是否执行成功
*/
public boolean execOracleSQL(Connection conn, String sql) {
boolean flag = false;
try {
Statement statement = conn.createStatement();
if (statement.executeUpdate(sql) > 0)
flag = true;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return flag;
}
}

View File

@ -6,6 +6,4 @@ import com.platform.entities.PagerOptions;
public interface DataInfoService {
public ModelMap getPagerTableData(PagerOptions pagerOptions);
void deleteData(String[] id);
}

View File

@ -24,35 +24,11 @@ public class DataInfoServiceImp implements DataInfoService {
public ModelMap getPagerTableData(PagerOptions pagerOptions) {
// TODO Auto-generated method stub
ModelMap modelMap = new ModelMap();
int count = dfdDao.getLimitedDataCount(pagerOptions); //获取总记录条数
int offset = 0;
if (pagerOptions.getCurrentPageNum() > 1) {
pagerOptions.setTotalLimit((pagerOptions.getCurrentPageNum() - 1)
* pagerOptions.getPriorTableSize());
offset = dfdDao.getLimitedBeginId(pagerOptions); //获取起始查询id
System.out.println(offset);
}
pagerOptions.setOffset(offset + 1);
List<DataInfoEntity> result = dfdDao
.getLimitedDataInfoEntities(pagerOptions);
int count = dfdDao.getLimitedDataCount(pagerOptions);
modelMap.addAttribute("data", result);
modelMap.addAttribute("length", count);
return modelMap;
}
@Override
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){
//删除文件操作
for (int i = 0; i < paths.size(); i++) {
System.out.println(paths.get(i));
}
//删除数据库记录
//dfdDao.deleteRow(idx);
}
}
}
}

View File

@ -5,7 +5,7 @@ import java.util.List;
import com.platform.entities.EncodedInfoEntity;
/**
* 数据库业务逻辑处理接口
* 数据库业务逻辑处理接口
*
* @author wuming
*

View File

@ -10,7 +10,7 @@ import com.platform.dao.EncodeInfoDao;
import com.platform.entities.EncodedInfoEntity;
/**
* 业务逻辑的具体实现类
* 业务逻辑的具体实现类
*
* @author wuming
*
@ -26,7 +26,7 @@ public class EncodeInfoServiceImpl implements EncodeInfoService {
}
/**
* 根据传递的tableName参数获取对应实体信息行政区划/系统
* 根据传递的tableName参数获取对应实体信息行政区划/系统
*/
@Override
public List<EncodedInfoEntity> getAllEncodeInfo(String tableName) {
@ -35,7 +35,7 @@ public class EncodeInfoServiceImpl implements EncodeInfoService {
}
/**
* 测试事物
* 测试事物
*/
@Override
public int deleteEncodeByCode(String code, String tableName) {

View File

@ -1,47 +0,0 @@
/**
* 文件名 : IGfsService.java
* 版权 : <版权/公司名>
* 描述 : <描述>
* @author chen
* 版本 : <版本>
* 修改时间 2016年9月8日
* 修改内容 <修改内容>
*/
package com.platform.service;
import com.platform.entities.FolderNode;
/**
* <一句话功能简述>
* <功能详细描述>
* @author chen
* @version [版本号2016年9月8日]
* @see [相关类/方法]
* @since [产品/模块版本]
*/
public interface IGfsService {
/**
* <一句话功能简述> 查找path的所有子目录
* <功能详细描述>
* @param path
* @return
* @throws Exception
* @see [#方法#成员]
*/
public FolderNode getFolder(String path) throws Exception;
/**
* <一句话功能简述> 复制path的所有子目录
* <功能详细描述>
* @param srcPath
* @param dstPath
* @return
* @throws Exception
* @see [#方法#成员]
*/
public int copyFolder(String src, String dst, String name) throws Exception;
}

View File

@ -1,151 +0,0 @@
package com.platform.service;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.mysql.jdbc.Connection;
import com.platform.entities.OracleConnectorParams;
import com.platform.oracle.OracleConnector;
import com.platform.utils.Configs;
import com.platform.utils.FileOperateHelper;
public class OracleExtractHelper {
private OracleConnector oConnector;
/**
* 判断dblink是否已经存在
*
* @param conn
* @param linkName
* dblink的名称
* @return
*/
private boolean hasSameNameDBLink(Connection conn, String linkName) {
boolean flag = false;
String sql = "SELECT * FROM ALL_DB_LINKS WHERE DB_LINK=" + linkName;
ResultSet rSet = oConnector.getSQLExecResultSet(conn, sql);
try {
rSet.last();
if (rSet.getRow() > 0)
flag = true;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return flag;
}
/**
* 创建dblink
*
* @param conn
* @param oc
* dblink连接参数实体
*/
public void createDBLink(Connection conn, OracleConnectorParams oc) {
String linkName = "LinkTo" + oc.getName();
String sql = "CREATE PUBLIC DATABASE LINK LinkTo"
+ linkName
+ " CONNECT TO "
+ "IDENTIFIED BY "
+ oc.getPassword()
+ " USING '(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = "
+ oc.getIp() + ")(PORT = " + oc.getPort()
+ ")))(CONNECT_DATA =(SERVICE_NAME =" + oc.getDatabase()
+ ")))';";
if (null != oc) {
if (hasSameNameDBLink(conn, linkName)) { // 如果dblink已经存在,先删除dblink在创建dblink
String deleteSql = "DROP PUBLIC DATABASE LINK LinkTo"
+ linkName;
FileOperateHelper
.fileWrite(
Configs.EXTRACT_LOG_LOCALTION + oc.getName(),
deleteSql);
if (oConnector.execOracleSQL(conn, deleteSql)) {
FileOperateHelper.fileWrite(Configs.EXTRACT_LOG_LOCALTION
+ oc.getName(), sql);
oConnector.execOracleSQL(conn, sql);
} else {
Configs.CONSOLE_LOGGER.error("删除已有的DBLink失败,无法创建新的DBLink!");
FileOperateHelper.fileWrite(Configs.EXTRACT_LOG_LOCALTION
+ oc.getName(), "删除已有的DBLink失败,无法创建新的DBLink!");
}
} else {
// 否则创建dblink
oConnector.execOracleSQL(conn, sql);
FileOperateHelper.fileWrite(
Configs.EXTRACT_LOG_LOCALTION + oc.getName(), sql);
}
}
}
/**
* 创建表空间
*
* @param conn
* @param oc
* @return
*/
public boolean createTableSpace(Connection conn, OracleConnectorParams oc) {
String tmpSql = "select TABLESPACE_NAME from dba_tablespaces where TABLESPACE_NAME = '"
+ Configs.GATHER_TABLESPACE_NAME + "'";
if (oConnector.execOracleSQL(conn, tmpSql)) {
return true;
} else {
String sql = "create tablespace " + Configs.GATHER_TABLESPACE_NAME
+ " datafile '" + Configs.GATHER_TABLESPACE_PATH
+ Configs.GATHER_TABLESPACE_NAME + ".dbf"
+ "' size 512M autoextend on next 512M maxsize unlimited";
return oConnector.execOracleSQL(conn, sql);
}
}
/**
* 创建用户并授权
*
* @param conn
* @param oc
*/
public void createUser(Connection conn, OracleConnectorParams oc) {
String strTUser = oc.getName() + Configs.TABLE_SUFFIX;
String sql = "Create user " + strTUser + " default tablespace "
+ Configs.GATHER_TABLESPACE_NAME + " identified by "
+ Configs.GATHER_TABLE_PASSWORD;
String grantSql = "grant connect, resource, dba to " + strTUser;
oConnector.execOracleSQL(conn, sql);
oConnector.execOracleSQL(conn, grantSql);
}
/**
* 执行汇总操作
*
* @param conn
* @param oc
*/
public void extractColleDB(Connection conn, OracleConnectorParams oc) {
String strTUser = oc.getName() + Configs.TABLE_SUFFIX;
String sql = "SELECT 'create table "
+ strTUser
+ ".J'|| substr(t.OWNER||'_'||t.TABLE_NAME,0,29)||' as select * from '||t.OWNER||'.'||t.TABLE_NAME||"
+ "'@linkTo"
+ oc.getName()
+ ";' FROM dba_tables@linkTo"
+ oc.getName()
+ " t WHERE t.TABLESPACE_NAME NOT IN ('SYSTEM','SYSAUX')"
+ " and t.owner||t.table_name not in (select owner||table_name from dba_tables@linkTo"
+ oc.getName() + " where 'data_type'='CLOB')";
ResultSet rsSet = oConnector.getSQLExecResultSet(conn, sql);
try {
while (rsSet.next()) {
String resultSql = rsSet.getString(0);
oConnector.execOracleSQL(conn, resultSql);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

View File

@ -1,24 +0,0 @@
package com.platform.service;
import com.platform.entities.OracleConnectorParams;
import com.platform.oracle.OracleConnector;
import com.platform.utils.Configs;
public class OracleExtractService extends Thread implements Runnable {
private OracleConnectorParams ocp;
private java.sql.Connection conn;
public OracleExtractService(OracleConnectorParams ocp){
this.ocp=ocp;
String url = "";
this.conn=OracleConnector.ConnectionBuilder(url, Configs.GATHER_USER_NAME, Configs.GATHER_USER_PASSWORD);
}
@Override
public void run() {
// TODO Auto-generated method stub
}
}

View File

@ -1,149 +0,0 @@
package com.platform.service;
import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.api.model.ReplicationController;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import com.platform.entities.OracleConnectorParams;
import com.platform.kubernetes.SimpleKubeClient;
import com.platform.oracle.OracleConnector;
import com.platform.utils.Configs;
public class OracleStatusService {
private static Map<String, Timer> alliveTask = new Hashtable<String, Timer>();
public final static int EXEC_TIME = 10;// 连接多少次后不成功取消链接
public final static long INTERVAL_TIME = 60 * 1000;// 每隔多少毫秒执行一次连接任务
public final static long DELAY_TIME = 0; // 延迟多少秒后执行
public void connectToOracle(String replicasName) {
SimpleKubeClient sKubeClient = new SimpleKubeClient();
ReplicationController replicationController = sKubeClient
.getReplicationController(replicasName);
if (alliveTask.containsKey(replicasName)) {
killAlliveTask(replicasName);
}
if (null != replicationController) {
List<Pod> filterPods = sKubeClient
.getPodsForApplicaList(replicationController);
if (filterPods != null && filterPods.size() > 0) {
Pod pod = filterPods.get(0);
OracleConnectorParams orp = new OracleConnectorParams(
String.valueOf(sKubeClient.getPodContainerport(pod)),
sKubeClient.getPodHostIp(pod), replicasName);
Timer timer = new Timer();
alliveTask.put(replicasName, timer);
timer.schedule(new connectTask(orp, sKubeClient), DELAY_TIME,
INTERVAL_TIME);
}
}
}
public void cancelToOracle(String replicasName, String operate) {
if (operate.equals("stop")) {
SimpleKubeClient sKubeClient = new SimpleKubeClient();
sKubeClient.updateOrAddReplicasLabelById(replicasName, "status",
"0");
}
killAlliveTask(replicasName);
}
/**
* 取消并移除指定定时任务
*
*
* @param taskName
*/
public void killAlliveTask(String taskName) {
if (alliveTask.containsKey(taskName)) {
alliveTask.get(taskName).cancel();
alliveTask.remove(taskName);
}
}
public void killAlliveTasks(String... tasksName) {
for (String taskName : tasksName)
killAlliveTask(taskName);
}
/**
* 清空定时任务
*/
public void cleanUpAlliveTask() {
Iterator<Map.Entry<String, Timer>> iterator = alliveTask.entrySet()
.iterator();
while (iterator.hasNext()) {
Map.Entry<String, Timer> entry = iterator.next();
entry.getValue().cancel();
}
alliveTask.clear();
}
/**
* 链接oracle任务类
*
* @author wuming
*
*/
class connectTask extends TimerTask {
private String taskName;
private int count;
private OracleConnectorParams ocp;
private SimpleKubeClient client;
public connectTask(OracleConnectorParams ocp, SimpleKubeClient client) {
this.taskName = ocp.getName();
this.ocp = ocp;
this.count = 0;
this.client = client;
}
@Override
public void run() {
if (count == EXEC_TIME && alliveTask.containsKey(taskName)) {
killAlliveTask(taskName);
client.updateOrAddReplicasLabelById(taskName, "status", "1");
} else {
String url = "jdbc:oracle:thin:@" + ocp.getIp() + ":"
+ ocp.getPort() + ":" + ocp.getDatabase();
boolean flag = OracleConnector.canConnect(url, ocp.getUser(),
ocp.getPassword());
String message = "失败";
if (flag && alliveTask.containsKey(taskName)) {
client.updateOrAddReplicasLabelById(taskName, "status", "2");
message = "成功";
killAlliveTask(taskName); // 连接成功取消连接
}
Configs.CONSOLE_LOGGER.info("连接到数据库服务: " + taskName
+ "\t[连接结果: " + message + "]");
}
count++;
}
@Override
public boolean cancel() {
System.out.println("aaaaaaa");
if (client != null)
this.client.close();
return super.cancel();
}
public String getTaskName() {
return taskName;
}
public void setTaskName(String taskName) {
this.taskName = taskName;
}
public int getCount() {
return count;
}
}
}

View File

@ -1,20 +0,0 @@
package com.platform.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import com.platform.entities.SimpleConfigParamsBean;
public class SimplePropertyReader {
@Autowired @Qualifier("simpeConfig")
private SimpleConfigParamsBean configParamsBean;
public void setConfigParamsBean(SimpleConfigParamsBean configParamsBean) {
this.configParamsBean = configParamsBean;
}
public SimpleConfigParamsBean getConfigParamsBean() {
return configParamsBean;
}
}

View File

@ -1,48 +0,0 @@
/**
* 文件名 : GfsServiceImpl.java
* 版权 : <版权/公司名>
* 描述 : <描述>
* @author chen
* 版本 : <版本>
* 修改时间 2016年9月8日
* 修改内容 <修改内容>
*/
package com.platform.service.impl;
import org.springframework.stereotype.Service;
import com.platform.entities.FolderNode;
import com.platform.glusterfs.CopyData;
import com.platform.glusterfs.GetTreeData;
import com.platform.service.IGfsService;
/**
* <一句话功能简述>
* <功能详细描述>
* @author chen
* @version [版本号2016年9月8日]
* @see [相关类/方法]
* @since [产品/模块版本]
*/
@Service(value = "gfsService")
public class GfsServiceImpl implements IGfsService {
private GetTreeData gfsTree = new GetTreeData();
private CopyData copydata = new CopyData();
@Override
public FolderNode getFolder(String path) {
FolderNode result = gfsTree.getDatas(path);
return result;
}
@Override
public int copyFolder(String src, String dst, String name)
throws Exception {
// TODO Auto-generated method stub
int status = copydata.copyVolumeFiles(src, dst, name);
return status;
}
}

View File

@ -1,84 +0,0 @@
package com.platform.utils;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.commons.lang.StringUtils;
public class ConfigLoder {
private String configPath;
private volatile static ConfigLoder configLoder;
private ConfigLoder(String configPath) {
this.configPath = configPath;
}
public static ConfigLoder Builder(String configPtah) {
if (null == configLoder) {
synchronized (ConfigLoder.class) {
if (null == configLoder)
configLoder = new ConfigLoder(configPtah);
}
}
return configLoder;
}
/**
* 读取文Property中的属性值
*
* @param key
* @return
*/
public String getProperty(String key) {
String value = null;
if (StringUtils.isEmpty(key))
return value;
try {
InputStream is = new BufferedInputStream(new FileInputStream(
new File(configPath)));
Properties properties = new Properties();
properties.load(is);
value = properties.getProperty(key);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return value;
}
public Properties getProperties() {
Properties properties = null;
try {
InputStream is;
properties = new Properties();
is = new BufferedInputStream(new FileInputStream(new File(
configPath)));
properties.load(is);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return properties;
}
public String getConfigPath() {
return configPath;
}
public void setConfigPath(String configPath) {
this.configPath = configPath;
}
}

View File

@ -1,84 +0,0 @@
package com.platform.utils;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.commons.lang.StringUtils;
public class ConfigPropertyReader {
private String configPath;
private volatile static ConfigPropertyReader configLoder;
private ConfigPropertyReader(String configPath) {
this.configPath = configPath;
}
public static ConfigPropertyReader Builder(String configPtah) {
if (null == configLoder) {
synchronized (ConfigPropertyReader.class) {
if (null == configLoder)
configLoder = new ConfigPropertyReader(configPtah);
}
}
return configLoder;
}
/**
* 读取文Property中的属性值
*
* @param key
* @return
*/
public synchronized String getProperty(String key) {
String value = null;
if (StringUtils.isEmpty(key))
return value;
try {
InputStream is = new BufferedInputStream(new FileInputStream(
new File(configPath)));
Properties properties = new Properties();
properties.load(is);
value = properties.getProperty(key);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return value;
}
public Properties getProperties() {
Properties properties = null;
try {
InputStream is;
properties = new Properties();
is = new BufferedInputStream(new FileInputStream(new File(
configPath)));
properties.load(is);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return properties;
}
public String getConfigPath() {
return configPath;
}
public void setConfigPath(String configPath) {
this.configPath = configPath;
}
}

View File

@ -1,52 +0,0 @@
package com.platform.utils;
import org.apache.log4j.Logger;
public class Configs {
/** 全局自定义异常--编码 */
public static final String GLOBAL_EXP_CUSTOM = "3001001001";
/** 全局非自定义异常--编码 */
public static final String GLOBAL_EXP_NOT_CUSTOM = "3001001002";
public static final String CONFIG_LOCALTION = "WebContent/WEB-INF/config/config.properties";
public static final Logger CONSOLE_LOGGER = Logger.getLogger("console");
public static final Logger DAILY_ROLLING_LOGGER = Logger
.getLogger("dailyRollingFile");
public static final Logger DAILY_LOGGER = Logger.getLogger("railyFile");
public static final Logger LOGGER = Logger.getLogger(Configs.class);
public static String KUBE_MASTER_URL = "http://192.168.0.113:8080/"; // kubernetes集群的maser
// URl
public static int ORACLE_DEFAULT_PORT = 1521; // oracle的默认端口号
public static String COLLECT_USER_NAME = "system"; //采集统一的登入用户名
public static String COLLECT_PASSWORD = "oracle"; //采集统一的登入密码
public static String COLLECT_SERVICE_NAME = "orcl"; //采集库统一的服务名
public static String GATHER_PORT ="1521"; //汇总库的端口号
public static String GATHER_USER_NAME = "system"; //汇总库的登入用户名
public static String GATHER_USER_PASSWORD = "1"; //汇总库的登入密码
public static String GATHER_SERVICE_NAME = "orcl"; //汇总库的服务名
public static String TABLE_SUFFIX = "_20152016"; //汇总库汇总表的后缀名
public static String EXTRACT_LOG_LOCALTION = "/home/log"; //数据汇总日志保存位置
public static String GATHER_TABLESPACE_NAME=""; //表空间名
public static String GATHER_TABLESPACE_PATH=""; //表空间路径
public static String GATHER_TABLE_PASSWORD=""; //登入密码
}

View File

@ -1,73 +0,0 @@
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();
}
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;
}
}

Some files were not shown because too many files have changed in this diff Show More