Search in sources :

Example 1 with ServerJob

use of org.netxms.client.server.ServerJob in project netxms by netxms.

the class ServerJobManager method doJobAction.

/**
 * Do job action: cancel, hold, unhold
 *
 * @param actionName
 * @param actionId
 */
private void doJobAction(final String actionName, final String actionErrorName, final int actionId) {
    final IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    new ConsoleJob(String.format(Messages.get().ServerJobManager_ActionJobName, actionName), this, Activator.PLUGIN_ID, JOB_FAMILY) {

        @SuppressWarnings("rawtypes")
        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            Iterator it = selection.iterator();
            while (it.hasNext()) {
                Object object = it.next();
                if (object instanceof ServerJob) {
                    final ServerJob jobObject = (ServerJob) object;
                    switch(actionId) {
                        case CANCEL_JOB:
                            session.cancelServerJob(jobObject.getId());
                            break;
                        case HOLD_JOB:
                            session.holdServerJob(jobObject.getId());
                            break;
                        case UNHOLD_JOB:
                            session.unholdServerJob(jobObject.getId());
                            break;
                        default:
                            throw new NXCException(RCC.INTERNAL_ERROR);
                    }
                } else {
                    throw new NXCException(RCC.INTERNAL_ERROR);
                }
            }
        }

        @Override
        protected String getErrorMessage() {
            return String.format(Messages.get().ServerJobManager_ActionJobError, actionErrorName);
        }

        @Override
        protected void jobFinalize() {
            refreshJobList(false);
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ServerJob(org.netxms.client.server.ServerJob) Iterator(java.util.Iterator) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) NXCException(org.netxms.client.NXCException) NXCException(org.netxms.client.NXCException)

Example 2 with ServerJob

use of org.netxms.client.server.ServerJob in project netxms by netxms.

the class NXCSession method getServerJobList.

/**
 * Get list of server jobs
 *
 * @return list of server jobs
 * @throws IOException  if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public ServerJob[] getServerJobList() throws IOException, NXCException {
    NXCPMessage msg = newMessage(NXCPCodes.CMD_GET_JOB_LIST);
    sendMessage(msg);
    final NXCPMessage response = waitForRCC(msg.getMessageId());
    int count = response.getFieldAsInt32(NXCPCodes.VID_JOB_COUNT);
    ServerJob[] jobList = new ServerJob[count];
    long baseVarId = NXCPCodes.VID_JOB_LIST_BASE;
    for (int i = 0; i < count; i++, baseVarId += 10) {
        jobList[i] = new ServerJob(response, baseVarId);
    }
    return jobList;
}
Also used : ServerJob(org.netxms.client.server.ServerJob) NXCPMessage(org.netxms.base.NXCPMessage) ConnectionPoint(org.netxms.client.topology.ConnectionPoint) AccessPoint(org.netxms.client.objects.AccessPoint)

Example 3 with ServerJob

use of org.netxms.client.server.ServerJob in project netxms by netxms.

the class ServerJobComparator method compare.

/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
	 */
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
    int result;
    switch(// $NON-NLS-1$
    (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID")) {
        case ServerJobManager.COLUMN_STATUS:
            result = ((ServerJob) e1).getStatus() - ((ServerJob) e2).getStatus();
            break;
        case ServerJobManager.COLUMN_NODE:
            AbstractObject object1 = session.findObjectById(((ServerJob) e1).getNodeId());
            AbstractObject object2 = session.findObjectById(((ServerJob) e2).getNodeId());
            // $NON-NLS-1$
            String name1 = (object1 != null) ? object1.getObjectName() : "<unknown>";
            // $NON-NLS-1$
            String name2 = (object2 != null) ? object2.getObjectName() : "<unknown>";
            result = name1.compareToIgnoreCase(name2);
            break;
        case ServerJobManager.COLUMN_DESCRIPTION:
            result = ((ServerJob) e1).getDescription().compareToIgnoreCase(((ServerJob) e2).getDescription());
            break;
        case ServerJobManager.COLUMN_MESSAGE:
            result = ((ServerJob) e1).getFailureMessage().compareToIgnoreCase(((ServerJob) e2).getFailureMessage());
            break;
        default:
            result = 0;
            break;
    }
    return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
Also used : ServerJob(org.netxms.client.server.ServerJob) AbstractObject(org.netxms.client.objects.AbstractObject) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer)

Example 4 with ServerJob

use of org.netxms.client.server.ServerJob in project netxms by netxms.

the class ServerJobManager method refreshJobList.

/**
 * Refresh job list
 */
private void refreshJobList(boolean userInitiated) {
    ConsoleJob job = new ConsoleJob(Messages.get(viewer.getControl().getDisplay()).ServerJobManager_RefreshJobName, this, Activator.PLUGIN_ID, JOB_FAMILY, viewer.getControl().getDisplay()) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final ServerJob[] jobList = session.getServerJobList();
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    // Remember current selection
                    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
                    Object[] selectedObjects = selection.toArray();
                    viewer.setInput(jobList);
                    // Build new list of selected jobs - add object to selection if
                    // object with same id was selected before
                    List<ServerJob> selectedJobs = new ArrayList<ServerJob>(selectedObjects.length);
                    for (int i = 0; i < selectedObjects.length; i++) {
                        for (int j = 0; j < jobList.length; j++) {
                            if (((ServerJob) selectedObjects[i]).getId() == jobList[j].getId()) {
                                selectedJobs.add(jobList[j]);
                                break;
                            }
                        }
                    }
                    viewer.setSelection(new StructuredSelection(selectedJobs));
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().ServerJobManager_RefreshJobError;
        }
    };
    job.setUser(userInitiated);
    job.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ServerJob(org.netxms.client.server.ServerJob) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ArrayList(java.util.ArrayList) List(java.util.List) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Aggregations

ServerJob (org.netxms.client.server.ServerJob)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 NXCPMessage (org.netxms.base.NXCPMessage)1 NXCException (org.netxms.client.NXCException)1 AbstractObject (org.netxms.client.objects.AbstractObject)1 AccessPoint (org.netxms.client.objects.AccessPoint)1 ConnectionPoint (org.netxms.client.topology.ConnectionPoint)1 SortableTableViewer (org.netxms.ui.eclipse.widgets.SortableTableViewer)1