Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #28 from jabbera/deploymentGroups
Browse files Browse the repository at this point in the history
Deployment groups
  • Loading branch information
jabbera committed Feb 28, 2018
2 parents d10b27b + cdd299a commit e738033
Show file tree
Hide file tree
Showing 29 changed files with 1,232 additions and 924 deletions.
Empty file removed .gitmodules
Empty file.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.insertSpaces": true
}
14 changes: 12 additions & 2 deletions Extensions/Common/DeploymentSDK/Src/InvokeRemoteDeployment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ function Invoke-RemoteDeployment
{
Write-Host "Performing deployment in parallel on all the machines."
[hashtable]$Jobs = @{}
$dtlsdkErrors = @()
foreach($resource in $resourceList)
{
$winRmPort = [System.Convert]::ToInt32($resource.port)
Expand Down Expand Up @@ -161,6 +162,7 @@ function Invoke-RemoteDeployment
}
Write-Verbose ($output|Format-List -Force|Out-String)
Write-Host "Deployment failed on machine $machineName with following message : $errorMsg"
$dtlsdkErrors += $output.DeploymentSummary
}
else
{
Expand All @@ -173,7 +175,10 @@ function Invoke-RemoteDeployment

if($operationStatus -ne "Passed")
{
$errorMsg = 'Deployment on one or more machines failed.'
foreach ($error in $dtlsdkErrors) {
Write-Telemetry "DTLSDK_Error" $error
}
$errorMsg = [string]::Format("Deployment on one or more machines failed. {0}", $errorMsg)
}
}
else
Expand All @@ -190,12 +195,13 @@ function Invoke-RemoteDeployment
if ($deploymentResponse.Status -ne "Passed")
{
$operationStatus = "Failed"
Write-Telemetry "DTLSDK_Error" $deploymentResponse.DeploymentSummary
Write-Verbose ($deploymentResponse|Format-List -Force|Out-String)
if($deploymentResponse.Error -ne $null)
{
$errorMsg = $deploymentResponse.Error.ToString()
break
}
}
}
else
{
Expand Down Expand Up @@ -253,6 +259,7 @@ function Get-Credentials
Write-Verbose "Creating credentials object for connecting to remote host"
if([string]::IsNullOrWhiteSpace($userName) -or [string]::IsNullOrWhiteSpace($password))
{
Write-Telemetry "Input_Validation" "Invalid administrator credentials. UserName/Password null/empty"
throw "Invalid administrator credentials."
}

Expand Down Expand Up @@ -314,17 +321,20 @@ function Get-MachineNameAndPort

if($tokens.Count -gt 2)
{
Write-Telemetry "Input_Validation" "Invalid user input, speficy machines in machine:port format."
throw "Invalid user input, speficy machines in machine:port format."
}

[System.Int32]$port = $null
if($tokens.Count -eq 2 -and ![System.Int32]::TryParse($tokens[1], [ref]$port))
{
Write-Telemetry "Input_Validation" "Invalid user input, port is not an integer."
throw "Invalid user input, port is not an integer."
}

if([string]::IsNullOrWhiteSpace($tokens[0]))
{
Write-Telemetry "Input_Validation" "Invalid user input, machine name can not be empty."
throw "Invalid user input, machine name can not be empty."
}

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
54 changes: 54 additions & 0 deletions Extensions/Common/DeploymentSDK/Src/Utility.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
function convertTo-JsonFormat($InputObject) {
if (Get-Command ConvertTo-Json -ErrorAction SilentlyContinue)
{
$jsonOutput = ConvertTo-Json -InputObject $InputObject
}
else
{
try
{
add-type -assembly system.web.extensions
$scriptSerializer = new-object system.web.script.serialization.javascriptSerializer
$jsonOutput = $scriptSerializer.Serialize($InputObject)
}
catch
{
Write-Verbose $_.Exception
$errorMessage = "Unable to convert json string to object. Please install WMF 4.0 and try again."
if($_.Exception.Message)
{
$errorMessage = [string]::Format("{0} {1} {2}", $errorMessage, [Environment]::NewLine, $_.Exception.Message)
}
throw $errorMessage
}
}
return $jsonOutput
}

function convertFrom-JsonFormat($InputObject) {
if (Get-Command ConvertTo-Json -ErrorAction SilentlyContinue)
{
$convertedObject = ConvertFrom-Json -InputObject $InputObject
}
else
{
try
{
add-type -assembly system.web.extensions
$scriptSerializer = new-object system.web.script.serialization.javascriptSerializer
$convertedObject = ,$scriptSerializer.DeserializeObject($InputObject)
}
catch
{
Write-Verbose $_.Exception
$errorMessage = "Unable to convert json string to object. Please install WMF 4.0 and try again."
if($_.Exception.Message)
{
$errorMessage = [string]::Format("{0} {1} {2}", $errorMessage, [Environment]::NewLine, $_.Exception.Message)
}
throw $errorMessage
}

}
return $convertedObject
}
Binary file modified Extensions/Common/DeploymentSDK/Src/VisualStudioRemoteDeployer.exe
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ if(-not (Test-Path -Path $invokeRemoteDeployment ))

. "$invokeRemoteDeployment"

## Mocking the telemetry method
function Write-Telemetry {}

Describe "Tests for testing InitializationScript block" {
Context "Invoke-PsOnRemote successfully returns" {
. $InitializationScript
Expand Down Expand Up @@ -134,7 +137,7 @@ Describe "Tests for testing Invoke-RemoteDeployment functionality" {

It "Should process jobs in parallel and wait for their completion"{
Assert-VerifiableMocks
($errMsg) | Should Be "Deployment on one or more machines failed."
($errMsg) | Should Be "Deployment on one or more machines failed. "
Assert-MockCalled Write-Host -Times 8 -Exactly
}
}
Expand Down
75 changes: 75 additions & 0 deletions Extensions/Common/DeploymentSDK/Tests/Utility.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
$currentScriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
$VerbosePreference = 'Continue'

$UtilityScript = "$currentScriptPath\..\Src\$sut"

if(-not (Test-Path -Path $UtilityScript))
{
throw [System.IO.FileNotFoundException] "Unable to find Utility.ps1 at $UtilityScript"
}

. "$UtilityScript"


Describe "Tests for ConvertTo-JsonFormat method" {
Context "Convert object to json string on PS where ConvertTo-Json cmdlet exists" {
$argumentAsObject = @{Name="test";Type="task"}

Mock Get-Command -Verifiable { return $true}

$jsonOutput = ConvertTo-JsonFormat -InputObject $argumentAsObject

It "Should convert object to json string" {
$jsonOutput | Should Not be $null
$jsonOutput.GetType().Name | Should Be "String"
$jsonOutput.Contains("Name") | Should Be $true
$jsonOutput.Contains("Type") | Should Be $true
}
}

Context "Convert object to json string on PS where ConvertTo-Json cmdlet doesnot exists" {
$argumentAsObject = @{Name="test";Type="task"}

Mock Get-Command -Verifiable { return $false}

$jsonOutput = ConvertTo-JsonFormat -InputObject $argumentAsObject

It "Should convert object to json string" {
$jsonOutput | Should Not be $null
$jsonOutput.GetType().Name | Should Be "String"
$jsonOutput.Contains("Name") | Should Be $true
$jsonOutput.Contains("Type") | Should Be $true
}
}

Context "Convert json string to object on PS where ConvertTo-Json cmdlet exists" {
$jsonString = "{`"Name`":`"test`",`"Type`":`"task`"}"

Mock Get-Command -Verifiable { return $true}

$argObject = ConvertFrom-JsonFormat -InputObject $jsonString

It "Should convert json string into object" {
$argObject | Should Not be $null
$argObject.GetType().Name | Should Be "PSCustomObject"
$argObject.Name | Should Be "test"
$argObject.Type | Should Be "task"
}
}

Context "Convert json string to object on PS where ConvertTo-Json cmdlet doesnot exists" {
$jsonString = "{`"Name`":`"test`",`"Type`":`"task`"}"

Mock Get-Command -Verifiable { return $false}

$argObject = ConvertFrom-JsonFormat -InputObject $jsonString

It "Should convert json string into object" {
$argObject | Should Not be $null
$argObject.Name | Should Be "test"
$argObject.Type | Should Be "task"
}
}
}

Loading

0 comments on commit e738033

Please sign in to comment.