Commit e99e56fa authored by Claes Sjofors's avatar Claes Sjofors

Sev, bugfixes, console logging, status message and improved errorhandling

parent e3d38276
......@@ -21,6 +21,7 @@
#include "pwr.h"
#include "co_cdh.h"
#include "co_dcli.h"
#include "co_time.h"
#include "co_error.h"
......@@ -39,6 +40,7 @@
#define sev_cGarbageInterval 120
int sev_server::init( int noneth)
{
qcom_sNode node;
......@@ -50,9 +52,13 @@ int sev_server::init( int noneth)
pwr_tFileName envname;
char socket[200];
m_server_status = PWR__SRVSTARTUP;
qcom_Init( &m_sts, &aid, "sev_server");
if ( EVEN(m_sts)) throw co_error(m_sts);
errh_Init( "sev_server", (errh_eAnix)0);
m_noneth = noneth;
if (!m_noneth) {
// Check server config object
......@@ -81,19 +87,21 @@ int sev_server::init( int noneth)
env->open( envname);
if ( !env->createDb()) {
errh_Fatal("Failed to create to database");
errh_Fatal("Failed to create to database '%s'", sev_dbms_env::dbName());
exit(0);
}
}
else {
if ( !env->openDb()) {
errh_Fatal("Failed to connect to database");
errh_Fatal("Failed to connect to database '%s'", sev_dbms_env::dbName());
exit(0);
}
}
m_db = new sev_dbms( env);
errh_Info("Database opened '%s'", sev_dbms_env::dbName());
m_db->get_items( &m_sts);
for ( unsigned int i = 0; i < m_db->m_items.size(); i++) {
......@@ -153,7 +161,9 @@ int sev_server::connect()
qcom_sQid tgt;
qcom_sPut put;
pwr_tStatus sts, lsts;
// Wait for qmon to start
sleep(5);
for ( unsigned int i = 0; i < m_nodes.size(); i++) {
tgt.nid = m_nodes[i].nid;
......@@ -173,7 +183,10 @@ int sev_server::connect()
if ( !qcom_Put( &sts, &tgt, &put)) {
qcom_Free( &sts, put.data);
errh_Info( "No connection to %s (%s)", m_nodes[i].name, cdh_NodeIdToString( 0, m_nodes[i].nid, 0, 0));
}
else
errh_Info( "Connect sent to %s (%s)", m_nodes[i].name, cdh_NodeIdToString( 0, m_nodes[i].nid, 0, 0));
}
return 1;
......@@ -274,6 +287,41 @@ int sev_server::send_itemlist( qcom_sQid tgt)
return 1;
}
int sev_server::send_server_status( qcom_sQid tgt)
{
qcom_sPut put;
pwr_tStatus sts, lsts;
put.size = sizeof(sev_sMsgServerStatus);
put.data = qcom_Alloc(&lsts, put.size);
((sev_sMsgServerStatus *)put.data)->Type = sev_eMsgType_ServerStatus;
sts = m_server_status;
for ( unsigned int i = 0; i < m_db->m_items.size(); i++) {
if ( m_db->m_items[i].deleted || m_db->m_items[i].status == 0)
continue;
if ( errh_Severity( m_db->m_items[i].status) > errh_Severity( sts))
sts = m_db->m_items[i].status;
}
((sev_sMsgServerStatus *)put.data)->Status = sts;
put.reply.nid = m_nodes[0].nid;
put.reply.qix = sev_eProcSevServer;
put.type.b = (qcom_eBtype) sev_cMsgClass;
put.type.s = (qcom_eStype) sev_eMsgType_ServerStatus;
put.msg_id = m_msg_id++;
if ( !qcom_Put( &sts, &tgt, &put)) {
qcom_Free( &sts, put.data);
return 0;
}
return 1;
}
int sev_server::delete_item( qcom_sQid tgt, sev_sMsgHistItemDelete *rmsg)
{
qcom_sPut put;
......@@ -320,6 +368,8 @@ int sev_server::mainloop()
time_GetTime( &currenttime);
time_Aadd( &next_garco, &currenttime, &garco_interval);
m_server_status = PWR__SRUN;
for (;;) {
memset( &get, 0, sizeof(get));
mp = qcom_Get(&sts, &qid, &get, tmo);
......@@ -336,9 +386,11 @@ int sev_server::mainloop()
case sev_cMsgClass:
switch ( get.type.s) {
case sev_eMsgType_NodeUp:
errh_Info("Node up %s", cdh_NodeIdToString( 0, get.reply.nid, 0, 0));
request_items( get.reply.nid);
break;
case sev_eMsgType_HistItems:
errh_Info("Itemlist received %s", cdh_NodeIdToString( 0, get.reply.nid, 0, 0));
check_histitems( (sev_sMsgHistItems *) mp, get.size);
break;
case sev_eMsgType_HistDataStore:
......@@ -353,6 +405,9 @@ int sev_server::mainloop()
case sev_eMsgType_HistItemDelete:
delete_item( get.reply, (sev_sMsgHistItemDelete *) mp);
break;
case sev_eMsgType_ServerStatusRequest:
send_server_status( get.reply);
break;
default: ;
}
break;
......@@ -472,7 +527,7 @@ int sev_server::send_histdata( qcom_sQid tgt, sev_sMsgHistDataGetRequest *rmsg,
endtime = net_NetTimeToTime( &rmsg->EndTime);
m_db->get_values( &m_sts, rmsg->Oid, m_db->m_items[idx].options, m_db->m_items[idx].deadband,
rmsg->AName, m_db->m_items[idx].attr[0].type, m_db->m_items[idx].attr[0].size,
m_db->m_items[idx].scantime,
m_db->m_items[idx].scantime, &m_db->m_items[idx].creatime,
&starttime, &endtime, rmsg->NumPoints, &tbuf, &vbuf, &rows);
}
if ( ODD(m_sts))
......
......@@ -68,12 +68,13 @@ class sev_item_key {
class sev_server {
public:
sev_server() : m_msg_id(0) {}
sev_server() : m_server_status(0), m_msg_id(0) {}
typedef map<sev_refid, unsigned int>::iterator iterator_refid;
typedef map<sev_item_key, unsigned int>::iterator iterator_item_key;
pwr_tStatus m_sts;
pwr_tStatus m_server_status;
vector<sev_node> m_nodes;
map<sev_refid, unsigned int> m_refid;
map<sev_item_key, unsigned int> m_item_key;
......@@ -89,6 +90,7 @@ class sev_server {
int receive_histdata( sev_sMsgHistDataStore *msg, unsigned int size);
int send_histdata( qcom_sQid tgt, sev_sMsgHistDataGetRequest *msg, unsigned int size);
int send_itemlist( qcom_sQid tgt);
int send_server_status( qcom_sQid tgt);
int delete_item( qcom_sQid tgt, sev_sMsgHistItemDelete *rmsg);
void garbage_collector();
};
......
......@@ -48,9 +48,9 @@ XttTbl::~XttTbl()
}
XttTbl::XttTbl( void *xn_parent_ctx, sevcli_tCtx xn_sevcli) :
parent_ctx(xn_parent_ctx), sevcli(xn_sevcli), command_open(0), close_cb(0),
parent_ctx(xn_parent_ctx), sevcli(xn_sevcli), cologin(0), command_open(0), close_cb(0),
base_priv(pwr_mPrv_System), priv(pwr_mPrv_System), verify(0), ccm_func_registred(0),
quiet(0)
wow(0), quiet(0)
{
char default_priv[80];
......
......@@ -38,7 +38,8 @@ class sev_attr {
class sev_item {
public:
sev_item() : deadband_active(0), last_id(0), first_storage(1), deleted(0)
sev_item() : deadband_active(0), last_id(0), first_storage(1), status(0), logged_status(0),
deleted(0)
{ memset( old_value, 0, sizeof(old_value));}
unsigned int id;
char tablename[256];
......@@ -58,6 +59,8 @@ class sev_item {
int first_storage;
unsigned int attrnum;
sev_attr attr[1];
pwr_tStatus status;
pwr_tStatus logged_status;
int deleted;
};
......@@ -83,7 +86,7 @@ class sev_db {
pwr_tTime time, void *buf, unsigned int size) { return 0;}
virtual int get_values( pwr_tStatus *sts, pwr_tOid oid, pwr_tMask options, float deadband,
char *aname, pwr_eType type,
unsigned int size, pwr_tFloat32 scantime, pwr_tTime *starttime,
unsigned int size, pwr_tFloat32 scantime, pwr_tTime *creatime, pwr_tTime *starttime,
pwr_tTime *endtime, int maxsize, pwr_tTime **tbuf, void **vbuf,
unsigned int *bsize) { return 0;}
virtual int get_items( pwr_tStatus *sts) { return 0;}
......
......@@ -35,6 +35,7 @@
#include "rt_load.h"
#include "sev_dbms.h"
#include "rt_sev_msg.h"
#include "rt_errh.h"
char sev_dbms_env::m_systemName[40];
......@@ -833,8 +834,14 @@ int sev_dbms::store_value( pwr_tStatus *sts, int item_idx, int attr_idx,
}
int rc = mysql_query( m_env->con(), query);
if (rc) {
printf( "Store value: %s\n", mysql_error(m_env->con()));
// printf( "Store value: %s \"%s\"\n", mysql_error(m_env->con()), query);
*sts = SEV__DBERROR;
m_items[item_idx].status = *sts;
if ( m_items[item_idx].status != m_items[item_idx].logged_status) {
m_items[item_idx].logged_status = m_items[item_idx].status;
errh_Error( "Database store error: %s, table: %s object: %s",
mysql_error(m_env->con()), m_items[item_idx].tablename, m_items[item_idx].oname);
}
return 0;
}
if ( m_items[item_idx].options & pwr_mSevOptionsMask_ReadOptimized)
......@@ -872,19 +879,27 @@ int sev_dbms::store_value( pwr_tStatus *sts, int item_idx, int attr_idx,
int rc = mysql_query( m_env->con(), query);
if (rc) {
printf( "Update value: %s\n", mysql_error(m_env->con()));
// printf( "Update value: %s\n", mysql_error(m_env->con()));
*sts = SEV__DBERROR;
m_items[item_idx].status = *sts;
if ( m_items[item_idx].status != m_items[item_idx].logged_status) {
m_items[item_idx].logged_status = m_items[item_idx].status;
errh_Error( "Database update error: %s, table: %s object: %s",
mysql_error(m_env->con()), m_items[item_idx].tablename, m_items[item_idx].oname);
}
return 0;
}
}
*sts = SEV__SUCCESS;
m_items[item_idx].status = *sts;
m_items[item_idx].logged_status = 1;
return 1;
}
int sev_dbms::get_values( pwr_tStatus *sts, pwr_tOid oid, pwr_tMask options, float deadband,
char *aname, pwr_eType type,
unsigned int size, pwr_tFloat32 scantime,
unsigned int size, pwr_tFloat32 scantime, pwr_tTime *creatime,
pwr_tTime *starttime, pwr_tTime *endtime,
int maxsize, pwr_tTime **tbuf, void **vbuf, unsigned int *bsize)
{
......@@ -941,8 +956,8 @@ int sev_dbms::get_values( pwr_tStatus *sts, pwr_tOid oid, pwr_tMask options, flo
timestr_to_time( row[11], &create_time);
timestr_to_time( row[12], &update_time);
if ( time_Acomp( &create_time, &stime) == 1)
stime = create_time;
if ( time_Acomp( creatime, &stime) == 1)
stime = *creatime;
if ( time_Acomp( &etime, &update_time) == 1)
etime = update_time;
......
......@@ -117,7 +117,8 @@ class sev_dbms : public sev_db {
int store_value( pwr_tStatus *sts, int item_idx, int attr_idx,
pwr_tTime time, void *buf, unsigned int size);
int get_values( pwr_tStatus *sts, pwr_tOid oid, pwr_tMask options, float deadband, char *aname,
pwr_eType type, unsigned int size, pwr_tFloat32 scantime, pwr_tTime *starttime,
pwr_eType type, unsigned int size, pwr_tFloat32 scantime, pwr_tTime *creatime,
pwr_tTime *starttime,
pwr_tTime *endtime, int maxsize, pwr_tTime **tbuf, void **vbuf, unsigned int *bsize);
int delete_old_data( pwr_tStatus *sts, pwr_tOid oid, char *aname,
pwr_tMask options, pwr_tTime limit);
......
......@@ -29,8 +29,8 @@
#include "rt_qcom_msg.h"
#include "rt_ini_event.h"
#include "rt_errh.h"
#include "rt_sevhistmon.h"
#include "rt_sev_net.h"
#include "rt_sevhistmon.h"
#include "rt_sev_msg.h"
#include "rt_pwr_msg.h"
......@@ -357,6 +357,12 @@ void rt_sevhistmon::set_status()
{
pwr_tStatus sts = m_server_status;
for ( unsigned int i = 0; i < m_nodes.size(); i++) {
if ( m_nodes[i].connected && m_nodes[i].status != 0 &&
errh_Severity( m_nodes[i].status) > errh_Severity( sts))
sts = m_nodes[i].status;
}
for ( unsigned int i = 0; i < m_hs.size(); i++) {
if ( EVEN( m_hs[i].threadp->Status) &&
errh_Severity( m_hs [i].threadp->Status) > errh_Severity( sts)) {
......@@ -438,6 +444,66 @@ bool rt_sevhistmon::send_connect( pwr_tNid nid, pwr_tStatus *sts)
return ODD(*sts);
}
bool rt_sevhistmon::send_server_status_request( pwr_tStatus *sts)
{
int stime;
float scantime = 30;
pwr_tStatus send_sts;
*sts = SEV__SUCCESS;
stime = int(scantime / m_scantime + 0.5);
if ( !stime || m_loopcnt % stime != 0)
return false;
for ( unsigned int i = 0; i < m_nodes.size(); i++) {
if ( m_nodes[i].connected) {
send_server_status_request( m_nodes[i].nid, &send_sts);
if ( EVEN(send_sts))
*sts = send_sts;
}
}
return true;
}
bool rt_sevhistmon::send_server_status_request( pwr_tNid nid, pwr_tStatus *sts)
{
sev_sMsgAny *msg;
qcom_sQid tgt;
qcom_sPut put;
pwr_tStatus lsts;
tgt.nid = nid;
tgt.qix = sev_eProcSevServer;
put.reply.nid = m_nodes[0].nid;
put.reply.qix = sev_eProcSevClient;
put.type.b = (qcom_eBtype) sev_cMsgClass;
put.type.s = (qcom_eStype) sev_eMsgType_ServerStatusRequest;
put.msg_id = m_msg_id++;
put.size = sizeof(*msg);
msg = (sev_sMsgAny *) qcom_Alloc(&lsts, put.size);
put.data = msg;
msg->Type = sev_eMsgType_NodeUp;
if ( !qcom_Put( sts, &tgt, &put)) {
qcom_Free( &lsts, put.data);
}
return ODD(*sts);
}
void rt_sevhistmon::receive_server_status( sev_sMsgServerStatus *msg, pwr_tNid nid)
{
for ( unsigned int i = 0; i < m_nodes.size(); i++) {
if ( nid == m_nodes[i].nid) {
m_nodes[i].status = msg->Status;
break;
}
}
}
int rt_sevhistmon::send_itemlist( pwr_tNid nid)
{
int item_cnt = 0;
......@@ -560,6 +626,7 @@ int rt_sevhistmon::mainloop()
if ( sts == QCOM__TMO || !mp) {
m_loopcnt++;
send_data();
send_server_status_request( &sts);
continue;
}
......@@ -570,6 +637,9 @@ int rt_sevhistmon::mainloop()
case sev_eMsgType_HistItemsRequest:
send_itemlist( get.sender.nid);
break;
case sev_eMsgType_ServerStatus:
receive_server_status( (sev_sMsgServerStatus *) mp, get.sender.nid);
break;
default: ;
}
break;
......
......@@ -58,12 +58,13 @@ class sev_sevhistthread {
class sev_node {
public:
sev_node() : is_server(0), connected(0), ctime(0) {}
sev_node() : is_server(0), connected(0), ctime(0), status(0) {}
pwr_tNid nid;
char name[80];
int is_server;
int connected;
double ctime;
pwr_tStatus status;
};
class rt_sevhistmon {
......@@ -94,6 +95,9 @@ class rt_sevhistmon {
int connect();
int retry_connect();
bool send_connect( pwr_tNid nid, pwr_tStatus *sts);
bool send_server_status_request( pwr_tStatus *sts);
bool send_server_status_request( pwr_tNid nid, pwr_tStatus *sts);
void receive_server_status( sev_sMsgServerStatus *msg, pwr_tNid nid);
int send_itemlist( pwr_tNid nid);
int send_data();
};
......
......@@ -40,7 +40,9 @@ typedef enum {
sev_eMsgType_HistDataGetRequest,
sev_eMsgType_HistDataGet,
sev_eMsgType_HistItemDelete,
sev_eMsgType_HistItemStatus
sev_eMsgType_HistItemStatus,
sev_eMsgType_ServerStatusRequest,
sev_eMsgType_ServerStatus
} sev_eMsgType;
typedef struct {
......@@ -124,6 +126,11 @@ typedef struct {
pwr_tStatus Status;
} sev_sMsgHistItemStatus;
typedef struct {
sev_eMsgType Type;
pwr_tStatus Status;
} sev_sMsgServerStatus;
#ifdef __cplusplus
}
#endif
......
......@@ -189,7 +189,7 @@ int sevcli_get_itemdata( pwr_tStatus *sts, sevcli_tCtx ctx, pwr_tOid oid,
sev_sMsgHistDataGetRequest *msg;
qcom_sQid tgt;
qcom_sPut put;
int tmo = 10000;
int tmo = 30000;
qcom_sGet get;
pwr_tStatus lsts;
......@@ -217,13 +217,20 @@ int sevcli_get_itemdata( pwr_tStatus *sts, sevcli_tCtx ctx, pwr_tOid oid,
msg->EndTime = net_TimeToNetTime( &endtime);
msg->NumPoints = numpoints;
// Empty queue
sev_sMsgHistDataGet *rmsg;
for (;;) {
rmsg = (sev_sMsgHistDataGet *) qcom_Get(sts, &ctx->qid, &get, 0);
if ( !rmsg)
break;
}
if ( !qcom_Put( sts, &tgt, &put)) {
qcom_Free( &lsts, put.data);
return 0;
}
sev_sMsgHistDataGet *rmsg;
memset( &get, 0, sizeof(get));
for (;;) {
......
......@@ -52,7 +52,7 @@ XttSevHist::XttSevHist( void *parent_ctx,
sevcli_tCtx xn_scctx,
int *sts) :
xnav(parent_ctx), gcd(0), curve(0), rows(0), vsize(0), timerid(0), close_cb(0), help_cb(0),
first_scan(1), scctx(xn_scctx), oid(xn_oid[0])
first_scan(1), scctx(xn_scctx), oid(xn_oid[0]), time_low_old(0), time_high_old(0)
{
strncpy( aname, xn_aname[0], sizeof(aname));
......@@ -207,6 +207,9 @@ void XttSevHist::sevhist_higher_res_cb( void *ctx)
}
sevhist->get_data( &sts, t_low, t_high);
sevhist->time_low_old = 0;
sevhist->time_high_old = 0;
}
void XttSevHist::sevhist_lower_res_cb( void *ctx)
......@@ -225,6 +228,13 @@ void XttSevHist::sevhist_lower_res_cb( void *ctx)
5 * (sevhist->gcd->max_value_axis[0] - sevhist->gcd->min_value_axis[0]));
t_high.tv_nsec = 0;
if ( t_low.tv_sec == sevhist->time_low_old && t_high.tv_sec == sevhist->time_high_old) {
t_low.tv_sec = int( sevhist->gcd->min_value_axis[0] -
25 * (sevhist->gcd->max_value_axis[0] - sevhist->gcd->min_value_axis[0]));
t_high.tv_sec = int( sevhist->gcd->max_value_axis[0] +
25 * (sevhist->gcd->max_value_axis[0] - sevhist->gcd->min_value_axis[0]));
}
{
char s1[40], s2[40];
time_AtoAscii( &t_low, time_eFormat_NumDateAndTime, s1, sizeof(s1));
......@@ -233,6 +243,8 @@ void XttSevHist::sevhist_lower_res_cb( void *ctx)
printf( "Low: %s, High: %s\n", s1, s2);
}
sevhist->get_data( &sts, t_low, t_high);
sevhist->time_low_old = t_low.tv_sec;
sevhist->time_high_old = t_high.tv_sec;
}
void XttSevHist::sevhist_help_cb( void *ctx)
......
......@@ -71,6 +71,8 @@ class XttSevHist {
pwr_tOName aname;
pwr_tOid oid;
CoWow *wow;
long int time_low_old;
long int time_high_old;
//! Constructor
XttSevHist( void *xn_parent_ctx,
......
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 to comment