implemented gui for moving nodes between zones; fixed bug in subnet binding checker
authorVictor Kirhenshtein <victor@netxms.org>
Fri, 29 Apr 2011 16:16:38 +0000 (16:16 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Fri, 29 Apr 2011 16:16:38 +0000 (16:16 +0000)
.gitattributes
src/java/netxms-eclipse/ObjectManager/plugin.xml
src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/actions/ChangeZone.java [new file with mode: 0644]
src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/dialogs/ZoneSelectionDialog.java [new file with mode: 0644]
src/java/netxms-eclipse/ObjectView/src/org/netxms/ui/eclipse/objectview/objecttabs/elements/GeneralInfo.java
src/server/core/node.cpp
src/server/include/nms_objects.h

index 3ac89d6..eb78736 100644 (file)
@@ -953,6 +953,7 @@ src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/ac
 src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/actions/AddClusterNode.java -text
 src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/actions/BindObject.java -text
 src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/actions/ChangeIpAddress.java -text
+src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/actions/ChangeZone.java -text
 src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/actions/ConfigurationPoll.java -text
 src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/actions/CreateContainer.java -text
 src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/actions/CreateNode.java -text
@@ -970,6 +971,7 @@ src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/di
 src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/dialogs/CreateNodeDialog.java -text
 src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/dialogs/CreateZoneDialog.java -text
 src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/dialogs/EnterIpAddressDialog.java -text
+src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/dialogs/ZoneSelectionDialog.java -text
 src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/propertypages/AccessControl.java -text
 src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/propertypages/AutoApply.java -text
 src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/propertypages/AutoBind.java -text
index e804b5a..b70af77 100644 (file)
       <objectContribution\r
             id="org.netxms.ui.eclipse.objectmanager.actions.popup.object.Node"\r
             objectClass="org.netxms.client.objects.Node">\r
+         <action\r
+               class="org.netxms.ui.eclipse.objectmanager.actions.ChangeZone"\r
+               enablesFor="1"\r
+               id="org.netxms.ui.eclipse.objectmanager.popupActions.ChangeZone_Node"\r
+               label="Change zone..."\r
+               menubarPath="objectmgmt">\r
+         </action>\r
          <action\r
                class="org.netxms.ui.eclipse.objectmanager.actions.ChangeIpAddress"\r
                enablesFor="1"\r
diff --git a/src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/actions/ChangeZone.java b/src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/actions/ChangeZone.java
new file mode 100644 (file)
index 0000000..a91a627
--- /dev/null
@@ -0,0 +1,115 @@
+/**\r
+ * NetXMS - open source network management system\r
+ * Copyright (C) 2003-2010 Victor Kirhenshtein\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ */\r
+package org.netxms.ui.eclipse.objectmanager.actions;\r
+\r
+import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.eclipse.jface.action.IAction;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.jface.viewers.IStructuredSelection;\r
+import org.eclipse.jface.window.Window;\r
+import org.eclipse.ui.IObjectActionDelegate;\r
+import org.eclipse.ui.IWorkbenchPart;\r
+import org.eclipse.ui.IWorkbenchWindow;\r
+import org.netxms.client.NXCSession;\r
+import org.netxms.client.objects.Node;\r
+import org.netxms.ui.eclipse.jobs.ConsoleJob;\r
+import org.netxms.ui.eclipse.objectmanager.Activator;\r
+import org.netxms.ui.eclipse.objectmanager.dialogs.ZoneSelectionDialog;\r
+import org.netxms.ui.eclipse.shared.ConsoleSharedData;\r
+\r
+/**\r
+ * Change IP address for node.\r
+ */\r
+public class ChangeZone implements IObjectActionDelegate\r
+{\r
+       private boolean zoningEnabled;\r
+       private IWorkbenchWindow window;\r
+       private IWorkbenchPart part;\r
+       private Node node;\r
+       \r
+       /**\r
+        * The constructor\r
+        */\r
+       public ChangeZone()\r
+       {\r
+               zoningEnabled = ((NXCSession)ConsoleSharedData.getSession()).isZoningEnabled();\r
+       }\r
+\r
+       /* (non-Javadoc)\r
+        * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)\r
+        */\r
+       @Override\r
+       public void setActivePart(IAction action, IWorkbenchPart targetPart)\r
+       {\r
+               part = targetPart;\r
+               window = targetPart.getSite().getWorkbenchWindow();\r
+       }\r
+\r
+       /* (non-Javadoc)\r
+        * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)\r
+        */\r
+       @Override\r
+       public void run(IAction action)\r
+       {\r
+               final ZoneSelectionDialog dlg = new ZoneSelectionDialog(window.getShell());\r
+               if (dlg.open() != Window.OK)\r
+                       return;\r
+\r
+               final NXCSession session = (NXCSession)ConsoleSharedData.getSession();\r
+               new ConsoleJob("Change zone for node " + node.getObjectName(), part, Activator.PLUGIN_ID, null) {\r
+                       @Override\r
+                       protected void runInternal(IProgressMonitor monitor) throws Exception\r
+                       {\r
+                               session.changeObjectZone(node.getObjectId(), dlg.getZoneId());\r
+                       }\r
+\r
+                       @Override\r
+                       protected String getErrorMessage()\r
+                       {\r
+                               return "Cannot change zone for node " + node.getObjectName();\r
+                       }\r
+               }.start();\r
+       }\r
+\r
+       /* (non-Javadoc)\r
+        * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)\r
+        */\r
+       @Override\r
+       public void selectionChanged(IAction action, ISelection selection)\r
+       {\r
+               if ((selection instanceof IStructuredSelection) && (((IStructuredSelection)selection).size() == 1))\r
+               {\r
+                       final Object obj = ((IStructuredSelection)selection).getFirstElement();\r
+                       if (obj instanceof Node)\r
+                       {\r
+                               node = (Node)obj;\r
+                       }\r
+                       else\r
+                       {\r
+                               node = null;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       node = null;\r
+               }\r
+\r
+               action.setEnabled((node != null) && zoningEnabled);\r
+       }\r
+}\r
diff --git a/src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/dialogs/ZoneSelectionDialog.java b/src/java/netxms-eclipse/ObjectManager/src/org/netxms/ui/eclipse/objectmanager/dialogs/ZoneSelectionDialog.java
new file mode 100644 (file)
index 0000000..019edfb
--- /dev/null
@@ -0,0 +1,119 @@
+/**\r
+ * NetXMS - open source network management system\r
+ * Copyright (C) 2003-2011 Victor Kirhenshtein\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ */\r
+package org.netxms.ui.eclipse.objectmanager.dialogs;\r
+\r
+import org.eclipse.jface.dialogs.Dialog;\r
+import org.eclipse.jface.dialogs.MessageDialog;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.layout.GridData;\r
+import org.eclipse.swt.layout.GridLayout;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Control;\r
+import org.eclipse.swt.widgets.Shell;\r
+import org.netxms.client.NXCSession;\r
+import org.netxms.client.objects.GenericObject;\r
+import org.netxms.client.objects.Zone;\r
+import org.netxms.ui.eclipse.objectbrowser.widgets.ObjectSelector;\r
+import org.netxms.ui.eclipse.shared.ConsoleSharedData;\r
+import org.netxms.ui.eclipse.tools.WidgetHelper;\r
+\r
+/**\r
+ * Dialog for entering IP address\r
+ *\r
+ */\r
+public class ZoneSelectionDialog extends Dialog\r
+{\r
+       private ObjectSelector objectSelector;\r
+       private long zoneId;\r
+       \r
+       /**\r
+        * Constructor\r
+        * \r
+        * @param parent Parent shell\r
+        */\r
+       public ZoneSelectionDialog(Shell parent)\r
+       {\r
+               super(parent);\r
+       }\r
+\r
+       /* (non-Javadoc)\r
+        * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)\r
+        */\r
+       @Override\r
+       protected void configureShell(Shell newShell)\r
+       {\r
+               super.configureShell(newShell);\r
+               newShell.setText("Select Zone");\r
+       }\r
+       \r
+       /* (non-Javadoc)\r
+        * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)\r
+        */\r
+       @Override\r
+       protected Control createDialogArea(Composite parent)\r
+       {\r
+               Composite dialogArea = (Composite)super.createDialogArea(parent);\r
+\r
+               GridLayout layout = new GridLayout();\r
+      layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;\r
+      layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;\r
+      dialogArea.setLayout(layout);\r
+\r
+      objectSelector = new ObjectSelector(dialogArea, SWT.NONE);\r
+      objectSelector.setLabel("Zone object");\r
+      objectSelector.setObjectClass(GenericObject.OBJECT_ZONE);\r
+      GridData gd = new GridData();\r
+      gd.horizontalAlignment = SWT.FILL;\r
+      gd.grabExcessHorizontalSpace = true;\r
+      gd.widthHint = 300;\r
+      objectSelector.setLayoutData(gd);\r
+      \r
+               return dialogArea;\r
+       }\r
+\r
+       /* (non-Javadoc)\r
+        * @see org.eclipse.jface.dialogs.Dialog#okPressed()\r
+        */\r
+       @Override\r
+       protected void okPressed()\r
+       {\r
+               long objectId = objectSelector.getObjectId();\r
+               if (objectId == 0)\r
+               {\r
+                       MessageDialog.openWarning(getShell(), "Warning", "Please select zone object!");\r
+                       return;\r
+               }\r
+               GenericObject object = ((NXCSession)ConsoleSharedData.getSession()).findObjectById(objectId);\r
+               if ((object == null) || !(object instanceof Zone))\r
+               {\r
+                       MessageDialog.openWarning(getShell(), "Warning", "Please select zone object!");\r
+                       return;\r
+               }\r
+               zoneId = ((Zone)object).getZoneId();\r
+               super.okPressed();\r
+       }\r
+\r
+       /**\r
+        * @return the zoneObjectId\r
+        */\r
+       public long getZoneId()\r
+       {\r
+               return zoneId;\r
+       }\r
+}\r
index 61e6b91..8b6f2ca 100644 (file)
@@ -24,6 +24,7 @@ import org.netxms.client.NXCSession;
 import org.netxms.client.objects.GenericObject;\r
 import org.netxms.client.objects.Interface;\r
 import org.netxms.client.objects.Node;\r
+import org.netxms.client.objects.Subnet;\r
 import org.netxms.client.objects.Zone;\r
 import org.netxms.ui.eclipse.console.resources.StatusDisplayInfo;\r
 import org.netxms.ui.eclipse.shared.ConsoleSharedData;\r
@@ -83,6 +84,11 @@ public class GeneralInfo extends TableElement
                                addPair("SNMP Object ID", node.getSnmpOID(), false);\r
                                addPair("Driver", node.getDriverName(), false);\r
                                break;\r
+                       case GenericObject.OBJECT_SUBNET:\r
+                               Subnet subnet = (Subnet)object;\r
+                               if (((NXCSession)ConsoleSharedData.getSession()).isZoningEnabled())\r
+                                       addPair("Zone ID", Long.toString(subnet.getZoneId()));\r
+                               break;\r
                        case GenericObject.OBJECT_ZONE:\r
                                Zone zone = (Zone)object;\r
                                addPair("Zone ID", Long.toString(zone.getZoneId()));\r
index ee5bc2f..bcae3be 100644 (file)
@@ -514,7 +514,7 @@ InterfaceList *Node::getInterfaceList()
    if (pIfList != NULL)
        {
                pIfList->removeLoopbacks();
-      CheckInterfaceNames(pIfList);
+      checkInterfaceNames(pIfList);
                addVrrpInterfaces(pIfList);
        }
 
@@ -847,7 +847,7 @@ void Node::createNewInterface(DWORD dwIpAddr, DWORD dwNetMask, const TCHAR *name
                                        NetObjInsert(pSubnet, TRUE);
                                        if (IsZoningEnabled())
                                        {
-                                               Zone *zone = (Zone *)g_idxZoneByGUID.get(m_zoneId);
+                                               Zone *zone = FindZoneByGUID(m_zoneId);
                                                if (zone != NULL)
                                                {
                                                        zone->addSubnet(pSubnet);
@@ -1767,7 +1767,7 @@ skip_snmp_checks:
                {
                        SendPollerMsg(dwRqId, _T("Node name is an IP address and need to be resolved\r\n"));
              SetPollerInfo(nPoller, _T("resolving name"));
-                       if (ResolveName(FALSE))
+                       if (resolveName(FALSE))
                        {
                                SendPollerMsg(dwRqId, POLLER_INFO _T("Node name resolved to %s\r\n"), m_szName);
                                bHasChanges = TRUE;
@@ -1783,7 +1783,7 @@ skip_snmp_checks:
                        {
                                SendPollerMsg(dwRqId, _T("Syncing node name with DNS\r\n"));
                      SetPollerInfo(nPoller, _T("resolving name"));
-                               if (ResolveName(TRUE))
+                               if (resolveName(TRUE))
                                {
                                        SendPollerMsg(dwRqId, POLLER_INFO _T("Node name resolved to %s\r\n"), m_szName);
                                        bHasChanges = TRUE;
@@ -2042,7 +2042,7 @@ BOOL Node::updateInterfaceConfiguration(DWORD dwRqId, DWORD dwNetMask)
          }
       }
 
-               CheckSubnetBinding(pIfList);
+               checkSubnetBinding(pIfList);
 
                delete pIfList;
    }
@@ -3579,7 +3579,7 @@ BOOL Node::CheckSNMPIntegerValue(SNMP_Transport *pTransport, const TCHAR *pszOID
 // Check and update if needed interface names
 //
 
-void Node::CheckInterfaceNames(InterfaceList *pIfList)
+void Node::checkInterfaceNames(InterfaceList *pIfList)
 {
    // Cut interface names to MAX_OBJECT_NAME and check for unnamed interfaces
    for(int i = 0; i < pIfList->getSize(); i++)
@@ -3687,7 +3687,7 @@ SNMP_SecurityContext *Node::getSnmpSecurityContext()
 // Resolve node's name
 //
 
-BOOL Node::ResolveName(BOOL useOnlyDNS)
+BOOL Node::resolveName(BOOL useOnlyDNS)
 {
        BOOL bSuccess = FALSE;
        HOSTENT *hs;
@@ -4025,7 +4025,7 @@ void Node::resolveVlanPorts(VlanList *vlanList)
 // Check subnet bindings
 //
 
-void Node::CheckSubnetBinding(InterfaceList *pIfList)
+void Node::checkSubnetBinding(InterfaceList *pIfList)
 {
        Subnet *pSubnet;
        Interface *pInterface;
@@ -4037,6 +4037,7 @@ void Node::CheckSubnetBinding(InterfaceList *pIfList)
        pCluster = getMyCluster();
 
        // Check if we have subnet bindings for all interfaces
+       DbgPrintf(5, _T("Checking subnet bindings for node %s [%d]"), m_szName, m_dwId);
        for(i = 0; i < pIfList->getSize(); i++)
        {
                NX_INTERFACE_INFO *iface = pIfList->get(i);
@@ -4067,6 +4068,14 @@ void Node::CheckSubnetBinding(InterfaceList *pIfList)
                                                                         pSubnet->Name(), pSubnet->Id(), m_szName, m_dwId);
                                                pSubnet->setCorrectMask(pInterface->IpAddr() & pInterface->getIpNetMask(), pInterface->getIpNetMask());
                                        }
+
+                                       // Check if node is linked to this subnet
+                                       if (!pSubnet->IsChild(m_dwId))
+                                       {
+                                               DbgPrintf(4, _T("Restored link between subnet %s [%d] and node %s [%d]"),
+                                                                        pSubnet->Name(), pSubnet->Id(), m_szName, m_dwId);
+                                               pSubnet->AddNode(this);
+                                       }
                                }
                        }
                        else if (!isSync)
index 9a81d48..481df3f 100644 (file)
@@ -748,13 +748,13 @@ protected:
    BOOL CheckSNMPIntegerValue(SNMP_Transport *pTransport, const TCHAR *pszOID, int nValue);
    void CheckOSPFSupport(SNMP_Transport *pTransport);
        void addVrrpInterfaces(InterfaceList *ifList);
-       BOOL ResolveName(BOOL useOnlyDNS);
+       BOOL resolveName(BOOL useOnlyDNS);
    void setAgentProxy(AgentConnection *pConn);
 
    DWORD getInterfaceCount(Interface **ppInterface);
 
-   void CheckInterfaceNames(InterfaceList *pIfList);
-       void CheckSubnetBinding(InterfaceList *pIfList);
+   void checkInterfaceNames(InterfaceList *pIfList);
+       void checkSubnetBinding(InterfaceList *pIfList);
        void checkAgentPolicyBinding(AgentConnection *conn);
 
        void ApplySystemTemplates();