Commit 8e1e2114 by Tomasz Ciesielczyk

minor bug fix, algorithm command check

parent e1ab964b
......@@ -3,13 +3,13 @@ package psnc.m2dc.rtm
import com.google.gson.JsonElement
import com.google.gson.JsonObject
import org.slf4j.LoggerFactory
import psnc.m2dc.rtm.commands.java.AlgorithmCheckCommand
import psnc.m2dc.rtm.dao.DAO
import psnc.m2dc.rtm.esm.ESMAlgorithm
import psnc.m2dc.rtm.model.rest.ResourceAction
import psnc.m2dc.rtm.model.rest.ResourceActionResult
import psnc.m2dc.rtm.pcm.PCMAlgorithm
import psnc.m2dc.rtm.pcm.PCMApi
import psnc.m2dc.rtm.pcm.algorithm.Algorithm
import psnc.m2dc.rtm.pcm.algorithm.Utils
import psnc.m2dc.rtm.properties.RTMProperties
import psnc.m2dc.rtm.rpm.RPMApi
......@@ -55,7 +55,7 @@ class RTMApi private constructor() {
}
fun checkConf() {
log.info("Start service Check!")
log.info("Start rest service check!")
ServerInitializer.check()
val nodes = DAO.Resource.getNodes()
......@@ -72,15 +72,18 @@ class RTMApi private constructor() {
}
}
actionList.toJson(RTMProperties.parsePath("${RTMProperties.basePath}/check_reset_actions_result.json").toString())
val limits = PCMApi.instance().checkLimits()
val state = CurrentState(limits.currentPowerUsage)
Thread.sleep(90000)
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 state = CurrentState(limits.currentPowerUsage)
PCMAlgorithm(state)
Thread.sleep(5000)
actionList = ArrayList<ResourceAction>()
actionResultList = ArrayList<ResourceActionResult>()
actionList = ArrayList<ResourceAction>()
actionResultList = ArrayList<ResourceActionResult>()
nodes.values.forEach { node ->
Utils.getPropertyAction(node.id, 100.0, null)?.let { actionList.addAll(it) }
}
......@@ -91,14 +94,17 @@ class RTMApi private constructor() {
}
}
actionList.toJson(RTMProperties.parsePath("${RTMProperties.basePath}/check_reset_actions_result_100.json").toString())
Thread.sleep(5000)
Thread.sleep(90000)
limits = PCMApi.instance().checkLimits()
state = CurrentState(limits.currentPowerUsage)
PCMAlgorithm(state)
RPMApi.instance().getPowerUsageList().toJson(RTMProperties.parsePath("${RTMProperties.basePath}/check_power_usage_100.json").toString())
// ESMAlgorithm(state)
// ESMAlgorithm(state)
}
fun checkAlgorithm(path: String,algorithm: Algorithm,limit:Double) {
fun checkAlgorithm(path: String, algorithm: AlgorithmCheckCommand.Algorithm, limit: Double) {
log.info("Algorithm Check!")
ServerInitializer.check()
val state = loadJsonFile<CurrentState>(Paths.get(path), CurrentState::class.java)
......
......@@ -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
......@@ -27,10 +28,12 @@ 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()
......@@ -133,7 +136,7 @@ object ServerInitializer {
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)
}
......
......@@ -20,19 +20,19 @@ import psnc.m2dc.rtm.RTMApi;
public class AlgorithmCheckCommand extends ICommandLine {
private static final Logger log = LoggerFactory.getLogger(AlgorithmCheckCommand.class);
@Parameter(names = {"--path"}, description = " main config file")
private String algo = null;
@Parameter(names = {"--algo"}, description = " algorithm name")
private String path = null;
@Parameter(names = {"--algo"}, description = " algorithm name")
private String algo = null;
@Parameter(names = {"--limit"}, description = " power limit")
private Double limit = null;
private enum Algorithm{
public enum Algorithm{
greedy,milp,random,simple,proportional
}
@Override
public void execute() {
RTMApi.Companion.instance().checkConf();
RTMApi.Companion.instance().checkAlgorithm(path,Algorithm.valueOf(algo),limit);
}
}
package psnc.m2dc.rtm.commands.java
val APP_VERSION = "1.0.529_34574"
\ No newline at end of file
val APP_VERSION = "1.0.529_67561"
\ No newline at end of file
......@@ -25,7 +25,7 @@ public class VersionCommand extends ICommandLine {
// } catch (UtilsException ex) {
// Logger.getLogger(VersionCommand.class.getName()).log(Level.SEVERE, null, ex);
// }
System.out.println(VERSION);
System.out.println(VersionKt.getAPP_VERSION());
}
}
package psnc.m2dc.rtm.client
const val APP_VERSION = "1.1.529_34575"
\ No newline at end of file
const val APP_VERSION = "1.1.529_67561"
\ No newline at end of file
......@@ -219,7 +219,7 @@ class ResourceManager : DataDAO() {
val details = this.getRecsHosts(false)
printConsole("recs hosts: ${details.toJson()}")
val list = RECSMonitoringApi.instance.listAllNodes(details)
printConsole("loaded recs nodes1: ${list.toJson()}")
// printConsole("loaded recs nodes1: ${list.toJson()}")
list.forEach { resource ->
res[resource.id] = resource
}
......@@ -290,8 +290,8 @@ class ResourceManager : DataDAO() {
printConsole("append resources:${resourceList.joinToString(separator = ", ") { "resource: ${it.id}:${it.typeId}" }}")
val current = loadResourceFromFile()
//merge with existing
printConsole(current.toJson())
printConsole(resourceList.toJson())
// printConsole(current.toJson())
// printConsole(resourceList.toJson())
current.putAll(resourceList.filter { !current.containsKey(it.id) }.map { it.id to it })
//save to file
current.toJson(RTMProperties.parsePath(Keys.RTM.resource_file.get()).toString(), true)
......
......@@ -257,7 +257,7 @@ class RPMApiImpl : RPMApi {
// }
when (api) {
ManagementApi.ssh -> {
println("Start set property")
println("Start SSH set property")
SSHApiImpl.init(resource, false).setProperty(entityId, propertyName, value)
}
else -> {
......
......@@ -12,7 +12,6 @@ import psnc.m2dc.mock.rtm.rpm.RECSApiMock
import psnc.m2dc.rtm.model.recs.*
import psnc.m2dc.rtm.properties.RTMProperties
import psnc.m2dc.rtm.properties.keys.Keys
import psnc.m2dc.rtm.utils.logDebug
import psnc.m2dc.rtm.utils.logInfo
import psnc.m2dc.rtm.utils.printConsole
import psnc.m2dc.rtm.utils.toJson
......@@ -160,7 +159,8 @@ class RECSApiImpl private constructor(parser: XStream = initXMLParser() ) : RECS
printConsole("GET: $url : ${headers.toJson()}" )
val connection = Jsoup.connect(url).timeout(30000)
.method(Connection.Method.GET).headers(headers).execute()
logDebug("recs output: ${connection.body()}")
//TODO: log debug
// logDebug("recs output: ${connection.body()}")
return Pair(XMLParser.fromXML(connection.body()) as T, connection.headers())
//fromCache = Pair(XMLParser.fromXML(connection.body()) as T, connection.headers())
// setCache(fromCache, storage, url, headers.toString())
......
......@@ -6,7 +6,6 @@ import psnc.m2dc.rtm.dao.LightStorage
import psnc.m2dc.rtm.model.recs.*
import psnc.m2dc.rtm.model.rest.NodeModel
import psnc.m2dc.rtm.model.rpm.*
import psnc.m2dc.rtm.properties.RTMProperties
import psnc.m2dc.rtm.properties.keys.Keys
import psnc.m2dc.rtm.rpm.ManagementExecutor
import psnc.m2dc.rtm.rpm.ManagementWorker
......@@ -182,7 +181,8 @@ 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()
logDebug("recs nodes: " + RTMProperties.JSONParser.toJson(nl.nodeList.size))
//TODO: debug print
// logDebug("recs nodes: " + RTMProperties.JSONParser.toJson(nl.nodeList.size))
return nl
}
......
......@@ -232,6 +232,7 @@ open class SSHApiImpl private constructor(val resource: Resource) : SSHApi {
File(RTMProperties.parsePath(Keys.RTM.remote_script_location.get()).toString().replace("\$user",
this.resource.get(Resource.Property.ssh_username.toString())!!),
_scriptName).path.toString(), params)
printConsole("RUN SSH command: " + cmd.toJson())
result = runCommand(cmd)
}
// printConsole("sshTest result:$result")
......@@ -247,7 +248,8 @@ open class SSHApiImpl private constructor(val resource: Resource) : SSHApi {
try {
val array = cmd.build()
log.debug("running ssh cmd: " + cmd.toString())
// printConsole("running ssh cmd2: " + array.toJson())
printConsole("running ssh cmd2: " + array.toJson())
// printConsole("running ssh cmd2: " + cmd.toString())
p = Runtime.getRuntime().exec(array)
p.waitFor()
......@@ -284,9 +286,9 @@ open class SSHApiImpl private constructor(val resource: Resource) : SSHApi {
}
log.debug(stdOut.toString())
if (stdOut.length > 1)
return stdOut.toString().trim()
return stdOut.toString().trim().let { printConsole("ssh result: ${it.take(256).replace("\n"," ")}"); it }
else {
return stdErr.toString().trim()
return stdErr.toString().trim().let { printConsole("ssh err $it"); it }
}
}
......
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