Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implement upgradeDeployment API

  • Loading branch information...
commit 792863e6ebc47dc3f12737d83ed94759f4c3f5ce 1 parent 5cfa165
Abdelrahman Elogeel ogail authored
4 WindowsAzure/Common/Internal/Resources.php
View
@@ -264,6 +264,7 @@ class Resources
const QPV_REGENERATE = 'regenerate';
const QPV_CONFIG = 'config';
const QPV_STATUS = 'status';
+ const QPV_UPGRADE = 'upgrade';
// Request body content types
const URL_ENCODED_CONTENT_TYPE = 'application/x-www-form-urlencoded';
@@ -349,6 +350,9 @@ class Resources
const XTAG_CHANGE_CONFIGURATION = 'ChangeConfiguration';
const XTAG_MODE = 'Mode';
const XTAG_UPDATE_DEPLOYMENT_STATUS = 'UpdateDeploymentStatus';
+ const XTAG_ROLE_TO_UPGRADE = 'RoleToUpgrade';
+ const XTAG_FORCE = 'Force';
+ const XTAG_UPGRADE_DEPLOYMENT = 'UpgradeDeployment';
// Service Bus
const LIST_TOPICS_PATH = '$Resources/Topics';
6 WindowsAzure/ServiceManagement/Models/GetDeploymentOptions.php
View
@@ -39,8 +39,14 @@
*/
class GetDeploymentOptions
{
+ /**
+ * @var string
+ */
private $_slot;
+ /**
+ * @var string
+ */
private $_deploymentName;
72 WindowsAzure/ServiceManagement/Models/UpgradeDeploymentOptions.php
View
@@ -0,0 +1,72 @@
+<?php
+
+/**
+ * LICENSE: 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.
+ *
+ * PHP version 5
+ *
+ * @category Microsoft
+ * @package WindowsAzure\ServiceManagement\Models
+ * @author Azure PHP SDK <azurephpsdk@microsoft.com>
+ * @copyright 2012 Microsoft Corporation
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
+ * @link https://github.com/windowsazure/azure-sdk-for-php
+ */
+
+namespace WindowsAzure\ServiceManagement\Models;
+use WindowsAzure\Common\Internal\Validate;
+
+/**
+ * The optional parameters for upgradeDeployment API.
+ *
+ * @category Microsoft
+ * @package WindowsAzure\ServiceManagement\Models
+ * @author Azure PHP SDK <azurephpsdk@microsoft.com>
+ * @copyright 2012 Microsoft Corporation
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
+ * @version Release: @package_version@
+ * @link https://github.com/windowsazure/azure-sdk-for-php
+ */
+class UpgradeDeploymentOptions extends GetDeploymentOptions
+{
+ /**
+ * @var string
+ */
+ private $_roleToUpgrade;
+
+ /**
+ * Gets the role to upgrade name.
+ *
+ * The name of the specific role to upgrade.
+ *
+ * @return string
+ */
+ public function getRoleToUpgrade()
+ {
+ return $this->_roleToUpgrade;
+ }
+
+ /**
+ * Sets the role to upgrade name.
+ *
+ * @param string $roleToUpgrade The role to upgrade name.
+ *
+ * @return none
+ */
+ public function setRoleToUpgrade($roleToUpgrade)
+ {
+ Validate::isString($roleToUpgrade, 'roleToUpgrade');
+ Validate::notNullOrEmpty($roleToUpgrade, 'roleToUpgrade');
+
+ $this->_roleToUpgrade = $roleToUpgrade;
+ }
+}
50 WindowsAzure/ServiceManagement/ServiceManagementRestProxy.php
View
@@ -50,6 +50,7 @@
use WindowsAzure\ServiceManagement\Models\CreateDeploymentOptions;
use WindowsAzure\ServiceManagement\Models\GetDeploymentResult;
use WindowsAzure\ServiceManagement\Models\DeploymentStatus;
+use WindowsAzure\ServiceManagement\Models\Mode;
/**
* This class constructs HTTP requests and receive HTTP responses for service
@@ -1192,11 +1193,11 @@ public function updateDeploymentStatus($name, $status, $options)
);
Validate::notNullOrEmpty($options, 'options');
- $body = $this->_createRequestXml(
+ $body = $this->_createRequestXml(
array(Resources::XTAG_STATUS => $status),
Resources::XTAG_UPDATE_DEPLOYMENT_STATUS
);
- $context = new HttpCallContext();
+ $context = new HttpCallContext();
$context->setMethod(Resources::HTTP_POST);
$context->setPath($this->_getDeploymentPath($name, $options) . '/');
$context->addStatusCode(Resources::STATUS_ACCEPTED);
@@ -1255,7 +1256,50 @@ public function upgradeDeployment(
$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::isString($packageUrl, 'packageUrl');
+ Validate::notNullOrEmpty($packageUrl, 'packageUrl');
+ Validate::isString($configuration, 'configuration');
+ Validate::notNullOrEmpty($configuration, 'configuration');
+ Validate::isString($label, 'label');
+ Validate::notNullOrEmpty($label, 'label');
+ Validate::isBoolean($force, 'force');
+ Validate::notNullOrEmpty($force, 'force');
+ Validate::notNullOrEmpty($options, 'options');
+
+ $xmlElements = array(
+ Resources::XTAG_MODE => $mode,
+ Resources::XTAG_PACKAGE_URL => $packageUrl,
+ Resources::XTAG_CONFIGURATION => $configuration,
+ Resources::XTAG_LABEL => $label,
+ Resources::XTAG_ROLE_TO_UPGRADE => $options->getRoleToUpgrade(),
+ Resources::XTAG_FORCE => Utilities::booleanToString($force),
+ );
+ $body = $this->_createRequestXml(
+ $xmlElements,
+ Resources::XTAG_UPGRADE_DEPLOYMENT
+ );
+ $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_UPGRADE
+ );
+ $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());
}
/**
1  WindowsAzure/WindowsAzure.php
View
@@ -219,6 +219,7 @@ function($class) {
'windowsazure\\servicemanagement\\models\\roleinstance' => '/ServiceManagement/Models/RoleInstance.php',
'windowsazure\\servicemanagement\\models\\storageservice' => '/ServiceManagement/Models/StorageService.php',
'windowsazure\\servicemanagement\\models\\updateserviceoptions' => '/ServiceManagement/Models/UpdateServiceOptions.php',
+ 'windowsazure\\servicemanagement\\models\\upgradedeploymentoptions' => '/ServiceManagement/Models/UpgradeDeploymentOptions.php',
'windowsazure\\servicemanagement\\models\\upgradestatus' => '/ServiceManagement/Models/UpgradeStatus.php',
'windowsazure\\servicemanagement\\servicemanagementrestproxy' => '/ServiceManagement/ServiceManagementRestProxy.php',
'windowsazure\\serviceruntime\\internal\\acquirecurrentstate' => '/ServiceRuntime/Internal/AcquireCurrentState.php',
1  tests/WindowsAzureTests.php
View
@@ -249,6 +249,7 @@ function($class) {
'tests\\unit\\windowsazure\\servicemanagement\\models\\roletest' => '/unit/WindowsAzure/ServiceManagement/Models/RoleTest.php',
'tests\\unit\\windowsazure\\servicemanagement\\models\\storageservicetest' => '/unit/WindowsAzure/ServiceManagement/Models/StorageServiceTest.php',
'tests\\unit\\windowsazure\\servicemanagement\\models\\updateserviceoptionstest' => '/unit/WindowsAzure/ServiceManagement/Models/UpdateServiceOptionsTest.php',
+ 'tests\\unit\\windowsazure\\servicemanagement\\models\\upgradedeploymentoptionstest' => '/unit/WindowsAzure/ServiceManagement/Models/UpgradeDeploymentOptionsTest.php',
'tests\\unit\\windowsazure\\servicemanagement\\models\\upgradestatustest' => '/unit/WindowsAzure/ServiceManagement/Models/UpgradeStatusTest.php',
'tests\\unit\\windowsazure\\servicemanagement\\servicemanagementrestproxytest' => '/unit/WindowsAzure/ServiceManagement/ServiceManagementRestProxyTest.php',
'tests\\unit\\windowsazure\\serviceruntime\\internal\\acquirecurrentstatetest' => '/unit/WindowsAzure/ServiceRuntime/Internal/AcquireCurrentStateTest.php',
57 tests/unit/WindowsAzure/ServiceManagement/Models/UpgradeDeploymentOptionsTest.php
View
@@ -0,0 +1,57 @@
+<?php
+
+/**
+ * LICENSE: 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.
+ *
+ * PHP version 5
+ *
+ * @category Microsoft
+ * @package Tests\Unit\WindowsAzure\ServiceManagement\Models
+ * @author Azure PHP SDK <azurephpsdk@microsoft.com>
+ * @copyright 2012 Microsoft Corporation
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
+ * @link https://github.com/windowsazure/azure-sdk-for-php
+ */
+
+namespace Tests\Unit\WindowsAzure\ServiceManagement\Models;
+use WindowsAzure\ServiceManagement\Models\UpgradeDeploymentOptions;
+
+/**
+ * Unit tests for class UpgradeDeploymentOptions
+ *
+ * @category Microsoft
+ * @package Tests\Unit\WindowsAzure\ServiceManagement\Models
+ * @author Azure PHP SDK <azurephpsdk@microsoft.com>
+ * @copyright 2012 Microsoft Corporation
+ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
+ * @version Release: @package_version@
+ * @link https://github.com/windowsazure/azure-sdk-for-php
+ */
+class UpgradeDeploymentOptionsTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @covers WindowsAzure\ServiceManagement\Models\UpgradeDeploymentOptions::setRoleToUpgrade
+ * @covers WindowsAzure\ServiceManagement\Models\UpgradeDeploymentOptions::getRoleToUpgrade
+ */
+ public function testSetRoleToUpgrade()
+ {
+ // Setup
+ $expected = 'myrole';
+ $options = new UpgradeDeploymentOptions();
+
+ // Test
+ $options->setRoleToUpgrade($expected);
+
+ // Assert
+ $this->assertEquals($expected, $options->getRoleToUpgrade());
+ }
+}
46 tests/unit/WindowsAzure/ServiceManagement/ServiceManagementRestProxyTest.php
View
@@ -38,6 +38,8 @@
use WindowsAzure\ServiceManagement\Models\DeploymentSlot;
use WindowsAzure\ServiceManagement\Models\ChangeDeploymentConfigurationOptions;
use WindowsAzure\ServiceManagement\Models\DeploymentStatus;
+use WindowsAzure\ServiceManagement\Models\Mode;
+use WindowsAzure\ServiceManagement\Models\UpgradeDeploymentOptions;
/**
* Unit tests for class ServiceManagementRestProxy
@@ -1000,4 +1002,48 @@ public function testUpdateDeploymentStatus()
$deployment = $result->getDeployment();
$this->assertEquals(DeploymentStatus::SUSPENDED, $deployment->getStatus());
}
+
+ /**
+ * @covers WindowsAzure\ServiceManagement\ServiceManagementRestProxy::upgradeDeployment
+ * @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 testUpgradeDeployment()
+ {
+ // Setup
+ $name = 'testUpgradeDeployment';
+ $this->createDeployment($name);
+ $mode = Mode::AUTO;
+ $configuration = $this->encodedComplexConfiguration;
+ $packageUrl = TestResources::complexPackageUrl();
+ $label = base64_encode($name . 'upgraded');
+ $force = true;
+ $options = new UpgradeDeploymentOptions();
+ $options->setDeploymentName($name);
+ $expectedInstancesCount = 4;
+
+ // Test
+ $result = $this->restProxy->upgradeDeployment(
+ $name,
+ $mode,
+ $packageUrl,
+ $configuration,
+ $label,
+ $force,
+ $options
+ );
+
+ // Block until the status update is done.
+ $this->blockUntilAsyncSucceed($result);
+
+ // Assert
+ $options = new GetDeploymentOptions();
+ $options->setSlot(DeploymentSlot::PRODUCTION);
+ $result = $this->restProxy->getDeployment($name, $options);
+ $deployment = $result->getDeployment();
+ $this->assertCount($expectedInstancesCount, $deployment->getRoleInstanceList());
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.