glusterfs-api
lily 10 years ago
parent b28af5fa13
commit 4daefb6d79

1
.gitignore vendored

@ -2,3 +2,4 @@
/build
.classpath
/bin/

@ -17,10 +17,7 @@ import org.apache.log4j.PropertyConfigurator;
import com.platform.utils.Constant;
/**
*
* nullmapipip
* ipPeerinCluster(Connected)
* ipPeerinCluster(Disconnected)
*
* @author liliy
* @version [2016912]
* @see [/]
@ -29,6 +26,14 @@ import com.platform.utils.Constant;
public class ClusterInfo {
public static Logger log = Logger.getLogger(ClusterInfo.class);
/**
*
* nullmapipip
* ipPeerinCluster(Connected)
* ipPeerinCluster(Disconnected)
* @return
* @see [##]
*/
public Map<String, String> showClusterInfo() {
log.info("get cluster info");
Map<String, String> peerIps = new HashMap<String, String>();
@ -98,8 +103,12 @@ public class ClusterInfo {
if(peerIps==null || peerIps.size()==0){
return null;
}
if(peerip.equals(Constant.hostIp)){
return Constant.peerincluster_connected;
}
if(!peerIps.containsKey(peerip)){
return Constant.peerincluster_disconnected;
return Constant.peerNotinCluster;
}
return peerIps.get(peerip);
}
@ -108,6 +117,7 @@ public class ClusterInfo {
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"));
}
}

@ -55,7 +55,7 @@ public class CopyData {
return -3;
}
reStrings=showData.showFolderData(sourceFolderName+"/"+fileName);
reStrings=showData.showFolderData(sourceFolderName+"/"+fileName);
if(reStrings==null){
log.info("3202 "+sourceFolderName+"/"+fileName+" is not exists");
return -2;
@ -71,11 +71,27 @@ public class CopyData {
log.info("copy " + sourceFolderName +"/" + fileName+ " to " + destFolderName + " running");
return 1;
}
@Test
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;
}
@Test
public void testcreateFolders() {
createFolders("/aaa/vvv/ddd/www/rrrr");
}
//@Test
public void testCopyFolderFiles() {
PropertyConfigurator.configure("log4j.properties");
copyFolderFiles("/home", "/home/ubuntu", "system_data");
}
}

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

@ -132,9 +132,16 @@ public class SetVolume {
return 1;
}
/*
/**
* volumebrick, 1 ;
* volumebrickcount
* <>
* @param volumeName
* @param brickName
* @param count
* @param type
* @return
* @see [##]
*/
public int addBrickVolume(String volumeName, List<String> brickName, int count, String type) {
// 检查是否满足添加bricks的条件
@ -169,9 +176,16 @@ public class SetVolume {
}
}
/*
/**
* volumebrick, 1 ;
* volumebrickcount
* @param volumeName
* @param brickName
* @param count
* @param type
* @return
* @see [##]
*/
public int deleteBrickVolume(String volumeName, List<String> brickName, int count, String type) {
int able = isAble(volumeName, count, type, brickName);
@ -189,7 +203,7 @@ public class SetVolume {
command = "echo -e \"y\" | gluster volume remove-brick " + volumeName + " " + brick + " force";
} else if (type.equals(Constant.replica)) {
command = "echo -e \"y\" | gluster volume remove-brick " + volumeName + " repli " + count + " " + brick
+ " force";
+ " force";
} else if (type.equals(Constant.stripe)) {
command = "echo -e \"y\" | gluster volume remove-brick " + volumeName + " stripe " + count + " " + brick
+ " force";
@ -453,14 +467,14 @@ public class SetVolume {
public static void main(String[] args) {
SetVolume setVolume = new SetVolume();
int operation = 0;
PropertyConfigurator.configure("log4j.properties");
// PropertyConfigurator.configure("log4j.properties");
// TODO Auto-generated method stub
// 测试创建volume的代码
List<String> bricksToCreate = new ArrayList<String>();
bricksToCreate.add("192.168.0.110:/v1");
bricksToCreate.add("192.168.0.116:/v1");
operation = setVolume.createVolume("v1", 0, "distributed", bricksToCreate, "/home/v1_point");
bricksToCreate.add("192.168.0.110:/v2");
bricksToCreate.add("192.168.0.116:/v2");
operation = setVolume.createVolume("v2", 0, "distributed", bricksToCreate, "/home/v2_point");
// operation = setVolume.deleteVolume("v3");
//
// // 以下是测试添加brick的代码

File diff suppressed because it is too large Load Diff

@ -14,6 +14,7 @@ public class Constant {
public static String df = "df -k ";
public static String peerincluster_connected = "PeerinCluster(Connected)";
public static String peerincluster_disconnected = "PeerinCluster(Disconnected)";
public static String peerNotinCluster = "PeerNotinCluster";
public static String distributed = "distributed";
public static String replica = "replica";
public static String stripe = "stripe";

Loading…
Cancel
Save