From 46edbd1983c6997df23abdc10a21bc3c9b032e0c Mon Sep 17 00:00:00 2001 From: Manty Date: Sun, 24 Oct 2021 04:25:46 +0900 Subject: [PATCH 01/20] add socks5 settings on login popup --- scouter.client/.classpath | 26 ++-- scouter.client/META-INF/MANIFEST.MF | 2 +- .../src/scouter/client/Application.java | 14 ++- .../client/actions/AddServerAction.java | 2 +- .../context/actions/OpenServerAction.java | 3 +- .../src/scouter/client/net/ClientTCP.java | 10 +- .../src/scouter/client/net/LoginMgr.java | 3 + .../src/scouter/client/net/TcpProxy.java | 15 ++- .../scouter/client/popup/LoginDialog2.java | 115 ++++++++++++++---- .../client/popup/ServerManagerDialog.java | 5 +- .../preferences/PreferenceConstants.java | 3 + .../client/preferences/ServerPrefUtil.java | 29 ++++- .../src/scouter/client/server/Server.java | 44 +++++++ .../src/scouter/client/util/UIUtil.java | 1 - 14 files changed, 221 insertions(+), 51 deletions(-) diff --git a/scouter.client/.classpath b/scouter.client/.classpath index e4fbbf4b3..56c1b2de9 100644 --- a/scouter.client/.classpath +++ b/scouter.client/.classpath @@ -1,16 +1,20 @@ - + + + + + + - - - - - - - - - - + + + + + + + + + diff --git a/scouter.client/META-INF/MANIFEST.MF b/scouter.client/META-INF/MANIFEST.MF index 959dc555b..e4f754910 100644 --- a/scouter.client/META-INF/MANIFEST.MF +++ b/scouter.client/META-INF/MANIFEST.MF @@ -25,7 +25,7 @@ Require-Bundle: org.eclipse.swt, org.eclipse.e4.core.commands, org.eclipse.e4.ui.services -Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-RequiredExecutionEnvironment: JavaSE-11 Bundle-ActivationPolicy: lazy Bundle-ClassPath: ., lib/scouter.common.jar, diff --git a/scouter.client/src/scouter/client/Application.java b/scouter.client/src/scouter/client/Application.java index bf1203116..66dac6f05 100644 --- a/scouter.client/src/scouter/client/Application.java +++ b/scouter.client/src/scouter/client/Application.java @@ -93,7 +93,7 @@ public void loginSuccess(String serverAddr, int serverId) { ServerManager.getInstance().setDefaultServer(server); } - }, LoginDialog2.TYPE_STARTUP, null); + }, LoginDialog2.TYPE_STARTUP, null, null); return (dialog.open() == Window.OK); } @@ -113,7 +113,17 @@ private boolean loginAutomaticallyWhenAutoLoginEnabled() { if (iport == null || iport.length < 2) { continue; } - Server server = new Server(iport[0], iport[1]); + + String socksIp = null; + String socksPort = null; + if (ServerPrefUtil.isSocksLogin(addr)) { + String socksAddr = ServerPrefUtil.getStoredSocksServer(addr); + String[] socksAddrs = socksAddr.split(":"); + socksIp = socksAddrs[0]; + socksPort = socksAddrs[1]; + } + + Server server = new Server(iport[0], iport[1], null, socksIp, socksPort); if (addr.equals(defaultSrv)) { manager.setDefaultServer(server); } else { diff --git a/scouter.client/src/scouter/client/actions/AddServerAction.java b/scouter.client/src/scouter/client/actions/AddServerAction.java index 2fbcb70aa..d13cba207 100644 --- a/scouter.client/src/scouter/client/actions/AddServerAction.java +++ b/scouter.client/src/scouter/client/actions/AddServerAction.java @@ -44,7 +44,7 @@ public AddServerAction(IWorkbenchWindow window, String label, Image image) { public void run() { if (window != null) { - dialog = new LoginDialog2(window.getShell(), null, LoginDialog2.TYPE_ADD_SERVER, null); + dialog = new LoginDialog2(window.getShell(), null, LoginDialog2.TYPE_ADD_SERVER, null, null); dialog.open(); } } diff --git a/scouter.client/src/scouter/client/context/actions/OpenServerAction.java b/scouter.client/src/scouter/client/context/actions/OpenServerAction.java index 35ffdd017..d053bf80e 100644 --- a/scouter.client/src/scouter/client/context/actions/OpenServerAction.java +++ b/scouter.client/src/scouter/client/context/actions/OpenServerAction.java @@ -48,7 +48,8 @@ public void run() { ConsoleProxy.errorSafe(result.getErrorMessage()); } } else { - LoginDialog2 dialog = new LoginDialog2(Display.getDefault().getActiveShell(), null, LoginDialog2.TYPE_OPEN_SERVER, server.getIp() + ":" + server.getPort()); + + LoginDialog2 dialog = new LoginDialog2(Display.getDefault().getActiveShell(), null, LoginDialog2.TYPE_OPEN_SERVER, server.getIp() + ":" + server.getPort(), server.getSocksAddr()); dialog.open(); } } diff --git a/scouter.client/src/scouter/client/net/ClientTCP.java b/scouter.client/src/scouter/client/net/ClientTCP.java index 958daee14..7e067ddc5 100644 --- a/scouter.client/src/scouter/client/net/ClientTCP.java +++ b/scouter.client/src/scouter/client/net/ClientTCP.java @@ -20,6 +20,7 @@ import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.net.InetSocketAddress; +import java.net.Proxy; import java.net.Socket; import scouter.client.server.Server; @@ -35,14 +36,19 @@ public class ClientTCP{ DataInputX in; DataOutputX out; - public void open(int serverId) { + public void open(int serverId, boolean socksLogin) { close(); Server server = ServerManager.getInstance().getServer(serverId); if (server == null) { return; } try { - socket = new Socket(); + if (socksLogin) { + InetSocketAddress proxyAddr = new InetSocketAddress(server.getSocksIp(), server.getSocksPort() ); + socket = new Socket(new Proxy(Proxy.Type.SOCKS, proxyAddr)); + }else { + socket = new Socket(); + } /// socket.setKeepAlive(true); socket.setTcpNoDelay(true); diff --git a/scouter.client/src/scouter/client/net/LoginMgr.java b/scouter.client/src/scouter/client/net/LoginMgr.java index bf95256c0..53b51adce 100644 --- a/scouter.client/src/scouter/client/net/LoginMgr.java +++ b/scouter.client/src/scouter/client/net/LoginMgr.java @@ -54,6 +54,9 @@ public static LoginResult silentLogin(Server server, String user, String passwor param.put("pass", password); param.put("version", Version.getClientFullVersion()); param.put("hostname", SysJMX.getHostName()); + param.put("isSocks", server.isSocksLogin()); + param.put("socksIp", server.getSocksIp()); + param.put("socksPort", server.getSocksPort()); MapPack out = TcpProxy.loginProxy(server.getId(), param); if (out == null) { diff --git a/scouter.client/src/scouter/client/net/TcpProxy.java b/scouter.client/src/scouter/client/net/TcpProxy.java index 08075818f..0b5e766fc 100644 --- a/scouter.client/src/scouter/client/net/TcpProxy.java +++ b/scouter.client/src/scouter/client/net/TcpProxy.java @@ -17,6 +17,7 @@ */ package scouter.client.net; +import scouter.client.preferences.ServerPrefUtil; import scouter.client.server.Server; import scouter.client.server.ServerManager; import scouter.io.DataInputX; @@ -75,10 +76,18 @@ public Server getServer() { public synchronized void open() { if (tcp.isSessionOk() == false) { - tcp.open(this.server.getId()); + boolean socksLogin =ServerPrefUtil.isSocksLogin(this.getServer().getIp()+":"+this.getServer().getPort()); + tcp.open(this.server.getId(),socksLogin); } } + public synchronized void open(boolean socksLogin) { + if (tcp.isSessionOk() == false) { + tcp.open(this.server.getId(), socksLogin); + } + } + + public synchronized void close() { sendClose(); tcp.close(); @@ -181,8 +190,10 @@ public synchronized void sendClose() { } public static MapPack loginProxy(int serverId, MapPack param) throws IOException { + Boolean socksLogin = param.getBoolean("isSocks"); + TcpProxy proxy = new TcpProxy(serverId); - proxy.open(); + proxy.open(socksLogin); if (proxy.isValid() == false) { return null; } diff --git a/scouter.client/src/scouter/client/popup/LoginDialog2.java b/scouter.client/src/scouter/client/popup/LoginDialog2.java index d412bbc6b..b19951189 100644 --- a/scouter.client/src/scouter/client/popup/LoginDialog2.java +++ b/scouter.client/src/scouter/client/popup/LoginDialog2.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015 the original author or authors. * @https://github.com/scouter-project/scouter * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -64,31 +64,34 @@ public class LoginDialog2 extends Dialog { ArrayList storeAddr = new ArrayList(); FormData data; - Combo addrCombo; + Combo addrCombo, socksAddrCombo; Text id, pass; Label idLabel, passLabel; List list; - Button autoLoginCheck, secureCheck; + Button autoLoginCheck, secureCheck, sock5Check; boolean autoLogin; boolean secureLogin = true; + boolean sock5Login = false; String address = null; + String socksAddress = null; - public LoginDialog2(Shell shell, ILoginDialog callback, int openType, String address) { + public LoginDialog2(Shell shell, ILoginDialog callback, int openType, String address, String socksAddress) { super(shell); this.shell = shell; this.callback = callback; this.openType = openType; this.address = address; + this.socksAddress = socksAddress; + this.sock5Login = StringUtil.isNotEmpty(socksAddress); } - @Override protected Control createDialogArea(Composite parent) { - Composite comp = (Composite) super.createDialogArea(parent); + Composite comp = (Composite) super.createDialogArea(parent); comp.setLayout(UIUtil.formLayout(5, 5)); final Group parentGroup = new Group(comp, SWT.NONE); parentGroup.setText("Authentication Info"); @@ -142,7 +145,7 @@ public void widgetSelected(SelectionEvent e) { } }); autoLoginCheck.setSelection(false); - + // to hash password before transfer, default true secureCheck = new Button(parentGroup, SWT.CHECK); secureCheck.setText("Secure Login"); @@ -158,13 +161,57 @@ public void widgetSelected(SelectionEvent e) { }); secureCheck.setSelection(true); - list = new List(parentGroup, SWT.NONE); - list.setLayoutData(UIUtil.formData(0, 5, secureCheck, 10, 100, -5, null, -1, -1, 60)); + // console group + final Group socksGroup = new Group(comp, SWT.NONE); + socksGroup.setText("SOCKS5"); + socksGroup.setLayout(UIUtil.formLayout(5, 5)); + socksGroup.setLayoutData(UIUtil.formData(null, -1, parentGroup, 0, null, -1, null, -1)); + + // to use SOCKS5 + sock5Check = new Button(socksGroup, SWT.CHECK|SWT.LEFT); + sock5Check.setText("SOCKS5"); + sock5Check.setLayoutData(UIUtil.formData(0, 0, 0, 5, 100, -5, null, -1)); + sock5Check.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + if (sock5Check.getSelection()) { + sock5Login = true; + } else { + sock5Login = false; + } + socksAddrCombo.setEnabled(sock5Login); + } + }); + sock5Check.setSelection(false); + + // socks5 address + Label socks5AddrLabel = new Label(socksGroup, SWT.RIGHT); + socks5AddrLabel.setText("SOCKS5 Address :"); + socks5AddrLabel.setLayoutData(UIUtil.formData(null, -1, sock5Check, 10, null, -1, null, -1, 100)); + + // socks5 address combo + String[] socks5Addrs = ServerPrefUtil.getStoredSocks5ServerList(); + + socksAddrCombo = new Combo(socksGroup, SWT.VERTICAL | SWT.BORDER | SWT.H_SCROLL); + if (socks5Addrs != null && socks5Addrs.length > 0) { + socksAddrCombo.setItems(socks5Addrs); + } + socksAddrCombo.setEnabled(sock5Login); + socksAddrCombo.setLayoutData(UIUtil.formData(socks5AddrLabel, 5, sock5Check, 10, 100, -5, null, -1, 150)); + + + // console group + final Group consoleGroup = new Group(comp, SWT.NONE); + consoleGroup.setLayout(UIUtil.formLayout(5, 5)); + consoleGroup.setLayoutData(UIUtil.formData(null, -1, socksGroup, 0, null, -1, null, -1)); + + // connection status console + list = new List(consoleGroup, SWT.NONE); + list.setLayoutData(UIUtil.formData(0, 5, 0, 5, 100, -5, null, -1, 250, 60)); + //list.setLayoutData(UIUtil.formData(0, 5, socks5AddrLabel, 10, 100, -5, null, -1, -1, 60)); list.add("Type your authentication info..."); list.select(list.getItemCount() - 1); list.showSelection(); - if (StringUtil.isNotEmpty(this.address)) { addrCombo.setText(address); Server server = ServerManager.getInstance().getServer(address); @@ -173,16 +220,25 @@ public void widgetSelected(SelectionEvent e) { secureCheck.setSelection(server.isSecureMode()); } autoLoginCheck.setSelection(ServerPrefUtil.isAutoLoginAddress(address)); - } else if (openType == TYPE_STARTUP){ + } else if (openType == TYPE_STARTUP) { addrCombo.setText("127.0.0.1:" + NetConstants.SERVER_TCP_PORT); id.setText("admin"); } + if (StringUtil.isNotEmpty(this.socksAddress)) { + socksAddrCombo.setText(socksAddress); + sock5Check.setSelection(true); + Server server = ServerManager.getInstance().getServer(address); + if (server != null && StringUtil.isNotEmpty(server.getUserId())) { + id.setText(server.getUserId()); + secureCheck.setSelection(server.isSecureMode()); + } + autoLoginCheck.setSelection(ServerPrefUtil.isAutoLoginAddress(address)); + } + return comp; } - - - + @Override protected Point getInitialLocation(Point initialSize) { Monitor primaryMonitor = Display.getDefault().getPrimaryMonitor(); @@ -192,8 +248,6 @@ protected Point getInitialLocation(Point initialSize) { return new Point(x, y); } - - @Override protected void configureShell(Shell newShell) { super.configureShell(newShell); @@ -221,7 +275,7 @@ protected void configureShell(Shell newShell) { protected boolean isResizable() { return false; } - + private void createPasswordInput(Composite parentGroup) { pass = new Text(parentGroup, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD); pass.addFocusListener(new FocusListener() { @@ -234,19 +288,15 @@ public void focusGained(FocusEvent e) { }); pass.setLayoutData(UIUtil.formData(passLabel, 5, id, 7, 100, -5, null, -1)); } - - @Override protected void okPressed() { - if (loginInToServer(addrCombo.getText())) { + if (loginInToServer(addrCombo.getText(), socksAddrCombo.getText())) { super.okPressed(); } } - - - public boolean loginInToServer(String address) { + public boolean loginInToServer(String address, String socksAddress) { Server server = null; if (StringUtil.isEmpty(address)) { errMsg("Please check server address"); @@ -264,6 +314,16 @@ public boolean loginInToServer(String address) { String addr[] = address.split(":"); ip = addr[0]; port = addr[1]; + + String socksIp = null; + String socksPort = null; + if (socksAddress.contains(":") == false) { + errMsg("Check SOCKS Address"); + } + String socksAddr[] = socksAddress.split(":"); + socksIp = socksAddr[0]; + socksPort = socksAddr[1]; + msg("Log in..." + address); ServerManager srvMgr = ServerManager.getInstance(); @@ -272,21 +332,24 @@ public boolean loginInToServer(String address) { msg(""); return false; } + - server = new Server(ip, port); + server = new Server(ip, port,null, socksIp, socksPort); if (srvMgr.getServer(server.getId()) == null) { srvMgr.addServer(server); } else { existServer = true; server = srvMgr.getServer(server.getId()); + server.setSocksIp(socksIp); + server.setSocksPort(socksPort == null ? 0 : Integer.parseInt(socksPort)); } - LoginResult result = LoginMgr.login(server.getId(), id.getText(), pass.getText(), secureLogin); + LoginResult result = LoginMgr.login(server.getId(), id.getText(), pass.getText()); if (result.success) { msg("Successfully log in to " + address); ServerPrefUtil.addServerAddr(address); if (autoLogin) { - ServerPrefUtil.addAutoLoginServer(address, id.getText(), server.getPassword()); + ServerPrefUtil.addAutoLoginServer(address, id.getText(), server.getPassword(), socksAddress); } else { ServerPrefUtil.removeAutoLoginServer(address); } diff --git a/scouter.client/src/scouter/client/popup/ServerManagerDialog.java b/scouter.client/src/scouter/client/popup/ServerManagerDialog.java index 8a27aba01..07125a5ec 100644 --- a/scouter.client/src/scouter/client/popup/ServerManagerDialog.java +++ b/scouter.client/src/scouter/client/popup/ServerManagerDialog.java @@ -137,11 +137,12 @@ public void handleEvent(Event event) { TableItem items[] = table.getSelection(); if (items != null && items.length > 0) { String addr = (String) items[0].getData(); + String socksAddr = ServerPrefUtil.getStoredSocksServer(addr); if (items[0].getForeground().getRGB().equals(ColorUtil.getInstance().getColor(SWT.COLOR_RED).getRGB())) { - LoginDialog2 loginDialog = new LoginDialog2(dialog, ServerManagerDialog.this, LoginDialog2.TYPE_ADD_SERVER, addr); + LoginDialog2 loginDialog = new LoginDialog2(dialog, ServerManagerDialog.this, LoginDialog2.TYPE_ADD_SERVER, addr, socksAddr); loginDialog.open(); } else { - LoginDialog2 loginDialog = new LoginDialog2(dialog, ServerManagerDialog.this, LoginDialog2.TYPE_EDIT_SERVER, addr); + LoginDialog2 loginDialog = new LoginDialog2(dialog, ServerManagerDialog.this, LoginDialog2.TYPE_EDIT_SERVER, addr, socksAddr); loginDialog.open(); } } diff --git a/scouter.client/src/scouter/client/preferences/PreferenceConstants.java b/scouter.client/src/scouter/client/preferences/PreferenceConstants.java index 991b3c9d4..5d97a82cf 100644 --- a/scouter.client/src/scouter/client/preferences/PreferenceConstants.java +++ b/scouter.client/src/scouter/client/preferences/PreferenceConstants.java @@ -25,6 +25,9 @@ public class PreferenceConstants { public static final String P_SVR_ACCOUNT_PREFIX = "autologin_"; public static final String P_SVR_DIVIDER = ","; + public static final String P_SOCKS_SVR_ADDR_PREFIX = "socksServerAddr_"; + public static final String P_SOCKS_SVR_AUTOLOGIN_LIST = "socksSvrAddrAutoLogin"; + public static final String P_PERS_WAS_SERV_DEFAULT_HOST = "wasServiceDefaultHost"; public static final String P_PERS_WAS_SERV_DEFAULT_WAS = "wasServiceDefaultWAS"; diff --git a/scouter.client/src/scouter/client/preferences/ServerPrefUtil.java b/scouter.client/src/scouter/client/preferences/ServerPrefUtil.java index 6487bf958..6a14bddb0 100644 --- a/scouter.client/src/scouter/client/preferences/ServerPrefUtil.java +++ b/scouter.client/src/scouter/client/preferences/ServerPrefUtil.java @@ -17,7 +17,6 @@ */ package scouter.client.preferences; -import scouter.util.StringUtil; import scouter.util.StringUtil; public class ServerPrefUtil { @@ -38,7 +37,7 @@ public static void addServerAddr(String addr) { } } - public static void addAutoLoginServer(String addr, String id, String encryptedPass) { + public static void addAutoLoginServer(String addr, String id, String encryptedPass, String socksAddr) { String addrs = PManager.getInstance().getString(PreferenceConstants.P_SVR_AUTOLOGIN_LIST); if (StringUtil.isEmpty(addrs)) { PManager.getInstance().setValue(PreferenceConstants.P_SVR_AUTOLOGIN_LIST, addr); @@ -48,7 +47,20 @@ public static void addAutoLoginServer(String addr, String id, String encryptedPa PManager.getInstance().setValue(PreferenceConstants.P_SVR_AUTOLOGIN_LIST, addrs); } } + + + String socksAddrs = PManager.getInstance().getString(PreferenceConstants.P_SOCKS_SVR_AUTOLOGIN_LIST); + if (StringUtil.isEmpty(socksAddrs)) { + PManager.getInstance().setValue(PreferenceConstants.P_SOCKS_SVR_AUTOLOGIN_LIST, socksAddr); + } else { + if (socksAddrs.contains(socksAddr) == false) { + socksAddrs += (PreferenceConstants.P_SVR_DIVIDER + socksAddr); + PManager.getInstance().setValue(PreferenceConstants.P_SOCKS_SVR_AUTOLOGIN_LIST, socksAddrs); + } + } + PManager.getInstance().setValue(PreferenceConstants.P_SVR_ACCOUNT_PREFIX + addr, id + PreferenceConstants.P_SVR_DIVIDER + encryptedPass); + PManager.getInstance().setValue(PreferenceConstants.P_SOCKS_SVR_ADDR_PREFIX + addr, socksAddr); } public static void removeServerAddr(String addr) { @@ -78,6 +90,11 @@ public static String[] getStoredServerList() { return StringUtil.tokenizer(addrs, PreferenceConstants.P_SVR_DIVIDER); } + public static String[] getStoredSocks5ServerList() { + String addrs = PManager.getInstance().getString(PreferenceConstants.P_SOCKS_SVR_AUTOLOGIN_LIST); + return StringUtil.tokenizer(addrs, PreferenceConstants.P_SVR_DIVIDER); + } + public static String[] getStoredAutoLoginServerList() { String addrs = PManager.getInstance().getString(PreferenceConstants.P_SVR_AUTOLOGIN_LIST); return StringUtil.tokenizer(addrs, PreferenceConstants.P_SVR_DIVIDER); @@ -87,6 +104,14 @@ public static String getStoredAccountInfo(String addr) { return PManager.getInstance().getString(PreferenceConstants.P_SVR_ACCOUNT_PREFIX + addr); } + public static boolean isSocksLogin(String addr) { + return StringUtil.isNotEmpty(PManager.getInstance().getString(PreferenceConstants.P_SOCKS_SVR_ADDR_PREFIX + addr)); + } + + public static String getStoredSocksServer(String addr) { + return PManager.getInstance().getString(PreferenceConstants.P_SOCKS_SVR_ADDR_PREFIX + addr); + } + public static boolean isAutoLoginAddress(String addr) { String addrs = PManager.getInstance().getString(PreferenceConstants.P_SVR_AUTOLOGIN_LIST); return addrs.contains(addr); diff --git a/scouter.client/src/scouter/client/server/Server.java b/scouter.client/src/scouter/client/server/Server.java index 3fb57a2ac..c28085680 100644 --- a/scouter.client/src/scouter/client/server/Server.java +++ b/scouter.client/src/scouter/client/server/Server.java @@ -56,15 +56,43 @@ public class Server { private MapValue groupPolicyMap = new MapValue(); private MapValue menuEnableMap = new MapValue(); + private String socksIp; + private int socksPort; + + public Server(String ip, String port) { this(ip, port, null); } public Server(String ip, String port, String name) { + this(ip, port, name, null, null); + } + + public Server(String ip, String port, String name, String socksIp, String socksPort) { this.id = HashUtil.hash(ip + port); this.ip = ip; this.port = Integer.valueOf(port); this.name = name; + this.socksIp = socksIp; + if ( socksPort != null ) { + try { + this.socksPort = Integer.valueOf(socksPort); + }catch(Exception e) { + e.printStackTrace(); + } + } + } + + public String getSocksAddr() { + String socksAddr = null; + if (getSocksIp() != null && getSocksPort() != 0) { + socksAddr = getSocksIp() + ":" + getSocksPort(); + } + return socksAddr; + } + + public boolean isSocksLogin() { + return getSocksIp() != null && getSocksPort() != 0; } public int getId() { @@ -79,6 +107,22 @@ public int getPort() { return port; } + public String getSocksIp() { + return socksIp; + } + + public void setSocksIp(String socksIp) { + this.socksIp = socksIp; + } + + public int getSocksPort() { + return socksPort; + } + + public void setSocksPort(int socksPort) { + this.socksPort = socksPort; + } + public ConnectionPool getConnectionPool() { return this.connPool; } diff --git a/scouter.client/src/scouter/client/util/UIUtil.java b/scouter.client/src/scouter/client/util/UIUtil.java index aac650c7b..273b01d92 100644 --- a/scouter.client/src/scouter/client/util/UIUtil.java +++ b/scouter.client/src/scouter/client/util/UIUtil.java @@ -36,7 +36,6 @@ import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableItem; -import scouter.client.Images; import scouter.util.CastUtil; public class UIUtil { From 98e73428c53142d10727ea3dff14318914241aec Mon Sep 17 00:00:00 2001 From: Manty Date: Sun, 24 Oct 2021 17:31:55 +0900 Subject: [PATCH 02/20] eclipse version update --- scouter.client.build/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scouter.client.build/pom.xml b/scouter.client.build/pom.xml index 639bbde79..048428924 100644 --- a/scouter.client.build/pom.xml +++ b/scouter.client.build/pom.xml @@ -11,14 +11,14 @@ ../scouter.client.product - 2.3.0 + 2.5.0 UTF-8 - eclipse-simultaneous-2021-09 + eclipse-simultaneous-2021-12 p2 - https://download.eclipse.org/releases/2021-09/ + https://download.eclipse.org/releases/2021-12/ From 71f01b7fc7174e87885c84066549c2c070cd92ab Mon Sep 17 00:00:00 2001 From: Manty Date: Sun, 24 Oct 2021 19:35:50 +0900 Subject: [PATCH 03/20] logging --- scouter.client.build/pom.xml | 2 +- .../src/scouter/client/Application.java | 50 +++--- .../client/actions/AddServerAction.java | 4 +- .../src/scouter/client/net/ClientTCP.java | 12 +- .../scouter/client/net/ConnectionPool.java | 8 +- .../src/scouter/client/net/INetReader.java | 4 +- .../src/scouter/client/net/TcpProxy.java | 40 ++--- .../scouter/client/popup/LoginDialog2.java | 165 +++++++----------- .../event/AbstractFocusGainedListener.java | 11 ++ .../event/AbstractFocusLostListener.java | 11 ++ .../scouter/client/server/ServerManager.java | 26 +-- 11 files changed, 161 insertions(+), 172 deletions(-) create mode 100644 scouter.client/src/scouter/client/popup/event/AbstractFocusGainedListener.java create mode 100644 scouter.client/src/scouter/client/popup/event/AbstractFocusLostListener.java diff --git a/scouter.client.build/pom.xml b/scouter.client.build/pom.xml index 048428924..81c5eb9d3 100644 --- a/scouter.client.build/pom.xml +++ b/scouter.client.build/pom.xml @@ -35,7 +35,7 @@ org.eclipse.tycho target-platform-configuration ${tycho-version} - + win32 diff --git a/scouter.client/src/scouter/client/Application.java b/scouter.client/src/scouter/client/Application.java index 66dac6f05..39e3da007 100644 --- a/scouter.client/src/scouter/client/Application.java +++ b/scouter.client/src/scouter/client/Application.java @@ -28,7 +28,6 @@ import scouter.client.net.LoginMgr; import scouter.client.net.LoginResult; import scouter.client.popup.LoginDialog2; -import scouter.client.popup.LoginDialog2.ILoginDialog; import scouter.client.preferences.PreferenceConstants; import scouter.client.preferences.ServerPrefUtil; import scouter.client.server.Server; @@ -41,6 +40,8 @@ import java.util.HashSet; import java.util.Set; +import static java.io.File.separator; + /** * This class controls all aspects of the application's execution */ @@ -53,15 +54,15 @@ public Object start(IApplicationContext context) throws Exception { // instanceLocation.set(new URL("file", null, System.getProperty("user.home") + "/scouter-workspace-test"), false); String workspaceRootName = instanceLocation.getURL().getFile(); - String importWorkingDirName = workspaceRootName + "/import-working"; + String importWorkingDirName = workspaceRootName + separator+ "import-working"; try { - ClientFileUtil.copy(new File(importWorkingDirName + "/" + ClientFileUtil.XLOG_COLUMN_FILE), - new File(workspaceRootName + "/" + ClientFileUtil.XLOG_COLUMN_FILE)); - ClientFileUtil.copy(new File(importWorkingDirName + "/" + ClientFileUtil.GROUP_FILE), - new File(workspaceRootName + "/" + ClientFileUtil.GROUP_FILE)); - ClientFileUtil.copy(new File(importWorkingDirName + "/" + ClientFileUtil.WORKSPACE_METADATA_DIR), - new File(workspaceRootName + "/" + ClientFileUtil.WORKSPACE_METADATA_DIR)); + ClientFileUtil.copy(new File(importWorkingDirName + separator + ClientFileUtil.XLOG_COLUMN_FILE), + new File(workspaceRootName + separator + ClientFileUtil.XLOG_COLUMN_FILE)); + ClientFileUtil.copy(new File(importWorkingDirName + separator + ClientFileUtil.GROUP_FILE), + new File(workspaceRootName + separator + ClientFileUtil.GROUP_FILE)); + ClientFileUtil.copy(new File(importWorkingDirName + separator + ClientFileUtil.WORKSPACE_METADATA_DIR), + new File(workspaceRootName + separator + ClientFileUtil.WORKSPACE_METADATA_DIR)); } catch (IOException e) { e.printStackTrace(); } @@ -72,7 +73,7 @@ public Object start(IApplicationContext context) throws Exception { Object exitStrategy = IApplication.EXIT_OK; try { boolean loginSuccessed = loginAutomaticallyWhenAutoLoginEnabled(); - if (loginSuccessed == false) { + if (!loginSuccessed) { loginSuccessed = openLoginDialog(display); } if (loginSuccessed) { @@ -85,14 +86,10 @@ public Object start(IApplicationContext context) throws Exception { } private boolean openLoginDialog(Display display) { - LoginDialog2 dialog = new LoginDialog2(display.getActiveShell(), new ILoginDialog() { - @Override - public void loginSuccess(String serverAddr, int serverId) { - Server server = ServerManager.getInstance().getServer(serverId); - ServerPrefUtil.storeDefaultServer(server.getIp()+":"+server.getPort()); - ServerManager.getInstance().setDefaultServer(server); - } - + LoginDialog2 dialog = new LoginDialog2(display.getActiveShell(), (serverAddr, serverId) -> { + Server server = ServerManager.getInstance().getServer(serverId); + ServerPrefUtil.storeDefaultServer(server.getIp()+":"+server.getPort()); + ServerManager.getInstance().setDefaultServer(server); }, LoginDialog2.TYPE_STARTUP, null, null); return (dialog.open() == Window.OK); } @@ -102,15 +99,15 @@ private boolean loginAutomaticallyWhenAutoLoginEnabled() { String[] serverList = ServerPrefUtil.getStoredServerList(); if (serverList != null && serverList.length > 0) { String[] autoList = ServerPrefUtil.getStoredAutoLoginServerList(); - HashSet autoSet = new HashSet(); + HashSet autoSet = new HashSet<>(); if (autoList != null && autoList.length > 0) { - autoSet = new HashSet(Arrays.asList(autoList)); + autoSet = new HashSet<>(Arrays.asList(autoList)); } String defaultSrv = ServerPrefUtil.getStoredDefaultServer(); ServerManager manager = ServerManager.getInstance(); for (String addr : serverList) { String[] iport = addr.split(":"); - if (iport == null || iport.length < 2) { + if (iport.length < 2) { continue; } @@ -135,7 +132,7 @@ private boolean loginAutomaticallyWhenAutoLoginEnabled() { int index = accountInfo.indexOf(PreferenceConstants.P_SVR_DIVIDER); if (index > -1) { String id = accountInfo.substring(0, index); - String pwd = accountInfo.substring(index + 1, accountInfo.length()); + String pwd = accountInfo.substring(index + 1); LoginResult result = LoginMgr.silentLogin(server, id, pwd); if (result.success) { autoLogined = true; @@ -144,7 +141,7 @@ private boolean loginAutomaticallyWhenAutoLoginEnabled() { } } } - if (autoLogined && autoSet.contains(defaultSrv) == false) { + if (autoLogined && !autoSet.contains(defaultSrv)) { Set openSet = manager.getOpenServerList(); Integer[] array = openSet.toArray(new Integer[openSet.size()]); Server server = manager.getServer(array[0]); @@ -170,12 +167,9 @@ public void stop() { if (workbench == null) return; final Display display = workbench.getDisplay(); - display.syncExec(new Runnable() { - - public void run() { - if (!display.isDisposed()) - workbench.close(); - } + display.syncExec(() -> { + if (!display.isDisposed()) + workbench.close(); }); } } diff --git a/scouter.client/src/scouter/client/actions/AddServerAction.java b/scouter.client/src/scouter/client/actions/AddServerAction.java index d13cba207..06bd94598 100644 --- a/scouter.client/src/scouter/client/actions/AddServerAction.java +++ b/scouter.client/src/scouter/client/actions/AddServerAction.java @@ -21,13 +21,12 @@ import org.eclipse.jface.action.Action; import org.eclipse.swt.graphics.Image; import org.eclipse.ui.IWorkbenchWindow; - import scouter.client.popup.LoginDialog2; import scouter.client.util.ImageUtil; public class AddServerAction extends Action { - public final static String ID = AddServerAction.class.getName(); + public static final String ID = AddServerAction.class.getName(); private final IWorkbenchWindow window; @@ -42,6 +41,7 @@ public AddServerAction(IWorkbenchWindow window, String label, Image image) { LoginDialog2 dialog; + @Override public void run() { if (window != null) { dialog = new LoginDialog2(window.getShell(), null, LoginDialog2.TYPE_ADD_SERVER, null, null); diff --git a/scouter.client/src/scouter/client/net/ClientTCP.java b/scouter.client/src/scouter/client/net/ClientTCP.java index 7e067ddc5..fc28aecb9 100644 --- a/scouter.client/src/scouter/client/net/ClientTCP.java +++ b/scouter.client/src/scouter/client/net/ClientTCP.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015 the original author or authors. * @https://github.com/scouter-project/scouter * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -32,6 +32,7 @@ public class ClientTCP{ + Socket socket; DataInputX in; DataOutputX out; @@ -64,8 +65,11 @@ public void open(int serverId, boolean socksLogin) { out.writeInt(NetCafe.TCP_CLIENT); out.flush(); //*************// - if (server.isConnected() == false) { - System.out.println("Success to connect " + server.getIp() + ":" + server.getPort()); + if (!server.isConnected()) { + System.out.println( + String.format("Success to connect %s:%d (%s)", + server.getIp(), server.getPort(), + server.isSocksLogin()?server.getSocksIp()+":"+server.getSocksPort() : "direct")); } server.setConnected(true); } catch (Throwable t) { @@ -86,7 +90,7 @@ public DataInputX getInput() { } public boolean isSessionOk() { - return socket != null && socket.isClosed() == false; + return socket != null && !socket.isClosed(); } public void close() { diff --git a/scouter.client/src/scouter/client/net/ConnectionPool.java b/scouter.client/src/scouter/client/net/ConnectionPool.java index 73c6ba96b..5cd8c1c8c 100644 --- a/scouter.client/src/scouter/client/net/ConnectionPool.java +++ b/scouter.client/src/scouter/client/net/ConnectionPool.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015 the original author or authors. * @https://github.com/scouter-project/scouter * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,9 +21,9 @@ public class ConnectionPool { - private final static int POOL_SIZE = 3; + private static final int POOL_SIZE = 3; - private LinkedList pool = new LinkedList(); + private final LinkedList pool = new LinkedList<>(); public int size() { return pool.size(); @@ -41,7 +41,7 @@ void put(TcpProxy t) { } public void closeAll() { - while (pool.size() > 0) { + while (!pool.isEmpty()) { pool.removeFirst().close(); } } diff --git a/scouter.client/src/scouter/client/net/INetReader.java b/scouter.client/src/scouter/client/net/INetReader.java index efba0ce0c..67b3fa00e 100644 --- a/scouter.client/src/scouter/client/net/INetReader.java +++ b/scouter.client/src/scouter/client/net/INetReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015 the original author or authors. * @https://github.com/scouter-project/scouter * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,5 +23,5 @@ public interface INetReader { - public void process(DataInputX in) throws IOException; + void process(DataInputX in) throws IOException; } diff --git a/scouter.client/src/scouter/client/net/TcpProxy.java b/scouter.client/src/scouter/client/net/TcpProxy.java index 0b5e766fc..690580730 100644 --- a/scouter.client/src/scouter/client/net/TcpProxy.java +++ b/scouter.client/src/scouter/client/net/TcpProxy.java @@ -45,7 +45,7 @@ protected TcpProxy(int serverId) { public static synchronized TcpProxy getTcpProxy(int serverId) { Server server = ServerManager.getInstance().getServer(serverId); - if (server == null || server.isOpen() == false || server.isConnected() == false) { + if (server == null || !server.isOpen() || !server.isConnected()) { return new DummyTcpProxy(); } ConnectionPool pool = server.getConnectionPool(); @@ -75,14 +75,14 @@ public Server getServer() { } public synchronized void open() { - if (tcp.isSessionOk() == false) { + if (!tcp.isSessionOk()) { boolean socksLogin =ServerPrefUtil.isSocksLogin(this.getServer().getIp()+":"+this.getServer().getPort()); tcp.open(this.server.getId(),socksLogin); } } public synchronized void open(boolean socksLogin) { - if (tcp.isSessionOk() == false) { + if (!tcp.isSessionOk()) { tcp.open(this.server.getId(), socksLogin); } } @@ -95,11 +95,11 @@ public synchronized void close() { protected void finalize() throws Throwable { tcp.close(); - }; + } public Pack getSingle(String cmd, Pack param) { List values = process(cmd, param); - if (values == null || values.size() == 0) + if (values == null || values.isEmpty()) return null; else return values.get(0); @@ -107,31 +107,27 @@ public Pack getSingle(String cmd, Pack param) { public List process(String cmd, Pack param) { - final List list = new ArrayList(); - process(cmd, param, new INetReader() { - public void process(DataInputX in) throws IOException { - Pack p = in.readPack(); - list.add(p); - } + final List list = new ArrayList<>(); + process(cmd, param, in -> { + Pack p = in.readPack(); + list.add(p); }); return list; } public Value getSingleValue(String cmd, Pack param) { List values = processValues(cmd, param); - if (values == null || values.size() == 0) + if (values == null || values.isEmpty()) return null; else return values.get(0); } public List processValues(String cmd, Pack param) { - final List list = new ArrayList(); - process(cmd, param, new INetReader() { - public void process(DataInputX in) throws IOException { - Value v = in.readValue(); - list.add(v); - } + final List list = new ArrayList<>(); + process(cmd, param, in -> { + Value v = in.readValue(); + list.add(v); }); return list; } @@ -145,7 +141,7 @@ public boolean isValid() { public synchronized void process(String cmd, Object param, INetReader recv) { open(); - if (tcp.isSessionOk() == false) { + if (!tcp.isSessionOk()) { return; } @@ -178,7 +174,7 @@ public synchronized void process(String cmd, Object param, INetReader recv) { } public synchronized void sendClose() { - if (tcp.isSessionOk() == false) { + if (!tcp.isSessionOk()) { return; } DataOutputX out = tcp.getOutput(); @@ -190,11 +186,11 @@ public synchronized void sendClose() { } public static MapPack loginProxy(int serverId, MapPack param) throws IOException { - Boolean socksLogin = param.getBoolean("isSocks"); + boolean socksLogin = param.getBoolean("isSocks"); TcpProxy proxy = new TcpProxy(serverId); proxy.open(socksLogin); - if (proxy.isValid() == false) { + if (!proxy.isValid()) { return null; } param.put("ip", proxy.getLocalInetAddress().getHostAddress()); diff --git a/scouter.client/src/scouter/client/popup/LoginDialog2.java b/scouter.client/src/scouter/client/popup/LoginDialog2.java index b19951189..8dacb7521 100644 --- a/scouter.client/src/scouter/client/popup/LoginDialog2.java +++ b/scouter.client/src/scouter/client/popup/LoginDialog2.java @@ -1,8 +1,8 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015 the original author or authors. * @https://github.com/scouter-project/scouter * - * Licensed under the Apache License, Version 2.0 (the "License"); + * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * @@ -12,44 +12,31 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License. + * limitations under the License. * */ package scouter.client.popup; -import java.util.ArrayList; - import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.events.FocusEvent; -import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.layout.FormData; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.List; -import org.eclipse.swt.widgets.Monitor; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - +import org.eclipse.swt.widgets.*; import scouter.Version; import scouter.client.net.LoginMgr; import scouter.client.net.LoginResult; +import scouter.client.popup.event.AbstractFocusGainedListener; import scouter.client.preferences.ServerPrefUtil; import scouter.client.server.Server; import scouter.client.server.ServerManager; import scouter.client.util.UIUtil; import scouter.net.NetConstants; import scouter.util.StringUtil; +import scouter.util.ThreadUtil; public class LoginDialog2 extends Dialog { public static final String ID = LoginDialog2.class.getName(); @@ -62,21 +49,27 @@ public class LoginDialog2 extends Dialog { public static final int TYPE_OPEN_SERVER = 993; public static final int TYPE_EDIT_SERVER = 994; - ArrayList storeAddr = new ArrayList(); - FormData data; - Combo addrCombo, socksAddrCombo; - Text id, pass; - Label idLabel, passLabel; + Combo addrCombo; + Combo socksAddrCombo; + + Text idText; + Text passText; + + Label idLabel; + Label passLabel; - List list; + List messageList; + + Button autoLoginCheck; + Button secureCheck; + Button sock5Check; - Button autoLoginCheck, secureCheck, sock5Check; boolean autoLogin; boolean secureLogin = true; - boolean sock5Login = false; + boolean sock5Login; - String address = null; - String socksAddress = null; + String address; + String socksAddress; public LoginDialog2(Shell shell, ILoginDialog callback, int openType, String address, String socksAddress) { super(shell); @@ -87,7 +80,7 @@ public LoginDialog2(Shell shell, ILoginDialog callback, int openType, String add this.socksAddress = socksAddress; this.sock5Login = StringUtil.isNotEmpty(socksAddress); } - + @Override protected Control createDialogArea(Composite parent) { @@ -115,20 +108,17 @@ protected Control createDialogArea(Composite parent) { idLabel.setText("ID :"); idLabel.setLayoutData(UIUtil.formData(null, -1, addrCombo, 10, null, -1, null, -1, 100)); - id = new Text(parentGroup, SWT.SINGLE | SWT.BORDER); - id.setLayoutData(UIUtil.formData(idLabel, 5, addrCombo, 7, 100, -5, null, -1)); - id.addFocusListener(new FocusListener() { - public void focusLost(FocusEvent e) { - } - + idText = new Text(parentGroup, SWT.SINGLE | SWT.BORDER); + idText.setLayoutData(UIUtil.formData(idLabel, 5, addrCombo, 7, 100, -5, null, -1)); + idText.addFocusListener(new AbstractFocusGainedListener() { public void focusGained(FocusEvent e) { - id.selectAll(); + idText.selectAll(); } }); passLabel = new Label(parentGroup, SWT.RIGHT); passLabel.setText("Password :"); - passLabel.setLayoutData(UIUtil.formData(null, -1, id, 10, null, -1, null, -1, 100)); + passLabel.setLayoutData(UIUtil.formData(null, -1, idText, 10, null, -1, null, -1, 100)); createPasswordInput(parentGroup); @@ -137,11 +127,7 @@ public void focusGained(FocusEvent e) { autoLoginCheck.setLayoutData(UIUtil.formData(null, -1, passLabel, 10, 100, -5, null, -1)); autoLoginCheck.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - if (autoLoginCheck.getSelection()) { - autoLogin = true; - } else { - autoLogin = false; - } + autoLogin = autoLoginCheck.getSelection(); } }); autoLoginCheck.setSelection(false); @@ -152,15 +138,11 @@ public void widgetSelected(SelectionEvent e) { secureCheck.setLayoutData(UIUtil.formData(null, -1, passLabel, 10, autoLoginCheck, -5, null, -1)); secureCheck.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - if (secureCheck.getSelection()) { - secureLogin = true; - } else { - secureLogin = false; - } + secureLogin = secureCheck.getSelection(); } }); secureCheck.setSelection(true); - + // console group final Group socksGroup = new Group(comp, SWT.NONE); socksGroup.setText("SOCKS5"); @@ -173,11 +155,7 @@ public void widgetSelected(SelectionEvent e) { sock5Check.setLayoutData(UIUtil.formData(0, 0, 0, 5, 100, -5, null, -1)); sock5Check.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - if (sock5Check.getSelection()) { - sock5Login = true; - } else { - sock5Login = false; - } + sock5Login = sock5Check.getSelection(); socksAddrCombo.setEnabled(sock5Login); } }); @@ -198,43 +176,42 @@ public void widgetSelected(SelectionEvent e) { socksAddrCombo.setEnabled(sock5Login); socksAddrCombo.setLayoutData(UIUtil.formData(socks5AddrLabel, 5, sock5Check, 10, 100, -5, null, -1, 150)); - + // console group final Group consoleGroup = new Group(comp, SWT.NONE); consoleGroup.setLayout(UIUtil.formLayout(5, 5)); consoleGroup.setLayoutData(UIUtil.formData(null, -1, socksGroup, 0, null, -1, null, -1)); - + // connection status console - list = new List(consoleGroup, SWT.NONE); - list.setLayoutData(UIUtil.formData(0, 5, 0, 5, 100, -5, null, -1, 250, 60)); - //list.setLayoutData(UIUtil.formData(0, 5, socks5AddrLabel, 10, 100, -5, null, -1, -1, 60)); - list.add("Type your authentication info..."); - list.select(list.getItemCount() - 1); - list.showSelection(); + messageList = new List(consoleGroup, SWT.NONE); + messageList.setLayoutData(UIUtil.formData(0, 5, 0, 5, 100, -5, null, -1, 250, 60)); + messageList.add("Type your authentication info..."); + messageList.select(messageList.getItemCount() - 1); + messageList.showSelection(); if (StringUtil.isNotEmpty(this.address)) { addrCombo.setText(address); Server server = ServerManager.getInstance().getServer(address); if (server != null && StringUtil.isNotEmpty(server.getUserId())) { - id.setText(server.getUserId()); + idText.setText(server.getUserId()); secureCheck.setSelection(server.isSecureMode()); } autoLoginCheck.setSelection(ServerPrefUtil.isAutoLoginAddress(address)); } else if (openType == TYPE_STARTUP) { addrCombo.setText("127.0.0.1:" + NetConstants.SERVER_TCP_PORT); - id.setText("admin"); + idText.setText("admin"); } - + if (StringUtil.isNotEmpty(this.socksAddress)) { socksAddrCombo.setText(socksAddress); sock5Check.setSelection(true); Server server = ServerManager.getInstance().getServer(address); if (server != null && StringUtil.isNotEmpty(server.getUserId())) { - id.setText(server.getUserId()); + idText.setText(server.getUserId()); secureCheck.setSelection(server.isSecureMode()); } autoLoginCheck.setSelection(ServerPrefUtil.isAutoLoginAddress(address)); - } + } return comp; } @@ -277,16 +254,13 @@ protected boolean isResizable() { } private void createPasswordInput(Composite parentGroup) { - pass = new Text(parentGroup, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD); - pass.addFocusListener(new FocusListener() { - public void focusLost(FocusEvent e) { - } - + passText = new Text(parentGroup, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD); + passText.addFocusListener(new AbstractFocusGainedListener() { public void focusGained(FocusEvent e) { - pass.selectAll(); + passText.selectAll(); } }); - pass.setLayoutData(UIUtil.formData(passLabel, 5, id, 7, 100, -5, null, -1)); + passText.setLayoutData(UIUtil.formData(passLabel, 5, idText, 7, 100, -5, null, -1)); } @Override @@ -308,22 +282,22 @@ public boolean loginInToServer(String address, String socksAddress) { try { String ip = null; String port = null; - if (address.contains(":") == false) { + if (!address.contains(":")) { address = address.concat(":" + NetConstants.SERVER_TCP_PORT); } - String addr[] = address.split(":"); + String[] addr = address.split(":"); ip = addr[0]; port = addr[1]; - - String socksIp = null; - String socksPort = null; - if (socksAddress.contains(":") == false) { + + String socksIp; + String socksPort; + if (!socksAddress.contains(":")) { errMsg("Check SOCKS Address"); } - String socksAddr[] = socksAddress.split(":"); + String[] socksAddr = socksAddress.split(":"); socksIp = socksAddr[0]; socksPort = socksAddr[1]; - + msg("Log in..." + address); ServerManager srvMgr = ServerManager.getInstance(); @@ -332,7 +306,7 @@ public boolean loginInToServer(String address, String socksAddress) { msg(""); return false; } - + server = new Server(ip, port,null, socksIp, socksPort); if (srvMgr.getServer(server.getId()) == null) { @@ -344,12 +318,12 @@ public boolean loginInToServer(String address, String socksAddress) { server.setSocksPort(socksPort == null ? 0 : Integer.parseInt(socksPort)); } - LoginResult result = LoginMgr.login(server.getId(), id.getText(), pass.getText()); + LoginResult result = LoginMgr.login(server.getId(), idText.getText(), passText.getText()); if (result.success) { msg("Successfully log in to " + address); ServerPrefUtil.addServerAddr(address); if (autoLogin) { - ServerPrefUtil.addAutoLoginServer(address, id.getText(), server.getPassword(), socksAddress); + ServerPrefUtil.addAutoLoginServer(address, idText.getText(), server.getPassword(), socksAddress); } else { ServerPrefUtil.removeAutoLoginServer(address); } @@ -358,14 +332,10 @@ public boolean loginInToServer(String address, String socksAddress) { if (callback != null) { callback.loginSuccess(address, server.getId()); } - try { - Thread.sleep(100); - } catch (InterruptedException e) { - e.printStackTrace(); - } + ThreadUtil.sleep(100L); return true; } else { - if (existServer == false) { + if (!existServer) { ServerManager.getInstance().removeServer(server.getId()); } errMsg(result.getErrorMessage()); @@ -373,19 +343,19 @@ public boolean loginInToServer(String address, String socksAddress) { return false; } } catch (Exception e) { - if (server != null && existServer == false) { + if (server != null && !existServer) { ServerManager.getInstance().removeServer(server.getId()); } e.printStackTrace(); - MessageDialog.openError(shell, "Error", "error occured:" + e.getMessage()); + MessageDialog.openError(shell, "Error", "error occurred:" + e.getMessage()); } return false; } private void msg(String msg) { - list.add(msg); - list.select(list.getItemCount() - 1); - list.showSelection(); + messageList.add(msg); + messageList.select(messageList.getItemCount() - 1); + messageList.showSelection(); } private void errMsg(String msg) { @@ -395,5 +365,4 @@ private void errMsg(String msg) { public interface ILoginDialog { void loginSuccess(String serverAddr, int serverId); } - -} +} \ No newline at end of file diff --git a/scouter.client/src/scouter/client/popup/event/AbstractFocusGainedListener.java b/scouter.client/src/scouter/client/popup/event/AbstractFocusGainedListener.java new file mode 100644 index 000000000..e107316a6 --- /dev/null +++ b/scouter.client/src/scouter/client/popup/event/AbstractFocusGainedListener.java @@ -0,0 +1,11 @@ +package scouter.client.popup.event; + +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; + +public abstract class AbstractFocusGainedListener implements FocusListener { + @Override + public final void focusLost(FocusEvent focusEvent) { + // do nothing. + } +} diff --git a/scouter.client/src/scouter/client/popup/event/AbstractFocusLostListener.java b/scouter.client/src/scouter/client/popup/event/AbstractFocusLostListener.java new file mode 100644 index 000000000..031591f28 --- /dev/null +++ b/scouter.client/src/scouter/client/popup/event/AbstractFocusLostListener.java @@ -0,0 +1,11 @@ +package scouter.client.popup.event; + +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; + +public abstract class AbstractFocusLostListener implements FocusListener { + @Override + public final void focusGained(FocusEvent focusEvent) { + // do nothing. + } +} diff --git a/scouter.client/src/scouter/client/server/ServerManager.java b/scouter.client/src/scouter/client/server/ServerManager.java index 6beb7d55e..23b4c9eb1 100644 --- a/scouter.client/src/scouter/client/server/ServerManager.java +++ b/scouter.client/src/scouter/client/server/ServerManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015 the original author or authors. * @https://github.com/scouter-project/scouter * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -28,19 +28,21 @@ import scouter.util.LinkedMap; import scouter.util.ThreadUtil; + public class ServerManager extends Thread { private static volatile ServerManager instance; - private LinkedMap serverMap = new LinkedMap(); + private final LinkedMap serverMap = new LinkedMap<>(); public static ServerManager getInstance() { if (instance == null) { synchronized (ServerManager.class) { if (instance == null) { - instance = new ServerManager(); - instance.setName(ThreadUtil.getName(instance)); - instance.setDaemon(true); - instance.start(); + ServerManager serverManager = new ServerManager(); + serverManager.setName(ThreadUtil.getName(serverManager)); + serverManager.setDaemon(true); + serverManager.start(); + instance = serverManager; } } } @@ -66,7 +68,7 @@ public boolean setDefaultServer(Server server) { public void run() { while (true) { syncServerTime(); - ThreadUtil.sleep(2000); + ThreadUtil.sleep(2000L); } } @@ -103,11 +105,13 @@ public Server getServer(int id) { } public Server getServer(String addr) { - String[] iport = addr.split(":"); - if (iport == null || iport.length < 2) { + if (addr == null) return null; + + String[] addrSplits = addr.split(":"); + if (addrSplits.length < 2) { return null; } - return getServer(HashUtil.hash(iport[0] + iport[1])); + return getServer(HashUtil.hash(addrSplits[0] + addrSplits[1])); } public void removeServer(int serverId) { @@ -119,7 +123,7 @@ public void removeServer(int serverId) { } public Set getOpenServerList() { - Set keySet = new HashSet(); + Set keySet = new HashSet<>(); Enumeration servers = serverMap.values(); while (servers.hasMoreElements()) { Server server = servers.nextElement(); From 7e67ce24dc3079d5d788b4a63c6865cb6aa2cfad Mon Sep 17 00:00:00 2001 From: Gun Lee Date: Mon, 25 Oct 2021 14:53:53 +0900 Subject: [PATCH 04/20] for java6 --- .gitignore | 4 +++ .../agent/asm/weaver/WeaverClassASM.java | 2 +- .../scouter/weaver/TraceSupportWeave.java | 34 +++++++++---------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index fb5ac5cd1..8e857e2c7 100644 --- a/.gitignore +++ b/.gitignore @@ -41,6 +41,10 @@ scouter.server.boot/database/* scouter.document/.project +build_client_local.sh +build_package_local.sh + + ### Vim template [._]*.s[a-w][a-z] [._]s[a-w][a-z] diff --git a/scouter.agent.java/src/main/java/scouter/agent/asm/weaver/WeaverClassASM.java b/scouter.agent.java/src/main/java/scouter/agent/asm/weaver/WeaverClassASM.java index 2ee2e599b..8cd29c97d 100644 --- a/scouter.agent.java/src/main/java/scouter/agent/asm/weaver/WeaverClassASM.java +++ b/scouter.agent.java/src/main/java/scouter/agent/asm/weaver/WeaverClassASM.java @@ -36,7 +36,7 @@ */ public class WeaverClassASM implements IASM, Opcodes { - public static Set weaveMethodNames = new HashSet<>(); + public static Set weaveMethodNames = new HashSet(); @Override public ClassVisitor transform(ClassVisitor cv, String className, ClassDesc classDesc) { diff --git a/scouter.agent.java/src/main/java/scouter/weaver/TraceSupportWeave.java b/scouter.agent.java/src/main/java/scouter/weaver/TraceSupportWeave.java index 3a49521bb..c17d66af6 100644 --- a/scouter.agent.java/src/main/java/scouter/weaver/TraceSupportWeave.java +++ b/scouter.agent.java/src/main/java/scouter/weaver/TraceSupportWeave.java @@ -97,32 +97,32 @@ public static Object addMessageProfileOnTheSameThread(String className, String m } public static Object addHashedMessageProfileByCtx(String className, String methodName, String methodDesc, Object this1, Object[] arg) { - TraceSupport.addHashedMessageProfileByCtx(arg[0], (String)arg[1], (int)arg[2], (int)arg[3]); + TraceSupport.addHashedMessageProfileByCtx(arg[0], (String)arg[1], (Integer)arg[2], (Integer)arg[3]); return null; } public static Object addHashedMessageProfileByCustomTxid(String className, String methodName, String methodDesc, Object this1, Object[] arg) { - TraceSupport.addHashedMessageProfileByCustomTxid((String)arg[0], (String)arg[1], (int)arg[2], (int)arg[3]); + TraceSupport.addHashedMessageProfileByCustomTxid((String)arg[0], (String)arg[1], (Integer)arg[2], (Integer)arg[3]); return null; } public static Object addHashedMessageProfileOnTheSameThread(String className, String methodName, String methodDesc, Object this1, Object[] arg) { - TraceSupport.addHashedMessageProfileOnTheSameThread((String)arg[0], (int)arg[1], (int)arg[2]); + TraceSupport.addHashedMessageProfileOnTheSameThread((String)arg[0], (Integer)arg[1], (Integer)arg[2]); return null; } public static Object addParameterizedMessageProfileByCtx(String className, String methodName, String methodDesc, Object this1, Object[] arg) { - TraceSupport.addParameterizedMessageProfileByCtx(arg[0], (String)arg[1], (byte)arg[2], (int)arg[3], (String[])arg[4]); + TraceSupport.addParameterizedMessageProfileByCtx(arg[0], (String)arg[1], (Byte)arg[2], (Integer)arg[3], (String[])arg[4]); return null; } public static Object addParameterizedMessageProfileByCustomTxid(String className, String methodName, String methodDesc, Object this1, Object[] arg) { - TraceSupport.addParameterizedMessageProfileByCustomTxid((String)arg[0], (String)arg[1], (byte)arg[2], (int)arg[3], (String[])arg[4]); + TraceSupport.addParameterizedMessageProfileByCustomTxid((String)arg[0], (String)arg[1], (Byte)arg[2], (Integer)arg[3], (String[])arg[4]); return null; } public static Object addParameterizedMessageProfileOnTheSameThread(String className, String methodName, String methodDesc, Object this1, Object[] arg) { - TraceSupport.addParameterizedMessageProfileOnTheSameThread((String)arg[0], (byte)arg[1], (int)arg[2], (String[])arg[3]); + TraceSupport.addParameterizedMessageProfileOnTheSameThread((String)arg[0], (Byte)arg[1], (Integer)arg[2], (String[])arg[3]); return null; } @@ -153,48 +153,48 @@ public static Object linkCustomTxidByCtx(String className, String methodName, S //xlog info setters public static Object setXlogServiceValue(String className, String methodName, String methodDesc, Object this1, Object[] arg) { - TraceSupport.setXlogServiceValue((long)arg[0], (String)arg[1]); + TraceSupport.setXlogServiceValue((Long)arg[0], (String)arg[1]); return null; } public static Object setXlogIpValue(String className, String methodName, String methodDesc, Object this1, Object[] arg) { - TraceSupport.setXlogIpValue((long)arg[0], (String)arg[1]); + TraceSupport.setXlogIpValue((Long)arg[0], (String)arg[1]); return null; } public static Object setXlogUaValue(String className, String methodName, String methodDesc, Object this1, Object[] arg) { - TraceSupport.setXlogUaValue((long)arg[0], (String)arg[1]); + TraceSupport.setXlogUaValue((Long)arg[0], (String)arg[1]); return null; } public static Object setXlogErrorValue(String className, String methodName, String methodDesc, Object this1, Object[] arg) { - TraceSupport.setXlogErrorValue((long)arg[0], (String)arg[1]); + TraceSupport.setXlogErrorValue((Long)arg[0], (String)arg[1]); return null; } public static Object setXlogLoginValue(String className, String methodName, String methodDesc, Object this1, Object[] arg) { - TraceSupport.setXlogLoginValue((long)arg[0], (String)arg[1]); + TraceSupport.setXlogLoginValue((Long)arg[0], (String)arg[1]); return null; } public static Object setXlogDescValue(String className, String methodName, String methodDesc, Object this1, Object[] arg) { - TraceSupport.setXlogDescValue((long)arg[0], (String)arg[1]); + TraceSupport.setXlogDescValue((Long)arg[0], (String)arg[1]); return null; } public static Object setXlogText1Value(String className, String methodName, String methodDesc, Object this1, Object[] arg) { - TraceSupport.setXlogText1Value((long)arg[0], (String)arg[1]); + TraceSupport.setXlogText1Value((Long)arg[0], (String)arg[1]); return null; } public static Object setXlogText2Value(String className, String methodName, String methodDesc, Object this1, Object[] arg) { - TraceSupport.setXlogText2Value((long)arg[0], (String)arg[1]); + TraceSupport.setXlogText2Value((Long)arg[0], (String)arg[1]); return null; } public static Object setXlogText3Value(String className, String methodName, String methodDesc, Object this1, Object[] arg) { - TraceSupport.setXlogText3Value((long)arg[0], (String)arg[1]); + TraceSupport.setXlogText3Value((Long)arg[0], (String)arg[1]); return null; } public static Object setXlogText4Value(String className, String methodName, String methodDesc, Object this1, Object[] arg) { - TraceSupport.setXlogText4Value((long)arg[0], (String)arg[1]); + TraceSupport.setXlogText4Value((Long)arg[0], (String)arg[1]); return null; } public static Object setXlogText5Value(String className, String methodName, String methodDesc, Object this1, Object[] arg) { - TraceSupport.setXlogText5Value((long)arg[0], (String)arg[1]); + TraceSupport.setXlogText5Value((Long)arg[0], (String)arg[1]); return null; } From f937ce07eae96a1665863030ad3a1b3a0aca725a Mon Sep 17 00:00:00 2001 From: hwanyseo Date: Thu, 4 Nov 2021 10:53:27 +0900 Subject: [PATCH 05/20] When multiple objects are connected, unable to display information in viewer for CUBRID. --- .../scouter/client/cubrid/ActiveDbInfo.java | 102 +++++++++++++----- .../actions/AddLongPeriodCalendarDialog.java | 10 +- .../actions/AddLongTransactionList.java | 10 +- .../cubrid/actions/AddRealTimeDialog.java | 10 +- .../actions/AddShortPeriodCalendarDialog.java | 8 +- .../cubrid/actions/MultiViewDialogAction.java | 6 +- .../cubrid/actions/OpenOtherViewAction.java | 7 +- .../views/CubridLongTransactionList.java | 23 ++-- .../cubrid/views/CubridRealtimeDmlView.java | 15 +-- .../cubrid/views/CubridServerInfoView.java | 24 +++-- .../CubridSingleDailyPeriodMultiView.java | 24 ++--- .../views/CubridSinglePeriodMultiView.java | 18 ++-- .../views/CubridSingleRealTimeMultiView.java | 26 +++-- .../cubrid/views/CubridSpaceDbView.java | 23 ++-- .../src/scouter/client/util/MenuUtil.java | 1 + 15 files changed, 208 insertions(+), 99 deletions(-) diff --git a/scouter.client/src/scouter/client/cubrid/ActiveDbInfo.java b/scouter.client/src/scouter/client/cubrid/ActiveDbInfo.java index b4016cb13..23c55b72c 100755 --- a/scouter.client/src/scouter/client/cubrid/ActiveDbInfo.java +++ b/scouter.client/src/scouter/client/cubrid/ActiveDbInfo.java @@ -27,7 +27,7 @@ public class ActiveDbInfo { private static ActiveDbInfo instance; - private static Hashtable dbInfo = new Hashtable<>(); + private static Hashtable > ServerInfo = new Hashtable<>(); public synchronized static ActiveDbInfo getInstance() { if (instance == null) { @@ -39,58 +39,112 @@ public synchronized static ActiveDbInfo getInstance() { private ActiveDbInfo() { } - public ArrayList getDbList() { - ArrayList dbList = new ArrayList<>(); - for (String dbName : dbInfo.keySet()) { - dbList.add(dbName); + public void addServerInfo(int serverId) { + if (ServerInfo.get(serverId) == null) { + Hashtable dbInfo = new Hashtable<>(); + ServerInfo.put(serverId, dbInfo); } + } - return dbList; + public ArrayList getDbList(int serverId) { + ArrayList dbList = new ArrayList<>(); + Hashtable dbInfo = ServerInfo.get(serverId); + + if (dbInfo != null) { + for (String dbName : dbInfo.keySet()) { + dbList.add(dbName); + } + + return dbList; + } + + return null; } - public Set keySet() { - return dbInfo.keySet(); + public Set keySet(int serverId) { + Hashtable dbInfo = ServerInfo.get(serverId); + + if (dbInfo != null) { + return dbInfo.keySet(); + } + + return null; } - public String getObjectName(String dbname) { - return dbInfo.get(dbname); + public String getObjectName(int serverId, String dbname) { + Hashtable dbInfo = ServerInfo.get(serverId); + + if (dbInfo != null) { + return String.valueOf(dbInfo.get(dbname)); + } + + return null; } - public int getObjectHash(String dbname) { - if (dbInfo.get(dbname) != null) { + public int getObjectHash(int serverId, String dbname) { + Hashtable dbInfo = ServerInfo.get(serverId); + + if (dbInfo != null && dbInfo.get(dbname) != null) { return HashUtil.hash(dbInfo.get(dbname)); } else { return -1; } } - public void setActiveDBInfo(Hashtable info) { - dbInfo = info; + public void setActiveDBInfo(int serverId, Hashtable info) { + Hashtable dbInfo = ServerInfo.get(serverId); + + if (dbInfo != null) { + dbInfo = info; + } } - public boolean isEmpty() { - return dbInfo.isEmpty(); + public boolean isEmpty(int serverId) { + Hashtable dbInfo = ServerInfo.get(serverId); + + if (dbInfo != null) { + return dbInfo.isEmpty(); + } else { + return true; + } } - public int size() { - return dbInfo.size(); + public int size(int serverId) { + Hashtable dbInfo = ServerInfo.get(serverId); + + if (dbInfo != null) { + return dbInfo.size(); + } else { + return 0; + } } - public void clear() { - dbInfo.clear(); + public void clear(int serverId) { + Hashtable dbInfo = ServerInfo.get(serverId); + + if (dbInfo != null) { + dbInfo.clear(); + } } - public void put(String dbName, String ObjectName) { - dbInfo.put(dbName, ObjectName); + public void put(int serverId, String dbName, String ObjectName) { + Hashtable dbInfo = ServerInfo.get(serverId); + if (dbInfo != null) { + dbInfo.put(dbName, ObjectName); + } } - public Hashtable getActiveDBInfo() { + public Hashtable getActiveDBInfo(int serverId) { + Hashtable dbInfo = ServerInfo.get(serverId); return dbInfo; } - public boolean equals(Hashtable other) { + public boolean equals(int serverId, Hashtable other) { if (other == null) return false; + + Hashtable dbInfo = ServerInfo.get(serverId); + if (dbInfo == null) return false; diff --git a/scouter.client/src/scouter/client/cubrid/actions/AddLongPeriodCalendarDialog.java b/scouter.client/src/scouter/client/cubrid/actions/AddLongPeriodCalendarDialog.java index 3aa2f4b67..a15a23639 100755 --- a/scouter.client/src/scouter/client/cubrid/actions/AddLongPeriodCalendarDialog.java +++ b/scouter.client/src/scouter/client/cubrid/actions/AddLongPeriodCalendarDialog.java @@ -45,13 +45,15 @@ public class AddLongPeriodCalendarDialog { private final Display display; + private final int serverId; private final IAddSingleLongPeriodDialog callback; - + Combo dbListCombo; Combo counterCombo; - public AddLongPeriodCalendarDialog(Display display, IAddSingleLongPeriodDialog callback) { + public AddLongPeriodCalendarDialog(Display display, int serverId, IAddSingleLongPeriodDialog callback) { this.display = display; + this.serverId = serverId; this.callback = callback; } @@ -222,8 +224,8 @@ public interface IAddSingleLongPeriodDialog { private void dbLoad() { ActiveDbInfo activeDBList = ActiveDbInfo.getInstance(); - if (!activeDBList.isEmpty()) { - for (String dbName : activeDBList.keySet()) { + if (!activeDBList.isEmpty(serverId)) { + for (String dbName : activeDBList.keySet(serverId)) { dbListCombo.add(dbName); } } else { diff --git a/scouter.client/src/scouter/client/cubrid/actions/AddLongTransactionList.java b/scouter.client/src/scouter/client/cubrid/actions/AddLongTransactionList.java index fbb9d2147..950c2f6c8 100755 --- a/scouter.client/src/scouter/client/cubrid/actions/AddLongTransactionList.java +++ b/scouter.client/src/scouter/client/cubrid/actions/AddLongTransactionList.java @@ -37,12 +37,14 @@ public class AddLongTransactionList { private final Display display; private final IAddLongTransactionList callback; - + private final int serverId; + Combo dbListCombo; - public AddLongTransactionList(Display display, IAddLongTransactionList callback) { + public AddLongTransactionList(Display display, int serverId, IAddLongTransactionList callback) { this.display = display; this.callback = callback; + this.serverId = serverId; } public void show(Point p) { @@ -124,8 +126,8 @@ public interface IAddLongTransactionList { private void dbLoad() { ActiveDbInfo activeDBList = ActiveDbInfo.getInstance(); - if (!activeDBList.isEmpty()) { - for (String dbName : activeDBList.keySet()) { + if (!activeDBList.isEmpty(serverId)) { + for (String dbName : activeDBList.keySet(serverId)) { dbListCombo.add(dbName); } } else { diff --git a/scouter.client/src/scouter/client/cubrid/actions/AddRealTimeDialog.java b/scouter.client/src/scouter/client/cubrid/actions/AddRealTimeDialog.java index 3ebdcdcc7..a0dc4d8d3 100755 --- a/scouter.client/src/scouter/client/cubrid/actions/AddRealTimeDialog.java +++ b/scouter.client/src/scouter/client/cubrid/actions/AddRealTimeDialog.java @@ -43,14 +43,16 @@ public class AddRealTimeDialog { private final Display display; private final IAddSingleRealTimeDialog callback; - + private int serverId; + Combo dbListCombo; Combo counterCombo; Combo timeRangeCombo; - public AddRealTimeDialog(Display display, IAddSingleRealTimeDialog callback) { + public AddRealTimeDialog(Display display, int serverId, IAddSingleRealTimeDialog callback) { this.display = display; this.callback = callback; + this.serverId = serverId; } public void show(Point p) { @@ -189,8 +191,8 @@ public interface IAddSingleRealTimeDialog { private void dbLoad() { ActiveDbInfo activeDBList = ActiveDbInfo.getInstance(); - if (!activeDBList.isEmpty()) { - for (String dbName : activeDBList.keySet()) { + if (!activeDBList.isEmpty(serverId)) { + for (String dbName : activeDBList.keySet(serverId)) { dbListCombo.add(dbName); } } else { diff --git a/scouter.client/src/scouter/client/cubrid/actions/AddShortPeriodCalendarDialog.java b/scouter.client/src/scouter/client/cubrid/actions/AddShortPeriodCalendarDialog.java index e7d7883ec..eae21cdad 100755 --- a/scouter.client/src/scouter/client/cubrid/actions/AddShortPeriodCalendarDialog.java +++ b/scouter.client/src/scouter/client/cubrid/actions/AddShortPeriodCalendarDialog.java @@ -47,13 +47,15 @@ public class AddShortPeriodCalendarDialog { private final Display display; private final IAddSingleShortPeriodDialog callback; + private final int serverId; Combo dbListCombo; Combo counterCombo; - public AddShortPeriodCalendarDialog(Display display, IAddSingleShortPeriodDialog callback) { + public AddShortPeriodCalendarDialog(Display display, int serverId, IAddSingleShortPeriodDialog callback) { this.display = display; this.callback = callback; + this.serverId = serverId; } public void show(Point p, long stime, long etime) { @@ -368,8 +370,8 @@ public interface IAddSingleShortPeriodDialog { private void dbLoad() { ActiveDbInfo activeDBList = ActiveDbInfo.getInstance(); - if (!activeDBList.isEmpty()) { - for (String dbName : activeDBList.keySet()) { + if (!activeDBList.isEmpty(serverId)) { + for (String dbName : activeDBList.keySet(serverId)) { dbListCombo.add(dbName); } } else { diff --git a/scouter.client/src/scouter/client/cubrid/actions/MultiViewDialogAction.java b/scouter.client/src/scouter/client/cubrid/actions/MultiViewDialogAction.java index fa1ea2de8..5938b47d3 100755 --- a/scouter.client/src/scouter/client/cubrid/actions/MultiViewDialogAction.java +++ b/scouter.client/src/scouter/client/cubrid/actions/MultiViewDialogAction.java @@ -49,7 +49,7 @@ public MultiViewDialogAction(IWorkbenchWindow window, int serverId, CubridTypePe public void run() { if (periodType == CubridTypePeriod.REALTIME) { - AddRealTimeDialog dialog = new AddRealTimeDialog(window.getShell().getDisplay(), + AddRealTimeDialog dialog = new AddRealTimeDialog(window.getShell().getDisplay(), serverId, new AddRealTimeDialog.IAddSingleRealTimeDialog() { @Override public void onPressedOk(String dbName, CubridSingleItem viewType, long timeRange) { @@ -70,7 +70,7 @@ public void onPressedCancel() { dialog.show(); } else if (periodType == CubridTypePeriod.PAST_LESS_1DAY) { - AddShortPeriodCalendarDialog dialog = new AddShortPeriodCalendarDialog(window.getShell().getDisplay(), + AddShortPeriodCalendarDialog dialog = new AddShortPeriodCalendarDialog(window.getShell().getDisplay(), serverId, new AddShortPeriodCalendarDialog.IAddSingleShortPeriodDialog() { @Override @@ -99,7 +99,7 @@ public void onPressedCancel() { TimeUtil.getCurrentTime(serverId)); } } else { - AddLongPeriodCalendarDialog dialog = new AddLongPeriodCalendarDialog(window.getShell().getDisplay(), + AddLongPeriodCalendarDialog dialog = new AddLongPeriodCalendarDialog(window.getShell().getDisplay(), serverId, new AddLongPeriodCalendarDialog.IAddSingleLongPeriodDialog() { @Override diff --git a/scouter.client/src/scouter/client/cubrid/actions/OpenOtherViewAction.java b/scouter.client/src/scouter/client/cubrid/actions/OpenOtherViewAction.java index 0c1f128a6..a580f7b55 100755 --- a/scouter.client/src/scouter/client/cubrid/actions/OpenOtherViewAction.java +++ b/scouter.client/src/scouter/client/cubrid/actions/OpenOtherViewAction.java @@ -25,6 +25,7 @@ import scouter.client.Images; import scouter.client.cubrid.views.CubridLongTransactionList; import scouter.client.cubrid.views.CubridRealtimeDmlView; +import scouter.client.cubrid.views.CubridServerInfoView; import scouter.client.cubrid.views.CubridSpaceDbView; import scouter.client.util.ConsoleProxy; import scouter.client.util.ImageUtil; @@ -53,6 +54,9 @@ public void run() { } else if (viewType.equals(OtherViewType.DML_REALTIME)) { PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(CubridRealtimeDmlView.ID, serverId + "&" + "default", IWorkbenchPage.VIEW_ACTIVATE); + } else if (viewType.equals(OtherViewType.CUBRID_SERVERINFO)) { + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(CubridServerInfoView.ID, + "" + serverId, IWorkbenchPage.VIEW_ACTIVATE); } } catch (PartInitException e) { ConsoleProxy.errorSafe(e.toString()); @@ -62,7 +66,8 @@ public void run() { public enum OtherViewType { DB_SPACE_INFO("DB Space Info"), LONG_TRANSACTION("Long Tranjaction List"), - DML_REALTIME("Realtime DML"); + DML_REALTIME("Realtime DML"), + CUBRID_SERVERINFO("CUBRID ServerInfo"); private String title; diff --git a/scouter.client/src/scouter/client/cubrid/views/CubridLongTransactionList.java b/scouter.client/src/scouter/client/cubrid/views/CubridLongTransactionList.java index 0a7636233..7778ecf5b 100755 --- a/scouter.client/src/scouter/client/cubrid/views/CubridLongTransactionList.java +++ b/scouter.client/src/scouter/client/cubrid/views/CubridLongTransactionList.java @@ -142,7 +142,12 @@ public void createPartControl(Composite parent) { private void initialLayout(Composite parent) { Server server = ServerManager.getInstance().getServer(serverId); - this.setPartName("Long Transaction List[" + server.getName() + "]"); + + if (server != null) { + this.setPartName("Long Transaction List[" + server.getName() + "]"); + } else { + this.setPartName("Long Transaction List"); + } parent.setLayout(new GridLayout(2, true)); dbListCombo = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY); @@ -343,7 +348,7 @@ private void createTableContextMenu() { manager.add(new Action("&Add LongTransaction ListView", ImageDescriptor.createFromImage(Images.add)) { public void run() { IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - AddLongTransactionList dialog = new AddLongTransactionList(window.getShell().getDisplay(), + AddLongTransactionList dialog = new AddLongTransactionList(window.getShell().getDisplay(), serverId, new AddLongTransactionList.IAddLongTransactionList() { @Override public void onPressedOk(String dbName) { @@ -644,7 +649,7 @@ public void refresh() { MapValue mv = null; if (objHashLv.size() > 0) { - if (activeDBList.isEmpty()) { + if (activeDBList.isEmpty(serverId)) { transactionList.clear(); } @@ -719,11 +724,15 @@ public void checkDBList() { return; } - if (ActiveDbInfo.getInstance().getActiveDBInfo().hashCode() == prvActiveDBHash) { + if (ActiveDbInfo.getInstance().getActiveDBInfo(serverId) == null) { + return; + } + + if (ActiveDbInfo.getInstance().getActiveDBInfo(serverId).hashCode() == prvActiveDBHash) { return; } - prvActiveDBHash = ActiveDbInfo.getInstance().getActiveDBInfo().hashCode(); + prvActiveDBHash = ActiveDbInfo.getInstance().getActiveDBInfo(serverId).hashCode(); ExUtil.exec(dbListCombo, new Runnable() { public void run() { @@ -731,10 +740,10 @@ public void run() { } }); - if (!ActiveDbInfo.getInstance().isEmpty()) { + if (!ActiveDbInfo.getInstance().isEmpty(serverId)) { ExUtil.exec(dbListCombo, new Runnable() { public void run() { - for (String dbName : ActiveDbInfo.getInstance().keySet()) { + for (String dbName : ActiveDbInfo.getInstance().keySet(serverId)) { dbListCombo.add(dbName); } dbListCombo.setEnabled(true); diff --git a/scouter.client/src/scouter/client/cubrid/views/CubridRealtimeDmlView.java b/scouter.client/src/scouter/client/cubrid/views/CubridRealtimeDmlView.java index c3b4a8086..45ce79f37 100755 --- a/scouter.client/src/scouter/client/cubrid/views/CubridRealtimeDmlView.java +++ b/scouter.client/src/scouter/client/cubrid/views/CubridRealtimeDmlView.java @@ -275,7 +275,8 @@ private void createContextMenu() { manager.add(new Action("&Add Realtime DML", ImageDescriptor.createFromImage(Images.add)) { public void run() { IWorkbenchWindow window = getSite().getWorkbenchWindow(); - AddLongTransactionList dialog = new AddLongTransactionList(getSite().getWorkbenchWindow().getShell().getDisplay(), + AddLongTransactionList dialog = new AddLongTransactionList( + getSite().getWorkbenchWindow().getShell().getDisplay(), serverId, new AddLongTransactionList.IAddLongTransactionList() { @Override public void onPressedOk(String dbName) { @@ -326,7 +327,7 @@ public void refresh() { try { MapPack param = new MapPack(); - if (ActiveDbInfo.getInstance() == null || ActiveDbInfo.getInstance().isEmpty()) { + if (ActiveDbInfo.getInstance() == null || ActiveDbInfo.getInstance().isEmpty(serverId)) { return; } @@ -338,7 +339,7 @@ public void refresh() { System.out.println("CubridRealtimeDmlView ActiveDbInfo.getInstance() is null"); } - String objectName = ActiveDbInfo.getInstance().getObjectName(selectionDB); + String objectName = ActiveDbInfo.getInstance().getObjectName(serverId, selectionDB); if (objectName == null) { return; @@ -491,11 +492,11 @@ public void checkDBList() { return; } - if (ActiveDbInfo.getInstance().getActiveDBInfo().hashCode() == prvActiveDBHash) { + if (ActiveDbInfo.getInstance().getActiveDBInfo(serverId).hashCode() == prvActiveDBHash) { return; } - prvActiveDBHash = ActiveDbInfo.getInstance().getActiveDBInfo().hashCode(); + prvActiveDBHash = ActiveDbInfo.getInstance().getActiveDBInfo(serverId).hashCode(); ExUtil.exec(canvas, new Runnable() { public void run() { @@ -503,10 +504,10 @@ public void run() { } }); - if (!ActiveDbInfo.getInstance().isEmpty()) { + if (!ActiveDbInfo.getInstance().isEmpty(serverId)) { ExUtil.exec(canvas, new Runnable() { public void run() { - for (String dbName : ActiveDbInfo.getInstance().keySet()) { + for (String dbName : ActiveDbInfo.getInstance().keySet(serverId)) { dbListCombo.add(dbName); } dbListCombo.setEnabled(true); diff --git a/scouter.client/src/scouter/client/cubrid/views/CubridServerInfoView.java b/scouter.client/src/scouter/client/cubrid/views/CubridServerInfoView.java index c82f2e2da..13481b29c 100755 --- a/scouter.client/src/scouter/client/cubrid/views/CubridServerInfoView.java +++ b/scouter.client/src/scouter/client/cubrid/views/CubridServerInfoView.java @@ -41,6 +41,8 @@ import scouter.client.model.RefreshThread; import scouter.client.model.RefreshThread.Refreshable; import scouter.client.net.TcpProxy; +import scouter.client.server.Server; +import scouter.client.server.ServerManager; import scouter.client.sorter.TableLabelSorter; import scouter.client.util.ExUtil; import scouter.client.util.TimeUtil; @@ -86,7 +88,15 @@ public void init(IViewSite site) throws PartInitException { @Override public void createPartControl(Composite parent) { - this.setPartName("CUBRID ServerInfo"); + Server server = ServerManager.getInstance().getServer(serverId); + ActiveDbInfo activeDBList = ActiveDbInfo.getInstance(); + + if (server != null) { + this.setPartName("CUBRID ServerInfo" + "[" + server.getName() + "]"); + activeDBList.addServerInfo(serverId); + } else { + this.setPartName("CUBRID ServerInfo"); + } Composite tableComposite = new Composite(parent, SWT.NONE); tableColumnLayout = new TableColumnLayout(); @@ -238,11 +248,11 @@ public void run() { MapValue mv = null; if (objHashLv.size() > 0) { - if (activeDBList.isEmpty()) { + if (activeDBList.isEmpty(serverId)) { dataList.clear(); } - for (String dbName : activeDBList.keySet()) { + for (String dbName : activeDBList.keySet(serverId)) { param.put("objHash", objHashLv); param.put("date", date); param.put("stime", stime); @@ -254,6 +264,8 @@ public void run() { sp = (StatusPack) p; mv = sp.data; responseData.add(mv); + } else { + System.out.println("CubridServerInfoView p is null"); } } } @@ -337,16 +349,16 @@ private boolean getDBList() { } prvData = mv; - activeDBList.clear(); + activeDBList.clear(serverId); for (String key : mv.keySet()) { - activeDBList.put(key, String.valueOf(mv.get(key))); + activeDBList.put(serverId, key, String.valueOf(mv.get(key))); } } else { if (prvData != null) prvData.clear(); - activeDBList.clear(); + activeDBList.clear(serverId); return false; } diff --git a/scouter.client/src/scouter/client/cubrid/views/CubridSingleDailyPeriodMultiView.java b/scouter.client/src/scouter/client/cubrid/views/CubridSingleDailyPeriodMultiView.java index eb2da5b44..8ffc07c8b 100755 --- a/scouter.client/src/scouter/client/cubrid/views/CubridSingleDailyPeriodMultiView.java +++ b/scouter.client/src/scouter/client/cubrid/views/CubridSingleDailyPeriodMultiView.java @@ -181,8 +181,8 @@ public void run() { dbListCombo.removeAll(); dbListCombo.add("BROKER_INFO"); dbListCombo.select(0); - if (ActiveDbInfo.getInstance().getDbList().isEmpty()) { - selectionDB = ActiveDbInfo.getInstance().getDbList().get(0); + if (ActiveDbInfo.getInstance().getDbList(serverId).isEmpty()) { + selectionDB = ActiveDbInfo.getInstance().getDbList(serverId).get(0); } } else { dbListCombo.removeAll(); @@ -556,11 +556,11 @@ public void checkDBList() { return; } - if (ActiveDbInfo.getInstance().getActiveDBInfo().hashCode() == prvActiveDBHash) { + if (ActiveDbInfo.getInstance().getActiveDBInfo(serverId).hashCode() == prvActiveDBHash) { return; } - prvActiveDBHash = ActiveDbInfo.getInstance().getActiveDBInfo().hashCode(); + prvActiveDBHash = ActiveDbInfo.getInstance().getActiveDBInfo(serverId).hashCode(); ExUtil.exec(canvas, new Runnable() { public void run() { @@ -568,10 +568,10 @@ public void run() { } }); - if (!ActiveDbInfo.getInstance().isEmpty()) { + if (!ActiveDbInfo.getInstance().isEmpty(serverId)) { ExUtil.exec(canvas, new Runnable() { public void run() { - for (String dbName : ActiveDbInfo.getInstance().keySet()) { + for (String dbName : ActiveDbInfo.getInstance().keySet(serverId)) { dbListCombo.add(dbName); } dbListCombo.setEnabled(true); @@ -619,8 +619,8 @@ private void longPastLoad() { } if (viewType.getInfoType() == InfoType.BROKER_INFO) { - if (!ActiveDbInfo.getInstance().getDbList().isEmpty()) { - selectionDB = ActiveDbInfo.getInstance().getDbList().get(0); + if (!ActiveDbInfo.getInstance().getDbList(serverId).isEmpty()) { + selectionDB = ActiveDbInfo.getInstance().getDbList(serverId).get(0); } else { return; } @@ -643,7 +643,7 @@ public void run() { try { MapPack param = new MapPack(); ListValue objHashLv = new ListValue(); - objHashLv.add(ActiveDbInfo.getInstance().getObjectHash(selectionDB)); + objHashLv.add(ActiveDbInfo.getInstance().getObjectHash(serverId, selectionDB)); param.put("objHash", objHashLv); param.put("counter", viewType.getCounterName()); param.put("sDate", pastSdate); @@ -717,8 +717,8 @@ public void refresh() { } if (viewType.getInfoType() == InfoType.BROKER_INFO) { - if (!ActiveDbInfo.getInstance().getDbList().isEmpty()) { - selectionDB = ActiveDbInfo.getInstance().getDbList().get(0); + if (!ActiveDbInfo.getInstance().getDbList(serverId).isEmpty()) { + selectionDB = ActiveDbInfo.getInstance().getDbList(serverId).get(0); } else { return; } @@ -740,7 +740,7 @@ public void run() { } }); - if (ActiveDbInfo.getInstance().isEmpty()) { + if (ActiveDbInfo.getInstance().isEmpty(serverId)) { return; } diff --git a/scouter.client/src/scouter/client/cubrid/views/CubridSinglePeriodMultiView.java b/scouter.client/src/scouter/client/cubrid/views/CubridSinglePeriodMultiView.java index 3bef7dd90..a5cc9ba6e 100755 --- a/scouter.client/src/scouter/client/cubrid/views/CubridSinglePeriodMultiView.java +++ b/scouter.client/src/scouter/client/cubrid/views/CubridSinglePeriodMultiView.java @@ -507,8 +507,8 @@ public void refresh() { } if (viewType.getInfoType() == InfoType.BROKER_INFO) { - if (!ActiveDbInfo.getInstance().getDbList().isEmpty()) { - selectionDB = ActiveDbInfo.getInstance().getDbList().get(0); + if (!ActiveDbInfo.getInstance().getDbList(serverId).isEmpty()) { + selectionDB = ActiveDbInfo.getInstance().getDbList(serverId).get(0); } else { return; } @@ -545,7 +545,7 @@ public void run() { try { MapPack param = new MapPack(); ListValue objHashLv = new ListValue(); - objHashLv.add(ActiveDbInfo.getInstance().getObjectHash(selectionDB)); + objHashLv.add(ActiveDbInfo.getInstance().getObjectHash(serverId, selectionDB)); param.put("objHash", objHashLv); param.put("counter", viewType.getCounterName()); v = tcp.getSingleValue(RequestCmd.CUBRID_DB_REALTIME_MULTI_DATA, param); @@ -614,11 +614,11 @@ public void checkDBList() { return; } - if (ActiveDbInfo.getInstance().getActiveDBInfo().hashCode() == prvActiveDBHash) { + if (ActiveDbInfo.getInstance().getActiveDBInfo(serverId).hashCode() == prvActiveDBHash) { return; } - prvActiveDBHash = ActiveDbInfo.getInstance().getActiveDBInfo().hashCode(); + prvActiveDBHash = ActiveDbInfo.getInstance().getActiveDBInfo(serverId).hashCode(); ExUtil.exec(canvas, new Runnable() { public void run() { @@ -626,10 +626,10 @@ public void run() { } }); - if (!ActiveDbInfo.getInstance().isEmpty()) { + if (!ActiveDbInfo.getInstance().isEmpty(serverId)) { ExUtil.exec(canvas, new Runnable() { public void run() { - for (String dbName : ActiveDbInfo.getInstance().keySet()) { + for (String dbName : ActiveDbInfo.getInstance().keySet(serverId)) { dbListCombo.add(dbName); } dbListCombo.setEnabled(true); @@ -675,12 +675,12 @@ private void pastLoad() { try { MapPack param = new MapPack(); ListValue objHashLv = new ListValue(); - objHashLv.add(ActiveDbInfo.getInstance().getObjectHash(selectionDB)); + objHashLv.add(ActiveDbInfo.getInstance().getObjectHash(serverId, selectionDB)); param.put("objHash", objHashLv); param.put("counter", viewType.getCounterName()); param.put("stime", pastStime); param.put("etime", pastEtime); - param.put("objName", ActiveDbInfo.getInstance().getObjectName(selectionDB)); + param.put("objName", ActiveDbInfo.getInstance().getObjectName(serverId, selectionDB)); tcp.process(RequestCmd.CUBRID_DB_PERIOD_MULTI_DATA, param, new INetReader() { public void process(DataInputX in) throws IOException { diff --git a/scouter.client/src/scouter/client/cubrid/views/CubridSingleRealTimeMultiView.java b/scouter.client/src/scouter/client/cubrid/views/CubridSingleRealTimeMultiView.java index b4efc7a64..0d556647a 100755 --- a/scouter.client/src/scouter/client/cubrid/views/CubridSingleRealTimeMultiView.java +++ b/scouter.client/src/scouter/client/cubrid/views/CubridSingleRealTimeMultiView.java @@ -136,7 +136,10 @@ public void init(IViewSite site) throws PartInitException { public void createPartControl(Composite parent) { Server server = ServerManager.getInstance().getServer(serverId); - this.setPartName("SingleRealTimeMultiView " + viewType.getTitle() + " [" + server.getName() + "]"); + if (viewType != null && server != null) { + this.setPartName("SingleRealTimeMultiView " + viewType.getTitle() + " [" + server.getName() + "]"); + } + IWorkbenchWindow window = getSite().getWorkbenchWindow(); IToolBarManager man = getViewSite().getActionBars().getToolBarManager(); @@ -377,13 +380,14 @@ public void dispose() { public void refresh() { - if (ActiveDbInfo.getInstance() == null) { + if (ActiveDbInfo.getInstance() == null + || ActiveDbInfo.getInstance().getDbList(serverId) == null) { return; } if (viewType.getInfoType() == InfoType.BROKER_INFO) { - if (!ActiveDbInfo.getInstance().getDbList().isEmpty()) { - selectionDB = ActiveDbInfo.getInstance().getDbList().get(0); + if (!ActiveDbInfo.getInstance().getDbList(serverId).isEmpty()) { + selectionDB = ActiveDbInfo.getInstance().getDbList(serverId).get(0); } else { return; } @@ -400,7 +404,7 @@ public void refresh() { try { MapPack param = new MapPack(); ListValue objHashLv = new ListValue(); - objHashLv.add(ActiveDbInfo.getInstance().getObjectHash(selectionDB)); + objHashLv.add(ActiveDbInfo.getInstance().getObjectHash(serverId, selectionDB)); param.put("objHash", objHashLv); param.put("counter", viewType.getCounterName()); v = tcp.getSingleValue(RequestCmd.CUBRID_DB_REALTIME_MULTI_DATA, param); @@ -470,11 +474,15 @@ public void checkDBList() { return; } - if (ActiveDbInfo.getInstance().getActiveDBInfo().hashCode() == prvActiveDBHash) { + if (ActiveDbInfo.getInstance().getActiveDBInfo(serverId) == null) { + return; + } + + if (ActiveDbInfo.getInstance().getActiveDBInfo(serverId).hashCode() == prvActiveDBHash) { return; } - prvActiveDBHash = ActiveDbInfo.getInstance().getActiveDBInfo().hashCode(); + prvActiveDBHash = ActiveDbInfo.getInstance().getActiveDBInfo(serverId).hashCode(); ExUtil.exec(canvas, new Runnable() { public void run() { @@ -482,10 +490,10 @@ public void run() { } }); - if (!ActiveDbInfo.getInstance().isEmpty()) { + if (!ActiveDbInfo.getInstance().isEmpty(serverId)) { ExUtil.exec(canvas, new Runnable() { public void run() { - for (String dbName : ActiveDbInfo.getInstance().keySet()) { + for (String dbName : ActiveDbInfo.getInstance().keySet(serverId)) { dbListCombo.add(dbName); } dbListCombo.setEnabled(true); diff --git a/scouter.client/src/scouter/client/cubrid/views/CubridSpaceDbView.java b/scouter.client/src/scouter/client/cubrid/views/CubridSpaceDbView.java index c910baf24..1c8360162 100755 --- a/scouter.client/src/scouter/client/cubrid/views/CubridSpaceDbView.java +++ b/scouter.client/src/scouter/client/cubrid/views/CubridSpaceDbView.java @@ -54,6 +54,8 @@ import scouter.client.model.RefreshThread; import scouter.client.model.RefreshThread.Refreshable; import scouter.client.net.TcpProxy; +import scouter.client.server.Server; +import scouter.client.server.ServerManager; import scouter.client.util.ExUtil; import scouter.client.util.TimeUtil; import scouter.lang.constants.StatusConstants; @@ -119,7 +121,12 @@ public void init(IViewSite site) throws PartInitException { @Override public void createPartControl(Composite parent) { - this.setPartName("CUBRID DBSpaceInfo"); + Server server = ServerManager.getInstance().getServer(serverId); + if (server != null) { + this.setPartName("CUBRID DBSpaceInfo" + "[" + server.getName() + "]"); + } else { + this.setPartName("CUBRID DBSpaceInfo"); + } composite = parent; GridLayout layout = new GridLayout(3, true); parent.setLayout(layout); @@ -245,7 +252,7 @@ private void createContextMenu() { manager.add(new Action("&Add DBSpaceInfo", ImageDescriptor.createFromImage(Images.add)) { public void run() { IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - AddLongTransactionList dialog = new AddLongTransactionList(window.getShell().getDisplay(), + AddLongTransactionList dialog = new AddLongTransactionList(window.getShell().getDisplay(), serverId, new AddLongTransactionList.IAddLongTransactionList() { @Override public void onPressedOk(String dbName) { @@ -341,11 +348,15 @@ public void run() { public void checkDBList() { - if (ActiveDbInfo.getInstance().getActiveDBInfo().hashCode() == prvActiveDBHash) { + if (ActiveDbInfo.getInstance().getActiveDBInfo(serverId) == null) { + return; + } + + if (ActiveDbInfo.getInstance().getActiveDBInfo(serverId).hashCode() == prvActiveDBHash) { return; } - prvActiveDBHash = ActiveDbInfo.getInstance().getActiveDBInfo().hashCode(); + prvActiveDBHash = ActiveDbInfo.getInstance().getActiveDBInfo(serverId).hashCode(); ExUtil.exec(composite, new Runnable() { public void run() { @@ -353,10 +364,10 @@ public void run() { } }); - if (!ActiveDbInfo.getInstance().isEmpty()) { + if (!ActiveDbInfo.getInstance().isEmpty(serverId)) { ExUtil.exec(composite, new Runnable() { public void run() { - for (String dbName : ActiveDbInfo.getInstance().keySet()) { + for (String dbName : ActiveDbInfo.getInstance().keySet(serverId)) { dbListCombo.add(dbName); } dbListCombo.setEnabled(true); diff --git a/scouter.client/src/scouter/client/util/MenuUtil.java b/scouter.client/src/scouter/client/util/MenuUtil.java index f56589a9f..f64c458ed 100644 --- a/scouter.client/src/scouter/client/util/MenuUtil.java +++ b/scouter.client/src/scouter/client/util/MenuUtil.java @@ -342,6 +342,7 @@ public static void addObjectContextMenu(IMenuManager mgr, IWorkbenchWindow win, MenuManager cubridDbListView = new MenuManager(MenuStr.CUBRID_DB_LIST_VIEW, Images.CAPTURE, MenuStr.CUBRID_DB_LIST_VIEW_ID); mgr.add(cubridDbListView); + cubridDbListView.add(new OpenOtherViewAction(serverId, objHash, OpenOtherViewAction.OtherViewType.CUBRID_SERVERINFO)); cubridDbListView.add(new OpenOtherViewAction(serverId, objHash, OpenOtherViewAction.OtherViewType.DB_SPACE_INFO)); cubridDbListView.add(new OpenOtherViewAction(serverId, objHash, OpenOtherViewAction.OtherViewType.LONG_TRANSACTION)); From 36f26070ce1435559a3e7626e59acf6609ceaaa5 Mon Sep 17 00:00:00 2001 From: hwanyseo Date: Fri, 5 Nov 2021 09:02:25 +0900 Subject: [PATCH 06/20] added autoscroll on table and deleted unused sort function --- .../views/CubridLongTransactionList.java | 155 ++++-------------- 1 file changed, 34 insertions(+), 121 deletions(-) diff --git a/scouter.client/src/scouter/client/cubrid/views/CubridLongTransactionList.java b/scouter.client/src/scouter/client/cubrid/views/CubridLongTransactionList.java index 7778ecf5b..04e3322ff 100755 --- a/scouter.client/src/scouter/client/cubrid/views/CubridLongTransactionList.java +++ b/scouter.client/src/scouter/client/cubrid/views/CubridLongTransactionList.java @@ -22,6 +22,8 @@ import java.util.Map; import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.layout.TableColumnLayout; import org.eclipse.jface.resource.ImageDescriptor; @@ -34,7 +36,6 @@ import org.eclipse.swt.dnd.Clipboard; import org.eclipse.swt.dnd.TextTransfer; import org.eclipse.swt.dnd.Transfer; -import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridData; @@ -63,8 +64,8 @@ import scouter.client.net.TcpProxy; import scouter.client.server.Server; import scouter.client.server.ServerManager; -import scouter.client.sorter.ColumnLabelSorter; import scouter.client.util.ExUtil; +import scouter.client.util.ImageUtil; import scouter.client.util.TimeUtil; import scouter.lang.constants.StatusConstants; import scouter.lang.counters.CounterConstants; @@ -113,6 +114,8 @@ public class CubridLongTransactionList extends ViewPart implements Refreshable { int lastListIndex = 0; int prvActiveDBHash = -1; + boolean scrollLock = false; + public void init(IViewSite site) throws PartInitException { super.init(site); String secId = site.getSecondaryId(); @@ -219,56 +222,21 @@ public void widgetDefaultSelected(SelectionEvent arg0) { tableComposite.setLayout(new GridLayout(1, true)); createTableViewer(tableComposite); + IToolBarManager man = getViewSite().getActionBars().getToolBarManager(); + Action scrollAct = new Action("Scroll Lock", IAction.AS_CHECK_BOX) { + public void run() { + scrollLock = isChecked(); + } + }; + scrollAct.setImageDescriptor(ImageUtil.getImageDescriptor(Images.table_scroll_lock)); + scrollAct.setChecked(false); + man.add(scrollAct); + thread = new RefreshThread(this, REFRESH_INTERVAL); thread.start(); } -// private void load() { -// ExUtil.asyncRun(new Runnable() { -// public void run() { -// TcpProxy tcpProxy = TcpProxy.getTcpProxy(serverId); -// try { -// MapPack param = new MapPack(); -// param.put("objHash", objHash); -// MapPack pack = (MapPack) tcpProxy.getSingle(RequestCmd.HOST_TOP, param); -// if (pack == null) return; -// String error = pack.getText("error"); -// if (error != null) { -// ConsoleProxy.errorSafe(error); -// } -// ListValue pidLv = pack.getList("PID"); -// ListValue userLv = pack.getList("USER"); -// ListValue cpuLv = pack.getList("CPU"); -// ListValue memLv = pack.getList("MEM"); -// ListValue timeLv = pack.getList("TIME"); -// ListValue nameLv = pack.getList("NAME"); -// -// transactionList = new TransactionObject[pidLv.size()]; -// for (int i = 0; i < pidLv.size(); i++) { -// transactionList[lastListIndex] = new TransactionObject(); -// transactionList[lastListIndex].sql_text = (int) pidLv.getLong(i); -// transactionList[lastListIndex].user = userLv.getString(i); -// transactionList[lastListIndex].sql_id = (float) cpuLv.getDouble(i); -// transactionList[lastListIndex].host = memLv.getLong(i); -// transactionList[lastListIndex].pid = timeLv.getLong(i); -// transactionList[lastListIndex].program = nameLv.getString(i); -// transactionList[lastListIndex].tran_time = nameLv.getString(i); -// transactionList[lastListIndex].query_time = nameLv.getString(i); -// } -// ExUtil.exec(viewer.getTable(), new Runnable() { -// public void run() { -// viewer.setInput(transactionList); -// } -// }); -// } catch (Throwable th){ -// th.printStackTrace(); -// } finally { -// TcpProxy.putTcpProxy(tcpProxy); -// } -// } -// }); -// } - + private void createTableViewer(Composite composite) { viewer = new TableViewer(composite, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER); tableColumnLayout = new TableColumnLayout(); @@ -278,64 +246,9 @@ private void createTableViewer(Composite composite) { table.setHeaderVisible(true); table.setLinesVisible(true); createTableContextMenu(); -// table.addMouseListener(new MouseAdapter() { -// public void mouseDoubleClick(MouseEvent e) { -// TableItem[] item = table.getSelection(); -// if (item == null || item.length == 0) -// return; -// int pid = CastUtil.cint(item[0].getText(0)); -// IWorkbenchWindow win = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); -// try { -// ProcessDetailView view = (ProcessDetailView) win.getActivePage().showView( -// ProcessDetailView.ID, "" + pid + objHash, IWorkbenchPage.VIEW_ACTIVATE); -// view.setInput(serverId, objHash, pid); -// } catch (PartInitException e1) {} -// } -// }); + viewer.setContentProvider(new ArrayContentProvider()); - viewer.setComparator(new ColumnLabelSorter(viewer).setCustomCompare(new ColumnLabelSorter.ICustomCompare() { - public int doCompare(TableColumn col, int index, Object o1, Object o2) { - if (!(o1 instanceof TransactionObject) || !(o2 instanceof TransactionObject)) { - return 0; - } - TransactionObject p1 = (TransactionObject) o1; - TransactionObject p2 = (TransactionObject) o2; - Boolean isNumber = (Boolean) col.getData("isNumber"); - if (isNumber != null && isNumber.booleanValue()) { - String v1 = ColumnLabelSorter.numonly(p1.getValueByIndex(index)); - String v2 = ColumnLabelSorter.numonly(p2.getValueByIndex(index)); - if (v1 == null) v1 = "0"; - if (v2 == null) v2 = "0"; - if (v1.contains(".") || v2.contains(".")) { - double d1 = Double.valueOf(v1); - double d2 = Double.valueOf(v2); - if (d1 > d2) { - return 1; - } else if (d2 > d1) { - return -1; - } else { - return 0; - } - } else { - long i1 = Long.valueOf(v1); - long i2 = Long.valueOf(v2); - if (i1 > i2) { - return 1; - } else if (i2 > i1) { - return -1; - } else { - return 0; - } - } - } else { - String v1 = p1.getValueByIndex(index); - String v2 = p2.getValueByIndex(index); - if (v1 == null) v1 = ""; - if (v2 == null) v2 = ""; - return v1.compareTo(v2); - } - } - })); + GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true); viewer.getControl().setLayoutData(gridData); } @@ -518,12 +431,6 @@ private TableViewerColumn createTableViewerColumn(String title, int width, int a column.setMoveable(moveable); tableColumnLayout.setColumnData(column, new ColumnWeightData(30, width, resizable)); column.setData("isNumber", isNumber); - column.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - ColumnLabelSorter sorter = (ColumnLabelSorter) viewer.getComparator(); - sorter.setColumn(column); - } - }); return viewerColumn; } @@ -570,14 +477,14 @@ public String toString() { } public enum ColumnEnum { - SQL_TEXT("SQL TEXT", 50, SWT.RIGHT, true, true, true), - TRAN_TIME("TRAN TIME", 150, SWT.LEFT, true, true, false), - QUERY_TIME("QUERY_TIME", 150, SWT.LEFT, true, true, false), - HOST("HOST", 50, SWT.RIGHT, true, true, true), - PID("PID", 50, SWT.RIGHT, true, true, true), + SQL_TEXT("SQL TEXT", 50, SWT.RIGHT, true, true, false), + TRAN_TIME("TRAN TIME", 150, SWT.LEFT, true, true, true), + QUERY_TIME("QUERY_TIME", 150, SWT.LEFT, true, true, true), + HOST("HOST", 50, SWT.RIGHT, true, true, false), + PID("PID", 50, SWT.RIGHT, true, true, false), USER("USER", 70, SWT.RIGHT, true, true, false), - PROGRAM("PROGRAM", 100, SWT.RIGHT, true, true, true), - SQL_ID("SQL_ID", 50, SWT.RIGHT, true, true, true); + PROGRAM("PROGRAM", 100, SWT.RIGHT, true, true, false), + SQL_ID("SQL_ID", 50, SWT.RIGHT, true, true, false); private final String title; private final int width; @@ -695,12 +602,15 @@ public void refresh() { TcpProxy.putTcpProxy(tcp); } - if (saveData.size() > 0) { - updateTableview(); - } + updateTableview(); } private void updateTableview() { + + if (saveData.size() < 1) { + return; + } + int skipCount = saveData.size() - MaxListValue; transactionList.clear(); for(String key : saveData.keySet()) { @@ -714,6 +624,9 @@ private void updateTableview() { ExUtil.exec(viewer.getTable(), new Runnable() { public void run() { viewer.setInput(transactionList.toArray()); + if (transactionList.size() > 0 && !scrollLock) { + viewer.getTable().setTopIndex(transactionList.size() - 1); + } } }); } From 3725e8120699bc739abd7aac5cd2c1b51c0a2923 Mon Sep 17 00:00:00 2001 From: hwanyseo Date: Fri, 5 Nov 2021 10:02:51 +0900 Subject: [PATCH 07/20] added image --- scouter.client/icons/table_scroll_lock.png | Bin 0 -> 1092 bytes scouter.client/src/scouter/client/Images.java | 1 + 2 files changed, 1 insertion(+) create mode 100755 scouter.client/icons/table_scroll_lock.png diff --git a/scouter.client/icons/table_scroll_lock.png b/scouter.client/icons/table_scroll_lock.png new file mode 100755 index 0000000000000000000000000000000000000000..822110fa32189bfe60d4752b74a5284e2924c59a GIT binary patch literal 1092 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJOS+@4BLl<6e(pbstU$g(vPY0F z14ES>14Ba#1H&(%P{RubhEf9thF1v;3|2E37{m+a>8Q;1lAiAJh-hCc|W9 z!mO&u#K_2?;oZAtCg=bEf{{sXcaQQ&h%xrnacHSAF)=YPF)}bSGq5l-{Qs}=|G(z{ z|6*@1@wSw*Gcz&h`giFC^{e}IGcdU82lfMvH3$Ncx&eKL!4oVZr)c~2sw*>jJF^&S zGwb^I8HP--j+v_E+vDrPQk=#HL?!8Lp+2ly{vh`hB(o()fcz63$Xb-frlP>49XLft zg`psYO+$qVqQKRbMai|p!=ACNg1s!04d{&WOt$t4_7HCtpaScdX`EUm(^}aVPviu0 z*)@unOk}@tfTyX1{oHo$P4l=e?dEo|VL7^l0h{@Ae9$&rl(yn8-uHJdEYJUz|x;5g5Vb3CTulMbJ~fBWGZpqb0JUD$K{ z_W%F?Pu$}!2D-1lB*+hxG;ji*qxWP%Sj{-1qXV^434+IF87;S9VVAt`29j3cC6{&YU^&;rk4x zh&SJgnPc95FK5YZVY8|0$N<{UnB?v5GNbGwn;nqDS>O=~bf3`y5N6a!iMkCGWH0gb zb!C6b%_6R$KKY`?W1!GAPZ!4!iOb0e6DF?BpD;N+Atfm-F(ox6B_SXnCnqQRJUju6Y%4!?om!P8A+K>jAvQRg{kbs{Lz%VpmaJMqkPlT$Tq8@|CiGh`|iMD}(m4U(Qy}Y|nH00)|WTsW()-dbARyLpp22WQ% Jmvv4FO#n7ca}59h literal 0 HcmV?d00001 diff --git a/scouter.client/src/scouter/client/Images.java b/scouter.client/src/scouter/client/Images.java index 380bcf85b..a0168dbac 100644 --- a/scouter.client/src/scouter/client/Images.java +++ b/scouter.client/src/scouter/client/Images.java @@ -371,5 +371,6 @@ public static ArrayList getAllCounterImages(int serverId){ public static final Image star = Activator.getImage("icons/star.png"); public static final Image page_white_stack = Activator.getImage("icons/page_white_stack.png"); public static final Image page_white_text = Activator.getImage("icons/page_white_text.png"); + public static final Image table_scroll_lock = Activator.getImage("icons/table_scroll_lock.png"); } From cf0527ea78fc635f463e4049f03cb5e3965e0cbb Mon Sep 17 00:00:00 2001 From: Manty Date: Fri, 5 Nov 2021 16:43:13 +0900 Subject: [PATCH 08/20] fix array out of bound error --- .../src/scouter/client/popup/LoginDialog2.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/scouter.client/src/scouter/client/popup/LoginDialog2.java b/scouter.client/src/scouter/client/popup/LoginDialog2.java index 8dacb7521..6e7bda9b0 100644 --- a/scouter.client/src/scouter/client/popup/LoginDialog2.java +++ b/scouter.client/src/scouter/client/popup/LoginDialog2.java @@ -289,14 +289,16 @@ public boolean loginInToServer(String address, String socksAddress) { ip = addr[0]; port = addr[1]; - String socksIp; - String socksPort; - if (!socksAddress.contains(":")) { - errMsg("Check SOCKS Address"); + String socksIp = null; + String socksPort = null; + if (this.sock5Login) { + if (StringUtil.isEmpty(socksAddress) || !socksAddress.contains(":")) { + errMsg("Check SOCKS Address"); + } + String[] socksAddr = socksAddress.split(":"); + socksIp = socksAddr[0]; + socksPort = socksAddr[1]; } - String[] socksAddr = socksAddress.split(":"); - socksIp = socksAddr[0]; - socksPort = socksAddr[1]; msg("Log in..." + address); From 37eb75c6b00a13b2f8de312b60f8d76b7b10854e Mon Sep 17 00:00:00 2001 From: Manty Date: Fri, 5 Nov 2021 16:44:53 +0900 Subject: [PATCH 09/20] fix array out of bound error --- scouter.client/src/scouter/client/popup/LoginDialog2.java | 1 + 1 file changed, 1 insertion(+) diff --git a/scouter.client/src/scouter/client/popup/LoginDialog2.java b/scouter.client/src/scouter/client/popup/LoginDialog2.java index 6e7bda9b0..c3a0ba7da 100644 --- a/scouter.client/src/scouter/client/popup/LoginDialog2.java +++ b/scouter.client/src/scouter/client/popup/LoginDialog2.java @@ -294,6 +294,7 @@ public boolean loginInToServer(String address, String socksAddress) { if (this.sock5Login) { if (StringUtil.isEmpty(socksAddress) || !socksAddress.contains(":")) { errMsg("Check SOCKS Address"); + return false; } String[] socksAddr = socksAddress.split(":"); socksIp = socksAddr[0]; From 9ba01410202b2b8311918a595d92c496cfcaebfe Mon Sep 17 00:00:00 2001 From: Gun Lee Date: Tue, 30 Nov 2021 22:39:34 +0900 Subject: [PATCH 10/20] [agent.java] webflux support bug fix. (fix unfinished xlog on some jvm environment.) --- .../agent/proxy/ReactiveSupportFactory.java | 16 +- .../xtra/reactive/ReactiveSupport.java | 16 +- .../ReactiveSupportWithCoroutine.java | 338 ++++++++++++++++++ 3 files changed, 352 insertions(+), 18 deletions(-) create mode 100644 scouter.agent.java/src/main/java/scouter/xtra/reactive/ReactiveSupportWithCoroutine.java diff --git a/scouter.agent.java/src/main/java/scouter/agent/proxy/ReactiveSupportFactory.java b/scouter.agent.java/src/main/java/scouter/agent/proxy/ReactiveSupportFactory.java index 7167b6070..3f4ff885a 100644 --- a/scouter.agent.java/src/main/java/scouter/agent/proxy/ReactiveSupportFactory.java +++ b/scouter.agent.java/src/main/java/scouter/agent/proxy/ReactiveSupportFactory.java @@ -21,6 +21,7 @@ public class ReactiveSupportFactory { private static final String REACTIVE_SUPPORT = "scouter.xtra.reactive.ReactiveSupport"; + private static final String REACTIVE_SUPPORT_W_COROUTINE = "scouter.xtra.reactive.ReactiveSupportWithCoroutine"; public static final IReactiveSupport dummy = new IReactiveSupport() { public Object subscriptOnContext(Object mono0, TraceContext traceContext) { @@ -46,11 +47,20 @@ public static IReactiveSupport create(ClassLoader parent) { if (loader == null) { return dummy; } - Class c = Class.forName(REACTIVE_SUPPORT, true, loader); - return (IReactiveSupport) c.newInstance(); + IReactiveSupport reactiveSupport = null; + try { + Class c = Class.forName(REACTIVE_SUPPORT_W_COROUTINE, true, loader); + reactiveSupport = (IReactiveSupport) c.newInstance(); + } catch (Throwable e) { + Logger.println("A133-0", "fail to create reactive support: REACTIVE_SUPPORT_W_COROUTINE", e); + Class c = Class.forName(REACTIVE_SUPPORT, true, loader); + reactiveSupport = (IReactiveSupport) c.newInstance(); + Logger.println("success to create reactive support without coroutine support"); + } + return reactiveSupport; } catch (Throwable e) { - Logger.println("A133-1", "fail to create", e); + Logger.println("A133-2", "fail to create", e); return dummy; } } diff --git a/scouter.agent.java/src/main/java/scouter/xtra/reactive/ReactiveSupport.java b/scouter.agent.java/src/main/java/scouter/xtra/reactive/ReactiveSupport.java index 0a7918e54..19de11ee4 100644 --- a/scouter.agent.java/src/main/java/scouter/xtra/reactive/ReactiveSupport.java +++ b/scouter.agent.java/src/main/java/scouter/xtra/reactive/ReactiveSupport.java @@ -18,9 +18,6 @@ package scouter.xtra.reactive; -import kotlin.coroutines.CoroutineContext; -import kotlinx.coroutines.ThreadContextElement; -import kotlinx.coroutines.ThreadContextElementKt; import org.reactivestreams.Publisher; import org.reactivestreams.Subscription; import reactor.core.CoreSubscriber; @@ -136,18 +133,7 @@ private TraceContext getTraceContext(Scannable scannable, Context currentContext @Override public Object monoCoroutineContextHook(Object _coroutineContext, TraceContext traceContext) { - try { - CoroutineContext coroutineContext = (CoroutineContext) _coroutineContext; - - TraceContextManager.startByCoroutine(traceContext); - - ThreadContextElement threadContextElement = ThreadContextElementKt - .asContextElement(TraceContextManager.txidByCoroutine, traceContext.txid); - return coroutineContext.plus(threadContextElement); - } catch (Exception e) { - Logger.println("R167p", e.getMessage(), e); - return _coroutineContext; - } + return _coroutineContext; } public static class SubscribeDepth {} diff --git a/scouter.agent.java/src/main/java/scouter/xtra/reactive/ReactiveSupportWithCoroutine.java b/scouter.agent.java/src/main/java/scouter/xtra/reactive/ReactiveSupportWithCoroutine.java new file mode 100644 index 000000000..5f305e3f7 --- /dev/null +++ b/scouter.agent.java/src/main/java/scouter/xtra/reactive/ReactiveSupportWithCoroutine.java @@ -0,0 +1,338 @@ +/* + * Copyright 2015 the original author or authors. + * @https://github.com/scouter-project/scouter + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package scouter.xtra.reactive; + +import kotlin.coroutines.CoroutineContext; +import kotlinx.coroutines.ThreadContextElement; +import kotlinx.coroutines.ThreadContextElementKt; +import org.reactivestreams.Publisher; +import org.reactivestreams.Subscription; +import reactor.core.CoreSubscriber; +import reactor.core.Fuseable; +import reactor.core.Scannable; +import reactor.core.publisher.Hooks; +import reactor.core.publisher.Mono; +import reactor.core.publisher.Operators; +import reactor.core.publisher.ScouterOptimizableOperatorProxy; +import reactor.core.publisher.SignalType; +import reactor.util.context.Context; +import scouter.agent.AgentCommonConstant; +import scouter.agent.Configure; +import scouter.agent.Logger; +import scouter.agent.netio.data.DataProxy; +import scouter.agent.proxy.IReactiveSupport; +import scouter.agent.trace.TraceContext; +import scouter.agent.trace.TraceContextManager; +import scouter.agent.trace.TraceMain; +import scouter.agent.util.Tuple; +import scouter.lang.enumeration.ParameterizedMessageLevel; +import scouter.lang.step.ParameterizedMessageStep; +import scouter.util.StringUtil; + +import java.util.function.BiFunction; +import java.util.function.Consumer; +import java.util.function.Function; + +public class ReactiveSupportWithCoroutine implements IReactiveSupport { + + static Configure configure = Configure.getInstance(); + + @Override + public Object subscriptOnContext(Object mono0, final TraceContext traceContext) { + try { + if (traceContext.isReactiveTxidMarked) { + return mono0; + } + Mono mono = (Mono) mono0; + traceContext.isReactiveTxidMarked = true; + return mono.subscriberContext(new Function() { + @Override + public Context apply(Context context) { + return context.put(TraceContext.class, traceContext); + } + }).doOnSuccess(new Consumer() { + @Override + public void accept(Object o) { + TraceMain.endHttpService(new TraceMain.Stat(traceContext), null); + } + }).doOnError(new Consumer() { + @Override + public void accept(Throwable throwable) { + TraceMain.endHttpService(new TraceMain.Stat(traceContext), throwable); + } + }).doOnCancel(new Runnable() { + @Override + public void run() { + TraceMain.endCanceledHttpService(traceContext); + } + }).doFinally(new Consumer() { + @Override + public void accept(SignalType signalType) { + TraceContextManager.clearAllContext(traceContext); + } + }).doAfterTerminate(new Runnable() { + @Override + public void run() { + } + }); + } catch (Throwable e) { + Logger.println("R201", e.getMessage(), e); + return mono0; + } + } + + @Override + public void contextOperatorHook() { + try { + Hooks.onEachOperator(AgentCommonConstant.TRACE_ID, Operators.lift( + new BiFunction, CoreSubscriber>() { + @Override + public CoreSubscriber apply(Scannable scannable, CoreSubscriber subscriber) { + try { + if (scannable instanceof Fuseable.ScalarCallable) { + return subscriber; + } + Context context = subscriber.currentContext(); + TraceContext traceContext = getTraceContext(scannable, context); + + if (traceContext != null) { + return new TxidLifter(subscriber, scannable, null, traceContext); + } else { + return subscriber; + } + } catch (Exception e) { + Logger.println("R1660", e.getMessage(), e); + return subscriber; + } + } + })); + } catch (Throwable e) { + Logger.println("R166", e.getMessage(), e); + } + } + + private TraceContext getTraceContext(Scannable scannable, Context currentContext) { + if (scannable == null || currentContext == null) { + return null; + } + return currentContext.getOrDefault(TraceContext.class, null); + } + + @Override + public Object monoCoroutineContextHook(Object _coroutineContext, TraceContext traceContext) { + try { + CoroutineContext coroutineContext = (CoroutineContext) _coroutineContext; + + TraceContextManager.startByCoroutine(traceContext); + + ThreadContextElement threadContextElement = ThreadContextElementKt + .asContextElement(TraceContextManager.txidByCoroutine, traceContext.txid); + return coroutineContext.plus(threadContextElement); + } catch (Exception e) { + Logger.println("R167p", e.getMessage(), e); + return _coroutineContext; + } + } + + public static class SubscribeDepth {} + public static class TxidLifter implements SpanSubscription, Scannable { + + private final CoreSubscriber coreSubscriber; + private final Context ctx; + private final Scannable scannable; + private final Publisher publisher; + private final TraceContext traceContext; + private final String checkpointDesc; + private final Integer depth; + private Subscription orgSubs; + + private enum ReactorCheckPointType { + ON_SUBSCRIBE, + ON_COMPLETE, + ON_ERROR, + ON_CANCEL + } + + public TxidLifter(CoreSubscriber coreSubscriber, Scannable scannable, Publisher publisher, + TraceContext traceContext) { + this.coreSubscriber = coreSubscriber; + Context context = coreSubscriber.currentContext(); + this.scannable = scannable; + this.publisher = publisher; + this.traceContext = traceContext; + + Tuple.StringLongPair checkpointPair = ScouterOptimizableOperatorProxy + .nameOnCheckpoint(scannable, configure.profile_reactor_checkpoint_search_depth); + checkpointDesc = checkpointPair.aString; + + Integer parentDepth = context.getOrDefault(SubscribeDepth.class, 0); + depth = (!"".equals(checkpointDesc)) ? parentDepth + 1 : parentDepth; + this.ctx = context.put(SubscribeDepth.class, depth); + + //todo parent something +// this.ctx = parent != null +// && !parent.equals(ctx.getOrDefault(TraceContext.class, null)) +// ? ctx.put(TraceContext.class, parent) : ctx; + } + + @Override + public void onSubscribe(Subscription subs) { + copyToThread(currentContext(), traceContext); + try { + traceContext.scannables.put(scannable.hashCode(), + new TraceContext.TimedScannable(System.currentTimeMillis(), scannable)); + profileCheckPoint(scannable, traceContext, ReactorCheckPointType.ON_SUBSCRIBE, null); + } catch (Throwable e) { + Logger.println("[R109]", "reactive support onSubscribe error.", e); + } + this.orgSubs = subs; + coreSubscriber.onSubscribe(this); + } + + @Override + public void onNext(T t) { + copyToThread(currentContext(), traceContext); + coreSubscriber.onNext(t); + } + + @Override + public void onError(Throwable throwable) { + copyToThread(currentContext(), traceContext); + try { + TraceContext.TimedScannable timedScannable = traceContext.scannables.remove(scannable.hashCode()); + profileCheckPoint(scannable, traceContext, ReactorCheckPointType.ON_ERROR, timedScannable); + } catch (Throwable e) { + Logger.println("[R110]", "reactive support onError error.", e); + } + coreSubscriber.onError(throwable); + } + + @Override + public void onComplete() { + copyToThread(currentContext(), traceContext); + try { + TraceContext.TimedScannable timedScannable = traceContext.scannables.remove(scannable.hashCode()); + profileCheckPoint(scannable, traceContext, ReactorCheckPointType.ON_COMPLETE, timedScannable); + } catch (Throwable e) { + Logger.println("[R111]", "reactive support onComplete error.", e); + } + coreSubscriber.onComplete(); + } + + @Override + public void request(long n) { + this.orgSubs.request(n); + } + + @Override + public void cancel() { + copyToThread(currentContext(), traceContext); + try { + TraceContext.TimedScannable timedScannable = traceContext.scannables.remove(scannable.hashCode()); + profileCheckPoint(scannable, traceContext, ReactorCheckPointType.ON_CANCEL, timedScannable); + } catch (Throwable e) { + Logger.println("[R112]", "reactive support onCancel error.", e); + } + this.orgSubs.cancel(); + } + + @Override + public Context currentContext() { + return ctx; + } + + @Override + public Object scanUnsafe(Attr key) { + if (key == Attr.PARENT) { + return this.orgSubs; + } + else { + return key == Attr.ACTUAL ? this.coreSubscriber : null; + } + } + + private void copyToThread(Context context, TraceContext traceContext) { + Long threadLocalTxid = TraceContextManager.getLocalTxid(); + if (threadLocalTxid == null) { + TraceContextManager.setTxidLocal(traceContext.txid); + } else if (threadLocalTxid != traceContext.txid) { + TraceContextManager.setTxidLocal(traceContext.txid); + } + } + + private void profileCheckPoint(Scannable scannable, TraceContext traceContext, ReactorCheckPointType type, + TraceContext.TimedScannable timedScannable) { + if (!configure.profile_reactor_checkpoint_enabled) { + return; + } + if (scannable.isScanAvailable()) { + if (!"".equals(checkpointDesc)) { + boolean important = false; + if (checkpointDesc.startsWith("checkpoint")) { + important = true; + } + if (!configure.profile_reactor_more_checkpoint_enabled && !important) { + return; + } + String duration; + StringBuilder messageBuilder = new StringBuilder(300) + .append(StringUtil.padding((depth - 1) * 2, ' ')) + .append("[") + .append(type.name()); + + if (timedScannable != null) { + messageBuilder.append("(%sms): "); + duration = String.valueOf(System.currentTimeMillis() - timedScannable.start); + } else { + messageBuilder.append(": "); + duration = ""; + } + + String message = messageBuilder.append(scannable.name()) + .append("] near-cp -> ") + .append(checkpointDesc).toString(); + + ParameterizedMessageStep step = new ParameterizedMessageStep(); + step.setMessage(DataProxy.sendHashedMessage(message), duration); + step.start_time = (int) (System.currentTimeMillis() - traceContext.startTime); + + if (important) { + step.setLevel(ParameterizedMessageLevel.INFO); + } else { + step.setLevel(ParameterizedMessageLevel.DEBUG); + } + traceContext.profile.add(step); + } + } + } + } + + public String dumpScannable(TraceContext traceContext, TraceContext.TimedScannable timedScannable, long now) { + if (traceContext == null || timedScannable == null) { + return null; + } + Scannable scannable = (Scannable) timedScannable.scannable; + long duration = now - timedScannable.start; + StringBuilder builder = new StringBuilder(1000) + .append(scannable.name()).append(" ").append(duration).append("ms"); + + ScouterOptimizableOperatorProxy.appendSources4Dump(scannable, builder, configure.profile_reactor_checkpoint_search_depth); + return builder.toString(); + } +} From 2074e54bc3c66d76cd6253557cfa36793b110001 Mon Sep 17 00:00:00 2001 From: Gun Lee Date: Tue, 30 Nov 2021 22:41:20 +0900 Subject: [PATCH 11/20] [agent.java] obj_name on kube pod auto naming bug fix --- .../main/java/scouter/agent/Configure.java | 4 +- .../agent/counter/task/AgentHeartBeat.java | 52 ++++++++++++++----- .../scouter/agent/trace/TraceContext.java | 1 + 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/scouter.agent.host/src/main/java/scouter/agent/Configure.java b/scouter.agent.host/src/main/java/scouter/agent/Configure.java index 765efcc2b..6227fcfc4 100644 --- a/scouter.agent.host/src/main/java/scouter/agent/Configure.java +++ b/scouter.agent.host/src/main/java/scouter/agent/Configure.java @@ -504,8 +504,8 @@ public StringKeyLinkedMap getConfigureValueType() { } private boolean isKube() { - Properties properties = System.getProperties(); - return !StringUtil.isEmpty(properties.getProperty("KUBERNETES_SERVICE_HOST")); + Map env = System.getenv(); + return !StringUtil.isEmpty(env.get("KUBERNETES_SERVICE_HOST")); } public static void main(String[] args) { diff --git a/scouter.agent.host/src/main/java/scouter/agent/counter/task/AgentHeartBeat.java b/scouter.agent.host/src/main/java/scouter/agent/counter/task/AgentHeartBeat.java index 4284699ae..65bb26bff 100644 --- a/scouter.agent.host/src/main/java/scouter/agent/counter/task/AgentHeartBeat.java +++ b/scouter.agent.host/src/main/java/scouter/agent/counter/task/AgentHeartBeat.java @@ -75,25 +75,49 @@ public void writeHostNameForKube(CounterBasket pw) { File dir = new File(conf.counter_object_registry_path); File file = new File(dir, seqNoForKube + ".scouterkubeseq"); if (dir.canWrite()) { + deleteAllHostNameFileWithIgnore(dir, seqNoForKube); FileUtil.save(file, conf.obj_name.getBytes()); } } else { File dir = new File(conf.counter_object_registry_path); - if (dir == null) - return; - - File[] files = dir.listFiles(); - for (int i = 0; i < files.length; i++) { - if (files[i].isDirectory()) - continue; - String name = files[i].getName(); - if (!name.endsWith(".scouterkubeseq")) { - continue; - } - if (files[i].canWrite()) { - files[i].delete(); - } + deleteAllHostNameFileWithIgnore(dir, -1); + } + } + + private void deleteAllHostNameFileWithIgnore(File dir, long ignoreSeq) { + if (dir == null) + return; + + File[] files = dir.listFiles(); + for (int i = 0; i < files.length; i++) { + if (files[i].isDirectory()) + continue; + String name = files[i].getName(); + if (!name.endsWith(".scouterkubeseq")) { + continue; + } + + int kubeSeq = cintErrorMinusOne(name.substring(0, name.lastIndexOf("."))); + if (kubeSeq < 0) + continue; + if (kubeSeq == ignoreSeq) { + continue; + } + if (files[i].canWrite()) { + files[i].delete(); + } + } + } + + public static int cintErrorMinusOne(String value) { + if (value == null) { + return -1; + } else { + try { + return Integer.parseInt(value); + } catch (Exception e) { + return -1; } } } diff --git a/scouter.agent.java/src/main/java/scouter/agent/trace/TraceContext.java b/scouter.agent.java/src/main/java/scouter/agent/trace/TraceContext.java index 46fb8c01e..87d2d1019 100644 --- a/scouter.agent.java/src/main/java/scouter/agent/trace/TraceContext.java +++ b/scouter.agent.java/src/main/java/scouter/agent/trace/TraceContext.java @@ -195,6 +195,7 @@ public void initScannables() { public Throwable asyncThrowable; public boolean alreadySetControllerName = false; + public boolean forceNotSamplingDrop = false; private Queue errorQueue = new LinkedBlockingQueue(10); From 976867764c4a8d27339a634ada9cce41efac817d Mon Sep 17 00:00:00 2001 From: Gun Lee Date: Tue, 30 Nov 2021 22:42:10 +0900 Subject: [PATCH 12/20] [agent.java] add stuck service profile stop option. --- .../main/java/scouter/agent/Configure.java | 15 +++++++++++++-- .../agent/trace/TraceContextManager.java | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/scouter.agent.java/src/main/java/scouter/agent/Configure.java b/scouter.agent.java/src/main/java/scouter/agent/Configure.java index d22be9088..79e6d8572 100644 --- a/scouter.agent.java/src/main/java/scouter/agent/Configure.java +++ b/scouter.agent.java/src/main/java/scouter/agent/Configure.java @@ -323,6 +323,13 @@ public static final Configure getInstance() { @ConfigDesc("") public int autodump_stuck_check_interval_ms = 10000; + @ConfigDesc("ends sxlog profile when it exceeds profile_force_end_stuck_millis.") + public boolean profile_force_end_stuck_service = true; + @ConfigDesc("alert when forcibly ends xlog profile.") + public boolean profile_force_end_stuck_alert = true; + @ConfigDesc("stuck service millis for forcibly ends xlog profile") + public int profile_force_end_stuck_millis = 300000; + //Auto dump options on exceeded process cpu @ConfigDesc("Enable the function to generate dump file when this process cpu is over than the set threshold") public boolean autodump_cpu_exceeded_enabled = false; @@ -974,6 +981,10 @@ private void apply() { this.autodump_stuck_thread_ms = getInt("autodump_stuck_thread_ms", 0); this.autodump_stuck_check_interval_ms = getInt("autodump_stuck_check_interval_ms", 10000); + this.profile_force_end_stuck_service = getBoolean("profile_force_end_stuck_service", false); + this.profile_force_end_stuck_alert = getBoolean("profile_force_end_stuck_alert", true); + this.profile_force_end_stuck_millis = getInt("profile_force_end_stuck_millis", 300000); + this.autodump_cpu_exceeded_enabled = getBoolean("autodump_cpu_exceeded_enabled", false); this.autodump_cpu_exceeded_threshold_pct = getInt("autodump_cpu_exceeded_threshold_pct", 90); this.autodump_cpu_exceeded_duration_ms = getInt("autodump_cpu_exceeded_duration_ms", 30000); @@ -1627,8 +1638,8 @@ public void initTmpDir() { } private boolean isKube() { - Properties properties = System.getProperties(); - return !StringUtil.isEmpty(properties.getProperty("KUBERNETES_SERVICE_HOST")); + Map env = System.getenv(); + return !StringUtil.isEmpty(env.get("KUBERNETES_SERVICE_HOST")); } private String readHostNameFromHostAgent() { diff --git a/scouter.agent.java/src/main/java/scouter/agent/trace/TraceContextManager.java b/scouter.agent.java/src/main/java/scouter/agent/trace/TraceContextManager.java index f4e2f5afb..ba5900cbb 100644 --- a/scouter.agent.java/src/main/java/scouter/agent/trace/TraceContextManager.java +++ b/scouter.agent.java/src/main/java/scouter/agent/trace/TraceContextManager.java @@ -19,6 +19,7 @@ import scouter.agent.Configure; import scouter.agent.util.SimpleLru; +import scouter.lang.AlertLevel; import scouter.util.KeyGen; import scouter.util.LongLongLinkedMap; @@ -71,6 +72,24 @@ public static int[] getActiveCount() { } else { act[2]++; } + + if (conf.profile_force_end_stuck_service && tm > conf.profile_force_end_stuck_millis) { + TraceMain.Stat stat = new TraceMain.Stat(ctx); + Throwable th = new RuntimeException("Stuck service. finish xlog but actually may be processing."); + if (ctx.http != null) { + TraceMain.endHttpService(stat, th); + } else { + TraceMain.endService(stat, null, th); + } + String msg = String.format("service: %s, elapsed: %d, start thread: %s, txid: %s", ctx.serviceName, tm, + ctx.threadName, ctx.txid); + if (conf.profile_force_end_stuck_alert) { + AlertProxy.sendAlert(AlertLevel.ERROR, "STUCK", msg); + } else { + AlertProxy.sendAlert(AlertLevel.WARN, "STUCK", msg); + } + } + } } catch (Throwable t) { } From 425881343cd4bc36bc96f31930be86eab3a0e64f Mon Sep 17 00:00:00 2001 From: Gun Lee Date: Tue, 30 Nov 2021 22:42:42 +0900 Subject: [PATCH 13/20] [agent.java] bug fix for scouter weaver feature. --- .../java/scouter/agent/trace/TraceMain.java | 33 ++++++++++++++++--- .../java/scouter/weaver/TraceSupport.java | 6 ++-- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/scouter.agent.java/src/main/java/scouter/agent/trace/TraceMain.java b/scouter.agent.java/src/main/java/scouter/agent/trace/TraceMain.java index 8190c3ff3..da10aef97 100644 --- a/scouter.agent.java/src/main/java/scouter/agent/trace/TraceMain.java +++ b/scouter.agent.java/src/main/java/scouter/agent/trace/TraceMain.java @@ -764,19 +764,36 @@ public static boolean isStaticContents(String serviceName) { } } + public static Object startServiceWithCustomTxid(String name, String className, String methodName, String methodDesc, Object _this, + Object[] arg, byte xType, String customTxid) { + + TraceContext ctx = TraceContextManager.getContextByCustomTxid(customTxid); + if (ctx != null) { + return null; + } + return startService0(name, className, methodName, methodDesc, _this, arg, xType, customTxid); + } + public static Object startService(String name, String className, String methodName, String methodDesc, Object _this, Object[] arg, byte xType) { + + TraceContext ctx = TraceContextManager.getContext(true); + if (ctx != null) { + return null; + } + return startService0(name, className, methodName, methodDesc, _this, arg, xType, null); + } + + public static Object startService0(String name, String className, String methodName, String methodDesc, Object _this, + Object[] arg, byte xType, String customTxid) { try { - TraceContext ctx = TraceContextManager.getContext(true); - if (ctx != null) { - return null; - } if (TraceContextManager.startForceDiscard()) { return null; } Configure conf = Configure.getInstance(); - ctx = new TraceContext(false); + TraceContext ctx = new TraceContext(false); + String service_name = AgentCommonConstant.normalizeHashCode(name); ctx.thread = Thread.currentThread(); ctx.serviceHash = HashUtil.hash(service_name); @@ -787,6 +804,9 @@ public static Object startService(String name, String className, String methodNa ctx.threadId = ctx.thread.getId(); TraceContextManager.start(ctx); + if (customTxid != null) { + TraceContextManager.linkCustomTxid(customTxid, ctx.txid); + } ctx.bytes = SysJMX.getCurrentThreadAllocBytes(conf.profile_thread_memory_usage_enabled); ctx.profile_thread_cputime = conf.profile_thread_cputime_enabled; @@ -1204,6 +1224,9 @@ public static void setStatus(int httpStatus) { } private static XLogDiscard findXLogDiscard(TraceContext ctx, Configure conf, XLogPack pack) { + if (ctx.forceNotSamplingDrop) { + return XLogDiscard.NONE; + } XLogDiscard discardMode = pack.error != 0 ? XLogDiscard.NONE : XLogSampler.getInstance().evaluateXLogDiscard(pack.elapsed, ctx.serviceName); //check xlog discard pattern if (XLogSampler.getInstance().isDiscardServicePattern(ctx.serviceName)) { diff --git a/scouter.agent.java/src/main/java/scouter/weaver/TraceSupport.java b/scouter.agent.java/src/main/java/scouter/weaver/TraceSupport.java index fce3dbd4a..b9744a6ab 100644 --- a/scouter.agent.java/src/main/java/scouter/weaver/TraceSupport.java +++ b/scouter.agent.java/src/main/java/scouter/weaver/TraceSupport.java @@ -49,10 +49,8 @@ public static Object startServiceAndGetCtx(String serviceName) { } public static Object startServiceWithCustomTxidAndGetCtx(String serviceName, String customTxid) { - Object o = TraceMain.startService(serviceName, "_custom_", serviceName, "_none_", dummyObj, dummyArgs, XLogTypes.APP_SERVICE); - TraceContext ctx = ((LocalContext) o).context; - TraceContextManager.linkCustomTxid(customTxid, ctx.txid); - return o; + return TraceMain.startServiceWithCustomTxid(serviceName, "_custom_", serviceName, "_none_", dummyObj, dummyArgs, + XLogTypes.APP_SERVICE, customTxid); } public static void endServiceByCtx(Object anyCtx, Throwable thr) { From 37e6e826ca77d469881b3dc7f675a9c35a78131b Mon Sep 17 00:00:00 2001 From: Gun Lee Date: Sat, 25 Dec 2021 15:01:38 +0900 Subject: [PATCH 14/20] [agent.java] change maps of holding trace contexts from scouter's primitive collection to un-primitive read lock free map. --- .../scouter/agent/summary/ServiceSummary.java | 73 ++++++++++--------- .../java/scouter/agent/trace/TransferMap.java | 5 +- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/scouter.agent.java/src/main/java/scouter/agent/summary/ServiceSummary.java b/scouter.agent.java/src/main/java/scouter/agent/summary/ServiceSummary.java index c76afcae1..f4e6ce5be 100644 --- a/scouter.agent.java/src/main/java/scouter/agent/summary/ServiceSummary.java +++ b/scouter.agent.java/src/main/java/scouter/agent/summary/ServiceSummary.java @@ -18,6 +18,7 @@ import scouter.agent.Configure; import scouter.agent.netio.data.DataProxy; +import scouter.agent.util.SimpleLru; import scouter.io.DataInputX; import scouter.lang.SummaryEnum; import scouter.lang.pack.SummaryPack; @@ -25,12 +26,10 @@ import scouter.lang.step.ApiCallStep; import scouter.lang.step.SqlStep; import scouter.lang.value.ListValue; -import scouter.util.*; -import scouter.util.IntIntLinkedMap.IntIntLinkedEntry; -import scouter.util.IntKeyLinkedMap.IntKeyLinkedEntry; -import scouter.util.LongKeyLinkedMap.LongKeyLinkedEntry; +import scouter.util.BitUtil; +import scouter.util.IPUtil; -import java.util.Enumeration; +import java.util.Map; public class ServiceSummary { @@ -114,8 +113,8 @@ public void process(ApiCallStep apiStep) { } } - private synchronized SummaryData getSummaryMap(IntKeyLinkedMap table, int hash) { - IntKeyLinkedMap tempTable = table; + private synchronized SummaryData getSummaryMap(SimpleLru table, int hash) { + SimpleLru tempTable = table; SummaryData d = tempTable.get(hash); if (d == null) { d = new SummaryData(); @@ -124,9 +123,9 @@ private synchronized SummaryData getSummaryMap(IntKeyLinkedMap tabl return d; } - private synchronized ErrorData getSummaryError(LongKeyLinkedMap table, long key) { + private synchronized ErrorData getSummaryError(SimpleLru table, long key) { - LongKeyLinkedMap tempTable = table; + SimpleLru tempTable = table; ErrorData d = tempTable.get(key); if (d == null) { d = new ErrorData(); @@ -135,36 +134,44 @@ private synchronized ErrorData getSummaryError(LongKeyLinkedMap table return d; } - private LongKeyLinkedMap errorMaster = new LongKeyLinkedMap() - .setMax(conf._summary_error_max_count); +// private LongKeyLinkedMap errorMaster = new LongKeyLinkedMap().setMax(conf._summary_error_max_count); + private SimpleLru errorMaster = new SimpleLru(conf._summary_error_max_count); - private IntKeyLinkedMap sqlMaster = new IntKeyLinkedMap().setMax(conf._summary_sql_max_count); - private IntKeyLinkedMap apiMaster = new IntKeyLinkedMap().setMax(conf._summary_api_max_count); - private IntKeyLinkedMap serviceMaster = new IntKeyLinkedMap() - .setMax(conf._summary_service_max_count); - private IntIntLinkedMap ipMaster = new IntIntLinkedMap().setMax(conf._summary_ip_max_count); - private IntIntLinkedMap uaMaster = new IntIntLinkedMap().setMax(conf._summary_useragent_max_count); +// private IntKeyLinkedMap sqlMaster = new SimpleLru().setMax(conf._summary_sql_max_count); + private SimpleLru sqlMaster = new SimpleLru(conf._summary_sql_max_count); + +// private IntKeyLinkedMap apiMaster = new IntKeyLinkedMap().setMax(conf._summary_api_max_count); + private SimpleLru apiMaster = new SimpleLru(conf._summary_api_max_count); + +// private IntKeyLinkedMap serviceMaster = new IntKeyLinkedMap().setMax(conf._summary_service_max_count); + private SimpleLru serviceMaster = new SimpleLru(conf._summary_service_max_count); + +// private IntIntLinkedMap ipMaster = new IntIntLinkedMap().setMax(conf._summary_ip_max_count); + private SimpleLru ipMaster = new SimpleLru(conf._summary_ip_max_count); + +// private IntIntLinkedMap uaMaster = new IntIntLinkedMap().setMax(conf._summary_useragent_max_count); + private SimpleLru uaMaster = new SimpleLru(conf._summary_useragent_max_count); public SummaryPack getAndClear(byte type) { - IntKeyLinkedMap temp; + SimpleLru temp; switch (type) { case SummaryEnum.APP: if (serviceMaster.size() == 0) return null; temp = serviceMaster; - serviceMaster = new IntKeyLinkedMap().setMax(conf._summary_service_max_count); + serviceMaster = new SimpleLru(conf._summary_service_max_count); break; case SummaryEnum.SQL: if (sqlMaster.size() == 0) return null; temp = sqlMaster; - sqlMaster = new IntKeyLinkedMap().setMax(conf._summary_sql_max_count); + sqlMaster = new SimpleLru(conf._summary_sql_max_count); break; case SummaryEnum.APICALL: if (apiMaster.size() == 0) return null; temp = apiMaster; - apiMaster = new IntKeyLinkedMap().setMax(conf._summary_api_max_count); + apiMaster = new SimpleLru(conf._summary_api_max_count); break; default: return null; @@ -185,9 +192,7 @@ public SummaryPack getAndClear(byte type) { cpu = p.table.newList("cpu"); mem = p.table.newList("mem"); } - Enumeration> en = temp.entries(); - for (int i = 0; i < cnt; i++) { - IntKeyLinkedEntry ent = en.nextElement(); + for (Map.Entry ent : temp.entrySet()) { int key = ent.getKey(); SummaryData data = ent.getValue(); id.add(key); @@ -203,19 +208,19 @@ public SummaryPack getAndClear(byte type) { } public SummaryPack getAndClearX(byte type) { - IntIntLinkedMap temp; + SimpleLru temp; switch (type) { case SummaryEnum.IP: if (ipMaster.size() == 0) return null; temp = ipMaster; - ipMaster = new IntIntLinkedMap().setMax(conf._summary_ip_max_count); + ipMaster = new SimpleLru(conf._summary_ip_max_count); break; case SummaryEnum.USER_AGENT: if (uaMaster.size() == 0) return null; temp = uaMaster; - uaMaster = new IntIntLinkedMap().setMax(conf._summary_useragent_max_count); + uaMaster = new SimpleLru(conf._summary_useragent_max_count); break; default: return null; @@ -228,9 +233,7 @@ public SummaryPack getAndClearX(byte type) { ListValue id = p.table.newList("id"); ListValue count = p.table.newList("count"); - Enumeration en = temp.entries(); - for (int i = 0; i < cnt; i++) { - IntIntLinkedEntry ent = en.nextElement(); + for (Map.Entry ent : temp.entrySet()) { int key = ent.getKey(); int value = ent.getValue(); id.add(key); @@ -243,8 +246,8 @@ public SummaryPack getAndClearError(byte type) { if (errorMaster.size() == 0) return null; - LongKeyLinkedMap temp = errorMaster; - errorMaster = new LongKeyLinkedMap().setMax(conf._summary_error_max_count); + SimpleLru temp = errorMaster; + errorMaster = new SimpleLru(conf._summary_error_max_count); SummaryPack p = new SummaryPack(); p.stype = type; @@ -261,9 +264,7 @@ public SummaryPack getAndClearError(byte type) { ListValue apicall = p.table.newList("apicall"); ListValue fullstack = p.table.newList("fullstack"); - Enumeration> en = temp.entries(); - for (int i = 0; i < cnt; i++) { - LongKeyLinkedEntry ent = en.nextElement(); + for (Map.Entry ent : temp.entrySet()) { long key = ent.getKey(); ErrorData data = ent.getValue(); id.add(key); @@ -278,4 +279,4 @@ public SummaryPack getAndClearError(byte type) { } return p; } -} \ No newline at end of file +} diff --git a/scouter.agent.java/src/main/java/scouter/agent/trace/TransferMap.java b/scouter.agent.java/src/main/java/scouter/agent/trace/TransferMap.java index 286f53b3c..db89481be 100644 --- a/scouter.agent.java/src/main/java/scouter/agent/trace/TransferMap.java +++ b/scouter.agent.java/src/main/java/scouter/agent/trace/TransferMap.java @@ -1,7 +1,7 @@ package scouter.agent.trace; +import scouter.agent.util.SimpleLru; import scouter.lang.step.ThreadCallPossibleStep; -import scouter.util.IntKeyLinkedMap; public class TransferMap { public static class ID { @@ -26,7 +26,8 @@ public ID(long gxid, long caller, long callee, byte xType, long callerThreadId, } } - private static IntKeyLinkedMap map = new IntKeyLinkedMap().setMax(2001); + //private static IntKeyLinkedMap map = new IntKeyLinkedMap().setMax(2001); + private static SimpleLru map = new SimpleLru(2001); public static void put(int hash, long gxid, long caller, long callee, byte xType) { put(hash, gxid, caller, callee, xType, 0L, null); From 4c05c8e83ed2f0f49634b2bd99e9c2fbdda45d00 Mon Sep 17 00:00:00 2001 From: Gun Lee Date: Sat, 25 Dec 2021 21:18:26 +0900 Subject: [PATCH 15/20] documentation for scouter.weaver --- README.md | 2 + README_kr.md | 1 + pom.xml | 2 +- scouter.agent.batch/pom.xml | 2 +- scouter.agent.host/pom.xml | 2 +- scouter.agent.java/pom.xml | 2 +- .../agent/asm/JDBCPreparedStatementASM.java | 2 +- scouter.common/pom.xml | 2 +- scouter.deploy/pom.xml | 2 +- scouter.document/weaver/Weaver-Guide.md | 97 +++++++++ scouter.document/weaver/Weaver-Guide_kr.md | 98 +++++++++ scouter.server.boot/pom.xml | 2 +- scouter.server/pom.xml | 2 +- scouter.weaver/pom.xml | 2 +- .../main/java/scouterx/weaver/Scouter.java | 205 +++++++++++++++++- scouter.webapp/pom.xml | 2 +- 16 files changed, 411 insertions(+), 14 deletions(-) create mode 100644 scouter.document/weaver/Weaver-Guide.md create mode 100644 scouter.document/weaver/Weaver-Guide_kr.md diff --git a/README.md b/README.md index 2471171d5..1e197fb25 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,8 @@ SCOUTER can help you. - **Web API (Since @1.8.0)** : scouter web apis to get counters, XLogs, profiles and another performance metrics via HTTP protocol. - [Web API Guide](./scouter.document/tech/Web-API-Guide.md) +- **Weaver (Since @2.17.0)** : Provides the ability to directly control Scouter XLog and Profiles at the code level of Java applications. + - [Scouter Weaver Guide](./scouter.document/weaver/Weaver-Guide.md) ### 3rd-party UIs - **scouter paper** : [scouter paper homepage](https://scouter-contrib.github.io/scouter-paper/) diff --git a/README_kr.md b/README_kr.md index 400ad0f84..0020a9a98 100644 --- a/README_kr.md +++ b/README_kr.md @@ -60,6 +60,7 @@ - **Web API (Since @1.8.0)** : 성능 카운터, XLog, 프로파일등의 정보를 HTTP 프로토콜을 통해 제공 - [Web API Guide](./scouter.document/tech/Web-API-Guide_kr.md) +- **Weaver (Since @2.17.0)** : Java 애플리케이션의 코드 수준에서 Scouter XLog와 Profile을 직접 제어하는 기능 제공 ### 3rd-party UIs - **scouter paper** : [scouter-paper homepage](https://scouter-contrib.github.io/scouter-paper/) diff --git a/pom.xml b/pom.xml index e441ae294..40a1fe0b6 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.scouter-project scouter-parent - 2.17.0-SNAPSHOT + 2.17.1-SNAPSHOT pom SCOUTER APM diff --git a/scouter.agent.batch/pom.xml b/scouter.agent.batch/pom.xml index 6d61d347c..a1227b25e 100644 --- a/scouter.agent.batch/pom.xml +++ b/scouter.agent.batch/pom.xml @@ -5,7 +5,7 @@ io.github.scouter-project scouter-parent - 2.17.0-SNAPSHOT + 2.17.1-SNAPSHOT scouter-agent-batch diff --git a/scouter.agent.host/pom.xml b/scouter.agent.host/pom.xml index 2b91f709d..f53389505 100644 --- a/scouter.agent.host/pom.xml +++ b/scouter.agent.host/pom.xml @@ -4,7 +4,7 @@ io.github.scouter-project scouter-parent - 2.17.0-SNAPSHOT + 2.17.1-SNAPSHOT scouter-agent-host diff --git a/scouter.agent.java/pom.xml b/scouter.agent.java/pom.xml index e34e6b47e..0afcfc054 100644 --- a/scouter.agent.java/pom.xml +++ b/scouter.agent.java/pom.xml @@ -4,7 +4,7 @@ io.github.scouter-project scouter-parent - 2.17.0-SNAPSHOT + 2.17.1-SNAPSHOT scouter-agent-java diff --git a/scouter.agent.java/src/main/java/scouter/agent/asm/JDBCPreparedStatementASM.java b/scouter.agent.java/src/main/java/scouter/agent/asm/JDBCPreparedStatementASM.java index f1792e1f7..faea97d93 100644 --- a/scouter.agent.java/src/main/java/scouter/agent/asm/JDBCPreparedStatementASM.java +++ b/scouter.agent.java/src/main/java/scouter/agent/asm/JDBCPreparedStatementASM.java @@ -91,7 +91,7 @@ public JDBCPreparedStatementASM() { noField.add("jdbc/FakePreparedStatement2"); noField.add("org/mariadb/jdbc/MariaDbClientPreparedStatement"); noField.add("org/mariadb/jdbc/MariaDbServerPreparedStatement"); - target.add("com/mysql/cj/jdbc/ServerPreparedStatement"); + noField.add("com/mysql/cj/jdbc/ServerPreparedStatement"); } public ClassVisitor transform(ClassVisitor cv, String className, ClassDesc classDesc) { diff --git a/scouter.common/pom.xml b/scouter.common/pom.xml index c313bf29f..26e1413ed 100644 --- a/scouter.common/pom.xml +++ b/scouter.common/pom.xml @@ -4,7 +4,7 @@ io.github.scouter-project scouter-parent - 2.17.0-SNAPSHOT + 2.17.1-SNAPSHOT scouter-common diff --git a/scouter.deploy/pom.xml b/scouter.deploy/pom.xml index 0b5c1622a..49ecca122 100644 --- a/scouter.deploy/pom.xml +++ b/scouter.deploy/pom.xml @@ -4,7 +4,7 @@ io.github.scouter-project scouter-parent - 2.17.0-SNAPSHOT + 2.17.1-SNAPSHOT scouter-deploy diff --git a/scouter.document/weaver/Weaver-Guide.md b/scouter.document/weaver/Weaver-Guide.md new file mode 100644 index 000000000..dc2c7b690 --- /dev/null +++ b/scouter.document/weaver/Weaver-Guide.md @@ -0,0 +1,97 @@ +# Scouter Weaver Guide +[![English](https://img.shields.io/badge/language-English-orange.svg)](Weaver-Guide.md) [![Korean](https://img.shields.io/badge/language-Korean-blue.svg)](Weaver-Guide_kr.md) + +You can directly control the scouter's xlog and profile through Scouter Weaver. +* Start tracing and End tracing of XLog trace. +* Add Method Profile. +* Add message profile. +* Link to scouter trace context with custom transaction id. +* Set values for XLog fields. + +## Installation +* Maven +```xml + + io.github.scouter-project + scouter-weaver + {scouter_version} + +``` + +* Gradle +```groovy +implementation 'io.github.scouter-project:scouter-weaver:{scouter_version}' //2.17.1 +``` + +## How to use +Refer to Scouter Weaver class description. + - [Weaver class](https://github.com/scouter-project/scouter/blob/master/scouter.weaver/src/main/java/scouterx/weaver/Scouter.java) + +### start & end trace + +```java +TransferCtx tctx = Scouter.startServiceAndGetCtxTransfer("{service_api_name}"); +doSomething(); +Scouter.endServiceByCtxTransfer(tctx, null); //commonly inside finally staterment +//or +// Scouter.endServiceOnTheSameThread(null); +``` +do with custom transaction id +```java +TransferCtx tctx = Scouter.startServiceWithCustomTxidAndGetCtxTransfer("{service_api_name}", "{customTxid}"); +doSomething(); +Scouter.endServiceByCustomTxid("{customTxid}", null); +``` + +### add method profile +```java +void doSomething(TransferCtx tctx, ...) { + MethodCtx mctx = MethodCtxScouter.startMethodOnTheSameThread("doSomething"); + //or Scouter.startMethodByCtxTransfer(), Scouter.startMethodByCustomTxid(); + try { + doOthers(); + } finally { + Scouter.endMethodByMethodTransfer(mctx, null); + } +} +``` + +### add profiles +```java +Scouter.addMessageProfileOnTheSameThread("{simple massage}"); +Scouter.addHashedMessageProfileOnTheSameThread("{massage for dictionary encoding in scouter}", 0, 0); //메시지 전체가 사전에 인덱싱 되므로 메시지 종류가 수천개 미만인 경우 사용해야 합니다. (그렇지 않으면 사전 성능이 저하됩니다.) +Scouter.addParameterizedMessageProfileOnTheSameThread("{massage with param %s, param2: %s}", ProfileLevel.INFO, 0, param1, param2); + +``` + +### get trace info and support methods +```java +boolean scouterActivated = Scouter.isScouterJavaAgentActivated(); //check if scouter agent is activated. + +TransferCtx tctx = Scouter.getTransferCtxOnTheSameThread(); //get aleady started scouter trace transfer context. + +Scouter.linkCustomTxidOnTheSameThread("{my custom txid}"); //link my custom trace id onto the scouter trace context. +Scouter.linkCustomTxidByCtxTransfer("{my custom txid}", transferCtx) {} + +ScouterTxid stxid = getTxidOnTheSameThread(); +ScouterTxid stxid = getTxidByCustomTxid("{my custom txid}"); + + +``` + + +### add xlog column values +```java +Scouter.setXlogServiceDictionaryValue(scouterTxid, "{service api name}"); +/* + see other methods... + setXlogUaDictionaryValue() + setXlogErrorDictionaryValue() + setXlogIpValue() + setXlogLoginDictionaryValue() + setXlogDescDictionaryValue() + setXlogText1Value() + setXlogText2Value() + setXlogText3Value() + */ +``` diff --git a/scouter.document/weaver/Weaver-Guide_kr.md b/scouter.document/weaver/Weaver-Guide_kr.md new file mode 100644 index 000000000..2b79a5acb --- /dev/null +++ b/scouter.document/weaver/Weaver-Guide_kr.md @@ -0,0 +1,98 @@ +# Scouter Weaver Guide +[![English](https://img.shields.io/badge/language-English-orange.svg)](Weaver-Guide.md) [![Korean](https://img.shields.io/badge/language-Korean-blue.svg)](Weaver-Guide_kr.md) + +Scouter Weaver를 통해 scouter의 xlog와 profile을 직접 제어할 수 있다. +* XLog trace의 시작/종료 +* Method Profile 추가 +* 메시지 Profile 추가 +* 커스텀 transaction id와 연결 +* XLog 기본 필드 및 사용자 정의 필드에 값 설정 + +## Installation + +* Maven +```xml + + io.github.scouter-project + scouter-weaver + {scouter_version} + +``` + +* Gradle +```groovy +implementation 'io.github.scouter-project:scouter-weaver:{scouter_version}' //2.17.1 +``` + +## How to use +Refer to Scouter Weaver class description. + - [Weaver class](https://github.com/scouter-project/scouter/blob/master/scouter.weaver/src/main/java/scouterx/weaver/Scouter.java) + +### start & end trace + +```java +TransferCtx tctx = Scouter.startServiceAndGetCtxTransfer("{service_api_name}"); +doSomething(); +Scouter.endServiceByCtxTransfer(tctx, null); //commonly inside finally staterment +//or +// Scouter.endServiceOnTheSameThread(null); +``` +do with custom transaction id +```java +TransferCtx tctx = Scouter.startServiceWithCustomTxidAndGetCtxTransfer("{service_api_name}", "{customTxid}"); +doSomething(); +Scouter.endServiceByCustomTxid("{customTxid}", null); +``` + +### add method profile +```java +void doSomething(TransferCtx tctx, ...) { + MethodCtx mctx = MethodCtxScouter.startMethodOnTheSameThread("doSomething"); + //or Scouter.startMethodByCtxTransfer(), Scouter.startMethodByCustomTxid(); + try { + doOthers(); + } finally { + Scouter.endMethodByMethodTransfer(mctx, null); + } +} +``` + +### add profiles +```java +Scouter.addMessageProfileOnTheSameThread("{simple massage}"); +Scouter.addHashedMessageProfileOnTheSameThread("{massage for dictionary encoding in scouter}", 0, 0); //메시지 전체가 사전에 인덱싱 되므로 메시지 종류가 수천개 미만인 경우 사용해야 합니다. (그렇지 않으면 사전 성능이 저하됩니다.) +Scouter.addParameterizedMessageProfileOnTheSameThread("{massage with param %s, param2: %s}", ProfileLevel.INFO, 0, param1, param2); + +``` + +### get trace info and support methods +```java +boolean scouterActivated = Scouter.isScouterJavaAgentActivated(); //check if scouter agent is activated. + +TransferCtx tctx = Scouter.getTransferCtxOnTheSameThread(); //get aleady started scouter trace transfer context. + +Scouter.linkCustomTxidOnTheSameThread("{my custom txid}"); //link my custom trace id onto the scouter trace context. +Scouter.linkCustomTxidByCtxTransfer("{my custom txid}", transferCtx) {} + +ScouterTxid stxid = getTxidOnTheSameThread(); +ScouterTxid stxid = getTxidByCustomTxid("{my custom txid}"); + + +``` + + +### add xlog column values +```java +Scouter.setXlogServiceDictionaryValue(scouterTxid, "{service api name}"); +/* + see other methods... + setXlogUaDictionaryValue() + setXlogErrorDictionaryValue() + setXlogIpValue() + setXlogLoginDictionaryValue() + setXlogDescDictionaryValue() + setXlogText1Value() + setXlogText2Value() + setXlogText3Value() + */ +``` diff --git a/scouter.server.boot/pom.xml b/scouter.server.boot/pom.xml index 80bd65149..7a2e7bcc8 100644 --- a/scouter.server.boot/pom.xml +++ b/scouter.server.boot/pom.xml @@ -4,7 +4,7 @@ io.github.scouter-project scouter-parent - 2.17.0-SNAPSHOT + 2.17.1-SNAPSHOT scouter-server-boot diff --git a/scouter.server/pom.xml b/scouter.server/pom.xml index 138b20ee5..f04b593b7 100644 --- a/scouter.server/pom.xml +++ b/scouter.server/pom.xml @@ -4,7 +4,7 @@ io.github.scouter-project scouter-parent - 2.17.0-SNAPSHOT + 2.17.1-SNAPSHOT scouter-server diff --git a/scouter.weaver/pom.xml b/scouter.weaver/pom.xml index 43e64c595..02d91eba4 100644 --- a/scouter.weaver/pom.xml +++ b/scouter.weaver/pom.xml @@ -5,7 +5,7 @@ io.github.scouter-project scouter-parent - 2.17.0-SNAPSHOT + 2.17.1-SNAPSHOT 4.0.0 diff --git a/scouter.weaver/src/main/java/scouterx/weaver/Scouter.java b/scouter.weaver/src/main/java/scouterx/weaver/Scouter.java index 113359d76..9abcaf3d8 100644 --- a/scouter.weaver/src/main/java/scouterx/weaver/Scouter.java +++ b/scouter.weaver/src/main/java/scouterx/weaver/Scouter.java @@ -21,6 +21,10 @@ */ public class Scouter { + /** + * check if scouter java agent is activated + * @return + */ public static boolean isScouterJavaAgentActivated() { Object scouterJavaAgentActivated = Weaving.isScouterJavaAgentActivated(); if (scouterJavaAgentActivated instanceof Boolean) { @@ -30,6 +34,10 @@ public static boolean isScouterJavaAgentActivated() { } } + /** + * get already started transfer context. if the trace is not started, it returns empty transfer(trace) context. + * @return + */ public static TransferCtx getTransferCtxOnTheSameThread() { Object ctx = Weaving.getCtxOnTheSameThread(); if (ctx == null) { @@ -39,6 +47,11 @@ public static TransferCtx getTransferCtxOnTheSameThread() { return new TransferCtx(ctx, ScouterTxid.of(txid)); } + /** + * get already started transfer context. if the trace is not started, it returns empty transfer(trace) context. + * @param customTxid + * @return + */ public static TransferCtx getTransferCtxByCustomTxid(String customTxid) { Object ctx = Weaving.getCtxByCustomTxid(customTxid); if (ctx == null) { @@ -48,6 +61,11 @@ public static TransferCtx getTransferCtxByCustomTxid(String customTxid) { return new TransferCtx(ctx, ScouterTxid.of(txid)); } + /** + * start trace(Xlog) for the serviceName and generate new transferCtx of the transaction for transferring a trace context via service flow. + * @param serviceName + * @return + */ public static TransferCtx startServiceAndGetCtxTransfer(String serviceName) { try { Object ctx = Weaving.startServiceAndGetCtx(serviceName); @@ -62,6 +80,12 @@ public static TransferCtx startServiceAndGetCtxTransfer(String serviceName) { } } + /** + * start trace(Xlog) for the serviceName with connecting custom txid with scouter + * and generate new transferCtx of the transaction for transferring a trace context via service flow. + * @param serviceName + * @return + */ public static TransferCtx startServiceWithCustomTxidAndGetCtxTransfer(String serviceName, String customTxid) { try { Object ctx = Weaving.startServiceWithCustomTxidAndGetCtx(serviceName, customTxid); @@ -76,6 +100,12 @@ public static TransferCtx startServiceWithCustomTxidAndGetCtxTransfer(String ser } } + /** + * end trace(Xlog) and internally measure an elapsed time of service. + * error is marked on the xlog if thr is not null + * @param ctxTransfer + * @param thr + */ public static void endServiceByCtxTransfer(TransferCtx ctxTransfer, Throwable thr) { if (ctxTransfer == null || ctxTransfer.isEmpty()) { return; @@ -87,6 +117,12 @@ public static void endServiceByCtxTransfer(TransferCtx ctxTransfer, Throwable th } } + /** + * end trace(Xlog) and internally measure an elapsed time of service. + * error is marked on the xlog if thr is not null + * @param customTxid + * @param thr + */ public static void endServiceByCustomTxid(String customTxid, Throwable thr) { try { Weaving.endServiceByCustomTxid(customTxid, thr); @@ -95,6 +131,11 @@ public static void endServiceByCustomTxid(String customTxid, Throwable thr) { } } + /** + * end trace(Xlog) and internally measure an elapsed time of service. + * error is marked on the xlog if thr is not null + * @param thr + */ public static void endServiceOnTheSameThread(Throwable thr) { try { Weaving.endServiceOnTheSameThread(thr); @@ -103,6 +144,12 @@ public static void endServiceOnTheSameThread(Throwable thr) { } } + /** + * start method profiling + * @param ctxTransfer + * @param name + * @return + */ public static MethodCtx startMethodByCtxTransfer(TransferCtx ctxTransfer, String name) { if (ctxTransfer == null || ctxTransfer.isEmpty()) { return MethodCtx.EMPTY; @@ -115,6 +162,11 @@ public static MethodCtx startMethodByCtxTransfer(TransferCtx ctxTransfer, String } } + /** + * start method profiling + * @param name + * @return + */ public static MethodCtx startMethodOnTheSameThread(String name) { try { return new MethodCtx(Weaving.startMethodOnTheSameThread(name)); @@ -124,6 +176,12 @@ public static MethodCtx startMethodOnTheSameThread(String name) { } } + /** + * start method profiling + * @param customTxid + * @param name + * @return + */ public static MethodCtx startMethodByCustomTxid(String customTxid, String name) { try { return new MethodCtx(Weaving.startMethodByCustomTxid(customTxid, name)); @@ -133,6 +191,11 @@ public static MethodCtx startMethodByCustomTxid(String customTxid, String name) } } + /** + * end method profiling and mark this method's elapsed time on the profile. + * @param methodTransfer + * @param thr + */ public static void endMethodByMethodTransfer(MethodCtx methodTransfer, Throwable thr) { if (methodTransfer == null || methodTransfer.isEmpty()) { return; @@ -144,6 +207,11 @@ public static void endMethodByMethodTransfer(MethodCtx methodTransfer, Throwable } } + /** + * add message profile + * @param ctxTransfer + * @param message + */ public static void addMessageProfileByCtxTransfer(TransferCtx ctxTransfer, String message) { if (ctxTransfer == null || ctxTransfer.isEmpty()) { return; @@ -155,6 +223,11 @@ public static void addMessageProfileByCtxTransfer(TransferCtx ctxTransfer, Strin } } + /** + * add message profile + * @param customTxid + * @param message + */ public static void addMessageProfileByCustomTxid(String customTxid, String message) { try { Weaving.addMessageProfileByCustomTxid(customTxid, message); @@ -163,6 +236,10 @@ public static void addMessageProfileByCustomTxid(String customTxid, String messa } } + /** + * add message profile + * @param message + */ public static void addMessageProfileOnTheSameThread(String message) { try { Weaving.addMessageProfileOnTheSameThread(message); @@ -171,6 +248,13 @@ public static void addMessageProfileOnTheSameThread(String message) { } } + /** + * add hashed(dictionary encoded) message profile. + * @param ctxTransfer + * @param message + * @param elapsedMs + * @param anyValue + */ public static void addHashedMessageProfileByCtxTransfer(TransferCtx ctxTransfer, String message, int elapsedMs, int anyValue) { if (ctxTransfer == null || ctxTransfer.isEmpty()) { return; @@ -182,6 +266,13 @@ public static void addHashedMessageProfileByCtxTransfer(TransferCtx ctxTransfer, } } + /** + * add hashed(dictionary encoded) message profile. + * @param customTxid + * @param message + * @param elapsedMs + * @param anyValue + */ public static void addHashedMessageProfileByCustomTxid(String customTxid, String message, int elapsedMs, int anyValue) { try { Weaving.addHashedMessageProfileByCustomTxid(customTxid, message, elapsedMs, anyValue); @@ -190,6 +281,12 @@ public static void addHashedMessageProfileByCustomTxid(String customTxid, String } } + /** + * add hashed(dictionary encoded) message profile. + * @param message + * @param elapsedMs + * @param anyValue + */ public static void addHashedMessageProfileOnTheSameThread(String message, int elapsedMs, int anyValue) { try { Weaving.addHashedMessageProfileOnTheSameThread(message, elapsedMs, anyValue); @@ -198,6 +295,14 @@ public static void addHashedMessageProfileOnTheSameThread(String message, int el } } + /** + * add hashed(dictionary encoded) with parameterized message profile. + * @param ctxTransfer + * @param message + * @param level + * @param elapsedMs + * @param params + */ public static void addParameterizedMessageProfileByCtxTransfer(TransferCtx ctxTransfer, String message, ProfileLevel level, int elapsedMs, String... params) { if (ctxTransfer == null || ctxTransfer.isEmpty()) { return; @@ -209,6 +314,14 @@ public static void addParameterizedMessageProfileByCtxTransfer(TransferCtx ctxTr } } + /** + * add hashed(dictionary encoded) with parameterized message profile. + * @param customTxid + * @param message + * @param level + * @param elapsedMs + * @param params + */ public static void addParameterizedMessageProfileByCustomTxid(String customTxid, String message, ProfileLevel level, int elapsedMs, String... params) { try { Weaving.addParameterizedMessageProfileByCustomTxid(customTxid, message, level.getLevel(), elapsedMs, params); @@ -217,6 +330,13 @@ public static void addParameterizedMessageProfileByCustomTxid(String customTxid, } } + /** + * add hashed(dictionary encoded) with parameterized message profile. + * @param message + * @param level + * @param elapsedMs + * @param params + */ public static void addParameterizedMessageProfileOnTheSameThread(String message, ProfileLevel level, int elapsedMs, String... params) { try { Weaving.addParameterizedMessageProfileOnTheSameThread(message, level.getLevel(), elapsedMs, params); @@ -225,22 +345,38 @@ public static void addParameterizedMessageProfileOnTheSameThread(String message, } } - //txid getters + /** + * get ScouterTxid + * @return + */ public static ScouterTxid getTxidOnTheSameThread() { Object txid = Weaving.getTxidOnTheSameThread(); return ScouterTxid.of(txid); } + /** + * get ScouterTxid + * @param customTxid + * @return + */ public static ScouterTxid getTxidByCustomTxid(String customTxid) { Object txid = Weaving.getTxidByCustomTxid(customTxid); return ScouterTxid.of(txid); } - //link custom txid + /** + * link custom txid onto the scouter trace context. + * @param customTxid + */ public static void linkCustomTxidOnTheSameThread(String customTxid) { Weaving.linkCustomTxidOnTheSameThread(customTxid); } + /** + * link custom txid onto the scouter trace context. + * @param customTxid + * @param ctxTransfer + */ public static void linkCustomTxidByCtxTransfer(String customTxid, TransferCtx ctxTransfer) { if (ctxTransfer == null || ctxTransfer.isEmpty()) { return; @@ -248,25 +384,47 @@ public static void linkCustomTxidByCtxTransfer(String customTxid, TransferCtx ct Weaving.linkCustomTxidByCtx(customTxid, ctxTransfer.ctx); } - //xlog info setters + /** + * add value onto xlog service column + * @param txid + * @param value + */ public static void setXlogServiceDictionaryValue(ScouterTxid txid, String value) { if (txid == null || txid.isEmpty() || value == null) { return; } Weaving.setXlogServiceValue(txid.getTxid(), value); } + + /** + * add value onto xlog ip column + * @param txid + * @param value + */ public static void setXlogIpValue(ScouterTxid txid, String value) { if (txid == null || txid.isEmpty() || value == null) { return; } Weaving.setXlogIpValue(txid.getTxid(), value); } + + /** + * add value onto xlog user agent column + * @param txid + * @param value + */ public static void setXlogUaDictionaryValue(ScouterTxid txid, String value) { if (txid == null || txid.isEmpty() || value == null) { return; } Weaving.setXlogUaValue(txid.getTxid(), value); } + + /** + * add value onto xlog error column + * @param txid + * @param value + */ public static void setXlogErrorDictionaryValue(ScouterTxid txid, String value) { if (txid == null || txid.isEmpty() || value == null) { return; @@ -274,42 +432,83 @@ public static void setXlogErrorDictionaryValue(ScouterTxid txid, String value) { Weaving.setXlogErrorValue(txid.getTxid(), value); } + /** + * add value onto xlog login column + * @param txid + * @param value + */ public static void setXlogLoginDictionaryValue(ScouterTxid txid, String value) { if (txid == null || txid.isEmpty() || value == null) { return; } Weaving.setXlogLoginValue(txid.getTxid(), value); } + + /** + * add value onto xlog desc column + * @param txid + * @param value + */ public static void setXlogDescDictionaryValue(ScouterTxid txid, String value) { if (txid == null || txid.isEmpty() || value == null) { return; } Weaving.setXlogDescValue(txid.getTxid(), value); } + + /** + * add value onto xlog text1 column + * @param txid + * @param value + */ public static void setXlogText1Value(ScouterTxid txid, String value) { if (txid == null || txid.isEmpty() || value == null) { return; } Weaving.setXlogText1Value(txid.getTxid(), value); } + + /** + * add value onto xlog text2 column + * @param txid + * @param value + */ public static void setXlogText2Value(ScouterTxid txid, String value) { if (txid == null || txid.isEmpty() || value == null) { return; } Weaving.setXlogText2Value(txid.getTxid(), value); } + + /** + * add value onto xlog text3 column + * @param txid + * @param value + */ public static void setXlogText3Value(ScouterTxid txid, String value) { if (txid == null || txid.isEmpty() || value == null) { return; } Weaving.setXlogText3Value(txid.getTxid(), value); } + + /** + * add value onto xlog text4 column + * @param txid + * @param value + */ public static void setXlogText4Value(ScouterTxid txid, String value) { if (txid == null || txid.isEmpty() || value == null) { return; } Weaving.setXlogText4Value(txid.getTxid(), value); } + + /** + * add value onto xlog text5 column + * @param txid + * @param value + */ public static void setXlogText5Value(ScouterTxid txid, String value) { if (txid == null || txid.isEmpty() || value == null) { return; diff --git a/scouter.webapp/pom.xml b/scouter.webapp/pom.xml index 9f5f9391b..6a077385b 100644 --- a/scouter.webapp/pom.xml +++ b/scouter.webapp/pom.xml @@ -5,7 +5,7 @@ io.github.scouter-project scouter-parent - 2.17.0-SNAPSHOT + 2.17.1-SNAPSHOT 4.0.0 From cb919b6008e85f5ad3be5e29a5a8316aa3c4c426 Mon Sep 17 00:00:00 2001 From: Gun Lee Date: Mon, 27 Dec 2021 11:51:23 +0900 Subject: [PATCH 16/20] WIP check xlog display missing after ServiceSummary.java modified --- .../scouter/agent/summary/ServiceSummary.java | 131 +++++++++--------- 1 file changed, 65 insertions(+), 66 deletions(-) diff --git a/scouter.agent.java/src/main/java/scouter/agent/summary/ServiceSummary.java b/scouter.agent.java/src/main/java/scouter/agent/summary/ServiceSummary.java index f4e6ce5be..e978956c4 100644 --- a/scouter.agent.java/src/main/java/scouter/agent/summary/ServiceSummary.java +++ b/scouter.agent.java/src/main/java/scouter/agent/summary/ServiceSummary.java @@ -1,8 +1,8 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015 the original author or authors. * @https://github.com/scouter-project/scouter * - * Licensed under the Apache License, Version 2.0 (the "License"); + * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * @@ -12,13 +12,12 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License. + * limitations under the License. */ package scouter.agent.summary; import scouter.agent.Configure; import scouter.agent.netio.data.DataProxy; -import scouter.agent.util.SimpleLru; import scouter.io.DataInputX; import scouter.lang.SummaryEnum; import scouter.lang.pack.SummaryPack; @@ -26,10 +25,12 @@ import scouter.lang.step.ApiCallStep; import scouter.lang.step.SqlStep; import scouter.lang.value.ListValue; -import scouter.util.BitUtil; -import scouter.util.IPUtil; +import scouter.util.*; +import scouter.util.IntIntLinkedMap.IntIntLinkedEntry; +import scouter.util.IntKeyLinkedMap.IntKeyLinkedEntry; +import scouter.util.LongKeyLinkedMap.LongKeyLinkedEntry; -import java.util.Map; +import java.util.Enumeration; public class ServiceSummary { @@ -113,8 +114,8 @@ public void process(ApiCallStep apiStep) { } } - private synchronized SummaryData getSummaryMap(SimpleLru table, int hash) { - SimpleLru tempTable = table; + private synchronized SummaryData getSummaryMap(IntKeyLinkedMap table, int hash) { + IntKeyLinkedMap tempTable = table; SummaryData d = tempTable.get(hash); if (d == null) { d = new SummaryData(); @@ -123,9 +124,9 @@ private synchronized SummaryData getSummaryMap(SimpleLru t return d; } - private synchronized ErrorData getSummaryError(SimpleLru table, long key) { + private synchronized ErrorData getSummaryError(LongKeyLinkedMap table, long key) { - SimpleLru tempTable = table; + LongKeyLinkedMap tempTable = table; ErrorData d = tempTable.get(key); if (d == null) { d = new ErrorData(); @@ -134,47 +135,39 @@ private synchronized ErrorData getSummaryError(SimpleLru table, return d; } -// private LongKeyLinkedMap errorMaster = new LongKeyLinkedMap().setMax(conf._summary_error_max_count); - private SimpleLru errorMaster = new SimpleLru(conf._summary_error_max_count); + private LongKeyLinkedMap errorMaster = new LongKeyLinkedMap() + .setMax(conf._summary_error_max_count); -// private IntKeyLinkedMap sqlMaster = new SimpleLru().setMax(conf._summary_sql_max_count); - private SimpleLru sqlMaster = new SimpleLru(conf._summary_sql_max_count); - -// private IntKeyLinkedMap apiMaster = new IntKeyLinkedMap().setMax(conf._summary_api_max_count); - private SimpleLru apiMaster = new SimpleLru(conf._summary_api_max_count); - -// private IntKeyLinkedMap serviceMaster = new IntKeyLinkedMap().setMax(conf._summary_service_max_count); - private SimpleLru serviceMaster = new SimpleLru(conf._summary_service_max_count); - -// private IntIntLinkedMap ipMaster = new IntIntLinkedMap().setMax(conf._summary_ip_max_count); - private SimpleLru ipMaster = new SimpleLru(conf._summary_ip_max_count); - -// private IntIntLinkedMap uaMaster = new IntIntLinkedMap().setMax(conf._summary_useragent_max_count); - private SimpleLru uaMaster = new SimpleLru(conf._summary_useragent_max_count); + private IntKeyLinkedMap sqlMaster = new IntKeyLinkedMap().setMax(conf._summary_sql_max_count); + private IntKeyLinkedMap apiMaster = new IntKeyLinkedMap().setMax(conf._summary_api_max_count); + private IntKeyLinkedMap serviceMaster = new IntKeyLinkedMap() + .setMax(conf._summary_service_max_count); + private IntIntLinkedMap ipMaster = new IntIntLinkedMap().setMax(conf._summary_ip_max_count); + private IntIntLinkedMap uaMaster = new IntIntLinkedMap().setMax(conf._summary_useragent_max_count); public SummaryPack getAndClear(byte type) { - SimpleLru temp; + IntKeyLinkedMap temp; switch (type) { - case SummaryEnum.APP: - if (serviceMaster.size() == 0) - return null; - temp = serviceMaster; - serviceMaster = new SimpleLru(conf._summary_service_max_count); - break; - case SummaryEnum.SQL: - if (sqlMaster.size() == 0) + case SummaryEnum.APP: + if (serviceMaster.size() == 0) + return null; + temp = serviceMaster; + serviceMaster = new IntKeyLinkedMap().setMax(conf._summary_service_max_count); + break; + case SummaryEnum.SQL: + if (sqlMaster.size() == 0) + return null; + temp = sqlMaster; + sqlMaster = new IntKeyLinkedMap().setMax(conf._summary_sql_max_count); + break; + case SummaryEnum.APICALL: + if (apiMaster.size() == 0) + return null; + temp = apiMaster; + apiMaster = new IntKeyLinkedMap().setMax(conf._summary_api_max_count); + break; + default: return null; - temp = sqlMaster; - sqlMaster = new SimpleLru(conf._summary_sql_max_count); - break; - case SummaryEnum.APICALL: - if (apiMaster.size() == 0) - return null; - temp = apiMaster; - apiMaster = new SimpleLru(conf._summary_api_max_count); - break; - default: - return null; } SummaryPack p = new SummaryPack(); @@ -192,7 +185,9 @@ public SummaryPack getAndClear(byte type) { cpu = p.table.newList("cpu"); mem = p.table.newList("mem"); } - for (Map.Entry ent : temp.entrySet()) { + Enumeration> en = temp.entries(); + for (int i = 0; i < cnt; i++) { + IntKeyLinkedEntry ent = en.nextElement(); int key = ent.getKey(); SummaryData data = ent.getValue(); id.add(key); @@ -208,22 +203,22 @@ public SummaryPack getAndClear(byte type) { } public SummaryPack getAndClearX(byte type) { - SimpleLru temp; + IntIntLinkedMap temp; switch (type) { - case SummaryEnum.IP: - if (ipMaster.size() == 0) + case SummaryEnum.IP: + if (ipMaster.size() == 0) + return null; + temp = ipMaster; + ipMaster = new IntIntLinkedMap().setMax(conf._summary_ip_max_count); + break; + case SummaryEnum.USER_AGENT: + if (uaMaster.size() == 0) + return null; + temp = uaMaster; + uaMaster = new IntIntLinkedMap().setMax(conf._summary_useragent_max_count); + break; + default: return null; - temp = ipMaster; - ipMaster = new SimpleLru(conf._summary_ip_max_count); - break; - case SummaryEnum.USER_AGENT: - if (uaMaster.size() == 0) - return null; - temp = uaMaster; - uaMaster = new SimpleLru(conf._summary_useragent_max_count); - break; - default: - return null; } SummaryPack p = new SummaryPack(); @@ -233,7 +228,9 @@ public SummaryPack getAndClearX(byte type) { ListValue id = p.table.newList("id"); ListValue count = p.table.newList("count"); - for (Map.Entry ent : temp.entrySet()) { + Enumeration en = temp.entries(); + for (int i = 0; i < cnt; i++) { + IntIntLinkedEntry ent = en.nextElement(); int key = ent.getKey(); int value = ent.getValue(); id.add(key); @@ -246,8 +243,8 @@ public SummaryPack getAndClearError(byte type) { if (errorMaster.size() == 0) return null; - SimpleLru temp = errorMaster; - errorMaster = new SimpleLru(conf._summary_error_max_count); + LongKeyLinkedMap temp = errorMaster; + errorMaster = new LongKeyLinkedMap().setMax(conf._summary_error_max_count); SummaryPack p = new SummaryPack(); p.stype = type; @@ -264,7 +261,9 @@ public SummaryPack getAndClearError(byte type) { ListValue apicall = p.table.newList("apicall"); ListValue fullstack = p.table.newList("fullstack"); - for (Map.Entry ent : temp.entrySet()) { + Enumeration> en = temp.entries(); + for (int i = 0; i < cnt; i++) { + LongKeyLinkedEntry ent = en.nextElement(); long key = ent.getKey(); ErrorData data = ent.getValue(); id.add(key); From 2f97a7d6148a57c1cdf567b2810b8f635bc40fd3 Mon Sep 17 00:00:00 2001 From: Gun Lee Date: Mon, 27 Dec 2021 13:00:39 +0900 Subject: [PATCH 17/20] misc --- .../src/main/java/scouter/agent/Logger.java | 4 +- .../scouter/agent/summary/ServiceSummary.java | 90 ++++++++++--------- 2 files changed, 51 insertions(+), 43 deletions(-) diff --git a/scouter.agent.java/src/main/java/scouter/agent/Logger.java b/scouter.agent.java/src/main/java/scouter/agent/Logger.java index c54e92323..5008900c1 100644 --- a/scouter.agent.java/src/main/java/scouter/agent/Logger.java +++ b/scouter.agent.java/src/main/java/scouter/agent/Logger.java @@ -60,7 +60,7 @@ private static String toString(Object message) { private static String build(String id, String message) { if (message == null) { - return "null-err-message"; + message = "null-err-message"; } return new StringBuffer(20 + id.length() + message.length()) .append(DateUtil.datetime(System.currentTimeMillis())).append(" [").append(id).append("] ") @@ -254,4 +254,4 @@ public void close() { } } -} \ No newline at end of file +} diff --git a/scouter.agent.java/src/main/java/scouter/agent/summary/ServiceSummary.java b/scouter.agent.java/src/main/java/scouter/agent/summary/ServiceSummary.java index e978956c4..56bc2b10f 100644 --- a/scouter.agent.java/src/main/java/scouter/agent/summary/ServiceSummary.java +++ b/scouter.agent.java/src/main/java/scouter/agent/summary/ServiceSummary.java @@ -18,6 +18,7 @@ import scouter.agent.Configure; import scouter.agent.netio.data.DataProxy; +import scouter.agent.util.SimpleLru; import scouter.io.DataInputX; import scouter.lang.SummaryEnum; import scouter.lang.pack.SummaryPack; @@ -25,17 +26,34 @@ import scouter.lang.step.ApiCallStep; import scouter.lang.step.SqlStep; import scouter.lang.value.ListValue; -import scouter.util.*; -import scouter.util.IntIntLinkedMap.IntIntLinkedEntry; -import scouter.util.IntKeyLinkedMap.IntKeyLinkedEntry; -import scouter.util.LongKeyLinkedMap.LongKeyLinkedEntry; +import scouter.util.BitUtil; +import scouter.util.IPUtil; -import java.util.Enumeration; +import java.util.Map; public class ServiceSummary { private static ServiceSummary instance = null; + private Configure conf = Configure.getInstance(); + // private LongKeyLinkedMap errorMaster = new LongKeyLinkedMap().setMax(conf._summary_error_max_count); + private SimpleLru errorMaster = new SimpleLru(conf._summary_error_max_count); + + // private IntKeyLinkedMap sqlMaster = new SimpleLru().setMax(conf._summary_sql_max_count); + private SimpleLru sqlMaster = new SimpleLru(conf._summary_sql_max_count); + + // private IntKeyLinkedMap apiMaster = new IntKeyLinkedMap().setMax(conf._summary_api_max_count); + private SimpleLru apiMaster = new SimpleLru(conf._summary_api_max_count); + + // private IntKeyLinkedMap serviceMaster = new IntKeyLinkedMap().setMax(conf._summary_service_max_count); + private SimpleLru serviceMaster = new SimpleLru(conf._summary_service_max_count); + + // private IntIntLinkedMap ipMaster = new IntIntLinkedMap().setMax(conf._summary_ip_max_count); + private SimpleLru ipMaster = new SimpleLru(conf._summary_ip_max_count); + + // private IntIntLinkedMap uaMaster = new IntIntLinkedMap().setMax(conf._summary_useragent_max_count); + private SimpleLru uaMaster = new SimpleLru(conf._summary_useragent_max_count); + public final static synchronized ServiceSummary getInstance() { if (instance == null) { instance = new ServiceSummary(); @@ -43,8 +61,6 @@ public final static synchronized ServiceSummary getInstance() { return instance; } - private Configure conf = Configure.getInstance(); - public void process(XLogPack p) { if (conf.summary_enabled == false) return; @@ -61,11 +77,19 @@ public void process(XLogPack p) { // ip summary if (IPUtil.isOK(p.ipaddr) && p.ipaddr[0] != 0 && p.ipaddr[0] != 127) { int ip = DataInputX.toInt(p.ipaddr, 0); - ipMaster.put(ip, ipMaster.get(ip) + 1); + Integer v = ipMaster.get(ip); + if (v == null) { + v = 0; + } + ipMaster.put(ip, v + 1); } // user-agent summary if (p.userAgent != 0) { - uaMaster.put(p.userAgent, uaMaster.get(p.userAgent) + 1); + Integer v = uaMaster.get(p.userAgent); + if (v == null) { + v = 0; + } + uaMaster.put(p.userAgent, v + 1); } } @@ -114,8 +138,8 @@ public void process(ApiCallStep apiStep) { } } - private synchronized SummaryData getSummaryMap(IntKeyLinkedMap table, int hash) { - IntKeyLinkedMap tempTable = table; + private synchronized SummaryData getSummaryMap(SimpleLru table, int hash) { + SimpleLru tempTable = table; SummaryData d = tempTable.get(hash); if (d == null) { d = new SummaryData(); @@ -124,9 +148,9 @@ private synchronized SummaryData getSummaryMap(IntKeyLinkedMap tabl return d; } - private synchronized ErrorData getSummaryError(LongKeyLinkedMap table, long key) { + private synchronized ErrorData getSummaryError(SimpleLru table, long key) { - LongKeyLinkedMap tempTable = table; + SimpleLru tempTable = table; ErrorData d = tempTable.get(key); if (d == null) { d = new ErrorData(); @@ -135,36 +159,26 @@ private synchronized ErrorData getSummaryError(LongKeyLinkedMap table return d; } - private LongKeyLinkedMap errorMaster = new LongKeyLinkedMap() - .setMax(conf._summary_error_max_count); - - private IntKeyLinkedMap sqlMaster = new IntKeyLinkedMap().setMax(conf._summary_sql_max_count); - private IntKeyLinkedMap apiMaster = new IntKeyLinkedMap().setMax(conf._summary_api_max_count); - private IntKeyLinkedMap serviceMaster = new IntKeyLinkedMap() - .setMax(conf._summary_service_max_count); - private IntIntLinkedMap ipMaster = new IntIntLinkedMap().setMax(conf._summary_ip_max_count); - private IntIntLinkedMap uaMaster = new IntIntLinkedMap().setMax(conf._summary_useragent_max_count); - public SummaryPack getAndClear(byte type) { - IntKeyLinkedMap temp; + SimpleLru temp; switch (type) { case SummaryEnum.APP: if (serviceMaster.size() == 0) return null; temp = serviceMaster; - serviceMaster = new IntKeyLinkedMap().setMax(conf._summary_service_max_count); + serviceMaster = new SimpleLru(conf._summary_service_max_count); break; case SummaryEnum.SQL: if (sqlMaster.size() == 0) return null; temp = sqlMaster; - sqlMaster = new IntKeyLinkedMap().setMax(conf._summary_sql_max_count); + sqlMaster = new SimpleLru(conf._summary_sql_max_count); break; case SummaryEnum.APICALL: if (apiMaster.size() == 0) return null; temp = apiMaster; - apiMaster = new IntKeyLinkedMap().setMax(conf._summary_api_max_count); + apiMaster = new SimpleLru(conf._summary_api_max_count); break; default: return null; @@ -185,9 +199,7 @@ public SummaryPack getAndClear(byte type) { cpu = p.table.newList("cpu"); mem = p.table.newList("mem"); } - Enumeration> en = temp.entries(); - for (int i = 0; i < cnt; i++) { - IntKeyLinkedEntry ent = en.nextElement(); + for (Map.Entry ent : temp.entrySet()) { int key = ent.getKey(); SummaryData data = ent.getValue(); id.add(key); @@ -203,19 +215,19 @@ public SummaryPack getAndClear(byte type) { } public SummaryPack getAndClearX(byte type) { - IntIntLinkedMap temp; + SimpleLru temp; switch (type) { case SummaryEnum.IP: if (ipMaster.size() == 0) return null; temp = ipMaster; - ipMaster = new IntIntLinkedMap().setMax(conf._summary_ip_max_count); + ipMaster = new SimpleLru(conf._summary_ip_max_count); break; case SummaryEnum.USER_AGENT: if (uaMaster.size() == 0) return null; temp = uaMaster; - uaMaster = new IntIntLinkedMap().setMax(conf._summary_useragent_max_count); + uaMaster = new SimpleLru(conf._summary_useragent_max_count); break; default: return null; @@ -228,9 +240,7 @@ public SummaryPack getAndClearX(byte type) { ListValue id = p.table.newList("id"); ListValue count = p.table.newList("count"); - Enumeration en = temp.entries(); - for (int i = 0; i < cnt; i++) { - IntIntLinkedEntry ent = en.nextElement(); + for (Map.Entry ent : temp.entrySet()) { int key = ent.getKey(); int value = ent.getValue(); id.add(key); @@ -243,8 +253,8 @@ public SummaryPack getAndClearError(byte type) { if (errorMaster.size() == 0) return null; - LongKeyLinkedMap temp = errorMaster; - errorMaster = new LongKeyLinkedMap().setMax(conf._summary_error_max_count); + SimpleLru temp = errorMaster; + errorMaster = new SimpleLru(conf._summary_error_max_count); SummaryPack p = new SummaryPack(); p.stype = type; @@ -261,9 +271,7 @@ public SummaryPack getAndClearError(byte type) { ListValue apicall = p.table.newList("apicall"); ListValue fullstack = p.table.newList("fullstack"); - Enumeration> en = temp.entries(); - for (int i = 0; i < cnt; i++) { - LongKeyLinkedEntry ent = en.nextElement(); + for (Map.Entry ent : temp.entrySet()) { long key = ent.getKey(); ErrorData data = ent.getValue(); id.add(key); From 49d10fc0edc58209543faca8a56ed0c2373ad011 Mon Sep 17 00:00:00 2001 From: Gun Lee Date: Sat, 26 Mar 2022 16:10:57 +0900 Subject: [PATCH 18/20] [client] rcp build version to 2022-03 --- scouter.client.build/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scouter.client.build/pom.xml b/scouter.client.build/pom.xml index 81c5eb9d3..dba4c0f1d 100644 --- a/scouter.client.build/pom.xml +++ b/scouter.client.build/pom.xml @@ -16,9 +16,9 @@ - eclipse-simultaneous-2021-12 + eclipse-simultaneous-2022-03 p2 - https://download.eclipse.org/releases/2021-12/ + https://download.eclipse.org/releases/2022-03/ From 1eeee67bb59ff324f1572eab527a9ad33dced141 Mon Sep 17 00:00:00 2001 From: Gun Lee Date: Sat, 26 Mar 2022 16:26:11 +0900 Subject: [PATCH 19/20] [agent.java] Only when the trace_propagete_b3_header option is true, the b3 header is used to determine gxid and txid. --- .../src/main/java/scouter/xtra/http/HttpTrace.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scouter.agent.java/src/main/java/scouter/xtra/http/HttpTrace.java b/scouter.agent.java/src/main/java/scouter/xtra/http/HttpTrace.java index 7950bfef8..4e544e1b4 100644 --- a/scouter.agent.java/src/main/java/scouter/xtra/http/HttpTrace.java +++ b/scouter.agent.java/src/main/java/scouter/xtra/http/HttpTrace.java @@ -304,7 +304,7 @@ public void start(TraceContext ctx, Object req, Object res) { } } - if (b3ModeValid) { + if (b3ModeValid && conf.trace_propagete_b3_header) { ctx.gxid = HexCodec.lowerHexToUnsignedLong(b3TraceId); ctx.txid = HexCodec.lowerHexToUnsignedLong(request.getHeader(B3Constant.B3_HEADER_SPANID)); String caller = request.getHeader(B3Constant.B3_HEADER_PARENTSPANID); From 6ccb929f5f67b0180e4e4d027b29579c3338e37c Mon Sep 17 00:00:00 2001 From: Gun Lee Date: Sat, 26 Mar 2022 16:55:12 +0900 Subject: [PATCH 20/20] scouter version v2.17.1 --- pom.xml | 2 +- scouter.agent.batch/pom.xml | 2 +- scouter.agent.host/pom.xml | 2 +- scouter.agent.java/pom.xml | 2 +- .../src/main/java/scouter/xtra/http/WebfluxHttpTrace.java | 2 +- scouter.common/pom.xml | 2 +- scouter.deploy/pom.xml | 2 +- scouter.server.boot/pom.xml | 2 +- scouter.server/pom.xml | 2 +- scouter.weaver/pom.xml | 2 +- scouter.webapp/pom.xml | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 40a1fe0b6..f8b7823e1 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.scouter-project scouter-parent - 2.17.1-SNAPSHOT + 2.17.1 pom SCOUTER APM diff --git a/scouter.agent.batch/pom.xml b/scouter.agent.batch/pom.xml index a1227b25e..2b71a8c15 100644 --- a/scouter.agent.batch/pom.xml +++ b/scouter.agent.batch/pom.xml @@ -5,7 +5,7 @@ io.github.scouter-project scouter-parent - 2.17.1-SNAPSHOT + 2.17.1 scouter-agent-batch diff --git a/scouter.agent.host/pom.xml b/scouter.agent.host/pom.xml index f53389505..659b3eeec 100644 --- a/scouter.agent.host/pom.xml +++ b/scouter.agent.host/pom.xml @@ -4,7 +4,7 @@ io.github.scouter-project scouter-parent - 2.17.1-SNAPSHOT + 2.17.1 scouter-agent-host diff --git a/scouter.agent.java/pom.xml b/scouter.agent.java/pom.xml index 0afcfc054..4f375c569 100644 --- a/scouter.agent.java/pom.xml +++ b/scouter.agent.java/pom.xml @@ -4,7 +4,7 @@ io.github.scouter-project scouter-parent - 2.17.1-SNAPSHOT + 2.17.1 scouter-agent-java diff --git a/scouter.agent.java/src/main/java/scouter/xtra/http/WebfluxHttpTrace.java b/scouter.agent.java/src/main/java/scouter/xtra/http/WebfluxHttpTrace.java index 5ed3e982f..cc949900d 100644 --- a/scouter.agent.java/src/main/java/scouter/xtra/http/WebfluxHttpTrace.java +++ b/scouter.agent.java/src/main/java/scouter/xtra/http/WebfluxHttpTrace.java @@ -275,7 +275,7 @@ public void start(TraceContext ctx, Object req, Object res) { } } - if (b3ModeValid) { + if (b3ModeValid && conf.trace_propagete_b3_header) { ctx.gxid = HexCodec.lowerHexToUnsignedLong(b3TraceId); ctx.txid = HexCodec.lowerHexToUnsignedLong(getHeader(request, B3Constant.B3_HEADER_SPANID)); String caller = getHeader(request, B3Constant.B3_HEADER_PARENTSPANID); diff --git a/scouter.common/pom.xml b/scouter.common/pom.xml index 26e1413ed..79d935da4 100644 --- a/scouter.common/pom.xml +++ b/scouter.common/pom.xml @@ -4,7 +4,7 @@ io.github.scouter-project scouter-parent - 2.17.1-SNAPSHOT + 2.17.1 scouter-common diff --git a/scouter.deploy/pom.xml b/scouter.deploy/pom.xml index 49ecca122..04620f901 100644 --- a/scouter.deploy/pom.xml +++ b/scouter.deploy/pom.xml @@ -4,7 +4,7 @@ io.github.scouter-project scouter-parent - 2.17.1-SNAPSHOT + 2.17.1 scouter-deploy diff --git a/scouter.server.boot/pom.xml b/scouter.server.boot/pom.xml index 7a2e7bcc8..138ba46fa 100644 --- a/scouter.server.boot/pom.xml +++ b/scouter.server.boot/pom.xml @@ -4,7 +4,7 @@ io.github.scouter-project scouter-parent - 2.17.1-SNAPSHOT + 2.17.1 scouter-server-boot diff --git a/scouter.server/pom.xml b/scouter.server/pom.xml index f04b593b7..4ef32d637 100644 --- a/scouter.server/pom.xml +++ b/scouter.server/pom.xml @@ -4,7 +4,7 @@ io.github.scouter-project scouter-parent - 2.17.1-SNAPSHOT + 2.17.1 scouter-server diff --git a/scouter.weaver/pom.xml b/scouter.weaver/pom.xml index 02d91eba4..23321b3f1 100644 --- a/scouter.weaver/pom.xml +++ b/scouter.weaver/pom.xml @@ -5,7 +5,7 @@ io.github.scouter-project scouter-parent - 2.17.1-SNAPSHOT + 2.17.1 4.0.0 diff --git a/scouter.webapp/pom.xml b/scouter.webapp/pom.xml index 6a077385b..9b3c79e1f 100644 --- a/scouter.webapp/pom.xml +++ b/scouter.webapp/pom.xml @@ -5,7 +5,7 @@ io.github.scouter-project scouter-parent - 2.17.1-SNAPSHOT + 2.17.1 4.0.0