2012-12-22

Gerrit Code Review - setup

Gerrit Code Review has given me a hard time when I first tried it out.

It wasn't such a big problem to have it installed, as it was to have it configured. Whenever I was done with initial setup, it kept failing on attempt to register first user, and the problem re-emerged some time later, when I decided to upgrade the system.

My biggest fail back then was to set things up manually. I added user to specific groups by hand, thinking that the setup script was not mature enough to handle it for me. While searching around for how i did this last time i stumbled upon a short [ticket](, which helped me realize, that it was all so much out of sync, it just couldn't handle the upgrade.

Ultimately, every time I set up the review site from scratch, the attempt to register first user ended up with the following message:

[2012-12-22 18:58:24,835] WARN / : Unexpected error during authentication
java.util.NoSuchElementException
 at java.util.ArrayList$Itr.next(ArrayList.java:794)
 at com.google.gerrit.server.account.AccountManager.create(AccountManager.java:291)
 at com.google.gerrit.server.account.AccountManager.authenticate(AccountManager.java:122)
 at com.google.gerrit.httpd.auth.openid.OpenIdServiceImpl.doAuth(OpenIdServiceImpl.java:409)
 at com.google.gerrit.httpd.auth.openid.OpenIdLoginServlet.doPost(OpenIdLoginServlet.java:50)
 at com.google.gerrit.httpd.auth.openid.OpenIdLoginServlet.doGet(OpenIdLoginServlet.java:40)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)

Here's a step-by-step procedure that will help you set things up right the first time you try.

Prerequisites:

  • Linux box, 
  • Sun JAVA virtual machine - version 1.6 or later, 
  • PostgreSQL installed and running

Here's what you do:

  1. As root: Prepare Gerrit repository folder, say
    mkdir /var/repositories

  2. As root: Change permissions on this folder, allowing your gerrit2 user full access:
    chown -R gerrit2 /var/repositories
  3. As gerrit2: Initialize a new repository:
    git init --bare /var/repositories/All-Projects.git
  4. As gerrit2: Create new PostgreSQL user:
    createuser -A -D -P -E gerrit2
  5. As gerrit2: Create new PostgreSQL database:
    createdb -E UTF-8 -O gerrit2 reviewdb
  6. As gerrit2: Download the latest gerrit2 installation package and launch the setup:
    java -jar gerrit-full-2.5.1.war init \
        -d /home/gerrit2/review_site
  7. Finally, navigate to Gerrit web site and register your new user:
    xdg-open http://localhost:8080/#/admin/projects
Now, if you are facing complete reinstallation of your system, and upgrading is simply not possible (say, you did the same thing I did previously), here's what you need to do:
  1. As gerrit2: stop the review site:
    cd ~/review_site bin/gerrit.sh stop
  2. As postgres: drop the database:
    dropdb reviewdb
  3. As gerrit2: remove the All-Projects repo:
    rm -rf /var/repositories/All-Projects.git
Yes, this will purge the history of your reviews. It sucks - well, kind of. Ultimately you will get fully functional review site, which is pretty much what counts more.

Next step is usually to trim the approval categories. It feels kind-of wrong to manipulate the database directly, but then, at the same time, it feels stupid to go through verification of own changes.

Typically, one could do this by invoking:

ssh server gerrit gsql
delete from approval_categories \
    [where category_id="VRIF" or category_id="CRVW"]
delete from approval_category_values \
    [where category_id ...]

The contents of these two tables are:


gerrit> select * from approval_categories;
 name        | abbreviated_name | position | function_name | copy_min_score | category_id
 ------------+------------------+----------+---------------+----------------+------------
 Verified    | V                | 0        | MaxWithBlock  | N              | VRIF
 Code Review | R                | 1        | MaxWithBlock  | Y              | CRVW
(2 rows; 14 ms)

gerrit> select * from approval_category_values; name                                            | category_id | value
 ------------------------------------------------+-------------+------
 Verified                                        | VRIF        | 1
 No score                                        | VRIF        | 0
 Fails                                           | VRIF        | -1
 Looks good to me, approved                      | CRVW        | 2
 Looks good to me, but someone else must approve | CRVW        | 1
 No score                                        | CRVW        | 0
 I would prefer that you didn't submit this      | CRVW        | -1
 Do not submit                                   | CRVW        | -2
(8 rows; 7 ms)

so, nothing's lost - just delete the contents. Gerrit still does need an approval category. To add them, execute:

ssh server gerrit gsql

insert into approval_categories values \
    ("Approved", 'A', 0, MaxNoBlock, 'Y', "APRV");
insert into approval_category_values values \
    ('No Score', 'APRV', 0);
insert into approval_category_values values \
    ('Approved', 'APRV', 1);

and restart the server (for some, invoking flush-caches would work, too).

No comments:

Post a Comment