Skip to content

Commit d5a46e9

Browse files
committed
Fixing build failure in analysisservices dataplane apis
1 parent a97425a commit d5a46e9

File tree

6 files changed

+58
-34
lines changed

6 files changed

+58
-34
lines changed

src/ResourceManager/AnalysisServices/Commands.AnalysisServices.ServiceManagement/AzureRM.AnalysisServices.ServiceManagement.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
@{
1010

1111
# Version number of this module.
12-
ModuleVersion = '1.0.0'
12+
ModuleVersion = '0.0.1'
1313

1414
# ID used to uniquely identify this module
1515
GUID = 'c717b5a4-1f1b-4a2f-8aa1-bfd09934626e'

src/ResourceManager/AnalysisServices/Commands.AnalysisServices.ServiceManagement/Commands/AddAzureASAccount.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected override AzureContext DefaultContext
4444
{
4545
get
4646
{
47-
// Nothing to do with Azure Resource Managment APIs
47+
// Nothing to do with Azure Resource Managment context
4848
return null;
4949
}
5050
}
@@ -108,10 +108,6 @@ public override void ExecuteCmdlet()
108108
}
109109

110110
var asAzureProfile = AsAzureClientSession.Instance.Login(currentProfile.Context, password);
111-
if (!currentProfile.Environments.ContainsKey(EnvironmentName))
112-
{
113-
currentProfile.Environments.Add(AsEnvironment.Name, AsEnvironment);
114-
}
115111

116112
WriteObject(asAzureProfile);
117113
}

src/ResourceManager/AnalysisServices/Commands.AnalysisServices.ServiceManagement/Commands/Restart-AzureAsInstance.cs

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using System;
16+
using System.Linq;
1617
using System.Management.Automation;
18+
using System.Management.Instrumentation;
1719
using System.Net.Http;
1820
using System.Net.Http.Headers;
1921
using System.Threading.Tasks;
@@ -32,11 +34,20 @@ namespace Microsoft.Azure.Commands.AnalysisServices.ServiceManagement
3234
[OutputType(typeof(AsAzureProfile))]
3335
public class RestartAzureAnalysisServer: AzurePSCmdlet, IModuleAssemblyInitializer
3436
{
37+
private string serverName;
38+
3539
[Parameter(Mandatory = true, HelpMessage = "Name of the Azure Analysis Services server to restart")]
3640
[ValidateNotNullOrEmpty]
3741
public string Instance { get; set; }
3842

39-
protected override AzureContext DefaultContext { get; }
43+
protected override AzureContext DefaultContext
44+
{
45+
get
46+
{
47+
// Nothing to do with Azure Resource Managment context
48+
return null;
49+
}
50+
}
4051

4152
protected override void SaveDataCollectionProfile()
4253
{
@@ -55,13 +66,30 @@ protected override void BeginProcessing()
5566
#pragma warning disable 0618
5667
if (Instance == null)
5768
{
58-
throw new PSArgumentNullException(nameof(Instance));
69+
throw new PSArgumentNullException(nameof(Instance), "Name of Azure Analysis Services server not specified");
5970
}
6071

6172
if (AsAzureClientSession.Instance.Profile.Environments.Count == 0)
6273
{
6374
throw new PSInvalidOperationException(string.Format(Resources.NotLoggedInMessage, ""));
6475
}
76+
77+
serverName = Instance;
78+
Uri uriResult;
79+
80+
// if the user specifies the FQN of the server, then extract the servername out of that.
81+
// and set the current context
82+
if (Uri.TryCreate(Instance, UriKind.Absolute, out uriResult) && uriResult.Scheme == "asazure")
83+
{
84+
serverName = uriResult.PathAndQuery.Trim('/');
85+
if (string.Compare(AsAzureClientSession.Instance.Profile.Context.Environment.Name, uriResult.DnsSafeHost, StringComparison.InvariantCultureIgnoreCase) != 0)
86+
{
87+
AsAzureClientSession.Instance.SetCurrentContext(
88+
new AsAzureAccount(),
89+
AsAzureClientSession.Instance.Profile.CreateEnvironment(uriResult.DnsSafeHost));
90+
}
91+
}
92+
6593
#pragma warning restore 0618
6694
}
6795

@@ -72,33 +100,28 @@ protected override void InitializeQosEvent()
72100

73101
public override void ExecuteCmdlet()
74102
{
75-
if (!string.IsNullOrEmpty(Instance))
103+
if (ShouldProcess(Instance, Resources.RestartingAnalysisServicesServer))
76104
{
77-
if (ShouldProcess(Instance, Resources.RestartingAnalysisServicesServer))
105+
var context = AsAzureClientSession.Instance.Profile.Context;
106+
AsAzureClientSession.Instance.Login(context, null);
107+
TokenCacheItem tokenCacheItem = AsAzureClientSession.TokenCache.ReadItems()
108+
.FirstOrDefault(tokenItem => tokenItem.TenantId.Equals(context.Account.Tenant));
109+
110+
if (tokenCacheItem == null || string.IsNullOrEmpty(tokenCacheItem.AccessToken))
78111
{
79-
var context = AsAzureClientSession.Instance.Profile.Context;
80-
var restartEndpoint = string.Format(context.Environment.Endpoints[AsAzureEnvironment.AsRolloutEndpoints.RestartEndpointFormat], Instance);
81-
string restartBaseUri = string.Format("https://{0}", context.Environment.Name);
82-
var accessToken = AsAzureClientSession.GetAadAuthenticatedToken(
83-
context,
84-
null,
85-
PromptBehavior.Auto,
86-
AsAzureClientSession.AsAzureClientId,
87-
restartBaseUri,
88-
AsAzureClientSession.RedirectUri);
89-
90-
using (HttpResponseMessage message = CallPostAsync(
91-
new Uri(restartBaseUri),
92-
restartEndpoint,
93-
accessToken).Result)
94-
{
95-
message.EnsureSuccessStatusCode();
96-
}
112+
throw new PSInvalidOperationException(string.Format(Resources.NotLoggedInMessage, ""));
113+
}
114+
115+
Uri restartBaseUri = new Uri(string.Format("{0}{1}{2}", Uri.UriSchemeHttps, Uri.SchemeDelimiter, context.Environment.Name));
116+
117+
var restartEndpoint = string.Format(context.Environment.Endpoints[AsAzureEnvironment.AsRolloutEndpoints.RestartEndpointFormat], serverName);
118+
using (HttpResponseMessage message = CallPostAsync(
119+
restartBaseUri,
120+
restartEndpoint,
121+
tokenCacheItem.AccessToken).Result)
122+
{
123+
message.EnsureSuccessStatusCode();
97124
}
98-
}
99-
else
100-
{
101-
WriteExceptionError(new PSArgumentNullException(nameof(Instance), "Name of Azure Analysis Services server not specified"));
102125
}
103126
}
104127

src/ResourceManager/AnalysisServices/Commands.AnalysisServices.ServiceManagement/Models/AsAzureClientSession.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ public AsAzureProfile Login(AsAzureContext asAzureContext, SecureString password
7070

7171
_profile.Context.TokenCache = AsAzureClientSession.TokenCache.Serialize();
7272

73+
if (!_profile.Environments.ContainsKey(asAzureContext.Environment.Name))
74+
{
75+
_profile.Environments.Add(asAzureContext.Environment.Name, asAzureContext.Environment);
76+
}
77+
7378
return _profile;
7479
}
7580

src/ResourceManager/AnalysisServices/Commands.AnalysisServices.ServiceManagement/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@
3535
// by using the '*' as shown below:
3636

3737

38-
[assembly: AssemblyVersion("1.0.1")]
39-
[assembly: AssemblyFileVersion("1.0.1")]
38+
[assembly: AssemblyVersion("0.0.1")]
39+
[assembly: AssemblyFileVersion("0.0.1")]

0 commit comments

Comments
 (0)