Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add ShardingPass + Configuration

  • Loading branch information...
commit e11284b287f353722bcba2f71f147a557f24dd7d 1 parent cb62b37
@beberlei authored
View
12 Command/GenerateVendorRolesFileCommand.php
@@ -30,16 +30,20 @@ class GenerateVendorRolesFileCommand extends ContainerAwareCommand
protected function configure()
{
$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')
- ->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)
{
$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);
}
-}
+}
View
74 DependencyInjection/CompilerPass/ShardingPass.php
@@ -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);
+ }
+ }
+}
+
View
11 DependencyInjection/Configuration.php
@@ -105,6 +105,17 @@ public function getConfigTreeBuilder()
->scalarNode('key')->isRequired()->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()
;
View
10 DependencyInjection/WindowsAzureDistributionExtension.php
@@ -41,12 +41,22 @@ public function load(array $configs, ContainerBuilder $container)
$this->loadAsset($config['assets'], $container);
$this->loadStorages($config, $container);
$this->loadTable($config, $container);
+ $this->loadSharding($config, $container);
/*if (isset($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)
{
if (!isset($config['table'])) {
View
43 Resources/docs/04_storage.md
@@ -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);
+ }
+ }
+
View
32 Resources/docs/05_table.md
@@ -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
View
10 WindowsAzureDistributionBundle.php
@@ -14,6 +14,8 @@
namespace WindowsAzure\DistributionBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use WindowsAzure\DistributionBundle\DependencyInjection\CompilerPass\ShardingPass;
class WindowsAzureDistributionBundle extends Bundle
{
@@ -28,5 +30,13 @@ public function boot()
// instantiate storage registry, will lead to registration of stream wrappers.
$storageRegistry = $this->container->get('windows_azure_distribution.storage_registry');
}
+
+ public function build(ContainerBuilder $container)
+ {
+ parent::build($container);
+
+ $container->addCompilerPass(new ShardingPass());
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.