{"id":370,"date":"2013-03-12T18:35:00","date_gmt":"2013-03-12T18:35:00","guid":{"rendered":"http:\/\/corneliadavis.com\/blog\/?p=370"},"modified":"2013-03-12T18:35:00","modified_gmt":"2013-03-12T18:35:00","slug":"bonus-track-deploying-the-echo-service-via-the-service_broker","status":"publish","type":"post","link":"https:\/\/corneliadavis.com\/blog\/2013\/03\/12\/bonus-track-deploying-the-echo-service-via-the-service_broker\/","title":{"rendered":"Bonus track: Deploying the Echo Service via the service_broker"},"content":{"rendered":"<p>Part IV in a three part series \ud83d\ude09<\/p>\n<p>In <a href=\"http:\/\/corneliadavis.com\/blog\/2013\/01\/29\/the-anatomy-of-a-cloud-foundry-system-service-implementation\/\">Part II<\/a> I went into a little bit of detail on how the echo service gateway and node work, in collaboration with the actual echo server.  Or rather, in this case, how the node does not work with the echo server at all. \u00a0The echo_node implementation simply looks up some metadata values from it&#8217;s config file and returns them, via the gateway, to the requesting party (the dea). \u00a0You might question why the node was in there at all. \u00a0The answer is that in this case you don&#8217;t really need it.<\/p>\n<p>Included in the vcap-services repository is an implementation for a service broker which can be used to act as a gateway to services that are running outside of cloud foundry. \u00a0Recall from <a href=\"http:\/\/corneliadavis.com\/blog\/2013\/01\/04\/learning-how-to-add-services-to-cloud-foundry\/\">part I<\/a> in this series that the echo server, the java application that listens on a port and parrots back what it hears there, really doesn&#8217;t have anything to do with cloud foundry; again, not even the echo_node communicates with it. \u00a0So really, you can think of it as a server running external to cloud foundry.<\/p>\n<p>The service_broker is a service_gateway implementation that stands up a RESTful web service that implements all of the resources that any service gateway resource does; resources that allow you to create or delete a service instance, bind or unbind it from applications, etc. \u00a0In this case, the gateway implementation simply offers a metadata registry with entries for each of the brokered services. In a &#8220;normal&#8221; cloud foundry service\u00a0implementation, in response to these web service requests the gateway will dispatch a message to NATS, a node will pick it up, fulfill the request and communicate back to the gateway, which in turn responds to its client. \u00a0In the case of the service_broker there is no node and hence no need to dispatch messages onto NATS. \u00a0The web services of the gateway simply look up \u00a0the values in its registry and return them. \u00a0This begs the question of how things get into that registry; the service_broker gateway offers a RESTful web service resource for the registry itself, supporting POST to add things and DELETE to remove them. \u00a0You can either issue those service invocations yourself or you can use the <a href=\"https:\/\/github.com\/cloudfoundry\/vcap-services\/tree\/master\/tools\/service_broker_cli\">service broker cli<\/a>.<\/p>\n<p>So here&#8217;s what I did to go through the exercise of deploying the echo server as a brokered service:<\/p>\n<p><strong>Step 1<\/strong>: Start with a vcap devbox, following the instructions you find in the <a href=\"https:\/\/github.com\/cloudfoundry\/vcap-services\">vcap repsitory<\/a>, EXCEPT that you also need to start up the service broker; see <a href=\"http:\/\/stackoverflow.com\/questions\/15285455\/how-do-i-get-the-service-broker-to-start-up-in-a-vcap-dev-deployment\">this stackoverflow thread<\/a> for how to do that.<\/p>\n<p><strong>Step 2<\/strong>: Register the echo service with the service_broker. \u00a0I used the <a href=\"https:\/\/github.com\/cloudfoundry\/vcap-services\/tree\/master\/tools\/service_broker_cli\">service_broker_cli<\/a> which will already be on the devbox you set up in step 1. \u00a0Running the cli with no arguments will register what is found in the services.yml file found in the <a href=\"https:\/\/github.com\/cloudfoundry\/vcap-services\/tree\/master\/tools\/service_broker_cli\/config\">config<\/a> directory, so I ran it as follows:<\/p>\n<pre>bin\/service_broker_cli -c config\/echobrokeredservice.yml<\/pre>\n<p>with the contents of the echobrokeredservice.yml as follows:<\/p>\n<pre>---\nservice_broker: http:\/\/service-broker.vcap.me\ntoken: \"changebrokertoken\"\nservice:\n  name: echo\n  description: cloud foundry sample service\n  version: \"1.0\"\n  options:\n    - name: service\n      acls:\n        users: []\n        wildcards: [*@emc.com]\n      credentials:\n        host: 192.168.1.150\n        port: 5002<\/pre>\n<p>Notice the &#8220;credentials&#8221; section &#8211; there are the same values that were in the echo_node.yml file in <a href=\"http:\/\/corneliadavis.com\/blog\/2013\/01\/04\/learning-how-t\u2026-cloud-foundry\/\">part I<\/a> but now instead of the echo_gateway dispatching to NATS and the echo_node simply returning the values from the echo_node.yml file, the service_broker_gateway just looks those values up in its registry and returns them.<\/p>\n<p>When you now run a<\/p>\n<pre>vmc info --services<\/pre>\n<p>you should see the echo service listed.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/corneliadavis.com\/blog\/wp-content\/uploads\/2013\/03\/echosb1.png\"><img data-recalc-dims=\"1\" decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-372\" title=\"echosb1\" src=\"https:\/\/i0.wp.com\/corneliadavis.com\/blog\/wp-content\/uploads\/2013\/03\/echosb1-300x94.png?resize=300%2C94\" alt=\"\" width=\"300\" height=\"94\" \/><\/a><\/p>\n<p><strong>Step 3<\/strong>: Deploy your client app and bind to the echo_service.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/corneliadavis.com\/blog\/wp-content\/uploads\/2013\/03\/echosb2.png\"><img data-recalc-dims=\"1\" decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-373\" title=\"echosb2\" src=\"https:\/\/i0.wp.com\/corneliadavis.com\/blog\/wp-content\/uploads\/2013\/03\/echosb2-175x300.png?resize=175%2C300\" alt=\"\" width=\"175\" height=\"300\" \/><\/a><\/p>\n<p>Seriously. \u00a0That&#8217;s it.<\/p>\n<p>But before you think, &#8220;why did I go through all of those other hairy steps with the node and gateway and BOSH, etc.?,&#8221; remember that this echo server is just a sample, and a very, very simplified one. Servers that run within cloud foundry (and are hopefully deployed with BOSH) benefit from management, monitoring, logging and other cloud foundry capabilities, and the gateway\/node combination is a loosely coupled mechanism for offering lifecycle operations on those services. \u00a0A very valuable part of the cloud foundry services story. \u00a0That said, there is clearly value in brokering external services and that&#8217;s why you have this bonus track. \ud83d\ude42<\/p>\n<h1>The Echo Client<\/h1>\n<p>So just a bit more on step 3 from above. The Echo client application that was posted all the way back on the <a href=\"http:\/\/support.cloudfoundry.com\/entries\/20485171-how-to-add-a-system-service-to-oss-cloud-foundry-step-by-step-guide\">original support forum article<\/a> is a bit rigid. \u00a0It accesses the details of the bound services through the VCAP_SERVICES environmental variable, and that&#8217;s fine, but it then looks for a service type named (exactly) &#8220;echo&#8221; and an instance name of (exactly) &#8220;myecho.&#8221; \u00a0This hard coding always bugged me but because of the way that brokered services are named as a part of their configuration, I finally did something about it. \u00a0It required some changes to JsonParseUtil.java where I now take in a string and look for a service type name and instance name that contains that string. \u00a0So in an updated version of the echo client source code that you can find <a href=\"https:\/\/github.com\/cdavisafc\/cloudfoundry-misc\/tree\/master\/echoclient\">here<\/a>, the client will look for a bound service with the type and the instance name containing the string &#8220;echo&#8221;; so the service type of &#8220;echo_service&#8221; with a name like &#8220;echo_service-a302&#8221; fits the bill. \u00a0Oh, and one other slight add to the app &#8211; this one now prints the contents of the VCAP_SERVICES environmental variable &#8211; helps when you are first getting started with such things.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/corneliadavis.com\/blog\/wp-content\/uploads\/2013\/03\/echosb3.png\"><img data-recalc-dims=\"1\" decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-374\" title=\"echosb3\" src=\"https:\/\/i0.wp.com\/corneliadavis.com\/blog\/wp-content\/uploads\/2013\/03\/echosb3-300x136.png?resize=300%2C136\" alt=\"\" width=\"300\" height=\"136\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Part IV in a three part series \ud83d\ude09 In Part II I went into a little bit of detail on how the echo service gateway and node work, in collaboration with the actual echo server. Or rather, in this case, how the node does not work with the echo server at all. \u00a0The echo_node implementation [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5,13,19,21],"tags":[53],"class_list":["post-370","post","type-post","status-publish","format-standard","hentry","category-cloud","category-howto","category-opensource","category-paas","tag-cloudfoundry"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/corneliadavis.com\/blog\/wp-json\/wp\/v2\/posts\/370","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/corneliadavis.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/corneliadavis.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/corneliadavis.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/corneliadavis.com\/blog\/wp-json\/wp\/v2\/comments?post=370"}],"version-history":[{"count":0,"href":"https:\/\/corneliadavis.com\/blog\/wp-json\/wp\/v2\/posts\/370\/revisions"}],"wp:attachment":[{"href":"https:\/\/corneliadavis.com\/blog\/wp-json\/wp\/v2\/media?parent=370"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/corneliadavis.com\/blog\/wp-json\/wp\/v2\/categories?post=370"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/corneliadavis.com\/blog\/wp-json\/wp\/v2\/tags?post=370"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}