13 * to license@zend.com so we can send you a copy immediately. |
13 * to license@zend.com so we can send you a copy immediately. |
14 * |
14 * |
15 * @category Zend |
15 * @category Zend |
16 * @package Zend_Service_WindowsAzure |
16 * @package Zend_Service_WindowsAzure |
17 * @subpackage Diagnostics |
17 * @subpackage Diagnostics |
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
18 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
20 * @version $Id$ |
20 * @version $Id$ |
21 */ |
21 */ |
22 |
|
23 /** |
|
24 * @see Zend_Service_WindowsAzure_Storage_Blob |
|
25 */ |
|
26 require_once 'Zend/Service/WindowsAzure/Storage/Blob.php'; |
|
27 |
|
28 /** |
|
29 * @see Zend_Service_WindowsAzure_Diagnostics_Exception |
|
30 */ |
|
31 require_once 'Zend/Service/WindowsAzure/Diagnostics/Exception.php'; |
|
32 |
22 |
33 /** |
23 /** |
34 * @see Zend_Service_WindowsAzure_Diagnostics_ConfigurationInstance |
24 * @see Zend_Service_WindowsAzure_Diagnostics_ConfigurationInstance |
35 */ |
25 */ |
36 require_once 'Zend/Service/WindowsAzure/Diagnostics/ConfigurationInstance.php'; |
26 require_once 'Zend/Service/WindowsAzure/Diagnostics/ConfigurationInstance.php'; |
37 |
27 |
38 /** |
28 /** |
39 * @category Zend |
29 * @category Zend |
40 * @package Zend_Service_WindowsAzure |
30 * @package Zend_Service_WindowsAzure |
41 * @subpackage Diagnostics |
31 * @subpackage Diagnostics |
42 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
32 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
43 * @license http://framework.zend.com/license/new-bsd New BSD License |
33 * @license http://framework.zend.com/license/new-bsd New BSD License |
44 */ |
34 */ |
45 class Zend_Service_WindowsAzure_Diagnostics_Manager |
35 class Zend_Service_WindowsAzure_Diagnostics_Manager |
46 { |
36 { |
47 /** |
37 /** |
99 * @return boolean |
89 * @return boolean |
100 * @throws Zend_Service_WindowsAzure_Diagnostics_Exception |
90 * @throws Zend_Service_WindowsAzure_Diagnostics_Exception |
101 */ |
91 */ |
102 public function configurationForRoleInstanceExists($roleInstance = null) |
92 public function configurationForRoleInstanceExists($roleInstance = null) |
103 { |
93 { |
104 if ($roleInstance === null) { |
94 if (is_null($roleInstance)) { |
|
95 require_once 'Zend/Service/WindowsAzure/Diagnostics/Exception.php'; |
105 throw new Zend_Service_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.'); |
96 throw new Zend_Service_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.'); |
106 } |
97 } |
107 |
98 |
108 return $this->_blobStorageClient->blobExists($this->_controlContainer, $roleInstance); |
99 return $this->_blobStorageClient->blobExists($this->_controlContainer, $roleInstance); |
109 } |
100 } |
115 * @throws Zend_Service_WindowsAzure_Diagnostics_Exception |
106 * @throws Zend_Service_WindowsAzure_Diagnostics_Exception |
116 */ |
107 */ |
117 public function configurationForCurrentRoleInstanceExists() |
108 public function configurationForCurrentRoleInstanceExists() |
118 { |
109 { |
119 if (!isset($_SERVER['RdRoleId'])) { |
110 if (!isset($_SERVER['RdRoleId'])) { |
120 throw new Zend_Service_WindowsAzure_Diagnostics_Exception('Server variable \'RdRoleId\' is unknown. Please verify the application is running in Development Fabric or Windows Azure Fabric.'); |
111 require_once 'Zend/Service/WindowsAzure/Diagnostics/Exception.php'; |
121 } |
112 throw new Zend_Service_WindowsAzure_Diagnostics_Exception('Server variable \'RdRoleId\' is unknown. Please verify the application is running in Development Fabric or Windows Azure Fabric.'); |
122 |
113 } |
123 return $this->_blobStorageClient->blobExists($this->_controlContainer, $_SERVER['RdRoleId']); |
114 |
|
115 return $this->_blobStorageClient->blobExists($this->_controlContainer, $this->_getCurrentRoleInstanceId()); |
124 } |
116 } |
125 |
117 |
126 /** |
118 /** |
127 * Get configuration for current role instance. Only works on Development Fabric or Windows Azure Fabric. |
119 * Get configuration for current role instance. Only works on Development Fabric or Windows Azure Fabric. |
128 * |
120 * |
130 * @throws Zend_Service_WindowsAzure_Diagnostics_Exception |
122 * @throws Zend_Service_WindowsAzure_Diagnostics_Exception |
131 */ |
123 */ |
132 public function getConfigurationForCurrentRoleInstance() |
124 public function getConfigurationForCurrentRoleInstance() |
133 { |
125 { |
134 if (!isset($_SERVER['RdRoleId'])) { |
126 if (!isset($_SERVER['RdRoleId'])) { |
135 throw new Zend_Service_WindowsAzure_Diagnostics_Exception('Server variable \'RdRoleId\' is unknown. Please verify the application is running in Development Fabric or Windows Azure Fabric.'); |
127 require_once 'Zend/Service/WindowsAzure/Diagnostics/Exception.php'; |
136 } |
128 throw new Zend_Service_WindowsAzure_Diagnostics_Exception('Server variable \'RdRoleId\' is unknown. Please verify the application is running in Development Fabric or Windows Azure Fabric.'); |
137 return $this->getConfigurationForRoleInstance($_SERVER['RdRoleId']); |
129 } |
|
130 return $this->getConfigurationForRoleInstance($this->_getCurrentRoleInstanceId()); |
|
131 } |
|
132 |
|
133 /** |
|
134 * Get the current role instance ID. Only works on Development Fabric or Windows Azure Fabric. |
|
135 * |
|
136 * @return string |
|
137 * @throws Zend_Service_WindowsAzure_Diagnostics_Exception |
|
138 */ |
|
139 protected function _getCurrentRoleInstanceId() |
|
140 { |
|
141 if (!isset($_SERVER['RdRoleId'])) { |
|
142 require_once 'Zend/Service/WindowsAzure/Diagnostics/Exception.php'; |
|
143 throw new Zend_Service_WindowsAzure_Diagnostics_Exception('Server variable \'RdRoleId\' is unknown. Please verify the application is running in Development Fabric or Windows Azure Fabric.'); |
|
144 } |
|
145 |
|
146 if (strpos($_SERVER['RdRoleId'], 'deployment(') === false) { |
|
147 return $_SERVER['RdRoleId']; |
|
148 } else { |
|
149 $roleIdParts = explode('.', $_SERVER['RdRoleId']); |
|
150 return $roleIdParts[0] . '/' . $roleIdParts[2] . '/' . $_SERVER['RdRoleId']; |
|
151 } |
|
152 |
|
153 if (!isset($_SERVER['RoleDeploymentID']) && !isset($_SERVER['RoleInstanceID']) && !isset($_SERVER['RoleName'])) { |
|
154 throw new Exception('Server variables \'RoleDeploymentID\', \'RoleInstanceID\' and \'RoleName\' are unknown. Please verify the application is running in Development Fabric or Windows Azure Fabric.'); |
|
155 } |
|
156 |
|
157 if (strpos($_SERVER['RdRoleId'], 'deployment(') === false) { |
|
158 return $_SERVER['RdRoleId']; |
|
159 } else { |
|
160 return $_SERVER['RoleDeploymentID'] . '/' . $_SERVER['RoleInstanceID'] . '/' . $_SERVER['RoleName']; |
|
161 } |
138 } |
162 } |
139 |
163 |
140 /** |
164 /** |
141 * Set configuration for current role instance. Only works on Development Fabric or Windows Azure Fabric. |
165 * Set configuration for current role instance. Only works on Development Fabric or Windows Azure Fabric. |
142 * |
166 * |
144 * @throws Zend_Service_WindowsAzure_Diagnostics_Exception |
168 * @throws Zend_Service_WindowsAzure_Diagnostics_Exception |
145 */ |
169 */ |
146 public function setConfigurationForCurrentRoleInstance(Zend_Service_WindowsAzure_Diagnostics_ConfigurationInstance $configuration) |
170 public function setConfigurationForCurrentRoleInstance(Zend_Service_WindowsAzure_Diagnostics_ConfigurationInstance $configuration) |
147 { |
171 { |
148 if (!isset($_SERVER['RdRoleId'])) { |
172 if (!isset($_SERVER['RdRoleId'])) { |
149 throw new Zend_Service_WindowsAzure_Diagnostics_Exception('Server variable \'RdRoleId\' is unknown. Please verify the application is running in Development Fabric or Windows Azure Fabric.'); |
173 require_once 'Zend/Service/WindowsAzure/Diagnostics/Exception.php'; |
150 } |
174 throw new Zend_Service_WindowsAzure_Diagnostics_Exception('Server variable \'RdRoleId\' is unknown. Please verify the application is running in Development Fabric or Windows Azure Fabric.'); |
151 $this->setConfigurationForRoleInstance($_SERVER['RdRoleId'], $configuration); |
175 } |
|
176 |
|
177 $this->setConfigurationForRoleInstance($this->_getCurrentRoleInstanceId(), $configuration); |
152 } |
178 } |
153 |
179 |
154 /** |
180 /** |
155 * Get configuration for a specific role instance |
181 * Get configuration for a specific role instance |
156 * |
182 * |
158 * @return Zend_Service_WindowsAzure_Diagnostics_ConfigurationInstance |
184 * @return Zend_Service_WindowsAzure_Diagnostics_ConfigurationInstance |
159 * @throws Zend_Service_WindowsAzure_Diagnostics_Exception |
185 * @throws Zend_Service_WindowsAzure_Diagnostics_Exception |
160 */ |
186 */ |
161 public function getConfigurationForRoleInstance($roleInstance = null) |
187 public function getConfigurationForRoleInstance($roleInstance = null) |
162 { |
188 { |
163 if ($roleInstance === null) { |
189 if (is_null($roleInstance)) { |
|
190 require_once 'Zend/Service/WindowsAzure/Diagnostics/Exception.php'; |
164 throw new Zend_Service_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.'); |
191 throw new Zend_Service_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.'); |
165 } |
192 } |
166 |
193 |
|
194 |
|
195 |
167 if ($this->_blobStorageClient->blobExists($this->_controlContainer, $roleInstance)) { |
196 if ($this->_blobStorageClient->blobExists($this->_controlContainer, $roleInstance)) { |
168 $configurationInstance = new Zend_Service_WindowsAzure_Diagnostics_ConfigurationInstance(); |
197 $configurationInstance = new Zend_Service_WindowsAzure_Diagnostics_ConfigurationInstance(); |
169 $configurationInstance->loadXml( $this->_blobStorageClient->getBlobData($this->_controlContainer, $roleInstance) ); |
198 $configurationInstance->loadXml( $this->_blobStorageClient->getBlobData($this->_controlContainer, $roleInstance) ); |
170 return $configurationInstance; |
199 return $configurationInstance; |
171 } |
200 } |
180 * @param Zend_Service_WindowsAzure_Diagnostics_ConfigurationInstance $configuration Configuration to apply |
209 * @param Zend_Service_WindowsAzure_Diagnostics_ConfigurationInstance $configuration Configuration to apply |
181 * @throws Zend_Service_WindowsAzure_Diagnostics_Exception |
210 * @throws Zend_Service_WindowsAzure_Diagnostics_Exception |
182 */ |
211 */ |
183 public function setConfigurationForRoleInstance($roleInstance = null, Zend_Service_WindowsAzure_Diagnostics_ConfigurationInstance $configuration) |
212 public function setConfigurationForRoleInstance($roleInstance = null, Zend_Service_WindowsAzure_Diagnostics_ConfigurationInstance $configuration) |
184 { |
213 { |
185 if ($roleInstance === null) { |
214 if (is_null($roleInstance)) { |
|
215 require_once 'Zend/Service/WindowsAzure/Diagnostics/Exception.php'; |
186 throw new Zend_Service_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.'); |
216 throw new Zend_Service_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.'); |
187 } |
217 } |
188 |
218 |
189 $this->_blobStorageClient->putBlobData($this->_controlContainer, $roleInstance, $configuration->toXml(), array(), null, array('Content-Type' => 'text/xml')); |
219 $this->_blobStorageClient->putBlobData($this->_controlContainer, $roleInstance, $configuration->toXml(), array(), null, array('Content-Type' => 'text/xml')); |
190 } |
220 } |