Skip to content

Commit

Permalink
feat: Add logging for graph db installation
Browse files Browse the repository at this point in the history
  • Loading branch information
yaraslau-kavaliou committed Oct 17, 2023
1 parent c7ca9d4 commit a5cdf12
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
20 changes: 20 additions & 0 deletions scripts/install/CleanGraphDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,21 @@

namespace oat\tao\scripts\install;

use common_persistence_GraphPersistence;
use common_persistence_Manager;
use oat\oatbox\extension\InstallAction;
use oat\oatbox\log\ColoredVerboseLogger;
use oat\oatbox\log\LoggerAwareTrait;
use Psr\Log\LogLevel;

class CleanGraphDatabase extends InstallAction
{
use LoggerAwareTrait;

public function __invoke($params)
{
$this->setLogger(new ColoredVerboseLogger(LogLevel::INFO));

$persistenceId = $params[0];
if (empty($persistenceId)) {
throw new \common_Exception('Persistence id should be provided in script parameters');
Expand All @@ -38,7 +46,19 @@ public function __invoke($params)
->get(common_persistence_Manager::SERVICE_ID)
->getPersistenceById($persistenceId);

$this->removeNodes($persistence);
$this->removeConstraints($persistence);

$this->logInfo(sprintf('Data from "%s" persistence has been cleared', $persistenceId));
}

private function removeNodes(common_persistence_GraphPersistence $persistence)
{
$persistence->run('MATCH (n) DETACH DELETE n');
}

private function removeConstraints(common_persistence_GraphPersistence $persistence)
{
$persistence->run('CALL apoc.schema.assert({}, {}, true) YIELD label, key RETURN *');
}
}
36 changes: 29 additions & 7 deletions scripts/install/EnableGraphDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,46 @@

namespace oat\tao\scripts\install;

use core_kernel_persistence_smoothsql_SmoothModel;
use core_kernel_persistence_starsql_StarModel;
use oat\generis\model\data\Ontology;
use oat\generis\model\kernel\persistence\smoothsql\search\ComplexSearchService;
use oat\oatbox\extension\InstallAction;
use oat\oatbox\log\ColoredVerboseLogger;
use oat\oatbox\log\LoggerAwareTrait;
use Psr\Log\LogLevel;

class EnableGraphDatabase extends InstallAction
{
use LoggerAwareTrait;

public function __invoke($params)
{
$this->setLogger(new ColoredVerboseLogger(LogLevel::INFO));

$persistenceId = $params[0];
if (empty($persistenceId)) {
throw new \common_Exception('Persistence id should be provided in script parameters');
}

$sm = $this->getServiceManager();
$this->updateOntologyService($persistenceId);
$this->updateComplexSearchService();
}

$ontologyService = $sm->get(Ontology::SERVICE_ID);
private function updateOntologyService($persistenceId)
{
$ontologyService = $this->getServiceManager()->get(Ontology::SERVICE_ID);
$serviceOptions = $ontologyService->getOptions();
$serviceOptions[core_kernel_persistence_smoothsql_SmoothModel::OPTION_PERSISTENCE] = $persistenceId;
$sm->register(Ontology::SERVICE_ID, new core_kernel_persistence_starsql_StarModel($serviceOptions));
$serviceOptions[core_kernel_persistence_starsql_StarModel::OPTION_PERSISTENCE] = $persistenceId;
$this
->getServiceManager()
->register(Ontology::SERVICE_ID, new core_kernel_persistence_starsql_StarModel($serviceOptions));

$complexSearchService = $sm->get(ComplexSearchService::SERVICE_ID);
$this->logInfo(sprintf('"%s" persistence has been set for ontology service', $persistenceId));
}

private function updateComplexSearchService()
{
$complexSearchService = $this->getServiceManager()->get(ComplexSearchService::SERVICE_ID);
$serviceOptions = $complexSearchService->getOptions();
$serviceOptions['shared']['search.neo4j.serialyser'] = false;
$serviceOptions['invokables']['search.driver.neo4j'] =
Expand All @@ -53,6 +70,11 @@ public function __invoke($params)
'\\oat\\generis\\model\\kernel\\persistence\\starsql\\search\\QuerySerializer';
$serviceOptions['invokables']['search.tao.gateway'] =
'\\oat\\generis\\model\\kernel\\persistence\\starsql\\search\\GateWay';
$sm->register(ComplexSearchService::SERVICE_ID, new ComplexSearchService($serviceOptions));
$this
->getServiceManager()
->register(ComplexSearchService::SERVICE_ID, new ComplexSearchService($serviceOptions));

$this
->logInfo('ComplexSearch service has been updated to compliant with graph database');
}
}

0 comments on commit a5cdf12

Please sign in to comment.