Skip to content

Commit

Permalink
Add ShardingPass + Configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed May 8, 2012
1 parent cb62b37 commit e11284b
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Command/GenerateVendorRolesFileCommand.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@ class GenerateVendorRolesFileCommand extends ContainerAwareCommand
protected function configure() protected function configure()
{ {
$this $this
->setName('windowsazure:generate:vendor-roles-file') ->setName('windowsazure:generate-vendor-roles-file')
->setDescription('Generates the roles file of your projects vendor directory for Windows Azure deployments') ->setDescription('Generates the roles file of your projects vendor directory for Windows Azure deployments')
->addArgument('vendor-dir', InputArgument::REQUIRED, 'Your projects vendor dir') ->addArgument('vendor-dir', InputArgument::OPTIONAL, 'Your projects vendor dir')
; ;
} }


protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$output->writeln('<info>Generating Windows Azure role file</info>'); $output->writeln('<info>Generating Windows Azure role file</info>');
$vendorDir = $input->getArgument('vendor-dir');
if ( !$vendorDir) {
$vendorDir = getcwd() . DIRECTORY_SEPARATOR . "vendor";
}


VendorRoleFilesListener::generateVendorRolesFile($input->getArgument('vendor-dir')); VendorRoleFilesListener::generateVendorRolesFile($vendorDir);
} }
} }
74 changes: 74 additions & 0 deletions DependencyInjection/CompilerPass/ShardingPass.php
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* WindowsAzure TaskDemoBundle
*
* LICENSE
*
* This source file is subject to the MIT license that is bundled
* with this package in the file LICENSE.txt.
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to kontakt@beberlei.de so I can send you a copy immediately.
*/

namespace WindowsAzure\DistributionBundle\DependencyInjection\CompilerPass;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;

/**
* This will end up in the DoctrineBundle some day, but for now we have to
* register the sharding manager here in an extra compiler pass.
*/
class ShardingPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if ( ! $container->hasParameter('windows_azure_distribution.sharding')) {
return;
}

$shards = $container->getParameter('windows_azure_distribution.sharding');

foreach ($shards as $connectionName => $options) {
$this->registerShard($connectionName, $options, $container);
}
}

private function registerShard($connectionName, $options, $container)
{
$id = 'doctrine.dbal.' . $connectionName . '_connection';
$shardId = 'windows_azure_task_demo.' . $connectionName . '_shard_manager';

if ( ! $container->hasDefinition($id)) {
throw new \InvalidArgumentException("No connection " . $connectionName . " found for federations.");
}

$def = $container->findDefinition($id);
$args = $def->getArguments();

if ( ! isset($args[0]['driver']) || strpos($args[0]['driver'], 'sqlsrv') === false) {
throw new \InvalidArgumentException("Sharding only possible with sqlsrv driver.");
}

$args[0]['sharding'] = array(
'federationName' => $options['federationName'],
'distributionKey' => $options['distributionKey'],
'distributionType' => $options['distributionType'],
'filteringEnabled' => $options['filteringEnabled'],
);

$def->setArguments($args);

$shardDef = new Definition('Doctrine\Shards\DBAL\SQLAzure\SQLAzureShardManager');
$shardDef->addArgument(new Reference($id));
$container->setDefinition($shardId, $shardDef);

if ($connection == 'default') {
$container->setAlias('windows_azure_task_demo.shard_manager', $shardId);
}
}
}

11 changes: 11 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ public function getConfigTreeBuilder()
->scalarNode('key')->isRequired()->end() ->scalarNode('key')->isRequired()->end()
->end() ->end()
->end() ->end()
->arrayNode('federations')
->useAttributeAsKey('name')
->prototype('array')
->children()
->scalarNode('federationName')->isRequired()->end()
->scalarNode('distributionKey')->isRequired()->end()
->scalarNode('distributionType')->isRequired()->end()
->scalarNode('filteringEnabled')->defaultValue(false)->end()
->end()
->end()
->end()
->end() ->end()
; ;


Expand Down
10 changes: 10 additions & 0 deletions DependencyInjection/WindowsAzureDistributionExtension.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -41,12 +41,22 @@ public function load(array $configs, ContainerBuilder $container)
$this->loadAsset($config['assets'], $container); $this->loadAsset($config['assets'], $container);
$this->loadStorages($config, $container); $this->loadStorages($config, $container);
$this->loadTable($config, $container); $this->loadTable($config, $container);
$this->loadSharding($config, $container);


/*if (isset($config['diagnostics'])) { /*if (isset($config['diagnostics'])) {
$container->setParameter('windows_azure_distribution.config.diagnostics.storage', $config['diagnostics']); $container->setParameter('windows_azure_distribution.config.diagnostics.storage', $config['diagnostics']);
}*/ }*/
} }


protected function loadSharding($config, $container)
{
if ( ! isset($config['federations'])) {
return;
}

$container->setParameter('windows_azure_distribution.sharding', $config['federations']);
}

protected function loadTable($config, $container) protected function loadTable($config, $container)
{ {
if (!isset($config['table'])) { if (!isset($config['table'])) {
Expand Down
43 changes: 43 additions & 0 deletions Resources/docs/04_storage.md
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,43 @@
# Blob Storage

The Windows Azure Distribution Bundle comes with support for accessing Windows Blob Storage.
This can be done using the [Azure Blob Storage](http://github.com/beberlei/aure-blob-storage) library.
This library is a dependency that you have install.

You can configure blob storages from the config.yml (or config_azure.yml):

windows_azure_distribution:
blob_storage:
test:
accountName: myacc
accountKey: key
test_with_stream:
accountName: myacc2
accountKey: key2
stream: azure

There is not yet a mechanism to fallback to a local API if you dont want to hit
blob storage during development, so you need to put the details into config.yml
so it works in development.

With this configuration you can access the blob storage accounts from your
controllers (or any services) using the storage registry service:

<?php
namespace Vendor\AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class MyController extends Controller
{
public function indexAction()
{
$registry = $this->container->get('windows_azure_distribution.storage_registry');
$client = $registry->get('test');
$client2 = $registry->get('test2');

$streamFile = 'azure://container/test.jpg';
$data = file_get_contents($streamFile);
}
}

32 changes: 32 additions & 0 deletions Resources/docs/05_table.md
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,32 @@
# Table Service

Note: Only works with Doctrine Common 2.2

The Windows Azure Distribution bundle comes with support for accessing Windows Table Storage.
This is done in combination with the [Doctrine KeyValueStore](http://github.com/doctrine/KeyValueStore)
project.

You can configure the table manager with:

windows_azure_distribution:
table:
account: "acc"
key: "key"

If you configured the manager and installed the Doctrine Key Value Store project you can access the
table manager with:

<?php
namespace Vendor\AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class MyController extends Controller
{
public function indexAction()
{
$manager = $this->container->get('windows_azure_distribution.table.manager');
}
}

Table entities can be any objects in your project, no additional configuration is necessary. Just
10 changes: 10 additions & 0 deletions WindowsAzureDistributionBundle.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
namespace WindowsAzure\DistributionBundle; namespace WindowsAzure\DistributionBundle;


use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use WindowsAzure\DistributionBundle\DependencyInjection\CompilerPass\ShardingPass;


class WindowsAzureDistributionBundle extends Bundle class WindowsAzureDistributionBundle extends Bundle
{ {
Expand All @@ -28,5 +30,13 @@ public function boot()
// instantiate storage registry, will lead to registration of stream wrappers. // instantiate storage registry, will lead to registration of stream wrappers.
$storageRegistry = $this->container->get('windows_azure_distribution.storage_registry'); $storageRegistry = $this->container->get('windows_azure_distribution.storage_registry');
} }

public function build(ContainerBuilder $container)
{
parent::build($container);

$container->addCompilerPass(new ShardingPass());
}

} }


0 comments on commit e11284b

Please sign in to comment.