Recurrency in Azure and WebApi - azure

I have implemented a WebApi that is now running in Azure. Now I need to implement a recurrent service that will run everyday. The main problem is I do now know the best and safer way to achieve it since I have never done anything like it.
I know that in Azure I can create a configurable scheduler or webjob that will call an endpoint recurrently, but for that I think my WebApi needs to expose the endpoint to be accessed. To be honest, this would facilitate my life since I have all my code there with easy access to the storages and stuff, but I have no idea if it can't cause a security problem.
I also read about Fluent Scheduler which can run in my WebApi and I liked this approach, but sincerely I do not know what is the best way to achieve what I pretend.

I suggest you create a WebJob and use the Azure Scheduler to schedule it to run once per day at a set time.
Microsoft has some great documentation, check out the section "Create a scheduled WebJob using the Azure Scheduler".

Related

Deactivate / Activate whole azure subscription with API call

We would like have a DR and staging subscriptions at my Azure. Also we do not want to pay for not used resources. We have Continuous deployment server. We would like to have the same deployment process in different environments.
Process
1.We read the current live subscription configuration from Azure resource manager
2.Modify some parts
3.Create DR and Staging
4.Deactivate them when not used using API calls triggered from the Continuous deployment server
5.Activate them when not used using API calls triggered from the Continuous deployment server
From time to time we are updating the resources.
Questions
What are the best practices ?
What are the API calls we can use?
I would argue that this is not possible (I might be wrong, never tried disabling subscription with active resources and see what happens) and not viable (for sure).
First of all, most PaaS offering cannot be switched off in Azure. That means you cannot achieve what you want (well, unless you can disable the entire sub and enable it after with all the resources starting to work like nothing happened). To try and figure the REST call to disable the sub I would go and capture the rest request with fiddler and try to reproduce it. Because I'm quite sure this call is not documented
The route I would go in this case - I would create ARM templates to make deployments repeatable and use those to deploy needed resources into prod\dev\stage\whatever with a flip of a switch. This would allow you to have the same deployment process you crave for.

Azure worker role automation

I created my custom Azure Worker Role. This code is ready. What I'm trying to do is to create instances of this Azure-Worker-Role in specific Azure data-center, at the requested time. For example, I'm want to send command to Azure to create 10 instances of my Custom-Azure-Worker in West-Europe data-center - now.
It's important to pass this command also a parameter that will be the input problem to be solved by my workers.
I pretty sure that this automation task must be covered by Azure automation. Is that true? Looking for more information\directions.
Thank you!
You can use Azure Management Libraries to create and deploy your cloud services from C# code. Just create application (eg ASP.NET MVC) to manage your cloud services by sending commands and deploy it also on Azure or even keep it locally.
See this article for more details http://www.bradygaster.com/post/getting-started-with-the-windows-azure-management-libraries
You'll want to leverage the service management API to spin up and tear down roles. It can be accessed any number of way, including directly via REST.
RE: providing a parameter to the worker role, one option is leveraging the cloud service configuration file that you provide with the cspkg. Define specifics for the role there.
Depending on the complexity or simplicity of your scenario, you may also get away with simply having a table in storage that you personally poke with desired configuration values and that the worker can read to retrieve.
The Azure Automation service should definitely be able to automate this task for you. Anything you can script via the Azure PowerShell module, can be imported as a runbook and called manually, via a third-party system, or on a schedule in Azure Automation.
Whether there is an existing runbook for the specific task you are looking to automate, I do not know. But Azure Automation has a gallery of community-contributed content for many common processes, so this may be available there.

Saving complete azure configuration to file?

Is there any way to save the complete state of my azure configuration?
Basically, I just created a demo for a project I'm working on. This demo has a website/webjob, scheduler, storage queue, storage blob, redis cache and documentDB. I have configured these components in terms of size/scale/schedules but now the demo is done.
I don't want to pay for these services and I don't need them online for now. However, I don't want to have to recreate and reconfigure them if I need to relaunch the demo in a month.
Is there a way to save my current azure configurations to a file and then to be able to recreate all the services again automatically (with a script or a small program)?
Thanks!
This is a very good question, that sums up a historical problem we're in the process of making easier and more flexible. I'll answer this question with two parts.
First and foremost, you have tools like the PowerShell cmdlets now, that you can script out the creation of an entire "world" in Azure and then re-run whenever you want, against a subscription, to scaffold out a whole architecture. You can also use the management libraries for .NET to do this from a .NET application. When we embarked on the VS WebJobs tooling, for instance, I worked up a prototype for my developers on using MAML to create WebJobs and scheduler job collections. You can see the demo code for that here: https://github.com/bradygaster/maml-demo-scheduled-webjob-creator
We've also recently embarked on new mission of re-creating a lot of the management APIs so that they support the notion of templates and resource groups, to marry up with the new portal experience. Here's a great MSDN article that discusses how the PowerShell cmdlets for the Gallery could be used to pull down a list of the various templates that could then be pushed back up as fully-baked architectures running in Azure. You have the capability of building these templates yourself, then you could use these cmdlets to fan out and create things that you write up in your own custom templates. http://msdn.microsoft.com/en-us/library/dn654596.aspx
Hope this helps!
For Azure websites you can use the Back and Restore option to store the site and restore it back when you want to demo again, But all you have to do is Stop the services and you should be able to keep the demo without incurring cost.

Create Azure task scheduler

We are going to host our ASP.Net web site on Azure server. I am not quite familiar with Azure. I need to create some kind of scheduler which will send request to google API once a week and save response data to DB. I read some articles about Worker Role. Is it suitable for this? How it should be deployed to the Azure server? Any other solutions?
You could certainly make use of Worker Role for that purpose however I would not recommend going down that route as you are only going to use the functionality once a week. Or in other words you would be under utilizing the resources. Do take a look at Windows Azure Mobile Service Scheduler: http://www.windowsazure.com/en-us/develop/mobile/tutorials/schedule-backend-tasks/. Other alternative would be use a 3rd party service like Aditi Scheduler: http://www.aditicloud.com/. There's also a website which also allows you to do the same functionality (I'm sorry I forgot the name of that site :)).
If you're still keen on doing it through Windows Azure Worker Role, I wrote a blog post about the same which you may find useful: http://gauravmantri.com/2013/01/23/building-a-simple-task-scheduler-in-windows-azure/.

Windows Azure for simulation

We are thinking of using Windows Azure for simulation. ~100 VM nodes each working on it's problem set and reporting back the result to a Master node.
I have created VM instances from the web UI. In order for this to work, we would need to use Azure API to bring servers up and shut them down once they are done.
Does anyone have any experience with something like this? I am looking for advise, gotchas etc.
thanks.
You sure can do it and I have helped other to make it happen on hundreds on nodes. Take a look at Windows Azure Rest API to configure your role as described here. While others may have other idea, I think the general steps would be as below:
Create a master machine or a webrole to manage your roles using REST API
Create a worker role instance and use it to clone multiple instances as if needed
Use REST API to start and shutdown worker role along with update the instance count when in need
Use Azure Boot Strapper to bootstrap the VM depend on your requirement
Azure REST based Service Management API can work from a web app or a standalone app, so you can also have a web role to make it happen from anywhere in world. This way you don't need any on premise components at all as it will be totally cloud solution. If you need any help on creating web role I sure can help.
You can provision Virtual Machines using Service Management REST API (there's also a managed API on NuGet).
But in your case you might want to consider using Cloud Services (PaaS). With Cloud Services you simply build your application, you package it and deploy it. Then using the portal or the management API you can simply configure the number of instances. There is even a command line tool (csmanage.exe) which allows you to to change the number of instances through the service configuration.

Resources