Skip to content

Commit

Permalink
Merge pull request Azure#34 from ogail/dev
Browse files Browse the repository at this point in the history
Implement rebootRoleInstace API

Code Review: christav and gcheng
  • Loading branch information
Abdelrahman Elogeel authored and Abdelrahman Elogeel committed Aug 10, 2012
2 parents cae03e1 + 47813ad commit 64ad560
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 36 deletions.
2 changes: 2 additions & 0 deletions WindowsAzure/Common/Internal/Resources.php
Expand Up @@ -156,6 +156,7 @@ class Resources
const CONTENT_ENCODING = 'content-encoding';
const CONTENT_LANGUAGE = 'content-language';
const CONTENT_LENGTH = 'content-length';
const CONTENT_LENGTH_NO_SPACE = 'contentlength';
const CONTENT_MD5 = 'content-md5';
const CONTENT_TYPE = 'content-type';
const CONTENT_ID = 'content-id';
Expand Down Expand Up @@ -266,6 +267,7 @@ class Resources
const QPV_STATUS = 'status';
const QPV_UPGRADE = 'upgrade';
const QPV_WALK_UPGRADE_DOMAIN = 'walkupgradedomain';
const QPV_REBOOT = 'reboot';

// Request body content types
const URL_ENCODED_CONTENT_TYPE = 'application/x-www-form-urlencoded';
Expand Down
Expand Up @@ -497,9 +497,9 @@ public function walkUpgradeDomain($name, $upgradeDomain, $options);
* environment (staging or production), or by specifying the deployment's unique
* name.
*
* @param string $name The hosted service name.
* @param string $roleName The role instance name.
* @param RebootRoleInstanceOptions $options The optional parameters.
* @param string $name The hosted service name.
* @param string $roleName The role instance name.
* @param GetDeploymentOptions $options The optional parameters.
*
* @return AsynchronousOperationResult
*
Expand Down
86 changes: 54 additions & 32 deletions WindowsAzure/ServiceManagement/ServiceManagementRestProxy.php
Expand Up @@ -165,6 +165,40 @@ private function _getDeploymentPathUsingName($name, $deploymentName)
return $this->_getPath($path, $deploymentName);
}

private function _getRoleInstancePath($name, $options, $roleName)
{
$path = $this->_getDeploymentPath($name, $options) . '/roleinstances';
return "$path/$roleName";
}

/**
* Gets the deployment URI path using the slot or name.
*
* @param string $name The hosted service name.
* @param GetDeploymentOptions $options The optional parameters.
*
* @return string
*/
private function _getDeploymentPath($name, $options)
{
$slot = $options->getSlot();
$deploymentName = $options->getDeploymentName();
$path = null;

Validate::isTrue(
!empty($slot) || !empty($deploymentName),
Resources::INVALID_DEPLOYMENT_LOCATOR_MSG
);

if (!empty($slot)) {
$path = $this->_getDeploymentPathUsingSlot($name, $slot);
} else {
$path = $this->_getDeploymentPathUsingName($name, $deploymentName);
}

return $path;
}

/**
* Constructs URI path for storage service key.
*
Expand Down Expand Up @@ -961,34 +995,6 @@ public function createDeployment(
return AsynchronousOperationResult::create($response->getHeader());
}

/**
* Gets the deployment URI path using the slot or name.
*
* @param string $name The hosted service name.
* @param GetDeploymentOptions $options The optional parameters.
*
* @return string
*/
private function _getDeploymentPath($name, $options)
{
$slot = $options->getSlot();
$deploymentName = $options->getDeploymentName();
$path = null;

Validate::isTrue(
!empty($slot) || !empty($deploymentName),
Resources::INVALID_DEPLOYMENT_LOCATOR_MSG
);

if (!empty($slot)) {
$path = $this->_getDeploymentPathUsingSlot($name, $slot);
} else {
$path = $this->_getDeploymentPathUsingName($name, $deploymentName);
}

return $path;
}

/**
* Returns configuration information, status, and system properties for a
* deployment.
Expand Down Expand Up @@ -1359,17 +1365,33 @@ public function walkUpgradeDomain($name, $upgradeDomain, $options)
* environment (staging or production), or by specifying the deployment's unique
* name.
*
* @param string $name The hosted service name.
* @param string $roleName The role instance name.
* @param RebootRoleInstanceOptions $options The optional parameters.
* @param string $name The hosted service name.
* @param string $roleName The role instance name.
* @param GetDeploymentOptions $options The optional parameters.
*
* @return AsynchronousOperationResult
*
* @see http://msdn.microsoft.com/en-us/library/windowsazure/gg441298.aspx
*/
public function rebootRoleInstance($name, $roleName, $options)
{
throw new \Exception(Resources::NOT_IMPLEMENTED_MSG);
Validate::isString($name, 'name');
Validate::notNullOrEmpty($name, 'name');
Validate::isString($roleName, 'roleName');
Validate::notNullOrEmpty($roleName, 'roleName');
Validate::notNullOrEmpty($options, 'options');

$context = new HttpCallContext();
$context->setMethod(Resources::HTTP_POST);
$context->setPath($this->_getRoleInstancePath($name, $options, $roleName));
$context->addStatusCode(Resources::STATUS_ACCEPTED);
$context->addQueryParameter(Resources::QP_COMP, Resources::QPV_REBOOT);
$context->addHeader(Resources::CONTENT_TYPE, Resources::XML_CONTENT_TYPE);
$context->addHeader(Resources::CONTENT_LENGTH_NO_SPACE, 0);

$response = $this->sendContext($context);

return AsynchronousOperationResult::create($response->getHeader());
}

/**
Expand Down
13 changes: 13 additions & 0 deletions tests/framework/ServiceManagementRestProxyTestBase.php
Expand Up @@ -244,6 +244,19 @@ public function createComplexDeployment($name, $slot = null, $deploymentName = n
$this->createdDeployments[] = $name;
}

public function waitUntilDeploymentReachStatus($name, $status)
{
$options = new GetDeploymentOptions();
$options->setSlot($this->defaultSlot);
$currentStatus = null;

do {
$result = $this->restProxy->getDeployment($name, $options);
$deployment = $result->getDeployment();
$currentStatus = $deployment->getStatus();
} while($currentStatus != $status);
}

public function createDeployment($name, $slot = null, $deploymentName = null, $options = null)
{
$deploymentName = is_null($deploymentName) ? $name : $deploymentName;
Expand Down
Expand Up @@ -40,6 +40,7 @@
use WindowsAzure\ServiceManagement\Models\DeploymentStatus;
use WindowsAzure\ServiceManagement\Models\Mode;
use WindowsAzure\ServiceManagement\Models\UpgradeDeploymentOptions;
use WindowsAzure\ServiceManagement\Models\CreateDeploymentOptions;

/**
* Unit tests for class ServiceManagementRestProxy
Expand Down Expand Up @@ -1068,7 +1069,7 @@ public function testWalkUpgradeDomain()
$packageUrl = TestResources::complexPackageUrl();
$label = base64_encode($name . 'upgraded');
$force = true;
$options = new UpgradeDeploymentOptions();
$options = new GetDeploymentOptions();
$options->setDeploymentName($name);
$expectedInstancesCount = 4;

Expand Down Expand Up @@ -1098,4 +1099,45 @@ public function testWalkUpgradeDomain()
$deployment = $result->getDeployment();
$this->assertCount($expectedInstancesCount, $deployment->getRoleInstanceList());
}

/**
* @covers WindowsAzure\ServiceManagement\ServiceManagementRestProxy::rebootRoleInstance
* @covers WindowsAzure\ServiceManagement\ServiceManagementRestProxy::_getRoleInstancePath
* @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 testRebootRoleInstance()
{
// Setup
$name = 'testRebootRoleInstance';
$roleName = 'WebRole1_IN_0';
$options = new CreateDeploymentOptions();
$options->setStartDeployment(true);
$this->createDeployment(
$name,
$this->defaultSlot,
$name,
$options
);
$options = new GetDeploymentOptions();
$options->setDeploymentName($name);

$this->waitUntilDeploymentReachStatus($name, DeploymentStatus::RUNNING);

// Test
$result = $this->restProxy->rebootRoleInstance($name, $roleName, $options);

// Block until reboot request is completed
$this->blockUntilAsyncSucceed($result);

// Assert
$result = $this->restProxy->getDeployment($name, $options);
$deployment = $result->getDeployment();
$roleInstanceList = $deployment->getRoleInstanceList();
$webRoleInstance = $roleInstanceList[0];
$this->assertEquals('StartingVM', $webRoleInstance->getInstanceStatus());
}
}

0 comments on commit 64ad560

Please sign in to comment.