Search in sources :

Example 1 with PackageInfo

use of org.netxms.client.packages.PackageInfo in project netxms by netxms.

the class PackageManager method installPackage.

/**
 * Install new package
 */
private void installPackage() {
    FileDialog fd = new FileDialog(getSite().getShell(), SWT.OPEN);
    fd.setText(Messages.get().PackageManager_SelectFile);
    String npiName = fd.open();
    if (npiName != null) {
        try {
            final File npiFile = new File(npiName);
            final PackageInfo p = new PackageInfo(npiFile);
            final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
            new ConsoleJob(Messages.get().PackageManager_InstallPackage, this, Activator.PLUGIN_ID, null) {

                @Override
                protected void runInternal(final IProgressMonitor monitor) throws Exception {
                    final long id = session.installPackage(p, new File(npiFile.getParent(), p.getFileName()), new ProgressListener() {

                        long prevAmount = 0;

                        @Override
                        public void setTotalWorkAmount(long amount) {
                            monitor.beginTask(Messages.get(getDisplay()).PackageManager_UploadPackage, (int) amount);
                        }

                        @Override
                        public void markProgress(long amount) {
                            monitor.worked((int) (amount - prevAmount));
                            prevAmount = amount;
                        }
                    });
                    p.setId(id);
                    runInUIThread(new Runnable() {

                        @Override
                        public void run() {
                            packageList.add(p);
                            viewer.setInput(packageList.toArray());
                        }
                    });
                }

                @Override
                protected String getErrorMessage() {
                    return Messages.get().PackageManager_InstallError;
                }
            }.start();
        } catch (IOException e) {
            MessageDialogHelper.openError(getSite().getShell(), Messages.get().PackageManager_Error, Messages.get().PackageManager_PkgFileOpenError + e.getLocalizedMessage());
        }
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) ProgressListener(org.netxms.client.ProgressListener) PackageInfo(org.netxms.client.packages.PackageInfo) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) IOException(java.io.IOException) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException)

Example 2 with PackageInfo

use of org.netxms.client.packages.PackageInfo in project netxms by netxms.

the class PackageManager method deployPackage.

/**
 * Deploy package on managed nodes
 */
private void deployPackage() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.size() != 1)
        return;
    final PackageInfo pkg = (PackageInfo) selection.getFirstElement();
    ObjectSelectionDialog dlg = new ObjectSelectionDialog(getSite().getShell(), null, ObjectSelectionDialog.createNodeSelectionFilter(false));
    dlg.enableMultiSelection(true);
    if (dlg.open() != Window.OK)
        return;
    final Set<Long> objects = new HashSet<Long>();
    for (AbstractObject o : dlg.getSelectedObjects()) {
        objects.add(o.getObjectId());
    }
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    ConsoleJob job = new ConsoleJob(Messages.get().PackageManager_DeployAgentPackage, null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            session.deployPackage(pkg.getId(), objects.toArray(new Long[objects.size()]), new PackageDeploymentListener() {

                private PackageDeploymentMonitor monitor = null;

                @Override
                public void statusUpdate(long nodeId, int status, String message) {
                    if (monitor != null)
                        monitor.viewStatusUpdate(nodeId, status, message);
                }

                @Override
                public void deploymentStarted() {
                    final Object sync = new Object();
                    synchronized (sync) {
                        runInUIThread(new Runnable() {

                            @Override
                            public void run() {
                                try {
                                    monitor = (PackageDeploymentMonitor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(PackageDeploymentMonitor.ID, toString(), IWorkbenchPage.VIEW_ACTIVATE);
                                    monitor.setPackageId(pkg.getId());
                                } catch (PartInitException e) {
                                    MessageDialogHelper.openError(getSite().getShell(), Messages.get().PackageManager_Error, Messages.get().PackageManager_ErrorOpenView + e.getLocalizedMessage());
                                }
                                synchronized (sync) {
                                    sync.notify();
                                }
                            }
                        });
                        try {
                            sync.wait();
                        } catch (InterruptedException e) {
                        }
                    }
                }

                @Override
                public void deploymentComplete() {
                    runInUIThread(new Runnable() {

                        @Override
                        public void run() {
                            MessageDialogHelper.openInformation(getSite().getShell(), Messages.get().PackageManager_Information, Messages.get().PackageManager_PkgDepCompleted);
                        }
                    });
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().PackageManager_DepStartError;
        }
    };
    job.setUser(false);
    job.start();
}
Also used : NXCSession(org.netxms.client.NXCSession) PackageInfo(org.netxms.client.packages.PackageInfo) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PackageDeploymentListener(org.netxms.client.packages.PackageDeploymentListener) ObjectSelectionDialog(org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AbstractObject(org.netxms.client.objects.AbstractObject) AbstractObject(org.netxms.client.objects.AbstractObject) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException) HashSet(java.util.HashSet)

Example 3 with PackageInfo

use of org.netxms.client.packages.PackageInfo in project netxms by netxms.

the class NXCSession method getInstalledPackages.

/**
 * Get list of installed packages
 *
 * @return List of PackageInfo objects
 * @throws IOException  if socket or file I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public List<PackageInfo> getInstalledPackages() throws IOException, NXCException {
    final NXCPMessage msg = newMessage(NXCPCodes.CMD_GET_PACKAGE_LIST);
    sendMessage(msg);
    waitForRCC(msg.getMessageId());
    List<PackageInfo> list = new ArrayList<PackageInfo>();
    while (true) {
        final NXCPMessage response = waitForMessage(NXCPCodes.CMD_PACKAGE_INFO, msg.getMessageId());
        if (response.getFieldAsInt64(NXCPCodes.VID_PACKAGE_ID) == 0)
            break;
        list.add(new PackageInfo(response));
    }
    return list;
}
Also used : PackageInfo(org.netxms.client.packages.PackageInfo) NXCPMessage(org.netxms.base.NXCPMessage) ArrayList(java.util.ArrayList)

Example 4 with PackageInfo

use of org.netxms.client.packages.PackageInfo in project netxms by netxms.

the class PackageComparator 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) {
    PackageInfo p1 = (PackageInfo) e1;
    PackageInfo p2 = (PackageInfo) e2;
    int result;
    switch(// $NON-NLS-1$
    (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID")) {
        case PackageManager.COLUMN_ID:
            result = Long.signum(p1.getId() - p2.getId());
            break;
        case PackageManager.COLUMN_DESCRIPTION:
            result = p1.getDescription().compareToIgnoreCase(p2.getDescription());
            break;
        case PackageManager.COLUMN_FILE:
            result = p1.getFileName().compareToIgnoreCase(p2.getFileName());
            break;
        case PackageManager.COLUMN_NAME:
            result = p1.getName().compareToIgnoreCase(p2.getName());
            break;
        case PackageManager.COLUMN_PLATFORM:
            result = p1.getPlatform().compareToIgnoreCase(p2.getPlatform());
            break;
        case PackageManager.COLUMN_VERSION:
            result = p1.getVersion().compareToIgnoreCase(p2.getVersion());
            break;
        default:
            result = 0;
    }
    return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
Also used : PackageInfo(org.netxms.client.packages.PackageInfo) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer)

Example 5 with PackageInfo

use of org.netxms.client.packages.PackageInfo in project netxms by netxms.

the class PackageManager method removePackage.

/**
 * Remove selected package(s)
 */
private void removePackage() {
    if (!MessageDialogHelper.openConfirm(getSite().getShell(), Messages.get().PackageManager_ConfirmDeleteTitle, Messages.get().PackageManager_ConfirmDeleteText))
        return;
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    final Object[] packages = ((IStructuredSelection) viewer.getSelection()).toArray();
    final List<Object> removedPackages = new ArrayList<Object>();
    new ConsoleJob(Messages.get().PackageManager_DeletePackages, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            for (Object p : packages) {
                session.removePackage(((PackageInfo) p).getId());
                removedPackages.add(p);
            }
        }

        @Override
        protected void jobFinalize() {
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    packageList.removeAll(removedPackages);
                    viewer.setInput(packageList.toArray());
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().PackageManager_PkgDeleteError;
        }
    }.start();
}
Also used : NXCSession(org.netxms.client.NXCSession) PackageInfo(org.netxms.client.packages.PackageInfo) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AbstractObject(org.netxms.client.objects.AbstractObject) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Aggregations

PackageInfo (org.netxms.client.packages.PackageInfo)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 PartInitException (org.eclipse.ui.PartInitException)3 NXCSession (org.netxms.client.NXCSession)3 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 NXCException (org.netxms.client.NXCException)2 AbstractObject (org.netxms.client.objects.AbstractObject)2 File (java.io.File)1 HashSet (java.util.HashSet)1 FileDialog (org.eclipse.swt.widgets.FileDialog)1 NXCPMessage (org.netxms.base.NXCPMessage)1 ProgressListener (org.netxms.client.ProgressListener)1 PackageDeploymentListener (org.netxms.client.packages.PackageDeploymentListener)1 ObjectSelectionDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog)1 SortableTableViewer (org.netxms.ui.eclipse.widgets.SortableTableViewer)1