Skip to content

Commit 89e2b92

Browse files
committed
Add Data Sync PowerShell Cmdlets
1 parent fb5e65d commit 89e2b92

File tree

60 files changed

+13584
-8562
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+13584
-8562
lines changed

src/ResourceManager/Sql/Commands.Sql/Commands.Sql.csproj

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,42 @@
116116
<Compile Include="Database Backup\Cmdlet\GetAzureSqlDatabaseGeoBackupPolicy.cs" />
117117
<Compile Include="Database Backup\Cmdlet\SetAzureSqlDatabaseGeoBackupPolicy.cs" />
118118
<Compile Include="Database Backup\Model\AzureSqlDatabaseGeoBackupPolicyModel.cs" />
119+
<Compile Include="Data Sync\Cmdlet\AzureSqlSyncAgentCmdletBase.cs" />
120+
<Compile Include="Data Sync\Cmdlet\AzureSqlSyncGroupCmdletBase.cs" />
121+
<Compile Include="Data Sync\Cmdlet\AzureSqlSyncMemberCmdletBase.cs" />
122+
<Compile Include="Data Sync\Cmdlet\AzureSqlSyncSchemaCmdletBase.cs" />
123+
<Compile Include="Data Sync\Cmdlet\GetAzureSqlSyncAgent.cs" />
124+
<Compile Include="Data Sync\Cmdlet\GetAzureSqlSyncAgentLinkedDatabase.cs" />
125+
<Compile Include="Data Sync\Cmdlet\GetAzureSqlSyncGroup.cs" />
126+
<Compile Include="Data Sync\Cmdlet\GetAzureSqlSyncGroupLog.cs" />
127+
<Compile Include="Data Sync\Cmdlet\GetAzureSqlSyncMember.cs" />
128+
<Compile Include="Data Sync\Cmdlet\GetAzureSqlSyncSchema.cs" />
129+
<Compile Include="Data Sync\Cmdlet\NewAzureSqlSyncAgent.cs" />
130+
<Compile Include="Data Sync\Cmdlet\NewAzureSqlSyncAgentKey.cs" />
131+
<Compile Include="Data Sync\Cmdlet\NewAzureSqlSyncGroup.cs" />
132+
<Compile Include="Data Sync\Cmdlet\NewAzureSqlSyncMember.cs" />
133+
<Compile Include="Data Sync\Cmdlet\RemoveAzureSqlSyncAgent.cs" />
134+
<Compile Include="Data Sync\Cmdlet\RemoveAzureSqlSyncGroup.cs" />
135+
<Compile Include="Data Sync\Cmdlet\RemoveAzureSqlSyncMember.cs" />
136+
<Compile Include="Data Sync\Cmdlet\SetAzureSqlSyncGroup.cs" />
137+
<Compile Include="Data Sync\Cmdlet\SetAzureSqlSyncMember.cs" />
138+
<Compile Include="Data Sync\Cmdlet\StartAzureSqlSyncGroupSynchronization.cs" />
139+
<Compile Include="Data Sync\Cmdlet\InvokeAzureSqlSyncSchemaRefresh.cs" />
140+
<Compile Include="Data Sync\Cmdlet\StopAzureSqlSyncGroupSynchronization.cs" />
141+
<Compile Include="Data Sync\Model\AzureSqlSyncAgentKeyModel.cs" />
142+
<Compile Include="Data Sync\Model\AzureSqlSyncAgentLinkedDatabaseModel.cs" />
143+
<Compile Include="Data Sync\Model\AzureSqlSyncAgentModel.cs" />
144+
<Compile Include="Data Sync\Model\AzureSqlSyncGroupLogModel.cs" />
145+
<Compile Include="Data Sync\Model\AzureSqlSyncGroupModel.cs" />
146+
<Compile Include="Data Sync\Model\AzureSqlSyncMemberModel.cs" />
147+
<Compile Include="Data Sync\Model\AzureSqlSyncFullSchemaModel.cs" />
148+
<Compile Include="Data Sync\Services\AzureSqlDataSyncAdapter.cs" />
149+
<Compile Include="Data Sync\Services\AzureSqlDataSyncCommunicator.cs" />
150+
<Compile Include="Data Sync\Model\AzureSqlSyncFullSchemaColumnModel.cs" />
151+
<Compile Include="Data Sync\Model\AzureSqlSyncFullSchemaTableModel.cs" />
152+
<Compile Include="Data Sync\Model\AzureSqlSyncGroupSchemaColumnModel.cs" />
153+
<Compile Include="Data Sync\Model\AzureSqlSyncGroupSchemaModel.cs" />
154+
<Compile Include="Data Sync\Model\AzureSqlSyncGroupSchemaTableModel.cs" />
119155
<Compile Include="ImportExport\Cmdlet\GetAzureSqlDatabaseImportExportStatus.cs" />
120156
<Compile Include="ImportExport\Model\AzureSqlDatabaseImportExportStatusModel.cs" />
121157
<Compile Include="ImportExport\Cmdlet\ImportExportCmdletBase.cs" />
Lines changed: 50 additions & 0 deletions
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 System.Collections.Generic;
16+
using System.Management.Automation;
17+
using Microsoft.Azure.Commands.Sql.DataSync.Model;
18+
using Microsoft.Azure.Commands.Sql.DataSync.Services;
19+
using Microsoft.Azure.Commands.Sql.Common;
20+
using Microsoft.Azure.Commands.Common.Authentication.Models;
21+
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
22+
23+
namespace Microsoft.Azure.Commands.Sql.DataSync.Cmdlet
24+
{
25+
/// <summary>
26+
/// The base class for sync agent cmdlets
27+
/// </summary>
28+
public abstract class AzureSqlSyncAgentCmdletBase : AzureSqlCmdletBase<IEnumerable<AzureSqlSyncAgentModel>, AzureSqlDataSyncAdapter>
29+
{
30+
/// <summary>
31+
/// Gets or sets the name of the database server to use.
32+
/// </summary>
33+
[Parameter(Mandatory = true,
34+
ValueFromPipelineByPropertyName = true,
35+
Position = 1,
36+
HelpMessage = "The name of the Azure SQL Database Server the sync agent is in.")]
37+
[ValidateNotNullOrEmpty]
38+
public string ServerName { get; set; }
39+
40+
/// <summary>
41+
/// Creation and initialization of the ModelAdapter object
42+
/// </summary>
43+
/// <param name="subscription">The Azure Subscription in which the current execution is performed</param>
44+
/// <returns>An initialized and ready to use ModelAdapter object</returns>
45+
protected override AzureSqlDataSyncAdapter InitModelAdapter(IAzureSubscription subscription)
46+
{
47+
return new AzureSqlDataSyncAdapter(DefaultProfile.DefaultContext);
48+
}
49+
}
50+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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.IO;
16+
using System.Collections.Generic;
17+
using System.Management.Automation;
18+
using Microsoft.Azure.Commands.Common.Authentication.Models;
19+
using Microsoft.Azure.Commands.Sql.Common;
20+
using Microsoft.Azure.Commands.Sql.DataSync.Model;
21+
using Microsoft.Azure.Commands.Sql.DataSync.Services;
22+
using Microsoft.Azure.Management.Sql.Models;
23+
using Newtonsoft.Json.Linq;
24+
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
25+
26+
namespace Microsoft.Azure.Commands.Sql.DataSync.Cmdlet
27+
{
28+
/// <summary>
29+
/// The base class for all sync group cmdlets
30+
/// </summary>
31+
public abstract class AzureSqlSyncGroupCmdletBase : AzureSqlDatabaseCmdletBase<IEnumerable<AzureSqlSyncGroupModel>, AzureSqlDataSyncAdapter>
32+
{
33+
/// <summary>
34+
/// Creation and initialization of the ModelAdapter object
35+
/// </summary>
36+
/// <param name="subscription">The Azure Subscription in which the current execution is performed</param>
37+
/// <returns>An initialized and ready to use ModelAdapter object</returns>
38+
protected override AzureSqlDataSyncAdapter InitModelAdapter(IAzureSubscription subscription)
39+
{
40+
return new AzureSqlDataSyncAdapter(DefaultProfile.DefaultContext);
41+
}
42+
43+
/// <summary>
44+
/// Construct schema for schema file
45+
/// </summary>
46+
/// <param name="filePath">The path of the schema file</param>
47+
/// <returns>A schema object of member database</returns>
48+
protected AzureSqlSyncGroupSchemaModel ConstructSchemaFromFile(string filePath)
49+
{
50+
AzureSqlSyncGroupSchemaModel schema = new AzureSqlSyncGroupSchemaModel();
51+
try
52+
{
53+
JObject jSchema = JObject.Parse(File.ReadAllText(filePath));
54+
schema.MasterSyncMemberName = jSchema["masterSyncMemberName"] == null ? null : jSchema["masterSyncMemberName"].ToString();
55+
List<AzureSqlSyncGroupSchemaTableModel> tables = new List<AzureSqlSyncGroupSchemaTableModel>();
56+
JArray jTables = (JArray)jSchema["tables"];
57+
if (jTables != null)
58+
{
59+
foreach (var jTable in jTables.Children())
60+
{
61+
AzureSqlSyncGroupSchemaTableModel table = new AzureSqlSyncGroupSchemaTableModel();
62+
table.QuotedName = jTable["quotedName"] == null ? null : jTable["quotedName"].ToString();
63+
List<AzureSqlSyncGroupSchemaColumnModel> columns = new List<AzureSqlSyncGroupSchemaColumnModel>();
64+
JArray jColumns = (JArray)jTable["columns"];
65+
if (jColumns != null)
66+
{
67+
foreach (var jColumn in jColumns.Children())
68+
{
69+
AzureSqlSyncGroupSchemaColumnModel column = new AzureSqlSyncGroupSchemaColumnModel();
70+
column.QuotedName = jColumn["quotedName"] == null ? null : jColumn["quotedName"].ToString();
71+
columns.Add(column);
72+
}
73+
}
74+
table.Columns = columns;
75+
tables.Add(table);
76+
}
77+
}
78+
schema.Tables = tables;
79+
return schema;
80+
}
81+
catch (Newtonsoft.Json.JsonReaderException)
82+
{
83+
throw new PSArgumentException("The schema file is empty or invalid!", "SchemaFile");
84+
}
85+
}
86+
}
87+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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.Management.Automation;
16+
using System.Collections.Generic;
17+
using Microsoft.Azure.Commands.Common.Authentication.Models;
18+
using Microsoft.Azure.Commands.Sql.Common;
19+
using Microsoft.Azure.Commands.Sql.DataSync.Model;
20+
using Microsoft.Azure.Commands.Sql.DataSync.Services;
21+
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
22+
23+
namespace Microsoft.Azure.Commands.Sql.DataSync.Cmdlet
24+
{
25+
/// <summary>
26+
/// The base class for all sync member cmdlets
27+
/// </summary>
28+
public abstract class AzureSqlSyncMemberCmdletBase : AzureSqlDatabaseCmdletBase<IEnumerable<AzureSqlSyncMemberModel>, AzureSqlDataSyncAdapter>
29+
{
30+
/// <summary>
31+
/// Gets or sets the sync group name
32+
/// </summary>
33+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The sync group name.")]
34+
[ValidateNotNullOrEmpty]
35+
public string SyncGroupName { get; set; }
36+
37+
/// <summary>
38+
/// Creation and initialization of the ModelAdapter object
39+
/// </summary>
40+
/// <param name="subscription">The Azure Subscription in which the current execution is performed</param>
41+
/// <returns>An initialized and ready to use ModelAdapter object</returns>
42+
protected override AzureSqlDataSyncAdapter InitModelAdapter(IAzureSubscription subscription)
43+
{
44+
return new AzureSqlDataSyncAdapter(DefaultProfile.DefaultContext);
45+
}
46+
}
47+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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.Collections.Generic;
16+
using System.Management.Automation;
17+
using Microsoft.Azure.Commands.Sql.DataSync.Model;
18+
using Microsoft.Azure.Commands.Sql.DataSync.Services;
19+
using Microsoft.Azure.Commands.Common.Authentication.Models;
20+
using Microsoft.Azure.Commands.Sql.Common;
21+
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
22+
23+
namespace Microsoft.Azure.Commands.Sql.DataSync.Cmdlet
24+
{
25+
/// <summary>
26+
/// The base class for cmdlets that get full schema of hub and member database of a sync member
27+
/// </summary>
28+
public abstract class AzureSqlSyncSchemaCmdletBase : AzureSqlDatabaseCmdletBase<IEnumerable<AzureSqlSyncFullSchemaModel>, AzureSqlDataSyncAdapter>
29+
{
30+
/// <summary>
31+
/// Gets or sets the sync group name
32+
/// </summary>
33+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The sync group name.")]
34+
[ValidateNotNullOrEmpty]
35+
public string SyncGroupName { get; set; }
36+
37+
/// <summary>
38+
/// Gets or sets the sync member name
39+
/// </summary>
40+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The sync member name.")]
41+
public string SyncMemberName { get; set; }
42+
43+
/// <summary>
44+
/// Creation and initialization of the ModelAdapter object
45+
/// </summary>
46+
/// <param name="subscription">The Azure Subscription in which the current execution is performed</param>
47+
/// <returns>An initialized and ready to use ModelAdapter object</returns>
48+
protected override AzureSqlDataSyncAdapter InitModelAdapter(IAzureSubscription subscription)
49+
{
50+
return new AzureSqlDataSyncAdapter(DefaultProfile.DefaultContext);
51+
}
52+
}
53+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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.Collections.Generic;
16+
using System.Management.Automation;
17+
using Microsoft.Azure.Commands.Sql.DataSync.Model;
18+
19+
namespace Microsoft.Azure.Commands.Sql.DataSync.Cmdlet
20+
{
21+
/// <summary>
22+
/// Cmdlet to get information of specified sync agent or list all the sync agents under a specified resource group
23+
/// </summary>
24+
[Cmdlet(VerbsCommon.Get, "AzureRmSqlSyncAgent", SupportsShouldProcess = true,
25+
ConfirmImpact = ConfirmImpact.None)]
26+
public class GetAzureSqlSyncAgent : AzureSqlSyncAgentCmdletBase
27+
{
28+
/// <summary>
29+
/// Gets or sets the sync agent name
30+
/// </summary>
31+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The sync agent name.")]
32+
public string SyncAgentName { get; set; }
33+
34+
/// <summary>
35+
/// Get the entities from the service
36+
/// </summary>
37+
/// <returns>The list of entities</returns>
38+
protected override IEnumerable<AzureSqlSyncAgentModel> GetEntity()
39+
{
40+
ICollection<AzureSqlSyncAgentModel> results;
41+
42+
if (MyInvocation.BoundParameters.ContainsKey("SyncAgentName"))
43+
{
44+
results = new List<AzureSqlSyncAgentModel>();
45+
results.Add(ModelAdapter.GetSyncAgent(this.ResourceGroupName, this.ServerName, this.SyncAgentName));
46+
}
47+
else
48+
{
49+
results = ModelAdapter.ListSyncAgents(this.ResourceGroupName, this.ServerName);
50+
}
51+
return results;
52+
}
53+
54+
/// <summary>
55+
/// No changes to persist to server
56+
/// </summary>
57+
/// <param name="entity">The output of apply user input to model</param>
58+
/// <returns>The input entity</returns>
59+
protected override IEnumerable<AzureSqlSyncAgentModel> PersistChanges(IEnumerable<AzureSqlSyncAgentModel> entity)
60+
{
61+
return entity;
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)