### Start Application with V3 API Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Initiates the starting process for a specified application. Ensure the applicationId is valid. ```java import org.cloudfoundry.client.v3.applications.StartApplicationRequest; // Start application cloudFoundryClient.applicationsV3() .start(StartApplicationRequest.builder() .applicationId(applicationId) .build()) .block(); ``` -------------------------------- ### Build the project from source Source: https://github.com/cloudfoundry/cf-java-client/blob/main/README.md Initializes submodules and installs the project to the local Maven cache. ```shell $ git submodule update --init --recursive $ ./mvnw clean install ``` -------------------------------- ### Manage Application Lifecycle in Java Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Perform start, stop, restart, restage, and instance-specific restart operations on Cloud Foundry applications. ```java import org.cloudfoundry.operations.applications.StartApplicationRequest; import org.cloudfoundry.operations.applications.StopApplicationRequest; import org.cloudfoundry.operations.applications.RestartApplicationRequest; import org.cloudfoundry.operations.applications.RestageApplicationRequest; import org.cloudfoundry.operations.applications.RestartApplicationInstanceRequest; // Start an application cloudFoundryOperations.applications() .start(StartApplicationRequest.builder() .name("my-application") .build()) .block(); // Stop an application cloudFoundryOperations.applications() .stop(StopApplicationRequest.builder() .name("my-application") .build()) .block(); // Restart an application cloudFoundryOperations.applications() .restart(RestartApplicationRequest.builder() .name("my-application") .build()) .block(); // Restage an application (rebuild droplet) cloudFoundryOperations.applications() .restage(RestageApplicationRequest.builder() .name("my-application") .build()) .block(); // Restart a specific instance cloudFoundryOperations.applications() .restartInstance(RestartApplicationInstanceRequest.builder() .name("my-application") .instanceIndex(0) .build()) .block(); ``` -------------------------------- ### Get Application Details Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Fetches detailed metadata and instance-level metrics for a specific application by name. ```java import org.cloudfoundry.operations.applications.GetApplicationRequest; import org.cloudfoundry.operations.applications.ApplicationDetail; // Get detailed application info cloudFoundryOperations.applications() .get(GetApplicationRequest.builder() .name("my-application") .build()) .subscribe(app -> { System.out.println("Name: " + app.getName()); System.out.println("ID: " + app.getId()); System.out.println("State: " + app.getRequestedState()); System.out.println("Instances: " + app.getInstances()); System.out.println("Memory: " + app.getMemoryLimit() + "MB"); System.out.println("Disk: " + app.getDiskQuota() + "MB"); System.out.println("URLs: " + app.getUrls()); System.out.println("Buildpacks: " + app.getBuildpacks()); System.out.println("Running Instances: " + app.getRunningInstances()); app.getInstanceDetails().forEach(instance -> { System.out.printf(" Instance %s: %s, CPU: %.2f%%, Memory: %d/%d%n", instance.getIndex(), instance.getState(), instance.getCpu(), instance.getMemoryUsage(), instance.getMemoryQuota()); }); }); ``` -------------------------------- ### Cloud Foundry Connection Context and Token Provider Setup Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Set up the connection context with the API endpoint and configure token providers for authentication. Supports password grants for users and client credentials grants for service accounts. SSL validation can be skipped if necessary. ```java import org.cloudfoundry.reactor.DefaultConnectionContext; import org.cloudfoundry.reactor.tokenprovider.PasswordGrantTokenProvider; import org.cloudfoundry.reactor.tokenprovider.ClientCredentialsGrantTokenProvider; // Create connection context with API endpoint DefaultConnectionContext connectionContext = DefaultConnectionContext.builder() .apiHost("api.example.cloudfoundry.com") .skipSslValidation(false) // Set true for self-signed certs .build(); // Password-based authentication for user credentials PasswordGrantTokenProvider tokenProvider = PasswordGrantTokenProvider.builder() .username("admin@example.com") .password("your-password") .build(); // Alternative: Client credentials grant for service accounts ClientCredentialsGrantTokenProvider clientTokenProvider = ClientCredentialsGrantTokenProvider.builder() .clientId("your-client-id") .clientSecret("your-client-secret") .build(); ``` -------------------------------- ### Push Application Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Deploy applications to Cloud Foundry. Supports pushing from ZIP files, Docker images, and configuring custom domains, hosts, and health checks. Use 'noStart(true)' to deploy without starting the application. ```java import org.cloudfoundry.operations.applications.PushApplicationRequest; import org.cloudfoundry.operations.applications.ApplicationHealthCheck; import java.nio.file.Paths; // Push a new application from a ZIP file cloudFoundryOperations.applications() .push(PushApplicationRequest.builder() .name("my-application") .path(Paths.get("/path/to/application.zip")) .buildpack("staticfile_buildpack") .diskQuota(512) .memory(256) .instances(2) .healthCheckType(ApplicationHealthCheck.PORT) .noStart(false) .build()) .block(); // Push with custom domain and host cloudFoundryOperations.applications() .push(PushApplicationRequest.builder() .name("my-app") .path(Paths.get("/path/to/app")) .buildpack("java_buildpack") .diskQuota(1024) .memory(512) .domain("example.com") .host("my-app") .routePath("/api") .healthCheckType(ApplicationHealthCheck.HTTP) .healthCheckHttpEndpoint("/health") .build()) .block(); // Push Docker application cloudFoundryOperations.applications() .push(PushApplicationRequest.builder() .name("docker-app") .dockerImage("cloudfoundry/lattice-app") .diskQuota(512) .memory(64) .healthCheckType(ApplicationHealthCheck.PORT) .build()) .block(); ``` -------------------------------- ### Get Application Health Check Configuration Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Retrieve the current health check configuration for an application. The result is blocked until retrieved. ```java import org.cloudfoundry.operations.applications.GetApplicationHealthCheckRequest; import org.cloudfoundry.operations.applications.ApplicationHealthCheck; // Get current health check configuration ApplicationHealthCheck healthCheck = cloudFoundryOperations.applications() .getHealthCheck(GetApplicationHealthCheckRequest.builder() .name("my-application") .build()) .block(); System.out.println("Health Check Type: " + healthCheck); ``` -------------------------------- ### Wait for Build to Complete and Get Droplet ID Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Polls the build status until it is STAGED, then extracts the droplet ID. This operation has a timeout and retries with a delay. ```java import org.cloudfoundry.client.v3.builds.GetBuildRequest; import org.cloudfoundry.client.v3.builds.BuildState; import java.time.Duration; // Wait for build to complete and get droplet String dropletId = cloudFoundryClient.builds() .get(GetBuildRequest.builder() .buildId(buildId) .build()) .repeatWhen(flux -> flux.delayElements(Duration.ofSeconds(5))) .filter(response -> response.getState() == BuildState.STAGED) .next() .map(response -> response.getDroplet().getId()) .block(Duration.ofMinutes(10)); ``` -------------------------------- ### Build DefaultCloudFoundryOperations Source: https://github.com/cloudfoundry/cf-java-client/blob/main/README.md Instantiate `DefaultCloudFoundryOperations` by configuring it with necessary clients and organization/space details. Not all clients are required. ```java DefaultCloudFoundryOperations.builder() .cloudFoundryClient(cloudFoundryClient) .dopplerClient(dopplerClient) .uaaClient(uaaClient) .organization("example-organization") .space("example-space") .build(); ``` -------------------------------- ### Create Service Instances Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Create managed service instances with optional parameters or user-provided service instances with credentials or syslog drains. ```java import org.cloudfoundry.operations.services.CreateServiceInstanceRequest; import org.cloudfoundry.operations.services.CreateUserProvidedServiceInstanceRequest; import java.util.HashMap; import java.util.Map; // Create a managed service instance cloudFoundryOperations.services() .createInstance(CreateServiceInstanceRequest.builder() .serviceInstanceName("my-database") .serviceName("postgresql") .planName("standard") .build()) .block(); // Create with parameters Map params = new HashMap<>(); params.put("storage_size", "10GB"); params.put("backup_enabled", true); cloudFoundryOperations.services() .createInstance(CreateServiceInstanceRequest.builder() .serviceInstanceName("my-configured-db") .serviceName("postgresql") .planName("premium") .parameters(params) .build()) .block(); // Create user-provided service instance Map credentials = new HashMap<>(); credentials.put("uri", "postgres://user:pass@external-db.example.com:5432/mydb"); credentials.put("username", "dbuser"); credentials.put("password", "dbpassword"); cloudFoundryOperations.services() .createUserProvidedInstance(CreateUserProvidedServiceInstanceRequest.builder() .name("external-database") .credentials(credentials) .build()) .block(); // User-provided service with syslog drain cloudFoundryOperations.services() .createUserProvidedInstance(CreateUserProvidedServiceInstanceRequest.builder() .name("log-drain") .syslogDrainUrl("syslog-tls://logs.example.com:6514") .build()) .block(); ``` -------------------------------- ### Create Build from Package Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Initiates the build process for an application using a prepared package. Requires the package ID and returns a build ID upon success. ```java import org.cloudfoundry.client.v3.builds.CreateBuildRequest; // Create a build from the package CreateBuildResponse buildResponse = cloudFoundryClient.builds() .create(CreateBuildRequest.builder() .getPackage(Relationship.builder() .id(packageId) .build()) .build()) .block(); String buildId = buildResponse.getId(); ``` -------------------------------- ### List organizations with CloudFoundryClient Source: https://github.com/cloudfoundry/cf-java-client/blob/main/README.md Demonstrates the lower-level client API implementation for fetching and mapping organization resources. ```java cloudFoundryClient.organizations() .list(ListOrganizationsRequest.builder() .page(1) .build()) .flatMapIterable(ListOrganizationsResponse::getResources) .map(resource -> OrganizationSummary.builder() .id(resource.getMetadata().getId()) .name(resource.getEntity().getName()) .build()); ``` -------------------------------- ### Create Application with V3 API Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Use this snippet to create a new application with specified name, environment variables, metadata, and space relationship. Ensure the spaceId is available. ```java import org.cloudfoundry.client.v3.applications.*; import org.cloudfoundry.client.v3.Metadata; import org.cloudfoundry.client.v3.Relationship; import org.cloudfoundry.client.v3.ToOneRelationship; // Create application with V3 API cloudFoundryClient.applicationsV3() .create(CreateApplicationRequest.builder() .name("my-v3-application") .environmentVariable("ENV_VAR", "value") .metadata(Metadata.builder() .label("environment", "production") .label("team", "backend") .annotation("contact", "team@example.com") .build()) .relationships(ApplicationRelationships.builder() .space(ToOneRelationship.builder() .data(Relationship.builder() .id(spaceId) .build()) .build()) .build()) .build()) .subscribe(response -> { System.out.println("Created App ID: " + response.getId()); }); ``` -------------------------------- ### Build ReactorCloudFoundryClient Source: https://github.com/cloudfoundry/cf-java-client/blob/main/README.md Instantiate `ReactorCloudFoundryClient` using a `ConnectionContext` and `TokenProvider`. This provides Reactor-based access to raw REST APIs. ```java ReactorCloudFoundryClient.builder() .connectionContext(connectionContext) .tokenProvider(tokenProvider) .build(); ``` -------------------------------- ### Push Application with Manifest Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Deploys applications using a manifest definition for repeatable configurations. Requires an ApplicationManifest builder to specify resources, environment variables, and routes. ```java import org.cloudfoundry.operations.applications.PushApplicationManifestRequest; import org.cloudfoundry.operations.applications.ApplicationManifest; import org.cloudfoundry.operations.applications.Route; import java.nio.file.Paths; import java.util.Arrays; // Push using application manifest cloudFoundryOperations.applications() .pushManifest(PushApplicationManifestRequest.builder() .manifest(ApplicationManifest.builder() .name("my-application") .path(Paths.get("/path/to/application.zip")) .buildpack("java_buildpack") .disk(1024) .memory(512) .instances(2) .healthCheckType(ApplicationHealthCheck.HTTP) .healthCheckHttpEndpoint("/actuator/health") .environmentVariable("SPRING_PROFILES_ACTIVE", "cloud") .environmentVariable("JAVA_OPTS", "-Xmx384m") .service("my-database") .service("my-redis") .route(Route.builder() .route("my-app.example.com") .build()) .route(Route.builder() .route("api.example.com/v1") .build()) .build()) .noStart(false) .build()) .block(); // Push with multiple buildpacks cloudFoundryOperations.applications() .pushManifest(PushApplicationManifestRequest.builder() .manifest(ApplicationManifest.builder() .name("multi-buildpack-app") .path(Paths.get("/path/to/app")) .buildpacks(Arrays.asList("nodejs_buildpack", "python_buildpack")) .disk(512) .memory(256) .build()) .noStart(true) .build()) .block(); ``` -------------------------------- ### Build ReactorDopplerClient Source: https://github.com/cloudfoundry/cf-java-client/blob/main/README.md Instantiate `ReactorDopplerClient` using a `ConnectionContext` and `TokenProvider`. This provides Reactor-based access to raw REST APIs. ```java ReactorDopplerClient.builder() .connectionContext(connectionContext) .tokenProvider(tokenProvider) .build(); ``` -------------------------------- ### List Organizations via Client API V2 Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Shows how to list organizations using the low-level V2 Client API, including pagination support. ```java import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.organizations.ListOrganizationsRequest; import org.cloudfoundry.client.v2.organizations.OrganizationResource; // List organizations with pagination cloudFoundryClient.organizations() .list(ListOrganizationsRequest.builder() .page(1) .build()) .flatMapIterable(response -> response.getResources()) .map(resource -> OrganizationSummary.builder() .id(resource.getMetadata().getId()) .name(resource.getEntity().getName()) .build()) .subscribe(org -> System.out.println(org.getName())); ``` -------------------------------- ### List and Retrieve Services Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Retrieve lists of service instances, specific instance details, or available service offerings from the marketplace. ```java import org.cloudfoundry.operations.services.ServiceInstanceSummary; import org.cloudfoundry.operations.services.GetServiceInstanceRequest; import org.cloudfoundry.operations.services.ListServiceOfferingsRequest; // List all service instances in current space cloudFoundryOperations.services() .listInstances() .subscribe(service -> { System.out.printf("Service: %s, Plan: %s, Type: %s%n", service.getName(), service.getPlan(), service.getType()); }); // Get service instance details cloudFoundryOperations.services() .getInstance(GetServiceInstanceRequest.builder() .name("my-database") .build()) .subscribe(service -> { System.out.println("Name: " + service.getName()); System.out.println("Service: " + service.getService()); System.out.println("Plan: " + service.getPlan()); System.out.println("Bound Apps: " + service.getApplications()); System.out.println("Dashboard URL: " + service.getDashboardUrl()); }); // List available service offerings in marketplace cloudFoundryOperations.services() .listServiceOfferings(ListServiceOfferingsRequest.builder() .build()) .subscribe(offering -> { System.out.printf("Service: %s - %s%n", offering.getLabel(), offering.getDescription()); }); ``` -------------------------------- ### Enable Wire-Level Trace Logging Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Configure logging to TRACE level for `cloudfoundry-client.wire` to include request and response bodies in logs. ```properties logging.level.cloudfoundry-client.wire=TRACE ``` -------------------------------- ### Scale Application Resources in Java Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Adjust application instances, memory limits, and disk quotas individually or simultaneously. ```java import org.cloudfoundry.operations.applications.ScaleApplicationRequest; // Scale instances cloudFoundryOperations.applications() .scale(ScaleApplicationRequest.builder() .name("my-application") .instances(4) .build()) .block(); // Scale memory cloudFoundryOperations.applications() .scale(ScaleApplicationRequest.builder() .name("my-application") .memoryLimit(1024) .build()) .block(); // Scale disk quota cloudFoundryOperations.applications() .scale(ScaleApplicationRequest.builder() .name("my-application") .diskLimit(2048) .build()) .block(); // Scale all at once cloudFoundryOperations.applications() .scale(ScaleApplicationRequest.builder() .name("my-application") .instances(3) .memoryLimit(512) .diskLimit(1024) .build()) .block(); ``` -------------------------------- ### Create Package for Application Upload Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Creates a new package associated with an application, preparing it for bits upload. Requires the application ID and specifies the package type. ```java import org.cloudfoundry.client.v3.packages.*; import org.cloudfoundry.client.v3.Metadata; import org.cloudfoundry.client.v3.Relationship; import org.cloudfoundry.client.v3.ToOneRelationship; // Create a package CreatePackageResponse packageResponse = cloudFoundryClient.packages() .create(CreatePackageRequest.builder() .type(PackageType.BITS) .relationships(PackageRelationships.builder() .application(ToOneRelationship.builder() .data(Relationship.builder() .id(applicationId) .build()) .build()) .build()) .build()) .block(); String packageId = packageResponse.getId(); ``` -------------------------------- ### Create and Delete Organization Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Use this to create a new organization or delete an existing one. Ensure the organization name is unique. ```java import org.cloudfoundry.operations.organizations.CreateOrganizationRequest; import org.cloudfoundry.operations.organizations.DeleteOrganizationRequest; // Create a new organization cloudFoundryOperations.organizations() .create(CreateOrganizationRequest.builder() .organizationName("new-organization") .build()) .block(); // Delete an organization cloudFoundryOperations.organizations() .delete(DeleteOrganizationRequest.builder() .name("organization-to-delete") .build()) .block(); ``` -------------------------------- ### Manage Application Routes Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Create, map, unmap, and delete routes for applications. Includes functionality to check for route existence and clean up orphaned routes. ```java import org.cloudfoundry.operations.routes.CreateRouteRequest; import org.cloudfoundry.operations.routes.ListRoutesRequest; import org.cloudfoundry.operations.routes.MapRouteRequest; import org.cloudfoundry.operations.routes.UnmapRouteRequest; import org.cloudfoundry.operations.routes.DeleteRouteRequest; import org.cloudfoundry.operations.routes.CheckRouteRequest; // Create a route cloudFoundryOperations.routes() .create(CreateRouteRequest.builder() .domain("example.com") .host("my-app") .path("/api") .space("development") .build()) .block(); // Check if route exists Boolean routeExists = cloudFoundryOperations.routes() .check(CheckRouteRequest.builder() .domain("example.com") .host("my-app") .path("/api") .build()) .block(); // List all routes cloudFoundryOperations.routes() .list(ListRoutesRequest.builder() .build()) .subscribe(route -> { System.out.printf("Route: %s.%s%s -> %s%n", route.getHost(), route.getDomain(), route.getPath(), route.getApplications()); }); // Map route to application cloudFoundryOperations.routes() .map(MapRouteRequest.builder() .applicationName("my-application") .domain("example.com") .host("api") .build()) .block(); // Unmap route from application cloudFoundryOperations.routes() .unmap(UnmapRouteRequest.builder() .applicationName("my-application") .domain("example.com") .host("api") .build()) .block(); // Delete a route cloudFoundryOperations.routes() .delete(DeleteRouteRequest.builder() .domain("example.com") .host("old-api") .build()) .block(); // Delete orphaned routes (not mapped to any apps) cloudFoundryOperations.routes() .deleteOrphanedRoutes(DeleteOrphanedRoutesRequest.builder() .build()) .block(); ``` -------------------------------- ### List Application Tasks Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Retrieve a list of tasks for a given application. The results are subscribed to as they become available. ```java import org.cloudfoundry.operations.applications.ListApplicationTasksRequest; import org.cloudfoundry.operations.applications.Task; // List tasks for an application cloudFoundryOperations.applications() .listTasks(ListApplicationTasksRequest.builder() .name("my-application") .build()) .subscribe(t -> { System.out.printf("Task %d: %s - %s%n", t.getSequenceId(), t.getName(), t.getState()); }); ``` -------------------------------- ### Wait for Package to be Ready Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Polls the status of a package until it reaches the READY state. This is crucial before proceeding to build creation. It includes a delay and a timeout. ```java import org.cloudfoundry.client.v3.packages.GetPackageRequest; import org.cloudfoundry.client.v3.packages.PackageState; import java.time.Duration; // Wait for package to be ready cloudFoundryClient.packages() .get(GetPackageRequest.builder() .packageId(packageId) .build()) .repeatWhen(flux -> flux.delayElements(Duration.ofSeconds(2))) .filter(response -> response.getState() == PackageState.READY) .next() .block(Duration.ofMinutes(5)); ``` -------------------------------- ### List Applications Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Retrieves a list of all applications within the current space. Results can be processed reactively or collected into a list. ```java import org.cloudfoundry.operations.applications.ApplicationSummary; // List all applications cloudFoundryOperations.applications() .list() .subscribe(app -> { System.out.printf("App: %s, State: %s, Instances: %d/%d%n", app.getName(), app.getRequestedState(), app.getRunningInstances(), app.getInstances()); }); // Collect to list List apps = cloudFoundryOperations.applications() .list() .collectList() .block(); ``` -------------------------------- ### Upload Application Bits to Package Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Uploads the application's archive (e.g., a zip file) to a previously created package. Ensure the packageId and the path to the bits are correct. ```java import org.cloudfoundry.client.v3.packages.UploadPackageRequest; import java.nio.file.Paths; // Upload bits to package cloudFoundryClient.packages() .upload(UploadPackageRequest.builder() .packageId(packageId) .bits(Paths.get("/path/to/application.zip")) .build()) .block(); ``` -------------------------------- ### Run Application Task Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Execute a one-off task on an application. Specify command, task name, disk, and memory. The task is blocked until completion. ```java import org.cloudfoundry.operations.applications.RunApplicationTaskRequest; import org.cloudfoundry.operations.applications.Task; // Run a task Task task = cloudFoundryOperations.applications() .runTask(RunApplicationTaskRequest.builder() .applicationName("my-application") .command("rake db:migrate") .taskName("database-migration") .disk(512) .memory(256) .build()) .block(); System.out.println("Task ID: " + task.getSequenceId()); System.out.println("State: " + task.getState()); ``` -------------------------------- ### Build ReactorUaaClient Source: https://github.com/cloudfoundry/cf-java-client/blob/main/README.md Instantiate `ReactorUaaClient` using a `ConnectionContext` and `TokenProvider`. This provides Reactor-based access to raw REST APIs. ```java ReactorUaaClient.builder() .connectionContext(connectionContext) .tokenProvider(tokenProvider) .build(); ``` -------------------------------- ### List and Manage Spaces Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Manage spaces within the current organization. This includes listing, creating, retrieving details, and deleting spaces. Ensure the organization name is specified when creating a space. ```java import org.cloudfoundry.operations.spaces.SpaceSummary; import org.cloudfoundry.operations.spaces.CreateSpaceRequest; import org.cloudfoundry.operations.spaces.DeleteSpaceRequest; import org.cloudfoundry.operations.spaces.GetSpaceRequest; // List all spaces in current organization cloudFoundryOperations.spaces() .list() .subscribe(space -> System.out.println(space.getName())); // Create a new space cloudFoundryOperations.spaces() .create(CreateSpaceRequest.builder() .name("development") .organization("my-organization") .build()) .block(); // Get space details cloudFoundryOperations.spaces() .get(GetSpaceRequest.builder() .name("development") .build()) .subscribe(spaceDetail -> { System.out.println("Space ID: " + spaceDetail.getId()); System.out.println("Applications: " + spaceDetail.getApplicationNames()); }); // Allow/disallow SSH for a space cloudFoundryOperations.spaces() .allowSsh(AllowSpaceSshRequest.builder() .spaceName("development") .build()) .block(); // Delete a space cloudFoundryOperations.spaces() .delete(DeleteSpaceRequest.builder() .name("old-space") .build()) .block(); ``` -------------------------------- ### Run tests with HTTP trace output Source: https://github.com/cloudfoundry/cf-java-client/blob/main/README.md Enables verbose HTTP logging during the test execution. ```shell CLIENT_LOGGING_LEVEL=trace ./mvnw -Pintegration-test clean test ``` -------------------------------- ### Build DefaultConnectionContext Source: https://github.com/cloudfoundry/cf-java-client/blob/main/README.md Instantiate `DefaultConnectionContext` with the API host. This is a low-level building block intended to be shared. ```java DefaultConnectionContext.builder() .apiHost(apiHost) .build(); ``` -------------------------------- ### Build PasswordGrantTokenProvider Source: https://github.com/cloudfoundry/cf-java-client/blob/main/README.md Instantiate `PasswordGrantTokenProvider` with username and password. This is a low-level building block intended to be shared. ```java PasswordGrantTokenProvider.builder() .password(password) .username(username) .build(); ``` -------------------------------- ### Run integration tests Source: https://github.com/cloudfoundry/cf-java-client/blob/main/README.md Executes the integration test suite using the integration-test Maven profile. ```shell $ ./mvnw -Pintegration-test clean test ``` -------------------------------- ### List Organizations via Operations API Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Demonstrates listing organizations, collecting results synchronously, and retrieving detailed organization information using the high-level Operations API. ```java import org.cloudfoundry.operations.CloudFoundryOperations; import org.cloudfoundry.operations.organizations.OrganizationSummary; import reactor.core.publisher.Flux; // List all organizations and print their names cloudFoundryOperations.organizations() .list() .map(OrganizationSummary::getName) .subscribe(System.out::println); // Block and collect to list (for synchronous usage) List orgNames = cloudFoundryOperations.organizations() .list() .map(OrganizationSummary::getName) .collectList() .block(); // Get detailed organization info cloudFoundryOperations.organizations() .get(OrganizationInfoRequest.builder() .name("my-organization") .build()) .subscribe(orgDetail -> { System.out.println("Org ID: " + orgDetail.getId()); System.out.println("Quota: " + orgDetail.getQuota().getName()); }); ``` -------------------------------- ### Manage Environment Variables in Java Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Set, retrieve, and remove environment variables for Cloud Foundry applications. ```java import org.cloudfoundry.operations.applications.SetEnvironmentVariableApplicationRequest; import org.cloudfoundry.operations.applications.UnsetEnvironmentVariableApplicationRequest; import org.cloudfoundry.operations.applications.GetApplicationEnvironmentsRequest; // Set environment variable cloudFoundryOperations.applications() .setEnvironmentVariable(SetEnvironmentVariableApplicationRequest.builder() .name("my-application") .variableName("DATABASE_URL") .variableValue("postgres://localhost:5432/mydb") .build()) .block(); // Get environment variables cloudFoundryOperations.applications() .getEnvironments(GetApplicationEnvironmentsRequest.builder() .name("my-application") .build()) .subscribe(envs -> { System.out.println("User-provided: " + envs.getUserProvided()); System.out.println("System-provided: " + envs.getSystemProvided()); System.out.println("Running: " + envs.getRunning()); System.out.println("Staging: " + envs.getStaging()); }); // Unset environment variable cloudFoundryOperations.applications() .unsetEnvironmentVariable(UnsetEnvironmentVariableApplicationRequest.builder() .name("my-application") .variableName("DEPRECATED_VAR") .build()) .block(); ``` -------------------------------- ### List organizations with CloudFoundryOperations Source: https://github.com/cloudfoundry/cf-java-client/blob/main/README.md Retrieves a list of organizations and prints their names using the reactive Flux API. ```java cloudFoundryOperations.organizations() .list() .map(OrganizationSummary::getName) .subscribe(System.out::println); ``` -------------------------------- ### Manage UAA Users and Authentication Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Use these methods to create users, list existing users, and retrieve the current username from the UAA service. ```java import org.cloudfoundry.uaa.UaaClient; import org.cloudfoundry.uaa.users.*; // Create a new user cloudFoundryClient.uaaClient() .users() .create(CreateUserRequest.builder() .userName("newuser@example.com") .email(Email.builder() .value("newuser@example.com") .primary(true) .build()) .name(Name.builder() .givenName("New") .familyName("User") .build()) .password("secure-password") .build()) .subscribe(response -> { System.out.println("Created user ID: " + response.getId()); }); // List users uaaClient.users() .list(ListUsersRequest.builder() .filter("email eq \"user@example.com\"") .build()) .flatMapIterable(ListUsersResponse::getResources) .subscribe(user -> { System.out.println("User: " + user.getUserName()); }); // Get current username uaaClient.getUsername() .subscribe(username -> System.out.println("Current user: " + username)); ``` -------------------------------- ### Run a specific integration test Source: https://github.com/cloudfoundry/cf-java-client/blob/main/README.md Targets a specific test class and method for execution. ```shell ./mvnw -Pintegration-test clean test -Dtest=org.cloudfoundry.client.v3.ServiceBrokersTest#update ``` -------------------------------- ### Handle API Pagination Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Utilize PaginationUtils to automatically traverse paginated results for both V2 and V3 Cloud Foundry APIs. ```java import org.cloudfoundry.util.PaginationUtils; import org.cloudfoundry.client.v3.applications.ListApplicationsRequest; import org.cloudfoundry.client.v3.applications.ApplicationResource; // Automatically paginate through all results PaginationUtils.requestClientV3Resources(page -> cloudFoundryClient.applicationsV3() .list(ListApplicationsRequest.builder() .page(page) .build())) .filter(app -> app.getName().startsWith("my-")) .subscribe(app -> System.out.println("App: " + app.getName())); // V2 API pagination PaginationUtils.requestClientV2Resources(page -> cloudFoundryClient.organizations() .list(ListOrganizationsRequest.builder() .page(page) .build())) .map(resource -> resource.getEntity().getName()) .subscribe(System.out::println); ``` -------------------------------- ### List Organizations (Client API - V2) Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt List organizations using the low-level V2 Client API with pagination support. ```APIDOC ## List Organizations (Client API - V2) List organizations using the low-level V2 Client API with pagination support. ```java import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.organizations.ListOrganizationsRequest; import org.cloudfoundry.client.v2.organizations.OrganizationResource; // List organizations with pagination cloudFoundryClient.organizations() .list(ListOrganizationsRequest.builder() .page(1) .build()) .flatMapIterable(response -> response.getResources()) .map(resource -> OrganizationSummary.builder() .id(resource.getMetadata().getId()) .name(resource.getEntity().getName()) .build()) .subscribe(org -> System.out.println(org.getName())); ``` ``` -------------------------------- ### Programmatic Reactor Debugging Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Enable Reactor debugging either by initializing the `ReactorDebugAgent` at startup or by using `Hooks.onOperatorDebug()` for debugging reactive streams. ```java // Programmatic reactor debugging import reactor.tools.agent.ReactorDebugAgent; // Enable at startup ReactorDebugAgent.init(); // Or use Hooks for debugging import reactor.core.publisher.Hooks; Hooks.onOperatorDebug(); ``` -------------------------------- ### Scale Application with V3 API Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Adjust the resources (instances, memory, disk) for a specific application. This requires a valid applicationId. ```java import org.cloudfoundry.client.v3.applications.ScaleApplicationRequest; // Scale application cloudFoundryClient.applicationsV3() .scale(ScaleApplicationRequest.builder() .applicationId(applicationId) .type("web") .instances(3) .memoryInMb(512) .diskInMb(1024) .build()) .block(); ``` -------------------------------- ### Enable SSH Access Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Enable SSH access for a specified application. The operation is blocked until completion. ```java import org.cloudfoundry.operations.applications.EnableApplicationSshRequest; // Enable SSH cloudFoundryOperations.applications() .enableSsh(EnableApplicationSshRequest.builder() .name("my-application") .build()) .block(); ``` -------------------------------- ### Maven Dependencies for Cloud Foundry Java Client Source: https://github.com/cloudfoundry/cf-java-client/blob/main/README.md Include these dependencies in your Maven project to use the Cloud Foundry Java Client. The `cloudfoundry-client-reactor` provides the client implementation, and `cloudfoundry-operations` offers higher-level operations. ```xml org.cloudfoundry cloudfoundry-client-reactor latest.RELEASE org.cloudfoundry cloudfoundry-operations latest.RELEASE ... ``` -------------------------------- ### Stream Application Logs Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Use this to stream live application logs. For recent logs, set `recent(true)`. ```java import org.cloudfoundry.operations.applications.ApplicationLogsRequest; import org.cloudfoundry.operations.applications.ApplicationLog; // Get recent logs cloudFoundryOperations.applications() .logs(ApplicationLogsRequest.builder() .name("my-application") .recent(true) .build()) .subscribe(log -> { System.out.printf("[%s] %s: %s%n", log.getTimestamp(), log.getSourceName(), log.getMessage()); }); // Stream live logs cloudFoundryOperations.applications() .logs(ApplicationLogsRequest.builder() .name("my-application") .recent(false) .build()) .subscribe(log -> { System.out.printf("[%s][%s] %s%n", log.getLogType(), log.getSourceName(), log.getMessage()); }); ``` -------------------------------- ### Spring Bean for ReactorCloudFoundryClient Source: https://github.com/cloudfoundry/cf-java-client/blob/main/README.md Encapsulate `ReactorCloudFoundryClient` instantiation in a Spring bean definition, using provided `ConnectionContext` and `TokenProvider`. ```java @Bean ReactorCloudFoundryClient cloudFoundryClient(ConnectionContext connectionContext, TokenProvider tokenProvider) { return ReactorCloudFoundryClient.builder() .connectionContext(connectionContext) .tokenProvider(tokenProvider) .build(); } ``` -------------------------------- ### Gradle Dependencies for Cloud Foundry Java Client Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Configure your Gradle build file with these dependencies to integrate the Cloud Foundry Java Client. Snapshot repositories are included for development versions. ```groovy dependencies { implementation 'org.cloudfoundry:cloudfoundry-client-reactor:5.x.x.RELEASE' implementation 'org.cloudfoundry:cloudfoundry-operations:5.x.x.RELEASE' } // For snapshot versions repositories { maven { url 'https://repo.spring.io/snapshot' } } ``` -------------------------------- ### Spring Bean for DefaultCloudFoundryOperations Source: https://github.com/cloudfoundry/cf-java-client/blob/main/README.md Encapsulate `DefaultCloudFoundryOperations` instantiation in a Spring bean definition, configuring it with clients and organization/space from properties. ```java @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(); } ``` -------------------------------- ### Configure Cloud Foundry Clients as Spring Beans Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Defines Spring beans for connection context, token providers, and various Cloud Foundry clients to enable dependency injection. ```java import org.cloudfoundry.reactor.DefaultConnectionContext; import org.cloudfoundry.reactor.client.ReactorCloudFoundryClient; import org.cloudfoundry.reactor.doppler.ReactorDopplerClient; import org.cloudfoundry.reactor.tokenprovider.PasswordGrantTokenProvider; import org.cloudfoundry.reactor.uaa.ReactorUaaClient; import org.cloudfoundry.operations.DefaultCloudFoundryOperations; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class CloudFoundryConfig { @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(); } @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(); } @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(); } } ``` -------------------------------- ### Maven Repository for Snapshot Artifacts Source: https://github.com/cloudfoundry/cf-java-client/blob/main/README.md Configure this repository in your Maven `pom.xml` to access snapshot artifacts of the Cloud Foundry Java Client. ```xml spring-snapshots Spring Snapshots https://repo.spring.io/snapshot true ... ``` -------------------------------- ### Spring Boot Configuration Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Configure Cloud Foundry clients as Spring beans for dependency injection in Spring Boot applications. ```APIDOC ## Spring Boot Configuration Configure Cloud Foundry clients as Spring beans for dependency injection in Spring Boot applications. ```java import org.cloudfoundry.reactor.DefaultConnectionContext; import org.cloudfoundry.reactor.client.ReactorCloudFoundryClient; import org.cloudfoundry.reactor.doppler.ReactorDopplerClient; import org.cloudfoundry.reactor.tokenprovider.PasswordGrantTokenProvider; import org.cloudfoundry.reactor.uaa.ReactorUaaClient; import org.cloudfoundry.operations.DefaultCloudFoundryOperations; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class CloudFoundryConfig { @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(); } @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(); } @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(); } } ``` ``` -------------------------------- ### Gradle Repository for Snapshot Artifacts Source: https://github.com/cloudfoundry/cf-java-client/blob/main/README.md Include this repository in your Gradle build script to fetch snapshot artifacts for the Cloud Foundry Java Client. ```groovy repositories { maven { url 'https://repo.spring.io/snapshot' } ... } ``` -------------------------------- ### Bind and Unbind Services Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Manage service bindings to applications, including passing optional parameters during the binding process. ```java import org.cloudfoundry.operations.services.BindServiceInstanceRequest; import org.cloudfoundry.operations.services.UnbindServiceInstanceRequest; import java.util.HashMap; import java.util.Map; // Bind service to application cloudFoundryOperations.services() .bind(BindServiceInstanceRequest.builder() .serviceInstanceName("my-database") .applicationName("my-application") .build()) .block(); // Bind with parameters Map bindParams = new HashMap<>(); bindParams.put("role", "admin"); cloudFoundryOperations.services() .bind(BindServiceInstanceRequest.builder() .serviceInstanceName("my-database") .applicationName("my-application") .parameters(bindParams) .build()) .block(); // Unbind service from application cloudFoundryOperations.services() .unbind(UnbindServiceInstanceRequest.builder() .serviceInstanceName("my-database") .applicationName("my-application") .build()) .block(); ``` -------------------------------- ### Stop Application with V3 API Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Initiates the stopping process for a specified application. Ensure the applicationId is valid. ```java import org.cloudfoundry.client.v3.applications.StopApplicationRequest; // Stop application cloudFoundryClient.applicationsV3() .stop(StopApplicationRequest.builder() .applicationId(applicationId) .build()) .block(); ``` -------------------------------- ### Manage Domains Source: https://context7.com/cloudfoundry/cf-java-client/llms.txt Create private and shared domains, including support for TCP domains with specific router groups. ```java import org.cloudfoundry.operations.domains.CreateDomainRequest; import org.cloudfoundry.operations.domains.CreateSharedDomainRequest; // Create a private domain for an organization cloudFoundryOperations.domains() .create(CreateDomainRequest.builder() .domain("private.example.com") .organization("my-organization") .build()) .block(); // Create a shared domain (admin only) cloudFoundryOperations.domains() .createShared(CreateSharedDomainRequest.builder() .domain("shared.example.com") .build()) .block(); // Create TCP domain with router group cloudFoundryOperations.domains() .createShared(CreateSharedDomainRequest.builder() .domain("tcp.example.com") .routerGroup("default-tcp") .build()) .block(); ```