concept app in category cloud

This is an excerpt from Manning's book Cloud Native Patterns: Designing change-tolerant software.
You’ll note that any entity that has an arrow going to it, indicating that the component is depended upon by another, is a service. That’s right—almost everything is a service. Even the app that’s the root of the topology has an arrow to it from the software consumer. Apps, of course, are where you’re writing your code. And I particularly like the combination of service and state annotations, making clear that you have some services that are devoid of state (the stateless services you’ve surely heard about, annotated here with “app”), whereas others are all about managing state.
To help you understand the content of this chapter as well as provide a basis for later explanations, figure 7.1 depicts a fairly vanilla sequence of stages an app goes through in its lifetime. You’ll notice that I’ve excluded the creation of the deployable artifact from the app lifecycle; that’s part of the SDLC. On the other hand, you might find it curious that I’ve included having a provisioned environment and, later, a disposed-of environment, within the app lifecycle. I’ll ask for your patience; I promise this will become clear soon.
A rolling upgrade is also used to perform a zero-downtime update to a running application, and just as with blue/green deployments, when completed, all traffic to the app will be routed to the new version of an app. During the upgrade process, however, things are markedly different.
Figure 7.6 depicts the process. At the onset, all traffic is being load-balanced across the multiple instances of the current version of the app. During the upgrade, you’ll incrementally take a subset of the current version instances offline and bring a number of instances of the new version of the app online to replace them. As you do so, traffic is load-balanced across instances of the original version of the app and instances of the new version of the app. Traffic is being served to more than one version of the app! After the first batch is running well, you upgrade the next batch, and so on. The rolling upgrade is complete when all old versions of the app have been replaced by new.
Figure 7.6. During rolling upgrades, production traffic is routed to more than one version of the app. The app must be able to function as a single logical whole, even as requests are being distributed over different versions.
![]()
I once again draw your attention back to figure 6.1, which indicates that eventually all instances of an app will be running with the same configuration. Now you can see concretely what I mean.
In this example, you’ll implement the credential rotation pattern depicted in figure 7.9. You’ll update the Posts service in a rolling fashion, then the Connections’ Posts service in a rolling fashion, and then finally the Posts service, again in a rolling fashion. Notice that each app has two instances deployed; in the starting state, the credentials configured in match across the instances of an app, and they’re coordinated across the Connections’ Posts service and the Connections and Posts services. I’ll remind you that each of the three apps is drawing its configuration, via the config server, from the single mycookbook.properties file that’s checked into GitHub. Note that this is a configuration file for the composition of the three apps that collectively form the My Cookbook software.
Let’s now look at the client side, in the implementation of the Connections’ Posts app in listing 7.3. The basic structure is similar to that of the Posts and Connections apps. You use the Utils class to process the secrets configuration. Then in the app controller, in which the calls are made to the Posts and Connections services, you access the values through the singleton utils object. Looking first at the controller code, you can see that it’s straightforward. You access the posts or connections secret that’s configured into the app by asking for the value from the utils object, and send it on the query string.
Listing 7.3. Method from ConnectionsPostsController.java
@RequestMapping(method = RequestMethod.GET, value="/Connections' Posts") public Iterable<PostSummary> getByUsername( @CookieValue(value = "userToken", required=false) String token, HttpServletResponse response) { // <lines omitted for brevity> // get connections String secretQueryParam #1 = "?secret=" + utils.getConnectionsSecret(); ResponseEntity<ConnectionResult[]> respConns = restTemplate.getForEntity( connectionsUrl + username + secretQueryParam, ConnectionResult[].class); // <lines omitted for brevity> secretQueryParam = "&secret=" + utils.getPostsSecret(); #2 // get posts for those connections ResponseEntity<PostResult[]> respPosts = restTemplate.getForEntity( postsUrl + ids + secretQueryParam, PostResult[].class); // <lines omitted for brevity> }Although most of the Utils.class here is similar to the same class in the Posts app, it has one nuance. Notice that although the com.corneliadavis.cloudnative.connections.secrets and com.corneliadavis.cloudnative.posts.secrets properties are drawn from the mycookbook.properties file and may each contain a list of secrets, in the Connections’ Posts service, you need only the most recent one. You’ll establish an operational practice, and this must be covered in the documentation for the Connections’ Posts service, where the newest secret is always in the first position in the list. As you can see, you store in the state of the singleton utils object only one secret for each of the Posts and Connections services. To make that clear, the property that’s configured into the app is the single secret, even though the property file is carrying more than one. Again, the following code includes logging output that isn’t suitable for a production system but is a valuable teaching tool.