|
18 | 18 |
|
19 | 19 | package com.dtstack.flink.sql.launcher.factory; |
20 | 20 |
|
21 | | -import com.dtstack.flink.sql.util.MathUtil; |
22 | 21 | import org.apache.flink.client.deployment.ClusterDescriptor; |
23 | 22 | import org.apache.flink.client.deployment.ClusterSpecification; |
24 | 23 | import org.apache.flink.configuration.Configuration; |
25 | | -import java.util.Properties; |
| 24 | +import org.apache.flink.configuration.ConfigurationUtils; |
| 25 | +import org.apache.flink.configuration.TaskManagerOptions; |
| 26 | +import org.apache.flink.runtime.clusterframework.TaskExecutorProcessUtils; |
| 27 | + |
| 28 | +import static org.apache.flink.util.Preconditions.checkNotNull; |
26 | 29 |
|
27 | 30 |
|
28 | 31 | /** |
|
32 | 35 | */ |
33 | 36 | public abstract class AbstractClusterClientFactory { |
34 | 37 |
|
| 38 | + public ClusterSpecification getClusterSpecification(Configuration configuration) { |
| 39 | + checkNotNull(configuration); |
35 | 40 |
|
36 | | - public final static int MIN_JM_MEMORY = 768; |
37 | | - public final static int MIN_TM_MEMORY = 1024; |
38 | | - |
39 | | - public final static String JOBMANAGER_MEMORY_MB = "jobmanager.memory.mb"; |
40 | | - public final static String TASKMANAGER_MEMORY_MB = "taskmanager.memory.mb"; |
41 | | - public final static String SLOTS_PER_TASKMANAGER = "taskmanager.slots"; |
42 | | - |
43 | | - public ClusterSpecification getClusterSpecification(Properties confProperties) { |
44 | | - int jobmanagerMemoryMb = 768; |
45 | | - int taskmanagerMemoryMb = 1024; |
46 | | - int slotsPerTaskManager = 1; |
47 | | - |
48 | | - if (confProperties != null) { |
49 | | - if (confProperties.containsKey(JOBMANAGER_MEMORY_MB)) { |
50 | | - jobmanagerMemoryMb = MathUtil.getIntegerVal(confProperties.get(JOBMANAGER_MEMORY_MB)); |
51 | | - if (jobmanagerMemoryMb < MIN_JM_MEMORY) { |
52 | | - jobmanagerMemoryMb = MIN_JM_MEMORY; |
53 | | - } |
54 | | - } |
55 | | - |
56 | | - if (confProperties.containsKey(TASKMANAGER_MEMORY_MB)) { |
57 | | - taskmanagerMemoryMb = MathUtil.getIntegerVal(confProperties.get(TASKMANAGER_MEMORY_MB)); |
58 | | - if (taskmanagerMemoryMb < MIN_TM_MEMORY) { |
59 | | - taskmanagerMemoryMb = MIN_TM_MEMORY; |
60 | | - } |
61 | | - } |
| 41 | + final int jobManagerMemoryMB = ConfigurationUtils |
| 42 | + .getJobManagerHeapMemory(configuration) |
| 43 | + .getMebiBytes(); |
| 44 | + // taskmanager.memory.process.size |
| 45 | + final int taskManagerMemoryMB = TaskExecutorProcessUtils |
| 46 | + .processSpecFromConfig(TaskExecutorProcessUtils.getConfigurationMapLegacyTaskManagerHeapSizeToConfigOption( |
| 47 | + configuration, TaskManagerOptions.TOTAL_PROCESS_MEMORY)) |
| 48 | + .getTotalProcessMemorySize() |
| 49 | + .getMebiBytes(); |
62 | 50 |
|
63 | | - if (confProperties.containsKey(SLOTS_PER_TASKMANAGER)) { |
64 | | - slotsPerTaskManager = MathUtil.getIntegerVal(confProperties.get(SLOTS_PER_TASKMANAGER)); |
65 | | - } |
66 | | - } |
| 51 | + int slotsPerTaskManager = configuration.getInteger(TaskManagerOptions.NUM_TASK_SLOTS); |
67 | 52 |
|
68 | 53 | return new ClusterSpecification.ClusterSpecificationBuilder() |
69 | | - .setMasterMemoryMB(jobmanagerMemoryMb) |
70 | | - .setTaskManagerMemoryMB(taskmanagerMemoryMb) |
| 54 | + .setMasterMemoryMB(jobManagerMemoryMB) |
| 55 | + .setTaskManagerMemoryMB(taskManagerMemoryMB) |
71 | 56 | .setSlotsPerTaskManager(slotsPerTaskManager) |
72 | 57 | .createClusterSpecification(); |
73 | 58 | } |
|
0 commit comments