Browse Source

REPORT-114391 【微服务适配】远程&本地设计器能够正常启动

mss/2.0
Destiny.Lin 5 months ago
parent
commit
01601bd9fd
  1. 5
      designer-base/src/main/java/com/fr/design/backup/EnvBackupHelper.java
  2. 6
      designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionComboBoxPanel.java
  3. 57
      designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListPane.java
  4. 4
      designer-base/src/main/java/com/fr/design/data/datapane/connect/JDBCDefPane.java
  5. 67
      designer-base/src/main/java/com/fr/design/data/datapane/connect/LocalConnectionSource.java
  6. 11
      designer-base/src/main/java/com/fr/design/gui/ilist/TableViewList.java
  7. 19
      designer-realize/src/main/java/com/fanruan/boot/env/DesignEnvComponent.java
  8. 3
      designer-realize/src/main/java/com/fanruan/boot/env/function/DesignDatasourceComponent.java

5
designer-base/src/main/java/com/fr/design/backup/EnvBackupHelper.java

@ -5,6 +5,7 @@ import com.fanruan.config.realm.ConfigRepositoryFactory;
import com.fanruan.config.realm.local.LocalConfigRepositoryBuilder;
import com.fr.design.ConfigHelper;
import com.fr.design.mem.MemConfigBackupManager;
import com.fr.design.mem.MemConfigRepositoryBuilder;
import com.fr.log.FineLoggerFactory;
import com.fr.workspace.WorkContext;
import com.fr.workspace.Workspace;
@ -71,6 +72,10 @@ public class EnvBackupHelper {
} else {
// 如果是切到远程,先暂时用备份的内存配置,成功后再转到新配置,失败则切回原内存配置
MemConfigBackupManager.getInstance().startSwitch();
if (local) {
// 原来不是远程,需要先切一下内存配置框架
ConfigRepositoryFactory.getInstance().registerConfigRepositoryBuilder(new MemConfigRepositoryBuilder());
}
}
}

6
designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionComboBoxPanel.java

@ -13,8 +13,8 @@ import com.fr.design.gui.ibutton.UILockButton;
import com.fr.report.LockItem;
import com.fr.stable.StringUtils;
import com.fr.workspace.WorkContext;
import com.fr.workspace.server.connection.DBConnectAuth;
import com.fr.workspace.server.repository.authority.RemoteAuthorityRepository;
import com.fr.workspace.server.repository.connection.ConnectionRepository;
import javax.swing.SwingUtilities;
import java.awt.Dimension;
@ -80,7 +80,7 @@ public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel {
* 刷新ComboBox.items
*/
protected Iterator<String> items() {
Iterator<String> nameIt = ConnectionConfigProviderFactory.getConfigProvider().getConnections().keySet().iterator();
Iterator<String> nameIt = ConnectionRepository.getInstance().getConnNames().iterator();
Collection<String> noAuthConnections = RemoteAuthorityRepository.getInstance().getNoAuthConnections();
@ -94,7 +94,7 @@ public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel {
if (noAuthConnections.contains(conName)) {
continue;
}
Connection connection = ConnectionConfigProviderFactory.getConfigProvider().getConnection(conName);
Connection connection = ConnectionRepository.getInstance().getByName(conName).getConnection();
// nameList依赖items方法初始化,父类ItemEditableComboBoxPanel里异步执行item方法
filterConnection(connection, conName, nameList);
}

57
designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListPane.java

@ -3,12 +3,11 @@ package com.fr.design.data.datapane.connect;
import com.fanruan.config.impl.data.ConnectionConfigProviderFactory;
import com.fanruan.config.impl.data.ConnectionConfigWriterFactory;
import com.fr.config.remote.RemoteConfigEvent;
import com.fr.data.driver.DriverClassNotFoundException;
import com.fr.data.impl.Connection;
import com.fr.data.impl.JDBCDatabaseConnection;
import com.fr.data.impl.JNDIDatabaseConnection;
import com.fr.data.metric.utils.DatabaseConnectionMetricHandler;
import com.fr.data.operator.DataOperator;
import com.fr.decision.webservice.bean.datasource.ConnectionInfoBean;
import com.fr.decision.webservice.v10.datasource.connection.processor.impl.ConnectionProcessorFactory;
import com.fr.design.ExtraDesignClassManager;
import com.fr.design.data.MapCompareUtils;
import com.fr.design.dialog.BasicDialog;
@ -219,28 +218,26 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh
Arrays.stream(res).map(n -> (NameObject) n).forEach(no -> updatedMap.put(no.getName(), (Connection) no.getObject()));
List<String> removedConnNames = new ArrayList<>();
List<ConnectionBean> addConnections = new ArrayList<>();
List<ConnectionBean> updateConnection = new ArrayList<>();
List<ConnectionInfoBean> addConnections = new ArrayList<>();
List<ConnectionInfoBean> updateConnection = new ArrayList<>();
MapCompareUtils.contrastMapEntries(populatedConnectionsSnapshot, updatedMap, (entryEventKind, s, connection) -> {
try {
switch (entryEventKind) {
case REMOVED:
removedConnNames.add(s);
break;
case ADDED:
addConnections.add(new ConnectionBean(connection, s));
if (connection instanceof JDBCDatabaseConnection) {
DatabaseConnectionMetricHandler.handleSaveConnection((JDBCDatabaseConnection) connection, null);
}
addConnections.add(ConnectionProcessorFactory.createConnectionInfoBean(s, connection));
break;
case UPDATED:
updateConnection.add(new ConnectionBean(connection, s));
if (connection instanceof JDBCDatabaseConnection) {
DatabaseConnectionMetricHandler.handleSaveConnection((JDBCDatabaseConnection) connection, null);
}
updateConnection.add(ConnectionProcessorFactory.createConnectionInfoBean(s, connection));
break;
default:
break;
}
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}, new MapCompareUtils.UpdateRule<String, Connection>() {
@Override
public boolean needUpdate(Connection origin, Connection connection) {
@ -269,23 +266,22 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh
}
});
List<ConnectionBean> validateBeans = new ArrayList<>();
List<ConnectionInfoBean> validateBeans = new ArrayList<>();
validateBeans.addAll(addConnections);
validateBeans.addAll(updateConnection);
this.validateDatabaseType(validateBeans);
this.validateConnections(validateBeans);
this.alterConnections(new BatchConnectionModifyBean(addConnections, removedConnNames, updateConnection));
this.alterConnections(addConnections, removedConnNames, updateConnection);
}
/**
* 校验是否支持所有新增和修改数据连接的数据库类型
*/
public void validateDatabaseType(@NotNull List<ConnectionBean> addedOrUpdatedConnections) {
public void validateDatabaseType(@NotNull List<ConnectionInfoBean> addedOrUpdatedConnections) throws Exception {
Set<String> notSupportedConnections = new HashSet<>();
if (!addedOrUpdatedConnections.isEmpty()) {
for (ConnectionBean bean : addedOrUpdatedConnections) {
Connection connection = bean.getConnection();
// 仅校验jdbc连接,其他插件数据连接不进行校验
for (ConnectionInfoBean bean : addedOrUpdatedConnections) {
Connection connection = ConnectionProcessorFactory.createConnection(bean);
// 仅校验jdbc连接,其他插件数据连接不进行校验;
if (connection instanceof JDBCDatabaseConnection) {
DBTypes dataBaseTypePoint = DataBaseTypePointManager.getInstance().getDataBaseTypePoint(connection.getDriver(), connection.feature());
if (connectionIsNotSupported(connection, dataBaseTypePoint)) {
@ -322,25 +318,18 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh
}
private void validateConnections(List<ConnectionBean> addedOrUpdatedConnections) throws Exception {
private void alterConnections(List<ConnectionInfoBean> addConnections, List<String> removedConnNames, List<ConnectionInfoBean> updateConnection) {
for (ConnectionBean connectionBean : addedOrUpdatedConnections) {
Connection connection = connectionBean.getConnection();
try {
ConnectionRepository.getInstance().validSettings(new com.fr.workspace.server.entity.connection.ConnectionBean(connection));
} catch (DriverClassNotFoundException e) {
FineLoggerFactory.getLogger().info(e.getMessage());
} catch (Exception e) {
throw new SQLException(Toolkit.i18nText("Fine-Design_Basic_Database_Connection_Invalid_Config", connectionBean.getName()) + ", " + e.getMessage(), e.getCause());
for (ConnectionInfoBean bean : addConnections) {
ConnectionRepository.getInstance().add(bean);
}
for (ConnectionInfoBean bean : updateConnection) {
ConnectionRepository.getInstance().update(bean);
}
for (String name : removedConnNames) {
ConnectionRepository.getInstance().delete(new ConnectionInfoBean(name));
}
private void alterConnections(BatchConnectionModifyBean bean) {
try {
ConnectionRepository.getInstance().save(bean);
// hades:远程环境时,由于时直接RPC调用远程修改,因此设计器本地配置需要失效
if (!WorkContext.getCurrent().isLocal()) {
EventDispatcher.fire(RemoteConfigEvent.EDIT, "ConnectionConfig");

4
designer-base/src/main/java/com/fr/design/data/datapane/connect/JDBCDefPane.java

@ -451,8 +451,8 @@ public class JDBCDefPane extends JPanel {
jdbcDatabase.setPassword(new String(this.passwordTextField.getPassword()).trim());
jdbcDatabase.setOriginalCharsetName(this.originalCharSet);
if (this.charSetComboBox.getSelectedIndex() == 0) {
jdbcDatabase.setNewCharsetName(null);
jdbcDatabase.setOriginalCharsetName(null);
jdbcDatabase.setNewCharsetName(StringUtils.EMPTY);
jdbcDatabase.setOriginalCharsetName(StringUtils.EMPTY);
} else {
jdbcDatabase.setNewCharsetName(EncodeConstants.ENCODING_GBK);
jdbcDatabase.setOriginalCharsetName(((String) this.charSetComboBox.getSelectedItem()));

67
designer-base/src/main/java/com/fr/design/data/datapane/connect/LocalConnectionSource.java

@ -0,0 +1,67 @@
package com.fr.design.data.datapane.connect;
import com.fr.data.driver.DriverClassNotFoundException;
import com.fr.data.impl.Connection;
import com.fr.decision.webservice.bean.datasource.ConnectionInfoBean;
import com.fr.decision.webservice.v10.datasource.connection.processor.impl.ConnectionProcessorFactory;
import com.fr.design.i18n.Toolkit;
import com.fr.log.FineLoggerFactory;
import com.fr.workspace.server.repository.connection.BaseConnectionSource;
import java.sql.SQLException;
/**
* 本地Connection资源操作
*
* @author Destiny.Lin
* @since 11.0
* Created on 2024/5/29
*/
public class LocalConnectionSource extends BaseConnectionSource {
@Override
public void add(ConnectionInfoBean bean) throws Exception {
Connection connection = ConnectionProcessorFactory.createConnection(bean);
validate(bean.getConnectionName(), connection);
ConnectionProcessorFactory.addConnection(bean);
}
@Override
public void delete(ConnectionInfoBean bean) throws Exception {
ConnectionProcessorFactory.deleteConnection(bean.getConnectionName());
}
@Override
public void update(ConnectionInfoBean bean) throws Exception {
Connection connection = ConnectionProcessorFactory.createConnection(bean);
validate(bean.getConnectionName(), connection);
ConnectionProcessorFactory.updateConnection(bean.getConnectionName(), bean);
}
@Override
public boolean lock(String str) {
// 本地默认锁定成功,让其执行后续动作
return true;
}
@Override
public boolean unlock(String str) {
// 本地默认解锁成功
return true;
}
@Override
public boolean isLock(String str) {
// 本地默认未锁定
return false;
}
private void validate(String name, Connection connection) throws SQLException {
try {
connection.validateSettings();
} catch (DriverClassNotFoundException e) {
FineLoggerFactory.getLogger().info(e.getMessage());
} catch (Exception e) {
throw new SQLException(Toolkit.i18nText("Fine-Design_Basic_Database_Connection_Invalid_Config", name) + ", " + e.getMessage(), e.getCause());
}
}
}

11
designer-base/src/main/java/com/fr/design/gui/ilist/TableViewList.java

@ -15,6 +15,8 @@ import com.fr.general.ComparatorUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.ArrayUtils;
import com.fr.stable.StringUtils;
import com.fr.workspace.server.entity.connection.ConnectionBean;
import com.fr.workspace.server.repository.connection.ConnectionRepository;
import javax.swing.DefaultListCellRenderer;
import javax.swing.DefaultListModel;
@ -95,14 +97,19 @@ public class TableViewList extends UIList {
@Override
protected DefaultListModel doInBackground() throws Exception {
Connection datasource = ConnectionConfigProviderFactory.getConfigProvider().getConnection(databaseName);
Connection datasource = ConnectionRepository.getInstance().getByName(databaseName).getConnection();
boolean status = false;
int count = 3;
//总共给3次连接的机会
while (!status && count > 0) {
status = DataOperator.getInstance().testConnection(datasource);
try {
ConnectionRepository.getInstance().testConnection(new ConnectionBean(datasource));
status = true;
break;
} catch (Exception e) {
count--;
}
}
if (!status) {
throw new Exception(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Database_Connection_Failed"));
}

19
designer-realize/src/main/java/com/fanruan/boot/env/DesignEnvComponent.java vendored

@ -26,6 +26,7 @@ import com.fanruan.kv.factory.KVStoreFactory;
import com.fanruan.kv.manager.CarinaKVManager;
import com.fanruan.kv.store.KVStore;
import com.fanruan.kv.store.KVStoreHolder;
import com.fanruan.workplace.http.RepositoryManager;
import com.fr.cbb.dialect.security.InsecurityElementFactory;
import com.fr.cluster.ClusterBridge;
import com.fr.cluster.lock.ClusterLock;
@ -48,11 +49,6 @@ import com.fr.config.holder.ValidateConfigManger;
import com.fr.config.impl.ConfConfigProviderImpl;
import com.fr.config.impl.ConfigInsecurityElementProviderImpl;
import com.fr.decision.service.context.ServiceContext;
import com.fr.decision.webservice.v10.datasource.connection.processor.impl.ConnectionPluginProcessor;
import com.fr.decision.webservice.v10.datasource.connection.processor.impl.ConnectionProcessorFactory;
import com.fr.decision.webservice.v10.datasource.connection.processor.impl.JDBCConnectionProcessor;
import com.fr.decision.webservice.v10.datasource.connection.processor.impl.JDYConnectionProcessor;
import com.fr.decision.webservice.v10.datasource.connection.processor.impl.JNDIConnectionProcessor;
import com.fr.design.backup.EnvBackupHelper;
import com.fr.env.detect.EnvDetectorCenter;
import com.fr.event.EventDispatcher;
@ -79,6 +75,7 @@ import com.fr.scheduler.QuartzContext;
import com.fr.scheduler.SchedulerEvent;
import com.fr.scheduler.tenant.ScheduleThreadCurrentTenantProvider;
import com.fr.security.encryption.EncryptionInitialization;
import com.fr.security.encryption.SystemEncryptionManager;
import com.fr.security.encryption.core.EncryptionScaffold;
import com.fr.security.encryption.provider.SecuritySeedProvider;
import com.fr.security.encryption.storage.keys.LoadSeedSecurityKey;
@ -273,11 +270,11 @@ public class DesignEnvComponent {
private void startFileServer() throws Exception {
if (WorkContext.getCurrent().isLocal()) {
// 设计器远程下不需要文件系统,走PublicRepo的接口,本地下走基础的磁盘读写
LocalFileRepository localFileRepository = new LocalFileRepository(ProjectConstants.LOCAL_ENV, ServiceContext.getWebInfPath());
LocalFileRepository.getSingleton().setWorkRoot(ServiceContext.getWebInfPath());
ResourceRepository realRepo = RepositoryFactory.getRepo();
FSProperties fsProperties = Carina.properties(FSProperties.class);
FileServer.init(
new ResourceRepositoryWrapper(localFileRepository, StringUtils.EMPTY),
new ResourceRepositoryWrapper(LocalFileRepository.getSingleton(), StringUtils.EMPTY),
new ResourceRepositoryWrapper(realRepo, StringUtils.EMPTY),
new ResourceRepositoryWrapper(realRepo, StringUtils.EMPTY),
new ResourceRepositoryWrapper(realRepo.generateTenantsSharedRepo(fsProperties.getTenantsSharedNamespace()), StringUtils.EMPTY));
@ -383,6 +380,9 @@ public class DesignEnvComponent {
}
});
LoadSeedSecurityKey.getInstance().init();
} else {
// 远程也先写死加解密,放在内存中就好,fbp那边暂时没有提供扩展,两边都是写死的,等他们提供扩展后设计器再适配
SystemEncryptionManager.getInstance().restore();
}
}
@ -403,5 +403,10 @@ public class DesignEnvComponent {
private void startEnvPrepare() {
EnvDetectorCenter.getInstance().init();
if (WorkContext.getCurrent().isLocal()) {
// 如果是切回本地,要初始化成本地仓库
// 如果是切回远程,会在用户创建的时候就同步初始化远程仓库
RepositoryManager.getInstance().initLocalRepository();
}
}
}

3
designer-realize/src/main/java/com/fanruan/boot/env/function/DesignDatasourceComponent.java vendored

@ -15,7 +15,9 @@ import com.fr.decision.webservice.v10.datasource.connection.processor.impl.Conne
import com.fr.decision.webservice.v10.datasource.connection.processor.impl.JDBCConnectionProcessor;
import com.fr.decision.webservice.v10.datasource.connection.processor.impl.JDYConnectionProcessor;
import com.fr.decision.webservice.v10.datasource.connection.processor.impl.JNDIConnectionProcessor;
import com.fr.design.data.datapane.connect.LocalConnectionSource;
import com.fr.workspace.server.repository.connection.ConnectionWriterShell;
import com.fr.workspace.server.repository.connection.LocalConnectionShell;
/**
@ -40,6 +42,7 @@ public class DesignDatasourceComponent extends DatasourceComponent {
ConnectionProcessorFactory.register(JNDIConnectionProcessor.KEY);
ConnectionProcessorFactory.register(ConnectionPluginProcessor.KEY);
ConnectionProcessorFactory.register(JDYConnectionProcessor.KEY);
Carina.getApplicationContext().singleton(LocalConnectionShell.class).set(new LocalConnectionSource());
}
/**

Loading…
Cancel
Save