|
1 | 1 | ---
|
2 |
| -title: "Configuration" |
| 2 | +title: "Spring Config Server" |
3 | 3 | ---
|
4 | 4 |
|
5 |
| -Oracle Backend for Spring Boot and Microservices includes Spring Cloud Config which provides server- and client-side support for externalized |
6 |
| -configurations in a distributed system. The Spring Cloud Config server provides a central place to manage external properties for applications |
7 |
| -across all environments. |
| 5 | +Oracle Backend for Spring Boot and Microservices includes Spring Cloud Config which provides server- and client-side support for externalized configurations in a distributed system. The Spring Cloud Config server provides a central place to manage external properties for applications across all environments. |
8 | 6 |
|
9 |
| -The Spring Cloud Config server is pre-configured to work with the Spring Boot Eureka service registry, and it is configured to store the |
10 |
| -configuration in the Oracle Autonomous Database, so it easily supports labelled versions of configuration |
11 |
| -environments, as well as being accessible to a wide range of tools for managing the content. |
12 |
| -Configuration is stored in the `CONFIGSERVER` schema in the `PROPERTIES` table. |
| 7 | +The Spring Cloud Config server is pre-configured to work with the Spring Boot Eureka service registry, configured to store the Configuration in the Oracle Autonomous Database to support labeled versions of configuration environments as well as being accessible to a wide range of tools for managing the content. More details can be found here: ([Spring Cloud Config Documentation](https://spring.io/projects/spring-cloud-config)). |
13 | 8 |
|
14 |
| -For example, the Spring Cloud Config client's Spring `application.yaml` configuration file could include: |
| 9 | +When building applications using Spring Config Server, the Spring Cloud Config client's `application.yaml` configuration file must include access information to the deployed Spring Config Server: |
15 | 10 |
|
16 | 11 | ```yaml
|
17 | 12 | spring:
|
18 | 13 | config:
|
19 | 14 | import: optional:configserver:http://config-server.config-server.svc.cluster.local:8080
|
20 |
| - application: |
21 |
| - name: atael |
22 |
| - cloud: |
23 |
| - config: |
24 |
| - label: latest |
25 |
| - profile: dev |
26 | 15 | ```
|
27 | 16 |
|
28 |
| -This example fetches data where the application is `atael`, profile is `dev` and the label is `latest`. |
| 17 | +Configuration is stored in the `CONFIGSERVER` schema in the `PROPERTIES` table. Managing the data for the Spring Cloud Config server should be done using the CLI or the REST API endpoints. If you prefer, you can also work directly with the `CONFIGSERVER.PROPERTIES` table in the database. How to access the database is documented here, ([Accessing the database](../../database/)). |
29 | 18 |
|
30 |
| -Managing the data for the Spring Cloud Config server should be done using the CLI. If you prefer, you can also work directly |
31 |
| -with the `CONFIGSERVER.PROPERTIES` table in the database. |
| 19 | +During setup of Oracle Backend for Spring Boot and Microservices, the following data is loaded into `CONFIGSERVER.PROPERTIES`. This data can be deleted. |
32 | 20 |
|
| 21 | +```code |
| 22 | +| APPLICATION | PROFILE | LABEL | PROP_KEY | VALUE |
| 23 | +|-----------------|----------------|----------|---------------------|-----------------------------------| |
| 24 | +| atael | dev | latest | test-property | This is the test-property value | |
| 25 | +| atael | dev | latest | test-property-2 | This is the test-property-2 value | |
| 26 | +| application-a | production | 12c | db-name | databasename-a-prod | |
| 27 | +| application-a | production | 12c | db-connection | connectionstring-a-prod | |
| 28 | +| application-a | development | 23cbeta | db-dev-name | databasename-a-dev | |
| 29 | +| application-a | development | 23cbeta | db-dev-connection | connectionstring-a-dev | |
| 30 | +| application-b | production | 19c | db-name | databasename-b-prod | |
| 31 | +| application-b | production | 19c | db-connection | connectionstring-b-prod | |
| 32 | +| application-b | development | 23cbeta | db-dev-name | databasename-b-dev | |
| 33 | +| application-b | development | 23cbeta | db-dev-connection | connectionstring-b-dev | |
| 34 | +| application-c | secret | 23.4 | json-db | 23c-json-db | |
| 35 | +| application-c | secret | 23.4 | json-sdb-conn | 23c-mongo-conn | |
| 36 | +| application-c | secret | 23.4 | txenventq | 23c-conn-string | |
| 37 | +| application-c | secret | 23.4 | txeventq | 23c-kafka-name | |
| 38 | +``` |
| 39 | + |
| 40 | +## Config Server REST API endpoints overview |
| 41 | + |
| 42 | +The following REST API endpoints are available to the Config Server entries. The table lists which minimum required role is needed to perform the operation. 'N/A' in the following table indicates that the endpoint does not require authentication to be accessed. |
| 43 | + |
| 44 | +| End point | Method | Description | Minimum Required Role | |
| 45 | +|-------------------------------|--------|---------------------------------------------------------|-----------------------| |
| 46 | +| /srv/config/all | GET | Get all distinct properties for a service (application) | N/A | |
| 47 | +| /srv/config/properties | GET | Get all distinct properties with filters (see examples) | N/A | |
| 48 | +| /srv/config/properties/add | POST | Create properties from a file | ROLE_USER | |
| 49 | +| /srv/config/property/add | POST | Create a property | ROLE_USER | |
| 50 | +| /srv/config/property/update | PUT | Update a property | ROLE_USER | |
| 51 | +| /srv/config/properties/delete | DELETE | Delete properties with filters (see examples) | ROLE_ADMIN | |
| 52 | + |
| 53 | +### Config Server REST API endpoints examples |
| 54 | + |
| 55 | +In all of the following examples, replace `<username>:<password>` with your username and password when necessary. ([Getting User information](../../security/azn-server/)). The examples are using `curl` to interact with the REST API endpoints. This also requires an open tunnel on port 8080 to either the `config-server` or `obaas-admin` service. Use the following command to start a tunnel to the `config-server` service: |
| 56 | + |
| 57 | +```shell |
| 58 | +kubectl port-forward -n config-server svc/config-server 8080 |
| 59 | +``` |
| 60 | + |
| 61 | +The output will be slightly different when using a tunnel to `obaas-admin`. The data will be included in the `"body"` section. |
| 62 | + |
| 63 | +#### /srv/config/all |
| 64 | + |
| 65 | +Get all distinct application services: |
| 66 | + |
| 67 | +```shell |
| 68 | +curl -s http://localhost:8080/srv/config/all |
| 69 | +``` |
| 70 | + |
| 71 | +Example of data returned: |
| 72 | + |
| 73 | +```json |
| 74 | +[ |
| 75 | + { |
| 76 | + "name": "application-a", |
| 77 | + "label": "", |
| 78 | + "profile": "" |
| 79 | + }, |
| 80 | + { |
| 81 | + "name": "application-b", |
| 82 | + "label": "", |
| 83 | + "profile": "" |
| 84 | + }, |
| 85 | + { |
| 86 | + "name": "application-c", |
| 87 | + "label": "", |
| 88 | + "profile": "" |
| 89 | + }, |
| 90 | + { |
| 91 | + "name": "atael", |
| 92 | + "label": "", |
| 93 | + "profile": "" |
| 94 | + } |
| 95 | +] |
| 96 | +``` |
| 97 | + |
| 98 | +#### /srv/config/all?service-profile=\<profile-name\> |
| 99 | + |
| 100 | +Get all distinct services filtered on profile (service-profile): |
| 101 | + |
| 102 | +```shell |
| 103 | +curl -s http://localhost:8080/srv/config/all\?service-profile\=dev |
| 104 | +``` |
| 105 | + |
| 106 | +Example of data returned: |
| 107 | + |
| 108 | +```json |
| 109 | +[ |
| 110 | + { |
| 111 | + "name": "atael", |
| 112 | + "label": "latest", |
| 113 | + "profile": "dev" |
| 114 | + } |
| 115 | +] |
| 116 | +``` |
| 117 | + |
| 118 | +#### /srv/config/properties?service-name=\<service-name\> |
| 119 | + |
| 120 | +Get all properties for a service-name (application): |
| 121 | + |
| 122 | +```shell |
| 123 | +curl -s http://localhost:8080/srv/config/properties\?service-name\=application-a |
| 124 | +``` |
| 125 | + |
| 126 | +Example of data returned: |
| 127 | + |
| 128 | +```json |
| 129 | +[ |
| 130 | + { |
| 131 | + "id": 3, |
| 132 | + "application": "application-a", |
| 133 | + "profile": "production", |
| 134 | + "label": "12c", |
| 135 | + "propKey": "db-name", |
| 136 | + "value": "databasename-a-prod", |
| 137 | + "createdOn": "2023-10-19T16:50:07.000+00:00", |
| 138 | + "createdBy": "ADMIN" |
| 139 | + }, |
| 140 | + { |
| 141 | + "id": 4, |
| 142 | + "application": "application-a", |
| 143 | + "profile": "production", |
| 144 | + "label": "12c", |
| 145 | + "propKey": "db-connection", |
| 146 | + "value": "connectionstring-a-prod", |
| 147 | + "createdOn": "2023-10-19T16:50:07.000+00:00", |
| 148 | + "createdBy": "ADMIN" |
| 149 | + }, |
| 150 | + { |
| 151 | + "id": 5, |
| 152 | + "application": "application-a", |
| 153 | + "profile": "development", |
| 154 | + "label": "23cbeta", |
| 155 | + "propKey": "db-dev-name", |
| 156 | + "value": "databasename-a-dev", |
| 157 | + "createdOn": "2023-10-19T16:50:07.000+00:00", |
| 158 | + "createdBy": "ADMIN" |
| 159 | + }, |
| 160 | + { |
| 161 | + "id": 6, |
| 162 | + "application": "application-a", |
| 163 | + "profile": "development", |
| 164 | + "label": "23cbeta", |
| 165 | + "propKey": "db-dev-connection", |
| 166 | + "value": "connectionstring-a-dev", |
| 167 | + "createdOn": "2023-10-19T16:50:07.000+00:00", |
| 168 | + "createdBy": "ADMIN" |
| 169 | + } |
| 170 | +] |
| 171 | +``` |
| 172 | + |
| 173 | +#### /srv/config/properties?service-name=\<service-name\>&service-label=\<service-label\> |
| 174 | + |
| 175 | +Get all properties for a service-name (application) filtered on service-label (label): |
| 176 | + |
| 177 | +```shell |
| 178 | +curl -s http://localhost:8080/srv/config/properties\?service-name\=application-b\&service-label\=19c |
| 179 | +``` |
| 180 | + |
| 181 | +Example of data returned: |
| 182 | + |
| 183 | +```json |
| 184 | +[ |
| 185 | + { |
| 186 | + "id": 7, |
| 187 | + "application": "application-b", |
| 188 | + "profile": "production", |
| 189 | + "label": "19c", |
| 190 | + "propKey": "db-name", |
| 191 | + "value": "databasename-b-prod", |
| 192 | + "createdOn": "2023-10-19T16:50:07.000+00:00", |
| 193 | + "createdBy": "ADMIN" |
| 194 | + }, |
| 195 | + { |
| 196 | + "id": 8, |
| 197 | + "application": "application-b", |
| 198 | + "profile": "production", |
| 199 | + "label": "19c", |
| 200 | + "propKey": "db-connection", |
| 201 | + "value": "connectionstring-b-prod", |
| 202 | + "createdOn": "2023-10-19T16:50:07.000+00:00", |
| 203 | + "createdBy": "ADMIN" |
| 204 | + } |
| 205 | +] |
| 206 | +``` |
| 207 | + |
| 208 | +#### /srv/config/properties?service-name=\<service-name\>&service-label=\<service-label\>&service-profile=\<service-profile\> |
| 209 | + |
| 210 | +Get all properties for a service-name (application) filtered on service-label (label) and service-profile (profile): |
| 211 | + |
| 212 | +```shell |
| 213 | +curl -s http://localhost:8080/srv/config/properties\?service-name\=application-b\&service-label\=19c\&service-profile\=production |
| 214 | +``` |
| 215 | + |
| 216 | +Example of data returned: |
| 217 | + |
| 218 | +```json |
| 219 | +[ |
| 220 | + { |
| 221 | + "id": 7, |
| 222 | + "application": "application-b", |
| 223 | + "profile": "production", |
| 224 | + "label": "19c", |
| 225 | + "propKey": "db-name", |
| 226 | + "value": "databasename-b-prod", |
| 227 | + "createdOn": "2023-10-19T16:50:07.000+00:00", |
| 228 | + "createdBy": "ADMIN" |
| 229 | + }, |
| 230 | + { |
| 231 | + "id": 8, |
| 232 | + "application": "application-b", |
| 233 | + "profile": "production", |
| 234 | + "label": "19c", |
| 235 | + "propKey": "db-connection", |
| 236 | + "value": "connectionstring-b-prod", |
| 237 | + "createdOn": "2023-10-19T16:50:07.000+00:00", |
| 238 | + "createdBy": "ADMIN" |
| 239 | + } |
| 240 | +] |
| 241 | +``` |
| 242 | + |
| 243 | +#### /srv/config/properties?service-name=\<service-name\>&service-label=\<service-label\>&service-profile=\<service-profile\>&property-key=\<property-key\> |
| 244 | + |
| 245 | +Get all properties for a service-name (application) filtered on service-label (label), service-profile (profile) and property-key (prop_key): |
| 246 | + |
| 247 | +```shell |
| 248 | +curl -s http://localhost:8080/srv/config/properties\?service-name\=application-c\&service-label\=23.4\&service-profile\=secret\&property-key\=txeventq |
| 249 | +``` |
| 250 | + |
| 251 | +Example of data returned: |
| 252 | + |
| 253 | +```json |
| 254 | +[ |
| 255 | + { |
| 256 | + "id": 14, |
| 257 | + "application": "application-c", |
| 258 | + "profile": "secret", |
| 259 | + "label": "23.4", |
| 260 | + "propKey": "txeventq", |
| 261 | + "value": "23c-kafka-name", |
| 262 | + "createdOn": "2023-10-19T16:50:07.000+00:00", |
| 263 | + "createdBy": "ADMIN" |
| 264 | + } |
| 265 | +] |
| 266 | +``` |
| 267 | + |
| 268 | +#### /srv/config/property/add |
| 269 | + |
| 270 | +Create a property: |
| 271 | + |
| 272 | +```shell |
| 273 | +curl -u <username>:<password> -s -X POST \ |
| 274 | + -d "service-name=application-d&service-label=1.0&service-profile=AI&property-key=url-to-host&property-value=hostname" \ |
| 275 | + http://localhost:8080/srv/config/property/add |
| 276 | +``` |
| 277 | + |
| 278 | +Successful creation of a property returns: |
| 279 | + |
| 280 | +```text |
| 281 | +Property added successfully. |
| 282 | +``` |
| 283 | + |
| 284 | +#### /srv/config/property/update |
| 285 | + |
| 286 | +Update a property: |
| 287 | + |
| 288 | +```shell |
| 289 | +curl -u <username>:<password> -s -X PUT \ |
| 290 | + -d "service-name=application-d&service-label=1.0&service-profile=AI&property-key=url-to-host&property-value=new-hostname" \ |
| 291 | + http://localhost:8080/srv/config/property/update |
| 292 | +``` |
| 293 | + |
| 294 | +Successful update of a property returns: |
| 295 | + |
| 296 | +```text |
| 297 | +Property successfully modified. |
| 298 | +``` |
| 299 | + |
| 300 | +#### /srv/config/properties/delete?service-name\<service-name\> |
| 301 | + |
| 302 | +Delete all properties from a service (application): |
| 303 | + |
| 304 | +```Shell |
| 305 | +curl -u <username>:<password> -s -X DELETE http://localhost:8080/srv/config/properties/delete\?service-name\=atael |
| 306 | +``` |
| 307 | + |
| 308 | +Successful deletion of properties returns: |
| 309 | + |
| 310 | +```text |
| 311 | +Properties successfully deleted. |
| 312 | +``` |
| 313 | + |
| 314 | +#### /srv/config/delete?service-profile=\<profile-name\>&service-profile=\<service-profile\> |
| 315 | + |
| 316 | +Delete all properties with a service profile: |
| 317 | + |
| 318 | +```Shell |
| 319 | +curl -u <username>:<password> -s -X DELETE http://localhost:8080/srv/config/properties/delete\?service-name\=application-d\&service-profile\=AI |
| 320 | +``` |
| 321 | + |
| 322 | +Successful deletion of properties returns: |
| 323 | + |
| 324 | +```text |
| 325 | +Properties successfully deleted. |
| 326 | +``` |
| 327 | + |
| 328 | +#### /srv/config/delete?service-profile=\<profile-name\>&service-profile=\<service-profile\>&service-label=\<service-label\> |
| 329 | + |
| 330 | +Delete all properties from a service with a profile and a label: |
| 331 | + |
| 332 | +```Shell |
| 333 | +curl -u <username>:<password> -s -X DELETE http://localhost:8080/srv/config/properties/delete\?service-name\=application-a\&service-profile\=development\&service-label\=12c |
| 334 | +``` |
| 335 | + |
| 336 | +Successful deletion of properties returns: |
| 337 | + |
| 338 | +```text |
| 339 | +Properties successfully deleted. |
| 340 | +``` |
| 341 | + |
| 342 | +#### /srv/config/delete?service-profile=\<profile-name\>&service-profile=\<service-profile\>&service-label=\<service-label\>&property-key=\<property-key\> |
| 343 | + |
| 344 | +Delete all properties from a service with a profile and a label: |
| 345 | + |
| 346 | +```Shell |
| 347 | +curl -u <username>:<password> -s -X DELETE http://localhost:8080/srv/config/properties/delete\?service-name\=application-b\&service-profile\=development\&service-label\=23cbeta\&property-key\=db-dev-name |
| 348 | +``` |
| 349 | + |
| 350 | +Successful deletion of properties returns: |
| 351 | + |
| 352 | +```text |
| 353 | +Properties successfully deleted. |
| 354 | +``` |
| 355 | + |
| 356 | +## Re-create test data |
| 357 | + |
| 358 | +The Config Server data can be created using the following SQL statements: |
| 359 | + |
| 360 | +```sql |
| 361 | +INSERT INTO CONFIGSERVER.PROPERTIES (APPLICATION, PROFILE, LABEL, PROP_KEY, VALUE) VALUES ('atael','dev','latest','test-property','This is the test-property value'); |
| 362 | +INSERT INTO CONFIGSERVER.PROPERTIES (APPLICATION, PROFILE, LABEL, PROP_KEY, VALUE) VALUES ('atael','dev','latest','test-property-2','This is the test-property-2 value'); |
| 363 | +INSERT INTO CONFIGSERVER.PROPERTIES (APPLICATION, PROFILE, LABEL, PROP_KEY, VALUE) VALUES ('application-a','production','12c','db-name','databasename-a-prod'); |
| 364 | +INSERT INTO CONFIGSERVER.PROPERTIES (APPLICATION, PROFILE, LABEL, PROP_KEY, VALUE) VALUES ('application-a','production','12c','db-connection','connectionstring-a-prod'); |
| 365 | +INSERT INTO CONFIGSERVER.PROPERTIES (APPLICATION, PROFILE, LABEL, PROP_KEY, VALUE) VALUES ('application-a','development','23cbeta','db-dev-name','databasename-a-dev'); |
| 366 | +INSERT INTO CONFIGSERVER.PROPERTIES (APPLICATION, PROFILE, LABEL, PROP_KEY, VALUE) VALUES ('application-a','development','23cbeta','db-dev-connection','connectionstring-a-dev'); |
| 367 | +INSERT INTO CONFIGSERVER.PROPERTIES (APPLICATION, PROFILE, LABEL, PROP_KEY, VALUE) VALUES ('application-b','production','19c','db-name','databasename-b-prod'); |
| 368 | +INSERT INTO CONFIGSERVER.PROPERTIES (APPLICATION, PROFILE, LABEL, PROP_KEY, VALUE) VALUES ('application-b','production','19c','db-connection','connectionstring-b-prod'); |
| 369 | +INSERT INTO CONFIGSERVER.PROPERTIES (APPLICATION, PROFILE, LABEL, PROP_KEY, VALUE) VALUES ('application-b','development','23cbeta','db-dev-name','databasename-b-dev'); |
| 370 | +INSERT INTO CONFIGSERVER.PROPERTIES (APPLICATION, PROFILE, LABEL, PROP_KEY, VALUE) VALUES ('application-b','development','23cbeta','db-dev-connection','connectionstring-b-dev'); |
| 371 | +INSERT INTO CONFIGSERVER.PROPERTIES (APPLICATION, PROFILE, LABEL, PROP_KEY, VALUE) VALUES ('application-c','secret','23.4','json-db','23c-json-db'); |
| 372 | +INSERT INTO CONFIGSERVER.PROPERTIES (APPLICATION, PROFILE, LABEL, PROP_KEY, VALUE) VALUES ('application-c','secret','23.4','json-sdb-conn','23c-mongo-conn'); |
| 373 | +INSERT INTO CONFIGSERVER.PROPERTIES (APPLICATION, PROFILE, LABEL, PROP_KEY, VALUE) VALUES ('application-c','secret','23.4','txenventq','23c-conn-string'); |
| 374 | +INSERT INTO CONFIGSERVER.PROPERTIES (APPLICATION, PROFILE, LABEL, PROP_KEY, VALUE) VALUES ('application-c','secret','23.4','txeventq','23c-kafka-name'); |
| 375 | +``` |
0 commit comments