From 34f78e42cdf6d715042055238dc5f4d95aba94c6 Mon Sep 17 00:00:00 2001 From: Scott Frederick Date: Tue, 10 Apr 2018 20:31:55 -0500 Subject: [PATCH] Update sample application. (#23) * Update sample application. * Bump CF Java Client version to 3.9.0. --- pom.xml | 2 +- .../hi-service.groovy | 4 ++-- .../sample/CloudFoundryApplication.java | 24 ++++++++++++++----- .../src/main/resources/application.properties | 4 ---- .../src/main/resources/application.yaml | 9 +++++++ 5 files changed, 30 insertions(+), 13 deletions(-) delete mode 100644 spring-cloud-cloudfoundry-sample/src/main/resources/application.properties create mode 100644 spring-cloud-cloudfoundry-sample/src/main/resources/application.yaml diff --git a/pom.xml b/pom.xml index d39a235..5357d51 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ - 3.3.0.RELEASE + 3.9.0.RELEASE cloudfoundry ${basedir} 2.0.0.BUILD-SNAPSHOT diff --git a/spring-cloud-cloudfoundry-sample/hi-service.groovy b/spring-cloud-cloudfoundry-sample/hi-service.groovy index d70fb6b..05babba 100644 --- a/spring-cloud-cloudfoundry-sample/hi-service.groovy +++ b/spring-cloud-cloudfoundry-sample/hi-service.groovy @@ -1,7 +1,7 @@ -// to run on ur local machine this use: +// to run locally use: // spring run hi-service.groovy // -// to deploy this to Cloud Foundry, use +// to deploy to Cloud Foundry use: // spring jar hi.jar hi-service.groovy // cf push hi-service -p hi.jar diff --git a/spring-cloud-cloudfoundry-sample/src/main/java/org/springframework/cloud/cloudfoundry/sample/CloudFoundryApplication.java b/spring-cloud-cloudfoundry-sample/src/main/java/org/springframework/cloud/cloudfoundry/sample/CloudFoundryApplication.java index 2c6b53f..173a868 100644 --- a/spring-cloud-cloudfoundry-sample/src/main/java/org/springframework/cloud/cloudfoundry/sample/CloudFoundryApplication.java +++ b/spring-cloud-cloudfoundry-sample/src/main/java/org/springframework/cloud/cloudfoundry/sample/CloudFoundryApplication.java @@ -26,15 +26,27 @@ import org.springframework.cloud.cloudfoundry.discovery.EnableCloudFoundryClient import org.springframework.context.annotation.Bean; /** - * This example assumes you've registered an application on - * Cloud Foundry named {@code hi-service} that - * responds with a String at {@code /hi/ name} . There is a sample file in the project - * root called {@code hi-service.groovy} which you can deploy using the {@code spring} CLI - * and the {@code cf} CLI that works appropriately for this demonstration. + * This example uses the Spring Cloud {@code DiscoveryClient} abstraction to list all services + * available to the application. It should deployed to a Cloud Foundry organization and space that + * has other applications deployed to it. + * + * There is a sample file in the project root called {@code hi-service.groovy} which can be + * deployed using the {@code spring} CLI and the {@code cf} CLI that works appropriately for + * this example. + * + * Either modify this application's {@code application.yml} configuration file to provide credentials + * and other information for the Cloud Foundry the app is deployed to, or set the following + * environment variables on the application (using {@code cf set-env}): + * + * * {@code CF_USERNAME} + * * {@code CF_PASSWORD} + * * {@code CF_ORG} + * * {@code CF_SPACE} * * @author Josh Long * @author Spencer Gibb * @author Dave Syer + * @author Scott Frederick */ @SpringBootApplication @EnableCloudFoundryClient @@ -50,7 +62,7 @@ public class CloudFoundryApplication { return args -> discoveryClient.getServices().forEach(svc -> { log.info("service = " + svc); - discoveryClient.getInstances(svc).forEach(si -> log.info("\t" + si)); + discoveryClient.getInstances(svc).forEach(si -> log.info("\tinstance = " + si)); }); } } diff --git a/spring-cloud-cloudfoundry-sample/src/main/resources/application.properties b/spring-cloud-cloudfoundry-sample/src/main/resources/application.properties deleted file mode 100644 index a197c9a..0000000 --- a/spring-cloud-cloudfoundry-sample/src/main/resources/application.properties +++ /dev/null @@ -1,4 +0,0 @@ -spring.application.name=test-app -spring.cloud.cloudfoundry.discovery.email=${email:starbuxman@gmail.com} -spring.cloud.cloudfoundry.discovery.password=${password:xxxx} -VCAP_APPLICATION={"limits":{"mem":1024,"disk":1024,"fds":16384},"application_version":"36eff082-96d6-498f-8214-508fda72ba65","application_name":"hi-service","application_uris":["hi-service.cfapps.io"],"version":"36eff082-96d6-498f-8214-508fda72ba65","name":"hi-service","space_name":"joshlong","space_id":"e0cd969c-3461-41ae-abde-4e11bb5acbd1","uris":["hi-service.cfapps.io"],"users":null,"application_id":"af350f7c-88c4-4e35-a04e-698a1dbc7354","instance_id":"e4843ca23bd947b28e6d4cb3f9b92cbb","instance_index":0,"host":"0.0.0.0","port":61590,"started_at":"2015-05-07 20:00:10 +0000","started_at_timestamp":1431028810,"start":"2015-05-07 20:00:10 +0000","state_timestamp":1431028810} \ No newline at end of file diff --git a/spring-cloud-cloudfoundry-sample/src/main/resources/application.yaml b/spring-cloud-cloudfoundry-sample/src/main/resources/application.yaml new file mode 100644 index 0000000..c814d81 --- /dev/null +++ b/spring-cloud-cloudfoundry-sample/src/main/resources/application.yaml @@ -0,0 +1,9 @@ +spring: + application: + name: test-app + cloud: + cloudfoundry: + username: ${CF_USERNAME:starbuxman@gmail.com} + password: ${CF_PASSWORD:xxxx} + org: ${CF_ORG:} + space: ${CF_SPACE:} \ No newline at end of file