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 |
Yuxuan 'fishy' Wang | d85b687 | 2013-11-15 11:47:46 -0800 | [diff] [blame] | 7 | -- |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 8 | 'java' -jar gerrit.war 'daemon' |
| 9 | -d <SITE_PATH> |
| 10 | [\--enable-httpd | \--disable-httpd] |
| 11 | [\--enable-sshd | \--disable-sshd] |
| 12 | [\--console-log] |
| 13 | [\--slave] |
| 14 | -s |
Yuxuan 'fishy' Wang | d85b687 | 2013-11-15 11:47:46 -0800 | [diff] [blame] | 15 | -- |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 16 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 17 | == DESCRIPTION |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 18 | Runs the Gerrit network daemon on the local system as described |
| 19 | in the link:pgm-daemon.html[Daemon documentation], additionally |
| 20 | starting an interactive Jython shell for inspection |
| 21 | and troubleshooting of live data of the Gerrit instance. |
| 22 | |
| 23 | CAUTION: Gerrit Inspector works directly on instances of Java Virtual |
| 24 | Machine objects and it is possible to read and write instance |
| 25 | members as well as invoke Java functions. Access is granted |
| 26 | also to 'private' and 'protected' members. Therefore it is possible |
| 27 | to introduce changes to the internal state of the system in |
| 28 | an inconsistent way. Care must be taken not to break the running system |
| 29 | and/or destroy the data. |
| 30 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 31 | == INSTALLATION |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 32 | |
| 33 | Gerrit Inspector requires Jython library ('jython.jar') to be installed |
| 34 | in the '$site_path/lib' directory. Jython, a Python interpreter for |
| 35 | the Java Virtual Machine, can be obtained from the http://www.jython.org/ |
| 36 | website. Only 'jython.jar' file is needed, installation of Jython libraries |
| 37 | is optional. Gerrit Inspector has been tested with Jython 2.5.2 but |
| 38 | might work an earlier version. |
| 39 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 40 | == STARTUP |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 41 | |
| 42 | During startup Jython examines Java libraries found on the classpath. |
| 43 | While libraries are inspected a large amount of messages is displayed on the console: |
| 44 | |
| 45 | ---- |
| 46 | *sys-package-mgr*: processing new jar, '/home/user/.gerritcodereview/tmp/gerrit_4890671371398741854_app/sshd-core-0.5.1-r1095809.jar' |
| 47 | ---- |
| 48 | |
| 49 | After this a system-wide embedded initialization script is started. This script |
| 50 | is contained in the gerrit's WAR archive. This script produces output similar to |
| 51 | the following on the console: |
| 52 | |
| 53 | ---- |
| 54 | "Shell" is "com.google.gerrit.pgm.shell.JythonShell@61644f2d" |
| 55 | "m" is "com.google.gerrit.lifecycle.LifecycleManager@6f03b248" |
| 56 | "ds" is "com.google.gerrit.server.schema.DataSourceProvider@6b3592c" |
| 57 | "schk" is "com.google.gerrit.server.schema.SchemaVersionCheck@5e8cb9bd" |
| 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 |
| 91 | http://www.jython.org/[Jython documentation]. |
| 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 | |
| 111 | Startup script provides some convenient variables to access some global Gerrit components, |
| 112 | for example a connection to the review database is kept open: |
| 113 | |
| 114 | ---- |
| 115 | >>> ds |
| 116 | org.apache.commons.dbcp.BasicDataSource@61db2215 |
| 117 | >>> ds.driverClassName |
| 118 | u'org.postgresql.Driver' |
| 119 | >>> ds.dataSource |
| 120 | org.apache.commons.dbcp.PoolingDataSource@23226fe1 |
| 121 | >>> ds.dataSource.connection |
| 122 | jdbc:postgresql://localhost/reviewdb, UserName=rv, PostgreSQL Native Driver |
| 123 | ---- |
| 124 | |
| 125 | It is also possible to interact with the ORM layer: |
| 126 | |
| 127 | ---- |
| 128 | >>> db = schk.schema.open() |
| 129 | >>> db |
| 130 | com.google.gerrit.reviewdb.server.ReviewDb_Schema_GwtOrm$$28@24cbbdf3 |
| 131 | >>> db.getDialect() |
| 132 | com.google.gwtorm.schema.sql.DialectPostgreSQL@4de07d3e |
| 133 | >>> for x in db.patchSets().iterateAllEntities(): |
| 134 | ... print x |
| 135 | ... |
| 136 | [PatchSet 1,1] |
| 137 | [PatchSet 2,1] |
| 138 | [PatchSet 3,1] |
| 139 | [PatchSet 4,1] |
| 140 | [PatchSet 5,1] |
| 141 | [PatchSet 6,1] |
| 142 | [PatchSet 7,1] |
| 143 | [PatchSet 8,1] |
| 144 | [PatchSet 6,2] |
| 145 | >>> for x in db.patchComments().iterateAllEntities(): |
| 146 | ... print x |
| 147 | com.google.gerrit.reviewdb.client.PatchLineComment@5381298a |
| 148 | com.google.gerrit.reviewdb.client.PatchLineComment@44ce4dda |
| 149 | com.google.gerrit.reviewdb.client.PatchLineComment@44594680 |
| 150 | >>> dir(com.google.gerrit.reviewdb.client.PatchLineComment) |
| 151 | ['Key', 'STATUS_DRAFT', 'STATUS_PUBLISHED', 'Status', '__class__', |
| 152 | '__copy__', '__deepcopy__', '__delattr__', '__doc__', '__eq__', |
| 153 | '__getattribute__', '__hash__', '__init__', '__ne__', '__new__', |
| 154 | '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', |
| 155 | '__unicode__', 'author', 'class', 'clone', 'equals', 'finalize', |
| 156 | 'getAuthor', 'getClass', 'getKey', 'getLine', 'getMessage', |
| 157 | 'getParentUuid', 'getSide', 'getStatus', 'getWrittenOn', 'hashCode', |
| 158 | 'key', 'line', 'lineNbr', 'message', 'notify', 'notifyAll', |
| 159 | 'parentUuid', 'registerNatives', 'setMessage', 'setSide', 'setStatus', |
| 160 | 'side', 'status', 'toString', 'updated', 'wait', 'writtenOn'] |
| 161 | >>> for x in db.patchComments().iterateAllEntities(): |
| 162 | ... print x.status, x.line, x.message |
| 163 | ... |
| 164 | P 2 I like it! |
| 165 | P 2 more |
| 166 | P 1 better |
| 167 | ---- |
| 168 | |
| 169 | A built-in *help()* function provides values of global variables |
| 170 | defined in the interpreter: |
| 171 | |
| 172 | ---- |
| 173 | >>> help() |
| 174 | "schk" is "com.google.gerrit.server.schema.SchemaVersionCheck@5e8cb9bd" |
| 175 | "ds" is "com.google.gerrit.server.schema.DataSourceProvider@6b3592c" |
| 176 | "m" is "com.google.gerrit.lifecycle.LifecycleManager@6f03b248" |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 177 | "Shell" is "com.google.gerrit.pgm.shell.JythonShell@61644f2d" |
David Ostrovsky | 947a80f | 2013-11-06 22:13:11 +0100 | [diff] [blame] | 178 | "d" is "com.google.gerrit.pgm.Daemon@28a3f689" |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 179 | |
| 180 | Welcome to the Gerrit Inspector |
| 181 | Enter help() to see the above again, EOF to quit and stop Gerrit |
| 182 | ---- |
| 183 | |
| 184 | Java and Python exceptions are intercepted by the Inspector: |
| 185 | ---- |
| 186 | >>> import java.lang.RuntimeException |
| 187 | >>> raise java.lang.RuntimeException("Exiting") |
| 188 | Traceback (most recent call last): |
| 189 | File "<stdin>", line 1, in <module> |
| 190 | at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) |
| 191 | at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) |
| 192 | at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) |
| 193 | at java.lang.reflect.Constructor.newInstance(Constructor.java:532) |
| 194 | at org.python.core.PyReflectedConstructor.constructProxy(PyReflectedConstructor.java:210) |
| 195 | |
| 196 | java.lang.RuntimeException: java.lang.RuntimeException: Exiting |
| 197 | >>> |
| 198 | ---- |
| 199 | |
| 200 | To exit the interpreter, use EOF character (Ctrl-D on Unix systems, Ctrl-Z on Windows). |
| 201 | |
| 202 | It is also possible to shut down the JVM by using *System.exit()* |
| 203 | |
| 204 | ---- |
| 205 | >>> import java.lang.System |
| 206 | >>> java.lang.System.exit(1) |
| 207 | ---- |
| 208 | |
| 209 | And Gerrit should shut down all its subsystems and exit: |
| 210 | |
| 211 | ---- |
| 212 | [2012-04-17 15:31:08,458] INFO com.google.gerrit.pgm.Daemon : caught shutdown, cleaning up |
| 213 | ---- |
| 214 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 215 | == TROUBLESHOOTING |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 216 | |
| 217 | Gerrit Inspector is logging to the Gerrit error log. |
| 218 | |
| 219 | A successful startup is indicated in the logfile: |
| 220 | |
| 221 | ---- |
| 222 | [2012-04-17 13:43:44,888] INFO com.google.gerrit.pgm.shell.JythonShell : Jython shell instance created. |
| 223 | ---- |
| 224 | |
| 225 | If 'jython.jar' library is not available, Gerrit refuses to start when given *-s* option: |
| 226 | |
| 227 | ---- |
| 228 | [2012-04-17 13:57:29,611] ERROR com.google.gerrit.pgm.Daemon : Unable to start daemon |
| 229 | com.google.inject.ProvisionException: Guice provision errors: |
| 230 | |
| 231 | 1) Error injecting constructor, java.lang.UnsupportedOperationException: Cannot create Jython shell: Class org.python.util.InteractiveConsole not found |
| 232 | (You might need to install jython.jar in the lib directory) |
| 233 | at com.google.gerrit.pgm.shell.JythonShell.<init>(JythonShell.java:47) |
| 234 | while locating com.google.gerrit.pgm.shell.JythonShell |
| 235 | while locating com.google.gerrit.pgm.shell.InteractiveShell |
| 236 | ---- |
| 237 | |
| 238 | Errors during processing of the startup script, 'Startup.py', are logged |
| 239 | to the error log: |
| 240 | |
| 241 | ---- |
| 242 | [2012-04-17 14:20:30,558] INFO com.google.gerrit.pgm.shell.JythonShell : Jython shell instance created. |
| 243 | [2012-04-17 14:20:38,005] ERROR com.google.gerrit.pgm.shell.JythonShell : Exception occured while loading file Startup.py : |
| 244 | java.lang.reflect.InvocationTargetException |
| 245 | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) |
| 246 | at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) |
| 247 | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) |
| 248 | at java.lang.reflect.Method.invoke(Method.java:616) |
| 249 | at com.google.gerrit.pgm.shell.JythonShell.runMethod0(JythonShell.java:112) |
| 250 | at com.google.gerrit.pgm.shell.JythonShell.execFile(JythonShell.java:194) |
| 251 | at com.google.gerrit.pgm.shell.JythonShell.reload(JythonShell.java:178) |
| 252 | at com.google.gerrit.pgm.shell.JythonShell.run(JythonShell.java:152) |
| 253 | at com.google.gerrit.pgm.Daemon.run(Daemon.java:190) |
| 254 | at com.google.gerrit.pgm.util.AbstractProgram.main(AbstractProgram.java:67) |
| 255 | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) |
| 256 | at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) |
| 257 | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) |
| 258 | at java.lang.reflect.Method.invoke(Method.java:616) |
| 259 | at com.google.gerrit.launcher.GerritLauncher.invokeProgram(GerritLauncher.java:167) |
| 260 | at com.google.gerrit.launcher.GerritLauncher.mainImpl(GerritLauncher.java:91) |
| 261 | at com.google.gerrit.launcher.GerritLauncher.main(GerritLauncher.java:49) |
| 262 | at Main.main(Main.java:25) |
| 263 | Caused by: Traceback (most recent call last): |
| 264 | File "/home/user/.gerritcodereview/Startup.py", line 1, in <module> |
| 265 | Test |
| 266 | NameError: name 'Test' is not defined |
| 267 | ---- |
| 268 | |
| 269 | Those errors are non-fatal. System and user scripts can be loaded again |
| 270 | by issuing the following command in the Gerrit Inspector console: |
| 271 | |
| 272 | ---- |
| 273 | Shell.reload() |
| 274 | ---- |
| 275 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 276 | == LOGGING |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 277 | Error and warning messages from the server are automatically written |
| 278 | to the log file under '$site_path/logs/error_log'. |
| 279 | |
| 280 | Output and error messages (including Java and Python exceptions) |
| 281 | resulting from interactive work are logged to the console. |
| 282 | |
Yuxuan 'fishy' Wang | 61698b1 | 2013-12-20 12:55:51 -0800 | [diff] [blame] | 283 | == KNOWN ISSUES |
Marcin Cieślak | ed612fb | 2012-04-17 16:24:34 +0000 | [diff] [blame] | 284 | The Inspector does not yet recognize Google Guice bindings. |
| 285 | |
| 286 | IMPORTANT: Using the Inspector may void your warranty. |
| 287 | |
| 288 | GERRIT |
| 289 | ------ |
| 290 | Part of link:index.html[Gerrit Code Review] |
Yuxuan 'fishy' Wang | 99cb68d | 2013-10-31 17:26:00 -0700 | [diff] [blame] | 291 | |
| 292 | SEARCHBOX |
| 293 | --------- |