Skip to content

Commit

Permalink
support for TIS deploy incr instance with kubernete application mode
Browse files Browse the repository at this point in the history
  • Loading branch information
baisui1981 committed Mar 15, 2024
1 parent 0b2a7ce commit 1fac219
Show file tree
Hide file tree
Showing 21 changed files with 496 additions and 456 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* <p>
* http:https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.qlangtech.tis.coredefine.module.action;

Expand All @@ -32,7 +32,15 @@ public interface IRCController {
/**
* 连接是否可用进行校验,如果连接不可用直接抛出TisException
*/
void checkUseable();
void checkUseable(TargetResName collection);

/**
* 实例是否已经创建
*
* @param collection
* @return
*/
boolean hasCreated(TargetResName collection);

/**
* 发布增量实例
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* <p>
* http:https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.qlangtech.tis.coredefine.module.action.impl;
Expand All @@ -34,6 +34,11 @@ public void deploy(TargetResName collection, ReplicasSpec incrSpec, long timesta
throw new UnsupportedOperationException();
}

@Override
public boolean hasCreated(TargetResName collection) {
return true;
}

@Override
public void restoreFromCheckpoint(TargetResName resName, Integer checkpointId) {
throw new UnsupportedOperationException();
Expand All @@ -60,7 +65,8 @@ public void discardSavepoint(TargetResName resName, String savepointPath) {
}

@Override
public void checkUseable() {
public void checkUseable(TargetResName collection
) {
throw new UnsupportedOperationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,31 @@ public static File getPluginLibDir(String pluginName) {
public static final String SUB_DIR_LIBS = "libs";

public static final String SUB_DIR_CFG_REPO = "cfg_repo";
public static final String DB_TYPE_MYSQL = "mysql";
public static final String DB_TYPE_DERBY = "derby";

public enum SysDBType {
MySQL("mysql"), DERBY("derby");
String token;

private SysDBType(String token) {
this.token = token;
}

public String getToken() {
return this.token;
}

public static SysDBType parse(String token) {
for (SysDBType type : SysDBType.values()) {
if (type.token.equalsIgnoreCase(token)) {
return type;
}
}
throw new IllegalStateException("illegal token:" + token);
}
}

// public static final String DB_TYPE_MYSQL = "mysql";
// public static final String DB_TYPE_DERBY = "derby";

public static final String QLANGTECH_PACKAGE = "com.qlangtech";

Expand Down Expand Up @@ -192,7 +215,7 @@ public String put(String key, String value) {
pairs.put(KEY_ASSEMBLE_HOST, this.assembleHost);
pairs.put(KEY_TIS_HOST, this.tisHost);
pairs.put(KEY_RUNTIME, this.runtime);
pairs.put(KEY_TIS_DATASOURCE_TYPE, dbCfg.dbtype);
pairs.put(KEY_TIS_DATASOURCE_TYPE, dbCfg.dbtype.token);
pairs.put(KEY_TIS_DATASOURCE_DBNAME, dbCfg.dbname);
pairs.put(KEY_DEPLOY_MODE, this.deployMode);
pairs.put(TisAppLaunch.KEY_LOG_DIR, TisAppLaunch.getLogDir().getAbsolutePath());
Expand Down Expand Up @@ -250,7 +273,7 @@ public static File getTisHome() {
public static File getDataDir(boolean valiate) {
File dir = null; //new File(System.getProperty(KEY_DATA_DIR, DEFAULT_DATA_DIR));
try {
dir = getInstance().dataDir;
dir = getInstance().dataDir();
} catch (Throwable e) {
logger.warn("can not get dataDir from config instance:" + e.getMessage());
dir = new File(System.getProperty(KEY_DATA_DIR, DEFAULT_DATA_DIR));
Expand All @@ -271,6 +294,10 @@ public static File getDataDir(boolean valiate) {

private File dataDir;

public File dataDir() {
return this.dataDir;
}


// // 组装节点
private final String assembleHost;
Expand Down Expand Up @@ -313,15 +340,15 @@ private Config() {

this.dbCfg = new TisDbConfig();
try {
dbCfg.dbtype = propGetter.getString(KEY_TIS_DATASOURCE_TYPE, true);
dbCfg.dbtype = SysDBType.parse(propGetter.getString(KEY_TIS_DATASOURCE_TYPE, true));
dbCfg.dbname = propGetter.getString(KEY_TIS_DATASOURCE_DBNAME, true);

if (!(DB_TYPE_MYSQL.equals(dbCfg.dbtype)
|| DB_TYPE_DERBY.equals(dbCfg.dbtype))) {
throw new IllegalStateException("dbCfg.dbtype:" + dbCfg.dbtype + " is illegal");
}
// if (!(DB_TYPE_MYSQL.equals(dbCfg.dbtype)
// || DB_TYPE_DERBY.equals(dbCfg.dbtype))) {
// throw new IllegalStateException("dbCfg.dbtype:" + dbCfg.dbtype + " is illegal");
// }

if (DB_TYPE_MYSQL.equals(dbCfg.dbtype)) {
if (SysDBType.MySQL == (dbCfg.dbtype)) {
dbCfg.port = Integer.parseInt(propGetter.getString("tis.datasource.port"));
dbCfg.url = propGetter.getString("tis.datasource.url");
dbCfg.userName = propGetter.getString("tis.datasource.username");
Expand Down Expand Up @@ -484,7 +511,7 @@ protected String getProp(String key) {
}

if (KEY_TIS_DATASOURCE_TYPE.equals(key)) {
return DB_TYPE_DERBY;
return SysDBType.DERBY.token;
}
return StringUtils.defaultIfEmpty(System.getenv(key), System.getProperty(key));
}
Expand Down Expand Up @@ -590,7 +617,7 @@ public static void setConfig(Config cfg) {

public static class TisDbConfig {

public String dbtype;
public SysDBType dbtype;
public String dbname;

// tis.datasource.url=192.168.28.200
Expand All @@ -610,7 +637,7 @@ public String toString() {
", port=" + port +
", url='" + url + '\'' +
", userName='" + userName + '\'' +
", password='" + password + '\'' +
// ", password='" + password + '\'' +
'}';
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* <p>
* http:https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.qlangtech.tis.manage.common;

import com.qlangtech.tis.ibatis.BasicCriteria;
import com.qlangtech.tis.manage.common.Config.SysDBType;

import java.text.MessageFormat;

Expand All @@ -33,9 +34,9 @@ public abstract class TISBaseCriteria extends BasicCriteria {
public final String getPaginationScript() {

Config.TisDbConfig dbCfg = Config.getDbCfg();
if (Config.DB_TYPE_DERBY.equals(dbCfg.dbtype)) {
if (SysDBType.DERBY == (dbCfg.dbtype)) {
return DB_DERBY_PAGINATION_FORMAT.format(new Object[]{this.getSkip(), this.getPageSize()});
} else if (Config.DB_TYPE_MYSQL.equals(dbCfg.dbtype)) {
} else if (SysDBType.MySQL == (dbCfg.dbtype)) {
return DB_MYSQL_PAGINATION_FORMAT.format(new Object[]{this.getSkip(), this.getPageSize()});
} else {
throw new IllegalStateException("illegal dbtype:" + dbCfg.dbtype);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.qlangtech.tis.manage.spring;

import com.qlangtech.tis.manage.common.Config;
import com.qlangtech.tis.manage.common.Config.SysDBType;
import com.qlangtech.tis.manage.common.DaoUtils;
import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.lang.StringUtils;
Expand All @@ -29,6 +30,7 @@
import org.springframework.jndi.JndiAccessor;

import javax.naming.NamingException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
Expand Down Expand Up @@ -67,7 +69,17 @@ public BasicDataSource getDS() {
*
* @return
*/
// public abstract boolean needInitZkPath();

public boolean dbTisConsoleExist(Config.TisDbConfig dbCfg) throws SQLException {

try (Connection conn = this.getDS().getConnection()) {
try (Statement statement = conn.createStatement()) {
return dbTisConsoleExist(dbCfg, statement);
}
}
}


public abstract boolean dbTisConsoleExist(Config.TisDbConfig dbCfg, Statement statement) throws SQLException;

public abstract void createSysDB(Config.TisDbConfig dbCfg, Statement statement) throws SQLException;
Expand Down Expand Up @@ -148,7 +160,7 @@ public boolean isSingleton() {
return true;
}

public static SystemDBInit createDataSource(String dbType, Config.TisDbConfig dbCfg, boolean useDBName, boolean dbAutoCreate) {
public static SystemDBInit createDataSource(SysDBType dbType, Config.TisDbConfig dbCfg, boolean useDBName, boolean dbAutoCreate) {
if (systemDBInitThreadLocal.get() != null) {
return systemDBInitThreadLocal.get();
}
Expand All @@ -163,16 +175,17 @@ public static SystemDBInit createDataSource(String dbType, Config.TisDbConfig db
* @param getDSFromJNDI 当是derby数据源类型时,需要从jndi容器中取ds
* @return
*/
public static SystemDBInit createDataSource(String dbType, Config.TisDbConfig dbCfg
public static SystemDBInit createDataSource(SysDBType dbType, Config.TisDbConfig dbCfg
, boolean useDBName, final boolean dbAutoCreate, boolean getDSFromJNDI, TISDataSourceFactory dsFactory) {
if (StringUtils.isEmpty(dbType)) {
throw new IllegalArgumentException("param dbType can not be null");
}
Objects.requireNonNull(dbType, "param dbType can not be null");
// if () {
// throw new IllegalArgumentException("param dbType can not be null");
// }
if (StringUtils.isEmpty(dbCfg.dbname)) {
throw new IllegalArgumentException("param dbName can not be null");
}
BasicDataSource dataSource = new BasicDataSource();
if (Config.DB_TYPE_MYSQL.equals(dbType)) {
if (SysDBType.MySQL == (dbType)) {

dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl("jdbc:mysql:https://" + dbCfg.url + ":" + dbCfg.port + (useDBName ? ("/" + dbCfg.dbname) : StringUtils.EMPTY)
Expand Down Expand Up @@ -206,14 +219,19 @@ public void dropDB(Config.TisDbConfig dbCfg, Statement statement) throws SQLExce
public void createSysDB(Config.TisDbConfig dbCfg, Statement statement) throws SQLException {
statement.addBatch("create database " + dbCfg.dbname + ";");
statement.addBatch("use " + dbCfg.dbname + ";");
statement.executeBatch();
}

@Override
public boolean shallSkip(String sql) {
if (StringUtils.startsWithIgnoreCase(sql, "CREATE DATABASE")
|| StringUtils.startsWithIgnoreCase(sql, "USE")) {
return true;
}
return false;
}
};
} else if (Config.DB_TYPE_DERBY.equals(dbType)) {
} else if (SysDBType.DERBY == (dbType)) {

if (getDSFromJNDI) {
dataSource = getJndiDatasource(dsFactory);
Expand Down
Loading

0 comments on commit 1fac219

Please sign in to comment.