Author Topic: How to get a host status using Management API  (Read 2355 times)

Offline oceanblue

  • Newbie
  • *
  • Posts: 23
  • Karma: 0
How to get a host status using Management API
« on: June 29, 2019, 08:37:00 PM »
Hey Guys - I been trying to get host status using the following code without success :

RequestSubscribe requestSubscribeHost = RequestSubscribe.create();
requestSubscribeHost.setControlObjectType(ControlObjectType.Host);
requestSubscribeHost.setControlObjectId(hostDbid);
scsProtocol.send(requestSubscribeHost);

RequestGetHostInfo requestGetHostInfo = RequestGetHostInfo.create();
requestGetHostInfo.setControlObjectId(hostDbid);
scsProtocol.send(requestGetHostInfo);

each time I execute it for any host of various different status (i.e., up, unknown etc), I get the following output :

"has NO serverInfo, exiting"

what am I doing wrong?

Also, I noticed there's a HostStatus class which extends GEnum. Has anybody used it before?

Thanks,

Offline RobertH

  • Jr. Member
  • **
  • Posts: 69
  • Karma: 1
Re: How to get a host status using Management API
« Reply #1 on: July 02, 2019, 12:56:05 PM »
For me it work like this

Open protocol:
protocol = new SolutionControlServerProtocol(new Endpoint(new URI("tcp://" + host + ":" + port)));
protocol.setMessageHandler(handler);
protocol.addChannelListener(handler);
protocol.open();

Send request get info:
      sendRequest(req.requestGetHostInfo(101));

101 - is my host DBID from configuration.

Request code looks like this:
      public RequestGetHostInfo requestGetHostInfo(int dbid) {
RequestGetHostInfo req = RequestGetHostInfo.create();
req.setControlObjectId(dbid);
return req;
}

The handler is public class SCSHandler implements MessageHandler, ChannelListener and onChannelOpened { sendRequest(req.requestGetHostInfo(101)); }

log looks like this:
SCS Channel Opened = java.util.EventObject[source=com.genesyslab.platform.management.protocol.SolutionControlServerProtocol@59b3beac@{psdkendpoint - tcp://appsrv6:5010}]
sendRequest req='RequestGetHostInfo' (13) attributes:
attr_cfg_obj_id [int] = 101
attr_ref_id [int] = 2
sendRequest refid=2
SCS Message = 'EventInfo' (1) attributes:
attr_obj_live_status [int] = 2
attr_message [str] = "HOST_STATUS_RUNNING"
attr_cfg_obj_type [int] = 10 [Host]
attr_cfg_obj_id [int] = 101
attr_ref_id [int] = 2
attr_client [int] = 19

The RequestSubscribe is not required if you want to use RequestGetHostInfo only. RequestSubscribe will allow you to receive unsolicited host status changes.
for me it works and request code is:
public RequestSubscribe requestSubscribe(int dbid, ControlObjectType objType) {
RequestSubscribe req = RequestSubscribe.create();
req.setControlObjectType(objType);
req.setControlObjectId(dbid);
return req;
}

103 is my host dbid, I did switch on/off LCA on that machine and log looks like this.

sendRequest req='RequestSubscribe' (15) attributes:
attr_cfg_obj_id [int] = 103
attr_cfg_obj_type [int] = 10 [Host]
attr_ref_id [int] = 2
..on registered
SCS Message = 'EventInfo' (1) attributes:
attr_obj_live_status [int] = 0
attr_message [str] = "Registered"
attr_cfg_obj_type [int] = 10 [Host]
attr_cfg_obj_id [int] = 103
attr_ref_id [int] = 2
attr_client [int] = 19

... ON LCA down
SCS Message = 'EventInfo' (1) attributes:
attr_obj_live_status [int] = 3
attr_message [str] = "HOST_STATUS_UNAVAILABLE"
attr_cfg_obj_type [int] = 10 [Host]
attr_cfg_obj_id [int] = 103
attr_ref_id [int] = 0

.. then lots of disconnected messages
SCS Message = 'EventInfo' (1) attributes:
attr_obj_live_status [int] = 1
attr_message [str] = "HOST_STATUS_DISCONNECTED"
attr_cfg_obj_type [int] = 10 [Host]
attr_cfg_obj_id [int] = 103
attr_ref_id [int] = 0

... on LCA back UP
SCS Message = 'EventInfo' (1) attributes:
attr_obj_live_status [int] = 2
attr_message [str] = "HOST_STATUS_RUNNING"
attr_cfg_obj_type [int] = 10 [Host]
attr_cfg_obj_id [int] = 103
attr_ref_id [int] = 0

Maybe you did use wrong DBID?

Offline oceanblue

  • Newbie
  • *
  • Posts: 23
  • Karma: 0
Re: How to get a host status using Management API
« Reply #2 on: July 16, 2019, 05:21:31 AM »
Thank you so much for sharing this, Robert! Much appreciated!

In my case, I was having difficulties connecting to the correct SCS (in a distributed system) for a host. So, the  logic is it would first determine the SCS by host from config and then try to establish a connection to it.