Unverified Commit 8358a14f authored by aiwenmo's avatar aiwenmo Committed by GitHub

[Optimization-1761][admin,core,web] Remove shared session (#1762)

* [Optimization-1761][admin,core,web] Remove shared session * Set python udf configuration --------- Co-authored-by: 's avatarwenmo <32723967+wenmo@users.noreply.github.com>
parent f0179b40
...@@ -21,7 +21,6 @@ package org.dinky.controller; ...@@ -21,7 +21,6 @@ package org.dinky.controller;
import org.dinky.assertion.Asserts; import org.dinky.assertion.Asserts;
import org.dinky.common.result.Result; import org.dinky.common.result.Result;
import org.dinky.dto.SessionDTO;
import org.dinky.dto.StudioCADTO; import org.dinky.dto.StudioCADTO;
import org.dinky.dto.StudioDDLDTO; import org.dinky.dto.StudioDDLDTO;
import org.dinky.dto.StudioExecuteDTO; import org.dinky.dto.StudioExecuteDTO;
...@@ -35,15 +34,11 @@ import org.dinky.result.IResult; ...@@ -35,15 +34,11 @@ import org.dinky.result.IResult;
import org.dinky.result.SelectResult; import org.dinky.result.SelectResult;
import org.dinky.result.SqlExplainResult; import org.dinky.result.SqlExplainResult;
import org.dinky.service.StudioService; import org.dinky.service.StudioService;
import org.dinky.session.SessionInfo;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
...@@ -122,40 +117,6 @@ public class StudioController { ...@@ -122,40 +117,6 @@ public class StudioController {
: Result.succeed(lineage, "血缘分析成功"); : Result.succeed(lineage, "血缘分析成功");
} }
/** 创建session */
@PutMapping("/createSession")
public Result<SessionInfo> createSession(@RequestBody SessionDTO sessionDTO) {
return Result.succeed(studioService.createSession(sessionDTO, "admin"), "创建成功");
}
/** 清除指定session */
@DeleteMapping("/clearSession")
public Result<String> clearSession(@RequestBody JsonNode para) {
if (para.size() <= 0) {
return Result.failed("请选择要清除的记录");
}
List<String> error = new ArrayList<>();
for (final JsonNode item : para) {
String session = item.asText();
if (!studioService.clearSession(session)) {
error.add(session);
}
}
if (error.isEmpty()) {
return Result.succeed("清除成功");
} else {
return Result.succeed(String.format("清除部分成功,但%s清除失败,共%d次失败。", error, error.size()));
}
}
/** 获取session列表 */
@GetMapping("/listSession")
public Result<List<SessionInfo>> listSession() {
return Result.succeed(studioService.listSession("admin"), "获取成功");
}
/** 获取flinkJobs列表 */ /** 获取flinkJobs列表 */
@GetMapping("/listJobs") @GetMapping("/listJobs")
public Result<JsonNode[]> listJobs(@RequestParam Integer clusterId) { public Result<JsonNode[]> listJobs(@RequestParam Integer clusterId) {
......
...@@ -165,7 +165,6 @@ public class TaskController { ...@@ -165,7 +165,6 @@ public class TaskController {
@PostMapping("/rollbackTask") @PostMapping("/rollbackTask")
public Result<Void> rollbackTask(@RequestBody TaskRollbackVersionDTO dto) { public Result<Void> rollbackTask(@RequestBody TaskRollbackVersionDTO dto) {
return taskService.rollbackTask(dto); return taskService.rollbackTask(dto);
} }
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
package org.dinky.service; package org.dinky.service;
import org.dinky.dto.SessionDTO;
import org.dinky.dto.SqlDTO; import org.dinky.dto.SqlDTO;
import org.dinky.dto.StudioCADTO; import org.dinky.dto.StudioCADTO;
import org.dinky.dto.StudioDDLDTO; import org.dinky.dto.StudioDDLDTO;
...@@ -33,7 +32,6 @@ import org.dinky.model.Schema; ...@@ -33,7 +32,6 @@ import org.dinky.model.Schema;
import org.dinky.result.IResult; import org.dinky.result.IResult;
import org.dinky.result.SelectResult; import org.dinky.result.SelectResult;
import org.dinky.result.SqlExplainResult; import org.dinky.result.SqlExplainResult;
import org.dinky.session.SessionInfo;
import java.util.List; import java.util.List;
...@@ -62,12 +60,6 @@ public interface StudioService { ...@@ -62,12 +60,6 @@ public interface StudioService {
SelectResult getJobData(String jobId); SelectResult getJobData(String jobId);
SessionInfo createSession(SessionDTO sessionDTO, String createUser);
boolean clearSession(String session);
List<SessionInfo> listSession(String createUser);
LineageResult getLineage(StudioCADTO studioCADTO); LineageResult getLineage(StudioCADTO studioCADTO);
List<JsonNode> listJobs(Integer clusterId); List<JsonNode> listJobs(Integer clusterId);
......
...@@ -23,7 +23,6 @@ import org.dinky.api.FlinkAPI; ...@@ -23,7 +23,6 @@ import org.dinky.api.FlinkAPI;
import org.dinky.assertion.Asserts; import org.dinky.assertion.Asserts;
import org.dinky.config.Dialect; import org.dinky.config.Dialect;
import org.dinky.dto.AbstractStatementDTO; import org.dinky.dto.AbstractStatementDTO;
import org.dinky.dto.SessionDTO;
import org.dinky.dto.SqlDTO; import org.dinky.dto.SqlDTO;
import org.dinky.dto.StudioCADTO; import org.dinky.dto.StudioCADTO;
import org.dinky.dto.StudioDDLDTO; import org.dinky.dto.StudioDDLDTO;
...@@ -60,9 +59,6 @@ import org.dinky.service.FragmentVariableService; ...@@ -60,9 +59,6 @@ import org.dinky.service.FragmentVariableService;
import org.dinky.service.SavepointsService; import org.dinky.service.SavepointsService;
import org.dinky.service.StudioService; import org.dinky.service.StudioService;
import org.dinky.service.TaskService; import org.dinky.service.TaskService;
import org.dinky.session.SessionConfig;
import org.dinky.session.SessionInfo;
import org.dinky.session.SessionPool;
import org.dinky.sql.FlinkQuery; import org.dinky.sql.FlinkQuery;
import org.dinky.utils.RunTimeUtil; import org.dinky.utils.RunTimeUtil;
...@@ -335,41 +331,6 @@ public class StudioServiceImpl implements StudioService { ...@@ -335,41 +331,6 @@ public class StudioServiceImpl implements StudioService {
return JobManager.getJobData(jobId); return JobManager.getJobData(jobId);
} }
@Override
public SessionInfo createSession(SessionDTO sessionDTO, String createUser) {
if (sessionDTO.isUseRemote()) {
Cluster cluster = clusterService.getById(sessionDTO.getClusterId());
SessionConfig sessionConfig =
SessionConfig.build(
sessionDTO.getType(),
true,
cluster.getId(),
cluster.getAlias(),
clusterService.buildEnvironmentAddress(
true, sessionDTO.getClusterId()));
return JobManager.createSession(sessionDTO.getSession(), sessionConfig, createUser);
} else {
SessionConfig sessionConfig =
SessionConfig.build(
sessionDTO.getType(),
false,
null,
null,
clusterService.buildEnvironmentAddress(false, null));
return JobManager.createSession(sessionDTO.getSession(), sessionConfig, createUser);
}
}
@Override
public boolean clearSession(String session) {
return SessionPool.remove(session) > 0;
}
@Override
public List<SessionInfo> listSession(String createUser) {
return JobManager.listSession(createUser);
}
@Override @Override
public LineageResult getLineage(StudioCADTO studioCADTO) { public LineageResult getLineage(StudioCADTO studioCADTO) {
ProcessEntity process = ProcessEntity process =
......
...@@ -25,7 +25,6 @@ import org.dinky.executor.ExecutorSetting; ...@@ -25,7 +25,6 @@ import org.dinky.executor.ExecutorSetting;
import org.dinky.gateway.GatewayType; import org.dinky.gateway.GatewayType;
import org.dinky.gateway.config.GatewayConfig; import org.dinky.gateway.config.GatewayConfig;
import org.dinky.gateway.config.SavePointStrategy; import org.dinky.gateway.config.SavePointStrategy;
import org.dinky.session.SessionConfig;
import org.apache.flink.configuration.CoreOptions; import org.apache.flink.configuration.CoreOptions;
import org.apache.flink.configuration.RestOptions; import org.apache.flink.configuration.RestOptions;
...@@ -262,14 +261,6 @@ public class JobConfig { ...@@ -262,14 +261,6 @@ public class JobConfig {
config); config);
} }
public void setSessionConfig(SessionConfig sessionConfig) {
if (sessionConfig != null) {
address = sessionConfig.getAddress();
clusterId = sessionConfig.getClusterId();
useRemote = sessionConfig.isUseRemote();
}
}
public void buildGatewayConfig(Map<String, Object> config) { public void buildGatewayConfig(Map<String, Object> config) {
gatewayConfig = GatewayConfig.build(config); gatewayConfig = GatewayConfig.build(config);
if (config.containsKey("flinkConfig") if (config.containsKey("flinkConfig")
......
...@@ -58,10 +58,6 @@ import org.dinky.result.InsertResult; ...@@ -58,10 +58,6 @@ import org.dinky.result.InsertResult;
import org.dinky.result.ResultBuilder; import org.dinky.result.ResultBuilder;
import org.dinky.result.ResultPool; import org.dinky.result.ResultPool;
import org.dinky.result.SelectResult; import org.dinky.result.SelectResult;
import org.dinky.session.ExecutorEntity;
import org.dinky.session.SessionConfig;
import org.dinky.session.SessionInfo;
import org.dinky.session.SessionPool;
import org.dinky.trans.Operations; import org.dinky.trans.Operations;
import org.dinky.utils.LogUtil; import org.dinky.utils.LogUtil;
import org.dinky.utils.SqlUtil; import org.dinky.utils.SqlUtil;
...@@ -122,7 +118,6 @@ public class JobManager { ...@@ -122,7 +118,6 @@ public class JobManager {
private ExecutorSetting executorSetting; private ExecutorSetting executorSetting;
private JobConfig config; private JobConfig config;
private Executor executor; private Executor executor;
private Configuration configuration;
private boolean useGateway = false; private boolean useGateway = false;
private boolean isPlanMode = false; private boolean isPlanMode = false;
private boolean useStatementSet = false; private boolean useStatementSet = false;
...@@ -220,7 +215,6 @@ public class JobManager { ...@@ -220,7 +215,6 @@ public class JobManager {
if (!runMode.equals(GatewayType.LOCAL) && !useGateway && config.isUseRemote()) { if (!runMode.equals(GatewayType.LOCAL) && !useGateway && config.isUseRemote()) {
executor = executor =
Executor.buildRemoteExecutor(environmentSetting, config.getExecutorSetting()); Executor.buildRemoteExecutor(environmentSetting, config.getExecutorSetting());
return executor;
} else { } else {
if (ArrayUtil.isNotEmpty(config.getJarFiles())) { if (ArrayUtil.isNotEmpty(config.getJarFiles())) {
config.getExecutorSetting() config.getExecutorSetting()
...@@ -231,26 +225,7 @@ public class JobManager { ...@@ -231,26 +225,7 @@ public class JobManager {
.map(FileUtil::getAbsolutePath) .map(FileUtil::getAbsolutePath)
.collect(Collectors.joining(","))); .collect(Collectors.joining(",")));
} }
executor = Executor.buildLocalExecutor(config.getExecutorSetting()); executor = Executor.buildLocalExecutor(config.getExecutorSetting());
return executor;
}
}
private Executor createExecutorWithSession() {
if (config.isUseSession()) {
ExecutorEntity executorEntity = SessionPool.get(config.getSession());
if (Asserts.isNotNull(executorEntity)) {
executor = executorEntity.getExecutor();
config.setSessionConfig(executorEntity.getSessionConfig());
initEnvironmentSetting();
executor.update(executorSetting);
} else {
createExecutor();
SessionPool.push(new ExecutorEntity(config.getSession(), executor));
}
} else {
createExecutor();
} }
executor.getSqlManager().registerSqlFragment(config.getVariables()); executor.getSqlManager().registerSqlFragment(config.getVariables());
return executor; return executor;
...@@ -278,8 +253,7 @@ public class JobManager { ...@@ -278,8 +253,7 @@ public class JobManager {
sqlSeparator = SystemConfiguration.getInstances().getSqlSeparator(); sqlSeparator = SystemConfiguration.getInstances().getSqlSeparator();
initExecutorSetting(); initExecutorSetting();
createExecutorWithSession(); createExecutor();
return false; return false;
} }
...@@ -725,31 +699,6 @@ public class JobManager { ...@@ -725,31 +699,6 @@ public class JobManager {
return ResultPool.get(jobId); return ResultPool.get(jobId);
} }
public static SessionInfo createSession(
String session, SessionConfig sessionConfig, String createUser) {
if (SessionPool.exist(session)) {
return SessionPool.getInfo(session);
}
Executor sessionExecutor = null;
if (sessionConfig.isUseRemote()) {
sessionExecutor =
Executor.buildRemoteExecutor(
EnvironmentSetting.build(sessionConfig.getAddress()),
ExecutorSetting.DEFAULT);
} else {
sessionExecutor = Executor.buildLocalExecutor(sessionConfig.getExecutorSetting());
}
ExecutorEntity executorEntity =
new ExecutorEntity(
session, sessionConfig, createUser, LocalDateTime.now(), sessionExecutor);
SessionPool.push(executorEntity);
return SessionInfo.build(executorEntity);
}
public static List<SessionInfo> listSession(String createUser) {
return SessionPool.filter(createUser);
}
public ExplainResult explainSql(String statement) { public ExplainResult explainSql(String statement) {
return Explainer.build(executor, useStatementSet, sqlSeparator) return Explainer.build(executor, useStatementSet, sqlSeparator)
.initialize(this, config, statement) .initialize(this, config, statement)
...@@ -829,7 +778,6 @@ public class JobManager { ...@@ -829,7 +778,6 @@ public class JobManager {
job.setStatus(Job.JobStatus.FAILED); job.setStatus(Job.JobStatus.FAILED);
failed(); failed();
} }
} catch (Exception e) { } catch (Exception e) {
String error = String error =
LogUtil.getError( LogUtil.getError(
......
/*
*
* 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://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 org.dinky.session;
import org.dinky.executor.Executor;
import java.time.LocalDateTime;
import lombok.Getter;
import lombok.Setter;
/**
* FlinkEntity
*
* @author wenmo
* @since 2021/5/25 14:45
*/
@Setter
@Getter
public class ExecutorEntity {
private String sessionId;
private SessionConfig sessionConfig;
private String createUser;
private LocalDateTime createTime;
private Executor executor;
public ExecutorEntity(String sessionId, Executor executor) {
this.sessionId = sessionId;
this.executor = executor;
}
public ExecutorEntity(
String sessionId,
SessionConfig sessionConfig,
String createUser,
LocalDateTime createTime,
Executor executor) {
this.sessionId = sessionId;
this.sessionConfig = sessionConfig;
this.createUser = createUser;
this.createTime = createTime;
this.executor = executor;
}
}
/*
*
* 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://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 org.dinky.session;
import org.dinky.executor.ExecutorSetting;
import lombok.Getter;
import lombok.Setter;
/**
* SessionConfig
*
* @author wenmo
* @since 2021/7/6 21:59
*/
@Getter
@Setter
public class SessionConfig {
private SessionType type;
private boolean useRemote;
private Integer clusterId;
private String clusterName;
private String address;
public enum SessionType {
PUBLIC,
PRIVATE
}
public SessionConfig(
SessionType type,
boolean useRemote,
Integer clusterId,
String clusterName,
String address) {
this.type = type;
this.useRemote = useRemote;
this.clusterId = clusterId;
this.clusterName = clusterName;
this.address = address;
}
public static SessionConfig build(
String type, boolean useRemote, Integer clusterId, String clusterName, String address) {
return new SessionConfig(
SessionType.valueOf(type), useRemote, clusterId, clusterName, address);
}
public ExecutorSetting getExecutorSetting() {
return new ExecutorSetting(true);
}
}
/*
*
* 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://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 org.dinky.session;
import java.time.LocalDateTime;
import lombok.Getter;
import lombok.Setter;
/**
* SessionInfo
*
* @author wenmo
* @since 2021/7/6 22:22
*/
@Setter
@Getter
public class SessionInfo {
private String session;
private SessionConfig sessionConfig;
private String createUser;
private LocalDateTime createTime;
public SessionInfo(
String session,
SessionConfig sessionConfig,
String createUser,
LocalDateTime createTime) {
this.session = session;
this.sessionConfig = sessionConfig;
this.createUser = createUser;
this.createTime = createTime;
}
public static SessionInfo build(ExecutorEntity executorEntity) {
return new SessionInfo(
executorEntity.getSessionId(),
executorEntity.getSessionConfig(),
executorEntity.getCreateUser(),
executorEntity.getCreateTime());
}
}
/*
*
* 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://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 org.dinky.session;
import org.dinky.constant.FlinkConstant;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
/**
* SessionPool
*
* @author wenmo
* @since 2021/5/25 14:32
*/
public class SessionPool {
private static volatile List<ExecutorEntity> executorList =
new Vector<>(FlinkConstant.DEFAULT_SESSION_COUNT);
public static boolean exist(String sessionId) {
for (ExecutorEntity executorEntity : executorList) {
if (executorEntity.getSessionId().equals(sessionId)) {
return true;
}
}
return false;
}
public static Integer push(ExecutorEntity executorEntity) {
if (executorList.size()
>= FlinkConstant.DEFAULT_SESSION_COUNT * FlinkConstant.DEFAULT_FACTOR) {
executorList.remove(0);
} else if (executorList.size() >= FlinkConstant.DEFAULT_SESSION_COUNT) {
executorList.clear();
}
executorList.add(executorEntity);
return executorList.size();
}
public static Integer remove(String sessionId) {
int count = executorList.size();
for (int i = 0; i < executorList.size(); i++) {
if (sessionId.equals(executorList.get(i).getSessionId())) {
executorList.remove(i);
break;
}
}
return count - executorList.size();
}
public static ExecutorEntity get(String sessionId) {
for (ExecutorEntity executorEntity : executorList) {
if (executorEntity.getSessionId().equals(sessionId)) {
return executorEntity;
}
}
return null;
}
public static List<ExecutorEntity> list() {
return executorList;
}
public static List<SessionInfo> filter(String createUser) {
List<SessionInfo> sessionInfos = new ArrayList<>();
for (ExecutorEntity item : executorList) {
if (item.getSessionConfig().getType() == SessionConfig.SessionType.PUBLIC) {
sessionInfos.add(SessionInfo.build(item));
} else {
if (createUser != null && createUser.equals(item.getCreateUser())) {
sessionInfos.add(SessionInfo.build(item));
}
}
}
return sessionInfos;
}
public static SessionInfo getInfo(String sessionId) {
ExecutorEntity executorEntity = get(sessionId);
if (executorEntity != null) {
return SessionInfo.build(executorEntity);
} else {
return null;
}
}
}
...@@ -42,7 +42,6 @@ import org.apache.flink.table.api.ExplainDetail; ...@@ -42,7 +42,6 @@ import org.apache.flink.table.api.ExplainDetail;
import org.apache.flink.table.api.StatementSet; import org.apache.flink.table.api.StatementSet;
import org.apache.flink.table.api.TableConfig; import org.apache.flink.table.api.TableConfig;
import org.apache.flink.table.api.TableResult; import org.apache.flink.table.api.TableResult;
import org.apache.flink.table.catalog.CatalogManager;
import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.UserGroupInformation;
import java.io.IOException; import java.io.IOException;
...@@ -73,7 +72,7 @@ public abstract class Executor { ...@@ -73,7 +72,7 @@ public abstract class Executor {
private static final Logger logger = LoggerFactory.getLogger(Executor.class); private static final Logger logger = LoggerFactory.getLogger(Executor.class);
protected StreamExecutionEnvironment environment; protected StreamExecutionEnvironment environment;
protected CustomTableEnvironment stEnvironment; protected CustomTableEnvironment tableEnvironment;
protected EnvironmentSetting environmentSetting; protected EnvironmentSetting environmentSetting;
protected ExecutorSetting executorSetting; protected ExecutorSetting executorSetting;
protected Map<String, Object> setConfig = new HashMap<>(); protected Map<String, Object> setConfig = new HashMap<>();
...@@ -137,7 +136,7 @@ public abstract class Executor { ...@@ -137,7 +136,7 @@ public abstract class Executor {
} }
public CustomTableEnvironment getCustomTableEnvironment() { public CustomTableEnvironment getCustomTableEnvironment() {
return stEnvironment; return tableEnvironment;
} }
public ExecutorSetting getExecutorSetting() { public ExecutorSetting getExecutorSetting() {
...@@ -157,7 +156,7 @@ public abstract class Executor { ...@@ -157,7 +156,7 @@ public abstract class Executor {
} }
public TableConfig getTableConfig() { public TableConfig getTableConfig() {
return stEnvironment.getConfig(); return tableEnvironment.getConfig();
} }
public String getTimeZone() { public String getTimeZone() {
...@@ -166,61 +165,32 @@ public abstract class Executor { ...@@ -166,61 +165,32 @@ public abstract class Executor {
protected void init() { protected void init() {
initEnvironment(); initEnvironment();
initStreamExecutionEnvironment(); initExecutionEnvironment();
}
public void update(ExecutorSetting executorSetting) {
updateEnvironment(executorSetting);
updateStreamExecutionEnvironment(executorSetting);
} }
public void initEnvironment() { public void initEnvironment() {
updateEnvironment(executorSetting);
}
public void updateEnvironment(ExecutorSetting executorSetting) {
if (executorSetting.isValidParallelism()) { if (executorSetting.isValidParallelism()) {
environment.setParallelism(executorSetting.getParallelism()); environment.setParallelism(executorSetting.getParallelism());
} }
if (executorSetting.isValidConfig()) {
if (executorSetting.getConfig() != null) { environment
Configuration configuration = Configuration.fromMap(executorSetting.getConfig()); .getConfig()
environment.getConfig().configure(configuration, null); .configure(Configuration.fromMap(executorSetting.getConfig()), null);
} }
} }
abstract CustomTableEnvironment createCustomTableEnvironment(); abstract CustomTableEnvironment createCustomTableEnvironment();
private void initStreamExecutionEnvironment() { private void initExecutionEnvironment() {
updateStreamExecutionEnvironment(executorSetting);
}
private void updateStreamExecutionEnvironment(ExecutorSetting executorSetting) {
useSqlFragment = executorSetting.isUseSqlFragment(); useSqlFragment = executorSetting.isUseSqlFragment();
CustomTableEnvironment newestEnvironment = createCustomTableEnvironment(); tableEnvironment = createCustomTableEnvironment();
if (stEnvironment != null) { Configuration configuration = tableEnvironment.getConfig().getConfiguration();
for (String catalog : stEnvironment.listCatalogs()) {
stEnvironment
.getCatalog(catalog)
.ifPresent(
t -> {
newestEnvironment
.getCatalogManager()
.unregisterCatalog(catalog, true);
newestEnvironment.registerCatalog(catalog, t);
});
}
}
stEnvironment = newestEnvironment;
final Configuration configuration = stEnvironment.getConfig().getConfiguration();
if (executorSetting.isValidJobName()) { if (executorSetting.isValidJobName()) {
configuration.setString(PipelineOptions.NAME.key(), executorSetting.getJobName()); configuration.setString(PipelineOptions.NAME.key(), executorSetting.getJobName());
setConfig.put(PipelineOptions.NAME.key(), executorSetting.getJobName());
} }
if (executorSetting.isValidConfig()) {
setConfig.put(PipelineOptions.NAME.key(), executorSetting.getJobName());
if (executorSetting.getConfig() != null) {
for (Map.Entry<String, String> entry : executorSetting.getConfig().entrySet()) { for (Map.Entry<String, String> entry : executorSetting.getConfig().entrySet()) {
configuration.setString(entry.getKey(), entry.getValue()); configuration.setString(entry.getKey(), entry.getValue());
} }
...@@ -251,7 +221,7 @@ public abstract class Executor { ...@@ -251,7 +221,7 @@ public abstract class Executor {
} }
if (!flinkInterceptorResult.isNoExecute()) { if (!flinkInterceptorResult.isNoExecute()) {
this.loginFromKeytabIfNeed(); this.loginFromKeytabIfNeed();
return stEnvironment.executeSql(statement); return tableEnvironment.executeSql(statement);
} else { } else {
return CustomTableResultImpl.TABLE_RESULT_OK; return CustomTableResultImpl.TABLE_RESULT_OK;
} }
...@@ -328,12 +298,9 @@ public abstract class Executor { ...@@ -328,12 +298,9 @@ public abstract class Executor {
if (udfPyFilePath == null || udfPyFilePath.length == 0) { if (udfPyFilePath == null || udfPyFilePath.length == 0) {
return; return;
} }
Map<String, String> config = executorSetting.getConfig(); Configuration configuration = tableEnvironment.getConfig().getConfiguration();
if (Asserts.isNotNull(config)) { configuration.setString(PythonOptions.PYTHON_FILES, String.join(",", udfPyFilePath));
config.put(PythonOptions.PYTHON_FILES.key(), String.join(",", udfPyFilePath)); configuration.setString(PythonOptions.PYTHON_CLIENT_EXECUTABLE, executable);
config.put(PythonOptions.PYTHON_CLIENT_EXECUTABLE.key(), executable);
}
update(executorSetting);
} }
public String explainSql(String statement, ExplainDetail... extraDetails) { public String explainSql(String statement, ExplainDetail... extraDetails) {
...@@ -342,29 +309,20 @@ public abstract class Executor { ...@@ -342,29 +309,20 @@ public abstract class Executor {
return ""; return "";
} }
return stEnvironment.explainSql(statement, extraDetails); return tableEnvironment.explainSql(statement, extraDetails);
} }
public SqlExplainResult explainSqlRecord(String statement, ExplainDetail... extraDetails) { public SqlExplainResult explainSqlRecord(String statement, ExplainDetail... extraDetails) {
statement = pretreatStatement(statement); statement = pretreatStatement(statement);
if (Asserts.isNotNullString(statement) && !pretreatExecute(statement).isNoExecute()) { if (Asserts.isNotNullString(statement) && !pretreatExecute(statement).isNoExecute()) {
return stEnvironment.explainSqlRecord(statement, extraDetails); return tableEnvironment.explainSqlRecord(statement, extraDetails);
} }
return null; return null;
} }
public ObjectNode getStreamGraph(String statement) {
statement = pretreatStatement(statement);
if (pretreatExecute(statement).isNoExecute()) {
return null;
}
return stEnvironment.getStreamGraph(statement);
}
public ObjectNode getStreamGraph(List<String> statements) { public ObjectNode getStreamGraph(List<String> statements) {
StreamGraph streamGraph = stEnvironment.getStreamGraphFromInserts(statements); StreamGraph streamGraph = tableEnvironment.getStreamGraphFromInserts(statements);
return getStreamGraphJsonNode(streamGraph); return getStreamGraphJsonNode(streamGraph);
} }
...@@ -390,13 +348,12 @@ public abstract class Executor { ...@@ -390,13 +348,12 @@ public abstract class Executor {
for (String statement : statements) { for (String statement : statements) {
executeSql(statement); executeSql(statement);
} }
StreamGraph streamGraph = getStreamGraph(); StreamGraph streamGraph = getStreamGraph();
return getStreamGraphJsonNode(streamGraph); return getStreamGraphJsonNode(streamGraph);
} }
public JobPlanInfo getJobPlanInfo(List<String> statements) { public JobPlanInfo getJobPlanInfo(List<String> statements) {
return stEnvironment.getJobPlanInfo(statements); return tableEnvironment.getJobPlanInfo(statements);
} }
public JobPlanInfo getJobPlanInfoFromDataStream(List<String> statements) { public JobPlanInfo getJobPlanInfoFromDataStream(List<String> statements) {
...@@ -407,20 +364,12 @@ public abstract class Executor { ...@@ -407,20 +364,12 @@ public abstract class Executor {
return new JobPlanInfo(JsonPlanGenerator.generatePlan(streamGraph.getJobGraph())); return new JobPlanInfo(JsonPlanGenerator.generatePlan(streamGraph.getJobGraph()));
} }
public CatalogManager getCatalogManager() {
return stEnvironment.getCatalogManager();
}
public JobGraph getJobGraphFromInserts(List<String> statements) { public JobGraph getJobGraphFromInserts(List<String> statements) {
return stEnvironment.getJobGraphFromInserts(statements); return tableEnvironment.getJobGraphFromInserts(statements);
}
public StatementSet createStatementSet() {
return stEnvironment.createStatementSet();
} }
public TableResult executeStatementSet(List<String> statements) { public TableResult executeStatementSet(List<String> statements) {
StatementSet statementSet = stEnvironment.createStatementSet(); StatementSet statementSet = tableEnvironment.createStatementSet();
for (String item : statements) { for (String item : statements) {
statementSet.addInsertSql(item); statementSet.addInsertSql(item);
} }
...@@ -428,7 +377,7 @@ public abstract class Executor { ...@@ -428,7 +377,7 @@ public abstract class Executor {
} }
public String explainStatementSet(List<String> statements) { public String explainStatementSet(List<String> statements) {
StatementSet statementSet = stEnvironment.createStatementSet(); StatementSet statementSet = tableEnvironment.createStatementSet();
for (String item : statements) { for (String item : statements) {
statementSet.addInsertSql(item); statementSet.addInsertSql(item);
} }
...@@ -444,10 +393,10 @@ public abstract class Executor { ...@@ -444,10 +393,10 @@ public abstract class Executor {
} }
public boolean parseAndLoadConfiguration(String statement) { public boolean parseAndLoadConfiguration(String statement) {
return stEnvironment.parseAndLoadConfiguration(statement, environment, setConfig); return tableEnvironment.parseAndLoadConfiguration(statement, environment, setConfig);
} }
public List<LineageRel> getLineage(String statement) { public List<LineageRel> getLineage(String statement) {
return stEnvironment.getLineage(statement); return tableEnvironment.getLineage(statement);
} }
} }
...@@ -179,11 +179,15 @@ public class ExecutorSetting { ...@@ -179,11 +179,15 @@ public class ExecutorSetting {
} }
public boolean isValidParallelism() { public boolean isValidParallelism() {
return this.getParallelism() != null && this.getParallelism() > 0; return Asserts.isNotNull(this.getParallelism()) && this.getParallelism() > 0;
} }
public boolean isValidJobName() { public boolean isValidJobName() {
return this.getJobName() != null && !"".equals(this.getJobName()); return Asserts.isNotNullString(this.getJobName());
}
public boolean isValidConfig() {
return Asserts.isNotNullMap(this.getConfig());
} }
@Override @Override
......
/*
*
* 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://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.
*
*/
import React, {useState} from 'react';
import {Button, Form, Input, Modal, Select, Switch, Tag} from 'antd';
import {SessionItem} from '../data.d';
import {connect} from "umi";
import {StateType} from "@/pages/DataStudio/model";
import {l} from "@/utils/intl";
export type UpdateFormProps = {
onCancel: (flag?: boolean, formVals?: Partial<SessionItem>) => void;
onSubmit: (values: Partial<SessionItem>) => void;
updateModalVisible: boolean;
values: Partial<SessionItem>;
};
const {Item} = Form;
const {Option} = Select;
const formLayout = {
labelCol: {span: 7},
wrapperCol: {span: 13},
};
const SessionForm: React.FC<UpdateFormProps> = (props) => {
const [formVals, setFormVals] = useState<Partial<SessionItem>>({
session: props.values.session,
type: props.values.type,
useRemote: props.values.useRemote,
clusterId: props.values.clusterId,
});
const {cluster} = props;
const [form] = Form.useForm();
const {
onSubmit: handleUpdate,
onCancel: handleUpdateModalVisible,
updateModalVisible,
values,
} = props;
const submitForm = async () => {
const fieldsValue = await form.validateFields();
setFormVals({...formVals, ...fieldsValue});
handleUpdate({...formVals, ...fieldsValue});
};
const getClusterOptions = () => {
let itemList = [(<Option value={0} label={(<><Tag color="default">Local</Tag>本地环境</>)}>
<Tag color="default">Local</Tag>
本地环境
</Option>)];
for (let item of cluster) {
let tag = (<><Tag
color={item.enabled ? "processing" : "error"}>{item.type}</Tag>{item.name}</>);
itemList.push(<Option value={item.id} label={tag}>
{tag}
</Option>)
}
return itemList;
};
const renderContent = () => {
return (
<>
<Item
name="session"
label="名称"
rules={[{required: true, message: '请输入唯一名称!'}]}>
<Input placeholder="请输入"/>
</Item>
<Item
name="type"
label="访问权限"
>
<Select defaultValue="PUBLIC">
<Option value="PUBLIC">共享</Option>
<Option value="PRIVATE">私密</Option>
</Select>
</Item>
<Item
name="useRemote"
label="是否远程"
>
<Switch checkedChildren={l('button.enable')} unCheckedChildren={l('button.disable')}
defaultChecked={formVals.useRemote}/>
</Item>
<Item
name="clusterId"
label="集群"
>
<Select
style={{width: '100%'}}
placeholder="选择Flink集群"
optionLabelProp="label"
>
{getClusterOptions()}
</Select>
</Item>
</>
);
};
const renderFooter = () => {
return (
<>
<Button onClick={() => handleUpdateModalVisible(false, values)}>{l('button.cancel')}</Button>
<Button type="primary" onClick={() => submitForm()}>
{l('button.finish')}
</Button>
</>
);
};
return (
<Modal
width={640}
bodyStyle={{padding: '32px 40px 48px'}}
destroyOnClose
title={'创建新会话'}
visible={updateModalVisible}
footer={renderFooter()}
onCancel={() => handleUpdateModalVisible()}
>
<Form
{...formLayout}
form={form}
initialValues={{
session: formVals.session,
type: formVals.type,
useRemote: formVals.useRemote,
clusterId: formVals.clusterId,
}}
>
{renderContent()}
</Form>
</Modal>
);
};
export default connect(({Studio}: { Studio: StateType }) => ({
cluster: Studio.cluster,
}))(SessionForm);
/*
*
* 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://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.
*
*/
export type SessionItem = {
session: string,
type:string,
useRemote:boolean,
clusterId:number,
clusterName:string,
address:string,
createUser: string,
createTime: string,
};
/*
*
* 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://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.
*
*/
@import '~antd/lib/style/themes/default.less';
.session-path{
line-height: 32px;
}
...@@ -17,13 +17,11 @@ ...@@ -17,13 +17,11 @@
* *
*/ */
import {Tabs} from "antd"; import {Tabs} from "antd";
import {AppstoreOutlined, BarsOutlined, InsertRowAboveOutlined, MessageOutlined} from "@ant-design/icons"; import {AppstoreOutlined, BarsOutlined, InsertRowAboveOutlined} from "@ant-design/icons";
import {StateType} from "@/pages/DataStudio/model"; import {StateType} from "@/pages/DataStudio/model";
import {connect} from "umi"; import {connect} from "umi";
import StudioTree from "../StudioTree"; import StudioTree from "../StudioTree";
import StudioConnector from "./StudioConnector";
import StudioMetaData from "./StudioMetaData"; import StudioMetaData from "./StudioMetaData";
import StudioMetaStore from "./StudioMetaStore"; import StudioMetaStore from "./StudioMetaStore";
import {l} from "@/utils/intl"; import {l} from "@/utils/intl";
...@@ -43,9 +41,6 @@ const StudioLeftTool = (props: any) => { ...@@ -43,9 +41,6 @@ const StudioLeftTool = (props: any) => {
key="MetaStore"> key="MetaStore">
<StudioMetaStore/> <StudioMetaStore/>
</TabPane> </TabPane>
<TabPane tab={<span><MessageOutlined/> {l('pages.datastudio.label.session')}</span>} key="Connectors">
<StudioConnector/>
</TabPane>
<TabPane tab={<span><AppstoreOutlined/> {l('pages.datastudio.label.meta')}</span>} key="MetaData"> <TabPane tab={<span><AppstoreOutlined/> {l('pages.datastudio.label.meta')}</span>} key="MetaData">
<StudioMetaData/> <StudioMetaData/>
</TabPane> </TabPane>
......
...@@ -367,7 +367,6 @@ export default { ...@@ -367,7 +367,6 @@ export default {
'pages.datastudio.label.directory': 'Directory', 'pages.datastudio.label.directory': 'Directory',
'pages.datastudio.label.structure': 'Structure', 'pages.datastudio.label.structure': 'Structure',
'pages.datastudio.label.session': 'Session',
'pages.datastudio.label.cluster': 'Cluster', 'pages.datastudio.label.cluster': 'Cluster',
'pages.datastudio.label.datasource': 'Data Source', 'pages.datastudio.label.datasource': 'Data Source',
'pages.datastudio.label.meta': 'Meta Data', 'pages.datastudio.label.meta': 'Meta Data',
......
...@@ -367,7 +367,6 @@ export default { ...@@ -367,7 +367,6 @@ export default {
'pages.datastudio.label.directory': '目录', 'pages.datastudio.label.directory': '目录',
'pages.datastudio.label.structure': '结构', 'pages.datastudio.label.structure': '结构',
'pages.datastudio.label.session': '会话',
'pages.datastudio.label.cluster': '集群', 'pages.datastudio.label.cluster': '集群',
'pages.datastudio.label.datasource': '数据源', 'pages.datastudio.label.datasource': '数据源',
'pages.datastudio.label.meta': '元数据', 'pages.datastudio.label.meta': '元数据',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment