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());
}
}
}
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();
}
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;
}
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;
}
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();
}
Aggregations