diff --git a/.gitignore b/.gitignore index d2df204c7..4a20fb08c 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ scouter.agent.host/bin/* scouter.agent.host.boot/bin/* scouter.server.boot/bin/* *.log +scouter.enduser.script/.project diff --git a/scouter.agent.java/src/scouter/agent/AgentTransformer.java b/scouter.agent.java/src/scouter/agent/AgentTransformer.java index 1da34b3ca..ae2e9d377 100644 --- a/scouter.agent.java/src/scouter/agent/AgentTransformer.java +++ b/scouter.agent.java/src/scouter/agent/AgentTransformer.java @@ -59,13 +59,13 @@ public class AgentTransformer implements ClassFileTransformer { static { final Configure conf = Configure.getInstance(); reload(); - hook_signature=conf.hook_signature; + hook_signature=conf.getHookSignature(); ConfObserver.add("AgentTransformer", new Runnable(){ public void run() { - if(conf.hook_signature !=hook_signature){ + if(conf.getHookSignature() !=hook_signature){ reload(); } - hook_signature=conf.hook_signature; + hook_signature=conf.getHookSignature(); } }); diff --git a/scouter.agent.java/src/scouter/agent/Configure.java b/scouter.agent.java/src/scouter/agent/Configure.java index f2e89d2c7..4acd35a6c 100644 --- a/scouter.agent.java/src/scouter/agent/Configure.java +++ b/scouter.agent.java/src/scouter/agent/Configure.java @@ -87,7 +87,6 @@ public final static synchronized Configure getInstance() { public boolean enable_plus_objtype = false; public boolean enable_asm_jdbc = true; - public boolean enable_asm_httpsession = true; public boolean enable_asm_socket = true; public boolean http_debug_querystring; @@ -145,7 +144,8 @@ public final static synchronized Configure getInstance() { public String plugin_classpath = ""; - public StringSet log_ignore = new StringSet(); + public String log_ignore = ""; + public StringSet log_ignore_set = new StringSet(); public String hook_args = ""; public String hook_return = ""; @@ -174,6 +174,10 @@ public final static synchronized Configure getInstance() { public String hook_apicall_info = ""; public String hook_jsp = ""; + public String hook_jdbc_pstmt = ""; + public String hook_jdbc_stmt = ""; + public String hook_jdbc_rs = ""; + // /LOAD CONTROL///// public boolean enable_reject_service = false; public int max_active_service = 10000; @@ -187,7 +191,6 @@ public final static synchronized Configure getInstance() { public String plugin_http_trace = ""; public String plugin_apicall_name = ""; - public String plugin_http_trace_param = ""; public boolean profile_fullstack_service_error = false; public boolean profile_fullstack_apicall_error = false; public int profile_fullstack_lines = 0; @@ -201,16 +204,13 @@ public final static synchronized Configure getInstance() { public String this_txid = "scouter_this_txid"; public String caller_txid = "scouter_caller_txid"; - public int hook_signature; + private int hook_signature; - public int max_concurrent_server_request = 10; public String userid_jsessionid = "JSESSIONID"; public boolean enable_auto_service_trace = false; public boolean enable_auto_service_backstack = true; - public boolean debug_apicall = false; - public String hook_future_task = ""; public String hook_future_task_prefix = ""; @@ -224,11 +224,6 @@ public final static synchronized Configure getInstance() { public boolean enable_hook_step7 = true; public boolean enable_hook_step8 = true; - public int stat_sql_max = 10000; - public int stat_api_max = 5000; - public int stat_app_sql_max = 10000; - public int stat_app_api_max = 5000; - public String direct_patch_class = ""; public long max_think_time = DateUtil.MILLIS_PER_FIVE_MINUTE; @@ -368,7 +363,6 @@ private void apply() { this.profile_sql_escape = getBoolean("profile_sql_escape", true); this.enable_asm_jdbc = getBoolean("enable_asm_jdbc", getBoolean("enable.asm.jdbc", true)); - this.enable_asm_httpsession = getBoolean("enable_asm_httpsession", getBoolean("enable.asm.httpsession", true)); this.enable_asm_socket = getBoolean("enable_asm_socket", getBoolean("enable.asm.socket", true)); this.udp_packet_max = getInt("udp_packet_max", getInt("udp.packet.max", 60000)); @@ -376,7 +370,8 @@ private void apply() { this.yellow_line_time = getLong("yellow_line_time", getLong("yellow.line.time", 3000)); this.red_line_time = getLong("red_line_time", getLong("red.line.time", 8000)); - this.log_ignore = getStringSet("log_ignore", ","); + this.log_ignore = getValue("log_ignore", ""); + this.log_ignore_set = getStringSet("log_ignore", ","); this.debug_udp_xlog = getBoolean("debug_udp_xlog", getBoolean("debug.udp.xlog", false)); this.debug_udp_object = getBoolean("debug_udp_object", getBoolean("debug.udp.object", false)); @@ -414,10 +409,14 @@ private void apply() { this._hook_method_ignore_classes = new StringSet(StringUtil.tokenizer( this.hook_method_ignore_classes.replace('.', '/'), ",")); - this.hook_service = getValue("hook_service", getValue("hook.service", "")); - this.hook_apicall = getValue("hook_apicall", getValue("hook.subcall", "")); + this.hook_service = getValue("hook_service", ""); + this.hook_apicall = getValue("hook_apicall", ""); this.hook_apicall_info = getValue("hook_apicall_info", ""); - this.hook_jsp = getValue("hook_jsp", getValue("hook.jsp", "")); + this.hook_jsp = getValue("hook_jsp", ""); + + this.hook_jdbc_pstmt = getValue("hook_jdbc_pstmt", ""); + this.hook_jdbc_stmt = getValue("hook_jdbc_stmt", ""); + this.hook_jdbc_rs = getValue("hook_jdbc_rs", ""); this.hook_signature ^= this.hook_args.hashCode(); this.hook_signature ^= this.hook_return.hashCode(); @@ -461,7 +460,6 @@ private void apply() { this.this_txid = getValue("this_txid", "scouter_this_txid"); this.caller_txid = getValue("caller_txid", "scouter_caller_txid"); - this.max_concurrent_server_request = getInt("max_concurrent_server_request", 10); this.debug_dbopen_fullstack = getBoolean("debug_dbopen_fullstack", false); this.debug_dbopen_autocommit = getBoolean("debug_dbopen_autocommit", false); @@ -473,8 +471,6 @@ private void apply() { this.enable_auto_service_trace = getBoolean("enable_auto_service_trace", false); this.enable_auto_service_backstack = getBoolean("enable_auto_service_backstack", true); - this.debug_apicall = getBoolean("debug_apicall", false); - this.hook_future_task = getValue("hook_future_task", ""); this.hook_future_task_prefix = getValue("hook_future_task_prefix", ""); @@ -488,13 +484,6 @@ private void apply() { this.enable_hook_step7 = getBoolean("enable_hook_step7", true); this.enable_hook_step8 = getBoolean("enable_hook_step8", true); - this.stat_sql_max = getInt("stat_sql_max", 10000); - this.stat_api_max = getInt("stat_api_max", 5000); - this.stat_app_sql_max = getInt("stat_app_sql_max", 10000); - this.stat_app_api_max = getInt("stat_app_api_max", 5000); - - this.plugin_http_trace_param = getValue("plugin_http_trace_param", ""); - this.direct_patch_class = getValue("direct_patch_class", ""); this.max_think_time = getLong("max_think_time", DateUtil.MILLIS_PER_FIVE_MINUTE); @@ -728,6 +717,10 @@ public MapValue getKeyValueInfo() { return m; } + + public int getHookSignature() { + return this.hook_signature; + } public static void main(String[] args) { System.out.println(Configure.getInstance().getKeyValueInfo().toString().replace(',', '\n')); diff --git a/scouter.agent.java/src/scouter/agent/Logger.java b/scouter.agent.java/src/scouter/agent/Logger.java index 5da031326..de6756681 100644 --- a/scouter.agent.java/src/scouter/agent/Logger.java +++ b/scouter.agent.java/src/scouter/agent/Logger.java @@ -35,7 +35,7 @@ public static void println(String id, String message) { } private static boolean checkOk(String id) { - if (Configure.getInstance().log_ignore.hasKey(id)) + if (Configure.getInstance().log_ignore_set.hasKey(id)) return false; long last = lastLog.get(id); long now = System.currentTimeMillis(); diff --git a/scouter.agent.java/src/scouter/agent/asm/JDBCPreparedStatementASM.java b/scouter.agent.java/src/scouter/agent/asm/JDBCPreparedStatementASM.java index 50bd1e77f..8f2d3da08 100644 --- a/scouter.agent.java/src/scouter/agent/asm/JDBCPreparedStatementASM.java +++ b/scouter.agent.java/src/scouter/agent/asm/JDBCPreparedStatementASM.java @@ -14,78 +14,90 @@ * limitations under the License. */ package scouter.agent.asm; + import java.util.HashSet; + import scouter.agent.ClassDesc; import scouter.agent.Configure; import scouter.agent.Logger; -import scouter.agent.asm.jdbc.P0ClearParametersMV; -import scouter.agent.asm.jdbc.P0ExecuteMV; -import scouter.agent.asm.jdbc.P0InitMV; -import scouter.agent.asm.jdbc.P0SetMV; import scouter.agent.asm.jdbc.PsClearParametersMV; import scouter.agent.asm.jdbc.PsExecuteMV; import scouter.agent.asm.jdbc.PsInitMV; import scouter.agent.asm.jdbc.PsSetMV; import scouter.agent.asm.jdbc.StExecuteMV; +import scouter.agent.asm.util.MethodSet; import scouter.agent.trace.SqlParameter; import scouter.agent.trace.TraceSQL; import scouter.org.objectweb.asm.ClassVisitor; import scouter.org.objectweb.asm.MethodVisitor; import scouter.org.objectweb.asm.Opcodes; import scouter.org.objectweb.asm.Type; + public class JDBCPreparedStatementASM implements IASM, Opcodes { - public final HashSet target = new HashSet(); + public final HashSet target = MethodSet.getHookingClassSet(Configure.getInstance().hook_jdbc_pstmt); + public final HashSet noField = new HashSet(); + public JDBCPreparedStatementASM() { target.add("org/mariadb/jdbc/MySQLPreparedStatement"); target.add("oracle/jdbc/driver/OraclePreparedStatement"); - target.add("com/mysql/jdbc/PreparedStatement"); + target.add("org/postgresql/jdbc2/AbstractJdbc2Statement"); target.add("org/apache/derby/client/am/PreparedStatement"); - target.add("jdbc/FakePreparedStatement"); target.add("net/sourceforge/jtds/jdbc/JtdsPreparedStatement"); - + + target.add("jdbc/FakePreparedStatement"); + target.add("jdbc/FakePreparedStatement2"); target.add("com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement"); target.add("com/tmax/tibero/jdbc/TbPreparedStatement"); target.add("org/hsqldb/jdbc/JDBCPreparedStatement"); + + target.add("com/mysql/jdbc/ServerPreparedStatement"); + target.add("com/mysql/jdbc/PreparedStatement"); + + // @skyworker - MySQL ServerPreparedStatement는 특별히 필드를 추가하지 않음 + noField.add("com/mysql/jdbc/ServerPreparedStatement"); + noField.add("jdbc/FakePreparedStatement2"); } + public boolean isTarget(String className) { - return target.contains(className) ; + return target.contains(className); } + public ClassVisitor transform(ClassVisitor cv, String className, ClassDesc classDesc) { if (target.contains(className) == false) { return cv; } - if(Configure.getInstance().enable_asm_jdbc==false) + if (Configure.getInstance().enable_asm_jdbc == false) return cv; - Logger.println("A106", "jdbc pstmt found: " + className + " redefinable="+Configure.JDBC_REDEFINED); - return new PreparedStatementCV(cv); + Logger.println("A106", "jdbc pstmt found: " + className); + return new PreparedStatementCV(cv, noField); } } + class PreparedStatementCV extends ClassVisitor implements Opcodes { - public PreparedStatementCV(ClassVisitor cv) { + HashSet noField; + + public PreparedStatementCV(ClassVisitor cv, HashSet noField) { super(ASM4, cv); + this.noField = noField; } + private String owner; + @Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { super.visit(version, access, name, signature, superName, interfaces); - //add dummy field - - if(Configure.JDBC_REDEFINED==false){ - super.visitField(ACC_PUBLIC, TraceSQL.PSTMT_PARAM_FIELD, Type.getDescriptor(SqlParameter.class), null, null).visitEnd(); - } this.owner = name; + if (noField.contains(name) == false) { + // add trace field + super.visitField(ACC_PUBLIC, TraceSQL.PSTMT_PARAM_FIELD, Type.getDescriptor(SqlParameter.class), null, null) + .visitEnd(); + } } + @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); - if(Configure.JDBC_REDEFINED){ - return ifRedefined(access, name, desc, mv); - }else{ - return ifNotRedefined(access, name, desc, mv); - } - } - private MethodVisitor ifRedefined(int access, String name, String desc, MethodVisitor mv) { if ("".equals(name)) { return new PsInitMV(access, desc, mv, owner); } else { @@ -106,25 +118,5 @@ private MethodVisitor ifRedefined(int access, String name, String desc, MethodVi } return mv; } - private MethodVisitor ifNotRedefined(int access, String name, String desc, MethodVisitor mv) { - if ("".equals(name)) { - return new P0InitMV(access, desc, mv, owner); - } else { - String targetDesc = P0SetMV.getSetSignature(name); - if (targetDesc != null) { - if (targetDesc.equals(desc)) { - return new P0SetMV(access, name, desc, mv, owner); - } - } else if (P0ExecuteMV.isTarget(name)) { - if (desc.startsWith("()")) { - return new P0ExecuteMV(access, desc, mv, owner); - } else if (desc.startsWith("(Ljava/lang/String;)")) { - return new StExecuteMV(access, desc, mv, owner); - } - } else if ("clearParameters".equals(name) && "()V".equals(desc)) { - return new P0ClearParametersMV(access, desc, mv, owner); - } - } - return mv; - } + } diff --git a/scouter.agent.java/src/scouter/agent/asm/JDBCResultSetASM.java b/scouter.agent.java/src/scouter/agent/asm/JDBCResultSetASM.java index 0866bf1a6..7b6a4519f 100644 --- a/scouter.agent.java/src/scouter/agent/asm/JDBCResultSetASM.java +++ b/scouter.agent.java/src/scouter/agent/asm/JDBCResultSetASM.java @@ -14,52 +14,60 @@ * limitations under the License. */ package scouter.agent.asm; + import java.util.HashSet; import scouter.agent.ClassDesc; import scouter.agent.Configure; import scouter.agent.Logger; import scouter.agent.asm.jdbc.RsCloseMV; import scouter.agent.asm.jdbc.RsNextMV; +import scouter.agent.asm.util.MethodSet; import scouter.org.objectweb.asm.ClassVisitor; import scouter.org.objectweb.asm.MethodVisitor; import scouter.org.objectweb.asm.Opcodes; + public class JDBCResultSetASM implements IASM, Opcodes { - public final HashSet target = new HashSet(); + public final HashSet target = MethodSet.getHookingClassSet(Configure.getInstance().hook_jdbc_rs); + public JDBCResultSetASM() { target.add("org/mariadb/jdbc/MySQLResultSet"); - + target.add("oracle/jdbc/driver/OracleResultSetImpl"); target.add("com/mysql/jdbc/ResultSetImpl"); target.add("org/postgresql/jdbc2/AbstractJdbc2ResultSet"); target.add("org/apache/derby/client/am/ResultSet"); target.add("jdbc/FakeResultSet"); target.add("net/sourceforge/jtds/jdbc/JtdsResultSet"); - + target.add("com/microsoft/sqlserver/jdbc/SQLServerResultSet"); target.add("com/tmax/tibero/jdbc/TbResultSet"); - + target.add("oracle/jdbc/driver/InsensitiveScrollableResultSet"); target.add("oracle/jdbc/driver/SensitiveScrollableResultSet"); - + target.add("org/hsqldb/jdbc/JDBCResultSet"); } + public boolean isTarget(String className) { - return target.contains(className) ; + return target.contains(className); } + public ClassVisitor transform(ClassVisitor cv, String className, ClassDesc classDesc) { if (target.contains(className) == false) { return cv; } - if(Configure.getInstance().enable_asm_jdbc==false) + if (Configure.getInstance().enable_asm_jdbc == false) return cv; Logger.println("A107", "jdbc rs found: " + className); return new ResultSetCV(cv); } } + class ResultSetCV extends ClassVisitor implements Opcodes { public ResultSetCV(ClassVisitor cv) { super(ASM4, cv); } + @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); diff --git a/scouter.agent.java/src/scouter/agent/asm/JDBCStatementASM.java b/scouter.agent.java/src/scouter/agent/asm/JDBCStatementASM.java index 709de2f11..119a26a36 100644 --- a/scouter.agent.java/src/scouter/agent/asm/JDBCStatementASM.java +++ b/scouter.agent.java/src/scouter/agent/asm/JDBCStatementASM.java @@ -19,11 +19,12 @@ import scouter.agent.Configure; import scouter.agent.Logger; import scouter.agent.asm.jdbc.StExecuteMV; +import scouter.agent.asm.util.MethodSet; import scouter.org.objectweb.asm.ClassVisitor; import scouter.org.objectweb.asm.MethodVisitor; import scouter.org.objectweb.asm.Opcodes; public class JDBCStatementASM implements IASM, Opcodes { - public final HashSet target = new HashSet(); + public final HashSet target = MethodSet.getHookingClassSet(Configure.getInstance().hook_jdbc_stmt); public JDBCStatementASM() { target.add("org/mariadb/jdbc/MySQLStatement"); diff --git a/scouter.agent.java/src/scouter/agent/asm/jdbc/P0ClearParametersMV.java b/scouter.agent.java/src/scouter/agent/asm/jdbc/P0ClearParametersMV.java deleted file mode 100644 index ef5960df8..000000000 --- a/scouter.agent.java/src/scouter/agent/asm/jdbc/P0ClearParametersMV.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2015 LG CNS. - * - * 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.agent.asm.jdbc; - -import scouter.agent.trace.TraceSQL; -import scouter.org.objectweb.asm.MethodVisitor; -import scouter.org.objectweb.asm.Opcodes; -import scouter.org.objectweb.asm.commons.LocalVariablesSorter; - -public class P0ClearParametersMV extends LocalVariablesSorter implements Opcodes { - private final static String TRACESQL = TraceSQL.class.getName().replace('.', '/'); - private final static String METHOD = "clear"; - private static final String SIGNATURE = "(Ljava/lang/Object;Lscouter/agent/trace/SqlParameter;)V"; - - // ///////////////////////////////////////////////////////////////// - public P0ClearParametersMV(int access, String desc, MethodVisitor mv, String owner) { - super(ASM4,access, desc, mv); - this.owner = owner; - } - - private String owner; - - @Override - public void visitCode() { - mv.visitVarInsn(ALOAD, 0); - mv.visitVarInsn(ALOAD, 0); - mv.visitFieldInsn(GETFIELD, owner, TraceSQL.PSTMT_PARAM_FIELD, "Lscouter/agent/trace/SqlParameter;"); - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, METHOD, SIGNATURE); - super.visitCode(); - - } - -} \ No newline at end of file diff --git a/scouter.agent.java/src/scouter/agent/asm/jdbc/P0ExecuteMV.java b/scouter.agent.java/src/scouter/agent/asm/jdbc/P0ExecuteMV.java deleted file mode 100644 index 33f71b097..000000000 --- a/scouter.agent.java/src/scouter/agent/asm/jdbc/P0ExecuteMV.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2015 LG CNS. - * - * 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.agent.asm.jdbc; - -import java.util.HashSet; -import java.util.Set; - -import scouter.agent.trace.TraceSQL; -import scouter.org.objectweb.asm.Label; -import scouter.org.objectweb.asm.MethodVisitor; -import scouter.org.objectweb.asm.Opcodes; -import scouter.org.objectweb.asm.Type; -import scouter.org.objectweb.asm.commons.LocalVariablesSorter; - - -public class P0ExecuteMV extends LocalVariablesSorter implements Opcodes { - private static Set target = new HashSet(); - static { - target.add("execute"); - target.add("executeQuery"); - target.add("executeUpdate"); - target.add("executeBatch"); - } - - public static boolean isTarget(String name) { - return target.contains(name); - } - - private final static String TRACESQL = TraceSQL.class.getName().replace('.', '/'); - private final static String START_METHOD = "start"; - private final static String END_METHOD = "end"; - private static final String END_SIGNATURE = "(Ljava/lang/Object;Ljava/lang/Throwable;)V"; - private static final String START_SIGNATURE = "(Ljava/lang/Object;Lscouter/agent/trace/SqlParameter;)Ljava/lang/Object;"; - - public P0ExecuteMV(int access, String desc, MethodVisitor mv, String owner) { - super(ASM4,access, desc, mv); - this.owner = owner; - } - private Label startFinally = new Label(); - - private String owner; - private int statIdx; - - @Override - public void visitCode() { - mv.visitVarInsn(ALOAD, 0); - mv.visitVarInsn(ALOAD, 0); - mv.visitFieldInsn(GETFIELD, owner, TraceSQL.PSTMT_PARAM_FIELD, "Lscouter/agent/trace/SqlParameter;"); - - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, START_METHOD, START_SIGNATURE); - - statIdx = newLocal(scouter.org.objectweb.asm.Type.getType(Object.class)); - mv.visitVarInsn(Opcodes.ASTORE, statIdx); - mv.visitLabel(startFinally); - mv.visitCode(); - } - - @Override - public void visitInsn(int opcode) { - if ((opcode >= IRETURN && opcode <= RETURN)) { - mv.visitVarInsn(Opcodes.ALOAD, statIdx); - mv.visitInsn(Opcodes.ACONST_NULL); - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, END_METHOD, END_SIGNATURE); - } - mv.visitInsn(opcode); - } - - @Override - public void visitMaxs(int maxStack, int maxLocals) { - Label endFinally = new Label(); - mv.visitTryCatchBlock(startFinally, endFinally, endFinally, null); - mv.visitLabel(endFinally); - mv.visitInsn(DUP); - int errIdx = newLocal(Type.getType(Throwable.class)); - mv.visitVarInsn(Opcodes.ASTORE, errIdx); - - mv.visitVarInsn(Opcodes.ALOAD, statIdx); - mv.visitVarInsn(Opcodes.ALOAD, errIdx); - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, END_METHOD, END_SIGNATURE); - mv.visitInsn(ATHROW); - mv.visitMaxs(maxStack + 8, maxLocals + 2); - } -} \ No newline at end of file diff --git a/scouter.agent.java/src/scouter/agent/asm/jdbc/P0InitMV.java b/scouter.agent.java/src/scouter/agent/asm/jdbc/P0InitMV.java deleted file mode 100644 index dd0d24c91..000000000 --- a/scouter.agent.java/src/scouter/agent/asm/jdbc/P0InitMV.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2015 LG CNS. - * - * 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.agent.asm.jdbc; - -import scouter.agent.asm.util.AsmUtil; -import scouter.agent.trace.SqlParameter; -import scouter.agent.trace.TraceSQL; -import scouter.org.objectweb.asm.Label; -import scouter.org.objectweb.asm.MethodVisitor; -import scouter.org.objectweb.asm.Opcodes; -import scouter.org.objectweb.asm.Type; -import scouter.org.objectweb.asm.commons.LocalVariablesSorter; - -public class P0InitMV extends LocalVariablesSorter implements Opcodes { - - private final static String TRACESQL = TraceSQL.class.getName().replace('.', '/'); - private final static String METHOD = "prepare"; - private final static String SIGNATURE = "(Ljava/lang/Object;Lscouter/agent/trace/SqlParameter;Ljava/lang/String;)V"; - - public P0InitMV(int access, String desc, MethodVisitor mv, String owner) { - super(ASM4,access, desc, mv); - this.owner = owner; - this.strArgIdx = AsmUtil.getStringIdx(access, desc); - - } - - private String owner; - private int strArgIdx = -1; - - @Override - public void visitInsn(int opcode) { - if (strArgIdx >= 0 && (opcode >= IRETURN && opcode <= RETURN)) { - - mv.visitVarInsn(ALOAD, 0); - mv.visitFieldInsn(GETFIELD, owner, TraceSQL.PSTMT_PARAM_FIELD, "Lscouter/agent/trace/SqlParameter;"); - - Label end = new Label(); - mv.visitJumpInsn(IFNONNULL, end); - mv.visitVarInsn(ALOAD, 0); - mv.visitTypeInsn(NEW, Type.getInternalName(SqlParameter.class)); - mv.visitInsn(DUP); - mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(SqlParameter.class), "", "()V",false); - mv.visitFieldInsn(PUTFIELD, owner, TraceSQL.PSTMT_PARAM_FIELD, "Lscouter/agent/trace/SqlParameter;"); - - mv.visitLabel(end); - mv.visitVarInsn(ALOAD, 0); - mv.visitVarInsn(ALOAD, 0); - mv.visitFieldInsn(GETFIELD, owner, TraceSQL.PSTMT_PARAM_FIELD, "Lscouter/agent/trace/SqlParameter;"); - mv.visitVarInsn(ALOAD, strArgIdx); - - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, METHOD, SIGNATURE,false); - } - mv.visitInsn(opcode); - } - -} \ No newline at end of file diff --git a/scouter.agent.java/src/scouter/agent/asm/jdbc/P0SetMV.java b/scouter.agent.java/src/scouter/agent/asm/jdbc/P0SetMV.java deleted file mode 100644 index e06151a04..000000000 --- a/scouter.agent.java/src/scouter/agent/asm/jdbc/P0SetMV.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright 2015 LG CNS. - * - * 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.agent.asm.jdbc; - -import java.util.HashMap; -import java.util.Map; - -import scouter.agent.asm.util.AsmUtil; -import scouter.agent.trace.SqlParameter; -import scouter.agent.trace.TraceSQL; -import scouter.org.objectweb.asm.MethodVisitor; -import scouter.org.objectweb.asm.Opcodes; -import scouter.org.objectweb.asm.Type; -import scouter.org.objectweb.asm.commons.LocalVariablesSorter; - -public class P0SetMV extends LocalVariablesSorter implements Opcodes { - - private static Map target = new HashMap(); - static { - target.put("setNull", "(II)V"); - - target.put("setByte", "(IB)V"); - target.put("setBoolean", "(IZ)V"); - target.put("setShort", "(IS)V"); - target.put("setInt", "(II)V"); - target.put("setFloat", "(IF)V"); - target.put("setLong", "(IJ)V"); - target.put("setDouble", "(ID)V"); - - target.put("setBigDecimal", "(ILjava/math/BigDecimal;)V"); - target.put("setBlob", "(ILjava/sql/Blob;)V"); - target.put("setClob", "(ILjava/sql/Clob;)V"); - target.put("setObject", "(ILjava/lang/Object;)V"); - target.put("setString", "(ILjava/lang/String;)V"); - target.put("setDate", "(IBLjava/sql/Date;)V"); - target.put("setTime", "(ILjava/sql/Time;)V"); - target.put("setTimestamp", "(ILjava/sql/Timestamp;)V"); - target.put("setURL", "(ILjava/net/URL;)V"); // - } - - public static String getSetSignature(String name) { - return target.get(name); - } - - private final static String TRACESQL = TraceSQL.class.getName().replace('.', '/'); - - public P0SetMV(int access, String name, String desc, MethodVisitor mv, String owner) { - super(ASM4,access, desc, mv); - - this.owner = owner; - this.args = Type.getArgumentTypes(desc); - this.name = name; - } - - private String owner; - private String name; - private Type[] args; - - public void visitCode() { - - mv.visitVarInsn(Opcodes.ALOAD, 0); - mv.visitFieldInsn(GETFIELD, owner, TraceSQL.PSTMT_PARAM_FIELD, "Lscouter/agent/trace/SqlParameter;"); - mv.visitVarInsn(Opcodes.ILOAD, 1); - - if (name.equals("setNull")) { - AsmUtil.PUSH(mv, (String) null); - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "set", - "(Lscouter/agent/trace/SqlParameter;ILjava/lang/String;)V"); - } else { - Type tp = args[1]; - switch (tp.getSort()) { - case Type.BOOLEAN: - mv.visitVarInsn(Opcodes.ILOAD, 2); - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "set", "(Lscouter/agent/trace/SqlParameter;IZ)V"); - break; - case Type.CHAR: - case Type.BYTE: - case Type.SHORT: - case Type.INT: - mv.visitVarInsn(Opcodes.ILOAD, 2); - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "set", "(Lscouter/agent/trace/SqlParameter;II)V"); - break; - case Type.LONG: - mv.visitVarInsn(Opcodes.LLOAD, 2); - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "set", "(Lscouter/agent/trace/SqlParameter;IJ)V"); - break; - case Type.FLOAT: - mv.visitVarInsn(Opcodes.FLOAD, 2); - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "set", "(Lscouter/agent/trace/SqlParameter;IF)V"); - break; - case Type.DOUBLE: - mv.visitVarInsn(Opcodes.DLOAD, 2); - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "set", "(Lscouter/agent/trace/SqlParameter;ID)V"); - break; - case Type.ARRAY: - case Type.OBJECT: - mv.visitVarInsn(Opcodes.ALOAD, 2); - if (tp.equals(AsmUtil.stringType)) { - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "set", - "(Lscouter/agent/trace/SqlParameter;ILjava/lang/String;)V"); - } else { - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "set", - "(Lscouter/agent/trace/SqlParameter;ILjava/lang/Object;)V"); - } - break; - default: - mv.visitVarInsn(Opcodes.ALOAD, 2); - AsmUtil.PUSH(mv, "unknown " + tp); - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "set", - "(Lscouter/agent/trace/SqlParameter;ILjava/lang/String;)V"); - break; - } - } - - super.visitCode(); - } - - public static void main(String[] args) { - System.out.println(Type.getDescriptor(SqlParameter.class)); - } -} \ No newline at end of file diff --git a/scouter.agent.java/src/scouter/agent/asm/jdbc/PsClearParametersMV.java b/scouter.agent.java/src/scouter/agent/asm/jdbc/PsClearParametersMV.java index 45d2ab168..070205527 100644 --- a/scouter.agent.java/src/scouter/agent/asm/jdbc/PsClearParametersMV.java +++ b/scouter.agent.java/src/scouter/agent/asm/jdbc/PsClearParametersMV.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 LG CNS. + * Copyright 2015 Scouter Project. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package scouter.agent.asm.jdbc; - import scouter.agent.trace.TraceSQL; import scouter.org.objectweb.asm.MethodVisitor; import scouter.org.objectweb.asm.Opcodes; @@ -25,7 +24,7 @@ public class PsClearParametersMV extends LocalVariablesSorter implements Opcodes { private final static String TRACESQL = TraceSQL.class.getName().replace('.', '/'); private final static String METHOD = "clear"; - private static final String SIGNATURE = "(Ljava/lang/Object;)V"; + private static final String SIGNATURE = "(Ljava/lang/Object;Lscouter/agent/trace/SqlParameter;)V"; // ///////////////////////////////////////////////////////////////// public PsClearParametersMV(int access, String desc, MethodVisitor mv, String owner) { @@ -39,8 +38,8 @@ public PsClearParametersMV(int access, String desc, MethodVisitor mv, String own public void visitCode() { mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); - //mv.visitFieldInsn(GETFIELD, owner, TraceSQL.PSTMT_PARAM_FIELD, "Lscouter/agent/trace/SqlParameter;"); - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, METHOD, SIGNATURE); + mv.visitFieldInsn(GETFIELD, owner, TraceSQL.PSTMT_PARAM_FIELD, "Lscouter/agent/trace/SqlParameter;"); + mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, METHOD, SIGNATURE,false); super.visitCode(); } diff --git a/scouter.agent.java/src/scouter/agent/asm/jdbc/PsExecuteMV.java b/scouter.agent.java/src/scouter/agent/asm/jdbc/PsExecuteMV.java index 41103d8ed..e4d2d40b8 100644 --- a/scouter.agent.java/src/scouter/agent/asm/jdbc/PsExecuteMV.java +++ b/scouter.agent.java/src/scouter/agent/asm/jdbc/PsExecuteMV.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 LG CNS. + * Copyright 2015 Scouter Project. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package scouter.agent.asm.jdbc; - import java.util.HashSet; import java.util.Set; @@ -27,6 +26,7 @@ import scouter.org.objectweb.asm.Type; import scouter.org.objectweb.asm.commons.LocalVariablesSorter; + public class PsExecuteMV extends LocalVariablesSorter implements Opcodes { private static Set target = new HashSet(); static { @@ -44,13 +44,12 @@ public static boolean isTarget(String name) { private final static String START_METHOD = "start"; private final static String END_METHOD = "end"; private static final String END_SIGNATURE = "(Ljava/lang/Object;Ljava/lang/Throwable;)V"; - private static final String START_SIGNATURE = "(Ljava/lang/Object;)Ljava/lang/Object;"; + private static final String START_SIGNATURE = "(Ljava/lang/Object;Lscouter/agent/trace/SqlParameter;)Ljava/lang/Object;"; public PsExecuteMV(int access, String desc, MethodVisitor mv, String owner) { super(ASM4,access, desc, mv); this.owner = owner; } - private Label startFinally = new Label(); private String owner; @@ -59,13 +58,12 @@ public PsExecuteMV(int access, String desc, MethodVisitor mv, String owner) { @Override public void visitCode() { mv.visitVarInsn(ALOAD, 0); - // mv.visitVarInsn(ALOAD, 0); - // mv.visitFieldInsn(GETFIELD, owner, TraceSQL.PSTMT_PARAM_FIELD, - // "Lscouter/agent/trace/SqlParameter;"); - - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, START_METHOD, START_SIGNATURE); + mv.visitVarInsn(ALOAD, 0); + mv.visitFieldInsn(GETFIELD, owner, TraceSQL.PSTMT_PARAM_FIELD, "Lscouter/agent/trace/SqlParameter;"); + + mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, START_METHOD, START_SIGNATURE,false); - statIdx = newLocal(Type.getType(Object.class)); + statIdx = newLocal(scouter.org.objectweb.asm.Type.getType(Object.class)); mv.visitVarInsn(Opcodes.ASTORE, statIdx); mv.visitLabel(startFinally); mv.visitCode(); @@ -76,7 +74,7 @@ public void visitInsn(int opcode) { if ((opcode >= IRETURN && opcode <= RETURN)) { mv.visitVarInsn(Opcodes.ALOAD, statIdx); mv.visitInsn(Opcodes.ACONST_NULL); - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, END_METHOD, END_SIGNATURE); + mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, END_METHOD, END_SIGNATURE,false); } mv.visitInsn(opcode); } @@ -92,7 +90,7 @@ public void visitMaxs(int maxStack, int maxLocals) { mv.visitVarInsn(Opcodes.ALOAD, statIdx); mv.visitVarInsn(Opcodes.ALOAD, errIdx); - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, END_METHOD, END_SIGNATURE); + mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, END_METHOD, END_SIGNATURE,false); mv.visitInsn(ATHROW); mv.visitMaxs(maxStack + 8, maxLocals + 2); } diff --git a/scouter.agent.java/src/scouter/agent/asm/jdbc/PsInitMV.java b/scouter.agent.java/src/scouter/agent/asm/jdbc/PsInitMV.java index b63f9c120..0cd169d8e 100644 --- a/scouter.agent.java/src/scouter/agent/asm/jdbc/PsInitMV.java +++ b/scouter.agent.java/src/scouter/agent/asm/jdbc/PsInitMV.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 LG CNS. + * Copyright 2015 Scouter Project. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,25 +17,28 @@ package scouter.agent.asm.jdbc; import scouter.agent.asm.util.AsmUtil; +import scouter.agent.trace.SqlParameter; import scouter.agent.trace.TraceSQL; +import scouter.org.objectweb.asm.Label; import scouter.org.objectweb.asm.MethodVisitor; import scouter.org.objectweb.asm.Opcodes; +import scouter.org.objectweb.asm.Type; import scouter.org.objectweb.asm.commons.LocalVariablesSorter; public class PsInitMV extends LocalVariablesSorter implements Opcodes { private final static String TRACESQL = TraceSQL.class.getName().replace('.', '/'); private final static String METHOD = "prepare"; - private final static String SIGNATURE = "(Ljava/lang/Object;Ljava/lang/String;)V"; + private final static String SIGNATURE = "(Ljava/lang/Object;Lscouter/agent/trace/SqlParameter;Ljava/lang/String;)V"; public PsInitMV(int access, String desc, MethodVisitor mv, String owner) { super(ASM4,access, desc, mv); - //this.owner = owner; + this.owner = owner; this.strArgIdx = AsmUtil.getStringIdx(access, desc); } - //private String owner; + private String owner; private int strArgIdx = -1; @Override @@ -43,25 +46,22 @@ public void visitInsn(int opcode) { if (strArgIdx >= 0 && (opcode >= IRETURN && opcode <= RETURN)) { mv.visitVarInsn(ALOAD, 0); - // mv.visitFieldInsn(GETFIELD, owner, TraceSQL.PSTMT_PARAM_FIELD, - // "Lscouter/agent/trace/SqlParameter;"); - // - // Label end = new Label(); - // mv.visitJumpInsn(IFNONNULL, end); - // mv.visitVarInsn(ALOAD, 0); - // mv.visitTypeInsn(NEW, Type.getInternalName(SqlParameter.class)); - // mv.visitInsn(DUP); - // mv.visitMethodInsn(INVOKESPECIAL, - // Type.getInternalName(SqlParameter.class), "", "()V"); - // mv.visitFieldInsn(PUTFIELD, owner, TraceSQL.PSTMT_PARAM_FIELD, - // "Lscouter/agent/trace/SqlParameter;"); - // - // mv.visitLabel(end); - // mv.visitVarInsn(ALOAD, 0); - // mv.visitVarInsn(ALOAD, 0); - // mv.visitFieldInsn(GETFIELD, owner, TraceSQL.PSTMT_PARAM_FIELD, - // "Lscouter/agent/trace/SqlParameter;"); + mv.visitFieldInsn(GETFIELD, owner, TraceSQL.PSTMT_PARAM_FIELD, "Lscouter/agent/trace/SqlParameter;"); + + Label end = new Label(); + mv.visitJumpInsn(IFNONNULL, end); + mv.visitVarInsn(ALOAD, 0); + mv.visitTypeInsn(NEW, Type.getInternalName(SqlParameter.class)); + mv.visitInsn(DUP); + mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(SqlParameter.class), "", "()V",false); + mv.visitFieldInsn(PUTFIELD, owner, TraceSQL.PSTMT_PARAM_FIELD, "Lscouter/agent/trace/SqlParameter;"); + + mv.visitLabel(end); + mv.visitVarInsn(ALOAD, 0); + mv.visitVarInsn(ALOAD, 0); + mv.visitFieldInsn(GETFIELD, owner, TraceSQL.PSTMT_PARAM_FIELD, "Lscouter/agent/trace/SqlParameter;"); mv.visitVarInsn(ALOAD, strArgIdx); + mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, METHOD, SIGNATURE,false); } mv.visitInsn(opcode); diff --git a/scouter.agent.java/src/scouter/agent/asm/jdbc/PsSetMV.java b/scouter.agent.java/src/scouter/agent/asm/jdbc/PsSetMV.java index 639026b85..7beddee22 100644 --- a/scouter.agent.java/src/scouter/agent/asm/jdbc/PsSetMV.java +++ b/scouter.agent.java/src/scouter/agent/asm/jdbc/PsSetMV.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 LG CNS. + * Copyright 2015 Scouter Project. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,20 +16,16 @@ package scouter.agent.asm.jdbc; - import java.util.HashMap; import java.util.Map; import scouter.agent.asm.util.AsmUtil; -import scouter.agent.trace.SqlParameter; import scouter.agent.trace.TraceSQL; import scouter.org.objectweb.asm.MethodVisitor; import scouter.org.objectweb.asm.Opcodes; import scouter.org.objectweb.asm.Type; import scouter.org.objectweb.asm.commons.LocalVariablesSorter; - - public class PsSetMV extends LocalVariablesSorter implements Opcodes { private static Map target = new HashMap(); @@ -74,60 +70,62 @@ public PsSetMV(int access, String name, String desc, MethodVisitor mv, String ow private Type[] args; public void visitCode() { - -// mv.visitVarInsn(Opcodes.ALOAD, 0); -// mv.visitFieldInsn(GETFIELD, owner, TraceSQL.PSTMT_PARAM_FIELD, "Lscouter/agent/trace/SqlParameter;"); + mv.visitVarInsn(Opcodes.ALOAD, 0); + mv.visitFieldInsn(GETFIELD, owner, TraceSQL.PSTMT_PARAM_FIELD, "Lscouter/agent/trace/SqlParameter;"); mv.visitVarInsn(Opcodes.ILOAD, 1); + if (name.equals("setNull")) { AsmUtil.PUSH(mv, (String) null); - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "set", "(ILjava/lang/String;)V"); + mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "set", + "(Lscouter/agent/trace/SqlParameter;ILjava/lang/String;)V",false); } else { Type tp = args[1]; switch (tp.getSort()) { case Type.BOOLEAN: mv.visitVarInsn(Opcodes.ILOAD, 2); - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "set", "(IZ)V"); + mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "set", "(Lscouter/agent/trace/SqlParameter;IZ)V",false); break; case Type.CHAR: case Type.BYTE: case Type.SHORT: case Type.INT: mv.visitVarInsn(Opcodes.ILOAD, 2); - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "set", "(II)V"); + mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "set", "(Lscouter/agent/trace/SqlParameter;II)V",false); break; case Type.LONG: mv.visitVarInsn(Opcodes.LLOAD, 2); - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "set", "(IJ)V"); + mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "set", "(Lscouter/agent/trace/SqlParameter;IJ)V",false); break; case Type.FLOAT: mv.visitVarInsn(Opcodes.FLOAD, 2); - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "set", "(IF)V"); + mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "set", "(Lscouter/agent/trace/SqlParameter;IF)V",false); break; case Type.DOUBLE: mv.visitVarInsn(Opcodes.DLOAD, 2); - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "set", "(ID)V"); + mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "set", "(Lscouter/agent/trace/SqlParameter;ID)V",false); break; case Type.ARRAY: case Type.OBJECT: mv.visitVarInsn(Opcodes.ALOAD, 2); if (tp.equals(AsmUtil.stringType)) { - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "set", "(ILjava/lang/String;)V"); + mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "set", + "(Lscouter/agent/trace/SqlParameter;ILjava/lang/String;)V",false); } else { - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "set", "(ILjava/lang/Object;)V"); + mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "set", + "(Lscouter/agent/trace/SqlParameter;ILjava/lang/Object;)V",false); } break; default: mv.visitVarInsn(Opcodes.ALOAD, 2); AsmUtil.PUSH(mv, "unknown " + tp); - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "set", "(ILjava/lang/String;)V"); + mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "set", + "(Lscouter/agent/trace/SqlParameter;ILjava/lang/String;)V",false); break; } } super.visitCode(); } - public static void main(String[] args) { - System.out.println(Type.getDescriptor(SqlParameter.class)); - } + } \ No newline at end of file diff --git a/scouter.agent.java/src/scouter/agent/asm/jdbc/RsCloseMV.java b/scouter.agent.java/src/scouter/agent/asm/jdbc/RsCloseMV.java index 357020e43..2d6dcced5 100644 --- a/scouter.agent.java/src/scouter/agent/asm/jdbc/RsCloseMV.java +++ b/scouter.agent.java/src/scouter/agent/asm/jdbc/RsCloseMV.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 LG CNS. + * Copyright 2015 Scouter Project. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,7 +34,7 @@ public RsCloseMV(MethodVisitor mv) { public void visitInsn(int opcode) { if ((opcode >= IRETURN && opcode <= RETURN)) { mv.visitVarInsn(Opcodes.ALOAD, 0); - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, METHOD, SIGNATURE); + mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, METHOD, SIGNATURE,false); } mv.visitInsn(opcode); } diff --git a/scouter.agent.java/src/scouter/agent/asm/jdbc/RsNextMV.java b/scouter.agent.java/src/scouter/agent/asm/jdbc/RsNextMV.java index 2f2fc2860..48ad934e4 100644 --- a/scouter.agent.java/src/scouter/agent/asm/jdbc/RsNextMV.java +++ b/scouter.agent.java/src/scouter/agent/asm/jdbc/RsNextMV.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 LG CNS. + * Copyright 2015 Scouter Project. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,7 +33,7 @@ public RsNextMV(MethodVisitor mv) { @Override public void visitInsn(int opcode) { if ((opcode >= IRETURN && opcode <= RETURN)) { - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, METHOD, SIGNATURE); + mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, METHOD, SIGNATURE,false); } mv.visitInsn(opcode); } diff --git a/scouter.agent.java/src/scouter/agent/asm/jdbc/StExecuteMV.java b/scouter.agent.java/src/scouter/agent/asm/jdbc/StExecuteMV.java index d38268857..00d529101 100644 --- a/scouter.agent.java/src/scouter/agent/asm/jdbc/StExecuteMV.java +++ b/scouter.agent.java/src/scouter/agent/asm/jdbc/StExecuteMV.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 LG CNS. + * Copyright 2015 Scouter Project. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,9 +14,8 @@ * limitations under the License. */ -package scouter.agent.asm.jdbc; - - +package scouter.agent.asm.jdbc; + import java.util.HashSet; import java.util.Set; @@ -26,71 +25,69 @@ import scouter.org.objectweb.asm.Opcodes; import scouter.org.objectweb.asm.Type; import scouter.org.objectweb.asm.commons.LocalVariablesSorter; - - - -public class StExecuteMV extends LocalVariablesSorter implements Opcodes { - private static Set target = new HashSet(); - static { - target.add("execute"); - target.add("executeQuery"); - target.add("executeUpdate"); - target.add("executeBatch"); - } - - public static boolean isTarget(String name) { - return target.contains(name); - } - - private final static String TRACESQL = TraceSQL.class.getName().replace('.', '/'); - private final static String START_METHOD = "start"; - private static final String START_SIGNATURE = "(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;"; - private final static String END_METHOD = "end"; - private static final String END_SIGNATURE = "(Ljava/lang/Object;Ljava/lang/Throwable;)V"; - - public StExecuteMV(int access, String desc, MethodVisitor mv, String owner) { - super(ASM4,access, desc, mv); - } - - private Label startFinally = new Label(); - private int statIdx; - - @Override - public void visitCode() { - mv.visitVarInsn(ALOAD, 0); - mv.visitVarInsn(ALOAD, 1); - - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, START_METHOD, START_SIGNATURE); - - statIdx = newLocal(Type.getType(Object.class)); - mv.visitVarInsn(Opcodes.ASTORE, statIdx); - mv.visitLabel(startFinally); - mv.visitCode(); - } - - @Override - public void visitInsn(int opcode) { - if ((opcode >= IRETURN && opcode <= RETURN)) { - mv.visitVarInsn(Opcodes.ALOAD, statIdx); - mv.visitInsn(Opcodes.ACONST_NULL); - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, END_METHOD, END_SIGNATURE); - } - mv.visitInsn(opcode); - } - - @Override - public void visitMaxs(int maxStack, int maxLocals) { - Label endFinally = new Label(); - mv.visitTryCatchBlock(startFinally, endFinally, endFinally, null); - mv.visitLabel(endFinally); - mv.visitInsn(DUP); - int errIdx = newLocal(Type.getType(Throwable.class)); - mv.visitVarInsn(Opcodes.ASTORE, errIdx); - - mv.visitVarInsn(Opcodes.ALOAD, statIdx); - mv.visitVarInsn(Opcodes.ALOAD, errIdx); - mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, END_METHOD, END_SIGNATURE); - mv.visitInsn(ATHROW); - mv.visitMaxs(maxStack + 8, maxLocals + 2); - } + +public class StExecuteMV extends LocalVariablesSorter implements Opcodes { + private static Set target = new HashSet(); + static { + target.add("execute"); + target.add("executeQuery"); + target.add("executeUpdate"); + target.add("executeBatch"); + } + + public static boolean isTarget(String name) { + return target.contains(name); + } + + private final static String TRACESQL = TraceSQL.class.getName().replace('.', '/'); + private final static String START_METHOD = "start"; + private static final String START_SIGNATURE = "(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;"; + private final static String END_METHOD = "end"; + private static final String END_SIGNATURE = "(Ljava/lang/Object;Ljava/lang/Throwable;)V"; + + public StExecuteMV(int access, String desc, MethodVisitor mv, String owner) { + super(ASM4, access, desc, mv); + } + + private Label startFinally = new Label(); + private int statIdx; + + @Override + public void visitCode() { + mv.visitVarInsn(ALOAD, 0); + mv.visitVarInsn(ALOAD, 1); + + mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, START_METHOD, START_SIGNATURE, false); + + statIdx = newLocal(Type.getType(Object.class)); + mv.visitVarInsn(Opcodes.ASTORE, statIdx); + mv.visitLabel(startFinally); + mv.visitCode(); + } + + @Override + public void visitInsn(int opcode) { + if ((opcode >= IRETURN && opcode <= RETURN)) { + mv.visitVarInsn(Opcodes.ALOAD, statIdx); + mv.visitInsn(Opcodes.ACONST_NULL); + mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, END_METHOD, END_SIGNATURE, false); + } + mv.visitInsn(opcode); + } + + @Override + public void visitMaxs(int maxStack, int maxLocals) { + Label endFinally = new Label(); + mv.visitTryCatchBlock(startFinally, endFinally, endFinally, null); + mv.visitLabel(endFinally); + mv.visitInsn(DUP); + int errIdx = newLocal(Type.getType(Throwable.class)); + mv.visitVarInsn(Opcodes.ASTORE, errIdx); + + mv.visitVarInsn(Opcodes.ALOAD, statIdx); + mv.visitVarInsn(Opcodes.ALOAD, errIdx); + mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, END_METHOD, END_SIGNATURE, false); + mv.visitInsn(ATHROW); + mv.visitMaxs(maxStack + 8, maxLocals + 2); + } } \ No newline at end of file diff --git a/scouter.agent.java/src/scouter/agent/asm/util/AsmUtil.java b/scouter.agent.java/src/scouter/agent/asm/util/AsmUtil.java index 0b8218e02..844d8b561 100644 --- a/scouter.agent.java/src/scouter/agent/asm/util/AsmUtil.java +++ b/scouter.agent.java/src/scouter/agent/asm/util/AsmUtil.java @@ -142,6 +142,7 @@ public static int getStringIdx(int access, String desc) { return -1; } + public static boolean isSpecial(String name) { return name.indexOf("$") >= 0 || name.startsWith("<"); } diff --git a/scouter.agent.java/src/scouter/agent/asm/util/MethodSet.java b/scouter.agent.java/src/scouter/agent/asm/util/MethodSet.java index 1bef55326..06e1bbd20 100644 --- a/scouter.agent.java/src/scouter/agent/asm/util/MethodSet.java +++ b/scouter.agent.java/src/scouter/agent/asm/util/MethodSet.java @@ -14,10 +14,11 @@ * limitations under the License. */ -package scouter.agent.asm.util; - +package scouter.agent.asm.util; + import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -26,158 +27,128 @@ import scouter.agent.Configure; import scouter.util.StrMatch; import scouter.util.StringUtil; - + public class MethodSet { - public byte xType=0; - public StrMatch classMatch = null; - protected HashMap inner = new HashMap(); - - private boolean all_flag = false; - private int all_flag_value; - - public boolean isA(String method, String desc) { - if (all_flag) - return true; - else if (this.contains(method)) - return true; - else if (this.contains(method + desc)) - return true; - return false; - } - - public boolean contains(String name) { - return inner.containsKey(name); - } - - public void add(String mname) { - if ("*".equals(mname)) { - this.all_flag = true; - } else { - inner.put(mname, ""); - } - } - - public void add(String mname, int idx) { - if ("*".equals(mname)) { - this.all_flag = true; - this.all_flag_value = idx; - } else { - this.inner.put(mname, idx); - } - } - - public int get(String method, String desc) { - if (all_flag) - return all_flag_value; - - Integer i = (Integer) this.inner.get(method); - if (i != null) { - return i.intValue(); - } - i = (Integer) this.inner.get(method); - if (i != null) { - return i.intValue(); - } - return -1; - } - - public static Map getHookingSet(String arg) { - String[] c = StringUtil.split(arg, ','); - Map classSet = new HashMap(); - for (int i = 0; i < c.length; i++) { - String s = c[i]; - int x = s.lastIndexOf("."); - if (x <= 0) - continue; - String cname = s.substring(0, x).replace('.', '/'); - String mname = s.substring(x + 1); - - MethodSet methodSet = classSet.get(cname); - if (methodSet == null) { - methodSet = new MethodSet(); - classSet.put(cname, methodSet); - } - methodSet.add(mname); - } - return classSet; - } - - public static List getHookingMethodSet(String arg) { - String[] c = StringUtil.split(arg, ','); - - Map classSet = new HashMap(); - for (int i = 0; i < c.length; i++) { - String s = c[i]; - int x = s.lastIndexOf("."); - if (x <= 0) - continue; - String cname = s.substring(0, x).replace('.', '/').trim(); - String mname = s.substring(x + 1).trim(); - - MethodSet methodSet = classSet.get(cname); - if (methodSet == null) { - methodSet = new MethodSet(); - classSet.put(cname, methodSet); + public byte xType = 0; + public StrMatch classMatch = null; + protected HashMap inner = new HashMap(); + + private boolean all_flag = false; + private int all_flag_value; + + public boolean isA(String method, String desc) { + if (all_flag) + return true; + else if (this.contains(method)) + return true; + else if (this.contains(method + desc)) + return true; + return false; + } + + public boolean contains(String name) { + return inner.containsKey(name); + } + + public void add(String mname) { + if ("*".equals(mname)) { + this.all_flag = true; + } else { + inner.put(mname, ""); + } + } + + public void add(String mname, int idx) { + if ("*".equals(mname)) { + this.all_flag = true; + this.all_flag_value = idx; + } else { + this.inner.put(mname, idx); + } + } + + public int get(String method, String desc) { + if (all_flag) + return all_flag_value; + + Integer i = (Integer) this.inner.get(method); + if (i != null) { + return i.intValue(); + } + i = (Integer) this.inner.get(method); + if (i != null) { + return i.intValue(); + } + return -1; + } + + public static Map getHookingSet(String arg) { + String[] c = StringUtil.split(arg, ','); + Map classSet = new HashMap(); + for (int i = 0; i < c.length; i++) { + String s = c[i]; + int x = s.lastIndexOf("."); + if (x <= 0) + continue; + String cname = s.substring(0, x).replace('.', '/'); + String mname = s.substring(x + 1); + + MethodSet methodSet = classSet.get(cname); + if (methodSet == null) { + methodSet = new MethodSet(); + classSet.put(cname, methodSet); + } + methodSet.add(mname); + } + return classSet; + } + + public static List getHookingMethodSet(String arg) { + String[] c = StringUtil.split(arg, ','); + + Map classSet = new HashMap(); + for (int i = 0; i < c.length; i++) { + String s = c[i]; + int x = s.lastIndexOf("."); + if (x <= 0) + continue; + String cname = s.substring(0, x).replace('.', '/').trim(); + String mname = s.substring(x + 1).trim(); + + MethodSet methodSet = classSet.get(cname); + if (methodSet == null) { + methodSet = new MethodSet(); + classSet.put(cname, methodSet); } - - methodSet.add(mname); - } - - List list = new ArrayList(); - Iterator> itr = classSet.entrySet().iterator(); - while (itr.hasNext()) { - Entry e = itr.next(); - e.getValue().classMatch = new StrMatch(e.getKey()); - list.add(e.getValue()); - } - - return list; - } - - public static void setHookingMethod(Map classSet, String cname, String mname) { - - MethodSet methodSet = classSet.get(cname); - if (methodSet == null) { - methodSet = new MethodSet(); - classSet.put(cname, methodSet); - } - methodSet.add(mname); - } - - public static Map getHookingDiv(String mode) { - Configure conf = Configure.getInstance(); - Map classSet = new HashMap(); - - int divPerfSize = conf.getInt("divperf.size", 0); - for (int m = 0; m < divPerfSize; m++) { - String[] c = StringUtil.split(conf.getValue("divperf." + m, ""), ';'); - for (int i = 0; i < c.length; i++) { - String s = c[i]; - int x = s.lastIndexOf("."); - if (x <= 0) - continue; - String cname = s.substring(0, x).replace('.', '/'); - String mname = s.substring(x + 1); - if (mname.endsWith(mode) == false) - continue; - mname = mname.substring(0, mname.length() - mode.length()); - - MethodSet methodSet = classSet.get(cname); - if (methodSet == null) { - methodSet = new MethodSet(); - classSet.put(cname, methodSet); - } - methodSet.add(mname, m); - } - } - - return classSet; - } - - public static void add(List list, String classname, String method) { - add(list, classname, method,(byte)0); + + methodSet.add(mname); + } + + List list = new ArrayList(); + Iterator> itr = classSet.entrySet().iterator(); + while (itr.hasNext()) { + Entry e = itr.next(); + e.getValue().classMatch = new StrMatch(e.getKey()); + list.add(e.getValue()); + } + + return list; } - + + public static void setHookingMethod(Map classSet, String cname, String mname) { + + MethodSet methodSet = classSet.get(cname); + if (methodSet == null) { + methodSet = new MethodSet(); + classSet.put(cname, methodSet); + } + methodSet.add(mname); + } + + public static void add(List list, String classname, String method) { + add(list, classname, method, (byte) 0); + } + public static void add(List list, String classname, String method, byte serviceType) { for (int i = 0; i < list.size(); i++) { MethodSet m = list.get(i); @@ -187,9 +158,20 @@ public static void add(List list, String classname, String method, by } } MethodSet m = new MethodSet(); - m.xType=serviceType; + m.xType = serviceType; m.classMatch = new StrMatch(classname); m.add(method); list.add(m); - } + } + + public static HashSet getHookingClassSet(String arg) { + String[] c = StringUtil.tokenizer(arg, ","); + HashSet classSet = new HashSet(); + if(c ==null) + return classSet; + for (int i = 0; i < c.length; i++) { + classSet.add(c[i]); + } + return classSet; + } } \ No newline at end of file diff --git a/scouter.agent.java/src/scouter/agent/plugin/ApiCallTracePlugin.java b/scouter.agent.java/src/scouter/agent/plugin/ApiCallTracePlugin.java index 08b376ffa..208f0b407 100644 --- a/scouter.agent.java/src/scouter/agent/plugin/ApiCallTracePlugin.java +++ b/scouter.agent.java/src/scouter/agent/plugin/ApiCallTracePlugin.java @@ -66,12 +66,6 @@ private static void defaultObjects() { put(new ForJCOClient()); put(new ForRibbonLB()); put(new ForNettyHttpRequest()); - - // TODO:LF를 위해 임시로 추가해둠 나중에 Plugin으로 분리해야함 - put("lgfs/frontoffice/sap/service/SapServiceImpl", new ForSAPTemp()); - put("lgfs/woutlet/sap/service/SapServiceImpl", new ForSAPTemp()); - put("lgfs/mfront/sap/service/SapServiceImpl", new ForSAPTemp()); - put("lgfs/moutlet/sap/service/SapServiceImpl", new ForSAPTemp()); } public static void reinit() { diff --git a/scouter.agent.java/src/scouter/agent/trace/TraceSQL.java b/scouter.agent.java/src/scouter/agent/trace/TraceSQL.java index 52748ddbd..bfb057514 100644 --- a/scouter.agent.java/src/scouter/agent/trace/TraceSQL.java +++ b/scouter.agent.java/src/scouter/agent/trace/TraceSQL.java @@ -116,7 +116,7 @@ public static Object start(Object o) { if (ctx.profile_thread_cputime) { step.start_cpu = (int) (SysJMX.getCurrentThreadCPU() - ctx.startCpu); } - step.xtype=SqlXType.DYNA; + step.xtype = SqlXType.DYNA; ctx.sqlActiveArgs = ctx.sql; @@ -155,7 +155,7 @@ public static Object start(Object o, String sql) { sql = escapeLiteral(sql, step); } step.hash = DataProxy.sendSqlText(sql); - step.xtype=SqlXType.STMT; + step.xtype = SqlXType.STMT; ctx.profile.push(step); ctx.sqltext = sql; @@ -394,7 +394,7 @@ public static Object start(Object o, SqlParameter args) { if (sql != null) { step.hash = DataProxy.sendSqlText(sql); } - step.xtype=SqlXType.PREPARED; + step.xtype = SqlXType.PREPARED; ctx.profile.push(step); ctx.sqltext = sql; @@ -405,6 +405,17 @@ public static void prepare(Object o, SqlParameter args, String sql) { if (args != null) { args.setSql(sql); } + + // @skyworker : debug code 2015.09.18 + // TraceContext ctx = TraceContextManager.getLocalContext(); + // if (ctx != null) { + // MessageStep m = new MessageStep(); + // m.start_time = (int) (System.currentTimeMillis() - ctx.startTime); + // m.message = + // ThreadUtil.getStackTrace(Thread.currentThread().getStackTrace()); + // ctx.profile.add(m); + // } + } /** diff --git a/scouter.client/plugin.xml b/scouter.client/plugin.xml index 9aa3670b3..dbd88bff7 100644 --- a/scouter.client/plugin.xml +++ b/scouter.client/plugin.xml @@ -298,20 +298,12 @@ - - defaultHighlightings; - - private StyledText text; - private String agentConfig; - private int objHash; - private String objName; - - RedefineClassDialog dialog; - - boolean saved = false; - private int serverId; - - Composite listComp; - Table table; - - private Clipboard clipboard = new Clipboard(null); - - CustomLineStyleListener listener; - - @Override - public void init(IViewSite site) throws PartInitException { - super.init(site); - String objHash = site.getSecondaryId(); - if (objHash != null) { - this.objHash = Integer.valueOf(objHash); - } - } - - public void setInput(int serverId){ - this.serverId = serverId; - objName = TextProxy.object.getLoadText(DateUtil.yyyymmdd(TimeUtil.getCurrentTime(serverId)), objHash, serverId); - setPartName("Config Agent [" + objName + "]"); - loadConfig(); - loadConfigList(); - } - - @Override - public void createPartControl(Composite parent) { - parent.setLayout(new FillLayout()); - SashForm sashForm = new SashForm(parent, SWT.HORIZONTAL); - sashForm.SASH_WIDTH = 1; - initialStyledText(sashForm); - listComp = new Composite(sashForm, SWT.NONE); - listComp.setLayout(ChartUtil.gridlayout(1)); - table = new Table(listComp,SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL); - table.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL)); - table.setHeaderVisible(true); - table.setLinesVisible(true); - UIUtil.create(table, SWT.LEFT, "Key", 3, 0, false, 200); - UIUtil.create(table, SWT.CENTER, "Value", 3, 1, false, 100); - UIUtil.create(table, SWT.CENTER, "Def.", 3, 2, false, 100); - - table.addKeyListener(new KeyAdapter() { - public void keyPressed(KeyEvent e) { - if(e.stateMask == SWT.CTRL){ - if (e.keyCode == 'c' || e.keyCode == 'C') { - TableItem[] items = table.getSelection(); - if (items == null || items.length < 1) { - return; - } - StringBuffer sb = new StringBuffer(); - for (TableItem item : items) { - sb.append(item.getText(0)); - sb.append("="); - sb.append(item.getText(1)); - sb.append("\n"); - } - clipboard.setContents(new Object[] {sb.toString()}, new Transfer[] {TextTransfer.getInstance()}); - } - } - } - }); - - sashForm.setWeights(new int[] {1, 1}); - sashForm.setMaximizedControl(null); - - initialToolBar(); - } - - - - private void initialStyledText(Composite parent) { - text = new StyledText(parent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); - text.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - saved = false; - } - }); - text.addKeyListener(new KeyListener() { - public void keyReleased(KeyEvent e) { - } - public void keyPressed(KeyEvent e) { - if(e.stateMask == SWT.CTRL){ - if(e.keyCode == 's'){ - saveConfigurations(); - }else if(e.keyCode == 'a'){ - text.selectAll(); - } - } - } - }); - - - listener = new CustomLineStyleListener(text.getDisplay(), true, defaultHighlightings, false); - text.addLineStyleListener(listener); - } - - private void saveConfigurations(){ - TcpProxy tcp = TcpProxy.getTcpProxy(serverId); - try { - MapPack param = new MapPack(); - param.put("objHash", objHash); - param.put("setConfig", text.getText()); - MapPack out = (MapPack) tcp.getSingle(RequestCmd.SET_CONFIGURE_WAS, param); - - if(out == null){ - return; - } - - if (out != null) { - String config = out.getText("result"); - if("true".equalsIgnoreCase(config)) { - MessageDialog.open(MessageDialog.INFORMATION - , PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() - , "Success" - , objName + "- Configuration saving is done." - , SWT.NONE); - loadConfigList(); - saved = true; - } else { - MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() - ,"Error" - , objName + "- Configuration saving is failed."); - } - } - } catch(Exception e){ - ConsoleProxy.errorSafe(e.toString()); - } finally { - TcpProxy.putTcpProxy(tcp); - } - } - - private void initialToolBar() { - IToolBarManager man = getViewSite().getActionBars().getToolBarManager(); - man.add(new Action("Save", ImageUtil.getImageDescriptor(Images.save)) { - public void run() { - saveConfigurations(); - } - }); -// man.add(new Action("Redefine", ImageUtil.getImageDescriptor(Images.apply)) { -// public void run() { -// if(!saved){ -// MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() -// ,"Redefine class" -// , "Please save server configuration first."); -// -// return; -// } -// -// String configureBody = text.getText(); -// Properties prop = new Properties(); -// -// try { -// prop.load(new ByteArrayInputStream(configureBody.getBytes())); -// } catch (IOException e) { -// e.printStackTrace(); -// } -// String methods = prop.getProperty("hook.method"); -// String services = prop.getProperty("hook.service"); -// -// if(methods == null){ -// methods = ""; -// } -// if(services == null){ -// services = ""; -// } -// -// String value = methods + "," + services; -// -// Display display = Display.getCurrent(); -// if (display == null) { -// display = Display.getDefault(); -// } -// dialog = new RedefineClassDialog(display); -// dialog.show(objHash, value, serverId, getViewSite().getShell().getBounds()); -// } -// }); - } - - private void loadConfig() { - ExUtil.asyncRun(new Runnable() { - public void run() { - MapPack mpack = null; - TcpProxy tcp = TcpProxy.getTcpProxy(serverId); - try { - MapPack param = new MapPack(); - param.put("objHash", objHash); - mpack = (MapPack) tcp.getSingle(RequestCmd.GET_CONFIGURE_WAS, param); - if(mpack == null){ - return; - } - - } catch(Exception e){ - ConsoleProxy.errorSafe(e.toString()); - } finally { - TcpProxy.putTcpProxy(tcp); - } - if (mpack != null) { - ListValue configKey = mpack.getList("configKey"); - - defaultHighlightings = new ArrayList(); - for(int inx = 0 ; configKey != null && inx < configKey.size(); inx++){ - defaultHighlightings.add(new ColoringWord(configKey.getString(inx), SWT.COLOR_BLUE, true)); - } - defaultHighlightings.add(new ColoringWord(";", SWT.COLOR_RED, true)); - - agentConfig = mpack.getText("agentConfig"); - } - - ExUtil.exec(text, new Runnable() { - public void run() { - listener.setKeywordArray(defaultHighlightings); - text.setText(agentConfig); - } - }); - } - }); - } - - private void loadConfigList() { - ExUtil.asyncRun(new Runnable() { - public void run() { - MapPack pack = null; - TcpProxy tcp = TcpProxy.getTcpProxy(serverId); - try { - MapPack param = new MapPack(); - param.put("objHash", objHash); - pack = (MapPack) tcp.getSingle(RequestCmd.LIST_CONFIGURE_WAS, param); - } catch (Exception e) { - e.printStackTrace(); - } finally { - TcpProxy.putTcpProxy(tcp); - } - if (pack != null) { - final ListValue keyList = pack.getList("key"); - final ListValue valueList = pack.getList("value"); - final ListValue defaultList = pack.getList("default"); - ExUtil.exec(listComp, new Runnable() { - public void run() { - table.removeAll(); - for (int i = 0; i < keyList.size(); i++) { - TableItem item = new TableItem(table, SWT.NONE); - item.setText(new String[] {CastUtil.cString(keyList.get(i)), - CastUtil.cString(valueList.get(i)), - CastUtil.cString(defaultList.get(i)) }); - } - listComp.layout(); - } - }); - } - } - }); - } - - public void setFocus() { - IStatusLineManager slManager= getViewSite().getActionBars().getStatusLineManager(); - slManager.setMessage("CTRL + S : save configurations, CTRL + A : select all text"); - } - -} diff --git a/scouter.client/src/scouter/client/configuration/views/ConfigureServerView.java b/scouter.client/src/scouter/client/configuration/views/ConfigureServerView.java deleted file mode 100644 index d4a2b571b..000000000 --- a/scouter.client/src/scouter/client/configuration/views/ConfigureServerView.java +++ /dev/null @@ -1,251 +0,0 @@ -/* - * Copyright 2015 LG CNS. - * - * 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.client.configuration.views; - -import java.util.ArrayList; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IStatusLineManager; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.SashForm; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.dnd.Clipboard; -import org.eclipse.swt.dnd.TextTransfer; -import org.eclipse.swt.dnd.Transfer; -import org.eclipse.swt.events.KeyAdapter; -import org.eclipse.swt.events.KeyEvent; -import org.eclipse.swt.events.KeyListener; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableItem; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.part.ViewPart; - -import scouter.client.Images; -import scouter.client.net.TcpProxy; -import scouter.client.server.Server; -import scouter.client.server.ServerManager; -import scouter.client.util.ChartUtil; -import scouter.client.util.ColoringWord; -import scouter.client.util.ConsoleProxy; -import scouter.client.util.ExUtil; -import scouter.client.util.ImageUtil; -import scouter.client.util.CustomLineStyleListener; -import scouter.client.util.UIUtil; -import scouter.lang.pack.MapPack; -import scouter.lang.value.ListValue; -import scouter.net.RequestCmd; -import scouter.util.CastUtil; - -public class ConfigureServerView extends ViewPart { - public final static String ID = ConfigureServerView.class.getName(); - - private ArrayList defaultHighlightings; - - private StyledText text; - private String serverConfig; - private int serverId; - - Composite listComp; - Table table; - - private Clipboard clipboard = new Clipboard(null); - - CustomLineStyleListener listener; - - public void createPartControl(Composite parent) { - parent.setLayout(new FillLayout()); - SashForm sashForm = new SashForm(parent, SWT.HORIZONTAL); - sashForm.SASH_WIDTH = 1; - initialStyledText(sashForm); - listComp = new Composite(sashForm, SWT.NONE); - listComp.setLayout(ChartUtil.gridlayout(1)); - table = new Table(listComp,SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL); - table.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL)); - table.setHeaderVisible(true); - table.setLinesVisible(true); - UIUtil.create(table, SWT.LEFT, "Key", 3, 0, false, 200); - UIUtil.create(table, SWT.CENTER, "Value", 3, 1, false, 100); - UIUtil.create(table, SWT.CENTER, "Def.", 3, 2, false, 100); - - table.addKeyListener(new KeyAdapter() { - public void keyPressed(KeyEvent e) { - if(e.stateMask == SWT.CTRL){ - if (e.keyCode == 'c' || e.keyCode == 'C') { - TableItem[] items = table.getSelection(); - if (items == null || items.length < 1) { - return; - } - StringBuffer sb = new StringBuffer(); - for (TableItem item : items) { - sb.append(item.getText(0)); - sb.append("="); - sb.append(item.getText(1)); - sb.append("\n"); - } - clipboard.setContents(new Object[] {sb.toString()}, new Transfer[] {TextTransfer.getInstance()}); - } - } - } - }); - - sashForm.setWeights(new int[] {1, 1}); - sashForm.setMaximizedControl(null); - initialToolBar(); - } - - public void setInput(int serverId){ - this.serverId = serverId; - Server server = ServerManager.getInstance().getServer(serverId); - if (server != null) { - setPartName("Config Server[" + server.getName() + "]"); - loadConfig(); - loadConfigList(); - } - } - - private void initialStyledText(Composite parent) { - text = new StyledText(parent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); - listener = new CustomLineStyleListener(true, defaultHighlightings, false); - text.addLineStyleListener(listener); - text.addKeyListener(new KeyListener() { - public void keyReleased(KeyEvent e) { - } - public void keyPressed(KeyEvent e) { - if(e.stateMask == SWT.CTRL){ - if(e.keyCode == 's'){ - saveConfigurations(); - }else if(e.keyCode == 'a'){ - text.selectAll(); - } - } - } - }); - } - - private void saveConfigurations(){ - TcpProxy tcp = TcpProxy.getTcpProxy(serverId); - try { - MapPack param = new MapPack(); - param.put("setConfig", text.getText()); - MapPack out = (MapPack) tcp.getSingle(RequestCmd.SET_CONFIGURE_SERVER, param); - - if (out != null) { - String config = out.getText("result"); - if("true".equalsIgnoreCase(config)) { - MessageDialog.open(MessageDialog.INFORMATION - , PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() - , "Success" - , "Configuration saving is done." - , SWT.NONE); - loadConfigList(); - } else { - MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() - ,"Error" - , "Configuration saving is failed."); - } - } - } catch(Exception e){ - ConsoleProxy.errorSafe(e.toString()); - } finally { - TcpProxy.putTcpProxy(tcp); - } - } - - private void initialToolBar() { - IToolBarManager man = getViewSite().getActionBars().getToolBarManager(); - man.add(new Action("Save", ImageUtil.getImageDescriptor(Images.save)) { - public void run() { - saveConfigurations(); - } - }); - } - - private void loadConfig() { - ExUtil.asyncRun(new Runnable() { - public void run() { - MapPack mpack = null; - TcpProxy tcp = TcpProxy.getTcpProxy(serverId); - try { - mpack = (MapPack) tcp.getSingle(RequestCmd.GET_CONFIGURE_SERVER, null); - } finally { - TcpProxy.putTcpProxy(tcp); - } - if (mpack != null) { - ListValue configKey = mpack.getList("configKey"); - - defaultHighlightings = new ArrayList(); - for(int inx = 0 ; configKey != null && inx < configKey.size(); inx++){ - defaultHighlightings.add(new ColoringWord(configKey.getString(inx), SWT.COLOR_BLUE, true)); - } - defaultHighlightings.add(new ColoringWord(";", SWT.COLOR_RED, true)); - - serverConfig = mpack.getText("serverConfig"); - } - ExUtil.exec(text, new Runnable() { - public void run() { - listener.setKeywordArray(defaultHighlightings); - text.setText(serverConfig); - } - }); - } - }); - } - - private void loadConfigList() { - ExUtil.asyncRun(new Runnable() { - public void run() { - MapPack pack = null; - TcpProxy tcp = TcpProxy.getTcpProxy(serverId); - try { - pack = (MapPack) tcp.getSingle(RequestCmd.LIST_CONFIGURE_SERVER, null); - } catch (Exception e) { - e.printStackTrace(); - } finally { - TcpProxy.putTcpProxy(tcp); - } - if (pack != null) { - final ListValue keyList = pack.getList("key"); - final ListValue valueList = pack.getList("value"); - final ListValue defaultList = pack.getList("default"); - ExUtil.exec(listComp, new Runnable() { - public void run() { - table.removeAll(); - for (int i = 0; i < keyList.size(); i++) { - TableItem item = new TableItem(table, SWT.NONE); - item.setText(new String[] {CastUtil.cString(keyList.get(i)), - CastUtil.cString(valueList.get(i)), - CastUtil.cString(defaultList.get(i)) }); - } - listComp.layout(); - } - }); - } - } - }); - } - - public void setFocus() { - IStatusLineManager slManager= getViewSite().getActionBars().getStatusLineManager(); - slManager.setMessage("CTRL + S : save configurations, CTRL + A : select all text"); - } - -} diff --git a/scouter.client/src/scouter/client/configuration/views/ConfigureView.java b/scouter.client/src/scouter/client/configuration/views/ConfigureView.java new file mode 100644 index 000000000..ce6f7d9d3 --- /dev/null +++ b/scouter.client/src/scouter/client/configuration/views/ConfigureView.java @@ -0,0 +1,391 @@ +/* + * Copyright 2015 LG CNS. + * + * 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.client.configuration.views; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IStatusLineManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.layout.TableColumnLayout; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.jface.viewers.ColumnWeightData; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TableViewerColumn; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.dnd.Clipboard; +import org.eclipse.swt.dnd.TextTransfer; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.part.ViewPart; + +import scouter.client.Images; +import scouter.client.model.TextProxy; +import scouter.client.net.TcpProxy; +import scouter.client.server.Server; +import scouter.client.server.ServerManager; +import scouter.client.sorter.ColumnLabelSorter; +import scouter.client.util.ColoringWord; +import scouter.client.util.ConsoleProxy; +import scouter.client.util.CustomLineStyleListener; +import scouter.client.util.ExUtil; +import scouter.client.util.ImageUtil; +import scouter.lang.pack.MapPack; +import scouter.lang.value.ListValue; +import scouter.net.RequestCmd; +import scouter.util.CastUtil; +import scouter.util.StringUtil; + +public class ConfigureView extends ViewPart { + public final static String ID = ConfigureView.class.getName(); + + private ArrayList defaultHighlightings; + + private StyledText text; + private String content; + private int serverId; + private int objHash; + + Composite listComp; + TableViewer viewer; + Table table; + Text searchTxt; + + TableColumnLayout tableColumnLayout; + + private Clipboard clipboard = new Clipboard(null); + + CustomLineStyleListener listener; + + public void createPartControl(Composite parent) { + parent.setLayout(new FillLayout()); + SashForm sashForm = new SashForm(parent, SWT.HORIZONTAL); + sashForm.SASH_WIDTH = 1; + initialStyledText(sashForm); + listComp = new Composite(sashForm, SWT.NONE); + listComp.setLayout(new GridLayout(1, true)); + searchTxt = new Text(listComp, SWT.BORDER); + searchTxt.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + searchTxt.setToolTipText("Search Key/Value"); + searchTxt.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + String searchText = searchTxt.getText(); + if (StringUtil.isEmpty(searchText)) { + viewer.setInput(configList); + } else { + searchText = searchText.toLowerCase(); + List tempList = new ArrayList(); + for (ConfObject data : configList) { + String name = data.key.toLowerCase(); + String value = data.value.toLowerCase(); + if (name.contains(searchText) || value.contains(searchText)) { + tempList.add(data); + } + } + viewer.setInput(tempList); + } + } + }); + Composite tableComp = new Composite(listComp, SWT.NONE); + tableComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + tableColumnLayout = new TableColumnLayout(); + tableComp.setLayout(tableColumnLayout); + viewer = new TableViewer(tableComp, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL); + createColumns(); + table = viewer.getTable(); + table.setHeaderVisible(true); + table.setLinesVisible(true); + viewer.setContentProvider(new ArrayContentProvider()); + viewer.setComparator(new ColumnLabelSorter(viewer)); + table.addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent e) { + if(e.stateMask == SWT.CTRL || e.stateMask == SWT.COMMAND){ + if (e.keyCode == 'c' || e.keyCode == 'C') { + TableItem[] items = table.getSelection(); + if (items == null || items.length < 1) { + return; + } + StringBuffer sb = new StringBuffer(); + for (TableItem item : items) { + sb.append(item.getText(0)); + sb.append("="); + sb.append(item.getText(1)); + sb.append("\n"); + } + clipboard.setContents(new Object[] {sb.toString()}, new Transfer[] {TextTransfer.getInstance()}); + } + } + } + }); + + sashForm.setWeights(new int[] {1, 1}); + sashForm.setMaximizedControl(null); + initialToolBar(); + } + + public void setInput(int serverId){ + this.serverId = serverId; + Server server = ServerManager.getInstance().getServer(serverId); + if (server != null) { + setPartName("Config Server[" + server.getName() + "]"); + loadConfig(RequestCmd.GET_CONFIGURE_SERVER, null); + loadConfigList(RequestCmd.LIST_CONFIGURE_SERVER, null); + } + } + + public void setInput(int serverId, int objHash){ + this.serverId = serverId; + this.objHash = objHash; + Server server = ServerManager.getInstance().getServer(serverId); + if (server != null) { + setPartName("Config Agent[" + TextProxy.object.getText(objHash) + "]"); + MapPack param = new MapPack(); + param.put("objHash", objHash); + loadConfig(RequestCmd.GET_CONFIGURE_WAS, param); + loadConfigList(RequestCmd.LIST_CONFIGURE_WAS, param); + } + } + + private void initialStyledText(Composite parent) { + text = new StyledText(parent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); + listener = new CustomLineStyleListener(true, defaultHighlightings, false); + text.addLineStyleListener(listener); + text.addKeyListener(new KeyListener() { + public void keyReleased(KeyEvent e) { + } + public void keyPressed(KeyEvent e) { + if(e.stateMask == SWT.CTRL || e.stateMask == SWT.COMMAND){ + if(e.keyCode == 's' || e.keyCode == 'S'){ + saveConfigurations(); + }else if(e.keyCode == 'a' || e.keyCode == 'A'){ + text.selectAll(); + } + } + } + }); + } + + private void saveConfigurations(){ + TcpProxy tcp = TcpProxy.getTcpProxy(serverId); + try { + MapPack param = new MapPack(); + param.put("setConfig", text.getText()); + MapPack out = null; + if (objHash == 0) { + out = (MapPack) tcp.getSingle(RequestCmd.SET_CONFIGURE_SERVER, param); + } else { + param.put("objHash", objHash); + out = (MapPack) tcp.getSingle(RequestCmd.SET_CONFIGURE_WAS, param); + } + + if (out != null) { + String config = out.getText("result"); + if("true".equalsIgnoreCase(config)) { + MessageDialog.open(MessageDialog.INFORMATION + , PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() + , "Success" + , "Configuration saving is done." + , SWT.NONE); + if (objHash == 0) { + loadConfigList(RequestCmd.LIST_CONFIGURE_SERVER, null); + } else { + MapPack param2 = new MapPack(); + param2.put("objHash", objHash); + loadConfigList(RequestCmd.LIST_CONFIGURE_WAS, param2); + } + } else { + MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() + ,"Error" + , "Configuration saving is failed."); + } + } + } catch(Exception e){ + ConsoleProxy.errorSafe(e.toString()); + } finally { + TcpProxy.putTcpProxy(tcp); + } + } + + private void initialToolBar() { + IToolBarManager man = getViewSite().getActionBars().getToolBarManager(); + man.add(new Action("Save", ImageUtil.getImageDescriptor(Images.save)) { + public void run() { + saveConfigurations(); + } + }); + } + + private void loadConfig(final String requestCmd, final MapPack param) { + ExUtil.asyncRun(new Runnable() { + public void run() { + MapPack mpack = null; + TcpProxy tcp = TcpProxy.getTcpProxy(serverId); + try { + mpack = (MapPack) tcp.getSingle(requestCmd, param); + } finally { + TcpProxy.putTcpProxy(tcp); + } + if (mpack != null) { + ListValue configKey = mpack.getList("configKey"); + + defaultHighlightings = new ArrayList(); + for(int inx = 0 ; configKey != null && inx < configKey.size(); inx++){ + defaultHighlightings.add(new ColoringWord(configKey.getString(inx), SWT.COLOR_BLUE, true)); + } + defaultHighlightings.add(new ColoringWord(";", SWT.COLOR_RED, true)); + + if (objHash == 0) { + content = mpack.getText("serverConfig"); + } else { + content = mpack.getText("agentConfig"); + } + } + ExUtil.exec(text, new Runnable() { + public void run() { + listener.setKeywordArray(defaultHighlightings); + text.setText(content); + } + }); + } + }); + } + + ArrayList configList = new ArrayList(); + + private void loadConfigList(final String requestCmd, final MapPack param) { + ExUtil.asyncRun(new Runnable() { + public void run() { + MapPack pack = null; + TcpProxy tcp = TcpProxy.getTcpProxy(serverId); + try { + pack = (MapPack) tcp.getSingle(requestCmd, param); + } catch (Exception e) { + e.printStackTrace(); + } finally { + TcpProxy.putTcpProxy(tcp); + } + if (pack != null) { + final ListValue keyList = pack.getList("key"); + final ListValue valueList = pack.getList("value"); + final ListValue defaultList = pack.getList("default"); + configList.clear(); + for (int i = 0; i < keyList.size(); i++) { + ConfObject obj = new ConfObject(); + String key = CastUtil.cString(keyList.get(i)); + String value = CastUtil.cString(valueList.get(i)); + String def = CastUtil.cString(defaultList.get(i)); + obj.key = key == null ? "" : key; + obj.value = value == null ? "" : value; + obj.def = def == null ? "" : def; + configList.add(obj); + } + ExUtil.exec(listComp, new Runnable() { + public void run() { + searchTxt.notifyListeners(SWT.Modify, new Event()); + } + }); + } + } + }); + } + + public void setFocus() { + IStatusLineManager slManager= getViewSite().getActionBars().getStatusLineManager(); + slManager.setMessage("CTRL + S : save configurations, CTRL + A : select all text"); + } + + private void createColumns() { + for (ConfEnum column : ConfEnum.values()) { + TableViewerColumn c = createTableViewerColumn(column.getTitle(), column.getWidth(), column.getAlignment(), column.isNumber()); + ColumnLabelProvider labelProvider = null; + switch (column) { + case KEY: + labelProvider = new ColumnLabelProvider() { + public String getText(Object element) { + if (element instanceof ConfObject) { + return ((ConfObject) element).key; + } + return null; + } + }; + break; + case VALUE: + labelProvider = new ColumnLabelProvider() { + public String getText(Object element) { + if (element instanceof ConfObject) { + return ((ConfObject) element).value; + } + return null; + } + }; + break; + case DEFAULT: + labelProvider = new ColumnLabelProvider() { + public String getText(Object element) { + if (element instanceof ConfObject) { + return ((ConfObject) element).def; + } + return null; + } + }; + break; + } + if (labelProvider != null) { + c.setLabelProvider(labelProvider); + } + } + } + + private TableViewerColumn createTableViewerColumn(String title, int width, int alignment, final boolean isNumber) { + final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE); + final TableColumn column = viewerColumn.getColumn(); + column.setText(title); + column.setAlignment(alignment); + tableColumnLayout.setColumnData(column, new ColumnWeightData(30, width, true)); + column.setData("isNumber", isNumber); + column.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + ColumnLabelSorter sorter = (ColumnLabelSorter) viewer.getComparator(); + TableColumn selectedColumn = (TableColumn) e.widget; + sorter.setColumn(selectedColumn); + } + }); + return viewerColumn; + } + +} diff --git a/scouter.client/src/scouter/client/model/AgentModelThread.java b/scouter.client/src/scouter/client/model/AgentModelThread.java index 89fc9c71f..181a97562 100644 --- a/scouter.client/src/scouter/client/model/AgentModelThread.java +++ b/scouter.client/src/scouter/client/model/AgentModelThread.java @@ -97,6 +97,12 @@ public void process(DataInputX in) throws IOException { TextProxy.object.putText(objHash, objName); } AgentObject agentObject = new AgentObject(objType, objHash, objName, serverId); + if (tempAgentMap.containsKey(objHash)) { + AgentObject oldAgent = tempAgentMap.get(objHash); + if (oldAgent.isAlive()) { + continue; + } + } tempAgentMap.put(objHash, agentObject); agentObject.objPack = m; if (counterEngine.isUnknownObjectType(objType)) { diff --git a/scouter.client/src/scouter/client/popup/AddServerAddressDialog.java b/scouter.client/src/scouter/client/popup/AddServerAddressDialog.java index 8fc9623e7..6d6c19f48 100644 --- a/scouter.client/src/scouter/client/popup/AddServerAddressDialog.java +++ b/scouter.client/src/scouter/client/popup/AddServerAddressDialog.java @@ -33,6 +33,7 @@ import org.eclipse.swt.widgets.ToolTip; import scouter.client.util.UIUtil; +import scouter.net.NetConstants; import scouter.util.StringUtil; public class AddServerAddressDialog { @@ -80,7 +81,7 @@ private Shell setDialogLayout() { newAddressLbl.setLayoutData(UIUtil.formData(0, 5, 0, 5, null, -1, null, -1)); final ToolTip formatTip = new ToolTip(dialog, SWT.BALLOON); - formatTip.setMessage("IP:Port ex) 127.0.0.1:6200"); + formatTip.setMessage("IP:Port ex) 127.0.0.1:" + NetConstants.SERVER_TCP_PORT); final ToolTip existTip = new ToolTip(dialog, SWT.BALLOON); existTip.setMessage("Server Address is already exist!"); diff --git a/scouter.client/src/scouter/client/util/MenuUtil.java b/scouter.client/src/scouter/client/util/MenuUtil.java index e9ce54bd9..0beee1392 100644 --- a/scouter.client/src/scouter/client/util/MenuUtil.java +++ b/scouter.client/src/scouter/client/util/MenuUtil.java @@ -43,10 +43,10 @@ import scouter.client.actions.OpenServiceGroupAction; import scouter.client.actions.SetColorAction; import scouter.client.configuration.actions.DefineObjectTypeAction; +import scouter.client.configuration.actions.OpenAgentConfigureAction; import scouter.client.constants.MenuStr; import scouter.client.context.actions.OpenAPIDebugViewAction; import scouter.client.context.actions.OpenCxtmenuActiveServiceListAction; -import scouter.client.context.actions.OpenCxtmenuConfigureAgentViewAction; import scouter.client.context.actions.OpenCxtmenuDumpActiveServiceListAction; import scouter.client.context.actions.OpenCxtmenuDumpFileListAction; import scouter.client.context.actions.OpenCxtmenuDumpHeapHistoAction; @@ -431,7 +431,7 @@ public static void addObjectContextMenu(IMenuManager mgr, IWorkbenchWindow win, if (server.isAllowAction(GroupPolicyConstants.ALLOW_CONFIGURE)) { mgr.add(new Separator()); - mgr.add(new OpenCxtmenuConfigureAgentViewAction(win, MenuStr.CONFIGURE, objHash, serverId)); + mgr.add(new OpenAgentConfigureAction(win, MenuStr.CONFIGURE, objHash, serverId)); } } else if (counterEngine.isChildOf(objType, CounterConstants.FAMILY_HOST)) { performanceSnapshot.add(new OpenCxtmenuEnvAction(win, MenuStr.ENV, objHash, serverId)); @@ -440,7 +440,7 @@ public static void addObjectContextMenu(IMenuManager mgr, IWorkbenchWindow win, mgr.add(new Separator()); if (server.isAllowAction(GroupPolicyConstants.ALLOW_CONFIGURE)) - mgr.add(new OpenCxtmenuConfigureAgentViewAction(win, MenuStr.CONFIGURE, objHash, serverId)); + mgr.add(new OpenAgentConfigureAction(win, MenuStr.CONFIGURE, objHash, serverId)); } } if (server.isAllowAction(GroupPolicyConstants.ALLOW_DEFINEOBJTYPE)) { diff --git a/scouter.client/src/scouter/client/xlog/views/XLogViewMouse.java b/scouter.client/src/scouter/client/xlog/views/XLogViewMouse.java index 3777ef77b..3290c6c66 100644 --- a/scouter.client/src/scouter/client/xlog/views/XLogViewMouse.java +++ b/scouter.client/src/scouter/client/xlog/views/XLogViewMouse.java @@ -169,7 +169,6 @@ public void listSelectedXLog(final Display display, int x1, int y1, int x2, int public void zoominArea(final Display display, final int x1, final int y1, final int x2, final int y2) { ExUtil.asyncRun(new Runnable() { public void run() { - int txCnt = 0; final LongKeyLinkedMap zoomData = new LongKeyLinkedMap(); LongEnumer enumer = data.keys(); double max = 0; @@ -179,7 +178,6 @@ public void run() { XLogData item = data.get(key); if (inRect(x1, y1, x2, y2, item.x, item.y) && (item.filter_ok)) { - txCnt++; switch(viewPainter.yAxisMode) { case ELAPSED: if (item.p.elapsed / 1000d > max) { @@ -249,11 +247,7 @@ public void run() { zoomData.put(key, new XLogData(item.p, item.serverId)); } } - if (txCnt < 1) { - ConsoleProxy.info("[XLog] no xlogs in selected area."); - return; - } - ConsoleProxy.info("[XLog] "+txCnt + " selected."); + if (zoomData.isEmpty()) return; final long stime = zoomData.getFirstValue().p.endTime - 500; final long etime = zoomData.getLastValue().p.endTime + 500; final double yMax = max * 1.01; @@ -262,6 +256,7 @@ public void run() { ExUtil.exec(display, new Runnable() { public void run() { try { + ConsoleProxy.info("[XLog] "+ zoomData.size() + " selected."); IWorkbenchWindow win = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); XLogZoomTimeView view = (XLogZoomTimeView) win.getActivePage().showView(XLogZoomTimeView.ID,// objType+stime+etime+yMax+yMin, IWorkbenchPage.VIEW_ACTIVATE); diff --git a/scouter.common/src/scouter/lang/counters/counters.xml b/scouter.common/src/scouter/lang/counters/counters.xml index 67398bdaf..376155718 100644 --- a/scouter.common/src/scouter/lang/counters/counters.xml +++ b/scouter.common/src/scouter/lang/counters/counters.xml @@ -50,7 +50,6 @@ mrhit : MariaDB HitRatio - diff --git a/scouter.common/src/scouter/util/StringUtil.java b/scouter.common/src/scouter/util/StringUtil.java index f22064b09..f74add917 100644 --- a/scouter.common/src/scouter/util/StringUtil.java +++ b/scouter.common/src/scouter/util/StringUtil.java @@ -44,7 +44,7 @@ public static String lastWord(String target, String delim) { String value = ""; StringTokenizer nizer = new StringTokenizer(target, delim); while (nizer.hasMoreTokens()) { - value = trimEmpty(nizer.nextToken()); + value = trimEmpty(nizer.nextToken()); } return value; } @@ -216,12 +216,6 @@ public static String leftPad(String str, int size) { return sb.toString(); } - public static void main(String[] args) { - String s = "aaa = bbb ccc"; - String[] ss = divKeyValue(s, "="); - System.out.println(ArrayUtil.toString(ss)); - } - public static String cutLastString(String className, char delim) { int x = className.lastIndexOf(delim); if (x > 0) @@ -312,4 +306,14 @@ public static String padding(int len, char ch) { return sb.toString(); } + public static int getWordCount(String text, String word) { + int n = 0; + int x = text.indexOf(word); + while (x >= 0) { + n++; + x = text.indexOf(word, x + word.length()); + } + return n; + } + } diff --git a/scouter.deploy/build.xml b/scouter.deploy/build.xml index 62b64d422..c6400cb28 100644 --- a/scouter.deploy/build.xml +++ b/scouter.deploy/build.xml @@ -4,7 +4,7 @@ - + diff --git a/scouter.server/src/scouter/server/core/app/XLogGroupUtil.scala b/scouter.server/src/scouter/server/core/app/XLogGroupUtil.scala index 81f9e13d0..af8444b14 100644 --- a/scouter.server/src/scouter/server/core/app/XLogGroupUtil.scala +++ b/scouter.server/src/scouter/server/core/app/XLogGroupUtil.scala @@ -47,7 +47,7 @@ object XLogGroupUtil { if (groupHash == 0 || groupHash == 0) { val url = TextRD.getString(DateUtil.yyyymmdd(endtime), TextTypes.SERVICE, service); groupHash = getGroupHash(url); - if (url != null) { + if (groupHash!=0) { groupMap.put(service, groupHash); } } @@ -69,7 +69,6 @@ object XLogGroupUtil { statics.add("xml"); statics.add("js"); - add(HashUtil.hash("unknown"), "unknown"); add(HashUtil.hash("*.jsp"), "*.jsp"); add(HashUtil.hash("**"), "**"); add(HashUtil.hash("images"), "images"); @@ -82,7 +81,6 @@ object XLogGroupUtil { private val saved = new IntSet(); - private val h0 = HashUtil.hash("unknown"); private val h2 = HashUtil.hash("*.jsp"); private val h3 = HashUtil.hash("images"); private val h4 = HashUtil.hash("statics"); @@ -91,7 +89,7 @@ object XLogGroupUtil { def getGroupHash(url: String): Int = { if (url == null) - return h0; + return 0; val x = url.lastIndexOf('.'); if (x > 0) {