Jaa


IntelliSense for Marathon Application and Group JSON in Visual Studio Code

tl;dr – You can get IntelliSense for Marathon applications and groups in Visual Studio Code by adding a $schema property

The Problem

I’ve been having quite a lot of fun with Docker Containers recently, including presenting at various conferences! For ease and speed of demoing, I’ve tended to show Docker Swarm (with Docker Compose) when deploying an application to a cluster because there are fewer new concepts to introduce. You can get IntelliSense for Dockerfile and docker-compose.yml files in both Visual Studio and Visual Studio Code (I often use the latter simply because I often demo from a non-Windows machine). I’ve spent some time with DC/OS recently, too. With DC/OS, you can use Marathon to run your containers, and these can be described in Application JSON or Application Group JSON. The Marathon UI gives you an interactive way to define this:

 

image

And it even shows you the JSON behind it and allows you to edit it for scenarios that the UI doesn’t support:

image

If you work with the definition in JSON files then you can use the DC/OS CLI to create applications from the command line. Call me old-fashioned, but I like that this approach allows me to version-control my definitions. However, I wasn’t getting any help from Visual Studio Code with editing the files and that bothered me!

The Solution

It turned out that there was a pretty quick fix for this, which was to specify the JSON Schema for the file I was editing. If you’re familiar with XML, you can kind of think of JSON Schema as XSDs for JSON.

After a quick bit of searching I found schemas for both the application and group JSON. Visual Studio Code has built-in support for JSON Schema, so all I needed to do was add the $schema property to my JSON file.

For application JSON use:

"$schema": "https://raw.githubusercontent.com/mesosphere/marathon/master/docs/docs/rest-api/public/api/v2/schema/AppDefinition.json",

For group JSON use:

"$schema": "https://raw.githubusercontent.com/mesosphere/marathon/master/docs/docs/rest-api/public/api/v2/schema/Group.json",

Once that’s done you can enjoy IntelliSense (and naturally run your Swarm or DCOS workloads on Container Service Winking smile)

marathon-code