public void deleteServer(Object server) { String id = ((Server) server).getName(); Server serverIns = (Server) server; DOMConfigurator config = null; try { Bundle bundle = Platform.getBundle(Application.PLUGIN_ID); URL fileURL = FileLocator.toFileURL(BundleUtility.find(bundle, "configuration/nabee.xml")); config = new DOMConfigurator(fileURL.getPath()); config.deleteConf("monitor/server", id); if (serverIns.getConnect().isConnect()) serverIns.getConnect().getProtocol()._close(); } catch (ParserConfigurationException e) { IMessageBox.Error(shell, NBLabel.get(0x008F)); return; } catch (TransformerException e) { IMessageBox.Error(shell, NBLabel.get(0x008F)); return; } catch (IOException e) { IMessageBox.Error(shell, NBLabel.get(0x008F)); return; } catch (SAXException e) { IMessageBox.Error(shell, NBLabel.get(0x008F)); return; } catch (Exception e) { IMessageBox.Error(shell, NBLabel.get(0x008F)); return; } serverIns.getParent().removeChild(id); treeViewer.refresh(); }
public void openInstanceView( String serverName, InstanceList instanceList, NBFields netFields, Server server) { try { ArrayList<Boolean> runStateList = new ArrayList<Boolean>(); if (netFields != null) { @SuppressWarnings("unchecked") ArrayList<NBFields> nList = (ArrayList<NBFields>) netFields.get("INSTANCE_LIST"); ArrayList<String> iList = new ArrayList<String>(); try { for (int i = 0; i < nList.size(); i++) { iList.add((String) nList.get(i).get("INSTANCE_NAME")); runStateList.add(((String) nList.get(i).get("RUNNING")).equals("true")); } instanceList.setList(iList); } catch (NullPointerException e) { } } IPCProtocol protocol = server.getConnect().getProtocol(); InstanceView instanceView = (InstanceView) getSite().getPage().showView(InstanceView.ID); instanceView.setProtocol(protocol); instanceView.setPartName(serverName); instanceView.setInstance(serverName, instanceList.getList(), runStateList); instanceView.setPartProperty("SERVER_NAME", serverName); instanceView.setServer(server); } catch (PartInitException e) { IMessageBox.Error(shell, NBLabel.get(0x0096)); } }
public void disconnectServer(boolean needAlert) { if (needAlert && IMessageBox.Confirm(shell, NBLabel.get(0x0094)) != SWT.OK) return; Server server = null; IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection(); if (selection.getFirstElement() instanceof Server) { server = (Server) selection.getFirstElement(); } else { IMessageBox.Error(shell, NBLabel.get(0x0091)); return; } closeConnection(server); }
private boolean controlServer(int messageType, IPCProtocol protocol) { NBFields fields = new NBFields(); fields.put(IPC.NB_MSG_TYPE, messageType); fields.put(IPC.NB_LOAD_CLASS, "com.nabsys.management.server.ControlServer"); try { fields = protocol.execute(fields); if ((Integer) fields.get(IPC.NB_MSG_RETURN) == IPC.FAIL) { IMessageBox.Error(shell, (String) fields.get("RTN_MSG")); return false; } else { return true; } } catch (SocketClosedException e) { IMessageBox.Error(shell, NBLabel.get(0x0090)); closeConnection(); return false; } catch (TimeoutException e) { IMessageBox.Error(shell, e.getMessage()); return false; } catch (NetException e) { IMessageBox.Error(shell, NBLabel.get(0x0090)); closeConnection(); return false; } catch (UnsupportedEncodingException e) { IMessageBox.Error(shell, NBLabel.get(0x0090)); closeConnection(); return false; } catch (NoSuchAlgorithmException e) { IMessageBox.Error(shell, NBLabel.get(0x0090)); closeConnection(); return false; } catch (DataTypeException e) { IMessageBox.Error(shell, NBLabel.get(0x0090)); closeConnection(); return false; } catch (ProtocolException e) { IMessageBox.Error(shell, NBLabel.get(0x0090)); closeConnection(); return false; } }
private NBFields getServerConfigInfo(IPCProtocol protocol) { NBFields fields = new NBFields(); fields.put(IPC.NB_LOAD_CLASS, "com.nabsys.management.server.ServerConfig"); fields.put("CMD_CODE", "R"); try { fields = protocol.execute(fields); if ((Integer) fields.get(IPC.NB_MSG_RETURN) == IPC.FAIL) { IMessageBox.Error(shell, (String) fields.get("RTN_MSG")); } } catch (SocketClosedException e) { IMessageBox.Error(shell, NBLabel.get(0x0090)); closeConnection(); fields = null; } catch (TimeoutException e) { IMessageBox.Error(shell, e.getMessage()); fields = null; } catch (NetException e) { IMessageBox.Error(shell, NBLabel.get(0x0090)); closeConnection(); fields = null; } catch (UnsupportedEncodingException e) { IMessageBox.Error(shell, NBLabel.get(0x0090)); closeConnection(); fields = null; } catch (NoSuchAlgorithmException e) { IMessageBox.Error(shell, NBLabel.get(0x0090)); closeConnection(); fields = null; } catch (DataTypeException e) { IMessageBox.Error(shell, NBLabel.get(0x0090)); closeConnection(); fields = null; } catch (ProtocolException e) { IMessageBox.Error(shell, NBLabel.get(0x0090)); closeConnection(); fields = null; } return fields; }
public void closeConnection(Server server) { try { server.getConnect().getProtocol()._close(); } catch (IOException e) { IMessageBox.Error(shell, e.getMessage()); } server.setImage(Activator.getImageDescriptor("/icons/disconserver.gif").createImage(display)); server.removeConfig(); server.removeUserList(); server.removeInstance(); treeViewer.refresh(); connectAction.setEnabled(true); disconnectAction.setEnabled(false); refreshAction.setEnabled(false); terminateAction.setEnabled(false); closeInstanceView(server.getName()); }
public boolean connectServer(HashMap<String, String> params) { ServerConnect connect = null; Server server = null; if (!treeViewer.getSelection().isEmpty()) { IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection(); if (selection.getFirstElement() instanceof Server) { server = (Server) selection.getFirstElement(); connect = server.getConnect(); } else { IMessageBox.Error(shell, NBLabel.get(0x0090)); return true; } if (params.containsKey("SAVE_FLAG") && params.get("SAVE_FLAG").equals("true")) connect.setPassword(params.get("PASSWORD")); params.put("IP_ADDRESS", connect.getHostAddr()); params.put("PORT", Integer.toString(connect.getHostPort())); params.put("ENCODING", connect.getServerEncoding()); } else if (params.containsKey("SERVER_NAME")) { String serverName = params.get("SERVER_NAME"); ArrayList<Model> children = ((Model) treeViewer.getInput()).getChildren(); for (int i = 0; i < children.size(); i++) { if (serverName.equals(children.get(i).getName())) { server = (Server) children.get(i); connect = ((Server) children.get(i)).getConnect(); } } } else { IMessageBox.Error(shell, NBLabel.get(0x0090)); return true; } try { Socket socket = new Socket(params.get("IP_ADDRESS"), Integer.parseInt(params.get("PORT")), 4096, 30); InstanceHeaderFields fields = new InstanceHeaderFields(); fields.put( "LENGTH", new TelegramFieldContext("LENGTH", "LENGTH", 0, 4, true, ' ', ' ', 'I', "")); fields.put( "MSG_TYPE", new TelegramFieldContext("MSG_TYPE", "MSG_TYPE", 1, 4, true, ' ', ' ', 'I', "")); fields.put( "RETURN", new TelegramFieldContext("RETURN", "RETURN", 2, 4, true, ' ', ' ', 'I', "")); fields.setLengthFieldIndex("LENGTH"); fields.setMsgTypeFieldIndex("MSG_TYPE"); fields.setReturnFieldIndex("RETURN"); IPCProtocol protocol = new IPCProtocol( socket, params.get("USER"), params.get("PASSWORD"), fields, params.get("ENCODING")); connect.setProtocol(protocol); NBFields netFields = new NBFields(); netFields.put(IPC.NB_LOAD_CLASS, "com.nabsys.management.instance.InstanceConfig"); netFields.put("CMD_CODE", "L"); netFields = protocol.execute(netFields); if (protocol.getUserAuthority().equals("Admin")) { new ServerConfig( server, NBLabel.get(0x0049), Activator.getImageDescriptor("/icons/config_obj.gif").createImage(display)); new UserList( server, NBLabel.get(0x009D), Activator.getImageDescriptor("/icons/user_view.gif").createImage(display)); new InstanceList( server, NBLabel.get(0x0093), Activator.getImageDescriptor("/icons/pview.gif").createImage(display)); terminateAction.setEnabled(true); } else if (protocol.getUserAuthority().equals("Operator")) { new UserList( server, NBLabel.get(0x009D), Activator.getImageDescriptor("/icons/user_view.gif").createImage(display)); new InstanceList( server, NBLabel.get(0x0093), Activator.getImageDescriptor("/icons/pview.gif").createImage(display)); } else if (protocol.getUserAuthority().equals("Developer")) { new InstanceList( server, NBLabel.get(0x0093), Activator.getImageDescriptor("/icons/pview.gif").createImage(display)); } server.setImage(Activator.getImageDescriptor("/icons/conserver.gif").createImage(display)); treeViewer.refresh(); connectAction.setEnabled(false); disconnectAction.setEnabled(true); treeViewer.expandToLevel(server, 1); openInstanceView(server.getName(), server.getInstance(), netFields, server); } catch (NumberFormatException e) { try { if (connect.getProtocol() != null) connect.getProtocol()._close(); } catch (IOException e1) { } IMessageBox.Error(shell, e.getMessage()); return true; } catch (NetException e) { try { if (connect.getProtocol() != null) connect.getProtocol()._close(); } catch (IOException e1) { } IMessageBox.Error(shell, e.getMessage()); return false; } catch (SocketClosedException e) { try { if (connect.getProtocol() != null) connect.getProtocol()._close(); } catch (IOException e1) { } IMessageBox.Error(shell, e.getMessage()); return true; } catch (ClassNotFoundException e) { try { if (connect.getProtocol() != null) connect.getProtocol()._close(); } catch (IOException e1) { } IMessageBox.Error(shell, e.getMessage()); return true; } catch (TimeoutException e) { try { if (connect.getProtocol() != null) connect.getProtocol()._close(); } catch (IOException e1) { } IMessageBox.Error(shell, e.getMessage()); return false; } catch (UnsupportedEncodingException e) { try { if (connect.getProtocol() != null) connect.getProtocol()._close(); } catch (IOException e1) { } IMessageBox.Error(shell, e.getMessage()); return true; } catch (NoSuchAlgorithmException e) { try { if (connect.getProtocol() != null) connect.getProtocol()._close(); } catch (IOException e1) { } IMessageBox.Error(shell, e.getMessage()); return true; } catch (DataTypeException e) { try { if (connect.getProtocol() != null) connect.getProtocol()._close(); } catch (IOException e1) { } IMessageBox.Error(shell, e.getMessage()); return true; } catch (ProtocolException e) { try { if (connect.getProtocol() != null) connect.getProtocol()._close(); } catch (IOException e1) { } IMessageBox.Error(shell, e.getMessage()); return true; } catch (Exception e) { try { if (connect.getProtocol() != null) connect.getProtocol()._close(); } catch (IOException e1) { } IMessageBox.Error(shell, e.getMessage()); return true; } return true; }