機械翻訳について

前処理式および後処理式と複数のアウトバウンド・リクエスト

この手順では、前処理式または後処理式および複数のアウトバウンド・リクエストを含むフローを実装する方法を示します。

サンプル・コードは、次の方法を示しています:

  • タスクを前処理し、テナント情報を構築します。
  • 複数のアウトバウンド・リクエストを作成します。
  • 最終リクエストを行うために出力を前処理します。
  • 2つのリクエストの出力を後処理操作としてマージします。
  1. Visual Studio Codeでアダプタ定義ドキュメントを開きます。
  2. ドキュメントのflowsコード・セクションを見つけます。
  3. 操作タイプの単一の状態を持つフローを定義します。 アウトバウンド・コールの場合は、カスタム・タイプ、操作connectivity::restタイプのファンクションおよび一意の名前を追加します。
    サンプル・コード:
    "flows": {   
        "compartmentIdFlow" :      {
          "id": "compartmentIdFlow",
          "description": "compartmentIdFlow",
          "specVersion": "0.8",
          "version": "0.1",
          "start": "startState",
          "functions": [
             {
              "name": "generalRestFunc",
              "type": "custom",
              "operation": "connectivity::rest"
            }
             
          ],
          "states": [
            {
              "actions": [
                
              ],
              "name": "startState",
              "type": "operation",
              "end": true
            }
          ]
        }
    }
  4. フローに関数定義を追加し、状態の最初のアクションから定義された関数を参照します。

    前処理操作では、条件に基づいて構成または接続プロパティからtenantIdを抽出します。

    サンプル・コード:

    "functions": [
            {
              "name": "generalRestFunc",
              "type": "custom",
              "operation": "connectivity::rest"
            },
            {
              "name": "getTenantId",
              "type": "expression",
              "operation": "if .configuration.tenantId then .configuration.tenantId else .connectionProperties.TenancyOCID end"
            }
    ]
    ...
     "states":[
            {
              "name":"startState",
              "type":"operation",
              "actions":[
                {
                  "functionRef": "getTenantId",
                  "actionDataFilter": {
                    "toStateData": "${ .configuration.tenantId }"
                  }
                }
            ]
  5. アウトバウンド呼出しの場合は、アウトバウンド呼出しにさらに2つのアクションを追加します。 最初の呼出しでは、識別されたテナントのresourceIdが取得されます。 2番目の呼出しは、識別されたテナントからサブリソースIDを取得します。

    サンプル・コード:

    "actions":[
               {
                 "functionRef": "getTenantId",
                 "actionDataFilter": {
                   "toStateData": "${ .configuration.tenantId }"
                 }
               },
               {
                 "functionRef": {
                   "refName": "generalRestFunc",
                   "arguments": {
                     "uri": "${ \"https://identity.\" + .connectionProperties.region + \".oraclecloud.com/20160918/compartments/\" + .configuration.tenantId }",
                     "method": "GET"
                   }
                 },
                 "actionDataFilter": {
                   "results": "${ {keyName:.body.id, displayName:.body.name} }",
                   "toStateData": "${ .rootCompartment }"
                 }
               },
               {
                 "functionRef": {
                   "refName": "generalRestFunc",
                   "arguments": {
                     "uri": "${ \"https://identity.\" + .connectionProperties.region + \".oraclecloud.com/20160918/compartments\" }",
                     "method": "GET",
                     "parameters": {
                       "compartmentId": "${ .configuration.tenantId }",
                       "lifecycleState": "ACTIVE",
                       "compartmentIdInSubtree": true
                     }
                   }
                 },
                 "actionDataFilter": {
                   "results": "${ .body | map({keyName:.id, displayName:.name}) }",
                   "toStateData": "${ .childCompartments }"
                 }
               }
      ]
  6. 後処理操作の一部として、2つの呼出しの出力をマージします。

    サンプル・コード:

    "functions": [
            {
              "name": "generalRestFunc",
              "type": "custom",
              "operation": "connectivity::rest"
            },
            {
              "name": "getTenantId",
              "type": "expression",
              "operation": "if .configuration.tenantId then .configuration.tenantId else .connectionProperties.TenancyOCID end"
            },
            {
              "name": "mergeTenantsList",
              "type": "expression",
              "operation": "[.rootCompartment] + .childCompartments"
            }
          ]
    ...
     "states":[
            {
              "name":"startState",
              "type":"operation",
              "actions":[
                {
                  "functionRef": "getTenantId",
                  "actionDataFilter": {
                    "toStateData": "${ .configuration.tenantId }"
                  }
                },
                {
                  "functionRef": {
                    "refName": "generalRestFunc",
                    "arguments": {
                      "uri": "${ \"https://identity.\" + .connectionProperties.region + \".oraclecloud.com/20160918/compartments/\" + .configuration.tenantId }",
                      "method": "GET"
                    }
                  },
                  "actionDataFilter": {
                    "results": "${ {keyName:.body.id, displayName:.body.name} }",
                    "toStateData": "${ .rootCompartment }"
                  }
                },
                {
                  "functionRef": {
                    "refName": "generalRestFunc",
                    "arguments": {
                      "uri": "${ \"https://identity.\" + .connectionProperties.region + \".oraclecloud.com/20160918/compartments\" }",
                      "method": "GET",
                      "parameters": {
                        "compartmentId": "${ .configuration.tenantId }",
                        "lifecycleState": "ACTIVE",
                        "compartmentIdInSubtree": true
                      }
                    }
                  },
                  "actionDataFilter": {
                    "results": "${ .body | map({keyName:.id, displayName:.name}) }",
                    "toStateData": "${ .childCompartments }"
                  }
                },
                {
                  "functionRef": "mergeTenantsList",
                  "actionDataFilter": {
                    "toStateData": "${ .output }"
                  }
                }
              ],
              "end": true
            }
          ]
        }
    }

完全なサンプル・コード:

"flows": {   
   "compartmentIdFlow" :      {
      "id": "compartmentIdFlow",
      "description": "compartmentIdFlow",
      "specVersion": "0.8",
      "version": "0.1",
      "start": "startState",
      "functions": [
        {
          "name": "generalRestFunc",
          "type": "custom",
          "operation": "connectivity::rest"
        },
        {
          "name": "getTenantId",
          "type": "expression",
          "operation": "if .configuration.tenantId then .configuration.tenantId else .connectionProperties.TenancyOCID end"
        },
        {
          "name": "mergeTenantsList",
          "type": "expression",
          "operation": "[.rootCompartment] + .childCompartments"
        }
      ],
      "states":[
        {
          "name":"startState",
          "type":"operation",
          "actions":[
            {
              "functionRef": "getTenantId",
              "actionDataFilter": {
                "toStateData": "${ .configuration.tenantId }"
              }
            },
            {
              "functionRef": {
                "refName": "generalRestFunc",
                "arguments": {
                  "uri": "${ \"https://identity.\" + .connectionProperties.region + \".oraclecloud.com/20160918/compartments/\" + .configuration.tenantId }",
                  "method": "GET"
                }
              },
              "actionDataFilter": {
                "results": "${ {keyName:.body.id, displayName:.body.name} }",
                "toStateData": "${ .rootCompartment }"
              }
            },
            {
              "functionRef": {
                "refName": "generalRestFunc",
                "arguments": {
                  "uri": "${ \"https://identity.\" + .connectionProperties.region + \".oraclecloud.com/20160918/compartments\" }",
                  "method": "GET",
                  "parameters": {
                    "compartmentId": "${ .configuration.tenantId }",
                    "lifecycleState": "ACTIVE",
                    "compartmentIdInSubtree": true
                  }
                }
              },
              "actionDataFilter": {
                "results": "${ .body | map({keyName:.id, displayName:.name}) }",
                "toStateData": "${ .childCompartments }"
              }
            },
            {
              "functionRef": "mergeTenantsList",
              "actionDataFilter": {
                "toStateData": "${ .output }"
              }
            }
          ],
          "end": true
        }
      ]
    }
}