The latest version of the Cloud Foundry Eclipse plug-in contains various enhancements for managing services in Cloud Foundry. Cloud Foundry Eclipse is a joint collaboration between Pivotal Software and IBM. Version 1.7.2 of the plug-in contains an updated UI that improves Cloud service management in Eclipse. In this article, we will cover service management for a Pivotal Web Services (PWS) server instance using the new UI.
We first start by showing how to install Cloud Foundry Eclipse and create a server instance to PWS. We then show how to create service instances and bind them to an application. Finally, we show how to unbind a service instance from an application and delete it.
Those new to Cloud Foundry can find additional information on Cloud services and service instances here. In Cloud Foundry Eclipse, service management specifically refers to service instances.
Installing Cloud Foundry Eclipse
Cloud Foundry Eclipse can be installed either into Spring Tool Suite (STS) or Eclipse JEE from the STS dashboard or the Eclipse Marketplace. For this article, we use STS.
Java 7 is now a minimum required execution environment for Cloud Foundry Eclipse.
Creating a Server Instance
Account registration for PWS can be found here, and it is required prior to creating a PWS server instance through Cloud Foundry Eclipse.
Before Cloud services can be managed through Eclipse, a Cloud Foundry server instance must be created. Cloud Foundry Eclipse is integrated into the Eclipse Web Tools Platform, and a server instance can easily be created through the Eclipse New Server wizard.
Following the instructions in the link above, we will first create a server instance to a PWS organization and space, which then appears in the Eclipse Servers view as “Pivotal Cloud Foundry”.
We will use this server instance to show how service instances can be added to our space, bound and unbound to an application, and deleted.
Creating a Service
Services are managed and created through the Cloud Foundry server editor. To create a service instance, we first double-click on our server in the Eclipse Servers view to open the editor, and then navigate to the Applications and Services tab.
In Applications and Services, services are managed in a Services section on the bottom left of the editor, shown in the screenshot below. This section shows all the service instances that are currently created in the server’s space. Service instances can be created, deleted and bound to applications from this section. To create a service instance, we click on a toolbar button on the top right corner of the Services section to open the Add Service wizard, as highlighted in red below.
The UI for the Add Service wizard has changed substantially from previous versions of the plug-in. In the latest version, all available services in the space are shown in a scrollable list for easier browsing.
A filter control allows this list to be narrowed down by patterns matched to service names or descriptions. In our case, we want to filter out all services except those that match “sql”. In PWS, the list is reduced to two entries: MySQL (cleardb) and PostgreSQL (elephantsql).
We then select elephantsql from the list. A service instance name and plan, shown at the bottom of the wizard, must be specified before the wizard can complete. Each service selection in the list populates the instance name and plan with default values. However, we can also set our own name and choose a different plan. In our case, we change the default name to “cfeclipsepqsl” and keep the default plan.
We then finish the wizard to create the service instance, and it now appears in the Services section.
Certain service instances can be bound to applications either when the application is first deployed to Cloud Foundry, or any time afterward through the Cloud Foundry server editor.
Binding a Service During Deployment
To bind a service instance to an application during deployment, we first push an application to our Cloud Foundry server. For this example, we create a Spring Boot application called “pwsspringbootweb” through the STS Spring Starter wizard, which is available in STS version 3.4.0 or higher.
Once created, we need to configure the Spring Boot application for deployment to the Cloud Foundry server. In the Eclipse Package or Project Explorer, we right-click on the Spring Boot project and select Configure -> Enable as Cloud Foundry App in the context menu.
Now we drag and drop the project from the Package or Project Explorer into the Applications section in the editor. Alternatively, we can also right-click on the project in the Package or Project Explorer and select Run As -> Run on Server in the context menu, and choose our Cloud Foundry server instance, “Pivotal Cloud Foundry”, from the list of servers.
Either application deployment approach opens the Application Deployment wizard.
We enter the deployment details for the application in the first two pages, like the application name, memory and URL, and click “Next” until the Services Selection page is displayed.
This page allows us to both create new service instances and bind existing or new ones to the application.
To add a new service instance and bind it to the application, we click on the Add Service button in the top right toolbar as shown above, which displays the same Add Service wizard opened earlier from the editor. We create a “rediscloud” service, and once it appears in the Services Selection list, it will by default be checked for binding.
Binding services through the Application Deployment wizard is optional. Only checked services in the Services Selection list will be bound to the application, and any of the services can be unchecked. In our case we do not check any further services to bind except for “rediscloud”.
Clicking “Finish” deploys the application, and after it has been successfully pushed to the Cloud Foundry server, it appears both in the Eclipse Servers view and the editor.
The screenshot above shows the deployed application on the left side of the editor. Selecting the application then shows additional UI on the right side that displays further application details, including an Application Services section. This section lists all the bound service instances for the application, which in our case is the “rediscloud” service that we created and bound earlier during the application deployment phase.
Binding Additional Services
Previously, we had also created another service instance called “cfeclipsepqsl”. We now would like to bind this service to our Spring Boot application. There are two approaches to bind further services to an existing application:
1. Drag and Drop
Drag and drop the service instance from the Services section on the left side into the Application Services section on the right, as shown above.
2. Manage Service Bindings Wizard
Introduced in version 1.7.2 of the plug-in to improve user accessibility and provide an alternative for binding a service, services can now also be bound to applications through a context menu on a service selection in the Services section.
We will use this approach to bind “cfeclipsepqsl” to our application. We select “cfeclipsepqsl” in the Services section and right-click to select Manage Service Bindings from the context menu. This opens the Manage Service Bindings wizard where we see a list of all the deployed applications in the space.
We now select which applications we want “cfeclipsepsql” to be bound with. As we only have one application deployed in our space, namely “pwsspringbootweb”, we select this application and click “Finish”.
The service instance is then bound to the application and will appear in the Application Services section.
Unbinding a Service
Unbinding services can easily be done in the Application Services section for an application. We right-click on a bound service instance in Application Services and choose Unbind from Application in the context menu, which unbinds the service and removes it from the list of bound services.
Deleting a Service
Finally, we show how to delete a service instance from a space. In the Applications and Services tab in the editor, we select a service instance in the Services section and simply right-click on it and choose Delete from the context menu.
This deletes the service instancce, as well as automatically unbinds it from any application in the space that uses this service.
About the Author