✨ Introducing new features. closed #4642 up seata-server 1.6.1

This commit is contained in:
aeizzz committed 2023-01-28 13:58:45 +08:00
1 parent 859a049646
commit 510061cc75
116 files changed
+12716 -8752

No files matched your search

@@ -0,0 +1,36 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed 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://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.
*/
package io.seata.server.console.controller;
import io.seata.server.console.service.BranchSessionService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* Branch Session Controller
* @author zhongxiang.wang
*/
@RestController
@RequestMapping("console/branchSession")
public class BranchSessionController {
@Resource(type = BranchSessionService.class)
private BranchSessionService branchSessionService;
}
@@ -0,0 +1,51 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed 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://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.
*/
package io.seata.server.console.controller;
import io.seata.console.result.PageResult;
import io.seata.server.console.param.GlobalLockParam;
import io.seata.server.console.service.GlobalLockService;
import io.seata.server.console.vo.GlobalLockVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* Global Lock Controller
* @author zhongxiang.wang
*/
@RestController
@RequestMapping("/api/v1/console/globalLock")
public class GlobalLockController {
@Resource(type = GlobalLockService.class)
private GlobalLockService globalLockService;
/**
* Query locks by param
* @param param the param
* @return the list of GlobalLockVO
*/
@GetMapping("query")
public PageResult<GlobalLockVO> query(@ModelAttribute GlobalLockParam param) {
return globalLockService.query(param);
}
}
@@ -0,0 +1,50 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed 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://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.
*/
package io.seata.server.console.controller;
import io.seata.console.result.PageResult;
import io.seata.server.console.param.GlobalSessionParam;
import io.seata.server.console.service.GlobalSessionService;
import io.seata.server.console.vo.GlobalSessionVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* Global Session Controller
* @author zhongxiang.wang
*/
@RestController
@RequestMapping("/api/v1/console/globalSession")
public class GlobalSessionController {
@Resource(type = GlobalSessionService.class)
private GlobalSessionService globalSessionService;
/**
* Query all globalSession
* @param param param for query globalSession
* @return the list of GlobalSessionVO
*/
@GetMapping("query")
public PageResult<GlobalSessionVO> query(@ModelAttribute GlobalSessionParam param) {
return globalSessionService.query(param);
}
}
@@ -0,0 +1,101 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed 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://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.
*/
package io.seata.server.console.impl.db;
import io.seata.common.ConfigurationKeys;
import io.seata.common.exception.StoreException;
import io.seata.common.loader.EnhancedServiceLoader;
import io.seata.common.util.IOUtil;
import io.seata.common.util.StringUtils;
import io.seata.config.Configuration;
import io.seata.config.ConfigurationFactory;
import io.seata.console.result.PageResult;
import io.seata.core.store.db.DataSourceProvider;
import io.seata.core.store.db.sql.log.LogStoreSqlsFactory;
import io.seata.server.console.service.BranchSessionService;
import io.seata.server.console.vo.BranchSessionVO;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Component;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import static io.seata.common.DefaultValues.DEFAULT_STORE_DB_BRANCH_TABLE;
/**
* Branch Session DataBase ServiceImpl
*
* @author zhongxiang.wang
* @author lvekee 734843455@qq.com
*/
@Component
@org.springframework.context.annotation.Configuration
@ConditionalOnExpression("#{'db'.equals('${sessionMode}')}")
public class BranchSessionDBServiceImpl implements BranchSessionService {
private String branchTable;
private String dbType;
private DataSource dataSource;
public BranchSessionDBServiceImpl() {
Configuration configuration = ConfigurationFactory.getInstance();
branchTable = configuration.getConfig(ConfigurationKeys.STORE_DB_BRANCH_TABLE, DEFAULT_STORE_DB_BRANCH_TABLE);
dbType = configuration.getConfig(ConfigurationKeys.STORE_DB_TYPE);
if (StringUtils.isBlank(dbType)) {
throw new IllegalArgumentException(ConfigurationKeys.STORE_DB_TYPE + " should not be blank");
}
String dbDataSource = configuration.getConfig(ConfigurationKeys.STORE_DB_DATASOURCE_TYPE);
if (StringUtils.isBlank(dbDataSource)) {
throw new IllegalArgumentException(ConfigurationKeys.STORE_DB_DATASOURCE_TYPE + " should not be blank");
}
dataSource = EnhancedServiceLoader.load(DataSourceProvider.class, dbDataSource).provide();
}
@Override
public PageResult<BranchSessionVO> queryByXid(String xid) {
if (StringUtils.isBlank(xid)) {
throw new IllegalArgumentException("xid should not be blank");
}
String whereCondition = " where xid = ? ";
String branchSessionSQL = LogStoreSqlsFactory.getLogStoreSqls(dbType).getAllBranchSessionSQL(branchTable, whereCondition);
List<BranchSessionVO> list = new ArrayList<>();
ResultSet rs = null;
try (Connection conn = dataSource.getConnection();
PreparedStatement ps = conn.prepareStatement(branchSessionSQL)) {
ps.setObject(1, xid);
rs = ps.executeQuery();
while (rs.next()) {
list.add(BranchSessionVO.convert(rs));
}
} catch (SQLException e) {
throw new StoreException(e);
} finally {
IOUtil.close(rs);
}
return PageResult.success(list, list.size(), 0, 0, 0);
}
}
@@ -0,0 +1,145 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed 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://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.
*/
package io.seata.server.console.impl.db;
import io.seata.common.ConfigurationKeys;
import io.seata.common.exception.StoreException;
import io.seata.common.loader.EnhancedServiceLoader;
import io.seata.common.util.IOUtil;
import io.seata.common.util.PageUtil;
import io.seata.common.util.StringUtils;
import io.seata.config.Configuration;
import io.seata.config.ConfigurationFactory;
import io.seata.console.result.PageResult;
import io.seata.core.store.db.DataSourceProvider;
import io.seata.core.store.db.sql.lock.LockStoreSqlFactory;
import io.seata.server.console.param.GlobalLockParam;
import io.seata.server.console.service.GlobalLockService;
import io.seata.server.console.vo.GlobalLockVO;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Component;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import static io.seata.common.DefaultValues.DEFAULT_LOCK_DB_TABLE;
/**
* Global Lock DB ServiceImpl
*
* @author zhongxiang.wang
* @author lvekee 734843455@qq.com
*/
@Component
@org.springframework.context.annotation.Configuration
@ConditionalOnExpression("#{'db'.equals('${lockMode}')}")
public class GlobalLockDBServiceImpl implements GlobalLockService {
private String lockTable;
private String dbType;
private DataSource dataSource;
public GlobalLockDBServiceImpl() {
Configuration configuration = ConfigurationFactory.getInstance();
lockTable = configuration.getConfig(ConfigurationKeys.LOCK_DB_TABLE, DEFAULT_LOCK_DB_TABLE);
dbType = configuration.getConfig(ConfigurationKeys.STORE_DB_TYPE);
if (StringUtils.isBlank(dbType)) {
throw new IllegalArgumentException(ConfigurationKeys.STORE_DB_TYPE + " should not be blank");
}
String dbDataSource = configuration.getConfig(ConfigurationKeys.STORE_DB_DATASOURCE_TYPE);
if (StringUtils.isBlank(dbDataSource)) {
throw new IllegalArgumentException(ConfigurationKeys.STORE_DB_DATASOURCE_TYPE + " should not be blank");
}
dataSource = EnhancedServiceLoader.load(DataSourceProvider.class, dbDataSource).provide();
}
@Override
public PageResult<GlobalLockVO> query(GlobalLockParam param) {
PageUtil.checkParam(param.getPageNum(), param.getPageSize());
List<Object> sqlParamList = new ArrayList<>();
String whereCondition = this.getWhereConditionByParam(param, sqlParamList);
String sourceSql = LockStoreSqlFactory.getLogStoreSql(dbType).getAllLockSql(lockTable, whereCondition);
String queryLockSql = PageUtil.pageSql(sourceSql, dbType, param.getPageNum(), param.getPageSize());
String lockCountSql = PageUtil.countSql(sourceSql, dbType);
List<GlobalLockVO> list = new ArrayList<>();
int count = 0;
ResultSet rs = null;
ResultSet countRs = null;
try (Connection conn = dataSource.getConnection();
PreparedStatement ps = conn.prepareStatement(queryLockSql);
PreparedStatement countPs = conn.prepareStatement(lockCountSql)) {
PageUtil.setObject(ps, sqlParamList);
rs = ps.executeQuery();
while (rs.next()) {
list.add(GlobalLockVO.convert(rs));
}
PageUtil.setObject(countPs, sqlParamList);
countRs = countPs.executeQuery();
if (countRs.next()) {
count = countRs.getInt(1);
}
} catch (SQLException e) {
throw new StoreException(e);
} finally {
IOUtil.close(rs, countRs);
}
return PageResult.success(list, count, param.getPageNum(), param.getPageSize());
}
private String getWhereConditionByParam(GlobalLockParam param, List<Object> sqlParamList) {
StringBuilder whereConditionBuilder = new StringBuilder();
if (StringUtils.isNotBlank(param.getXid())) {
whereConditionBuilder.append(" and xid = ? ");
sqlParamList.add(param.getXid());
}
if (StringUtils.isNotBlank(param.getTableName())) {
whereConditionBuilder.append(" and table_name = ? ");
sqlParamList.add(param.getTableName());
}
if (StringUtils.isNotBlank(param.getTransactionId())) {
whereConditionBuilder.append(" and transaction_id = ? ");
sqlParamList.add(param.getTransactionId());
}
if (StringUtils.isNotBlank(param.getBranchId())) {
whereConditionBuilder.append(" and branch_id = ? ");
sqlParamList.add(param.getBranchId());
}
if (param.getTimeStart() != null) {
whereConditionBuilder.append(" and gmt_create >= ? ");
sqlParamList.add(param.getTimeStart());
}
if (param.getTimeEnd() != null) {
whereConditionBuilder.append(" and gmt_create <= ? ");
sqlParamList.add(param.getTimeEnd());
}
String whereCondition = whereConditionBuilder.toString();
return whereCondition.replaceFirst("and", "where");
}
}
@@ -0,0 +1,160 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed 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://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.
*/
package io.seata.server.console.impl.db;
import io.seata.common.ConfigurationKeys;
import io.seata.common.exception.StoreException;
import io.seata.common.loader.EnhancedServiceLoader;
import io.seata.common.util.IOUtil;
import io.seata.common.util.PageUtil;
import io.seata.common.util.StringUtils;
import io.seata.config.Configuration;
import io.seata.config.ConfigurationFactory;
import io.seata.console.result.PageResult;
import io.seata.core.store.db.DataSourceProvider;
import io.seata.core.store.db.sql.log.LogStoreSqlsFactory;
import io.seata.server.console.param.GlobalSessionParam;
import io.seata.server.console.service.BranchSessionService;
import io.seata.server.console.service.GlobalSessionService;
import io.seata.server.console.vo.BranchSessionVO;
import io.seata.server.console.vo.GlobalSessionVO;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import static io.seata.common.DefaultValues.DEFAULT_STORE_DB_GLOBAL_TABLE;
/**
* Global Session DataBase ServiceImpl
*
* @author zhongxiang.wang
* @author lvekee 734843455@qq.com
*/
@Component
@org.springframework.context.annotation.Configuration
@ConditionalOnExpression("#{'db'.equals('${sessionMode}')}")
public class GlobalSessionDBServiceImpl implements GlobalSessionService {
private String globalTable;
private String dbType;
private DataSource dataSource;
@Resource(type = BranchSessionService.class)
private BranchSessionService branchSessionService;
public GlobalSessionDBServiceImpl() {
Configuration configuration = ConfigurationFactory.getInstance();
globalTable = configuration.getConfig(ConfigurationKeys.STORE_DB_GLOBAL_TABLE, DEFAULT_STORE_DB_GLOBAL_TABLE);
dbType = configuration.getConfig(ConfigurationKeys.STORE_DB_TYPE);
if (StringUtils.isBlank(dbType)) {
throw new IllegalArgumentException(ConfigurationKeys.STORE_DB_TYPE + " should not be blank");
}
String dbDataSource = configuration.getConfig(ConfigurationKeys.STORE_DB_DATASOURCE_TYPE);
if (StringUtils.isBlank(dbDataSource)) {
throw new IllegalArgumentException(ConfigurationKeys.STORE_DB_DATASOURCE_TYPE + " should not be blank");
}
dataSource = EnhancedServiceLoader.load(DataSourceProvider.class, dbDataSource).provide();
}
@Override
public PageResult<GlobalSessionVO> query(GlobalSessionParam param) {
PageUtil.checkParam(param.getPageNum(), param.getPageSize());
List<Object> sqlParamList = new ArrayList<>();
String whereCondition = getWhereConditionByParam(param, sqlParamList);
String sourceSql = LogStoreSqlsFactory.getLogStoreSqls(dbType).getAllGlobalSessionSql(globalTable, whereCondition);
String querySessionSql = PageUtil.pageSql(sourceSql, dbType, param.getPageNum(), param.getPageSize());
String sessionCountSql = PageUtil.countSql(sourceSql, dbType);
List<GlobalSessionVO> list = new ArrayList<>();
int count = 0;
ResultSet rs = null;
ResultSet countRs = null;
try (Connection conn = dataSource.getConnection();
PreparedStatement ps = conn.prepareStatement(querySessionSql);
PreparedStatement countPs = conn.prepareStatement(sessionCountSql)) {
PageUtil.setObject(ps, sqlParamList);
rs = ps.executeQuery();
while (rs.next()) {
list.add(GlobalSessionVO.convert(rs));
}
PageUtil.setObject(countPs, sqlParamList);
countRs = countPs.executeQuery();
if (countRs.next()) {
count = countRs.getInt(1);
}
if (param.isWithBranch()) {
for (GlobalSessionVO globalSessionVO : list) {
PageResult<BranchSessionVO> pageResp = branchSessionService.queryByXid(globalSessionVO.getXid());
globalSessionVO.setBranchSessionVOs(new HashSet<>(pageResp.getData()));
}
}
} catch (SQLException e) {
throw new StoreException(e);
} finally {
IOUtil.close(rs, countRs);
}
return PageResult.success(list, count, param.getPageNum(), param.getPageSize());
}
private String getWhereConditionByParam(GlobalSessionParam param, List<Object> sqlParamList) {
StringBuilder whereConditionBuilder = new StringBuilder();
if (StringUtils.isNotBlank(param.getXid())) {
whereConditionBuilder.append(" and xid = ? ");
sqlParamList.add(param.getXid());
}
if (StringUtils.isNotBlank(param.getApplicationId())) {
whereConditionBuilder.append(" and application_id = ? ");
sqlParamList.add(param.getApplicationId());
}
if (param.getStatus() != null) {
whereConditionBuilder.append(" and status = ? ");
sqlParamList.add(param.getStatus());
}
if (StringUtils.isNotBlank(param.getTransactionName())) {
whereConditionBuilder.append(" and transaction_name = ? ");
sqlParamList.add(param.getTransactionName());
}
if (param.getTimeStart() != null) {
whereConditionBuilder.append(" and gmt_create >= ? ");
sqlParamList.add(new Date(param.getTimeStart()));
}
if (param.getTimeEnd() != null) {
whereConditionBuilder.append(" and gmt_create <= ? ");
sqlParamList.add(new Date(param.getTimeEnd()));
}
String whereCondition = whereConditionBuilder.toString();
return whereCondition.replaceFirst("and", "where");
}
}
@@ -0,0 +1,39 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed 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://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.
*/
package io.seata.server.console.impl.file;
import io.seata.common.exception.NotSupportYetException;
import io.seata.console.result.PageResult;
import io.seata.server.console.service.BranchSessionService;
import io.seata.server.console.vo.BranchSessionVO;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Component;
/**
* Branch Session File ServiceImpl
*
* @author zhongxiang.wang
*/
@Component
@org.springframework.context.annotation.Configuration
@ConditionalOnExpression("#{'file'.equals('${sessionMode}')}")
public class BranchSessionFileServiceImpl implements BranchSessionService {
@Override
public PageResult<BranchSessionVO> queryByXid(String xid) {
throw new NotSupportYetException();
}
}
@@ -0,0 +1,170 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed 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://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.
*/
package io.seata.server.console.impl.file;
import io.seata.common.util.CollectionUtils;
import io.seata.common.util.StringUtils;
import io.seata.console.result.PageResult;
import io.seata.core.lock.RowLock;
import io.seata.server.console.param.GlobalLockParam;
import io.seata.server.console.service.GlobalLockService;
import io.seata.server.console.vo.GlobalLockVO;
import io.seata.server.lock.LockerManagerFactory;
import io.seata.server.session.BranchSession;
import io.seata.server.session.GlobalSession;
import io.seata.server.session.SessionHolder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Component;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static io.seata.common.util.StringUtils.isBlank;
import static io.seata.server.console.vo.GlobalLockVO.convert;
import static java.util.Objects.isNull;
/**
* Global Lock File ServiceImpl
*
* @author zhongxiang.wang
* @author miaoxueyu
*/
@Component
@org.springframework.context.annotation.Configuration
@ConditionalOnExpression("#{'file'.equals('${lockMode}')}")
public class GlobalLockFileServiceImpl implements GlobalLockService {
@Override
public PageResult<GlobalLockVO> query(GlobalLockParam param) {
checkParam(param);
final Collection<GlobalSession> allSessions = SessionHolder.getRootSessionManager().allSessions();
final AtomicInteger total = new AtomicInteger();
List<RowLock> result = allSessions
.parallelStream()
.filter(obtainGlobalSessionPredicate(param))
.flatMap(globalSession -> globalSession.getBranchSessions().stream())
.filter(obtainBranchSessionPredicate(param))
.flatMap(branchSession -> filterAndMap(param, branchSession))
.peek(globalSession -> total.incrementAndGet())
.collect(Collectors.toList());
return PageResult.build(convert(result), param.getPageNum(), param.getPageSize());
}
/**
* filter with tableName and generate RowLock
*
* @param param the query param
* @param branchSession the branch session
* @return the RowLock list
*/
private Stream<RowLock> filterAndMap(GlobalLockParam param, BranchSession branchSession) {
final String tableName = param.getTableName();
// get rowLock from branchSession
final List<RowLock> rowLocks = LockerManagerFactory.getLockManager().collectRowLocks(branchSession);
if (StringUtils.isNotBlank(tableName)) {
return rowLocks.parallelStream().filter(rowLock -> rowLock.getTableName().contains(param.getTableName()));
}
return rowLocks.stream();
}
/**
* check the param
*
* @param param the param
*/
private void checkParam(GlobalLockParam param) {
if (param.getPageSize() <= 0 || param.getPageNum() <= 0) {
throw new IllegalArgumentException("wrong pageSize or pageNum");
}
// verification data type
try {
Long.parseLong(param.getTransactionId());
} catch (NumberFormatException e) {
param.setTransactionId(null);
}
try {
Long.parseLong(param.getBranchId());
} catch (NumberFormatException e) {
param.setBranchId(null);
}
}
/**
* obtain the branch session condition
*
* @param param condition for query branch session
* @return the filter condition
*/
private Predicate<? super BranchSession> obtainBranchSessionPredicate(GlobalLockParam param) {
return branchSession -> {
// transactionId
return (isBlank(param.getTransactionId()) ||
String.valueOf(branchSession.getTransactionId()).contains(param.getTransactionId()))
&&
// branch id
(isBlank(param.getBranchId()) ||
String.valueOf(branchSession.getBranchId()).contains(param.getBranchId()))
;
};
}
/**
* obtain the global session condition
*
* @param param condition for query global session
* @return the filter condition
*/
private Predicate<? super GlobalSession> obtainGlobalSessionPredicate(GlobalLockParam param) {
return globalSession -> {
// first, there must be withBranchSession
return CollectionUtils.isNotEmpty(globalSession.getBranchSessions())
&&
// The second is other conditions
// xid
(isBlank(param.getXid()) || globalSession.getXid().contains(param.getXid()))
&&
// timeStart
(isNull(param.getTimeStart()) || param.getTimeStart() <= globalSession.getBeginTime())
&&
// timeEnd
(isNull(param.getTimeEnd()) || param.getTimeEnd() >= globalSession.getBeginTime());
};
}
}
@@ -0,0 +1,102 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed 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://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.
*/
package io.seata.server.console.impl.file;
import io.seata.console.result.PageResult;
import io.seata.server.console.param.GlobalSessionParam;
import io.seata.server.console.service.GlobalSessionService;
import io.seata.server.console.vo.GlobalSessionVO;
import io.seata.server.session.GlobalSession;
import io.seata.server.session.SessionHolder;
import io.seata.server.storage.SessionConverter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Component;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import static io.seata.common.util.StringUtils.isBlank;
import static java.util.Objects.isNull;
/**
* Global Session File ServiceImpl
*
* @author zhongxiang.wang
* @author miaoxueyu
*/
@Component
@org.springframework.context.annotation.Configuration
@ConditionalOnExpression("#{'file'.equals('${sessionMode}')}")
public class GlobalSessionFileServiceImpl implements GlobalSessionService {
@Override
public PageResult<GlobalSessionVO> query(GlobalSessionParam param) {
if (param.getPageSize() <= 0 || param.getPageNum() <= 0) {
throw new IllegalArgumentException("wrong pageSize or pageNum");
}
final Collection<GlobalSession> allSessions = SessionHolder.getRootSessionManager().allSessions();
final List<GlobalSession> filteredSessions = allSessions
.parallelStream()
.filter(obtainPredicate(param))
.collect(Collectors.toList());
return PageResult.build(SessionConverter.convertGlobalSession(filteredSessions), param.getPageNum(), param.getPageSize());
}
/**
* obtain the condition
*
* @param param condition for query global session
* @return the filter condition
*/
private Predicate<? super GlobalSession> obtainPredicate(GlobalSessionParam param) {
return session -> {
return
// xid
(isBlank(param.getXid()) || session.getXid().contains(param.getXid()))
&&
// applicationId
(isBlank(param.getApplicationId()) || session.getApplicationId().contains(param.getApplicationId()))
&&
// status
(isNull(param.getStatus()) || Objects.equals(session.getStatus().getCode(), param.getStatus()))
&&
// transactionName
(isBlank(param.getTransactionName()) || session.getTransactionName().contains(param.getTransactionName()))
&&
// timeStart
(isNull(param.getTimeStart()) || param.getTimeStart() <= session.getBeginTime())
&&
// timeEnd
(isNull(param.getTimeEnd()) || param.getTimeEnd() >= session.getBeginTime());
};
}
}
@@ -0,0 +1,65 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed 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://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.
*/
package io.seata.server.console.impl.redis;
import io.seata.common.util.CollectionUtils;
import io.seata.common.util.StringUtils;
import io.seata.console.result.PageResult;
import io.seata.core.store.BranchTransactionDO;
import io.seata.server.console.service.BranchSessionService;
import io.seata.server.console.vo.BranchSessionVO;
import io.seata.server.storage.redis.store.RedisTransactionStoreManager;
import org.springframework.beans.BeanUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
* Branch Session Redis ServiceImpl
*
* @author zhongxiang.wang
* @author doubleDimple
*/
@Component
@org.springframework.context.annotation.Configuration
@ConditionalOnExpression("#{'redis'.equals('${sessionMode}')}")
public class BranchSessionRedisServiceImpl implements BranchSessionService {
@Override
public PageResult<BranchSessionVO> queryByXid(String xid) {
if (StringUtils.isBlank(xid)) {
return PageResult.success();
}
List<BranchSessionVO> branchSessionVos = new ArrayList<>();
RedisTransactionStoreManager instance = RedisTransactionStoreManager.getInstance();
List<BranchTransactionDO> branchSessionDos = instance.findBranchSessionByXid(xid);
if (CollectionUtils.isNotEmpty(branchSessionDos)) {
for (BranchTransactionDO branchSessionDo : branchSessionDos) {
BranchSessionVO branchSessionVO = new BranchSessionVO();
BeanUtils.copyProperties(branchSessionDo, branchSessionVO);
branchSessionVos.add(branchSessionVO);
}
}
return PageResult.success(branchSessionVos, branchSessionVos.size(), 0, branchSessionVos.size());
}
}
@@ -0,0 +1,119 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed 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://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.
*/
package io.seata.server.console.impl.redis;
import io.seata.common.util.BeanUtils;
import io.seata.common.util.CollectionUtils;
import io.seata.console.result.PageResult;
import io.seata.server.console.param.GlobalLockParam;
import io.seata.server.console.service.GlobalLockService;
import io.seata.server.console.vo.GlobalLockVO;
import io.seata.server.storage.redis.JedisPooledFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import static io.seata.common.Constants.ROW_LOCK_KEY_SPLIT_CHAR;
import static io.seata.common.exception.FrameworkErrorCode.ParameterRequired;
import static io.seata.common.util.StringUtils.isNotBlank;
import static io.seata.console.result.PageResult.checkPage;
import static io.seata.core.constants.RedisKeyConstants.*;
/**
* Global Lock Redis Service Impl
* @author zhongxiang.wang
* @author doubleDimple
*/
@Component
@org.springframework.context.annotation.Configuration
@ConditionalOnExpression("#{'redis'.equals('${lockMode}')}")
public class GlobalLockRedisServiceImpl implements GlobalLockService {
@Override
public PageResult<GlobalLockVO> query(GlobalLockParam param) {
int total = 0;
List<GlobalLockVO> globalLockVos;
checkPage(param);
if (isNotBlank(param.getXid())) {
globalLockVos = queryGlobalByXid(param.getXid());
total = globalLockVos.size();
return PageResult.success(globalLockVos,total,param.getPageNum(),param.getPageSize());
} else if (isNotBlank(param.getTableName()) && isNotBlank(param.getPk()) && isNotBlank(param.getResourceId())) {
//SEATA_ROW_LOCK_jdbc:mysql://116.62.62.26/seata-order^^^order^^^2188
String tableName = param.getTableName();
String pk = param.getPk();
String resourceId = param.getResourceId();
globalLockVos = queryGlobalLockByRowKey(buildRowKey(tableName,pk,resourceId));
total = globalLockVos.size();
return PageResult.success(globalLockVos,total,param.getPageNum(),param.getPageSize());
} else {
return PageResult.failure(ParameterRequired.getErrCode(),"only three parameters of tableName,pk,resourceId or Xid are supported");
}
}
private List<GlobalLockVO> queryGlobalLockByRowKey(String buildRowKey) {
return readGlobalLockByRowKey(buildRowKey);
}
private String buildRowKey(String tableName, String pk,String resourceId) {
return DEFAULT_REDIS_SEATA_ROW_LOCK_PREFIX + resourceId + SPLIT + tableName + SPLIT + pk;
}
private List<GlobalLockVO> queryGlobalByXid(String xid) {
return readGlobalLockByXid(DEFAULT_REDIS_SEATA_GLOBAL_LOCK_PREFIX + xid);
}
private List<GlobalLockVO> readGlobalLockByXid(String key) {
List<GlobalLockVO> vos = new ArrayList<>();
try (Jedis jedis = JedisPooledFactory.getJedisInstance()) {
Map<String, String> mapGlobalKeys = jedis.hgetAll(key);
if (CollectionUtils.isNotEmpty(mapGlobalKeys)) {
List<String> rowLockKeys = new ArrayList<>();
mapGlobalKeys.forEach((k,v) -> rowLockKeys.addAll(Arrays.asList(v.split(ROW_LOCK_KEY_SPLIT_CHAR))));
for (String rowLoclKey : rowLockKeys) {
Map<String, String> mapRowLockKey = jedis.hgetAll(rowLoclKey);
GlobalLockVO vo = (GlobalLockVO)BeanUtils.mapToObject(mapRowLockKey, GlobalLockVO.class);
if (vo != null) {
vos.add(vo);
}
}
}
}
return vos;
}
private List<GlobalLockVO> readGlobalLockByRowKey(String key) {
List<GlobalLockVO> vos = new ArrayList<>();
try (Jedis jedis = JedisPooledFactory.getJedisInstance()) {
Map<String, String> map = jedis.hgetAll(key);
GlobalLockVO vo = (GlobalLockVO)BeanUtils.mapToObject(map, GlobalLockVO.class);
if (vo != null) {
vos.add(vo);
}
}
return vos;
}
}
@@ -0,0 +1,110 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed 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://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.
*/
package io.seata.server.console.impl.redis;
import io.seata.common.util.CollectionUtils;
import io.seata.console.result.PageResult;
import io.seata.core.model.GlobalStatus;
import io.seata.server.console.param.GlobalSessionParam;
import io.seata.server.console.service.GlobalSessionService;
import io.seata.server.console.vo.GlobalSessionVO;
import io.seata.server.session.GlobalSession;
import io.seata.server.session.SessionCondition;
import io.seata.server.storage.redis.store.RedisTransactionStoreManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import static io.seata.common.exception.FrameworkErrorCode.ParameterRequired;
import static io.seata.common.util.StringUtils.isBlank;
import static io.seata.common.util.StringUtils.isNotBlank;
import static io.seata.console.result.PageResult.checkPage;
import static io.seata.server.storage.SessionConverter.convertToGlobalSessionVo;
/**
* Global Session Redis ServiceImpl
* @author zhongxiang.wang
* @author doubleDimple
*/
@Component
@org.springframework.context.annotation.Configuration
@ConditionalOnExpression("#{'redis'.equals('${sessionMode}')}")
public class GlobalSessionRedisServiceImpl implements GlobalSessionService {
private static final Logger LOGGER = LoggerFactory.getLogger(GlobalSessionRedisServiceImpl.class);
@Override
public PageResult<GlobalSessionVO> query(GlobalSessionParam param) {
List<GlobalSessionVO> result = new ArrayList<>();
Long total = 0L;
if (param.getTimeStart() != null || param.getTimeEnd() != null) {
//not support time range query
LOGGER.debug("not supported according to time range query");
return PageResult.failure(ParameterRequired.getErrCode(),"not supported according to time range query");
}
List<GlobalSession> globalSessions = new ArrayList<>();
RedisTransactionStoreManager instance = RedisTransactionStoreManager.getInstance();
checkPage(param);
if (isBlank(param.getXid()) && param.getStatus() == null) {
total = instance.countByGlobalSessions(GlobalStatus.values());
globalSessions = instance.findGlobalSessionByPage(param.getPageNum(), param.getPageSize(),param.isWithBranch());
} else {
List<GlobalSession> globalSessionsNew = new ArrayList<>();
if (isNotBlank(param.getXid())) {
SessionCondition sessionCondition = new SessionCondition();
sessionCondition.setXid(param.getXid());
sessionCondition.setLazyLoadBranch(!param.isWithBranch());
globalSessions = instance.readSession(sessionCondition);
total = (long)globalSessions.size();
}
if (param.getStatus() != null && GlobalStatus.get(param.getStatus()) != null) {
if (CollectionUtils.isNotEmpty(globalSessions)) {
globalSessionsNew = globalSessions.stream().filter(globalSession -> globalSession.getStatus().getCode() == (param.getStatus())).collect(Collectors.toList());
total = (long)globalSessionsNew.size();
} else {
total = instance.countByGlobalSessions(new GlobalStatus[] {GlobalStatus.get(param.getStatus())});
globalSessionsNew = instance.readSessionStatusByPage(param);
}
}
if (LOGGER.isDebugEnabled()) {
if (isNotBlank(param.getApplicationId())) {
//not support
LOGGER.debug("not supported according to applicationId query");
}
if (isNotBlank(param.getTransactionName())) {
//not support
LOGGER.debug("not supported according to transactionName query");
}
}
globalSessions = globalSessionsNew.size() > 0 ? globalSessionsNew : globalSessions;
}
convertToGlobalSessionVo(result,globalSessions);
return PageResult.success(result,total.intValue(),param.getPageNum(),param.getPageSize());
}
}
@@ -0,0 +1,114 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed 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://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.
*/
package io.seata.server.console.param;
import io.seata.console.param.BaseParam;
import java.io.Serializable;
/**
* Global lock param
* @author zhongxiang.wang
*/
public class GlobalLockParam extends BaseParam implements Serializable {
private static final long serialVersionUID = 615412528070131284L;
/**
* the xid
*/
private String xid;
/**
* the table name
*/
private String tableName;
/**
* the transaction id
*/
private String transactionId;
/**
* the branch id
*/
private String branchId;
/**
* the primary Key
*/
private String pk;
/**
* the resourceId
*/
private String resourceId;
public String getTransactionId() {
return transactionId;
}
public void setTransactionId(String transactionId) {
this.transactionId = transactionId;
}
public String getBranchId() {
return branchId;
}
public void setBranchId(String branchId) {
this.branchId = branchId;
}
public String getXid() {
return xid;
}
public void setXid(String xid) {
this.xid = xid;
}
public String getTableName() {
return tableName;
}
public void setTableName(String tableName) {
this.tableName = tableName;
}
public String getPk() {
return pk;
}
public void setPk(String pk) {
this.pk = pk;
}
public String getResourceId() {
return resourceId;
}
public void setResourceId(String resourceId) {
this.resourceId = resourceId;
}
@Override
public String toString() {
return "GlobalLockParam{" +
"xid='" + xid + '\'' +
", tableName='" + tableName + '\'' +
", transactionId='" + transactionId + '\'' +
", branchId='" + branchId + '\'' +
", pk='" + pk + '\'' +
", resourceId='" + resourceId + '\'' +
'}';
}
}
@@ -0,0 +1,102 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed 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://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.
*/
package io.seata.server.console.param;
import io.seata.console.param.BaseParam;
import java.io.Serializable;
/**
* Global session param
* @author zhongxiang.wang
*/
public class GlobalSessionParam extends BaseParam implements Serializable {
private static final long serialVersionUID = 115488252809011284L;
/**
* the xid
*/
private String xid;
/**
* the application id
*/
private String applicationId;
/**
* the global session status
*/
private Integer status;
/**
* the transaction name
*/
private String transactionName;
/**
* if with branch
* true: with branch session
* false: no branch session
*/
private boolean withBranch;
public String getXid() {
return xid;
}
public void setXid(String xid) {
this.xid = xid;
}
public String getTransactionName() {
return transactionName;
}
public void setTransactionName(String transactionName) {
this.transactionName = transactionName;
}
public String getApplicationId() {
return applicationId;
}
public void setApplicationId(String applicationId) {
this.applicationId = applicationId;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public boolean isWithBranch() {
return withBranch;
}
public void setWithBranch(boolean withBranch) {
this.withBranch = withBranch;
}
@Override
public String toString() {
return "GlobalSessionParam{" +
"xid='" + xid + '\'' +
", applicationId='" + applicationId + '\'' +
", status=" + status +
", transactionName='" + transactionName + '\'' +
", withBranch=" + withBranch +
'}';
}
}
@@ -0,0 +1,34 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed 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://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.
*/
package io.seata.server.console.service;
import io.seata.console.result.PageResult;
import io.seata.server.console.vo.BranchSessionVO;
/**
* Branch session service
* @author wangzhongxiang
*/
public interface BranchSessionService {
/**
* Query branch session by xid
* @param xid the xid
* @return the BranchSessionVO list
*/
PageResult<BranchSessionVO> queryByXid(String xid);
}
@@ -0,0 +1,37 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed 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://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.
*/
package io.seata.server.console.service;
import io.seata.console.result.PageResult;
import io.seata.server.console.param.GlobalLockParam;
import io.seata.server.console.vo.GlobalLockVO;
/**
* Global lock service
* @author wangzhongxiang
*/
public interface GlobalLockService {
/**
* Query locks by param
* @param param the param
* @return the list of GlobalLockVO
*/
PageResult<GlobalLockVO> query(GlobalLockParam param);
}
@@ -0,0 +1,35 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed 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://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.
*/
package io.seata.server.console.service;
import io.seata.console.result.PageResult;
import io.seata.server.console.param.GlobalSessionParam;
import io.seata.server.console.vo.GlobalSessionVO;
/**
* Global session service
* @author wangzhongxiang
*/
public interface GlobalSessionService {
/**
* Query global session
* @param param the param
* @return the GlobalSessionVO list
*/
PageResult<GlobalSessionVO> query(GlobalSessionParam param);
}
@@ -0,0 +1,241 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed 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://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.
*/
package io.seata.server.console.vo;
import io.seata.core.constants.ServerTableColumnsName;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Objects;
/**
* BranchSessionVO
* @author zhongxiang.wang
*/
public class BranchSessionVO {
private String xid;
private String transactionId;
private String branchId;
private String resourceGroupId;
private String resourceId;
private String branchType;
private Integer status;
private String clientId;
private String applicationData;
private Long gmtCreate;
private Long gmtModified;
public BranchSessionVO(){
}
public BranchSessionVO(String xid,
Long transactionId,
Long branchId,
String resourceGroupId,
String resourceId,
String branchType,
Integer status,
String clientId,
String applicationData) {
this.xid = xid;
this.transactionId = String.valueOf(transactionId);
this.branchId = String.valueOf(branchId);
this.resourceGroupId = resourceGroupId;
this.resourceId = resourceId;
this.branchType = branchType;
this.status = status;
this.clientId = clientId;
this.applicationData = applicationData;
}
public String getXid() {
return xid;
}
public void setXid(String xid) {
this.xid = xid;
}
public String getTransactionId() {
return transactionId;
}
public void setTransactionId(Long transactionId) {
this.transactionId = String.valueOf(transactionId);
}
public String getBranchId() {
return branchId;
}
public void setBranchId(Long branchId) {
this.branchId = String.valueOf(branchId);
}
public String getResourceGroupId() {
return resourceGroupId;
}
public void setResourceGroupId(String resourceGroupId) {
this.resourceGroupId = resourceGroupId;
}
public String getResourceId() {
return resourceId;
}
public void setResourceId(String resourceId) {
this.resourceId = resourceId;
}
public String getBranchType() {
return branchType;
}
public void setBranchType(String branchType) {
this.branchType = branchType;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public String getClientId() {
return clientId;
}
public void setClientId(String clientId) {
this.clientId = clientId;
}
public String getApplicationData() {
return applicationData;
}
public void setApplicationData(String applicationData) {
this.applicationData = applicationData;
}
public Long getGmtCreate() {
return gmtCreate;
}
public void setGmtCreate(Long gmtCreate) {
this.gmtCreate = gmtCreate;
}
public Long getGmtModified() {
return gmtModified;
}
public void setGmtModified(Long gmtModified) {
this.gmtModified = gmtModified;
}
public static BranchSessionVO convert(ResultSet rs) throws SQLException {
BranchSessionVO branchSessionVO = new BranchSessionVO();
branchSessionVO.setXid(rs.getString(ServerTableColumnsName.BRANCH_TABLE_XID));
branchSessionVO.setTransactionId(rs.getLong(ServerTableColumnsName.BRANCH_TABLE_TRANSACTION_ID));
branchSessionVO.setBranchId(rs.getLong(ServerTableColumnsName.BRANCH_TABLE_BRANCH_ID));
branchSessionVO.setResourceGroupId(rs.getString(ServerTableColumnsName.BRANCH_TABLE_RESOURCE_GROUP_ID));
branchSessionVO.setResourceId(rs.getString(ServerTableColumnsName.BRANCH_TABLE_RESOURCE_ID));
branchSessionVO.setBranchType(rs.getString(ServerTableColumnsName.BRANCH_TABLE_BRANCH_TYPE));
branchSessionVO.setStatus(rs.getInt(ServerTableColumnsName.BRANCH_TABLE_STATUS));
branchSessionVO.setClientId(rs.getString(ServerTableColumnsName.BRANCH_TABLE_CLIENT_ID));
branchSessionVO.setApplicationData(rs.getString(ServerTableColumnsName.BRANCH_TABLE_APPLICATION_DATA));
Date gmtCreateTimestamp = rs.getDate(ServerTableColumnsName.BRANCH_TABLE_GMT_CREATE);
if (gmtCreateTimestamp != null) {
branchSessionVO.setGmtCreate(gmtCreateTimestamp.getTime());
}
Date gmtModifiedTimestamp = rs.getDate(ServerTableColumnsName.BRANCH_TABLE_GMT_MODIFIED);
if (gmtModifiedTimestamp != null) {
branchSessionVO.setGmtModified(gmtModifiedTimestamp.getTime());
}
return branchSessionVO;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
BranchSessionVO that = (BranchSessionVO) o;
return Objects.equals(xid, that.xid)
&& Objects.equals(transactionId, that.transactionId)
&& Objects.equals(branchId, that.branchId)
&& Objects.equals(resourceGroupId, that.resourceGroupId)
&& Objects.equals(resourceId, that.resourceId)
&& Objects.equals(branchType, that.branchType)
&& Objects.equals(status, that.status)
&& Objects.equals(clientId, that.clientId)
&& Objects.equals(applicationData, that.applicationData)
&& Objects.equals(gmtCreate, that.gmtCreate)
&& Objects.equals(gmtModified, that.gmtModified);
}
@Override
public int hashCode() {
return Objects.hash(xid,
transactionId,
branchId,
resourceGroupId,
resourceId,
branchType,
status,
clientId,
applicationData,
gmtCreate,
gmtModified);
}
@Override
public String toString() {
return "BranchSessionVO{" +
"xid='" + xid + '\'' +
", transactionId=" + transactionId +
", branchId=" + branchId +
", resourceGroupId='" + resourceGroupId + '\'' +
", resourceId='" + resourceId + '\'' +
", branchType='" + branchType + '\'' +
", status=" + status +
", clientId='" + clientId + '\'' +
", applicationData='" + applicationData + '\'' +
", gmtCreate=" + gmtCreate +
", gmtModified=" + gmtModified +
'}';
}
}
@@ -0,0 +1,196 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed 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://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.
*/
package io.seata.server.console.vo;
import io.seata.common.util.CollectionUtils;
import io.seata.core.constants.ServerTableColumnsName;
import io.seata.core.lock.RowLock;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* GlobalLockVO
* @author zhongxiang.wang
* @author miaoxueyu
*/
public class GlobalLockVO {
private String xid;
private String transactionId;
private String branchId;
private String resourceId;
private String tableName;
private String pk;
private String rowKey;
private Long gmtCreate;
private Long gmtModified;
/**
* convert RowLock list to GlobalLockVO list
* @param rowLocks the RowLock list
* @return the GlobalLockVO list
*/
public static List<GlobalLockVO> convert(List<RowLock> rowLocks) {
if (CollectionUtils.isEmpty(rowLocks)) {
return Collections.emptyList();
}
final List<GlobalLockVO> result = new ArrayList<>(rowLocks.size());
for (RowLock rowLock : rowLocks) {
result.add(convert(rowLock));
}
return result;
}
/**
* convert RowLock to GlobalLockVO
* @param rowLock the RowLock
* @return the GlobalLockVO
*/
public static GlobalLockVO convert(RowLock rowLock) {
final GlobalLockVO globalLockVO = new GlobalLockVO();
globalLockVO.setXid(rowLock.getXid());
globalLockVO.setTransactionId(rowLock.getTransactionId());
globalLockVO.setBranchId(rowLock.getBranchId());
globalLockVO.setResourceId(rowLock.getResourceId());
globalLockVO.setTableName(rowLock.getTableName());
globalLockVO.setPk(rowLock.getPk());
globalLockVO.setRowKey(rowLock.getRowKey());
return globalLockVO;
}
public String getXid() {
return xid;
}
public void setXid(String xid) {
this.xid = xid;
}
public String getTransactionId() {
return transactionId;
}
public void setTransactionId(Long transactionId) {
this.transactionId = String.valueOf(transactionId);
}
public String getBranchId() {
return branchId;
}
public void setBranchId(Long branchId) {
this.branchId = String.valueOf(branchId);
}
public String getResourceId() {
return resourceId;
}
public void setResourceId(String resourceId) {
this.resourceId = resourceId;
}
public String getTableName() {
return tableName;
}
public void setTableName(String tableName) {
this.tableName = tableName;
}
public String getPk() {
return pk;
}
public void setPk(String pk) {
this.pk = pk;
}
public String getRowKey() {
return rowKey;
}
public void setRowKey(String rowKey) {
this.rowKey = rowKey;
}
public Long getGmtCreate() {
return gmtCreate;
}
public void setGmtCreate(Long gmtCreate) {
this.gmtCreate = gmtCreate;
}
public Long getGmtModified() {
return gmtModified;
}
public void setGmtModified(Long gmtModified) {
this.gmtModified = gmtModified;
}
public static GlobalLockVO convert(ResultSet rs) throws SQLException {
GlobalLockVO globalLockVO = new GlobalLockVO();
globalLockVO.setRowKey(rs.getString(ServerTableColumnsName.LOCK_TABLE_ROW_KEY));
globalLockVO.setXid(rs.getString(ServerTableColumnsName.LOCK_TABLE_XID));
globalLockVO.setTransactionId(rs.getLong(ServerTableColumnsName.LOCK_TABLE_TRANSACTION_ID));
globalLockVO.setBranchId(rs.getLong(ServerTableColumnsName.LOCK_TABLE_BRANCH_ID));
globalLockVO.setResourceId(rs.getString(ServerTableColumnsName.LOCK_TABLE_RESOURCE_ID));
globalLockVO.setTableName(rs.getString(ServerTableColumnsName.LOCK_TABLE_TABLE_NAME));
globalLockVO.setPk(rs.getString(ServerTableColumnsName.LOCK_TABLE_PK));
Timestamp gmtCreateTimestamp = rs.getTimestamp(ServerTableColumnsName.LOCK_TABLE_GMT_CREATE);
if (gmtCreateTimestamp != null) {
globalLockVO.setGmtCreate(gmtCreateTimestamp.getTime());
}
Timestamp gmtModifiedTimestamp = rs.getTimestamp(ServerTableColumnsName.LOCK_TABLE_GMT_MODIFIED);
if (gmtModifiedTimestamp != null) {
globalLockVO.setGmtModified(gmtModifiedTimestamp.getTime());
}
return globalLockVO;
}
@Override
public String toString() {
return "GlobalLockVO{" +
"xid='" + xid + '\'' +
", transactionId=" + transactionId +
", branchId=" + branchId +
", resourceId='" + resourceId + '\'' +
", tableName='" + tableName + '\'' +
", pk='" + pk + '\'' +
", rowKey='" + rowKey + '\'' +
", gmtCreate=" + gmtCreate +
", gmtModified=" + gmtModified +
'}';
}
}
@@ -0,0 +1,217 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed 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://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.
*/
package io.seata.server.console.vo;
import io.seata.core.constants.ServerTableColumnsName;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Set;
/**
* GlobalSessionVO
* @author zhongxiang.wang
*/
public class GlobalSessionVO {
private String xid;
private String transactionId;
private Integer status;
private String applicationId;
private String transactionServiceGroup;
private String transactionName;
private Long timeout;
private Long beginTime;
private String applicationData;
private Long gmtCreate;
private Long gmtModified;
private Set<BranchSessionVO> branchSessionVOs;
public GlobalSessionVO() {
}
public GlobalSessionVO(String xid,
Long transactionId,
Integer status,
String applicationId,
String transactionServiceGroup,
String transactionName,
Long timeout,
Long beginTime,
String applicationData,
Set<BranchSessionVO> branchSessionVOs) {
this.xid = xid;
this.transactionId = String.valueOf(transactionId);
this.status = status;
this.applicationId = applicationId;
this.transactionServiceGroup = transactionServiceGroup;
this.transactionName = transactionName;
this.timeout = timeout;
this.beginTime = beginTime;
this.applicationData = applicationData;
this.branchSessionVOs = branchSessionVOs;
}
public String getXid() {
return xid;
}
public void setXid(String xid) {
this.xid = xid;
}
public String getTransactionId() {
return transactionId;
}
public void setTransactionId(Long transactionId) {
this.transactionId = String.valueOf(transactionId);
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public String getApplicationId() {
return applicationId;
}
public void setApplicationId(String applicationId) {
this.applicationId = applicationId;
}
public String getTransactionServiceGroup() {
return transactionServiceGroup;
}
public void setTransactionServiceGroup(String transactionServiceGroup) {
this.transactionServiceGroup = transactionServiceGroup;
}
public String getTransactionName() {
return transactionName;
}
public void setTransactionName(String transactionName) {
this.transactionName = transactionName;
}
public Long getTimeout() {
return timeout;
}
public void setTimeout(Long timeout) {
this.timeout = timeout;
}
public Long getBeginTime() {
return beginTime;
}
public void setBeginTime(Long beginTime) {
this.beginTime = beginTime;
}
public String getApplicationData() {
return applicationData;
}
public void setApplicationData(String applicationData) {
this.applicationData = applicationData;
}
public Long getGmtCreate() {
return gmtCreate;
}
public void setGmtCreate(Long gmtCreate) {
this.gmtCreate = gmtCreate;
}
public Long getGmtModified() {
return gmtModified;
}
public void setGmtModified(Long gmtModified) {
this.gmtModified = gmtModified;
}
public Set<BranchSessionVO> getBranchSessionVOs() {
return branchSessionVOs;
}
public void setBranchSessionVOs(Set<BranchSessionVO> branchSessionVOs) {
this.branchSessionVOs = branchSessionVOs;
}
public static GlobalSessionVO convert(ResultSet rs) throws SQLException {
GlobalSessionVO globalSessionVO = new GlobalSessionVO();
globalSessionVO.setXid(rs.getString(ServerTableColumnsName.GLOBAL_TABLE_XID));
globalSessionVO.setTransactionId(rs.getLong(ServerTableColumnsName.GLOBAL_TABLE_TRANSACTION_ID));
globalSessionVO.setStatus(rs.getInt(ServerTableColumnsName.GLOBAL_TABLE_STATUS));
globalSessionVO.setApplicationId(rs.getString(ServerTableColumnsName.GLOBAL_TABLE_APPLICATION_ID));
globalSessionVO.setTransactionServiceGroup(rs.getString(ServerTableColumnsName.GLOBAL_TABLE_TRANSACTION_SERVICE_GROUP));
globalSessionVO.setTransactionName(rs.getString(ServerTableColumnsName.GLOBAL_TABLE_TRANSACTION_NAME));
globalSessionVO.setTimeout(rs.getLong(ServerTableColumnsName.GLOBAL_TABLE_TIMEOUT));
globalSessionVO.setBeginTime(rs.getLong(ServerTableColumnsName.GLOBAL_TABLE_BEGIN_TIME));
globalSessionVO.setApplicationData(rs.getString(ServerTableColumnsName.GLOBAL_TABLE_APPLICATION_DATA));
Timestamp gmtCreateTimestamp = rs.getTimestamp(ServerTableColumnsName.GLOBAL_TABLE_GMT_CREATE);
if (gmtCreateTimestamp != null) {
globalSessionVO.setGmtCreate(gmtCreateTimestamp.getTime());
}
Timestamp gmtModifiedTimestamp = rs.getTimestamp(ServerTableColumnsName.GLOBAL_TABLE_GMT_MODIFIED);
if (gmtModifiedTimestamp != null) {
globalSessionVO.setGmtModified(gmtModifiedTimestamp.getTime());
}
return globalSessionVO;
}
@Override
public String toString() {
return "GlobalSessionVO{" +
"xid='" + xid + '\'' +
", transactionId=" + transactionId +
", status=" + status +
", applicationId='" + applicationId + '\'' +
", transactionServiceGroup='" + transactionServiceGroup + '\'' +
", transactionName='" + transactionName + '\'' +
", timeout=" + timeout +
", beginTime=" + beginTime +
", applicationData='" + applicationData + '\'' +
", gmtCreate=" + gmtCreate +
", gmtModified=" + gmtModified +
", branchSessionVOs=" + branchSessionVOs +
'}';
}
}