- few SLM inconsistencies fixed
authorAlex Kalimulin <alex@netxms.org>
Mon, 29 Aug 2011 22:20:46 +0000 (22:20 +0000)
committerAlex Kalimulin <alex@netxms.org>
Mon, 29 Aug 2011 22:20:46 +0000 (22:20 +0000)
src/server/core/bizservice.cpp
src/server/core/nodelink.cpp
src/server/core/nxcore.vcproj
src/server/core/slm.cpp [deleted file]
src/server/include/nms_objects.h

index be88b13..4f4a3e9 100644 (file)
@@ -257,6 +257,8 @@ void BizService::poll( ClientSession *pSession, DWORD dwRqId, int nPoller )
        {
                if (m_pChildList[i]->Type() == OBJECT_SLMCHECK)
                        ((SlmCheck*)m_pChildList[i])->execute();
+               else if (m_pChildList[i]->Type() == OBJECT_NODELINK)
+                       ((NodeLink*)m_pChildList[i])->execute();
        }
 
        // Set the status based on what the kids' been up to
index 6dcd0c1..b87df19 100644 (file)
@@ -33,7 +33,7 @@ NodeLink::NodeLink()
 :Container()
 {
        _tcscpy(m_szName, _T("Default"));
-       m_node = NULL;
+       m_nodeId = 0;
 }
 
 
@@ -44,7 +44,7 @@ NodeLink::NodeLink()
 NodeLink::NodeLink(const TCHAR *name)
 :Container(name, 0)
 {
-       m_node = NULL;
+       m_nodeId = 0;
 }
 
 
@@ -54,12 +54,42 @@ NodeLink::NodeLink(const TCHAR *name)
 
 NodeLink::~NodeLink()
 {
-       safe_delete_and_null(m_node);
 }
 
+//
+// Calculate status for compound object based on childs status
+// ! Copy/paste from BizService::calculateCompoundStatus()
+//
+
 void NodeLink::calculateCompoundStatus(BOOL bForcedRecalc /*= FALSE*/)
 {
-       m_iStatus = STATUS_NORMAL;
+       int i, iCount, iMostCriticalStatus;
+       int iOldStatus = m_iStatus;
+
+       // Calculate own status by selecting the most critical status of the kids
+       LockChildList(FALSE);
+       for(i = 0, iCount = 0, iMostCriticalStatus = -1; i < int(m_dwChildCount); i++)
+       {
+               int iChildStatus = m_pChildList[i]->Status();
+               if ((iChildStatus < STATUS_UNKNOWN) &&
+                       (iChildStatus > iMostCriticalStatus))
+               {
+                       iMostCriticalStatus = iChildStatus;
+                       iCount++;
+               }
+       }
+       m_iStatus = (iCount > 0) ? iMostCriticalStatus : STATUS_UNKNOWN;
+       UnlockChildList();
+
+       // Cause parent object(s) to recalculate it's status
+       if ((iOldStatus != m_iStatus) || bForcedRecalc)
+       {
+               LockParentList(FALSE);
+               for(i = 0; i < int(m_dwParentCount); i++)
+                       m_pParentList[i]->calculateCompoundStatus();
+               UnlockParentList();
+               Modify();   /* LOCK? */
+       }
 }
 
 //
@@ -69,7 +99,6 @@ void NodeLink::calculateCompoundStatus(BOOL bForcedRecalc /*= FALSE*/)
 BOOL NodeLink::CreateFromDB(DWORD id)
 {
        const int script_length = 1024;
-       DWORD nodeId;
        m_dwId = id;
 
        if (!loadCommonProperties())
@@ -98,11 +127,13 @@ BOOL NodeLink::CreateFromDB(DWORD id)
                return FALSE;
        }
 
-       nodeId  = DBGetFieldLong(hResult, 0, 0);
-       if (nodeId > 0)
+       m_nodeId        = DBGetFieldLong(hResult, 0, 0);
+       if (m_nodeId <= 0)
        {
-               m_node = new Node;
-               m_node->CreateFromDB(nodeId);
+               DBFreeResult(hResult);
+               DBFreeStatement(hStmt);
+               DbgPrintf(4, _T("Cannot load nodelink object %ld - node id is missing"), (long)m_dwId);
+               return FALSE;
        }
 
        DBFreeResult(hResult);
@@ -149,7 +180,7 @@ BOOL NodeLink::SaveToDB(DB_HANDLE hdb)
                // DbgPrintf(4, _T("Cannot prepare %s from node_links"), bNewObject ? _T("insert") : _T("update"));
                return FALSE;
        }
-       DBBind(hStmt, 1, DB_SQLTYPE_INTEGER, m_node == NULL ? 0 : m_node->Id());
+       DBBind(hStmt, 1, DB_SQLTYPE_INTEGER, m_nodeId);
        DBBind(hStmt, 2, DB_SQLTYPE_INTEGER, m_dwId);
        if (!DBExecute(hStmt))
        {
@@ -197,7 +228,7 @@ BOOL NodeLink::DeleteFromDB()
 void NodeLink::CreateMessage(CSCPMessage *pMsg)
 {
        NetObj::CreateMessage(pMsg);
-       pMsg->SetVariable(VID_NODELINK_NODE_ID, m_node->Id());
+       pMsg->SetVariable(VID_NODELINK_NODE_ID, m_nodeId);
 }
 
 
@@ -212,10 +243,25 @@ DWORD NodeLink::ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked)
 
        if (pRequest->IsVariableExist(VID_NODELINK_NODE_ID))
        {
-               safe_delete_and_null(m_node);
-               m_node = new Node;
-               m_node->CreateFromDB(pRequest->GetVariableLong(VID_NODELINK_NODE_ID));
+               m_nodeId = pRequest->GetVariableLong(VID_NODELINK_NODE_ID);
        }
 
        return NetObj::ModifyFromMessage(pRequest, TRUE);
 }
+
+//
+// Execute underlying checks for this node link
+//
+
+void NodeLink::execute()
+{
+       DbgPrintf(9, _T("NodeLink::execute() started for id %ld"), long(m_dwId));
+
+       for (int i = 0; i < int(m_dwChildCount); i++)
+       {
+               if (m_pChildList[i]->Type() == OBJECT_SLMCHECK)
+                       ((SlmCheck*)m_pChildList[i])->execute();
+       }
+
+       DbgPrintf(9, _T("NodeLink::execute() finished for id %ld"), long(m_dwId));
+}
\ No newline at end of file
index 2453f1d..976f9a6 100644 (file)
                                RelativePath=".\situation.cpp"\r
                                >\r
                        </File>\r
-                       <File\r
-                               RelativePath=".\slm.cpp"\r
-                               >\r
-                       </File>\r
                        <File\r
                                RelativePath=".\slmcheck.cpp"\r
                                >\r
diff --git a/src/server/core/slm.cpp b/src/server/core/slm.cpp
deleted file mode 100644 (file)
index 4ff29d9..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/* 
-** NetXMS - Network Management System
-** Copyright (C) 2003-2011 NetXMS Team
-**
-** This program is free software; you can redistribute it and/or modify
-** it under the terms of the GNU General Public License as published by
-** the Free Software Foundation; either version 2 of the License, or
-** (at your option) any later version.
-**
-** This program is distributed in the hope that it will be useful,
-** but WITHOUT ANY WARRANTY; without even the implied warranty of
-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-** GNU General Public License for more details.
-**
-** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-**
-** File: slm.cpp
-**
-**/
-
-// MUST THIS FILE BE DELETED??
\ No newline at end of file
index 5218925..a39efb0 100644 (file)
@@ -1557,7 +1557,7 @@ public:
 class NXCORE_EXPORTABLE NodeLink : public Container
 {
 protected:
-       Node* m_node;
+       DWORD m_nodeId;
 
 public:
        NodeLink();
@@ -1573,6 +1573,8 @@ public:
 
        virtual void CreateMessage(CSCPMessage *pMsg);
        virtual DWORD ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
+
+       void execute();
 };
 
 //