protected function init($jobId) { $this->jobMapper = $this->getContainer()->get('syrup.elasticsearch.current_component_job_mapper'); // Get job from ES $this->job = $this->jobMapper->get($jobId); if ($this->job == null) { $this->logger->error("Job id '" . $jobId . "' not found."); return self::STATUS_ERROR; } // SAPI init /** @var ObjectEncryptor $encryptor */ $encryptor = $this->getContainer()->get('syrup.object_encryptor'); $this->sapiClient = new SapiClient(['token' => $encryptor->decrypt($this->job->getToken()['token']), 'url' => $this->getContainer()->getParameter('storage_api.url'), 'userAgent' => $this->job->getComponent()]); $this->sapiClient->setRunId($this->job->getRunId()); /** @var \Keboola\Syrup\Service\StorageApi\StorageApiService $storageApiService */ $storageApiService = $this->getContainer()->get('syrup.storage_api'); $storageApiService->setClient($this->sapiClient); $this->storageApiService = $storageApiService; /** @var \Keboola\Syrup\Monolog\Processor\JobProcessor $logProcessor */ $logProcessor = $this->getContainer()->get('syrup.monolog.job_processor'); $logProcessor->setJob($this->job); /** @var \Keboola\Syrup\Monolog\Processor\SyslogProcessor $logProcessor */ $logProcessor = $this->getContainer()->get('syrup.monolog.syslog_processor'); $logProcessor->setRunId($this->job->getRunId()); $logProcessor->setTokenData($storageApiService->getTokenData()); // Lock DB /** @var Connection $conn */ $conn = $this->getContainer()->get('doctrine.dbal.lock_connection'); $conn->exec('SET wait_timeout = 31536000;'); $this->lock = new Lock($conn, $this->job->getLockName()); }
public function testReadFilesEsQueryFilterRunId() { $root = $this->tmpDir; file_put_contents($root . "/upload", "test"); $reader = new Reader($this->client); $fo = new FileUploadOptions(); $fo->setTags(["docker-bundle-test"]); $this->client->setRunId('xyz'); $id1 = $this->client->uploadFile($root . "/upload", $fo); $id2 = $this->client->uploadFile($root . "/upload", $fo); $this->client->setRunId('1234567'); $id3 = $this->client->uploadFile($root . "/upload", $fo); $id4 = $this->client->uploadFile($root . "/upload", $fo); $this->client->setRunId('1234567.8901234'); $id5 = $this->client->uploadFile($root . "/upload", $fo); $id6 = $this->client->uploadFile($root . "/upload", $fo); $configuration = [["query" => "tags: docker-bundle-test", "filter_by_run_id" => true]]; $reader->downloadFiles($configuration, $root . "/download"); $this->assertFalse(file_exists($root . "/download/" . $id1 . '_upload')); $this->assertFalse(file_exists($root . "/download/" . $id2 . '_upload')); $this->assertTrue(file_exists($root . "/download/" . $id3 . '_upload')); $this->assertTrue(file_exists($root . "/download/" . $id4 . '_upload')); $this->assertTrue(file_exists($root . "/download/" . $id5 . '_upload')); $this->assertTrue(file_exists($root . "/download/" . $id6 . '_upload')); }
public function getClient() { $request = $this->requestStack->getCurrentRequest(); if ($this->client == null) { if ($request == null) { throw new NoRequestException(); } if (!$request->headers->has('X-StorageApi-Token')) { throw new UserException('Missing StorageAPI token'); } $this->setClient(new Client(['token' => $request->headers->get('X-StorageApi-Token'), 'url' => $this->storageApiUrl, 'userAgent' => explode('/', $request->getPathInfo())[1], 'backoffMaxTries' => $this->getBackoffTries(gethostname())])); if ($request->headers->has('X-KBC-RunId')) { $this->client->setRunId($request->headers->get('X-KBC-RunId')); } } return $this->client; }
public function getClient() { //@todo remove in 2.6 - setRequest() will be removed if ($this->request != null) { $request = $this->request; } else { $request = $this->requestStack->getCurrentRequest(); } if ($this->client == null) { if ($request == null) { throw new NoRequestException(); } if (!$request->headers->has('X-StorageApi-Token')) { throw new UserException('Missing StorageAPI token'); } $this->setClient(new Client(['token' => $request->headers->get('X-StorageApi-Token'), 'url' => $this->storageApiUrl, 'userAgent' => explode('/', $request->getPathInfo())[1]])); if ($request->headers->has('X-KBC-RunId')) { $this->client->setRunId($request->headers->get('X-KBC-RunId')); } } return $this->client; }
//set $token = getenv('KBC_TOKEN'); if (count($argv) < 2) { print 'php-uploader error: kbc token not provided'; exit(1); } $token = $argv[1]; if (empty($token)) { print 'php-uploader error: kbc token not provided or missing'; exit(1); } //set $filesPath if (count($argv) < 3) { print 'php-uploader error: upload path not provided'; exit(1); } $filesPath = $argv[2]; // set run id $runId = ''; if (count($argv) > 3) { $runId = $argv[3]; } $sapiClient = new Client(['token' => $token]); $sapiClient->setRunId($runId); $uploader = new Uploader($sapiClient); try { $uploader->uploadFiles($filesPath); } catch (\Exception $e) { print $e->getMessage(); exit(1); } exit(0);