Search in sources :

Example 1 with PackageDeploymentListener

use of org.netxms.client.packages.PackageDeploymentListener 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 2 with PackageDeploymentListener

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

the class PackageDeploymentMonitor method redeployPackages.

private void redeployPackages() {
    final Set<Long> objects = new HashSet<Long>();
    Collection<DeploymentStatus> array = statusList.values();
    for (DeploymentStatus obj : array) {
        if (// status failed
        obj.getStatus() == 4) {
            objects.add(obj.getNodeObject().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(packageId, objects.toArray(new Long[objects.size()]), new PackageDeploymentListener() {

                @Override
                public void statusUpdate(long nodeId, int status, String message) {
                    viewStatusUpdate(nodeId, status, message);
                }

                @Override
                public void deploymentStarted() {
                }

                @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) PackageDeploymentListener(org.netxms.client.packages.PackageDeploymentListener) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) DeploymentStatus(org.netxms.ui.eclipse.agentmanager.views.helpers.DeploymentStatus) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 NXCSession (org.netxms.client.NXCSession)2 PackageDeploymentListener (org.netxms.client.packages.PackageDeploymentListener)2 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 PartInitException (org.eclipse.ui.PartInitException)1 AbstractObject (org.netxms.client.objects.AbstractObject)1 PackageInfo (org.netxms.client.packages.PackageInfo)1 DeploymentStatus (org.netxms.ui.eclipse.agentmanager.views.helpers.DeploymentStatus)1 ObjectSelectionDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog)1