Skip to content

Commit

Permalink
Fixing merge confilcs,
Browse files Browse the repository at this point in the history
  • Loading branch information
mkherani committed Jul 9, 2015
2 parents ffc31bd + 29d2007 commit 41e7538
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,22 @@ public IEnumerable<CSMContainerResponse> ListContainers(string filter)
/// <summary>
/// Register container
/// </summary>
/// <param name="request"></param>
/// <param name="containerName"></param>
/// <returns></returns>
public Guid RegisterContainer(RegisterContainerRequestInput request)
public Guid RegisterContainer(string containerName)
{
var response = AzureBackupClient.Container.RegisterAsync(request, GetCustomRequestHeaders(), CmdletCancellationToken).Result;
var response = AzureBackupClient.Container.RegisterAsync(containerName, GetCustomRequestHeaders(), CmdletCancellationToken).Result;
return response.OperationId;
}

/// <summary>
/// UnRegister container
/// </summary>
/// <param name="request"></param>
/// <param name="containerName"></param>
/// <returns></returns>
public Guid UnRegisterContainer(UnregisterContainerRequestInput request)
public Guid UnRegisterContainer(string containerName)
{
var response = AzureBackupClient.Container.UnregisterAsync(request, GetCustomRequestHeaders(), CmdletCancellationToken).Result;
var response = AzureBackupClient.Container.UnregisterAsync(containerName, GetCustomRequestHeaders(), CmdletCancellationToken).Result;
return response.OperationId;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public override void ExecuteCmdlet()
{
containerInfos.RemoveAll(containerInfo =>
{
// TODO: Parse ManagedResourceGroupName from ParentContainerId by getting the last segment
return containerInfo.Properties.ParentContainerId != ManagedResourceGroupName;
string rgName = ContainerHelpers.GetRGNameFromId(containerInfo.Properties.ParentContainerId);
return rgName != ManagedResourceGroupName;
});
WriteDebug(string.Format("Count of containers after resource group filter = {0}", containerInfos.Count));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public override void ExecuteCmdlet()
Guid jobId = Guid.Empty;
bool isDiscoveryNeed = false;

ContainerInfo container = null;
CSMContainerResponse container = null;
isDiscoveryNeed = IsDiscoveryNeeded(vmName, rgName, out container);
if(isDiscoveryNeed)
{
Expand All @@ -101,10 +101,7 @@ public override void ExecuteCmdlet()

//Container is discovered. Register the container
WriteDebug(String.Format("Going to register VM {0}", vmName));
List<string> containerNameList = new List<string>();
containerNameList.Add(container.Name);
RegisterContainerRequestInput registrationRequest = new RegisterContainerRequestInput(containerNameList, AzureBackupContainerType.IaasVMContainer.ToString());
var operationId = AzureBackupClient.RegisterContainer(registrationRequest);
var operationId = AzureBackupClient.RegisterContainer(container.Name);

var operationStatus = GetOperationStatus(operationId);
WriteObject(GetCreatedJobs(Vault, operationStatus.Jobs).FirstOrDefault());
Expand Down Expand Up @@ -156,7 +153,7 @@ private bool WaitForDiscoveryToComplete(Guid operationId, out bool isDiscoverySu
return isRetryNeeded;
}

private bool IsDiscoveryNeeded(string vmName, string rgName, out ContainerInfo container)
private bool IsDiscoveryNeeded(string vmName, string rgName, out CSMContainerResponse container)
{
bool isDiscoveryNeed = false;
//First check if container is discoverd or not
Expand All @@ -178,9 +175,8 @@ private bool IsDiscoveryNeeded(string vmName, string rgName, out ContainerInfo c

else
{
//We can have multiple container with same friendly name.
//Look for resourceGroup name in the container unoque name
container = containers.Where(c => c.ParentContainerFriendlyName.ToLower().Equals(rgName.ToLower())).FirstOrDefault();
//We can have multiple container with same friendly name.
container = containers.Where(c => ContainerHelpers.GetRGNameFromId(c.Properties.ParentContainerId).Equals(rgName.ToLower())).FirstOrDefault(); //TODO need to change.
if (container == null)
{
//Container is not in list of registered container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public override void ExecuteCmdlet()
base.ExecuteCmdlet();

string containerUniqueName = Container.ContainerUniqueName;
UnregisterContainerRequestInput unregRequest = new UnregisterContainerRequestInput(containerUniqueName, AzureBackupContainerType.IaasVMContainer.ToString());
var operationId = AzureBackupClient.UnRegisterContainer(unregRequest);
var operationId = AzureBackupClient.UnRegisterContainer(containerUniqueName);

WriteObject(GetCreatedJobs(new Models.AzurePSBackupVault(Container.ResourceGroupName, Container.ResourceName, Container.Location), GetOperationStatus(operationId).Jobs).FirstOrDefault());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@
using CmdletModel = Microsoft.Azure.Commands.AzureBackup.Models;
using System.Collections.Specialized;
using System.Web;
using System.Text.RegularExpressions;

namespace Microsoft.Azure.Commands.AzureBackup.Helpers
{
internal class ContainerHelpers
{
private static readonly Regex ResourceGroupRegex =
new Regex(@"/resourceGroups/(?<resourceGroupName>.+)/providers/", RegexOptions.Compiled);
internal static string GetQueryFilter(ListContainerQueryParameter queryParams)
{
NameValueCollection collection = new NameValueCollection();
Expand All @@ -58,10 +61,41 @@ internal static string GetQueryFilter(ListContainerQueryParameter queryParams)
return String.Empty;
}

var httpValueCollection = HttpUtility.ParseQueryString(String.Empty);
httpValueCollection.Add(collection);
return CreateQueryString(collection);
}

return "&" + httpValueCollection.ToString();
internal static string GetRGNameFromId(string id)
{
var match = ResourceGroupRegex.Match(id);
if (match.Success)
{
var resourceGroupNameGroup = match.Groups["resourceGroupName"];
if (resourceGroupNameGroup != null && resourceGroupNameGroup.Success)
{
return resourceGroupNameGroup.Value;
}
}

return null;
}
private static string CreateQueryString(NameValueCollection collection)
{
string filterValue = string.Empty;

if (collection == null)
{
throw new ArgumentNullException("collection");
}

if (collection.Count > 0)
{
foreach (string key in collection.Keys)
{
filterValue += key + " eq '" + collection[key] + "' and ";
}
filterValue = filterValue.Remove(filterValue.Length - 5);
}
return filterValue;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.AzureBackup.Helpers;
using Microsoft.Azure.Management.BackupServices.Models;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -51,8 +52,7 @@ public AzureBackupContainer() : base() { }
public AzureBackupContainer(AzurePSBackupVault vault, CSMContainerResponse containerInfo)
: base(vault, containerInfo)
{
// TODO: Parse ManagedResourceGroupName from ParentContainerId by getting the last segment
//ManagedResourceGroupName = containerInfo.Properties.ParentContainerId;
ManagedResourceGroupName = ContainerHelpers.GetRGNameFromId(containerInfo.Properties.ParentContainerId);
ManagedResourceName = containerInfo.Properties.FriendlyName;
HealthStatus = containerInfo.Properties.HealthStatus;
RegistrationStatus = containerInfo.Properties.Status;
Expand Down
Binary file not shown.

0 comments on commit 41e7538

Please sign in to comment.