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.

Table 5.1. Fabric8 configuration files

Name

Purpose

Sample file

Deployment configuration

Controls overall deployment

deploymentconfig.yml

JDBC service configuration

Specifies JDBC service

jdbc-svc.yml

OData service configuation

Specifies OData service

odata-svc.yml

OData route configuration

Specifies OData route

odata-route.yml

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.

Note

OData routes are created automatically for virtual databases that you create in Fuse Online.

Prerequisites

  • You have the sample template odata-svc.yml and odata-route.yml files from the Teiid OpenShift repository.
  • You have completed the configuration tasks that are summarized in Chapter 2, Virtual database creation.

Procedure

  1. Add the following dependency in your pom.xml file:

    <dependency>
        <groupId>org.teiid</groupId>
        <artifactId>spring-odata</artifactId>
    </dependency>
  2. In the /src/main/fabric8 folder of your Java project, add an odata-svc.yml file to create an OData service.
  3. 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

Procedure

  1. To create a JDBC service, add the file jdbc-svc.yml to the /src/main/fabric8 folder of your Java project.
Note

If you add the jdbc-svc.yml file from the Teiid OpenShift sample repository, the JDBC service is enabled by default.

  1. 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
  2. Log in to OpenShift and run the following command to deploy the file to OpenShift:

    $ oc create -f -ingress
  3. Run the following command to determine the IP port:

    $ oc get svc rdbms-example-ingress
  4. Share the port number that is returned with your API clients.

Additional resources

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.

Note

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. .

Note

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

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.