From edce8754cc814a89e2d83e71849271df2f3b3e75 Mon Sep 17 00:00:00 2001 From: Kushagra Thapar Date: Tue, 2 Feb 2021 10:44:09 -0800 Subject: [PATCH 1/5] Updated cosmos emulator yml script to remove the existing installation, install latest version and run emulator with latest version --- .../templates/steps/cosmos-emulator.yml | 80 ++++++++++++++++++- 1 file changed, 78 insertions(+), 2 deletions(-) diff --git a/eng/common/pipelines/templates/steps/cosmos-emulator.yml b/eng/common/pipelines/templates/steps/cosmos-emulator.yml index 564f3e429bd73..739261856d36c 100644 --- a/eng/common/pipelines/templates/steps/cosmos-emulator.yml +++ b/eng/common/pipelines/templates/steps/cosmos-emulator.yml @@ -9,8 +9,84 @@ steps: Write-Host "Target Dir: $targetDir" msiexec /a ${{ parameters.EmulatorMsiUrl }} TARGETDIR=$targetDir /qn | wait-process displayName: Download and Extract Public Cosmos DB Emulator + - powershell: | + Write-Host "Deleting Cosmos DB Emulator data" + if (Test-Path $Env:LOCALAPPDATA\CosmosDbEmulator) { Remove-Item -Recurse -Force $Env:LOCALAPPDATA\CosmosDbEmulator } + displayName: Delete Cosmos DB Emulator data + - powershell: | + Write-Host "Getting Cosmos DB Emulator Version" + $ProductName = "Azure Cosmos DB Emulator" + $Emulator = (Join-Path $env:temp (Join-Path $ProductName "Microsoft.Azure.Cosmos.Emulator.exe")) + $fileVersion = Get-ChildItem $Emulator + Write-Host $Emulator $fileVersion.VersionInfo + displayName: Get Cosmos DB Emulator Version - powershell: | Write-Host "Launching Cosmos DB Emulator" - Import-Module "$env:temp\Azure Cosmos DB Emulator\PSModules\Microsoft.Azure.CosmosDB.Emulator" - Start-CosmosDbEmulator -NoUI ${{ parameters.StartParameters }} + $ProductName = "Azure Cosmos DB Emulator" + $Emulator = (Join-Path $env:temp (Join-Path $ProductName "Microsoft.Azure.Cosmos.Emulator.exe")) + if (!(Test-Path $Emulator)) { + Write-Error "The emulator is not installed where expected at '$Emulator'" + return + } + $process = Start-Process $Emulator -ArgumentList "/getstatus" -PassThru -Wait + switch ($process.ExitCode) { + 1 { + Write-Host "The emulator is already starting" + return + } + 2 { + Write-Host "The emulator is already running" + return + } + 3 { + Write-Host "The emulator is stopped" + } + default { + Write-Host "Unrecognized exit code $process.ExitCode" + return + } + } + $argumentList = "" + if (-not [string]::IsNullOrEmpty("${{ parameters.StartParameters }}")) { + $argumentList += , "${{ parameters.StartParameters }}" + } + Write-Host "Starting emulator process: $Emulator $argumentList" + $process=Start-Process $Emulator -ArgumentList $argumentList -ErrorAction Stop -PassThru + Write-Host "Emulator process started: $($process.Name), $($process.FileVersion)" + $Timeout = 600 + $result="NotYetStarted" + $complete = if ($Timeout -gt 0) { + $start = [DateTimeOffset]::Now + $stop = $start.AddSeconds($Timeout) + { + $result -eq "Running" -or [DateTimeOffset]::Now -ge $stop + } + } + else { + { + $result -eq "Running" + } + } + do { + $process = Start-Process $Emulator -ArgumentList "/getstatus" -PassThru -Wait + switch ($process.ExitCode) { + 1 { + Write-Host "The emulator is starting" + } + 2 { + Write-Host "The emulator is running" + $result="Running" + return + } + 3 { + Write-Host "The emulator is stopped" + } + default { + Write-Host "Unrecognized exit code $process.ExitCode" + } + } + Start-Sleep -Seconds 5 + } + until ($complete.Invoke()) + Write-Error "The emulator failed to reach Running status within ${Timeout} seconds" displayName: Start Cosmos DB Emulator \ No newline at end of file From 4a9f04c3e987667e68aa47636e8e413d7e29c03f Mon Sep 17 00:00:00 2001 From: Kushagra Thapar Date: Wed, 3 Feb 2021 09:56:52 -0800 Subject: [PATCH 2/5] Added default emulator start arguments if none provided --- eng/common/pipelines/templates/steps/cosmos-emulator.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/eng/common/pipelines/templates/steps/cosmos-emulator.yml b/eng/common/pipelines/templates/steps/cosmos-emulator.yml index 739261856d36c..cb5e5b64442a0 100644 --- a/eng/common/pipelines/templates/steps/cosmos-emulator.yml +++ b/eng/common/pipelines/templates/steps/cosmos-emulator.yml @@ -49,6 +49,9 @@ steps: $argumentList = "" if (-not [string]::IsNullOrEmpty("${{ parameters.StartParameters }}")) { $argumentList += , "${{ parameters.StartParameters }}" + } else { + # Use the default params if none provided + $argumentList = "/noexplorer /noui /enablepreview /disableratelimiting /enableaadauthentication /partitioncount=50 /consistency=Strong" } Write-Host "Starting emulator process: $Emulator $argumentList" $process=Start-Process $Emulator -ArgumentList $argumentList -ErrorAction Stop -PassThru From 1a42ede5f6948dee1d1492f6a3fd8fec939fcb82 Mon Sep 17 00:00:00 2001 From: Kushagra Thapar Date: Wed, 3 Feb 2021 10:05:09 -0800 Subject: [PATCH 3/5] Updated default start params --- eng/common/pipelines/templates/steps/cosmos-emulator.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/eng/common/pipelines/templates/steps/cosmos-emulator.yml b/eng/common/pipelines/templates/steps/cosmos-emulator.yml index cb5e5b64442a0..0a4ad8d29a53e 100644 --- a/eng/common/pipelines/templates/steps/cosmos-emulator.yml +++ b/eng/common/pipelines/templates/steps/cosmos-emulator.yml @@ -1,6 +1,6 @@ parameters: EmulatorMsiUrl: "https://aka.ms/cosmosdb-emulator" - StartParameters: '' + StartParameters: '/noexplorer /noui /enablepreview /disableratelimiting /enableaadauthentication /partitioncount=50 /consistency=Strong' steps: - powershell: | @@ -49,9 +49,6 @@ steps: $argumentList = "" if (-not [string]::IsNullOrEmpty("${{ parameters.StartParameters }}")) { $argumentList += , "${{ parameters.StartParameters }}" - } else { - # Use the default params if none provided - $argumentList = "/noexplorer /noui /enablepreview /disableratelimiting /enableaadauthentication /partitioncount=50 /consistency=Strong" } Write-Host "Starting emulator process: $Emulator $argumentList" $process=Start-Process $Emulator -ArgumentList $argumentList -ErrorAction Stop -PassThru From c2579890ad5fcc283c455f50ac8174036b727848 Mon Sep 17 00:00:00 2001 From: Kushagra Thapar Date: Wed, 3 Feb 2021 10:40:39 -0800 Subject: [PATCH 4/5] Updated default start params in PS script --- eng/common/pipelines/templates/steps/cosmos-emulator.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/eng/common/pipelines/templates/steps/cosmos-emulator.yml b/eng/common/pipelines/templates/steps/cosmos-emulator.yml index 0a4ad8d29a53e..cb5e5b64442a0 100644 --- a/eng/common/pipelines/templates/steps/cosmos-emulator.yml +++ b/eng/common/pipelines/templates/steps/cosmos-emulator.yml @@ -1,6 +1,6 @@ parameters: EmulatorMsiUrl: "https://aka.ms/cosmosdb-emulator" - StartParameters: '/noexplorer /noui /enablepreview /disableratelimiting /enableaadauthentication /partitioncount=50 /consistency=Strong' + StartParameters: '' steps: - powershell: | @@ -49,6 +49,9 @@ steps: $argumentList = "" if (-not [string]::IsNullOrEmpty("${{ parameters.StartParameters }}")) { $argumentList += , "${{ parameters.StartParameters }}" + } else { + # Use the default params if none provided + $argumentList = "/noexplorer /noui /enablepreview /disableratelimiting /enableaadauthentication /partitioncount=50 /consistency=Strong" } Write-Host "Starting emulator process: $Emulator $argumentList" $process=Start-Process $Emulator -ArgumentList $argumentList -ErrorAction Stop -PassThru From f7f8582d6db84d43ebb2d11b25c2e33eb4beaf8b Mon Sep 17 00:00:00 2001 From: Kushagra Thapar Date: Wed, 3 Feb 2021 11:56:56 -0800 Subject: [PATCH 5/5] Updated default start params in PS script --- eng/common/pipelines/templates/steps/cosmos-emulator.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/pipelines/templates/steps/cosmos-emulator.yml b/eng/common/pipelines/templates/steps/cosmos-emulator.yml index cb5e5b64442a0..3032eab02d150 100644 --- a/eng/common/pipelines/templates/steps/cosmos-emulator.yml +++ b/eng/common/pipelines/templates/steps/cosmos-emulator.yml @@ -51,7 +51,7 @@ steps: $argumentList += , "${{ parameters.StartParameters }}" } else { # Use the default params if none provided - $argumentList = "/noexplorer /noui /enablepreview /disableratelimiting /enableaadauthentication /partitioncount=50 /consistency=Strong" + $argumentList = "/noexplorer /noui /enablepreview /disableratelimiting /enableaadauthentication" } Write-Host "Starting emulator process: $Emulator $argumentList" $process=Start-Process $Emulator -ArgumentList $argumentList -ErrorAction Stop -PassThru