parent
edceebeb58
commit
e2e392e319
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
|
||||
<persistence-unit name="aggregation-platform">
|
||||
</persistence-unit>
|
||||
</persistence>
|
@ -1,5 +1,39 @@
|
||||
package com.platform.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.platform.entities.GatherOracleInfo;
|
||||
|
||||
@Repository(value = "gatherOracleDao")
|
||||
public interface GatherOracleDao {
|
||||
|
||||
/**
|
||||
* @return 查询所有的oracle记录
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
public List<GatherOracleInfo> selectAllOracle() throws Exception;
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public int deleteOracleById(int id) throws Exception;
|
||||
|
||||
/**
|
||||
* @param oracle
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public int insertOracle(GatherOracleInfo oracle) throws Exception;
|
||||
|
||||
/**
|
||||
* @param oracle
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public int updateOracleById(GatherOracleInfo oracle) throws Exception;
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,86 @@
|
||||
package com.platform.glusterfs;
|
||||
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.PropertyConfigurator;
|
||||
|
||||
import com.platform.utils.Constant;
|
||||
|
||||
public class ClusterInfo {
|
||||
public static Logger log = Logger.getLogger(ClusterInfo.class);
|
||||
|
||||
public Map<String, String> showClusterInfo() {
|
||||
log.info("get cluster info");
|
||||
Map<String, String> peerIps = new HashMap<String, String>();
|
||||
|
||||
/*
|
||||
String command = "echo \"" + Constant.rootPasswd + "\"|sudo -S gluster peer status";
|
||||
RunCommand runCommand = new RunCommand();
|
||||
List<String> reStrings = runCommand.runCommandWait(command);
|
||||
*/
|
||||
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, Constant.port, Constant.glusterPeerStatus);
|
||||
if (reStrings == null) {
|
||||
log.error("1101 command get result is null");
|
||||
return null;
|
||||
}
|
||||
if (reStrings.size() == 0) {
|
||||
log.error("1102 command get result is nothing");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!(reStrings.get(0).split(":")[0].contains("Number of Peers"))) {
|
||||
|
||||
log.error("1103 get result string wrong");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// System.out.print(reStrings.get(0));
|
||||
|
||||
int flag = 0;
|
||||
String ipString = "";
|
||||
String state = "";
|
||||
for (Iterator it2 = reStrings.iterator(); it2.hasNext();) {
|
||||
String line = (String) it2.next();
|
||||
line=line.replaceAll(" +", " ");
|
||||
String keyValue[] = line.split(":");
|
||||
if (keyValue[0].equals("Hostname")) {
|
||||
|
||||
if (keyValue.length < 2) {
|
||||
log.error("1105 command get result is wrong");
|
||||
continue;
|
||||
}
|
||||
|
||||
ipString = keyValue[1].replaceAll(" ", "");
|
||||
flag = 1;
|
||||
} else if (flag == 1 && keyValue[0].equals("State")) {
|
||||
|
||||
if (keyValue.length < 2) {
|
||||
log.error("1106 command get result is wrong");
|
||||
continue;
|
||||
}
|
||||
|
||||
state = keyValue[1].replaceAll(" ", "");
|
||||
flag = 0;
|
||||
peerIps.put(ipString, state);
|
||||
}
|
||||
|
||||
}
|
||||
return peerIps;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
PropertyConfigurator.configure("log4j.properties");
|
||||
System.out.println(new ClusterInfo().showClusterInfo());
|
||||
}
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
package com.platform.glusterfs;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.PropertyConfigurator;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.platform.utils.Constant;
|
||||
|
||||
|
||||
|
||||
public class RemoveData {
|
||||
|
||||
public static Logger log = Logger.getLogger ( RemoveData.class);
|
||||
public int deleteVolumeFiles(String volumeName,String fileName){
|
||||
log.info("start delete "+volumeName+" "+fileName);
|
||||
int status=-1;
|
||||
/**
|
||||
* get mount point of volumeName
|
||||
*/
|
||||
String folderName=volumeName;
|
||||
|
||||
status=deleteFolderFiles(folderName,fileName);
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* -1 :error; 0: the filename is not exists ; 1: right
|
||||
* @param folderName
|
||||
* @param fileName
|
||||
* @return
|
||||
*/
|
||||
public int deleteFolderFiles(String folderName,String fileName){
|
||||
log.info("start delete "+folderName+"/"+fileName);
|
||||
|
||||
ShowData showData=new ShowData();
|
||||
Map<String,String> reStrings=showData.showFolderData(folderName+"/"+fileName);
|
||||
|
||||
if(reStrings==null){
|
||||
log.error("3301 "+folderName+"/"+fileName+" is not exists");
|
||||
return -1;
|
||||
}
|
||||
|
||||
String command="rm -r "+folderName+"/"+fileName;
|
||||
|
||||
// int status=runCommand.runCommand(command);
|
||||
Constant.ganymedSSH.execCmdNoWaitAcquiescent(command);
|
||||
|
||||
log.info("delete "+folderName+" "+fileName+" running");
|
||||
return 1;
|
||||
}
|
||||
|
||||
public int getFolderSize(String name) {
|
||||
log.info("get "+name+" size");
|
||||
String command="du -k -d 0 "+name;
|
||||
/*
|
||||
* RunCommand runCommand=new RunCommand();
|
||||
|
||||
List<String> reStrings=runCommand.runCommandWait(command);
|
||||
*/
|
||||
List<String> reStrings=Constant.ganymedSSH.execCmdWaitAcquiescent(command);
|
||||
|
||||
if(reStrings==null){
|
||||
log.error("3302 the "+command+" return error");
|
||||
return -1;
|
||||
}
|
||||
if(reStrings.size()<1){
|
||||
log.error("3303 the "+command+" return error");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(reStrings.size()==1 && reStrings.get(0).contains("No such file or directory")){
|
||||
log.info("3304 "+name+" is not exists");
|
||||
return 0;
|
||||
}
|
||||
String strSize=(reStrings.get(0).split("\t"))[0];
|
||||
int size=Integer.parseInt(strSize);
|
||||
log.info(name +" size is "+size);
|
||||
return size;
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void test_getFolderSize() {
|
||||
PropertyConfigurator.configure("log4j.properties");
|
||||
getFolderSize("/home/ubuntu");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteFolderFiles() {
|
||||
PropertyConfigurator.configure("log4j.properties");
|
||||
deleteFolderFiles("/home/ubuntu","system_data");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.platform.glusterfs;
|
||||
|
||||
public class SetCluster {
|
||||
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
package com.platform.glusterfs;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
||||
import org.apache.log4j.PropertyConfigurator;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.platform.utils.Constant;
|
||||
|
||||
|
||||
public class ShowData {
|
||||
|
||||
public static Logger log = Logger.getLogger ( ShowData.class);
|
||||
/**
|
||||
* get the data of volumeName Map<string s1,string s2> s1 is data name and s2 is type file or folder
|
||||
* @param volumeName
|
||||
* @return
|
||||
*/
|
||||
|
||||
|
||||
public Map<String,String> showVolumeFiles(String volumeName){
|
||||
log.info("start show the data");
|
||||
Map<String,String> data_type=new HashMap<String, String>();
|
||||
/**
|
||||
* get mount point of volumeName
|
||||
*/
|
||||
String folderName=volumeName;
|
||||
|
||||
data_type=showFolderData(volumeName);
|
||||
return data_type;
|
||||
}
|
||||
/**
|
||||
* get the data of folder name
|
||||
* Map<String,String> is folder name and type 1 is file and others is folder
|
||||
|
||||
|
||||
* @param FolderName
|
||||
* @return
|
||||
*/
|
||||
public Map<String,String> showFolderData(String folderName){
|
||||
log.info(" start get "+folderName+" data");
|
||||
|
||||
|
||||
Map<String,String> data_type=new HashMap<String, String>();
|
||||
String command="ls -l "+folderName;
|
||||
|
||||
/*
|
||||
RunCommand runCommand=new RunCommand();
|
||||
List<String> reStrings=runCommand.runCommandWait(command);
|
||||
*/
|
||||
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, Constant.port, command);
|
||||
if(reStrings==null){
|
||||
log.error("2101 command get result is null");
|
||||
return null;
|
||||
}
|
||||
if(reStrings.size()==0){
|
||||
log.info("2102 the folder is empty");
|
||||
return data_type;
|
||||
}
|
||||
if(reStrings.get(0).contains("No such file or directory")){
|
||||
log.info("2103 the "+folderName+" is not exists");
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* remove first line total number
|
||||
*/
|
||||
reStrings.remove(0);
|
||||
|
||||
for(Iterator it2 = reStrings.iterator();it2.hasNext();){
|
||||
String line=(String)it2.next();
|
||||
line=line.replaceAll(" +", " ");
|
||||
String keyValue[]=line.split(" ");
|
||||
if(keyValue.length<9){
|
||||
log.error("2104 "+line+" length is short");
|
||||
continue;
|
||||
}
|
||||
|
||||
data_type.put(keyValue[8], keyValue[1]);
|
||||
|
||||
}
|
||||
log.info(" get "+folderName+" data successed");
|
||||
return data_type;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* <一句话功能简述>
|
||||
* <功能详细描述>
|
||||
* @see [类、类#方法、类#成员]
|
||||
*/
|
||||
@Test
|
||||
public void testShowData(){
|
||||
|
||||
System.out.println(showFolderData("/home"));
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,271 @@
|
||||
package com.platform.glusterfs;
|
||||
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.PropertyConfigurator;
|
||||
|
||||
import com.platform.utils.Constant;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class VolumeInfo {
|
||||
public static Logger log = Logger.getLogger(VolumeInfo.class);
|
||||
|
||||
public List<String> showAllVolumeName() {
|
||||
log.info("get volume name");
|
||||
List<String> volNames = new ArrayList<String>();
|
||||
|
||||
/*
|
||||
* String command = "echo \"" + Constant.rootPasswd +
|
||||
* "\" |sudo -S gluster volume info|grep ^Volume.Name"; RunCommand
|
||||
* runCommand = new RunCommand(); List<String> reStrings =
|
||||
* runCommand.runCommandWait(command);
|
||||
*/
|
||||
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd,
|
||||
Constant.port, Constant.glusterVolumeInfo + "|grep ^Volume.Name");
|
||||
// System.out.println(reStrings);
|
||||
if(reStrings==null){
|
||||
log.error("1401 get result is null");
|
||||
return null;
|
||||
}
|
||||
if(reStrings.size()==0){
|
||||
log.error("1402 get result is nothing");
|
||||
return null;
|
||||
}
|
||||
if(reStrings.get(0).contains(Constant.noVolume)){
|
||||
reStrings.clear();
|
||||
return reStrings;
|
||||
}
|
||||
if (!(reStrings.get(0).split(":")[0].contains("Volume Name"))) {
|
||||
log.error("1403 get result string wrong");
|
||||
return null;
|
||||
}
|
||||
|
||||
String nameInfo = "";
|
||||
for (Iterator it = reStrings.iterator(); it.hasNext();) {
|
||||
String line = (String) it.next();
|
||||
String str[] = line.split(":");
|
||||
volNames.add(str[1].replaceAll(" ", ""));
|
||||
}
|
||||
return volNames;
|
||||
|
||||
}
|
||||
|
||||
public String getVolumeType(String volumeName) {
|
||||
log.info("get volume type");
|
||||
String volType = "";
|
||||
|
||||
/*
|
||||
* =======
|
||||
*
|
||||
* >>>>>>> origin/AlexKie String command = "echo \"" +
|
||||
* Constant.rootPasswd + "\" |sudo -S gluster volume info " +
|
||||
* volumeName + "|grep ^Type"; RunCommand runCommand = new RunCommand();
|
||||
* List<String> reStrings = runCommand.runCommandWait(command); <<<<<<<
|
||||
* HEAD
|
||||
*/
|
||||
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd,
|
||||
Constant.port, Constant.glusterVolumeInfo + volumeName + "|grep ^Type");
|
||||
// System.out.println(reStrings);
|
||||
if(reStrings==null){
|
||||
log.error("1501 get result is null");
|
||||
return null;
|
||||
}
|
||||
if(reStrings.size()==0){
|
||||
log.error("1502 get result is nothing");
|
||||
return null;
|
||||
}
|
||||
if (!(reStrings.get(0).split(":")[0].contains("Type"))) {
|
||||
log.error("1503 get result string wrong");
|
||||
return null;
|
||||
}
|
||||
|
||||
// System.out.println(reStrings);
|
||||
|
||||
for (Iterator it = reStrings.iterator(); it.hasNext();) {
|
||||
String line = (String) it.next();
|
||||
String str[] = line.split(":");
|
||||
volType = str[1];
|
||||
}
|
||||
volType=volType.replaceAll(" ", "");
|
||||
return volType;
|
||||
}
|
||||
|
||||
public String getVolumeStatus(String volumeName) {
|
||||
log.info("get volume status");
|
||||
String volStatus = "";
|
||||
|
||||
/*
|
||||
* =======
|
||||
*
|
||||
* >>>>>>> origin/AlexKie String command = "echo \"" +
|
||||
* Constant.rootPasswd + "\" |sudo -S gluster volume info " +
|
||||
* volumeName + "|grep ^Status"; RunCommand runCommand = new
|
||||
* RunCommand(); List<String> reStrings =
|
||||
* runCommand.runCommandWait(command); <<<<<<< HEAD
|
||||
*/
|
||||
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd,
|
||||
Constant.port, Constant.glusterVolumeInfo + "|grep ^Status");
|
||||
// System.out.println(reStrings);
|
||||
if(reStrings==null){
|
||||
log.error("1701 get result is null");
|
||||
return null;
|
||||
}
|
||||
if(reStrings.size()==0){
|
||||
log.error("1702 get result is nothing");
|
||||
return null;
|
||||
}
|
||||
if (!(reStrings.get(0).split(":")[0].contains("Status"))) {
|
||||
log.error("1703 get result string wrong");
|
||||
return null;
|
||||
}
|
||||
|
||||
for (Iterator it = reStrings.iterator(); it.hasNext();) {
|
||||
String line = (String) it.next();
|
||||
String str[] = line.split(":");
|
||||
volStatus = str[1].replaceAll(" ", "");
|
||||
}
|
||||
|
||||
return volStatus;
|
||||
}
|
||||
|
||||
public Double getVolumeAllSize(String volumeName) {
|
||||
log.info("get volume allSize");
|
||||
Double allSize = null;
|
||||
/*
|
||||
* ======= // waiting for testing... public Double
|
||||
* getVolumeAllSize(String volumeName) { log.info("get volume allSize");
|
||||
* Double allSize = null;
|
||||
*
|
||||
* >>>>>>> origin/AlexKie String command = "echo \"" +
|
||||
* Constant.rootPasswd + "\" |sudo -S df -h|grep " + volumeName +
|
||||
* "|awk '{print $2}'"; RunCommand runCommand = new RunCommand();
|
||||
* List<String> reStrings = runCommand.runCommandWait(command); <<<<<<<
|
||||
* HEAD
|
||||
*/
|
||||
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd,
|
||||
Constant.port, Constant.df + "|grep " + volumeName + "|awk '{print $2}'");
|
||||
// System.out.println(reStrings);
|
||||
if(reStrings==null){
|
||||
log.error("1801 get result is null");
|
||||
return null;
|
||||
}
|
||||
if(reStrings.size()==0){
|
||||
log.error("1802 get result is nothing");
|
||||
return null;
|
||||
}
|
||||
char flag = reStrings.get(0).trim().toCharArray()[0];
|
||||
if (flag < 48 || flag > 57) {
|
||||
log.error("1803 get result string wrong");
|
||||
return null;
|
||||
}
|
||||
|
||||
for (Iterator it = reStrings.iterator(); it.hasNext();) {
|
||||
String line = (String) it.next();
|
||||
String str[] = line.split("[^0-9]");
|
||||
allSize = Double.parseDouble(str[0]);
|
||||
}
|
||||
|
||||
return allSize;
|
||||
}
|
||||
|
||||
public Double getVolumeUseSize(String volumeName) {
|
||||
log.info("get volume used size");
|
||||
Double usedSize = null;
|
||||
|
||||
/*
|
||||
* =======
|
||||
*
|
||||
* >>>>>>> origin/AlexKie String command = "echo \"" +
|
||||
* Constant.rootPasswd + "\" |sudo -S df -h|grep " + volumeName +
|
||||
* "|awk '{print $3}'"; RunCommand runCommand = new RunCommand();
|
||||
* List<String> reStrings = runCommand.runCommandWait(command); <<<<<<<
|
||||
* HEAD
|
||||
*/
|
||||
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd,
|
||||
Constant.port, Constant.df + "|grep " + volumeName + "|awk '{print $3}'");
|
||||
// System.out.println(reStrings);
|
||||
if(reStrings==null){
|
||||
log.error("1901 get result is null");
|
||||
return null;
|
||||
}
|
||||
if(reStrings.size()==0){
|
||||
log.error("1902 get result is nothing");
|
||||
return null;
|
||||
}
|
||||
char flag = reStrings.get(0).trim().toCharArray()[0];
|
||||
if (flag < 48 || flag > 57) {
|
||||
log.error("1903 get result string wrong");
|
||||
return null;
|
||||
}
|
||||
|
||||
for (Iterator it = reStrings.iterator(); it.hasNext();) {
|
||||
String line = (String) it.next();
|
||||
String str[] = line.split("[^0-9]");
|
||||
|
||||
usedSize = Double.parseDouble(str[0]);
|
||||
}
|
||||
|
||||
return usedSize;
|
||||
}
|
||||
|
||||
public String getVolumeMountPoint(String volumeName) {
|
||||
log.info("get volume mountPoint");
|
||||
// String mountPoint = "";
|
||||
|
||||
/*
|
||||
* =======
|
||||
*
|
||||
* >>>>>>> origin/AlexKie String command = "echo \"" +
|
||||
* Constant.rootPasswd + "\" |sudo -S df -h|grep " + volumeName +
|
||||
* "|awk '{print $6}'"; RunCommand runCommand = new RunCommand();
|
||||
* List<String> reStrings = runCommand.runCommandWait(command); <<<<<<<
|
||||
* HEAD
|
||||
*/
|
||||
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd,
|
||||
Constant.port, Constant.df + "|grep " + volumeName + "|awk '{print $6}'");
|
||||
// System.out.println(reStrings);
|
||||
if(reStrings==null){
|
||||
log.error("11001 get result string wrong");
|
||||
return null;
|
||||
}
|
||||
if(reStrings.size()==0){
|
||||
log.error("11002 "+volumeName+" is no mountpoint");
|
||||
return null;
|
||||
}
|
||||
|
||||
char flag = reStrings.get(0).trim().toCharArray()[0];
|
||||
if (flag != '/') {
|
||||
log.error("11003 get result string wrong");
|
||||
return null;
|
||||
}
|
||||
|
||||
Iterator it = reStrings.iterator();
|
||||
String mountPoint = (String) it.next();
|
||||
mountPoint=mountPoint.replaceAll(" ", "");
|
||||
return mountPoint;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
PropertyConfigurator.configure("log4j.properties");
|
||||
|
||||
System.out.println(new VolumeInfo().showAllVolumeName());
|
||||
System.out.println(new VolumeInfo().getVolumeType("v1"));
|
||||
|
||||
System.out.println(new VolumeInfo().getVolumeStatus("v1"));
|
||||
System.out.println(new VolumeInfo().getVolumeMountPoint("v1"));
|
||||
|
||||
System.out.println(new VolumeInfo().getVolumeAllSize("v1"));
|
||||
System.out.println(new VolumeInfo().getVolumeUseSize("v1"));
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.platform.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.platform.entities.GatherOracleInfo;
|
||||
|
||||
public interface IMySqlService {
|
||||
|
||||
/**
|
||||
* @return 查询
|
||||
* @throws Exception
|
||||
*/
|
||||
public List<GatherOracleInfo> findAllMySql() throws Exception;
|
||||
|
||||
/** 删除
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public int deleteMySql(int id) throws Exception;
|
||||
|
||||
public int insertOracle(GatherOracleInfo oracle) throws Exception;
|
||||
|
||||
public int updateOracle(GatherOracleInfo oracle) throws Exception;
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.platform.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface IOracleExtractService {
|
||||
|
||||
/** 抽取数据库
|
||||
* @param name
|
||||
* @param dataInfo //采集库连接参数
|
||||
* @param oracleConnect
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public boolean extractOracle(String name, List<Map<String, String>> dataInfo, Map<String, String> oracleConnect) throws Exception;
|
||||
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package com.platform.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.platform.dao.GatherOracleDao;
|
||||
import com.platform.entities.GatherOracleInfo;
|
||||
import com.platform.service.IMySqlService;
|
||||
|
||||
@Service(value = "mySqlService")
|
||||
public class MySqlServiceImpl implements IMySqlService{
|
||||
|
||||
@Resource(name = "gatherOracleDao")
|
||||
private GatherOracleDao gatherOracleDao;
|
||||
|
||||
@Override
|
||||
public List<GatherOracleInfo> findAllMySql() throws Exception {
|
||||
List<GatherOracleInfo> result = gatherOracleDao.selectAllOracle();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteMySql(int id) throws Exception {
|
||||
|
||||
int result = 0;
|
||||
if (id > 0) {
|
||||
// result = gatherOracleDao.deleteOracleById(id);
|
||||
GatherOracleInfo oracle = new GatherOracleInfo();
|
||||
oracle.setId(id);
|
||||
oracle.setRemove("1");
|
||||
result = gatherOracleDao.updateOracleById(oracle );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int insertOracle(GatherOracleInfo oracle) throws Exception {
|
||||
int result = gatherOracleDao.insertOracle(oracle);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateOracle(GatherOracleInfo oracle) throws Exception {
|
||||
int result;
|
||||
if (oracle.getId() > 0) {
|
||||
result = gatherOracleDao.updateOracleById(oracle);
|
||||
}
|
||||
else {
|
||||
result = gatherOracleDao.insertOracle(oracle);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package com.platform.service.impl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.platform.entities.DataInfoEntity;
|
||||
import com.platform.entities.GatherOracleInfo;
|
||||
import com.platform.entities.OracleConnectorParams;
|
||||
import com.platform.oracle.OracleConnector;
|
||||
import com.platform.service.IOracleExtractService;
|
||||
import com.platform.service.OracleExtractHelper;
|
||||
import com.platform.utils.Bean2MapUtils;
|
||||
|
||||
@Service(value = "OracleExtract")
|
||||
public class OracleExtractServiceImpl implements IOracleExtractService {
|
||||
|
||||
/**
|
||||
* 抽取
|
||||
*/
|
||||
private OracleExtractHelper oracleExtract = new OracleExtractHelper();
|
||||
|
||||
/**
|
||||
* 数据库连接实现类
|
||||
*/
|
||||
private OracleConnector connect = new OracleConnector();
|
||||
|
||||
@Override
|
||||
public boolean extractOracle(String name, List<Map<String, String>> dataInfoMap,
|
||||
Map<String, String> oracleConnect) throws Exception {
|
||||
boolean isSuccess = false;
|
||||
try{
|
||||
//map转 bean(汇总库信息-带tableName的)
|
||||
GatherOracleInfo oracleModel = (GatherOracleInfo) Bean2MapUtils.convertMap(GatherOracleInfo.class, oracleConnect);
|
||||
|
||||
//采集库连接参数
|
||||
List<OracleConnectorParams> datainfos = new ArrayList<OracleConnectorParams>();
|
||||
for (Map<String, String> map : dataInfoMap) {
|
||||
OracleConnectorParams dataInfoEntity = (OracleConnectorParams) Bean2MapUtils.convertMap(OracleConnectorParams.class, oracleConnect);
|
||||
datainfos.add(dataInfoEntity);
|
||||
}
|
||||
|
||||
Connection conn = OracleConnector.ConnectionBuilder("jdbc:oracle:thin:@" + oracleModel.getIp() + ":" + oracleModel.getPort() + "/"
|
||||
+ oracleModel.getDatabaseName(), oracleModel.getUser(), oracleModel.getPassword());
|
||||
|
||||
for (OracleConnectorParams collectOracle : datainfos) {
|
||||
|
||||
oracleExtract.createDBLink(conn, collectOracle);
|
||||
oracleExtract.createTableSpace(conn, oracleModel);
|
||||
oracleExtract.createUser(conn, oracleModel);
|
||||
oracleExtract.extractColleDB(conn, collectOracle);
|
||||
}
|
||||
isSuccess = true;
|
||||
}catch(Exception e){
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package com.platform.utils;
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Bean2MapUtils {
|
||||
|
||||
/**
|
||||
* 将一个 Map 对象转化为一个 JavaBean
|
||||
* @param type 要转化的类型
|
||||
* @param map 包含属性值的 map
|
||||
* @return 转化出来的 JavaBean 对象
|
||||
* @throws IntrospectionException
|
||||
* 如果分析类属性失败
|
||||
* @throws IllegalAccessException
|
||||
* 如果实例化 JavaBean 失败
|
||||
* @throws InstantiationException
|
||||
* 如果实例化 JavaBean 失败
|
||||
* @throws InvocationTargetException
|
||||
* 如果调用属性的 setter 方法失败
|
||||
*/
|
||||
public static Object convertMap(Class type, Map map)
|
||||
throws IntrospectionException, IllegalAccessException,
|
||||
InstantiationException, InvocationTargetException {
|
||||
BeanInfo beanInfo = Introspector.getBeanInfo(type); // 获取类属性
|
||||
Object obj = type.newInstance(); // 创建 JavaBean 对象
|
||||
|
||||
// 给 JavaBean 对象的属性赋值
|
||||
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
|
||||
for (int i = 0; i< propertyDescriptors.length; i++) {
|
||||
PropertyDescriptor descriptor = propertyDescriptors[i];
|
||||
String propertyName = descriptor.getName();
|
||||
try{
|
||||
if (map.containsKey(propertyName)) {
|
||||
// 下面一句可以 try 起来,这样当一个属性赋值失败的时候就不会影响其他属性赋值。
|
||||
Object value = map.get(propertyName);
|
||||
|
||||
Object[] args = new Object[1];
|
||||
args[0] = value;
|
||||
|
||||
descriptor.getWriteMethod().invoke(obj, args);
|
||||
}
|
||||
}
|
||||
catch(Exception e){
|
||||
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将一个 JavaBean 对象转化为一个 Map
|
||||
* @param bean 要转化的JavaBean 对象
|
||||
* @return 转化出来的 Map 对象
|
||||
* @throws IntrospectionException 如果分析类属性失败
|
||||
* @throws IllegalAccessException 如果实例化 JavaBean 失败
|
||||
* @throws InvocationTargetException 如果调用属性的 setter 方法失败
|
||||
*/
|
||||
public static Map convertBean(Object bean)
|
||||
throws IntrospectionException, IllegalAccessException, InvocationTargetException {
|
||||
Class type = bean.getClass();
|
||||
Map returnMap = new HashMap();
|
||||
BeanInfo beanInfo = Introspector.getBeanInfo(type);
|
||||
|
||||
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
|
||||
for (int i = 0; i< propertyDescriptors.length; i++) {
|
||||
PropertyDescriptor descriptor = propertyDescriptors[i];
|
||||
String propertyName = descriptor.getName();
|
||||
if (!propertyName.equals("class")) {
|
||||
Method readMethod = descriptor.getReadMethod();
|
||||
Object result = readMethod.invoke(bean, new Object[0]);
|
||||
if (result != null) {
|
||||
returnMap.put(propertyName, result);
|
||||
} else {
|
||||
returnMap.put(propertyName, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnMap;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.platform.utils;
|
||||
|
||||
import com.platform.entities.FolderNode;
|
||||
|
||||
public class CacheTreeData {
|
||||
|
||||
private static FolderNode folders = null;
|
||||
|
||||
public static FolderNode getFolders() {
|
||||
return folders;
|
||||
}
|
||||
|
||||
public static void setFolders(FolderNode folders) {
|
||||
CacheTreeData.folders = folders;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.platform.utils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Constant {
|
||||
public static String rootUser = "root";
|
||||
public static String rootPasswd = "root";
|
||||
public static String hostIp = "192.168.0.116";
|
||||
public static int port = 22;
|
||||
public static String glusterPeerStatus = "gluster peer status";
|
||||
public static String glusterVolumeInfo = "gluster volume info ";
|
||||
public static String df = "df -k ";
|
||||
public static String peerincluster_connected="PeerinCluster(Connected)";
|
||||
public static String distributed="distributed";
|
||||
public static String replica="replica";
|
||||
public static String stripe="stripe";
|
||||
public static String noVolume="No volumes present";
|
||||
public static GanymedSSH ganymedSSH=new GanymedSSH(hostIp, rootUser, rootPasswd, port);
|
||||
|
||||
/**
|
||||
* volume 获取的线程休眠时间
|
||||
*/
|
||||
public final static int get_volume_sleep_time = 300000;
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package com.platform.utils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.apache.log4j.*;
|
||||
|
||||
public class RunCommand {
|
||||
|
||||
|
||||
public static Logger log = Logger.getLogger(RunCommand.class);
|
||||
|
||||
public List<String> runCommandWait(String command) {
|
||||
List<String> reStrings = null;
|
||||
String cmds[] = { "/bin/bash", "-c", command };
|
||||
try {
|
||||
Process ps = Runtime.getRuntime().exec(cmds);
|
||||
ps.waitFor();
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream()));
|
||||
reStrings = new ArrayList<String>();
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
reStrings.add(line);
|
||||
// System.out.println(line);
|
||||
}
|
||||
|
||||
br = new BufferedReader(new InputStreamReader(ps.getErrorStream()));
|
||||
reStrings = new ArrayList<String>();
|
||||
|
||||
while ((line = br.readLine()) != null) {
|
||||
reStrings.add(line);
|
||||
// System.out.println(line);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
log.error("0001 runCommandWait is error");
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
return reStrings;
|
||||
}
|
||||
|
||||
public int runCommand(String command) {
|
||||
List<String> reStrings = null;
|
||||
String cmds[] = { "/bin/bash", "-c", command };
|
||||
try {
|
||||
Process ps = Runtime.getRuntime().exec(cmds);
|
||||
} catch (Exception e) {
|
||||
|
||||
log.error("0002 runCommand execute " + command + " is error");
|
||||
|
||||
e.printStackTrace();
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.platform.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TestSupport {
|
||||
public List<String> strToList(String str) {
|
||||
List<String> reStrings=new ArrayList<String>();
|
||||
for(String one:str.split("\n")){
|
||||
reStrings.add(one);
|
||||
}
|
||||
return reStrings;
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.platform.utils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.platform.entities.FolderNode;
|
||||
import com.platform.glusterfs.GetTreeData;
|
||||
import com.platform.glusterfs.VolumeInfo;
|
||||
|
||||
public class VolumeThread extends Thread implements Runnable{
|
||||
|
||||
/**
|
||||
* 挂载点路径
|
||||
*/
|
||||
private static String pointPath = "/home";
|
||||
|
||||
public VolumeThread() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public VolumeThread(String path) {
|
||||
if (null != path && !"".equals(path.trim())) {
|
||||
VolumeThread.pointPath = path;
|
||||
}
|
||||
}
|
||||
|
||||
/** gfs目录树形展示 */
|
||||
private GetTreeData gfsTree = new GetTreeData();
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
super.run();
|
||||
while(true){
|
||||
FolderNode folders = gfsTree.getDatas(pointPath);
|
||||
//TODO
|
||||
CacheTreeData.setFolders(folders);
|
||||
try {
|
||||
Thread.sleep(Constant.get_volume_sleep_time);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static String getPointPath() {
|
||||
return pointPath;
|
||||
}
|
||||
|
||||
public static void setPointPath(String pointPath) {
|
||||
VolumeThread.pointPath = pointPath;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.platform.utils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.platform.entities.FolderNode;
|
||||
|
||||
public class getTreeDataByPath {
|
||||
|
||||
/**
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
public FolderNode findByPath(String path) {
|
||||
FolderNode folderNode = CacheTreeData.getFolders();
|
||||
if (null == folderNode) {
|
||||
return null;
|
||||
}
|
||||
FolderNode folder = getFolder(folderNode, path);
|
||||
return folder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param f
|
||||
* @return
|
||||
*/
|
||||
private FolderNode getFolder(FolderNode f, String path){
|
||||
FolderNode result = null;
|
||||
if(path.equals(f.getName())){
|
||||
return f;
|
||||
}
|
||||
List<FolderNode> folds = f.getChildNodes();
|
||||
if (null != folds) {
|
||||
for (FolderNode folderNode : folds) {
|
||||
result = getFolder(folderNode, path);
|
||||
if (null != result) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue