Skip to content

Commit 29da4ce

Browse files
committed
Adding Dataplane API to analysis services powershell
1 parent 31b9155 commit 29da4ce

File tree

12 files changed

+693
-7
lines changed

12 files changed

+693
-7
lines changed

src/ResourceManager/AnalysisServices/Commands.AnalysisServices.Test/ScenarioTests/AsTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,12 @@ public void TestNegativeAnalysisServicesServer()
3737
{
3838
NewInstance.RunPsTest(string.Format("Test-NegativeAnalysisServicesServer -location '{0}'", AsTestsBase.resourceGroupLocation));
3939
}
40+
41+
[Fact]
42+
[Trait(Category.AcceptanceType, Category.CheckIn)]
43+
public void TestAnalysisServicesServerRestart()
44+
{
45+
NewInstance.RunPsTest(string.Format("Test-AnalysisServicesServerRestart -environment '{0}'", "aspaaswestusloop1.asazure-int.windows.net"));
46+
}
4047
}
4148
}

src/ResourceManager/AnalysisServices/Commands.AnalysisServices.Test/ScenarioTests/AsTests.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22
.SYNOPSIS
33
Tests Analysis Services server lifecycle (Create, Update, Get, List, Delete).
44
#>
5+
6+
function Test-AnalysisServicesServerRestart
7+
{
8+
param
9+
(
10+
$environment = "aspaaswestusloop1.asazure-int.windows.net"
11+
)
12+
13+
$secpasswd = ConvertTo-SecureString 'Pa$$word2' -AsPlainText -Force
14+
$mycreds = New-Object System.Management.Automation.PSCredential ('[email protected]', $secpasswd)
15+
Login-AzureASAccount -EnvironmentName $environment -Credential $mycreds
16+
#Login-AzureRmAccount -EnvironmentName dogfood -TenantId daef39e6-82cb-4664-bbfa-8c332dbdf939 -SubscriptionId e48bff2b-f633-4bd6-857a-ff243767676e
17+
}
18+
519
function Test-AnalysisServicesServer
620
{
721
param

src/ResourceManager/AnalysisServices/Commands.AnalysisServices/Commands.AnalysisServices.csproj

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,20 @@
116116
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
117117
</ItemGroup>
118118
<ItemGroup>
119-
<Compile Include="Commands\ResumeAzureRmAnalysisServicesServer.cs" />
120-
<Compile Include="Commands\SuspendAzureRmAnalysisServicesServer.cs" />
121-
<Compile Include="Commands\GetAzureRmAnalysisServicesServer.cs" />
122-
<Compile Include="Commands\RemoveAzureRmAnalysisServicesServer.cs" />
123-
<Compile Include="Commands\SetAzureRmAnalysisServicesServer.cs" />
124-
<Compile Include="Commands\TestAzureRmAnalysisServicesServer.cs" />
125-
<Compile Include="Commands\NewAzureRmAnalysisServicesServer.cs" />
119+
<Compile Include="Commands\ControlPlane\ResumeAzureRmAnalysisServicesServer.cs" />
120+
<Compile Include="Commands\ControlPlane\SuspendAzureRmAnalysisServicesServer.cs" />
121+
<Compile Include="Commands\ControlPlane\GetAzureRmAnalysisServicesServer.cs" />
122+
<Compile Include="Commands\ControlPlane\RemoveAzureRmAnalysisServicesServer.cs" />
123+
<Compile Include="Commands\ControlPlane\SetAzureRmAnalysisServicesServer.cs" />
124+
<Compile Include="Commands\ControlPlane\TestAzureRmAnalysisServicesServer.cs" />
125+
<Compile Include="Commands\ControlPlane\NewAzureRmAnalysisServicesServer.cs" />
126+
<Compile Include="Commands\DataPlane\AddAzureASAccount.cs" />
127+
<Compile Include="Commands\DataPlane\AsAzureProfile.cs" />
128+
<Compile Include="Commands\DataPlane\AsAzureContext.cs" />
129+
<Compile Include="Commands\DataPlane\AsAzureEnvironment.cs" />
130+
<Compile Include="Commands\DataPlane\AsAzureTenant.cs" />
131+
<Compile Include="Commands\DataPlane\AsAzureAccount.cs" />
132+
<Compile Include="Commands\DataPlane\AsAzureClientUtility.cs" />
126133
<Compile Include="Models\AnalysisServicesClient.cs" />
127134
<Compile Include="Models\AnalysisServicesCmdletBase.cs" />
128135
<Compile Include="Models\StringOrByteArrayInstance.cs" />
@@ -177,6 +184,7 @@
177184
<Name>Commands.Tags</Name>
178185
</ProjectReference>
179186
</ItemGroup>
187+
<ItemGroup />
180188
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
181189
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
182190
</Project>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 Newtonsoft.Json;
16+
using System;
17+
18+
namespace Microsoft.Azure.Commands.AnalysisServices
19+
{
20+
/// <summary>
21+
/// Represents current Azure session context.
22+
/// </summary>
23+
[Serializable]
24+
public class AsAzureContext
25+
{
26+
/// <summary>
27+
/// Creates new instance of AzureContext.
28+
/// </summary>
29+
/// <param name="account">The azure account object</param>
30+
/// <param name="environment">The azure environment object</param>
31+
/// <param name="tenant">The azure tenant object</param>
32+
public AsAzureContext(AsAzureAccount account, AsAzureEnvironment environment)
33+
{
34+
Account = account;
35+
Environment = environment;
36+
//Tenant = tenant;
37+
}
38+
39+
/// <summary>
40+
/// Gets the azure account.
41+
/// </summary>
42+
public AsAzureAccount Account { get; private set; }
43+
44+
/// <summary>
45+
/// Gets the azure environment.
46+
/// </summary>
47+
public AsAzureEnvironment Environment { get; private set; }
48+
49+
///// <summary>
50+
///// Gets the azure tenant.
51+
///// </summary>
52+
//public AsAzureTenant Tenant { get; private set; }
53+
54+
/// <summary>
55+
/// Gets or sets the token cache contents.
56+
/// </summary>
57+
public byte[] TokenCache { get; set; }
58+
}
59+
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
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.Commands.Common.Authentication;
16+
using Microsoft.Azure.Commands.Common.Authentication.Models;
17+
using Microsoft.Azure.Commands.ResourceManager.Common;
18+
using Microsoft.WindowsAzure.Commands.Common;
19+
using System;
20+
using System.IO;
21+
using System.Management.Automation;
22+
using System.Reflection;
23+
using System.Security;
24+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
25+
26+
namespace Microsoft.Azure.Commands.AnalysisServices
27+
{
28+
/// <summary>
29+
/// Cmdlet to log into an Analysis Services environment
30+
/// </summary>
31+
[Cmdlet("Add", "AzureASAccount", SupportsShouldProcess=true)]
32+
[Alias("Login-AzureASAccount")]
33+
[OutputType(typeof(AsAzureProfile))]
34+
public class AddAzureASAccountCommand : AzurePSCmdlet, IModuleAssemblyInitializer
35+
{
36+
[Parameter(Mandatory = true, HelpMessage = "Name of the environment containing the account to log into")]
37+
[ValidateNotNullOrEmpty]
38+
public string EnvironmentName { get; set; }
39+
40+
[Parameter(Mandatory = false, HelpMessage = "Credential")]
41+
public PSCredential Credential { get; set; }
42+
43+
protected AsAzureEnvironment AsEnvironment;
44+
45+
protected override AzureContext DefaultContext
46+
{
47+
get
48+
{
49+
return null;
50+
}
51+
}
52+
53+
protected override void SaveDataCollectionProfile()
54+
{
55+
// No data collection for this commandlet
56+
}
57+
58+
protected override void PromptForDataCollectionProfileIfNotExists()
59+
{
60+
// No data collection for this commandlet
61+
}
62+
63+
protected override void BeginProcessing()
64+
{
65+
base.BeginProcessing();
66+
#pragma warning disable 0618
67+
if (EnvironmentName == null)
68+
{
69+
throw new PSInvalidOperationException(string.Format(Properties.Resources.UnknownEnvironment, EnvironmentName));
70+
}
71+
else
72+
{
73+
if (AsAzureClientUtility.Instance.Profile.Environments.ContainsKey(EnvironmentName))
74+
{
75+
AsEnvironment = AsAzureClientUtility.Instance.Profile.Environments[EnvironmentName];
76+
}
77+
else
78+
{
79+
AsEnvironment = AsAzureClientUtility.Instance.Profile.CreateEnvironment(EnvironmentName);
80+
}
81+
}
82+
#pragma warning restore 0618
83+
}
84+
85+
protected override void InitializeQosEvent()
86+
{
87+
// nothing to do here.
88+
}
89+
90+
public override void ExecuteCmdlet()
91+
{
92+
AsAzureAccount azureAccount = new AsAzureAccount();
93+
94+
SecureString password = null;
95+
if (Credential != null)
96+
{
97+
azureAccount.Id = Credential.UserName;
98+
password = Credential.Password;
99+
}
100+
101+
#pragma warning disable 0618
102+
if (ShouldProcess(string.Format(Properties.Resources.LoginTarget, AsEnvironment.Name), "log in"))
103+
{
104+
var currentProfile = AsAzureClientUtility.Instance.Profile;
105+
106+
if (currentProfile.Context == null)
107+
{
108+
AsAzureClientUtility.Instance.SetCurrentContext(azureAccount, AsEnvironment);
109+
}
110+
111+
var asAzureProfile = AsAzureClientUtility.Instance.Login(currentProfile.Context, password);
112+
WriteObject(asAzureProfile);
113+
}
114+
#pragma warning restore 0618
115+
}
116+
117+
/// <summary>
118+
/// Load global aliases for ARM
119+
/// </summary>
120+
public void OnImport()
121+
{
122+
try
123+
{
124+
System.Management.Automation.PowerShell invoker = null;
125+
invoker = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace);
126+
invoker.AddScript(File.ReadAllText(FileUtilities.GetContentFilePath(
127+
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
128+
"AzureRmProfileStartup.ps1")));
129+
invoker.Invoke();
130+
}
131+
catch
132+
{
133+
// This will throw exception for tests, ignore.
134+
}
135+
}
136+
137+
}
138+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
18+
namespace Microsoft.Azure.Commands.AnalysisServices
19+
{
20+
[Serializable]
21+
public partial class AsAzureAccount
22+
{
23+
public string Id { get; set; }
24+
25+
public string Tenant { get; set; }
26+
}
27+
}

0 commit comments

Comments
 (0)