Start learning free

LESSON 156 OF 173 · BACKEND: SHIPPING IT

Project: The Release Checklist in Java

Practice

Before a new version goes live, a release checklist makes sure nothing was forgotten on the server. Your method releaseChecklist(env, db, client) gets the server's environment variables as a Map, its database as a JdbcTemplate, and a RestTemplate client that talks to its app. It collects what is wrong in a list, problems, and the code at the end prints it.

Each check reads a value, compares it, and adds a sentence when something is wrong. Here is a check for another setting:

Map<String, String> env = Map.of("SHOP_NAME", "Mug Shop", "ADMIN_EMAIL", "");
List<String> problems = new ArrayList<>();
if (env.getOrDefault("ADMIN_EMAIL", "").isEmpty()) {
    problems.add("set ADMIN_EMAIL");
}
System.out.println(problems);   // [set ADMIN_EMAIL]

Your checklist asks four things, in this order. Debug mode is off: DEBUG is "0", or not set at all (this check is already written). Every name in SECRETS is set and not empty. Every name in MIGRATIONS has its row in the table migrations: db.queryForList gives an empty list when it doesn't. And GET /health answers 200: the client you get hands back every answer, 503 included, without throwing.

Six test servers go through the checklist. The finished code prints:

Server 1: all set
Ready to release
Server 2: debug left on
To do: turn debug off (DEBUG is 1)
Server 3: secrets forgotten
To do: set the secret SECRET_KEY
To do: set the secret WEBHOOK_SECRET
Server 4: new code, old database
To do: run the migration 003_add_reviews
Server 5: the app is not healthy
To do: fix /health, it answers 503
Server 6: nothing done yet
To do: turn debug off (DEBUG is true)
To do: set the secret SECRET_KEY
To do: set the secret PAYMENTS_API_KEY
To do: set the secret WEBHOOK_SECRET
To do: run the migration 001_create_products
To do: run the migration 002_create_orders
To do: run the migration 003_add_reviews
To do: fix /health, it answers 503

Your task: inside releaseChecklist, below the debug check, add the three other checks: the secrets, then the migrations, then /health. Each one adds to problems the sentence that follows To do: in the output above.


Assignment
Follow the Coding Tutorial to add the checks of the release checklist: secrets set, migrations run and /health green.


Hint
env.getOrDefault(name, "") gives "" for a missing secret, never null. Pass name after the SQL to fill the ? placeholder. A number added to a string becomes text, so the status code needs no conversion.


STEP 1 OF 10
    Ctrl + Enter to check

    Ship Release Checklist in Java

    Keep going with Java1,600+ step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free