Sunday 14 June 2020

Pause and Resume Analysis Services with ADF only

Case
I want to start and stop my Azure Analysis Services from within Azure Data Factory, but I don't want write code or use other Azure services like Azure Automation or Azure Logic Apps to do this. Is there an Azure Data Factory-only solution where we only use the standard pipeline activities from ADF?
Save some money on your Azure Bill by pausing AAS




















Solution
Yes you can use the Web Activity to call the Rest API of Azure Analysis Services (AAS), but that requires you to give ADF permissions in AAS via its Managed Service Identity (MSI). If you already used our Process Model example, then this is slightly different (and easier).


1) Add ADF as contributer to AAS
Different than for processing one of the AAS models we don't need SSMS to add ADF as an Server Administrator. Instead we will use Access control (IAM) on the Azure portal to make our ADF a contributor for the AAS that we want to pause or resume.
  • Go to your AAS the Azure portal
  • In the left menu click on Access control (IAM)
  • Click on + Add and choose Add role assignment
  • In the new Add role assignment pane select Contributor as Role
  • In the Assign access to dropdown select Data Factory
  • Select the right Subscription
  • Now Select your Data Factory and click on the Save button
Add ADF as Contributor to AAS















2) Add Web Activity
In your ADF pipeline you need to add a Web Activity to call the Rest API of Analysis Services. First step is to determine the Rest API URL. Replace in the string below, the <xxx> values with the subscription id, resource group and servername of your Analysis Services. The Rest API method we will be using is 'Suspend' but you can replace that word by 'Resume' to startup the AAS:
https://management.azure.com/subscriptions/<xxx>/resourceGroups/<xxx>/providers/Microsoft.AnalysisServices/servers/<xxx>/Suspend?api-version=2017-08-01

Example:
https://management.azure.com/subscriptions/a74a173e-4d8a-48d9-9ab7-a0b85abb98fb/resourceGroups/bitools/providers/Microsoft.AnalysisServices/servers/bitools2/Suspend?api-version=2017-08-01

Second step is to create a JSON message for the Rest API. Well the Rest API doesn't use it, but it is required in the Web activity when you use POST as method. So you just need to create a dummy json message:
{
    "Dummy": "Dummy"
}
  • Add the Web activity to your pipeline
  • Give it a descriptive name like Pause AAS (or Resume AAS)
  • Go to the Settings tab
  • Use the Rest API URL from above in the URL property
  • Choose POST as Method
  • Add the dummy JSON message from above in the Body property
  • Under advanced choose MSI as Authentication method
  • Add 'https://management.azure.com/ in the Resource property (different than process example)
Web Activity calling the AAS Rest API



















Then Debug the Pipeline to check the suspend/resume action














3) Retrieve info
By changing the method type from POST to GET (body property will disappear) and removing the method (suspend or pause) from the URL, you can retrieve information about the AAS. Like status and pricing tier. You could for example use that to first check the status before changing it.
Retrieve service info via GET


Summary
In this post you learned how pause and resume your Analysis Services to save some money on your Azure bill. The big advantage of this method is that you don't need other Azure services which makes maintenance a little easier. In a next post we will also show you how to change the pricing tier via the Rest API.

15 comments:

  1. Thanks for the post. Can this solution be used to refresh model in Azure Analysis Services through ADF Web Activity?

    ReplyDelete
    Replies
    1. See the link in the first paragraph of the solution. That one is for processing.

      Delete
  2. Thanks for this post. Have you wrote a post how to change the pricing tier?

    ReplyDelete
    Replies
    1. Not yet via the Rest API. If you are interested I could write one. Otherwise you could use PowerShell https://microsoft-bitools.blogspot.com/2017/06/schedule-upscaledownscale-azure.html

      Delete
  3. I have followed this step by step guide, but receives the following error when I run the ADF:
    Operation on target Pause AAS failed: {"error":{"code":"AuthorizationFailed","message":"The client 'b2218d72-96f4-44c0-965b-fc6635946700' with object id 'b2218d72-96f4-44c0-965b-fc6635946700' does not have authorization to perform action 'Microsoft.AnalysisServices/servers/Suspend/action' over scope '/subscriptions/ac7fac18-844a-4ca4-8010-dc35419dd18d/resourceGroups/al-rg-aim-d365-dev/providers/Microsoft.AnalysisServices/servers/alasaimd365dev ' or the scope is invalid. If access was recently granted, please refresh your credentials."}}

    Do you know what this means? I have done step 1.

    Regards Jonas

    ReplyDelete
    Replies
    1. No ideas at the moment. But make sure you used the correct role and correct ADF in step 1

      Delete
    2. If you've done step 1, then the chances are you've got the wrong subscription, resource group or server name in the scope. (Covered by the "or the scope is invalid" bit of the error message)

      Delete
  4. Hi, I found this post very useful. Any chance you could write a post using the web API to scale up and scale down Azure Analysis Services.

    ReplyDelete
    Replies
    1. Thx for reminding me.... I actually started writing that post and never finished it. Will try to finish it soon

      Delete
  5. The scale AAS post is now also online: https://microsoft-bitools.blogspot.com/2021/02/scaling-analysis-services-with-adf-only.html

    ReplyDelete
  6. Thanks for this post. Have you wrote a post to scale up and scale down Synapse DWU using ADF?

    ReplyDelete
    Replies
    1. https://microsoft-bitools.blogspot.com/2021/01/scaling-azure-dedicated-sql-pools-from.html

      Delete
  7. Hi can I pause multiple servers using one web activity?
    If I can create a parameter with array type and pass two server names will the rest api able to pause both the servers or I need to create as many web activity for as many servers I want to pause

    ReplyDelete
    Replies
    1. I wrote below expression in Web activity URL:
      https://management.azure.com/subscriptions/64XXf4-xxxx-4051-9290-90XXXXe11e/resourceGroups/DEV/providers/Microsoft.AnalysisServices/servers/@item()/resume?api-version=2017-08-01

      Let me know if I am doing something wrong here

      Thanks

      Delete

All comments will be verified first to avoid URL spammers. यूआरएल स्पैमर से बचने के लिए सभी टिप्पणियों को पहले सत्यापित किया जाएगा।