[jvm-packages] logging version number (#4271)

* print version number

* add property file
This commit is contained in:
Nan Zhu 2019-03-21 18:24:29 +08:00 committed by GitHub
parent 8eab966998
commit 45c89a6792
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 2 deletions

View File

@ -212,6 +212,12 @@
</snapshotRepository> </snapshotRepository>
</distributionManagement> </distributionManagement>
<build> <build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.scalastyle</groupId> <groupId>org.scalastyle</groupId>

View File

@ -18,6 +18,7 @@ package ml.dmlc.xgboost4j.scala.spark
import java.io.File import java.io.File
import java.nio.file.Files import java.nio.file.Files
import java.util.Properties
import scala.collection.mutable.ListBuffer import scala.collection.mutable.ListBuffer
import scala.collection.{AbstractIterator, mutable} import scala.collection.{AbstractIterator, mutable}
@ -31,7 +32,7 @@ import org.apache.commons.io.FileUtils
import org.apache.commons.logging.LogFactory import org.apache.commons.logging.LogFactory
import org.apache.spark.rdd.RDD import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkContext, SparkParallelismTracker, TaskContext} import org.apache.spark.{SparkContext, SparkException, SparkParallelismTracker, TaskContext}
import org.apache.spark.sql.{DataFrame, SparkSession} import org.apache.spark.sql.{DataFrame, SparkSession}
import org.apache.spark.storage.StorageLevel import org.apache.spark.storage.StorageLevel
@ -386,7 +387,7 @@ object XGBoost extends Serializable {
hasGroup: Boolean = false, hasGroup: Boolean = false,
evalSetsMap: Map[String, RDD[XGBLabeledPoint]] = Map()): evalSetsMap: Map[String, RDD[XGBLabeledPoint]] = Map()):
(Booster, Map[String, Array[Float]]) = { (Booster, Map[String, Array[Float]]) = {
logger.info(s"XGBoost training with parameters:\n${params.mkString("\n")}") logger.info(s"Running XGBoost ${spark.VERSION} with parameters:\n${params.mkString("\n")}")
val (nWorkers, round, _, _, _, _, trackerConf, timeoutRequestWorkers, val (nWorkers, round, _, _, _, _, trackerConf, timeoutRequestWorkers,
checkpointPath, checkpointInterval) = parameterFetchAndValidation(params, checkpointPath, checkpointInterval) = parameterFetchAndValidation(params,
trainingData.sparkContext) trainingData.sparkContext)

View File

@ -0,0 +1,48 @@
/*
Copyright (c) 2014 by Contributors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package ml.dmlc.xgboost4j.scala
import java.util.Properties
import org.apache.spark.SparkException
package object spark {
private def loadVersionInfo(): String = {
val versionResourceFile = Thread.currentThread().getContextClassLoader.getResourceAsStream(
"xgboost4j-version.properties")
try {
val unknownProp = "<unknown>"
val props = new Properties()
props.load(versionResourceFile)
props.getProperty("version", unknownProp)
} catch {
case e: Exception =>
throw new SparkException("Error loading properties from xgboost4j-version.properties", e)
} finally {
if (versionResourceFile != null) {
try {
versionResourceFile.close()
} catch {
case e: Exception =>
throw new SparkException("Error closing xgboost4j version resource stream", e)
}
}
}
}
val VERSION: String = loadVersionInfo()
}

View File

@ -0,0 +1 @@
version=${project.version}