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