修复启动oracle,测试连接oracle失败的Bug

web_backend_develope
wu ming 9 years ago
parent 608e658d3a
commit acd377cc4d

@ -10,13 +10,20 @@
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/websocket
http://www.springframework.org/schema/websocket/spring-websocket.xsd">
<!-- 读取db.properties中的属性值 -->
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="WEB-INF/config/config.properties"></property>
</bean>
<bean id="messageCodeResolver"
class="org.springframework.validation.DefaultMessageCodesResolver">
<property name="prefix" value="validation."></property>
</bean>
<!-- 连接MySQL数据库 -->
<bean id="mySQLDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
@ -26,11 +33,11 @@
<property name="password" value="${jdbc.mysql.password}" />
</bean>
<bean id="mySQLSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="WEB-INF/config/mybatis-applicationConfig.xml" />
<property name="configLocation" value="WEB-INF/config/mybatis-applicationConfig.xml" />
<property name="dataSource" ref="mySQLDataSource" />
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.platform.dao,com.dao.mapper" />
<property name="basePackage" value="com.platform.dao,com.dao.mapper" />
</bean>
<!-- 配置声明式事物 事物管理器 -->
<!-- 配置声明式事物 -->
@ -42,7 +49,7 @@
<tx:attributes>
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="select*" read-only="true" />
</tx:attributes>
</tx:advice>

@ -1,16 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:websocket="http://www.springframework.org/schema/websocket"
xsi:schemaLocation="
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/websocket
http://www.springframework.org/schema/websocket/spring-websocket-4.0.xsd"
default-autowire="byName">
<context:component-scan base-package="com.platform.controller,com.platform.test;" >
<context:component-scan base-package="com.platform.controller,com.platform.test,com.platform.websocket;" >
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>
</context:component-scan>
<context:annotation-config />
<mvc:annotation-driven/>
<!-- 用于将对象转换为JSON -->
<bean id="stringConverter"

@ -37,9 +37,9 @@ public class OracleConnectorParams {
private void maybeInit() {
Properties properties = ConfigPropertyReader.Builder(
Configs.CONFIG_LOCALTION).getProperties();
this.user = properties.getProperty("collect-user");
this.user = properties.getProperty("collect-user-name");
this.password = properties.getProperty("collect-password");
this.databaseName = properties.getProperty("collect-database");
this.databaseName = properties.getProperty("collect-service-name");
}
public String getPort() {

@ -6,11 +6,9 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.validation.constraints.Pattern.Flag;
import com.platform.utils.Configs;
public class OracleConnector {
public class OracleConnector {
static {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
@ -19,18 +17,17 @@ public class OracleConnector {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static Connection ConnectionBuilder(String url, String user,
String password) {
Connection conn = null;
String password) {
Connection conn=null;
try {
conn = DriverManager.getConnection(url, user, password);
} catch (SQLException e) {
return conn;
} catch (SQLException e) {
Configs.CONSOLE_LOGGER.info("创建oracle连接失败: [" + e.getMessage() + "]");
}
return conn;
}
@ -75,5 +72,5 @@ public class OracleConnector {
e.printStackTrace();
}
return flag;
}
}
}

@ -17,7 +17,7 @@ import com.platform.utils.Configs;
public class OracleStatusService {
private static Map<String, Timer> alliveTask = new Hashtable<String, Timer>();
public final static int EXEC_TIME = 10;// 连接多少次后不成功,取消链接
public final static int EXEC_TIME = 9;// 连接多少次后不成功,取消链接
public final static long INTERVAL_TIME = 60 * 1000;// 每隔多少毫秒执行一次连接任务
public final static long DELAY_TIME = 0; // 延迟多少秒后执行
@ -96,12 +96,11 @@ public class OracleStatusService {
private int count;
private OracleConnectorParams ocp;
private SimpleKubeClient client;
public connectTask(OracleConnectorParams ocp, SimpleKubeClient client) {
this.taskName = ocp.getName();
this.ocp = ocp;
this.count = 0;
this.client = client;
this.client = client;
}
@Override
@ -109,9 +108,12 @@ public class OracleStatusService {
if (count == EXEC_TIME && alliveTask.containsKey(taskName)) {
killAlliveTask(taskName);
client.updateOrAddReplicasLabelById(taskName, "status", "1");
Configs.CONSOLE_LOGGER.info("更新replicationController标签 " + taskName
+ "\t[标签更新为: 失败]");
} else {
String url = "jdbc:oracle:thin:@" + ocp.getIp() + ":"
+ ocp.getPort() + "/" + ocp.getDatabaseName();
+ ocp.getPort() + ":" + ocp.getDatabaseName();
System.out.println("url:" + url +",user:" + ocp.getUser() + ",password:" + ocp.getPassword());
boolean flag = OracleConnector.canConnect(url, ocp.getUser(),
ocp.getPassword());
String message = "失败";
@ -119,6 +121,8 @@ public class OracleStatusService {
client.updateOrAddReplicasLabelById(taskName, "status", "2");
message = "成功";
killAlliveTask(taskName); // 连接成功,取消连接
Configs.CONSOLE_LOGGER.info("更新replicationController标签 " + taskName
+ "\t[标签更新为: 成功]");
}
Configs.CONSOLE_LOGGER.info("连接到数据库服务: " + taskName
+ "\t[连接结果: " + message + "]");

Loading…
Cancel
Save