View all files | ||||
| cloudfoundry-client | |
| cloudfoundry-client-reactor | |
| cloudfoundry-operations | |
| cloudfoundry-util |
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.
The Cloud Foundry Java Client has two active versions. The 6.x line includes breaking changes (see below), while the 5.x line maintains backward compatibility.
Warning
Removed since cf-java-client 6.0.x
The DopplerClient.recentLogs() endpoint (and the related RecentLogsRequest / LogMessage types from the org.cloudfoundry.doppler package) have been removed.
This API relied on the Loggregator Doppler/Traffic Controller endpoint /apps/{id}/recentlogs, which was removed in Loggregator ≥ 107.0. The affected platform versions are:
| CF Deployment (CFD) | < 24.3 |
| Tanzu Application Service (TAS) | < 4.0 |
Migration: Replace any call to DopplerClient.recentLogs() with LogCacheClient.read() (available via org.cloudfoundry.logcache.v1.LogCacheClient).
The return type and envelope objects differ between the two APIs:
| Return type | Flux<Envelope> | Mono<ReadResponse> → unpack via response.getEnvelopes().getBatch() |
| Log access | envelope.getLogMessage() → LogMessage | envelope.getLog() → Log |
| Message text | logMessage.getMessage() | log.getPayloadAsText() |
| Message type | MessageType.OUT / ERR | LogType.OUT / ERR |
| Source metadata | logMessage.getSourceType(), .getSourceInstance() | envelope.getTags().get("source_type"), envelope.getInstanceId() |
See the [org.cloudfoundry.doppler][doppler-pkg] and [org.cloudfoundry.logcache.v1][logcache-pkg] Javadoc for full type details.
Note
Operations API users: Use Applications.logs(ApplicationLogsRequest) instead of the removed Applications.logs(LogsRequest).
Warning
Removed since cf-java-client 6.0.x The Applications.logs(LogsRequest) method (and the LogsRequest type) have been removed.
Migration: Use Applications.logs(ApplicationLogsRequest) instead. For recent logs, set recent(true) (the default). For streaming, set recent(false).
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:
Snapshot artifacts can be found in the Spring snapshot repository:
For Gradle, the dependencies would be defined like this:
Snapshot artifacts can be found in the Spring snapshot repository:
Both the cloudfoundry-operations and cloudfoundry-client projects follow a "Reactive" design pattern and expose their responses with Project Reactor Monoss and Fluxs.
Note
DopplerClient — partial deprecation: The recentLogs() method on DopplerClient is deprecated and only works against Loggregator < 107.0 (CFD < 24.3 / TAS < 4.0). See the Deprecations section above for the migration path to LogCacheClient.
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:
In Spring-based applications, you'll want to encapsulate them in bean definitions:
CloudFoundryClient, DopplerClient, and UaaClient are only interfaces. Each has a Reactor-based implementation. To instantiate them, you configure them with builders:
In Spring-based applications, you'll want to encapsulate them in bean definitions:
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.
In Spring-based applications, you'll want to encapsulate this in a bean definition as well:
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:
To relate the example to the description above the following happens:
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):
The above example is more complicated:
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:
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.
The project depends on Java 8. To build from source and install to your local Maven cache, run the following:
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:
To run a specific integration test, run the following replacing with -Dtest=org.cloudfoundry.TestClass#test-method (#test-method is optional):
To run tests & enable HTTP trace output, execute:
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:
| 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. |
| UAA_API_REQUEST_LIMIT | (Optional) If your UAA server does rate limiting and returns 429 errors, set this variable to the smallest limit configured there. Whether your server limits UAA calls is shown in the log, together with the location of the configuration file on the server. Defaults to 0 (no limit). |
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).
Pull requests and Issues are welcome.
This project is released under version 2.0 of the Apache License.