In a series of recentposts, I’ve shown off what the GlassFish 4.0 REST client wrappers should look like, giving simple examples of using the wrappers using both Java and Python, the two currently supported languages. In this post, we’ll take a look at a more complex example, that of setting up clusters and standalone instances, deploying an app, then cleaning up after ourselves. Let’s jump right in.
In this fairly contrived scenario, we’re going to create one cluster, c1, with two nodes, c1in1 and c1in2, as well as two standalone instances, in1 and in2. In a real world situation, we might be deploying a single app to three different customer environments, for example. Once the cluster and instances are created, we’ll deploy the app, and then create application references on each of the instances. This is GlassFish’s way of deploying the same application to multiple targets. We could, of course, deploy the war multiple times, but that would result in the war file being deployed several times. There’s nothing inherently wrong with either approach. We’re just going to go with the former.
Enough with that, then, let’s get to the code. Hopefully, if you’ve been following along, this should be pretty straightforward and easy to read.
There’s not much to say about the code beyond what I said in the intro. I should note, though, that I removed some error checking to try to make this a bit shorter. Typically, after each REST call, I would have assert (rr.isSuccess()); just to make sure. In production code, you would need something similar (though, obviously, more robust).
If you have any questions about the code, please feel free to ask questions in the comments section. I’ll try to get the Python version posted as soon as I can. If there’s anything in particular you’d like to see me address about these client wrappers or the GlassFish REST interface in general, you know where to ask. ;)