Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract duplicate code #93

Merged
merged 3 commits into from
Feb 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,20 @@ package com.vesoft.nebula.algorithm.config
import java.io.File
import java.nio.file.Files
import org.apache.log4j.Logger

import scala.collection.JavaConverters._
import com.typesafe.config.{Config, ConfigFactory}
import com.vesoft.nebula.algorithm.config.Configs.readConfig

import scala.collection.mutable

/**
* sparkConfig is used to submit spark application, such as graph algorithm
*/
object SparkConfigEntry {
def apply(config: Config): SparkConfigEntry = {
val map = mutable.Map[String, String]()
val sparkConfig = config.getObject("spark")
for (key <- sparkConfig.unwrapped().keySet().asScala) {
val sparkKey = s"spark.${key}"
if (config.getAnyRef(sparkKey).isInstanceOf[String]) {
val sparkValue = config.getString(sparkKey)
map += sparkKey -> sparkValue
} else {
for (subKey <- config.getObject(sparkKey).unwrapped().keySet().asScala) {
val key = s"${sparkKey}.${subKey}"
val sparkValue = config.getString(key)
map += key -> sparkValue
}
}
}
SparkConfigEntry(map.toMap)
val map = readConfig(config, "spark")
SparkConfigEntry(map)
}
}

Expand All @@ -41,22 +30,8 @@ object SparkConfigEntry {
*/
object AlgorithmConfigEntry {
def apply(config: Config): AlgorithmConfigEntry = {
val map = mutable.Map[String, String]()
val algoConfig = config.getObject("algorithm")
for (key <- algoConfig.unwrapped().keySet().asScala) {
val algorithmKey = s"algorithm.${key}"
if (config.getAnyRef(algorithmKey).isInstanceOf[String]) {
val algorithmValue = config.getString(algorithmKey)
map += algorithmKey -> algorithmValue
} else {
for (subkey <- config.getObject(algorithmKey).unwrapped().keySet().asScala) {
val key = s"${algorithmKey}.${subkey}"
val value = config.getString(key)
map += key -> value
}
}
}
AlgorithmConfigEntry(map.toMap)
val map = readConfig(config, "algorithm")
AlgorithmConfigEntry(map)
}
}

Expand Down Expand Up @@ -365,6 +340,24 @@ object Configs {
}
parser.parse(args, Argument())
}

def readConfig(config: Config, name: String): Map[String, String] = {
val map = mutable.Map[String, String]()
val configObject = config.getObject(name)
for (key <- configObject.unwrapped().keySet().asScala) {
val refinedKey = s"$name.$key"
config.getAnyRef(refinedKey) match {
case stringValue: String => map += refinedKey -> stringValue
case _ =>
for (subKey <- config.getObject(refinedKey).unwrapped().keySet().asScala) {
val refinedSubKey = s"$refinedKey.$subKey"
val sparkValue = config.getString(refinedSubKey)
artemkorsakov marked this conversation as resolved.
Show resolved Hide resolved
map += refinedSubKey -> sparkValue
}
}
}
map.toMap
}
}

object AlgoConstants {
Expand Down
Loading