1

I'm building some function apps in C# (via REST API) to make refreshes of tabular cube located on an azure ssas server. So far, no problem. However, I can't find a way to pause/start the ssas server (I saw some doc in powershell but I'd like to stay in C# so as not to mix languages)

Has anyone ever created anything like this?

I tried to make a POST suspend but no solution for now.

GregGalloway
  • 11,355
  • 3
  • 16
  • 47

3 Answers3

2

See the ResumeAzureAS() method here:

protected async Task<bool> ResumeAzureAS()
        {
            HttpClient client = new HttpClient();
            var apiURI = new Uri(string.Format("https://management.azure.com/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.AnalysisServices/servers/{2}/resume?api-version=2016-05-16", subscriptionID, resourcegroup, server));

            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

            HttpResponseMessage response = await client.PostAsync(apiURI.ToString(), null);
            response.EnsureSuccessStatusCode();
            return true;
        }

The rest of the API calls (such as suspend) are documented here.

Community
  • 1
  • 1
GregGalloway
  • 11,355
  • 3
  • 16
  • 47
  • Hello and thanks for this answer. I've follow the same approach as you've describe but receive a "forbidden" error. I suspect the problem come from the generation of the Token. I'll check from where the problem can come from. Thanks for the tip. I'll keep you post of the progress – Miguel Martin Perez Aug 18 '19 at 17:32
  • @MiguelMartinPerez whatever identity you are using needs Contribute permissions in the Access Control (IAM) tab of your Azure AS server in the Azure Portal. Feel free to share your token generation code. – GregGalloway Aug 18 '19 at 19:44
  • First of all, thank for your help and quick answer. I've done some test and no way to be able to do a suspend or resume; I've got a 403 error. Does the token generation need to be different for a pauseresume vs a refresh ? – Miguel Martin Perez Aug 26 '19 at 12:59
  • @MiguelMartinPerez yes. It is different than refresh. When you post your token generation code we can look at it. – GregGalloway Aug 26 '19 at 13:27
  • private async Task AASAcquireToken() { // Get auth token and add the access token to the authorization header of the request. string authority = "https://login.windows.net/" + tenant + "/oauth/authorize"; AuthenticationContext ac = new AuthenticationContext(authority); ClientCredential cred = new ClientCredential(clientID, keyID); AuthenticationResult ar = await ac.AcquireTokenAsync(audience, cred); return ar.AccessToken; } – Miguel Martin Perez Aug 28 '19 at 07:55
  • With audience set as "https://management.azure.com" and for the "pause" itself : I use as servername the complete name mention in the portal azure as "asazure://northeurope.asazure.windows...." For the version of the api , well I don't know where to find it so I use one I found on the net. – Miguel Martin Perez Aug 28 '19 at 07:55
  • @MiguelMartinPerez audience is right. Leave the version alone in my code or change it to the API Version mentioned in the last link I provided. The server name should just be the short name of your server not the full asazure:// – GregGalloway Aug 28 '19 at 11:09
  • 1
    Hello , after several frustration because I was pretty sur my code was ok ... I found the root cause ; audience was simply wrong. The right audience was audience = "https://management.core.windows.net/"; – Miguel Martin Perez Aug 29 '19 at 07:46
0
private async Task<string> AASAcquireToken()
    {
        // Get auth token and add the access token to the authorization header of the request.
        string authority = "https://login.windows.net/" + tenant + "/oauth/authorize";
        AuthenticationContext ac = new AuthenticationContext(authority);
        ClientCredential cred = new ClientCredential(clientID, keyID);
        AuthenticationResult ar = await ac.AcquireTokenAsync(audience, cred);
        return ar.AccessToken;

    } 

With audience set as "https://management.azure.com"

and for the "pause" itself : I use as servername the complete name mention in the portal azure as "asazure://northeurope.asazure.windows...." For the version of the api , well I don't know where to find it so I use one I found on the net.

        var apiURI = new Uri(string.Format("https://management.azure.com/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.AnalysisServices/servers/{2}/suspend?api-version=2016-05-16", subscription, ressourceID, servername));

        audience = "https://management.azure.com";

        myClient.BaseAddress = new Uri(location);
        myClient.DefaultRequestHeaders.Accept.Clear();
        myClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        myClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", await AASAcquireToken());

        HttpResponseMessage response = await myClient.PostAsync(apiURI.ToString(), null);
        var output = await response.Content.ReadAsStringAsync();

        response.EnsureSuccessStatusCode();
0

The right audience was :

audience = "https://management.core.windows.net/";