Search in sources :

Example 1 with SchemaEvolutionConstraint

use of org.zalando.nakadi.validation.schema.SchemaEvolutionConstraint in project nakadi by zalando.

the class ValidatorConfig method schemaEvolutionService.

@Bean
public SchemaEvolutionService schemaEvolutionService() throws IOException {
    final JSONObject metaSchemaJson = new JSONObject(Resources.toString(Resources.getResource("schema.json"), Charsets.UTF_8));
    final Schema metaSchema = SchemaLoader.load(metaSchemaJson);
    final List<SchemaEvolutionConstraint> schemaEvolutionConstraints = Lists.newArrayList(new CategoryChangeConstraint(), new CompatibilityModeChangeConstraint(), new PartitionKeyFieldsConstraint(), new PartitionStrategyConstraint(), new EnrichmentStrategyConstraint());
    final Map<SchemaChange.Type, Version.Level> compatibleChanges = new HashMap<>();
    compatibleChanges.put(DESCRIPTION_CHANGED, PATCH);
    compatibleChanges.put(TITLE_CHANGED, PATCH);
    compatibleChanges.put(PROPERTIES_ADDED, MINOR);
    compatibleChanges.put(ID_CHANGED, MAJOR);
    compatibleChanges.put(SCHEMA_REMOVED, MAJOR);
    compatibleChanges.put(TYPE_CHANGED, MAJOR);
    compatibleChanges.put(NUMBER_OF_ITEMS_CHANGED, MAJOR);
    compatibleChanges.put(PROPERTY_REMOVED, MAJOR);
    compatibleChanges.put(DEPENDENCY_ARRAY_CHANGED, MAJOR);
    compatibleChanges.put(DEPENDENCY_SCHEMA_CHANGED, MAJOR);
    compatibleChanges.put(COMPOSITION_METHOD_CHANGED, MAJOR);
    compatibleChanges.put(ATTRIBUTE_VALUE_CHANGED, MAJOR);
    compatibleChanges.put(ENUM_ARRAY_CHANGED, MAJOR);
    compatibleChanges.put(SUB_SCHEMA_CHANGED, MAJOR);
    compatibleChanges.put(DEPENDENCY_SCHEMA_REMOVED, MAJOR);
    compatibleChanges.put(REQUIRED_ARRAY_CHANGED, MAJOR);
    compatibleChanges.put(REQUIRED_ARRAY_EXTENDED, MAJOR);
    compatibleChanges.put(ADDITIONAL_PROPERTIES_CHANGED, MAJOR);
    compatibleChanges.put(ADDITIONAL_ITEMS_CHANGED, MAJOR);
    final Map<SchemaChange.Type, Version.Level> forwardChanges = new HashMap<>();
    forwardChanges.put(DESCRIPTION_CHANGED, PATCH);
    forwardChanges.put(TITLE_CHANGED, PATCH);
    forwardChanges.put(PROPERTIES_ADDED, MINOR);
    forwardChanges.put(REQUIRED_ARRAY_EXTENDED, MINOR);
    forwardChanges.put(ID_CHANGED, MAJOR);
    forwardChanges.put(SCHEMA_REMOVED, MAJOR);
    forwardChanges.put(TYPE_CHANGED, MAJOR);
    forwardChanges.put(NUMBER_OF_ITEMS_CHANGED, MAJOR);
    forwardChanges.put(PROPERTY_REMOVED, MAJOR);
    forwardChanges.put(DEPENDENCY_ARRAY_CHANGED, MAJOR);
    forwardChanges.put(DEPENDENCY_SCHEMA_CHANGED, MAJOR);
    forwardChanges.put(COMPOSITION_METHOD_CHANGED, MAJOR);
    forwardChanges.put(ATTRIBUTE_VALUE_CHANGED, MAJOR);
    forwardChanges.put(ENUM_ARRAY_CHANGED, MAJOR);
    forwardChanges.put(SUB_SCHEMA_CHANGED, MAJOR);
    forwardChanges.put(DEPENDENCY_SCHEMA_REMOVED, MAJOR);
    forwardChanges.put(REQUIRED_ARRAY_CHANGED, MAJOR);
    forwardChanges.put(ADDITIONAL_PROPERTIES_CHANGED, MAJOR);
    forwardChanges.put(ADDITIONAL_PROPERTIES_NARROWED, MINOR);
    forwardChanges.put(ADDITIONAL_ITEMS_CHANGED, MAJOR);
    final Map<SchemaChange.Type, String> errorMessage = new HashMap<>();
    errorMessage.put(SCHEMA_REMOVED, "change not allowed");
    errorMessage.put(TYPE_CHANGED, "schema types must be the same");
    errorMessage.put(NUMBER_OF_ITEMS_CHANGED, "the number of schema items cannot be changed");
    errorMessage.put(PROPERTY_REMOVED, "schema properties cannot be removed");
    errorMessage.put(DEPENDENCY_ARRAY_CHANGED, "schema dependencies array cannot be changed");
    errorMessage.put(DEPENDENCY_SCHEMA_CHANGED, "schema dependencies cannot be changed");
    errorMessage.put(COMPOSITION_METHOD_CHANGED, "schema composition method changed");
    errorMessage.put(ATTRIBUTE_VALUE_CHANGED, "change to attribute value not allowed");
    errorMessage.put(ENUM_ARRAY_CHANGED, "enum array changed");
    errorMessage.put(SUB_SCHEMA_CHANGED, "sub schema changed");
    errorMessage.put(DEPENDENCY_SCHEMA_REMOVED, "dependency schema removed");
    errorMessage.put(REQUIRED_ARRAY_CHANGED, "required array changed");
    errorMessage.put(REQUIRED_ARRAY_EXTENDED, "required array changed");
    errorMessage.put(ADDITIONAL_PROPERTIES_CHANGED, "change not allowed");
    errorMessage.put(ADDITIONAL_PROPERTIES_NARROWED, "change not allowed");
    errorMessage.put(ADDITIONAL_ITEMS_CHANGED, "change not allowed");
    final SchemaDiff diff = new SchemaDiff();
    return new SchemaEvolutionService(metaSchema, schemaEvolutionConstraints, diff, compatibleChanges, forwardChanges, errorMessage);
}
Also used : PartitionKeyFieldsConstraint(org.zalando.nakadi.validation.schema.PartitionKeyFieldsConstraint) HashMap(java.util.HashMap) Schema(org.everit.json.schema.Schema) SchemaDiff(org.zalando.nakadi.validation.schema.diff.SchemaDiff) CompatibilityModeChangeConstraint(org.zalando.nakadi.validation.schema.CompatibilityModeChangeConstraint) SchemaEvolutionService(org.zalando.nakadi.validation.SchemaEvolutionService) EnrichmentStrategyConstraint(org.zalando.nakadi.validation.schema.EnrichmentStrategyConstraint) JSONObject(org.json.JSONObject) SchemaEvolutionConstraint(org.zalando.nakadi.validation.schema.SchemaEvolutionConstraint) PartitionStrategyConstraint(org.zalando.nakadi.validation.schema.PartitionStrategyConstraint) CategoryChangeConstraint(org.zalando.nakadi.validation.schema.CategoryChangeConstraint) Bean(org.springframework.context.annotation.Bean)

Example 2 with SchemaEvolutionConstraint

use of org.zalando.nakadi.validation.schema.SchemaEvolutionConstraint in project nakadi by zalando.

the class SchemaEvolutionServiceTest method setUp.

@Before
public void setUp() throws IOException {
    final List<SchemaEvolutionConstraint> evolutionConstraints = Lists.newArrayList(evolutionConstraint);
    final JSONObject metaSchemaJson = new JSONObject(Resources.toString(Resources.getResource("schema.json"), Charsets.UTF_8));
    final Schema metaSchema = SchemaLoader.load(metaSchemaJson);
    this.service = new SchemaEvolutionService(metaSchema, evolutionConstraints, schemaDiff, compatibleChanges, forwardChanges, errorMessages);
    Mockito.doReturn("error").when(errorMessages).get(any());
}
Also used : SchemaEvolutionConstraint(org.zalando.nakadi.validation.schema.SchemaEvolutionConstraint) JSONObject(org.json.JSONObject) Schema(org.everit.json.schema.Schema) Before(org.junit.Before)

Aggregations

Schema (org.everit.json.schema.Schema)2 JSONObject (org.json.JSONObject)2 SchemaEvolutionConstraint (org.zalando.nakadi.validation.schema.SchemaEvolutionConstraint)2 HashMap (java.util.HashMap)1 Before (org.junit.Before)1 Bean (org.springframework.context.annotation.Bean)1 SchemaEvolutionService (org.zalando.nakadi.validation.SchemaEvolutionService)1 CategoryChangeConstraint (org.zalando.nakadi.validation.schema.CategoryChangeConstraint)1 CompatibilityModeChangeConstraint (org.zalando.nakadi.validation.schema.CompatibilityModeChangeConstraint)1 EnrichmentStrategyConstraint (org.zalando.nakadi.validation.schema.EnrichmentStrategyConstraint)1 PartitionKeyFieldsConstraint (org.zalando.nakadi.validation.schema.PartitionKeyFieldsConstraint)1 PartitionStrategyConstraint (org.zalando.nakadi.validation.schema.PartitionStrategyConstraint)1 SchemaDiff (org.zalando.nakadi.validation.schema.diff.SchemaDiff)1