Bookmark this page

Guided Exercise: Creating Backends and Products

In this exercise, you will deploy a set of microservices for use in a regional library system. To expose these APIs, you will create one or more of the following resources:

  • Backends

  • Products

  • Applications

  • Application plans

Outcomes

You should be able to:

  • Deploy microservices on Red Hat OpenShift Container Platform (RHOCP) in a way that is consumable by 3scale API Management.

  • Create backends and products.

  • Connect those backends and products to an application and corresponding application plan.

As the student user on the workstation machine, use the lab command to prepare your system for this exercise.

[student@workstation ~]$ lab start applications-products

Procedure 2.1. Instructions

  1. Create a product called library_product. Within that product, create an application and application plan.

    1. Use the 3scale Toolbox to create a product named library_product:

      [student@workstation ~]$ 3scale service create 3scale-tenant library_product
      Service 'library_product' has been created with ID: 1

      Note

      In 3scale API Management, a product and a service are the same.

    2. Create an application plan named east-branch-plan:

      [student@workstation ~]$ 3scale application-plan \
      create 3scale-tenant library_product east-branch-plan
      Created application plan id: 16. Default: false; Disabled: false

      Note that the product is referenced via its system ID library_product.

    3. Find the ID of the example developer named John:

      [student@workstation ~]$ 3scale account find 3scale-tenant john
      org_name => Developer
      id => 3
    4. Create an application named east-branch-app that references the east-branch-plan application plan and the example developer:

      [student@workstation ~]$ 3scale application \
      create 3scale-tenant 3 library_product east_branch_plan east-branch-app
      Created application id: 9
  2. Create a backend for each of the APIs.

    1. Using a web browser, log in to the Admin Portal as the admin user. The portal is located at https://3scale-admin.apps.ocp4.example.com.

      Note

      If this is your first time accessing the admin portal, a setup wizard opens. Use the X button to exit this wizard.

    2. From the top pane drop-down menu, select Backends to view the list of backends.

    3. Create a backend for the book API by clicking Create Backend, providing the following values, and submitting the form. Leave all other fields as their default values.

      FieldValue
      Name book-backend
      Private Base URL http://books-api.book-library.svc.cluster.local:8080
    4. Create another backend for the patron API with the following values:

      FieldValue
      Name patron-backend
      Private Base URL http://patrons-api.book-library.svc.cluster.local:8080
  3. Associate book-backend and patron-backend with the library_product.

    1. From the top pane drop-down menu, select Products to view the list of products. Click the name of the library_product product in the list.

    2. Navigate to the list of backends associated with the product by selecting IntegrationBackends. Associate a backend with the product by clicking Add Backend. Select book-backend as the backend, provide the unique path /b-api, and submit the form.

    3. Repeat the previous step for the patron backend, but select the patron-backend and enter /p-api as the path.

  4. Promote and test the product configuration.

    1. Navigate to the product configuration by selecting IntegrationConfiguration.

    2. Promote the product's configuration to the staging environment by clicking Promote v.1 to Staging APIcast.

    3. Promote the product's configuration to the production environment by clicking Promote v.1 to Production APIcast.

    4. From the Production APIcast section, copy the hostname from the URL value. In the command line, store this value in an environment variable called API, to use in a later step.

      [student@workstation ~]$ API=https://library-product-3scale-apicast-production\
      .apps.ocp4.example.com:443
    5. From the Staging APIcast section, copy the user_key value from the example curl command. In the command line, store this value in a USER_KEY environment variable.

      [student@workstation ~]$ USER_KEY=02e852852327972ebc6edfae27b9037a

      Note

      Your user_key will differ from the one listed here.

    6. Retrieve the book list from the book application.

      [student@workstation ~]$ curl -s $API/b-api/books?user_key=$USER_KEY | jq
      [
        {
          "title": "Frankenstein",
          "authorName": "Mary Shelley",
          "year": 1818,
          "copies": 10
        },
        {
          "title": "A Christmas Carol",
          "authorName": "Charles Dickens",
          "year": 1843,
          "copies": 5
        },
        {
          "title": "Pride and Prejudice",
          "authorName": "Jane Austen",
          "year": 1813,
          "copies": 3
        }
      ]
    7. Retrieve the patron list from the patron application.

      [student@workstation ~]$ curl -s $API/p-api/patrons?user_key=$USER_KEY | jq
      [
        {
          "name": "John Smith",
          "numBooks": 3,
          "cardNumber": "00001"
        },
        {
          "name": "Patty Jones",
          "numBooks": 1,
          "cardNumber": "00002"
        },
        {
          "name": "Frank Doe",
          "numBooks": 8,
          "cardNumber": "00003"
        }
      ]
    8. Run the previous command several times to generate request metrics.

  5. Review the endpoint metrics within the Admin Portal.

    1. In the admin portal, navigate to AnalyticsTraffic.

    2. Use the selection menu to adjust the scale of the graph by selecting Hits (hits). Make sure 24 hours is selected so that the time scale is correct.

      Note that your graph could look slightly different based on how many times you ran the curl command.

      Figure 2.5: Graph scale selection menu

Finish

On the workstation machine, use the lab command to complete this exercise. This is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish applications-products

This concludes the guided exercise.

Revision: do240-2.11-40390f6