Unable to retrieve VCAP_SERVICES environment variable after binding to a service

824 views
Skip to first unread message

Dave Chen

unread,
Mar 14, 2015, 7:47:11 PM3/14/15
to vcap...@cloudfoundry.org
Hi,

I am following the this wiki: http://docs.cloudfoundry.org/buildpacks/java/spring-service-bindings.html to read the VCAP_SERVICES environment variable.

We have a custom service (mk_service) which is deployed to marketplace. I bind my app to the mk_service however I am unable to retrieve the property cloud.services.{service-name}.connection.uri from the cf vcap_service. The value I am getting back is NULL.

Here is what I did:

cf cs 'mk_service' 'Basic ACS Plan' dave-service
cf push dave-sample-app -p target/springmvc-api-sample-2.0.0-SNAPSHOT.jar
cf bs dave-sample-app dave-service
cf restart dave-sample-app

When I do:
cf env dave-sample-app

I see this, the uri is showing in the
VCAP_SERVICE
System-Provided: {
"VCAP_SERVICES": { "mk_service": [ { "credentials": { "uri": "http://my-stating.ice.ge.com" }, "label": "mk_service", "name": "dave-service", "plan": "Basic ACS Plan", "tags": [] } ],
Below is the code snippet I use to retrieve the uri value

       CloudFactory cloudFactory = new CloudFactory();

        Cloud cloud = cloudFactory.getCloud();

        Properties cloudProperties = cloud.getCloudProperties();

        System.out.println(cloudProperties.getProperty("cloud.services.dave-service.connection.uri"));


I dig more into it and find out somehow the cloudProperties are not return the "cloud.services.dave-service.connection.uri" property. The cloudProperties only contains the "cloud.services.dave-service.id".

Does anyone know what I am missing?


Thanks,

Dave


Josh Ghiloni

unread,
Mar 14, 2015, 10:24:41 PM3/14/15
to vcap...@cloudfoundry.org
try cloud.services.dave-service.credentials.uri. I think the "connection" segment was just a typo.

--
You received this message because you are subscribed to the Google Groups "Cloud Foundry Developers" group.
To view this discussion on the web visit https://groups.google.com/a/cloudfoundry.org/d/msgid/vcap-dev/6ebc7289-e432-495a-83b4-38114d77aebf%40cloudfoundry.org.

To unsubscribe from this group and stop receiving emails from it, send an email to vcap-dev+u...@cloudfoundry.org.

Dave Chen

unread,
Mar 15, 2015, 12:32:59 AM3/15/15
to vcap...@cloudfoundry.org
Hi Josh,

Thanks for the reply, I tried cloud.services.dave-service.credentials.uri it did not work either. The problem I think is the uri is not returning from cloud.getCloudProperties(). 
Below is the list of the keys from  cloud.getCloudProperties():

2015-03-14T21:26:27.02-0700 [App/0]   OUT cloud.application.state_timestamp

2015-03-14T21:26:27.02-0700 [App/0]   OUT cloud.application.uris

2015-03-14T21:26:27.02-0700 [App/0]   OUT cloud.application.limits

2015-03-14T21:26:27.02-0700 [App/0]   OUT cloud.application.version

2015-03-14T21:26:27.02-0700 [App/0]   OUT cloud.application.name

2015-03-14T21:26:27.02-0700 [App/0]   OUT cloud.application.application_id

2015-03-14T21:26:27.02-0700 [App/0]   OUT cloud.application.application_uris

2015-03-14T21:26:27.02-0700 [App/0]   OUT cloud.application.started_at_timestamp

2015-03-14T21:26:27.02-0700 [App/0]   OUT cloud.application.instance_id

2015-03-14T21:26:27.02-0700 [App/0]   OUT cloud.application.space_name

2015-03-14T21:26:27.02-0700 [App/0]   OUT cloud.application.application_name

2015-03-14T21:26:27.02-0700 [App/0]   OUT cloud.application.application_version

2015-03-14T21:26:27.02-0700 [App/0]   OUT cloud.services.null.id

2015-03-14T21:26:27.02-0700 [App/0]   OUT cloud.application.started_at

2015-03-14T21:26:27.02-0700 [App/0]   OUT cloud.application.start

2015-03-14T21:26:27.03-0700 [App/0]   OUT cloud.application.port

2015-03-14T21:26:27.03-0700 [App/0]   OUT cloud.application.instance-id

2015-03-14T21:26:27.03-0700 [App/0]   OUT cloud.services.dave-service.id

2015-03-14T21:26:27.03-0700 [App/0]   OUT cloud.application.host

2015-03-14T21:26:27.03-0700 [App/0]   OUT cloud.application.app-id

2015-03-14T21:26:27.03-0700 [App/0]   OUT cloud.application.instance_index

2015-03-14T21:26:27.03-0700 [App/0]   OUT cloud.application.space_id

Dave Chen

unread,
Mar 15, 2015, 12:36:11 AM3/15/15
to vcap...@cloudfoundry.org
And this the section from the cloud foundry wiki: http://docs.cloudfoundry.org/buildpacks/java/spring-service-bindings.html

If the service exposed the credentials as a single uri field, then the following properties would be set up:

cloud.services.my-postgres.connection.uri
cloud.services.my-postgres.plan
cloud.services.my-postgres.type

Josh Ghiloni

unread,
Mar 15, 2015, 5:21:45 PM3/15/15
to vcap...@cloudfoundry.org
Do you have a service info creator for that service type? It might be easier to just do System.getenv("VCAP_SERVICES") and parse it manually.

Shannon Coen

unread,
Mar 16, 2015, 10:49:21 AM3/16/15
to vcap...@cloudfoundry.org
Did you restage your app after binding? This must be done in order for the env vars to be updated in the app container.

Dave Chen

unread,
Mar 17, 2015, 8:43:43 PM3/17/15
to vcap...@cloudfoundry.org
Hi Josh,

Yes, that's the problem. We need to add a ServiceInfo creator for our service.

Thanks,
Dave
Reply all
Reply to author
Forward
0 new messages