Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Azure

Running a healthy service in the cloud : Using the service management API (part 3) - Automating a deployment

3/23/2011 6:12:50 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

4. Automating a deployment

Even though you can do everything you need through the naked REST API of the service management service, it’s a lot easier to use something that provides a higher level of abstraction. REST is fine, but it’s too low-level for us on a daily basis.

There are two popular options to go with. The first is a collection of PowerShell commandlets that have been provided by Microsoft. These are useful when you’re integrating cloud management into your existing management scripts. You can find these commandlets at http://code.msdn.microsoft.com/azurecmdlets.

We might be using a higher-level tool, but you still need to provide the tool with the subscription ID of your Azure account and the thumbprint for the certificate you’ll be using to manage your account. You can enter these into the configuration file for the tool, csmanage.exe.config. The easiest place to find the ID and the thumbprint is on the Azure portal.

The csmanage application can work with one of three resources online: hosted services, storage services, or affinity groups. Each command you send will include a reference to the resource you want to work with.

Getting a List of Hosted Services

To get a simple list of the hosted services you have in your account, you can execute the following command at a command prompt. This command executes the same query you previously made manually.

csmanage.exe /list-hosted-services

When you run this command, the application connects to your account in the cloud and returns a list of the services you have. When we executed this command, we had just one hosted service, as shown in figure 2.

Figure 2. You can use the csmanage command-line tool to execute management commands against your account in the cloud. In this example, we used a simple command to list the hosted services we have.


After you have a list of your services, you next task is to create a deployment of your application.

Creating a Deployment

First, you need to create the package for your code. You’ve probably done this a thousand times by now, but right-click the Azure project and choose Publish.

When you’re using the management service, a service package has to be in BLOB storage for you to deploy it; you can’t upload it as part of the actual create-deployment command. What you can do is upload the package through any tool you want to use. In this example, we just want to upload the cspkg file. This BLOB container can be public or private, but it should probably be private. You don’t want some jokester on the inter-web to download your source package. Because the management call is signed, it’ll have access to your private BLOB containers, so you won’t have to provide the credentials. The configuration file will be uploaded when you run the create-deployment command. The following listing shows the command-line code for deploying a package.

Listing 3. Pushing a deployment to the cloud from the command line

That’s a lot to type in by hand. The most common use of csmanage is in an automated deployment script. You could make the deployment completely hands-off with enough script and PowerShell. When you execute the command in listing 3, there’ll be a slight pause as the configuration is uploaded and the management service deploys your bits. The output of the command is shown in figure 4.

Figure 4. The output from csmanage when you script out a deployment to staging. We’re deploying our ninja doughnut application, which has nothing to do with doughnuts or ninjas.


All this is wonderful, but you don’t want to just upload and deploy your code; you need to start it.

Starting the Code

You need to start your code so that the FC can start your site. The command to start everything is quite simple:

csmanage /update-deployment /slot:staging /hosted-service:aiademo1 /status:running


This command tells the management API that you want to update the deployment of your service that’s in the staging slot to running. (You can use the same command to set the status to suspended.) After you set the status to running, it can take a few minutes for the FC to get everything up and running. You can check on the status of each instance of your roles by using the view-deployment command:

csmanage /view-deployment /slot:staging /hosted-service:aiademo1

When you execute this command, you’ll get a detailed view of each instance. In this example, both of our instances were busy, as shown in figure 5. If we just wait a few minutes, they’ll flip to ready.

Figure 5. You can check the detailed status of each role instance by using the view-deployment option. In this example, our instances are busy because we’ve just deployed the package. In a moment, the status will change to ready.


When your instance status reads as ready, you can use a command to perform a VIP swap.

Performing a VIP Swap

Remember, a VIP swap occurs when you swap the virtual IPs for production and staging, performing a clean cutover from one environment to the other. Using a VIP swap is the simplest way to deploy a new version. You can always do an update domain walk, which is more complicated but provides the capability for a rolling upgrade.

You need a deployment in each slot to perform a VIP swap through the csmanage or REST interfaces. If you’re deploying for the first time to an empty environment, either deploy your first version into the production slot, or rerun the swap-deployment command and adjust the slot parameter to production.

To perform the VIP swap, execute the following command:

csmanage /swap-deployment /production-slot:ninjasV0 /source-deployment:ninjas
/hosted-service:aiademo1


Be careful when you type in this command. The third parameter, source-deployment, is different from what you would expect. Because the second parameter is production-slot, you would expect the third to be staging-slot. The naming isn’t terribly consistent. Another mystery is why you need to define the slot names at all. You can have only one slot of each anyway. Go figure.

Figure 6 shows the successful completion of the VIP swap.

Figure 6. The VIP swap has successfully swapped the staging and production slots. You need to provide the names of the deployments in each slot.


Now that you’ve swapped out to production and have fully tested the slot, you can tear down the staging slot.

Tearing Down a Deployment

Use the following command to suspend the state of the servers, and then delete the deployment:

csmanage /update-deployment /slot:staging /hosted-service:aiademo1 /
status:suspended

csmanage /delete-deployment /slot:staging /hosted-service:aiademo1

You need to execute these two commands back-to-back. You can’t delete a service while it’s running, so you have to wait for the first command to suspend the service to finish.

Figure 7 shows the successful completion of these commands.

Figure 7. After deploying and swapping your new version to production, you suspend the staging environment and then tear it down to stop the billing. This process involves two steps: first you must suspend the service, and then you delete it.


You’ve successfully automated the deployment of a cloud service, started it, moved it to production, and then finally stopped and tore down the old version of the service.

You’ve done this without having to use the portal. Even so, you still had to use the portal to upload your management certificates and create the initial service container.

Now to what people really care about in the cloud: dynamically scaling the number of instances that are running your service.

Other -----------------
- Running a healthy service in the cloud : Transferring diagnostic data
- Running a healthy service in the cloud : Configuring the diagnostic agent (part 3)
- Running a healthy service in the cloud : Configuring the diagnostic agent (part 2) - Diagnostic host configuration
- Running a healthy service in the cloud : Configuring the diagnostic agent (part 1) - Default configuration
- Running a healthy service in the cloud : Diagnostics in the cloud
- SOA Security with .NET and Windows Azure : Windows Identity Foundation (part 3)
- SOA Security with .NET and Windows Azure : Windows Identity Foundation (part 2) - Windows Cardspace & Active Directory Federation Services
- SOA Security with .NET and Windows Azure : Windows Identity Foundation (part 1) - Digital Identity
- SQL Azure and relational data : Common SQL Azure scenarios
- SQL Azure and relational data : Limitations of SQL Azure
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server