|
| 1 | +# Running a Magic 8-ball Python script in SQL Server big data cluster |
| 2 | + |
| 3 | +### Contents |
| 4 | + |
| 5 | +[About this sample](#about-this-sample)<br/> |
| 6 | +[Before you begin](#before-you-begin)<br/> |
| 7 | +[Run this sample](#run-this-sample)<br/> |
| 8 | +[Sample details](#sample-details)<br/> |
| 9 | +[Related links](#related-links)<br/> |
| 10 | + |
| 11 | +<a name=about-this-sample></a> |
| 12 | + |
| 13 | +## About this sample |
| 14 | + |
| 15 | +This is a sample [Python](https://www.python.org/) app, which runs a [Magic 8-Ball](https://en.wikipedia.org/wiki/Magic_8-Ball). This sample creates an app that adds requires a question as input and returns an answer to the question. The code for this sample is in [magic8ball.py](magic8ball.py) The inputs and outputs are shown below. |
| 16 | + |
| 17 | +### Inputs |
| 18 | +|Parameter|Description| |
| 19 | +|-|-| |
| 20 | +|`txt`|The input question on which you would like answered| |
| 21 | + |
| 22 | +### Outputs |
| 23 | +|Parameter|Description| |
| 24 | +|-|-| |
| 25 | +|`result`|The answer of the Magic 8-ball| |
| 26 | + |
| 27 | + |
| 28 | +<a name=before-you-begin></a> |
| 29 | + |
| 30 | +## Before you begin |
| 31 | + |
| 32 | +To run this sample, you need the following prerequisites. |
| 33 | + |
| 34 | +**Software prerequisites:** |
| 35 | + |
| 36 | +1. SQL Server big data cluster CTP 2.3 or later. |
| 37 | +2. `mssqlctl`. Refer to [installing mssqlctl](https://docs.microsoft.com/en-us/sql/big-data-cluster/deploy-install-mssqlctl?view=sqlallproducts-allversions) document on setting up the `mssqlctl` and connecting to a SQL Server 2019 big data cluster. |
| 38 | + |
| 39 | +<a name=run-this-sample></a> |
| 40 | + |
| 41 | +## Run this sample |
| 42 | + |
| 43 | +1. Clone or download this sample on your computer. |
| 44 | +2. Log in to the SQL Server big data cluster using the command below using the IP address of the `endpoint-service-proxy` in your cluster. If you are not familiar with `mssqltctl` you can refer to the [documentation](https://docs.microsoft.com/en-us/sql/big-data-cluster/big-data-cluster-create-apps?view=sqlallproducts-allversions) and then return to this sample. |
| 45 | + |
| 46 | + ```bash |
| 47 | + mssqlctl login -e https://<ip-address-of-endpoint-service-proxy>:30777 -u <user-name> -p <password> |
| 48 | + ``` |
| 49 | +3. Deploy the application by running the following command, specifying the folder where your `spec.yaml` and `magic8ball.py` files are located: |
| 50 | + ```bash |
| 51 | + mssqlctl app create --spec ./magic8ball |
| 52 | + ``` |
| 53 | +4. Check the deployment by running the following command: |
| 54 | + ```bash |
| 55 | + mssqlctl app list -n magic8ball -v [version] |
| 56 | + ``` |
| 57 | + Once the app is listed as `Ready` you can continue to the next step. |
| 58 | +5. Test the app by running the following command: |
| 59 | + ```bash |
| 60 | + mssqlctl app run -n magic8ball -v [version] --input txt="Will it rain tomorrow?" |
| 61 | + ``` |
| 62 | + You should get output like the example below. The answer to your question are returned as `result`. |
| 63 | + ```json |
| 64 | + { |
| 65 | + "changedFiles": [], |
| 66 | + "consoleOutput": "", |
| 67 | + "errorMessage": "", |
| 68 | + "outputFiles": {}, |
| 69 | + "outputParameters": { |
| 70 | + "result": "You may rely on it" |
| 71 | + }, |
| 72 | + "success": true |
| 73 | + } |
| 74 | + ``` |
| 75 | +6. You can clean up the sample by running the following commands: |
| 76 | + ```bash |
| 77 | + # delete app |
| 78 | + mssqlctl app delete --name magic8ball --version [version] |
| 79 | + ``` |
| 80 | + |
| 81 | +<a name=sample-details></a> |
| 82 | + |
| 83 | +## Sample details |
| 84 | + |
| 85 | +Please refer to [magic8ball.py](magic8ball.py) for the code for this sample. |
| 86 | + |
| 87 | +### Spec file |
| 88 | +Here is the spec file for this application. As you can see the sample uses the `Python` runtime and calls the `magic8ball` method in the `magic8ball.py` file, accepting a `str` input called `txt` (the question that you ask the Magic 8-ball) and returning a `str` output named `result`. |
| 89 | + |
| 90 | +```yaml |
| 91 | +name: magic8ball |
| 92 | +version: v2 |
| 93 | +runtime: Python |
| 94 | +src: ./magic8ball.py |
| 95 | +entrypoint: magic8ball |
| 96 | +replicas: 1 |
| 97 | +poolsize: 1 |
| 98 | +inputs: |
| 99 | + txt: str |
| 100 | +output: |
| 101 | + result: str |
| 102 | +``` |
| 103 | + |
| 104 | +<a name=related-links></a> |
| 105 | + |
| 106 | +## Related Links |
| 107 | +For more information, see these articles: |
| 108 | + |
| 109 | +[How to deploy and app on SQL Server 2019 big data cluster (preview)](https://docs.microsoft.com/en-us/sql/big-data-cluster/big-data-cluster-create-apps?view=sqlallproducts-allversions) |
0 commit comments