Commit 6ecaf64f by Tomasz Ciesielczyk

fix ssh command required userinput: timeout for ssh command

parent c5117c97
......@@ -116,7 +116,7 @@ Lets define set of nodes in the heterogeneous microserver appliance as:
, where:
\begin_inset Formula
\begin{gather}
n_{i}\in N_{i},\:i<\left|N\right|\wedge\:i\in\mathbb{N}\label{eq:node definition}
n_{i}\in N_{i},\:i=0,1,...,(\left|N\right|-1)\label{eq:node definition}
\end{gather}
\end_inset
......
......@@ -17,6 +17,7 @@ import psnc.m2dc.rtm.properties.keys.Keys
import psnc.m2dc.rtm.rpm.RPMApi
import psnc.m2dc.rtm.utils.loadJsonFile
import psnc.m2dc.rtm.utils.logDebug
import psnc.m2dc.rtm.utils.printConsole
import psnc.m2dc.rtm.utils.toJson
import java.io.File
import java.nio.file.Paths
......@@ -56,11 +57,19 @@ class RTMApi private constructor() {
}
private fun javaState(): String {
val sb =StringBuilder()
Thread.getAllStackTraces().keys.forEach {
sb.append("${it.name}(${it.id}): ${it.isAlive} \n")
}
return sb.toString()
}
fun checkConf() {
log.info("Start rest service check!")
printConsole(javaState(),false)
ServerInitializer.check()
printConsole(javaState(),false)
val nodes = DAO.Resource.getNodes()
nodes.toJson(RTMProperties.parsePath("${RTMProperties.basePath}/check_node_list.json").toString())
var actionList = ArrayList<ResourceAction>()
......@@ -77,6 +86,7 @@ class RTMApi private constructor() {
actionList.toJson(RTMProperties.parsePath("${RTMProperties.basePath}/check_reset_actions_result.json").toString())
printConsole(javaState(),false)
Thread.sleep(90000)
RPMApi.instance().getPowerUsageList().toJson(RTMProperties.parsePath("${RTMProperties.basePath}/check_power_usage.json").toString())
//init solvers in order to dump their state
......@@ -97,25 +107,26 @@ class RTMApi private constructor() {
}
}
actionList.toJson(RTMProperties.parsePath("${RTMProperties.basePath}/check_reset_actions_result_100.json").toString())
printConsole(javaState(),false)
Thread.sleep(90000)
limits = PCMApi.instance().checkLimits()
state = CurrentState(limits.currentPowerUsage)
PCMAlgorithm(state, Solver.Algorithm.greedy)
RPMApi.instance().getPowerUsageList().toJson(RTMProperties.parsePath("${RTMProperties.basePath}/check_power_usage_100.json").toString())
// ESMAlgorithm(state)
printConsole("End conf check ")
printConsole(javaState(),false)
}
fun checkAlgorithm(path: String, algorithm: Solver.Algorithm?, limit: Double) {
log.info("Algorithm Check!")
val state = {tradeoff:Double ->
val state = { tradeoff: Double ->
val s = loadJsonFile<CurrentState>(Paths.get(path), CurrentState::class.java)
?: throw NullPointerException("State not found")
s.currentPowerOverLimit = s.powerUsage - limit
s.eval.resetPowerBudget(s.currentPowerOverLimit)
s.eval.tradeOff =tradeoff
s.eval.tradeOff = tradeoff
s
}
ServerInitializer.check()
......@@ -123,23 +134,23 @@ class RTMApi private constructor() {
val initialState = state(tradeoff)
if (algorithm != null) {
var res = PCMAlgorithm(state(tradeoff), algorithm).next()
this.saveResult(res, algorithm, "pcm", initialState,limit.toInt())
this.saveResult(res, algorithm, "pcm", initialState, limit.toInt())
res = ESMAlgorithm(state(tradeoff), algorithm).next()
this.saveResult(res, algorithm, "esm", initialState,limit.toInt())
this.saveResult(res, algorithm, "esm", initialState, limit.toInt())
// res.toJson(RTMProperties.parsePath("${RTMProperties.basePath}/esm_$algorithm.out").toAbsolutePath().toString(), true)
} else {
Solver.Algorithm.values().forEach { algorithm ->
var res = PCMAlgorithm(state(tradeoff), algorithm).next()
this.saveResult(res, algorithm, "pcm", initialState,limit.toInt())
this.saveResult(res, algorithm, "pcm", initialState, limit.toInt())
res = ESMAlgorithm(state(tradeoff), algorithm).next()
this.saveResult(res, algorithm, "esm", initialState,limit.toInt())
this.saveResult(res, algorithm, "esm", initialState, limit.toInt())
}
}
}
fun saveResult(powerSettings: PowerSettings, algorithm: Solver.Algorithm, procedure: String, initialState: CurrentState,powerLimit:Int) {
fun saveResult(powerSettings: PowerSettings, algorithm: Solver.Algorithm, procedure: String, initialState: CurrentState, powerLimit: Int) {
var avgPerf = 0.0
var expectedPowerConsumption = 0.0
var expectedPowerConsumption100 = 0.0
......@@ -153,8 +164,8 @@ class RTMApi private constructor() {
val newUtil = model.calculateUtil(newPerformanceLevel, initialPerfLevel, initialUtil)
val performanceValue = model.getPerformance(newPerformanceLevel)
avgPerf += performanceValue * newUtil
expectedPowerConsumption += model.getPower(newPerformanceLevel, newUtil)/performanceValue
expectedInitialPowerConsumption += model.getPower(initialPerfLevel, initialUtil)/initialPerformanceValue
expectedPowerConsumption += model.getPower(newPerformanceLevel, newUtil) / performanceValue
expectedInitialPowerConsumption += model.getPower(initialPerfLevel, initialUtil) / initialPerformanceValue
expectedPowerConsumption100 += model.getPower(100.0, model.calculateUtil(100.0, initialPerfLevel, initialUtil))
......@@ -164,7 +175,6 @@ class RTMApi private constructor() {
val path = RTMProperties.parsePath("${RTMProperties.basePath}/powercap_output/limit_$powerLimit/${procedure}_$algorithm.out").toAbsolutePath()
val f = File(path.toString())
f.parentFile.mkdirs()
val sb = StringBuilder()
......@@ -175,8 +185,8 @@ class RTMApi private constructor() {
sb.append("expected power consumption => ${expectedPowerConsumption}\n")
sb.append("expected initial power consumption => ${expectedInitialPowerConsumption}\n")
sb.append("expected max power consumption => ${expectedPowerConsumption100}\n")
sb.append("expected power consumption savings => ${(expectedInitialPowerConsumption-expectedPowerConsumption)/expectedInitialPowerConsumption}\n")
sb.append("expected absolute powe consumption savings => ${(expectedPowerConsumption100-expectedPowerConsumption)/expectedPowerConsumption100}\n")
sb.append("expected power consumption savings => ${(expectedInitialPowerConsumption - expectedPowerConsumption) / expectedInitialPowerConsumption}\n")
sb.append("expected absolute powe consumption savings => ${(expectedPowerConsumption100 - expectedPowerConsumption) / expectedPowerConsumption100}\n")
f.writeText(sb.toString())
......
......@@ -22,7 +22,9 @@ object RTMScannerWorker {
init {
if (Keys.RTM.scan_thread.getBoolean()) {
logInfo("Initialize scanner")
initLock!!.acquire()
scanner = Scanner()
Thread(scanner).start()
......
package psnc.m2dc.rtm
import com.google.gson.reflect.TypeToken
import psnc.m2dc.rtm.commands.java.APP_VERSION
import psnc.m2dc.rtm.dao.DAO
import psnc.m2dc.rtm.dao.LightStorage
import psnc.m2dc.rtm.model.rest.ResourceAction
import psnc.m2dc.rtm.model.rpm.ModelMap
import psnc.m2dc.rtm.model.rpm.Resource
import psnc.m2dc.rtm.properties.RTMProperties
......@@ -19,22 +17,22 @@ object ServerConfInitializer {
fun init() {
try {
var s = """
{"0": {"powerAction": "set_property", "value": "[\"-p\", \"cpu_freq\", \"-p\", \"40\"]"}, "16": {"powerAction": "set_property", "value": "[\"-p\", \"cpu_freq\", \"-p\", \"100\"]"}, "37": {"powerAction": "set_property", "value": "[\"-p\", \"cpu_freq\", \"-p\", \"50\"]"}, "39": {"powerAction": "set_property", "value": "[\"-p\", \"cpu_freq\", \"-p\", \"20\"]"}, "100": {"powerAction": "set_property", "value": "[\"-p\", \"cpu_freq\", \"-p\", \"30\"]"}}
""".trimIndent()
s ="""
{"0": [{
"powerAction": "set_property", "properties": {"value": "[\"-p\", \"rapl\", \"-p\", \"50\"]"}
} ] }
"""
s = """
{"0": [{"resourceId": "", "powerAction": "set_property", "properties": {"value": "[\"-p\", \"rapl\", \"-p\", \"10\"]"}}], "13": [{"resourceId": "", "powerAction": "set_property", "properties": {"value": "[\"-p\", \"rapl\", \"-p\", \"80\"]"}}], "26": [{"resourceId": "", "powerAction": "set_property", "properties": {"value": "[\"-p\", \"rapl\", \"-p\", \"95\"]"}}], "77": [{"resourceId": "", "powerAction": "set_property", "properties": {"value": "[\"-p\", \"rapl\", \"-p\", \"90\"]"}}], "100": [{"resourceId": "", "powerAction": "set_property", "properties": {"value": "[\"-p\", \"rapl\", \"-p\", \"60\"]"}}]}
"""
val parsed = s.fromJson<HashMap<Double, List<ResourceAction>>>(
object : TypeToken<HashMap<Double, List<ResourceAction>>>() {
}.type)
// var s = """
// {"0": {"powerAction": "set_property", "value": "[\"-p\", \"cpu_freq\", \"-p\", \"40\"]"}, "16": {"powerAction": "set_property", "value": "[\"-p\", \"cpu_freq\", \"-p\", \"100\"]"}, "37": {"powerAction": "set_property", "value": "[\"-p\", \"cpu_freq\", \"-p\", \"50\"]"}, "39": {"powerAction": "set_property", "value": "[\"-p\", \"cpu_freq\", \"-p\", \"20\"]"}, "100": {"powerAction": "set_property", "value": "[\"-p\", \"cpu_freq\", \"-p\", \"30\"]"}}
//
// """.trimIndent()
// s ="""
// {"0": [{
// "powerAction": "set_property", "properties": {"value": "[\"-p\", \"rapl\", \"-p\", \"50\"]"}
// } ] }
//
// """
// s = """
// {"0": [{"resourceId": "", "powerAction": "set_property", "properties": {"value": "[\"-p\", \"rapl\", \"-p\", \"10\"]"}}], "13": [{"resourceId": "", "powerAction": "set_property", "properties": {"value": "[\"-p\", \"rapl\", \"-p\", \"80\"]"}}], "26": [{"resourceId": "", "powerAction": "set_property", "properties": {"value": "[\"-p\", \"rapl\", \"-p\", \"95\"]"}}], "77": [{"resourceId": "", "powerAction": "set_property", "properties": {"value": "[\"-p\", \"rapl\", \"-p\", \"90\"]"}}], "100": [{"resourceId": "", "powerAction": "set_property", "properties": {"value": "[\"-p\", \"rapl\", \"-p\", \"60\"]"}}]}
// """
// val parsed = s.fromJson<HashMap<Double, List<ResourceAction>>>(
// object : TypeToken<HashMap<Double, List<ResourceAction>>>() {
// }.type)
logInfo("version: $APP_VERSION")
......@@ -47,12 +45,7 @@ object ServerConfInitializer {
if (overwrite) {
printConsole("Save resources")
DAO.ResourcesManagerApi.saveResourcesToFile(resources)
// resources.toJson(RTMProperties.parsePath("${Keys.RTM.resource_file.get()}").toString(), true)
}
// loadResources()
// setDefaultPriorities()
LightStorage.instance.save(null)
printConsole("end init")
} catch (e: Exception) {
......
......@@ -11,30 +11,38 @@ import psnc.m2dc.rtm.pcm.PCMApi
import psnc.m2dc.rtm.properties.keys.Keys
import psnc.m2dc.rtm.rest.Handlers
import psnc.m2dc.rtm.rest.auth.RESTAuth
import psnc.m2dc.rtm.utils.Timer
import psnc.m2dc.rtm.utils.logError
import psnc.m2dc.rtm.utils.logInfo
import psnc.m2dc.rtm.utils.setWatch
import psnc.m2dc.rtm.utils.*
import spark.Spark
/**
* Server's initialization methods
*/
object ServerInitializer {
private fun javaState(): String {
val sb =StringBuilder()
Thread.getAllStackTraces().keys.forEach {
sb.append("${it.name}(${it.id}): ${it.isAlive} \n")
}
return sb.toString()
}
private fun init() {
try {
logInfo("version: $APP_VERSION")
loadConfig()// -> tu zglasza null pointer
loadResources()
printConsole("x1: "+javaState(),false)
PCMApi.init()
printConsole("x2.2: "+javaState(),false)
ESMApi.init()
printConsole("x2: "+javaState(),false)
setDefaultPriorities()
printConsole("x3: "+javaState(),false)
LightStorage.saveStorage()
printConsole("x4: "+javaState(),false)
// StorageKeys.POWER_LIMIT = Values.powerLimit(440.0)
// val a =PCMApi.instance().predictPCMActions()
// a.generateScripts().toJson(true)
......
package psnc.m2dc.rtm.commands.java
val APP_VERSION = "1.0.530_69557"
\ No newline at end of file
val APP_VERSION = "1.0.548_47218"
\ No newline at end of file
package psnc.m2dc.rtm.client
const val APP_VERSION = "1.1.530_69557"
\ No newline at end of file
const val APP_VERSION = "1.1.548_47218"
\ No newline at end of file
......@@ -18,7 +18,7 @@ class PowerSettingCommand : Runnable {
@CommandLine.ParentCommand
private lateinit var parent: RTMCLI
@CommandLine.Option(names = ["-r", "--resource"], description = ["resource id list"])
@CommandLine.Option(names = ["-r", "--resource"], description = ["resource id list or 'nodes' for all nodes"])
private var resourceIdList: List<String>? = null
@CommandLine.Option(names = ["-v", "--value"], description = ["setting value"])
private var settingValue: Double? = null
......
......@@ -443,7 +443,8 @@ class ResourceManager : DataDAO() {
} else null
val worker = ManagementWorkerImpl(endpoint, {
logDebug("$endpoint/$resourceId worker start")
Timer.stopwatch("Data download time: $endpoint/$resourceId") {
Timer.stopwatch("Data download time for$endpoint/$resourceId") {
try {
val res = RPMApi.instance().loadData(apiType, resourceId, endpoint, username)
res
......
......@@ -63,15 +63,21 @@ class RTMProperties {
basePath = p.toAbsolutePath().parent.toString()
// printConsole(basePath+ " dd")
conf = configurations.ini(p.toString())
val confDirPath=conf.getString("Default.configuration_dir_path")?:"$basePath${File.separator}conf${File.separator}additional"
if (File("$basePath${File.separator}conf${File.separator}additional").exists())
FileUtils.listFiles("$basePath${File.separator}conf${File.separator}additional", ".conf").forEach { it ->
conf.copy(Configurations().ini("$basePath${File.separator}conf${File.separator}additional${File.separator}$it"))
FileUtils.listFiles(confDirPath, ".conf").forEach { it ->
var c = Configurations().ini("$confDirPath${File.separator}$it")
conf.copy(c)
}
Keys.initializeKeys()
setup()
if (Keys.Default.print_conf.get())
printConf()
ONLINE_DATA_TIMEOUT = Keys.FileStorage.default_key_timeout.get()
// println(Keys.PCM.default_node_priority)
} catch (e: Exception) {
log.error("Init properties: ${e.message}")
e.printStackTrace()
......@@ -234,7 +240,6 @@ class RTMProperties {
when (it.value) {
"$[basePath]" -> sb.append(this.basePath)
"$[null]" -> return null
// "$[file]" -> loadFromFile = true
"$[conf]" -> {
} //TODO: load conf file
else -> sb.append(conf.getString(
......
......@@ -16,11 +16,17 @@ data class RTMProperty<T : Any>(val key: String, private val defaultValue: T?, v
var path: String? = null
init {
initProperty()
}
fun initProperty() {
var value = RTMProperties.conf.getString(this.key) ?: defaultKey
if (type != null && type.simpleName.toLowerCase().contains("generic")) {
println()
}
if (value != null && value.startsWith("\$[file]")) {
path = RTMProperties.parsePath(value.substring(7)).toString()
value = try {
......@@ -42,7 +48,6 @@ data class RTMProperty<T : Any>(val key: String, private val defaultValue: T?, v
"type has not been provided"))::class.java)
RTMProperties.conf.setProperty(this.key, obj)
}
}
@Suppress("UNCHECKED_CAST")
......
......@@ -41,7 +41,10 @@ $[null] -> empty value"""
Default + "parallel_action_execution",
false, description = "resource action execution mode")
val keystore_path = RTMProperty(Default + "keystore_path", null, String::class.java)
val keystore_password = RTMProperty(Default + "keystore_password", null, String::class.java)
val use_ssl = RTMProperty(Default + "use_ssl", false)
val configuration_dir_path = RTMProperty(Default + "configuration_dir_path", null, String::class.java)
// }
}
\ No newline at end of file
......@@ -2,19 +2,45 @@ package psnc.m2dc.rtm.properties.keys
object Keys {
val Default = Default()
val TokenAuth = TokenAuth()
val ESM = ESM()
val Auth = Auth()
// val SqlStorage = SqlStorage()
val FileStorage = FileStorage()
val fm = FM
val PCM = PCM()
val Keystone = Keystone()
val TestBed = TestBed()
val RTM = RTM()
val RTMClient = RTMClient()
val SSHHosts = SSHHosts()
lateinit var Default :Default
private set
lateinit var TokenAuth : TokenAuth
private set
lateinit var ESM : ESM
private set
lateinit var Auth : Auth
private set
// var SqlStorage : SqlStorage
lateinit var FileStorage : FileStorage
private set
// var fm : FM
lateinit var PCM : PCM
private set
lateinit var Keystone : Keystone
private set
lateinit var TestBed : TestBed
private set
lateinit var RTM : RTM
private set
lateinit var RTMClient : RTMClient
private set
lateinit var SSHHosts : SSHHosts
private set
//
fun initializeKeys() {
Default = Default()
TokenAuth = TokenAuth()
ESM = ESM()
Auth = Auth()
FileStorage = FileStorage()
PCM = PCM()
Keystone = Keystone()
TestBed = TestBed()
RTM = RTM()
RTMClient = RTMClient()
SSHHosts = SSHHosts()
}
}
\ No newline at end of file
......@@ -334,7 +334,9 @@ class RPMApiImpl : RPMApi {
} catch (e: Exception) {
throw IllegalArgumentException("Set property (${action.resourceId}/$actionValue) failed")
// e.printStackTrace()
// logError(e,"Set property failed")
throw IllegalArgumentException("Set property (${action.resourceId}/$actionValue) failed: ${e.message}")
}
......@@ -380,7 +382,7 @@ class RPMApiImpl : RPMApi {
}
} catch (e: Exception) {
log.error("""setProperty failed (resourceId: ${resource.id} """)
log.error("""setProperty failed (resourceId: ${resource.id}) """)
log.debug("setProperty failed", e)
throw Exception(e.message)
}
......
......@@ -181,8 +181,6 @@ class RECSMonitoringApi private constructor(/*storage: IStorage<String>? = null*
fun listNodes(host: String): NodeList {
val result = RECSApi.getXML<NodeList>("""http://$host/REST/node""")
val nl = result.first ?: NodeList()
//TODO: debug print
// logDebug("recs nodes: " + RTMProperties.JSONParser.toJson(nl.nodeList.size))
return nl
}
......
......@@ -4,6 +4,9 @@ import psnc.m2dc.rtm.model.rpm.Resource
interface SSHApi {
companion object {
val SSH_COMMAND_TIMEOUT = 10000L
}
fun suspend()
fun getChildResources(): List<Resource>
......
......@@ -8,12 +8,14 @@ import psnc.m2dc.rtm.model.rpm.Resource
import psnc.m2dc.rtm.model.rpm.SSHCommand
import psnc.m2dc.rtm.properties.RTMProperties
import psnc.m2dc.rtm.properties.keys.Keys
import psnc.m2dc.rtm.rpm.nativeapi.SSHApi.Companion.SSH_COMMAND_TIMEOUT
import psnc.m2dc.rtm.utils.*
import java.io.BufferedReader
import java.io.File
import java.io.IOException
import java.io.InputStreamReader
import java.util.*
import java.util.concurrent.TimeUnit
private val MAP_TYPE = object : TypeToken<HashMap<String, HashMap<String, Any>>>() {
}.type
......@@ -252,7 +254,10 @@ open class SSHApiImpl private constructor(val resource: Resource) : SSHApi {
// printConsole("running ssh cmd2: " + cmd.toString())
p = Runtime.getRuntime().exec(array)
p.waitFor()
printConsole("pwait for : ${cmd.host}")
p.waitFor(SSH_COMMAND_TIMEOUT,TimeUnit.MILLISECONDS)
printConsole("pwaited for : ${cmd.host}")
var reader = BufferedReader(InputStreamReader(p.inputStream))
var line = reader.readLine()
......@@ -260,6 +265,7 @@ open class SSHApiImpl private constructor(val resource: Resource) : SSHApi {
stdOut.append(line).append("\n")
line = reader.readLine()
}
printConsole("pwait for read : ${cmd.host}")
reader = BufferedReader(InputStreamReader(p.errorStream))
line = reader.readLine()
......@@ -267,6 +273,7 @@ open class SSHApiImpl private constructor(val resource: Resource) : SSHApi {
stdErr.append(line).append("\n")
line = reader.readLine()
}
printConsole("pwait for read2 : ${cmd.host}")
if (Keys.Default.debug.get()) {
stdOut.toString()
.let { if (it.length > 250) it.substring(0, 200) else it }
......@@ -285,10 +292,11 @@ open class SSHApiImpl private constructor(val resource: Resource) : SSHApi {
throw Exception(e)
}
log.debug(stdOut.toString())
if (stdOut.length > 1)
return stdOut.toString().trim().let { printConsole("ssh result: ${it.take(256).replace("\n"," ")}"); it }
printConsole("output for ${cmd.host} :$stdOut")
return if (stdOut.length > 1)
stdOut.toString().trim().let { printConsole("ssh result: ${it.take(256).replace("\n"," ")}"); it }
else {
return stdErr.toString().trim().let { printConsole("ssh err $it"); it }
stdErr.toString().trim().let { printConsole("ssh err ${cmd.build().toJson() } :$it"); it }
}
}
......
......@@ -243,7 +243,7 @@ object Timer {
} finally {
val diff = (Date()).time - begin
if (diff > TIME_THRESHOLD) {
logInfo("""Execution time: ${parseTimeDiff(diff)}(${Date(begin)}) ($name)""")
logInfo("""($name): Execution time: ${parseTimeDiff(diff)}(${Date(begin)}) """)
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment