Commit 9eafcedb by Tomasz Ciesielczyk

evaluation update, utilization new formula, resource conf file initializer

parent 0d5cc679
java -jar ../rtm-cli-test.jar --config="/home/tomaszc/rtmserver_dev/rtm.conf" "$@"
java -jar ../rtm-cli-test.jar --config="../rtm.conf" "$@"
java -jar ../rtm-server-test.jar --config-file /home/tomaszc/rtmserver_dev/rtm.conf start
java -jar ../rtm-server-test.jar --config-file ../rtm.conf start
......@@ -4,27 +4,9 @@
"powerCapabilities": ["PM"],
"weight": 1.0,
"validIn": {
"begin": 1542200000000,
"length": 3600000000
"begin": 1542500000000,
"length": 13600000000
}
},
"compute16": {
"nodeId": "compute16",
"powerCapabilities": [ "PM"],
"weight": 0.5,
"validIn": {
"begin": 1542200000000,
"length": 3600000000
}
},
"compute18": {
"nodeId": "compute18",
"powerCapabilities": [ "PM"],
"weight": 0.0,
"validIn": {
"begin": 1542200000000,
"length": 3600000000
}
}
}
}
{
"RCU_86659187831_BB_9_0": {
"id": "RCU_86659187831_BB_9_0",
"typeId": "xeon.e.cpu",
"compute18": {
"id": "compute18",
"typeId": "xeonnode.ipmi",
"properties": {
"NodeModel": {
"modelName": "RCU_86659187831_BB_9_0",
"architecture": "x86",
"properties": {}
},
"ipmi_host": "10.11.12.235",
"ssh_username": "tomaszc",
"recs_host": "10.11.12.242",
"ssh_host": "10.12.1.32",
"ssh_host": "10.12.10.18",
"is_node": true,
"node_id": "RCU_86659187831_BB_9_0"
"node_id": "compute18"
}
},
"RCU_86659187831_BB_16_0": {
"id": "RCU_86659187831_BB_16_0",
"typeId": "xeon.e.v100",
"compute15": {
"id": "compute15",
"typeId": "xeonnode.ipmi",
"properties": {
"NodeModel": {
"modelName": "RCU_86659187831_BB_16_0",
"architecture": "x86",
"properties": {}
},
"ipmi_host": "10.11.12.232",
"ssh_username": "tomaszc",
"recs_host": "10.11.12.242",
"ssh_host": "10.12.1.26",
"ssh_host": "10.12.10.15",
"is_node": true,
"node_id": "RCU_86659187831_BB_16_0"
"node_id": "compute15"
}
},
"RCU_86659187831_BB_14_0": {
"id": "RCU_86659187831_BB_14_0",
"typeId": "xeon.e.p40",
"compute16": {
"id": "compute16",
"typeId": "xeonnode",
"properties": {
"NodeModel": {
"modelName": "RCU_86659187831_BB_14_0",
"architecture": "x86",
"properties": {}
},
"ssh_username": "tomaszc",
"recs_host": "10.11.12.242",
"ssh_host": "10.12.1.25",
"ssh_host": "10.12.10.16",
"is_node": true,
"node_id": "RCU_86659187831_BB_14_0"
"node_id": "compute16"
}
},
"compute18": {
"id": "compute18",
"typeId": "xeonnode.ipmi",
} ,
"compute17": {
"id": "compute17",
"typeId": "xeonnode",
"properties": {
"ipmi_host": "10.11.12.235",
"ssh_username": "tomek",
"ssh_host": "10.12.10.18",
"ssh_username": "tomaszc",
"ssh_host": "10.12.10.17",
"is_node": true,
"node_id": "compute18"
"node_id": "compute17"
}
},
"compute16": {
"id": "compute16",
} ,
"compute7": {
"id": "compute7",
"typeId": "xeonnode",
"properties": {
"ssh_username": "tomek",
"ssh_host": "10.12.10.16",
"ssh_username": "tomaszc",
"ssh_host": "10.12.10.7",
"is_node": true,
"node_id": "compute16"
}
},
"compute15": {
"id": "compute15",
"typeId": "xeonnode.ipmi",
} ,
"compute8": {
"id": "compute8",
"typeId": "xeonnode",
"properties": {
"ipmi_host": "10.11.12.232",
"ssh_username": "tomek",
"ssh_host": "10.12.10.15",
"ssh_username": "tomaszc",
"ssh_host": "10.12.10.8",
"is_node": true,
"node_id": "compute15"
"node_id": "compute16"
}
}
}
}
\ No newline at end of file
#resource_type_profile=model
xeon.e.p40_default=default
xeon.e.p40_gpu=xeon_e_p40_gpu
xeonnode_default=xeon_rapl_node_auto
xeonnode.ipmi_default=xeon_rapl_node_auto
Express-KL.IntelR.XeonR.CPU.E3-1505M.v6.@.3.00GHz_default=default
Express-BD7.IntelR.XeonR.CPU.D-1548.@.2.00GHz_default=default
xeonnode.ipmi_default=xeon_rapl_node_auto
default_default=default
default_cpubound=default
xeon.e.v100_default=default
xeon.e.v100_gpu=xeon_e_v100_gpu
Host key verification failed._default=default
xeon.e.cpu_default=xeon_e_cpu
......@@ -16,10 +16,10 @@
"current_power_usage":[{"id":"current_power_usage","type":"current_power_usage","name":"actualPowerUsage","api":"recs"}],
"current_util":[{"id":"current_util","type":"current_util","name":"current_util","api":"ssh"}],
"current_temperature":[{"id":"current_temperature","type":"current_temperature","name":"outletTemperature","api":"recs"},
{"id":"ssh_current_temperature","type":"current_temperature","name":"current_temperature","api":"ssh"}],
"temperature":[{"id":"outletTemperature","type":"temperature","name":"outletTemperature","api":"recs"},
{"id":"inletTemperature","type":"temperature","name":"inletTemperature","api":"recs"},
{"id":"highestTemperature","type":"temperature","name":"highestTemperature","api":"recs"}]
{"id":"ssh_current_temperature","type":"current_temperature","name":"current_temperature","api":"ssh"}],
{"id":"highestTemperature","type":"temperature","name":"highestTemperature","api":"recs"}] ,
"suspend":[{"id":"ssh_suspend","type":"suspend","name":"ssh_node_suspend","api":"ssh"}],
"turn_off":[{"id":"recs_turn_off","type":"turn_off","name":"recs_turn_off","api":"recs"}],
"set_property":[{"id":"ssh_set_property","type":"set_property","name":"ssh_set_property","api":"ssh"}]
......
......@@ -2,12 +2,27 @@
source $(dirname "$0")/logger.sh
log_issuer=$(whoami)":"`basename "$0"`
DEBUG=false
NODE_ID=$(hostname | cut -d"." -f1)
while getopts "n:" OPTION
do
case "${OPTION}" in
n)
NODE_ID=$OPTARG
# exit
;;
\?)
echo "help"
# exit
;;
esac
done
testcmd=$(command -v sensors)
if [ ${#testcmd} -eq 0 ]; then
current_power_usage="\"current_power_usage\": {}\n"
else
NODE_ID=$(hostname | cut -d"." -f1)
power=$(sensors -u | egrep 'power[1-9]+_average:' | cut -d ' ' -f 4 | tr '\\n' ';')
current_power_usage="\"current_power_usage\": {\""$NODE_ID"\":"$power"}\n"
fi
......
linux:
nvidia-smi - jeśli jest karta graficzna
cpupower
lmsensors
mpstat
lmsensors
https://github.com/powercap/raplcap
\ No newline at end of file
......@@ -52,6 +52,7 @@ class ESMWorker private constructor(val state: CurrentState) : RTMWorker() {
synchronized(lock) {
val t = Thread(Runnable {
val actions = algorithm.next()
notify(actions)
if(Keys.RTM.debug_actions.get()){
printConsole(actions.toJson())
......
......@@ -2,6 +2,7 @@ package psnc.m2dc.rtm.pcm.algorithm
import org.slf4j.LoggerFactory
import psnc.m2dc.rtm.model.rpm.ComponentPowerModel
import psnc.m2dc.rtm.model.rpm.ComponentPowerModel.Companion.MAX_PERFORMANCE_LVL
import psnc.m2dc.rtm.model.rpm.StateDefinition
import psnc.m2dc.rtm.properties.RTMProperties
import psnc.m2dc.rtm.utils.toJson
......@@ -167,7 +168,7 @@ advancedPriorityMode: Boolean = true) {
var sum = 0.0
perfLvlxMap.forEach { key, perfLvlx ->
val state = this.stateMap.get(key)!!
val util = state.model.recalculateUtil(state.perfLevel, perfLvlx, state.util)
val util = state.model.calculateUtil(perfLvlx, state.perfLevel, state.util)
sum += state.model.getPower(perfLvlx, util)
}
......@@ -179,7 +180,7 @@ advancedPriorityMode: Boolean = true) {
perfLvlxMap.forEach { key, perfLvlx ->
val state = this.stateMap.get(key)!!
val util = state.model.recalculateUtil(state.perfLevel, perfLvlx, state.util)
val util = state.model.calculateUtil(perfLvlx,state.perfLevel, state.util)
sum += state.power - state.model.getPower(perfLvlx, util)
}
......@@ -190,14 +191,14 @@ advancedPriorityMode: Boolean = true) {
val state = this.stateMap.get(resourceId)!!
val util = state.model.recalculateUtil(state.perfLevel, perfLvlx, state.util)
val util = state.model.calculateUtil( perfLvlx,state.perfLevel, state.util)
return state.model.getPower(perfLvlx, util)
}
fun evaluateState(resourceId: String, perfLvlx: Double): Double {
val i0 = this.stateMap.get(resourceId) ?: throw NullPointerException("resource not found: ${resourceId}")
// print("resourceid: ${resourceId} ")
// print("resourceid: ${resourceId} ")
//poprawic funkcje celu
//sprawdzic ten wynik{"compute18":73.0,"compute16":41.0,"compute15":95.0}
//czemu ooplaca bardzie sie zwiekszy dla priorytetu 0 niz 1 , perf 95 >= perf 73 ? -> sprawdzić
......@@ -235,47 +236,61 @@ advancedPriorityMode: Boolean = true) {
fun evaluateState(currentState: StateDefinition, perfLvlx: Double, print: Boolean = false): Double {
val model = currentState.model
val MAX_PERFORMANCE_LVL = 100.0
val x = 0.2 //TODO: unknown parameter?
val util0 = model.recalculateUtil(currentState.perfLevel, MAX_PERFORMANCE_LVL,
currentState.util) //predict utilization for maximum performance
val power0 = model.getPower(MAX_PERFORMANCE_LVL, util0) //power usage for maximum performance
val performance0 = model.getPerformance(MAX_PERFORMANCE_LVL) //power usage for maximum performance
val utilx = model.recalculateUtil(currentState.perfLevel, perfLvlx, currentState.util)
val powerx = model.getPower(perfLvlx, utilx)
val performancex = model.getPerformance(perfLvlx)
val powerChange = power0 - powerx
val deltaPerf = performancex / performance0
if (deltaPerf == 0.0) {
return ComponentPowerModel.LOW_VALUE
}
var gainX = 0.0
//deltaPerf = model.getDeltaPerf(MAX_PERFORMANCE_LVL, perfLvlx, util0, utilx)
var costX = 0.0 // -(alpha) * (deltaPerf - 1)
val weight: Double
if (currentState.priority == 0.0) {
val efficiencyX = model.getEfficiency(MAX_PERFORMANCE_LVL, perfLvlx)
gainX = (Math.pow(efficiencyX, (1 - alpha + x) * (beta + 1)) - 1)
weight = powerx
} else if (currentState.priority == 1.0) {
costX = ((1 / Math.pow(deltaPerf, (alpha + x) * (beta + 1))) - 1)
weight = Math.abs(powerChange)
} else {
val efficiencyX = model.getEfficiency(MAX_PERFORMANCE_LVL, perfLvlx)
gainX = (Math.pow(efficiencyX, (1 - alpha) * (beta + 1)) - 1) *
Math.pow(deltaPerf, alpha * beta)
costX = currentState.priority * ((1 / Math.pow(deltaPerf, alpha * (beta + 1))) - 1)
weight = Math.abs(powerChange)
}
if (print)
println("${currentState.perfLevel}/$perfLvlx gain $gainX, cost: $costX ${(gainX - costX) * Math.abs(
powerChange)}")
return (gainX - costX) * weight
// power_{iyi}*r(i)(t_{ij})^{\alpha}(eff_{ij})^{1-\alpha}
val util0 = model.calculateUtil(MAX_PERFORMANCE_LVL, currentState.perfLevel, currentState.util)
val power = model.getPower(MAX_PERFORMANCE_LVL, util0) //TODO: czy na pewno skalować przez utylizacje
}
val r_i = if (currentState.priority > 0.0 && currentState.priority < 1.0) (currentState.priority) / (1 - currentState.priority) else 1.0
val performanceImpact = Math.pow(model.getPerformance(perfLvlx), alpha)
val efficiencyImpact = Math.pow(model.getEfficiency(perfLvlx), 1 - alpha)
val eval = power * r_i * performanceImpact * efficiencyImpact
return eval
}
// fun evaluateState(currentState: StateDefinition, perfLvlx: Double, print: Boolean = false): Double {
//val x = 0.2 //T ODO: unknown parameter?
// val model = currentState.model
//// przeanalizowac
//// val util0 = model.recalculateUtil(currentState.perfLevel, MAX_PERFORMANCE_LVL,
//// currentState.util) //predict utilization for maximum performance
// val newUtil = model.calculateUtil(perfLvlx,currentState.perfLevel,currentState.util)
// val power0 = model.getPower(MAX_PERFORMANCE_LVL, util0) //power usage for maximum performance
// val performance0 = model.getPerformance(MAX_PERFORMANCE_LVL) //power usage for maximum performance
//// val utilx = model.recalculateUtil(currentState.perfLevel, perfLvlx, currentState.util)
// val powerx = model.getPower(perfLvlx, utilx)
// val performancex = model.getPerformance(perfLvlx)
//
// val powerChange = power0 - powerx
// val deltaPerf = performancex / performance0
// if (deltaPerf == 0.0) {
// return ComponentPowerModel.LOW_VALUE
// }
// var gainX = 0.0
// //deltaPerf = model.getDeltaPerf(MAX_PERFORMANCE_LVL, perfLvlx, util0, utilx)
// var costX = 0.0 // -(alpha) * (deltaPerf - 1)
// val weight: Double
// if (currentState.priority == 0.0) {
// val efficiencyX = model.getEfficiency(MAX_PERFORMANCE_LVL, perfLvlx)
// gainX = (Math.pow(efficiencyX, (1 - alpha + x) * (beta + 1)) - 1)
// weight = powerx
// } else if (currentState.priority == 1.0) {
// costX = ((1 / Math.pow(deltaPerf, (alpha + x) * (beta + 1))) - 1)
// weight = Math.abs(powerChange)
// } else {
// val efficiencyX = model.getEfficiency(MAX_PERFORMANCE_LVL, perfLvlx)
// gainX = (Math.pow(efficiencyX, (1 - alpha) * (beta + 1)) - 1) *
// Math.pow(deltaPerf, alpha * beta)
// costX = currentState.priority * ((1 / Math.pow(deltaPerf, alpha * (beta + 1))) - 1)
// weight = Math.abs(powerChange)
// }
// if (print)
// println("${currentState.perfLevel}/$perfLvlx gain $gainX, cost: $costX ${(gainX - costX) * Math.abs(
// powerChange)}")
// return (gainX - costX) * weight
//
// }
}
\ No newline at end of file
......@@ -120,7 +120,6 @@ public final class JCommandAgent extends JCommander {
}
public void execute() throws NoSuchMethodException {
for (Object obj : this.getObjects()) {
if (obj instanceof MainOptions) {
MainOptions.load((MainOptions) obj);
......
......@@ -4,11 +4,9 @@ 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.rpm.ModelMap
import psnc.m2dc.rtm.model.rpm.Resource
import psnc.m2dc.rtm.properties.keys.Keys
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.*
/**
* Server's initialization methods
......@@ -20,6 +18,7 @@ object ServerConfInitializer {
try {
logInfo("version: $APP_VERSION")
loadConfig()
prepareResourceFile().toJson()
loadResources()
// setDefaultPriorities()
......@@ -67,7 +66,33 @@ object ServerConfInitializer {
if (Keys.RTM.resources_src_list.get().contains("RECS"))
DAO.ResourcesManagerApi.getRecsHosts(true)
DAO.ResourcesManagerApi.loadResources()
DAO.ResourcesManagerApi.saveResourcesToFile(listOf())
DAO.ResourcesManagerApi.saveResourcesToFile(listOf<Resource>())
setWatch(t)
}
fun prepareResourceFile():List<Resource>{
if (Keys.RTM.resources_src_list.get().contains("RECS"))
DAO.ResourcesManagerApi.getRecsHosts(true)
DAO.ResourcesManagerApi.loadResources()
val result = ArrayList<Resource>()
System.getProperty("user.name")
DAO.Resource.getNodes().values.forEach {
val r= Resource(it.id,it.typeId,null)
val ssh_username = it.get(Resource.Property.ssh_username.toString())?:System.getProperty("user.name");
r.put(Resource.Property.ssh_username, ssh_username)
val ssh_host = it.get(Resource.Property.ssh_host.toString())?:"ssh_host";
r.put(Resource.Property.ssh_host, ssh_host)
it.get(Resource.Property.ipmi_host.toString())?.let { r.put(Resource.Property.ipmi_host, it)}
it.get(Resource.Property.recs_host.toString())?.let { r.put(Resource.Property.recs_host, it)}
}
val r= Resource("dummy_node","node_type",null)
r.put(Resource.Property.ssh_username, System.getProperty("user.name"))
r.put(Resource.Property.ssh_host, "ssh_host")
r.put(Resource.Property.ipmi_host, "ipmi_host")
r.put(Resource.Property.recs_host, "recs_host")
// result.add dummy
return result
}
}
\ No newline at end of file
......@@ -6,6 +6,7 @@ import psnc.m2dc.rtm.dao.LightStorage
import psnc.m2dc.rtm.esm.ESMApi
import psnc.m2dc.rtm.model.rest.NodePriority
import psnc.m2dc.rtm.model.rpm.ModelMap
import psnc.m2dc.rtm.model.rpm.Resource
import psnc.m2dc.rtm.pcm.PCMApi
import psnc.m2dc.rtm.properties.keys.Keys
import psnc.m2dc.rtm.rest.Handlers
......@@ -22,10 +23,12 @@ import spark.Spark
object ServerInitializer {
fun init() {
try {
logInfo("version: $APP_VERSION")
loadConfig()// -> tu zglasza null pointer
loadResources()
PCMApi.init()
ESMApi.init()
......@@ -113,4 +116,5 @@ object ServerInitializer {
setWatch(t)
}
}
\ No newline at end of file
package psnc.m2dc.rtm.commands.java
val APP_VERSION = "1.0.453_46352"
\ No newline at end of file
val APP_VERSION = "1.0.490_43783"
\ No newline at end of file
package psnc.m2dc.rtm.client
const val APP_VERSION = "1.1.453_46352"
\ No newline at end of file
const val APP_VERSION = "1.1.490_43783"
\ No newline at end of file
......@@ -8,22 +8,23 @@ package psnc.m2dc.rtm.model.rpm
enum class ManagementMethodType {
suspend, turn_off, turn_on, temperature, power, test, set_property, get_value,
node_resource_details, none;
/* model*/
fun getPowerSavings(model: ComponentPowerModel, powerUsage: Double, performanceSetting: Double? = null): Double {
return when (this) {
suspend -> powerUsage - (model.suspendPowerUsage ?: powerUsage)
turn_off -> powerUsage
set_property -> {
val utilization = model.getUtil(powerUsage, performanceSetting ?: 100.0)
val newUtil = model.recalculateUtil(performanceSetting ?: 100.0, 0.0, utilization)
powerUsage - model.getPower(0.0, newUtil)
}
else -> 0.0
// turn_on, none, get_value, test, power, node_resource_details, temperature -> 0.0
}
}
//
// /* model*/
// fun getPowerSavings(model: ComponentPowerModel, powerUsage: Double, currentPerformanceSetting: Double? = null): Double {
//
// return when (this) {
// suspend -> powerUsage - (model.suspendPowerUsage ?: powerUsage)
// turn_off -> powerUsage
// set_property -> {
// sprawdzic
// val utilization = model.getUtil(powerUsage, currentPerformanceSetting ?: 100.0)
// val newUtil = model.calculateUtil(0.0, currentPerformanceSetting ?: 100.0, utilization)
// powerUsage - model.getPower(0.0, newUtil)
// }
// else -> 0.0
// // turn_on, none, get_value, test, power, node_resource_details, temperature -> 0.0
// }
// }
}
enum class PrivLvl {
......@@ -38,8 +39,8 @@ object ApiType {
val temperature = "temperature"
val set_property = "set_property"
val suspend = "suspend"
// val recs_turn_off = "recs_turn_off"
// val power_usage = "power_usage"
// val recs_turn_off = "recs_turn_off"
// val power_usage = "power_usage"
val sub_component = "sub_component"
}
......
......@@ -483,7 +483,7 @@ class RPMApiImpl : RPMApi {
val result = ArrayList<Triple<String, String, Any>>()
val usage: HashMap<String, HashMap<String, Any>> = SSHApiImpl.init(dummyResource).getCurrentUsage()
// printConsole(usage.toJson())
val powerUsage = usage["ssh_current_power_usage"]?.get(resourceId)
val powerUsage = usage["current_power_usage"]?.get(resourceId)
if (powerUsage != null) {
result.add(Triple(resourceId, "current_power_usage", powerUsage))
}
......
......@@ -43,9 +43,6 @@ class RECSMonitoringApi private constructor(/*storage: IStorage<String>? = null*
val map = DAO.Resource.getNodes()
val nodes = listNodes(host).nodeList.filter {
// printConsole(Keys.TestBed.resource_list.getNullable()?.contains(it.id)?.toString() ?: "null ")
// printConsole("id ${it.id}")
!map.containsKey(it.id) &&
(!Keys.TestBed.filter_nodes.get() ||
Keys.TestBed.resource_list.getNullable()?.contains(it.id) ?: false)
......
......@@ -8,10 +8,7 @@ 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.utils.fromJson
import psnc.m2dc.rtm.utils.logError
import psnc.m2dc.rtm.utils.printConsole
import psnc.m2dc.rtm.utils.toJson
import psnc.m2dc.rtm.utils.*
import java.io.BufferedReader
import java.io.File
import java.io.IOException
......@@ -71,35 +68,35 @@ open class SSHApiImpl private constructor(val resource: Resource) : SSHApi {
init(resource).suspend()
}
fun suspendComponent(resource: Resource, coreId: String) {
init(resource).suspendComponent(coreId)
}
fun getCurrentUsage(resource: Resource,
args: ArrayList<String> = ArrayList()): HashMap<String, HashMap<String, Any>> {
return init(resource).getCurrentUsage(args)
}
fun powerOff(resource: Resource) {
init(resource).powerOff()
}
fun powerOffComponent(resource: Resource, coreId: String) {
init(resource).powerOffComponent(coreId)
}
fun powerOnComponent(resource: Resource, coreId: String) {
init(resource).powerOnComponent(coreId)
}
fun hibernate(resource: Resource) {
init(resource).hibernate()
}
fun getChildResource(resource: Resource): List<Resource> {
return init(resource).getChildResources()
}
// fun suspendComponent(resource: Resource, coreId: String) {
// init(resource).suspendComponent(coreId)
// }
//
// fun getCurrentUsage(resource: Resource,
// args: ArrayList<String> = ArrayList()): HashMap<String, HashMap<String, Any>> {
// return init(resource).getCurrentUsage(args)
// }
//
// fun powerOff(resource: Resource) {
// init(resource).powerOff()
// }
//
// fun powerOffComponent(resource: Resource, coreId: String) {
// init(resource).powerOffComponent(coreId)
// }
//
// fun powerOnComponent(resource: Resource, coreId: String) {
// init(resource).powerOnComponent(coreId)
// }
//
// fun hibernate(resource: Resource) {
// init(resource).hibernate()
// }
//
// fun getChildResource(resource: Resource): List<Resource> {
//
// return init(resource).getChildResources()
// }
fun setProperty(resource: Resource, entityId: String, propertyName: String, value: String): Boolean {
......@@ -134,16 +131,16 @@ open class SSHApiImpl private constructor(val resource: Resource) : SSHApi {
}
override fun suspend() {
runScript("suspend", arrayListOf("-d", DEBUG))
runScript("rtm-suspend", arrayListOf("-d", DEBUG))
}
override fun suspendComponent(coreId: String) {
runScript("suspend_component", arrayListOf(coreId))
runScript("rtm-suspend_component", arrayListOf(coreId))
}
override fun getCurrentUsage(args: ArrayList<String>?): HashMap<String, HashMap<String, Any>> =
RTMProperties.parseJson(runScript("current_usage", arrayListOf("-n", resource.id)), MAP_TYPE)
RTMProperties.parseJson(runScript("rtm-current_usage", arrayListOf("-n", resource.id)), MAP_TYPE)
// {
// val key = getKey(resource.id, "current_usage")
//// return getData(key, {
......@@ -155,7 +152,7 @@ open class SSHApiImpl private constructor(val resource: Resource) : SSHApi {
printConsole("get type for :${resource.id} ")
// val type = object : TypeToken<HashMap<String, String>>() {
// }.type
val type = Values.typeName(runScript("resource_type"))
val type = Values.typeName(runScript("rtm-resource_type"))
return mapOf("resource_type" to type)
// return RTMProperties.parseJson(runScript("resource_type"), type)
......@@ -163,65 +160,65 @@ open class SSHApiImpl private constructor(val resource: Resource) : SSHApi {
}
override fun powerOff() {
runScript("power_off", arrayListOf("-d", DEBUG))
runScript("rtm-power_off", arrayListOf("-d", DEBUG))
}
override fun powerOffComponent(coreId: String) {
runScript("power_off_component", arrayListOf(coreId))
runScript("rtm-power_off_component", arrayListOf(coreId))
}
override fun powerOnComponent(coreId: String) {
runScript("power_on_component", arrayListOf(coreId))
runScript("rtm-power_on_component", arrayListOf(coreId))
}
override fun hibernate() {
runScript("hibernate")
runScript("rtm-hibernate")
}
override fun setProperty(entityId: String, propertyName: String, value: String): Boolean {
val parsedValue = value.toIntOrNull()?.toString() ?: value
val result = runScript("set_property",
val result = runScript("rtm-set_property",
arrayListOf("-d", DEBUG, "-p", propertyName, "-p", entityId, "-p", parsedValue))
// println("ssh res:'$result' " + (result.trim() == "OK"))
return result.trim() == "OK"
}
override fun setProperty(args: List<String>): Boolean {
val result = runScript("set_property", args)
val result = runScript("rtm-set_property", args)
return result.trim() == "OK"
}
override fun getChildResources(): List<Resource> {
val type = object : TypeToken<List<Resource>>() {}.type
val result = runScript("get_child_resources",
val result = runScript("rtm-get_child_resources",
arrayListOf("-d", DEBUG, "-p", this.resource.id, "-p"))
try {
return result.fromJson(type)
} catch (e: Exception) {
logError(e, "Cannot get child resources for:${this.resource.id}: ssh result:$result")
return listOf()
return listOf<Resource>()
}
}
override fun setProperty(propertyName: String, value: String): Boolean {