User interface

There is no open source portal for OpenWhisk at the time of writing. To make it easier for developers to use OpenWhisk, I'm developing a UI portal for it. SuraWhisk is an open source project hosted on GitHub. Its source can be found at https://github.com/surawhisk/ui. If you do not want to look at the source code, you can just start the UI from a ready-to-use Docker image.

First, create a volume to store the settings data. Endpoints and their API keys for authentication will be stored there in the volume:

$ docker volume create surawhisk_vol

Then the UI can be run using the following command:

$ docker run -d -p 8080:8080 -v surawhisk_vol:/root/data surawhisk/ui

After SuraWhisk UI starts, point the browser to http://localhost:8080. The UI's navigation bar on the left-hand side currently contains three basic items: settings, actions, and namespaces.

The Settings page, as shown in Figure 6.3, is for setting up an OpenWhisk endpoint and its API key. The SuraWhisk container is running on a bridge network; therefore, it can access the OpenWhisk's API gateway via the Docker's gateway bridge IP, 172.17.0.1. That is, the endpoint to our local OpenWhisk's instance will be https://172.17.0.1/api/v1. The API key for the current guest namespace can be obtained by running the wsk CLI with the following command. If the bridge IP is not working, you may try the local IP of the local machine, as the OpenWhisk's API gateway is exposed over the machine's IP as well:

$ wsk property get --auth
whisk auth 23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP

The result of the command provides a long string saying that it is a whisk auth. Copy and paste the whole string, 23b...IwP, into the API Key textbox of the Settings page, and click the Save button:

Figure 6.3: The Settings screen of SuraWhisk for specifying the Endpoint and API Key

Now the SuraWhisk Portal will be able to communicate with the OpenWhisk instance. We will proceed to the step of defining a new function.

A function, an action in OpenWhisk, can be defined on the Actions/Create page, as in Figure 6.4. The Docker image built earlier in this chapter will be used here. In the following example, we create a function named hello as a Docker container, whose image is chanwit/whisk_c:

Figure 6.4: The Action Creation screen which allows us to define a new action in OpenWhisk

When everything is ready, click the Create button. The portal will connect to the OpenWhisk instance and request creation of a new action. The Docker image is not pulled during this stage, so the step will be finished quickly. If the hello action is created successfully, dialog will pop up, as in Figure 6.5.

Figure 6.5: Dialog showing that an action was successfully created

To invoke the action, go to the menu Actions/Invoke on the left-hand side navigation bar, as in Figure 6.6. All actions in the current namespace will be listed in the Action combo box. Each invocation accepts key/value pairs as the action's parameters. They can be added by clicking the Add button. In the following example, the book parameter is set to contain the value serverless. A parameter can be removed at any time by clicking the Remove button of each pair. These parameters will be encoded into JSON before being passed to the action:

Figure 6.6: The Invoke Action screen in SuraWhisk showing the result

After selecting the action to be invoked, clicking the invoke button will start the invocation process. In the previous example, the hello action is in the form of a Docker container.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset