-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #511 from InterestingLab/rickyhuo.enhance.driver
Rickyhuo.enhance.driverConf
- Loading branch information
Showing
2 changed files
with
70 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...p-core/src/main/java/io/github/interestinglab/waterdrop/config/ExposeSparkDriverConf.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package io.github.interestinglab.waterdrop.config; | ||
|
||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.io.File; | ||
|
||
|
||
public class ExposeSparkDriverConf { | ||
|
||
public static List<String> splitKey(String key) { | ||
List<String> keys = new LinkedList<>(); | ||
int index = 0; | ||
for (int i = 0; i < key.length(); i ++) { | ||
char symbol = key.charAt(i); | ||
if (symbol >= 'A' && symbol <= 'Z') { | ||
keys.add(key.substring(index, i).toLowerCase()); | ||
index = i; | ||
} | ||
} | ||
|
||
keys.add(key.substring(index).toLowerCase()); | ||
|
||
if (keys.get(0).equals("extra")) { | ||
return keys.subList(1, keys.size()); | ||
} | ||
return keys; | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
Config appConfig = ConfigFactory.parseFile(new File(args[0])) | ||
.resolve(ConfigResolveOptions.defaults().setAllowUnresolved(true)) | ||
.resolveWith(ConfigFactory.systemProperties(), ConfigResolveOptions.defaults().setAllowUnresolved(true)); | ||
|
||
String driverPrefix = "spark.driver."; | ||
Config sparkConfig = appConfig.getConfig("spark"); | ||
|
||
if (!TypesafeConfigUtils.hasSubConfig(sparkConfig, driverPrefix)) { | ||
System.out.println(""); | ||
} else { | ||
Config sparkDriverConfig = TypesafeConfigUtils.extractSubConfig(sparkConfig, driverPrefix, false); | ||
StringBuilder stringBuilder = new StringBuilder(); | ||
for (Map.Entry<String, ConfigValue> entry: sparkDriverConfig.entrySet()) { | ||
List<String> keys = splitKey(entry.getKey()); | ||
String conf = String.format(" --driver-%s=%s ", String.join("-", keys), entry.getValue().unwrapped()); | ||
stringBuilder.append(conf); | ||
} | ||
|
||
System.out.println(stringBuilder.toString()); | ||
} | ||
} | ||
} |