0

I am using Spring Cloud Connector to bind to databases. Is there any way to get the plan of the bound service? When I extend an AbstractCloudConfig and do

cloud().getSingletonServiceInfosByType(PostgresqlServiceInfo.class)...

I will have information on the url and how to connect to the postgres. PostgresqlServiceInfo and others do not carry along the plan data. How can I extend the service info, in order to read this information form VCAP_SERVICES?

Thanks

Benny
  • 1,435
  • 1
  • 15
  • 33

1 Answers1

0

By design, the ServiceInfo classes in Spring Cloud Connectors carry just enough information to create the connection beans necessary for an app to consume the service resources. Connectors was designed to be platform-neutral, and fields like plan, label, and tags that are available on Cloud Foundry are not captured because they might not be available on other platforms (e.g. Heroku).

To add the plan information to a ServiceInfo, you'd need to write your own ServiceInfo class that includes a field for the value, then write a CloudFoundryServiceInfoCreator to populate the value from the VCAP_SERVICES data that the framework provides as a Map. See the project documentation for more information on creating such an extension.

Another (likely easier) option is to use the newer java-cfenv project instead of Spring Cloud Connectors. java-cfenv supports Cloud Foundry only, and gives access to the full set of information in VCAP_SERVICES. See the project documentation for an example of how you can use this library.

Scott Frederick
  • 4,184
  • 19
  • 22
  • Hi Scott, I thought about pretty much the same (for extending Cloud Connector). Problem is, that the creators are maintained in a list and the first that accepts the data (service info creator `accept` method) will be used. Not sure, if custom ones are prefered, or this can lead to a race condition? – Benny Mar 14 '19 at 14:48
  • The methods in the `Cloud` class like the one mentioned in your post will return a list of all `ServiceInfo`s that match the provided criteria (e.g. service name or `ServiceInfo` type). These methods should return both the built-in `PostgresqlServiceInfo` and any custom `ServiceInfo`s that also match via `accept`). If you want to use `connectionFactory` from `AbstractCloudConfig` to get a `DataSource` Bean, you'd also need to write a custom `ServiceConnectorCreator` that looks a lot like `PostgresqlDataSourceCreator` but uses your custom `ServiceInfo` type for selection. – Scott Frederick Mar 15 '19 at 17:03