Search in sources :

Example 31 with NXCException

use of org.netxms.client.NXCException in project netxms by netxms.

the class SoftwareInventory method refresh.

/**
 * Refresh list
 */
public void refresh() {
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob(Messages.get().SoftwareInventory_JobName, viewPart, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            AbstractObject object = session.findObjectById(rootObjectId);
            if (object instanceof AbstractNode) {
                final List<SoftwarePackage> packages = session.getNodeSoftwarePackages(rootObjectId);
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        viewer.setInput(packages.toArray());
                    }
                });
            } else {
                final List<SoftwareInventoryNode> nodes = new ArrayList<SoftwareInventoryNode>();
                for (final AbstractObject o : object.getAllChilds(AbstractObject.OBJECT_NODE)) {
                    try {
                        List<SoftwarePackage> packages = session.getNodeSoftwarePackages(o.getObjectId());
                        nodes.add(new SoftwareInventoryNode((Node) o, packages));
                    } catch (NXCException e) {
                        if (e.getErrorCode() != RCC.NO_SOFTWARE_PACKAGE_DATA)
                            throw e;
                    }
                }
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        viewer.setInput(nodes);
                    }
                });
            }
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().SoftwareInventory_JobError;
        }
    }.start();
}
Also used : NXCSession(org.netxms.client.NXCSession) AbstractNode(org.netxms.client.objects.AbstractNode) NXCException(org.netxms.client.NXCException) NXCException(org.netxms.client.NXCException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SoftwareInventoryNode(org.netxms.ui.eclipse.objectview.widgets.helpers.SoftwareInventoryNode) AbstractObject(org.netxms.client.objects.AbstractObject) ArrayList(java.util.ArrayList) List(java.util.List) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 32 with NXCException

use of org.netxms.client.NXCException in project netxms by netxms.

the class InstallPolicy method run.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
@Override
public void run(IAction action) {
    int initialMode = SelectInstallTargetDialog.INSTALL_ON_CURRENT;
    for (AgentPolicy p : currentSelection) {
        if (p.hasChildren()) {
            initialMode = SelectInstallTargetDialog.INSTALL_ON_SELECTED;
            break;
        }
    }
    final SelectInstallTargetDialog dlg = new SelectInstallTargetDialog(shell, initialMode);
    if (dlg.open() == Window.OK) {
        final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
        for (final AgentPolicy policy : currentSelection) {
            new ConsoleJob(String.format(Messages.get().InstallPolicy_JobName, policy.getObjectName()), null, Activator.PLUGIN_ID, null) {

                @Override
                protected void runInternal(IProgressMonitor monitor) throws Exception {
                    final AbstractObject[] nodeList = (dlg.getInstallMode() == SelectInstallTargetDialog.INSTALL_ON_SELECTED) ? dlg.getSelectedObjects() : policy.getChildsAsArray();
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < nodeList.length; i++) {
                        try {
                            session.deployAgentPolicy(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().InstallPolicy_JobError, policy.getObjectName());
                }
            }.start();
        }
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AgentPolicy(org.netxms.client.objects.AgentPolicy) NXCSession(org.netxms.client.NXCSession) SelectInstallTargetDialog(org.netxms.ui.eclipse.policymanager.dialogs.SelectInstallTargetDialog) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) NXCException(org.netxms.client.NXCException) NXCException(org.netxms.client.NXCException)

Example 33 with NXCException

use of org.netxms.client.NXCException 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)

Example 34 with NXCException

use of org.netxms.client.NXCException in project netxms by netxms.

the class SyslogParserConfigurator method refresh.

/**
 * Refresh viewer
 */
private void refresh() {
    if (modified) {
        if (!MessageDialogHelper.openQuestion(getSite().getShell(), Messages.get().SyslogParserConfigurator_ConfirmRefresh, Messages.get().SyslogParserConfigurator_ConfirmRefreshText))
            return;
    }
    actionSave.setEnabled(false);
    new ConsoleJob(Messages.get().SyslogParserConfigurator_LoadJobName, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            try {
                // $NON-NLS-1$
                content = session.getServerConfigClob("SyslogParser");
            } catch (NXCException e) {
                // UNKNOWN_VARIABLE error
                if (e.getErrorCode() != RCC.UNKNOWN_VARIABLE)
                    throw e;
                // $NON-NLS-1$
                content = "<parser>\n</parser>\n";
            }
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    editor.setParserXml(content);
                    setModified(false);
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().SyslogParserConfigurator_LoadJobError;
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException) NXCException(org.netxms.client.NXCException) NXCException(org.netxms.client.NXCException)

Aggregations

NXCException (org.netxms.client.NXCException)34 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)20 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)20 NXCSession (org.netxms.client.NXCSession)16 PartInitException (org.eclipse.ui.PartInitException)13 IOException (java.io.IOException)12 AbstractObject (org.netxms.client.objects.AbstractObject)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 List (java.util.List)4 ArrayList (java.util.ArrayList)3 UUID (java.util.UUID)3 Alarm (org.netxms.client.events.Alarm)3 AbstractNode (org.netxms.client.objects.AbstractNode)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 AccessListElement (org.netxms.client.AccessListElement)2 DataCollectionConfiguration (org.netxms.client.datacollection.DataCollectionConfiguration)2 DataCollectionItem (org.netxms.client.datacollection.DataCollectionItem)2 GraphSettings (org.netxms.client.datacollection.GraphSettings)2 AgentPolicy (org.netxms.client.objects.AgentPolicy)2 Node (org.netxms.client.objects.Node)2