use of org.zalando.nakadi.validation.schema.SchemaEvolutionIncompatibility in project nakadi by zalando.
the class SchemaEvolutionService method checkEvolutionIncompatibilities.
private void checkEvolutionIncompatibilities(final EventType from, final EventTypeBase to) throws InvalidEventTypeException {
final List<SchemaEvolutionIncompatibility> incompatibilities = schemaEvolutionConstraints.stream().map(c -> c.validate(from, to)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
if (incompatibilities.isEmpty()) {
return;
}
// There is a special case of incompatibility - change of category from NONE to BUSINESS, with adding metadata.
// Let's check that it is the case.
// This solution is not scalable, but without huge refactoring it is the simplest one.
final boolean categoryChanged = incompatibilities.stream().anyMatch(v -> v instanceof SchemaEvolutionIncompatibility.CategoryIncompatibility);
if (categoryChanged) {
final boolean metadataChanged = incompatibilities.stream().anyMatch(v -> v instanceof SchemaEvolutionIncompatibility.MetadataIncompatibility);
final int expectedIncompatibilities = 1 + (metadataChanged ? 1 : 0);
if (incompatibilities.size() == expectedIncompatibilities) {
// Now let's check, that it is really change from NONE to BUSINESS and some other conditions.
if (from.getCategory() == EventCategory.UNDEFINED && to.getCategory() == EventCategory.BUSINESS) {
if (to.getEnrichmentStrategies().contains(EnrichmentStrategyDescriptor.METADATA_ENRICHMENT) && to.getCompatibilityMode() != CompatibilityMode.COMPATIBLE) {
// Finally, we are allowing this step.
return;
}
}
}
throw new InvalidEventTypeException("Category change is allowed only from 'undefined' to 'business'. " + "'enrichment_strategies' should be properly set as well");
}
throw new InvalidEventTypeException(incompatibilities.stream().map(SchemaEvolutionIncompatibility::getReason).collect(Collectors.joining("; ")));
}
use of org.zalando.nakadi.validation.schema.SchemaEvolutionIncompatibility in project nakadi by zalando.
the class SchemaEvolutionServiceTest method checkEvolutionConstraints.
@Test(expected = InvalidEventTypeException.class)
public void checkEvolutionConstraints() throws Exception {
final EventTypeTestBuilder builder = EventTypeTestBuilder.builder();
final EventType oldEventType = builder.build();
final EventType newEventType = builder.build();
final Optional<SchemaEvolutionIncompatibility> incompatibility = Optional.of(new SchemaEvolutionIncompatibility("incompatible"));
Mockito.doReturn(incompatibility).when(evolutionConstraint).validate(oldEventType, newEventType);
service.evolve(oldEventType, newEventType);
}
Aggregations