Skip to content

Commit 2a37633

Browse files
author
dragonfly91
committed
1. Directory restructuring
2. Hydra Adapter
1 parent 11ab0c6 commit 2a37633

24 files changed

+380
-41
lines changed

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Cmdlets.csproj

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,6 @@
7474
<Project>{3819d8a7-c62c-4c47-8ddd-0332d9ce1252}</Project>
7575
<Name>Commands.ResourceManager.Common</Name>
7676
</ProjectReference>
77-
<ProjectReference Include="Helpers\Commands.RecoveryServices.Backup.Helpers.csproj">
78-
<Project>{0e1d3f36-e6c8-4764-8c7d-6f9ee537490c}</Project>
79-
<Name>Commands.RecoveryServices.Backup.Helpers</Name>
80-
</ProjectReference>
81-
<ProjectReference Include="Models\Commands.RecoveryServices.Backup.Models.csproj">
82-
<Project>{30b92759-50b3-494e-b9f0-ec9a2ce9d57b}</Project>
83-
<Name>Commands.RecoveryServices.Backup.Models</Name>
84-
</ProjectReference>
85-
<ProjectReference Include="ProviderModel\Commands.RecoveryServices.Backup.Providers.csproj">
86-
<Project>{02234e90-bcde-4b20-b1f5-01b1005821db}</Project>
87-
<Name>Commands.RecoveryServices.Backup.Providers</Name>
88-
</ProjectReference>
8977
</ItemGroup>
9078
<ItemGroup>
9179
<EmbeddedResource Include="Properties\Resources.resx">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
16+
using System;
17+
using System.Collections.Generic;
18+
using System.Linq;
19+
using System.Text;
20+
using System.Threading.Tasks;
21+
22+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.HydraAdapter
23+
{
24+
public partial class HydraAdapter
25+
{
26+
/// <summary>
27+
/// Fetches protection containers in the vault according to the query params
28+
/// </summary>
29+
/// <param name="parameters"></param>
30+
/// <returns></returns>
31+
public IEnumerable<ProtectionContainerResource> RecoveryServicesListContainers(string resourceGroupName, string resourceName, ProtectionContainerListQueryParams queryParams)
32+
{
33+
var listResponse = BmsAdapter.Client.Container.ListAsync(resourceGroupName, resourceName, queryParams,
34+
BmsAdapter.GetCustomRequestHeaders(), BmsAdapter.CmdletCancellationToken).Result;
35+
return listResponse.ItemList.ProtectionContainers;
36+
}
37+
38+
/// <summary>
39+
/// Triggers refresh of container catalog in service
40+
/// </summary>
41+
/// <returns></returns>
42+
public BaseRecoveryServicesJobResponse RecoveryServicesRefreshContainers(string resourceGroupName, string resourceName)
43+
{
44+
var response = BmsAdapter.Client.Container.RefreshAsync(
45+
resourceGroupName, resourceName,
46+
BmsAdapter.GetCustomRequestHeaders(), AzureFabricName, BmsAdapter.CmdletCancellationToken).Result;
47+
return response;
48+
}
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Collections.Generic;
17+
using System.Linq;
18+
using System.Text;
19+
using System.Threading.Tasks;
20+
21+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.HydraAdapter
22+
{
23+
public partial class HydraAdapter
24+
{
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Collections.Generic;
17+
using System.Linq;
18+
using System.Text;
19+
using System.Threading.Tasks;
20+
21+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.HydraAdapter
22+
{
23+
public partial class HydraAdapter
24+
{
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Collections.Generic;
17+
using System.Linq;
18+
using System.Text;
19+
using System.Threading.Tasks;
20+
21+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.HydraAdapter
22+
{
23+
public partial class HydraAdapter
24+
{
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Collections.Generic;
17+
using System.Linq;
18+
using System.Text;
19+
using System.Threading.Tasks;
20+
21+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.HydraAdapter
22+
{
23+
public partial class HydraAdapter
24+
{
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Hyak.Common;
16+
using Microsoft.Azure.Common.Authentication;
17+
using System;
18+
using System.Collections.Generic;
19+
using System.Linq;
20+
using System.Text;
21+
using System.Threading.Tasks;
22+
23+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.HydraAdapter
24+
{
25+
public partial class ClientProxy<TClient, THeader> : ClientProxyBase
26+
where TClient : ServiceClient<TClient>
27+
{
28+
/// <summary>
29+
/// Client to talk to backend service
30+
/// </summary>
31+
private TClient client;
32+
33+
/// <summary>
34+
/// Delegate action to generate custom request headers
35+
/// </summary>
36+
private Func<string, THeader> CustomRequestHeaderGenerator;
37+
38+
/// <summary>
39+
/// Get Azure backup client.
40+
/// </summary>
41+
public TClient Client
42+
{
43+
get
44+
{
45+
if (this.client == null)
46+
{
47+
this.client = AzureSession.ClientFactory.CreateCustomClient<TClient>(Parameters);
48+
}
49+
50+
return this.client;
51+
}
52+
}
53+
54+
public ClientProxy(Func<string, THeader> headerGenerator, params object[] parameters)
55+
: base(parameters)
56+
{
57+
CustomRequestHeaderGenerator = headerGenerator;
58+
}
59+
60+
public THeader GetCustomRequestHeaders()
61+
{
62+
return CustomRequestHeaderGenerator(this.ClientRequestId);
63+
}
64+
}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Collections.Generic;
17+
using System.Linq;
18+
using System.Net;
19+
using System.Text;
20+
using System.Threading;
21+
using System.Threading.Tasks;
22+
23+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.HydraAdapter
24+
{
25+
public class ClientProxyBase
26+
{
27+
protected object[] Parameters;
28+
29+
/// <summary>
30+
/// Client request id.
31+
/// </summary>
32+
protected string ClientRequestId;
33+
34+
/// <summary>
35+
/// Cancellation Token Source
36+
/// </summary>
37+
private CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
38+
public CancellationToken CmdletCancellationToken;
39+
40+
public ClientProxyBase(params object[] parameters)
41+
{
42+
Parameters = parameters;
43+
44+
RefreshClientRequestId();
45+
46+
// Temp code to be able to test internal env.
47+
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
48+
}
49+
50+
public void RefreshClientRequestId()
51+
{
52+
ClientRequestId = Guid.NewGuid().ToString() + "-" + DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ssZ") + "-PS";
53+
}
54+
55+
public string GetClientRequestId()
56+
{
57+
return ClientRequestId;
58+
}
59+
}
60+
}

src/ResourceManager/RecoveryServices.Backup/Adapter/Commands.RecoveryServices.Backup.HydraAdapter.csproj renamed to src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.HydraAdapter/Commands.RecoveryServices.Backup.HydraAdapter.csproj

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,24 @@
3030
<WarningLevel>4</WarningLevel>
3131
</PropertyGroup>
3232
<ItemGroup>
33+
<Reference Include="Hyak.Common">
34+
<HintPath>..\..\..\packages\Hyak.Common.1.0.3\lib\portable-net403+win+wpa81\Hyak.Common.dll</HintPath>
35+
</Reference>
36+
<Reference Include="Microsoft.Azure.Common">
37+
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.dll</HintPath>
38+
</Reference>
39+
<Reference Include="Microsoft.Azure.Common.Authentication">
40+
<HintPath>..\..\..\packages\Microsoft.Azure.Common.Authentication.1.6.1-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
41+
</Reference>
42+
<Reference Include="Microsoft.Azure.Management.RecoveryServicesBackupManagement, Version=0.9.0.0, Culture=neutral, processorArchitecture=MSIL">
43+
<SpecificVersion>False</SpecificVersion>
44+
<HintPath>Resources\Microsoft.Azure.Management.RecoveryServicesBackupManagement.dll</HintPath>
45+
</Reference>
46+
<Reference Include="Microsoft.Rest.ClientRuntime">
47+
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.1.8.2\lib\net45\Microsoft.Rest.ClientRuntime.dll</HintPath>
48+
</Reference>
3349
<Reference Include="System" />
50+
<Reference Include="System.Configuration" />
3451
<Reference Include="System.Core" />
3552
<Reference Include="System.Xml.Linq" />
3653
<Reference Include="System.Data.DataSetExtensions" />
@@ -39,8 +56,19 @@
3956
<Reference Include="System.Xml" />
4057
</ItemGroup>
4158
<ItemGroup>
59+
<Compile Include="BMSAPIs\PolicyAPIs.cs" />
60+
<Compile Include="BMSAPIs\OperationStatusAPIs.cs" />
61+
<Compile Include="BMSAPIs\JobAPIs.cs" />
62+
<Compile Include="BMSAPIs\ItemAPIs.cs" />
63+
<Compile Include="BMSAPIs\ContainerAPIs.cs" />
64+
<Compile Include="ClientProxy.cs" />
65+
<Compile Include="ClientProxyBase.cs" />
66+
<Compile Include="HydraAdapter.cs" />
4267
<Compile Include="Properties\AssemblyInfo.cs" />
4368
</ItemGroup>
69+
<ItemGroup>
70+
<Content Include="Resources\Microsoft.Azure.Management.RecoveryServicesBackupManagement.dll" />
71+
</ItemGroup>
4472
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
4573
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
4674
Other similar extension points exist, see Microsoft.Common.targets.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Collections.Generic;
17+
using System.Linq;
18+
using System.Text;
19+
using System.Threading.Tasks;
20+
using RecoveryServicesModelsNS = Microsoft.Azure.Management.RecoveryServices.Backup.Models;
21+
using RecoveryServicesNS = Microsoft.Azure.Management.RecoveryServices.Backup;
22+
23+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.HydraAdapter
24+
{
25+
public partial class HydraAdapter
26+
{
27+
const string AppSettingsSectionName = "appSettings";
28+
const string RecoveryServicesResourceNamespace = "Microsoft.RecoveryServices";
29+
const string ProviderNamespaceKey = "ProviderNamespace";
30+
const string AzureFabricName = "AzureIaasVM";
31+
32+
public ClientProxy<RecoveryServicesNS.RecoveryServicesBackupManagementClient, RecoveryServicesModelsNS.CustomRequestHeaders> BmsAdapter;
33+
34+
public HydraAdapter(SubscriptionCloudCredentials creds, Uri baseUri)
35+
{
36+
System.Configuration.Configuration exeConfiguration = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Reflection.Assembly.GetExecutingAssembly().Location);
37+
System.Configuration.AppSettingsSection appSettings = (System.Configuration.AppSettingsSection)exeConfiguration.GetSection(AppSettingsSectionName);
38+
string recoveryServicesResourceNamespace = RecoveryServicesResourceNamespace;
39+
if (appSettings.Settings[ProviderNamespaceKey] != null)
40+
{
41+
recoveryServicesResourceNamespace = appSettings.Settings[ProviderNamespaceKey].Value;
42+
}
43+
BmsAdapter = new ClientProxy<RecoveryServicesNS.RecoveryServicesBackupManagementClient, RecoveryServicesModelsNS.CustomRequestHeaders>(
44+
clientRequestId => new RecoveryServicesModelsNS.CustomRequestHeaders() { ClientRequestId = clientRequestId },
45+
recoveryServicesResourceNamespace, creds, baseUri);
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)