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,37 @@ 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
}

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

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."
}

# $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 -ne $solution -and ($solution.Count -ge 1)) {
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 +244,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 -ne $solution -and ($solution.Count -ge 1)) {
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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,25 +179,26 @@ function Initialize-AzMigrateLocalReplicationInfrastructure {

# Get Migrate Project
$migrateProject = InvokeAzMigrateGetCommandWithRetries `
-CommandName "Az.Migrate.private\Get-AzMigrateProject_Get" `
-CommandName "Get-AzMigrateProject" `
-Parameters @{
"SubscriptionId" = $SubscriptionId;
"ResourceGroupName" = $ResourceGroupName;
"Name" = $ProjectName;
"ResourceGroupName" = $ResourceGroupName
} `
-ErrorMessage "Migrate project '$ProjectName' not found."
if ($migrateProject.Property.ProvisioningState -ne [ProvisioningState]::Succeeded) {
throw "Migrate project '$ProjectName' is not in a valid state. The provisioning state is '$($migrateProject.Property.ProvisioningState)'. Please verify your Azure Migrate project setup."
}

# Get Data Replication Service, or the AMH solution
$amhSolutionName = "Servers-Migration-ServerMigration_DataReplication"
$amhSolutionName = $AzMigrateSolutions.DataReplicationSolution
$amhSolution = InvokeAzMigrateGetCommandWithRetries `
-CommandName "Az.Migrate.private\Get-AzMigrateSolution_Get" `
-CommandName "Get-AzMigrateSolution" `
-Parameters @{
"SubscriptionId" = $SubscriptionId;
"ResourceGroupName" = $ResourceGroupName;
"MigrateProjectName" = $ProjectName;
"Name" = $amhSolutionName
"Name" = $amhSolutionName;
} `
-ErrorMessage "No Data Replication Service Solution '$amhSolutionName' found. Please verify your appliance setup."

Expand All @@ -215,14 +216,14 @@ function Initialize-AzMigrateLocalReplicationInfrastructure {
-ErrorMessage "No Replication Vault '$replicationVaultName' found in Resource Group '$ResourceGroupName'. Please verify your Azure Migrate project setup"

# Access Discovery Service
$discoverySolutionName = "Servers-Discovery-ServerDiscovery"
$discoverySolutionName = $AzMigrateSolutions.DiscoverySolution
$discoverySolution = InvokeAzMigrateGetCommandWithRetries `
-CommandName "Az.Migrate.private\Get-AzMigrateSolution_Get" `
-CommandName "Get-AzMigrateSolution" `
-Parameters @{
"SubscriptionId" = $SubscriptionId;
"ResourceGroupName" = $ResourceGroupName;
"MigrateProjectName" = $ProjectName;
"Name" = $discoverySolutionName
"Name" = $discoverySolutionName;
} `
-ErrorMessage "Server Discovery Solution '$discoverySolutionName' not found."

Expand Down Expand Up @@ -268,10 +269,13 @@ function Initialize-AzMigrateLocalReplicationInfrastructure {
}

# Get healthy asrv2 fabrics in the resource group
$allFabrics = Az.Migrate.private\Get-AzMigrateLocalReplicationFabric_List1 -ResourceGroupName $ResourceGroupName | Where-Object {
$_.Property.ProvisioningState -eq [ProvisioningState]::Succeeded -and
$_.Property.CustomProperty.MigrationSolutionId -eq $amhSolution.Id
}
$allFabrics = Az.Migrate.private\Get-AzMigrateLocalReplicationFabric_List1 `
-ResourceGroupName $ResourceGroupName `
-SubscriptionId $SubscriptionId `
| Where-Object {
$_.Property.ProvisioningState -eq [ProvisioningState]::Succeeded -and
$_.Property.CustomProperty.MigrationSolutionId -eq $amhSolution.Id
}

# Filter for source fabric
$sourceFabric = $allFabrics | Where-Object {
Expand All @@ -290,8 +294,9 @@ function Initialize-AzMigrateLocalReplicationInfrastructure {
$sourceDras = InvokeAzMigrateGetCommandWithRetries `
-CommandName 'Az.Migrate.Internal\Get-AzMigrateFabricAgent' `
-Parameters @{
SubscriptionId = $SubscriptionId;
ResourceGroupName = $ResourceGroupName;
FabricName = $sourceFabric.Name;
ResourceGroupName = $ResourceGroupName
} `
-ErrorMessage $sourceDraErrorMessage
$sourceDra = $sourceDras | Where-Object {
Expand Down Expand Up @@ -326,7 +331,8 @@ function Initialize-AzMigrateLocalReplicationInfrastructure {
-CommandName 'Az.Migrate.Internal\Get-AzMigrateFabricAgent' `
-Parameters @{
FabricName = $($targetFabric.Name);
ResourceGroupName = $ResourceGroupName
ResourceGroupName = $ResourceGroupName;
SubscriptionId = $SubscriptionId;
} `
-ErrorMessage $targetDraErrorMessage
$targetDra = $targetDras | Where-Object {
Expand Down Expand Up @@ -543,12 +549,12 @@ function Initialize-AzMigrateLocalReplicationInfrastructure {

# Put Cache Storage Account
$amhSolution = InvokeAzMigrateGetCommandWithRetries `
-CommandName "Az.Migrate.private\Get-AzMigrateSolution_Get" `
-CommandName "Get-AzMigrateSolution" `
-Parameters @{
"SubscriptionId" = $SubscriptionId;
"ResourceGroupName" = $ResourceGroupName;
"MigrateProjectName" = $ProjectName;
"Name" = $amhSolutionName
"Name" = $amhSolutionName;
} `
-ErrorMessage "No Data Replication Service Solution '$amhSolutionName' found. Please verify your appliance setup."

Expand Down Expand Up @@ -635,12 +641,12 @@ function Initialize-AzMigrateLocalReplicationInfrastructure {
}

$amhSolution = InvokeAzMigrateGetCommandWithRetries `
-CommandName "Az.Migrate.private\Get-AzMigrateSolution_Get" `
-CommandName "Get-AzMigrateSolution" `
-Parameters @{
"SubscriptionId" = $SubscriptionId;
"ResourceGroupName" = $ResourceGroupName;
"MigrateProjectName" = $ProjectName;
"Name" = $amhSolutionName
"Name" = $amhSolutionName;
} `
-ErrorMessage "No Data Replication Service Solution '$amhSolutionName' found. Please verify your appliance setup."
# Check if AMH record is removed
Expand Down Expand Up @@ -926,12 +932,12 @@ function Initialize-AzMigrateLocalReplicationInfrastructure {
}

$amhSolution = InvokeAzMigrateGetCommandWithRetries `
-CommandName "Az.Migrate.private\Get-AzMigrateSolution_Get" `
-CommandName "Get-AzMigrateSolution" `
-Parameters @{
"SubscriptionId" = $SubscriptionId;
"ResourceGroupName" = $ResourceGroupName;
"MigrateProjectName" = $ProjectName;
"Name" = $amhSolutionName
"Name" = $amhSolutionName;
} `
-ErrorMessage "No Data Replication Service Solution '$amhSolutionName' found. Please verify your appliance setup."
if ($amhSolution.DetailExtendedDetail.ContainsKey("replicationStorageAccountId")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,9 @@ function New-AzMigrateLocalServerReplication {

# Get VMware site
$siteObject = InvokeAzMigrateGetCommandWithRetries `
-CommandName 'Az.Migrate.private\Get-AzMigrateSite_Get' `
-CommandName 'Get-AzMigrateSite' `
-Parameters @{
'SubscriptionId' = $SubscriptionId;
'ResourceGroupName' = $ResourceGroupName;
'SiteName' = $SiteName;
} `
Expand Down Expand Up @@ -351,13 +352,14 @@ function New-AzMigrateLocalServerReplication {
$ProjectName = $siteObject.DiscoverySolutionId.Split("/")[8]

# Get Data Replication Service, or the AMH solution
$amhSolutionName = "Servers-Migration-ServerMigration_DataReplication"
$amhSolutionName = $AzMigrateSolutions.DataReplicationSolution
$amhSolution = InvokeAzMigrateGetCommandWithRetries `
-CommandName 'Az.Migrate.private\Get-AzMigrateSolution_Get' `
-CommandName 'Get-AzMigrateSolution' `
-Parameters @{
"ResourceGroupName" = $ResourceGroupName;
"Name" = $amhSolutionName;
"MigrateProjectName" = $ProjectName;
"SubscriptionId" = $SubscriptionId
} `
-ErrorMessage "No Data Replication Service Solution '$amhSolutionName' found in resource group '$ResourceGroupName' and project '$ProjectName'. Please verify your appliance setup."

Expand All @@ -378,9 +380,9 @@ function New-AzMigrateLocalServerReplication {
}

# Access Discovery Service
$discoverySolutionName = "Servers-Discovery-ServerDiscovery"
$discoverySolutionName = $AzMigrateSolutions.DiscoverySolution
$discoverySolution = InvokeAzMigrateGetCommandWithRetries `
-CommandName "Az.Migrate.private\Get-AzMigrateSolution_Get" `
-CommandName "Get-AzMigrateSolution" `
-Parameters @{
"SubscriptionId" = $SubscriptionId;
"ResourceGroupName" = $ResourceGroupName;
Expand Down Expand Up @@ -424,10 +426,13 @@ function New-AzMigrateLocalServerReplication {
}

# Get healthy asrv2 fabrics in the resource group
$allFabrics = Az.Migrate.private\Get-AzMigrateLocalReplicationFabric_List1 -ResourceGroupName $ResourceGroupName | Where-Object {
$_.Property.ProvisioningState -eq [ProvisioningState]::Succeeded -and
$_.Property.CustomProperty.MigrationSolutionId -eq $amhSolution.Id
}
$allFabrics = Az.Migrate.private\Get-AzMigrateLocalReplicationFabric_List1 `
-ResourceGroupName $ResourceGroupName `
-SubscriptionId $SubscriptionId `
| Where-Object {
$_.Property.ProvisioningState -eq [ProvisioningState]::Succeeded -and
$_.Property.CustomProperty.MigrationSolutionId -eq $amhSolution.Id
}

# Filter for source fabric
if ($instanceType -eq $AzLocalInstanceTypes.HyperVToAzLocal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,12 @@ function Remove-AzMigrateLocalServerReplication {
$null = $PSBoundParameters.Add("VaultName", $vaultName)
$null = $PSBoundParameters.Add("Name", $protectedItemName)

$ProtectedItem = InvokeAzMigrateGetCommandWithRetries `
-CommandName 'Az.Migrate.Internal\Get-AzMigrateProtectedItem' `
-Parameters $PSBoundParameters `
-ErrorMessage "Replication item is not found with Id '$TargetObjectID'."
$ProtectedItem = Az.Migrate.Internal\Get-AzMigrateProtectedItem @PSBoundParameters `
-ErrorVariable notPresent `
-ErrorAction SilentlyContinue
if ($null -eq $ProtectedItem) {
throw "Replication item is not found with Id '$TargetObjectID'. Re-run this command if exists."
}

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

Expand Down
Loading
Loading