Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

417 issue cant load an avro schema serializer from register #420

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7a95344
using APICURIO when catch
RobertoSngular Oct 19, 2023
96b83a3
change AvroSchema to schema and fix tests
RobertoSngular Oct 19, 2023
9727eb3
Eliminar imports de AvroSchema de AvroCofluentExtractor y AvroCofluen…
RobertoSngular Oct 19, 2023
83bed3a
Fixed minor issue which appears after merging PR for issues 415 and 417
pablorodriguez-sngular Oct 20, 2023
2d0c8cb
Fixed minor issue which appears after merging PR for issues 415 and 417
pablorodriguez-sngular Oct 20, 2023
8d78919
New File to test AvroConfluentExtractor
GraciMndzSNG Oct 20, 2023
91cc5a4
Revert "New File to test AvroConfluentExtractor"
GraciMndzSNG Oct 20, 2023
1f9717b
New File to test AvroConfluentExtractor
GraciMndzSNG Oct 20, 2023
a31fcb0
Add test to verify extraction of a Schema
GraciMndzSNG Oct 23, 2023
52f1b2f
Add test for SchemaExtractor AVRO and CONFLUENT use case
fvarela-sng Oct 23, 2023
60d9015
Merge branch '417-issue-cant-load-an-avro-schema-serializer-from-regi…
GraciMndzSNG Oct 23, 2023
20c6155
File test Updated
GraciMndzSNG Oct 24, 2023
d895490
ExtractorFactoryTest with Mockito
pablorodriguez-sngular Oct 25, 2023
ba44193
ExtractorFactoryTest with Mockito
pablorodriguez-sngular Oct 25, 2023
d4d76a0
fix ExtractorFactoryTest
RobertoSngular Oct 26, 2023
d9803aa
Adding authority
GraciMndzSNG Oct 27, 2023
2eb42df
Merge Extractor
GraciMndzSNG Oct 27, 2023
95506f6
Added authorship
GraciMndzSNG Oct 27, 2023
5d4a133
adding authorship to pom
RobertoSngular Oct 27, 2023
68e44e7
Use of instanceof in AvroExtractor an 1 return
RobertoSngular Oct 27, 2023
1741e9b
Updated pom.xml
pablorodriguez-sngular Nov 6, 2023
369b681
merge y errores checkstile
RobertoSngular Nov 8, 2023
7cccf0e
Merge branch 'master' into 417-issue-cant-load-an-avro-schema-seriali…
jemacineiras Nov 13, 2023
9a955c0
Substitution of kafka ParsedSchema and factory metod fixing
RobertoSngular Nov 14, 2023
c8918af
Pom fixes
RobertoSngular Nov 14, 2023
475c982
Merge branch 'master' into 417-issue-cant-load-an-avro-schema-seriali…
RobertoSngular Nov 15, 2023
dd0d794
Updated version and checkstyle fixes in test
RobertoSngular Nov 15, 2023
dad5fcf
Uncomment test and fixes to use it plus checkstyle
RobertoSngular Nov 15, 2023
cb388d8
codacy test errors
RobertoSngular Nov 16, 2023
570ff8e
ExtractorFactoryTest checkstyle fixes
RobertoSngular Nov 16, 2023
4ddfd68
#417 Fix checkstyle
jemacineiras Nov 16, 2023
1bb2bb2
#417 Codacy issues
jemacineiras Nov 20, 2023
661f3b4
Bug fixes
RobertoSngular Nov 20, 2023
a6332bd
Merge branch '417-issue-cant-load-an-avro-schema-serializer-from-regi…
RobertoSngular Nov 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/checkstyle/OSS_checkstyle_suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<suppress checks="ClassDataAbstractionCoupling" files="[/\\].*ProcessorTest\.java" />
<suppress checks="ClassDataAbstractionCoupling" files="[/\\].*Standalone\.java" />
<suppress checks="ClassDataAbstractionCoupling" files="[/\\].*AvroSerializersUtil\.java" />
<suppress checks="ClassDataAbstractionCoupling" files="[/\\].*ExtractorFactoryTest\.java" />
<suppress checks="ExecutableStatementCount" files="[/\\].*Standalone\.java" />
<suppress checks="AnonInnerLength" files="[/\\].*AutoCompletion\.java" />
<suppress checks="Indentation" files="[/\\].*ExtractorTest\.java" />
Expand Down
11 changes: 11 additions & 0 deletions pom-maven-central.xml
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,17 @@
</roles>
<timezone>Europe/Madrid</timezone>
</developer>
<developer>
<id>RobertoSngular</id>
<name>Roberto Riveira Veiga</name>
<email>[email protected]</email>
<organization>Sngular</organization>
<organizationUrl>https://sngular.github.io/</organizationUrl>
<roles>
<role>Backend Developer</role>
</roles>
<timezone>Europe/Madrid</timezone>
</developer>
</developers>

<scm>
Expand Down
23 changes: 22 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<artifactId>kloadgen</artifactId>

<version>5.6.10</version>
<version>5.6.11</version>

<name>KLoadGen</name>
<description>Load Generation Jmeter plugin for Kafka Cluster. Supporting AVRO, JSON Schema and Protobuf schema types. Generate Artificial
Expand Down Expand Up @@ -310,6 +310,27 @@
<roles>
<role>Trainee Backend Developer</role>
</roles>
</developer>
<developer>
<id>GraciMndzSNG</id>
<name>Graciela Méndez Olmos</name>
<email>[email protected]</email>
<organization>Sngular</organization>
<organizationUrl>https://sngular.github.io/</organizationUrl>
<roles>
<role>Backend Developer</role>
</roles>
<timezone>Europe/Madrid</timezone>
</developer>
<developer>
<id>pablorodriguez-sngular</id>
<name>Pablo Rodríguez Pérez</name>
<email>[email protected]</email>
<organization>Sngular</organization>
<organizationUrl>https://sngular.github.io/</organizationUrl>
<roles>
<role>Backend Developer</role>
</roles>
<timezone>Europe/Madrid</timezone>
</developer>
</developers>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,23 @@ public ValueFileSerializedConfigElementBeanInfo() {

final PropertyDescriptor nameStrategyPropertyProps = property(VALUE_NAME_STRATEGY);
nameStrategyPropertyProps.setPropertyEditorClass(NameStrategyPropertyEditor.class);
nameStrategyPropertyProps.setValue(NOT_UNDEFINED, Boolean.TRUE);
nameStrategyPropertyProps.setValue(DEFAULT, "");
nameStrategyPropertyProps.setValue(NOT_EXPRESSION, Boolean.FALSE);
complete(nameStrategyPropertyProps);

final PropertyDescriptor serializerPropertyProps = property(VALUE_SERIALIZER_PROPERTY);
serializerPropertyProps.setPropertyEditorClass(ValueSerializerPropertyEditor.class);
serializerPropertyProps.setValue(NOT_UNDEFINED, Boolean.TRUE);
serializerPropertyProps.setValue(DEFAULT, "");
serializerPropertyProps.setValue(NOT_EXPRESSION, Boolean.FALSE);
complete(serializerPropertyProps);

final PropertyDescriptor subjectNameProps = property(VALUE_SUBJECT_NAME);
subjectNameProps.setPropertyEditorClass(FileSubjectPropertyEditor.class);
subjectNameProps.setValue(NOT_UNDEFINED, Boolean.TRUE);
subjectNameProps.setValue(DEFAULT, "");
subjectNameProps.setValue(NOT_EXPRESSION, Boolean.FALSE);
complete(subjectNameProps);

final PropertyDescriptor schemaType = property(VALUE_SCHEMA_TYPE);
schemaType.setPropertyEditorClass(SchemaTypePropertyEditor.class);
schemaType.setValue(NOT_UNDEFINED, Boolean.TRUE);
schemaType.setValue(DEFAULT, "");
schemaType.setValue(NOT_EXPRESSION, Boolean.FALSE);
complete(schemaType);

final PropertyDescriptor avroSchemaProps = property(VALUE_SCHEMA_DEFINITION);
avroSchemaProps.setPropertyEditorClass(SchemaConverterPropertyEditor.class);
avroSchemaProps.setValue(NOT_UNDEFINED, Boolean.TRUE);
avroSchemaProps.setValue(DEFAULT, "");
avroSchemaProps.setValue(NOT_EXPRESSION, Boolean.FALSE);
complete(avroSchemaProps);

final TypeEditor tableEditor = TypeEditor.TableEditor;
final PropertyDescriptor tableProperties = property(VALUE_SCHEMA_PROPERTIES, tableEditor);
Expand All @@ -79,4 +69,10 @@ public ValueFileSerializedConfigElementBeanInfo() {
tableProperties.setValue(DEFAULT, new ArrayList<>());
tableProperties.setValue(NOT_UNDEFINED, Boolean.TRUE);
}

private void complete(final PropertyDescriptor propertyDescriptor) {
propertyDescriptor.setValue(NOT_UNDEFINED, Boolean.TRUE);
propertyDescriptor.setValue(DEFAULT, "");
propertyDescriptor.setValue(NOT_EXPRESSION, Boolean.FALSE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.sngular.kloadgen.common.SchemaRegistryEnum;
import com.sngular.kloadgen.extractor.extractors.ExtractorFactory;
import com.sngular.kloadgen.model.FieldValueMapping;
import io.confluent.kafka.schemaregistry.ParsedSchema;
import com.sngular.kloadgen.parsedschema.ParsedSchema;
import lombok.Getter;
import org.apache.commons.lang3.tuple.Pair;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
import com.sngular.kloadgen.exception.KLoadGenException;
import com.sngular.kloadgen.extractor.extractors.avro.AvroExtractor;
import com.sngular.kloadgen.extractor.extractors.json.JsonExtractor;
import com.sngular.kloadgen.extractor.extractors.protobuff.ProtobuffExtractor;
import com.sngular.kloadgen.extractor.extractors.protobuf.ProtobufExtractor;
import com.sngular.kloadgen.model.FieldValueMapping;
import com.sngular.kloadgen.parsedschema.ParsedSchema;
import com.sngular.kloadgen.schemaregistry.adapter.impl.AbstractParsedSchemaAdapter;
import com.sngular.kloadgen.schemaregistry.adapter.impl.ApicurioAbstractParsedSchemaMetadata;
import com.sngular.kloadgen.util.JMeterHelper;
Expand All @@ -21,22 +22,28 @@
import org.apache.jmeter.threads.JMeterContextService;

public final class ExtractorFactory {
private static final AvroExtractor AVRO_EXTRACTOR = new AvroExtractor();
private static AvroExtractor avroExtractor = new AvroExtractor();

private static final JsonExtractor JSON_EXTRACTOR = new JsonExtractor();
private static JsonExtractor jsonExtractor = new JsonExtractor();

private static final ProtobuffExtractor PROTOBUFF_EXTRACTOR = new ProtobuffExtractor();
private static ProtobufExtractor protobufExtractor = new ProtobufExtractor();

private ExtractorFactory() {
}

public static void configExtractorFactory(final AvroExtractor avroExtractor, final JsonExtractor jsonExtractor, final ProtobufExtractor protobufExtractor) {
ExtractorFactory.avroExtractor = avroExtractor;
ExtractorFactory.jsonExtractor = jsonExtractor;
ExtractorFactory.protobufExtractor = protobufExtractor;
}

public static ExtractorRegistry getExtractor(final String schemaType) {

if (schemaType != null && EnumUtils.isValidEnum(SchemaTypeEnum.class, schemaType.toUpperCase())) {
final ExtractorRegistry response = switch (SchemaTypeEnum.valueOf(schemaType.toUpperCase())) {
case JSON -> JSON_EXTRACTOR;
case AVRO -> AVRO_EXTRACTOR;
case PROTOBUF -> PROTOBUFF_EXTRACTOR;
case JSON -> jsonExtractor;
case AVRO -> avroExtractor;
case PROTOBUF -> protobufExtractor;
default -> throw new KLoadGenException(String.format("Schema type not supported %s", schemaType));
};
return response;
Expand All @@ -62,7 +69,7 @@ public static Pair<String, List<FieldValueMapping>> flatPropertiesList(final Str
case APICURIO -> ((ApicurioAbstractParsedSchemaMetadata) abstractParsedSchemaAdapter).getSchema();
case CONFLUENT -> abstractParsedSchemaAdapter.getRawSchema();
};
attributeList.addAll(getExtractor(schemaType).processSchema(schema, schemaRegistryEnum));
attributeList.addAll(getExtractor(schemaType).processSchema(new ParsedSchema(schema), schemaRegistryEnum));
}
return Pair.of(schemaType, attributeList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

import com.sngular.kloadgen.extractor.extractors.Extractor;
import com.sngular.kloadgen.model.FieldValueMapping;
import io.confluent.kafka.schemaregistry.avro.AvroSchema;
import org.apache.avro.Schema;

public class AvroConfluentExtractor extends AbstractAvroFileExtractor implements Extractor<AvroSchema> {
public class AvroConfluentExtractor extends AbstractAvroFileExtractor implements Extractor<Schema> {

public final List<FieldValueMapping> processSchema(final AvroSchema schema) {
return this.processSchemaDefault(schema.rawSchema());
public final List<FieldValueMapping> processSchema(final Schema schema) {
return this.processSchemaDefault(schema);
}

public final List<String> getSchemaNameList(final String schema) {
return getSchemaNameList(new AvroSchema(schema).rawSchema());
return getSchemaNameList(new Schema.Parser().parse(schema));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@
import com.sngular.kloadgen.extractor.extractors.Extractor;
import com.sngular.kloadgen.extractor.extractors.ExtractorRegistry;
import com.sngular.kloadgen.model.FieldValueMapping;
import io.confluent.kafka.schemaregistry.ParsedSchema;
import io.confluent.kafka.schemaregistry.avro.AvroSchema;
import com.sngular.kloadgen.parsedschema.ParsedSchema;

public class AvroExtractor implements ExtractorRegistry<Object> {
public class AvroExtractor implements ExtractorRegistry<ParsedSchema> {

private static Map<SchemaRegistryEnum, Extractor> schemaRegistryMap = Map.of(SchemaRegistryEnum.CONFLUENT, new AvroConfluentExtractor(), SchemaRegistryEnum.APICURIO,
new AvroApicurioExtractor());

public final List<FieldValueMapping> processSchema(final Object schema, final SchemaRegistryEnum registryEnum) {
return schemaRegistryMap.get(registryEnum).processSchema(schema);
public final List<FieldValueMapping> processSchema(final ParsedSchema schema, final SchemaRegistryEnum registryEnum) {
return schemaRegistryMap.get(registryEnum).processSchema(schema.rawSchema());
}

public final ParsedSchema processSchema(final String fileContent) {
return new AvroSchema(fileContent);
return new ParsedSchema(fileContent, "AVRO");
}

public final List<String> getSchemaNameList(final String schema, final SchemaRegistryEnum registryEnum) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class JsonDefaultExtractor extends AbstractJsonExtractor implements Extra
@Override
public final List<FieldValueMapping> processSchema(final String schema) {

final Schema parsed = getSchemaParser().parse(schema.toString());
final Schema parsed = getSchemaParser().parse(schema);

final List<FieldValueMapping> attributeList = new ArrayList<>();
parsed.getProperties().forEach(field -> attributeList.addAll(processField(field, true, null)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@
import com.sngular.kloadgen.extractor.extractors.Extractor;
import com.sngular.kloadgen.extractor.extractors.ExtractorRegistry;
import com.sngular.kloadgen.model.FieldValueMapping;
import io.confluent.kafka.schemaregistry.ParsedSchema;
import io.confluent.kafka.schemaregistry.json.JsonSchema;
import com.sngular.kloadgen.parsedschema.ParsedSchema;


public class JsonExtractor implements ExtractorRegistry<Object> {
public class JsonExtractor implements ExtractorRegistry<ParsedSchema> {

private static final Map<SchemaRegistryEnum, Extractor> SCHEMA_REGISTRY_MAP = Map.of(SchemaRegistryEnum.CONFLUENT, new JsonDefaultExtractor(),
SchemaRegistryEnum.APICURIO, new JsonDefaultExtractor());

public final List<FieldValueMapping> processSchema(final Object schemaReceived, final SchemaRegistryEnum registryEnum) {
return SCHEMA_REGISTRY_MAP.get(registryEnum).processSchema(schemaReceived.toString());
public final List<FieldValueMapping> processSchema(final ParsedSchema schemaReceived, final SchemaRegistryEnum registryEnum) {
return SCHEMA_REGISTRY_MAP.get(registryEnum).processSchema(schemaReceived.rawSchema().toString());
}

public final ParsedSchema processSchema(final String fileContent) {
return new JsonSchema(fileContent);
return new ParsedSchema(fileContent, "JSON");
}

public final List<String> getSchemaNameList(final String schema, final SchemaRegistryEnum registryEnum) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sngular.kloadgen.extractor.extractors.protobuff;
package com.sngular.kloadgen.extractor.extractors.protobuf;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sngular.kloadgen.extractor.extractors.protobuff;
package com.sngular.kloadgen.extractor.extractors.protobuf;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.sngular.kloadgen.extractor.extractors.protobuff;
package com.sngular.kloadgen.extractor.extractors.protobuf;

import java.util.List;

import com.sngular.kloadgen.extractor.extractors.Extractor;
import com.sngular.kloadgen.model.FieldValueMapping;
import com.sngular.kloadgen.parsedschema.ParsedSchema;
import com.squareup.wire.schema.internal.parser.ProtoFileElement;
import io.confluent.kafka.schemaregistry.protobuf.ProtobufSchema;

public class ProtoBufConfluentExtractor extends AbstractProtoFileExtractor implements Extractor<ProtobufSchema> {
public class ProtoBufConfluentExtractor extends AbstractProtoFileExtractor implements Extractor<ParsedSchema> {

public final List<FieldValueMapping> processSchema(final ProtobufSchema schemaReceived) {
return processSchemaDefault(schemaReceived.rawSchema());
public final List<FieldValueMapping> processSchema(final ParsedSchema schemaReceived) {
return processSchemaDefault((ProtoFileElement) schemaReceived.rawSchema());
}

public final List<String> getSchemaNameList(final String schema) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sngular.kloadgen.extractor.extractors.protobuff;
package com.sngular.kloadgen.extractor.extractors.protobuf;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -8,27 +8,19 @@
import com.sngular.kloadgen.extractor.extractors.Extractor;
import com.sngular.kloadgen.extractor.extractors.ExtractorRegistry;
import com.sngular.kloadgen.model.FieldValueMapping;
import com.squareup.wire.schema.internal.parser.ProtoFileElement;
import io.confluent.kafka.schemaregistry.ParsedSchema;
import io.confluent.kafka.schemaregistry.protobuf.ProtobufSchema;
import com.sngular.kloadgen.parsedschema.ParsedSchema;

public class ProtobuffExtractor implements ExtractorRegistry<Object> {
public class ProtobufExtractor implements ExtractorRegistry<ParsedSchema> {

private static final Map<SchemaRegistryEnum, Extractor> SCHEMA_REGISTRY_MAP = Map.of(SchemaRegistryEnum.CONFLUENT, new ProtoBufConfluentExtractor(),
SchemaRegistryEnum.APICURIO, new ProtoBufApicurioExtractor());

public final List<FieldValueMapping> processSchema(final Object schemaReceived, final SchemaRegistryEnum registryEnum) {
final var resultSchema = new ArrayList<FieldValueMapping>();
if (schemaReceived instanceof ProtoFileElement) {
resultSchema.addAll(SCHEMA_REGISTRY_MAP.get(SchemaRegistryEnum.APICURIO).processSchema(schemaReceived));
} else {
resultSchema.addAll(SCHEMA_REGISTRY_MAP.get(registryEnum).processSchema(schemaReceived));
}
return resultSchema;
public final List<FieldValueMapping> processSchema(final ParsedSchema schemaReceived, final SchemaRegistryEnum registryEnum) {
return new ArrayList<FieldValueMapping>(SCHEMA_REGISTRY_MAP.get(registryEnum).processSchema(schemaReceived));
}

public final ParsedSchema processSchema(final String fileContent) {
return new ProtobufSchema(fileContent);
return new ParsedSchema(fileContent, "PROTOBUF");
}

public final List<String> getSchemaNameList(final String schema, final SchemaRegistryEnum registryEnum) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public final void setUpGenerator(
public final void setUpGenerator(final String schema, final List<FieldValueMapping> fieldExprMappings) {
final ProtobufSchema protobufSchema = new ProtobufSchema(schema);
this.protobufSchemaProcessor
.processSchema(SchemaTypeEnum.PROTOBUF, protobufSchema, new BaseSchemaMetadata<>(
.processSchema(SchemaTypeEnum.PROTOBUF, protobufSchema.rawSchema(), new BaseSchemaMetadata<>(
ConfluentSchemaMetadata.parse(new SchemaMetadata(1, 1, SchemaTypeEnum.PROTOBUF.name(), Collections.emptyList(), schema))),
fieldExprMappings);
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/sngular/kloadgen/parsedschema/IParsedSchema.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.sngular.kloadgen.parsedschema;

public interface IParsedSchema<T> {

String schemaType();

String name();

String canonicalString();

Object rawSchema();

}
Loading
Loading