예제 #1
0
 /**
  * Set configuration for a specific role instance
  *
  * @param string $roleInstance Role instance name, can be found in $_SERVER['RdRoleId'] when hosted on Windows Azure.
  * @param Microsoft_WindowsAzure_Diagnostics_ConfigurationInstance $configuration Configuration to apply
  * @throws Microsoft_WindowsAzure_Diagnostics_Exception
  */
 public function setConfigurationForRoleInstance($roleInstance = null, Microsoft_WindowsAzure_Diagnostics_ConfigurationInstance $configuration)
 {
     if (is_null($roleInstance)) {
         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.');
     }
     $this->_blobStorageClient->putBlobData($this->_controlContainer, $roleInstance, $configuration->toXml(), array(), null, array('Content-Type' => 'text/xml'));
 }
	/**
	 * @see FileBackend::doCreateInternal()
	 */
	function doCreateInternal( array $params ) {
		$status = Status::newGood();

		list( $dstCont, $dstRel ) = $this->resolveStoragePath( $params['dst'] );
		if ( $dstRel === null ) {
			$status->fatal( 'backend-fail-invalidpath', $params['dst'] );
			return $status;
		}

		// (a) Check if the destination object already exists
		$blobExists = $this->storageClient->blobExists( $dstCont, $dstRel );
		if ( $blobExists && empty( $params['overwriteDest'] ) ) { //Blob exists _and_ should not be overridden
			$status->fatal( 'backend-fail-alreadyexists', $params['dst'] );
			return $status;
		}

		// (b) Actually create the object
		try {
			// TODO: how do I know the container exists? Should we call prepare?
			$this->storageClient->putBlobData( $dstCont, $dstRel, $params['content'] );
		}
		catch ( Exception $e ) {
			$status->fatal( 'backend-fail-internal' );
		}

		return $status;
	}
예제 #3
0
 /**
  * Write a specific session
  * 
  * @param int $id Session Id
  * @param string $serializedData Serialized PHP object
  * @throws Exception
  */
 public function write($id, $serializedData)
 {
     // Encode data
     $serializedData = base64_encode(serialize($serializedData));
     if (strlen($serializedData) >= self::MAX_TS_PROPERTY_SIZE && $this->_storageType == self::STORAGE_TYPE_TABLE) {
         throw new Microsoft_WindowsAzure_Exception('Session data exceeds the maximum allowed size of ' . self::MAX_TS_PROPERTY_SIZE . ' bytes that can be stored using table storage. Consider switching to a blob storage back-end or try reducing session data size.');
     }
     // Store data
     if ($this->_storageType == self::STORAGE_TYPE_TABLE) {
         // In table storage
         $sessionRecord = new Microsoft_WindowsAzure_Storage_DynamicTableEntity($this->_sessionContainerPartition, $id);
         $sessionRecord->sessionExpires = time();
         $sessionRecord->serializedData = $serializedData;
         $sessionRecord->setAzurePropertyType('sessionExpires', 'Edm.Int32');
         try {
             $this->_storage->updateEntity($this->_sessionContainer, $sessionRecord);
         } catch (Microsoft_WindowsAzure_Exception $unknownRecord) {
             $this->_storage->insertEntity($this->_sessionContainer, $sessionRecord);
         }
     } else {
         if ($this->_storageType == self::STORAGE_TYPE_BLOB) {
             // In blob storage
             $this->_storage->putBlobData($this->_sessionContainer, $this->_sessionContainerPartition . '/' . $id, $serializedData, array('sessionexpires' => time()));
         }
     }
 }
예제 #4
0
 /**
  * Tests S3
  *
  * @param string $error
  * @return boolean
  */
 function test(&$error)
 {
     if (!parent::test($error)) {
         return false;
     }
     $string = 'test_azure_' . md5(time());
     if (!$this->_init($error)) {
         return false;
     }
     try {
         $containers = $this->_client->listContainers();
     } catch (Exception $exception) {
         $error = sprintf('Unable to list containers (%s).', $exception->getMessage());
         return false;
     }
     $container = null;
     foreach ((array) $containers as $_container) {
         if ($_container->Name == $this->_config['container']) {
             $container = $_container;
             break;
         }
     }
     if (!$container) {
         $error = sprintf('Container doesn\'t exist: %s.', $this->_config['container']);
         return false;
     }
     try {
         $this->_client->putBlobData($this->_config['container'], $string, $string);
     } catch (Exception $exception) {
         $error = sprintf('Unable to put blob data (%s).', $exception->getMessage());
         return false;
     }
     try {
         $data = $this->_client->getBlobData($this->_config['container'], $string);
     } catch (Exception $exception) {
         $error = sprintf('Unable to get blob data (%s).', $exception->getMessage());
         return false;
     }
     if ($data != $string) {
         try {
             $this->_client->deleteBlob($this->_config['container'], $string);
         } catch (Exception $exception) {
         }
         $error = 'Blob datas are not equal.';
         return false;
     }
     try {
         $this->_client->deleteBlob($this->_config['container'], $string);
     } catch (Exception $exception) {
         $error = sprintf('Unable to delete blob (%s).', $exception->getMessage());
         return false;
     }
     return true;
 }
 /**
  * @see FileBackend::doCreateInternal()
  */
 function doCreateInternal(array $params)
 {
     $status = Status::newGood();
     list($dstCont, $dstRel) = $this->resolveStoragePath($params['dst']);
     if ($dstRel === null) {
         $status->fatal('backend-fail-invalidpath', $params['dst']);
         return $status;
     }
     if (empty($params['overwrite'])) {
         //Blob should not be overridden
         // Check if the destination object already exists
         if ($this->storageClient->blobExists($dstCont, $dstRel)) {
             $status->fatal('backend-fail-alreadyexists', $params['dst']);
             return $status;
         }
     }
     // Actually create the object
     try {
         $this->storageClient->putBlobData($dstCont, $dstRel, $params['content']);
     } catch (Exception $e) {
         $status->fatal('backend-fail-internal');
     }
     return $status;
 }