2
0

watsonx.data SaaS版のPrestoエンジンにアクセスするための事前情報取得

Last updated at Posted at 2023-08-29

* IBM Cloud上のSaaS版についての記載です

watsonx.dataは「単一の統合データ・プラットフォームですべての企業データを収集、保存、照会、分析するためのデータ管理ソリューションです。オープン・データ・フォーマットに最適化された、柔軟で信頼性の高いプラットフォームを提供します」とのことで、いわゆるデータレイクハウスです。SW版とSaaS版があります。

当記事はwatsonx.data SaaS版のPresto エンジンに外部からアクセスするための事前情報取得方法について説明します。
尚、公式ドキュメントではConnecting to Presto serverに記述されている内容です。

1. Presto エンジンのホスト名とポート番号の取得

 1-1 watsonx.dataのサービスインスタンスにログインします

 image.png

1-2. 左上のナビゲーションメニューから、「インフラストラクチャー・マネージャー」をクリックし、リストビューを選択します。

ima.ge.png
image.png

1-3. 「エンジン」タブでアクセスしたいエンジン名をクリックし、詳細を表示します。

1-4. 「ホスト」ラベルの下にある「クリップボードにコピー」アイコンをクリックして、ホストの詳細をコピーします。

尚、ポート番号はホスト名の最後にコロンをつけて付加された数字です。

例: 下記の場合は

xxxxxxxx.lakehouse.appdomain.cloud:33333
  • xxxxxxxx.lakehouse.appdomain.cloudがホスト名
  • 33333がポート番号

です。
image.png

2. IBM API key または IBM IAM tokenの取得

ドキュメントによるとIBM IAM tokenの方がワークロード的におすすめとのことです。

ただIBM API key は一度取得したら削除するまで使えますが、IBM IAM tokenは作成後1時間有効となり、有効期限があります。どちらも使用可能なので、状況に合わせて選択してください。

2-1. IBM API keyの取得

IBM Cloud APIKEYの作成(取得)方法に従って取得してください。

2-2. IBM IAM tokenの取得

IBM IAM tokenを取得する場合は以下の方法で取得してください。
IBM IAM tokenの取得にはIBM API keyが必要です。「2-1. IBM API keyの取得」でまず取得お願いします。

<your-api-key>は「2-1. IBM API keyの取得」で取得したIBM API keyで置き換えて、以下のcurl コマンドを実行します。

curl -X \
POST 'https://iam.cloud.ibm.com/identity/token' \
--header "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "grant_type=urn:ibm:params:oauth:grant-type:apikey" \
--data-urlencode "apikey=<your-api-key>"

以下のような出力が返ってきますので、access_tokenの値が、IBM IAM tokenの値になります。下の画像の水色部分です。最初と最後のダブルクォーテーションはIBM IAM tokenの値ではありませんので、使用時は除外してください。
image.png

またはpythonで書くと(<your-api-key>は「2-1. IBM API keyの取得」で取得したIBM API keyで置き換えてから実行して下さい)、以下のようになります。

import requests
import sys

endpoint = 'https://iam.cloud.ibm.com/identity/token'
headers = {}
headers ['content-type'] = "application/x-www-form-urlencoded"
params = {}
params['grant_type'] = "urn:ibm:params:oauth:grant-type:apikey"
params['apikey'] = "<your-api-key>"

try:
    r = requests.post(endpoint,  headers=headers, data=params)
except Exception as err:
    print("RESTful call failed. Detailed information follows.")
    print(err)
    sys.exit()

try:
    access_token = r.json()['access_token']
    #print(r.json())
except:
    print("RESTful call did not return an access token.")
    print(r.json())
    sys.exit()


print (access_token)

access_tokenという変数に入ります。

以上で、watsonx.data SaaS版のPrestoエンジンにアクセスするための事前情報

  • ホスト名
  • ポート番号
  • IBM API key
  • IBM IAM token
    が取得できました。

3. 関連リンク

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0