Skip to content

Commit

Permalink
Merge pull request #126 from talis/ent_518_remove_config_job_job_payload
Browse files Browse the repository at this point in the history
Remove config from job payload
  • Loading branch information
rsinger authored May 7, 2018
2 parents 4ae950e + 283ef9a commit 5536177
Show file tree
Hide file tree
Showing 62 changed files with 1,819 additions and 995 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Quickstart
```php
require_once("tripod.inc.php");

\Tripod\Mongo\Config::setConfig($conf); // set the config, usually read in as JSON from a file
\Tripod\Config::setConfig($conf); // set the config, usually read in as JSON from a file

$tripod = new Driver(
"CBD_users", // pod (read: MongoDB collection) we're working with
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@
"require-dev": {
"phpunit/phpunit": "4.1.*",
"squizlabs/php_codesniffer": "3.2.*"
}
},
"autoload": {
"classmap": ["src/"]
}
}
2 changes: 1 addition & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Tripod config is typically defined as a JSON file or stream which is added to th

```php
$conf = json_decode(file_get_contents('tripod_config.json');
\Tripod\Mongo\Config::setConfig($conf); // set the config, usually read in as JSON from a file
\Tripod\Config::setConfig($conf); // set the config, usually read in as JSON from a file
```

Namespaces
Expand Down
2 changes: 1 addition & 1 deletion scripts/mongo/BSONToQuads.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

array_shift($argv);
$config = json_decode(file_get_contents($argv[0]), true);
\Tripod\Mongo\Config::setConfig($config);
\Tripod\Config::setConfig($config);

$tu = new \Tripod\Mongo\TriplesUtil();

Expand Down
2 changes: 1 addition & 1 deletion scripts/mongo/BSONToTriples.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}
array_shift($argv);
$config = json_decode(file_get_contents($argv[0]), true);
\Tripod\Mongo\Config::setConfig($config);
\Tripod\Config::setConfig($config);

$tu = new \Tripod\Mongo\TriplesUtil();

Expand Down
10 changes: 5 additions & 5 deletions scripts/mongo/createSearchDocuments.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ function showUsage($scriptName)
*/
function generateSearchDocuments($id, $specId, $storeName, $stat = null, $queue = null)
{
$spec = \Tripod\Mongo\Config::getInstance()->getSearchDocumentSpecification($storeName, $specId);
$spec = \Tripod\Config::getInstance()->getSearchDocumentSpecification($storeName, $specId);
if (array_key_exists("from",$spec))
{
\Tripod\Mongo\Config::getInstance()->setMongoCursorTimeout(-1);
\Tripod\Config::getInstance()->setMongoCursorTimeout(-1);

print "Generating $specId";
$tripod = new \Tripod\Mongo\Driver($spec['from'], $storeName, array('stat'=>$stat));
Expand All @@ -82,7 +82,7 @@ function generateSearchDocuments($id, $specId, $storeName, $stat = null, $queue
$t = new \Tripod\Timer();
$t->start();

\Tripod\Mongo\Config::setConfig(json_decode(file_get_contents($configLocation),true));
\Tripod\Config::setConfig(json_decode(file_get_contents($configLocation),true));

if(isset($options['s']) || isset($options['storename']))
{
Expand Down Expand Up @@ -120,7 +120,7 @@ function generateSearchDocuments($id, $specId, $storeName, $stat = null, $queue
}
else
{
$queue = \Tripod\Mongo\Config::getInstance()->getApplyQueueName();
$queue = \Tripod\Config::getInstance()->getApplyQueueName();
}
}

Expand All @@ -137,7 +137,7 @@ function generateSearchDocuments($id, $specId, $storeName, $stat = null, $queue
}
else
{
foreach(\Tripod\Mongo\Config::getInstance()->getSearchDocumentSpecifications($storeName) as $searchSpec)
foreach(\Tripod\Config::getInstance()->getSearchDocumentSpecifications($storeName) as $searchSpec)
{
generateSearchDocuments($id, $searchSpec['_id'], $storeName, $stat, $queue);
}
Expand Down
10 changes: 5 additions & 5 deletions scripts/mongo/createTables.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ function showUsage()
*/
function generateTables($id, $tableId, $storeName, $stat = null, $queue = null)
{
$tableSpec = \Tripod\Mongo\Config::getInstance()->getTableSpecification($storeName, $tableId);
$tableSpec = \Tripod\Config::getInstance()->getTableSpecification($storeName, $tableId);
if (array_key_exists("from",$tableSpec))
{
\Tripod\Mongo\Config::getInstance()->setMongoCursorTimeout(-1);
\Tripod\Config::getInstance()->setMongoCursorTimeout(-1);

print "Generating $tableId";
$tripod = new \Tripod\Mongo\Driver($tableSpec['from'], $storeName, array('stat'=>$stat));
Expand All @@ -83,7 +83,7 @@ function generateTables($id, $tableId, $storeName, $stat = null, $queue = null)
$t = new \Tripod\Timer();
$t->start();

\Tripod\Mongo\Config::setConfig(json_decode(file_get_contents($configLocation),true));
\Tripod\Config::setConfig(json_decode(file_get_contents($configLocation),true));

if(isset($options['s']) || isset($options['storename']))
{
Expand Down Expand Up @@ -121,7 +121,7 @@ function generateTables($id, $tableId, $storeName, $stat = null, $queue = null)
}
else
{
$queue = \Tripod\Mongo\Config::getInstance()->getApplyQueueName();
$queue = \Tripod\Config::getInstance()->getApplyQueueName();
}
}

Expand All @@ -138,7 +138,7 @@ function generateTables($id, $tableId, $storeName, $stat = null, $queue = null)
}
else
{
foreach(\Tripod\Mongo\Config::getInstance()->getTableSpecifications($storeName) as $tableSpec)
foreach(\Tripod\Config::getInstance()->getTableSpecifications($storeName) as $tableSpec)
{
generateTables($id, $tableSpec['_id'], $storeName, $stat, $queue);
}
Expand Down
10 changes: 5 additions & 5 deletions scripts/mongo/createViews.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ function showUsage()
*/
function generateViews($id, $viewId, $storeName, $stat, $queue)
{
$viewSpec = \Tripod\Mongo\Config::getInstance()->getViewSpecification($storeName, $viewId);
$viewSpec = \Tripod\Config::getInstance()->getViewSpecification($storeName, $viewId);
if (array_key_exists("from",$viewSpec))
{
\Tripod\Mongo\Config::getInstance()->setMongoCursorTimeout(-1);
\Tripod\Config::getInstance()->setMongoCursorTimeout(-1);

print "Generating $viewId";
$tripod = new \Tripod\Mongo\Driver($viewSpec['from'], $storeName, array('stat'=>$stat));
Expand All @@ -83,7 +83,7 @@ function generateViews($id, $viewId, $storeName, $stat, $queue)
$t = new \Tripod\Timer();
$t->start();

\Tripod\Mongo\Config::setConfig(json_decode(file_get_contents($configLocation),true));
\Tripod\Config::setConfig(json_decode(file_get_contents($configLocation),true));

if(isset($options['s']) || isset($options['storename']))
{
Expand Down Expand Up @@ -121,7 +121,7 @@ function generateViews($id, $viewId, $storeName, $stat, $queue)
}
else
{
$queue = \Tripod\Mongo\Config::getInstance()->getApplyQueueName();
$queue = \Tripod\Config::getInstance()->getApplyQueueName();
}
}

Expand All @@ -138,7 +138,7 @@ function generateViews($id, $viewId, $storeName, $stat, $queue)
}
else
{
foreach(\Tripod\Mongo\Config::getInstance()->getViewSpecifications($storeName) as $viewSpec)
foreach(\Tripod\Config::getInstance()->getViewSpecifications($storeName) as $viewSpec)
{
generateViews($id, $viewSpec['_id'], $storeName, $stat, $queue);
}
Expand Down
6 changes: 3 additions & 3 deletions scripts/mongo/detectNamespaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
),
);

\Tripod\Mongo\Config::setConfig($config);
\Tripod\Config::setConfig($config);


$util = new \Tripod\Mongo\TriplesUtil();
Expand Down Expand Up @@ -85,7 +85,7 @@
$newNsConfig[$prefix] = $n;
echo "\nFound ns $n suggest prefix $prefix";
$config["namespaces"] = array_merge($config["namespaces"],$newNsConfig);
\Tripod\Mongo\Config::setConfig($config);
\Tripod\Config::setConfig($config);
}
}
$ns = $util->extractMissingObjectNs($triples);
Expand All @@ -111,7 +111,7 @@
$newNsConfig[$prefix] = $n;
echo "\nFound object ns $n occurs > 500 times, suggest prefix $prefix";
$config["namespaces"] = array_merge($config["namespaces"],$newNsConfig);
\Tripod\Mongo\Config::setConfig($config);
\Tripod\Config::setConfig($config);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions scripts/mongo/ensureIndexes.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
}
array_shift($argv);

\Tripod\Mongo\Config::setConfig(json_decode(file_get_contents($argv[0]),true));
\Tripod\Config::setConfig(json_decode(file_get_contents($argv[0]),true));

$storeName = (isset($argv[1])) ? $argv[1] : null;
$forceReindex = (isset($argv[2])&&($argv[2]=="true")) ? true : false;
$background = (isset($argv[3])&&($argv[3]=="false")) ? false : true;

\Tripod\Mongo\Config::getInstance()->setMongoCursorTimeout(-1);
\Tripod\Config::getInstance()->setMongoCursorTimeout(-1);

$ei = new \Tripod\Mongo\Jobs\EnsureIndexes();

Expand Down
2 changes: 1 addition & 1 deletion scripts/mongo/loadTriples.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function load(\Tripod\Mongo\TriplesUtil $loader,$subject,Array $triples,Array &$

$storeName = $argv[0];
$podName = $argv[1];
\Tripod\Mongo\Config::setConfig(json_decode(file_get_contents($argv[2]),true));
\Tripod\Config::setConfig(json_decode(file_get_contents($argv[2]),true));

$i=0;
$currentSubject = "";
Expand Down
6 changes: 3 additions & 3 deletions scripts/mongo/triplesToBSON.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
array_shift($argv);

$config = json_decode(file_get_contents($argv[0]), true);
\Tripod\Mongo\Config::setConfig($config);
\Tripod\Config::setConfig($config);

$currentSubject = "";
$triples = array();
Expand All @@ -32,7 +32,7 @@

if ($currentSubject!=$subject) // once subject changes, we have all triples for that subject, flush to Mongo
{
print(json_encode($tu->getTArrayAbout($currentSubject,$triples,\Tripod\Mongo\Config::getInstance()->getDefaultContextAlias()))."\n");
print(json_encode($tu->getTArrayAbout($currentSubject,$triples,\Tripod\Config::getInstance()->getDefaultContextAlias()))."\n");
$currentSubject=$subject; // reset current subject to next subject
$triples = array(); // reset triples
}
Expand All @@ -41,7 +41,7 @@
}

// last doc
print(json_encode($tu->getTArrayAbout($currentSubject,$triples,\Tripod\Mongo\Config::getInstance()->getDefaultContextAlias()))."\n");
print(json_encode($tu->getTArrayAbout($currentSubject,$triples,\Tripod\Config::getInstance()->getDefaultContextAlias()))."\n");

?>

4 changes: 2 additions & 2 deletions scripts/mongo/validateConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ function showUsage()

\Tripod\Mongo\Config::setValidationLevel(\Tripod\Mongo\Config::VALIDATE_MAX);

\Tripod\Mongo\Config::setConfig(json_decode(file_get_contents($configLocation),true));
\Tripod\Config::setConfig(json_decode(file_get_contents($configLocation),true));

try {
\Tripod\Mongo\Config::getInstance();
\Tripod\Config::getInstance();

echo "\nConfig OK\n";
}
Expand Down
72 changes: 72 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace Tripod;

class Config implements ITripodConfig
{
/**
* @var Config
*/
private static $instance;

/**
* @var array
*/
private static $config = [];

/**
* Config should not be instantiated directly: use Config::getInstance()
*/
private function __construct()
{
}

/**
* Since this is a singleton class, use this method to create a new config instance.
* @uses Config::setConfig() Configuration must be set prior to calling this method. To generate a completely new object, set a new config
* @codeCoverageIgnore
* @throws \Tripod\Exceptions\ConfigException
* @return ITripodConfig
*/
public static function getInstance()
{
if (!isset(self::$config)) {
throw new \Tripod\Exceptions\ConfigException("Call Config::setConfig() first");
}
if (!isset(self::$instance)) {
self::$instance = TripodConfigFactory::create(self::$config);
}
return self::$instance;
}

/**
* Loads the Tripod config into the instance
*
* @return void
*/
public static function setConfig(array $config)
{
self::$config = $config;
self::$instance = null; // this will force a reload next time getInstance() is called
}

/**
* Returns the Tripod config array
*
* @return array
*/
public static function getConfig()
{
return self::$config;
}

/**
* This method was added to allow us to test the getInstance() method
* @codeCoverageIgnore
*/
public static function destroy()
{
self::$instance = null;
self::$config = null;
}
}
27 changes: 27 additions & 0 deletions src/ITripodConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Tripod;

interface ITripodConfig
{
/**
* Tripod Config instances are singletons, this method gets the existing or instantiates a new one.
*
* @return ITripodConfig
*/
public static function getInstance();

/**
* Loads the Tripod config into the instance
*
* @return void
*/
public static function setConfig(array $config);

/**
* Returns the Tripod config array
*
* @return array
*/
public static function getConfig();
}
22 changes: 22 additions & 0 deletions src/ITripodConfigSerializer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Tripod;

interface ITripodConfigSerializer
{

/**
* This should return an array that self::deserialize() can roundtrip into an Tripod Config object
*
* @return void
*/
public function serialize();

/**
* When given a valid config, returns a Tripod Config object
*
* @param array $config
* @return \Tripod\ITripodConfig
*/
public static function deserialize(array $config);
}
Loading

0 comments on commit 5536177

Please sign in to comment.