@@ -8,31 +8,20 @@ package com.vesoft.nebula.algorithm.config
8
8
import java .io .File
9
9
import java .nio .file .Files
10
10
import org .apache .log4j .Logger
11
+
11
12
import scala .collection .JavaConverters ._
12
13
import com .typesafe .config .{Config , ConfigFactory }
14
+ import com .vesoft .nebula .algorithm .config .Configs .readConfig
15
+
13
16
import scala .collection .mutable
14
17
15
18
/**
16
19
* sparkConfig is used to submit spark application, such as graph algorithm
17
20
*/
18
21
object SparkConfigEntry {
19
22
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)
36
25
}
37
26
}
38
27
@@ -41,22 +30,8 @@ object SparkConfigEntry {
41
30
*/
42
31
object AlgorithmConfigEntry {
43
32
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)
60
35
}
61
36
}
62
37
@@ -365,6 +340,24 @@ object Configs {
365
340
}
366
341
parser.parse(args, Argument ())
367
342
}
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
+ }
368
361
}
369
362
370
363
object AlgoConstants {
0 commit comments