Update unit tests and legacy

This commit is contained in:
Romain Neutron
2013-10-01 17:54:30 +02:00
parent d561436815
commit 58c402ac2b
19 changed files with 188 additions and 184 deletions

View File

@@ -129,6 +129,10 @@ registration-fields:
required: true required: true
task-manager: task-manager:
status: started status: started
listener:
protocol: tcp
host: 127.0.0.1
port: 6700
xsendfile: xsendfile:
enabled: false enabled: false
type: nginx type: nginx

View File

@@ -11,6 +11,7 @@
namespace Alchemy\Phrasea\Controller\Admin; namespace Alchemy\Phrasea\Controller\Admin;
use Alchemy\Phrasea\TaskManager\TaskManagerStatus;
use Silex\Application; use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
@@ -331,7 +332,8 @@ class Databoxes implements ControllerProviderInterface
*/ */
public function databasesUpgrade(Application $app, Request $request) public function databasesUpgrade(Application $app, Request $request)
{ {
if (\phrasea::is_scheduler_started($app)) { $info = $app['task-manager.live-information']->getManager();
if (TaskManagerStatus::STATUS_STARTED === $info['actual']) {
return $app->redirectPath('admin_databases', array('success' => 0, 'error' => 'scheduler-started')); return $app->redirectPath('admin_databases', array('success' => 0, 'error' => 'scheduler-started'));
} }

View File

@@ -210,21 +210,23 @@ class V1 implements ControllerProviderInterface
/** /**
* Get task informations * Get task informations
* *
* Route : /monitor/task/{task_id}/ * Route : /monitor/task/{task}/
* *
* Method : GET * Method : GET
* *
* Parameters : * Parameters :
* *
*/ */
$controllers->get('/monitor/task/{task_id}/', function(SilexApplication $app, Request $request, $task_id) { $controllers->get('/monitor/task/{task}/', function(SilexApplication $app, Request $request, $task) {
return $app['api']->get_task($app, $task_id)->get_response(); return $app['api']->get_task($app, $task)->get_response();
})->before($mustBeAdmin)->assert('task_id', '\d+'); })
->convert('task', array($app['converter.task'], 'convert'))
->before($mustBeAdmin)->assert('task', '\d+');
/** /**
* Start task * Start task
* *
* Route : /monitor/task/{task_id}/ * Route : /monitor/task/{task}/
* *
* Method : POST * Method : POST
* *
@@ -232,37 +234,43 @@ class V1 implements ControllerProviderInterface
* - name (string) change the name of the task * - name (string) change the name of the task
* - autostart (boolean) start task when scheduler starts * - autostart (boolean) start task when scheduler starts
*/ */
$controllers->post('/monitor/task/{task_id}/', function(SilexApplication $app, Request $request, $task_id) { $controllers->post('/monitor/task/{task}/', function(SilexApplication $app, Request $request, $task) {
return $app['api']->set_task_property($app, $task_id)->get_response(); return $app['api']->set_task_property($app, $task)->get_response();
})->before($mustBeAdmin)->assert('task_id', '\d+'); })
->convert('task', array($app['converter.task'], 'convert'))
->before($mustBeAdmin)->assert('task', '\d+');
/** /**
* Start task * Start task
* *
* Route : /monitor/task/{task_id}/start/ * Route : /monitor/task/{task}/start/
* *
* Method : POST * Method : POST
* *
* Parameters : * Parameters :
* *
*/ */
$controllers->post('/monitor/task/{task_id}/start/', function(SilexApplication $app, Request $request, $task_id) { $controllers->post('/monitor/task/{task}/start/', function(SilexApplication $app, Request $request, $task) {
return $app['api']->start_task($app, $task_id)->get_response(); return $app['api']->start_task($app, $task)->get_response();
})->before($mustBeAdmin); })
->convert('task', array($app['converter.task'], 'convert'))
->before($mustBeAdmin);
/** /**
* Stop task * Stop task
* *
* Route : /monitor/task/{task_id}/stop/ * Route : /monitor/task/{task}/stop/
* *
* Method : POST * Method : POST
* *
* Parameters : * Parameters :
* *
*/ */
$controllers->post('/monitor/task/{task_id}/stop/', function(SilexApplication $app, Request $request, $task_id) { $controllers->post('/monitor/task/{task}/stop/', function(SilexApplication $app, Request $request, $task) {
return $app['api']->stop_task($app, $task_id)->get_response(); return $app['api']->stop_task($app, $task)->get_response();
})->before($mustBeAdmin); })
->convert('task', array($app['converter.task'], 'convert'))
->before($mustBeAdmin);
/** /**
* Get some information about phraseanet * Get some information about phraseanet

View File

@@ -14,6 +14,7 @@ namespace Alchemy\Phrasea\Controller\Prod;
use Alchemy\Phrasea\Controller\RecordsRequest; use Alchemy\Phrasea\Controller\RecordsRequest;
use Alchemy\Phrasea\Exception\RuntimeException; use Alchemy\Phrasea\Exception\RuntimeException;
use DataURI; use DataURI;
use PHPExiftool\Exception\ExceptionInterface as PHPExiftoolException;
use Silex\Application; use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@@ -49,7 +50,7 @@ class Tools implements ControllerProviderInterface
$metadatas = $app['exiftool.reader'] $metadatas = $app['exiftool.reader']
->files($record->get_subdef('document')->get_pathfile()) ->files($record->get_subdef('document')->get_pathfile())
->first()->getMetadatas(); ->first()->getMetadatas();
} catch (\PHPExiftool\Exception\Exception $e) { } catch (PHPExiftoolException $e) {
} catch (\Exception_Media_SubdefNotFound $e) { } catch (\Exception_Media_SubdefNotFound $e) {

View File

@@ -31,13 +31,18 @@ class TaskManagerServiceProvider implements ServiceProviderInterface
}); });
$app['task-manager'] = $app->share(function(Application $app) { $app['task-manager'] = $app->share(function(Application $app) {
$options = array( $options = $app['task-manager.listener.options'];
'listener_protocol' => 'tcp',
'listener_host' => '127.0.0.1',
'listener_port' => 6660,
);
return TaskManager::create($app['dispatcher'], $app['task-manager.logger'], $app['task-manager.task-list'], $options); return TaskManager::create(
$app['dispatcher'],
$app['task-manager.logger'],
$app['task-manager.task-list'],
array(
'listener_protocol' => $options['protocol'],
'listener_host' => $options['host'],
'listener_port' => $options['port'],
)
);
}); });
$app['task-manager.task-list'] = $app->share(function(Application $app) { $app['task-manager.task-list'] = $app->share(function(Application $app) {

View File

@@ -22,7 +22,7 @@ class ManipulatorServiceProvider implements ServiceProviderInterface
public function register(SilexApplication $app) public function register(SilexApplication $app)
{ {
$app['manipulator.task'] = $app->share(function(SilexApplication $app) { $app['manipulator.task'] = $app->share(function(SilexApplication $app) {
return new TaskManipulator($app['EM']); return new TaskManipulator($app['EM'], $app['task-manager.notifier']);
}); });
$app['manipulator.user'] = $app->share(function($app) { $app['manipulator.user'] = $app->share(function($app) {

View File

@@ -104,7 +104,7 @@ class Installer
$this->app['manipulator.task']->create( $this->app['manipulator.task']->create(
$job->getName(), $job->getName(),
$job->getJobId(), $job->getJobId(),
$job->getEditor()->getDefaultSettings($app['phraseanet.configuration']), $job->getEditor()->getDefaultSettings($this->app['phraseanet.configuration']),
$job->getEditor()->getDefaultPeriod() $job->getEditor()->getDefaultPeriod()
); );
} }

View File

@@ -65,7 +65,9 @@ class PhraseanetIndexerJob extends AbstractJob
$indexerPath = $this->getPhraseanetIndexerPath($app); $indexerPath = $this->getPhraseanetIndexerPath($app);
$builder = new ProcessBuilder($this->getCommandline($indexerPath, $app, $task)); $builder = new ProcessBuilder($this->getCommandline($indexerPath, $app, $task));
$builder->setWorkingDirectory(dirname($indexerPath)); $builder
->setWorkingDirectory(dirname($indexerPath))
->setTimeout(0);
$process = $builder->getProcess(); $process = $builder->getProcess();
if (0 < $socketPort) { if (0 < $socketPort) {

View File

@@ -15,6 +15,7 @@ use Alchemy\Phrasea\TaskManager\Editor\WriteMetadataEditor;
use PHPExiftool\Driver\Metadata; use PHPExiftool\Driver\Metadata;
use PHPExiftool\Driver\Value; use PHPExiftool\Driver\Value;
use PHPExiftool\Driver\Tag; use PHPExiftool\Driver\Tag;
use PHPExiftool\Exception\ExceptionInterface as PHPExiftoolException;
use PHPExiftool\Writer; use PHPExiftool\Writer;
class WriteMetadataJob extends AbstractJob class WriteMetadataJob extends AbstractJob
@@ -158,8 +159,8 @@ class WriteMetadataJob extends AbstractJob
try { try {
$app['exiftool.writer']->write($file, $metadatas); $app['exiftool.writer']->write($file, $metadatas);
$this->log('debug', sprintf('meta written for sbasid=%1$d - recordid=%2$d (%3$s)', $databox->get_sbas_id(), $record_id, $name)); $this->log('debug', sprintf('meta written for sbasid=%1$d - recordid=%2$d (%3$s)', $databox->get_sbas_id(), $record_id, $name));
} catch (\PHPExiftool\Exception\Exception $e) { } catch (PHPExiftoolException $e) {
$this->log('debug', sprintf('meta NOT written for sbasid=%1$d - recordid=%2$d (%3$s) because "%s"', $databox->get_sbas_id(), $record_id, $name, $e->getMessage())); $this->log('error', sprintf('meta was not written for sbasid=%d - recordid=%d (%s) because "%s"', $databox->get_sbas_id(), $record_id, $name, $e->getMessage()));
} }
} }

View File

@@ -13,7 +13,7 @@ namespace Alchemy\Phrasea\TaskManager;
use Entities\Task as TaskEntity; use Entities\Task as TaskEntity;
use Alchemy\TaskManager\TaskInterface; use Alchemy\TaskManager\TaskInterface;
use Symfony\Component\Process\ProcessableInterface; use Symfony\Component\Process\Process;
class Task implements TaskInterface class Task implements TaskInterface
{ {
@@ -22,7 +22,7 @@ class Task implements TaskInterface
private $iterations; private $iterations;
private $process; private $process;
public function __construct(TaskEntity $entity, $name, $iterations, ProcessableInterface $process) public function __construct(TaskEntity $entity, $name, $iterations, Process $process)
{ {
$this->entity = $entity; $this->entity = $entity;
$this->name = $name; $this->name = $name;

View File

@@ -23,6 +23,7 @@ use Alchemy\Phrasea\Model\Entities\Feed;
use Alchemy\Phrasea\Model\Entities\FeedEntry; use Alchemy\Phrasea\Model\Entities\FeedEntry;
use Alchemy\Phrasea\Model\Entities\FeedItem; use Alchemy\Phrasea\Model\Entities\FeedItem;
use Alchemy\Phrasea\Model\Entities\LazaretFile; use Alchemy\Phrasea\Model\Entities\LazaretFile;
use Alchemy\Phrasea\Model\Entities\Task;
use Alchemy\Phrasea\Model\Entities\UserQuery; use Alchemy\Phrasea\Model\Entities\UserQuery;
use Alchemy\Phrasea\Model\Entities\ValidationParticipant; use Alchemy\Phrasea\Model\Entities\ValidationParticipant;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@@ -115,19 +116,17 @@ class API_V1_adapter extends API_V1_Abstract
public function get_scheduler(Application $app) public function get_scheduler(Application $app)
{ {
$result = new \API_V1_result($app, $app['request'], $this); $result = new \API_V1_result($app, $app['request'], $this);
$date = new \DateTime();
$data = $app['task-manager.live-information']->getManager();
$taskManager = $app['task-manager']; $result->set_datas(array('scheduler' => array(
$ret = $taskManager->getSchedulerState(); 'configuration' => $data['configuration'],
'state' => $data['actual'],
$ret['state'] = $ret['status']; 'status' => $data['actual'],
'pid' => $data['process-id'],
unset($ret['qdelay'], $ret['status']); 'process-id' => $data['process-id'],
'updated_on' => $date->format(DATE_ATOM),
if (null !== $ret['updated_on']) { )));
$ret['updated_on'] = $ret['updated_on']->format(DATE_ATOM);
}
$result->set_datas(array('scheduler' => $ret));
return $result; return $result;
} }
@@ -143,12 +142,9 @@ class API_V1_adapter extends API_V1_Abstract
{ {
$result = new \API_V1_result($app, $app['request'], $this); $result = new \API_V1_result($app, $app['request'], $this);
$taskManager = $app['task-manager'];
$tasks = $taskManager->getTasks();
$ret = array(); $ret = array();
foreach ($tasks as $task) { foreach ($app['manipulator.task']->getRepository()->findAll() as $task) {
$ret[] = $this->list_task($task); $ret[] = $this->list_task($app, $task);
} }
$result->set_datas(array('tasks' => $ret)); $result->set_datas(array('tasks' => $ret));
@@ -156,18 +152,28 @@ class API_V1_adapter extends API_V1_Abstract
return $result; return $result;
} }
protected function list_task(\task_abstract $task) protected function list_task(Application $app, Task $task)
{ {
$data = $app['task-manager.live-information']->getTask($task);
return array( return array(
'id' => $task->getID(), 'id' => $task->getId(),
'title' => $task->getName(),
'name' => $task->getName(), 'name' => $task->getName(),
'state' => $task->getState(), 'state' => $task->getStatus(),
'pid' => $task->getPID(), 'status' => $task->getStatus(),
'title' => $task->getTitle(), 'actual-status' => $data['actual'],
'last_exec_time' => $task->getLastExecTime() ? $task->getLastExecTime()->format(DATE_ATOM) : null, 'process-id' => $data['process-id'],
'auto_start' => !!$task->isActive(), 'pid' => $data['process-id'],
'runner' => $task->getRunner(), 'jobId' => $task->getJobId(),
'crash_counter' => $task->getCrashCounter() 'period' => $task->getPeriod(),
'last_exec_time' => $task->getLastExecution() ? $task->getLastExecution()->format(DATE_ATOM) : null,
'last_execution' => $task->getLastExecution() ? $task->getLastExecution()->format(DATE_ATOM) : null,
'updated' => $task->getUpdated() ? $task->getUpdated()->format(DATE_ATOM) : null,
'created' => $task->getCreated() ? $task->getCreated()->format(DATE_ATOM) : null,
'auto_start' => $task->getStatus() === Task::STATUS_STARTED,
'crashed' => $task->getCrashed(),
'status' => $task->getStatus(),
); );
} }
@@ -175,19 +181,13 @@ class API_V1_adapter extends API_V1_Abstract
* Get informations about an identified task * Get informations about an identified task
* *
* @param \Silex\Application $app The API silex application * @param \Silex\Application $app The API silex application
* @param integer $taskId * @param Task $task
* @return \API_V1_result * @return \API_V1_result
*/ */
public function get_task(Application $app, $taskId) public function get_task(Application $app, Task $task)
{ {
$result = new \API_V1_result($app, $app['request'], $this); $result = new \API_V1_result($app, $app['request'], $this);
$ret = array('task' => $this->list_task($app, $task));
$taskManager = $app['task-manager'];
$ret = array(
'task' => $this->list_task($taskManager->getTask($taskId))
);
$result->set_datas($ret); $result->set_datas($ret);
return $result; return $result;
@@ -197,21 +197,15 @@ class API_V1_adapter extends API_V1_Abstract
* Start a specified task * Start a specified task
* *
* @param \Silex\Application $app The API silex application * @param \Silex\Application $app The API silex application
* @param integer $taskId The task id * @param Task $task The task to start
* @return \API_V1_result * @return \API_V1_result
*/ */
public function start_task(Application $app, $taskId) public function start_task(Application $app, Task $task)
{ {
$result = new \API_V1_result($app, $app['request'], $this); $result = new \API_V1_result($app, $app['request'], $this);
$taskManager = $app['task-manager']; $app['manipulator.task']->start($task);
$result->set_datas(array('task' => $this->list_task($app, $task)));
$task = $taskManager->getTask($taskId);
if (!in_array($task->getState(), array(\task_abstract::STATE_TOSTART, \task_abstract::STATE_STARTED))) {
$task->setState(\task_abstract::STATE_TOSTART);
}
$result->set_datas(array('task' => $this->list_task($task)));
return $result; return $result;
} }
@@ -220,20 +214,15 @@ class API_V1_adapter extends API_V1_Abstract
* Stop a specified task * Stop a specified task
* *
* @param \Silex\Application $app The API silex application * @param \Silex\Application $app The API silex application
* @param integer $taskId The task id * @param Task $task The task to stop
* @return \API_V1_result * @return \API_V1_result
*/ */
public function stop_task(Application $app, $taskId) public function stop_task(Application $app, Task $task)
{ {
$result = new API_V1_result($app, $app['request'], $this); $result = new API_V1_result($app, $app['request'], $this);
$taskManager = $app['task-manager']; $app['manipulator.task']->stop($task);
$result->set_datas(array('task' => $this->list_task($app, $task)));
$task = $taskManager->getTask($taskId);
if (!in_array($task->getState(), array(\task_abstract::STATE_TOSTOP, \task_abstract::STATE_STOPPED))) {
$task->setState(\task_abstract::STATE_TOSTOP);
}
$result->set_datas(array('task' => $this->list_task($task)));
return $result; return $result;
} }
@@ -244,11 +233,11 @@ class API_V1_adapter extends API_V1_Abstract
* - autostart * - autostart
* *
* @param \Silex\Application $app Silex application * @param \Silex\Application $app Silex application
* @param integer $taskId the task id * @param Task $task The task
* @return \API_V1_result * @return \API_V1_result
* @throws \API_V1_exception_badrequest * @throws \API_V1_exception_badrequest
*/ */
public function set_task_property(Application $app, $taskId) public function set_task_property(Application $app, $task)
{ {
$result = new API_V1_result($app, $app['request'], $this); $result = new API_V1_result($app, $app['request'], $this);
@@ -259,19 +248,14 @@ class API_V1_adapter extends API_V1_Abstract
throw new \API_V1_exception_badrequest(); throw new \API_V1_exception_badrequest();
} }
$taskManager = $app['task-manager'];
$task = $taskManager->getTask($taskId);
if ($title) { if ($title) {
$task->setTitle($title); $task->setName($title);
} }
if ($autostart) { if ($autostart) {
$task->setActive(!!$autostart); $task->setStatus(Task::STATUS_STARTED);
} }
$result->set_datas(array('task' => $this->list_task($task))); $result->set_datas(array('task' => $this->list_task($app, $task)));
return $result; return $result;
} }

View File

@@ -11,6 +11,8 @@
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Entities\Task;
/** /**
* *
* @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @license http://opensource.org/licenses/gpl-3.0 GPLv3
@@ -66,7 +68,7 @@ class patch_370a8 implements patchInterface
{ {
$ttasks = array(); $ttasks = array();
$conn = $appbox->get_connection(); $conn = $appbox->get_connection();
$sql = 'SELECT task_id, active, name, class, settings FROM task2 WHERE class=\'task_period_workflow01\' OR class=\'task_period_ftv\''; $sql = 'SELECT task_id, active, name, class, settings FROM task2 WHERE class=\'task_period_workflow01\'';
if (($stmt = $conn->prepare($sql)) !== FALSE) { if (($stmt = $conn->prepare($sql)) !== FALSE) {
$stmt->execute(); $stmt->execute();
$ttasks = $stmt->fetchAll(); $ttasks = $stmt->fetchAll();
@@ -80,7 +82,7 @@ class patch_370a8 implements patchInterface
$warning = array(); $warning = array();
/* /*
* migrating task 'workflow01' or 'task_period_ftv' * migrating task 'workflow01'
*/ */
$x = $task['settings']; $x = $task['settings'];
if (false !== $sx = simplexml_load_string($x)) { if (false !== $sx = simplexml_load_string($x)) {
@@ -193,58 +195,6 @@ class patch_370a8 implements patchInterface
$taskstodel[] = $task['task_id']; $taskstodel[] = $task['task_id'];
} }
/*
* migrating task 'task_period_ftv'
*/
if ($task['class'] === 'task_period_ftv') {
foreach ($sx->tasks->task as $sxt) {
$active = true;
$warning = array();
$t = $dom->importNode(dom_import_simplexml($sxt), true);
$t->setAttribute('active', '0');
// $t->setAttribute('name', 'imported from \'' . $task->getTitle() . '\'');
$t->setAttribute('name', 'imported from \'' . $task['name'] . '\'');
$t->setAttribute('action', 'update');
if ($sx->sbas_id) {
$sbas_id = trim($sx->sbas_id);
if ($sbas_id != '' && is_numeric($sbas_id)) {
$t->setAttribute('sbas_id', $sx->sbas_id);
} else {
$warning[] = sprintf("Bad sbas_id '%s'", $sbas_id);
$active = false;
}
} else {
$warning[] = sprintf("missing sbas_id");
$active = false;
}
if ($active && $task['active'] == '1') {
$t->setAttribute('active', '1');
}
foreach ($warning as $w) {
$t->appendChild($dom->createComment($w));
}
$x = new DOMXPath($dom);
$nlfrom = $x->query('from', $t);
if ($nlfrom->length == 1) {
$nlcoll = $x->query('colls', $nlfrom->item(0));
if ($nlcoll->length > 0) {
$nn = $dom->createElement('coll');
$nn->setAttribute('compare', '=');
$nn->setAttribute('id', $nlcoll->item(0)->getAttribute('id'));
$nlfrom->item(0)->replaceChild($nn, $nlcoll->item(0));
}
$tasks->appendChild($t);
}
}
$taskstodel[] = $task['task_id'];
}
} }
if (count($taskstodel) > 0) { if (count($taskstodel) > 0) {
@@ -256,8 +206,20 @@ class patch_370a8 implements patchInterface
* save new tasks * save new tasks
*/ */
foreach ($tdom as $newtask) { foreach ($tdom as $newtask) {
$task = task_abstract::create($app, 'task_period_RecordMover', $newtask['dom']->saveXML()); $settings = $newtask['dom']->saveXML();
$sxml = simplexml_load_string($settings);
$period = $sxml->period ? (int) $sxml->period : 300;
$task = new Task();
$task
->setName('Record mover')
->setJobId('RecordMover')
->setSettings($settings)
->setPeriod($period)
->setStatus(Task::STATUS_STARTED);
$app['EM']->persist($task);
} }
$app['EM']->flush();
return true; return true;
} }

View File

@@ -1607,9 +1607,10 @@ class record_adapter implements record_Interface, cache_cacheableInterface
public function generate_subdefs(databox $databox, Application $app, Array $wanted_subdefs = null) public function generate_subdefs(databox $databox, Application $app, Array $wanted_subdefs = null)
{ {
$subdefs = $databox->get_subdef_structure()->getSubdefGroup($this->get_type()); $subdefs = $databox->get_subdef_structure()->getSubdefGroup($this->get_type());
$logger = isset($app['task-manager.logger']) ? $app['task-manager.logger'] : $app['monolog'];
if (!$subdefs) { if (!$subdefs) {
$app['task-manager.logger']->addInfo(sprintf('Nothing to do for %s', $this->get_type())); $logger->addInfo(sprintf('Nothing to do for %s', $this->get_type()));
return; return;
} }
@@ -1626,14 +1627,14 @@ class record_adapter implements record_Interface, cache_cacheableInterface
if ($this->has_subdef($subdefname) && $this->get_subdef($subdefname)->is_physically_present()) { if ($this->has_subdef($subdefname) && $this->get_subdef($subdefname)->is_physically_present()) {
$pathdest = $this->get_subdef($subdefname)->get_pathfile(); $pathdest = $this->get_subdef($subdefname)->get_pathfile();
$this->get_subdef($subdefname)->remove_file(); $this->get_subdef($subdefname)->remove_file();
$app['task-manager.logger']->addInfo(sprintf('Removed old file for %s', $subdefname)); $logger->addInfo(sprintf('Removed old file for %s', $subdefname));
$this->clearSubdefCache($subdefname); $this->clearSubdefCache($subdefname);
} }
$pathdest = $this->generateSubdefPathname($subdef, $app['filesystem'], $pathdest); $pathdest = $this->generateSubdefPathname($subdef, $app['filesystem'], $pathdest);
$app['task-manager.logger']->addInfo(sprintf('Generating subdef %s to %s', $subdefname, $pathdest)); $logger->addInfo(sprintf('Generating subdef %s to %s', $subdefname, $pathdest));
$this->generate_subdef($app['media-alchemyst'], $subdef, $pathdest, $app['task-manager.logger']); $this->generate_subdef($app['media-alchemyst'], $subdef, $pathdest, $logger);
if (file_exists($pathdest)) { if (file_exists($pathdest)) {
$media = $app['mediavorus']->guess($pathdest); $media = $app['mediavorus']->guess($pathdest);

View File

@@ -136,4 +136,8 @@ xsendfile:
mapping: [] mapping: []
task-manager: task-manager:
status: started status: started
listener:
protocol: tcp
host: 127.0.0.1
port: 6700
plugins: [] plugins: []

View File

@@ -6,6 +6,7 @@ use Alchemy\Phrasea\Border\File;
use Alchemy\Phrasea\Border\Manager; use Alchemy\Phrasea\Border\Manager;
use Alchemy\Phrasea\Core\PhraseaEvents; use Alchemy\Phrasea\Core\PhraseaEvents;
use Alchemy\Phrasea\Authentication\Context; use Alchemy\Phrasea\Authentication\Context;
use Entities\Task;
use Symfony\Component\HttpKernel\Client; use Symfony\Component\HttpKernel\Client;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
@@ -289,7 +290,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->evaluateMeta200($content); $this->evaluateMeta200($content);
$response = $content['response']; $response = $content['response'];
$tasks = self::$DI['app']['task-manager']->getTasks(); $tasks = self::$DI['app']['manipulator.task']->getRepository()->findAll();
$this->assertEquals(count($tasks), count($response['tasks'])); $this->assertEquals(count($tasks), count($response['tasks']));
foreach ($response['tasks'] as $task) { foreach ($response['tasks'] as $task) {
@@ -323,8 +324,11 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->assertArrayHasKey('state', $response['scheduler']); $this->assertArrayHasKey('state', $response['scheduler']);
$this->assertArrayHasKey('pid', $response['scheduler']); $this->assertArrayHasKey('pid', $response['scheduler']);
$this->assertArrayHasKey('updated_on', $response['scheduler']); $this->assertArrayHasKey('updated_on', $response['scheduler']);
$this->assertArrayHasKey('status', $response['scheduler']);
$this->assertArrayHasKey('configuration', $response['scheduler']);
$this->assertArrayHasKey('process-id', $response['scheduler']);
$this->assertEquals(3, count($response['scheduler'])); $this->assertEquals(6, count($response['scheduler']));
if (null !== $response['scheduler']['updated_on']) { if (null !== $response['scheduler']['updated_on']) {
$this->assertDateAtom($response['scheduler']['updated_on']); $this->assertDateAtom($response['scheduler']['updated_on']);
@@ -341,9 +345,19 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->assertArrayHasKey('id', $task); $this->assertArrayHasKey('id', $task);
$this->assertArrayHasKey('name', $task); $this->assertArrayHasKey('name', $task);
$this->assertArrayHasKey('state', $task); $this->assertArrayHasKey('state', $task);
$this->assertArrayHasKey('status', $task);
$this->assertArrayHasKey('actual-status', $task);
$this->assertArrayHasKey('pid', $task); $this->assertArrayHasKey('pid', $task);
$this->assertArrayHasKey('process-id', $task);
$this->assertArrayHasKey('title', $task); $this->assertArrayHasKey('title', $task);
$this->assertArrayHasKey('crashed', $task);
$this->assertArrayHasKey('auto_start', $task);
$this->assertArrayHasKey('last_exec_time', $task); $this->assertArrayHasKey('last_exec_time', $task);
$this->assertArrayHasKey('last_execution', $task);
$this->assertArrayHasKey('updated', $task);
$this->assertArrayHasKey('created', $task);
$this->assertArrayHasKey('period', $task);
$this->assertArrayHasKey('jobId', $task);
$this->assertInternalType('integer', $task['id']); $this->assertInternalType('integer', $task['id']);
@@ -352,13 +366,8 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
} }
$av_states = array( $av_states = array(
\task_abstract::STATE_STARTED, Task::STATUS_STARTED,
\task_abstract::STATE_STOPPED, Task::STATUS_STOPPED,
\task_abstract::STATE_OK,
\task_abstract::STATE_TODELETE,
\task_abstract::STATE_TORESTART,
\task_abstract::STATE_TOSTOP,
\task_abstract::STATE_TOSTART,
); );
$this->assertContains($task['state'], $av_states); $this->assertContains($task['state'], $av_states);
@@ -377,7 +386,8 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
*/ */
public function testGetMonitorTaskById() public function testGetMonitorTaskById()
{ {
$tasks = self::$DI['app']['task-manager']->getTasks(); $this->insertTwoTasks();
$tasks = self::$DI['app']['manipulator.task']->getRepository()->findAll();
if (null === self::$adminToken) { if (null === self::$adminToken) {
$this->markTestSkipped('there is no user with admin rights'); $this->markTestSkipped('there is no user with admin rights');
@@ -388,8 +398,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
} }
$this->setToken(self::$adminToken); $this->setToken(self::$adminToken);
reset($tasks); $idTask = $tasks[0]->getId();
$idTask = key($tasks);
$route = '/api/v1/monitor/task/' . $idTask . '/'; $route = '/api/v1/monitor/task/' . $idTask . '/';
$this->evaluateMethodNotAllowedRoute($route, array('PUT', 'DELETE')); $this->evaluateMethodNotAllowedRoute($route, array('PUT', 'DELETE'));
@@ -409,7 +418,8 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
*/ */
public function testPostMonitorTaskById() public function testPostMonitorTaskById()
{ {
$tasks = self::$DI['app']['task-manager']->getTasks(); $this->insertTwoTasks();
$tasks = self::$DI['app']['manipulator.task']->getRepository()->findAll();
if (null === self::$adminToken) { if (null === self::$adminToken) {
$this->markTestSkipped('there is no user with admin rights'); $this->markTestSkipped('there is no user with admin rights');
@@ -420,8 +430,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
} }
$this->setToken(self::$adminToken); $this->setToken(self::$adminToken);
reset($tasks); $idTask = $tasks[0]->getId();
$idTask = key($tasks);
$route = '/api/v1/monitor/task/' . $idTask . '/'; $route = '/api/v1/monitor/task/' . $idTask . '/';
$this->evaluateMethodNotAllowedRoute($route, array('PUT', 'DELETE')); $this->evaluateMethodNotAllowedRoute($route, array('PUT', 'DELETE'));
@@ -464,15 +473,15 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->markTestSkipped('there is no user with admin rights'); $this->markTestSkipped('there is no user with admin rights');
} }
$tasks = self::$DI['app']['task-manager']->getTasks(); $this->insertTwoTasks();
$tasks = self::$DI['app']['manipulator.task']->getRepository()->findAll();
if (!count($tasks)) { if (!count($tasks)) {
$this->markTestSkipped('no tasks created for the current instance'); $this->markTestSkipped('no tasks created for the current instance');
} }
$this->setToken(self::$adminToken); $this->setToken(self::$adminToken);
reset($tasks); $idTask = $tasks[0]->getId();
$idTask = key($tasks);
$route = '/api/v1/monitor/task/' . $idTask . '/start/'; $route = '/api/v1/monitor/task/' . $idTask . '/start/';
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE')); $this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
@@ -485,8 +494,8 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->assertArrayHasKey('task', $content['response']); $this->assertArrayHasKey('task', $content['response']);
$this->evaluateGoodTask($content['response']['task']); $this->evaluateGoodTask($content['response']['task']);
$task = self::$DI['app']['task-manager']->getTask($idTask); $task = self::$DI['app']['manipulator.task']->getRepository()->find($idTask);
$this->assertContains($task->getState(), array(\task_abstract::STATE_TOSTART, \task_abstract::STATE_STARTED)); $this->assertEquals(Task::STATUS_STARTED, $task->getStatus());
} }
/** /**
@@ -495,7 +504,8 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
*/ */
public function testPostMonitorStopTask() public function testPostMonitorStopTask()
{ {
$tasks = self::$DI['app']['task-manager']->getTasks(); $this->insertTwoTasks();
$tasks = self::$DI['app']['manipulator.task']->getRepository()->findAll();
if (null === self::$adminToken) { if (null === self::$adminToken) {
$this->markTestSkipped('there is no user with admin rights'); $this->markTestSkipped('there is no user with admin rights');
@@ -506,8 +516,7 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
} }
$this->setToken(self::$adminToken); $this->setToken(self::$adminToken);
reset($tasks); $idTask = $tasks[0]->getId();
$idTask = key($tasks);
$route = '/api/v1/monitor/task/' . $idTask . '/stop/'; $route = '/api/v1/monitor/task/' . $idTask . '/stop/';
$this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE')); $this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE'));
@@ -520,8 +529,8 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->assertArrayHasKey('task', $content['response']); $this->assertArrayHasKey('task', $content['response']);
$this->evaluateGoodTask($content['response']['task']); $this->evaluateGoodTask($content['response']['task']);
$task = self::$DI['app']['task-manager']->getTask($idTask); $task = self::$DI['app']['manipulator.task']->getRepository()->find($idTask);
$this->assertContains($task->getState(), array(\task_abstract::STATE_TOSTOP, \task_abstract::STATE_STOPPED)); $this->assertEquals(Task::STATUS_STOPPED, $task->getStatus());
} }
/** /**

View File

@@ -12,6 +12,7 @@ class CheckEnvironmentTest extends \PhraseanetPHPUnitAbstract
$output = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); $output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
$command = new CheckEnvironment('system:check'); $command = new CheckEnvironment('system:check');
$command->setContainer(self::$DI['cli']);
$this->assertLessThan(2, $command->execute($input, $output)); $this->assertLessThan(2, $command->execute($input, $output));
} }
} }

View File

@@ -2,13 +2,11 @@
namespace Alchemy\Tests\Phrasea\Core\Provider; namespace Alchemy\Tests\Phrasea\Core\Provider;
class ManipulatorServiceProviderTest extends ServiceProviderTestCase class ManipulatorServiceProvidertest extends ServiceProviderTestCase
{ {
public function provideServiceDescription() public function provideServiceDescription()
{ {
return array( return array(
array('Alchemy\Phrasea\Core\Provider\ManipulatorServiceProvider', 'manipulator.user', '\Alchemy\Phrasea\Model\Manipulator\UserManipulator'),
array('Alchemy\Phrasea\Core\Provider\ManipulatorServiceProvider', 'model.user-manager', '\Alchemy\Phrasea\Model\Manager\UserManager'),
array( array(
'Alchemy\Phrasea\Core\Provider\ManipulatorServiceProvider', 'Alchemy\Phrasea\Core\Provider\ManipulatorServiceProvider',
'manipulator.task', 'manipulator.task',

View File

@@ -9,7 +9,9 @@ class TaskTest extends TaskTestCase
{ {
public function testThatCreatedProcessAreDifferents() public function testThatCreatedProcessAreDifferents()
{ {
$process = $this->getMock('Symfony\Component\Process\ProcessableInterface'); $process = $this->getMockBuilder('Symfony\Component\Process\Process')
->disableOriginalConstructor()
->getMock();
$taskEntity = $this->getMock('Entities\Task'); $taskEntity = $this->getMock('Entities\Task');
$task = new Task($taskEntity, 'task number', 42, $process); $task = new Task($taskEntity, 'task number', 42, $process);
@@ -27,7 +29,9 @@ class TaskTest extends TaskTestCase
protected function getTask() protected function getTask()
{ {
$process = $this->getMock('Symfony\Component\Process\ProcessableInterface'); $process = $this->getMockBuilder('Symfony\Component\Process\Process')
->disableOriginalConstructor()
->getMock();
$taskEntity = $this->getMock('Entities\Task'); $taskEntity = $this->getMock('Entities\Task');
return new Task($taskEntity, 'task number', 42, $process); return new Task($taskEntity, 'task number', 42, $process);

View File

@@ -10,6 +10,7 @@ use Alchemy\Phrasea\Model\Entities\FeedEntry;
use Alchemy\Phrasea\Model\Entities\FeedItem; use Alchemy\Phrasea\Model\Entities\FeedItem;
use Alchemy\Phrasea\Model\Entities\FeedPublisher; use Alchemy\Phrasea\Model\Entities\FeedPublisher;
use Alchemy\Phrasea\Model\Entities\FeedToken; use Alchemy\Phrasea\Model\Entities\FeedToken;
use Alchemy\Phrasea\Model\Entities\Task;
use Alchemy\Phrasea\Model\Entities\User; use Alchemy\Phrasea\Model\Entities\User;
use Silex\WebTestCase; use Silex\WebTestCase;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
@@ -264,6 +265,23 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
$this->assertTrue(false !== stripos($response->getContent(), 'Sorry, the page you are looking for could not be found')); $this->assertTrue(false !== stripos($response->getContent(), 'Sorry, the page you are looking for could not be found'));
} }
public function insertTwoTasks()
{
$task1 = new Task();
$task1
->setName('task 1')
->setJobId('Null');
$task2 = new Task();
$task2
->setName('task 2')
->setJobId('Null');
self::$DI['app']['EM']->persist($task1);
self::$DI['app']['EM']->persist($task2);
self::$DI['app']['EM']->flush();
}
/** /**
* Insert fixture contained in the specified fixtureLoader * Insert fixture contained in the specified fixtureLoader
* into sqlLite test temporary database * into sqlLite test temporary database