Commit 529268b2 by Tomasz Ciesielczyk

build fix

parent b76162fe
......@@ -32,7 +32,7 @@ class CurrentState(val powerUsage: Double) {
*/
private val currentTimeInterval = TimeInterval()
var currentPowerOverLimit = PCMApi.instance().getPowerLimit()?.let { this.powerUsage - it } ?: 0.0
var currentPowerOverLimit = PCMApi.Instance.getPowerLimit()?.let { this.powerUsage - it } ?: 0.0
var eval = Evaluation(currentPowerOverLimit,
StorageKeys.POWER_SETTING_EVALUATION_MODE)
......@@ -79,7 +79,7 @@ class CurrentState(val powerUsage: Double) {
if (newNodeUtil.isInUse(currentTimeInterval)) {
this.activeMachines.add(newNodeUtil)
val priority = StorageKeys.NODE_PRIORITIES_MAP[node.id]?.weight ?: 0.5
if (PCMApi.instance().getPowerCappingStrategy() == PowerCappingStrategy.EAGER) {
if (PCMApi.Instance.getPowerCappingStrategy() == PowerCappingStrategy.EAGER) {
newNodeUtil = NodeUtil(node.id, 100.0, power * 100 / currentUtilization, currentProfile, null, currentTimeInterval)
}
//TODO: przy eager mode przeliczyc overlimit i zuzucia renergi
......
......@@ -3,8 +3,8 @@ package psnc.m2dc.rtm.esm
import psnc.m2dc.rtm.CurrentState
import psnc.m2dc.rtm.PowerSettings
import psnc.m2dc.rtm.RTMAlgorithm
import psnc.m2dc.rtm.RTMApi
import psnc.m2dc.rtm.model.rpm.Resource
import psnc.m2dc.rtm.pcm.PCMApi
import psnc.m2dc.rtm.pcm.algorithm.Solver
import psnc.m2dc.rtm.utils.logWarn
import psnc.m2dc.rtm.utils.printConsole
......@@ -44,7 +44,7 @@ class ESMAlgorithm(state: CurrentState,val algorithm: Solver.Algorithm) : RTMAlg
val suspendSavings = unusedResourcesSuspendSavings()
printConsole("esm powerbudget: ${-this.state.eval.powerOverLimit}")
printConsole(PCMApi.instance().getNodePerformance().toJson())
printConsole(RTMApi.getNodePerformance().toJson())
setSolver(suspendSavings)
printConsole("esm powerbudget: ${-this.state.eval.powerOverLimit}")
solver.solve()?.let {
......
package psnc.m2dc.rtm.esm
import org.slf4j.LoggerFactory
import psnc.m2dc.rtm.CurrentState
import psnc.m2dc.rtm.StorageKeys
import psnc.m2dc.rtm.model.rest.ESMPowerPolicy
......@@ -12,37 +11,8 @@ import psnc.m2dc.rtm.utils.printConsole
import psnc.m2dc.rtm.utils.sum
class ESMApi {
//#region initialize INSTANCE
companion object {
val log = LoggerFactory.getLogger(ESMApi::class.java.name)!!
private var Instance: ESMApi? = null
private val lock: Any = Any()
private var initialized = false
fun instance(): ESMApi {
synchronized(lock) {
if (Instance == null) {
log.warn("Initializing default ESM API", NullPointerException("ESM API not initialized"))
Instance = ESMApi()
}
if (!initialized) {
log.warn("ESM API not initialized, using default")
}
return Instance!!
}
object ESMApi {
}
fun init() {
synchronized(lock) {
this.Instance = ESMApi()
log.info("ESM Api initialized")
initialized = true
}
}
}
//#endregion
fun optimize(): Boolean {
......
......@@ -122,7 +122,7 @@ class PCMWorker(var state: CurrentState) : RTMWorker() {
private fun updateLimits() {
synchronized(lock) {
val limits = PCMApi.instance().checkLimits()
val limits = PCMApi.Instance.checkLimits()
this.state = CurrentState(limits.currentPowerUsage)
// + ((StorageKeys.POWER_LIMIT ?: 0.0) * Keys.PCM.power_buffer.get()))
this.algorithm.updateState(state)
......
......@@ -280,7 +280,7 @@ open class Solver(e: Evaluation, var mode: SolverMode, val powerBuffer: Double,
this.powerSavings = eval.totalPowerSavings(result)
this.currentGain = eval.totalGain(result)
return result
return null
// return null
}
private fun randomAlgo(): HashMap<String, Double>? {
......
Manifest-Version: 1.0
Main-Class: psnc.m2dc.rtm.RTMApiKt
Main-Class: psnc.m2dc.rtm.RTMServerApiKt
......@@ -57,15 +57,15 @@ object RTMScannerWorker {
while (Keys.RTM.scan_thread.getBoolean() && !stop) {
try {
printConsole("current scan timeout:${Keys.RTM.scan_timeout_ms.getLong()}, counter: $iter ")
val state = PCMApi.instance().checkLimits()
val state = PCMApi.Instance.checkLimits()
if (state.limitExceeded) {
PCMApi.instance().checkState()
PCMApi.Instance.checkState()
LightStorage.saveStorage()
iter = 0
} else if (iter > esmRatio) {
ActionPredictor.predict(PCMApi.instance().getPowerLimit()).generateScripts()
ActionPredictor.predict(PCMApi.Instance.getPowerLimit()).generateScripts()
if (Keys.ESM.scan_status.get()) {
ESMApi.instance().optimize()
ESMApi.optimize()
} else {
printConsole("ESM is stopped")
}
......
......@@ -23,22 +23,22 @@ import psnc.m2dc.rtm.utils.toJson
import java.io.File
import java.nio.file.Paths
class RTMApi private constructor() {
class RTMServerApi private constructor() {
companion object {
val log = LoggerFactory.getLogger(RTMApi::class.java.name)!!
val log = LoggerFactory.getLogger(RTMServerApi::class.java.name)!!
fun getJsonObj(json: String): JsonObject {
val je: JsonElement = RTMProperties.JSONParser.fromJson(json, JsonElement::class.java)
return je.asJsonObject
}
private var instance: RTMApi? = null
fun instance(): RTMApi {
private var instance: RTMServerApi? = null
fun instance(): RTMServerApi {
if (instance == null) {
logDebug("init rtm api INSTANCE", false)
instance = RTMApi()
instance = RTMServerApi()
}
return instance as RTMApi
return instance as RTMServerApi
}
......@@ -101,7 +101,7 @@ class RTMApi private constructor() {
RPMApi.instance().getPowerUsageList().toJson(RTMProperties.parsePath("${RTMProperties.basePath}/check_power_usage.json").toString())
//init solvers in order to dump their state
var limits = PCMApi.instance().checkLimits()
var limits = PCMApi.Instance.checkLimits()
var state = CurrentState(limits.currentPowerUsage)
PCMAlgorithm(state, Solver.Algorithm.greedy)
......@@ -118,7 +118,7 @@ class RTMApi private constructor() {
}
actionList.toJson(RTMProperties.parsePath("${RTMProperties.basePath}/check_reset_actions_result_100.json").toString())
Thread.sleep(90000)
limits = PCMApi.instance().checkLimits()
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())
......@@ -153,11 +153,11 @@ class RTMApi private constructor() {
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())
res = ESMAlgorithm(state(tradeoff), algorithm).next()
this.saveResult(res, algorithm, "esm", initialState, limit.toInt())
Solver.Algorithm.values().forEach { mAlgorithm ->
var res = PCMAlgorithm(state(tradeoff), mAlgorithm).next()
this.saveResult(res, mAlgorithm, "pcm", initialState, limit.toInt())
res = ESMAlgorithm(state(tradeoff), mAlgorithm).next()
this.saveResult(res, mAlgorithm, "esm", initialState, limit.toInt())
}
}
......@@ -169,7 +169,7 @@ class RTMApi private constructor() {
}
fun saveResult(powerSettings: PowerSettings, algorithm: Solver.Algorithm, procedure: String, initialState: CurrentState, powerLimit: Int) {
private 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
......
......@@ -3,11 +3,9 @@ package psnc.m2dc.rtm
import psnc.m2dc.rtm.commands.java.APP_VERSION
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.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
import psnc.m2dc.rtm.rest.auth.RESTAuth
......@@ -28,15 +26,8 @@ object ServerInitializer {
loadConfig()// -> tu zglasza null pointer
loadResources()
PCMApi.init()
ESMApi.init()
setDefaultPriorities()
LightStorage.saveStorage()
// StorageKeys.POWER_LIMIT = Values.powerLimit(440.0)
// val a =PCMApi.instance().predictPCMActions()
// a.generateScripts().toJson(true)
} catch (e: Exception) {
e.printStackTrace()
......@@ -108,7 +99,7 @@ object ServerInitializer {
private fun setDefaultPriorities() {
try {
logInfo("Setting default priorities")
val currentMap = PCMApi.instance().getNodePrioritiesAsMap()
val currentMap = RTMApi.getNodePrioritiesAsMap()
val defaultMap = Keys.PCM.default_node_priority_map
val defaultPriority = Keys.PCM.default_node_priority.getNullable()
val priorities = ArrayList<NodePriority>()
......@@ -121,7 +112,7 @@ object ServerInitializer {
}
}
}
PCMApi.instance().setNodePriorities(priorities)
RTMApi.setNodePriorities(priorities)
} catch (e: Exception) {
e.printStackTrace()
logError(e, "Default priorities not loaded: ${e.message}")
......
......@@ -10,7 +10,7 @@ import com.beust.jcommander.Parameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import psnc.m2dc.rtm.ICommandLine;
import psnc.m2dc.rtm.RTMApi;
import psnc.m2dc.rtm.RTMServerApi;
import psnc.m2dc.rtm.pcm.algorithm.Solver;
......@@ -32,9 +32,9 @@ public class AlgorithmCheckCommand extends ICommandLine {
@Override
public void execute() {
if (algo == null) {
RTMApi.Companion.instance().checkAlgorithm(path, null, limit);
RTMServerApi.Companion.instance().checkAlgorithm(path, null, limit);
} else {
RTMApi.Companion.instance().checkAlgorithm(path, Solver.Algorithm.valueOf(algo), limit);
RTMServerApi.Companion.instance().checkAlgorithm(path, Solver.Algorithm.valueOf(algo), limit);
}
}
......
......@@ -9,7 +9,7 @@ import com.beust.jcommander.Parameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import psnc.m2dc.rtm.ICommandLine;
import psnc.m2dc.rtm.RTMApi;
import psnc.m2dc.rtm.RTMServerApi;
/**
......@@ -21,7 +21,7 @@ public class CheckCommand extends ICommandLine {
@Override
public void execute() {
RTMApi.Companion.instance().checkConf();
RTMServerApi.Companion.instance().checkConf();
}
}
......@@ -9,7 +9,7 @@ import com.beust.jcommander.Parameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import psnc.m2dc.rtm.ICommandLine;
import psnc.m2dc.rtm.RTMApi;
import psnc.m2dc.rtm.RTMServerApi;
/**
......@@ -21,7 +21,7 @@ public class InitCommand extends ICommandLine {
@Override
public void execute() {
RTMApi.Companion.instance().initConf();
RTMServerApi.Companion.instance().initConf();
}
}
......@@ -9,7 +9,7 @@ import com.beust.jcommander.Parameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import psnc.m2dc.rtm.ICommandLine;
import psnc.m2dc.rtm.RTMApi;
import psnc.m2dc.rtm.RTMServerApi;
/**
......@@ -21,7 +21,7 @@ public class InstallResourceFileCommand extends ICommandLine {
@Override
public void execute() {
RTMApi.Companion.instance().installResources();
RTMServerApi.Companion.instance().installResources();
}
}
......@@ -9,7 +9,7 @@ import com.beust.jcommander.Parameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import psnc.m2dc.rtm.ICommandLine;
import psnc.m2dc.rtm.RTMApi;
import psnc.m2dc.rtm.RTMServerApi;
/**
......@@ -23,7 +23,7 @@ public class StartCommand extends ICommandLine {
public void execute() {
log.info("Start Power Capping Manager REST service");
// UtilsKt.logDebug("command start",false);
RTMApi.Companion.instance().start();
RTMServerApi.Companion.instance().start();
}
}
package psnc.m2dc.rtm.commands.java
val APP_VERSION = "1.0.624_54345"
\ No newline at end of file
val APP_VERSION = "1.0.624_58959"
\ No newline at end of file
......@@ -3,7 +3,7 @@ package psnc.m2dc.rtm.rest
import com.google.gson.JsonObject
import com.google.gson.reflect.TypeToken
import org.slf4j.LoggerFactory
import psnc.m2dc.rtm.RTMApi
import psnc.m2dc.rtm.RTMServerApi
import psnc.m2dc.rtm.model.rest.*
import psnc.m2dc.rtm.properties.RTMProperties
import psnc.m2dc.rtm.rest.handlers.EnergySaverHandler
......@@ -200,11 +200,11 @@ abstract class Handlers {
if (this.contentLength()<=0 || !this.body().isEmpty() ){
return null
}
return RTMApi.getJsonObj(this.body())
return RTMServerApi.getJsonObj(this.body())
}
}
// val map = RTMApi.INSTANCE().storage.get<HashMap<String, NodeSettings>>(StorageKeys.temperature_limits)
// val map = RTMServerApi.INSTANCE().storage.get<HashMap<String, NodeSettings>>(StorageKeys.temperature_limits)
......@@ -6,7 +6,7 @@ import com.auth0.jwt.exceptions.JWTVerificationException
import com.auth0.jwt.interfaces.RSAKeyProvider
import org.apache.commons.configuration2.PropertiesConfiguration
import org.slf4j.LoggerFactory
import psnc.m2dc.rtm.RTMApi
import psnc.m2dc.rtm.RTMServerApi
import psnc.m2dc.rtm.properties.keys.Keys
import psnc.m2dc.rtm.rest.HandlersMap
import psnc.m2dc.rtm.rest.RESTExamples
......@@ -53,7 +53,7 @@ class TokenAuth : IRestAuth {
fun setToken(request: Request, response: Response): String {
try {
val json = request.body()
val jsonObj = RTMApi.getJsonObj(json);
val jsonObj = RTMServerApi.getJsonObj(json);
val username = jsonObj.get("username").asString;
val password = jsonObj.get("password").asString
......
package psnc.m2dc.rtm.rest.handlers
import org.slf4j.LoggerFactory
import psnc.m2dc.rtm.RTMApi
import psnc.m2dc.rtm.RTMServerApi
import psnc.m2dc.rtm.esm.ESMApi
import psnc.m2dc.rtm.rest.Handlers
import psnc.m2dc.rtm.rest.HandlersMap
......@@ -43,7 +43,7 @@ class EnergySaverHandler : Handlers() {
fun optimize(req: Request, res: Response): String {
return try {
req.logDebug()
val result = ESMApi.instance().optimize()
val result = ESMApi.optimize()
JsonBuilder().addObj(RESTKeys.result, result).toJson()
} catch (e: Exception) {
res.status(400)
......@@ -55,9 +55,9 @@ class EnergySaverHandler : Handlers() {
fun setESMPolicy(req: Request, res: Response): String {
return try {
req.logDebug()
val jo = RTMApi.getJsonObj(req.body())
val jo = RTMServerApi.getJsonObj(req.body())
val policy = getESMPowerPolicy(jo)
ESMApi.instance().setESMPowerPolicy(policy)
ESMApi.setESMPowerPolicy(policy)
RESTExamples.OK_RESPONSE
} catch (e: Exception) {
res.status(400)
......@@ -69,7 +69,7 @@ class EnergySaverHandler : Handlers() {
fun getESMPolicy(req: Request, res: Response): String {
return try {
req.logDebug()
val jo = JsonBuilder().addObj(RESTKeys.policy, ESMApi.instance().getESMPowerPolicy())
val jo = JsonBuilder().addObj(RESTKeys.policy, ESMApi.getESMPowerPolicy())
jo.toJson()
} catch (e: Exception) {
res.status(400)
......
package psnc.m2dc.rtm.rest.handlers
import org.slf4j.LoggerFactory
import psnc.m2dc.rtm.RTMApi
import psnc.m2dc.rtm.RTMServerApi
import psnc.m2dc.rtm.fm.FMApi
import psnc.m2dc.rtm.rest.Handlers
import psnc.m2dc.rtm.rest.HandlersMap
......@@ -49,7 +49,7 @@ class FMHandler : Handlers() {
fun setTemperatureLimit(req: Request, res: Response): String {
return try {
req.logDebug()
val jo = RTMApi.getJsonObj(req.body())
val jo = RTMServerApi.getJsonObj(req.body())
val limit = getTemperatureLimitList(jo)
FMApi.instance().setTemperatureLimit(limit)
RESTExamples.OK_RESPONSE
......@@ -63,7 +63,7 @@ class FMHandler : Handlers() {
fun getTemperatureLimit(req: Request, res: Response): String {
return try {
req.logDebug()
val jo = RTMApi.getJsonObj(req.body())
val jo = RTMServerApi.getJsonObj(req.body())
val nodes = getNodeList(jo)
val sensor = getApi(jo)
val jsonBuilder = JsonBuilder()
......@@ -79,7 +79,7 @@ class FMHandler : Handlers() {
fun getTermalData(req: Request, res: Response): String {
return try {
req.logDebug()
val jo = RTMApi.getJsonObj(req.body())
val jo = RTMServerApi.getJsonObj(req.body())
val jsonBuilder = JsonBuilder()
throw NotImplementedError("not implemented")
jsonBuilder.toJson()
......@@ -92,7 +92,7 @@ class FMHandler : Handlers() {
fun resetTemperatureLimit(req: Request, res: Response): String {
return try {
req.logDebug()
val jo = RTMApi.getJsonObj(req.body())
val jo = RTMServerApi.getJsonObj(req.body())
val nodes = getNodeList(jo)
val sensor = getApi(jo)
FMApi.instance().resetNodeTemperatureLimit(sensor, nodes)
......@@ -119,7 +119,7 @@ class FMHandler : Handlers() {
fun getPredictedTemperature(req: Request, res: Response): String {
return try {
req.logDebug()
val jo = RTMApi.getJsonObj(req.body())
val jo = RTMServerApi.getJsonObj(req.body())
val sensorId = req.params(RESTParams.api_id)
val timeIntervals = this.getTimeIntervals(jo)
val resourceIdList = this.getResourceList(jo)
......@@ -138,7 +138,7 @@ class FMHandler : Handlers() {
// fun getPredictedPower(req: Request, res: Response): String {
// try {
// req.logDebug()
// val jo = RTMApi.getJsonObj(req.body())
// val jo = RTMServerApi.getJsonObj(req.body())
// val timeintervals = this.getTimeIntervals(jo)
// val resourceIdList = this.getResourceList(jo)
// FMApi.instance().getPredictedPower(resourceIdList, timeintervals)
......
package psnc.m2dc.rtm.rest.handlers
import org.slf4j.LoggerFactory
import psnc.m2dc.rtm.RTMApi
import psnc.m2dc.rtm.RTMServerApi
import psnc.m2dc.rtm.StorageKeys
import psnc.m2dc.rtm.dao.DAO
import psnc.m2dc.rtm.dao.LightStorage
......@@ -51,7 +51,7 @@ class ManagementHandlers : Handlers() {
"storage_size" to LightStorage.size(),
"node_count" to DAO.Resource.getNodes().size,
"resource_count" to DAO.Resource.getResources().size,
"power_limit" to PCMApi.instance().getPowerLimit(),
"power_limit" to PCMApi.Instance.getPowerLimit(),
"power_usage" to RPMApi.instance().getPowerUsage()
)
)
......@@ -100,7 +100,7 @@ class ManagementHandlers : Handlers() {
fun setSettings(req: Request, res: Response): String {
return try {
req.logDebug()
val jo = RTMApi.getJsonObj(req.body())
val jo = RTMServerApi.getJsonObj(req.body())
val settings = getSettings(jo)
StorageKeys.loadSettings(settings)
val jb = JsonBuilder()
......
......@@ -2,6 +2,7 @@ package psnc.m2dc.rtm.rest.handlers
import org.slf4j.LoggerFactory
import psnc.m2dc.rtm.RTMApi
import psnc.m2dc.rtm.RTMServerApi
import psnc.m2dc.rtm.model.rest.NodePriority
import psnc.m2dc.rtm.model.rest.RestPropertyKeys
import psnc.m2dc.rtm.pcm.PCMApi
......@@ -72,9 +73,9 @@ class PCMHandler : Handlers() {
fun setPCMPolicy(req: Request, res: Response): String {
return try {
req.logDebug()
val jo = RTMApi.getJsonObj(req.body())
val jo = RTMServerApi.getJsonObj(req.body())
val policy = this.getPCPowerPolicy(jo)
PCMApi.instance().setPCPowerPolicy(policy)
PCMApi.Instance.setPCPowerPolicy(policy)
RESTExamples.OK_RESPONSE
} catch (e: Exception) {
res.status(400)
......@@ -87,7 +88,7 @@ class PCMHandler : Handlers() {
return try {
req.logDebug()
val jb = JsonBuilder()
jb.addObj(RESTKeys.policy, PCMApi.instance().getPCPowerPolicy())
jb.addObj(RESTKeys.policy, PCMApi.Instance.getPCPowerPolicy())
jb.toJson()
} catch (e: Exception) {
res.status(400)
......@@ -99,9 +100,9 @@ class PCMHandler : Handlers() {
fun setPCMStrategy(req: Request, res: Response): String {
return try {
req.logDebug()
val jo = RTMApi.getJsonObj(req.body())
val jo = RTMServerApi.getJsonObj(req.body())
val policy = this.getPowerCappingStrategy(jo)
PCMApi.instance().setPowerCappingStrategy(policy)
PCMApi.Instance.setPowerCappingStrategy(policy)
RESTExamples.OK_RESPONSE
} catch (e: Exception) {
res.status(400)
......@@ -114,7 +115,7 @@ class PCMHandler : Handlers() {
return try {
req.logDebug()
val jb = JsonBuilder()
jb.addObj(RESTKeys.strategy, PCMApi.instance().getPowerCappingStrategy())
jb.addObj(RESTKeys.strategy, PCMApi.Instance.getPowerCappingStrategy())
jb.toJson()
} catch (e: Exception) {
res.status(400)
......@@ -126,7 +127,7 @@ class PCMHandler : Handlers() {
fun resetPCMPowerLimit(req: Request, res: Response): String {
return try {
req.logDebug()
PCMApi.instance().resetPowerLimit()
PCMApi.Instance.resetPowerLimit()
RESTExamples.OK_RESPONSE
} catch (e: Exception) {
res.status(400)
......@@ -138,14 +139,14 @@ class PCMHandler : Handlers() {
fun setPCMPowerLimit(req: Request, res: Response): String {
return try {
req.logDebug()
val jo = RTMApi.getJsonObj(req.body())
val jo = RTMServerApi.getJsonObj(req.body())
val limit = getPowerLimit(jo)
var pcmStatus: Boolean
val percentage = try {
if (limit == null) {
return (100.0).toString()
}
pcmStatus = PCMApi.instance().setPowerLimit(limit)
pcmStatus = PCMApi.Instance.setPowerLimit(limit)
} catch (e: NumberFormatException) {
pcmStatus = false
null
......@@ -163,7 +164,7 @@ class PCMHandler : Handlers() {
fun getPCMPowerLimit(req: Request, res: Response): String {
return try {
req.logDebug()
val limit = PCMApi.instance().getPowerLimit()
val limit = PCMApi.Instance.getPowerLimit()
JsonBuilder().addObj(RESTKeys.powerLimit, limit).toJson()
} catch (e: Exception) {
res.status(400)
......@@ -176,7 +177,7 @@ class PCMHandler : Handlers() {
return try {
req.logDebug()
val jb = JsonBuilder()
val state = PCMApi.instance().checkState()
val state = PCMApi.Instance.checkState()
jb.addObj(RESTKeys.state, state)
jb.toJson()
} catch (e: Exception) {
......@@ -189,7 +190,7 @@ class PCMHandler : Handlers() {
fun getPCMCurrentState(req: Request, res: Response): String {
return try {
req.logDebug()
val state = PCMApi.instance().getCurrentState()
val state = PCMApi.Instance.getCurrentState()
val jsonBuilder = JsonBuilder()
jsonBuilder.addObj(RESTKeys.result, state)
jsonBuilder.toJson()
......@@ -204,9 +205,9 @@ class PCMHandler : Handlers() {
fun setPCMPriorityList(req: Request, res: Response): String {
return try {
req.logDebug()
val jo = RTMApi.getJsonObj(req.body())
val jo = RTMServerApi.getJsonObj(req.body())
val priorities: ArrayList<NodePriority> = getNodePriority(jo)
PCMApi.instance().setNodePriorities(priorities)
RTMApi.setNodePriorities(priorities)
RESTExamples.OK_RESPONSE
} catch (e: Exception) {
res.status(400)
......@@ -219,7 +220,7 @@ class PCMHandler : Handlers() {
return try {
req.logDebug()
val jb = JsonBuilder()
val priorities = PCMApi.instance().getNodePrioritiesAsMap().values
val priorities = RTMApi.getNodePrioritiesAsMap().values
jb.addObj(RESTKeys.nodePriorities, priorities)
jb.toJson()
} catch (e: Exception) {
......
......@@ -3,11 +3,11 @@ package psnc.m2dc.rtm.rest.handlers
import org.slf4j.LoggerFactory
import psnc.m2dc.rtm.ActionCache
import psnc.m2dc.rtm.RTMApi
import psnc.m2dc.rtm.RTMServerApi
import psnc.m2dc.rtm.dao.DAO
import psnc.m2dc.rtm.dao.LightStorage
import psnc.m2dc.rtm.model.rpm.ManagementMethodType
import psnc.m2dc.rtm.model.rpm.Resource
import psnc.m2dc.rtm.pcm.PCMApi
import psnc.m2dc.rtm.rest.Handlers
import psnc.m2dc.rtm.rest.HandlersMap
import psnc.m2dc.rtm.rest.JsonBuilder
......@@ -180,7 +180,7 @@ class ResourceHandler : Handlers() {
// try {
// req.logDebug()
// throw NotImplementedError()
// /* val jo = RTMApi.getJsonObj(req.body())
// /* val jo = RTMServerApi.getJsonObj(req.body())
// var typeName = req.params(Handlers.RESTParams.type_name)
// val type = this.getResourceType(jo)
// // StorageKeys.RESOURCE_TYPES.set(typeName, type)
......@@ -312,7 +312,7 @@ class ResourceHandler : Handlers() {
DAO.Resource.setProperty(nodeId, metadataKey, metadataValue)
} else {
val jo = RTMApi.getJsonObj(req.body())
val jo = RTMServerApi.getJsonObj(req.body())
jo.entrySet().forEach({
val propertyName = it.key
val propertyValue = it.value.asString
......@@ -439,7 +439,7 @@ class ResourceHandler : Handlers() {
fun setRCUUTil(req: Request, res: Response): String {
return try {
req.logDebug()
val jo = RTMApi.getJsonObj(req.body())
val jo = RTMServerApi.getJsonObj(req.body())
val rcu = getRCUUtil(jo)!!
// val ttl = rcu.timeInterval.ttl() - 300 //5 min
DAO.Chassis.addRCUUtil(rcu)
......@@ -489,7 +489,7 @@ class ResourceHandler : Handlers() {
fun setNodeUtil(req: Request, res: Response): String {
return try {
req.logDebug()
val jo = RTMApi.getJsonObj(req.body())
val jo = RTMServerApi.getJsonObj(req.body())
val nodeUtils = this.getNodeUtil(jo)
nodeUtils.forEach { it ->
//check if all resources exists
......@@ -510,17 +510,17 @@ class ResourceHandler : Handlers() {
req.logDebug()
val resourceId = req.params(Handlers.RESTParams.node_id_list)
val jsonBuilder = JsonBuilder()
val jo = RTMApi.getJsonObj(req.body())
val jo = RTMServerApi.getJsonObj(req.body())
val performance = this.getPerformance(jo)
val profile = this.getProfile(jo)
if (resourceId == "nodes") {
DAO.Resource.getNodes().values.forEach {
PCMApi.instance().setPerformance(it.id, performance.toDouble(), profile)
RTMApi.setPerformance(it.id, performance.toDouble(), profile)
}
} else {
val nodes = TypeConverters.Resource.convertToList(req, "node_id_list")
nodes!!.forEach { resource ->
PCMApi.instance().setPerformance(resource.id, performance.toDouble(), profile)
RTMApi.setPerformance(resource.id, performance.toDouble(), profile)
}
}