Skip to content

Commit c2dcefc

Browse files
authored
Merge pull request #527 from keboola/pepa_PAT-161_noDindFeature
PAT-161: Allow enabling no-dind using project feature
2 parents efc1b48 + 3d0b277 commit c2dcefc

File tree

4 files changed

+137
-64
lines changed

4 files changed

+137
-64
lines changed

src/JobFactory/JobRuntimeResolver.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Keboola\StorageApiBranch\ClientWrapper;
1616
use Keboola\StorageApiBranch\Factory\ClientOptions;
1717
use Keboola\StorageApiBranch\Factory\StorageClientPlainFactory;
18+
use Keboola\StorageApiBranch\StorageApiToken;
1819
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1920

2021
/**
@@ -27,6 +28,7 @@ class JobRuntimeResolver
2728
];
2829

2930
private const PAY_AS_YOU_GO_FEATURE = 'pay-as-you-go';
31+
private const NO_DIND_FEATURE = 'job-queue-no-dind';
3032

3133
private ClientWrapper $clientWrapper;
3234
private Components $componentsApiClient;
@@ -39,7 +41,7 @@ public function __construct(
3941
) {
4042
}
4143

42-
public function resolveJobData(array $jobData, array $tokenInfo): array
44+
public function resolveJobData(array $jobData, StorageApiToken $token): array
4345
{
4446
$this->configuration = null;
4547
$this->jobData = $jobData;
@@ -56,14 +58,14 @@ public function resolveJobData(array $jobData, array $tokenInfo): array
5658
$jobData['tag'] = $this->resolveTag($jobData);
5759
$variableValues = $this->resolveVariables();
5860
$jobData['parallelism'] = $this->resolveParallelism($jobData);
59-
$jobData['executor'] = $this->resolveExecutor($jobData)->value;
61+
$jobData['executor'] = $this->resolveExecutor($jobData, $token)->value;
6062
$jobData = $this->resolveBranchType($jobData);
6163

6264
// set type after resolving parallelism
6365
$jobData['type'] = $this->resolveJobType($jobData)->value;
6466

6567
// set backend after resolving type
66-
$jobData['backend'] = $this->resolveBackend($jobData, $tokenInfo)->toDataArray();
68+
$jobData['backend'] = $this->resolveBackend($jobData, $token)->toDataArray();
6769

6870
foreach ($variableValues->asDataArray() as $key => $value) {
6971
$jobData[$key] = $value;
@@ -170,7 +172,7 @@ private function getBackend(array $jobData): Backend
170172
return $this->mergeBackendsData($backend, $overrideByBackend);
171173
}
172174

173-
private function resolveBackend(array $jobData, array $tokenInfo): Backend
175+
private function resolveBackend(array $jobData, StorageApiToken $token): Backend
174176
{
175177
$tempBackend = $this->getBackend($jobData);
176178

@@ -196,7 +198,7 @@ private function resolveBackend(array $jobData, array $tokenInfo): Backend
196198
We also ignore backend settings for other workspace types, as they do not make any sense at the moment.
197199
*/
198200
if (in_array($stagingStorage, ['local', 's3', 'abs', 'none']) &&
199-
!in_array(self::PAY_AS_YOU_GO_FEATURE, $tokenInfo['owner']['features'] ?? [])
201+
!$token->hasFeature(self::PAY_AS_YOU_GO_FEATURE)
200202
) {
201203
return new Backend(null, $tempBackend->getType(), $backendContext);
202204
}
@@ -288,11 +290,12 @@ private function resolveJobType(array $jobData): JobType
288290
return JobType::STANDARD;
289291
}
290292

291-
private function resolveExecutor(array $jobData): Executor
293+
private function resolveExecutor(array $jobData, StorageApiToken $token): Executor
292294
{
293295
$value = $jobData['executor'] ??
294296
$this->getConfigData()['runtime']['executor'] ??
295297
$this->getConfiguration()['runtime']['executor'] ??
298+
($token->hasFeature(self::NO_DIND_FEATURE) ? Executor::K8S_CONTAINERS->value : null) ??
296299
Executor::getDefault()->value
297300
;
298301

src/NewJobFactory.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ public function createNewJob(array $data): JobInterface
3131
$data = $this->validateJobData($data, NewJobDefinition::class);
3232

3333
try {
34-
$client = $this->storageClientFactory->createClientWrapper(new ClientOptions(
35-
null,
36-
$data['#tokenString'],
37-
))->getBasicClient();
38-
$tokenInfo = $client->verifyToken();
39-
$jobId = $client->generateId();
34+
$clientWrapper = $this->storageClientFactory->createClientWrapper(new ClientOptions(
35+
token: $data['#tokenString'],
36+
));
37+
$token = $clientWrapper->getToken();
38+
39+
$jobId = $clientWrapper->getBasicClient()->generateId();
4040
$runId = empty($data['parentRunId']) ? $jobId :
4141
$data['parentRunId'] . JobInterface::RUN_ID_DELIMITER . $jobId;
4242
} catch (StorageClientException $e) {
@@ -53,17 +53,15 @@ public function createNewJob(array $data): JobInterface
5353
);
5454
}
5555

56-
$projectId = (string) $tokenInfo['owner']['id'];
57-
5856
$jobData = [
5957
'id' => $jobId,
6058
'deduplicationId' => $data['deduplicationId'] ?? null,
6159
'runId' => $runId,
62-
'projectId' => $projectId,
63-
'projectName' => $tokenInfo['owner']['name'],
64-
'tokenId' => $tokenInfo['id'],
60+
'projectId' => $token->getProjectId(),
61+
'projectName' => $token->getProjectName(),
62+
'tokenId' => $token->getTokenId(),
6563
'#tokenString' => $data['#tokenString'],
66-
'tokenDescription' => $tokenInfo['description'],
64+
'tokenDescription' => $token->getTokenDesc(),
6765
'status' => JobInterface::STATUS_CREATED,
6866
'desiredStatus' => JobInterface::DESIRED_STATUS_PROCESSING,
6967
'mode' => $data['mode'],
@@ -89,14 +87,14 @@ public function createNewJob(array $data): JobInterface
8987
'onlyOrchestrationTaskIds' => $data['onlyOrchestrationTaskIds'] ?? null,
9088
'previousJobId' => $data['previousJobId'] ?? null,
9189
];
92-
$jobData = $this->jobRuntimeResolver->resolveJobData($jobData, $tokenInfo);
90+
$jobData = $this->jobRuntimeResolver->resolveJobData($jobData, $token);
9391

9492
$data = $this->objectEncryptor->encrypt(
9593
$jobData,
9694
(string) $data['componentId'],
97-
(string) $tokenInfo['owner']['id'],
95+
$token->getProjectId(),
9896
BranchType::from($jobData['branchType']),
99-
$tokenInfo['owner']['features'],
97+
$token->getFeatures(),
10098
);
10199

102100
$data = $this->validateJobData($data, FullJobDefinition::class);

0 commit comments

Comments
 (0)