迁移数据

glusterfs-api
chenlw 8 years ago
commit ef099fd1ae

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<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="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/com.sun.java.jdk7.win32.x86_64_1.7.0.u45"/>
<classpathentry kind="output" path="build/classes"/>
</classpath>

6
.gitignore vendored

@ -1 +1,5 @@
build/ /target
/build
.classpath
/bin/

@ -25,6 +25,11 @@
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand>
<name>com.genuitec.eclipse.ast.deploy.core.DeploymentBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec> </buildSpec>
<natures> <natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature> <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>

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

@ -1,2 +1,5 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
encoding//WebContent/WEB-INF/config/config.properties=UTF-8 encoding//WebContent/WEB-INF/config/config.properties=UTF-8
encoding//src/com/platform/utils/GanymedSSH.java=UTF-8
encoding/<project>=UTF-8
separateDerivedEncodings=true

@ -1,7 +1,101 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7 org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
org.eclipse.jdt.core.compiler.problem.deadCode=warning
org.eclipse.jdt.core.compiler.problem.deprecation=warning
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error
org.eclipse.jdt.core.compiler.problem.nullReference=warning
org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error
org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore
org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore
org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedImport=warning
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore
org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.source=1.7 org.eclipse.jdt.core.compiler.source=1.7

@ -0,0 +1,3 @@
eclipse.preferences.version=1
org.eclipse.jpt.core.platform=generic2_1
org.eclipse.jpt.jpa.core.discoverAnnotatedClasses=false

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

@ -0,0 +1,7 @@
<root>
<facet id="jpt.jpa">
<node name="libprov">
<attribute name="provider-id" value="jpa-no-op-library-provider"/>
</node>
</facet>
</root>

@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<faceted-project> <faceted-project>
<runtime name="Apache Tomcat v7.0"/> <runtime name="MyEclipse Tomcat v7.0"/>
<fixed facet="java"/> <fixed facet="java"/>
<fixed facet="wst.jsdt.web"/> <fixed facet="wst.jsdt.web"/>
<fixed facet="jst.web"/> <fixed facet="jst.web"/>
<installed facet="java" version="1.7"/> <installed facet="java" version="1.7"/>
<installed facet="jst.web" version="3.0"/> <installed facet="jst.web" version="3.0"/>
<installed facet="wst.jsdt.web" version="1.0"/> <installed facet="wst.jsdt.web" version="1.0"/>
<installed facet="jpt.jpa" version="2.1"/>
</faceted-project> </faceted-project>

@ -0,0 +1,17 @@
#!/bin/bash
function ergodic(){
for file in `ls $1`
do
if [ "$file" != "app" -a -d $1"/"$file ]
then
ergodic $1"/"$file
else
local path=$1"/"$file
echo $path
fi
done
}
IFS=$'\n' #这个必须要,否则会在文件名中有空格时出错
INIT_PATH=".";
ergodic $1

@ -14,7 +14,7 @@
<appender name="dailyRollingFile" class="org.apache.log4j.DailyRollingFileAppender"> <appender name="dailyRollingFile" class="org.apache.log4j.DailyRollingFileAppender">
<param name="Threshold" value="info"></param> <param name="Threshold" value="info"></param>
<param name="ImmediateFlush" value="true"></param> <param name="ImmediateFlush" value="true"></param>
<param name="File" value="d:/logs/dailyRollingFile.log"></param> <param name="File" value="logs/dailyRollingFile.log"></param>
<param name="DatePattern" value="'.'yyyy-MM-dd'.log'"></param> <param name="DatePattern" value="'.'yyyy-MM-dd'.log'"></param>
<layout class="org.apache.log4j.PatternLayout"> <layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{yyyy-MM-dd HH:mm:ss\} %-5p] [%t] {%c:%L}-%m%n"></param> <param name="ConversionPattern" value="[%d{yyyy-MM-dd HH:mm:ss\} %-5p] [%t] {%c:%L}-%m%n"></param>
@ -23,7 +23,7 @@
<!-- 输出日志到文件 文件大小到达指定尺寸的时候产生一个新的文件 --> <!-- 输出日志到文件 文件大小到达指定尺寸的时候产生一个新的文件 -->
<appender name="railyFile" class="org.apache.log4j.RollingFileAppender"> <appender name="railyFile" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="d:/logs/railyFile.log"></param> <param name="File" value="logs/railyFile.log"></param>
<param name="ImmediateFlush" value="true" /> <param name="ImmediateFlush" value="true" />
<param name="Threshold" value="info"></param> <param name="Threshold" value="info"></param>
<param name="Append" value="true"></param> <param name="Append" value="true"></param>

@ -1,3 +1,4 @@
/** /**
* BaseController.java * BaseController.java
* : XX * : XX
@ -60,4 +61,5 @@ public class BaseController {
return response; return response;
} }
} }
} }

@ -1,3 +1,5 @@
package com.base; package com.base;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -122,3 +124,4 @@ public class CustomException extends Exception {
return cause; return cause;
} }
} }

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

@ -184,14 +184,20 @@ public class DataModelController extends BaseController{
JSONObject jsonobject = JSONObject.fromObject(string); JSONObject jsonobject = JSONObject.fromObject(string);
map = jsonobject; map = jsonobject;
} }
String dstVolume = (String) map.get("volume");
List<String> listItemPath = new ArrayList<String>(); List<String> listItemPath = new ArrayList<String>();
String[] items = paramMap.get("selectItems"); String[] items = paramMap.get("selectItems");
System.out.println("selectItems"); System.out.println("selectItems");
List<DataInfoEntity> datas = new ArrayList<DataInfoEntity>(); List<DataInfoEntity> datas = new ArrayList<DataInfoEntity>();
List<String> srcVolumes = new ArrayList<String>();
for (String string : items) { for (String string : items) {
System.out.println(string); System.out.println(string);
JSONObject jsobj = JSONObject.fromObject(string); JSONObject jsobj = JSONObject.fromObject(string);
Map itemmap = jsobj; Map itemmap = jsobj;
if (null != itemmap.get("volume")) {
srcVolumes.add((String) itemmap.get("volume"));
}
DataInfoEntity data = (DataInfoEntity) Bean2MapUtils.convertMap(DataInfoEntity.class, itemmap); DataInfoEntity data = (DataInfoEntity) Bean2MapUtils.convertMap(DataInfoEntity.class, itemmap);
datas.add(data); datas.add(data);
} }
@ -231,7 +237,7 @@ public class DataModelController extends BaseController{
System.out.println("----------insertOracleInfo-----------------------"); System.out.println("----------insertOracleInfo-----------------------");
} }
@RequestMapping(value="/oracle/update", method= RequestMethod.POST) @RequestMapping(value="/oracle/{id}/update", method= RequestMethod.POST)
@ResponseBody @ResponseBody
public void updateOracleInfo(HttpServletRequest res, public void updateOracleInfo(HttpServletRequest res,
HttpServletResponse req, GatherOracleInfo oracle) throws Exception { HttpServletResponse req, GatherOracleInfo oracle) throws Exception {
@ -250,11 +256,10 @@ public class DataModelController extends BaseController{
return result; return result;
} }
@RequestMapping(value="/task/transfer/deletes", method= RequestMethod.POST) @RequestMapping(value="/task/transfer/delete", method= RequestMethod.POST)
@ResponseBody @ResponseBody
public Object taskdeletes() throws Exception { public Object taskdeletes(DataInfoEntityMoveTmp move) throws Exception {
DataInfoEntityMoveTmp dataMove = null; int result = moveDataService.delete(move);
int result = moveDataService.delete(dataMove);
return result; return result;
} }
} }

@ -1,3 +1,4 @@
package com.platform.controller; package com.platform.controller;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -28,3 +29,4 @@ public class DefaultController {
} }
} }

@ -1,6 +1,7 @@
package com.platform.controller; package com.platform.controller;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -13,11 +14,19 @@ import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import com.base.BaseController; import com.base.BaseController;
import com.base.CustomException; import com.base.CustomException;
import com.platform.entities.GfsFolderEntity; import com.platform.entities.GfsFolderEntity;
import com.platform.entities.VolumeEntity; import com.platform.entities.VolumeEntity;
import com.platform.glusterfs.VolumeInfo; import com.platform.glusterfs.VolumeInfo;
import com.platform.entities.VolumeEntity;
import com.platform.glusterfs.VolumeInfo;
import com.platform.service.IGfsService; import com.platform.service.IGfsService;
@ -30,13 +39,19 @@ import com.platform.service.IGfsService;
* @since [/] * @since [/]
*/ */
@Controller @Controller
@RequestMapping("") @RequestMapping("")
public class FolderController extends BaseController { public class FolderController extends BaseController {
@Resource(name = "gfsService") @Resource(name = "gfsService")
private IGfsService gfsService; private IGfsService gfsService;
@RequestMapping(value="/getAllSubPathByPath", method= RequestMethod.POST) @RequestMapping(value="/getAllSubPathByPath", method= RequestMethod.POST)
public Object getAllSubPathByPath(String path) throws Exception { public Object getAllSubPathByPath(String path) throws Exception {
System.out.println(path); System.out.println(path);
Object result = null; Object result = null;
@ -47,6 +62,22 @@ public class FolderController extends BaseController {
return result; 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 = 0;
// 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;
}
// /** // /**
// * <一句话功能简述> 查询集群中所有的 volume 及其 信息 // * <一句话功能简述> 查询集群中所有的 volume 及其 信息
// * <功能详细描述> // * <功能详细描述>
@ -77,6 +108,7 @@ public class FolderController extends BaseController {
public Object getVolumByName(String volumeName) throws Exception{ public Object getVolumByName(String volumeName) throws Exception{
VolumeEntity result = gfsService.getOneVolume(volumeName); VolumeEntity result = gfsService.getOneVolume(volumeName);
return result; return result;
} }
} }

@ -17,7 +17,12 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
/** /**
* <>
* <> * <>
* <> * <>
* @author liliy * @author liliy
* @version [201698] * @version [201698]
@ -26,6 +31,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
*/ */
@Controller @Controller
public class SetGlusterfsController { public class SetGlusterfsController {
@RequestMapping("/tes") @RequestMapping("/tes")
public Object defaultHandler(HttpServletRequest req, HttpServletResponse request) { public Object defaultHandler(HttpServletRequest req, HttpServletResponse request) {
//<2F><><EFBFBD><><C6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> //<2F><><EFBFBD><><C6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
@ -42,4 +48,5 @@ public class SetGlusterfsController {
} }
} }

@ -10,6 +10,7 @@
*/ */
package com.platform.controller; package com.platform.controller;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -17,9 +18,11 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import com.platform.glusterfs.ClusterInfo; import com.platform.glusterfs.ClusterInfo;
import com.platform.glusterfs.VolumeInfo;
/** /**
* <> * <>
* <> * <>
* @author liliy * @author liliy
* @version [201698] * @version [201698]
@ -28,8 +31,11 @@ import com.platform.glusterfs.ClusterInfo;
*/ */
@Controller @Controller
public class ShowGlusterfsController { public class ShowGlusterfsController {
/** /**
* <> * <>
* <> * <>
* @return * @return
* @see [##] * @see [##]

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

@ -9,9 +9,11 @@ public class FolderNode {
private String path; private String path;
private List<FolderNode> childNodes = new ArrayList<FolderNode>(); private List<FolderNode> childNodes = new ArrayList<FolderNode>();
public FolderNode() { public FolderNode() {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
public FolderNode(String name) { public FolderNode(String name) {
this.name = name; this.name = name;

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

@ -1,9 +1,9 @@
package com.platform.glusterfs; package com.platform.glusterfs;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator; import org.apache.log4j.PropertyConfigurator;
@ -33,7 +33,7 @@ public class CopyData {
String sourceFolderName = sourceVolumeName; String sourceFolderName = sourceVolumeName;
String destFolderName = destVolumeName; String destFolderName = destVolumeName;
status = copyFolderFiles(sourceFolderName, destFolderName, fileName); status = copyFolderFilesAnyway(sourceFolderName, destFolderName, fileName);
return status; return status;
} }
@ -47,13 +47,6 @@ public class CopyData {
*/ */
public int copyFolderFiles(String sourceFolderName, String destFolderName, String fileName) { public int copyFolderFiles(String sourceFolderName, String destFolderName, String fileName) {
int progress=0; int progress=0;
// 末尾 含有 /
Pattern pattern2 = Pattern.compile("\\/$");
Matcher matcher = pattern2.matcher(sourceFolderName);
if (matcher.find()) {
sourceFolderName = sourceFolderName.substring(0, sourceFolderName.length()-1);
}
log.info("start copy " + fileName + " from " + sourceFolderName + " to " + destFolderName); log.info("start copy " + fileName + " from " + sourceFolderName + " to " + destFolderName);
ShowData showData=new ShowData(); ShowData showData=new ShowData();
Map<String,String> reStrings=showData.showFolderData(destFolderName); Map<String,String> reStrings=showData.showFolderData(destFolderName);
@ -62,7 +55,7 @@ public class CopyData {
return -3; return -3;
} }
reStrings=showData.showFolderData(sourceFolderName+"/"+fileName); reStrings=showData.showFolderData(sourceFolderName+"/"+fileName);
if(reStrings==null){ if(reStrings==null){
log.info("3202 "+sourceFolderName+"/"+fileName+" is not exists"); log.info("3202 "+sourceFolderName+"/"+fileName+" is not exists");
return -2; return -2;
@ -79,45 +72,40 @@ public class CopyData {
return 1; return 1;
} }
/** /**
* -1 :error; -2: the filename is not exists ;-3 :destFolderName ; 1: right * @param sourceFolderName
* not exists * @param destFolderName
*
* @param folderName
* @param fileName * @param fileName
* @return * @return
*/ */
public int copyFolderFiles(String sourceFolderName, String destFolderName) { public int copyFolderFilesAnyway(String sourceFolderName, String destFolderName, String fileName) {
int progress=0; createFolders(destFolderName);
log.info("start copy " + " from " + sourceFolderName + " to " + destFolderName); int result = copyFolderFiles(sourceFolderName, destFolderName, fileName);
ShowData showData=new ShowData(); return result;
Map<String,String> reStrings=showData.showFolderData(destFolderName); }
if(reStrings==null){
log.info("3201 "+destFolderName+" is not exists");
return -3;
}
reStrings=showData.showFolderData(sourceFolderName);
if(reStrings==null){
log.info("3202 "+sourceFolderName+" is not exists");
return -2;
}
String command = "cp -r " + sourceFolderName+" "+destFolderName;
/*
* RunCommand runCommand = new RunCommand();
List<String> reStrings = runCommand.runCommandWait(command);
*/
Constant.ganymedSSH.execCmdNoWaitAcquiescent(command);
log.info("copy " + sourceFolderName +"/" + " to " + destFolderName + " running"); public int createFolders(String folder){
log.info("create "+folder);
String splitFolder[]=folder.substring(1).split("/");
String cmd="mkdir ";
for(String one:splitFolder){
cmd+="/"+one.replaceAll(" ", "");
Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
}
return 1; return 1;
} }
@Test @Test
public void testcreateFolders() {
createFolders("/aaa/vvv/ddd/www/rrrr");
}
//@Test
public void testCopyFolderFiles() { public void testCopyFolderFiles() {
PropertyConfigurator.configure("log4j.properties");
copyFolderFiles("/home", "/home/ubuntu", "system_data"); copyFolderFiles("/home", "/home/ubuntu", "system_data");
} }
} }

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

@ -16,17 +16,7 @@ import com.platform.utils.Constant;
public class RemoveData { public class RemoveData {
public static Logger log = Logger.getLogger ( RemoveData.class); 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 * -1 :error; 0: the filename is not exists ; 1: right
@ -34,65 +24,33 @@ public class RemoveData {
* @param fileName * @param fileName
* @return * @return
*/ */
public int deleteFolderFiles(String folderName,String fileName){ public int deleteFolder(String folderName){
log.info("start delete "+folderName+"/"+fileName); log.info("start delete "+folderName);
ShowData showData=new ShowData(); ShowData showData=new ShowData();
Map<String,String> reStrings=showData.showFolderData(folderName+"/"+fileName); Map<String,String> reStrings=showData.showFolderData(folderName);
if(reStrings==null){ if(reStrings==null){
log.error("3301 "+folderName+"/"+fileName+" is not exists"); log.error("3301 "+folderName+" is not exists");
return -1; return -1;
} }
String command="rm -r "+folderName+"/"+fileName; String command="rm -r "+folderName;
// int status=runCommand.runCommand(command); // int status=runCommand.runCommand(command);
Constant.ganymedSSH.execCmdNoWaitAcquiescent(command); Constant.ganymedSSH.execCmdNoWaitAcquiescent(command);
log.info("delete "+folderName+" "+fileName+" running"); log.info("delete "+folderName+" running");
return 1; 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 @Test
public void testDeleteFolderFiles() { public void testDeleteFolderFiles() {
PropertyConfigurator.configure("log4j.properties"); PropertyConfigurator.configure("log4j.properties");
deleteFolderFiles("/home/ubuntu","system_data"); deleteFolder("/home/ubuntu");
} }
} }

@ -1,11 +1,67 @@
package com.platform.glusterfs;
package com.platform.glusterfs;
import org.apache.log4j.Logger;
import java.util.List;
public class SetCluster {
public static Logger log = Logger.getLogger ( SetCluster.class); import org.apache.log4j.Logger;
import org.hamcrest.core.Is;
public int addPeer(String peerip){
return 0; import com.platform.utils.Constant;
} import com.platform.utils.Support;
}
public class SetCluster {
public static Logger log = Logger.getLogger ( SetCluster.class);
/**
*
* 1-1ip-2 0
* @param peerip
* @return
* @see [##]
*/
public int probePeer(String peerip){
if(!Support.checkIP(peerip)){
log.error(peerip +"is illegal!" );
return -1;
}
String cmd="gluster peer probe "+peerip;
List<String> reStrings=Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
if(reStrings==null || reStrings.size()==0){
log.error("detach error! ");
return -2;
}
if(reStrings.contains(Constant.success)){
log.info("probe success!");
return 1;
}
log.info("probe failed!");
return 0;
}
/**
*
* 1-1ip-2 0
* @param peerip
* @return
* @see [##]
*/
public int detachPeer(String peerip){
if(!Support.checkIP(peerip)){
log.error(peerip +"is illegal!" );
return -1;
}
String cmd="gluster peer detach "+peerip;
List<String> reStrings=Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
if(reStrings==null || reStrings.size()==0){
log.error("detach error! ");
return -2;
}
if(reStrings.contains(Constant.success)){
log.info("detach success!");
return 1;
}
log.info("detach failed!");
return 0;
}
}

File diff suppressed because it is too large Load Diff

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

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

@ -1,3 +1,4 @@
package com.platform.service; package com.platform.service;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;

@ -10,11 +10,13 @@
*/ */
package com.platform.service; package com.platform.service;
import java.util.List; import java.util.List;
import com.platform.entities.FolderNode; import com.platform.entities.FolderNode;
import com.platform.entities.VolumeEntity; import com.platform.entities.VolumeEntity;
/** /**
* <> * <>
* <> * <>
@ -45,6 +47,7 @@ public interface IGfsService {
* @throws Exception * @throws Exception
* @see [##] * @see [##]
*/ */
public int copyFolder(List<String> srcFolders, String dstFolder, String name) throws Exception; public int copyFolder(List<String> srcFolders, String dstFolder, String name) throws Exception;
/** /**
@ -68,5 +71,6 @@ public interface IGfsService {
public int moveData(String volumeName, String srcPath, String dstPath) throws Exception; public int moveData(String volumeName, String srcPath, String dstPath) throws Exception;
public int deleteData(String volumeName, String srcPath) throws Exception; public int deleteData(String volumeName, String srcPath) throws Exception;
} }

@ -40,8 +40,18 @@ public class OracleExtractHelper {
/** /**
* dblink * dblink
* *
<<<<<<< HEAD
<<<<<<< HEAD
* @param conn
* @param oc
=======
* @param conn
* @param oc
>>>>>>> 355b6e47a4fa8d058029ec939fe4fefdaa751275
=======
* @param conn * @param conn
* @param oc * @param oc
>>>>>>> web_backend_develope
* dblink * dblink
*/ */
public void createDBLink(Connection conn, OracleConnectorParams oc) { public void createDBLink(Connection conn, OracleConnectorParams oc) {

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

@ -135,7 +135,7 @@ public class ThreadMoveData{
//如果是 待 迁移状态的 //如果是 待 迁移状态的
if ("0".equals(next2move.getCompleteStatus())) { if ("0".equals(next2move.getCompleteStatus())) {
//待迁移的数据 -- 开始迁移 //待迁移的数据 -- 开始迁移
copy.copyFolderFiles(next2move.getDataPath(), next2move.getDstPath(), "app"); copy.copyFolderFilesAnyway(next2move.getDataPath(), next2move.getDstPath(), "app");
// "1" :正在上传0等待 迁移, 2成功 3失败 // "1" :正在上传0等待 迁移, 2成功 3失败
next2move.setCompleteStatus("1"); next2move.setCompleteStatus("1");
next2move.setLastTime(DateForm.date2StringBysecond(new Date())); next2move.setLastTime(DateForm.date2StringBysecond(new Date()));

@ -1,39 +1,39 @@
package com.platform.utils; package com.platform.utils;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.platform.entities.FolderNode; import com.platform.entities.FolderNode;
import com.platform.entities.VolumeEntity; import com.platform.entities.VolumeEntity;
public class CacheTreeData { public class CacheTreeData {
private static List<FolderNode> folders = null; private static List<FolderNode> folders = null;
private static List<VolumeEntity> volumeList = null; private static List<VolumeEntity> volumeList = null;
public static List<FolderNode> getFolders() { public static List<FolderNode> getFolders() {
return folders; return folders;
} }
public static void setFolders(List<FolderNode> folders) { public static void setFolders(List<FolderNode> folders) {
CacheTreeData.folders = folders; CacheTreeData.folders = folders;
} }
/** /**
* @return the volumeList * @return the volumeList
*/ */
public static List<VolumeEntity> getVolumeList() { public static List<VolumeEntity> getVolumeList() {
return volumeList; return volumeList;
} }
/** /**
* @param volumeList the volumeList to set * @param volumeList the volumeList to set
*/ */
public static void setVolumeList(List<VolumeEntity> volumeList) { public static void setVolumeList(List<VolumeEntity> volumeList) {
CacheTreeData.volumeList = volumeList; CacheTreeData.volumeList = volumeList;
} }
} }

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

@ -1,40 +1,46 @@
package com.platform.utils;
package com.platform.utils;
import java.util.List;
import java.util.List;
public class Constant {
public static String rootUser = "root"; public class Constant {
public static String rootPasswd = "root"; public static String rootUser = "root";
public static String hostIp = "192.168.0.116"; public static String rootPasswd = "root";
// public static String hostIp = "192.168.1.105"; public static String hostIp = "192.168.0.116";
public static int port = 22; // public static String hostIp = "192.168.1.105";
public static String glusterPeerStatus = "gluster peer status"; public static int port = 22;
public static String glusterVolumeInfo = "gluster volume info "; public static String glusterPeerStatus = "gluster peer status";
public static String df = "df -k "; public static String glusterVolumeInfo = "gluster volume info ";
public static String peerincluster_connected="PeerinCluster(Connected)"; public static String df = "df -k ";
public static String peerincluster_connected = "PeerinCluster(Connected)";
public static String peerincluster_disconnected="PeerinCluster(Disconnected)"; public static String peerincluster_disconnected = "PeerinCluster(Disconnected)";
public static String distributed="distributed"; public static String peerNotinCluster = "PeerNotinCluster";
public static String replica="replica"; public static String distributed = "distributed";
public static String stripe="stripe"; public static String replica = "replica";
public static String noVolume="No volumes present"; public static String stripe = "stripe";
public static String noSuchFile = "No such file or directory"; public static String noVolume = "No volumes present";
public static GanymedSSH ganymedSSH=new GanymedSSH(hostIp, rootUser, rootPasswd, port); public static String success = "success";
public static String fileGetTreeData="./WEB-INF/config/getTreedata.sh"; public static String failed = "failed";
public static String strGetTreeData = "function ergodic(){\n " public static String noSuchFile = "No such file or directory";
+ "for file in \\`ls \\$1\\`\n do\n if [ \"\\$file\" != \"app\" -a -d \\$1\\\"/\\\"\\$file ]\n " public static GanymedSSH ganymedSSH = new GanymedSSH(hostIp, rootUser, rootPasswd, port);
+ "then\n ergodic \\$1\"/\"\\$file\n else\n local path=\\$1\"/\"\\$file\n " public static String fileGetTreeData = "WebContent\\WEB-INF\\config\\getTreedata.sh";
+ "echo \\$path \n fi\n done\n}\n\nIFS=\\$\\'\\n\\' " public static String strGetTreeData = "function ergodic(){\n "
+ "#这个必须要,否则会在文件名中有空格时出错\nINIT_PATH=\".\";\nergodic \\$1\n"; + "for file in \\`ls \\$1\\`\n do\n if [ \"\\$file\" != \"app\" -a -d \\$1\\\"/\\\"\\$file ]\n "
+ "then\n ergodic \\$1\"/\"\\$file\n else\n local path=\\$1\"/\"\\$file\n "
/** + "echo \\$path \n fi\n done\n}\n\nIFS=\\$\\'\\n\\' "
* volume 线 + "#这个必须要,否则会在文件名中有空格时出错\nINIT_PATH=\".\";\nergodic \\$1\n";
*/
public final static int get_volume_sleep_time = 300000;
/**
* volume 线 /**
*/ * volume 线
public final static int update_dataInfo_sleep_time = 3000; */
public final static int get_volume_sleep_time = 300000;
}
/**
* volume 线
*/
public final static int update_dataInfo_sleep_time = 3000;
}

@ -7,6 +7,8 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import org.junit.Test;
/** /**
* *
* *
@ -65,14 +67,18 @@ public class FileOperateHelper {
* @param path * @param path
* @return * @return
*/ */
@SuppressWarnings("resource") @SuppressWarnings("resource")
public static String fileReaderAndendline(String path) { public static String fileReaderAndendline(String path) {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
String tempString = ""; String tempString = "";
try { try {
File file = new File(path); File file = new File(path);
if (!file.exists()) if (!file.exists())
return ""; return "";
FileInputStream fis = new FileInputStream(file); FileInputStream fis = new FileInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(fis)); BufferedReader br = new BufferedReader(new InputStreamReader(fis));
while ((tempString = br.readLine()) != null) { while ((tempString = br.readLine()) != null) {
@ -83,4 +89,7 @@ public class FileOperateHelper {
} }
return sb.toString(); return sb.toString();
} }
} }

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

@ -0,0 +1,31 @@
/**
* : Support.java
* : </>
* : <>
* @author liliy
* : <>
* 2016912
* <>
*/
package com.platform.utils;
import java.util.regex.Pattern;
/**
* <>
* <>
* @author liliy
* @version [2016912]
* @see [/]
* @since [/]
*/
public class Support {
public static boolean checkIP(String str) {
Pattern pattern = Pattern
.compile("^((\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5]"
+ "|[*])\\.){3}(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5]|[*])$");
return pattern.matcher(str).matches();
}
}

@ -59,7 +59,7 @@ public class ThreadVolume extends Thread implements Runnable{
if (null != path && path.size() > 0) { if (null != path && path.size() > 0) {
volume.setPath(path.get(0)); volume.setPath(path.get(0));
} }
volume.setAllSize(volumeInfo.getVolumeAllSize(volumeName)); volume.setAllSize(volumeInfo.getVolumeAvailableSize(volumeName));
volume.setUsedSize(volumeInfo.getVolumeUseSize(volumeName)); volume.setUsedSize(volumeInfo.getVolumeUseSize(volumeName));
//TODO 查询brick-- //TODO 查询brick--
//返回 ip:path //返回 ip:path

@ -1,48 +1,50 @@
package com.platform.utils;
package com.platform.utils;
import java.util.List;
import java.util.List;
import com.platform.entities.FolderNode;
import com.platform.entities.FolderNode;
public class getTreeDataByPath {
public class getTreeDataByPath {
/**
* @param path /**
* @return * @param path
*/ * @return
public FolderNode findByPath(String path) { */
List<FolderNode> folderNodelist = CacheTreeData.getFolders(); public FolderNode findByPath(String path) {
if (null == folderNodelist) { List<FolderNode> folderNodelist = CacheTreeData.getFolders();
return null; if (null == folderNodelist) {
} return null;
FolderNode folder = null; }
for (FolderNode folderNode : folderNodelist) { FolderNode folder = null;
folder = getFolder(folderNode, path); for (FolderNode folderNode : folderNodelist) {
if (null != folder) { folder = getFolder(folderNode, path);
break; if (null != folder) {
} break;
} }
return folder; }
} return folder;
}
/**
* @param f /**
* @return * @param f
*/ * @return
private FolderNode getFolder(FolderNode f, String path){ */
FolderNode result = null; private FolderNode getFolder(FolderNode f, String path){
if(path.equals(f.getPath())){ FolderNode result = null;
return f; if(path.equals(f.getPath())){
} return f;
List<FolderNode> folds = f.getChildNodes(); }
if (null != folds) { List<FolderNode> folds = f.getChildNodes();
for (FolderNode folderNode : folds) { if (null != folds) {
result = getFolder(folderNode, path); for (FolderNode folderNode : folds) {
if (null != result) { result = getFolder(folderNode, path);
break; if (null != result) {
} break;
} }
} }
return result; }
} return result;
} }
}

@ -35,8 +35,8 @@ public class TestController {
@ResponseBody @ResponseBody
public List<User> getJson(HttpServletRequest res, HttpServletResponse req) { public List<User> getJson(HttpServletRequest res, HttpServletResponse req) {
List<User> list = new ArrayList<User>(); List<User> list = new ArrayList<User>();
list.add(new User("lisi", 1, "ÄÐ")); list.add(new User("lisi", 1, ""));
list.add(new User("zhansan", 2, "ÄÐ")); list.add(new User("zhansan", 2, ""));
return list; return list;
} }

@ -32,26 +32,26 @@ public class TestEncodeInfoDao extends SMBasedTest {
@Test @Test
public void testGetEncodeNameByCode() { public void testGetEncodeNameByCode() {
String result = eiDao.getEncodeNameByCode("1", testTableName); String result = eiDao.getEncodeNameByCode("1", testTableName);
Assert.assertTrue(result.equals("预算执行系统")); Assert.assertTrue(result.equals("预算执行系统"));
} }
@Test @Test
public void testGetEncodeCodeByName() { public void testGetEncodeCodeByName() {
List<String> result = eiDao List<String> result = eiDao
.getEncodeCodeByName("预算执行系统", testTableName); .getEncodeCodeByName("预算执行系统", testTableName);
Assert.assertTrue(result.size() > 0); Assert.assertTrue(result.size() > 0);
} }
@Test @Test
public void testUpdateEncodeNameByCode() { public void testUpdateEncodeNameByCode() {
int result = eiDao int result = eiDao
.updateEncodeNameByCode("3", "财政一体化平台", testTableName); .updateEncodeNameByCode("3", "财政一体化平台", testTableName);
Assert.assertTrue(result > 0); Assert.assertTrue(result > 0);
} }
@Test @Test
public void testInsertEncodeEntity() { public void testInsertEncodeEntity() {
int result = eiDao.insertEncodeEntity(new EncodedInfoEntity("非税收入系统", int result = eiDao.insertEncodeEntity(new EncodedInfoEntity("非税收入系统",
"4"), testTableName); "4"), testTableName);
Assert.assertTrue(result == 1); Assert.assertTrue(result == 1);
} }

@ -24,11 +24,11 @@ public class TestEncodeService extends SMBasedTest {
@Test @Test
public void testGetEncodeNameByCode() { public void testGetEncodeNameByCode() {
String result = eis.getEncodeNameByCode("2", testTableName); String result = eis.getEncodeNameByCode("2", testTableName);
Assert.assertTrue(result.equals("²¿ÃÅÔ¤Ëã")); Assert.assertTrue(result.equals("部门预算"));
} }
/** /**
* ÊÂÎñ²âÊÔ *
*/ */
@Test @Test
public void testDeleteEncodeByCode() { public void testDeleteEncodeByCode() {

Loading…
Cancel
Save