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] |
| 14 | [--slave] |
| 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" |
| 57 | "ds" is "com.google.gerrit.server.schema.DataSourceProvider@6b3592c" |
| 58 | "schk" is "com.google.gerrit.server.schema.SchemaVersionCheck@5e8cb9bd" |
| 59 | |
| 60 | Welcome to the Gerrit Inspector |
| 61 | Enter help() to see the above again, EOF to quit and stop Gerrit |
| 62 | ---- |
| 63 | |
| 64 | Then an optional user startup script is processed. It should be |
| 65 | located in the gerrit user home directory as '.gerritcodereview/Startup.py'. |
| 66 | |
| 67 | This script can access all variables defined in the system (such |
| 68 | as the ones displayed by the initialization script as shown above). |
| 69 | Variables and functions defined by the startup scripts are available for |
| 70 | the interactive interpreter. |
| 71 | |
| 72 | When interactive interpreter exits (by issuing EOF on the command line), |
| 73 | a whole Gerrit instance is shut down gracefully. |
| 74 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 75 | == USING THE INTERPRETER |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 76 | |
| 77 | Gerrit Inspector launches Jython interpreter in the context of the Gerrit |
| 78 | Java Virtual Machine. All core facilities of the Jython (and Python) |
| 79 | language are available to the user. |
| 80 | |
| 81 | Additional facilities can be provided, for example a 'Lib' directory from the |
| 82 | Jython distribution can be installed under '$site_path/lib/Lib' to provide |
| 83 | access to many standard Python modules. Jython can also use additional Java |
| 84 | classes and libraries and most of the Python modules and scripts. |
| 85 | |
| 86 | The Inspector has by default access to classes and object instances available |
| 87 | in the Java Virtual Machine. Objects are introspected and *private* and *protected* |
| 88 | members are also available. |
| 89 | |
| 90 | For more information on using Jython, especially with regards to its limitations |
| 91 | in interfacing to the Java Virtual Machine, please refer to the |
| 92 | http://www.jython.org/[Jython documentation]. |
| 93 | |
David Pursehouse | 659860f | 2013-12-16 14:50:04 +0900 | [diff] [blame] | 94 | After successful initialization it is possible to examine components of |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 95 | Java packages, classes and live instances. |
| 96 | |
| 97 | ---- |
| 98 | >>> import com.google.inject |
| 99 | >>> dir(com.google.inject) |
| 100 | ['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'] |
| 101 | >>> type(com.google.inject) |
| 102 | <type 'javapackage'> |
| 103 | >>> dir(com.google.inject.Guice) |
| 104 | ['__class__', '__copy__', '__deepcopy__', '__delattr__', '__doc__', |
| 105 | '__eq__', '__getattribute__', '__hash__', '__init__', '__ne__', |
| 106 | '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', |
| 107 | '__str__', '__unicode__', 'class', 'clone', 'createInjector', |
| 108 | 'equals', 'finalize', 'getClass', 'hashCode', 'notify', 'notifyAll', |
| 109 | 'registerNatives', 'toString', 'wait'] |
| 110 | ---- |
| 111 | |
| 112 | Startup script provides some convenient variables to access some global Gerrit components, |
| 113 | for example a connection to the review database is kept open: |
| 114 | |
| 115 | ---- |
| 116 | >>> ds |
| 117 | org.apache.commons.dbcp.BasicDataSource@61db2215 |
| 118 | >>> ds.driverClassName |
| 119 | u'org.postgresql.Driver' |
| 120 | >>> ds.dataSource |
| 121 | org.apache.commons.dbcp.PoolingDataSource@23226fe1 |
| 122 | >>> ds.dataSource.connection |
| 123 | jdbc:postgresql://localhost/reviewdb, UserName=rv, PostgreSQL Native Driver |
| 124 | ---- |
| 125 | |
| 126 | It is also possible to interact with the ORM layer: |
| 127 | |
| 128 | ---- |
| 129 | >>> db = schk.schema.open() |
| 130 | >>> db |
| 131 | com.google.gerrit.reviewdb.server.ReviewDb_Schema_GwtOrm$$28@24cbbdf3 |
| 132 | >>> db.getDialect() |
| 133 | com.google.gwtorm.schema.sql.DialectPostgreSQL@4de07d3e |
| 134 | >>> for x in db.patchSets().iterateAllEntities(): |
| 135 | ... print x |
| 136 | ... |
| 137 | [PatchSet 1,1] |
| 138 | [PatchSet 2,1] |
| 139 | [PatchSet 3,1] |
| 140 | [PatchSet 4,1] |
| 141 | [PatchSet 5,1] |
| 142 | [PatchSet 6,1] |
| 143 | [PatchSet 7,1] |
| 144 | [PatchSet 8,1] |
| 145 | [PatchSet 6,2] |
| 146 | >>> for x in db.patchComments().iterateAllEntities(): |
| 147 | ... print x |
| 148 | com.google.gerrit.reviewdb.client.PatchLineComment@5381298a |
| 149 | com.google.gerrit.reviewdb.client.PatchLineComment@44ce4dda |
| 150 | com.google.gerrit.reviewdb.client.PatchLineComment@44594680 |
| 151 | >>> dir(com.google.gerrit.reviewdb.client.PatchLineComment) |
| 152 | ['Key', 'STATUS_DRAFT', 'STATUS_PUBLISHED', 'Status', '__class__', |
| 153 | '__copy__', '__deepcopy__', '__delattr__', '__doc__', '__eq__', |
| 154 | '__getattribute__', '__hash__', '__init__', '__ne__', '__new__', |
| 155 | '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', |
| 156 | '__unicode__', 'author', 'class', 'clone', 'equals', 'finalize', |
| 157 | 'getAuthor', 'getClass', 'getKey', 'getLine', 'getMessage', |
| 158 | 'getParentUuid', 'getSide', 'getStatus', 'getWrittenOn', 'hashCode', |
| 159 | 'key', 'line', 'lineNbr', 'message', 'notify', 'notifyAll', |
| 160 | 'parentUuid', 'registerNatives', 'setMessage', 'setSide', 'setStatus', |
| 161 | 'side', 'status', 'toString', 'updated', 'wait', 'writtenOn'] |
| 162 | >>> for x in db.patchComments().iterateAllEntities(): |
| 163 | ... print x.status, x.line, x.message |
| 164 | ... |
| 165 | P 2 I like it! |
| 166 | P 2 more |
| 167 | P 1 better |
| 168 | ---- |
| 169 | |
| 170 | A built-in *help()* function provides values of global variables |
| 171 | defined in the interpreter: |
| 172 | |
| 173 | ---- |
| 174 | >>> help() |
| 175 | "schk" is "com.google.gerrit.server.schema.SchemaVersionCheck@5e8cb9bd" |
| 176 | "ds" is "com.google.gerrit.server.schema.DataSourceProvider@6b3592c" |
| 177 | "m" is "com.google.gerrit.lifecycle.LifecycleManager@6f03b248" |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 178 | "Shell" is "com.google.gerrit.pgm.shell.JythonShell@61644f2d" |
David Ostrovsky | 947a80f | 2013-11-06 22:13:11 +0100 | [diff] [blame] | 179 | "d" is "com.google.gerrit.pgm.Daemon@28a3f689" |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 180 | |
| 181 | Welcome to the Gerrit Inspector |
| 182 | Enter help() to see the above again, EOF to quit and stop Gerrit |
| 183 | ---- |
| 184 | |
| 185 | Java and Python exceptions are intercepted by the Inspector: |
| 186 | ---- |
| 187 | >>> import java.lang.RuntimeException |
| 188 | >>> raise java.lang.RuntimeException("Exiting") |
| 189 | Traceback (most recent call last): |
| 190 | File "<stdin>", line 1, in <module> |
| 191 | at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) |
| 192 | at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) |
| 193 | at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) |
| 194 | at java.lang.reflect.Constructor.newInstance(Constructor.java:532) |
| 195 | at org.python.core.PyReflectedConstructor.constructProxy(PyReflectedConstructor.java:210) |
| 196 | |
| 197 | java.lang.RuntimeException: java.lang.RuntimeException: Exiting |
| 198 | >>> |
| 199 | ---- |
| 200 | |
| 201 | To exit the interpreter, use EOF character (Ctrl-D on Unix systems, Ctrl-Z on Windows). |
| 202 | |
| 203 | It is also possible to shut down the JVM by using *System.exit()* |
| 204 | |
| 205 | ---- |
| 206 | >>> import java.lang.System |
| 207 | >>> java.lang.System.exit(1) |
| 208 | ---- |
| 209 | |
| 210 | And Gerrit should shut down all its subsystems and exit: |
| 211 | |
| 212 | ---- |
| 213 | [2012-04-17 15:31:08,458] INFO com.google.gerrit.pgm.Daemon : caught shutdown, cleaning up |
| 214 | ---- |
| 215 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 216 | == TROUBLESHOOTING |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 217 | |
| 218 | Gerrit Inspector is logging to the Gerrit error log. |
| 219 | |
| 220 | A successful startup is indicated in the logfile: |
| 221 | |
| 222 | ---- |
| 223 | [2012-04-17 13:43:44,888] INFO com.google.gerrit.pgm.shell.JythonShell : Jython shell instance created. |
| 224 | ---- |
| 225 | |
| 226 | If 'jython.jar' library is not available, Gerrit refuses to start when given *-s* option: |
| 227 | |
| 228 | ---- |
| 229 | [2012-04-17 13:57:29,611] ERROR com.google.gerrit.pgm.Daemon : Unable to start daemon |
| 230 | com.google.inject.ProvisionException: Guice provision errors: |
| 231 | |
| 232 | 1) Error injecting constructor, java.lang.UnsupportedOperationException: Cannot create Jython shell: Class org.python.util.InteractiveConsole not found |
| 233 | (You might need to install jython.jar in the lib directory) |
| 234 | at com.google.gerrit.pgm.shell.JythonShell.<init>(JythonShell.java:47) |
| 235 | while locating com.google.gerrit.pgm.shell.JythonShell |
| 236 | while locating com.google.gerrit.pgm.shell.InteractiveShell |
| 237 | ---- |
| 238 | |
| 239 | Errors during processing of the startup script, 'Startup.py', are logged |
| 240 | to the error log: |
| 241 | |
| 242 | ---- |
| 243 | [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] | 244 | [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] | 245 | java.lang.reflect.InvocationTargetException |
| 246 | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) |
| 247 | at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) |
| 248 | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) |
| 249 | at java.lang.reflect.Method.invoke(Method.java:616) |
| 250 | at com.google.gerrit.pgm.shell.JythonShell.runMethod0(JythonShell.java:112) |
| 251 | at com.google.gerrit.pgm.shell.JythonShell.execFile(JythonShell.java:194) |
| 252 | at com.google.gerrit.pgm.shell.JythonShell.reload(JythonShell.java:178) |
| 253 | at com.google.gerrit.pgm.shell.JythonShell.run(JythonShell.java:152) |
| 254 | at com.google.gerrit.pgm.Daemon.run(Daemon.java:190) |
| 255 | at com.google.gerrit.pgm.util.AbstractProgram.main(AbstractProgram.java:67) |
| 256 | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) |
| 257 | at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) |
| 258 | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) |
| 259 | at java.lang.reflect.Method.invoke(Method.java:616) |
| 260 | at com.google.gerrit.launcher.GerritLauncher.invokeProgram(GerritLauncher.java:167) |
| 261 | at com.google.gerrit.launcher.GerritLauncher.mainImpl(GerritLauncher.java:91) |
| 262 | at com.google.gerrit.launcher.GerritLauncher.main(GerritLauncher.java:49) |
| 263 | at Main.main(Main.java:25) |
| 264 | Caused by: Traceback (most recent call last): |
| 265 | File "/home/user/.gerritcodereview/Startup.py", line 1, in <module> |
| 266 | Test |
| 267 | NameError: name 'Test' is not defined |
| 268 | ---- |
| 269 | |
| 270 | Those errors are non-fatal. System and user scripts can be loaded again |
| 271 | by issuing the following command in the Gerrit Inspector console: |
| 272 | |
| 273 | ---- |
| 274 | Shell.reload() |
| 275 | ---- |
| 276 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 277 | == LOGGING |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 278 | Error and warning messages from the server are automatically written |
| 279 | to the log file under '$site_path/logs/error_log'. |
| 280 | |
| 281 | Output and error messages (including Java and Python exceptions) |
| 282 | resulting from interactive work are logged to the console. |
| 283 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 284 | == KNOWN ISSUES |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 285 | The Inspector does not yet recognize Google Guice bindings. |
| 286 | |
Michael Ochmann | 8129ece | 2016-07-08 11:25:25 +0200 | [diff] [blame] | 287 | [IMPORTANT] |
| 288 | Using the Inspector may void your warranty. |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 289 | |
| 290 | GERRIT |
| 291 | ------ |
| 292 | Part of link:index.html[Gerrit Code Review] |
Yuxuan 'fishy' Wang | 99cb68d | 2013-10-31 17:26:00 -0700 | [diff] [blame] | 293 | |
| 294 | SEARCHBOX |
| 295 | --------- |