Search in sources :

Example 6 with AgentPolicy

use of org.netxms.client.objects.AgentPolicy in project netxms by netxms.

the class UninstallPolicy method run.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
@Override
public void run(IAction action) {
    // Read custom root objects
    long[] rootObjects = null;
    // $NON-NLS-1$
    Object value = ConsoleSharedData.getProperty("PolicyManager.rootObjects");
    if ((value != null) && (value instanceof long[])) {
        rootObjects = (long[]) value;
    }
    final ObjectSelectionDialog dlg = new ObjectSelectionDialog(shell, rootObjects, ObjectSelectionDialog.createNodeSelectionFilter(false));
    if (dlg.open() == Window.OK) {
        final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
        for (final AgentPolicy policy : currentSelection) {
            new ConsoleJob(String.format(Messages.get().UninstallPolicy_JobName, policy.getObjectName()), null, Activator.PLUGIN_ID, null) {

                @Override
                protected void runInternal(IProgressMonitor monitor) throws Exception {
                    AbstractObject[] nodeList = dlg.getSelectedObjects(Node.class);
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < nodeList.length; i++) {
                        try {
                            session.uninstallAgentPolicy(policy.getObjectId(), nodeList[i].getObjectId());
                        } catch (NXCException e) {
                            if (e.getErrorCode() == CommonRCC.INCOMPATIBLE_OPERATION || e.getErrorCode() == CommonRCC.INTERNAL_ERROR || e.getErrorCode() == CommonRCC.ACCESS_DENIED || e.getErrorCode() == CommonRCC.INVALID_OBJECT_ID) {
                                if (sb.length() == 0)
                                    sb.append("Could not apply policy to the node(s):\n");
                                sb.append(nodeList[i].getObjectName());
                                sb.append(" - ");
                                sb.append(e.getLocalizedMessage());
                                sb.append("\n");
                            } else {
                                throw (e);
                            }
                        }
                    }
                    if (sb.length() != 0) {
                        final String error = sb.toString();
                        runInUIThread(new Runnable() {

                            @Override
                            public void run() {
                                MessageDialog.openError(shell, "Error", error);
                            }
                        });
                    }
                }

                @Override
                protected String getErrorMessage() {
                    return String.format(Messages.get().UninstallPolicy_JobError, policy.getObjectName());
                }
            }.start();
        }
    }
}
Also used : NXCSession(org.netxms.client.NXCSession) Node(org.netxms.client.objects.Node) NXCException(org.netxms.client.NXCException) NXCException(org.netxms.client.NXCException) ObjectSelectionDialog(org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AgentPolicy(org.netxms.client.objects.AgentPolicy) AbstractObject(org.netxms.client.objects.AbstractObject) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Aggregations

AgentPolicy (org.netxms.client.objects.AgentPolicy)6 AbstractObject (org.netxms.client.objects.AbstractObject)5 Node (org.netxms.client.objects.Node)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 NXCException (org.netxms.client.NXCException)2 NXCSession (org.netxms.client.NXCSession)2 BusinessService (org.netxms.client.objects.BusinessService)2 BusinessServiceRoot (org.netxms.client.objects.BusinessServiceRoot)2 Cluster (org.netxms.client.objects.Cluster)2 Condition (org.netxms.client.objects.Condition)2 Container (org.netxms.client.objects.Container)2 Dashboard (org.netxms.client.objects.Dashboard)2 DashboardGroup (org.netxms.client.objects.DashboardGroup)2 DashboardRoot (org.netxms.client.objects.DashboardRoot)2 MobileDevice (org.netxms.client.objects.MobileDevice)2 NetworkMap (org.netxms.client.objects.NetworkMap)2 NetworkMapGroup (org.netxms.client.objects.NetworkMapGroup)2 NetworkMapRoot (org.netxms.client.objects.NetworkMapRoot)2 PolicyGroup (org.netxms.client.objects.PolicyGroup)2