|
|
@ -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 {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 获取oracle的连接ip地址和端口号
|
|
|
|
* 获取oracle的连接ip地址和端口号
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private Pod filterPod() {
|
|
|
|
private Pod filterPod() {
|
|
|
|