/** * @param array $taskData * @return static */ public static function reconstituteFromArray(array $taskData) { Assertion::keyExists($taskData, 'target_node_name'); Assertion::keyExists($taskData, 'process_definition'); Assertion::keyExists($taskData, 'sync_log_messages'); return new self(NodeName::fromString($taskData['target_node_name']), $taskData['process_definition'], (bool) $taskData['sync_log_messages']); }
/** * @test */ public function it_is_set_up_with_a_target_node_nome() { $subProcessDefinition = ["process_type" => Definition::PROCESS_LINEAR_MESSAGING, "tasks" => [["task_type" => Definition::TASK_COLLECT_DATA, "source" => 'test-case', "processing_type" => 'Prooph\\ProcessingTest\\Mock\\UserDictionary']]]; $task = RunSubProcess::setUp(NodeName::fromString('other_machine'), $subProcessDefinition); $this->assertInstanceOf('Prooph\\Processing\\Processor\\NodeName', $task->targetNodeName()); $this->assertEquals('other_machine', $task->targetNodeName()->toString()); }
/** * Handles a POST request that want to change the node name */ public function changeNodeNameAction() { $nodeName = $this->bodyParam('node_name'); if (!is_string($nodeName) || strlen($nodeName) < 3) { return new ApiProblemResponse(new ApiProblem(422, $this->translator->translate('The node name must be at least 3 characters long'))); } $this->commandBus->dispatch(ChangeNodeName::to(NodeName::fromString($nodeName), ConfigLocation::fromPath(Definition::getSystemConfigDir()))); return ['success' => true]; }
/** * @param string $taskListIdStr * @throws \InvalidArgumentException * @return TaskListId */ public static function fromString($taskListIdStr) { if (!is_string($taskListIdStr)) { throw new \InvalidArgumentException("TaskListIdStr must be string"); } $parts = explode(':TASK_LIST_ID:', $taskListIdStr); if (count($parts) != 2) { throw new \InvalidArgumentException(sprintf("Invalid taskLIstIdStr %s provided. Needs to have the format: node-name:PROCESS_ID:process-uuid:TASK_LIST_ID:task-list-uuid", $taskListIdStr)); } $envParts = explode(':PROCESS_ID:', $parts[0]); if (count($envParts) != 2) { throw new \InvalidArgumentException(sprintf("Invalid taskLIstIdStr %s provided. Needs to have the format: node-name:PROCESS_ID:process-uuid:TASK_LIST_ID:task-list-uuid", $taskListIdStr)); } $nodeName = NodeName::fromString($envParts[0]); $processId = ProcessId::fromString($envParts[1]); return new self($nodeName, $processId, Uuid::fromString($parts[1])); }
public function provideMessages() { $localTaskListPosition = TaskListPosition::at(TaskListId::linkWith(NodeName::defaultName(), ProcessId::generate()), 1); $remoteTaskListPosition = TaskListPosition::at(TaskListId::linkWith(NodeName::fromString("remote-system"), ProcessId::generate()), 1); $wfMessageWithoutTaskListPosition = WorkflowMessage::collectDataOf(TestUser::prototype(), 'test-case', 'localhost'); $expectedDataWfMessageWithoutTaskListPosition = ['message_id' => $wfMessageWithoutTaskListPosition->uuid()->toString(), 'message_name' => $wfMessageWithoutTaskListPosition->messageName(), 'version' => $wfMessageWithoutTaskListPosition->version(), 'task_list_position' => null, 'process_id' => null, 'status' => MessageStatus::PENDING, 'failure_msg' => null]; $wfMessageWithTaskListPosition = WorkflowMessage::collectDataOf(TestUser::prototype(), 'test-case', 'localhost'); $wfMessageWithTaskListPosition->connectToProcessTask($localTaskListPosition); $expectedDataWfMessageWithTaskListPosition = ['message_id' => $wfMessageWithTaskListPosition->uuid()->toString(), 'message_name' => $wfMessageWithTaskListPosition->messageName(), 'version' => $wfMessageWithTaskListPosition->version(), 'task_list_position' => $wfMessageWithTaskListPosition->processTaskListPosition()->toString(), 'process_id' => $wfMessageWithTaskListPosition->processTaskListPosition()->taskListId()->processId()->toString(), 'status' => MessageStatus::PENDING, 'failure_msg' => null]; $logMessage = LogMessage::logDebugMsg("Log message", $wfMessageWithTaskListPosition); $expectedDataLogMessage = ['message_id' => $logMessage->uuid()->toString(), 'message_name' => $logMessage->messageName(), 'version' => 1, 'task_list_position' => $logMessage->processTaskListPosition()->toString(), 'process_id' => $logMessage->processTaskListPosition()->taskListId()->processId()->toString(), 'status' => MessageStatus::PENDING, 'failure_msg' => null]; $startSubProcess = StartSubProcess::at($localTaskListPosition, ["process_type" => "faked"], false, "remote-system"); $expectedDataStartSubProcess = ['message_id' => $startSubProcess->uuid()->toString(), 'message_name' => $startSubProcess->messageName(), 'version' => $startSubProcess->version(), 'task_list_position' => $startSubProcess->parentTaskListPosition()->toString(), 'process_id' => $startSubProcess->parentTaskListPosition()->taskListId()->processId()->toString(), 'status' => MessageStatus::PENDING, 'failure_msg' => null]; $wfMessageWithRemoteTaskListPosition = WorkflowMessage::collectDataOf(TestUser::prototype(), 'test-case', 'localhost'); $wfMessageWithRemoteTaskListPosition->connectToProcessTask($remoteTaskListPosition); $logMessageSubProcess = LogMessage::logErrorMsg("Faked error", $wfMessageWithRemoteTaskListPosition); $subProcessFinished = SubProcessFinished::record(NodeName::fromString("remote-system"), $remoteTaskListPosition->taskListId()->processId(), false, $logMessageSubProcess, $localTaskListPosition); $expectedDataSubProcessFinished = ['message_id' => $subProcessFinished->uuid()->toString(), 'message_name' => $subProcessFinished->messageName(), 'version' => $subProcessFinished->version(), 'task_list_position' => $logMessageSubProcess->processTaskListPosition()->toString(), 'process_id' => $logMessageSubProcess->processTaskListPosition()->taskListId()->processId()->toString(), 'status' => MessageStatus::PENDING, 'failure_msg' => null]; return [[$wfMessageWithoutTaskListPosition, $expectedDataWfMessageWithoutTaskListPosition], [$wfMessageWithoutTaskListPosition->toServiceBusMessage(), $expectedDataWfMessageWithoutTaskListPosition], [$wfMessageWithTaskListPosition, $expectedDataWfMessageWithTaskListPosition], [$wfMessageWithTaskListPosition->toServiceBusMessage(), $expectedDataWfMessageWithTaskListPosition], [$logMessage, $expectedDataLogMessage], [$logMessage->toServiceBusMessage(), $expectedDataLogMessage], [$startSubProcess, $expectedDataStartSubProcess], [$startSubProcess->toServiceBusMessage(), $expectedDataStartSubProcess], [$subProcessFinished, $expectedDataSubProcessFinished], [$subProcessFinished->toServiceBusMessage(), $expectedDataSubProcessFinished]]; }
/** * @test */ public function it_translates_to_service_bus_message_and_back() { $nodeName = NodeName::fromString('other_machine'); $subProcessId = ProcessId::generate(); $parentTaskListPosition = TaskListPosition::at(TaskListId::linkWith(NodeName::defaultName(), ProcessId::generate()), 1); $wfMessage = $this->getUserDataCollectedTestMessage(); $wfMessage->connectToProcessTask(TaskListPosition::at(TaskListId::linkWith($nodeName, $subProcessId), 1)); $message = LogMessage::logDebugMsg("Processing finished", $wfMessage); $event = SubProcessFinished::record($nodeName, $subProcessId, true, $message, $parentTaskListPosition); $sbMessage = $event->toServiceBusMessage(); $this->assertInstanceOf('Prooph\\Common\\Messaging\\RemoteMessage', $sbMessage); $copyOfEvent = SubProcessFinished::fromServiceBusMessage($sbMessage); $this->assertInstanceOf('Prooph\\Processing\\Processor\\Event\\SubProcessFinished', $copyOfEvent); $this->assertTrue($nodeName->equals($copyOfEvent->processorNodeName())); $this->assertTrue($parentTaskListPosition->equals($copyOfEvent->parentTaskListPosition())); $this->assertEquals($parentTaskListPosition->taskListId()->nodeName()->toString(), $copyOfEvent->target()); $this->assertTrue($subProcessId->equals($copyOfEvent->subProcessId())); $this->assertTrue($copyOfEvent->succeed()); $this->assertEquals($message->technicalMsg(), $copyOfEvent->lastMessage()->technicalMsg()); }
/** * @return NodeName */ public function newNodeName() { return NodeName::fromString($this->payload['node_name']); }
/** * @test */ function it_is_equal_to_a_node_with_the_same_name() { $processingNode1 = ProcessingNode::initializeAs(NodeName::fromString('localhost')); $processingNode2 = ProcessingNode::initializeAs(NodeName::fromString('localhost')); $this->assertTrue($processingNode1->sameNodeAs($processingNode2)); }
/** * @return WorkflowProcessor */ protected function getOtherMachineWorkflowProcessor() { if (is_null($this->otherMachineWorkflowProcessor)) { $this->otherMachineWorkflowProcessor = new WorkflowProcessor(NodeName::fromString('other_machine'), $this->getOtherMachineEventStore(), $this->getOtherMachineProcessRepository(), $this->otherMachineWorkflowEngine, $this->getTestProcessFactory()); $this->otherMachineCommandRouter->route(StartSubProcess::MSG_NAME)->to($this->otherMachineWorkflowProcessor); } return $this->otherMachineWorkflowProcessor; }
/** * @param NodeName $newNodeName * @param ConfigWriter $configWriter */ public function changeNodeName(NodeName $newNodeName, ConfigWriter $configWriter) { $oldNodeName = NodeName::fromString($this->config['processing']['node_name']); $this->config['processing']['node_name'] = $newNodeName->toString(); $oldNodeNameAsString = $oldNodeName->toString(); foreach ($this->config['processing']['channels'] as &$channelConfig) { foreach ($channelConfig['targets'] as $i => $target) { if ($target === $oldNodeNameAsString) { $channelConfig['targets'][$i] = $newNodeName->toString(); } } if (isset($channelConfig['origin']) && $channelConfig['origin'] === $oldNodeNameAsString) { $channelConfig['origin'] = $newNodeName->toString(); } if (isset($channelConfig['sender']) && $channelConfig['sender'] === $oldNodeNameAsString) { $channelConfig['sender'] = $newNodeName->toString(); } } $this->writeConfig($configWriter); $this->recordThat(NodeNameWasChanged::to($newNodeName, $oldNodeName)); }
/** * @param array $taskDefinition * @return RunSubProcess */ private function createRunSubProcessTaskFromDefinition(array $taskDefinition) { Assertion::keyExists($taskDefinition, "target_node_name"); Assertion::keyExists($taskDefinition, "process_definition"); Assertion::isArray($taskDefinition["process_definition"]); return RunSubProcess::setUp(NodeName::fromString($taskDefinition['target_node_name']), $taskDefinition["process_definition"]); }
/** * @return NodeName */ public function getNodeName() { return NodeName::fromString($this->getConfig()->stringValue('node_name')); }
/** * Create service * * @param ServiceLocatorInterface $serviceLocator * @return mixed */ public function createService(ServiceLocatorInterface $serviceLocator) { /** @var $processingConfig ProcessingConfig */ $processingConfig = $serviceLocator->get('processing_config'); return ProcessingNode::initializeAs(NodeName::fromString($processingConfig->getNodeName())); }
/** * @return NodeName */ public function processorNodeName() { return NodeName::fromString($this->payload['processor_node_name']); }
/** * @return NodeName */ public function processingNodeName() { if (is_null($this->processingNodeName)) { $this->processingNodeName = NodeName::fromString($this->payload['processing_node_name']); } return $this->processingNodeName; }