A COBOL core in a modern project

This group is one small project, built and run in this container: a COBOL program that prices orders, and a Python HTTP service that runs it for a client. The COBOL does the arithmetic and the validation; the modern layer owns the protocol, the JSON, the timeouts and the HTTP status. Everything is shown as it was run.

The shape is deliberate and it is the one most modernisation projects arrive at: the working COBOL stays where it is, the interface to it is a fixed-width record, and a new program wraps it. The pages cover the contract, the core, the service, its failures, its tests, a second way to call the same core through ctypes, the Dockerfile, and what a production version should change.

30/50 The contract: fixed-width and JSON A thirty-byte request and a fifty-byte answer, the copybook that declares them, and the JSON the Python layer translates at the edge. Open Core The COBOL core One program that reads requests from stdin, validates and prices them and writes answers to stdout, plus a five-case COBOL test driver. Open http The Python service http.server, subprocess and four status codes, with real requests, real responses and the server log of the run. Open 4xx/5xx The error paths A short body, a rejected order, a missing core and a slow core: what the service answers and what the client sees. Open Test Tests of the Python layer Six unittest cases against the real server and the real COBOL core, started on a free port and stopped again. Open 2 ms Calling the core through ctypes The same logic as a shared module: one call without a process, and 4.43 milliseconds against 2.13 microseconds measured here. Open Docker Deployment The Dockerfile of the whole project: built on the host in Docker, run with a published port, and called from the host. Open Next What to change for production The closing page: what the measurements say about protocols, timeouts, tests and the shape of the service. Open

The files

Nine files, in the order a reader meets them. The two built files are not in the repository.

priceif.cpy — the request and answer records, the contract
price.cob — PRICE (stdin/stdout) and PRICECORE (the unit)
coretest.cob — the COBOL test driver, five cases
requests.fixed — five sample requests, thirty bytes each
server.py — the HTTP layer, standard library only
test_service.py — six unittest cases
call_core.py — one call through the shared module
bench.py — subprocess against ctypes, measured
Dockerfile — the image, built on the host

Where to start

Start with the contract: it is thirty odd bytes and every other page depends on it. The SELECT and FD and Python lessons are the course material behind the core and the ctypes page.