Skip to content

Commit 33caba3

Browse files
Merge pull request #72 from sandeepsnairms/main
Option to remove Mongo Dump from Drop Down + Increase Page Size limit
2 parents b27a3f8 + a1a4383 commit 33caba3

File tree

8 files changed

+116
-7
lines changed

8 files changed

+116
-7
lines changed

MongoMigrationWebApp/Components/MigrationDetails.razor

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
@inject Service.JobManager JobManager
2+
@inject IConfiguration Configuration
3+
24
@using OnlineMongoMigrationProcessor
35

46
<div class="modal fade show d-block bg-dark bg-opacity-75" id="myModal" aria-modal="true" role="dialog">
@@ -18,7 +20,10 @@
1820
<div class="mb-3">
1921
<label for="mongo-options">Data Migration Tool:</label>
2022
<select id="mongo-options" @onchange="OnSelectionChanged" >
21-
<option value="Use MongoDump and MongoRestore">Use MongoDump and MongoRestore</option>
23+
@if (AllowMongoDump)
24+
{
25+
<option value="Use MongoDump and MongoRestore">Use MongoDump and MongoRestore</option>
26+
}
2227
<option value="Use Mongo Driver">Use Mongo Driver</option>
2328
</select>
2429
</div>
@@ -98,7 +103,8 @@
98103
private string errorMessage = string.Empty;
99104
private bool useMongoDump = true; // Variable to track the selected value
100105
private string selectedOption = "Use MongoDump and MongoRestore"; // Default dropdown value
101-
private bool isSimulatedRun = false; // Variable to track the dummy run option
106+
private bool isSimulatedRun = false; // Variable to track the dummy run option
107+
private bool AllowMongoDump => Configuration.GetValue<bool>("AllowMongoDump");
102108

103109
private void OnSelectionChanged(ChangeEventArgs e)
104110
{

MongoMigrationWebApp/Components/MigrationSettings.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@
5757

5858
private void HandleSubmit()
5959
{
60-
if (configuration.MongoCopyPageSize < 50 || configuration.MongoCopyPageSize > 10000)
60+
if (configuration.MongoCopyPageSize < 50 || configuration.MongoCopyPageSize > 20000)
6161
{
62-
errorMessage = "Page Size should be between 50 and 10000.";
62+
errorMessage = "Page Size should be between 50 and 20000.";
6363
return;
6464
}
6565

MongoMigrationWebApp/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
builder.Services.AddRazorPages();
2828
builder.Services.AddServerSideBlazor();
29+
builder.Services.AddSingleton(builder.Configuration);
2930
builder.Services.AddSingleton<JobManager>();
3031
builder.Services.AddScoped<FileService>();
3132

MongoMigrationWebApp/Shared/MainLayout.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<main>
77
<div class="top-row px-4 d-flex justify-content-between align-items-center">
88
<h2 class="text-left">Migrate to Azure Cosmos DB for MongoDB (vCore based)</h2>
9-
<div class="ms-2 small">v0.7.11</div>
9+
<div class="ms-2 small">v0.7.13</div>
1010
</div>
1111

1212
<article class="content px-4">

MongoMigrationWebApp/appsettings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
}
77
},
88
"AllowedHosts": "*",
9-
"DetailedErrors": true
9+
"DetailedErrors": true,
10+
"AllowMongoDump": true
1011
}

MongoMigrationWebApp/readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Version: 0.7.10
1+
Version: 0.7.13
22
Instructions: https://github.com/AzureCosmosDB/MongoMigrationWebBasedUtility
33
Purpose: An online and offline migration utility designed to migrate any MongoDB source to Azure Cosmos DB for Mongo vCore. It operates as an Azure Web App (or on-premises) and offers multiple methods for data migration. It can either use mongodump and mongorestore for data movement or employ the MongoDB driver to read data from the source and write it

publish_code.ps1

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
param (
2+
[bool]$SupportMongoDump = $true
3+
)
4+
5+
# Variables to be replaced
6+
$resourceGroupName = "<Replace with Existing Resource Group Name>"
7+
$webAppName = "<Replace with WebApp Name>"
8+
$projectFolderPath = Get-Location
9+
10+
11+
# Paths - No changes required
12+
$projectFilePath = Join-Path $projectFolderPath "MongoMigrationWebApp\MongoMigrationWebApp.csproj"
13+
$publishFolder = Join-Path $projectFolderPath "publish"
14+
$zipPath = Join-Path $publishFolder "app.zip"
15+
16+
# Delete the existing publish folder (if exist)
17+
if (Test-Path $publishFolder) {
18+
Remove-Item -Path $publishFolder -Recurse -Force -Confirm:$false
19+
}
20+
21+
# Build the Blazor app
22+
Write-Host "Building Blazor app..."
23+
dotnet publish $projectFilePath -c Release -o $publishFolder -warnaserror:none --nologo
24+
25+
# Modify appsettings.json if SupportMongoDump is false
26+
if (-not $SupportMongoDump) {
27+
$appSettingsPath = Join-Path $publishFolder "appsettings.json"
28+
if (Test-Path $appSettingsPath) {
29+
$json = Get-Content $appSettingsPath -Raw | ConvertFrom-Json
30+
$json.AllowMongoDump = $false
31+
$json | ConvertTo-Json -Depth 10 | Set-Content -Path $appSettingsPath -Encoding UTF8
32+
Write-Host "Set AllowMongoDump to false in appsettings.json"
33+
} else {
34+
Write-Warning "appsettings.json not found at $appSettingsPath"
35+
}
36+
}
37+
38+
# Delete the existing zip file if it exists
39+
if (Test-Path $zipPath) {
40+
Remove-Item $zipPath -Force
41+
}
42+
43+
# Archive published files
44+
Compress-Archive -Path "$publishFolder\*" -DestinationPath $zipPath -Update
45+
46+
# Deploy files to Azure Web App
47+
Write-Host "Deploying to Azure Web App..."
48+
az webapp deploy --resource-group $resourceGroupName --name $webAppName --src-path $zipPath --type zip

publish_zip.ps1

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
param (
2+
[string]$resourceGroupName = "<Replace with Existing Resource Group Name>",
3+
[string]$webAppName = "<Replace with Web App Name>",
4+
[string]$zipFileName = "app.zip",
5+
[bool]$SupportMongoDump = $true
6+
)
7+
8+
# Calculate full zip path based on current folder
9+
$workingFolder = Get-Location
10+
$zipPath = Join-Path $workingFolder $zipFileName
11+
12+
# Login to Azure
13+
#az login
14+
15+
# Set subscription (optional)
16+
# az account set --subscription "your-subscription-id"
17+
18+
# If MongoDump is not supported, extract and modify the zip contents
19+
if (-not $SupportMongoDump) {
20+
$tempFolder = Join-Path $workingFolder "TempAppDeploy"
21+
22+
if (Test-Path $tempFolder) {
23+
Remove-Item -Path $tempFolder -Recurse -Force
24+
}
25+
New-Item -ItemType Directory -Path $tempFolder | Out-Null
26+
27+
# Extract the zip
28+
Expand-Archive -Path $zipPath -DestinationPath $tempFolder -Force
29+
30+
# Modify appsettings.json
31+
$appSettingsPath = Join-Path $tempFolder "appsettings.json"
32+
if (Test-Path $appSettingsPath) {
33+
$json = Get-Content $appSettingsPath -Raw | ConvertFrom-Json
34+
$json.AllowMongoDump = $false
35+
$json | ConvertTo-Json -Depth 10 | Set-Content -Path $appSettingsPath -Encoding UTF8
36+
Write-Host "Set AllowMongoDump to false in appsettings.json"
37+
} else {
38+
Write-Warning "appsettings.json not found at $appSettingsPath"
39+
}
40+
41+
# Recreate the zip
42+
Remove-Item $zipPath -Force
43+
Compress-Archive -Path "$tempFolder\*" -DestinationPath $zipPath
44+
45+
# Optionally clean up temp folder
46+
Remove-Item -Path $tempFolder -Recurse -Force
47+
}
48+
49+
# Deploy zip contents to Azure Web App
50+
Write-Host "Deploying to Azure Web App..."
51+
az webapp deploy --resource-group $resourceGroupName --name $webAppName --src-path $zipPath --type zip
52+
53+
Write-Host "Deployment completed successfully!"

0 commit comments

Comments
 (0)