Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 37 additions & 14 deletions src/Migrate/Migrate.Autorest/custom/Get-AzMigrateLocalJob.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ param(
)

process {
$helperPath = [System.IO.Path]::Combine($PSScriptRoot, "Helper", "AzLocalCommonSettings.ps1")
Import-Module $helperPath
$helperPath = [System.IO.Path]::Combine($PSScriptRoot, "Helper", "AzLocalCommonHelper.ps1")
Import-Module $helperPath

$parameterSet = $PSCmdlet.ParameterSetName
$null = $PSBoundParameters.Remove('ID')
$null = $PSBoundParameters.Remove('ResourceGroupName')
Expand All @@ -208,55 +213,73 @@ param(
$null = $PSBoundParameters.Remove('ResourceGroupID')
$null = $PSBoundParameters.Remove('ProjectID')

if (($parameterSet -match 'Name') -or ($parameterSet -eq 'ListById')) {
if ($parameterSet -eq 'ListById') {
if (($parameterSet -match 'Name') -or ($parameterSet -eq 'ListById'))
{
if ($parameterSet -eq 'ListById')
{
$ProjectIdArray = $ProjectID.Split("/")
if ($ProjectIdArray.Length -lt 9) {
if ($ProjectIdArray.Length -lt 9)
{
throw "Invalid Project ID '$ProjectID'"
}
$ProjectName = $ProjectIdArray[8]
$ResourceGroupName = $ResourceGroupID.Split("/")[4]
}

# Get the migrate solution.
$amhSolutionName = $AzMigrateSolutions.DataReplicationSolution
$null = $PSBoundParameters.Add("ResourceGroupName", $ResourceGroupName)
$null = $PSBoundParameters.Add("Name", "Servers-Migration-ServerMigration_DataReplication")
$null = $PSBoundParameters.Add("Name", $amhSolutionName)
$null = $PSBoundParameters.Add("MigrateProjectName", $ProjectName)

$solution = Az.Migrate.private\Get-AzMigrateSolution_Get @PSBoundParameters
if ($solution -and ($solution.Count -ge 1)) {

$solution = Az.Migrate.private\Get-AzMigrateSolution_Get @PSBoundParameters `
-ErrorVariable notPresent `
-ErrorAction SilentlyContinue
if ($null -ne $solution -and ($solution.Count -ge 1))
{
$vaultId = $solution.DetailExtendedDetail["vaultId"]
$vaultIdArray = $vaultId.Split("/")
if ($vaultIdArray.Length -lt 9) {
if ($vaultIdArray.Length -lt 9)
{
throw "Invalid Vault ID '$vaultId'"
}
$vaultName = $vaultIdArray[8]
}
else {
else
{
throw "Solution not found."
}

$null = $PSBoundParameters.Remove("ResourceGroupName")
$null = $PSBoundParameters.Remove("Name")
$null = $PSBoundParameters.Remove("MigrateProjectName")
}
else {
if ($parameterSet -eq 'GetByInputObject') {
else
{
if ($parameterSet -eq 'GetByInputObject')
{
$ID = $InputObject.Id
}

$jobIdArray = $ID.split('/')
if ($jobIdArray.Length -lt 11) {
if ($jobIdArray.Length -lt 11)
{
throw "Invalid Job ID '$ID'"
}

$ResourceGroupName = $jobIdArray[4]
$vaultName = $jobIdArray[8]
$Name = $jobIdArray[10]
}

$null = $PSBoundParameters.Add('ResourceGroupName', $ResourceGroupName)
$null = $PSBoundParameters.Add('VaultName', $vaultName)
if ($parameterSet -match 'Get') {

if ($parameterSet -match 'Get')
{
$null = $PSBoundParameters.Add('JobName', $Name)
}

return Az.Migrate.Internal\Get-AzMigrateLocalReplicationJob @PSBoundParameters -ErrorVariable notPresent -ErrorAction SilentlyContinue
return Az.Migrate.Internal\Get-AzMigrateLocalReplicationJob @PSBoundParameters
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,34 +185,36 @@ function Get-AzMigrateLocalServerReplication {
throw "Unknown machine site '$siteName' with Type '$siteType'."
}

# Occasionally, Get Machine Site will not return machine site even when the site exist,
# hence retry get machine site.
if ($siteType -eq $SiteTypes.VMwareSites) {
$siteObject = InvokeAzMigrateGetCommandWithRetries `
-CommandName 'Az.Migrate.private\Get-AzMigrateSite_Get' `
-Parameters $PSBoundParameters `
-ErrorMessage "Machine site '$siteName' with Type '$siteType' not found."
$siteObject = Az.Migrate.private\Get-AzMigrateSite_Get @PSBoundParameters `
-ErrorVariable notPresent `
-ErrorAction SilentlyContinue
} elseif ($siteType -eq $SiteTypes.HyperVSites) {
$siteObject = InvokeAzMigrateGetCommandWithRetries `
-CommandName 'Az.Migrate.Internal\Get-AzMigrateHyperVSite' `
-Parameters $PSBoundParameters `
-ErrorMessage "Machine site '$siteName' with Type '$siteType' not found."
$siteObject = Az.Migrate.Internal\Get-AzMigrateHyperVSite @PSBoundParameters `
-ErrorVariable notPresent `
-ErrorAction SilentlyContinue
}

if ($null -eq $siteObject)
{
throw "Machine site '$siteName' with Type '$siteType' not found. Please verify in your Azure Migrate project resource group '$ResourceGroupName' and re-run this command if exists."
}
$null = $PSBoundParameters.Remove('SiteName')

# $siteObject is not null or exception would have been thrown
$ProjectName = $siteObject.DiscoverySolutionId.Split("/")[8]

$null = $PSBoundParameters.Remove('SiteName')

# Get the migrate solution.
$amhSolutionName = "Servers-Migration-ServerMigration_DataReplication"
$amhSolutionName = $AzMigrateSolutions.DataReplicationSolution
$null = $PSBoundParameters.Add("Name", $amhSolutionName)
$null = $PSBoundParameters.Add("MigrateProjectName", $ProjectName)

$solution = InvokeAzMigrateGetCommandWithRetries `
-CommandName 'Az.Migrate.private\Get-AzMigrateSolution_Get' `
-Parameters $PSBoundParameters `
-ErrorMessage "No Data Replication Service Solution '$amhSolutionName' found in resource group '$ResourceGroupName' and project '$ProjectName'. Please verify your appliance setup."
$solution = Az.Migrate.private\Get-AzMigrateSolution_Get @PSBoundParameters `
-ErrorVariable notPresent `
-ErrorAction SilentlyContinue
if ($null -eq $solution) {
throw "No Data Replication Service Solution '$amhSolutionName' found in resource group '$ResourceGroupName' and project '$ProjectName'. Please verify your appliance setup."
}

$null = $PSBoundParameters.Remove("Name")
$null = $PSBoundParameters.Remove("MigrateProjectName")
Expand Down Expand Up @@ -241,15 +243,17 @@ function Get-AzMigrateLocalServerReplication {
$ProjectName = $projectIdArray[8] # {2}
}

$amhSolutionName = "Servers-Migration-ServerMigration_DataReplication"
$amhSolutionName = $AzMigrateSolutions.DataReplicationSolution
$null = $PSBoundParameters.Add("ResourceGroupName", $ResourceGroupName)
$null = $PSBoundParameters.Add("Name", $amhSolutionName)
$null = $PSBoundParameters.Add("MigrateProjectName", $ProjectName)

$solution = InvokeAzMigrateGetCommandWithRetries `
-CommandName 'Az.Migrate.private\Get-AzMigrateSolution_Get' `
-Parameters $PSBoundParameters `
-ErrorMessage "No Data Replication Service Solution '$amhSolutionName' found in resource group '$ResourceGroupName' and project '$ProjectName'. Please verify your appliance setup."
$solution = Az.Migrate.private\Get-AzMigrateSolution_Get @PSBoundParameters `
-ErrorVariable notPresent `
-ErrorAction SilentlyContinue
if ($null -eq $solution) {
throw "No Data Replication Service Solution '$amhSolutionName' found in resource group '$ResourceGroupName' and project '$ProjectName'. Please verify your appliance setup."
}

$null = $PSBoundParameters.Remove("Name")
$null = $PSBoundParameters.Remove("MigrateProjectName")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,9 @@ $TargetVMRamInMB = @{
Gen1Max = 1048576 # 1 TB
Gen2Min = 32
Gen2Max = 12582912 # 12 TB
}

$AzMigrateSolutions = @{
DataReplicationSolution = "Servers-Migration-ServerMigration_DataReplication"
DiscoverySolution = "Servers-Discovery-ServerDiscovery"
}
Loading
Loading