Skip to content

Commit

Permalink
feat(MPM-668): Remove additional parsing of the schema (#41)
Browse files Browse the repository at this point in the history
* Docker and composer changes

* Avoid additional parsing of the schema
  • Loading branch information
bajdzun authored Sep 26, 2022
1 parent 79bed1d commit be91115
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 22 deletions.
5 changes: 0 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
"homepage": "https://careers.jobcloud.ch/en/our-team/?term=133"
}
],
"repositories": [
{
"type": "vcs", "no-api": true, "url": "[email protected]:jobcloud/php-kafka-schema-registry-client.git"
}
],
"require": {
"php": ">=7.4",
"ext-json": "*",
Expand Down
1 change: 1 addition & 0 deletions docker/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
COMPOSE_PROJECT_NAME=php-console-kafka-schema-registry
5 changes: 1 addition & 4 deletions docker/dev/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ COPY files/php/ /phpIni

# SYS: Install required packages
RUN apk --no-cache upgrade && \
apk --no-cache add bash git sudo openssh autoconf gcc g++ make gettext make shadow

RUN apk add librdkafka librdkafka-dev \
--update-cache --repository http://dl-3.alpinelinux.org/alpine/edge/community
apk --no-cache add bash git sudo openssh autoconf gcc g++ make gettext make shadow librdkafka librdkafka-dev

# SYS: add ssh key (for GitHub)
COPY --chown=www-data:www-data files/.ssh /home/www-data/.ssh
Expand Down
8 changes: 1 addition & 7 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,8 @@ services:
environment:
KAFKA_SCHEMA_REGISTRY_URL: 'jobcloud-kafka-schema-registry:9081'
extra_hosts:
- "jobcloud-kafka-schema-registry:172.17.0.1"
- "jobcloud-kafka-schema-registry:host-gateway"
volumes:
- ../:/app/
working_dir: /app
tty: true
secrets:
- ssh_host_key

secrets:
ssh_host_key:
file: ~/.ssh/id_rsa
9 changes: 3 additions & 6 deletions src/Command/RegisterChangedSchemasCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Jobcloud\SchemaConsole\Command;

use AvroSchema;
use AvroSchemaParseException;
use Jobcloud\Kafka\SchemaRegistryClient\Exception\SubjectNotFoundException;
use Jobcloud\Kafka\SchemaRegistryClient\KafkaSchemaRegistryApiClientInterface;
use Jobcloud\SchemaConsole\Helper\SchemaFileHelper;
Expand Down Expand Up @@ -151,17 +149,16 @@ private function registerFiles(
}

try {
$schema = AvroSchema::parse($localSchema);
} catch (AvroSchemaParseException $e) {
$this->schemaRegistryApi->registerNewSchemaVersion($schemaName, $localSchema);
} catch (\Throwable $e) {
$io->writeln(sprintf('Skipping %s for now because %s', $schemaName, $e->getMessage()));
$failed[$schemaName] = $schemaName;
continue;
}
$this->schemaRegistryApi->registerNewSchemaVersion($schemaName, $schema);

$succeeded[$schemaName] = [
'name' => $schemaName,
'version' => $this->schemaRegistryApi->getVersionForSchema($schemaName, $schema),
'version' => $this->schemaRegistryApi->getVersionForSchema($schemaName, $localSchema),
];
unset($failed[$schemaName]);

Expand Down
6 changes: 6 additions & 0 deletions tests/Command/RegisterChangedSchemasCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ public function testOutputWhenCommandFailsRegisteringASchema(): void
'getLatestSubjectVersion' => '1'
]);

$schemaRegistryApi->expects(self::exactly(10))
->method('registerNewSchemaVersion')
->willThrowException(
new \Exception('Skipping test.schema.1 for now because is not a schema we know about.')
);

$application = new Application();
$application->add(new RegisterChangedSchemasCommand($schemaRegistryApi));
$command = $application->find('kafka-schema-registry:register:changed');
Expand Down

0 comments on commit be91115

Please sign in to comment.