Commit b90f8673 by Tomasz Ciesielczyk

prediction script builder

parent c847ed32
......@@ -8,7 +8,6 @@ import psnc.m2dc.rtm.pcm.PCMApi
import psnc.m2dc.rtm.pcm.algorithm.Evaluation
import psnc.m2dc.rtm.rpm.RPMApi
import psnc.m2dc.rtm.utils.logError
import psnc.m2dc.rtm.utils.printConsole
import java.util.ArrayList
import kotlin.Comparator
import kotlin.collections.HashMap
......@@ -60,7 +59,7 @@ class CurrentState(val powerUsage: Double) {
val power = nodeUtil?.powerUsage ?: powerMap[node.id] ?: {
logError("Power Usage not provided for ${node.id}");0.0
}.invoke()
printConsole("xxx: power for${node.id}= $power")
// printConsole("xxx: power for${node.id}= $power")
val currentPerf = ActionCache.getPerformanceSetting(node.id)
val currentProfile = nodeUtil?.loadProfile ?: ActionCache.getProfile(node.id)
nodeMap[node.id] = NodeState(node, power, currentPerf, currentProfile)
......@@ -69,7 +68,7 @@ class CurrentState(val powerUsage: Double) {
100.0
else
nodeUtil?.utilization ?: model.getUtil(power, currentPerf)
printConsole("util for: ${node.id}- $util/$power")
// printConsole("util for: ${node.id}- $util/$power")
val newNodeUtil = NodeUtil(node.id, util, power, currentProfile, null, currentTimeInterval)
currentUtil[node.id] = newNodeUtil
if (newNodeUtil.isInUse(currentTimeInterval)) {
......@@ -85,7 +84,7 @@ class CurrentState(val powerUsage: Double) {
})
this.orderUnusedMachines()
this.orderMachines()
printConsole("${this.activeMachines} unused: ${this.unusedMachines}")
// printConsole("${this.activeMachines} unused: ${this.unusedMachines}")
} catch (ex: Exception) {
ex.printStackTrace()
......
package psnc.m2dc.rtm.pcm
import psnc.m2dc.rtm.CurrentState
import psnc.m2dc.rtm.PowerSettings
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.SSHCommand
import psnc.m2dc.rtm.properties.RTMProperties
import psnc.m2dc.rtm.properties.keys.Keys
import psnc.m2dc.rtm.rpm.RPMApi
import psnc.m2dc.rtm.utils.printConsole
import psnc.m2dc.rtm.utils.toJsonObj
import java.io.File
/**
*
* Created by Tomek on 2018-11-30.
*/
object ActionPredictor {
fun predict(powerLimit: Double?): PredictedActionList {
val powerUsage = RPMApi.instance().getPowerUsage()
val maxPower = Math.max(DAO.Resource.getMaximumPowerUsage() ?: 0.0, powerUsage)
val currentLimit = powerLimit ?: maxPower
val pcmBuffer = currentLimit * Keys.PCM.power_buffer.get() + Keys.PCM.absolute_power_buffer.get()
val finalPowerLimit = currentLimit - (pcmBuffer)
val result = PredictedActionList()
val maximumPowerIncrease = maxPower - powerUsage
val powercapRatio = maxPower - currentLimit
var minPower = finalPowerLimit
listOf(0.1, 0.15, 0.15).forEach { lvl ->
val powerSpan = Math.min(lvl * maximumPowerIncrease, lvl * powercapRatio)
powerUsage + pcmBuffer
val state = CurrentState(pcmBuffer + powerSpan + minPower)
val algoResult = PCMAlgorithm(state).next()
val toList = algoResult.getResources().map { resource ->
resource.id to algoResult.getActions(resource)
}
val p = PredictedAction(minPower, minPower + powerSpan, toList)
minPower += powerSpan
result.list.add(p)
}
return result
}
class PredictedActionList(val list: ArrayList<ActionPredictor.PredictedAction> = ArrayList()) {
fun generateScripts(consoleOutput: Boolean = false) {
val sb = StringBuilder()
this.list.forEachIndexed { idx, it ->
sb.append(it.minPower).append("_").append(it.maxPower).append("=./pcm_prediction_$idx.sh\n")
if (!consoleOutput)
File("pcm_prediction_$idx.sh").writeText(it.toScript())
else printConsole(it.toScript())//printfile
}
if (!consoleOutput)
File("pcm_predictions.idx").writeText(sb.toString())
else printConsole(sb.toString())//printfile
// printConsole(sb.toString())
}
}
class PredictedAction(val minPower: Double, val maxPower: Double, val actionList: List<Pair<String, PowerSettings.PowerSetting>> = ArrayList()) {
fun toScript(): String {
val sb = StringBuilder()
this.actionList.forEach { resourceDetails ->
val resourceId = resourceDetails.first
val performance = resourceDetails.second.performance
val actionList = resourceDetails.second.actions
// sb.append(resourceId).append(":").append(performance).append("\n")
sb.append("echo $resourceId:$performance").append("\n")
actionList.forEach { action ->
val actionValue = action.properties[ResourceAction.PROPERTY_ACTION_VALUE]
val obj = RTMProperties.JSONParser.fromJson(actionValue, Any::class.java)?.toJsonObj()
if (obj != null && obj.isJsonArray) {
val array = obj.asJsonArray.map { it.toString() }
val host = LightStorage.instance.get<String>("resources", resourceId, "properties", "ssh_host")
val username = LightStorage.instance.get<String>("resources", resourceId, "properties", "ssh_username")
if (host != null) {
val cmd = SSHCommand(host, "./set_property.sh", username, array).build()
val s = cmd.joinToString(separator = " ") { it }
sb.append(s).append("\n")
} else {
sb.append("echo $resourceId -> host is null").append("\n")
}
}
}
}
return sb.toString()
}
}
}
\ No newline at end of file
......@@ -9,13 +9,10 @@ import psnc.m2dc.rtm.StorageKeys
import psnc.m2dc.rtm.dao.DAO
import psnc.m2dc.rtm.model.rest.*
import psnc.m2dc.rtm.model.rpm.Resource
import psnc.m2dc.rtm.properties.RTMProperties
import psnc.m2dc.rtm.properties.keys.Keys
import psnc.m2dc.rtm.rpm.RPMApi
import psnc.m2dc.rtm.utils.Timer
import psnc.m2dc.rtm.utils.printConsole
import psnc.m2dc.rtm.utils.sum
import psnc.m2dc.rtm.utils.toJsonObj
class PCMApi() {
//#region initialize INSTANCE
......@@ -75,6 +72,7 @@ class PCMApi() {
fun setPowerLimit(limit: Double): Boolean {
StorageKeys.POWER_LIMIT = Values.powerLimit(limit) ?: 0.0
ActionPredictor.predict(this.getPowerLimit())
return instance().checkState()
}
......@@ -127,36 +125,14 @@ class PCMApi() {
fun getCurrentState(): Any = PCMWorker.getCurrentState() ?: this.checkLimits()
fun predictPCMActions(): PredictedActionList {
val powerUsage = RPMApi.instance().getPowerUsage()
val maxPower = Math.max(DAO.Resource.getMaximumPowerUsage() ?: 0.0, powerUsage)
val currentLimit = this.getPowerLimit() ?: maxPower
val pcmBuffer = currentLimit * Keys.PCM.power_buffer.get() + Keys.PCM.absolute_power_buffer.get()
val finalPowerLimit = currentLimit - (pcmBuffer)
val result = PredictedActionList()
val maximumPowerIncrease = maxPower - powerUsage
val powercapRatio = maxPower - currentLimit
var minPower = finalPowerLimit
listOf(0.1, 0.15, 0.15).forEach { lvl ->
val powerSpan = Math.min(lvl * maximumPowerIncrease, lvl * powercapRatio)
powerUsage + pcmBuffer
val state = CurrentState(pcmBuffer + powerSpan + minPower)
val algoResult = PCMAlgorithm(state).next()
val toList = algoResult.getResources().map { resource ->
resource.id to algoResult.getActions(resource)
}
val p = PredictedAction(minPower, minPower + powerSpan, toList)
minPower += powerSpan
result.list.add(p)
}
return result
fun predictPCMActions(): ActionPredictor.PredictedActionList {
return ActionPredictor.predict(this.getPowerLimit())
}
fun checkState(): Boolean {
val limits = this.checkLimits()
printConsole("checkLimits $limits")
// printConsole("checkLimits $limits")
if (limits.limitExceeded) {// || Keys.PCM.simple_performance_restore.get()) {
Timer.start()
val state = CurrentState(limits.currentPowerUsage +
......@@ -169,6 +145,66 @@ class PCMApi() {
}
fun checkLimits(): PCMState {
try {
Timer.start()
val currentPowerOverLimit: Pair<Double, Double> = instance().getPowerOverLimit(true)
return PCMState(currentPowerOverLimit.first > 0, -currentPowerOverLimit.first,
currentPowerOverLimit.second)
} finally {
Timer.stop()
}
}
private fun getMaxPowerUsageList(): HashMap<String, Double> {
val res = HashMap<String, Double>()
DAO.Resource.getResources().filter {
it.value.get(Resource.Property.is_node, false)
}.values.forEach { resource ->
try {
val type = DAO.ResourcesManagerApi.getResourceType(resource)
val powerModel = DAO.Resource.getComponentPowerModel(type.id, null)!!
val powerMax = powerModel.getMax(ActionCache.getPerformanceSetting(resource.id))
res[resource.id] = powerMax
} catch (ex: Exception) {
RPMApi.log.error(
"""Cannot get max power usage for resource ${resource.id}, cause: ${ex.message} (${ex
.stackTrace[0]})""")
}
}
return res
// return null
}
/**
check if power limit is not exceeded
*/
fun getPowerOverLimit(getSparePower: Boolean = false): Pair<Double, Double> {
var totalLimit = StorageKeys.POWER_LIMIT
val map: HashMap<String, Double> = if (this.getPowerCappingStrategy() == PowerCappingStrategy.LAZY) {
RPMApi.instance().getPowerUsageList()
} else {
this.getMaxPowerUsageList()
}
if (totalLimit == null) {
totalLimit = this.getMaxPowerUsageList().sum()
}
val totalUsage = map.sum()
// printConsole("check limit: ${totalUsage} limit: ${totalLimit}")
if (totalUsage >= totalLimit || getSparePower) {
return Pair(totalUsage - totalLimit, totalUsage)
}
return Pair(0.0, totalUsage)
}
}
/**
// /**
// check if temperature limit is not exceeded
// return extended values
......@@ -176,7 +212,7 @@ class PCMApi() {
// fun isTemperatureLimitExceeded(nodeList: List<String>): Boolean {
// return !checkTemperatureLimit(nodeList).isEmpty()
// }
//#endregion
//#endregion
// /**
......@@ -214,102 +250,4 @@ class PCMApi() {
//
// return result
// }
fun checkLimits(): PCMState {
try {
Timer.start()
val currentPowerOverLimit: Pair<Double, Double> = instance().getPowerOverLimit(true)
return PCMState(currentPowerOverLimit.first > 0, -currentPowerOverLimit.first,
currentPowerOverLimit.second)
} finally {
Timer.stop()
}
}
/**
check if power limit is not exceeded
*/
fun getPowerOverLimit(getSparePower: Boolean = false): Pair<Double, Double> {
var totalLimit = StorageKeys.POWER_LIMIT
val map: HashMap<String, Double> = if (this.getPowerCappingStrategy() == PowerCappingStrategy.LAZY) {
RPMApi.instance().getPowerUsageList()
} else {
this.getMaxPowerUsageList()
}
if (totalLimit == null) {
totalLimit = this.getMaxPowerUsageList().sum()
}
val totalUsage = map.sum()
// printConsole("check limit: ${totalUsage} limit: ${totalLimit}")
if (totalUsage >= totalLimit || getSparePower) {
return Pair(totalUsage - totalLimit, totalUsage)
}
return Pair(0.0, totalUsage)
}
class PredictedActionList(val list: ArrayList<PredictedAction> = ArrayList()) {
fun generateScripts() {
val sb = StringBuilder()
this.list.forEach {
sb.append(it.minPower).append(":").append(it.maxPower).append("\n")
printConsole(it.toScript())//printfile
}
printConsole(sb.toString())
}
}
class PredictedAction(val minPower: Double, val maxPower: Double, val actionList: List<Pair<String, PowerSettings.PowerSetting>> = ArrayList()) {
fun toScript(): String {
val sb = StringBuilder()
this.actionList.forEach { resourceDetails ->
val resourceId = resourceDetails.first
val performance = resourceDetails.second.performance
val actionList = resourceDetails.second.actions
sb.append(resourceId).append(":").append(performance).append("\n")
actionList.forEach { action ->
val actionValue = action.properties[ResourceAction.PROPERTY_ACTION_VALUE]
val obj = RTMProperties.JSONParser.fromJson(actionValue, Any::class.java)?.toJsonObj()
if (obj != null && obj.isJsonArray) {
val s = obj.asJsonArray.map { it.toString() }.joinToString(separator = " ") { it }
sb.append(s).append("\n")
}
}
}
return sb.toString()
}
}
// private fun getMaxPowerUsage(): Double? {
// return this.getMaxPowerUsageList().sum()
// }
private fun getMaxPowerUsageList(): HashMap<String, Double> {
val res = HashMap<String, Double>()
DAO.Resource.getResources().filter {
it.value.get(Resource.Property.is_node, false)
}.values.forEach { resource ->
try {
val type = DAO.ResourcesManagerApi.getResourceType(resource)
val powerModel = DAO.Resource.getComponentPowerModel(type.id, null)!!
val powerMax = powerModel.getMax(ActionCache.getPerformanceSetting(resource.id))
res[resource.id] = powerMax
} catch (ex: Exception) {
RPMApi.log.error(
"""Cannot get max power usage for resource ${resource.id}, cause: ${ex.message} (${ex
.stackTrace[0]})""")
}
}
return res
// return null
}
}
*/
\ No newline at end of file
......@@ -27,7 +27,7 @@ object Utils {
ResourceAction(resource.id, it.powerAction, it.properties)
}
?: {
logError("Unknown performance setting no actions provided for: ${resource.id} ($perf")
logError("Unknown performance setting no actions provided for: ${resource.id} ($perf)")
// listOf<ResourceAction>(
// ResourceAction.initializeAction(resource.id, "cpu_freq", perf).let {
// it.put(ResourceAction.SET_PROPERTY_ACTION_VALUE, resource.id)
......
......@@ -2,6 +2,7 @@ package psnc.m2dc.rtm
import psnc.m2dc.rtm.dao.LightStorage
import psnc.m2dc.rtm.esm.ESMApi
import psnc.m2dc.rtm.pcm.ActionPredictor
import psnc.m2dc.rtm.pcm.PCMApi
import psnc.m2dc.rtm.properties.keys.Keys
import psnc.m2dc.rtm.utils.logError
......@@ -34,7 +35,7 @@ object RTMScannerWorker {
}
val isRunning: Boolean
get() = this.scanner?.isRunning?:false
get() = this.scanner?.isRunning ?: false
private class Scanner : RTMWorker() {
var stop = false
......@@ -59,11 +60,11 @@ object RTMScannerWorker {
PCMApi.instance().checkState()
LightStorage.saveStorage()
iter = 0
} else if (iter > esmRatio ) {
if(Keys.ESM.status.get()) {
} else if (iter > esmRatio) {
ActionPredictor.predict(PCMApi.instance().getPowerLimit())
if (Keys.ESM.status.get()) {
ESMApi.instance().optimize()
}
else{
} else {
printConsole("ESM is stopped")
}
}
......
......@@ -5,14 +5,16 @@ import psnc.m2dc.rtm.dao.DAO
import psnc.m2dc.rtm.dao.LightStorage
import psnc.m2dc.rtm.esm.ESMApi
import psnc.m2dc.rtm.model.rest.NodePriority
import psnc.m2dc.rtm.model.rest.Values
import psnc.m2dc.rtm.model.rpm.ModelMap
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.rpm.RPMApiImpl
import psnc.m2dc.rtm.utils.*
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 spark.Spark
/**
......@@ -30,9 +32,9 @@ object ServerInitializer {
setDefaultPriorities()
save()
StorageKeys.POWER_LIMIT = Values.powerLimit(440.0)
val a =PCMApi.instance().predictPCMActions()
a.generateScripts().toJson(true)
// StorageKeys.POWER_LIMIT = Values.powerLimit(440.0)
// val a =PCMApi.instance().predictPCMActions()
// a.generateScripts().toJson(true)
setScanner()
// ReloadTask.start()
if (Keys.Default.use_ssl.get()) {
......
package psnc.m2dc.rtm.commands.java
val APP_VERSION = "1.0.424_61797"
\ No newline at end of file
val APP_VERSION = "1.0.425_63508"
\ No newline at end of file
package psnc.m2dc.rtm.client
const val APP_VERSION = "1.1.424_61798"
\ No newline at end of file
const val APP_VERSION = "1.1.425_63509"
\ No newline at end of file
......@@ -98,8 +98,7 @@ class RECSApiMock(parser: XStream) : RECSApi(parser) {
override fun <T> getXML(url: String, headers: HashMap<String, String>):
Pair<T?, Map<String, String>> {
val res = this.get(url, headers).first
println("recs output: $res")
// printConsole("recs output: $res")
return Pair(XMLParser.fromXML(res) as T?, headers)
}
......
......@@ -60,7 +60,7 @@ object LightStorage {
val result = HashMap<String, T>()
val nodes = LightStorage.instance.listIndex(idx)
nodes?.forEach { path ->
printConsole("xpath: $path ${T::class.java.simpleName}")
// printConsole("xpath: $path ${T::class.java.simpleName}")
val obj = this.getObject<T>(path)
if (obj != null)
result[path] = obj
......
......@@ -308,22 +308,22 @@ abstract class ResourceManager : DataDAO() {
}
fun getUtil(resourceIdList: List<String>): HashMap<String, Any> {
val apiType = ApiType.current_util
val measurementFun = { resourceId: String ->
val res = DAO.Measurements.getUtil(resourceId)
res
}
val result = getMeasurements(resourceIdList, measurementFun, apiType, null)
resourceIdList.filter { resourceId ->
!result.containsKey(resourceId)
}.forEach { filteredResourceId ->
calculateUtilization(filteredResourceId)?.let { result[filteredResourceId] = it }
}
// printConsole("testx5 $result")
return result
}
// fun getUtil(resourceIdList: List<String>): HashMap<String, Any> {
//
// val apiType = ApiType.current_util
// val measurementFun = { resourceId: String ->
// val res = DAO.Measurements.getUtil(resourceId)
// res
// }
// val result = getMeasurements(resourceIdList, measurementFun, apiType, null)
// resourceIdList.filter { resourceId ->
// !result.containsKey(resourceId)
// }.forEach { filteredResourceId ->
// calculateUtilization(filteredResourceId)?.let { result[filteredResourceId] = it }
// }
//// printConsole("testx5 $result")
// return result
// }
//#region private
......@@ -392,7 +392,9 @@ abstract class ResourceManager : DataDAO() {
DAO.Measurements.addSensorValue(resource, sensorId, value)
// printConsole("${DAO.Measurements.getSensorValue(resource, sensorId )} expected:$row" )
}
} catch (e: Exception) {
} catch (e: TaskExecutor.DuplicateExecutionException) {
logWarn(e, "duplicate task for $id")
} catch (e: Exception) {
logError(e, "Cannot get result for $id")
}
}
......
......@@ -21,7 +21,7 @@ import java.io.File
object SettingsDAO : DataDAO() {
val model_map by lazy {
LightStorage.getMapWrapper<ComponentPowerModel>(ComponentPowerModel.default("default"), "model_map")
LightStorage.getMapWrapper(ComponentPowerModel.default("default"), "model_map")
}
val sensorMap by lazy {
RTMProperties.getJson<SensorMap>(RTMProperties.parsePath(Keys.Default.sensor_map_file.get()))
......@@ -43,12 +43,8 @@ object SettingsDAO : DataDAO() {
logDebug("save models")
val hashMap = model_map.getMap()
hashMap.forEach { _, model ->
//tutaj null pointer
val f = File(location + File.separator + model.name + ".pmx")
f.writeText(model.toString()) //tutaj nullpointer
File(location + File.separator + model.name + ".pmx").writeText(model.toString())
}
logDebug("save types")
}
}
......
......@@ -291,7 +291,7 @@ class ComponentPowerModel(val name: String, private val perfList: List<Double>,
var min = this.powerUsage[rowIdx].first()
var minIdx = 0
printConsole("getUtil: $powerUsage,$performanceSetting:$min-$max")
// printConsole("getUtil: $powerUsage,$performanceSetting:$min-$max")
this.powerUsage[rowIdx].forEachIndexed { idx, it ->
if (it in min..powerUsage && minIdx < idx) {
minIdx = idx
......@@ -302,7 +302,7 @@ class ComponentPowerModel(val name: String, private val perfList: List<Double>,
max = it
}
}
printConsole("getUtil2: $powerUsage,$performanceSetting: $min-$max, $minIdx-$maxIdx")
// printConsole("getUtil2: $powerUsage,$performanceSetting: $min-$max, $minIdx-$maxIdx")
val minUtil = this.utilStep * minIdx
val maxUtil = this.utilStep * maxIdx
val ratio = if (max == min) {
......@@ -312,7 +312,7 @@ class ComponentPowerModel(val name: String, private val perfList: List<Double>,
}
// sprawdzic czy zwrcaca dobrwartosc
val util = minUtil + (maxUtil - minUtil) * (ratio)
printConsole("xxx calculated util $util")
// printConsole("xxx calculated util $util")
return util
}
......
......@@ -61,10 +61,10 @@ class RTMProperties {
val storage = DataExpirationStorage<String>(300000, StandardSortedMap<String>(300000L, false),
newStorage, DataExpirationStorage.CleanMode.EVENT_BASED)
try {
log.debug("load storage for path: ${path}")
log.debug("load storage for path: $path")
storage.load()
} catch (ex: FileNotFoundException) {
log.warn("File:${path} not found ", ex.message)
log.warn("File:$path not found ", ex.message)
}
return storage
}
......@@ -100,7 +100,7 @@ class RTMProperties {
}
}
fun printConf() {
private fun printConf() {
val sb = StringBuilder()
this.conf.keys.forEach { sb.append("$it=>${this.conf.getString(it)}\n") }
printConsole(sb.toString(), false)
......
......@@ -93,16 +93,16 @@ abstract class TaskExecutor {
var taskAdded = false
try {
if (addTask(task as ManagementWorker<Any>, mode)) {
// printConsole("xxx: add task")
// printConsole("xxx: add task")
taskAdded = true
task.start()
} else {
// printConsole("xxx: not add task")
// printConsole("xxx: not add task")
}
} finally {
if (taskAdded) {
removeTask(task)
// printConsole("xxx: removed task")
// printConsole("xxx: removed task")
}
}
}
......@@ -176,7 +176,7 @@ abstract class TaskExecutor {
synchronized(currentlyExecuting) {
if (!this.currentlyExecuting.containsKey(task.getId())) {
// printConsole("error")
throw Exception("Task has been removed earlier")
throw DuplicateExecutionException("Task has been removed earlier")
}
if (currentlyExecuting[task.getId()]!!.size == 1) {
......@@ -198,7 +198,7 @@ abstract class TaskExecutor {
synchronized(this.currentlyExecuting) {
// printConsole("add task ${task.getId()} ${this.currentlyExecuting.toString()} ")
if (mode != ExecutionMode.SIMULTANEOUS && this.currentlyExecuting.containsKey(task.getId())) {
throw Exception("Task has been added earlier")
throw DuplicateExecutionException("Task has been added earlier")
}
if (this.currentlyExecuting[task.getId()] == null) {
this.currentlyExecuting[task.getId()] = ArrayList<ManagementWorker<Any>>()
......@@ -208,6 +208,8 @@ abstract class TaskExecutor {
}
}
class DuplicateExecutionException(s: String) : Exception(s)
/**
* check if task can be executed
*/
......
......@@ -12,10 +12,7 @@ import psnc.m2dc.rtm.rpm.ManagementExecutor
import psnc.m2dc.rtm.rpm.ManagementWorker
import psnc.m2dc.rtm.rpm.ManagementWorkerImpl
import psnc.m2dc.rtm.rpm.TaskExecutor
import psnc.m2dc.rtm.utils.Timer
import psnc.m2dc.rtm.utils.logError
import psnc.m2dc.rtm.utils.logInfo
import psnc.m2dc.rtm.utils.printConsole
import psnc.m2dc.rtm.utils.*
import java.util.concurrent.Future
import java.util.concurrent.TimeUnit
......@@ -204,7 +201,7 @@ 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()
printConsole("nodelist size: " + RTMProperties.JSONParser.toJson(nl.nodeList.size))
logDebug("recs nodes: " + RTMProperties.JSONParser.toJson(nl.nodeList.size))
return nl
}
......
......@@ -305,4 +305,5 @@ fun getSSHCommand(resource: Resource, cmd: String,
else {
throw Exception("No ssh properties ")
}
}
\ No newline at end of file
}
......@@ -72,9 +72,9 @@ fun logError(msg: String) {
val result = "${parseDate(Date())}:${i.className}-${i.methodName}(${i.fileName}:${i.lineNumber}): $msg"
RTMProperties.log.error(result)
if (_PRINT_DEBUG) {
println(msg)
}
// if (_PRINT_DEBUG) {
// println(msg)
// }
}
fun logInfo(msg: String) {
......@@ -84,6 +84,12 @@ fun logInfo(msg: String) {
RTMProperties.log.info(result)
}
fun logWarn(e: Exception, msg: String) {
val i = Throwable().stackTrace[2]
val result = "${parseDate(Date())}:${e::class.java.simpleName}${e.message}, ${i.className}-${i.methodName}(${i.fileName}:${i.lineNumber}): $msg"
RTMProperties.log.warn(result)
}
fun logWarn(msg: String) {
val i = Throwable().stackTrace[2]
......@@ -139,9 +145,10 @@ fun Any.toJson(print: Boolean): String {
return json