All Projects → cloudfoundry → Cf Java Client

cloudfoundry / Cf Java Client

Licence: apache-2.0
Java Client Library for Cloud Foundry

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Cf Java Client

cf-workshop
Cloud Foundry Workshop
Stars: ✭ 36 (-88.08%)
Mutual labels:  cloud-foundry
reactor-go
A golang implementation for reactive-streams.
Stars: ✭ 48 (-84.11%)
Mutual labels:  reactor
cloud-native-pwas
Cloud Native Progressive Web Apps with Spring Boot and Angular
Stars: ✭ 31 (-89.74%)
Mutual labels:  cloud-foundry
heroku-buildpack-deno
Heroku Buildpack for Deno
Stars: ✭ 72 (-76.16%)
Mutual labels:  cloud-foundry
cloud-service-broker
OSBAPI service broker that uses Terraform to provision and bind services. Derived from https://github.com/GoogleCloudPlatform/gcp-service-broker
Stars: ✭ 54 (-82.12%)
Mutual labels:  cloud-foundry
btp-full-stack-typescript-app
A sample project to demonstrate how to implement a full-stack app with SAP Cloud Application Programming Model, plus SAPUI5 and TypeScript.
Stars: ✭ 27 (-91.06%)
Mutual labels:  cloud-foundry
logsearch-boshrelease
A BOSH-scalable ELK release
Stars: ✭ 45 (-85.1%)
Mutual labels:  cloud-foundry
Spring Cloud Gateway
A Gateway built on Spring Framework 5.x and Spring Boot 2.x providing routing and more.
Stars: ✭ 3,305 (+994.37%)
Mutual labels:  reactor
Home
This is the old home for the Steeltoe project. Please refer to the SteeltoeOSS/steeltoe repository moving forward.
Stars: ✭ 49 (-83.77%)
Mutual labels:  cloud-foundry
abaplint-sci-server
Node backend application for running abaplint on ABAP
Stars: ✭ 15 (-95.03%)
Mutual labels:  cloud-foundry
ReactionMechanismSimulator.jl
The amazing Reaction Mechanism Simulator for simulating large chemical kinetic mechanisms
Stars: ✭ 39 (-87.09%)
Mutual labels:  reactor
bluechatter
Deploy & Scale a chat app using Cloud Foundry, Docker Container and Kubernetes
Stars: ✭ 64 (-78.81%)
Mutual labels:  cloud-foundry
mockpi
Reactive REST API mocking
Stars: ✭ 13 (-95.7%)
Mutual labels:  reactor
bluemix-go
Go library for accessing the Bluemix API
Stars: ✭ 37 (-87.75%)
Mutual labels:  cloud-foundry
tomee-buildpack
Cloud Foundry buildpack for running Java applications using TomEE
Stars: ✭ 12 (-96.03%)
Mutual labels:  cloud-foundry
Fiori-for-iOS-Roadshow-2019
A collection of materials for the joined SAP and Apple Roadshow event.
Stars: ✭ 12 (-96.03%)
Mutual labels:  cloud-foundry
Matlab4CRE
Collection of Matlab codes to solve typical CRE (Chemical Reaction Engineering) problems
Stars: ✭ 32 (-89.4%)
Mutual labels:  reactor
Webserver
A C++ High Performance Web Server
Stars: ✭ 4,164 (+1278.81%)
Mutual labels:  reactor
Reactive
Reactive: Examples of the most famous reactive libraries that you can find in the market.
Stars: ✭ 256 (-15.23%)
Mutual labels:  reactor
Security
ASP.NET Security Providers for CloudFoundry
Stars: ✭ 27 (-91.06%)
Mutual labels:  cloud-foundry

Cloud Foundry Java Client

Maven Central

Artifact Javadocs
cloudfoundry-client javadoc
cloudfoundry-client-reactor javadoc
cloudfoundry-operations javadoc
cloudfoundry-util javadoc
Job Status
unit-test java 8 unit-test-8-main
unit-test java 11 unit-test-11-main
integration-test-2.7 integration-test-2.7-main
integration-test-2.8 integration-test-2.8-main
integration-test-2.9 integration-test-2.9-main
integration-test-2.10 integration-test-2.10-main
deploy deploy-main

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 uses Spring Boot 2.4.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>5.0.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.cloudfoundry</groupId>
        <artifactId>cloudfoundry-operations</artifactId>
        <version>5.0.0.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:5.0.0.RELEASE'
    compile 'org.cloudfoundry:cloudfoundry-operations:5.0.0.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.

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

IMPORTANT Integration tests 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.

Contributing

Pull requests and Issues are welcome.

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].