Originally released in the late 1950s, COBOL became one of the most popular languages for business, finance, and other enterprise systems for decades. While COBOL didn’t crack Redmonk’s Programming Language Rankings this year, there is still a tremendous amount of it running in production, an estimated 220 billion lines of COBOL in 2017. Some of these COBOL applications are batch processing, fitting a scale-to-zero serverless approach quite well. As some of the platforms these workloads are running on approach their end of life (and ever-increasing support contracts), moving to newer platforms such as Kubernetes makes a lot of sense.
Kubernetes provides a standardized cloud native control plane for applications and services to run across public clouds and private data centers. Knative provides automatic application scaling up and down as workloads expand and contract in response to demand. Whether they are batch processing or continuously running, COBOL applications migrated to Kubernetes could continue to provide production value running free from the shackles of legacy systems and execute wherever the applications are needed.
GnuCOBOL is a modern, open source COBOL compiler that implements the COBOL 85, COBOL 2002, and COBOL 2014 standards and many of the extensions provided by other COBOL compilers (IBM COBOL, MicroFocus COBOL, and others). GnuCOBOL translates your COBOL code into C and compiles with your native C compiler (ie. GCC or Clang). Many existing legacy COBOL applications can safely be migrated to GnuCOBOL without being rewritten.
Inspired by the AWS Open Source Blog article on Serverless COBOL, our engineers put together a proof of concept for wrapping a COBOL application and running it on Knative. The source code is at https://github.com/triggermesh/cobolformation and this video walks through how it works.
COBOLformation is a Golang wrapper for COBOL applications, allowing them to run within Knative as a serverless application. The handler.go is a wrapper that takes a CloudEvent data payload the processEvent function and uses it as the arguments for the wrapped COBOL application. The data is passed to the COBOL application through C bindings as the C.datatyp defined through cgo definitions.
The example datatype.cob COBOL program takes the passed arguments as variables.
The Go float maps to COBOL’s COMP-1, double to COMP-2 and int to BINARY-SHORT SIGNED respectively. PIC X(24)is a 24 character string in COBOL. We do a few trivial operations to the data and return it to the Go wrapper.
The included ksvc.yaml is used to deploy the application to our Kubernetes cluster already running Knative Serving. You can use the Docker image referred to in the document or build it from the Dockerfile and push to your own registry if you prefer.
To deploy the application create a demo namespace.
Apply the ksvc.yaml to your Kubernetes deployment and create the cobolformation service.
Give it a few seconds to come up, then check that the cobolformation service is available and is serving on an external IP address.
You can use that address to post to the API with curl. You can copy and paste the example from the README, just make sure to update for your cobolformation endpoint.
The CloudEvent data payload is sent to the COBOL application and the returned results show the passed arguments were modified accordingly.
This is a relatively simple example, but it should be straightforward to upgrade the wrapper and the COBOL application for your own usage as necessary.