Browse files

Implement rollbackUpgradeOrUpdate API

  • Loading branch information...
1 parent 3b14524 commit 503674eae632ae11524799d52cc8c6d9485119a2 @ogail ogail committed Aug 10, 2012
View
2 WindowsAzure/Common/Internal/Resources.php
@@ -269,6 +269,7 @@ class Resources
const QPV_WALK_UPGRADE_DOMAIN = 'walkupgradedomain';
const QPV_REBOOT = 'reboot';
const QPV_REIMAGE = 'reimage';
+ const QPV_ROLLBACK = 'rollback';
// Request body content types
const URL_ENCODED_CONTENT_TYPE = 'application/x-www-form-urlencoded';
@@ -359,6 +360,7 @@ class Resources
const XTAG_UPGRADE_DEPLOYMENT = 'UpgradeDeployment';
const XTAG_UPGRADE_DOMAIN = 'UpgradeDomain';
const XTAG_WALK_UPGRADE_DOMAIN = 'WalkUpgradeDomain';
+ const XTAG_ROLLBACK_UPDATE_OR_UPGRADE = 'RollbackUpdateOrUpgrade';
// Service Bus
const LIST_TOPICS_PATH = '$Resources/Topics';
View
8 WindowsAzure/ServiceManagement/Internal/IServiceManagement.php
@@ -533,16 +533,16 @@ public function reimageRoleInstance($name, $roleName, $options);
* deployment environment (staging or production), or by specifying the
* deployment's unique name.
*
- * @param string $name The hosted service name.
- * @param string $mode Specifies whether the rollback
+ * @param string $name The hosted service name.
+ * @param string $mode Specifies whether the rollback
* should proceed automatically or not. Auto, The rollback proceeds without
* further user input. Manual, You must call the walkUpgradeDomain API to apply
* the rollback to each upgrade domain.
- * @param boolean $force Specifies whether the rollback
+ * @param boolean $force Specifies whether the rollback
* should proceed even when it will cause local data to be lost from some role
* instances. True if the rollback should proceed; otherwise false if the
* rollback should fail.
- * @param RollbackUpdateOrUpgradeOptions $options The optional parameters.
+ * @param GetDeploymentOptions $options The optional parameters.
*
* @return none
*
View
43 WindowsAzure/ServiceManagement/ServiceManagementRestProxy.php
@@ -1449,23 +1449,56 @@ public function reimageRoleInstance($name, $roleName, $options)
* deployment environment (staging or production), or by specifying the
* deployment's unique name.
*
- * @param string $name The hosted service name.
- * @param string $mode Specifies whether the rollback
+ * @param string $name The hosted service name.
+ * @param string $mode Specifies whether the rollback
* should proceed automatically or not. Auto, The rollback proceeds without
* further user input. Manual, You must call the walkUpgradeDomain API to apply
* the rollback to each upgrade domain.
- * @param boolean $force Specifies whether the rollback
+ * @param boolean $force Specifies whether the rollback
* should proceed even when it will cause local data to be lost from some role
* instances. True if the rollback should proceed; otherwise false if the
* rollback should fail.
- * @param RollbackUpdateOrUpgradeOptions $options The optional parameters.
+ * @param GetDeploymentOptions $options The optional parameters.
*
* @return none
*
* @see http://msdn.microsoft.com/en-us/library/windowsazure/hh403977.aspx
*/
public function rollbackUpdateOrUpgrade($name, $mode, $force, $options)
{
- throw new \Exception(Resources::NOT_IMPLEMENTED_MSG);
+ Validate::isString($name, 'name');
+ Validate::notNullOrEmpty($name, 'name');
+ Validate::isString($mode, 'mode');
+ Validate::isTrue(Mode::isValid($mode), Resources::INVALID_CHANGE_MODE_MSG);
+ Validate::isBoolean($force, 'force');
+ Validate::notNullOrEmpty($force, 'force');
+ Validate::notNullOrEmpty($options, 'options');
+
+ $xmlElements = array(
+ Resources::XTAG_MODE => $mode,
+ Resources::XTAG_FORCE => Utilities::booleanToString($force),
+ );
+ $body = $this->_createRequestXml(
+ $xmlElements,
+ Resources::XTAG_ROLLBACK_UPDATE_OR_UPGRADE
+ );
+ $context = new HttpCallContext();
+ $context->setMethod(Resources::HTTP_POST);
+ $context->setPath($this->_getDeploymentPath($name, $options) . '/');
+ $context->addStatusCode(Resources::STATUS_ACCEPTED);
+ $context->addQueryParameter(
+ Resources::QP_COMP,
+ Resources::QPV_ROLLBACK
+ );
+ $context->setBody($body);
+ $context->addHeader(
+ Resources::CONTENT_TYPE,
+ Resources::XML_CONTENT_TYPE
+ );
+
+ assert(Utilities::endsWith($context->getPath(), '/'));
+ $response = $this->sendContext($context);
+
+ return AsynchronousOperationResult::create($response->getHeader());
}
}
View
12 tests/framework/ServiceManagementRestProxyTestBase.php
@@ -257,6 +257,18 @@ public function waitUntilDeploymentReachStatus($name, $status)
} while($currentStatus != $status);
}
+ public function waitUntilRollbackIsAllowed($name)
+ {
+ $options = new GetDeploymentOptions();
+ $options->setSlot($this->defaultSlot);
+
+ do {
+ $result = $this->restProxy->getDeployment($name, $options);
+ $deployment = $result->getDeployment();
+ $rollbackAllowed = $deployment->getRollbackAllowed();
+ } while(!$rollbackAllowed);
+ }
+
public function waitUntilRoleInstanceReachStatus($name, $state, $roleInstanceName)
{
$options = new GetDeploymentOptions();
View
48 tests/unit/WindowsAzure/ServiceManagement/ServiceManagementRestProxyTest.php
@@ -1185,4 +1185,52 @@ public function testReimageRoleInstance()
$webRoleInstance = $roleInstanceList[0];
$this->assertEquals('StoppedVM', $webRoleInstance->getInstanceStatus());
}
+
+ /**
+ * @covers WindowsAzure\ServiceManagement\ServiceManagementRestProxy::rollbackUpdateOrUpgrade
+ * @covers WindowsAzure\ServiceManagement\ServiceManagementRestProxy::_getDeploymentPath
+ * @covers WindowsAzure\ServiceManagement\ServiceManagementRestProxy::_getPath
+ * @covers WindowsAzure\ServiceManagement\ServiceManagementRestProxy::_createRequestXml
+ * @covers WindowsAzure\ServiceManagement\Models\AsynchronousOperationResult::create
+ * @group Deployment
+ */
+ public function testRollbackUpgradeOrUpdate()
+ {
+ $name = 'testRollbackUpgradeOrUpdate';
+ $newConfig = '<?xml version="1.0" encoding="utf-8"?>
+ <ServiceConfiguration serviceName="WindowsAzureProject2" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="1" osVersion="*">
+ <Role name="WebRole1">
+ <Instances count="2" />
+ <ConfigurationSettings>
+ <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=false" />
+ </ConfigurationSettings>
+ </Role>
+ <Role name="WorkerRole1">
+ <Instances count="2" />
+ <ConfigurationSettings>
+ <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=false" />
+ </ConfigurationSettings>
+ </Role>
+ </ServiceConfiguration>';
+ $this->createComplexDeployment($name);
+ $options = new ChangeDeploymentConfigurationOptions();
+ $options->setSlot($this->defaultSlot);
+ $this->restProxy->changeDeploymentConfiguration($name, $newConfig, $options);
+ $mode = Mode::AUTO;
+ $force = true;
+ $expectedInstanceCount = 4;
+
+ $this->waitUntilRollbackIsAllowed($name);
+
+ // Test
+ $result = $this->restProxy->rollbackUpdateOrUpgrade($name, $mode, $force, $options);
+
+ // Block until reboot request is completed
+ $this->blockUntilAsyncSucceed($result);
+
+ // Assert
+ $result = $this->restProxy->getDeployment($name, $options);
+ $deployment = $result->getDeployment();
+ $this->assertCount($expectedInstanceCount, $deployment->getRoleInstanceList());
+ }
}

0 comments on commit 503674e

Please sign in to comment.