Chapter 5. Making virtual databases available to API consumers
To enable API consumers to access the virtual database, define services and routes for JDBC or OData protocols for the virtual database service on OpenShift.
After you define a protocol service for a virtual database, any client in the same OpenShift cluster can access the virtual database. Only applications that are in the same cluster have access. Remote clients do not have access. To enable OData access for remote clients, you must define an OData route to the virtual database service.
External JDBC clients do not use routes to access virtual database services. Instead, JDBC clients depend on the OpenShift load balancer service to allocate external IP addresses that external clients can use to access services in the cluster.
You configure services and routes by adding configuration files in /src/main/fabric8
. Download the sample Fabric8 configuration files from the Teiid OpenShift repository. The following table list the configuration files to add in /src/main/fabric8
to configure services and routes for the virtual database.
Name | Purpose | Sample file |
Deployment configuration | Controls overall deployment | |
JDBC service configuration | Specifies JDBC service | |
OData service configuation | Specifies OData service | |
OData route configuration | Specifies OData route |
If you choose not to create a service for one of the protocols, or to expose a route for that protocol, omit the corresponding file from the /fabric8
directory.
The service and route configuration files specify default values for port numbers and timeout values. Unless you have a specific reason for modifying those settings, you can retain the default values.
Prerequisites
- You downloaded the sample configuration files that you need from the Teiid OpenShift repository.
5.1. Configuring access for OData clients
The relational model of the data in a virtual database is automatically mapped to JSON or XML to allow applications to consume the data through OData APIs. However, if you want the virtual database to be available to OData clients, you must explicitly define an OData service and route. The default settings in the odata-svc.yml
and odata-route.yml
files that are available from the Teiid OpenShift sample repository are configured to enable an OData service and route.
Do not edit instances of the variable ${project.artifactId}
that appear in the configuration files. At build time, these variables are replaced automatically with information from elements in the pom.xml
file.
OData routes are created automatically for virtual databases that you create in Fuse Online.
Prerequisites
-
You have the sample template
odata-svc.yml
andodata-route.yml
files from the Teiid OpenShift repository. - You have completed the configuration tasks that are summarized in Chapter 2, Virtual database creation.
Procedure
Add the following dependency in your
pom.xml
file:<dependency> <groupId>org.teiid</groupId> <artifactId>spring-odata</artifactId> </dependency>
-
In the
/src/main/fabric8
folder of your Java project, add anodata-svc.yml
file to create an OData service. -
If you want to make the virtual database available to OData clients outside of the OpenShift cluster, add an
odata-route.yml
file to create and OData route.
5.2. Configuring access for JDBC clients
To enable JDBC client applications to access your virtual database, you must configure a JDBC service. After the JDBC service is enabled, OpenShift applications that share the cluster with the virtual database can access the database over JDBC. Third-party client applications that are outside of the OpenShift cluster have no JDBC access to the virtual database.
To provide JDBC access to external clients, you do not create a JDBC route as you do to enable OData access to external clients. Rather, you must configure an OpenShift load balancer service to configure ingress cluster traffic. After that you must provide external applications with the IP address that the load balancer service assigns to the virtual database.
Do not edit instances of the variable ${project.artifactId}
that appear in the configuration files. At build time, these variables are replaced automatically with information from elements in the pom.xml
file.
Prerequisites
-
You have the sample
jdbc-svc.yml
file from the Teiid OpenShift repository. - You have completed the configuration tasks that are summarized in Chapter 2, Virtual database creation.
Procedure
-
To create a JDBC service, add the file
jdbc-svc.yml
to the/src/main/fabric8
folder of your Java project.
If you add the jdbc-svc.yml
file from the Teiid OpenShift sample repository, the JDBC service is enabled by default.
Create a file with the name
ingress
and add the following contents to it:apiVersion: v1 kind: Service metadata: name: rdbms-example-ingress spec: ports: - name: teiid port: 31000 type: LoadBalancer selector: app: rdbms-example sessionAffinity: ClientIP
Log in to OpenShift and run the following command to deploy the file to OpenShift:
$ oc create -f -ingress
Run the following command to determine the IP port:
$ oc get svc rdbms-example-ingress
- Share the port number that is returned with your API clients.
Additional resources
- For more information about Configuring ingress cluster traffic using a load balancer, see the OpenShift documentation.
5.3. Identifying the OData endpoint of a virtual database
After you deploy a virtual database, you can share the OData URL with application developers so that they can use REST APIs to query and retrieve data from the virtual database.
For virtual databases that you create in Fuse Online, OData routes are exposed automatically on the Data Virtualizations page.
To retrieve the OData URL for virtual databases that you create using the Spring Boot Maven plugin, you run an OpenShift command. You then append /odata
to the URL that command returns to establish the API endpoint for the service. .
In this Technology Preview release, there is no relationship between virtual databases that you create by running the Maven Spring Boot plugin and those that you create in Fuse Online. As a result, the Data virtualization page in Fuse Online does not show virtual databases that you build and create outside of Fuse Online.
Prerequisites
- You used Maven Spring Boot to deploy a virtual database service on OpenShift, and you enabled OData access to the service.
Procedure
After you deploy the virtual database, log in to OpenShift and run the following command to obtain the OData URL for the service:
$ oc describe route <virtual-database-service-name>
For example,
oc describe route rdbms-example
The command returns the root URL for the service.
Additional resources
- For information about how to enable OData access to a virtual database service, see see Section 5.1, “Configuring access for OData clients”.