/**
  * Ensures that a DynamoDB table for sessions can be created
  */
 public function testCreatesTable()
 {
     $sh = SessionHandler::factory(array('dynamodb_client' => $this->client, 'table_name' => $this->table));
     self::log("Creating sessions table {$this->table}");
     $sh->createSessionsTable(25, 25);
     self::log("Ensuring the table {$this->table} was created");
     $result = $this->client->describeTable(array('TableName' => $this->table));
     $this->assertEquals($this->table, $result['Table']['TableName']);
 }
示例#2
0
 /**
  * Create the dynamodb table before tests run.
  */
 protected static function createTable()
 {
     try {
         self::$client->describeTable(['TableName' => self::$tableName]);
         return;
     } catch (DynamoDbException $e) {
         // table doesn't exist, create it below
     }
     self::$client->createTable(['TableName' => self::$tableName, 'AttributeDefinitions' => [['AttributeName' => 'id', 'AttributeType' => 'S']], 'KeySchema' => array(['AttributeName' => 'id', 'KeyType' => 'HASH']), 'ProvisionedThroughput' => ['ReadCapacityUnits' => 5, 'WriteCapacityUnits' => 5]]);
     self::$client->waitUntil('TableExists', ['TableName' => self::$tableName]);
 }
 /**
  * @param string $tableName
  */
 protected function createTable($tableName)
 {
     try {
         $this->client->describeTable(['TableName' => $tableName]);
     } catch (ResourceNotFoundException $e) {
         $this->client->createTable(['AttributeDefinitions' => [['AttributeName' => 'id', 'AttributeType' => 'S']], 'TableName' => $tableName, 'KeySchema' => [['AttributeName' => 'id', 'KeyType' => 'HASH']], 'ProvisionedThroughput' => ['ReadCapacityUnits' => 1, 'WriteCapacityUnits' => 1]]);
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->logger = $this->getContainer()->get('logger');
     $this->dynamoDbClient = $this->getContainer()->get('queue.dynamodb_client');
     $this->elasticsearch = $this->getContainer()->get('syrup.elasticsearch.search');
     $this->tableName = $this->getContainer()->getParameter('container_stats_dynamodb.table_name');
     try {
         $this->dynamoDbClient->describeTable(['TableName' => $this->tableName]);
     } catch (DynamoDbException $e) {
         if (strpos($e->getMessage(), 'ResourceNotFoundException') !== false) {
             throw new \Exception('Table ' . $this->tableName . ' doesn\'t exist.');
         } else {
             throw $e;
         }
     }
     $startTime = time();
     do {
         $notFoundIds = [];
         $stats = [];
         $jobIdsToFetchStatsFor = $this->getJobsToFetchStatsFor();
         foreach ($jobIdsToFetchStatsFor as $runId) {
             $jobStats = $this->fetchStatsForJob($runId);
             if ($jobStats !== null) {
                 $stats[$runId] = $jobStats;
             } else {
                 $notFoundIds[] = $runId;
             }
         }
         // update docs for which we found data
         if (count($stats) > 0) {
             $this->logger->info('Updating jobs for which we found stats', ['count' => count($stats)]);
         }
         foreach ($stats as $runId => $jobRawData) {
             $this->updateStatsForJob($runId, $jobRawData);
         }
         // mark remaining docs as processed
         if (count($notFoundIds) > 0) {
             $this->logger->info('Updating jobs for which we didn\'t found stats', ['count' => count($notFoundIds)]);
         }
         foreach ($notFoundIds as $runId) {
             $this->markDocumentAsProcessed($runId);
         }
         sleep(self::SLEEP_TIME_AFTER_SCAN);
     } while (time() - $startTime < self::MAX_RUN_TIME);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->dynamoDbClient = $this->getContainer()->get('queue.dynamodb_client');
     $this->tableName = $this->getContainer()->getParameter('container_stats_dynamodb.table_name');
     try {
         $this->dynamoDbClient->describeTable(['TableName' => $this->tableName]);
         echo 'Table ' . $this->tableName . ' already exists.' . "\n";
     } catch (DynamoDbException $e) {
         if (strpos($e->getMessage(), 'ResourceNotFoundException') !== false) {
             echo 'Creating ' . $this->tableName . ' table ...';
             $this->dynamoDbClient->createTable($this->getTableConfiguration());
             $this->dynamoDbClient->waitUntil('TableExists', ['TableName' => $this->tableName, '@waiter' => ['delay' => 3, 'maxAttempts' => 20]]);
             echo ' done!' . "\n";
         } else {
             throw $e;
         }
     }
 }
 /**
  * @depends testCreatesTable
  */
 public function testUpdatesTable()
 {
     self::log('Updating table');
     // Need to wait until the table is active
     $this->client->waitUntil('TableExists', $this->table, array('status' => 'active'));
     $this->client->updateTable(array('TableName' => $this->table, 'ProvisionedThroughput' => array('ReadCapacityUnits' => 20, 'WriteCapacityUnits' => 20)));
     // Wait until the table is active
     self::log('Waiting for the table to become active after updating');
     $this->client->waitUntil('table_exists', $this->table, array('status' => 'ACTIVE'));
     // Ensure the table is updated
     $result = $this->client->describeTable(array('TableName' => $this->table));
     // Ensure that the updates took effect
     $this->assertEquals(20, $result['Table']['ProvisionedThroughput']['ReadCapacityUnits']);
     $this->assertEquals(20, $result['Table']['ProvisionedThroughput']['WriteCapacityUnits']);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->logger = $this->getContainer()->get('logger');
     $this->dynamoDbClient = $this->getContainer()->get('queue.dynamodb_client');
     $this->tableName = $this->getContainer()->getParameter('container_stats_dynamodb.table_name');
     try {
         $this->dynamoDbClient->describeTable(['TableName' => $this->tableName]);
     } catch (DynamoDbException $e) {
         if (strpos($e->getMessage(), 'ResourceNotFoundException') !== false) {
             throw new \Exception('Table ' . $this->tableName . ' doesn\'t exist.');
         } else {
             throw $e;
         }
     }
     $queueId = $input->getArgument('queueId');
     $this->queue = $this->getContainer()->get('syrup.queue_factory')->get($queueId);
     $startTime = time();
     do {
         foreach ($this->queue->receive(self::MAX_NUMBER_OF_MESSAGES) as $message) {
             $this->processMessage($message);
             $this->queue->deleteMessage($message);
         }
     } while (time() - $startTime < self::MAX_RUN_TIME);
 }
示例#8
0
 /**
  * Describe table via the describe_table call
  * @param string $table The name of the table
  * @return Table\TableDescription
  */
 public function describeTable($table)
 {
     if (null !== $this->logger) {
         $this->log('Describe table ' . $table);
     }
     $parameters = array('TableName' => $table);
     if (null !== $this->logger) {
         $this->log('DescribeTable request paramaters : ' . print_r($parameters, true), Logger::DEBUG);
     }
     $response = $this->connector->describeTable($parameters);
     if (null !== $this->logger) {
         $this->log('DescribeTable request response : ' . print_r($response, true), Logger::DEBUG);
     }
     $tableDescription = new Table\TableDescription();
     $tableDescription->populateFromDynamoDB($response['Table']);
     return $tableDescription;
 }
示例#9
0
 private function createDynamoDb(\Aws\DynamoDb\DynamoDbClient $client, $prefix = null)
 {
     $tablesList = explode(' ', 'oauth_access_tokens oauth_authorization_codes oauth_clients oauth_jwt oauth_public_keys oauth_refresh_tokens oauth_scopes oauth_users');
     $nbTables = count($tablesList);
     $client->createTable(array('TableName' => $prefix . 'oauth_access_tokens', 'AttributeDefinitions' => array(array('AttributeName' => 'access_token', 'AttributeType' => 'S')), 'KeySchema' => array(array('AttributeName' => 'access_token', 'KeyType' => 'HASH')), 'ProvisionedThroughput' => array('ReadCapacityUnits' => 1, 'WriteCapacityUnits' => 1)));
     $client->createTable(array('TableName' => $prefix . 'oauth_authorization_codes', 'AttributeDefinitions' => array(array('AttributeName' => 'authorization_code', 'AttributeType' => 'S')), 'KeySchema' => array(array('AttributeName' => 'authorization_code', 'KeyType' => 'HASH')), 'ProvisionedThroughput' => array('ReadCapacityUnits' => 1, 'WriteCapacityUnits' => 1)));
     $client->createTable(array('TableName' => $prefix . 'oauth_clients', 'AttributeDefinitions' => array(array('AttributeName' => 'client_id', 'AttributeType' => 'S')), 'KeySchema' => array(array('AttributeName' => 'client_id', 'KeyType' => 'HASH')), 'ProvisionedThroughput' => array('ReadCapacityUnits' => 1, 'WriteCapacityUnits' => 1)));
     $client->createTable(array('TableName' => $prefix . 'oauth_jwt', 'AttributeDefinitions' => array(array('AttributeName' => 'client_id', 'AttributeType' => 'S'), array('AttributeName' => 'subject', 'AttributeType' => 'S')), 'KeySchema' => array(array('AttributeName' => 'client_id', 'KeyType' => 'HASH'), array('AttributeName' => 'subject', 'KeyType' => 'RANGE')), 'ProvisionedThroughput' => array('ReadCapacityUnits' => 1, 'WriteCapacityUnits' => 1)));
     $client->createTable(array('TableName' => $prefix . 'oauth_public_keys', 'AttributeDefinitions' => array(array('AttributeName' => 'client_id', 'AttributeType' => 'S')), 'KeySchema' => array(array('AttributeName' => 'client_id', 'KeyType' => 'HASH')), 'ProvisionedThroughput' => array('ReadCapacityUnits' => 1, 'WriteCapacityUnits' => 1)));
     $client->createTable(array('TableName' => $prefix . 'oauth_refresh_tokens', 'AttributeDefinitions' => array(array('AttributeName' => 'refresh_token', 'AttributeType' => 'S')), 'KeySchema' => array(array('AttributeName' => 'refresh_token', 'KeyType' => 'HASH')), 'ProvisionedThroughput' => array('ReadCapacityUnits' => 1, 'WriteCapacityUnits' => 1)));
     $client->createTable(array('TableName' => $prefix . 'oauth_scopes', 'AttributeDefinitions' => array(array('AttributeName' => 'scope', 'AttributeType' => 'S'), array('AttributeName' => 'is_default', 'AttributeType' => 'S')), 'KeySchema' => array(array('AttributeName' => 'scope', 'KeyType' => 'HASH')), 'GlobalSecondaryIndexes' => array(array('IndexName' => 'is_default-index', 'KeySchema' => array(array('AttributeName' => 'is_default', 'KeyType' => 'HASH')), 'Projection' => array('ProjectionType' => 'ALL'), 'ProvisionedThroughput' => array('ReadCapacityUnits' => 1, 'WriteCapacityUnits' => 1))), 'ProvisionedThroughput' => array('ReadCapacityUnits' => 1, 'WriteCapacityUnits' => 1)));
     $client->createTable(array('TableName' => $prefix . 'oauth_users', 'AttributeDefinitions' => array(array('AttributeName' => 'username', 'AttributeType' => 'S')), 'KeySchema' => array(array('AttributeName' => 'username', 'KeyType' => 'HASH')), 'ProvisionedThroughput' => array('ReadCapacityUnits' => 1, 'WriteCapacityUnits' => 1)));
     // Wait for creation
     $nbTableCreated = 0;
     while ($nbTableCreated != $nbTables) {
         $nbTableCreated = 0;
         foreach ($tablesList as $key => $table) {
             try {
                 $result = $client->describeTable(array('TableName' => $prefix . $table));
                 if ($result['Table']['TableStatus'] == 'ACTIVE') {
                     $nbTableCreated++;
                 }
             } catch (\Aws\DynamoDb\Exception\DynamoDbException $e) {
                 // Table does not exist : nothing to do
                 $nbTableCreated++;
             }
         }
         if ($nbTableCreated != $nbTables) {
             sleep(1);
         }
     }
 }
 public function describe()
 {
     $requestArgs = ["TableName" => $this->tableName];
     $result = $this->dbClient->describeTable($requestArgs);
     return $result['Table'];
 }
示例#11
0
 /**
  * Returns information about the table, including the current status of the table,
  * when it was created, the primary key schema, and any indexes on the table.
  *
  * @param string $tableName Name of the table to describe
  *
  * @return Guzzle\Service\Resource\Model
  *
  * @see http://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.DynamoDb.DynamoDbClient.html#_describeTable
  */
 public function describeTable($tableName)
 {
     return $this->client->describeTable(['TableName' => $tableName]);
 }