- Version number changed to 0.1.14-dev
authorVictor Kirhenshtein <victor@netxms.org>
Tue, 8 Feb 2005 21:49:33 +0000 (21:49 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Tue, 8 Feb 2005 21:49:33 +0000 (21:49 +0000)
- Added method Node::CreateAgentConnection()
- Further development of agent upgrade code

configure.ac
include/netxms-version.h
include/nms_cscp.h
src/server/core/node.cpp
src/server/core/package.cpp
src/server/core/session.cpp
src/server/include/nms_objects.h
src/server/include/nms_pkg.h
src/server/libnxsrv/db.cpp

index 1e1cc9c..2cc2a7d 100644 (file)
@@ -1,9 +1,9 @@
-# $Id: configure.ac,v 1.63 2005-02-08 09:41:32 victor Exp $
+# $Id: configure.ac,v 1.64 2005-02-08 21:49:32 victor Exp $
 #
 # Process this file with autoconf to produce a configure script.
 #
 
-AC_INIT([NetXMS], [0.1.13], [NetXMS Team <bugs@netxms.org>])
+AC_INIT([NetXMS], [0.1.14], [NetXMS Team <bugs@netxms.org>])
 AC_CONFIG_AUX_DIR([config])
 AM_CONFIG_HEADER([config.h])
 AM_INIT_AUTOMAKE
index 6be8525..23c727d 100644 (file)
@@ -30,8 +30,8 @@
 
 #define NETXMS_VERSION_MAJOR      0
 #define NETXMS_VERSION_MINOR      1
-#define NETXMS_VERSION_BUILD      13
-#define NETXMS_VERSION_STRING     _T("0.1.13")
+#define NETXMS_VERSION_BUILD      14
+#define NETXMS_VERSION_STRING     _T("0.1.14-dev")
 
 
 #endif
index 5080077..3b88671 100644 (file)
@@ -430,6 +430,7 @@ typedef struct
 #define VID_NUM_OBJECTS             ((DWORD)138)
 #define VID_OBJECT_LIST             ((DWORD)139)
 #define VID_DEPLOYMENT_STATUS       ((DWORD)140)
+#define VID_ERROR_MESSAGE           ((DWORD)141)
 
 // Variable ranges for object's ACL
 #define VID_ACL_USER_BASE           ((DWORD)0x00001000)
index 590d81d..cd08141 100644 (file)
@@ -1435,3 +1435,24 @@ void Node::CheckOSPFSupport(void)
       }
    }
 }
+
+
+//
+// Create ready to use agent connection
+//
+
+AgentConnection *Node::CreateAgentConnection(void)
+{
+   AgentConnection *pConn;
+
+   if (!(g_dwFlags & NF_IS_NATIVE_AGENT))
+      return NULL;
+
+   pConn = new AgentConnection(m_dwIpAddr, m_wAgentPort, m_wAuthMethod, m_szSharedSecret);
+   if (!pConn->Connect())
+   {
+      delete pConn;
+      pConn = NULL;
+   }
+   return pConn;
+}
index 3eaff4a..bfa0d3b 100644 (file)
@@ -146,8 +146,9 @@ static THREAD_RESULT THREAD_CALL DeploymentThread(void *pArg)
    DT_STARTUP_INFO *pStartup = (DT_STARTUP_INFO *)pArg;
    Node *pNode;
    CSCPMessage msg;
-   BOOL bSuccess = TRUE;
-   //AgentConnection *pAgentConn;
+   BOOL bSuccess = FALSE;
+   AgentConnection *pAgentConn;
+   char *pszErrorMsg = "";
 
    // Prepare notification message
    msg.SetCode(CMD_INSTALLER_INFO);
@@ -161,16 +162,57 @@ static THREAD_RESULT THREAD_CALL DeploymentThread(void *pArg)
          break;   // Queue is empty, exit
 
       // Create agent connection
+      pAgentConn = pNode->CreateAgentConnection();
+      if (pAgentConn != NULL)
+      {
+         BOOL bCheckOK = FALSE;
+         char szBuffer[256];
 
-      // Change deployment status to "File Transfer"
-      msg.SetVariable(VID_OBJECT_ID, pNode->Id());
-      msg.SetVariable(VID_DEPLOYMENT_STATUS, (WORD)DEPLOYMENT_STATUS_TRANSFER);
-      pStartup->pSession->SendMessage(&msg);
+         // Check if package can be deployed on target node
+         if (!stricmp(pStartup->szPlatform, "src"))
+         {
+            // Source package, check if target node
+            // supports source packages
+            if (pAgentConn->GetParameter("Agent.SourcePackageSupport", 32, szBuffer) == ERR_SUCCESS)
+            {
+               bCheckOK = (strtol(szBuffer, NULL, 0) != 0);
+            }
+         }
+         else
+         {
+            // Binary package, check target platform
+            if (pAgentConn->GetParameter("System.PlatformName", 256, szBuffer) == ERR_SUCCESS)
+            {
+               bCheckOK = !stricmp(szBuffer, pStartup->szPlatform);
+            }
+         }
+
+         if (bCheckOK)
+         {
+            // Change deployment status to "File Transfer"
+            msg.SetVariable(VID_OBJECT_ID, pNode->Id());
+            msg.SetVariable(VID_DEPLOYMENT_STATUS, (WORD)DEPLOYMENT_STATUS_TRANSFER);
+            pStartup->pSession->SendMessage(&msg);
+
+            //!pAgentConn->UploadFile(szBuffer);
+         }
+         else
+         {
+            pszErrorMsg = "Package is not compatible with target machine";
+         }
+
+         delete pAgentConn;
+      }
+      else
+      {
+         pszErrorMsg = "Unable to connect to agent";
+      }
 
       // Finish node processing
       msg.SetVariable(VID_OBJECT_ID, pNode->Id());
       msg.SetVariable(VID_DEPLOYMENT_STATUS, 
          bSuccess ? (WORD)DEPLOYMENT_STATUS_COMPLETED : (WORD)DEPLOYMENT_STATUS_FAILED);
+      msg.SetVariable(VID_ERROR_MESSAGE, pszErrorMsg);
       pStartup->pSession->SendMessage(&msg);
       pNode->DecRefCount();
    }
index d029db9..37a9eaa 100644 (file)
@@ -3914,6 +3914,8 @@ void ClientSession::DeployPackage(CSCPMessage *pRequest)
    DWORD i, j, dwNumObjects, *pdwObjectList, dwNumNodes, dwPkgId;
    Node **ppNodeList;
    NetObj *pObject;
+   TCHAR szQuery[256], szPkgFile[MAX_PATH], szPlatform[MAX_PLATFORM_NAME_LEN];
+   DB_RESULT hResult;
    BOOL bSuccess = TRUE;
    MUTEX hMutex;
 
@@ -3930,51 +3932,65 @@ void ClientSession::DeployPackage(CSCPMessage *pRequest)
       dwPkgId = pRequest->GetVariableLong(VID_PACKAGE_ID);
       if (IsValidPackageId(dwPkgId))
       {
-         // Create list of nodes to be upgraded
-         dwNumObjects = pRequest->GetVariableLong(VID_NUM_OBJECTS);
-         pdwObjectList = (DWORD *)malloc(sizeof(DWORD) * dwNumObjects);
-         pRequest->GetVariableInt32Array(VID_OBJECT_LIST, dwNumObjects, pdwObjectList);
-         for(i = 0; i < dwNumObjects; i++)
+         // Read package information
+         _sntprintf(szQuery, 256, _T("SELECT platform,pkg_file FROM agent_pkg WHERE pkg_id=%ld"), dwPkgId);
+         hResult = DBSelect(g_hCoreDB, szQuery);
+         if ((hResult != NULL) && (DBGetNumRows(hResult) > 0))
          {
-            pObject = FindObjectById(pdwObjectList[i]);
-            if (pObject != NULL)
+            _tcsncpy(szPlatform, DBGetField(hResult, 0, 0), MAX_PLATFORM_NAME_LEN);
+            _tcsncpy(szPkgFile, DBGetField(hResult, 0, 1), MAX_PATH);
+
+            // Create list of nodes to be upgraded
+            dwNumObjects = pRequest->GetVariableLong(VID_NUM_OBJECTS);
+            pdwObjectList = (DWORD *)malloc(sizeof(DWORD) * dwNumObjects);
+            pRequest->GetVariableInt32Array(VID_OBJECT_LIST, dwNumObjects, pdwObjectList);
+            for(i = 0; i < dwNumObjects; i++)
             {
-               if (pObject->CheckAccessRights(m_dwUserId, OBJECT_ACCESS_READ))
+               pObject = FindObjectById(pdwObjectList[i]);
+               if (pObject != NULL)
                {
-                  if (pObject->Type() == OBJECT_NODE)
+                  if (pObject->CheckAccessRights(m_dwUserId, OBJECT_ACCESS_READ))
                   {
-                     // Check if this node already in the list
-                     for(j = 0; j < dwNumNodes; j++)
-                        if (ppNodeList[j]->Id() == pdwObjectList[i])
-                           break;
-                     if (j == dwNumNodes)
+                     if (pObject->Type() == OBJECT_NODE)
                      {
-                        pObject->IncRefCount();
-                        ppNodeList = (Node **)realloc(ppNodeList, sizeof(Node *) * (dwNumNodes + 1));
-                        ppNodeList[dwNumNodes] = (Node *)pObject;
-                        dwNumNodes++;
+                        // Check if this node already in the list
+                        for(j = 0; j < dwNumNodes; j++)
+                           if (ppNodeList[j]->Id() == pdwObjectList[i])
+                              break;
+                        if (j == dwNumNodes)
+                        {
+                           pObject->IncRefCount();
+                           ppNodeList = (Node **)realloc(ppNodeList, sizeof(Node *) * (dwNumNodes + 1));
+                           ppNodeList[dwNumNodes] = (Node *)pObject;
+                           dwNumNodes++;
+                        }
+                     }
+                     else
+                     {
+                        pObject->AddChildNodesToList(&dwNumNodes, &ppNodeList, m_dwUserId);
                      }
                   }
                   else
                   {
-                     pObject->AddChildNodesToList(&dwNumNodes, &ppNodeList, m_dwUserId);
+                     msg.SetVariable(VID_RCC, RCC_ACCESS_DENIED);
+                     bSuccess = FALSE;
+                     break;
                   }
                }
                else
                {
-                  msg.SetVariable(VID_RCC, RCC_ACCESS_DENIED);
+                  msg.SetVariable(VID_RCC, RCC_INVALID_OBJECT_ID);
                   bSuccess = FALSE;
                   break;
                }
             }
-            else
-            {
-               msg.SetVariable(VID_RCC, RCC_INVALID_OBJECT_ID);
-               bSuccess = FALSE;
-               break;
-            }
+            safe_free(pdwObjectList);
+         }
+         else
+         {
+            msg.SetVariable(VID_RCC, RCC_DB_FAILURE);
+            bSuccess = FALSE;
          }
-         safe_free(pdwObjectList);
       }
       else
       {
@@ -3996,6 +4012,9 @@ void ClientSession::DeployPackage(CSCPMessage *pRequest)
          pInfo->pSession = this;
          pInfo->mutex = hMutex;
          pInfo->dwRqId = pRequest->GetId();
+         pInfo->dwPackageId = dwPkgId;
+         _tcscpy(pInfo->szPkgFile, szPkgFile);
+         _tcscpy(pInfo->szPlatform, szPlatform);
 
          ThreadCreate(DeploymentManager, 0, pInfo);
          msg.SetVariable(VID_RCC, RCC_SUCCESS);
index 5e7faed..dcbb69e 100644 (file)
@@ -431,6 +431,8 @@ public:
    void QueueItemsForPolling(Queue *pPollerQueue);
    DWORD GetItemForClient(int iOrigin, const char *pszParam, char *pszBuffer, DWORD dwBufSize);
 
+   AgentConnection *CreateAgentConnection(void);
+
    virtual void CreateMessage(CSCPMessage *pMsg);
    virtual DWORD ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
    void WriteParamListToMessage(CSCPMessage *pMsg);
index c28c431..550d7ba 100644 (file)
@@ -34,7 +34,10 @@ typedef struct
    Node **ppNodeList;
    ClientSession *pSession;
    DWORD dwRqId;
+   DWORD dwPackageId;
    Queue *pQueue;  // Used internally by deployment manager
+   TCHAR szPlatform[MAX_PLATFORM_NAME_LEN];
+   TCHAR szPkgFile[MAX_PATH];
 } DT_STARTUP_INFO;
 
 
index e295e74..aaaab24 100644 (file)
@@ -304,6 +304,8 @@ DWORD LIBNXSRV_EXPORTABLE DBGetFieldIPAddr(DB_RESULT hResult, int iRow, int iCol
 
 int LIBNXSRV_EXPORTABLE DBGetNumRows(DB_RESULT hResult)
 {
+   if (hResult == NULL)
+      return 0;
    return m_fpDrvGetNumRows(hResult);
 }
 
@@ -314,7 +316,8 @@ int LIBNXSRV_EXPORTABLE DBGetNumRows(DB_RESULT hResult)
 
 void LIBNXSRV_EXPORTABLE DBFreeResult(DB_RESULT hResult)
 {
-   m_fpDrvFreeResult(hResult);
+   if (hResult != NULL)
+      m_fpDrvFreeResult(hResult);
 }