Skip to content
Browse files

Adding Restart-AzureWebsite command

  • Loading branch information...
1 parent 6fc8783 commit 2f312ca0b5a58d15c985d7b51184ee59c1df8c50 @christav christav committed
View
1 .gitignore
@@ -8,5 +8,6 @@ TestResults
*.user
*.suo
*.orig
+*.ncrunchsolution
/Publish
/Package
View
1 WindowsAzurePowershell/src/Management.WebSites.Test/Management.WebSites.Test.csproj
@@ -113,6 +113,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="UnitTests\Cmdlets\RestartAzureWebsiteTests.cs" />
<Compile Include="UnitTests\Cmdlets\SetAzureWebSiteTests.cs" />
<Compile Include="UnitTests\Cmdlets\RestoreAzureWebsiteDeploymentTests.cs" />
<Compile Include="UnitTests\Cmdlets\SaveAzureWebsiteLogTests.cs" />
View
80 ...zurePowershell/src/Management.WebSites.Test/UnitTests/Cmdlets/RestartAzureWebsiteTests.cs
@@ -0,0 +1,80 @@
+// ----------------------------------------------------------------------------------
+//
+// Copyright 2011 Microsoft Corporation
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// http://www.apache.org/licenses/LICENSE-2.0
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+// ----------------------------------------------------------------------------------
+
+namespace Microsoft.WindowsAzure.Management.Websites.Test.UnitTests.Cmdlets
+{
+ using System;
+ using System.Text;
+ using System.Collections.Generic;
+ using System.Linq;
+ using Microsoft.VisualStudio.TestTools.UnitTesting;
+ using Microsoft.WindowsAzure.Management.Services;
+ using System.IO;
+ using Microsoft.WindowsAzure.Management.Test.Stubs;
+ using Microsoft.WindowsAzure.Management.Websites.Test.UnitTests.Utilities;
+ using Microsoft.WindowsAzure.Management.Websites.Services.WebEntities;
+ using Microsoft.WindowsAzure.Management.Websites.Cmdlets;
+ using Microsoft.WindowsAzure.Management.Test.Tests.Utilities;
+ using Microsoft.WindowsAzure.Management.Model;
+ using Microsoft.WindowsAzure.Management.Utilities;
+
+ [TestClass]
+ public class RestartAzureWebsiteTests
+ {
+ [TestInitialize]
+ public void SetupTest()
+ {
+ GlobalPathInfo.AzureAppDir = Path.Combine(Directory.GetCurrentDirectory(), "Windows Azure Powershell");
+ Extensions.CmdletSubscriptionExtensions.SessionManager = new InMemorySessionManager();
+ }
+
+ [TestMethod]
+ public void ProcessRestartWebsiteTest()
+ {
+ const string websiteName = "website1";
+ const string webspaceName = "webspace";
+
+ // Setup
+ SimpleWebsitesManagement channel = new SimpleWebsitesManagement();
+ channel.GetWebSpacesThunk = ar => new WebSpaces(new List<WebSpace> { new WebSpace { Name = webspaceName } });
+ channel.GetSitesThunk = ar => new Sites(new List<Site> { new Site { Name = websiteName, WebSpace = webspaceName } });
+ List<string> siteStates = new List<string>();
+
+ channel.UpdateSiteThunk = ar =>
+ {
+ Assert.AreEqual(webspaceName, ar.Values["webspaceName"]);
+ Site website = ar.Values["site"] as Site;
+ Assert.IsNotNull(website);
+ Assert.AreEqual(websiteName, website.Name);
+ Assert.IsNotNull(website.HostNames.FirstOrDefault(hostname => hostname.Equals(websiteName + General.AzureWebsiteHostNameSuffix)));
+ siteStates.Add(website.State);
+ };
+
+ // Test
+ RestartAzureWebsiteCommand restartAzureWebsiteCommand = new RestartAzureWebsiteCommand(channel)
+ {
+ ShareChannel = true,
+ CommandRuntime = new MockCommandRuntime(),
+ Name = websiteName,
+ CurrentSubscription = new SubscriptionData { SubscriptionId = "StartAzureWebSiteTests_ProcessStartWebsiteTest" }
+ };
+
+ restartAzureWebsiteCommand.ExecuteCommand();
+
+ Assert.AreEqual(2, siteStates.Count);
+ Assert.AreEqual("Stopped", siteStates[0]);
+ Assert.AreEqual("Running", siteStates[1]);
+ }
+ }
+}
View
83 WindowsAzurePowershell/src/Management.WebSites/Cmdlets/RestartAzureWebsite.cs
@@ -0,0 +1,83 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Microsoft.WindowsAzure.Management.WebSites.Cmdlets.Common;
+using System.Management.Automation;
+using Microsoft.WindowsAzure.Management.Websites.Services;
+using Microsoft.WindowsAzure.Management.Websites.Properties;
+using Microsoft.WindowsAzure.Management.Websites.Services.WebEntities;
+using Microsoft.WindowsAzure.Management.Utilities;
+using System.ServiceModel;
+
+namespace Microsoft.WindowsAzure.Management.Websites.Cmdlets
+{
+ [Cmdlet(VerbsLifecycle.Restart, "AzureWebsite")]
+ public class RestartAzureWebsiteCommand : WebsiteContextBaseCmdlet
+ {
+ /// <summary>
+ /// Initializes a new instance of the RestartAzureWebsiteCommand class.
+ /// </summary>
+ public RestartAzureWebsiteCommand()
+ : this(null)
+ {
+ }
+
+ public RestartAzureWebsiteCommand(IWebsitesServiceManagement channel)
+ {
+ Channel = channel;
+ }
+
+ internal override void ExecuteCommand()
+ {
+ Site website = GetWebSite();
+ Site siteUpdate = new Site
+ {
+ Name = Name,
+ HostNames = new [] { Name + General.AzureWebsiteHostNameSuffix }
+ };
+
+ InvokeInContext(() =>
+ {
+ siteUpdate.State = "Stopped";
+ RetryCall(s => Channel.UpdateSite(s, website.WebSpace, Name, siteUpdate));
+
+ siteUpdate.State = "Running";
+ RetryCall(s => Channel.UpdateSite(s, website.WebSpace, Name, siteUpdate));
+ });
+ }
+
+ private Site GetWebSite()
+ {
+ Site website = null;
+
+ InvokeInContext(() =>
+ {
+ website = RetryCall(s => Channel.GetSite(s, Name, null));
+ });
+
+ if (website == null)
+ {
+ throw new Exception(string.Format(Resources.InvalidWebsite, Name));
+ }
+
+ return website;
+ }
+
+ private void InvokeInContext(Action action)
+ {
+ InvokeInOperationContext(() =>
+ {
+ try
+ {
+ action();
+ }
+ catch (CommunicationException ex)
+ {
+ WriteErrorDetails(ex);
+ throw;
+ }
+ });
+ }
+ }
+}
View
1 WindowsAzurePowershell/src/Management.WebSites/Management.WebSites.csproj
@@ -132,6 +132,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Cmdlets\Common\DeploymentBaseCmdlet.cs" />
+ <Compile Include="Cmdlets\RestartAzureWebsite.cs" />
<Compile Include="Cmdlets\RestoreAzureWebsiteDeployment.cs" />
<Compile Include="Cmdlets\SaveAzureWebsiteLog.cs" />
<Compile Include="Cmdlets\GetAzureWebsiteDeployment.cs" />
View
113 ...owershell/src/Management.WebSites/Microsoft.WindowsAzure.Management.Websites.dll-Help.xml
@@ -1722,7 +1722,11 @@ C:\PS&gt; </maml:introduction>
<maml:linkText>Stop-AzureWebsite</maml:linkText>
<maml:uri/>
</maml:navigationLink>
- <maml:navigationLink>
+ <maml:navigationLink>
+ <maml:linkText>Restart-AzureWebsite</maml:linkText>
+ <maml:uri/>
+ </maml:navigationLink>
+ <maml:navigationLink>
<maml:linkText>Remove-AzureWebsite</maml:linkText>
<maml:uri/>
</maml:navigationLink>
@@ -1826,6 +1830,111 @@ C:\PS&gt; </maml:introduction>
<maml:linkText>Remove-AzureWebsite</maml:linkText>
<maml:uri/>
</maml:navigationLink>
- </maml:relatedLinks>
+ <maml:navigationLink>
+ <maml:linkText>Restart-AzureWebsite</maml:linkText>
+ <maml:uri/>
+ </maml:navigationLink>
+ </maml:relatedLinks>
</command:command>
+ <command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10">
+ <!--Generated by Help Cmdlet Editor-->
+ <command:details>
+ <command:name>Restart-AzureWebsite</command:name>
+ <maml:description>
+ <maml:para>Stop and then restart the specified Azure website</maml:para>
+ </maml:description>
+ <maml:copyright>
+ <maml:para />
+ <!--Add copy right info here.-->
+ </maml:copyright>
+ <command:verb>Restart</command:verb>
+ <command:noun>AzureWebsite</command:noun>
+ <!--Add Dev version info here.-->
+ <dev:version />
+ </command:details>
+ <maml:description>
+ <!--This is the Description section-->
+ <maml:para>Stop and then restart the specified Azure website</maml:para>
+ </maml:description>
+ <command:syntax>
+ <command:syntaxItem>
+ <maml:name>Restart-AzureWebsite</maml:name>
+ <command:parameter required = "false" variableLength = "false" globbing = "false" pipelineInput = "true (ByPropertyName)" position = "1" >
+ <maml:name>Name</maml:name>
+ <maml:description>
+ <maml:para>The name of the Azure website to restart</maml:para>
+ </maml:description>
+ <command:parameterValue required="true" variableLength = "false" >String</command:parameterValue>
+ </command:parameter>
+ </command:syntaxItem>
+ </command:syntax>
+ <command:parameters>
+ <command:parameter required="false" variableLength="false" globbing="false" pipelineInput="true (ByPropertyName)" position="1">
+ <maml:name>Name</maml:name>
+ <maml:description>
+ <maml:para>The name of the Azure website to restart</maml:para>
+ </maml:description>
+ <command:parameterValue required="true" variableLength="false">String</command:parameterValue>
+ <dev:type>
+ <maml:name>String</maml:name>
+ <maml:uri/>
+ </dev:type>
+ <dev:defaultValue></dev:defaultValue>
+ </command:parameter>
+ </command:parameters>
+ <command:inputTypes>
+ <command:inputType>
+ <dev:type>
+ <maml:name></maml:name>
+ <maml:uri/>
+ <maml:description>
+ <maml:para></maml:para>
+ </maml:description>
+ </dev:type>
+ <maml:description></maml:description>
+ </command:inputType>
+ </command:inputTypes>
+ <command:returnValues>
+ <command:returnValue>
+ <dev:type>
+ <maml:name></maml:name>
+ <maml:uri />
+ <maml:description>
+ <maml:para></maml:para>
+ </maml:description>
+ </dev:type>
+ <maml:description></maml:description>
+ </command:returnValue>
+ </command:returnValues>
+ <command:terminatingErrors>
+ </command:terminatingErrors>
+ <command:nonTerminatingErrors>
+ </command:nonTerminatingErrors>
+ <maml:alertSet>
+ <maml:title></maml:title>
+ <maml:alert>
+ <maml:para></maml:para>
+ </maml:alert>
+ </maml:alertSet>
+ <command:examples>
+ </command:examples>
+ <maml:relatedLinks>
+ <maml:navigationLink>
+ <maml:linkText>New-AzureWebsite</maml:linkText>
+ <maml:uri/>
+ </maml:navigationLink>
+ <maml:navigationLink>
+ <maml:linkText>Get-AzureWebsite</maml:linkText>
+ <maml:uri/>
+ </maml:navigationLink>
+ <maml:navigationLink>
+ <maml:linkText>Start-AzureWebsite</maml:linkText>
+ <maml:uri/>
+ </maml:navigationLink>
+ <maml:navigationLink>
+ <maml:linkText>Remove-AzureWebsite</maml:linkText>
+ <maml:uri/>
+ </maml:navigationLink>
+ </maml:relatedLinks>
+ </command:command>
</helpItems>

0 comments on commit 2f312ca

Please sign in to comment.
Something went wrong with that request. Please try again.