@@ -8,31 +8,20 @@ package com.vesoft.nebula.algorithm.config
88import java .io .File
99import java .nio .file .Files
1010import org .apache .log4j .Logger
11+
1112import scala .collection .JavaConverters ._
1213import com .typesafe .config .{Config , ConfigFactory }
14+ import com .vesoft .nebula .algorithm .config .Configs .readConfig
15+
1316import scala .collection .mutable
1417
1518/**
1619 * sparkConfig is used to submit spark application, such as graph algorithm
1720 */
1821object SparkConfigEntry {
1922 def apply (config : Config ): SparkConfigEntry = {
20- val map = mutable.Map [String , String ]()
21- val sparkConfig = config.getObject(" spark" )
22- for (key <- sparkConfig.unwrapped().keySet().asScala) {
23- val sparkKey = s " spark. ${key}"
24- if (config.getAnyRef(sparkKey).isInstanceOf [String ]) {
25- val sparkValue = config.getString(sparkKey)
26- map += sparkKey -> sparkValue
27- } else {
28- for (subKey <- config.getObject(sparkKey).unwrapped().keySet().asScala) {
29- val key = s " ${sparkKey}. ${subKey}"
30- val sparkValue = config.getString(key)
31- map += key -> sparkValue
32- }
33- }
34- }
35- SparkConfigEntry (map.toMap)
23+ val map = readConfig(config, " spark" )
24+ SparkConfigEntry (map)
3625 }
3726}
3827
@@ -41,22 +30,8 @@ object SparkConfigEntry {
4130 */
4231object AlgorithmConfigEntry {
4332 def apply (config : Config ): AlgorithmConfigEntry = {
44- val map = mutable.Map [String , String ]()
45- val algoConfig = config.getObject(" algorithm" )
46- for (key <- algoConfig.unwrapped().keySet().asScala) {
47- val algorithmKey = s " algorithm. ${key}"
48- if (config.getAnyRef(algorithmKey).isInstanceOf [String ]) {
49- val algorithmValue = config.getString(algorithmKey)
50- map += algorithmKey -> algorithmValue
51- } else {
52- for (subkey <- config.getObject(algorithmKey).unwrapped().keySet().asScala) {
53- val key = s " ${algorithmKey}. ${subkey}"
54- val value = config.getString(key)
55- map += key -> value
56- }
57- }
58- }
59- AlgorithmConfigEntry (map.toMap)
33+ val map = readConfig(config, " algorithm" )
34+ AlgorithmConfigEntry (map)
6035 }
6136}
6237
@@ -365,6 +340,24 @@ object Configs {
365340 }
366341 parser.parse(args, Argument ())
367342 }
343+
344+ def readConfig (config : Config , name : String ): Map [String , String ] = {
345+ val map = mutable.Map [String , String ]()
346+ val configObject = config.getObject(name)
347+ for (key <- configObject.unwrapped().keySet().asScala) {
348+ val refinedKey = s " $name. $key"
349+ config.getAnyRef(refinedKey) match {
350+ case stringValue : String => map += refinedKey -> stringValue
351+ case _ =>
352+ for (subKey <- config.getObject(refinedKey).unwrapped().keySet().asScala) {
353+ val refinedSubKey = s " $refinedKey. $subKey"
354+ val refinedSubValue = config.getString(refinedSubKey)
355+ map += refinedSubKey -> refinedSubValue
356+ }
357+ }
358+ }
359+ map.toMap
360+ }
368361}
369362
370363object AlgoConstants {
0 commit comments