/** * Check job in syrup queue * * @param $orchestrationId */ private function sqsScheduledJobTest($orchestrationId) { $assertCount = 1; $requiredStatus = StatusConverter::syrupToOrchestrator(Metadata\Job::STATUS_WAITING); $url = sprintf('/orchestrator/orchestrations/%d/jobs', $orchestrationId); $response = $this->callApiGet($url); $errorMessage = sprintf("Response for call '%s %s' should return only %d jobs.", 'GET', $url, $assertCount); $this->assertCount($assertCount, $response, $errorMessage); $errorMessage = sprintf("Response for call '%s %s' should return list of scheduled jobs.", 'GET', $url); $this->assertArrayHasKey('id', $response[0], $errorMessage); $this->assertArrayHasKey('initializedBy', $response[0], $errorMessage); $this->assertArrayHasKey('status', $response[0], $errorMessage); $this->assertEquals('scheduler', $response[0]['initializedBy'], $errorMessage); $this->assertEquals($requiredStatus, $response[0]['status'], $errorMessage); $this->assertArrayHasKey('isFinished', $response[0]); $this->assertEquals(false, $response[0]['isFinished']); $jobId = $response[0]['id']; $maxTime = 60; $startTime = time(); $errorMessage = sprintf("SQS Message for job '%s' not found.", $jobId); do { foreach ($this->queue->receive() as $message) { /** @var Queue\QueueMessage $message */ $body = $message->getBody(); $errorMessage = 'SQS Message should contains jobId and component name'; $this->assertObjectHasAttribute('jobId', $body, $errorMessage); $this->assertObjectHasAttribute('component', $body, $errorMessage); $errorMessage = 'SQS Message is not from orchestrator'; $this->assertEquals(KeboolaOrchestratorBundle::SYRUP_COMPONENT_NAME, $body->component, $errorMessage); $this->queue->deleteMessage($message); if ($body->jobId == $jobId) { $jobId = null; } } } while ($jobId && time() - $startTime < $maxTime); $this->assertEmpty($jobId, $errorMessage); }
public function testExecutionError() { $token1 = $this->createNewToken($this->storageApi, 'manage'); $orchestrationId = $this->createOrchestrationTest($token1); $actionParameters = array(array(), array('sleep' => 3)); $this->putOrchestrationErrorTaskTest($orchestrationId, $actionParameters); $jobId = $this->runOrchestrationTest($orchestrationId); $this->runCommandTest($jobId); $url = '/orchestrator/jobs/' . $jobId; $response = $this->callApiGet($url); $this->assertArrayHasKey('id', $response); $this->assertEquals($jobId, $response['id']); $this->assertArrayHasKey('status', $response); $this->assertEquals(StatusConverter::syrupToOrchestrator(Metadata\Job::STATUS_ERROR), $response['status']); $this->assertArrayHasKey('isFinished', $response); $this->assertEquals(true, $response['isFinished']); $this->assertArrayHasKey('initializedBy', $response); $this->assertEquals('manually', $response['initializedBy']); $this->assertArrayHasKey('results', $response); $this->assertArrayHasKey('tasks', $response['results']); $tasksResult = $response['results']['tasks']; // task 1 validation $this->assertArrayHasKey('response', $tasksResult[0]); $this->assertArrayHasKey('responseCode', $tasksResult[0]); $this->assertArrayHasKey('actionParameters', $tasksResult[0]); $this->assertEquals(400, $tasksResult[0]['responseCode']); $this->assertEquals($actionParameters[0], $tasksResult[0]['actionParameters']); $this->assertArrayHasKey('code', $tasksResult[0]['response']); $this->assertArrayHasKey('status', $tasksResult[0]); $this->assertEquals(StatusConverter::syrupToOrchestrator(Metadata\Job::STATUS_ERROR), $tasksResult[0]['status']); // task 2 validation $this->assertArrayHasKey('startTime', $tasksResult[1]); $this->assertArrayHasKey('actionParameters', $tasksResult[1]); $this->assertEquals($actionParameters[1], $tasksResult[1]['actionParameters']); $this->assertArrayHasKey('startTime', $tasksResult[1]); $this->assertArrayHasKey('status', $tasksResult[1]); $this->assertEmpty($tasksResult[1]['startTime']); $this->assertEmpty($tasksResult[1]['status']); }
public function toApiArray() { return array('id' => $this->getId(), 'orchestrationId' => $this->getOrchestrationId(), 'createdTime' => $this->getCreatedTime() ? $this->getCreatedTime()->format('c') : null, 'startTime' => $this->getStartTime() ? $this->getStartTime()->format('c') : null, 'endTime' => $this->getEndTime() ? $this->getEndTime()->format('c') : null, 'status' => StatusConverter::syrupToOrchestrator($this->getStatus()), 'isFinished' => StatusConverter::isFinishedStatus(StatusConverter::syrupToOrchestrator($this->getStatus())), 'initializedBy' => $this->getInitializedBy(), 'token' => array('id' => $this->getTokenId(), 'description' => $this->getTokenDesc()), 'initiatorToken' => array('id' => $this->getInitiatorTokenId(), 'description' => $this->getInitiatorTokenDesc(), 'userAgent' => $this->getInitiatorUserAgent()), 'tasks' => $this->getTasks(), 'results' => $this->getResults(), 'notificationsEmails' => $this->getNotificationsEmails(), 'runId' => $this->getRunId(), 'url' => $this->getUrl()); }