Unverified Commit f414c094 authored by YardStrong's avatar YardStrong Committed by GitHub

support custom flink/hadoop config for cluster configuration and fix the type…

support custom flink/hadoop config for cluster configuration and fix the type bug when auto regsiter session cluster (#2894) * fix the support for custom hadoop/flink config of cluster configuration * fix the registered cluster type after start yarn-session; fix the gateway type setting when start a flink job on yarn per-job mode * format code for cluster config * keep custom cluster config on yarn mode the same as on k8s mode --------- Co-authored-by: 's avatar苑强 <yuanqiang@bonc.com.cn>
parent ee0ffa4b
...@@ -231,7 +231,7 @@ public class ClusterInstanceServiceImpl extends SuperServiceImpl<ClusterInstance ...@@ -231,7 +231,7 @@ public class ClusterInstanceServiceImpl extends SuperServiceImpl<ClusterInstance
gatewayResult.getWebURL().replace("http://", ""), gatewayResult.getWebURL().replace("http://", ""),
gatewayResult.getId(), gatewayResult.getId(),
clusterCfg.getName() + "_" + LocalDateTime.now(), clusterCfg.getName() + "_" + LocalDateTime.now(),
clusterCfg.getName() + LocalDateTime.now(), gatewayConfig.getType().getLongValue(),
id, id,
null)); null));
} }
......
...@@ -225,6 +225,7 @@ public class JobConfig { ...@@ -225,6 +225,7 @@ public class JobConfig {
gatewayConfig = GatewayConfig.build(config); gatewayConfig = GatewayConfig.build(config);
gatewayConfig.setTaskId(getTaskId()); gatewayConfig.setTaskId(getTaskId());
gatewayConfig.setType(GatewayType.get(getType()));
} }
public void addGatewayConfig(Map<String, String> config) { public void addGatewayConfig(Map<String, String> config) {
......
...@@ -19,6 +19,13 @@ ...@@ -19,6 +19,13 @@
package org.dinky.gateway.config; package org.dinky.gateway.config;
import org.dinky.gateway.model.CustomConfig;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Getter; import lombok.Getter;
...@@ -55,6 +62,21 @@ public class ClusterConfig { ...@@ -55,6 +62,21 @@ public class ClusterConfig {
notes = "Path to the YARN configuration file") notes = "Path to the YARN configuration file")
private String hadoopConfigPath; private String hadoopConfigPath;
@ApiModelProperty(
value = "Additional hadoop configuration properties",
dataType = "List",
example = "[{\"name\":\"key1\",\"value\":\"value1\"}, {\"name\":\"key2\",\"value\":\"value2\"}]",
notes = "Additional hadoop configuration properties for the job on web page")
private List<CustomConfig> hadoopConfigList = new ArrayList<>();
@ApiModelProperty(
value = "Additional hadoop configuration properties",
dataType = "Map",
example = "{\"key1\":\"value1\",\"key2\":\"value2\"}",
notes = "Additional hadoop configuration properties for the job, invisible on web page",
hidden = true)
private Map<String, String> hadoopConfigMap = new HashMap<>();
@ApiModelProperty( @ApiModelProperty(
value = "YARN application ID", value = "YARN application ID",
dataType = "String", dataType = "String",
......
...@@ -22,6 +22,7 @@ package org.dinky.gateway.config; ...@@ -22,6 +22,7 @@ package org.dinky.gateway.config;
import org.dinky.assertion.Asserts; import org.dinky.assertion.Asserts;
import org.dinky.gateway.enums.ActionType; import org.dinky.gateway.enums.ActionType;
import org.dinky.gateway.enums.SavePointType; import org.dinky.gateway.enums.SavePointType;
import org.dinky.gateway.model.CustomConfig;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
...@@ -90,20 +91,20 @@ public class FlinkConfig { ...@@ -90,20 +91,20 @@ public class FlinkConfig {
notes = "Path to the savepoint") notes = "Path to the savepoint")
private String savePoint; private String savePoint;
@ApiModelProperty(
value = "Additional configuration properties",
dataType = "List",
example = "[{\"name\":\"key1\",\"value\":\"value1\"}, {\"name\":\"key2\",\"value\":\"value2\"}]",
notes = "Additional configuration properties for the job on web page")
private List<CustomConfig> flinkConfigList = new ArrayList<>();
@ApiModelProperty( @ApiModelProperty(
value = "Additional configuration properties", value = "Additional configuration properties",
dataType = "Map", dataType = "Map",
example = "{\"key1\":\"value1\",\"key2\":\"value2\"}", example = "{\"key1\":\"value1\",\"key2\":\"value2\"}",
notes = "Additional configuration properties for the job") notes = "Fixed configuration properties for the job on web page")
private Map<String, String> configuration = new HashMap<>(); private Map<String, String> configuration = new HashMap<>();
@ApiModelProperty(
value = "List of Flink configuration properties",
dataType = "List<Map<String, String>>",
example = "[{\"key\":\"value\"},{\"key2\":\"value2\"}]",
notes = "List of Flink configuration properties")
private List<Map<String, String>> flinkConfigList = new ArrayList<>();
private static final ObjectMapper mapper = new ObjectMapper(); private static final ObjectMapper mapper = new ObjectMapper();
public static final String DEFAULT_SAVEPOINT_PREFIX = "hdfs:///flink/savepoints/"; public static final String DEFAULT_SAVEPOINT_PREFIX = "hdfs:///flink/savepoints/";
......
...@@ -19,12 +19,10 @@ ...@@ -19,12 +19,10 @@
package org.dinky.gateway.config; package org.dinky.gateway.config;
import org.dinky.assertion.Asserts;
import org.dinky.gateway.enums.GatewayType; import org.dinky.gateway.enums.GatewayType;
import org.dinky.gateway.model.CustomConfig;
import org.dinky.gateway.model.FlinkClusterConfig; import org.dinky.gateway.model.FlinkClusterConfig;
import java.util.Map;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Assert;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
...@@ -88,12 +86,10 @@ public class GatewayConfig { ...@@ -88,12 +86,10 @@ public class GatewayConfig {
Assert.notNull(config); Assert.notNull(config);
GatewayConfig gatewayConfig = new GatewayConfig(); GatewayConfig gatewayConfig = new GatewayConfig();
BeanUtil.copyProperties(config, gatewayConfig); BeanUtil.copyProperties(config, gatewayConfig);
for (Map<String, String> item : gatewayConfig.getFlinkConfig().getFlinkConfigList()) { for (CustomConfig customConfig : config.getFlinkConfig().getFlinkConfigList()) {
if (Asserts.isNotNull(item)) { Assert.notNull(customConfig.getName(), "Custom flink config has null key");
Assert.notNull(item.get("name"), "Custer config has null item"); Assert.notNull(customConfig.getValue(), "Custom flink config has null value");
Assert.notNull(item.get("value"), "Custer config has null item"); gatewayConfig.getFlinkConfig().getConfiguration().put(customConfig.getName(), customConfig.getValue());
gatewayConfig.getFlinkConfig().getConfiguration().put(item.get("name"), item.get("value"));
}
} }
return gatewayConfig; return gatewayConfig;
} }
......
/*
*
* 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.gateway.model;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@ApiModel(value = "CustomConfig", description = "Custom config of name-value model")
public class CustomConfig {
@ApiModelProperty(value = "Custom Config Name", dataType = "String", notes = "The name of custom config")
private String name;
@ApiModelProperty(value = "Custom Config Value", dataType = "String", notes = "The value of custom config")
private String value;
}
...@@ -29,6 +29,7 @@ import org.dinky.gateway.config.GatewayConfig; ...@@ -29,6 +29,7 @@ import org.dinky.gateway.config.GatewayConfig;
import org.dinky.gateway.enums.ActionType; import org.dinky.gateway.enums.ActionType;
import org.dinky.gateway.enums.SavePointType; import org.dinky.gateway.enums.SavePointType;
import org.dinky.gateway.exception.GatewayException; import org.dinky.gateway.exception.GatewayException;
import org.dinky.gateway.model.CustomConfig;
import org.dinky.gateway.result.SavePointResult; import org.dinky.gateway.result.SavePointResult;
import org.dinky.gateway.result.TestResult; import org.dinky.gateway.result.TestResult;
...@@ -62,18 +63,22 @@ import java.net.URI; ...@@ -62,18 +63,22 @@ import java.net.URI;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Assert;
public abstract class YarnGateway extends AbstractGateway { public abstract class YarnGateway extends AbstractGateway {
public static final String HADOOP_CONFIG = "fs.hdfs.hadoopconf"; public static final String HADOOP_CONFIG = "fs.hdfs.hadoopconf";
protected YarnConfiguration yarnConfiguration; protected YarnConfiguration yarnConfiguration;
protected YarnClient yarnClient; protected YarnClient yarnClient;
public YarnGateway() {} public YarnGateway() {}
...@@ -115,8 +120,7 @@ public abstract class YarnGateway extends AbstractGateway { ...@@ -115,8 +120,7 @@ public abstract class YarnGateway extends AbstractGateway {
UserGroupInformation currentUser = UserGroupInformation.getCurrentUser(); UserGroupInformation currentUser = UserGroupInformation.getCurrentUser();
logger.info("安全认证结束,用户和认证方式:" + currentUser.toString()); logger.info("安全认证结束,用户和认证方式:" + currentUser.toString());
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage()); logger.error(e.getMessage(), e);
e.printStackTrace();
} }
} }
...@@ -129,11 +133,21 @@ public abstract class YarnGateway extends AbstractGateway { ...@@ -129,11 +133,21 @@ public abstract class YarnGateway extends AbstractGateway {
} }
private void initYarnClient() { private void initYarnClient() {
final ClusterConfig clusterConfig = config.getClusterConfig();
yarnConfiguration = new YarnConfiguration(); yarnConfiguration = new YarnConfiguration();
yarnConfiguration.addResource(getYanConfigFilePath("yarn-site.xml")); yarnConfiguration.addResource(getYanConfigFilePath("yarn-site.xml"));
yarnConfiguration.addResource(getYanConfigFilePath("core-site.xml")); yarnConfiguration.addResource(getYanConfigFilePath("core-site.xml"));
yarnConfiguration.addResource(getYanConfigFilePath("hdfs-site.xml")); yarnConfiguration.addResource(getYanConfigFilePath("hdfs-site.xml"));
List<CustomConfig> hadoopConfigList = clusterConfig.getHadoopConfigList();
if (CollectionUtil.isNotEmpty(hadoopConfigList)) {
hadoopConfigList.forEach((customConfig) -> {
Assert.notNull(customConfig.getName(), "Custom hadoop config has null key");
Assert.notNull(customConfig.getValue(), "Custom hadoop config has null value");
yarnConfiguration.set(customConfig.getName(), customConfig.getValue());
});
}
yarnClient = YarnClient.createYarnClient(); yarnClient = YarnClient.createYarnClient();
yarnClient.init(yarnConfiguration); yarnClient.init(yarnConfiguration);
yarnClient.start(); yarnClient.start();
......
/*
*
* 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.gateway.model;
import java.io.IOException;
import java.util.List;
import org.assertj.core.api.Assertions;
import org.junit.Ignore;
import org.junit.Test;
import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper;
public class FlinkClusterConfigTest {
@Ignore
@Test
public void testParseCustomConfig() throws IOException {
String clusterConfigJson = "{\n" + " \"clusterConfig\":{\n"
+ " \"hadoopConfigPath\":\"/opt/dinky-resources/hadoopConfDir\",\n"
+ " \"flinkLibPath\":\"hdfs:///flink/flink1.14-lib\",\n"
+ " \"flinkConfigPath\":\"/opt/flink/conf\",\n"
+ " \"hadoopConfigList\":[\n"
+ " {\n"
+ " \"name\":\"yarn.timeline-service.enabled\",\n"
+ " \"value\":\"false\"\n"
+ " }\n"
+ " ]\n"
+ " },\n"
+ " \"flinkConfig\":{\n"
+ " \"configuration\":{\n"
+ " \"jobmanager.memory.process.size\":\"2G\",\n"
+ " \"taskmanager.memory.process.size\":\"2G\",\n"
+ " \"taskmanager.memory.framework.heap.size\":\"1G\",\n"
+ " \"taskmanager.numberOfTaskSlots\":\"2\",\n"
+ " \"state.savepoints.dir\":\"hdfs:///flink/savepoint\",\n"
+ " \"state.checkpoints.dir\":\"hdfs:///flink/checkpoint\"\n"
+ " },\n"
+ " \"flinkConfigList\":[\n"
+ " {\n"
+ " \"name\":\"yarn.application.queue\",\n"
+ " \"value\":\"prod\"\n"
+ " }\n"
+ " ]\n"
+ " },\n"
+ " \"appConfig\":{\n"
+ " \"userJarPath\":\"hdfs:///flink/dinky/jar/dinky-app-1.14-1.0.0-rc1-jar-with-dependencies.jar\"\n"
+ " }\n"
+ "}";
ObjectMapper objectMapper = new ObjectMapper();
FlinkClusterConfig flinkClusterConfig = objectMapper.readValue(clusterConfigJson, FlinkClusterConfig.class);
List<CustomConfig> flinkConfigList = flinkClusterConfig.getFlinkConfig().getFlinkConfigList();
List<CustomConfig> hadoopConfigList =
flinkClusterConfig.getClusterConfig().getHadoopConfigList();
Assertions.assertThat(flinkConfigList.get(0).getName()).isEqualTo("yarn.application.queue");
Assertions.assertThat(hadoopConfigList.get(0).getName()).isEqualTo("yarn.timeline-service.enabled");
}
}
...@@ -54,7 +54,7 @@ const YarnConfig = (props: { flinkConfigOptions: DefaultOptionType[] }) => { ...@@ -54,7 +54,7 @@ const YarnConfig = (props: { flinkConfigOptions: DefaultOptionType[] }) => {
</ProFormGroup> </ProFormGroup>
<Divider>{l('rc.cc.hadoop.defineConfig')}</Divider> <Divider>{l('rc.cc.hadoop.defineConfig')}</Divider>
<ProFormList <ProFormList
name={['config', 'hadoopConfigList']} name={['config', 'clusterConfig', 'hadoopConfigList']}
copyIconProps={false} copyIconProps={false}
deleteIconProps={{ deleteIconProps={{
tooltipText: l('rc.cc.deleteConfig') tooltipText: l('rc.cc.deleteConfig')
...@@ -104,7 +104,7 @@ const YarnConfig = (props: { flinkConfigOptions: DefaultOptionType[] }) => { ...@@ -104,7 +104,7 @@ const YarnConfig = (props: { flinkConfigOptions: DefaultOptionType[] }) => {
<Divider>{l('rc.cc.flink.defineConfig')}</Divider> <Divider>{l('rc.cc.flink.defineConfig')}</Divider>
<ProFormList <ProFormList
name={['config', 'flinkConfigList']} name={['config', 'flinkConfig', 'flinkConfigList']}
copyIconProps={false} copyIconProps={false}
deleteIconProps={{ deleteIconProps={{
tooltipText: l('rc.cc.deleteConfig') tooltipText: l('rc.cc.deleteConfig')
......
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