Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions packages/core/classes/pipeline/Node.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/*
This file is part of the eQual framework <http://www.github.com/cedricfrancoys/equal>
Some Rights Reserved, Cedric Francoys, 2010-2021
Licensed under GNU GPL 3 license <http://www.gnu.org/licenses/>
*/

namespace core\pipeline;

use equal\orm\Model;

class Node extends Model
{

public static function getColumns()
{
return [
'name' => [
'type' => 'string',
'required' => true
],

'description' => [
'type' => 'string'
],

'pipeline_id' => [
'type' => 'many2one',
'foreign_object' => 'core\pipeline\Pipeline',
'required' => true
],

'out_links_ids' => [
'type' => 'one2many',
'foreign_object' => 'core\pipeline\NodeLink',
'foreign_field' => 'source_node_id'
],

'in_links_ids' => [
'type' => 'one2many',
'foreign_object' => 'core\pipeline\NodeLink',
'foreign_field' => 'target_node_id'
],

'operation_controller' => [
'type' => 'string'
],

'operation_type' => [
'type' => 'string'
],

'params_ids' => [
'type' => 'one2many',
'foreign_object' => 'core\pipeline\Parameter',
'foreign_field' => 'node_id'
]
];
}

public function getUnique()
{
return [
['name', 'pipeline_id']
];
}
}
40 changes: 40 additions & 0 deletions packages/core/classes/pipeline/NodeLink.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/*
This file is part of the eQual framework <http://www.github.com/cedricfrancoys/equal>
Some Rights Reserved, Cedric Francoys, 2010-2021
Licensed under GNU GPL 3 license <http://www.gnu.org/licenses/>
*/

namespace core\pipeline;

use equal\orm\Model;

class NodeLink extends Model
{

public static function getColumns()
{
return [
'reference_node_id' => [
'type' => 'integer',
'required' => true
],

'source_node_id' => [
'type' => 'many2one',
'foreign_object' => 'core\pipeline\Node',
'required' => true
],

'target_node_id' => [
'type' => 'many2one',
'foreign_object' => 'core\pipeline\Node',
'required' => true
],

'target_param' => [
'type' => 'string'
]
];
}
}
34 changes: 34 additions & 0 deletions packages/core/classes/pipeline/Parameter.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/*
This file is part of Symbiose Community Edition <https://github.com/yesbabylon/symbiose>
Some Rights Reserved, Yesbabylon SRL, 2020-2021
Licensed under GNU AGPL 3 license <http://www.gnu.org/licenses/>
*/

namespace core\pipeline;

use equal\orm\Model;

class Parameter extends Model
{

public static function getColumns()
{
return [
'node_id' => [
'type' => 'many2one',
'foreign_object' => 'core\pipeline\Node'
],

'value' => [
'type' => 'string',
'required' => true
],

'param' => [
'type' => 'string',
'required' => true
]
];
}
}
31 changes: 31 additions & 0 deletions packages/core/classes/pipeline/Pipeline.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/*
This file is part of the eQual framework <http://www.github.com/cedricfrancoys/equal>
Some Rights Reserved, Cedric Francoys, 2010-2021
Licensed under GNU GPL 3 license <http://www.gnu.org/licenses/>
*/

namespace core\pipeline;

use equal\orm\Model;

class Pipeline extends Model
{

public static function getColumns()
{
return [
'nodes_ids' => [
'type' => 'one2many',
'foreign_object' => 'core\pipeline\Node',
'foreign_field' => 'pipeline_id'
],

'name' => [
'type' => 'string',
'required' => true,
'unique' => true
],
];
}
}
30 changes: 30 additions & 0 deletions packages/core/classes/pipeline/PipelineExecution.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/*
This file is part of the eQual framework <http://www.github.com/cedricfrancoys/equal>
Some Rights Reserved, Cedric Francoys, 2010-2021
Licensed under GNU GPL 3 license <http://www.gnu.org/licenses/>
*/

namespace core\pipeline;

use equal\orm\Model;

class PipelineExecution extends Model
{

public static function getColumns()
{
return [

'pipeline_id' => [
'type' => 'many2one',
'foreign_object' => 'core\pipeline\Pipeline',
'required' => true
],

'status' => [
'type' => 'string'
]
];
}
}
40 changes: 40 additions & 0 deletions packages/core/classes/pipeline/PipelineNodeExecution.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/*
This file is part of the eQual framework <http://www.github.com/cedricfrancoys/equal>
Some Rights Reserved, Cedric Francoys, 2010-2021
Licensed under GNU GPL 3 license <http://www.gnu.org/licenses/>
*/

namespace core\pipeline;

use equal\orm\Model;

class PipelineNodeExecution extends Model
{

public static function getColumns()
{
return [

'pipeline_execution_id' => [
'type' => 'many2one',
'foreign_object' => 'core\pipeline\PipelineExecution',
'required' => true
],

'node_id' => [
'type' => 'many2one',
'foreign_object' => 'core\pipeline\Node',
'required' => true
],

'status' => [
'type' => 'string'
],

'result' => [
'type' => 'string'
]
];
}
}
96 changes: 96 additions & 0 deletions packages/core/data/check-pipeline.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php
/*
This file is part of the eQual framework <http://www.github.com/cedricfrancoys/equal>
Some Rights Reserved, Cedric Francoys, 2010-2021
Licensed under GNU LGPL 3 license <http://www.gnu.org/licenses/>
*/

use core\pipeline\Pipeline;

list($params, $providers) = eQual::announce([
'description' => 'Run the given pipeline.',
'params' => [
'pipeline_id' => [
'description' => 'Pipeline\'s id',
'type' => 'integer'
]
],
'response' => [
'content-type' => 'application/json',
'charset' => 'UTF-8',
'accept-origin' => '*',
'schema' => [
'type' => '',
'qty' => ''
]
],
'access' => [
'visibility' => 'protected'
],
'providers' => ['context']
]);

/**
* @var \equal\php\Context $context
*/
$context = $providers['context'];

$pipeline = Pipeline::id($params['pipeline_id'])
->read([
'nodes_ids' => [
'id',
'in_links_ids' => ['source_node_id'],
'out_links_ids' => ['target_node_id']
]
])
->first();

$pipeline_nodes = $pipeline['nodes_ids']->get(true);

$graph = [];

foreach ($pipeline_nodes as $node) {
$graph[$node['id']] = [];
foreach ($node['in_links_ids'] as $link) {
$graph[$node['id']][] = $link['source_node_id'];
}
foreach ($node['out_links_ids'] as $link) {
$graph[$node['id']][] = $link['target_node_id'];
}
$graph[$node['id']] = array_unique($graph[$node['id']]);
}

if (!isGraphConnected($graph)) {
throw new Exception('non-compliant_pipeline', QN_ERROR_UNKNOWN);
}

$context->httpResponse()
->body(['success' => true])
->send();

function isGraphConnected($graph)
{
$visited = [];
$start_node = array_key_first($graph);

depthSearch($graph, $start_node, $visited);

foreach ($graph as $node => $adjacent_nodes) {
if (!isset($visited[$node])) {
return false;
}
}

return true;
};

function depthSearch($graph, $node, &$visited)
{
$visited[$node] = true;

foreach ($graph[$node] as $adjacent_node) {
if (!isset($visited[$adjacent_node])) {
depthSearch($graph, $adjacent_node, $visited);
}
}
};
49 changes: 49 additions & 0 deletions packages/core/data/pipeline/test-divide.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/*
This file is part of the eQual framework <http://www.github.com/cedricfrancoys/equal>
Some Rights Reserved, Cedric Francoys, 2010-2021
Licensed under GNU LGPL 3 license <http://www.gnu.org/licenses/>
*/
list($params, $providers) = eQual::announce([
'description' => 'Returns the division of two values.',
'params' => [
'numerator' => [
'description' => 'Numerator',
'type' => 'integer',
'usage' => 'numeric/integer',
'required' => true
],
'denominator' => [
'description' => 'Denominator',
'type' => 'integer',
'usage' => 'numeric/integer',
'required' => true
]
],
'response' => [
'content-type' => 'application/json',
'charset' => 'UTF-8',
'accept-origin' => '*',
'schema' => [
'type' => 'integer',
'usage' => 'numeric/integer',
'qty' => 'one'
]
],
'access' => [
'visibility' => 'public',
],
'providers' => ['context']
]);

list($context) = [$providers['context']];

$result = 0;

if ($params['denominator'] != 0) {
$result = intdiv($params['numerator'], $params['denominator']);
}

$context->httpResponse()
->body($result)
->send();
Loading