Commit 52ff8d48 by Tomasz Ciesielczyk

new api commang, resoruce generator update, multiple recs hosts fix, other bug fixes

parent 224554a0
......@@ -17,6 +17,12 @@ import java.util.*
* Created by Tomek on 2018-08-30.
*/
abstract class RTMAlgorithm(currentState: CurrentState) {
fun saveState() {
this.state.toJson(RTMProperties.parsePath("${RTMProperties.basePath}/${this::class.java.simpleName}_${Date().time}.dmp").toString())
}
var state: CurrentState = currentState
private set
......
......@@ -5,6 +5,8 @@ import psnc.m2dc.rtm.PowerSettings
import psnc.m2dc.rtm.RTMAlgorithm
import psnc.m2dc.rtm.model.rpm.Resource
import psnc.m2dc.rtm.pcm.PCMApi
import psnc.m2dc.rtm.utils.loadJsonFile
import psnc.m2dc.rtm.utils.logWarn
import psnc.m2dc.rtm.utils.printConsole
import psnc.m2dc.rtm.utils.toJson
......@@ -22,6 +24,15 @@ IV. Perform chosen actions.
class ESMAlgorithm(state: CurrentState) : RTMAlgorithm(state) {
private lateinit var solver: ESMSolver
init {
this.saveState()
//TODO: remove this line
if(this.unusedResourcesSuspendSavings()>0){
logWarn("there are some suspends savings:" +this.unusedResourcesSuspendSavings())
}
}
private fun setSolver(powerBudget: Double) {
state.eval.addPowerBudget(powerBudget)
solver = ESMSolver(state.eval)
......
......@@ -5,6 +5,7 @@ import psnc.m2dc.rtm.PowerSettings
import psnc.m2dc.rtm.RTMAlgorithm
import psnc.m2dc.rtm.model.rpm.Resource
import psnc.m2dc.rtm.utils.logInfo
import psnc.m2dc.rtm.utils.logWarn
import psnc.m2dc.rtm.utils.printConsole
/*
......@@ -36,10 +37,19 @@ PCM algorithm:
class PCMAlgorithm(state: CurrentState) : RTMAlgorithm(state) {
private var solver: PCMSolver = PCMSolver(state.eval)
init {
this.saveState()
if (this.unusedResourcesSuspendSavings() > 0) {
logWarn("there are some suspends savings:" + this.unusedResourcesSuspendSavings())
}
}
// var algoState: AlgorithmState? = null
private fun setSolver(powerBudget: Double) {
this.state.eval.addPowerBudget(powerBudget)
solver = PCMSolver(state.eval)
}
fun next(): PowerSettings {
......
......@@ -87,7 +87,7 @@ advancedPriorityMode: Boolean = true) {
}
companion object {
val log = LoggerFactory.getLogger(Evaluation::class.java.name)
val log = LoggerFactory.getLogger(Evaluation::class.java.name)!!
}
private val stateMap = HashMap<String, StateDefinition>()
......
......@@ -6,6 +6,7 @@ import org.ojalgo.optimisation.Variable
import org.slf4j.LoggerFactory
import psnc.m2dc.rtm.model.rpm.StateDefinition
import psnc.m2dc.rtm.utils.logInfo
import java.util.*
import java.util.concurrent.atomic.AtomicInteger
//todo: dump power settings
......@@ -23,6 +24,9 @@ open class Solver(e: Evaluation, var mode: SolverMode, val powerBuffer: Double)
pcm, esm
}
private var currentBudget: Double
......@@ -49,6 +53,8 @@ open class Solver(e: Evaluation, var mode: SolverMode, val powerBuffer: Double)
companion object {
val log = LoggerFactory.getLogger(Solver::class.java.name) ?: throw NullPointerException("${Solver::class.java
.name} logger initializer failed")
}
init {
......
......@@ -52,6 +52,7 @@ public final class JCommandAgent extends JCommander {
@Parameter(names = {"--debug"}, description = " debug mode")
private boolean debug = true;
/**
* @return the configFile
*/
......
......@@ -3,8 +3,20 @@ package psnc.m2dc.rtm
import com.google.gson.JsonElement
import com.google.gson.JsonObject
import org.slf4j.LoggerFactory
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
import psnc.m2dc.rtm.utils.loadJsonFile
import psnc.m2dc.rtm.utils.logDebug
import psnc.m2dc.rtm.utils.toJson
import java.nio.file.Paths
class RTMApi private constructor() {
companion object {
......@@ -30,7 +42,7 @@ class RTMApi private constructor() {
fun start() {
log.info("Start REST service!")
ServerInitializer.init()
ServerInitializer.start()
}
......@@ -42,8 +54,47 @@ class RTMApi private constructor() {
}
fun checkConf() {
log.info("Start service Check!")
ServerInitializer.check()
RPMApi.instance().getPowerUsageList().toJson(RTMProperties.parsePath("${RTMProperties.basePath}/check_power_usage.json").toString())
val nodes = DAO.Resource.getNodes()
nodes.toJson(RTMProperties.parsePath("${RTMProperties.basePath}/check_node_list.json").toString())
val actionList = ArrayList<ResourceAction>()
val actionResultList = ArrayList<ResourceActionResult>()
nodes.values.forEach { node ->
Utils.getPropertyAction(node.id, 100.0, null)?.let { actionList.addAll(it) }
}
actionList.toJson(RTMProperties.parsePath("${RTMProperties.basePath}/check_reset_actions.json").toString())
actionList.forEach { action ->
RPMApi.instance().startAction(action).let { result ->
actionResultList.add(result)
}
}
actionList.toJson(RTMProperties.parsePath("${RTMProperties.basePath}/check_reset_actions_result.json").toString())
val limits = PCMApi.instance().checkLimits()
val state = CurrentState(limits.currentPowerUsage)
//init solvers in order to dump their state
PCMAlgorithm(state)
// ESMAlgorithm(state)
}
fun checkAlgorithm(path: String,algorithm: Algorithm,limit:Double) {
log.info("Algorithm Check!")
ServerInitializer.check()
val state = loadJsonFile<CurrentState>(Paths.get(path), CurrentState::class.java)
?: throw NullPointerException("State not found")
PCMAlgorithm(state)
ESMAlgorithm(state)
}
}
fun main(args: Array<String>) {
JCommandAgent.instance(args).execute()
......
......@@ -5,6 +5,7 @@ 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.RTMProperties
import psnc.m2dc.rtm.properties.keys.Keys
import psnc.m2dc.rtm.utils.*
......@@ -18,11 +19,22 @@ object ServerConfInitializer {
try {
logInfo("version: $APP_VERSION")
loadConfig()
prepareResourceFile().toJson("_resource.conf",true)
loadResources()
RTMProperties.parsePath("${RTMProperties.basePath}/_resource.conf")
val resources = prepareResourceFile()
resources.toJson(RTMProperties.parsePath("${RTMProperties.basePath}/_resource.conf").toString(), true)
//TODO: make this configurable
val overwrite = true
if (overwrite) {
printConsole("Save resources")
DAO.ResourcesManagerApi.saveResourcesToFile(resources)
// resources.toJson(RTMProperties.parsePath("${Keys.RTM.resource_file.get()}").toString(), true)
}
// setDefaultPriorities()
// loadResources()
// setDefaultPriorities()
LightStorage.instance.save(null)
printConsole("end init")
} catch (e: Exception) {
e.printStackTrace()
logError("Server initialization failed: ${e.message}")
......@@ -31,7 +43,6 @@ object ServerConfInitializer {
}
private fun loadConfig() {
Timer.start()
DAO.Settings.loadComponentPowerModel()
......@@ -61,36 +72,40 @@ object ServerConfInitializer {
//
// }
private fun loadResources() {
val t = setWatch()
if (Keys.RTM.resources_src_list.get().contains("RECS"))
DAO.ResourcesManagerApi.getRecsHosts(true)
DAO.ResourcesManagerApi.loadResources()
DAO.ResourcesManagerApi.saveResourcesToFile(listOf<Resource>())
setWatch(t)
}
// private fun loadResources() {
// val t = setWatch()
// if (Keys.RTM.resources_src_list.get().contains("RECS"))
// DAO.ResourcesManagerApi.getRecsHosts(true)
// DAO.ResourcesManagerApi.loadResources()
// DAO.ResourcesManagerApi.saveResourcesToFile(listOf<Resource>())
// setWatch(t)
// }
fun prepareResourceFile():List<Resource>{
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")
// printConsole( DAO.Resource.getNodes().toJson())
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");
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";
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)}
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) }
result.add(r)
}
val r= Resource("dummy_node","node_type",null)
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(r)
// result.add dummy
return result
}
......
......@@ -6,7 +6,6 @@ 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,9 +21,7 @@ import spark.Spark
*/
object ServerInitializer {
fun init() {
private fun init() {
try {
logInfo("version: $APP_VERSION")
loadConfig()// -> tu zglasza null pointer
......@@ -38,6 +35,17 @@ object ServerInitializer {
// StorageKeys.POWER_LIMIT = Values.powerLimit(440.0)
// val a =PCMApi.instance().predictPCMActions()
// a.generateScripts().toJson(true)
} catch (e: Exception) {
e.printStackTrace()
logError("Server initialization failed: ${e.message}")
System.exit(-1)
}
}
fun start() {
try {
this.init()
setScanner()
// ReloadTask.start()
if (Keys.Default.use_ssl.get()) {
......@@ -49,7 +57,19 @@ object ServerInitializer {
LightStorage.instance.save(null)
} catch (e: Exception) {
e.printStackTrace()
logError("Server initialization failed: ${e.message}")
logError("Server start failed: ${e.message}")
System.exit(-1)
}
}
fun check() {
try {
this.init()
LightStorage.instance.save(null)
} catch (e: Exception) {
e.printStackTrace()
logError("Server start failed: ${e.message}")
System.exit(-1)
}
}
......@@ -113,7 +133,7 @@ object ServerInitializer {
if (Keys.RTM.resources_src_list.get().contains("RECS"))
DAO.ResourcesManagerApi.getRecsHosts(true)
DAO.ResourcesManagerApi.loadResources()
DAO.ResourcesManagerApi.saveResourcesToFile(listOf())
setWatch(t)
}
......
/*
* 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.Parameter;
import com.beust.jcommander.Parameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import psnc.m2dc.rtm.ICommandLine;
import psnc.m2dc.rtm.RTMApi;
/**
* @author Tomek
*/
@Parameters(commandNames = "algorithm", commandDescription = " Check server conf")
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 = {"--limit"}, description = " power limit")
private Double limit = null;
private enum Algorithm{
greedy,milp,random,simple,proportional
}
@Override
public void execute() {
RTMApi.Companion.instance().checkConf();
}
}
/*
* 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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import psnc.m2dc.rtm.ICommandLine;
import psnc.m2dc.rtm.RTMApi;
/**
* @author Tomek
*/
@Parameters(commandNames = "check", commandDescription = " Check server conf")
public class CheckCommand extends ICommandLine {
private static final Logger log = LoggerFactory.getLogger(CheckCommand.class);
@Override
public void execute() {
RTMApi.Companion.instance().checkConf();
}
}
package psnc.m2dc.rtm.commands.java
val APP_VERSION = "1.0.500_53131"
\ No newline at end of file
val APP_VERSION = "1.0.519_65027"
\ No newline at end of file
......@@ -28,6 +28,7 @@ class ReloadTask {
val d = setWatch()
DAO.ResourcesManagerApi.loadResources()
DAO.ResourcesManagerApi.saveResourcesToFile(listOf())
// DAO.Settings.loadComponentPowerModel()
setWatch(d)
// loadResources()
......
package psnc.m2dc.rtm.client
const val APP_VERSION = "1.1.500_53133"
\ No newline at end of file
const val APP_VERSION = "1.1.519_65027"
\ No newline at end of file
......@@ -22,7 +22,7 @@ class ResourceDAO(val storage: TreeStorage) {
ManagementApi.ssh -> storage.get<String>("resources", resourceId, "properties", "ssh_host")
?: Keys.SSHHosts.get(resourceId)
ManagementApi.ipmi -> storage.get<String>("resources", resourceId, "properties", "ipmi_host")
ManagementApi.recs -> Keys.RTM.recs_hosts.get().first() //TODO: only ONE recs host is currently available
ManagementApi.recs -> storage.get<String>("resources", resourceId, "properties", "recs_host")
else -> null
}
......
......@@ -52,8 +52,6 @@ class ResourceManager : DataDAO() {
}
fun getResourceType(r: Resource): ResourceType {
return Keys.RTM.resource_type_map.getNullable(r.typeId) ?: throw NullPointerException(
"Cannot find resource type for resource: ${r.id}:${r.typeId}")
......@@ -85,13 +83,18 @@ class ResourceManager : DataDAO() {
fun loadResources() {
val srcList = Keys.RTM.resources_src_list.get()
val orderedSourceList = listOf("RECS", "FILE")
printConsole(srcList.toJson())
val orderedSourceList = listOf("RECS", "JSON", "FILE")
// val resources = HashMap<String, Resource>()
orderedSourceList.forEach { src ->
if (srcList.contains(src)) {
loadResources(src).forEach { loaded ->
loaded.value.get(Resource.Property.is_node, true)
// printConsole(DAO.Resource.getResources()[loaded.value.id]?.toJson() ?: "null: ${loaded.value.id}")
loaded.value.saveIndex(nodeIndex, "resources", loaded.key)
// printConsole("2: " + DAO.Resource.getResources()[loaded.value.id]?.toJson()
// ?: "null: ${loaded.value.id}")
//child resources
if (Keys.RTM.load_node_children.get()) {
logInfo("Load child resources for${loaded.key}")
......@@ -140,6 +143,9 @@ class ResourceManager : DataDAO() {
"FILE" -> {
loadResourceFromFile()
}
"JSON" -> {
loadResourceFromJsonFile()
}
else -> {
logError("Resource source($src) not supported")
throw IllegalArgumentException("src:$src not found")
......@@ -147,7 +153,7 @@ class ResourceManager : DataDAO() {
}
setParentNodeId(res)
logInfo("resources loaded from $src(${res.keys.size})")
logDebug("loaded resources: ${RTMProperties.JSONParser.toJson(res.keys.toList().subList(0, Math.min(res.size, 1600)))}")
logDebug("loaded resources$src: ${RTMProperties.JSONParser.toJson(res.keys.toList().subList(0, Math.min(res.size, 1600)))}")
return res
} catch (e: Exception) {
logError("${e.message}")
......@@ -210,11 +216,14 @@ class ResourceManager : DataDAO() {
val res = HashMap<String, Resource>()
val timer = setWatch()
val details = this.getRecsHosts(false)
printConsole("recs hosts: ${details.toJson()}")
val list = RECSMonitoringApi.instance.listAllNodes(details)
printConsole("loaded recs nodes1: ${list.toJson()}")
list.forEach { resource ->
res[resource.id] = resource
}
setWatch(timer)
// printConsole("loaded recs nodes: ${res.toJson()}")
res
} catch (ex: Exception) {
ex.printStackTrace()
......@@ -250,6 +259,29 @@ class ResourceManager : DataDAO() {
}
}
private fun loadResourceFromJsonFile(): HashMap<String, Resource> {
try {
val type = object : TypeToken<List<HashMap<String, Any>>>() {
}.type
val result = HashMap<String, Resource>()
val m = (RTMProperties.getJson<List<HashMap<String, Any>>>(RTMProperties.parsePath(Keys.RTM.resource_json_file.get()), type)
?: ArrayList())
m.forEach { map ->
val resource = Resource(map["id"]?.toString() ?: "dummy_node", map["type_id"]?.toString()
?: "node_type", null)
map["ssh_host"]?.let { resource.put(Resource.Property.ssh_host, it) }
map["ipmi_host"]?.let { resource.put(Resource.Property.ipmi_host, it) }
map["recs_host"]?.let { resource.put(Resource.Property.recs_host, it) }
map["ssh_username"]?.let { resource.put(Resource.Property.ssh_username, it) }
result[resource.id] = resource
}
return result
} catch (ex: Exception) {
logError("Error occured while loading resources from file: ${ex.message}")
return HashMap()
}
}
fun saveResourcesToFile(resourceList: List<Resource>) {
try {
......@@ -257,6 +289,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())
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)
......
......@@ -63,7 +63,7 @@ data class RTMProperty<T : Any>(val key: String, private val defaultValue: T?, v
}
return this.get(defaultValue::class.java) ?: defaultValue
}
throw NullPointerException("RTMProperty defaultValue not defined")
throw NullPointerException("RTMProperty defaultValue not defined ${this.key}")
}
@Suppress("UNCHECKED_CAST")
......
......@@ -15,11 +15,12 @@ class RTM {
return description
}
val resources_src_list = RTMProperty(RTM + "resources_src_list", arrayOf("FILE"), description = "Available sources: FILE, RECS")
val resources_src_list = RTMProperty(RTM + "resources_src_list", arrayOf("FILE"), description = "Available sources: FILE, RECS. JSON (json file)")
val recs_host_src_list = RTMProperty(RTM + "recs_host_src_list", arrayOf("CONFIG"), description = "Available sources: LDAP, FILE (TODO), CONF/CONFIG( @see recs_hosts)")
val recs_hosts_file = RTMProperty(RTM + "recs_hosts_file", null, String::class.java)
val recs_hosts = RTMProperty(RTM + "recs_hosts", arrayOf<String>(), description = "comma separated list of hosts")
val resource_file = RTMProperty(RTM + "resource_file", "\$[basePath]/conf/resources.conf", String::class.java)
val resource_json_file = RTMProperty(RTM + "resource_json_file", "\$[basePath]/conf/resources.json", String::class.java,description = " File containing resource properties in json format")
// val file_storage_location = RTMProperty(RTM + "file_storage_location", null, String::class.java)
val remote_script_location = RTMProperty(RTM + "remote_script_location", "/home/\$user/rtm/bin")
val ipmi_privilage_lvl = RTMProperty(RTM + "ipmi_privilage_lvl", null, PrivLvl::class.java, description = "CALLBACK, USER, OPERATOR, ADMINISTRATOR")
......
......@@ -15,11 +15,11 @@ class SSHHosts {
}
val default_host = RTMProperty(SSH_HOSTS + "default_host",
"example.ssh.host.org")
null)
fun get(nodeId: String): String {
fun get(nodeId: String): String? {
return RTMProperty(SSH_HOSTS + nodeId,
default_host.get()).get()
default_host.getNullable()).getNullable()
}
}
\ No newline at end of file
......@@ -474,7 +474,7 @@ class RPMApiImpl : RPMApi {
private fun loadSSHData(resourceId: String, host: String, userName: String?): ArrayList<Triple<String, String, Any>> {
if (userName == null) {
throw Exception("No ssh properties ")
throw Exception("No ssh properties $resourceId:$host")
}
val dummyResource = Resource(resourceId, "", null, null, hashMapOf(
Resource.Property.ssh_host.toString() to host,
......@@ -501,7 +501,7 @@ class RPMApiImpl : RPMApi {
private fun loadIPMIData(resourceId: String, endpoint: String): List<Triple<String, String, Any>> {
printConsole("ipmi")
printConsole("ipmi")
val data = this.ipmiApi.getSensorData(endpoint)
data["inlet_temp"]?.toDoubleOrNull()?.let { t1 ->
data["pch_temp"]?.toDoubleOrNull()?.let { t2 ->
......@@ -586,7 +586,7 @@ printConsole("ipmi")
//<editor-fold defaultstate="collapsed" desc="init/fields ">
// val storage: IStorage<String>
// val storage: IStorage<String>
// val fileStorageWrapper: DataDAOUtils
private val ipmiApi by lazy { IPMIApiImpl.init(IPMICredentials.loadFromProperties()) }
......
......@@ -12,8 +12,10 @@ 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
class RECSApiImpl private constructor(parser: XStream = initXMLParser() ) : RECSApi(parser) {
......@@ -155,9 +157,10 @@ class RECSApiImpl private constructor(parser: XStream = initXMLParser() ) : RECS
val authString = "$username:$password"
val base64login = String(Base64.encodeBase64(authString.toByteArray()))
headers["Authorization"] = "Basic $base64login"
printConsole("GET: $url : ${headers.toJson()}" )
val connection = Jsoup.connect(url).timeout(30000)
.method(Connection.Method.GET).headers(headers).execute()
log.debug("recs output: ${connection.body()}")
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())
......
......@@ -35,15 +35,18 @@ class RECSMonitoringApi private constructor(/*storage: IStorage<String>? = null*
}
fun listAllNodes(hosts: List<String>): List<Resource> {
//TODO: set reload param
val reload = true
logInfo("RECS: getnodes from: $hosts")
// println("list nodes, hostsize: " + recsDetails.hostMap.size)
val l = ArrayList<Resource>()
val updateList = ArrayList<Resource>()
hosts.forEach { host ->
val map = DAO.Resource.getNodes()
val nodes = listNodes(host).nodeList.filter {
!map.containsKey(it.id) &&
// printConsole("${!map.containsKey(it.id)}/${Keys.TestBed.resource_list.getNullable()?.toJson()}")
(!map.containsKey(it.id) || reload) &&
(!Keys.TestBed.filter_nodes.get() ||
Keys.TestBed.resource_list.getNullable()?.contains(it.id) ?: false)
}
......@@ -53,22 +56,25 @@ class RECSMonitoringApi private constructor(/*storage: IStorage<String>? = null*
try {
val typeId = DAO.Resource.getType(it.id)
val resource = Resource(it.id, typeId ?: "recsnode", null, properties = HashMap())
if (typeId == null) {
logWarn("Recs resource type is not set, try reload:${resource.id}")
l.add(resource)
}
val resource = Resource(it.id, typeId ?: "", null, properties = HashMap())
resource.put(Resource.Property.recs_host, host)
val model = NodeModel.create(it.id, it.architecture ?: "unknown", HashMap())
resource.put(Resource.Property.ssh_host, Keys.SSHHosts.get(resource.id))
if (Keys.RTM.default_ssh_user.getNullable() != null)
resource.put(Resource.Property.ssh_username, Keys.RTM.default_ssh_user.getNullable()!!)
Keys.SSHHosts.get(resource.id)
Keys.SSHHosts.get(resource.id)?.let { ssh_host ->
resource.put(Resource.Property.ssh_host, ssh_host)
}
Keys.RTM.default_ssh_user.getNullable()?.let { resource.put(Resource.Property.ssh_username, it) }
if (typeId == null && Keys.SSHHosts.get(resource.id) != null && Keys.RTM.default_ssh_user.getNullable() != null) {
logWarn("Recs resource type is not set, try reload:${resource.id}")
updateList.add(resource)
}
resource.put(model)
resource.put(Resource.Property.is_node, true)
resource.put(Resource.Property.node_id, resource.id)
l.add(resource)
//resource.resourceType = resourceType
} catch (e: Exception) {
......@@ -77,7 +83,7 @@ class RECSMonitoringApi private constructor(/*storage: IStorage<String>? = null*
}
}
}