Skip to content
This repository
Browse code

rewrite of 'add a service' docs for the reimplementation of services

  • Loading branch information...
commit 6178119bd137c0f4108111c79093a580295266b3 1 parent f7e3cae
Dr Nic Williams authored March 10, 2013

Showing 1 changed file with 59 additions and 21 deletions. Show diff stats Hide diff stats

  1. 80  docs/developer/add-new-services.md
80  docs/developer/add-new-services.md
Source Rendered
@@ -66,13 +66,69 @@ In your manifest spec, you might want to include an extension to `@system_config
66 66
 ]
67 67
 ```
68 68
 
69  
-Initially, the [SystemConfig](https://github.com/StarkAndWayne/bosh-cloudfoundry/blob/master/lib/bosh-cloudfoundry/config/system_config.rb) class (`@system_config`) does not have a `#mysql=` method. Find where postgresql/redis are defined and add your service name in that list.
  69
+Initially, the [SystemConfig](https://github.com/StarkAndWayne/bosh-cloudfoundry/blob/master/lib/bosh-cloudfoundry/config/system_config.rb) class (`@system_config`) does not have a `#mysql=` method. Let's now implement support for the new service.
70 70
 
71 71
 ### Creating a service config class
72 72
 
73 73
 For each of postgresql and redis there is a class that knows about its service's configuration, [PostgresqlServiceConfig](https://github.com/StarkAndWayne/bosh-cloudfoundry/blob/master/lib/bosh-cloudfoundry/config/postgresql_service_config.rb) & [RedisServiceConfig](https://github.com/StarkAndWayne/bosh-cloudfoundry/blob/master/lib/bosh-cloudfoundry/config/redis_service_config.rb), respectively.
74 74
 
75  
-Create another one for your service, say `MysqlServiceConfig`.
  75
+Create another one for your service, say `MysqlServiceConfig` as a subclass of [ServiceConfig](https://github.com/drnic/bosh-cloudfoundry/blob/master/lib/bosh-cloudfoundry/config/service_config.rb). Make it look something like:
  76
+
  77
+``` ruby
  78
+# Copyright (c) 2012-2013 Stark & Wayne, LLC
  79
+
  80
+module Bosh; module CloudFoundry; module Config; end; end; end
  81
+
  82
+module Bosh::CloudFoundry::Config
  83
+  class MysqlServiceConfig < ServiceConfig
  84
+
  85
+    # name that maps into the cf-release's jobs folder
  86
+    # for postgresql_gateway and postgresql_node jobs
  87
+    # also used as the key into SystemConfig manifest
  88
+    def service_name
  89
+      "mysql"
  90
+    end
  91
+
  92
+    # Add extra configuration properties into the manifest
  93
+    # for the gateway, node, and service plans
  94
+    def merge_manifest_properties(manifest)
  95
+      if any_service_nodes?
  96
+        # TODO
  97
+      end
  98
+    end
  99
+  end
  100
+
  101
+  SystemConfig.register_service_config(MysqlServiceConfig)
  102
+end
  103
+```
  104
+
  105
+Look at the other `ServiceConfig` subclasses for examples of what to put into the `merge_manifest_properties` method.
  106
+
  107
+### Hooking it up
  108
+
  109
+There is one step to hooking up your new class to make it fully integrated. Add the following line to the bottom of the [config.rb](https://github.com/drnic/bosh-cloudfoundry/blob/master/lib/bosh-cloudfoundry/config.rb) file:
  110
+
  111
+``` ruby
  112
+require "bosh-cloudfoundry/config/mysql_service_config"
  113
+```
  114
+
  115
+This will automatically register the new class with SystemConfig because of the call to `SystemConfig.register_service_config` at the end of the `mysql_service_config.rb` file above.
  116
+
  117
+### Tests should pass
  118
+
  119
+At this point, your tests should pass. 
  120
+
  121
+If they don't then adjust your `merge_manifest_properties` method or perhaps you'll need to override more of the methods provided by `ServiceConfig`.
  122
+
  123
+### Using the service
  124
+
  125
+Now, when your new service should be available via the CLI:
  126
+
  127
+```
  128
+$ bosh cf add service mysql
  129
+```
  130
+
  131
+## Further explanations
76 132
 
77 133
 The purpose of the `SystemConfig` class is two-fold:
78 134
 
@@ -94,22 +150,4 @@ During the building process, we delegate to each ServiceConfig object to modify
94 150
 * additional jobs (method `add_jobs_to_manifest`); we want the additional resource pool servers to become mysql service nodes ([mysql_node](https://github.com/cloudfoundry/cf-release/tree/master/jobs/mysql_node))
95 151
 * additional shared properties (method `merge_manifest_properties`); for example, to configure the service plans that the service nodes will support, such as "free", and what versions of the actual service (e.g. mysql 5.5) are running.
96 152
 
97  
-You trigger these 4 methods by calling them from the [SystemDeploymentManifestRenderer#perform](https://github.com/StarkAndWayne/bosh-cloudfoundry/blob/master/lib/bosh-cloudfoundry/system_deployment_manifest_renderer.rb#L20) method.
98  
-
99  
-## Tests should pass
100  
-
101  
-At this point, your tests should pass.
102  
-
103  
-## Enable the service
104  
-
105  
-At this point, the CLI still will not allow the new service. Let's fix that.
106  
-
107  
-In the main CLI file, [cf.rb](https://github.com/StarkAndWayne/bosh-cloudfoundry/blob/master/lib/bosh/cli/commands/cf.rb), find the `#supported_services` method and add your new service name (e.g. `mysql`).
108  
-
109  
-Finally, map your service name to your `ServiceConfig` class in the `#service_config` method.
110  
-
111  
-Now, when your new service should be available via the CLI:
112  
-
113  
-```
114  
-$ bosh cf add service mysql
115  
-```
  153
+The first three all have common implementations for all `ServiceConfig` subclasses. It is possible that your service may require already implementations. If so, then reimplement them in your subclass.

0 notes on commit 6178119

Please sign in to comment.
Something went wrong with that request. Please try again.