Merge branch 'web_backend_develope' of

https://git.trustie.net/fhx569287825/aggregation-platform into
web_backend_develope

Conflicts:
	src/com/platform/controller/DataModelController.java
	src/com/platform/oracle/OracleConnector.java
	src/com/platform/service/OracleExtractHelper.java
	src/com/platform/service/impl/OracleExtractServiceImpl.java
web_backend_develope
chenlw 9 years ago
commit 191aecd828

@ -4,7 +4,7 @@
# 驱动程序 # 驱动程序
jdbc.mysql.driver=com.mysql.jdbc.Driver jdbc.mysql.driver=com.mysql.jdbc.Driver
# 连接url # 连接url
jdbc.mysql.url=jdbc:mysql://192.168.0.110:3306/ftpdata?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true jdbc.mysql.url=jdbc:mysql://192.168.0.101:3306/test?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true
# 用户名 # 用户名
jdbc.mysql.username=root jdbc.mysql.username=root
# 密码 # 密码
@ -41,7 +41,7 @@ jdbc.minEvictableIdleTimeMillis=300000
# #
#============================================================================================================== #==============================================================================================================
table-suffix=_20152016 table-suffix=_20152016
extract-log-localtion=/home/log/ extract-log-localtion=D:\\log\\
gather-tablespace-name=TS_TTSSS gather-tablespace-name=TS_TTSSS
gather-tablespace-path=1 gather-tablespace-path=1
gather-table-user-password=1 gather-table-user-password=1

@ -113,7 +113,7 @@ public class DataModelController extends BaseController{
String[] oraclesName = paramMap.get("oracleName"); String[] oraclesName = paramMap.get("oracleName");
if (oraclesName != null) if (oraclesName != null)
for (String rcName : oraclesName) { for (String rcName : oraclesName) {
Configs.CONSOLE_LOGGER.info("连接成功\t" + rcName); Configs.CONSOLE_LOGGER.info("执行连接\t" + rcName);
new OracleStatusService().connectToOracle(rcName); new OracleStatusService().connectToOracle(rcName);
} }
req.setStatus(200); req.setStatus(200);

@ -4,6 +4,7 @@ import io.fabric8.kubernetes.api.model.Container;
import io.fabric8.kubernetes.api.model.ContainerPort; import io.fabric8.kubernetes.api.model.ContainerPort;
import io.fabric8.kubernetes.api.model.Pod; import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.api.model.ReplicationController; import io.fabric8.kubernetes.api.model.ReplicationController;
import io.fabric8.kubernetes.client.Client;
import io.fabric8.kubernetes.client.Config; import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.ConfigBuilder; import io.fabric8.kubernetes.client.ConfigBuilder;
import io.fabric8.kubernetes.client.DefaultKubernetesClient; import io.fabric8.kubernetes.client.DefaultKubernetesClient;
@ -32,18 +33,22 @@ public class SimpleKubeClient {
public SimpleKubeClient(Config config) { public SimpleKubeClient(Config config) {
Config cf = config; Config cf = config;
if (null == config) { if (null == config) {
cf = new ConfigBuilder().withMasterUrl(Configs.KUBE_MASTER_URL).build(); cf = new ConfigBuilder().withMasterUrl(Configs.KUBE_MASTER_URL)
.build();
} }
this.client = new DefaultKubernetesClient(cf); this.client = new DefaultKubernetesClient(cf);
} }
// RollingUpdatercline
public void updateOrAddReplicasLabelById(String namespace, public void updateOrAddReplicasLabelById(String namespace,
String resourceId, String key, String value) { String resourceId, String key, String value) {
KubernetesClient kubeClient = client; KubernetesClient kubeClient = client;
if (checkClientNull()) if (checkClientNull())
kubeClient = new DefaultKubernetesClient(Configs.KUBE_MASTER_URL); kubeClient = new DefaultKubernetesClient(Configs.KUBE_MASTER_URL);
kubeClient.replicationControllers().inNamespace(namespace) kubeClient.replicationControllers().inNamespace(namespace)
.withName(resourceId).edit().editMetadata() .withName(resourceId).rolling().edit().editMetadata()
.addToLabels(key, value).endMetadata().done(); .addToLabels(key, value).endMetadata().done();
} }

@ -10,10 +10,13 @@ import java.util.Map;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import org.apache.commons.lang.text.StrBuilder;
import com.platform.entities.OracleConnectorParams; import com.platform.entities.OracleConnectorParams;
import com.platform.kubernetes.SimpleKubeClient; import com.platform.kubernetes.SimpleKubeClient;
import com.platform.oracle.OracleConnector; import com.platform.oracle.OracleConnector;
import com.platform.utils.Configs; import com.platform.utils.Configs;
import com.platform.utils.Constant;
public class OracleStatusService { public class OracleStatusService {
private static Map<String, Timer> alliveTask = new Hashtable<String, Timer>(); private static Map<String, Timer> alliveTask = new Hashtable<String, Timer>();
@ -29,16 +32,24 @@ public class OracleStatusService {
OracleConnectorParams orp = new OracleConnectorParams(); OracleConnectorParams orp = new OracleConnectorParams();
Timer timer = new Timer(); Timer timer = new Timer();
alliveTask.put(replicasName, timer); alliveTask.put(replicasName, timer);
timer.schedule(new connectTask(replicasName, orp, sKubeClient), DELAY_TIME, timer.schedule(new connectTask(replicasName, orp, sKubeClient),
INTERVAL_TIME); DELAY_TIME, INTERVAL_TIME);
} }
public void cancelToOracle(String replicasName, String operate) { public void cancelToOracle(String replicasName, String operate) {
if (operate.equals("stop")) { if (operate.equals("stop")) {
SimpleKubeClient sKubeClient = new SimpleKubeClient(); String cmd = "kubectl label --overwrite rc " + replicasName
sKubeClient.updateOrAddReplicasLabelById(replicasName, "status", + " status=0";
"0"); List<String> rList = Constant.ganymedSSH
.execCmdWaitAcquiescent(cmd);
StringBuffer sb = new StringBuffer();
for (String str : rList)
sb.append(str).append("\n");
Configs.CONSOLE_LOGGER.info(sb.toString());
// SimpleKubeClient sKubeClient = new SimpleKubeClient();
// sKubeClient.updateOrAddReplicasLabelById(replicasName,
// "status","0");
} }
killAlliveTask(replicasName); killAlliveTask(replicasName);
} }
@ -86,7 +97,8 @@ public class OracleStatusService {
private OracleConnectorParams ocp; private OracleConnectorParams ocp;
private SimpleKubeClient client; private SimpleKubeClient client;
public connectTask(String taskName, OracleConnectorParams ocp, SimpleKubeClient client){ public connectTask(String taskName, OracleConnectorParams ocp,
SimpleKubeClient client) {
this.taskName = taskName; this.taskName = taskName;
this.ocp = ocp; this.ocp = ocp;
this.count = 0; this.count = 0;
@ -102,12 +114,20 @@ public class OracleStatusService {
@Override @Override
public void run() { public void run() {
if (count == EXEC_TIME && alliveTask.containsKey(taskName)) { //如果任务已经执行10次则任务oracle启动失败并取消oracle连接 if (count == EXEC_TIME && alliveTask.containsKey(taskName)) { // 如果任务已经执行10次则任务oracle启动失败并取消oracle连接
killAlliveTask(taskName); killAlliveTask(taskName);
client.updateOrAddReplicasLabelById(taskName, "status", "1"); //更新ReplicationController标签将oracle状态标示未1(0:启动中1失败2成功) // client.updateOrAddReplicasLabelById(taskName, "status", "1");
// //更新ReplicationController标签将oracle状态标示未1(0:启动中1失败2成功)
String cmd = "kubectl label --overwrite rc " + taskName
+ " status=1";
List<String> rList = Constant.ganymedSSH
.execCmdWaitAcquiescent(cmd);
StringBuffer sb = new StringBuffer();
for (String str : rList)
sb.append(str).append("\n");
Configs.CONSOLE_LOGGER.info("更新replicationController标签 " Configs.CONSOLE_LOGGER.info("更新replicationController标签 "
+ taskName + "\t[标签更新为: 失败]"); + taskName + "\t[标签更新为: 失败]");
} else { //否则执行连接oracle任务判断oracle是否启动成功 } else { // 否则执行连接oracle任务判断oracle是否启动成功
Pod pod = filterPod(); Pod pod = filterPod();
if (pod != null) { if (pod != null) {
String ip = client.getPodHostIp(pod); String ip = client.getPodHostIp(pod);
@ -115,15 +135,23 @@ public class OracleStatusService {
if (ip != null && port != 0) { if (ip != null && port != 0) {
String url = "jdbc:oracle:thin:@" + ip + ":" + port String url = "jdbc:oracle:thin:@" + ip + ":" + port
+ ":" + ocp.getDatabaseName(); + ":" + ocp.getDatabaseName();
boolean flag = OracleConnector.canConnect(url, //连接结果返回参数true标示连接成功false标示连接失败 boolean flag = OracleConnector.canConnect(url, // 连接结果返回参数true标示连接成功false标示连接失败
ocp.getUser(), ocp.getPassword()); ocp.getUser(), ocp.getPassword());
Configs.CONSOLE_LOGGER.info("url:" + url + ",user:" Configs.CONSOLE_LOGGER.info("url:" + url + ",user:"
+ ocp.getUser() + ",password:" + ocp.getUser() + ",password:"
+ ocp.getPassword()); + ocp.getPassword());
String message = "失败"; String message = "失败";
if (flag && alliveTask.containsKey(taskName)) { if (flag && alliveTask.containsKey(taskName)) {
client.updateOrAddReplicasLabelById(taskName, String cmd = "kubectl label --overwrite rc "
"status", "2"); + taskName + " status=2";
// client.updateOrAddReplicasLabelById(taskNSyame,
// "status", "2");
List<String> rList = Constant.ganymedSSH
.execCmdWaitAcquiescent(cmd);
StringBuffer sb = new StringBuffer();
for (String str : rList)
sb.append(str).append("\n");
Configs.CONSOLE_LOGGER.info(sb.toString());
message = "成功"; message = "成功";
killAlliveTask(taskName); // 连接成功,取消连接 killAlliveTask(taskName); // 连接成功,取消连接
Configs.CONSOLE_LOGGER Configs.CONSOLE_LOGGER
@ -140,6 +168,7 @@ public class OracleStatusService {
/** /**
* oracleip * oracleip
*
* @return * @return
*/ */
private Pod filterPod() { private Pod filterPod() {

@ -1,9 +1,7 @@
package com.platform.service.impl; package com.platform.service.impl;
import java.sql.Connection; import java.sql.Connection;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -13,14 +11,14 @@ import com.base.Custom4exception;
import com.base.CustomException; import com.base.CustomException;
import com.platform.dao.DataInfoDao; import com.platform.dao.DataInfoDao;
import com.platform.entities.DataInfoEntity; import com.platform.entities.DataInfoEntity;
import com.platform.entities.DataInfoEntityMoveTmp;
import com.platform.entities.GatherOracleInfo; import com.platform.entities.GatherOracleInfo;
import com.platform.entities.OracleConnectorParams; import com.platform.entities.OracleConnectorParams;
import com.platform.kubernetes.SimpleKubeClient; import com.platform.kubernetes.SimpleKubeClient;
import com.platform.oracle.OracleConnector; import com.platform.oracle.OracleConnector;
import com.platform.service.IOracleExtractService; import com.platform.service.IOracleExtractService;
import com.platform.service.OracleExtractHelper; import com.platform.service.OracleExtractHelper;
import com.platform.utils.Bean2MapUtils; import com.platform.utils.Configs;
import com.platform.utils.Constant;
@Service(value = "OracleExtract") @Service(value = "OracleExtract")
public class OracleExtractServiceImpl implements IOracleExtractService { public class OracleExtractServiceImpl implements IOracleExtractService {
@ -60,12 +58,27 @@ public class OracleExtractServiceImpl implements IOracleExtractService {
data.setExtractStatus(1); data.setExtractStatus(1);
dataInfoDao.updateExtract(data); dataInfoDao.updateExtract(data);
collectOracle.setName("J" + collectOracle.getName().replace("-", "_")); collectOracle.setName("J" + collectOracle.getName().replace("-", "_"));
String cmd = "kubectl label --overwrite rc "
+ collectOracle.getName() + " isExtract=1";
List<String> rList = Constant.ganymedSSH
.execCmdWaitAcquiescent(cmd);
StringBuffer sb = new StringBuffer();
for (String string : rList)
sb.append(string).append("\n");
Configs.CONSOLE_LOGGER.info(sb.toString());
// client.updateOrAddReplicasLabelById(collectOracle.getName(), "isExtract", "1"); //更新oracle汇总状态0标示为未汇总1标示汇总中2标示汇总完成 // client.updateOrAddReplicasLabelById(collectOracle.getName(), "isExtract", "1"); //更新oracle汇总状态0标示为未汇总1标示汇总中2标示汇总完成
oracleExtract.createDBLink(conn, collectOracle); //创建dblink oracleExtract.createDBLink(conn, collectOracle); //创建dblink
oracleExtract.createTableSpace(conn, oracleModel); //创建表空间 oracleExtract.createTableSpace(conn, oracleModel); //创建表空间
oracleExtract.createUser(conn, collectOracle, oracleModel);//创建用户并授权 oracleExtract.createUser(conn, collectOracle, oracleModel);//创建用户并授权
oracleExtract.extractColleDB(conn, collectOracle);//执行抽取 oracleExtract.extractColleDB(conn, collectOracle);//执行抽取
// client.updateOrAddReplicasLabelById(collectOracle.getName(), "isExtract", "2"); //更新oracle汇总状态0标示为未汇总1标示汇总中2标示汇总完成 // client.updateOrAddReplicasLabelById(collectOracle.getName(), "isExtract", "2"); //更新oracle汇总状态0标示为未汇总1标示汇总中2标示汇总完成
cmd = "kubectl label --overwrite rc "
+ collectOracle.getName() + " isExtract=2";
rList = Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
sb = new StringBuffer();
for (String string : rList)
sb.append(string).append("\n");
Configs.CONSOLE_LOGGER.info(sb.toString());
data.setExtractStatus(2); data.setExtractStatus(2);
dataInfoDao.updateExtract(data); dataInfoDao.updateExtract(data);
} }

@ -21,7 +21,7 @@ public class Configs {
public static final Logger LOGGER = Logger.getLogger(Configs.class); public static final Logger LOGGER = Logger.getLogger(Configs.class);
public static String KUBE_MASTER_URL = "http://192.168.0.113:8080/"; // kubernetes集群的maser public static String KUBE_MASTER_URL = "http://192.168.0.110:8080/"; // kubernetes集群的maser
// URl // URl
public static int ORACLE_DEFAULT_PORT = 1521; // oracle的默认端口号 public static int ORACLE_DEFAULT_PORT = 1521; // oracle的默认端口号
@ -42,12 +42,11 @@ public class Configs {
public static String TABLE_SUFFIX = "_20152016"; //汇总库汇总表的后缀名 public static String TABLE_SUFFIX = "_20152016"; //汇总库汇总表的后缀名
public static String EXTRACT_LOG_LOCALTION = "C:\\log"; //数据汇总日志保存位置 public static String EXTRACT_LOG_LOCALTION = "D:\\log"; //数据汇总日志保存位置
public static String GATHER_TABLESPACE_NAME=""; //表空间名 public static String GATHER_TABLESPACE_NAME=""; //表空间名
public static String GATHER_TABLESPACE_PATH=""; //表空间路径 public static String GATHER_TABLESPACE_PATH=""; //表空间路径
public static String GATHER_TABLE_PASSWORD="1"; //登入密码 public static String GATHER_TABLE_PASSWORD="1"; //登入密码
} }

Loading…
Cancel
Save