Skip to content

Commit

Permalink
Merge pull request #8 from alexdrenea/feature/offer-throughput
Browse files Browse the repository at this point in the history
Fix for issue #7 - respect offer throughput for target collection
  • Loading branch information
kranthimeda authored Jul 31, 2019
2 parents 019a668 + d3cc923 commit ffe7b5d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CosmosClone/CosmicCloneUI/CloneOptionsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@
<TextBlock Text="Offer Throughput" Style="{StaticResource TextBlockStyle}"/>
<TextBox x:Name="OfferThroughput" Text="10000" Style="{StaticResource TextBoxStyle}" VerticalAlignment="Top"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Image x:Name="ConnectionIcon" Width="30" Height="30"/>
<TextBlock Name="ConnectionTestMsg" TextWrapping="Wrap" />
</StackPanel>
</StackPanel>
</Page>
26 changes: 26 additions & 0 deletions CosmosClone/CosmicCloneUI/CloneOptionsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,31 @@ public CloneOptionsPage()
{
InitializeComponent();
}


public bool TestCloneOptions()
{
var result = true;
if (!int.TryParse(OfferThroughput.Text, out int RU))
result = false;

if (RU < 400) result = false;
if (RU % 100 != 0) result = false;

if (result)
{
var connectionIcon = (Image)this.FindName("ConnectionIcon");
ConnectionIcon.Source = new BitmapImage(new Uri("/Images/success.png", UriKind.Relative));
ConnectionTestMsg.Text = "Validation Passed";
}
else
{
var connectionIcon = (Image)this.FindName("ConnectionIcon");
ConnectionIcon.Source = new BitmapImage(new Uri("/Images/fail.png", UriKind.Relative));
ConnectionTestMsg.Text = "Invalid Throughput provided. Make sure it's a number greater than 400 and multiple of 100.";
}

return result;
}
}
}
17 changes: 11 additions & 6 deletions CosmosClone/CosmicCloneUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,17 @@ private bool PerformAction(Page currentPage)
}
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("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;
var page = ((CloneOptionsPage)currentPage);
var valid = page.TestCloneOptions();
if (!valid) return false;

CloneSettings.CopyStoredProcedures = page.SPs.IsChecked.Value;
CloneSettings.CopyUDFs = page.UDFs.IsChecked.Value;
CloneSettings.CopyTriggers = page.CosmosTriggers.IsChecked.Value;
CloneSettings.CopyDocuments = page.Documents.IsChecked.Value;
CloneSettings.CopyIndexingPolicy = page.IPs.IsChecked.Value;
CloneSettings.CopyPartitionKey = page.PKs.IsChecked.Value;
CloneSettings.TargetMigrationOfferThroughputRUs = int.Parse(page.OfferThroughput.Text);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace CosmosCloneCommon.Model

public static class RandomNumberGenerator
{
private static readonly Random _random = new Random(unchecked(Environment.TickCount * 31 + Thread.CurrentThread.ManagedThreadId));;
private static readonly Random _random = new Random(unchecked(Environment.TickCount * 31 + Thread.CurrentThread.ManagedThreadId));

public static int GetNext(int maxValue)
{
Expand Down
6 changes: 3 additions & 3 deletions CosmosClone/CosmosCloneCommon/Utility/CloneSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ static CloneSettings()
EndpointUrl = targetConfigs["EndpointUrl"],
AccessKey = targetConfigs["AccessKey"],
DatabaseName = targetConfigs["DatabaseName"],
CollectionName = targetConfigs["CollectionName"]
// OfferThroughputRUs = int.Parse(sourceConfigs["OfferThroughputRUs"])
CollectionName = targetConfigs["CollectionName"],
OfferThroughputRUs = int.Parse(targetConfigs["OfferThroughputRUs"])
};
}

Expand All @@ -95,6 +95,6 @@ public class CosmosCollectionValues
public string AccessKey { get; set; }
public string DatabaseName { get; set; }
public string CollectionName { get; set; }

public int OfferThroughputRUs { get; set; }
}
}

0 comments on commit ffe7b5d

Please sign in to comment.