Search This Blog

Monday 12 September 2016

JHipster, Spring Boot, AngularJS and finally deployed to Pivotal Cloud Foundry

I have known about JHipster for a while and thought I would finally give it a test drive and deploy a simple scaffolded app to Pivotal Cloud Foundry. In this post I will use the p-mysql (Pivotal MySQL) rather then the ClearDB instance.



1. I created a very basic "Monolithic" application as shown below.

pasapicella@pas-macbook:~/pivotal/software/jhipster/apps/employee-mysql-jhipster$ yo jhipster

.....

                            http://jhipster.github.io

Welcome to the JHipster Generator v3.6.1
Documentation for creating an application: https://jhipster.github.io/creating-an-app/
Application files will be generated in folder: /Users/pasapicella/pivotal/software/jhipster/apps/employee-mysql-jhipster
? (1/16) Which *type* of application would you like to create? Monolithic application (recommended for simple projects)
? (2/16) What is the base name of your application? employee_mysql_jhipster
? (3/16) What is your default Java package name? pas.pivotal.jhipster.employee
? (4/16) Which *type* of authentication would you like to use? HTTP Session Authentication (stateful, default Spring Security mechanism)
? (5/16) Do you want to use social login (Google, Facebook, Twitter)? Warning, this doesn't work with Cassandra! No
? (6/16) Which *type* of database would you like to use? SQL (H2, MySQL, MariaDB, PostgreSQL, Oracle)
? (7/16) Which *production* database would you like to use? MySQL
? (8/16) Which *development* database would you like to use? MySQL
? (9/16) Do you want to use Hibernate 2nd level cache? No
? (10/16) Do you want to use a search engine in your application? No
? (11/16) Do you want to use clustered HTTP sessions? No
? (12/16) Do you want to use WebSockets? No
? (13/16) Would you like to use Maven or Gradle for building the backend? Maven
? (14/16) Would you like to use the LibSass stylesheet preprocessor for your CSS? No
? (15/16) Would you like to enable internationalization support? Yes
? Please choose the native language of the application? English
? Please choose additional languages to install Italian
? (16/16) Which testing frameworks would you like to use? (Press to select)Gatling

Installing languages: en, it

....

2. This creates a lot of scaffold code and I have intentionally said I want to use MySQL so I can then bind to a p-mysql instance when I use the PROD profile shortly. For now lets add a single entity as shown below.

pasapicella@pas-macbook:~/pivotal/software/jhipster/apps/employee-mysql-jhipster$ yo jhipster:entity dept

The entity dept is being created.


Generating field #1

? Do you want to add a field to your entity? Yes
? What is the name of your field? deptno
? What is the type of your field? Long
? Do you want to add validation rules to your field? No

================= Dept =================
Fields
deptno (Long)


Generating field #2

? Do you want to add a field to your entity? Yes
? What is the name of your field? dname
? What is the type of your field? String
? Do you want to add validation rules to your field? No

================= Dept =================
Fields
deptno (Long)
dname (String)


Generating field #3

? Do you want to add a field to your entity? Yes
? What is the name of your field? loc
? What is the type of your field? String
? Do you want to add validation rules to your field? No

================= Dept =================
Fields
deptno (Long)
dname (String)
loc (String)


Generating field #4

? Do you want to add a field to your entity? No

================= Dept =================
Fields
deptno (Long)
dname (String)
loc (String)


Generating relationships to other entities

? Do you want to add a relationship to another entity? No

================= Dept =================
Fields
deptno (Long)
dname (String)
loc (String)



? Do you want to use a Data Transfer Object (DTO)? No, use the entity directly
? Do you want to use separate service class for your business logic? No, the REST controller should use the repository directly
? Do you want pagination on your entity? Yes, with a simple pager

Everything is configured, generating the entity...

....

3. Before you can run this have to do a few things, as shown below.

3.1. Create a database for the application

mysql> create database employee_mysql_jhipster;
Query OK, 1 row affected (0.00 sec)

3.2. Set the password / username you wish to use for me I used my local MYSQL database root user as it's just dev. The file is "./src/main/resources/config" where the application specific profiles exist, in this case all you need to do is edit the "application-dev.yml"

....

datasource:
    type: com.zaxxer.hikari.HikariDataSource
    url: jdbc:mysql://localhost:3306/employee_mysql_jhipster?useUnicode=true&characterEncoding=utf8&useSSL=false
    name:
    username: root
    password: welcome1
    hikari:
        data-source-properties:
            cachePrepStmts: true
            prepStmtCacheSize: 250
            prepStmtCacheSqlLimit: 2048
            useServerPrepStmts: true

....

3.2 You can now run in DEV mode the default profile if you don't select anything and test locally.

/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/bin/java -Dspring.output.ansi.enabled=always -Didea.launcher.port=7533 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath 

....

:: JHipster 🤓  :: Running Spring Boot 1.4.0.RELEASE ::
:: http://jhipster.github.io ::

2016-09-12 11:47:12.327  INFO 5450 --- [           main] p.p.j.employee.EmployeeMysqlJhipsterApp  : Starting EmployeeMysqlJhipsterApp on pas-macbook with PID 5450 (/Users/pasapicella/pivotal/software/jhipster/apps/employee-mysql-jhipster/target/classes started by pasapicella in /Users/pasapicella/pivotal/software/jhipster/apps/employee-mysql-jhipster)
 :

...

----------------------------------------------------------
Application 'employee_mysql_jhipster' is running! Access URLs:
Local: http://127.0.0.1:8080
External: http://127.0.0.1:8080
----------------------------------------------------------

4. At this point we can deploy out application to Pivotal Cloud Foundry BUT before we do that lets ensure we have what we need



4.1. Ensure a p-mysql service exists as shown below.



4.2. Package the PROD profile as shown below

pasapicella@pas-macbook:~/pivotal/software/jhipster/apps/employee-mysql-jhipster$ ./mvnw package -DskipTests=true -B -Pprod
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Employee Mysql Jhipster 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:copy-resources (default-resources) @ employee-mysql-jhipster ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 8 resources
[INFO] Copying 12 resources
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ employee-mysql-jhipster ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 8 resources
[INFO] Copying 12 resources
[INFO]
[INFO] --- maven-enforcer-plugin:1.4.1:enforce (enforce-versions) @ employee-mysql-jhipster ---
[INFO]
[INFO] --- jacoco-maven-plugin:0.7.7.201606060606:prepare-agent (pre-unit-tests) @ employee-mysql-jhipster ---
[INFO] surefireArgLine set to -javaagent:/Users/pasapicella/.m2/repository/org/jacoco/org.jacoco.agent/0.7.7.201606060606/org.jacoco.agent-0.7.7.201606060606-runtime.jar=destfile=/Users/pasapicella/pivotal/software/jhipster/apps/employee-mysql-jhipster/target/test-results/coverage/jacoco/jacoco.exec
[INFO]
[INFO] --- maven-processor-plugin:2.2.4:process (process) @ employee-mysql-jhipster ---
[INFO]
[INFO] --- frontend-maven-plugin:1.0:install-node-and-npm (install node and npm) @ employee-mysql-jhipster ---
[INFO] Node v4.4.7 is already installed.
[INFO] NPM 3.10.5 is already installed.
[INFO]
[INFO] --- frontend-maven-plugin:1.0:npm (npm install) @ employee-mysql-jhipster ---
[INFO] Running 'npm install' in /Users/pasapicella/pivotal/software/jhipster/apps/employee-mysql-jhipster
[INFO]
[INFO] --- frontend-maven-plugin:1.0:bower (bower install) @ employee-mysql-jhipster ---
[INFO] Running 'bower install --no-color' in /Users/pasapicella/pivotal/software/jhipster/apps/employee-mysql-jhipster
[INFO]
[INFO] --- frontend-maven-plugin:1.0:gulp (gulp build) @ employee-mysql-jhipster ---
[INFO] Running 'gulp.js build --no-notification' in /Users/pasapicella/pivotal/software/jhipster/apps/employee-mysql-jhipster
[INFO] [14:51:23] Using gulpfile ~/pivotal/software/jhipster/apps/employee-mysql-jhipster/gulpfile.js
[INFO] [14:51:23] Starting 'clean'...
[INFO] [14:51:23] Finished 'clean' after 22 ms
[INFO] [14:51:23] Starting 'build'...
[INFO] [14:51:23] Starting 'copy:i18n'...
[INFO] [14:51:23] Starting 'copy:fonts'...
[INFO] [14:51:23] Starting 'copy:common'...
[INFO] [14:51:23] Starting 'inject:vendor'...
[INFO] [14:51:23] Starting 'ngconstant:prod'...
[INFO] [14:51:23] Starting 'copy:languages'...
[INFO] [14:51:23] Finished 'ngconstant:prod' after 69 ms
[INFO] [14:51:23] gulp-inject 23 files into index.html.
[INFO] [14:51:23] Finished 'copy:languages' after 61 ms
[INFO] [14:51:23] Finished 'copy:common' after 142 ms
[INFO] [14:51:23] Finished 'inject:vendor' after 140 ms
[INFO] [14:51:23] Finished 'copy:fonts' after 193 ms
[INFO] [14:51:23] Finished 'copy:i18n' after 409 ms
[INFO] [14:51:23] Starting 'copy'...
[INFO] [14:51:23] Finished 'copy' after 8 μs
[INFO] [14:51:23] Starting 'inject:app'...
[INFO] [14:51:23] gulp-inject 108 files into index.html.
[INFO] [14:51:23] Finished 'inject:app' after 245 ms
[INFO] [14:51:23] Starting 'inject:troubleshoot'...
[INFO] [14:51:23] gulp-inject Nothing to inject into index.html.
[INFO] [14:51:23] Finished 'inject:troubleshoot' after 2.49 ms
[INFO] [14:51:23] Starting 'images'...
[INFO] [14:51:23] Starting 'styles'...
[INFO] [14:51:23] Starting 'html'...
[INFO] [14:51:23] Starting 'copy:swagger'...
[INFO] [14:51:23] Starting 'copy:images'...
[INFO] [14:51:23] Finished 'copy:images' after 10 ms
[INFO] [14:51:23] Finished 'styles' after 23 ms
[INFO] [14:51:24] Finished 'html' after 470 ms
[INFO] [14:51:24] Finished 'copy:swagger' after 560 ms
[INFO] [14:51:24] gulp-imagemin: Minified 3 images (saved 0 B - 0%)
[INFO] [14:51:24] Finished 'images' after 718 ms
[INFO] [14:51:24] Starting 'assets:prod'...
[INFO] [14:51:35] Finished 'assets:prod' after 11 s
[INFO] [14:51:35] Finished 'build' after 12 s
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ employee-mysql-jhipster ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 91 source files to /Users/pasapicella/pivotal/software/jhipster/apps/employee-mysql-jhipster/target/classes
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:testResources (default-testResources) @ employee-mysql-jhipster ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ employee-mysql-jhipster ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ employee-mysql-jhipster ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- jacoco-maven-plugin:0.7.7.201606060606:report (post-unit-test) @ employee-mysql-jhipster ---
[INFO] Loading execution data file /Users/pasapicella/pivotal/software/jhipster/apps/employee-mysql-jhipster/target/test-results/coverage/jacoco/jacoco.exec
[INFO] Analyzed bundle 'Employee Mysql Jhipster' with 100 classes
[INFO]
[INFO] --- frontend-maven-plugin:1.0:gulp (gulp test) @ employee-mysql-jhipster ---
[INFO] Skipping test phase.
[INFO]
[INFO] --- maven-war-plugin:2.6:war (default-war) @ employee-mysql-jhipster ---
[INFO] Packaging webapp
[INFO] Assembling webapp [employee-mysql-jhipster] in [/Users/pasapicella/pivotal/software/jhipster/apps/employee-mysql-jhipster/target/employee-mysql-jhipster-0.0.1-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [/Users/pasapicella/pivotal/software/jhipster/apps/employee-mysql-jhipster/target/www]
[INFO] Webapp assembled in [663 msecs]
[INFO] Building war: /Users/pasapicella/pivotal/software/jhipster/apps/employee-mysql-jhipster/target/employee-mysql-jhipster-0.0.1-SNAPSHOT.war
[INFO]
[INFO] --- spring-boot-maven-plugin:1.4.0.RELEASE:repackage (default) @ employee-mysql-jhipster ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 56.889 s
[INFO] Finished at: 2016-09-12T14:51:48+10:00
[INFO] Final Memory: 52M/441M
[INFO] ------------------------------------------------------------------------

5. Lets create a manifest.yml file to deploy our application in the root directory of the project

manifest-cf.yml

---
path: ./target/employee-mysql-jhipster-0.0.1-SNAPSHOT.war
instances: 1
buildpack: https://github.com/cloudfoundry/java-buildpack
services:
- pas-mysql
applications:
- name: employeemysqljhipster
  env:
    SPRING_PROFILES_ACTIVE: prod, cloudfoundry

6. Deploy as follows

pasapicella@pas-macbook:~/pivotal/software/jhipster/apps/employee-mysql-jhipster$ cf push -f manifest-cf.yml
Using manifest file manifest-cf.yml

Creating app employeemysqljhipster in org pivot-papicella / space development as papicella@pivotal.io...
OK

Creating route employeemysqljhipster.cfapps.pez.pivotal.io...
OK

Binding employeemysqljhipster.cfapps.pez.pivotal.io to employeemysqljhipster...
OK

Uploading employeemysqljhipster...
Uploading app files from: /var/folders/c3/27vscm613fjb6g8f5jmc2x_w0000gp/T/unzipped-app797077453
Uploading 25.1M, 3361 files
Done uploading
OK
Binding service pas-mysql to app employeemysqljhipster in org pivot-papicella / space development as papicella@pivotal.io...
OK

Starting app employeemysqljhipster in org pivot-papicella / space development as papicella@pivotal.io...
Creating container
Successfully created container
Downloading app package...
Downloaded app package (47.5M)
Staging...
-----> Java Buildpack Version: 1447aa9 | https://github.com/cloudfoundry/java-buildpack#1447aa9
-----> Downloading Open Jdk JRE 1.8.0_101 from https://java-buildpack.cloudfoundry.org/openjdk/trusty/x86_64/openjdk-1.8.0_101.tar.gz (4.6s)
       Expanding Open Jdk JRE to .java-buildpack/open_jdk_jre (1.3s)
-----> Downloading Open JDK Like Memory Calculator 2.0.2_RELEASE from https://java-buildpack.cloudfoundry.org/memory-calculator/trusty/x86_64/memory-calculator-2.0.2_RELEASE.tar.gz (0.6s)
       Memory Settings: -Xms681574K -XX:MetaspaceSize=104857K -Xmx681574K -XX:MaxMetaspaceSize=104857K -Xss349K
-----> Downloading Container Customizer 1.0.0_RELEASE from https://java-buildpack.cloudfoundry.org/container-customizer/container-customizer-1.0.0_RELEASE.jar (0.3s)
-----> Downloading Spring Auto Reconfiguration 1.10.0_RELEASE from https://java-buildpack.cloudfoundry.org/auto-reconfiguration/auto-reconfiguration-1.10.0_RELEASE.jar (0.7s)
Exit status 0
Staging complete
Uploading droplet, build artifacts cache...
Uploading build artifacts cache...
Uploading droplet...
Uploaded build artifacts cache (44.9M)
Uploaded droplet (91.3M)
Uploading complete
Destroying container
Successfully destroyed container

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 employeemysqljhipster 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" && SERVER_PORT=$PORT eval exec $PWD/.java-buildpack/open_jdk_jre/bin/java $JAVA_OPTS -cp $PWD/. org.springframework.boot.loader.WarLauncher`

Showing health and status for app employeemysqljhipster in org pivot-papicella / space development as papicella@pivotal.io...
OK

requested state: started
instances: 1/1
usage: 1G x 1 instances
urls: employeemysqljhipster.cfapps.pez.pivotal.io
last uploaded: Mon Sep 12 03:07:29 UTC 2016
stack: unknown
buildpack: https://github.com/cloudfoundry/java-buildpack

     state     since                    cpu      memory         disk           details
#0   running   2016-09-12 01:09:09 PM   126.5%   546.4M of 1G   200.7M of 1G

Some screen shots of what a JHipster basic application looks like, it has alot for very little effort and a great starting point for a full stack development project. 


How about Italian?


Basic View departments CRUD page





More Information



No comments: