Thursday, 26 March 2015

IBM Bluemix demo using IBM Watson Tradeoff Analytics Service

The IBM Watson Tradeoff Analytics service helps you make better choices under multiple conflicting goals. The service combines smart visualization and recommendations for tradeoff exploration.

The following demo application shows how to use the IBM Watson Tradeoff Analytics Service from IBM Bluemix. This is the demo application for this service.

1. Clone the GitHub project as shown below.

pas@pass-mbp:~/bluemix-apps/watson$ git clone https://github.com/watson-developer-cloud/tradeoff-analytics-nodejs.git
Cloning into 'tradeoff-analytics-nodejs'...
remote: Counting objects: 112, done.
remote: Total 112 (delta 0), reused 0 (delta 0), pack-reused 112
Receiving objects: 100% (112/112), 163.05 KiB | 11.00 KiB/s, done.
Resolving deltas: 100% (38/38), done.
Checking connectivity... done.


2. Create the Tradeoff Analytics service as shown below.

pas@pass-mbp:~/bluemix-apps/watson$ cf create-service tradeoff_analytics free tradeoff-analytics-service
Creating service tradeoff-analytics-service in org pasapi@au1.ibm.com / space dev as pasapi@au1.ibm.com...
OK


3. Create a mainifest.yml as shown below, ensuring you edit the application name to be a unique name

declared-services:
  tradeoff-analytics-service:
    label: tradeoff_analytics
    plan: free
applications:
- services:
  - tradeoff-analytics-service
  name: pas-tradeoff-analytics-nodejs
  command: node app.js
  path: .
  memory: 128M


4. Push the application into Bluemix as follows

pas@pass-mbp:~/bluemix-apps/watson/tradeoff-analytics-nodejs$ cf push
Using manifest file /Users/pas/ibm/bluemix/apps/watson/tradeoff-analytics-nodejs/manifest.yml

Creating app pas-tradeoff-analytics-nodejs in org pasapi@au1.ibm.com / space dev as pasapi@au1.ibm.com...
OK

Creating route pas-tradeoff-analytics-nodejs.mybluemix.net...
OK

Binding pas-tradeoff-analytics-nodejs.mybluemix.net to pas-tradeoff-analytics-nodejs...
OK

Uploading pas-tradeoff-analytics-nodejs...
Uploading app files from: /Users/pas/ibm/bluemix/apps/watson/tradeoff-analytics-nodejs
Uploading 204K, 45 files
Done uploading
OK
Binding service tradeoff-analytics-service to app pas-tradeoff-analytics-nodejs in org pasapi@au1.ibm.com / space dev as pasapi@au1.ibm.com...
OK

Starting app pas-tradeoff-analytics-nodejs in org pasapi@au1.ibm.com / space dev as pasapi@au1.ibm.com...
-----> Downloaded app package (156K)
-----> Node.js Buildpack Version: v1.14-20150309-1555
       TIP: Avoid using semver ranges starting with '>' in engines.node
-----> Requested node range:  >=0.10
-----> Resolved node version: 0.10.36
-----> Installing IBM SDK for Node.js from cache
-----> Checking and configuring service extensions
-----> Installing dependencies
       body-parser@1.10.2 node_modules/body-parser
       ├── media-typer@0.3.0
       ├── bytes@1.0.0
       ├── raw-body@1.3.2
       ├── depd@1.0.0
       ├── qs@2.3.3
       ├── on-finished@2.2.0 (ee-first@1.1.0)
       ├── iconv-lite@0.4.6
       └── type-is@1.5.7 (mime-types@2.0.10)
       express@4.12.3 node_modules/express
       ├── merge-descriptors@1.0.0
       ├── escape-html@1.0.1
       ├── utils-merge@1.0.0
       ├── cookie-signature@1.0.6
       ├── methods@1.1.1
       ├── fresh@0.2.4
       ├── cookie@0.1.2
       ├── range-parser@1.0.2
       ├── finalhandler@0.3.4
       ├── content-type@1.0.1
       ├── vary@1.0.0
       ├── parseurl@1.3.0
       ├── serve-static@1.9.2
       ├── content-disposition@0.5.0
       ├── path-to-regexp@0.1.3
       ├── depd@1.0.0
       ├── on-finished@2.2.0 (ee-first@1.1.0)
       ├── qs@2.4.1
       ├── debug@2.1.3 (ms@0.7.0)
       ├── etag@1.5.1 (crc@3.2.1)
       ├── send@0.12.2 (destroy@1.0.3, ms@0.7.0, mime@1.3.4)
       ├── proxy-addr@1.0.7 (forwarded@0.1.0, ipaddr.js@0.1.9)
       ├── accepts@1.2.5 (negotiator@0.5.1, mime-types@2.0.10)
       └── type-is@1.6.1 (media-typer@0.3.0, mime-types@2.0.10)
       errorhandler@1.3.5 node_modules/errorhandler
       ├── escape-html@1.0.1
       └── accepts@1.2.5 (negotiator@0.5.1, mime-types@2.0.10)
       request@2.53.0 node_modules/request
       ├── caseless@0.9.0
       ├── json-stringify-safe@5.0.0
       ├── forever-agent@0.5.2
       ├── aws-sign2@0.5.0
       ├── stringstream@0.0.4
       ├── oauth-sign@0.6.0
       ├── tunnel-agent@0.4.0
       ├── isstream@0.1.2
       ├── node-uuid@1.4.3
       ├── combined-stream@0.0.7 (delayed-stream@0.0.5)
       ├── qs@2.3.3
       ├── form-data@0.2.0 (async@0.9.0)
       ├── mime-types@2.0.10 (mime-db@1.8.0)
       ├── http-signature@0.10.1 (assert-plus@0.1.5, asn1@0.1.11, ctype@0.5.3)
       ├── bl@0.9.4 (readable-stream@1.0.33)
       ├── tough-cookie@0.12.1 (punycode@1.3.2)
       └── hawk@2.3.1 (cryptiles@2.0.4, sntp@1.0.9, boom@2.6.1, hoek@2.12.0)
       jade@1.9.2 node_modules/jade
       ├── character-parser@1.2.1
       ├── void-elements@2.0.1
       ├── commander@2.6.0
       ├── mkdirp@0.5.0 (minimist@0.0.8)
       ├── with@4.0.1 (acorn-globals@1.0.2, acorn@0.11.0)
       ├── transformers@2.1.0 (promise@2.0.0, css@1.0.8, uglify-js@2.2.5)
       └── constantinople@3.0.1 (acorn-globals@1.0.2)
       watson-developer-cloud@0.9.6 node_modules/watson-developer-cloud
       ├── object.pick@1.1.1
       ├── cookie@0.1.2
       ├── extend@2.0.0
       ├── isstream@0.1.2
       ├── async@0.9.0
       ├── string-template@0.2.0 (js-string-escape@1.0.0)
       └── object.omit@0.2.1 (isobject@0.2.0, for-own@0.1.3)
-----> Caching node_modules directory for future builds
-----> Cleaning up node-gyp and npm artifacts
-----> No Procfile found; Adding npm start to new Procfile
-----> Building runtime environment
-----> Checking and configuring service extensions
-----> Installing App Management
-----> Node.js Buildpack is done creating the droplet

-----> Uploading droplet (14M)

0 of 1 instances running, 1 starting
1 of 1 instances running

App started


OK

App pas-tradeoff-analytics-nodejs was started using this command `node app.js`

Showing health and status for app pas-tradeoff-analytics-nodejs in org pasapi@au1.ibm.com / space dev as pasapi@au1.ibm.com...
OK

requested state: started
instances: 1/1
usage: 128M x 1 instances
urls: pas-tradeoff-analytics-nodejs.mybluemix.net
last uploaded: Thu Mar 26 09:44:55 +0000 2015

     state     since                    cpu    memory          disk          details
#0   running   2015-03-26 08:45:51 PM   0.0%   43.5M of 128M   50.3M of 1G


5. Access the application


6. Click on the "Analyze Sample Data"


The demo can be found on the GutHub link below.

https://github.com/watson-developer-cloud/tradeoff-analytics-nodejs

Wednesday, 11 March 2015

Adding MySQL driver to Spring Boot CLI Groovy Demo

I previously showed how you can use the Spring Boot CLI to create a simple Restful Application saying Hello World as shown in the link below using Groovy.

http://theblasfrompas.blogspot.com.au/2015/02/spring-boot-hello-world-from-command.html

If you wanted to extend that demo to include additional dependencies JAR file such as MySQL driver jar file we would do the following

1. You can add extensions to the CLI using the install command as shown below to add MySQL driver. This is installed in the LIB folder of the Spring Boot CLI location directory

> spring install mysql:mysql-connector-java:5.1.34

2. Package the application into a JAR which now includes the MySQL driver JAR file to enable you to connect to a MySQL instance from your application. You will need to write the code to do that , BUT now the JAR file is packaged in the JAR created to enable you to do that.

> spring jar -cp /usr/local/Cellar/springboot/1.2.1.RELEASE/lib/mysql-connector-java-5.1.34.jar hello.jar hello.groovy

Note: If you find that you reach the limit of the CLI tool, you will probably want to look at converting your application to full Gradle or Maven built “groovy project”

More Information

http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#cli-using-the-cli


Friday, 6 March 2015

Reading VCAP_SERVICES Postgresql service credentials within Bluemix

The following shows how you can easily read the VCAP_SERVICES postgresql credentials within your Java Code using the maven repo. This assumes your using the ElephantSQL Postgresql service. A single connection won't be ideal but for demo purposes might just be all you need.

1. First add the maven dependency as follows. This will add WebSphere Application Server Liberty Profile to your project

  
<dependency>
        <groupId>com.ibm.tools.target</groupId>
        <artifactId>was-liberty</artifactId>
        <version>LATEST</version>
        <type>pom</type>
        <scope>provided</scope>
</dependency>

2. In your code , something as follows gets you the Connection details to make a JDBC connection withinyou java code.
  
private static Connection getConnection() throws Exception 
{
 Map<String, String> env = System.getenv();
 
 if (env.containsKey("VCAP_SERVICES")) {

  JSONObject vcap = (JSONObject) JSON.parse(env.get("VCAP_SERVICES"));
  JSONObject service = null;
  
  // We don't know exactly what the service is called,
  // but it will contain "elephantsql"
  for (Object key : vcap.keySet()) {
   String keyStr = (String) key;
   if (keyStr.toLowerCase().contains("elephantsql")) {
    service = (JSONObject) ((JSONArray) vcap.get(keyStr)).get(0);
    break;
   }
  }
  
  if (service != null) {
   JSONObject creds = (JSONObject) service.get("credentials");
   URI uri = URI.create((String) creds.get("uri"));
   String url = "jdbc:postgresql://" + uri.getHost() + ":" +
            uri.getPort() +
            uri.getPath();
   String username = uri.getUserInfo().split(":")[0];
   String password = uri.getUserInfo().split(":")[1];
   return DriverManager.getConnection(url, username, password);
  }
 }
 
 throw new Exception("No ElephantSQL service URL found. Make sure you " +
      "have bound the correct services to your app.");
}

Tuesday, 24 February 2015

Spring Boot - Hello World from the command line to IBM Bluemix in 1 minute

Here is how simple Spring Boot makes saying Hello World web based application with no IDE and no no need to package it up. Nearly as easy as NodeJS

1. Firstly install the Spring Boot CLI. From mac use brew as follows

pas@192-168-1-4:~$ brew tap pivotal/tap
Cloning into '/usr/local/Library/Taps/pivotal/homebrew-tap'...
remote: Counting objects: 366, done.
remote: Total 366 (delta 0), reused 0 (delta 0), pack-reused 366
Receiving objects: 100% (366/366), 60.09 KiB | 84.00 KiB/s, done.
Resolving deltas: 100% (195/195), done.
Checking connectivity... done.
Tapped 8 formulae
pas@192-168-1-4:~$ brew install springboot
==> Installing springboot from pivotal/homebrew-tap
==> Downloading https://repo.spring.io/release/org/springframework/boot/spring-boot-cli/1.2.1.RELEASE/spring-boot-cli-1.2.1.RELEASE-bin.tar.gz
######################################################################## 100.0%
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completion has been installed to:
  /usr/local/share/zsh/site-functions
==> Summary
��  /usr/local/Cellar/springboot/1.2.1.RELEASE: 6 files, 8.6M, built in 98 seconds


2. Now create a simple groovy file called hello.groovy as follows

  
@RestController
class HelloWorld {
  @RequestMapping("/")
  String home() {
    return "Hello World!"
  }
}

3. Run using the spring boot CLI as follows

pas@pass-mbp:~/ibm/software/spring/spring-boot/groovy-example$ spring run hello.groovy

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.2.1.RELEASE)

2015-02-24 21:13:13.544  INFO 7565 --- [       runner-0] o.s.boot.SpringApplication               : Starting application on 192-168-1-4.tpgi.com.au with PID 7565 (/Users/pas/.m2/repository/org/springframework/boot/spring-boot/1.2.1.RELEASE/spring-boot-1.2.1.RELEASE.jar started by pas in /Users/pas/ibm/software/spring/spring-boot/groovy-example)
2015-02-24 21:13:13.667  INFO 7565 --- [       runner-0] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@3b4b551f: startup date [Tue Feb 24 21:13:13 AEDT 2015]; root of context hierarchy
2015-02-24 21:13:14.189  INFO 7565 --- [       runner-0] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'beanNameViewResolver': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]]
2015-02-24 21:13:14.663  INFO 7565 --- [       runner-0] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2015-02-24 21:13:14.796  INFO 7565 --- [       runner-0] o.apache.catalina.core.StandardService   : Starting service Tomcat
2015-02-24 21:13:14.797  INFO 7565 --- [       runner-0] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.0.15
2015-02-24 21:13:14.849  INFO 7565 --- [ost-startStop-1] org.apache.catalina.loader.WebappLoader  : Unknown loader org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader@463a88aa class org.springframework.boot.cli.compiler.ExtendedGroovyClassLoader$DefaultScopeParentClassLoader
2015-02-24 21:13:14.868  INFO 7565 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2015-02-24 21:13:14.868  INFO 7565 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1203 ms
2015-02-24 21:13:15.304  INFO 7565 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean        : Mapping servlet: 'dispatcherServlet' to [/]
2015-02-24 21:13:15.308  INFO 7565 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'characterEncodingFilter' to: [/*]
2015-02-24 21:13:15.308  INFO 7565 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2015-02-24 21:13:15.474  INFO 7565 --- [       runner-0] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@3b4b551f: startup date [Tue Feb 24 21:13:13 AEDT 2015]; root of context hierarchy
2015-02-24 21:13:15.513  INFO 7565 --- [       runner-0] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String HelloWorld.home()
2015-02-24 21:13:15.514  INFO 7565 --- [       runner-0] 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)
2015-02-24 21:13:15.515  INFO 7565 --- [       runner-0] 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)
2015-02-24 21:13:15.537  INFO 7565 --- [       runner-0] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2015-02-24 21:13:15.537  INFO 7565 --- [       runner-0] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2015-02-24 21:13:15.568  INFO 7565 --- [       runner-0] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2015-02-24 21:13:15.927  INFO 7565 --- [       runner-0] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2015-02-24 21:13:15.964  INFO 7565 --- [       runner-0] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2015-02-24 21:13:15.965  INFO 7565 --- [       runner-0] o.s.boot.SpringApplication               : Started application in 2.568 seconds (JVM running for 3.81)


4. Invoke in a browser and you have your "Hello World" or just use "curl" as follows

pas@192-168-1-4:~/ibm/software/spring/spring-boot/groovy-example$ curl http://localhost:8080
Hello World!


5. Finally lets create a runnable JAR we can then deploy to IBM Bluemix

pas@192-168-1-4:~/ibm/software/spring/spring-boot/groovy-example$ spring jar hello.jar hello.groovy

6. Finally deploy to IBM Bluemix using the runnable JAR file as follows

pas@192-168-1-4:~/ibm/software/spring/spring-boot/groovy-example$ cf push hello-spring-boot -i 1 -m 256M -p ./hello.jar
Creating app hello-spring-boot in org pasapi@au1.ibm.com / space apple as pasapi@au1.ibm.com...
OK

Creating route hello-spring-boot.mybluemix.net...
OK

Binding hello-spring-boot.mybluemix.net to hello-spring-boot...
OK

Uploading hello-spring-boot...
Uploading app files from: ./hello.jar
Uploading 855.6K, 95 files
Done uploading
OK

Starting app hello-spring-boot in org pasapi@au1.ibm.com / space apple as pasapi@au1.ibm.com...
-----> Downloaded app package (15M)
-----> Liberty Buildpack Version: v1.13-20150209-1122
-----> Avoid Trouble: Specify a minimum of 512M as the Memory Limit for your apps when using IBM JDK.
-----> Retrieving IBM 1.7.1_sr2fp1ifx-20141220 JRE (ibm-java-jre-7.1-2.1-pxa6470_27sr2fp1ifx-20141220_02-sfj.tgz) ... (0.0s)
-----> Retrieving App Management Agent 2015.02.04_102631 (com.ibm.ws.cloudoe.app-mgmt-proxy-agent.zip) ... (0.0s)
         Expanding App Management to .app-management (0.0s)
-----> Downloading Auto Reconfiguration 1.7.0_RELEASE from https://download.run.pivotal.io/auto-reconfiguration/auto-reconfiguration-1.7.0_RELEASE.jar (0.8s)
-----> Liberty buildpack is done creating the droplet


0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
1 of 1 instances running

App started


OK

App hello-spring-boot was started using this command `$PWD/.java/jre/bin/java -Xtune:virtualized -Xmx192M -Xdump:none -Xdump:heap:defaults:file=./../dumps/heapdump.%Y%m%d.%H%M%S.%pid.%seq.phd -Xdump:java:defaults:file=./../dumps/javacore.%Y%m%d.%H%M%S.%pid.%seq.txt -Xdump:snap:defaults:file=./../dumps/Snap.%Y%m%d.%H%M%S.%pid.%seq.trc -Xdump:heap+java+snap:events=user -Xdump:tool:events=systhrow,filter=java/lang/OutOfMemoryError,request=serial+exclusive,exec=./.buildpack-diagnostics/killjava.sh $JVM_ARGS org.springframework.boot.loader.JarLauncher --server.port=$PORT`

Showing health and status for app hello-spring-boot in org pasapi@au1.ibm.com / space apple as pasapi@au1.ibm.com...
OK

requested state: started
instances: 1/1
usage: 256M x 1 instances
urls: hello-spring-boot.mybluemix.net
last uploaded: Tue Feb 24 10:19:56 +0000 2015

     state     since                    cpu    memory           disk          details
#0   running   2015-02-24 09:21:03 PM   0.0%   128.8M of 256M   99.7M of 1G



Saturday, 21 February 2015

IBM Bluemix - Deploy your app the way you want

We recently upgraded our capability in the IBM public cloud. Before this new version you could build, test, and deploy apps on Bluemix by using open source Cloud Foundry technology. But now you have more choice bringing two new options as follows

1. IBM Containers Beta

Use IBM Containers to run apps and services in a hosted cloud environment. Port your existing applications to IBM Bluemix and make them publicly accessible and composable. Use a private registry to upload, store, and retrieve your trusted images.

2. Virtual Machines Beta

Get total control over your app's infrastructure by deploying virtual machines. Manage them from the Bluemix dashboard, or from anywhere with OpenStack APIs.


Try it out as follows

https://console.ng.bluemix.net/

Tuesday, 17 February 2015

Creating an IBM Bluemix Server Connection from Eclipse

The post below shows how to create an IBM Bluemix server connection into the USA public hosted PaaS using Eclipse. It assumes you already have an existing account setup with http://bluemix.net/

1. Ensure you have added "IBM Eclipse Tools for Bluemix" as shown in the marketplace installed items.


More info can be found here.

http://marketplace.eclipse.org/content/ibm-eclipse-tools-bluemix

2. In the "Servers" tab click the link to create a new server and click on IBM Bluemix as shown below.


3. Click Next
4. Enter your account details, you can target the public cloud depending on the location, the default is USA based PUBLIC cloud instance


5. Click Next
6. Select the space to target for deployed applications


7. Click Finish

By clicking on the connection you can view connection attributes, plus deployed application, services, routes, memory settings plus more.



The following UTube video shows this in more detail.

https://www.youtube.com/watch?v=GpkXgklzOlk
IBM Eclipse Tools for Bluemix
IBM Eclipse Tools for Bluemix

Monday, 16 February 2015

Spring Boot JPA Thymeleaf application deployed to IBM Bluemix

IBM Bluemix is an open-standards, cloud-based platform for building, managing, and running apps of all types, such as web, mobile, big data, and smart devices. Capabilities include Java, mobile back-end development, and application monitoring, as well as features from ecosystem partners and open source—all provided as-a-service in the cloud.

The example below shows how to deploy an spring boot JPA application to IBM Bluemix. The example is based on the code below.

https://github.com/papicella/BluemixSpringBootJPA

1. Target the IBM Bluemix

cf api https://api.ng.bluemix.net

2. Log in as follows

cf login -u pasapi@au1.ibm.com -p ******-o pasapi@au1.ibm.com -s dev

3. Create a MYSQL service as shown below.

pas.apicella@IBM-XD082415H ~/bluemix-apps/spring-data-jpa-thymeleaf/mysql
$ cf create-service mysql 100 dev-mysql
Creating service dev-mysql in org pasapi@au1.ibm.com / space dev as pasapi@au1.ibm.com...
OK


4.  At this point lets run the application using an embedded tomcat server as shown below.

pas.apicella@IBM-XD082415H ~/bluemix-apps/spring-data-jpa-thymeleaf/mysql
$ java -jar BluemixSpringBootJPA-0.0.1-SNAPSHOT.jar

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.2.0.RELEASE)

2015-02-16 20:12:18.289  INFO 15824 --- [           main] p.cloud.webapp.ApplesCfDemoApplication   : Starting ApplesCfDemoApplication on IBM-XD082415H with PID 15824 (C:\ibm\bluemix\apps\spring-data-jpa-thymeleaf\mysql\BluemixSpringBootJPA-0.0.1-SNAPSHOT.jar started by pas.apicella in C:\ibm\bluemix\apps\spring-data-jpa-thymeleaf\mysql)
2015-02-16 20:12:18.356  INFO 15824 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6b51dbf6: startup date [Mon Feb 16 20:12:18 AEDT 2015]; root of context hierarchy
2015-02-16 20:12:20.679  INFO 15824 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.dao.PersistenceExceptionTranslationAutoConfiguration' of type [class org.springframework.boot.autoconfigure.dao.PersistenceExceptionTranslationAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2015-02-16 20:12:20.779  INFO 15824 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$15fe846f] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2015-02-16 20:12:20.831  INFO 15824 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'transactionAttributeSource' of type [class org.springframework.transaction.annotation.AnnotationTransactionAttributeSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2015-02-16 20:12:20.853  INFO 15824 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'transactionInterceptor' of type [class org.springframework.transaction.interceptor.TransactionInterceptor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

.....

class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2015-02-16 20:12:27.710  INFO 15824 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2015-02-16 20:12:28.385  INFO 15824 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2015-02-16 20:12:28.510  INFO 15824 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080/http
2015-02-16 20:12:28.513  INFO 15824 --- [           main] p.cloud.webapp.ApplesCfDemoApplication   : Started ApplesCfDemoApplication in 10.626 seconds (JVM running for 11.481)


5. Now using a manifest.yml as follows deploy the application to bluemix as shown below.

manifest.yml

applications:
- name: pas-mj-albums
  memory: 512M
  instances: 1
  host: pas-albums
  domain: mybluemix.net
  path: ./BluemixSpringBootJPA-0.0.1-SNAPSHOT.jar
  buildpack: https://github.com/cloudfoundry/java-buildpack.git
  services:
    - dev-mysql


Deployment output

pas.apicella@IBM-XD082415H ~/bluemix-apps/spring-data-jpa-thymeleaf/mysql
$ cf push -f manifest.yml
Using manifest file manifest.yml

Creating app pas-mj-albums in org pasapi@au1.ibm.com / space dev as pasapi@au1.ibm.com...
OK

Creating route pas-mj-albums.mybluemix.net...
OK

Binding pas-mj-albums.mybluemix.net to pas-mj-albums...
OK

Uploading pas-mj-albums...
Uploading app files from: BluemixSpringBootJPA-0.0.1-SNAPSHOT.jar
Uploading 837.2K, 135 files
Done uploading
OK
Binding service dev-mysql to app pas-mj-albums in org pasapi@au1.ibm.com / space dev as pasapi@au1.ibm.com...
OK

Starting app pas-mj-albums in org pasapi@au1.ibm.com / space dev as pasapi@au1.ibm.com...
-----> Java Buildpack Version: 303bda3 | https://github.com/cloudfoundry/java-buildpack.git#303bda3
-----> Uploading droplet (64M)

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-mj-albums was started using this command `SERVER_PORT=$PORT $PWD/.java-buildpack/open_jdk_jre/bin/java -cp $PWD/.:$PWD/.java-buildpack/spring_auto_reconfiguration/spring_auto_reconfiguration-1.7.0_RELEASE.jar -Djava.io.tmpdir=$TMPDIR -XX:OnOutOfMemoryError=$PWD/.java-buildpack/open_jdk_jre/bin/killjava.sh -Xmx382293K -Xms382293K -XX:MaxMetaspaceSize=64M -XX:MetaspaceSize=64M -Xss995K org.springframework.boot.loader.JarLauncher`

Showing health and status for app pas-mj-albums in org pasapi@au1.ibm.com / space dev as pasapi@au1.ibm.com...
OK

requested state: started
instances: ?/1
usage: 512M x 1 instances
urls: pas-mj-albums.mybluemix.net
last uploaded: Mon Feb 16 09:18:28 +0000 2015

     state     since                    cpu    memory           disk
#0   running   2015-02-16 08:20:04 PM   0.0%   393.4M of 512M   129.3M of 1G


6. Once deployed the Bluemix Console page shows it deployed as follows


7. Finally invoking the application using the unique route as follows

http://pas-mj-albums.mybluemix.net/albums





More Information

https://www.ng.bluemix.net/docs/#

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.