public function postCreateTokenAction($orchestrationId) { $orchestration = $this->dbOrchestrationManager->findOrchestrationById($orchestrationId, $this->token); if (!$orchestration) { $exception = new OrchestratorException(404, sprintf('Orchestration %s not found', $orchestrationId)); $exception->setExceptionCode('ORCHESTRATION_NOT_FOUND'); throw $exception; } try { $tokenId = $this->storageApi->createToken('manage', sprintf('Orchestrator %s', $orchestration->getName()), null, true); // fill token data $token = $this->storageApi->getToken($tokenId); $token = new StorageApi\Token(new Client(array('token' => $token['token'], 'url' => $this->storageApi->getApiUrl()))); $orchestration->setToken((string) $token)->setTokenId($token->getId())->setTokenDesc($token->getDescription())->setTokenOwnerName($token->getOwnerName())->setProjectId($token->getProjectId()); } catch (\Exception $e) { $exception = new OrchestratorException(500, sprintf('Could not create new token'), $e); $exception->setExceptionCode('TOKEN_VALIDATION'); throw $exception; } $orchestration = $this->dbOrchestrationManager->updateOrchestration($orchestration); $this->logger->info('Orchestration token changed'); $data = $orchestration->toApiArray(); return $this->createJsonResponse($data['token'], 201); }
/** * Cancel waiting job * * @param $jobId * @throws \Keboola\OrchestratorBundle\Exception\OrchestratorException * @return Response */ public function deleteAction($jobId) { $job = $this->jobEsManager->findJobById($jobId); if (!$job) { $exception = new OrchestratorException(404, sprintf('Job %s not found', $jobId)); $exception->setExceptionCode('JOB_NOT_FOUND'); throw $exception; } if (!$job->isWaiting()) { $exception = new OrchestratorException(403, 'Only waiting job can be cancelled'); $exception->setExceptionCode('INVALID_JOB_STATUS'); throw $exception; } $client = new GuzzleHttp\Client([]); try { $response = $client->post(sprintf($this->killUrl, $job->getId()), array('config' => array('curl' => array(CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0)), 'headers' => array('X-StorageApi-Token' => $this->token, 'X-KBC-RunId' => $this->storageApi->getRunId(), 'X-User-Agent', KeboolaOrchestratorBundle::SYRUP_COMPONENT_NAME . " - API cancel"), 'timeout' => 60)); if ($response->getStatusCode() == 202) { $this->logger->info(sprintf('Orchestration job %s cancelled', $job->getId())); $this->logger->debug(sprintf('Orchestration job %s cancelled - old api', $job->getId()), array('orchestrationId' => $job->getOrchestrationId(), 'orchestration' => $job->getOrchestrationName(), 'projectId' => $job->getProjectId(), 'project' => $job->getTokenOwnerName(), 'tokenId' => $this->token->getId(), 'token' => $this->token->getDescription())); } else { throw new ApplicationException('Job cancel via syrup api failed', null, array('statusCode' => $response->getStatusCode(), 'body' => ResponseDecoder::decode($response))); } } catch (GuzzleHttp\Exception\RequestException $e) { throw new ApplicationException('Job cancel via syrup api failed', $e); } $jsonResponse = $this->createJsonResponse(array(), 204); return $jsonResponse; }