Pivotal Cloud Foundry
(PCF) recently turned five-years-old. In celebration, Onsi Fakhouri reflects on how far the platform has come, and provides a look at our
plans for the months and years ahead.
The Pivotal Blog post exists here:
https://content.pivotal.io/blog/any-app-every-cloud-one-platform-delivering-on-pivotal-s-vision
Search This Blog
Showing posts with label PCF. Show all posts
Showing posts with label PCF. Show all posts
Thursday, 2 May 2019
Wednesday, 4 April 2018
Install Pivotal Container Service (PKS) on GCP and getting started
With the release of Pivotal Cloud Foundry 2.1 (PCF) I decided this time to install Pivotal Application Service (PAS) as well as Pivotal Container Service (PKS) using the one Bosh Director which isn't recommended for production installs BUT ok for dev installs. Once installed you will have both the PAS tile and PKS tile as shown below.
https://content.pivotal.io/blog/pivotal-cloud-foundry-2-1-adds-cloud-native-net-envoy-native-service-discovery-to-boost-your-transformation
So here is how to get started with PKS once it's installed
1. Create a user for the PKS client to login with.
1.1. ssh into the ops manager VM
1.2. Target the UAA endpoint for PKS this was setup in the PKS tile
ubuntu@opsman-pcf:~$ uaac target https://PKS-ENDPOINT:8443 --skip-ssl-validation
Unknown key: Max-Age = 86400
Target: https://PKS-ENDPOINT:8443
More Info
https://docs.pivotal.io/runtimes/pks/1-0/index.html
https://content.pivotal.io/blog/pivotal-cloud-foundry-2-1-adds-cloud-native-net-envoy-native-service-discovery-to-boost-your-transformation
So here is how to get started with PKS once it's installed
1. Create a user for the PKS client to login with.
1.1. ssh into the ops manager VM
1.2. Target the UAA endpoint for PKS this was setup in the PKS tile
ubuntu@opsman-pcf:~$ uaac target https://PKS-ENDPOINT:8443 --skip-ssl-validation
Unknown key: Max-Age = 86400
Target: https://PKS-ENDPOINT:8443
1.3. Authenticate with UAA using the secret you retrieve from the PKS tile / Credentials tab as shown in the image below. Run the following command, replacing UAA-ADMIN-SECRET with your UAA admin secret
ubuntu@opsman-pcf:~$ uaac token client get admin -s UAA-ADMIN-SECRET
Unknown key: Max-Age = 86400
Successfully fetched token via client credentials grant.
Target: https://PKS-ENDPIONT:8443
Context: admin, from client admin
1.4. Create an ADMIN user as shown below using the UAA-ADMIN-SECRET password obtained form ops manager UI as shown above
ubuntu@opsman-pcf:~$ uaac user add pas --emails papicella@pivotal.io -p PASSWD
user account successfully added
ubuntu@opsman-pcf:~$ uaac member add pks.clusters.admin pas
success
2. Now lets login using the PKS CLI with a new admin user we created
pasapicella@pas-macbook:~$ pks login -a PKS-ENDPOINT -u pas -p PASSWD -k
API Endpoint: pks-api.pks.pas-apples.online
User: pas
3. You can test whether you have a DNS issue with a command as follows.
Note: A test as follows determines any DNS issues you may have
pasapicella@pas-macbook:~$ nc -vz PKS-ENDPOINT 8443
found 0 associations
found 1 connections:
1: flags=82
outif en0
src 192.168.1.111 port 62124
dst 35.189.1.209 port 8443
rank info not available
TCP aux info available
Connection to PKS-ENDPOINT port 8443 [tcp/pcsync-https] succeeded!
4. You can run a simple command to verify your connected as follows, below shows no K8's clusters exist at this stage
pasapicella@pas-macbook:~$ pks list-clusters
Name Plan Name UUID Status Action
You can use PKS CLI to create a new cluster, view clusters, resize clusters etc
pasapicella@pas-macbook:~$ pks
The Pivotal Container Service (PKS) CLI is used to create, manage, and delete Kubernetes clusters. To deploy workloads to a Kubernetes cluster created using the PKS CLI, use the Kubernetes CLI, kubectl.
Version: 1.0.0-build.3
Note: The PKS CLI is under development, and is subject to change at any time.
Usage:
pks [command]
Available Commands:
cluster View the details of the cluster
clusters Show all clusters created with PKS
create-cluster Creates a kubernetes cluster, requires cluster name and an external host name
delete-cluster Deletes a kubernetes cluster, requires cluster name
get-credentials Allows you to connect to a cluster and use kubectl
help Help about any command
login Login to PKS
logout Logs user out of the PKS API
plans View the preconfigured plans available
resize Increases the number of worker nodes for a cluster
Flags:
-h, --help help for pks
--version version for pks
Use "pks [command] --help" for more information about a command.
5. You would create a cluster as follows now you have logged in and yu will get aK8's cluster to begin working with
pasapicella@pas-macbook:~$ pks create-cluster my-cluster --external-hostname EXT-LB-HOST --plan small
Name: my-cluster
Plan Name: small
UUID: 64a086ce-c94f-4c51-95f8-5a5edb3d1476
Last Action: CREATE
Last Action State: in progress
Last Action Description: Creating cluster
Kubernetes Master Host: cluster1.FQDN
Kubernetes Master Port: 8443
Worker Instances: 3
Kubernetes Master IP(s): In Progress
Finally when done you will see "Last Action:" as "succeeded" as shown below
pasapicella@pas-macbook:~$ pks cluster my-cluster
Name: my-cluster
Plan Name: small
UUID: 64a086ce-c94f-4c51-95f8-5a5edb3d1476
Last Action: CREATE
Last Action State: succeeded
Last Action Description: Instance provisioning completed
Kubernetes Master Host: cluster1.FQDN
Kubernetes Master Port: 8443
Worker Instances: 3
Kubernetes Master IP(s): MASTER-IP-ADDRESS
https://docs.pivotal.io/runtimes/pks/1-0/index.html
Thursday, 17 November 2016
Installing Pivotal Cloud Foundry (PCF) on Google Cloud Platform (GCP)
I decided to install PCF 1.8 onto Google Cloud Platform today and I thought the experience was fantastic and very straight forward. The GCP Console is fantastic and very powerful indeed. The steps to install it are as follows
http://docs.pivotal.io/pivotalcf/1-8/customizing/gcp.html
Here are some screen shots you would expect to see along the way when using Operations Manager
Screen Shots
Finally Once Installed here is how to create an ORG, USER and get started using the CLI. You will note you must log in as ADMIN to get started and finally I log in as the user who will be the OrgManager.
** Target my PCF Instance **
pasapicella@pas-macbook:~/pivotal/GCP/install$ cf api https://api.system.pas-apples.online --skip-ssl-validation
Setting api endpoint to https://api.system.pas-apples.online...
OK
API endpoint: https://api.system.pas-apples.online (API version: 2.58.0)
Not logged in. Use 'cf login' to log in.
** Login as ADMIN **
pasapicella@pas-macbook:~/pivotal/GCP/install$ cf login -u admin -p YYYY -o system -s system
API endpoint: https://api.system.pas-apples.online
Authenticating...
OK
Targeted org system
Targeted space system
API endpoint: https://api.system.pas-apples.online (API version: 2.58.0)
User: admin
Org: system
Space: system
** Create Org **
pasapicella@pas-macbook:~/pivotal/GCP/install$ cf create-org gcp-pcf-org
Creating org gcp-pcf-org as admin...
OK
Assigning role OrgManager to user admin in org gcp-pcf-org ...
OK
TIP: Use 'cf target -o gcp-pcf-org' to target new org
** Create a USER **
pasapicella@pas-macbook:~/pivotal/GCP/install$ cf create-user pas YYYY
Creating user pas...
OK
TIP: Assign roles with 'cf set-org-role' and 'cf set-space-role'
** Set ORG Role **
pasapicella@pas-macbook:~/pivotal/GCP/install$ cf set-org-role pas gcp-pcf-org OrgManager
Assigning role OrgManager to user pas in org gcp-pcf-org as admin...
OK
** Target the newly created ORG **
pasapicella@pas-macbook:~/pivotal/GCP/install$ cf target -o gcp-pcf-org
API endpoint: https://api.system.pas-apples.online (API version: 2.58.0)
User: admin
Org: gcp-pcf-org
Space: No space targeted, use 'cf target -s SPACE'
** Create a SPACE **
pasapicella@pas-macbook:~/pivotal/GCP/install$ cf create-space development
Creating space development in org gcp-pcf-org as admin...
OK
Assigning role RoleSpaceManager to user admin in org gcp-pcf-org / space development as admin...
OK
Assigning role RoleSpaceDeveloper to user admin in org gcp-pcf-org / space development as admin...
OK
TIP: Use 'cf target -o "gcp-pcf-org" -s "development"' to target new space
** Set Some Space Roles **
pasapicella@pas-macbook:~/pivotal/GCP/install$ cf set-space-role pas gcp-pcf-org development SpaceDeveloper
Assigning role RoleSpaceDeveloper to user pas in org gcp-pcf-org / space development as admin...
OK
pasapicella@pas-macbook:~/pivotal/GCP/install$ cf set-space-role pas gcp-pcf-org development SpaceManager
Assigning role RoleSpaceManager to user pas in org gcp-pcf-org / space development as admin...
OK
** Login as PAS user and target the correct ORG/SPACE **
pasapicella@pas-macbook:~/pivotal/GCP/install$ cf login -u pas -p YYYY -o gcp-pcf-org -s development
API endpoint: https://api.system.pas-apples.online
Authenticating...
OK
Targeted org gcp-pcf-org
Targeted space development
API endpoint: https://api.system.pas-apples.online (API version: 2.58.0)
User: pas
Org: gcp-pcf-org
Space: development
Lets push a simple application
Application manifest.yml
pasapicella@pas-macbook:~/piv-projects/PivotalSpringBootJPA$ cat manifest-inmemory-db.yml
applications:
- name: pas-albums
memory: 512M
instances: 1
random-route: true
path: ./target/PivotalSpringBootJPA-0.0.1-SNAPSHOT.jar
env:
JAVA_OPTS: -Djava.security.egd=file:///dev/urando
Deploy
pasapicella@pas-macbook:~/piv-projects/PivotalSpringBootJPA$ cf push -f manifest-inmemory-db.yml
Using manifest file manifest-inmemory-db.yml
Creating app pas-albums in org gcp-pcf-org / space development as pas...
OK
Creating route pas-albums-gloomful-synapse.apps.pas-apples.online...
OK
Binding pas-albums-gloomful-synapse.apps.pas-apples.online to pas-albums...
OK
Uploading pas-albums...
Uploading app files from: /var/folders/c3/27vscm613fjb6g8f5jmc2x_w0000gp/T/unzipped-app341113312
Uploading 31.6M, 195 files
Done uploading
OK
Starting app pas-albums in org gcp-pcf-org / space development as pas...
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
1 of 1 instances running
App started
OK
App pas-albums was started using this command `CALCULATED_MEMORY=$($PWD/.java-buildpack/open_jdk_jre/bin/java-buildpack-memory-calculator-2.0.2_RELEASE -memorySizes=metaspace:64m..,stack:228k.. -memoryWeights=heap:65,metaspace:10,native:15,stack:10 -memoryInitials=heap:100%,metaspace:100% -stackThreads=300 -totMemory=$MEMORY_LIMIT) && JAVA_OPTS="-Djava.io.tmpdir=$TMPDIR -XX:OnOutOfMemoryError=$PWD/.java-buildpack/open_jdk_jre/bin/killjava.sh $CALCULATED_MEMORY -Djava.security.egd=file:///dev/urando" && SERVER_PORT=$PORT eval exec $PWD/.java-buildpack/open_jdk_jre/bin/java $JAVA_OPTS -cp $PWD/. org.springframework.boot.loader.JarLauncher`
Showing health and status for app pas-albums in org gcp-pcf-org / space development as pas...
OK
requested state: started
instances: 1/1
usage: 512M x 1 instances
urls: pas-albums-gloomful-synapse.apps.pas-apples.online
last uploaded: Thu Nov 17 03:39:04 UTC 2016
stack: cflinuxfs2
buildpack: java-buildpack=v3.8.1-offline-https://github.com/cloudfoundry/java-buildpack.git#29c79f2 java-main java-opts open-jdk-like-jre=1.8.0_91-unlimited-crypto open-jdk-like-memory-calculator=2.0.2_RELEASE spring-auto-reconfiguration=1.10.0_RELEASE
state since cpu memory disk details
#0 running 2016-11-17 02:39:57 PM 142.6% 333.1M of 512M 161M of 1G
Get Route to Application
pasapicella@pas-macbook:~/piv-projects/PivotalSpringBootJPA$ cf apps
Getting apps in org gcp-pcf-org / space development as pas...
OK
name requested state instances memory disk urls
pas-albums started 1/1 512M 1G pas-albums-gloomful-synapse.apps.pas-apples.online
More Information
https://cloud.google.com/solutions/cloud-foundry-on-gcp
http://docs.pivotal.io/pivotalcf/1-8/customizing/gcp.html
Here are some screen shots you would expect to see along the way when using Operations Manager
Screen Shots
Finally Once Installed here is how to create an ORG, USER and get started using the CLI. You will note you must log in as ADMIN to get started and finally I log in as the user who will be the OrgManager.
** Target my PCF Instance **
pasapicella@pas-macbook:~/pivotal/GCP/install$ cf api https://api.system.pas-apples.online --skip-ssl-validation
Setting api endpoint to https://api.system.pas-apples.online...
OK
API endpoint: https://api.system.pas-apples.online (API version: 2.58.0)
Not logged in. Use 'cf login' to log in.
** Login as ADMIN **
pasapicella@pas-macbook:~/pivotal/GCP/install$ cf login -u admin -p YYYY -o system -s system
API endpoint: https://api.system.pas-apples.online
Authenticating...
OK
Targeted org system
Targeted space system
API endpoint: https://api.system.pas-apples.online (API version: 2.58.0)
User: admin
Org: system
Space: system
** Create Org **
pasapicella@pas-macbook:~/pivotal/GCP/install$ cf create-org gcp-pcf-org
Creating org gcp-pcf-org as admin...
OK
Assigning role OrgManager to user admin in org gcp-pcf-org ...
OK
TIP: Use 'cf target -o gcp-pcf-org' to target new org
** Create a USER **
pasapicella@pas-macbook:~/pivotal/GCP/install$ cf create-user pas YYYY
Creating user pas...
OK
TIP: Assign roles with 'cf set-org-role' and 'cf set-space-role'
** Set ORG Role **
pasapicella@pas-macbook:~/pivotal/GCP/install$ cf set-org-role pas gcp-pcf-org OrgManager
Assigning role OrgManager to user pas in org gcp-pcf-org as admin...
OK
** Target the newly created ORG **
pasapicella@pas-macbook:~/pivotal/GCP/install$ cf target -o gcp-pcf-org
API endpoint: https://api.system.pas-apples.online (API version: 2.58.0)
User: admin
Org: gcp-pcf-org
Space: No space targeted, use 'cf target -s SPACE'
** Create a SPACE **
pasapicella@pas-macbook:~/pivotal/GCP/install$ cf create-space development
Creating space development in org gcp-pcf-org as admin...
OK
Assigning role RoleSpaceManager to user admin in org gcp-pcf-org / space development as admin...
OK
Assigning role RoleSpaceDeveloper to user admin in org gcp-pcf-org / space development as admin...
OK
TIP: Use 'cf target -o "gcp-pcf-org" -s "development"' to target new space
** Set Some Space Roles **
pasapicella@pas-macbook:~/pivotal/GCP/install$ cf set-space-role pas gcp-pcf-org development SpaceDeveloper
Assigning role RoleSpaceDeveloper to user pas in org gcp-pcf-org / space development as admin...
OK
pasapicella@pas-macbook:~/pivotal/GCP/install$ cf set-space-role pas gcp-pcf-org development SpaceManager
Assigning role RoleSpaceManager to user pas in org gcp-pcf-org / space development as admin...
OK
** Login as PAS user and target the correct ORG/SPACE **
pasapicella@pas-macbook:~/pivotal/GCP/install$ cf login -u pas -p YYYY -o gcp-pcf-org -s development
API endpoint: https://api.system.pas-apples.online
Authenticating...
OK
Targeted org gcp-pcf-org
Targeted space development
API endpoint: https://api.system.pas-apples.online (API version: 2.58.0)
User: pas
Org: gcp-pcf-org
Space: development
Lets push a simple application
Application manifest.yml
pasapicella@pas-macbook:~/piv-projects/PivotalSpringBootJPA$ cat manifest-inmemory-db.yml
applications:
- name: pas-albums
memory: 512M
instances: 1
random-route: true
path: ./target/PivotalSpringBootJPA-0.0.1-SNAPSHOT.jar
env:
JAVA_OPTS: -Djava.security.egd=file:///dev/urando
Deploy
pasapicella@pas-macbook:~/piv-projects/PivotalSpringBootJPA$ cf push -f manifest-inmemory-db.yml
Using manifest file manifest-inmemory-db.yml
Creating app pas-albums in org gcp-pcf-org / space development as pas...
OK
Creating route pas-albums-gloomful-synapse.apps.pas-apples.online...
OK
Binding pas-albums-gloomful-synapse.apps.pas-apples.online to pas-albums...
OK
Uploading pas-albums...
Uploading app files from: /var/folders/c3/27vscm613fjb6g8f5jmc2x_w0000gp/T/unzipped-app341113312
Uploading 31.6M, 195 files
Done uploading
OK
Starting app pas-albums in org gcp-pcf-org / space development as pas...
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
1 of 1 instances running
App started
OK
App pas-albums was started using this command `CALCULATED_MEMORY=$($PWD/.java-buildpack/open_jdk_jre/bin/java-buildpack-memory-calculator-2.0.2_RELEASE -memorySizes=metaspace:64m..,stack:228k.. -memoryWeights=heap:65,metaspace:10,native:15,stack:10 -memoryInitials=heap:100%,metaspace:100% -stackThreads=300 -totMemory=$MEMORY_LIMIT) && JAVA_OPTS="-Djava.io.tmpdir=$TMPDIR -XX:OnOutOfMemoryError=$PWD/.java-buildpack/open_jdk_jre/bin/killjava.sh $CALCULATED_MEMORY -Djava.security.egd=file:///dev/urando" && SERVER_PORT=$PORT eval exec $PWD/.java-buildpack/open_jdk_jre/bin/java $JAVA_OPTS -cp $PWD/. org.springframework.boot.loader.JarLauncher`
Showing health and status for app pas-albums in org gcp-pcf-org / space development as pas...
OK
requested state: started
instances: 1/1
usage: 512M x 1 instances
urls: pas-albums-gloomful-synapse.apps.pas-apples.online
last uploaded: Thu Nov 17 03:39:04 UTC 2016
stack: cflinuxfs2
buildpack: java-buildpack=v3.8.1-offline-https://github.com/cloudfoundry/java-buildpack.git#29c79f2 java-main java-opts open-jdk-like-jre=1.8.0_91-unlimited-crypto open-jdk-like-memory-calculator=2.0.2_RELEASE spring-auto-reconfiguration=1.10.0_RELEASE
state since cpu memory disk details
#0 running 2016-11-17 02:39:57 PM 142.6% 333.1M of 512M 161M of 1G
Get Route to Application
pasapicella@pas-macbook:~/piv-projects/PivotalSpringBootJPA$ cf apps
Getting apps in org gcp-pcf-org / space development as pas...
OK
name requested state instances memory disk urls
pas-albums started 1/1 512M 1G pas-albums-gloomful-synapse.apps.pas-apples.online
More Information
https://cloud.google.com/solutions/cloud-foundry-on-gcp
Thursday, 22 September 2016
Using H2 Console in development with Spring Boot then NOT when deployed to Pivotal Cloud Foundry
Frequently when developing Spring based applications, I will use the H2 in memory database during your development process. H2 ships with a web based database console, which you can use while your
application is under development. It is a convenient way to view the
tables created by Hibernate and run queries against the in memory
database. In this post I show what is required to set this up as well as what it means to then deploy your Spring Boot applications to Pivotal Cloud Foundry and rely on a database service and hence your application becomes cloud aware.
1. First ensure you have included the H2 maven dependency as shown below. I also use DevTools BUT thats not needed to enable the H2 web console
application.yml
server:
error:
whitelabel:
enabled: false
spring:
h2:
console:
enabled: true
jpa:
hibernate:
ddl-auto: create
datasource:
url: jdbc:h2:mem:apples;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
username: sa
password:
driver-class-name: org.h2.Driver
platform: h2
3. Run your spring boot application
....
2016-09-22 21:30:26.771 INFO 18929 --- [ restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2016-09-22 21:30:26.778 INFO 18929 --- [ restartedMain] gBootJpaBootstrapEmployeeDemoApplication : Started SpringBootJpaBootstrapEmployeeDemoApplication in 6.021 seconds (JVM running for 6.553)
4. Connect to the H2 we console as follows
http://localhost:8080/h2-console/
The JDBC Url now becomes what you set in the dialog above, inshort the DB name I set was "apples"
When it comes to deployment in Pivotal Cloud Foundry (PCF) you most likely will not want to use H2 and instead bind to a database service like MySQL for example. To do that we would alter our project as follows.
5. Add the following maven dependancies. I add MySQL dependency and you can leave H2 as it will use that if it doesn't finda MySQL service instance to bind to. I also add "spring-boot-starter-cloud-connectors" as it's this which automatically creates and configures a DataSource which injects the service details at Runtime for me.
6. Add a specific cloud application YML file named "application-cloud.yml" as follows. I have left out a datasource and Spring Boot will create that for me when bound to the database service, BUT generally I always set the datasource with the correct properties required to meet my application requirements.
application-cloud.yml
spring:
jpa:
hibernate:
ddl-auto: create
server:
error:
whitelabel:
enabled: false
7. When creating a manifest.yml file to deploy your application to PCF all you need to do is add a MySQL database service and specify the active profile as CLOUD as shown below which will ensure we use the "application-cloud.yml" file we created above.
manifest.yml
---
applications:
- name: springboot-bootstrap-employee
memory: 512M
instances: 1
random-route: true
timeout: 180
path: ./target/springbootjpabootstrapemployeedemo-0.0.1-SNAPSHOT.jar
services:
- pas-mysql
env:
JAVA_OPTS: -Djava.security.egd=file:///dev/urando
SPRING_PROFILES_ACTIVE: cloud
The project in IntelliJ is as follows
GitHub URL as follows:
https://github.com/papicella/SpringBootJPABootstrapEmployeeDemo
1. First ensure you have included the H2 maven dependency as shown below. I also use DevTools BUT thats not needed to enable the H2 web console
<dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> </dependency>2. Then create an specific application.yml file while in development mode only and enable the H2 web console. Using the default name "application.yml"will ensure while your in DEV mode it will use that file. Notice how I give the database a name rather then use the default and also specify a datasource you don't need to go to that effort BUT to me it's good practice to define a datasource because it is what you will do for an application itself when not in DEV mode.
application.yml
server:
error:
whitelabel:
enabled: false
spring:
h2:
console:
enabled: true
jpa:
hibernate:
ddl-auto: create
datasource:
url: jdbc:h2:mem:apples;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
username: sa
password:
driver-class-name: org.h2.Driver
platform: h2
3. Run your spring boot application
....
2016-09-22 21:30:26.771 INFO 18929 --- [ restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2016-09-22 21:30:26.778 INFO 18929 --- [ restartedMain] gBootJpaBootstrapEmployeeDemoApplication : Started SpringBootJpaBootstrapEmployeeDemoApplication in 6.021 seconds (JVM running for 6.553)
http://localhost:8080/h2-console/
The JDBC Url now becomes what you set in the dialog above, inshort the DB name I set was "apples"
When it comes to deployment in Pivotal Cloud Foundry (PCF) you most likely will not want to use H2 and instead bind to a database service like MySQL for example. To do that we would alter our project as follows.
5. Add the following maven dependancies. I add MySQL dependency and you can leave H2 as it will use that if it doesn't finda MySQL service instance to bind to. I also add "spring-boot-starter-cloud-connectors" as it's this which automatically creates and configures a DataSource which injects the service details at Runtime for me.
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cloud-connectors</artifactId> </dependency>
6. Add a specific cloud application YML file named "application-cloud.yml" as follows. I have left out a datasource and Spring Boot will create that for me when bound to the database service, BUT generally I always set the datasource with the correct properties required to meet my application requirements.
application-cloud.yml
spring:
jpa:
hibernate:
ddl-auto: create
server:
error:
whitelabel:
enabled: false
7. When creating a manifest.yml file to deploy your application to PCF all you need to do is add a MySQL database service and specify the active profile as CLOUD as shown below which will ensure we use the "application-cloud.yml" file we created above.
manifest.yml
---
applications:
- name: springboot-bootstrap-employee
memory: 512M
instances: 1
random-route: true
timeout: 180
path: ./target/springbootjpabootstrapemployeedemo-0.0.1-SNAPSHOT.jar
services:
- pas-mysql
env:
JAVA_OPTS: -Djava.security.egd=file:///dev/urando
SPRING_PROFILES_ACTIVE: cloud
The project in IntelliJ is as follows
GitHub URL as follows:
https://github.com/papicella/SpringBootJPABootstrapEmployeeDemo
Sunday, 31 July 2016
PCFDev application accessing an Oracle 11g RDBMS
PCF Dev is a small footprint distribution of Pivotal Cloud Foundry (PCF)
intended to be run locally on a developer machine. It delivers the
essential elements of the Pivotal Cloud Foundry experience quickly
through a condensed set of components. PCF Dev is ideally suited to developers wanting to explore or evaluate
PCF, or those already actively building cloud native applications to be
run on PCF. Working with PCF Dev, developers can experience the power of
PCF - from the accelerated development cycles enabled by consistent,
structured builds to the operational excellence unlocked through
integrated logging, metrics and health monitoring and management.
In this example we show how you can use PCFDev to access an Oracle RDBMS from a PCFDev deployed Spring Boot Application. The application is using the classic Oracle EMP database table found in the SCOTT schema
Source Code as follows
In order to use the steps below you have to have installed PCFDev on your laptop or desktop as per the link below.
Download from here:
Instructions to setup as follows:
Steps
1. Clone as shown below
$ git clone https://github.com/papicella/PCFOracleDemo.git
2. Edit "./PCFOracleDemo/src/main/resources/application.properties" and add your oracle EMP schema connection details
3. Define a local MAVEN repo for Oracle 11g JDBC driver as per what is in the pom.xml
4. Package as per below
$ cd PCFOracleDemo
$ mvn package
5. Deploy as follows
pasapicella@pas-macbook:~/pivotal/DemoProjects/spring-starter/pivotal/PCFOracleDemo$ cf push
Using manifest file /Users/pasapicella/pivotal/DemoProjects/spring-starter/pivotal/PCFOracleDemo/manifest.yml
Creating app springboot-oracle in org pcfdev-org / space pcfdev-space as admin...
OK
Creating route springboot-oracle.local.pcfdev.io...
OK
Binding springboot-oracle.local.pcfdev.io to springboot-oracle...
OK
Uploading springboot-oracle...
Uploading app files from: /var/folders/c3/27vscm613fjb6g8f5jmc2x_w0000gp/T/unzipped-app506692756
Uploading 26.3M, 154 files
Done uploading
OK
Starting app springboot-oracle in org pcfdev-org / space pcfdev-space as admin...
Downloading binary_buildpack...
Downloading python_buildpack...
Downloading staticfile_buildpack...
Downloading java_buildpack...
Downloading php_buildpack...
Downloading ruby_buildpack...
Downloading go_buildpack...
Downloading nodejs_buildpack...
Downloaded staticfile_buildpack
Downloaded binary_buildpack (8.3K)
Downloaded php_buildpack (262.3M)
Downloaded java_buildpack (241.6M)
Downloaded go_buildpack (450.3M)
Downloaded ruby_buildpack (247.7M)
Downloaded python_buildpack (254.1M)
Downloaded nodejs_buildpack (60.7M)
Creating container
Successfully created container
Downloading app package...
Downloaded app package (23.5M)
Staging...
-----> Java Buildpack Version: v3.6 (offline) | https://github.com/cloudfoundry/java-buildpack.git#5194155
-----> Downloading Open Jdk JRE 1.8.0_71 from https://download.run.pivotal.io/openjdk/trusty/x86_64/openjdk-1.8.0_71.tar.gz (found in cache)
Expanding Open Jdk JRE to .java-buildpack/open_jdk_jre (1.2s)
-----> Downloading Open JDK Like Memory Calculator 2.0.1_RELEASE from https://download.run.pivotal.io/memory-calculator/trusty/x86_64/memory-calculator-2.0.1_RELEASE.tar.gz (found in cache)
Memory Settings: -XX:MetaspaceSize=64M -XX:MaxMetaspaceSize=64M -Xss995K -Xmx382293K -Xms382293K
-----> Downloading Spring Auto Reconfiguration 1.10.0_RELEASE from https://download.run.pivotal.io/auto-reconfiguration/auto-reconfiguration-1.10.0_RELEASE.jar (found in cache)
Exit status 0
Staging complete
Uploading droplet, build artifacts cache...
Uploading build artifacts cache...
Uploading droplet...
Uploaded build artifacts cache (109B)
Uploaded droplet (68.4M)
Uploading complete
1 of 1 instances running
App started
OK
App springboot-oracle was started using this command `CALCULATED_MEMORY=$($PWD/.java-buildpack/open_jdk_jre/bin/java-buildpack-memory-calculator-2.0.1_RELEASE -memorySizes=metaspace:64m.. -memoryWeights=heap:75,metaspace:10,native:10,stack:5 -memoryInitials=heap:100%,metaspace:100% -totMemory=$MEMORY_LIMIT) && JAVA_OPTS="-Djava.io.tmpdir=$TMPDIR -XX:OnOutOfMemoryError=$PWD/.java-buildpack/open_jdk_jre/bin/killjava.sh $CALCULATED_MEMORY" && SERVER_PORT=$PORT eval exec $PWD/.java-buildpack/open_jdk_jre/bin/java $JAVA_OPTS -cp $PWD/.:$PWD/.java-buildpack/spring_auto_reconfiguration/spring_auto_reconfiguration-1.10.0_RELEASE.jar org.springframework.boot.loader.JarLauncher`
Showing health and status for app springboot-oracle in org pcfdev-org / space pcfdev-space as admin...
OK
requested state: started
instances: 1/1
usage: 512M x 1 instances
urls: springboot-oracle.local.pcfdev.io
last uploaded: Sun Jul 31 01:23:03 UTC 2016
stack: unknown
buildpack: java-buildpack=v3.6-offline-https://github.com/cloudfoundry/java-buildpack.git#5194155 java-main open-jdk-like-jre=1.8.0_71 open-jdk-like-memory-calculator=2.0.1_RELEASE spring-auto-reconfiguration=1.10.0_RELEASE
state since cpu memory disk details
#0 running 2016-07-31 11:24:26 AM 0.0% 0 of 512M 0 of 512M
pasapicella@pas-macbook:~/pivotal/DemoProjects/spring-starter/pivotal/PCFOracleDemo$ cf apps
Getting apps in org pcfdev-org / space pcfdev-space as admin...
OK
name requested state instances memory disk urls
springboot-oracle started 1/1 512M 512M springboot-oracle.local.pcfdev.io
6. Access deployed application at the end point "http://springboot-oracle.local.pcfdev.io" or using the application route you set in the manifest.yml
error.whitelabel.enabled=false
oracle.username=scott
oracle.password=tiger
oracle.url=jdbc:oracle:thin:@//192.168.20.131:1521/ora11gr2
<!--
Installed as follows to allow inclusion into pom.xml
mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.3 -Dpackaging=jar -Dfile=ojdbc6.jar
-DgeneratePom=true
-->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
4. Package as per below
$ cd PCFOracleDemo
$ mvn package
5. Deploy as follows
pasapicella@pas-macbook:~/pivotal/DemoProjects/spring-starter/pivotal/PCFOracleDemo$ cf push
Using manifest file /Users/pasapicella/pivotal/DemoProjects/spring-starter/pivotal/PCFOracleDemo/manifest.yml
Creating app springboot-oracle in org pcfdev-org / space pcfdev-space as admin...
OK
Creating route springboot-oracle.local.pcfdev.io...
OK
Binding springboot-oracle.local.pcfdev.io to springboot-oracle...
OK
Uploading springboot-oracle...
Uploading app files from: /var/folders/c3/27vscm613fjb6g8f5jmc2x_w0000gp/T/unzipped-app506692756
Uploading 26.3M, 154 files
Done uploading
OK
Starting app springboot-oracle in org pcfdev-org / space pcfdev-space as admin...
Downloading binary_buildpack...
Downloading python_buildpack...
Downloading staticfile_buildpack...
Downloading java_buildpack...
Downloading php_buildpack...
Downloading ruby_buildpack...
Downloading go_buildpack...
Downloading nodejs_buildpack...
Downloaded staticfile_buildpack
Downloaded binary_buildpack (8.3K)
Downloaded php_buildpack (262.3M)
Downloaded java_buildpack (241.6M)
Downloaded go_buildpack (450.3M)
Downloaded ruby_buildpack (247.7M)
Downloaded python_buildpack (254.1M)
Downloaded nodejs_buildpack (60.7M)
Creating container
Successfully created container
Downloading app package...
Downloaded app package (23.5M)
Staging...
-----> Java Buildpack Version: v3.6 (offline) | https://github.com/cloudfoundry/java-buildpack.git#5194155
-----> Downloading Open Jdk JRE 1.8.0_71 from https://download.run.pivotal.io/openjdk/trusty/x86_64/openjdk-1.8.0_71.tar.gz (found in cache)
Expanding Open Jdk JRE to .java-buildpack/open_jdk_jre (1.2s)
-----> Downloading Open JDK Like Memory Calculator 2.0.1_RELEASE from https://download.run.pivotal.io/memory-calculator/trusty/x86_64/memory-calculator-2.0.1_RELEASE.tar.gz (found in cache)
Memory Settings: -XX:MetaspaceSize=64M -XX:MaxMetaspaceSize=64M -Xss995K -Xmx382293K -Xms382293K
-----> Downloading Spring Auto Reconfiguration 1.10.0_RELEASE from https://download.run.pivotal.io/auto-reconfiguration/auto-reconfiguration-1.10.0_RELEASE.jar (found in cache)
Exit status 0
Staging complete
Uploading droplet, build artifacts cache...
Uploading build artifacts cache...
Uploading droplet...
Uploaded build artifacts cache (109B)
Uploaded droplet (68.4M)
Uploading complete
1 of 1 instances running
App started
OK
App springboot-oracle was started using this command `CALCULATED_MEMORY=$($PWD/.java-buildpack/open_jdk_jre/bin/java-buildpack-memory-calculator-2.0.1_RELEASE -memorySizes=metaspace:64m.. -memoryWeights=heap:75,metaspace:10,native:10,stack:5 -memoryInitials=heap:100%,metaspace:100% -totMemory=$MEMORY_LIMIT) && JAVA_OPTS="-Djava.io.tmpdir=$TMPDIR -XX:OnOutOfMemoryError=$PWD/.java-buildpack/open_jdk_jre/bin/killjava.sh $CALCULATED_MEMORY" && SERVER_PORT=$PORT eval exec $PWD/.java-buildpack/open_jdk_jre/bin/java $JAVA_OPTS -cp $PWD/.:$PWD/.java-buildpack/spring_auto_reconfiguration/spring_auto_reconfiguration-1.10.0_RELEASE.jar org.springframework.boot.loader.JarLauncher`
Showing health and status for app springboot-oracle in org pcfdev-org / space pcfdev-space as admin...
OK
requested state: started
instances: 1/1
usage: 512M x 1 instances
urls: springboot-oracle.local.pcfdev.io
last uploaded: Sun Jul 31 01:23:03 UTC 2016
stack: unknown
buildpack: java-buildpack=v3.6-offline-https://github.com/cloudfoundry/java-buildpack.git#5194155 java-main open-jdk-like-jre=1.8.0_71 open-jdk-like-memory-calculator=2.0.1_RELEASE spring-auto-reconfiguration=1.10.0_RELEASE
state since cpu memory disk details
#0 running 2016-07-31 11:24:26 AM 0.0% 0 of 512M 0 of 512M
pasapicella@pas-macbook:~/pivotal/DemoProjects/spring-starter/pivotal/PCFOracleDemo$ cf apps
Getting apps in org pcfdev-org / space pcfdev-space as admin...
OK
name requested state instances memory disk urls
springboot-oracle started 1/1 512M 512M springboot-oracle.local.pcfdev.io
Monday, 25 July 2016
Telstra WIFI API Consumer on Pivotal Cloud Foundry
If you heard of Telstra WIFI API you will know it will allow you to search for WIFI Hotspots within a given radius and can be used after signing in for Telstra.dev account at https://dev.telstra.com/ to obtain the Hotpots within a given Radius and Lat/Long location.
The WIFI API for Telstra is described at the link below.
https://dev.telstra.com/content/wifi-api
The following application I built on Pivotal Cloud Foundry consumes this Telstra WIFI API service and using the Google Map API along with Spring Boot will show you all the WIFI Hotspots Telstra provides from a mobile device or a Web Browser at your current location. The live URL is as follows. You will need to agree to share your location and enable Location services from your browser when on a mobile device for the MAP to be of any use. Lastly this is only useful within Australia of course.
http://pas-telstrawifi.cfapps.io/
Source Code as follows:
https://github.com/papicella/TelstraWIFIAPIPublic
More Information
https://dev.telstra.com/content/wifi-api
The WIFI API for Telstra is described at the link below.
https://dev.telstra.com/content/wifi-api
The following application I built on Pivotal Cloud Foundry consumes this Telstra WIFI API service and using the Google Map API along with Spring Boot will show you all the WIFI Hotspots Telstra provides from a mobile device or a Web Browser at your current location. The live URL is as follows. You will need to agree to share your location and enable Location services from your browser when on a mobile device for the MAP to be of any use. Lastly this is only useful within Australia of course.
http://pas-telstrawifi.cfapps.io/
Source Code as follows:
https://github.com/papicella/TelstraWIFIAPIPublic
More Information
https://dev.telstra.com/content/wifi-api
Thursday, 14 July 2016
Billing/Metering on Pivotal Cloud Foundry using the Usage Service API's
Pivotal Cloud Foundry (PCF) provides a REST API to provide billing/metering data for application and service usage. Although this usage can we viewed in the applications manager dashboard UI in this post below we will show how to use the REST based API using PCF 1.7.
Below we will show how to use the cf CLI to retrieve information about your app and service instances via the Cloud Controller and Usage service APIs.
Obtain Usage Information for an Organization
To obtain individual org usage information, use the following procedure. You must log in as an admin or as an Org Manager or Org Auditor for the org you want to view.
1. Target the end point of the cloud controller as follows
papicella@papicella:~/apps/ENV$ cf api https://api.system.yyyy.net --skip-ssl-validation
Setting api endpoint to https://api.system.yyyy.net...
OK
API endpoint: https://api.system.yyyy.net (API version: 2.54.0)
User: papicella@pivotal.io
Org: system
Space: pas
2. Login as shown below
papicella@papicella:~/apps/ENV$ cf login -u papicella@pivotal.io -o system -s pas
API endpoint: https://api.system.yyyy.net
Password>
Authenticating...
OK
Targeted org system
Targeted space pas
API endpoint: https://api.system.yyyy.net (API version: 2.54.0)
User: papicella@pivotal.io
Org: system
Space: pas
Now if your using CURL for example you can inject the GUID of your organization as part of the command as well as the "oauth-token". Here is an example on how that is done.
Endpoint format:
https://app-usage.YOUR-DOMAIN/organizations/{ORG_GUID}/app_usages?start=YYYY-MM-DD&end=YYYY-MM-DD
3. Issue REST call as shown below.
papicella@papicella:~$ curl "https://app-usage.system.yyyy.net/organizations/`cf org system --guid`/app_usages?start=2016-06-01&end=2016-06-30" -k -v -H "authorization: `cf oauth-token`" | python -m json.tool
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 222.237.99.147...
* Connected to app-usage.system.yyyy.net (222.237.99.147) port 443 (#0)
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate: *.system.yyyy.net
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0> GET /organizations/b75c9069-83b4-4130-a98e-a5eb4c5454c5/app_usages?start=2016-06-01&end=2016-06-30 HTTP/1.1
> Host: app-usage.system.yyyy.net
> User-Agent: curl/7.43.0
> Accept: */*
> authorization: bearer AwZi1lYjYGVyIMPPO-06eUG1FM12DY964Eh5AA_6Ga8P7IoB4Qr2OVx_vHh6o35IFKw .....
>
< HTTP/1.1 200 OK
< Cache-Control: max-age=0, private, must-revalidate
< Content-Type: application/json; charset=utf-8
< Etag: "16161b20edbc072ab63f8f8acf6ff251"
< Server: thin
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< X-Request-Id: 3ef758d1-3f8d-4942-b0bc-44666c2797e5
< X-Runtime: 0.167997
< X-Vcap-Request-Id: 01794681-8e29-4a07-463c-3660d0c3b349
< X-Xss-Protection: 1; mode=block
< Date: Thu, 14 Jul 2016 00:41:55 GMT
< Content-Length: 1766
<
{ [1766 bytes data]
100 1766 100 1766 0 0 755 0 0:00:02 0:00:02 --:--:-- 755
* Connection #0 to host app-usage.system.yyyy.net left intact
{
"app_usages": [
{
"app_guid": "17eee541-051a-44b5-83ae-bbbba5519af7",
"app_name": "springboot-telstrasms",
"duration_in_seconds": 0,
"instance_count": 1,
"memory_in_mb_per_instance": 512,
"space_guid": "7a0cfa11-d71d-4dd6-a706-b5eff622fb66",
"space_name": "pas"
},
{
"app_guid": "1f102a77-ce84-4cf4-93d1-e015abdf65b5",
"app_name": "company",
"duration_in_seconds": 1622,
"instance_count": 1,
"memory_in_mb_per_instance": 512,
"space_guid": "85d952b4-1acb-45fa-bd8b-d440de745a6f",
"space_name": "development"
},
{
"app_guid": "2d05970c-3f94-4329-a92a-5b81f95a9365",
"app_name": "jay-test",
"duration_in_seconds": 448,
"instance_count": 1,
"memory_in_mb_per_instance": 512,
"space_guid": "85d952b4-1acb-45fa-bd8b-d440de745a6f",
"space_name": "development"
},
{
"app_guid": "2d05970c-3f94-4329-a92a-5b81f95a9365",
"app_name": "jay-test",
"duration_in_seconds": 692,
"instance_count": 1,
"memory_in_mb_per_instance": 1024,
"space_guid": "85d952b4-1acb-45fa-bd8b-d440de745a6f",
"space_name": "development"
},
{
"app_guid": "4b771593-5032-41f9-84ff-1ecfec9a7f4d",
"app_name": "company",
"duration_in_seconds": 18430,
"instance_count": 1,
"memory_in_mb_per_instance": 512,
"space_guid": "85d952b4-1acb-45fa-bd8b-d440de745a6f",
"space_name": "development"
},
{
"app_guid": "a5435de0-1dd3-49ba-a551-94e921a5999b",
"app_name": "springboot-telstrasms",
"duration_in_seconds": 677,
"instance_count": 1,
"memory_in_mb_per_instance": 512,
"space_guid": "7a0cfa11-d71d-4dd6-a706-b5eff622fb66",
"space_name": "pas"
},
{
"app_guid": "f9c7f387-d008-4541-b093-92fb23e01aee",
"app_name": "company",
"duration_in_seconds": 0,
"instance_count": 1,
"memory_in_mb_per_instance": 512,
"space_guid": "85d952b4-1acb-45fa-bd8b-d440de745a6f",
"space_name": "development"
}
],
"organization_guid": "b75c9069-83b4-4130-a98e-a5eb4c5454c5",
"period_end": "2016-06-30T23:59:59Z",
"period_start": "2016-06-01T00:00:00Z"
}
4. To obtain usage information about services you would issue a REST call as follows
Use cf curl to retrieve service instance information. The service_instances? endpoint retrieves details about both bound and unbound service instances:
Endpoint format:
https://app-usage.YOUR-DOMAIN/organizations{ORG_GUID}/service_usages?start=YYYY-MM-DD&end=YYYY-MM-DD
papicella@papicella:~$ curl "https://app-usage.system.yyyy.net/organizations/b75c9069-83b4-4130-a98e-a5eb4c5454c5/service_usages?start=2016-06-01&end=2016-06-30" -k -v -H "authorization: `cf oauth-token`" | python -m json.tool
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 222.237.99.147...
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to app-usage.system.yyyy.net (222.237.99.147) port 443 (#0)
0 0 0 0 0 0 0 0 --:--:-- 0:00:02 --:--:-- 0* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate: *.system.yyyy.net
> GET /organizations/b75c9069-83b4-4130-a98e-a5eb4c5454c5/service_usages?start=2016-06-01&end=2016-06-30 HTTP/1.1
> Host: app-usage.system.yyyy.net
> User-Agent: curl/7.43.0
> Accept: */*
> authorization: bearer eyJhbGciOiJSUzI1NiJ9.....
>
0 0 0 0 0 0 0 0 --:--:-- 0:00:03 --:--:-- 0< HTTP/1.1 200 OK
< Cache-Control: max-age=0, private, must-revalidate
< Content-Type: application/json; charset=utf-8
< Etag: "909824b589cbed6c3d19c2f36bec985e"
< Server: thin
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< X-Request-Id: 2255821e-116c-4651-b483-1939f0f1f866
< X-Runtime: 0.137921
< X-Vcap-Request-Id: 3991c5f9-11c2-4c0e-5f2b-d1f94be87ef4
< X-Xss-Protection: 1; mode=block
< Date: Thu, 14 Jul 2016 00:53:47 GMT
< Transfer-Encoding: chunked
<
{ [3632 bytes data]
100 3978 0 3978 0 0 1283 0 --:--:-- 0:00:03 --:--:-- 1283
* Connection #0 to host app-usage.system.yyyy.net left intact
{
"organization_guid": "b75c9069-83b4-4130-a98e-a5eb4c5454c5",
"period_end": "2016-06-30T23:59:59Z",
"period_start": "2016-06-01T00:00:00Z",
"service_usages": [
{
"deleted": false,
"duration_in_seconds": 2592000.0,
"service_guid": "5c03686a-6748-4b76-bb6f-cbd116d5d87e",
"service_instance_creation": "2016-05-10T01:58:01.000Z",
"service_instance_deletion": null,
"service_instance_guid": "bd09176c-483c-4011-b329-fba717abfc27",
"service_instance_name": "spring-cloud-broker-db",
"service_instance_type": "managed_service_instance",
"service_name": "p-mysql",
"service_plan_guid": "b3525660-1a74-452f-9564-65a2556895bd",
"service_plan_name": "100mb-dev",
"space_guid": "8a9788b2-8405-4312-99fc-6854a2972616",
"space_name": "p-spring-cloud-services"
},
{
"deleted": false,
"duration_in_seconds": 2592000.0,
"service_guid": "b0a9fb4e-325b-402b-8a99-d53d7f7df80c",
"service_instance_creation": "2016-05-10T01:58:03.000Z",
"service_instance_deletion": null,
"service_instance_guid": "ad82aa5b-fd7c-4e7d-b56f-523f7b285c5d",
"service_instance_name": "spring-cloud-broker-rmq",
"service_instance_type": "managed_service_instance",
"service_name": "p-rabbitmq",
"service_plan_guid": "0cfd01c4-aea0-4ab0-9817-a312d91eee8d",
"service_plan_name": "standard",
"space_guid": "8a9788b2-8405-4312-99fc-6854a2972616",
"space_name": "p-spring-cloud-services"
},
{
"deleted": false,
"duration_in_seconds": 2592000.0,
"service_guid": "5c03686a-6748-4b76-bb6f-cbd116d5d87e",
"service_instance_creation": "2016-05-11T06:53:19.000Z",
"service_instance_deletion": null,
"service_instance_guid": "9c306f43-b17d-4a59-964d-828db5047e04",
"service_instance_name": "mydb",
"service_instance_type": "managed_service_instance",
"service_name": "p-mysql",
"service_plan_guid": "b3525660-1a74-452f-9564-65a2556895bd",
"service_plan_name": "100mb-dev",
"space_guid": "7938ae22-6a1c-49bc-9cf4-08b9b6281e83",
"space_name": "autoscaling"
},
{
"deleted": false,
"duration_in_seconds": 2592000.0,
"service_guid": "23a0f05f-fed6-4873-b0f5-77457b721626",
"service_instance_creation": "2016-05-11T06:57:01.000Z",
"service_instance_deletion": null,
"service_instance_guid": "75a4f233-25a4-4fb2-b205-354716c6c081",
"service_instance_name": "auto",
"service_instance_type": "managed_service_instance",
"service_name": "app-autoscaler",
"service_plan_guid": "5e0285ad-92b5-4cda-95e7-36db4a16fa05",
"service_plan_name": "bronze",
"space_guid": "7938ae22-6a1c-49bc-9cf4-08b9b6281e83",
"space_name": "autoscaling"
},
{
"deleted": false,
"duration_in_seconds": 2592000.0,
"service_guid": "5c03686a-6748-4b76-bb6f-cbd116d5d87e",
"service_instance_creation": "2016-05-20T08:39:09.000Z",
"service_instance_deletion": null,
"service_instance_guid": "9b69e1d0-2f93-48d2-a0b0-fc009ebbfe1d",
"service_instance_name": "account-db",
"service_instance_type": "managed_service_instance",
"service_name": "p-mysql",
"service_plan_guid": "b3525660-1a74-452f-9564-65a2556895bd",
"service_plan_name": "100mb-dev",
"space_guid": "7938ae22-6a1c-49bc-9cf4-08b9b6281e83",
"space_name": "autoscaling"
},
{
"deleted": false,
"duration_in_seconds": 1947572.0,
"service_guid": "f603ea87-9b24-4114-9bdc-c4e8154b549c",
"service_instance_creation": "2016-06-08T11:00:28.000Z",
"service_instance_deletion": null,
"service_instance_guid": "3d75b148-ee78-4f91-aa49-a1b2aa511fd1",
"service_instance_name": "service-registry",
"service_instance_type": "managed_service_instance",
"service_name": "p-service-registry",
"service_plan_guid": "ee6a7f19-f4d2-44f8-b8a2-08246c5d9a5d",
"service_plan_name": "standard",
"space_guid": "85d952b4-1acb-45fa-bd8b-d440de745a6f",
"space_name": "development"
},
{
"deleted": false,
"duration_in_seconds": 67559.0,
"service_guid": "23da6824-3ee0-4d87-b031-6223e69327ed",
"service_instance_creation": "2016-06-30T05:14:01.000Z",
"service_instance_deletion": null,
"service_instance_guid": "fd8d2f19-6a8c-43ad-81c1-205e6a29d2b8",
"service_instance_name": "api-connectors-service",
"service_instance_type": "managed_service_instance",
"service_name": "apigee-edge",
"service_plan_guid": "36ae6841-9eb3-42b7-b40b-aa44ee72a14c",
"service_plan_name": "org",
"space_guid": "7a0cfa11-d71d-4dd6-a706-b5eff622fb66",
"space_name": "pas"
}
]
}
The following screen shots show how this is done using a REST client from a browser.
More Information
http://docs.pivotal.io/pivotalcf/1-7/opsguide/accounting-report.html
Below we will show how to use the cf CLI to retrieve information about your app and service instances via the Cloud Controller and Usage service APIs.
Obtain Usage Information for an Organization
To obtain individual org usage information, use the following procedure. You must log in as an admin or as an Org Manager or Org Auditor for the org you want to view.
1. Target the end point of the cloud controller as follows
papicella@papicella:~/apps/ENV$ cf api https://api.system.yyyy.net --skip-ssl-validation
Setting api endpoint to https://api.system.yyyy.net...
OK
API endpoint: https://api.system.yyyy.net (API version: 2.54.0)
User: papicella@pivotal.io
Org: system
Space: pas
2. Login as shown below
papicella@papicella:~/apps/ENV$ cf login -u papicella@pivotal.io -o system -s pas
API endpoint: https://api.system.yyyy.net
Password>
Authenticating...
OK
Targeted org system
Targeted space pas
API endpoint: https://api.system.yyyy.net (API version: 2.54.0)
User: papicella@pivotal.io
Org: system
Space: pas
Now if your using CURL for example you can inject the GUID of your organization as part of the command as well as the "oauth-token". Here is an example on how that is done.
Endpoint format:
https://app-usage.YOUR-DOMAIN/organizations/{ORG_GUID}/app_usages?start=YYYY-MM-DD&end=YYYY-MM-DD
3. Issue REST call as shown below.
papicella@papicella:~$ curl "https://app-usage.system.yyyy.net/organizations/`cf org system --guid`/app_usages?start=2016-06-01&end=2016-06-30" -k -v -H "authorization: `cf oauth-token`" | python -m json.tool
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 222.237.99.147...
* Connected to app-usage.system.yyyy.net (222.237.99.147) port 443 (#0)
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate: *.system.yyyy.net
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0> GET /organizations/b75c9069-83b4-4130-a98e-a5eb4c5454c5/app_usages?start=2016-06-01&end=2016-06-30 HTTP/1.1
> Host: app-usage.system.yyyy.net
> User-Agent: curl/7.43.0
> Accept: */*
> authorization: bearer AwZi1lYjYGVyIMPPO-06eUG1FM12DY964Eh5AA_6Ga8P7IoB4Qr2OVx_vHh6o35IFKw .....
>
< HTTP/1.1 200 OK
< Cache-Control: max-age=0, private, must-revalidate
< Content-Type: application/json; charset=utf-8
< Etag: "16161b20edbc072ab63f8f8acf6ff251"
< Server: thin
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< X-Request-Id: 3ef758d1-3f8d-4942-b0bc-44666c2797e5
< X-Runtime: 0.167997
< X-Vcap-Request-Id: 01794681-8e29-4a07-463c-3660d0c3b349
< X-Xss-Protection: 1; mode=block
< Date: Thu, 14 Jul 2016 00:41:55 GMT
< Content-Length: 1766
<
{ [1766 bytes data]
100 1766 100 1766 0 0 755 0 0:00:02 0:00:02 --:--:-- 755
* Connection #0 to host app-usage.system.yyyy.net left intact
{
"app_usages": [
{
"app_guid": "17eee541-051a-44b5-83ae-bbbba5519af7",
"app_name": "springboot-telstrasms",
"duration_in_seconds": 0,
"instance_count": 1,
"memory_in_mb_per_instance": 512,
"space_guid": "7a0cfa11-d71d-4dd6-a706-b5eff622fb66",
"space_name": "pas"
},
{
"app_guid": "1f102a77-ce84-4cf4-93d1-e015abdf65b5",
"app_name": "company",
"duration_in_seconds": 1622,
"instance_count": 1,
"memory_in_mb_per_instance": 512,
"space_guid": "85d952b4-1acb-45fa-bd8b-d440de745a6f",
"space_name": "development"
},
{
"app_guid": "2d05970c-3f94-4329-a92a-5b81f95a9365",
"app_name": "jay-test",
"duration_in_seconds": 448,
"instance_count": 1,
"memory_in_mb_per_instance": 512,
"space_guid": "85d952b4-1acb-45fa-bd8b-d440de745a6f",
"space_name": "development"
},
{
"app_guid": "2d05970c-3f94-4329-a92a-5b81f95a9365",
"app_name": "jay-test",
"duration_in_seconds": 692,
"instance_count": 1,
"memory_in_mb_per_instance": 1024,
"space_guid": "85d952b4-1acb-45fa-bd8b-d440de745a6f",
"space_name": "development"
},
{
"app_guid": "4b771593-5032-41f9-84ff-1ecfec9a7f4d",
"app_name": "company",
"duration_in_seconds": 18430,
"instance_count": 1,
"memory_in_mb_per_instance": 512,
"space_guid": "85d952b4-1acb-45fa-bd8b-d440de745a6f",
"space_name": "development"
},
{
"app_guid": "a5435de0-1dd3-49ba-a551-94e921a5999b",
"app_name": "springboot-telstrasms",
"duration_in_seconds": 677,
"instance_count": 1,
"memory_in_mb_per_instance": 512,
"space_guid": "7a0cfa11-d71d-4dd6-a706-b5eff622fb66",
"space_name": "pas"
},
{
"app_guid": "f9c7f387-d008-4541-b093-92fb23e01aee",
"app_name": "company",
"duration_in_seconds": 0,
"instance_count": 1,
"memory_in_mb_per_instance": 512,
"space_guid": "85d952b4-1acb-45fa-bd8b-d440de745a6f",
"space_name": "development"
}
],
"organization_guid": "b75c9069-83b4-4130-a98e-a5eb4c5454c5",
"period_end": "2016-06-30T23:59:59Z",
"period_start": "2016-06-01T00:00:00Z"
}
4. To obtain usage information about services you would issue a REST call as follows
Use cf curl to retrieve service instance information. The service_instances? endpoint retrieves details about both bound and unbound service instances:
Endpoint format:
https://app-usage.YOUR-DOMAIN/organizations{ORG_GUID}/service_usages?start=YYYY-MM-DD&end=YYYY-MM-DD
papicella@papicella:~$ curl "https://app-usage.system.yyyy.net/organizations/b75c9069-83b4-4130-a98e-a5eb4c5454c5/service_usages?start=2016-06-01&end=2016-06-30" -k -v -H "authorization: `cf oauth-token`" | python -m json.tool
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 222.237.99.147...
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to app-usage.system.yyyy.net (222.237.99.147) port 443 (#0)
0 0 0 0 0 0 0 0 --:--:-- 0:00:02 --:--:-- 0* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate: *.system.yyyy.net
> GET /organizations/b75c9069-83b4-4130-a98e-a5eb4c5454c5/service_usages?start=2016-06-01&end=2016-06-30 HTTP/1.1
> Host: app-usage.system.yyyy.net
> User-Agent: curl/7.43.0
> Accept: */*
> authorization: bearer eyJhbGciOiJSUzI1NiJ9.....
>
0 0 0 0 0 0 0 0 --:--:-- 0:00:03 --:--:-- 0< HTTP/1.1 200 OK
< Cache-Control: max-age=0, private, must-revalidate
< Content-Type: application/json; charset=utf-8
< Etag: "909824b589cbed6c3d19c2f36bec985e"
< Server: thin
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< X-Request-Id: 2255821e-116c-4651-b483-1939f0f1f866
< X-Runtime: 0.137921
< X-Vcap-Request-Id: 3991c5f9-11c2-4c0e-5f2b-d1f94be87ef4
< X-Xss-Protection: 1; mode=block
< Date: Thu, 14 Jul 2016 00:53:47 GMT
< Transfer-Encoding: chunked
<
{ [3632 bytes data]
100 3978 0 3978 0 0 1283 0 --:--:-- 0:00:03 --:--:-- 1283
* Connection #0 to host app-usage.system.yyyy.net left intact
{
"organization_guid": "b75c9069-83b4-4130-a98e-a5eb4c5454c5",
"period_end": "2016-06-30T23:59:59Z",
"period_start": "2016-06-01T00:00:00Z",
"service_usages": [
{
"deleted": false,
"duration_in_seconds": 2592000.0,
"service_guid": "5c03686a-6748-4b76-bb6f-cbd116d5d87e",
"service_instance_creation": "2016-05-10T01:58:01.000Z",
"service_instance_deletion": null,
"service_instance_guid": "bd09176c-483c-4011-b329-fba717abfc27",
"service_instance_name": "spring-cloud-broker-db",
"service_instance_type": "managed_service_instance",
"service_name": "p-mysql",
"service_plan_guid": "b3525660-1a74-452f-9564-65a2556895bd",
"service_plan_name": "100mb-dev",
"space_guid": "8a9788b2-8405-4312-99fc-6854a2972616",
"space_name": "p-spring-cloud-services"
},
{
"deleted": false,
"duration_in_seconds": 2592000.0,
"service_guid": "b0a9fb4e-325b-402b-8a99-d53d7f7df80c",
"service_instance_creation": "2016-05-10T01:58:03.000Z",
"service_instance_deletion": null,
"service_instance_guid": "ad82aa5b-fd7c-4e7d-b56f-523f7b285c5d",
"service_instance_name": "spring-cloud-broker-rmq",
"service_instance_type": "managed_service_instance",
"service_name": "p-rabbitmq",
"service_plan_guid": "0cfd01c4-aea0-4ab0-9817-a312d91eee8d",
"service_plan_name": "standard",
"space_guid": "8a9788b2-8405-4312-99fc-6854a2972616",
"space_name": "p-spring-cloud-services"
},
{
"deleted": false,
"duration_in_seconds": 2592000.0,
"service_guid": "5c03686a-6748-4b76-bb6f-cbd116d5d87e",
"service_instance_creation": "2016-05-11T06:53:19.000Z",
"service_instance_deletion": null,
"service_instance_guid": "9c306f43-b17d-4a59-964d-828db5047e04",
"service_instance_name": "mydb",
"service_instance_type": "managed_service_instance",
"service_name": "p-mysql",
"service_plan_guid": "b3525660-1a74-452f-9564-65a2556895bd",
"service_plan_name": "100mb-dev",
"space_guid": "7938ae22-6a1c-49bc-9cf4-08b9b6281e83",
"space_name": "autoscaling"
},
{
"deleted": false,
"duration_in_seconds": 2592000.0,
"service_guid": "23a0f05f-fed6-4873-b0f5-77457b721626",
"service_instance_creation": "2016-05-11T06:57:01.000Z",
"service_instance_deletion": null,
"service_instance_guid": "75a4f233-25a4-4fb2-b205-354716c6c081",
"service_instance_name": "auto",
"service_instance_type": "managed_service_instance",
"service_name": "app-autoscaler",
"service_plan_guid": "5e0285ad-92b5-4cda-95e7-36db4a16fa05",
"service_plan_name": "bronze",
"space_guid": "7938ae22-6a1c-49bc-9cf4-08b9b6281e83",
"space_name": "autoscaling"
},
{
"deleted": false,
"duration_in_seconds": 2592000.0,
"service_guid": "5c03686a-6748-4b76-bb6f-cbd116d5d87e",
"service_instance_creation": "2016-05-20T08:39:09.000Z",
"service_instance_deletion": null,
"service_instance_guid": "9b69e1d0-2f93-48d2-a0b0-fc009ebbfe1d",
"service_instance_name": "account-db",
"service_instance_type": "managed_service_instance",
"service_name": "p-mysql",
"service_plan_guid": "b3525660-1a74-452f-9564-65a2556895bd",
"service_plan_name": "100mb-dev",
"space_guid": "7938ae22-6a1c-49bc-9cf4-08b9b6281e83",
"space_name": "autoscaling"
},
{
"deleted": false,
"duration_in_seconds": 1947572.0,
"service_guid": "f603ea87-9b24-4114-9bdc-c4e8154b549c",
"service_instance_creation": "2016-06-08T11:00:28.000Z",
"service_instance_deletion": null,
"service_instance_guid": "3d75b148-ee78-4f91-aa49-a1b2aa511fd1",
"service_instance_name": "service-registry",
"service_instance_type": "managed_service_instance",
"service_name": "p-service-registry",
"service_plan_guid": "ee6a7f19-f4d2-44f8-b8a2-08246c5d9a5d",
"service_plan_name": "standard",
"space_guid": "85d952b4-1acb-45fa-bd8b-d440de745a6f",
"space_name": "development"
},
{
"deleted": false,
"duration_in_seconds": 67559.0,
"service_guid": "23da6824-3ee0-4d87-b031-6223e69327ed",
"service_instance_creation": "2016-06-30T05:14:01.000Z",
"service_instance_deletion": null,
"service_instance_guid": "fd8d2f19-6a8c-43ad-81c1-205e6a29d2b8",
"service_instance_name": "api-connectors-service",
"service_instance_type": "managed_service_instance",
"service_name": "apigee-edge",
"service_plan_guid": "36ae6841-9eb3-42b7-b40b-aa44ee72a14c",
"service_plan_name": "org",
"space_guid": "7a0cfa11-d71d-4dd6-a706-b5eff622fb66",
"space_name": "pas"
}
]
}
The following screen shots show how this is done using a REST client from a browser.
More Information
http://docs.pivotal.io/pivotalcf/1-7/opsguide/accounting-report.html
Tuesday, 12 July 2016
Creating a Service within IntelliJ IDEA to be used by the Service Registry for Pivotal Cloud Foundry
In this example I am going to show how to use IntelliJ IDEA 15 to create a service application from the IDE to be consumed by the Service Registry service in Pivotal Cloud Foundry (PCF). For more information on this service view the docs page below.
http://docs.pivotal.io/spring-cloud-services/service-registry/index.html
Service Registry for Pivotal Cloud Foundry® (PCF) provides your applications with an implementation of the Service Discovery pattern, one of the key tenets of a microservice-based architecture. Trying to hand-configure each client of a service or adopt some form of access convention can be difficult and prove to be brittle in production. Instead, your applications can use the Service Registry to dynamically discover and call registered services
1. Start IntelliJ IDEA and either "Create a New project" or add a "New Module" to an existing project.
2. Ensure you select "Spring Initializer" as shown below
3. Click Next
4. Describe your project or module, I normally use Maven and generate a JAR file
5. Click Next
6. At the minimum here we only need to select "Service Registry (PCF)" as shown below for the dependency. Of course you would select other options dependncies depending on what the service needed such as REST, JPA, H2 or MySQL etc
7. Click Next
8. Name your new model or project
9. Click Finish
10. Click Finish
11. Your service application must include the @EnableDiscoveryClient annotation on a configuration class. To do that we simply add the annotation to our main class as follows
Java Code
12. Set the spring.application.name property in application.yml. It might be an application.properties file BUT rename it to YML as I know that works. below I not only set the application name I also set the registrationMethod to "route" which is the default and then turn off security as it is enabled by default.
spring:
application:
name: employee-service
cloud:
services:
registrationMethod: route
security:
basic:
enabled: false
So that's all we really need to do here. Of course we will need to add code to our service to do what it needs to do BUT all the config required to enable this service to automatically register itself with the "Service Registry" in PCF is done.
13. Before we deploy this to out PCF instance we have to be sure we have a "Service Registry" service created as shown below using the CF CLI mine is already created.
14. Create a manifest.yml file for the service to be deployed, notice how it binds to the service registry "apples-service-registery", this will ensure it automatically gets registered on deployment with the Service Registry service
---
applications:
- name: apples-employee-service
memory: 512M
instances: 1
host: apples-employee-service-${random-word}
path: ./target/EmployeeService-0.0.1-SNAPSHOT.jar
services:
- apples-service-registery
15. Push the service application to PCF as shown below
.....
16. Login into your PCF instance App Manager UI, in this demo I am using PWS instance run.pivotal.io and find your "Service Registry" service and click on it as shown below
17. Click on the "Manage" link as shown below
18. Verify your service is registered as shown below
More Information
http://docs.pivotal.io/spring-cloud-services/service-registry/index.html
https://docs.pivotal.io/spring-cloud-services/service-registry/resources.html
http://docs.pivotal.io/spring-cloud-services/service-registry/writing-client-applications.html
http://docs.pivotal.io/spring-cloud-services/service-registry/index.html
Service Registry for Pivotal Cloud Foundry® (PCF) provides your applications with an implementation of the Service Discovery pattern, one of the key tenets of a microservice-based architecture. Trying to hand-configure each client of a service or adopt some form of access convention can be difficult and prove to be brittle in production. Instead, your applications can use the Service Registry to dynamically discover and call registered services
1. Start IntelliJ IDEA and either "Create a New project" or add a "New Module" to an existing project.
2. Ensure you select "Spring Initializer" as shown below
3. Click Next
4. Describe your project or module, I normally use Maven and generate a JAR file
5. Click Next
6. At the minimum here we only need to select "Service Registry (PCF)" as shown below for the dependency. Of course you would select other options dependncies depending on what the service needed such as REST, JPA, H2 or MySQL etc
7. Click Next
8. Name your new model or project
9. Click Finish
10. Click Finish
11. Your service application must include the @EnableDiscoveryClient annotation on a configuration class. To do that we simply add the annotation to our main class as follows
Java Code
package pas.au.pivotal.service.hr;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import javax.annotation.PostConstruct;
@SpringBootApplication
@EnableDiscoveryClient
public class EmployeeServiceApplication
{
@Autowired
private EmployeeRepository employeeRepository;
public static void main(String[] args) {
SpringApplication.run(EmployeeServiceApplication.class, args);
}
@PostConstruct
public void init()
{
employeeRepository.save(new Employee("pas"));
employeeRepository.save(new Employee("lucia"));
employeeRepository.save(new Employee("siena"));
employeeRepository.save(new Employee("lucas"));
}
}
12. Set the spring.application.name property in application.yml. It might be an application.properties file BUT rename it to YML as I know that works. below I not only set the application name I also set the registrationMethod to "route" which is the default and then turn off security as it is enabled by default.
spring:
application:
name: employee-service
cloud:
services:
registrationMethod: route
security:
basic:
enabled: false
So that's all we really need to do here. Of course we will need to add code to our service to do what it needs to do BUT all the config required to enable this service to automatically register itself with the "Service Registry" in PCF is done.
13. Before we deploy this to out PCF instance we have to be sure we have a "Service Registry" service created as shown below using the CF CLI mine is already created.
14. Create a manifest.yml file for the service to be deployed, notice how it binds to the service registry "apples-service-registery", this will ensure it automatically gets registered on deployment with the Service Registry service
---
applications:
- name: apples-employee-service
memory: 512M
instances: 1
host: apples-employee-service-${random-word}
path: ./target/EmployeeService-0.0.1-SNAPSHOT.jar
services:
- apples-service-registery
15. Push the service application to PCF as shown below
.....
16. Login into your PCF instance App Manager UI, in this demo I am using PWS instance run.pivotal.io and find your "Service Registry" service and click on it as shown below
17. Click on the "Manage" link as shown below
18. Verify your service is registered as shown below
More Information
http://docs.pivotal.io/spring-cloud-services/service-registry/index.html
https://docs.pivotal.io/spring-cloud-services/service-registry/resources.html
http://docs.pivotal.io/spring-cloud-services/service-registry/writing-client-applications.html
Subscribe to:
Posts (Atom)




























