Skip to content

Commit 977e76c

Browse files
Merge pull request #230801 from alexlzx/alex-23Mar
update ASA docs
2 parents 091fffe + 3192d2a commit 977e76c

File tree

5 files changed

+127
-188
lines changed

5 files changed

+127
-188
lines changed

articles/stream-analytics/TOC.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@
2727
items:
2828
- name: Azure portal
2929
href: create-cluster.md
30-
- name: Build application
31-
items:
32-
- name: Clickstream analysis
33-
href: quick-start-build-application.md
30+
- name: Build an End-to-End streaming application
31+
href: quick-start-build-application.md
3432
- name: Tutorials
3533
items:
3634
- name: Capture Event Hubs data in Parquet format

articles/stream-analytics/cicd-tools.md

Lines changed: 95 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -6,139 +6,128 @@ author: alexlzx
66
ms.author: zhenxilin
77
ms.service: stream-analytics
88
ms.topic: how-to
9-
ms.date: 12/27/2022
9+
ms.date: 03/08/2023
1010
---
1111

12-
# Automate builds, tests, and deployments of an Azure Stream Analytics job using CI/CD tools
12+
# Automate builds, tests, and deployments of a Stream Analytics project
1313

14-
After developing your Stream Analytics project in Visual Studio Code, you can use the Azure Stream Analytics (ASA) CI/CD npm package to automatically build, test, and deploy your Stream Analytics projects. This article shows how to use the npm package with any CI/CD system. For deployment with Azure Pipelines, see [Use Azure DevOps to create a CI/CD pipeline for a Stream Analytics job](set-up-cicd-pipeline.md).
14+
The Azure Stream Analytics (ASA) CI/CD npm package allows you to automatically build, test, and deploy your Stream Analytics projects. This article shows how to use the npm package with any CI/CD system. To set up a pipeline with Azure DevOps, see [Use Azure DevOps to create a CI/CD pipeline for a Stream Analytics job](set-up-cicd-pipeline.md).
15+
16+
If you don't have a Stream Analytics project, [create one using Visual Studio Code](./quick-create-visual-studio-code.md) or export an existing one from the Azure portal.
1517

1618
## Installation
1719

18-
You can [download the package](https://www.npmjs.com/package/azure-streamanalytics-cicd) directly, or install it [globally](https://docs.npmjs.com/downloading-and-installing-packages-globally) using the `npm install -g azure-streamanalytics-cicd` command. We recommend using the command, which can also be used in a PowerShell or Azure CLI script task of a build pipeline in **Azure Pipelines**.
20+
You can download the package from [npm site](https://www.npmjs.com/package/azure-streamanalytics-cicd), or run the following command in your terminal.
1921

20-
## Build the project
22+
```powershell
23+
npm install -g azure-streamanalytics-cicd
24+
```
2125

22-
The **asa-streamanalytics-cicd** npm package provides the tools to generate Azure Resource Manager templates of Stream Analytics [Visual Studio Code projects](./quick-create-visual-studio-code.md) or [Visual Studio projects](stream-analytics-quick-create-vs.md). You can also use the npm package on Windows, macOS, and Linux without installing Visual Studio Code or Visual Studio.
26+
## Build project
2327

24-
Once you've installed the package, use the following command to build your Stream Analytics projects.
28+
> [!NOTE]
29+
> We highly recommend that you use the `--v2` option for the updated ARM template schema. The updated schema has fewer parameters yet retains the same functionality as the previous version.
30+
>
31+
> The old ARM template will be deprecated in the future. From now on, only templates that were created via `build --v2` will receive updates or bug fixes.
2532
2633
```powershell
27-
azure-streamanalytics-cicd build -project <projectFullPath> [-outputPath <outputPath>]
34+
azure-streamanalytics-cicd build --v2 --project <projectFullPath> [--outputPath <outputPath>]
2835
```
2936

30-
The *build* command does a keyword syntax check and outputs the Azure Resource Manager template.
37+
The *build* command does a keyword syntax check and generates Azure Resource Manager (ARM) templates.
3138

32-
| Parameter | Description |
39+
| Argument | Description |
3340
|---|---|
34-
| `-project` | The absolute path of the **asaproj.json** file for your Visual Studio Code project or **[Your project name].asaproj** for Visual Studio project. |
35-
| `-outputPath` | The path of the output folder for Azure Resource Manager Templates. If it isn't specified, the templates will be placed in the current directory. |
41+
| `--project` | Specify the **asaproj.json** file using absolute or relative path. |
42+
| `--outputPath` | Specify the output folder for storing ARM Templates using absolute or relative path. If `outputPath` isn't specified, the templates are placed in the current directory. |
3643

37-
#### [Visual Studio Code](#tab/visual-studio-code)
44+
**Example**:
3845

3946
```powershell
40-
azure-streamanalytics-cicd build -project "/Users/username/projects/samplejob/asaproj.json"
41-
```
42-
43-
#### [Visual Studio](#tab/visual-studio)
47+
# Go to the project directory
48+
cd <path-to-the-project>
4449
45-
```powershell
46-
azure-streamanalytics-cicd build -project "/Users/username/projects/samplejob/samplejob.asaproj"
50+
# Build project
51+
azure-streamanalytics-cicd build --v2 --project ./asaproj.json --outputPath ./Deploy
4752
```
4853

49-
---
50-
51-
When a Stream Analytics project builds successfully, it generates the following two files under the output folder:
52-
53-
* Azure Resource Manager template file
54-
55-
`[ProjectName].JobTemplate.json`
56-
57-
* Azure Resource Manager parameter file
54+
If the project is built successfully, you see two JSON files created under the output folder:
5855

59-
`[ProjectName].JobTemplate.parameters.json`
56+
* ARM template file: `[ProjectName].JobTemplate.json`
57+
* ARM parameter file: `[ProjectName].JobTemplate.parameters.json`
6058

61-
The default parameters in the parameters.json file are from the settings in your Visual Studio Code or Visual Studio project. If you want to deploy to another environment, replace the parameters accordingly.
59+
The default values for **parameters.json** file come from your project settings. If you want to deploy to another environment, replace the values accordingly.
6260

6361
The default values for all credentials are **null**. You're required to set the values before you deploy to Azure.
6462

6563
```json
6664
"Input_EntryStream_sharedAccessPolicyKey": {
67-
"value": null
68-
},
65+
"value": null
66+
}
6967
```
7068

71-
To use Managed Identity for Azure Data Lake Store Gen1 as an output sink, you need to provide access to the service principal using PowerShell before you deploy to Azure. Learn more about how to [deploy ADLS Gen1 with Managed Identity with Resource Manager template](stream-analytics-managed-identities-adls.md#resource-manager-template-deployment).
69+
To use Managed Identity for Azure Data Lake Store Gen1 as output sink, you need to provide Access to the service principal using PowerShell before deploying to Azure. Learn more about how to [deploy ADLS Gen1 with Managed Identity with Resource Manager template](https://aka.ms/asamideploy).
7270

73-
## Local run
71+
## Run locally
7472

7573
If your project has specified local input files, you can run a Stream Analytics script locally by using the `localrun` command.
7674

7775
```powershell
7876
azure-streamanalytics-cicd localrun -project <projectFullPath> [-outputPath <outputPath>] [-customCodeZipFilePath <zipFilePath>]
7977
```
80-
81-
| Parameter | Description |
78+
| Argument | Description |
8279
|---|---|
83-
| `-project` | The path of the **asaproj.json** file for your Visual Studio Code project or **[Your project name].asaproj** for Visual Studio project. |
84-
| `-outputPath` | The path of the output folder. If it isn't specified, the output result files will be placed in the current directory. |
85-
| `-customCodeZipFilePath` | The path of the zip file for C# custom code, such as a UDF or deserializer, if they're used. Package the DLLs into a zip file and specify this path. |
80+
| `--project` | Specify the **asaproj.json** file using absolute or relative path. |
81+
| `--outputPath` | Specify the output folder for storing ARM Templates using absolute or relative path. If `outputPath` isn't specified, the templates are placed in the current directory. |
82+
| `--customCodeZipFilePath` | The path of the zip file for C# custom code, such as a UDF or deserializer, if they're used. Package the DLLs into a zip file and specify this path. |
8683

87-
#### [Visual Studio Code](#tab/visual-studio-code)
84+
**Example**:
8885

8986
```powershell
90-
azure-streamanalytics-cicd localrun -project "/Users/roger/projects/samplejob/asaproj.json"
91-
```
87+
# Go to the project directory
88+
cd <path-to-the-project>
9289
93-
#### [Visual Studio](#tab/visual-studio)
94-
95-
```powershell
96-
azure-streamanalytics-cicd localrun -project "/Users/roger/projects/samplejob/samplejob.asaproj"
90+
# Run project locally
91+
azure-streamanalytics-cicd localrun --project ./asaproj.json"
9792
```
9893

99-
---
100-
101-
> [!Note]
94+
> [!NOTE]
10295
> JavaScript UDF only works on Windows.
10396
10497
## Automated test
10598

106-
You can use the CI/CD npm package to configure and run automated tests for your Stream Analytics script.
99+
You can use the CI/CD npm package to configure and run automated tests for your Stream Analytics project.
107100

108101
### Add a test case
109102

110-
The test cases are described in a test configuration file. To get started, use the `addtestcase` command to add a test case template to the test configuration file. If the test configuration file doesn't exist, one is created by default.
111-
112103
```powershell
113-
azure-streamanalytics-cicd addtestcase -project <projectFullPath> [-testConfigPath <testConfigFileFullPath>]
104+
azure-streamanalytics-cicd addtestcase --project <projectFullPath> [-testConfigPath <testConfigFileFullPath>]
114105
```
115106

116-
| Parameter | Description |
117-
|---|---|
118-
| `-project` | The path of the **asaproj.json** file for your Visual Studio Code project or **[Your project name].asaproj** for Visual Studio project. |
119-
| `-testConfigPath` | The path of the test configuration file. If it isn't specified, the file will be searched in **\test** under the current directory of the **asaproj.json** file, with default file name **testConfig.json**. A new file will be created if not existed. |
107+
You can find the test cases in the test configuration file.
120108

121-
> [!NOTE]
122-
> The `Script` value in the generated **testConfig.json** file is only for providing the context; It's not used in the testing logic.
109+
| Argument | Description |
110+
|---|---|
111+
| `--project` | Specify the **asaproj.json** file using absolute or relative path. |
112+
| `--testConfigPath` | The path of the test configuration file. If it isn't specified, the file is searched in **\test** under the current directory of the **asaproj.json** file, with default file name **testConfig.json**. A new file is created if not existed. |
123113

124-
#### [Visual Studio Code](#tab/visual-studio-code)
114+
**Example**:
125115

126116
```powershell
127-
azure-streamanalytics-cicd addtestcase -project "/Users/roger/projects/samplejob/asaproj.json"
128-
```
129-
130-
#### [Visual Studio](#tab/visual-studio)
117+
# Go to the project directory
118+
cd <path-to-the-project>
131119
132-
```powershell
133-
azure-streamanalytics-cicd addtestcase -project "/Users/roger/projects/samplejob/samplejob.asaproj"
120+
# Add a test case
121+
azure-streamanalytics-cicd addtestcase --project ./asaproj.json
134122
```
135-
---
136123

137-
If the test configuration file is empty, the following content is written into the file. Otherwise, a test case is added into the array of **TestCases**. Necessary input configurations are automatically filled according to the input configuration files, if they exist. Otherwise, default values are configured. **FilePath** of each input and expected output must be specified before running the test. You can modify the configuration manually.
124+
If the test configuration file is empty, the following content is added to the file. Otherwise, a test case is added to a **TestCases** array. Necessary input configurations are automatically filled according to the input configuration file. **FilePath** of each input and expected output must be specified before running the test. You can modify this configuration manually.
125+
126+
If you want the test validation to ignore a certain output, set the **Required** field of that expected output to **false**.
138127

139128
```json
140129
{
141-
"Script": "",
130+
"Script": [Absolute path of your script],
142131
"TestCases": [
143132
{
144133
"Name": "Case 1",
@@ -155,6 +144,7 @@ If the test configuration file is empty, the following content is written into t
155144
{
156145
"OutputAlias": [Output alias string],
157146
"FilePath": [Required],
147+
"IgnoreFields": [Fields to ignore for test validation, e.g., ["col1", "col2"]],
158148
"Required": true
159149
}
160150
]
@@ -163,108 +153,22 @@ If the test configuration file is empty, the following content is written into t
163153
}
164154
```
165155

166-
The following example shows two test cases, on a query using two inputs. If you want the test validation to ignore a certain output, set the **Required** field of that expected output to **false**. In this case, the FilePath property must not be empty, but doesn't need to be valid.
167-
168-
```JSON
169-
{
170-
"Script": "C:\\...\\...\\samplejob.asaql",
171-
"TestCases": [
172-
{
173-
"Name": "Case 1 - Testing all outputs at once",
174-
"Inputs": [
175-
{
176-
"InputAlias": "entry",
177-
"Type": "Data Stream",
178-
"Format": "Json",
179-
"FilePath": "C:\\...\\...\\Case1_Data_entry.json",
180-
"ScriptType": "InputMock"
181-
},
182-
{
183-
"InputAlias": "exit",
184-
"Type": "Data Stream",
185-
"Format": "Json",
186-
"FilePath": "C:\\...\\...\\Case1_Data_exit.json",
187-
"ScriptType": "InputMock"
188-
}
189-
],
190-
"ExpectedOutputs": [
191-
{
192-
"OutputAlias": "output1",
193-
"FilePath": "C:\\...\\...\\Case1_output1.json",
194-
"Required": true
195-
},
196-
{
197-
"OutputAlias": "output2",
198-
"FilePath": "C:\\...\\...\\Case1_output2.json",
199-
"Required": true
200-
}
201-
]
202-
},
203-
{
204-
"Name": "Case 2 - Testing only one output at a time (recommended)",
205-
"Inputs": [
206-
{
207-
"InputAlias": "entry",
208-
"Type": "Data Stream",
209-
"Format": "Json",
210-
"FilePath": "C:\\...\\...\\Case2_Data_entry.json",
211-
"ScriptType": "InputMock"
212-
},
213-
{
214-
"InputAlias": "exit",
215-
"Type": "Data Stream",
216-
"Format": "Json",
217-
"FilePath": "C:\\...\\...\Case2_Data_exit.json",
218-
"ScriptType": "InputMock"
219-
}
220-
],
221-
"ExpectedOutputs": [
222-
{
223-
"OutputAlias": "output1",
224-
"FilePath": "C:\\...\\...\\Case2_output1.json",
225-
"Required": true
226-
},
227-
{
228-
"OutputAlias": "output2",
229-
"FilePath": "[N/A]",
230-
"Required": false
231-
}
232-
]
233-
}
234-
]
235-
}
236-
```
237-
238-
> [!NOTE]
239-
> Currently, the only allowed value for the `ScriptType` element is `InputMock`, which is also the default value. If you set it to any other value, it's ignored and the default value (`InputMock`) is used.
240-
241-
### Run a unit test
156+
### Run unit test
242157

243158
You can use the following command to run multiple test cases for your project. A summary of test results is generated in the output folder. The process exits with code **0** for all tests passed; **-1** for exception occurred; **-2** for tests failed.
244159

245160
```powershell
246-
azure-streamanalytics-cicd test -project <projectFullPath> [-testConfigPath <testConfigFileFullPath>] [-outputPath <outputPath>] [-customCodeZipFilePath <zipFilePath>]
161+
azure-streamanalytics-cicd test --project <projectFullPath> [--testConfigPath <testConfigFileFullPath>] [--outputPath <outputPath>] [--customCodeZipFilePath <zipFilePath>]
247162
```
248163

249-
| Parameter | Description |
164+
| Argument | Description |
250165
|---|---|
251-
| `-project` | The path of the **asaproj.json** file for your Visual Studio Code project or **[Your project name].asaproj** for Visual Studio project. |
252-
| `-testConfigPath` | The path to the test configuration file. If it isn't specified, the file will be searched in **\test** under the current directory of the **asaproj.json** file, with default file name **testConfig.json**.
253-
| `-outputPath` | The path of the test result output folder. If it isn't specified, the output result files will be placed in the current directory. |
254-
| `-customCodeZipFilePath` | The path of the zip file for custom code such as a UDF or deserializer, if they're used. |
255-
256-
As an example, in a PowerShell enabled terminal, if all test assets are located in a `test` subfolder of the project folder. With each test run output stored in a new timestamped subfolder of a `testResults` subfolder:
166+
| `--project` | The path of the **asaproj.json** file. |
167+
| `--testConfigPath` | The path to the test configuration file. If it isn't specified, the file is searched in **\test** under the current directory of the **asaproj.json** file, with default file name **testConfig.json**.
168+
| `--outputPath` | The path of the test result output folder. If it isn't specified, the output result files are placed in the current directory. |
169+
| `--customCodeZipFilePath` | The path of the zip file for custom code such as a UDF or deserializer, if they're used. You need to package the DLLs to zip file and specify the path. |
257170

258-
```PowerShell
259-
$projectPath = "C:\...\...\samplejob\"
260-
261-
azure-streamanalytics-cicd test `
262-
-project ($projectPath + "asaproj.json") `
263-
-testConfigPath ($projectPath + "test\testConfig.json") `
264-
-outputPath ($projectPath + "test\testResults\$(Get-Date -Format "yyyyMMddHHmmss")\")
265-
```
266-
267-
When all tests are finished, a summary of the test results in JSON format is generated in the output folder. The summary file is named **testResultSummary.json**.
171+
If test cases are executed, you can find a **testResultSummary.json** file generated in the output folder.
268172

269173
```json
270174
{
@@ -318,11 +222,37 @@ When all tests are finished, a summary of the test results in JSON format is gen
318222
}
319223
```
320224

225+
> [!NOTE]
226+
> If the query results contain float values, you might experience slight differences in the produced values leading to a probably failed test. This is based on the different .Net frameworks powering the Visual Studio or Visual Studio engine and the test processing engine. If you want to make sure that the tests run successfully, you will have to decrease the precision of your produced values or align the results to be compared manually to the generated test results.
227+
228+
321229
## Deploy to Azure
322230

323-
You can use the Azure Resource Manager template and parameter files generated from Build to [deploy your job to Azure](../azure-resource-manager/templates/template-tutorial-use-parameter-file.md?tabs=azure-powershell#deploy-template).
231+
To deploy your Stream Analytics project using ARM templates, follow these steps:
232+
1. Connect to your Azure account:
233+
234+
```powershell
235+
# Connect to Azure
236+
Connect-AzAccount
237+
# Set the Azure subscription
238+
Set-AzContext [SubscriptionID/SubscriptionName]
239+
```
240+
241+
2. Deploy your Stream Analytics project:
242+
243+
```powershell
244+
$templateFile = ".\Deploy\ClickStream-Filter.JobTemplate.json"
245+
$parameterFile = ".\Deploy\ClickStream-Filter.JobTemplate.parameters.json"
246+
New-AzResourceGroupDeployment `
247+
-Name devenvironment `
248+
-ResourceGroupName myResourceGroupDev `
249+
-TemplateFile $templateFile `
250+
-TemplateParameterFile $parameterFile
251+
```
252+
253+
For more information about deploying resources with ARM templates, see [Deploy with a Resource Manager template file and Azure PowerShell](https://aka.ms/armdeploytemplate).
324254
325255
## Next steps
326256
327257
* [Continuous integration and Continuous deployment for Azure Stream Analytics](cicd-overview.md)
328-
* [Set up CI/CD pipeline for Stream Analytics job using Azure Pipelines](set-up-cicd-pipeline.md)
258+
* [Set up CI/CD pipeline for Stream Analytics job using Azure Pipelines](set-up-cicd-pipeline.md)
1.64 MB
Loading

0 commit comments

Comments
 (0)