Azure Stream Analytics (ASA) CI/CD npm パッケージは、Stream Analytics プロジェクトを自動的にビルド、テスト、デプロイするのに役立ちます。 この記事では、CI/CD システムで npm パッケージを使用する方法について示します。 Azure DevOpsを使用してパイプラインを設定するには、「 Stream Analytics ジョブの CI/CD パイプラインを作成するAzure DevOpsを使用するを参照してください。
Stream Analytics プロジェクトがない場合は、Visual Studio Code を使用して作成するか、Azure portal から既存のものをエクスポートします。
インストール
npm サイトからパッケージをダウンロードするか、ターミナルで次のコマンドを実行できます。
npm install -g azure-streamanalytics-cicd
プロジェクトをビルドする
注意
更新された ARM テンプレート スキーマには、 --v2 オプションを使用します。 更新されたスキーマのパラメーターは少なくなりますが、以前のバージョンと同じ機能が保持されます。
古い ARM テンプレートは非推奨です。
build --v2によって作成されたテンプレートのみが、更新プログラムまたはバグ修正を受け取ります。
azure-streamanalytics-cicd build --v2 --project <projectFullPath> [--outputPath <outputPath>]
build コマンドはキーワード構文チェックを実行し、Azure Resource Manager (ARM) テンプレートを生成します。
| 引数 | 説明 |
|---|---|
--project |
絶対パスまたは相対パスを使用して 、asaproj.json ファイルを指定します。 |
--outputPath |
絶対パスまたは相対パスを使用して、ARM テンプレートを格納する出力フォルダーを指定します。
outputPathを指定しない場合、テンプレートは現在のディレクトリに格納されます。 |
例:
# Go to the project directory
cd <path-to-the-project>
# Build project
azure-streamanalytics-cicd build --v2 --project ./asaproj.json --outputPath ./Deploy
プロジェクトが正常にビルドされると、出力フォルダーの下に 2 つの JSON ファイルが作成されます。
- ARM テンプレート ファイル:
[ProjectName].JobTemplate.json - Azure Resource Manager パラメーター ファイル:
[ProjectName].JobTemplate.parameters.json
parameters.json ファイルの既定値は、プロジェクト設定から取得されます。 別の環境にデプロイする場合は、値を適宜置換します。
すべての資格情報の既定値は null です。 Azureにデプロイする前に値を設定します。
"Input_EntryStream_sharedAccessPolicyKey": {
"value": null
}
出力シンクとして Azure Data Lake Store Gen1 のマネージド ID を使用するには、Azureにデプロイする前に、PowerShell を使用してサービス プリンシパルへのアクセスを提供する必要があります。 詳細については、Resource Manager テンプレートを使用したマネージド ID を使用した ADLS Gen1 のデプロイに関するページを参照してください。
ローカルで実行する
プロジェクトにローカル入力ファイルが含まれている場合は、 localrun コマンドを使用して Stream Analytics スクリプトをローカルで実行します。
azure-streamanalytics-cicd localrun -project <projectFullPath> [-outputPath <outputPath>] [-customCodeZipFilePath <zipFilePath>]
| 引数 | 説明 |
|---|---|
--project |
絶対パスまたは相対パスを使用して asaproj.json ファイルを指定します。 |
--outputPath |
絶対パスまたは相対パスを使用して ARM テンプレートを格納する出力フォルダーを指定します。
outputPath が指定されていない場合、テンプレートは現在のディレクトリに格納されます。 |
--customCodeZipFilePath |
UDF やデシリアライザーなど、C# カスタム コード用の zip ファイルのパス (使用する場合)。 DLL を ZIP ファイルにパッケージして、そのパスを指定してください。 |
例:
# Go to the project directory
cd <path-to-the-project>
# Run project locally
azure-streamanalytics-cicd localrun --project ./asaproj.json"
注意
JavaScript UDF は、Windowsでのみ機能します。
自動テスト
CI/CD npm パッケージを使用して、Stream Analytics プロジェクトの自動テストを構成して実行します。
テスト ケースを追加する
azure-streamanalytics-cicd addtestcase --project <projectFullPath> [-testConfigPath <testConfigFileFullPath>]
テスト ケースは、テスト構成ファイルにあります。
| 引数 | 説明 |
|---|---|
--project |
絶対パスまたは相対パスを使用して asaproj.json ファイルを指定します。 |
--testConfigPath |
テスト構成ファイルのパス。 この引数を指定しない場合、ツールは既定のファイル名 testConfig.jsonを使用して、asaproj.json ファイルの現在のディレクトリで \test 内のファイルを検索します。 ファイルが存在しない場合は、ツールによって新しいファイルが作成されます。 |
例:
# Go to the project directory
cd <path-to-the-project>
# Add a test case
azure-streamanalytics-cicd addtestcase --project ./asaproj.json
テスト構成ファイルが空の場合は、次の内容をファイルに追加します。 それ以外の場合は、 TestCases 配列にテスト ケースを追加します。 ツールは、入力構成ファイルに従って、必要な入力構成を自動的に入力します。 テストを実行する前に、各入力と予想される出力に FilePath を指定する必要があります。 この構成は手動で変更できます。
テスト検証で特定の出力を無視したい場合は、必要な出力の Required フィールドを false に設定してください。
{
"Script": [Absolute path of your script],
"TestCases": [
{
"Name": "Case 1",
"Inputs": [
{
"InputAlias": [Input alias string],
"Type": "Data Stream",
"Format": "JSON",
"FilePath": [Required],
"ScriptType": "InputMock"
}
],
"ExpectedOutputs": [
{
"OutputAlias": [Output alias string],
"FilePath": [Required],
"IgnoreFields": [Fields to ignore for test validation, e.g., ["col1", "col2"]],
"Required": true
}
]
}
]
}
単体テストを実行する
プロジェクトに対して複数のテスト ケースを実行するには、次のコマンドを使用します。 このプロセスでは、出力フォルダーにテスト結果の概要が生成されます。 すべてのテストが成功した場合はコード 0 、例外が発生した場合は -1 、テストが失敗した場合は -2 で終了します。
azure-streamanalytics-cicd test --project <projectFullPath> [--testConfigPath <testConfigFileFullPath>] [--outputPath <outputPath>] [--customCodeZipFilePath <zipFilePath>]
| 引数 | 説明 |
|---|---|
--project |
asaproj.json ファイルのパス。 |
--testConfigPath |
テスト構成ファイルのパス。 この引数を指定しない場合、プロセスは、既定のファイル名が testConfig.jsonされた、asaproj.json ファイルの現在のディレクトリで \test 内のファイルを検索します。 |
--outputPath |
テスト結果の出力フォルダーのパス。 この引数を指定しない場合、プロセスは出力結果ファイルを現在のディレクトリに配置します。 |
--customCodeZipFilePath |
UDF やデシリアライザーなどのカスタム コードが使用されている場合、その ZIP ファイルのパス。 DLL を zip ファイルにパッケージ化し、パスを指定する必要があります。 |
テスト ケースを実行すると、出力フォルダーに生成された testResultSummary.json ファイルが見つかります。
{
"Total": (integer) total_number_of_test_cases,
"Passed": (integer) number_of_passed_test_cases,
"Failed": (integer) number_of_failed_test_cases,
"Script": (string) absolute_path_to_asaql_file,
"Results": [ (array) detailed_results_of_test_cases
{
"Name": (string) name_of_test_case,
"Status": (integer) 0(passed)_or_1(failed),
"Time": (string) time_span_of_running_test_case,
"OutputMatched": [ (array) records_of_actual_outputs_equal_to_expected_outputs
{
"OutputAlias": (string) output_alias,
"ExpectedOutput": (string) path_to_the_expected_output_file,
"Output": (string) path_to_the_actual_output_file
}
],
"OutputNotEqual": [ (array) records_of_actual_outputs_not_equal_to_expected_outputs
{
"OutputAlias": (string) output_alias,
"ExpectedOutput": (string) path_to_the_expected_output_file,
"Output": (string) path_to_the_actual_output_file
}
],
"OutputMissing": [ (array) records_of_actual_outputs_missing
{
"OutputAlias": (string) output_alias,
"ExpectedOutput": (string) path_to_the_expected_output_file,
"Output": ""
}
],
"OutputUnexpected": [ (array) records_of_actual_outputs_unexpected
{
"OutputAlias": (string) output_alias,
"ExpectedOutput": "",
"Output": (string) path_to_the_actual_output_file
}
],
"OutputUnrequired": [ (array) records_of_actual_outputs_unrequired_to_be_checked
{
"OutputAlias": (string) output_alias,
"ExpectedOutput": (string) path_to_the_expected_output_file,
"Output": (string) path_to_the_actual_output_file
}
]
}
],
"Time": (string) time_span_of_running_all_test_cases,
}
注意
クエリ結果に float 値が含まれている場合、生成された値にわずかな違いが生じ、テストが失敗する可能性があります。 この違いは、Visual StudioまたはVisual Studio エンジンとテスト処理エンジンに電力を供給するさまざまな.NET フレームワークに基づいています。 テストが正常に実行されるようにするには、生成された値の精度を下げるか、生成されたテスト結果と手動で比較する結果を調整します。
Azure にデプロイ
ARM テンプレートを使用して Stream Analytics プロジェクトをデプロイするには、次の手順に従います。
Azure アカウントに接続します。
# Connect to Azure Connect-AzAccount # Set the Azure subscription Set-AzContext [SubscriptionID/SubscriptionName]Stream Analytics プロジェクトをデプロイします。
$templateFile = ".\Deploy\ClickStream-Filter.JobTemplate.json" $parameterFile = ".\Deploy\ClickStream-Filter.JobTemplate.parameters.json" New-AzResourceGroupDeployment ` -Name devenvironment ` -ResourceGroupName myResourceGroupDev ` -TemplateFile $templateFile ` -TemplateParameterFile $parameterFile
ARM テンプレートを使用したリソースのデプロイの詳細については、「Deploy with a Resource Manager template file and Azure PowerShell」を参照してください。