• Stars
    star
    318
  • Rank 127,115 (Top 3 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 12 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Java Client Library for Cloud Foundry

Cloud Foundry Java Client

Maven Central

Artifact Javadocs
cloudfoundry-client javadoc
cloudfoundry-client-reactor javadoc
cloudfoundry-operations javadoc
cloudfoundry-util javadoc

The cf-java-client project is a Java language binding for interacting with a Cloud Foundry instance. The project is broken up into a number of components that expose different levels of abstraction depending on need.

  • cloudfoundry-client โ€“ Interfaces, request, and response objects mapping to the Cloud Foundry REST APIs. This project has no implementation and therefore cannot connect to a Cloud Foundry instance on its own.
  • cloudfoundry-client-reactor โ€“ The default implementation of the cloudfoundry-client project. This implementation is based on Reactor Netty HttpClient.
  • cloudfoundry-operations โ€“ An API and implementation that corresponds to the Cloud Foundry CLI operations. This project builds on the cloudfoundry-client and therefore has a single implementation.

Versions

The Cloud Foundry Java Client has two active versions. The 5.x line is compatible with Spring Boot 2.4.x - 2.6.x just to manage its dependencies, while the 4.x line uses Spring Boot 2.3.x.

Dependencies

Most projects will need two dependencies; the Operations API and an implementation of the Client API. For Maven, the dependencies would be defined like this:

<dependencies>
    <dependency>
        <groupId>org.cloudfoundry</groupId>
        <artifactId>cloudfoundry-client-reactor</artifactId>
        <version>latest.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.cloudfoundry</groupId>
        <artifactId>cloudfoundry-operations</artifactId>
        <version>latest.RELEASE</version>
    </dependency>
    ...
</dependencies>

Snapshot artifacts can be found in the Spring snapshot repository:

<repositories>
    <repository>
        <id>spring-snapshots</id>
        <name>Spring Snapshots</name>
        <url>https://repo.spring.io/snapshot</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
    ...
</repositories>

For Gradle, the dependencies would be defined like this:

dependencies {
    compile 'org.cloudfoundry:cloudfoundry-client-reactor:<latest>.RELEASE'
    compile 'org.cloudfoundry:cloudfoundry-operations:<latest>.RELEASE'
    ...
}

Snapshot artifacts can be found in the Spring snapshot repository:

repositories {
    maven { url 'https://repo.spring.io/snapshot' }
    ...
}

Usage

Both the cloudfoundry-operations and cloudfoundry-client projects follow a "Reactive" design pattern and expose their responses with Project Reactor Monoss and Fluxs.

CloudFoundryClient, DopplerClient, UaaClient Builders

The lowest-level building blocks of the API are ConnectionContext and TokenProvider. These types are intended to be shared between instances of the clients, and come with out of the box implementations. To instantiate them, you configure them with builders:

DefaultConnectionContext.builder()
    .apiHost(apiHost)
    .build();

PasswordGrantTokenProvider.builder()
    .password(password)
    .username(username)
    .build();

In Spring-based applications, you'll want to encapsulate them in bean definitions:

@Bean
DefaultConnectionContext connectionContext(@Value("${cf.apiHost}") String apiHost) {
    return DefaultConnectionContext.builder()
        .apiHost(apiHost)
        .build();
}

@Bean
PasswordGrantTokenProvider tokenProvider(@Value("${cf.username}") String username,
                                         @Value("${cf.password}") String password) {
    return PasswordGrantTokenProvider.builder()
        .password(password)
        .username(username)
        .build();
}

CloudFoundryClient, DopplerClient, and UaaClient are only interfaces. Each has a Reactor-based implementation. To instantiate them, you configure them with builders:

ReactorCloudFoundryClient.builder()
    .connectionContext(connectionContext)
    .tokenProvider(tokenProvider)
    .build();

ReactorDopplerClient.builder()
    .connectionContext(connectionContext)
    .tokenProvider(tokenProvider)
    .build();

ReactorUaaClient.builder()
    .connectionContext(connectionContext)
    .tokenProvider(tokenProvider)
    .build();

In Spring-based applications, you'll want to encapsulate them in bean definitions:

@Bean
ReactorCloudFoundryClient cloudFoundryClient(ConnectionContext connectionContext, TokenProvider tokenProvider) {
    return ReactorCloudFoundryClient.builder()
        .connectionContext(connectionContext)
        .tokenProvider(tokenProvider)
        .build();
}

@Bean
ReactorDopplerClient dopplerClient(ConnectionContext connectionContext, TokenProvider tokenProvider) {
    return ReactorDopplerClient.builder()
        .connectionContext(connectionContext)
        .tokenProvider(tokenProvider)
        .build();
}

@Bean
ReactorUaaClient uaaClient(ConnectionContext connectionContext, TokenProvider tokenProvider) {
    return ReactorUaaClient.builder()
        .connectionContext(connectionContext)
        .tokenProvider(tokenProvider)
        .build();
}

CloudFoundryOperations Builder

The CloudFoundryClient, DopplerClient, and UaaClients provide direct access to the raw REST APIs. This level of abstraction provides the most detailed and powerful access to the Cloud Foundry instance, but also requires users to perform quite a lot of orchestration on their own. Most users will instead want to work at the CloudFoundryOperations layer. Once again this is only an interface and the default implementation of this is the DefaultCloudFoundryOperations. To instantiate one, you configure it with a builder:

NOTE: The DefaultCloudfoundryOperations type does not require all clients in order to run. Since not all operations touch all kinds of clients, you can selectively configure the minimum needed. If a client is missing, the first invocation of a method that requires that client will return an error.

DefaultCloudFoundryOperations.builder()
    .cloudFoundryClient(cloudFoundryClient)
    .dopplerClient(dopplerClient)
    .uaaClient(uaaClient)
    .organization("example-organization")
    .space("example-space")
    .build();

In Spring-based applications, you'll want to encapsulate this in a bean definition as well:

@Bean
DefaultCloudFoundryOperations cloudFoundryOperations(CloudFoundryClient cloudFoundryClient,
                                                     DopplerClient dopplerClient,
                                                     UaaClient uaaClient,
                                                     @Value("${cf.organization}") String organization,
                                                     @Value("${cf.space}") String space) {
    return DefaultCloudFoundryOperations.builder()
            .cloudFoundryClient(cloudFoundryClient)
            .dopplerClient(dopplerClient)
            .uaaClient(uaaClient)
            .organization(organization)
            .space(space)
            .build();
}

CloudFoundryOperations APIs

Once you've got a reference to the CloudFoundryOperations, it's time to start making calls to the Cloud Foundry instance. One of the simplest possible operations is list all of the organizations the user is a member of. The following example does three things:

  1. Requests a list of all organizations
  2. Extracts the name of each organization
  3. Prints the name of each organization to System.out
cloudFoundryOperations.organizations()
    .list()
    .map(OrganizationSummary::getName)
    .subscribe(System.out::println);

To relate the example to the description above the following happens:

  1. .list() โ€“ Lists the Cloud Foundry organizations as a Flux of elements of type Organization.
  2. .map(...) โ€“ Maps each organization to its name (type String). This example uses a method reference; the equivalent lambda would look like organizationSummary -> organizationSummary.getName().
  3. subscribe... โ€“ The terminal operation that receives each name in the Flux. Again, this example uses a method reference and the equivalent lambda would look like name -> System.out.println(name).

CloudFoundryClient APIs

As mentioned earlier, the cloudfoundry-operations implementation builds upon the cloudfoundry-client API. That implementation takes advantage of the same reactive style in the lower-level API. The implementation of the Organizations.list() method (which was demonstrated above) looks like the following (roughly):

cloudFoundryClient.organizations()
    .list(ListOrganizationsRequest.builder()
        .page(1)
        .build())
    .flatMapIterable(ListOrganizationsResponse::getResources)
    .map(resource -> OrganizationSummary.builder()
        .id(resource.getMetadata().getId())
        .name(resource.getEntity().getName())
        .build());

The above example is more complicated:

  1. .list(...) โ€“ Retrieves the first page of Cloud Foundry organizations.
  2. .flatMapIterable(...) โ€“ Substitutes the original Mono with a Flux of the Resources returned by the requested page.
  3. .map(...) โ€“ Maps the Resource to an OrganizationSummary type.

Troubleshooting

If you are having issues with the cf-java-client in your applications...

First, read this article on debugging reactive applications and watch this Spring Tips Video also on debugging reactive apps.

Beyond that, it is helpful to capture the following information:

  1. The version of cf-java-client you are using
  2. If you are using Spring Boot & if so, the version
  3. A description of the problem behavior.
  4. A list of things, if any, you have recently changed in your project (even if seemingly unrelated)
  5. If you are getting failures with an operation or client request, capture the request and response information.
    • You may capture basic request and response information by setting the log level for cloudfoundry-client to DEBUG. For example with Spring Boot, set logging.level.cloudfoundry-client=debug.
    • You may perform a wire capture by setting the log level for cloudfoundry-client.wire to TRACE. For example with Spring Boot, set logging.level.cloudfoundry-client.wire=trace.

If you open a Github issue with a request for help, please include as much of the information above as possible and do not forget to sanitize any request/response data posted.

Development

The project depends on Java 8. To build from source and install to your local Maven cache, run the following:

$ git submodule update --init --recursive
$ ./mvnw clean install

It also depends on Immutables and won't compile in IDEs like Eclipse or IntelliJ unless you also have an enabled annotation processor. See this guide for instructions on how to configure your IDE.

To run the integration tests, run the following:

$ ./mvnw -Pintegration-test clean test

To run a specific integration test, run the following replacing with -Dtest=org.cloudfoundry.TestClass#test-method (#test-method is optional):

./mvnw -Pintegration-test clean test -Dtest=org.cloudfoundry.client.v3.ServiceBrokersTest#update

To run tests & enable HTTP trace output, execute:

CLIENT_LOGGING_LEVEL=trace ./mvnw -Pintegration-test clean test

IMPORTANT Integration tests require admin access and should be run against an empty Cloud Foundry instance. The integration tests are destructive, affecting nearly everything on an instance given the chance.

The integration tests require a running instance of Cloud Foundry to test against. To configure the integration tests with the appropriate connection information use the following environment variables:

Name Description
TEST_ADMIN_CLIENTID Client ID for a client with permissions for a Client Credentials grant
TEST_ADMIN_CLIENTSECRET Client secret for a client with permissions for a Client Credentials grant
TEST_ADMIN_PASSWORD Password for a user with admin permissions
TEST_ADMIN_USERNAME Username for a user with admin permissions
TEST_APIHOST The host of a Cloud Foundry instance. Typically something like api.local.pcfdev.io.
TEST_PROXY_HOST (Optional) The host of a proxy to route all requests through
TEST_PROXY_PASSWORD (Optional) The password for a proxy to route all requests through
TEST_PROXY_PORT (Optional) The port of a proxy to route all requests through. Defaults to 8080.
TEST_PROXY_USERNAME (Optional) The username for a proxy to route all requests through
TEST_SKIPSSLVALIDATION (Optional) Whether to skip SSL validation when connecting to the Cloud Foundry instance. Defaults to false.

If you do not have access to a CloudFoundry instance with admin access, you can run one locally using bosh-deployment & cf-deployment and Virtualbox.

For instructions installing Bosh in VirtualBox using bosh-deployment, see the Install Section to install Bosh.

With Bosh installed, follow the deployment guide to get CF installed. You can skip to step 4, since you're installing into VirtualBox. Be sure to read the entire document before you begin, however pay specific attention to this section which has specific instructions for running locally.

Lastly before running the tests, it is strongly recommended that you take a snapshot of the VMs in the environment. This allows for the quick rollback of the environment should the tests break something (they don't generally, integration tests should clean up after themselves).

Contributing

Pull requests and Issues are welcome.

License

This project is released under version 2.0 of the Apache License.

More Repositories

1

bosh

Cloud Foundry BOSH is an open source tool chain for release engineering, deployment and lifecycle management of large scale distributed services.
Ruby
2,010
star
2

cli

The official command line client for Cloud Foundry
Go
1,733
star
3

uaa

CloudFoundry User Account and Authentication (UAA) Server
Java
1,541
star
4

java-buildpack-memory-calculator

Cloud Foundry JVM Memory Calculator
Go
602
star
5

gosigar

A Golang implementation of the Sigar API
Go
453
star
6

gorouter

CF Router
Go
429
star
7

java-buildpack

Cloud Foundry buildpack for running Java applications
Ruby
425
star
8

go-diodes

Diodes are ring buffers manipulated via atomics.
Go
411
star
9

cf-for-k8s

The open source deployment manifest for Cloud Foundry on Kubernetes
Shell
302
star
10

cf-deployment

The canonical open source deployment manifest for Cloud Foundry
Go
279
star
11

korifi

Cloud Foundry on Kubernetes
Go
271
star
12

stratos

Stratos: Web-based Management UI for Cloud Foundry and Kubernetes
TypeScript
241
star
13

credhub

CredHub centralizes and secures credential generation, storage, lifecycle management, and access
Java
225
star
14

garden

Go Warden
Go
223
star
15

java-buildpack-auto-reconfiguration

Auto-reconfiguration functionality for the Java Buildpack
Java
219
star
16

loggregator-release

Cloud Native Logging
Go
217
star
17

bytefmt

Human readable byte formatter
Go
208
star
18

diego-release

BOSH Release for Diego
HTML
199
star
19

staticfile-buildpack

Deploy static HTML/JS/CSS apps to Cloud Foundry
Go
199
star
20

cloud_controller_ng

Cloud Foundry Cloud Controller
Ruby
181
star
21

bosh-bootloader

Command line utility for standing up a BOSH director on an IAAS of your choice.
Go
176
star
22

bosh-cli

BOSH CLI v2+
Go
174
star
23

nodejs-buildpack

Cloud Foundry buildpack for Node.js
Go
161
star
24

diego-design-notes

Diego Architectural Design Musings and Explications
HTML
142
star
25

php-buildpack

A Cloud Foundry Buildpack for PHP.
Python
142
star
26

bosh-deployment

Collection of BOSH manifests referenced by cloudfoundry/docs-bosh
Shell
125
star
27

python-buildpack

Cloud Foundry buildpack for the Python Language
Go
118
star
28

eirini

Pluggable container orchestration for Cloud Foundry, and a Kubernetes backend
Go
115
star
29

go-buildpack

Cloud Foundry buildpack for the Go Language
Go
80
star
30

multiapps-cli-plugin

A CLI plugin for Multi-Target Application (MTA) operations in Cloud Foundry
Go
77
star
31

cloud-service-broker

OSBAPI service broker that uses Terraform to provision and bind services. Derived from https://github.com/GoogleCloudPlatform/gcp-service-broker
Go
76
star
32

guardian

containers4life
Go
75
star
33

lager

An opinionated logger for Go.
Go
73
star
34

app-autoscaler

Auto Scaling for CF Applications
Go
73
star
35

ibm-websphere-liberty-buildpack

IBM WebSphere Application Server Liberty Buildpack
Ruby
71
star
36

summit-training-classes

Opensourced content for cloud foundry training classes: zero to hero (beginner), bosh/operator, and microservices
JavaScript
69
star
37

cf-networking-release

Container Networking for CloudFoundry
Go
68
star
38

cf-acceptance-tests

CF Acceptance tests
Go
68
star
39

ruby-buildpack

Cloud Foundry buildpack for Ruby, Sinatra and Rails
Go
63
star
40

garden-runc-release

Shell
63
star
41

bosh-google-cpi-release

BOSH Google CPI
Go
62
star
42

bosh-azure-cpi-release

BOSH Azure CPI
Ruby
61
star
43

loggregator

Archived: Now bundled in https://github.com/cloudfoundry/loggregator-release
Go
60
star
44

cf-mysql-release

Cloud Foundry MySQL Release
Go
58
star
45

go-pubsub

Tree based pubsub library for Go.
Go
56
star
46

bosh-agent

BOSH Agent runs on each BOSH deployed VM
Go
56
star
47

docs-book-cloudfoundry

The bookbinder repository for open source Cloud Foundry documentation
HTML
55
star
48

homebrew-tap

Cloud Foundry Homebrew packages
Ruby
53
star
49

multiapps-controller

The server side component (controller) for Multi-Target Application (MTA) for Cloud Foundry
Java
52
star
50

socks5-proxy

This is a go library for starting a socks5 proxy server via SSH
Go
44
star
51

cf-uaac

Ruby
41
star
52

docs-cloudfoundry-concepts

A place for architecture and concept docs
HTML
41
star
53

buildpacks-ci

Concourse CI pipelines for the buildpacks team
HTML
41
star
54

service-fabrik-broker

Cloud Foundry service broker which provisions service instances as Docker containers and BOSH deployments.
JavaScript
40
star
55

grootfs

Garden root file system
Go
40
star
56

routing-release

This is the BOSH release for cloud foundry routers
Ruby
39
star
57

docs-dev-guide

Documentation for application developers who want to deploy their applications to Cloud Foundry
HTML
39
star
58

cf-smoke-tests

Smoke tests for CloudFoundry that are safe to run in a production environment
Go
38
star
59

credhub-cli

CredHub CLI provides a command line interface to interact with CredHub servers
Go
38
star
60

bosh-linux-stemcell-builder

BOSH Ubuntu Linux stemcells
Ruby
37
star
61

haproxy-boshrelease

A BOSH release for haproxy (based on cf-release's haproxy job)
Ruby
37
star
62

pmc-notes

Agendas and Notes for Cloud Foundry Project Management Committee Meetings
36
star
63

eirini-release

Helm release for Project Eirini
Shell
36
star
64

bosh-s3cli

Go CLI for S3
Go
36
star
65

bpm-release

isolated bosh jobs
Go
35
star
66

cfdot

A command-line tool to interact with a Cloud Foundry Diego deployment.
Go
34
star
67

libbuildpack

A library for writing buildpacks
Go
34
star
68

bosh-openstack-cpi-release

BOSH OpenStack CPI
Ruby
33
star
69

java-test-applications

Applications used for testing the Java buildpack
Java
33
star
70

switchboard

Golang TCP Proxy
JavaScript
33
star
71

community

Governance and contact information for Cloud Foundry
Python
32
star
72

docs-bosh

The docs repo for BOSH
HTML
32
star
73

cf-k8s-networking

building a cloud foundry without gorouter....
Go
32
star
74

cflinuxfs2

The official Cloud Foundry app container rootfs
Ruby
31
star
75

pxc-release

BOSH release of Percona Xtradb Cluster
JavaScript
30
star
76

clock

time provider & rich fake for Go
Go
30
star
77

bosh-vsphere-cpi-release

BOSH vSphere CPI
Ruby
30
star
78

os-conf-release

Additional Linux OS configuration release
Go
30
star
79

binary-buildpack

Deploy binaries to Cloud Foundry
Shell
28
star
80

bbs

Internal API to access the database for Diego.
Go
28
star
81

nginx-buildpack

Cloud Foundry buildpack that provides NGINX
Go
28
star
82

jumpbox-deployment

Deploy single vanilla jumpbox machine with BOSH
Shell
28
star
83

bosh-aws-cpi-release

BOSH AWS CPI
Ruby
27
star
84

uaa-release

Bosh Release for the UAA
Ruby
27
star
85

app-autoscaler-release

Automated scaling for apps running on Cloud Foundry
Go
26
star
86

archiver

Utilities for extracting and compressing tgz and zip files.
Go
26
star
87

bosh-backup-and-restore

Go
26
star
88

exemplar-release

Shell
25
star
89

apt-buildpack

Go
25
star
90

diego-notes

Diego Notes
23
star
91

capi-release

Bosh Release for Cloud Controller and friends
HTML
23
star
92

noaa

NOAA is a client library to consume metric and log messages from Doppler.
Go
23
star
93

cli-plugin-repo

Public repository for community created CF CLI plugins.
Go
23
star
94

cf-deployment-concourse-tasks

Shell
23
star
95

buildpack-packager

Buildpack Packager
Ruby
23
star
96

metric-store-release

Metric Store: A Cloud-Native Time Series Database for Cloud Foundry
Go
23
star
97

uaa-cli

CLI for UAA written in Go
Go
22
star
98

galera-healthcheck

A lightweight web server written in Golang to check the health of a node in a Galera cluster
Go
21
star
99

docs-buildpacks

HTML
21
star
100

winc

CLI tool for spawning and running containers on Windows according to the OCI specification
Go
21
star