Microsoft_WindowsAzure
[ class tree: Microsoft_WindowsAzure ] [ index: Microsoft_WindowsAzure ] [ all elements ]

Source for file Manager.php

Documentation is available at Manager.php

  1. <?php
  2. /**
  3.  * Copyright (c) 2009 - 2011, RealDolmen
  4.  * All rights reserved.
  5.  *
  6.  * Redistribution and use in source and binary forms, with or without
  7.  * modification, are permitted provided that the following conditions are met:
  8.  *     * Redistributions of source code must retain the above copyright
  9.  *       notice, this list of conditions and the following disclaimer.
  10.  *     * Redistributions in binary form must reproduce the above copyright
  11.  *       notice, this list of conditions and the following disclaimer in the
  12.  *       documentation and/or other materials provided with the distribution.
  13.  *     * Neither the name of RealDolmen nor the
  14.  *       names of its contributors may be used to endorse or promote products
  15.  *       derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
  18.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20.  * DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
  21.  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26.  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  *
  28.  * @category   Microsoft
  29.  * @package    Microsoft_WindowsAzure
  30.  * @subpackage Diagnostics
  31.  * @copyright  Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
  32.  * @license    http://phpazure.codeplex.com/license
  33.  * @version    $Id: Storage.php 45989 2010-05-03 12:19:10Z unknown $
  34.  */
  35.  
  36. /**
  37.  * @see Microsoft_AutoLoader
  38.  */
  39. require_once dirname(__FILE__'/../../AutoLoader.php';
  40.  
  41. /**
  42.  * @category   Microsoft
  43.  * @package    Microsoft_WindowsAzure
  44.  * @subpackage Diagnostics
  45.  * @copyright  Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
  46.  * @license    http://phpazure.codeplex.com/license
  47.  */
  48. {
  49.     /**
  50.      * Blob storage client
  51.      * 
  52.      * @var Microsoft_WindowsAzure_Storage_Blob 
  53.      */
  54.     protected $_blobStorageClient = null;
  55.     
  56.     /**
  57.      * Control container name
  58.      * 
  59.      * @var string 
  60.      */
  61.     protected $_controlContainer = '';
  62.  
  63.     /**
  64.      * Create a new instance of Microsoft_WindowsAzure_Diagnostics_Manager
  65.      * 
  66.      * @param Microsoft_WindowsAzure_Storage_Blob $blobStorageClient Blob storage client
  67.      * @param string $controlContainer Control container name
  68.      */
  69.     public function __construct(Microsoft_WindowsAzure_Storage_Blob $blobStorageClient null$controlContainer 'wad-control-container')
  70.     {
  71.         $this->_blobStorageClient = $blobStorageClient;
  72.         $this->_controlContainer = $controlContainer;
  73.  
  74.         $this->_ensureStorageInitialized();
  75.     }
  76.  
  77.     /**
  78.      * Ensure storage has been initialized
  79.      */
  80.     protected function _ensureStorageInitialized()
  81.     {
  82.         if (!$this->_blobStorageClient->containerExists($this->_controlContainer)) {
  83.             $this->_blobStorageClient->createContainer($this->_controlContainer);
  84.         }
  85.     }
  86.     
  87.     /**
  88.      * Get default configuration values
  89.      * 
  90.      * @return Microsoft_WindowsAzure_Diagnostics_ConfigurationInstance 
  91.      */
  92.     public function getDefaultConfiguration()
  93.     {
  94.     }
  95.     
  96.     /**
  97.      * Checks if a configuration for a specific role instance exists.
  98.      * 
  99.      * @param string $roleInstance Role instance name, can be found in $_SERVER['RdRoleId'] when hosted on Windows Azure.
  100.      * @return boolean 
  101.      * @throws Microsoft_WindowsAzure_Diagnostics_Exception
  102.      */
  103.     public function configurationForRoleInstanceExists($roleInstance null)
  104.     {
  105.         if (is_null($roleInstance)) {
  106.             throw new Microsoft_WindowsAzure_Diagnostics_Exception('Role instance should be specified. Try reading $_SERVER[\'RdRoleId\'] for this information if the application is hosted on Windows Azure Fabric or Development Fabric.');
  107.         }
  108.  
  109.         return $this->_blobStorageClient->blobExists($this->_controlContainer$roleInstance);
  110.     }
  111.     
  112.     /**
  113.      * Checks if a configuration for current role instance exists. Only works on Development Fabric or Windows Azure Fabric.
  114.      * 
  115.      * @return boolean 
  116.      * @throws Microsoft_WindowsAzure_Diagnostics_Exception
  117.      */
  118.     public function configurationForCurrentRoleInstanceExists()
  119.     {
  120.         if (!isset($_SERVER['RdRoleId'])) {
  121.             throw new Microsoft_WindowsAzure_Diagnostics_Exception('Server variable \'RdRoleId\' is unknown. Please verify the application is running in Development Fabric or Windows Azure Fabric.');
  122.         }
  123.  
  124.         return $this->_blobStorageClient->blobExists($this->_controlContainer$this->_getCurrentRoleInstanceId());
  125.     }
  126.     
  127.     /**
  128.      * Get configuration for current role instance. Only works on Development Fabric or Windows Azure Fabric.
  129.      * 
  130.      * @return Microsoft_WindowsAzure_Diagnostics_ConfigurationInstance 
  131.      * @throws Microsoft_WindowsAzure_Diagnostics_Exception
  132.      */
  133.     public function getConfigurationForCurrentRoleInstance()
  134.     {
  135.         if (!isset($_SERVER['RdRoleId'])) {
  136.             throw new Microsoft_WindowsAzure_Diagnostics_Exception('Server variable \'RdRoleId\' is unknown. Please verify the application is running in Development Fabric or Windows Azure Fabric.');
  137.         }
  138.         return $this->getConfigurationForRoleInstance($this->_getCurrentRoleInstanceId());
  139.     }
  140.     
  141.     /**
  142.      * Get the current role instance ID. Only works on Development Fabric or Windows Azure Fabric.
  143.      * 
  144.      * @return string 
  145.      * @throws Microsoft_WindowsAzure_Diagnostics_Exception
  146.      */
  147.     protected function _getCurrentRoleInstanceId()
  148.     {
  149.         if (!isset($_SERVER['RdRoleId'])) {
  150.             throw new Microsoft_WindowsAzure_Diagnostics_Exception('Server variable \'RdRoleId\' is unknown. Please verify the application is running in Development Fabric or Windows Azure Fabric.');
  151.         }
  152.         
  153.         if (strpos($_SERVER['RdRoleId']'deployment('=== false{
  154.             return $_SERVER['RdRoleId'];
  155.         else {
  156.             $roleIdParts explode('.'$_SERVER['RdRoleId']);
  157.             return $roleIdParts[0'/' $roleIdParts[2'/' $_SERVER['RdRoleId'];
  158.         }
  159.  
  160.         if (!isset($_SERVER['RoleDeploymentID']&& !isset($_SERVER['RoleInstanceID']&& !isset($_SERVER['RoleName'])) {
  161.             throw new Exception('Server variables \'RoleDeploymentID\', \'RoleInstanceID\' and \'RoleName\' are unknown. Please verify the application is running in Development Fabric or Windows Azure Fabric.');
  162.         }
  163.         
  164.         if (strpos($_SERVER['RdRoleId']'deployment('=== false{
  165.             return $_SERVER['RdRoleId'];
  166.         else {
  167.             return $_SERVER['RoleDeploymentID''/' $_SERVER['RoleInstanceID''/' $_SERVER['RoleName'];
  168.         }
  169.     }
  170.     
  171.     /**
  172.      * Set configuration for current role instance. Only works on Development Fabric or Windows Azure Fabric.
  173.      * 
  174.      * @param Microsoft_WindowsAzure_Diagnostics_ConfigurationInstance $configuration Configuration to apply
  175.      * @throws Microsoft_WindowsAzure_Diagnostics_Exception
  176.      */
  177.     public function setConfigurationForCurrentRoleInstance(Microsoft_WindowsAzure_Diagnostics_ConfigurationInstance $configuration)
  178.     {
  179.         if (!isset($_SERVER['RdRoleId'])) {
  180.             throw new Microsoft_WindowsAzure_Diagnostics_Exception('Server variable \'RdRoleId\' is unknown. Please verify the application is running in Development Fabric or Windows Azure Fabric.');
  181.         }
  182.         
  183.         $this->setConfigurationForRoleInstance($this->_getCurrentRoleInstanceId()$configuration);
  184.     }
  185.     
  186.     /**
  187.      * Get configuration for a specific role instance
  188.      * 
  189.      * @param string $roleInstance Role instance name, can be found in $_SERVER['RdRoleId'] when hosted on Windows Azure.
  190.      * @return Microsoft_WindowsAzure_Diagnostics_ConfigurationInstance 
  191.      * @throws Microsoft_WindowsAzure_Diagnostics_Exception
  192.      */
  193.     public function getConfigurationForRoleInstance($roleInstance null)
  194.     {
  195.         if (is_null($roleInstance)) {
  196.             throw new Microsoft_WindowsAzure_Diagnostics_Exception('Role instance should be specified. Try reading $_SERVER[\'RdRoleId\'] for this information if the application is hosted on Windows Azure Fabric or Development Fabric.');
  197.         }
  198.  
  199.         if ($this->_blobStorageClient->blobExists($this->_controlContainer$roleInstance)) {
  200.             $configurationInstance new Microsoft_WindowsAzure_Diagnostics_ConfigurationInstance();
  201.             $configurationInstance->loadXml$this->_blobStorageClient->getBlobData($this->_controlContainer$roleInstance) );
  202.             return $configurationInstance;
  203.         }
  204.  
  205.     }
  206.     
  207.     /**
  208.      * Set configuration for a specific role instance
  209.      * 
  210.      * @param string $roleInstance Role instance name, can be found in $_SERVER['RdRoleId'] when hosted on Windows Azure.
  211.      * @param Microsoft_WindowsAzure_Diagnostics_ConfigurationInstance $configuration Configuration to apply
  212.      * @throws Microsoft_WindowsAzure_Diagnostics_Exception
  213.      */
  214.     public function setConfigurationForRoleInstance($roleInstance nullMicrosoft_WindowsAzure_Diagnostics_ConfigurationInstance $configuration)
  215.     {
  216.         if (is_null($roleInstance)) {
  217.             throw new Microsoft_WindowsAzure_Diagnostics_Exception('Role instance should be specified. Try reading $_SERVER[\'RdRoleId\'] for this information if the application is hosted on Windows Azure Fabric or Development Fabric.');
  218.         }
  219.  
  220.         $this->_blobStorageClient->putBlobData($this->_controlContainer$roleInstance$configuration->toXml()array()nullarray('Content-Type' => 'text/xml'));
  221.     }
  222. }

Documentation generated on Wed, 18 May 2011 12:06:41 +0200 by phpDocumentor 1.4.3