Skip to content

Commit 358c0db

Browse files
authored
Merge pull request #345 from keboola/pepa_SOX-405_internalApiClientFields
SOX-405 [internal api client] New job fields
2 parents fd27bd2 + f78dcd7 commit 358c0db

File tree

11 files changed

+403
-1
lines changed

11 files changed

+403
-1
lines changed

provisioning/local/.terraform.lock.hcl

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provisioning/local/gcp.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ resource "google_kms_crypto_key" "object_encryptor_key" {
2424
}
2525

2626
resource "google_service_account" "object_encryptor_service_account" {
27-
account_id = substr("${var.name_prefix}-job-queue-internal-api-php-client", 0, 28)
27+
account_id = "${var.name_prefix}-jqiapc"
2828
display_name = "${var.name_prefix} Job Queue Internal API PHP Client"
2929
}
3030

src/JobFactory/FullJobDefinition.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,44 @@ protected function getRootDefinition(TreeBuilder $treeBuilder): ArrayNodeDefinit
192192
->defaultNull()
193193
->beforeNormalization()->always($this->getStringNormalizer())->end()
194194
->end()
195+
->scalarNode('orchestrationTaskId')
196+
->validate()
197+
->ifTrue(fn($v) => $v !== null && !is_string($v))
198+
->thenInvalid('value must be a string')
199+
->end()
200+
->validate()
201+
->ifTrue(fn($v) => $v === '')
202+
->thenInvalid('value cannot be empty string')
203+
->end()
204+
->end()
205+
->variableNode('onlyOrchestrationTaskIds')
206+
->validate()
207+
->ifTrue(fn($v) => $v !== null && !is_array($v))
208+
->thenInvalid('value must be an array')
209+
->end()
210+
->validate()
211+
->ifTrue(fn($v) => $v === [])
212+
->thenInvalid('value cannot be empty list')
213+
->end()
214+
->validate()
215+
->ifTrue(fn($v) => count(array_filter($v ?? [], fn($i) => !is_string($i))) > 0)
216+
->thenInvalid('items must be strings')
217+
->end()
218+
->validate()
219+
->ifTrue(fn($v) => count(array_filter($v ?? [], fn($i) => $i === '')) > 0)
220+
->thenInvalid('item cannot be empty string')
221+
->end()
222+
->end()
223+
->scalarNode('previousJobId')
224+
->validate()
225+
->ifTrue(fn($v) => $v !== null && !is_string($v))
226+
->thenInvalid('value must be a string')
227+
->end()
228+
->validate()
229+
->ifTrue(fn($v) => $v === '')
230+
->thenInvalid('value cannot be empty string')
231+
->end()
232+
->end()
195233
->scalarNode('runnerId')
196234
->defaultNull()
197235
->beforeNormalization()->always($this->getStringNormalizer())->end()

src/JobFactory/Job.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,30 @@ public function getOrchestrationJobId(): ?string
317317
return $this->data['orchestrationJobId'] ?? null;
318318
}
319319

320+
/**
321+
* @return non-empty-string|null
322+
*/
323+
public function getOrchestrationTaskId(): ?string
324+
{
325+
return $this->data['orchestrationTaskId'] ?? null;
326+
}
327+
328+
/**
329+
* @return list<non-empty-list>|null
330+
*/
331+
public function getOnlyOrchestrationTaskIds(): ?array
332+
{
333+
return $this->data['onlyOrchestrationTaskIds'] ?? null;
334+
}
335+
336+
/**
337+
* @return non-empty-string|null
338+
*/
339+
public function getPreviousJobId(): ?string
340+
{
341+
return $this->data['previousJobId'] ?? null;
342+
}
343+
320344
public function getRunnerId(): ?string
321345
{
322346
return $this->data['runnerId'] ?? null;

src/JobFactory/JobInterface.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ public function isInRunMode(): bool;
134134
public function getComponentSpecification(): ComponentSpecification;
135135
public function getComponentConfiguration(): array;
136136
public function getOrchestrationJobId(): ?string;
137+
138+
/** @return non-empty-string|null */
139+
public function getOrchestrationTaskId(): ?string;
140+
141+
/** @return list<non-empty-list>|null */
142+
public function getOnlyOrchestrationTaskIds(): ?array;
143+
144+
/** @return non-empty-string|null */
145+
public function getPreviousJobId(): ?string;
146+
137147
public function getProjectFeatures(): array;
138148
public function getBranchType(): BranchType;
139149
}

src/JobFactory/NewJobDefinition.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,44 @@ protected function getRootDefinition(TreeBuilder $treeBuilder): ArrayNodeDefinit
8585
->end()
8686
->end()
8787
->scalarNode('orchestrationJobId')->end()
88+
->scalarNode('orchestrationTaskId')
89+
->validate()
90+
->ifTrue(fn($v) => $v !== null && !is_string($v))
91+
->thenInvalid('value must be a string')
92+
->end()
93+
->validate()
94+
->ifTrue(fn($v) => $v === '')
95+
->thenInvalid('value cannot be empty string')
96+
->end()
97+
->end()
98+
->variableNode('onlyOrchestrationTaskIds')
99+
->validate()
100+
->ifTrue(fn($v) => $v !== null && !is_array($v))
101+
->thenInvalid('value must be an array')
102+
->end()
103+
->validate()
104+
->ifTrue(fn($v) => $v === [])
105+
->thenInvalid('value cannot be empty list')
106+
->end()
107+
->validate()
108+
->ifTrue(fn($v) => count(array_filter($v ?? [], fn($i) => !is_string($i))) > 0)
109+
->thenInvalid('items must be strings')
110+
->end()
111+
->validate()
112+
->ifTrue(fn($v) => count(array_filter($v ?? [], fn($i) => $i === '')) > 0)
113+
->thenInvalid('item cannot be empty string')
114+
->end()
115+
->end()
116+
->scalarNode('previousJobId')
117+
->validate()
118+
->ifTrue(fn($v) => $v !== null && !is_string($v))
119+
->thenInvalid('value must be a string')
120+
->end()
121+
->validate()
122+
->ifTrue(fn($v) => $v === '')
123+
->thenInvalid('value cannot be empty string')
124+
->end()
125+
->end()
88126
->end();
89127
// @formatter:on
90128
return $rootNode;

src/NewJobFactory.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ public function createNewJob(array $data): JobInterface
9595
'variableValuesId' => $data['variableValuesId'] ?? null,
9696
'variableValuesData' => $data['variableValuesData'] ?? [],
9797
'orchestrationJobId' => $data['orchestrationJobId'] ?? null,
98+
'orchestrationTaskId' => $data['orchestrationTaskId'] ?? null,
99+
'onlyOrchestrationTaskIds' => $data['onlyOrchestrationTaskIds'] ?? null,
100+
'previousJobId' => $data['previousJobId'] ?? null,
98101
];
99102
$jobData = $this->jobRuntimeResolver->resolveJobData($jobData, $tokenInfo);
100103

tests/ClientFunctionalTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ public function testCreateJob(
176176
'runnerId' => null,
177177
'executor' => 'dind',
178178
'branchType' => 'default',
179+
'orchestrationTaskId' => null,
180+
'previousJobId' => null,
181+
'onlyOrchestrationTaskIds' => null,
179182
];
180183
self::assertEquals($expected, $response);
181184
}
@@ -287,6 +290,9 @@ public function testCreateJobsBatch(
287290
'runnerId' => null,
288291
'executor' => 'dind',
289292
'branchType' => 'default',
293+
'orchestrationTaskId' => null,
294+
'previousJobId' => null,
295+
'onlyOrchestrationTaskIds' => null,
290296
];
291297
self::assertEquals($expected, $responseJobJson);
292298
}

tests/JobFactory/FullJobDefinitionTest.php

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public function testValidJobMaximal(): void
3636
'parallelism' => null,
3737
'type' => 'standard',
3838
'branchType' => BranchType::DEFAULT->value,
39+
'orchestrationTaskId' => '123',
40+
'onlyOrchestrationTaskIds' => ['45', '67'],
41+
'previousJobId' => '789',
3942
];
4043
$definition = new FullJobDefinition();
4144
$processedData = $definition->processData($expectedData);
@@ -93,6 +96,9 @@ public function testValidJobFull(): void
9396
'orchestrationJobId' => '123456789',
9497
'runnerId' => $runnerId,
9598
'branchType' => 'dev',
99+
'orchestrationTaskId' => null,
100+
'onlyOrchestrationTaskIds' => null,
101+
'previousJobId' => null,
96102
];
97103
unset($data['extraKey']);
98104
unset($data['backend']['backendExtraKey']);
@@ -403,6 +409,150 @@ public function invalidJobProvider(): array
403409
],
404410
'#The value "invalid" is not allowed for path "job.branchType". Permissible values: "default", "dev"#',
405411
],
412+
'orchestrationTaskId not string' => [
413+
[
414+
'#tokenString' => getenv('TEST_STORAGE_API_TOKEN'),
415+
'id' => '12345',
416+
'runId' => '12345',
417+
'tokenId' => '1234',
418+
'projectId' => '123',
419+
'status' => 'created',
420+
'desiredStatus' => 'processing',
421+
'configId' => '123',
422+
'componentId' => 'keboola.test',
423+
'mode' => 'run',
424+
'orchestrationTaskId' => 134,
425+
],
426+
'/Invalid configuration for path "job.orchestrationTaskId": value must be a string/',
427+
],
428+
'orchestrationTaskId empty string' => [
429+
[
430+
'#tokenString' => getenv('TEST_STORAGE_API_TOKEN'),
431+
'id' => '12345',
432+
'runId' => '12345',
433+
'tokenId' => '1234',
434+
'projectId' => '123',
435+
'status' => 'created',
436+
'desiredStatus' => 'processing',
437+
'configId' => '123',
438+
'componentId' => 'keboola.test',
439+
'mode' => 'run',
440+
'orchestrationTaskId' => '',
441+
],
442+
'/Invalid configuration for path "job.orchestrationTaskId": value cannot be empty string/',
443+
],
444+
'onlyOrchestrationTaskIds not list' => [
445+
[
446+
'#tokenString' => getenv('TEST_STORAGE_API_TOKEN'),
447+
'id' => '12345',
448+
'runId' => '12345',
449+
'tokenId' => '1234',
450+
'projectId' => '123',
451+
'status' => 'created',
452+
'desiredStatus' => 'processing',
453+
'configId' => '123',
454+
'componentId' => 'keboola.test',
455+
'mode' => 'run',
456+
'onlyOrchestrationTaskIds' => '123',
457+
],
458+
'/Invalid configuration for path "job.onlyOrchestrationTaskIds": value must be an array/',
459+
],
460+
'onlyOrchestrationTaskIds empty list' => [
461+
[
462+
'#tokenString' => getenv('TEST_STORAGE_API_TOKEN'),
463+
'id' => '12345',
464+
'runId' => '12345',
465+
'tokenId' => '1234',
466+
'projectId' => '123',
467+
'status' => 'created',
468+
'desiredStatus' => 'processing',
469+
'configId' => '123',
470+
'componentId' => 'keboola.test',
471+
'mode' => 'run',
472+
'onlyOrchestrationTaskIds' => [],
473+
],
474+
'/Invalid configuration for path "job.onlyOrchestrationTaskIds": value cannot be empty list/',
475+
],
476+
'onlyOrchestrationTaskIds with non-string item' => [
477+
[
478+
'#tokenString' => getenv('TEST_STORAGE_API_TOKEN'),
479+
'id' => '12345',
480+
'runId' => '12345',
481+
'tokenId' => '1234',
482+
'projectId' => '123',
483+
'status' => 'created',
484+
'desiredStatus' => 'processing',
485+
'configId' => '123',
486+
'componentId' => 'keboola.test',
487+
'mode' => 'run',
488+
'onlyOrchestrationTaskIds' => [123],
489+
],
490+
'/Invalid configuration for path "job.onlyOrchestrationTaskIds": items must be strings/',
491+
],
492+
'onlyOrchestrationTaskIds with null item' => [
493+
[
494+
'#tokenString' => getenv('TEST_STORAGE_API_TOKEN'),
495+
'id' => '12345',
496+
'runId' => '12345',
497+
'tokenId' => '1234',
498+
'projectId' => '123',
499+
'status' => 'created',
500+
'desiredStatus' => 'processing',
501+
'configId' => '123',
502+
'componentId' => 'keboola.test',
503+
'mode' => 'run',
504+
'onlyOrchestrationTaskIds' => [null],
505+
],
506+
'/Invalid configuration for path "job.onlyOrchestrationTaskIds": items must be strings/',
507+
],
508+
'onlyOrchestrationTaskIds with empty item' => [
509+
[
510+
'#tokenString' => getenv('TEST_STORAGE_API_TOKEN'),
511+
'id' => '12345',
512+
'runId' => '12345',
513+
'tokenId' => '1234',
514+
'projectId' => '123',
515+
'status' => 'created',
516+
'desiredStatus' => 'processing',
517+
'configId' => '123',
518+
'componentId' => 'keboola.test',
519+
'mode' => 'run',
520+
'onlyOrchestrationTaskIds' => [''],
521+
],
522+
'/Invalid configuration for path "job.onlyOrchestrationTaskIds": item cannot be empty string/',
523+
],
524+
'previousJobId not string' => [
525+
[
526+
'#tokenString' => getenv('TEST_STORAGE_API_TOKEN'),
527+
'id' => '12345',
528+
'runId' => '12345',
529+
'tokenId' => '1234',
530+
'projectId' => '123',
531+
'status' => 'created',
532+
'desiredStatus' => 'processing',
533+
'configId' => '123',
534+
'componentId' => 'keboola.test',
535+
'mode' => 'run',
536+
'previousJobId' => 134,
537+
],
538+
'/Invalid configuration for path "job.previousJobId": value must be a string/',
539+
],
540+
'previousJobId empty string' => [
541+
[
542+
'#tokenString' => getenv('TEST_STORAGE_API_TOKEN'),
543+
'id' => '12345',
544+
'runId' => '12345',
545+
'tokenId' => '1234',
546+
'projectId' => '123',
547+
'status' => 'created',
548+
'desiredStatus' => 'processing',
549+
'configId' => '123',
550+
'componentId' => 'keboola.test',
551+
'mode' => 'run',
552+
'previousJobId' => '',
553+
],
554+
'/Invalid configuration for path "job.previousJobId": value cannot be empty string/',
555+
],
406556
];
407557
}
408558

0 commit comments

Comments
 (0)