/**
  * @return ProcessingMetadata
  */
 public function taskMetadata()
 {
     if (is_null($this->taskMetadata)) {
         $this->taskMetadata = ProcessingMetadata::fromArray($this->payload['task_metadata']);
     }
     return $this->taskMetadata;
 }
 /**
  * @return Message
  */
 public function startMessage()
 {
     if (is_null($this->startMessage)) {
         $processingType = $this->payload['start_message']['processing_type'];
         $this->startMessage = Message::emulateProcessingWorkflowMessage(MessageType::fromString($this->payload['start_message']['message_type']), $processingType::prototype(), ProcessingMetadata::fromArray($this->payload['start_message']['metadata']));
     }
     return $this->startMessage;
 }
Esempio n. 3
0
 /**
  * @test
  */
 function it_returns_a_emulated_process_data_message_when_its_type_is_process_data()
 {
     $messageHandler = $this->getArticleImporterMessageHandler();
     $task = Task::setUp($messageHandler, Task\TaskType::processData(), ArticleCollection::prototype(), ProcessingMetadata::fromArray([MessageMetadata::LIMIT => 100]));
     $message = $task->emulateWorkflowMessage();
     $this->assertInstanceOf(Message::class, $message);
     $this->assertTrue($message->messageType()->isProcessDataMessage());
     $this->assertEquals($task->processingType()->of(), $message->processingType()->of());
     $this->assertEquals($task->metadata()->toArray(), $message->processingMetadata()->toArray());
 }
 /**
  * @return Message
  */
 public function startMessage()
 {
     $startMessage = $this->payload['start_message'];
     if (isset($startMessage['metadata'])) {
         $metadata = ProcessingMetadata::fromArray($startMessage['metadata']);
     } else {
         $metadata = ProcessingMetadata::noData();
     }
     $processingType = $startMessage['processing_type'];
     return Message::emulateProcessingWorkflowMessage(MessageType::fromString($startMessage['message_type']), $processingType::prototype(), $metadata);
 }
 public function create($data)
 {
     if (!array_key_exists('name', $data)) {
         return $this->apiProblem(422, "No name given for the message handler");
     }
     if (!array_key_exists('node_name', $data)) {
         return $this->apiProblem(422, "No node_name given for the message handler");
     }
     if (!array_key_exists('type', $data)) {
         return $this->apiProblem(422, "No type given for the message handler");
     }
     if (!array_key_exists('data_direction', $data)) {
         return $this->apiProblem(422, "No data_direction given for the message handler");
     }
     if (!array_key_exists('metadata_riot_tag', $data)) {
         return $this->apiProblem(422, "No metadata_riot_tag given for the message handler");
     }
     if (!array_key_exists('icon', $data)) {
         return $this->apiProblem(422, "No icon given for the message handler");
     }
     if (!array_key_exists('icon_type', $data)) {
         return $this->apiProblem(422, "No icon_type given for the message handler");
     }
     if (!isset($data['processing_types'])) {
         $data['processing_types'] = ProcessingTypes::SUPPORT_ALL;
     }
     if (!isset($data['processing_metadata'])) {
         $data['processing_metadata'] = ProcessingMetadata::noData()->toArray();
     }
     if (!isset($data['preferred_type'])) {
         $data['preferred_type'] = null;
     }
     if (!isset($data['processing_id'])) {
         $data['processing_id'] = null;
     }
     if (!isset($data['additional_data'])) {
         $data['additional_data'] = [];
     }
     $messageHandlerId = MessageHandlerId::generate();
     $this->commandBus->dispatch(InstallMessageHandler::withData($messageHandlerId, $data['name'], $data['node_name'], $data['type'], $data['data_direction'], $data['processing_types'], $data['processing_metadata'], $data['metadata_riot_tag'], $data['icon'], $data['icon_type'], $data['preferred_type'], $data['processing_id'], $data['additional_data']));
     return $this->location($this->url()->fromRoute('prooph.link/process_config/api/message_handler', ['id' => $messageHandlerId->toString()]));
 }
 /**
  * @test
  */
 function it_installs_a_message_handler()
 {
     $messageHandler = ProcessingNode::initializeAs(NodeName::defaultName())->installMessageHandler(MessageHandlerId::generate(), 'Article Exporter', HandlerType::connector(), DataDirection::source(), ProcessingTypes::support([ArticleCollection::prototype()]), ProcessingMetadata::noData(), 'sqlconnector-pm-metadata', 'glyphicon-hdd', 'glyphicon', ArticleCollection::prototype(), ProcessingId::fromString('sqlconnector:::example'));
     $this->assertInstanceOf(MessageHandler::class, $messageHandler);
 }
Esempio n. 7
0
 /**
  * @param Task $previousTask
  * @param MessageHandler $previousMessageHandler
  * @param MessageHandler $nextMessageHandler
  * @throws \RuntimeException
  * @internal param \Prooph\Link\ProcessManager\Model\Workflow\Message $lastAnswer
  * @return Task[]
  */
 public function determineNextTasks(Task $previousTask, MessageHandler $previousMessageHandler, MessageHandler $nextMessageHandler)
 {
     $tasks = [];
     $taskMetadata = ProcessingMetadata::noData();
     $lastAnswer = $previousMessageHandler->emulateAnswerMessage($previousTask);
     //@TODO: Implement sub process set up
     if (!$this->processingNodeName()->equals($nextMessageHandler->processingNodeName())) {
         throw new \RuntimeException("Running message handler on different nodes is not supported yet!");
     }
     $task = $this->scheduleTaskFor($nextMessageHandler, $taskMetadata, $lastAnswer);
     $nextMessage = $task->emulateWorkflowMessage();
     $processType = $this->determineProcessType($nextMessage, $nextMessageHandler);
     $previousTaskProcess = $this->getProcessOfTask($previousTask);
     if (is_null($previousTaskProcess)) {
         throw TaskProcessNotFound::of($previousTask, $this);
     }
     if (!$previousTaskProcess->type()->isLinearMessaging() || !$processType->isLinearMessaging()) {
         //@TODO: Implement sub process handling
         throw new \RuntimeException("Handling follow up tasks with a process type other than linear messaging is not supported yet!");
     }
     $this->recordThat(TaskWasAddedToProcess::record($this->workflowId(), $previousTaskProcess, $task));
     $tasks[] = $task;
     return $tasks;
 }
 /**
  * Merges given metadata recursive into existing metadata and returns a new ProcessingMetadata object
  *
  * @param ProcessingMetadata $metadata
  * @return ProcessingMetadata
  */
 public function merge(ProcessingMetadata $metadata)
 {
     return new self(ArrayUtils::merge($this->metadata->toArray(), $metadata->toArray()));
 }
 function provideStartScenarios()
 {
     return [[Workflow\Message::emulateProcessingWorkflowMessage(Workflow\MessageType::collectData(), ArticleCollection::prototype(), ProcessingMetadata::noData()), $this->getArticleExporterMessageHandler(), ProcessingMetadata::noData(), Task\TaskType::TYPE_COLLECT_DATA, Workflow\ProcessType::TYPE_LINEAR_MESSAGING], [Workflow\Message::emulateProcessingWorkflowMessage(Workflow\MessageType::dataProcessed(), ArticleCollection::prototype(), ProcessingMetadata::noData()), $this->getArticleImporterMessageHandler(), ProcessingMetadata::noData(), Task\TaskType::TYPE_PROCESS_DATA, Workflow\ProcessType::TYPE_LINEAR_MESSAGING], [Workflow\Message::emulateProcessingWorkflowMessage(Workflow\MessageType::collectData(), ArticleCollection::prototype(), ProcessingMetadata::noData()), $this->getArticleExporterMessageHandler(true), ProcessingMetadata::noData(), Task\TaskType::TYPE_COLLECT_DATA, Workflow\ProcessType::TYPE_PARALLEL_FOREACH], [Workflow\Message::emulateProcessingWorkflowMessage(Workflow\MessageType::dataProcessed(), ArticleCollection::prototype(), ProcessingMetadata::noData()), $this->getArticleImporterMessageHandler(true), ProcessingMetadata::noData(), Task\TaskType::TYPE_PROCESS_DATA, Workflow\ProcessType::TYPE_PARALLEL_FOREACH], [Workflow\Message::emulateProcessingWorkflowMessage(Workflow\MessageType::collectData(), ArticleCollection::prototype(), ProcessingMetadata::fromArray([MessageMetadata::LIMIT => 100])), $this->getArticleExporterMessageHandler(), ProcessingMetadata::noData(), Task\TaskType::TYPE_COLLECT_DATA, Workflow\ProcessType::TYPE_PARALLEL_CHUNK], [Workflow\Message::emulateProcessingWorkflowMessage(Workflow\MessageType::dataCollected(), ArticleCollection::prototype(), ProcessingMetadata::fromArray([MessageMetadata::LIMIT => 100])), $this->getArticleImporterMessageHandler(), ProcessingMetadata::noData(), Task\TaskType::TYPE_PROCESS_DATA, Workflow\ProcessType::TYPE_PARALLEL_CHUNK]];
 }
Esempio n. 10
0
 /**
  * @param bool $singleItemMode
  * @return MessageHandler
  */
 protected function getArticleImporterMessageHandler($singleItemMode = false)
 {
     $supportedProcessingType = $singleItemMode ? Article::prototype() : ArticleCollection::prototype();
     return MessageHandler::fromDefinition(MessageHandlerId::generate(), 'Article Importer', NodeName::defaultName(), MessageHandler\HandlerType::connector(), MessageHandler\DataDirection::target(), MessageHandler\ProcessingTypes::support([$supportedProcessingType]), ProcessingMetadata::fromArray(['chunk_support' => true]), 'sqlconnector-pm-metadata', 'glyphicon-hdd', 'glyphicon');
 }
 /**
  * @param Message $message
  * @return bool
  */
 public function canHandleMessage(Message $message)
 {
     $this->lastValidationError = null;
     if (!$this->canHandleMessageType($message->messageType())) {
         $this->lastValidationError = sprintf("Message type %s is not supported.", $message->messageType());
         return false;
     }
     if ($message->processingMetadata()->shouldCollectionBeSplitIntoChunks()) {
         if (!$this->processingMetadata->canHandleChunks()) {
             $this->lastValidationError = "Unable to handle chunks.";
             return false;
         }
     }
     if (!$this->supportedProcessingTypes->isSupported($message->processingType())) {
         $this->lastValidationError = sprintf("Processing type %s is not supported. Supported types are: %s", $message->processingType()->of(), implode(", ", $this->supportedProcessingTypes->toArray()['processing_types']));
         return false;
     }
     return true;
 }
 /**
  * @test
  * @dataProvider provideNonValidMetadata
  * @expectedException \InvalidArgumentException
  */
 function it_does_not_allow_non_scalar_and_non_array_values($metadata)
 {
     ProcessingMetadata::fromArray($metadata);
 }
Esempio n. 13
0
 /**
  * @test
  */
 function it_is_equal_to_a_similar_message()
 {
     $message1 = Message::emulateProcessingWorkflowMessage(MessageType::collectData(), String::prototype(), ProcessingMetadata::fromArray(['meta' => 'data']));
     $message2 = Message::emulateProcessingWorkflowMessage(MessageType::collectData(), String::prototype(), ProcessingMetadata::fromArray(['meta' => 'data']));
     $this->assertTrue($message1->equals($message2));
 }
 /**
  * @return ProcessingMetadata
  */
 public function processingMetadata()
 {
     return ProcessingMetadata::fromArray($this->payload['processing_metadata']);
 }
 /**
  * @param $dataDirection
  * @param null|string $handlerType
  * @param null|array $metadata
  * @return MessageHandler
  */
 private function getMessageHandler($dataDirection, $handlerType = null, array $metadata = null)
 {
     if (!is_null($handlerType)) {
         $handlerType = MessageHandler\HandlerType::fromString($handlerType);
     } else {
         $handlerType = MessageHandler\HandlerType::connector();
     }
     if (!is_null($metadata)) {
         $metadata = ProcessingMetadata::fromArray($metadata);
     } else {
         $metadata = ProcessingMetadata::noData();
     }
     return MessageHandler::fromDefinition(MessageHandlerId::generate(), 'Article Export', NodeName::defaultName(), $handlerType, MessageHandler\DataDirection::fromString($dataDirection), MessageHandler\ProcessingTypes::support([ArticleCollection::prototype(), Article::prototype()]), $metadata, 'sqlconnector-pm-metadata', 'glyphicon-hdd', 'glyphicon', Article::prototype(), MessageHandler\ProcessingId::fromString('sqlconnector:::example'));
 }