Search This Blog

Tuesday, 16 December 2014

View application log files in PCF using the CF CLI

I recently setup verbose GC logging on a  deployed application to Pivotal Cloud Foundry (PCF) and specified a file to write the GC logging info to. Below shows how you can view application files using the CF CLI.

1. Start by invoking the following to show your deployed applications

[Tue Dec 16 09:32:10 papicella@:~/cf/APJ-vcloud ] $ cf apps
Getting apps in org ANZ / space development as pas...
OK

name                  requested state   instances   memory   disk   urls
pas-playjava          started           1/1         512M     1G     pas-playjava.apj.fe.pivotal.io
pcfhawq               started           1/1         512M     1G     pcfhawq.apj.fe.pivotal.io
apples-spring-music   started           1/1         512M     1G     apples-spring-music.apj.fe.pivotal.io
pas-petclinic         started           1/1         512M     1G     pas-petclinic.apj.fe.pivotal.io

2. Now lets view the files for the application

[Tue Dec 16 09:33:29 papicella@:~/cf/APJ-vcloud ] $ cf files apples-spring-music
Getting files for app apples-spring-music in org ANZ / space development as pas...
OK

.bash_logout                              220B
.bashrc                                   3.0K
.profile                                  675B
app/                                         -
logs/                                        -
run.pid                                     3B
staging_info.yml                          495B
tmp/                                         -

3. Now lets view the contents of a specific file by providing the full path to the file, in this case our GC log file.

[Tue Dec 16 09:33:41 papicella@:~/cf/APJ-vcloud ] $ cf files apples-spring-music /app/apples_gc.log
Getting files for app apples-spring-music in org ANZ / space development as pas...
OK

OpenJDK 64-Bit Server VM (25.40-b06) for linux-amd64 JRE (1.8.0_25--vagrant_2014_10_17_04_37-b17), built on Oct 17 2014 04:40:49 by "vagrant" with gcc 4.4.3
Memory: 4k page, physical 16434516k(1028892k free), swap 16434488k(16434476k free)
CommandLine flags: -XX:InitialHeapSize=391468032 -XX:MaxHeapSize=391468032 -XX:MaxMetaspaceSize=67108864 -XX:MetaspaceSize=67108864 -XX:OnOutOfMemoryError=/home/vcap/app/.java-buildpack/open_jdk_jre/bin/killjava.sh -XX:+PrintGC -XX:+PrintGCTimeStamps -XX:ThreadStackSize=995 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseParallelGC
1.522: [GC (Allocation Failure)  95744K->16737K(367104K), 0.0590876 secs]
1.786: [GC (Allocation Failure)  112481K->23072K(367104K), 0.0735813 secs]
2.075: [GC (Allocation Failure)  118816K->32499K(367104K), 0.0531070 secs]
2.315: [GC (Allocation Failure)  128243K->45124K(367104K), 0.0428136 secs]
2.893: [GC (Allocation Failure)  140868K->53805K(367104K), 0.0375078 secs]
4.143: [GC (Allocation Failure)  149549K->63701K(335360K), 0.1507024 secs]
5.686: [GC (Allocation Failure)  127701K->69319K(331776K), 0.0703850 secs]
7.060: [GC (Allocation Failure)  133319K->70962K(348672K), 0.0121269 secs]
8.458: [GC (Allocation Failure)  130866K->69734K(322560K), 0.0228917 secs]

Monday, 8 December 2014

Typesafe activator , play framework applications deployed to Pivotal Cloud Foundry

I decided to quickly build an application using Typesafe activator for a play framework scala application and deploy it to Pivotal Cloud Foundry. You can read more about Typesafe activator below.

https://typesafe.com/activator

Here are the steps to deploy a scala play framework application created using Typesafe activator. I created a basic hello world scala application with the play framework. The purpose here is what is needed to get it deployed on Pivotal Cloud Foundry.

Note: Assumes we have created an application with name "hello-play-scala" and we are in that actually directly as we create files for deployment.

1. Create a distribution ZIP file as follows once you have finished developing your application

> ./activator dist

2. Create a manifest file as follows which refers to the DIST zip file created in #1 above.

applications:
- name: pas-helloworld-scala
  memory: 756M
  instances: 1
  host: pas-helloworld-scala
  domain: apj.fe.pivotal.io
  path: ./target/universal/hello-play-scala-1.0-SNAPSHOT.zip

3. Create a build.sh file, make it executable. This simple shell script is going to call sbt/activator

java -jar activator-launch-1.2.12.jar dist

4. Deploy as shown below.

[Mon Dec 08 10:31:14 papicella@:~/vmware/software/scala/apps/hello-play-scala ] $ cf push -f manifest.yml
Using manifest file manifest.yml

Creating app pas-helloworld-scala in org ANZ / space development as pas...
OK

Using route pas-helloworld-scala.apj.fe.pivotal.io
Binding pas-helloworld-scala.apj.fe.pivotal.io to pas-helloworld-scala...
OK

Uploading pas-helloworld-scala...
Uploading app files from: target/universal/hello-play-scala-1.0-SNAPSHOT.zip
Uploading 1.1M, 131 files
OK

Starting app pas-helloworld-scala in org ANZ / space development as pas...
OK
-----> Downloaded app package (26M)
-----> Java Buildpack Version: v2.4 (offline) | https://github.com/cloudfoundry/java-buildpack.git#7cdcf1a
-----> Downloading Open Jdk JRE 1.7.0_60 from http://download.run.pivotal.io/openjdk/lucid/x86_64/openjdk-1.7.0_60.tar.gz (found in cache)
       Expanding Open Jdk JRE to .java-buildpack/open_jdk_jre (0.9s)
-----> Downloading Play Framework Auto Reconfiguration 1.4.0_RELEASE from http://download.run.pivotal.io/auto-reconfiguration/auto-reconfiguration-1.4.0_RELEASE.jar (found in cache)

-----> Uploading droplet (57M)

1 of 1 instances running

App started

Showing health and status for app pas-helloworld-scala in org ANZ / space development as pas...
OK

requested state: started
instances: 1/1
usage: 756M x 1 instances
urls: pas-helloworld-scala.apj.fe.pivotal.io

     state     since                    cpu    memory           disk
#0   running   2014-12-08 10:32:27 AM   0.0%   164.6M of 756M   118.8M of 1G


5. Finally access in a browser


Wednesday, 3 December 2014

Deploying Spring Boot Applications to Pivotal Cloud Foundry from STS

The example below shows how to use STS (Spring Tool Suite) to deploy a spring boot web application directly from the IDE itself. I created a basic spring boot web application using the template engine thymeleaf. The application isn't that fancy it simply displays a products page of some mock up Products. This blog entry just shows how you could deploy this to Pivotal Cloud Foundry from the IDE itself.

1. First create a Pivotal Cloud Foundry Server connection. The image blow shows the connection and one single application.



2. Right click on your Spring Boot application and select "Configure -> Enable as cloud foundry app"

3. Drag and Drop The project onto the Cloud Foundry Connection.

4. At this point a dialog appears asking for an application name as shown below.


5. Click Next

6. Select deployment options and click Next


7. Bind to existing services if you need to 


8. Click next
9. Click finish

At this point it will push the application to your Cloud Foundry Instance



Once complete the Console window in STS will show something as follows

Checking application - SpringBootWebCloudFoundry
Generating application archive
Creating application
Pushing application
Application successfully pushed
Starting and staging application
Got staging request for app with id bb3c63f5-c32d-4e27-a834-04076f2af35a
Updated app with guid bb3c63f5-c32d-4e27-a834-04076f2af35a ({"state"=>"STARTED"})
-----> Downloaded app package (12M)
-----> Java Buildpack Version: v2.4 (offline) | https://github.com/cloudfoundry/java-buildpack.git#7cdcf1a
-----> Downloading Open Jdk JRE 1.7.0_60 from http://download.run.pivotal.io/openjdk/lucid/x86_64/openjdk-1.7.0_60.tar.gz (found in cache)
       Expanding Open Jdk JRE to .java-buildpack/open_jdk_jre (0.9s)
-----> Downloading Spring Auto Reconfiguration 1.4.0_RELEASE from http://download.run.pivotal.io/auto-reconfiguration/auto-reconfiguration-1.4.0_RELEASE.jar (found in cache)
-----> Uploading droplet (43M)
Starting app instance (index 0) with guid bb3c63f5-c32d-4e27-a834-04076f2af35a

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.1.9.RELEASE)
2014-12-03 11:09:50.434  INFO 32 --- [           main] loudProfileApplicationContextInitializer : Adding 'cloud' to list of active profiles
2014-12-03 11:09:50.447  INFO 32 --- [           main] pertySourceApplicationContextInitializer : Adding 'cloud' PropertySource to ApplicationContext
2014-12-03 11:09:50.497  INFO 32 --- [           main] nfigurationApplicationContextInitializer : Adding cloud service auto-reconfiguration to ApplicationContext
2014-12-03 11:09:50.521  INFO 32 --- [           main] apples.sts.web.Application               : Starting Application on 187dfn5m5ve with PID 32 (/home/vcap/app started by vcap in /home/vcap/app)
2014-12-03 11:09:50.577  INFO 32 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@374d2f77: startup date [Wed Dec 03 11:09:50 UTC 2014]; root of context hierarchy
2014-12-03 11:09:50.930  WARN 32 --- [           main] .i.s.PathMatchingResourcePatternResolver : Skipping [/home/vcap/app/.java-buildpack/spring_auto_reconfiguration/spring_auto_reconfiguration-1.4.0_RELEASE.jar] because it does not denote a directory
2014-12-03 11:09:51.600  WARN 32 --- [           main] .i.s.PathMatchingResourcePatternResolver : Skipping [/home/vcap/app/.java-buildpack/spring_auto_reconfiguration/spring_auto_reconfiguration-1.4.0_RELEASE.jar] because it does not denote a directory
2014-12-03 11:09:52.349  INFO 32 --- [           main] urceCloudServiceBeanFactoryPostProcessor : Auto-reconfiguring beans of type javax.sql.DataSource
2014-12-03 11:09:52.358  INFO 32 --- [           main] urceCloudServiceBeanFactoryPostProcessor : No beans of type javax.sql.DataSource found. Skipping auto-reconfiguration.
2014-12-03 11:09:53.109  INFO 32 --- [           main] .t.TomcatEmbeddedServletContainerFactory : Server initialized with port: 61097
2014-12-03 11:09:53.391  INFO 32 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2014-12-03 11:09:53.393  INFO 32 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/7.0.56
2014-12-03 11:09:53.523  INFO 32 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2014-12-03 11:09:53.524  INFO 32 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2950 ms
2014-12-03 11:09:54.201  INFO 32 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean        : Mapping servlet: 'dispatcherServlet' to [/]
2014-12-03 11:09:54.205  INFO 32 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2014-12-03 11:09:54.521  INFO 32 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2014-12-03 11:09:54.611  INFO 32 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String apples.sts.web.WelcomeController.welcome(org.springframework.ui.Model)
2014-12-03 11:09:54.612  INFO 32 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/products],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String apples.sts.web.ProductController.listProducts(org.springframework.ui.Model)
2014-12-03 11:09:54.615  INFO 32 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[text/html],custom=[]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest)
2014-12-03 11:09:54.616  INFO 32 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2014-12-03 11:09:54.640  INFO 32 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2014-12-03 11:09:54.641  INFO 32 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2014-12-03 11:09:55.077  INFO 32 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2014-12-03 11:09:55.156  INFO 32 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 61097/http
2014-12-03 11:09:55.167  INFO 32 --- [           main] apples.sts.web.Application               : Started Application in 5.918 seconds (JVM running for 6.712)

You can also view the deployed application details in STS by double clicking on it as shown below.