Skip to content

Commit

Permalink
Moved hostname to config package.
Browse files Browse the repository at this point in the history
  • Loading branch information
aalexandrov committed Sep 9, 2016
1 parent 2cc6cb1 commit 65a70b8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ import net.sourceforge.argparse4j.internal.HelpScreenException
import org.apache.log4j.{Level, PatternLayout, RollingFileAppender}
import org.peelframework.core.PeelApplicationContext
import org.peelframework.core.cli.command.Command
import org.peelframework.core.util.shell
import org.peelframework.core.config.hostname
import org.slf4j.{Logger, LoggerFactory}

import scala.collection.JavaConversions._
import scala.sys.process.Process

object Peel {

Expand Down Expand Up @@ -164,11 +163,6 @@ object Peel {
parser
}

lazy val hostname = {
val name = Process("/bin/bash", Seq("-c", "CLASSPATH=;echo $HOSTNAME")).!!
if (name.nonEmpty) name.trim else "localhost"
}

def printHeader(logger: Logger) {
logger.info("############################################################")
logger.info("# PEEL EXPERIMENTS EXECUTION FRAMEWORK #")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import org.peelframework.core.beans.experiment.Experiment
import org.peelframework.core.beans.system.System
import org.peelframework.core.graph.{DependencyGraph, Node}
import org.peelframework.core.util.console.ConsoleColorise
import org.peelframework.core.util.shell
import org.slf4j.LoggerFactory

import scala.sys.process.Process

/** Package Object to handle the loading of configuration files
*
* Configuration files are loaded and resolved according to the
Expand Down Expand Up @@ -71,7 +72,7 @@ package object config {

// load current runtime config
logger.info(s"+-- Loading current runtime values as configuration")
cb.append(currentRuntimeConfig())
cb.append(currentRuntimeConfig)

// load system properties
logger.info(s"+-- Loading system properties as configuration")
Expand Down Expand Up @@ -122,7 +123,7 @@ package object config {

// load current runtime config
logger.info(s"+-- Loading current runtime values as configuration")
cb.append(currentRuntimeConfig())
cb.append(currentRuntimeConfig)

// load system properties
logger.info(s"+-- Loading system properties as configuration")
Expand Down Expand Up @@ -176,7 +177,7 @@ package object config {

// load current runtime config
logger.info(s"+-- Loading current runtime values as configuration")
cb.append(currentRuntimeConfig())
cb.append(currentRuntimeConfig)

// load system properties
logger.info(s"+-- Loading system properties as configuration")
Expand Down Expand Up @@ -204,18 +205,23 @@ package object config {
*
* @return current Config Object
*/
private def currentRuntimeConfig() = {
lazy val currentRuntimeConfig = {
// initial empty configuration
val runtimeConfig = new java.util.HashMap[String, Object]()
// add current runtime values to configuration
runtimeConfig.put("runtime.cpu.cores", Runtime.getRuntime.availableProcessors().asInstanceOf[Object])
runtimeConfig.put("runtime.memory.max", Runtime.getRuntime.maxMemory().asInstanceOf[Object])
runtimeConfig.put("runtime.hostname", (shell !! "echo $HOSTNAME").trim())
runtimeConfig.put("runtime.hostname", hostname)
runtimeConfig.put("runtime.disk.size", new File("/").getTotalSpace.asInstanceOf[Object])
// return a config object
ConfigFactory.parseMap(runtimeConfig)
}

lazy val hostname = {
val name = Process("/bin/bash", Seq("-c", "CLASSPATH=;echo $HOSTNAME")).!!
if (name.nonEmpty) name.trim else "localhost"
}

private class ConfigBuilder {

// initial empty configuration
Expand Down

0 comments on commit 65a70b8

Please sign in to comment.