github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/integration/assets/service_broker/README.md (about) 1 # CATS Async Broker 2 3 This directory contains an easily configured service broker that can be pushed as a CF app. 4 5 ### How to push ### 6 ------------------- 7 `cf push async-broker` 8 9 10 ### Configuration API ### 11 ------------------------ 12 The broker includes an api that allows on-the-fly configuration. 13 14 To fetch the configuration, you can curl the following endpoint: 15 `curl <app_url>/config` 16 17 If you'd like to include the broker's entire state, including config, instances, and bindings: 18 `curl <app_url>/config/all` 19 20 To update the configuration of the broker yourself: 21 `curl <app_url>/config -X POST -d @data.json` 22 23 To reset the broker to its original configuration: 24 `curl <app_url>/config/reset -X POST` 25 26 27 ### The Configuration File ### 28 ------------------------------ 29 data.json includes the basic configuration for the broker. You can update this config in many ways. 30 31 The configuration of a broker endpoint has the following form: 32 ```json 33 { 34 "catalog": { 35 "sleep_seconds": 0, 36 "status": 200, 37 "body": { 38 "key": "value" 39 } 40 } 41 } 42 ``` 43 44 This tells the broker to respond to a request by sleeping 0 seconds, then returning status code 200 with the JSON body 45 '{"key": "value"}'. 46 47 For all endpoints but the /v2/catalog endpoint, we can make the configuration dependent on the plan_id provided 48 in the request. This allows us to have different behavior for different situations. As an example, we might decide 49 that the provision endpoint (PUT /v2/service_instances/:guid) should return synchronously for one request and asynchronous 50 for another request. To achieve this, we configure the endpoint like this: 51 ```json 52 { 53 "provision": { 54 "sync-plan-guid": { 55 "sleep_seconds": 0, 56 "status": 200, 57 "body": {} 58 }, 59 "async-plan-guid": { 60 "sleep_seconds": 0, 61 "status": 202, 62 "body": { 63 "last_operation": { 64 "state": "in progress" 65 } 66 } 67 } 68 } 69 } 70 ``` 71 72 If we don't want to vary behavior by service plan, we can specify a default behavior: 73 ```json 74 { 75 "provision": { 76 "default": { 77 "sleep_seconds": 0, 78 "status": 200, 79 "body": {} 80 } 81 } 82 } 83 ``` 84 85 These behaviors are all compiled in the top-level "behaviors" key of the JSON config: 86 87 ```json 88 { 89 "behaviors": { 90 "provision": { ... }, 91 "deprovision": { ... }, 92 "bind": { ... }, 93 "unbind": { ... }, 94 "fetch": { ... }, 95 ... 96 } 97 } 98 ``` 99 100 ##### Fetching Status ##### 101 102 In the case of fetching operation status (GET /v2/service_instances/:guid/last_operation), we need to account for different behaviors 103 based on whether the instance operation is finished or in progress. 104 105 ```json 106 { 107 "fetch": { 108 "default": { 109 "in_progress": { 110 "sleep_seconds": 0, 111 "status": 200, 112 "body": { 113 "last_operation": { 114 "state": "in progress" 115 } 116 } 117 }, 118 "finished": { 119 "sleep_seconds": 0, 120 "status": 200, 121 "body": { 122 "last_operation": { 123 "state": "succeeded" 124 } 125 } 126 } 127 } 128 } 129 } 130 ``` 131 132 The broker will return the "in_progress" response for the endpoint until the instance's state has been requested more 133 times than the top-level "max_fetch_service_instance_requests" parameter. At that point, all requests to fetch in the 134 instance state will response with the "finished" response. 135 136 ##### Asynchronous Only Behavior ##### 137 138 Some brokers/ plans can only respond asynchronously to some actions. To simulate this, we can configure a plan for an action 139 to be 'async_only.' 140 141 ```json 142 { 143 "provision": { 144 "async-plan-guid": { 145 "sleep_seconds": 0, 146 "async_only": true, 147 "status": 200, 148 "body": {} 149 } 150 } 151 } 152 ``` 153 154 If we try to provision a new service instance for the 'async-plan' without sending the 'accepts_incomplete' parameter, 155 the broker will respond with a 422. 156 157 158 ### Bootstrapping ### 159 --------------------- 160 The repo also includes a ruby script `setup_new_broker.rb` to bootstrap a new broker. The script does the following: 161 - generates a unique config for the broker in order avoid guid and name conflicts with other brokers. 162 - pushes the broker as an app 163 - registers or updates the broker 164 - enables service access for the broker's service 165 166 Before running the script, you must: 167 - Choose a CF env with `cf api` 168 - `cf login` with an admin user and password 169 - `cf target -o <some org> -s <some space>` with an org and space where you'd like to push the broker 170 171 The script also takes parameters: 172 - `broker_name`: Specifies the app name and route for the broker. Defaults to 'async-broker'. 173 - `env`: Specifies the cf environment (used only for choosing an app domain). Allowed values are 'bosh-lite', 174 'tabasco', and 'a1'. Defaults to 'bosh-lite'. 175 176 177 ### Running multiple cases ### 178 -------------------------- 179 We often need to test how the CC handles many permutations of status code, body, and broker action. To make this simple, we've 180 written a script called run_all_cases.rb. It requires one parameter, which is a path to a CSV file. It also optionally allows 181 two additional parameters, a broker url and a --no-cleanup flag. 182 183 The script reads the CSV file and produces a list of test cases. For each test case, the script configures the brokers to behave 184 as specified, and then makes the corresponding cf cli command. The CLI output is stored in a new CSV file, which has the same 185 name as the input file with a "-out" suffix. (For example, acceptance.csv becomes acceptance-out.csv) 186 187 If the caller provides a broker URL, the script will use that address for its test cases, otherwise it will default to 188 async-broker.bosh-lite.com. 189 190 The script also preforms setup and cleanup for each test it executes. e.g. performing an update requires a setup which 191 creates an instance and cleanup which deletes it. 192 193 If the user provides --no-cleanup the script will not perform a cleanup at the end of each test. 194 195