Commit a83e1966 by Tomasz Ciesielczyk

update PCM and RTM methods

parent d98a68dc
......@@ -128,7 +128,7 @@ public final class JCommandAgent extends JCommander {
}
String parsed = this.getParsedCommand();
if (parsed == null) {
throw new NullPointerException("No command provided");
parsed = "start";//throw new NullPointerException("No command provided");
}
JCommander command = this.getCommands().get(parsed);
if (command == null) {
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package psnc.m2dc.rtm.commands.java;
import com.beust.jcommander.Parameters;
import com.beust.jcommander.ParametersDelegate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import psnc.m2dc.rtm.ICommandLine;
import psnc.m2dc.rtm.TestParameters;
/**
* @author Tomek
*/
@Parameters(commandNames = "test",
commandDescription = "test api")
public class TestCommand extends ICommandLine {
@ParametersDelegate
private TestParameters params = new TestParameters();
private static final Logger log = LoggerFactory.getLogger(TestCommand.class);
@Override
public void execute() {
log.info("Start test");
// RTMProperties.Companion.init();
//sample hosts
this.params.getTestNames().forEach(test -> {
switch (test) {
case "recs_connect":
psnc.m2dc.rtm.commands.TestCommand.INSTANCE.testRecsConnection();
break;
case "version":
psnc.m2dc.rtm.commands.TestCommand.INSTANCE.version();
break;
case "ldap_data":
psnc.m2dc.rtm.commands.TestCommand.INSTANCE.ldapData();
break;
case "help":
psnc.m2dc.rtm.commands.TestCommand.INSTANCE.help();
break;
case "get_resources":
psnc.m2dc.rtm.commands.TestCommand.INSTANCE.getResources();
break;
case "set_low_perf":
psnc.m2dc.rtm.commands.TestCommand.INSTANCE.setLowPerf();
break;
case "set_high_perf":
psnc.m2dc.rtm.commands.TestCommand.INSTANCE.setHighperf();
break;
case "power_cap":
psnc.m2dc.rtm.commands.TestCommand.INSTANCE.setPowerCap();
break;
case "power_optimize":
psnc.m2dc.rtm.commands.TestCommand.INSTANCE.setPowerOptimization();
break;
case "get_temperatures":
psnc.m2dc.rtm.commands.TestCommand.INSTANCE.getTemperature();
break;
case "get_power":
psnc.m2dc.rtm.commands.TestCommand.INSTANCE.getPower();
break;
case "get_model":
psnc.m2dc.rtm.commands.TestCommand.INSTANCE.getModel();
break;
case "ssh_usage":
psnc.m2dc.rtm.commands.TestCommand.INSTANCE.getUsage();
break;
case "ssh_suspend":
psnc.m2dc.rtm.commands.TestCommand.INSTANCE.suspend();
break;
case "ssh_power_off":
psnc.m2dc.rtm.commands.TestCommand.INSTANCE.powerOff();
break;
case "ssh_set_property":
psnc.m2dc.rtm.commands.TestCommand.INSTANCE.setProperty();
case "ssh_freq_up":
psnc.m2dc.rtm.commands.TestCommand.INSTANCE.frequencyUp();
break;
case "ssh_freq_down":
psnc.m2dc.rtm.commands.TestCommand.INSTANCE.frequencyDown();
break;
case "ssh_gpu_high_power":
psnc.m2dc.rtm.commands.TestCommand.INSTANCE.gpuPowerUp();
break;
case "get_priorities":
psnc.m2dc.rtm.commands.TestCommand.INSTANCE.getPriorities();
break;
case "ssh_gpu_low_power":
psnc.m2dc.rtm.commands.TestCommand.INSTANCE.gpuPowerDown();
break;
case "full_test":
psnc.m2dc.rtm.commands.TestCommand.INSTANCE.fullTest();
break;
default:
log.warn("Unsupported test: " + test);
}
});
}
}
///*
// * To change this license header, choose License Headers in Project Properties.
// * To change this template file, choose Tools | Templates
// * and open the template in the editor.
// */
//package psnc.m2dc.rtm.commands.java;
//
//import com.beust.jcommander.Parameters;
//import com.beust.jcommander.ParametersDelegate;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import psnc.m2dc.rtm.ICommandLine;
//import psnc.m2dc.rtm.TestParameters;
//
///**
// * @author Tomek
// */
//@Parameters(commandNames = "test",
// commandDescription = "test api")
//public class TestCommand extends ICommandLine {
//
// @ParametersDelegate
// private TestParameters params = new TestParameters();
// private static final Logger log = LoggerFactory.getLogger(TestCommand.class);
//
// @Override
// public void execute() {
// log.info("Start test");
// // RTMProperties.Companion.init();
// //sample hosts
// this.params.getTestNames().forEach(test -> {
// switch (test) {
// case "recs_connect":
// psnc.m2dc.rtm.commands.TestCommand.INSTANCE.testRecsConnection();
// break;
// case "version":
// psnc.m2dc.rtm.commands.TestCommand.INSTANCE.version();
// break;
// case "ldap_data":
// psnc.m2dc.rtm.commands.TestCommand.INSTANCE.ldapData();
// break;
// case "help":
// psnc.m2dc.rtm.commands.TestCommand.INSTANCE.help();
// break;
// case "get_resources":
// psnc.m2dc.rtm.commands.TestCommand.INSTANCE.getResources();
// break;
// case "set_low_perf":
// psnc.m2dc.rtm.commands.TestCommand.INSTANCE.setLowPerf();
// break;
// case "set_high_perf":
// psnc.m2dc.rtm.commands.TestCommand.INSTANCE.setHighperf();
// break;
// case "power_cap":
// psnc.m2dc.rtm.commands.TestCommand.INSTANCE.setPowerCap();
// break;
// case "power_optimize":
// psnc.m2dc.rtm.commands.TestCommand.INSTANCE.setPowerOptimization();
// break;
// case "get_temperatures":
// psnc.m2dc.rtm.commands.TestCommand.INSTANCE.getTemperature();
// break;
// case "get_power":
// psnc.m2dc.rtm.commands.TestCommand.INSTANCE.getPower();
// break;
// case "get_model":
// psnc.m2dc.rtm.commands.TestCommand.INSTANCE.getModel();
// break;
// case "ssh_usage":
// psnc.m2dc.rtm.commands.TestCommand.INSTANCE.getUsage();
// break;
// case "ssh_suspend":
// psnc.m2dc.rtm.commands.TestCommand.INSTANCE.suspend();
// break;
// case "ssh_power_off":
// psnc.m2dc.rtm.commands.TestCommand.INSTANCE.powerOff();
// break;
// case "ssh_set_property":
// psnc.m2dc.rtm.commands.TestCommand.INSTANCE.setProperty();
// case "ssh_freq_up":
// psnc.m2dc.rtm.commands.TestCommand.INSTANCE.frequencyUp();
// break;
// case "ssh_freq_down":
// psnc.m2dc.rtm.commands.TestCommand.INSTANCE.frequencyDown();
// break;
// case "ssh_gpu_high_power":
// psnc.m2dc.rtm.commands.TestCommand.INSTANCE.gpuPowerUp();
// break;
// case "get_priorities":
// psnc.m2dc.rtm.commands.TestCommand.INSTANCE.getPriorities();
// break;
// case "ssh_gpu_low_power":
// psnc.m2dc.rtm.commands.TestCommand.INSTANCE.gpuPowerDown();
// break;
// case "full_test":
// psnc.m2dc.rtm.commands.TestCommand.INSTANCE.fullTest();
// break;
// default:
// log.warn("Unsupported test: " + test);
// }
// });
//
// }
//
//}
package psnc.m2dc.rtm.commands.java
val APP_VERSION = "1.0.426_53008"
\ No newline at end of file
val APP_VERSION = "1.0.440_55159"
\ No newline at end of file
......@@ -20,31 +20,31 @@ import java.util.*
abstract class Handlers {
enum class RESTKeys {
rcuUtil, timeinterval, nodes, temperature, sensor, sensors, powerBuffer, policy, strategy, powerLimit, state,
rcuUtil, timeinterval, nodes, temperature, api, powerBuffer, policy, strategy, powerLimit, state,
resource_id_list, resource_id,
nodePriorities, performance, workload, node_model, result, power, resource_type, power_model, node_type,
time_interval_points, temperature_limit_list, settings, profile,node_util
}
object RESTParams {
val resource_id = "resource_id"
val node_id = "node_id"
val type_name = "type_name"
val power_model_name = "power_model_name"
val power_model_profile_name = "power_model_profile_name"
val object_type = "object_type"
val metadata_key = "metadata_key"
val metadata_value = "metadata_value"
val sensor_id = "sensor_id"
val sensor_type = "sensor_type"
val priorities = "priorities"
val node_id_list = "node_id_list"
const val resource_id = "resource_id"
const val node_id = "node_id"
const val type_name = "type_name"
const val power_model_name = "power_model_name"
const val power_model_profile_name = "power_model_profile_name"
const val object_type = "object_type"
const val metadata_key = "metadata_key"
const val metadata_value = "metadata_value"
const val api_id = "api_id"
const val api_type = "api_type"
//val priorities = "priorities"
const val node_id_list = "node_id_list"
}
companion object {
val log = LoggerFactory.getLogger(Handlers::class.java.name)
val log = LoggerFactory.getLogger(Handlers::class.java.name)!!
fun initHandlers() {
ResourceHandler.init()
EnergySaverHandler.init()
......@@ -128,8 +128,8 @@ abstract class Handlers {
RESTKeys.temperature_limit_list) ?: throw NullPointerException(
"${RESTKeys.temperature_limit_list} parameter not found")
protected fun getSensor(jo: JsonObject): String = this.getObject(jo, RESTKeys.sensor) ?: throw NullPointerException(
"sensor parameter not found")
protected fun getApi(jo: JsonObject): String = this.getObject(jo, RESTKeys.api) ?: throw NullPointerException(
"api parameter not found")
//
// protected fun getPowerBuffer(jo: JsonObject): Double = Values.powerBuffer(this.getObject(jo, RESTKeys.powerBuffer))
......
......@@ -2,23 +2,21 @@ package psnc.m2dc.rtm.rest
object HandlersMap {
const val auth_token = "/auth/token"
//#region management
const val state_save = "/storage/save"
const val get_state = "/state"
val get_custom_state = "/state/:${Handlers.RESTParams.object_type}"
const val get_custom_state = "/state/:${Handlers.RESTParams.object_type}"
const val rtm_settings = "/rtm/settings"
//#endregion
//#region fan management
/**
* refresh state
*/
const val fm_update = "/fm/update"
val fm_temperature = "/fm/:${Handlers.RESTParams.sensor_id}/temperature"
val fm_temperature = "/fm/:${Handlers.RESTParams.api_id}/temperature"
//val fm_power = "/fm/power/:${Handlers.RESTParams.sensor_id}"
val fm_temperature_limit = "/fm/temperature/limit/:${Handlers.RESTParams.sensor_id}"
val fm_temperature_limit = "/fm/temperature/limit/:${Handlers.RESTParams.api_id}"
const val fm_temperature_limit_reset = "/node/temperature/limit/reset"
const val fm_termal_data = "/fm/termaldata"
//#endregion
//#region energy saver
......@@ -27,7 +25,6 @@ object HandlersMap {
*/
const val esm_optimize = "/esm/optimize"
const val esm_policy = "/esm/policy"
//val esm_priorityList = "/esm/${Handlers.RESTParams.priorities}"
//#endregion
......@@ -37,9 +34,7 @@ object HandlersMap {
const val pcm_powerLimit = "/pcm/powerlimit"
const val reset_pcm_powerLimit = "/pcm/powerlimit/reset"
//TODO:deprecated
const val pcm_priorityList = "/pcm/prioritylist"
const val pcm_priority = "/pcm/priority"
const val rtm_priority = "/rtm/priority"
const val pcm_check_state = "/pcm/state"
const val pcm_current_state = "/pcm/current_state"
//#endregion
......@@ -47,37 +42,37 @@ object HandlersMap {
//#region resource management
const val node_rcuutil = "/node/rcu_util"
val resource_list = "/resource/:${Handlers.RESTParams.type_name}"
const val resource_list = "/resource/:${Handlers.RESTParams.type_name}"
// val node_resource_details = "/node/resource_details/:${Handlers.RESTParams.node_id}"
val set_resource_type = "/resource/type/:${Handlers.RESTParams.resource_id}/:${Handlers.RESTParams.type_name}"
val get_resource_type = "/resource/type/:${Handlers.RESTParams.resource_id}"
const val set_resource_type = "/resource/type/:${Handlers.RESTParams.resource_id}/:${Handlers.RESTParams.type_name}"
const val get_resource_type = "/resource/type/:${Handlers.RESTParams.resource_id}"
/**
* get new power model
*/
val resource_power_model = "/resource/power_model/:${Handlers.RESTParams.resource_id}"
const val resource_power_model = "/resource/power_model/:${Handlers.RESTParams.resource_id}"
/**
* add power model to resource's type
*/
val type_power_model = "/type/resource/power_model/:${Handlers.RESTParams.type_name}"
val power_model = "/power_model/:${Handlers.RESTParams.power_model_name}"
const val type_power_model = "/type/resource/power_model/:${Handlers.RESTParams.type_name}"
const val power_model = "/power_model/:${Handlers.RESTParams.power_model_name}"
/**
* get&set resource type
*/
val type_resource = "/type/resource/:${Handlers.RESTParams.type_name}"
const val type_resource = "/type/resource/:${Handlers.RESTParams.type_name}"
val node_metadata = "/node/metadata/:${Handlers.RESTParams.node_id}"
val set_node_metadata =
const val node_metadata = "/node/metadata/:${Handlers.RESTParams.node_id}"
const val set_node_metadata =
"/node/metadata/:${Handlers.RESTParams.node_id}/:${Handlers.RESTParams.metadata_key}/:${Handlers
.RESTParams.metadata_value}"
val get_node_metadata = "/node/metadata/:${Handlers.RESTParams.node_id}/:${Handlers.RESTParams.metadata_key}"
const val get_node_metadata = "/node/metadata/:${Handlers.RESTParams.node_id}/:${Handlers.RESTParams.metadata_key}"
val node_util = "/node/util/:${Handlers.RESTParams.node_id_list}"
val node_sensor_list = "/node/sensor/:${Handlers.RESTParams.node_id_list}"
val nodes_sensor_value = "/node/sensor/:${Handlers.RESTParams.node_id_list}/:${Handlers.RESTParams.sensor_id}"
val nodes_sensor_type_value = "/node/sensor/type/:${Handlers.RESTParams.node_id_list}/:${Handlers.RESTParams
.sensor_type}"
const val node_util = "/node/util/:${Handlers.RESTParams.node_id_list}"
const val node_api_list = "/node/api/:${Handlers.RESTParams.node_id_list}"
const val nodes_api_value = "/node/api/:${Handlers.RESTParams.node_id_list}/:${Handlers.RESTParams.api_id}"
const val nodes_api_type_value = "/node/api/type/:${Handlers.RESTParams.node_id_list}/:${Handlers.RESTParams
.api_type}"
//aggregated values
//val total_sensor_type_value = "/sensor/type/:${Handlers.RESTParams.sensor_type}"
......@@ -85,13 +80,13 @@ object HandlersMap {
const val node_power_all = "/node/power"
const val total_power_usage = "/power"
//#endregion
//#region pcm
//#region rtm
val pcm_current_resource_performance = "/pcm/current_performance/:${Handlers.RESTParams.node_id_list}"
const val pcm_resource_current_performance_map = "/pcm/current_performance"
const val rtm_current_resource_performance = "/rtm/current_performance/:${Handlers.RESTParams.node_id_list}"
const val rtm_resource_current_performance_map = "/rtm/current_performance"
//get available performance settings
val pcm_resource_performance_list = "/pcm/performance/:${Handlers.RESTParams.node_id_list}"
const val pcm_resource_performance_list_all = "/pcm/performance"
const val rtm_resource_performance_list = "/rtm/performance/:${Handlers.RESTParams.node_id_list}"
const val rtm_resource_performance_list_all = "/rtm/performance"
//#endregion
......
......@@ -38,6 +38,9 @@ class FMHandler : Handlers() {
get(HandlersMap.fm_temperature_limit) { req, res ->
instance.getTemperatureLimit(req, res)
}
get(HandlersMap.fm_termal_data) { req, res ->
instance.getTermalData(req, res)
}
}
......@@ -62,7 +65,7 @@ class FMHandler : Handlers() {
req.logDebug()
val jo = RTMApi.getJsonObj(req.body())
val nodes = getNodeList(jo)
val sensor = getSensor(jo)
val sensor = getApi(jo)
val jsonBuilder = JsonBuilder()
jsonBuilder.addObj(RESTKeys.result, FMApi.instance().getTemperatureLimit(nodes, sensor))
jsonBuilder.toJson()
......@@ -73,12 +76,25 @@ class FMHandler : Handlers() {
}
}
fun getTermalData(req: Request, res: Response): String {
return try {
req.logDebug()
val jo = RTMApi.getJsonObj(req.body())
val jsonBuilder = JsonBuilder()
throw NotImplementedError("not implemented")
jsonBuilder.toJson()
} catch (e: Exception) {
res.status(400)
Handlers.log.debug("400: Bad request!", e)
"Bad request: ${e.message}"
}
}
fun resetTemperatureLimit(req: Request, res: Response): String {
return try {
req.logDebug()
val jo = RTMApi.getJsonObj(req.body())
val nodes = getNodeList(jo)
val sensor = getSensor(jo)
val sensor = getApi(jo)
FMApi.instance().resetNodeTemperatureLimit(sensor, nodes)
RESTExamples.OK_RESPONSE
} catch (e: Exception) {
......@@ -104,7 +120,7 @@ class FMHandler : Handlers() {
return try {
req.logDebug()
val jo = RTMApi.getJsonObj(req.body())
val sensorId = req.params(RESTParams.sensor_id)
val sensorId = req.params(RESTParams.api_id)
val timeIntervals = this.getTimeIntervals(jo)
val resourceIdList = this.getResourceList(jo)
val jb = JsonBuilder()
......
......@@ -36,16 +36,11 @@ class PCMHandler : Handlers() {
get(HandlersMap.pcm_strategy) { req, res ->
instance.getPCMStrategy(req, res)
}
post(HandlersMap.pcm_priorityList) { req, res ->
instance.setPCMPriorityList(req, res)
}
get(HandlersMap.pcm_priorityList) { req, res ->
instance.getPCMPriorityList(req, res)
}
post(HandlersMap.pcm_priority) { req, res ->
post(HandlersMap.rtm_priority) { req, res ->
instance.setPCMPriorityList(req, res)
}
get(HandlersMap.pcm_priority) { req, res ->
get(HandlersMap.rtm_priority) { req, res ->
instance.getPCMPriorityList(req, res)
}
get(HandlersMap.pcm_current_state) { req, res ->
......
......@@ -31,13 +31,13 @@ class ResourceHandler : Handlers() {
fun init() {
//#region sensors
get(HandlersMap.nodes_sensor_value) { req, res ->
get(HandlersMap.nodes_api_value) { req, res ->
instance.getNodesSensorValue(req, res)
}
get(HandlersMap.nodes_sensor_type_value) { req, res ->
get(HandlersMap.nodes_api_type_value) { req, res ->
instance.getNodesSensorTypeValue(req, res)
}
get(HandlersMap.node_sensor_list) { req, res ->
get(HandlersMap.node_api_list) { req, res ->
instance.getNodeSensorList(req, res)
}
//#endregion
......@@ -102,19 +102,19 @@ class ResourceHandler : Handlers() {
get(HandlersMap.resource_list) { req, res ->
ResourceHandler.instance.listResources(req, res)
}
post(HandlersMap.pcm_current_resource_performance) { req, res ->
post(HandlersMap.rtm_current_resource_performance) { req, res ->
instance.setResourcePerformance(req, res)
}
get(HandlersMap.pcm_current_resource_performance) { req, res ->
get(HandlersMap.rtm_current_resource_performance) { req, res ->
instance.getResourcePerformance(req, res)
}
get(HandlersMap.pcm_resource_current_performance_map) { req, res ->
get(HandlersMap.rtm_resource_current_performance_map) { req, res ->
instance.getResourcePerformance(req, res)
}
get(HandlersMap.pcm_resource_performance_list) { req, res ->
get(HandlersMap.rtm_resource_performance_list) { req, res ->
instance.getPerformanceList(req, res)
}
get(HandlersMap.pcm_resource_performance_list_all) { req, res ->
get(HandlersMap.rtm_resource_performance_list_all) { req, res ->
instance.getPerformanceList(req, res)
}
get(HandlersMap.node_power_all) { req, res ->
......@@ -355,7 +355,7 @@ class ResourceHandler : Handlers() {
fun getNodesSensorValue(req: Request, res: Response): String {
return try {
req.logDebug()
val sensorId = req.params(Handlers.RESTParams.sensor_id)
val sensorId = req.params(Handlers.RESTParams.api_id)
val result = HashMap<String, Double?>()
val nodes = TypeConverters.Resource.convertToList(req, Handlers.RESTParams.node_id_list)
nodes?.forEach {
......@@ -378,11 +378,11 @@ class ResourceHandler : Handlers() {
val nodes = TypeConverters.Resource.convertToList(req, "node_id_list")
val filter = listOf(ManagementMethodType.power, ManagementMethodType.get_value,
ManagementMethodType.temperature)
val sensorMap = DAO.Settings.sensorMap!!
val sensorMap = DAO.Settings.apiMap!!
nodes?.forEach {
DAO.ResourcesManagerApi.getResourceType(it).let { type ->
val set = HashSet<String>()
type.apiMap.filter { filter.contains(sensorMap.typeMethodMap[it.key]) }
type.apiMap.filter { filter.contains(sensorMap.typeMap[it.key]) }
.forEach {
it.value.forEach {
set.add(it.id)
......@@ -396,7 +396,7 @@ class ResourceHandler : Handlers() {
}
val jsonBuilder = JsonBuilder()
//return only apis available for all nodes
jsonBuilder.addObj(Handlers.RESTKeys.sensors, result.filter { it.value == nodes?.size ?: 0 }.keys)
jsonBuilder.addObj(Handlers.RESTKeys.api, result.filter { it.value == nodes?.size ?: 0 }.keys)
jsonBuilder.toJson()
} catch (e: Exception) {
res.status(400)
......@@ -409,7 +409,7 @@ class ResourceHandler : Handlers() {
fun getNodesSensorTypeValue(req: Request, res: Response): String {
return try {
req.logDebug()
val sensorType = req.params(Handlers.RESTParams.sensor_type)
val sensorType = req.params(Handlers.RESTParams.api_type)
val result = HashMap<String, HashMap<String, Double?>>()
val nodes = TypeConverters.Resource.convertToList(req, "node_id_list")
nodes?.forEach {
......@@ -491,6 +491,12 @@ class ResourceHandler : Handlers() {
req.logDebug()
val jo = RTMApi.getJsonObj(req.body())
val nodeUtils = this.getNodeUtil(jo)
nodeUtils.forEach {
it->
if(DAO.Resource.getResource(it.nodeId)==null){
return "Resource not found: ${it.nodeId}"
}
}
DAO.Chassis.addNodeUtil(nodeUtils)
JsonBuilder().addOK().toJson()
......
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