Improve connection validation messages

This commit is contained in:
Kranthi Kumar Medam 2019-01-12 21:19:54 +05:30
Родитель 99e14e60d9
Коммит 34eb31b688
14 изменённых файлов: 315 добавлений и 240 удалений

Просмотреть файл

@ -75,15 +75,6 @@ namespace CloneConsoleRun
//var result = tcs.StartScrub(scrubRules);
}
public static async Task TestCollections()
{
logger.LogInfo("TestConnections");
var dbhelper = new CosmosDBHelper();
var vResult = await dbhelper.TestSourceConnection();
var vResult2 = await dbhelper.TestTargetConnection();
}
}
}

Просмотреть файл

@ -26,7 +26,7 @@
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="20,20,0,0">
<CheckBox x:Name="Triggers" VerticalAlignment="Center" IsChecked="True"/>
<CheckBox x:Name="CosmosTriggers" VerticalAlignment="Center" IsChecked="True"/>
<TextBlock Text="Triggers" FontSize="15" VerticalAlignment="Center" Margin="10,0,0,0"/>
</StackPanel>

Просмотреть файл

@ -56,10 +56,16 @@
<ManifestKeyFile>CosmicCloneUI_TemporaryKey.pfx</ManifestKeyFile>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>true</GenerateManifests>
<GenerateManifests>false</GenerateManifests>
</PropertyGroup>
<PropertyGroup>
<SignManifests>true</SignManifests>
<SignManifests>false</SignManifests>
</PropertyGroup>
<PropertyGroup>
<TargetZone>LocalIntranet</TargetZone>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>Properties\app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
@ -154,6 +160,7 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="App.config" />
<None Include="Properties\app.manifest" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>

Просмотреть файл

@ -40,6 +40,7 @@
</StackPanel>
</Button>
</StackPanel>
<TextBlock Name="ConnectionTestMsg" TextWrapping="Wrap" Text="" Height="35" Margin="100,10,100,5"/>
</StackPanel>
</Grid>
</Page>

Просмотреть файл

@ -33,20 +33,12 @@ namespace CosmicCloneUI
private void BtnTestTarget(object sender, RoutedEventArgs e)
{
if (TestConnection())
{
var connectionIcon = (Image)this.FindName("ConnectionIcon");
ConnectionIcon.Source = new BitmapImage(new Uri("/Images/success.png", UriKind.Relative));
}
else
{
var connectionIcon = (Image)this.FindName("ConnectionIcon");
ConnectionIcon.Source = new BitmapImage(new Uri("/Images/fail.png", UriKind.Relative));
}
TestDestinationConnection();
}
private bool TestConnection()
public bool TestDestinationConnection()
{
ConnectionTestMsg.Text = "";
CloneSettings.TargetSettings = new CosmosCollectionValues()
{
EndpointUrl = TargetURL.Text.ToString(),
@ -55,11 +47,20 @@ namespace CosmicCloneUI
CollectionName = TargetCollection.Text.ToString()
};
var result = cosmosHelper.TestTargetConnection_v2();
if (result.IsSuccess == true)
return true;
var result = cosmosHelper.TestTargetConnection();
if (result.IsSuccess)
{
var connectionIcon = (Image)this.FindName("ConnectionIcon");
ConnectionIcon.Source = new BitmapImage(new Uri("/Images/success.png", UriKind.Relative));
ConnectionTestMsg.Text = "Validation Passed";
}
else
return false;
{
var connectionIcon = (Image)this.FindName("ConnectionIcon");
ConnectionIcon.Source = new BitmapImage(new Uri("/Images/fail.png", UriKind.Relative));
ConnectionTestMsg.Text = result.Message;
}
return result.IsSuccess;
}
}
}

Просмотреть файл

@ -75,15 +75,15 @@ namespace CosmicCloneUI
private void BtnClickPrevious(object sender, RoutedEventArgs e)
{
Page currentPage = (Page)_mainFrame.Content;
_mainFrame.Navigate(getPreviousPage(currentPage));
_mainFrame.Navigate(GetPreviousPage(currentPage));
}
private void BtnClickNext(object sender, RoutedEventArgs e)
{
Page currentPage = (Page)_mainFrame.Content;
if(performAction(currentPage))
if(PerformAction(currentPage))
{
_mainFrame.Navigate(getNextPage(currentPage));
_mainFrame.Navigate(GetNextPage(currentPage));
}
}
@ -95,7 +95,7 @@ namespace CosmicCloneUI
private void NavigationHelper()
{
Page currentPage = (Page)_mainFrame.Content;
int pagenum = getPageNumber(currentPage);
int pagenum = GetPageNumber(currentPage);
if (pagenum == 0)
{
btn_previous.IsEnabled = false;
@ -116,17 +116,17 @@ namespace CosmicCloneUI
}
}
private Page getNextPage(Page currentPage)
private Page GetNextPage(Page currentPage)
{
return pages[getPageNumber(currentPage) + 1];
return pages[GetPageNumber(currentPage) + 1];
}
private Page getPreviousPage(Page currentPage)
private Page GetPreviousPage(Page currentPage)
{
return pages[getPageNumber(currentPage) - 1];
return pages[GetPageNumber(currentPage) - 1];
}
private int getPageNumber(Page page)
private int GetPageNumber(Page page)
{
for(int i=0;i<pages.Length;i++)
{
@ -143,82 +143,60 @@ namespace CosmicCloneUI
NavigationHelper();
}
private bool performAction(Page currentPage)
private bool PerformAction(Page currentPage)
{
if (getPageNumber(currentPage) == 0)
if (GetPageNumber(currentPage) == 0)
{
CloneSettings.SourceSettings = new CosmosCollectionValues()
{
EndpointUrl = ((TextBox)currentPage.FindName("SourceURL")).Text.ToString(),
AccessKey = ((TextBox)currentPage.FindName("SourceKey")).Text.ToString(),
DatabaseName = ((TextBox)currentPage.FindName("SourceDB")).Text.ToString(),
CollectionName = ((TextBox)currentPage.FindName("SourceCollection")).Text.ToString()
//OfferThroughputRUs = int.Parse(sourceConfigs["OfferThroughputRUs"])
};
var result = cosmosHelper.TestSourceConnection_v2();
if (result.IsSuccess == true)
return true;
else
return false;
var result = ((SourcePage)currentPage).TestSourceConnection();
return result;
}
else if (getPageNumber(currentPage) == 1)
else if (GetPageNumber(currentPage) == 1)
{
CloneSettings.TargetSettings = new CosmosCollectionValues()
{
EndpointUrl = ((TextBox)currentPage.FindName("TargetURL")).Text,
AccessKey = ((TextBox)currentPage.FindName("TargetKey")).Text,
DatabaseName = ((TextBox)currentPage.FindName("TargetDB")).Text,
CollectionName = ((TextBox)currentPage.FindName("TargetCollection")).Text
//OfferThroughputRUs = int.Parse(sourceConfigs["OfferThroughputRUs"])
};
var result = cosmosHelper.TestTargetConnection_v2();
if (result.IsSuccess == true)
return true;
else
return false;
var result = ((DestinationPage)currentPage).TestDestinationConnection();
return result;
}
else if (getPageNumber(currentPage) == 2)
else if (GetPageNumber(currentPage) == 2)
{
CloneSettings.CopyStoredProcedures = ((CheckBox)currentPage.FindName("SPs")).IsChecked.Value;
CloneSettings.CopyUDFs = ((CheckBox)currentPage.FindName("UDFs")).IsChecked.Value;
CloneSettings.CopyTriggers = ((CheckBox)currentPage.FindName("Triggers")).IsChecked.Value;
CloneSettings.CopyTriggers = ((CheckBox)currentPage.FindName("CosmosTriggers")).IsChecked.Value;
CloneSettings.CopyDocuments = ((CheckBox)currentPage.FindName("Documents")).IsChecked.Value;
CloneSettings.CopyIndexingPolicy = ((CheckBox)currentPage.FindName("IPs")).IsChecked.Value;
CloneSettings.CopyPartitionKey = ((CheckBox)currentPage.FindName("PKs")).IsChecked.Value;
return true;
}
else if (getPageNumber(currentPage) == 3)
else if (GetPageNumber(currentPage) == 3)
{
btn_finish.IsEnabled = false;
scrubRules = ((DataAnonymizationPage)currentPage).getScrubRules();
bool isValidationSuccess = ((DataAnonymizationPage)currentPage).validateInput();
if (!isValidationSuccess) return false;
BackgroundWorker worker = new BackgroundWorker();
worker.WorkerReportsProgress = true;
worker.DoWork += worker_DoWork;
worker.ProgressChanged += worker_ProgressChanged;
worker.RunWorkerCompleted += worker_RunWorkerCompleted;
BackgroundWorker worker = new BackgroundWorker
{
WorkerReportsProgress = true
};
worker.DoWork += Worker_DoWork;
worker.ProgressChanged += Worker_ProgressChanged;
worker.RunWorkerCompleted += Worker_RunWorkerCompleted;
worker.RunWorkerAsync(1000);
BackgroundWorker worker2 = new BackgroundWorker();
worker2.WorkerReportsProgress = true;
worker2.DoWork += worker_DoWork2;
worker2.ProgressChanged += worker_ProgressChanged2;
worker2.RunWorkerCompleted += worker_RunWorkerCompleted2;
BackgroundWorker worker2 = new BackgroundWorker
{
WorkerReportsProgress = true
};
worker2.DoWork += Worker_DoWork2;
worker2.ProgressChanged += Worker_ProgressChanged2;
worker2.RunWorkerCompleted += Worker_RunWorkerCompleted2;
worker2.RunWorkerAsync(1000);
var nextPage = getNextPage(currentPage);
var nextPage = GetNextPage(currentPage);
((CopyCollectionPage)nextPage).setRequiredprogressBars(scrubRules);
return true;
}
else if (getPageNumber(currentPage) == 4)
else if (GetPageNumber(currentPage) == 4)
{
btn_finish.IsEnabled = false;
((CopyCollectionPage)currentPage).setRequiredprogressBars(scrubRules);
@ -231,7 +209,7 @@ namespace CosmicCloneUI
}
void worker_DoWork(object sender, DoWorkEventArgs e)
void Worker_DoWork(object sender, DoWorkEventArgs e)
{
try
{
@ -252,18 +230,18 @@ namespace CosmicCloneUI
}
void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
void Worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
//((ProgressBar)pages[3].FindName("ReadProgress")).Value = e.ProgressPercentage;
}
void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
//MessageBox.Show("Document Collection Copied Successfully : ");
}
void worker_DoWork2(object sender, DoWorkEventArgs e)
void Worker_DoWork2(object sender, DoWorkEventArgs e)
{
long readPercentProgress = 0;
long writePercentProgress = 0;
@ -298,7 +276,7 @@ namespace CosmicCloneUI
Task.Delay(3000).Wait();
}
}
void worker_ProgressChanged2(object sender, ProgressChangedEventArgs e)
void Worker_ProgressChanged2(object sender, ProgressChangedEventArgs e)
{
int receivePercent = e.ProgressPercentage;
@ -315,7 +293,7 @@ namespace CosmicCloneUI
statustextbox.ScrollToEnd();
}
void worker_RunWorkerCompleted2(object sender, RunWorkerCompletedEventArgs e)
void Worker_RunWorkerCompleted2(object sender, RunWorkerCompletedEventArgs e)
{
while(!DocumentMigrator.IsCodeMigrationComplete)
{

Просмотреть файл

@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC Manifest Options
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
Specifying requestedExecutionLevel element will disable file and registry virtualization.
Remove this element if your application requires this virtualization for backwards
compatibility.
-->
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
<applicationRequestMinimum>
<PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true" ID="Custom" SameSite="site" />
<defaultAssemblyRequest permissionSetReference="Custom" />
</applicationRequestMinimum>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of the Windows versions that this application has been tested on and is
is designed to work with. Uncomment the appropriate elements and Windows will
automatically selected the most compatible environment. -->
<!-- Windows Vista -->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
<!-- Windows 7 -->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
<!-- Windows 8 -->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->
<!-- Windows 8.1 -->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
<!-- Windows 10 -->
<!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->
</application>
</compatibility>
<!-- Indicates that the application is DPI-aware and will not be automatically scaled by Windows at higher
DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need
to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should
also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config. -->
<!--
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
</windowsSettings>
</application>
-->
<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
<!--
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
-->
</assembly>

Просмотреть файл

@ -39,7 +39,9 @@
<TextBlock Text="Test Connection" VerticalAlignment="Center" Margin="5" />
</StackPanel>
</Button>
</StackPanel>
<TextBlock Name="ConnectionTestMsg" TextWrapping="Wrap" Text="" Height="35" Margin="100,10,100,5"/>
</StackPanel>
</Grid>
</Page>

Просмотреть файл

@ -30,20 +30,12 @@ namespace CosmicCloneUI
private void BtnTestSource(object sender, RoutedEventArgs e)
{
if (TestConnection())
{
var connectionIcon = (Image)this.FindName("ConnectionIcon");
ConnectionIcon.Source = new BitmapImage(new Uri("/Images/success.png", UriKind.Relative));
}
else
{
var connectionIcon = (Image)this.FindName("ConnectionIcon");
ConnectionIcon.Source = new BitmapImage(new Uri("/Images/fail.png", UriKind.Relative));
}
TestSourceConnection();
}
private bool TestConnection()
public bool TestSourceConnection()
{
ConnectionTestMsg.Text = "";
CloneSettings.SourceSettings = new CosmosCollectionValues()
{
EndpointUrl = SourceURL.Text.ToString(),
@ -52,11 +44,20 @@ namespace CosmicCloneUI
CollectionName = SourceCollection.Text.ToString()
};
var result = cosmosHelper.TestSourceConnection_v2();
if (result.IsSuccess == true)
return true;
var result = cosmosHelper.TestSourceConnection();
if (result.IsSuccess)
{
var connectionIcon = (Image)this.FindName("ConnectionIcon");
ConnectionIcon.Source = new BitmapImage(new Uri("/Images/success.png", UriKind.Relative));
ConnectionTestMsg.Text = "Validation Passed";
}
else
return false;
{
var connectionIcon = (Image)this.FindName("ConnectionIcon");
ConnectionIcon.Source = new BitmapImage(new Uri("/Images/fail.png", UriKind.Relative));
ConnectionTestMsg.Text = result.Message;
}
return result.IsSuccess;
}
}
}

Просмотреть файл

@ -79,6 +79,7 @@
<Compile Include="Model\ScrubRule.cs" />
<Compile Include="Model\Validationresult.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Sample\CosmosSampleDBHelper.cs" />
<Compile Include="Sample\EntityV2.cs" />
<Compile Include="Sample\Entity.cs" />
<Compile Include="Sample\SampleDBCreator.cs" />

Просмотреть файл

@ -87,17 +87,29 @@ namespace CosmosCloneCommon.Migrator
{
await ReadUploadInbatches((IDocumentQuery<dynamic>)SourceCommonDataFetchQuery);
}
IsCodeMigrationComplete = false;
if (CloneSettings.CopyStoredProcedures) { await CopyStoredProcedures(); }
if (CloneSettings.CopyUDFs) { await CopyUDFs(); }
if (CloneSettings.CopyTriggers) { await CopyTriggers(); }
IsCodeMigrationComplete = true;
else
{
//scrub documents for rules without filters(no where condition)
//This is also part of copy documents code hence this is included here when copydocuments is turned off
if (CloneSettings.ScrubbingRequired && noFilterScrubRules != null && noFilterScrubRules.Count > 0)
{
var dcs = new DataScrubMigrator();
var result = dcs.StartScrub(noFilterScrubRules);
}
}
if (CloneSettings.ScrubbingRequired && filteredScrubRules != null && filteredScrubRules.Count > 0)
{
var dcs = new DataScrubMigrator();
var result = dcs.StartScrub(filteredScrubRules);
}
IsCodeMigrationComplete = false;
if (CloneSettings.CopyStoredProcedures) { await CopyStoredProcedures(); }
if (CloneSettings.CopyUDFs) { await CopyUDFs(); }
if (CloneSettings.CopyTriggers) { await CopyTriggers(); }
IsCodeMigrationComplete = true;
return true;
}
public async Task InitializeMigration()
@ -208,7 +220,7 @@ namespace CosmosCloneCommon.Migrator
logger.LogInfo($"Total records retrieved {TotalRecordsRetrieved}. Total records uploaded {TotalRecordsSent}");
logger.LogInfo($"Time elapsed : {stopwatch.Elapsed} ");
}
setCompleteOnNoFilterRules();
SetCompleteOnNoFilterRules();
stopwatch.Stop();
logger.LogInfo("Document Migration completed");
}
@ -219,7 +231,7 @@ namespace CosmosCloneCommon.Migrator
//sourceCollection = await cosmosHelper.GetSourceDocumentCollection(sourceClient);
var setCorrect = await cosmosHelper.SetTargetRestOfferThroughPut();
}
public bool setCompleteOnNoFilterRules()
public bool SetCompleteOnNoFilterRules()
{
if (scrubRules != null && scrubRules.Count > 0)
{

Просмотреть файл

@ -0,0 +1,132 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.Documents.Client;
using Microsoft.Azure.Documents;
using CosmosCloneCommon.Model;
using logger = CosmosCloneCommon.Utility.CloneLogger;
using CosmosCloneCommon.Utility;
namespace CosmosCloneCommon.Sample
{
public class CosmosSampleDBHelper
{
private ConnectionPolicy ConnectionPolicy;
public CosmosSampleDBHelper()
{
ConnectionPolicy = new ConnectionPolicy
{
ConnectionMode = ConnectionMode.Direct,
ConnectionProtocol = Protocol.Tcp,
RetryOptions = new RetryOptions()
};
this.ConnectionPolicy.RetryOptions.MaxRetryAttemptsOnThrottledRequests = 20;
this.ConnectionPolicy.RetryOptions.MaxRetryWaitTimeInSeconds = 600;
}
public DocumentClient GetSampleDocumentDbClient()
{
try
{
var SourceCosmosDBSettings = CloneSettings.GetConfigurationSection("SampleCosmosDBSettings");
string SourceEndpointUrl = SourceCosmosDBSettings["EndpointUrl"];
string SourceAccessKey = SourceCosmosDBSettings["AccessKey"];
var sourceDocumentClient = new DocumentClient(new Uri(SourceEndpointUrl), SourceAccessKey, ConnectionPolicy);
return sourceDocumentClient;
}
catch (Exception ex)
{
logger.LogError(ex);
throw;
}
}
public async Task<DocumentCollection> CreateSampleDocumentCollection(DocumentClient sampleClient, bool IsFixedCollection = false)
{
try
{
var sampleCosmosDBSettings = CloneSettings.GetConfigurationSection("SampleCosmosDBSettings");
string sampleDatabaseName = sampleCosmosDBSettings["DatabaseName"]; ;
string sampleCollectionName = sampleCosmosDBSettings["CollectionName"];
int offerThroughput = 1000;
int.TryParse(sampleCosmosDBSettings["OfferThroughputRUs"], out offerThroughput);
await sampleClient.CreateDatabaseIfNotExistsAsync(new Database { Id = sampleDatabaseName });
DocumentCollection newDocumentCollection;
if (!IsFixedCollection)
{
var partitionKeyDefinition = new PartitionKeyDefinition();
partitionKeyDefinition.Paths.Add("/CompositeName");
newDocumentCollection = (DocumentCollection)await sampleClient.CreateDocumentCollectionIfNotExistsAsync
(UriFactory.CreateDatabaseUri(sampleDatabaseName),
new DocumentCollection { Id = sampleCollectionName, PartitionKey = partitionKeyDefinition },
new RequestOptions { OfferThroughput = offerThroughput });
}
else
{
//no partition key if it is a fixed collection
newDocumentCollection = (DocumentCollection)await sampleClient.CreateDocumentCollectionIfNotExistsAsync
(UriFactory.CreateDatabaseUri(sampleDatabaseName),
new DocumentCollection { Id = sampleCollectionName},
new RequestOptions { OfferThroughput = offerThroughput });
}
return newDocumentCollection;
}
catch (Exception ex)
{
logger.LogError(ex);
throw;
}
}
public async Task<DocumentCollection> CreateTargetDocumentCollection(DocumentClient targetClient, IndexingPolicy indexingPolicy, PartitionKeyDefinition partitionKeyDefinition)
{
try
{
//var targetCosmosDBSettings = CloneSettings.GetConfigurationSection("TargetCosmosDBSettings");
string targetDatabaseName = CloneSettings.TargetSettings.DatabaseName;
string targetCollectionName = CloneSettings.TargetSettings.CollectionName;
await targetClient.CreateDatabaseIfNotExistsAsync(new Database { Id = targetDatabaseName });
DocumentCollection newDocumentCollection;
if (partitionKeyDefinition != null && partitionKeyDefinition.Paths.Count>0)
{
if(CloneSettings.CopyPartitionKey)
{
// Partition key exists in Source (Unlimited Storage)
newDocumentCollection = (DocumentCollection)await targetClient.CreateDocumentCollectionIfNotExistsAsync
(UriFactory.CreateDatabaseUri(targetDatabaseName),
new DocumentCollection { Id = targetCollectionName, PartitionKey = partitionKeyDefinition, IndexingPolicy = indexingPolicy },
new RequestOptions { OfferEnableRUPerMinuteThroughput = true, OfferThroughput = CloneSettings.TargetMigrationOfferThroughputRUs });
}
else
{
newDocumentCollection = (DocumentCollection)await targetClient.CreateDocumentCollectionIfNotExistsAsync
(UriFactory.CreateDatabaseUri(targetDatabaseName),
new DocumentCollection { Id = targetCollectionName, IndexingPolicy = indexingPolicy },
new RequestOptions { OfferEnableRUPerMinuteThroughput = true, OfferThroughput = CloneSettings.TargetMigrationOfferThroughputRUs });
}
}
else
{ //no partition key set in source (Fixed storage)
newDocumentCollection = (DocumentCollection)await targetClient.CreateDocumentCollectionIfNotExistsAsync
(UriFactory.CreateDatabaseUri(targetDatabaseName),
new DocumentCollection { Id = targetCollectionName, IndexingPolicy = indexingPolicy },
new RequestOptions { OfferEnableRUPerMinuteThroughput = true, OfferThroughput = CloneSettings.TargetMigrationOfferThroughputRUs });
}
logger.LogInfo($"SuccessFully Created Target. Database: {targetDatabaseName} Collection:{targetCollectionName}");
return newDocumentCollection;
}
catch (Exception ex)
{
logger.LogError(ex);
throw;
}
}
}
}

Просмотреть файл

@ -26,7 +26,7 @@ namespace CosmosCloneCommon.Sample
protected int ReadDelaybetweenRequestsInMs = 2000;
protected int maxtestDocumentCount = 50000;
protected bool IsFixedCollection = true;
protected CosmosDBHelper cosmosHelper;
protected CosmosSampleDBHelper cosmosHelper;
protected CosmosBulkImporter cosmosBulkImporter;
protected DocumentClient sampleClient;
protected DocumentCollection sampleCollection;
@ -34,7 +34,7 @@ namespace CosmosCloneCommon.Sample
public SampleDBCreator()
{
cosmosHelper = new CosmosDBHelper();
cosmosHelper = new CosmosSampleDBHelper();
cosmosBulkImporter = new CosmosBulkImporter();
}

Просмотреть файл

@ -30,41 +30,7 @@ namespace CosmosCloneCommon.Utility
this.ConnectionPolicy.RetryOptions.MaxRetryWaitTimeInSeconds = 600;
}
public async Task<ValidationResult> TestSourceConnection()
{
var result = new ValidationResult();
DocumentClient sourceDocumentClient;
try
{
sourceDocumentClient = new DocumentClient(new Uri(CloneSettings.SourceSettings.EndpointUrl), CloneSettings.SourceSettings.AccessKey, ConnectionPolicy);
}
catch (Exception ex)
{
logger.LogError(ex);
result.IsSuccess = false;
result.Message = "Unable to connect to Source. Check your input url and key are accurate. If Firewall security is enabled for your database please add the ip address of the current machine.";
return result;
}
try
{
var cosmosDBURI = UriFactory.CreateDocumentCollectionUri(CloneSettings.SourceSettings.DatabaseName, CloneSettings.SourceSettings.CollectionName);
//var sourceDatabase = await sourceDocumentClient.ReadDatabaseAsync(Database);
var sourceCollection = await sourceDocumentClient.ReadDocumentCollectionAsync(cosmosDBURI);
}
catch (Exception ex)
{
logger.LogError(ex);
result.IsSuccess = false;
result.Message = "Incorrect DatabaseName or Collection. Check your input DatabaseName and Collection are accurate.";
return result;
}
result.IsSuccess = true;
result.Message = "OK";
return result;
}
public ValidationResult TestSourceConnection_v2()
public ValidationResult TestSourceConnection()
{
var result = new ValidationResult();
DocumentClient sourceDocumentClient;
@ -98,40 +64,7 @@ namespace CosmosCloneCommon.Utility
return result;
}
public async Task<ValidationResult> TestTargetConnection()
{
var result = new ValidationResult();
DocumentClient targetDocumentClient;
try
{
targetDocumentClient = new DocumentClient(new Uri(CloneSettings.TargetSettings.EndpointUrl), CloneSettings.TargetSettings.AccessKey, ConnectionPolicy);
}
catch (Exception ex)
{
logger.LogError(ex);
result.IsSuccess = false;
result.Message = "Unable to connect to Target. Check your input url and key are accurate. If Firewall security is enabled for your database please add the ip address of the current machine.";
return result;
}
try
{
var cosmosDBURI = UriFactory.CreateDatabaseUri(CloneSettings.TargetSettings.DatabaseName);
var sourceDatabase = await targetDocumentClient.ReadDatabaseAsync(cosmosDBURI);
}
catch (Exception ex)
{
logger.LogError(ex);
result.IsSuccess = false;
result.Message = "Incorrect DatabaseName .Check whether the input DatabaseName is accurate.";
return result;
}
result.IsSuccess = true;
result.Message = "OK";
return result;
}
public ValidationResult TestTargetConnection_v2()
public ValidationResult TestTargetConnection()
{
var result = new ValidationResult();
DocumentClient targetDocumentClient;
@ -197,24 +130,7 @@ namespace CosmosCloneCommon.Utility
throw;
}
}
public DocumentClient GetSampleDocumentDbClient()
{
try
{
var SourceCosmosDBSettings = CloneSettings.GetConfigurationSection("SampleCosmosDBSettings");
string SourceEndpointUrl = SourceCosmosDBSettings["EndpointUrl"];
string SourceAccessKey = SourceCosmosDBSettings["AccessKey"];
var sourceDocumentClient = new DocumentClient(new Uri(SourceEndpointUrl), SourceAccessKey, ConnectionPolicy);
return sourceDocumentClient;
}
catch (Exception ex)
{
logger.LogError(ex);
throw;
}
}
public async Task<DocumentCollection> GetTargetDocumentCollection(DocumentClient targetClient)
{
try
@ -279,43 +195,6 @@ namespace CosmosCloneCommon.Utility
}
}
public async Task<DocumentCollection> CreateSampleDocumentCollection(DocumentClient sampleClient, bool IsFixedCollection = false)
{
try
{
var sampleCosmosDBSettings = CloneSettings.GetConfigurationSection("SampleCosmosDBSettings");
string sampleDatabaseName = sampleCosmosDBSettings["DatabaseName"]; ;
string sampleCollectionName = sampleCosmosDBSettings["CollectionName"];
int offerThroughput = 1000;
int.TryParse(sampleCosmosDBSettings["OfferThroughputRUs"], out offerThroughput);
await sampleClient.CreateDatabaseIfNotExistsAsync(new Database { Id = sampleDatabaseName });
DocumentCollection newDocumentCollection;
if (!IsFixedCollection)
{
var partitionKeyDefinition = new PartitionKeyDefinition();
partitionKeyDefinition.Paths.Add("/CompositeName");
newDocumentCollection = (DocumentCollection)await sampleClient.CreateDocumentCollectionIfNotExistsAsync
(UriFactory.CreateDatabaseUri(sampleDatabaseName),
new DocumentCollection { Id = sampleCollectionName, PartitionKey = partitionKeyDefinition },
new RequestOptions { OfferThroughput = offerThroughput });
}
else
{
//no partition key if it is a fixed collection
newDocumentCollection = (DocumentCollection)await sampleClient.CreateDocumentCollectionIfNotExistsAsync
(UriFactory.CreateDatabaseUri(sampleDatabaseName),
new DocumentCollection { Id = sampleCollectionName},
new RequestOptions { OfferThroughput = offerThroughput });
}
return newDocumentCollection;
}
catch (Exception ex)
{
logger.LogError(ex);
throw;
}
}
public async Task<DocumentCollection> CreateTargetDocumentCollection(DocumentClient targetClient, IndexingPolicy indexingPolicy, PartitionKeyDefinition partitionKeyDefinition)
{
try