Marian Harbach | ebeb154 | 2019-12-13 10:42:46 +0100 | [diff] [blame] | 1 | :linkattrs: |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 2 | = Gerrit Inspector |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 3 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 4 | == NAME |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 5 | Gerrit Inspector - Interactive Jython environment for Gerrit |
| 6 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 7 | == SYNOPSIS |
Michael Ochmann | a843461 | 2016-07-08 10:58:27 +0200 | [diff] [blame] | 8 | [verse] |
Yuxuan 'fishy' Wang | d85b687 | 2013-11-15 11:47:46 -0800 | [diff] [blame] | 9 | -- |
Michael Ochmann | a843461 | 2016-07-08 10:58:27 +0200 | [diff] [blame] | 10 | _java_ -jar gerrit.war _daemon_ |
| 11 | -d <SITE_PATH> |
| 12 | [--enable-httpd | --disable-httpd] |
| 13 | [--enable-sshd | --disable-sshd] |
| 14 | [--console-log] |
Han-Wen Nienhuys | 348a603 | 2019-09-24 19:44:57 +0200 | [diff] [blame] | 15 | [--replica] |
Michael Ochmann | a843461 | 2016-07-08 10:58:27 +0200 | [diff] [blame] | 16 | -s |
Yuxuan 'fishy' Wang | d85b687 | 2013-11-15 11:47:46 -0800 | [diff] [blame] | 17 | -- |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 18 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 19 | == DESCRIPTION |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 20 | Runs the Gerrit network daemon on the local system as described |
| 21 | in the link:pgm-daemon.html[Daemon documentation], additionally |
| 22 | starting an interactive Jython shell for inspection |
| 23 | and troubleshooting of live data of the Gerrit instance. |
| 24 | |
| 25 | CAUTION: Gerrit Inspector works directly on instances of Java Virtual |
| 26 | Machine objects and it is possible to read and write instance |
| 27 | members as well as invoke Java functions. Access is granted |
| 28 | also to 'private' and 'protected' members. Therefore it is possible |
| 29 | to introduce changes to the internal state of the system in |
| 30 | an inconsistent way. Care must be taken not to break the running system |
| 31 | and/or destroy the data. |
| 32 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 33 | == INSTALLATION |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 34 | |
| 35 | Gerrit Inspector requires Jython library ('jython.jar') to be installed |
| 36 | in the '$site_path/lib' directory. Jython, a Python interpreter for |
Marian Harbach | 3425337 | 2019-12-10 18:01:31 +0100 | [diff] [blame] | 37 | the Java Virtual Machine, can be obtained from the http://www.jython.org/[role=external,window=_blank] |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 38 | website. Only 'jython.jar' file is needed, installation of Jython libraries |
| 39 | is optional. Gerrit Inspector has been tested with Jython 2.5.2 but |
| 40 | might work an earlier version. |
| 41 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 42 | == STARTUP |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 43 | |
| 44 | During startup Jython examines Java libraries found on the classpath. |
| 45 | While libraries are inspected a large amount of messages is displayed on the console: |
| 46 | |
| 47 | ---- |
| 48 | *sys-package-mgr*: processing new jar, '/home/user/.gerritcodereview/tmp/gerrit_4890671371398741854_app/sshd-core-0.5.1-r1095809.jar' |
| 49 | ---- |
| 50 | |
| 51 | After this a system-wide embedded initialization script is started. This script |
| 52 | is contained in the gerrit's WAR archive. This script produces output similar to |
| 53 | the following on the console: |
| 54 | |
| 55 | ---- |
| 56 | "Shell" is "com.google.gerrit.pgm.shell.JythonShell@61644f2d" |
| 57 | "m" is "com.google.gerrit.lifecycle.LifecycleManager@6f03b248" |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 58 | |
| 59 | Welcome to the Gerrit Inspector |
| 60 | Enter help() to see the above again, EOF to quit and stop Gerrit |
| 61 | ---- |
| 62 | |
| 63 | Then an optional user startup script is processed. It should be |
| 64 | located in the gerrit user home directory as '.gerritcodereview/Startup.py'. |
| 65 | |
| 66 | This script can access all variables defined in the system (such |
| 67 | as the ones displayed by the initialization script as shown above). |
| 68 | Variables and functions defined by the startup scripts are available for |
| 69 | the interactive interpreter. |
| 70 | |
| 71 | When interactive interpreter exits (by issuing EOF on the command line), |
| 72 | a whole Gerrit instance is shut down gracefully. |
| 73 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 74 | == USING THE INTERPRETER |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 75 | |
| 76 | Gerrit Inspector launches Jython interpreter in the context of the Gerrit |
| 77 | Java Virtual Machine. All core facilities of the Jython (and Python) |
| 78 | language are available to the user. |
| 79 | |
| 80 | Additional facilities can be provided, for example a 'Lib' directory from the |
| 81 | Jython distribution can be installed under '$site_path/lib/Lib' to provide |
| 82 | access to many standard Python modules. Jython can also use additional Java |
| 83 | classes and libraries and most of the Python modules and scripts. |
| 84 | |
| 85 | The Inspector has by default access to classes and object instances available |
| 86 | in the Java Virtual Machine. Objects are introspected and *private* and *protected* |
| 87 | members are also available. |
| 88 | |
| 89 | For more information on using Jython, especially with regards to its limitations |
| 90 | in interfacing to the Java Virtual Machine, please refer to the |
Marian Harbach | 3425337 | 2019-12-10 18:01:31 +0100 | [diff] [blame] | 91 | http://www.jython.org/[Jython documentation,role=external,window=_blank]. |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 92 | |
David Pursehouse | 659860f | 2013-12-16 14:50:04 +0900 | [diff] [blame] | 93 | After successful initialization it is possible to examine components of |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 94 | Java packages, classes and live instances. |
| 95 | |
| 96 | ---- |
| 97 | >>> import com.google.inject |
| 98 | >>> dir(com.google.inject) |
| 99 | ['AbstractModule', 'Binder', 'Binding', 'BindingAnnotation', 'ConfigurationException', 'CreationException', 'Exposed', 'Guice', 'ImplementedBy', 'Inject', 'Injector', 'Key', 'MembersInjector', 'Module', 'OutOfScopeException', 'PrivateBinder', 'PrivateModule', 'ProvidedBy', 'Provider', 'Provides', 'ProvisionException', 'Scope', 'ScopeAnnotation', 'Scopes', 'Singleton', 'Stage', 'TypeLiteral', '__name__', 'assistedinject', 'binder', 'internal', 'matcher', 'name', 'servlet', 'spi', 'util'] |
| 100 | >>> type(com.google.inject) |
| 101 | <type 'javapackage'> |
| 102 | >>> dir(com.google.inject.Guice) |
| 103 | ['__class__', '__copy__', '__deepcopy__', '__delattr__', '__doc__', |
| 104 | '__eq__', '__getattribute__', '__hash__', '__init__', '__ne__', |
| 105 | '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', |
| 106 | '__str__', '__unicode__', 'class', 'clone', 'createInjector', |
| 107 | 'equals', 'finalize', 'getClass', 'hashCode', 'notify', 'notifyAll', |
| 108 | 'registerNatives', 'toString', 'wait'] |
| 109 | ---- |
| 110 | |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 111 | A built-in *help()* function provides values of global variables |
| 112 | defined in the interpreter: |
| 113 | |
| 114 | ---- |
| 115 | >>> help() |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 116 | "m" is "com.google.gerrit.lifecycle.LifecycleManager@6f03b248" |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 117 | "Shell" is "com.google.gerrit.pgm.shell.JythonShell@61644f2d" |
David Ostrovsky | 947a80f | 2013-11-06 22:13:11 +0100 | [diff] [blame] | 118 | "d" is "com.google.gerrit.pgm.Daemon@28a3f689" |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 119 | |
| 120 | Welcome to the Gerrit Inspector |
| 121 | Enter help() to see the above again, EOF to quit and stop Gerrit |
| 122 | ---- |
| 123 | |
| 124 | Java and Python exceptions are intercepted by the Inspector: |
| 125 | ---- |
| 126 | >>> import java.lang.RuntimeException |
| 127 | >>> raise java.lang.RuntimeException("Exiting") |
| 128 | Traceback (most recent call last): |
| 129 | File "<stdin>", line 1, in <module> |
| 130 | at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) |
| 131 | at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) |
| 132 | at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) |
| 133 | at java.lang.reflect.Constructor.newInstance(Constructor.java:532) |
| 134 | at org.python.core.PyReflectedConstructor.constructProxy(PyReflectedConstructor.java:210) |
| 135 | |
| 136 | java.lang.RuntimeException: java.lang.RuntimeException: Exiting |
| 137 | >>> |
| 138 | ---- |
| 139 | |
| 140 | To exit the interpreter, use EOF character (Ctrl-D on Unix systems, Ctrl-Z on Windows). |
| 141 | |
| 142 | It is also possible to shut down the JVM by using *System.exit()* |
| 143 | |
| 144 | ---- |
| 145 | >>> import java.lang.System |
| 146 | >>> java.lang.System.exit(1) |
| 147 | ---- |
| 148 | |
| 149 | And Gerrit should shut down all its subsystems and exit: |
| 150 | |
| 151 | ---- |
| 152 | [2012-04-17 15:31:08,458] INFO com.google.gerrit.pgm.Daemon : caught shutdown, cleaning up |
| 153 | ---- |
| 154 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 155 | == TROUBLESHOOTING |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 156 | |
| 157 | Gerrit Inspector is logging to the Gerrit error log. |
| 158 | |
| 159 | A successful startup is indicated in the logfile: |
| 160 | |
| 161 | ---- |
| 162 | [2012-04-17 13:43:44,888] INFO com.google.gerrit.pgm.shell.JythonShell : Jython shell instance created. |
| 163 | ---- |
| 164 | |
| 165 | If 'jython.jar' library is not available, Gerrit refuses to start when given *-s* option: |
| 166 | |
| 167 | ---- |
| 168 | [2012-04-17 13:57:29,611] ERROR com.google.gerrit.pgm.Daemon : Unable to start daemon |
| 169 | com.google.inject.ProvisionException: Guice provision errors: |
| 170 | |
| 171 | 1) Error injecting constructor, java.lang.UnsupportedOperationException: Cannot create Jython shell: Class org.python.util.InteractiveConsole not found |
| 172 | (You might need to install jython.jar in the lib directory) |
| 173 | at com.google.gerrit.pgm.shell.JythonShell.<init>(JythonShell.java:47) |
| 174 | while locating com.google.gerrit.pgm.shell.JythonShell |
| 175 | while locating com.google.gerrit.pgm.shell.InteractiveShell |
| 176 | ---- |
| 177 | |
| 178 | Errors during processing of the startup script, 'Startup.py', are logged |
| 179 | to the error log: |
| 180 | |
| 181 | ---- |
| 182 | [2012-04-17 14:20:30,558] INFO com.google.gerrit.pgm.shell.JythonShell : Jython shell instance created. |
David Pursehouse | 1ff91c0 | 2015-05-19 15:05:26 +0900 | [diff] [blame] | 183 | [2012-04-17 14:20:38,005] ERROR com.google.gerrit.pgm.shell.JythonShell : Exception occurred while loading file Startup.py : |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 184 | java.lang.reflect.InvocationTargetException |
| 185 | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) |
| 186 | at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) |
| 187 | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) |
| 188 | at java.lang.reflect.Method.invoke(Method.java:616) |
| 189 | at com.google.gerrit.pgm.shell.JythonShell.runMethod0(JythonShell.java:112) |
| 190 | at com.google.gerrit.pgm.shell.JythonShell.execFile(JythonShell.java:194) |
| 191 | at com.google.gerrit.pgm.shell.JythonShell.reload(JythonShell.java:178) |
| 192 | at com.google.gerrit.pgm.shell.JythonShell.run(JythonShell.java:152) |
| 193 | at com.google.gerrit.pgm.Daemon.run(Daemon.java:190) |
| 194 | at com.google.gerrit.pgm.util.AbstractProgram.main(AbstractProgram.java:67) |
| 195 | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) |
| 196 | at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) |
| 197 | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) |
| 198 | at java.lang.reflect.Method.invoke(Method.java:616) |
| 199 | at com.google.gerrit.launcher.GerritLauncher.invokeProgram(GerritLauncher.java:167) |
| 200 | at com.google.gerrit.launcher.GerritLauncher.mainImpl(GerritLauncher.java:91) |
| 201 | at com.google.gerrit.launcher.GerritLauncher.main(GerritLauncher.java:49) |
| 202 | at Main.main(Main.java:25) |
| 203 | Caused by: Traceback (most recent call last): |
| 204 | File "/home/user/.gerritcodereview/Startup.py", line 1, in <module> |
| 205 | Test |
| 206 | NameError: name 'Test' is not defined |
| 207 | ---- |
| 208 | |
| 209 | Those errors are non-fatal. System and user scripts can be loaded again |
| 210 | by issuing the following command in the Gerrit Inspector console: |
| 211 | |
| 212 | ---- |
| 213 | Shell.reload() |
| 214 | ---- |
| 215 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 216 | == LOGGING |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 217 | Error and warning messages from the server are automatically written |
| 218 | to the log file under '$site_path/logs/error_log'. |
| 219 | |
| 220 | Output and error messages (including Java and Python exceptions) |
| 221 | resulting from interactive work are logged to the console. |
| 222 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 223 | == KNOWN ISSUES |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 224 | The Inspector does not yet recognize Google Guice bindings. |
| 225 | |
Michael Ochmann | 8129ece | 2016-07-08 11:25:25 +0200 | [diff] [blame] | 226 | [IMPORTANT] |
| 227 | Using the Inspector may void your warranty. |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 228 | |
| 229 | GERRIT |
| 230 | ------ |
| 231 | Part of link:index.html[Gerrit Code Review] |
Yuxuan 'fishy' Wang | 99cb68d | 2013-10-31 17:26:00 -0700 | [diff] [blame] | 232 | |
| 233 | SEARCHBOX |
| 234 | --------- |