java-on-cf



java-on-cf

0 1


java-on-cf

Material for a talk in running Java apps on Cloud Foundry

On Github scottfrederick / java-on-cf

Running Java Applications

on Cloud Foundry

Scott Frederick

Community Engineer on Cloud Foundry at Pivotal

@scottyfred

http://www.linkedin.com/in/scottfrederick

https://github.com/scottfrederick

Cloud Foundry

open Platform-as-a-Service

  • sponsored by Pivotal

  • enjoys a vibrant community and ecosystem

  • deployable to VMware vSphere, OpenStack, and AWS

    • additional infrastructure options in the works, including Google Compute Engine and Microsoft Azure

Pivotal CF Hosted

  • run.pivotal.io
  • deployment of Cloud Foundry on AWS
  • includes the Services Marketplace

Pivotal CF

  • commercial enterprise distribution of Cloud Foundry
  • deployable to VMware vSphere
    • other infrastructure options in the future
  • simple wizard-based configuration and installation
  • supports Pivotal One services
    • Pivotal HD
    • Pivotal Analytics
    • Pivotal RabbitMQ
    • MySQL

http://bit.ly/pivotal_cf_demo

Let's push an app

What happened?

  • an isolated container was created in a virtual machine
  • the app was uploaded to the container
  • a JRE was downloaded and installed
  • Tomcat was downloaded, installed, and configured
  • a MySQL database was created and exposed to the app

Buildpacks

Buildpacks are responsible for setting up the environment for an application to run in.

  • including decisions about
    • runtimes - JVM, Ruby runtime, Node.js runtime
    • web containers - Tomcat, Jetty, OSGi
    • library and package management - Ruby gems, NPM packages

Cloud Foundry Java Buildpack

  • easiest way to run Java applications
  • automatic detection of application configuration based on inspection of application bits
  • configurable and extensible by forking the GitHub repository
  • zero-touch services integration

Java Buildpack Concepts

Java Buildpack Containers

Supported containers and detection criteria

choose zero or one

Let's see containers in action

Java Buildpack Frameworks

Supported frameworks and detection criteria

choose all that apply

Let's see frameworks in action

Java Buildpack Customization

  • customizations should be done for a large set of applications, not individual applications
    • reduces configuration drift
    • eases auditing of applications for security concerns

Buildpack Customization by Configuration

  • some choices can be made in config/*.yml files
    • versions of JRE, Tomcat, other artifacts
    • repository locations
    • JRE memory configuration

Let's configure the buildpack

Buildpack Customization by Extension

  • extensions are additive
    • containers, frameworks, JREs
    • config/components.yml
  • well-defined API
    • initialize()
    • detect()
    • compile()
    • release()

Let's extend the buildpack

Java Tooling for Cloud Foundry

  • Maven plugin
  • Gradle plugin
  • Java client library

Cloud Foundry Maven Plugin

<plugin>
  <groupId>org.cloudfoundry</groupId>
  <artifactId>cf-maven-plugin</artifactId>
  <version>1.0.1</version>
  <configuration>
    <server>mycloudfoundry-instance</server>
    <target>http://api.run.pivotal.io</target>
    <org>mycloudfoundry-org</org>
    <space>development</space>
    <appname>my-app</appname>
    <url>my-app.cfapps.io</url>
    <memory>512</memory>
  </configuration>
</plugin>
$ mvn package cf:push

https://github.com/cloudfoundry/cf-java-client/tree/master/cloudfoundry-maven-plugin

Cloud Foundry Gradle Plugin

buildscript {
  dependencies {
    classpath group: 'org.cloudfoundry', name: 'cf-gradle-plugin', version: '1.0.1'
  }
}

apply plugin: 'cloudfoundry'

cloudfoundry {
  target = 'https://api.run.pivotal.io'
  organization = 'mycloudfoundry-org'
  space = 'development'
  application = 'my-app'
  file = new File("${war.archivePath}")
  uri = 'http://my-app.run.pivotal.io'
  memory = '512'
}
$ gradle assemble cf-push

https://github.com/cloudfoundry/cf-java-client/tree/master/cloudfoundry-gradle-plugin

Cloud Foundry Java Client Library

CloudCredentials credentials = new CloudCredentials(user, password);
CloudFoundryClient client = new CloudFoundryClient(credentials, getTargetURL(target));
client.login();

System.out.println("\nSpaces:");
for (CloudSpace space : client.getSpaces()) {
    System.out.println(space.getName() + ":" + space.getOrganization().getName());
}

System.out.println("\nApplications:");
for (CloudApplication app : client.getApplications()) {
    System.out.println(app.getName());
}

System.out.println("\nServices");
for (CloudService service : client.getServices()) {
    System.out.println(service.getName() + ":" + service.getLabel());
}

http://docs.cloudfoundry.com/docs/using/managing-apps/libs/java-client.html

Go Forth and Push!