From 447529f948cade0abb7e5e8d1f2648e57e237f4a Mon Sep 17 00:00:00 2001 From: Alex Van Boxel Date: Wed, 15 Apr 2020 16:19:01 +0200 Subject: [PATCH 01/11] Setting SNAPSHOT for 0.9.0-SNAPSHOT --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 5364c6c..bffbd38 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ allprojects { apply from: "${project.rootDir}/gradle/properties.gradle" group = "io.anemos" - version = "0.8.12-SNAPSHOT" + version = "0.9.0-SNAPSHOT" repositories { jcenter() From 1843d5402117af809e302d16d45f374f8864cbaa Mon Sep 17 00:00:00 2001 From: Alex Van Boxel Date: Mon, 23 Mar 2020 15:42:24 +0100 Subject: [PATCH 02/11] Split Registry and Bind --- .../core/registry/AbstractRegistry.java | 17 +- .../proto/grpc/registry/v1alpha1/bind.proto | 145 ++++++++++++++++ .../v1alpha1/{report.proto => patch.proto} | 0 .../grpc/registry/v1alpha1/registry.proto | 156 ++--------------- .../java/io/anemos/metastore/BindService.java | 164 ++++++++++++++++++ .../io/anemos/metastore/MetaStoreServer.java | 1 + .../io/anemos/metastore/RegistryService.java | 134 +------------- 7 files changed, 338 insertions(+), 279 deletions(-) create mode 100644 proto/src/main/proto/grpc/registry/v1alpha1/bind.proto rename proto/src/main/proto/grpc/registry/v1alpha1/{report.proto => patch.proto} (100%) create mode 100644 server/src/main/java/io/anemos/metastore/BindService.java diff --git a/core/src/main/java/io/anemos/metastore/core/registry/AbstractRegistry.java b/core/src/main/java/io/anemos/metastore/core/registry/AbstractRegistry.java index 91b9714..a74f370 100644 --- a/core/src/main/java/io/anemos/metastore/core/registry/AbstractRegistry.java +++ b/core/src/main/java/io/anemos/metastore/core/registry/AbstractRegistry.java @@ -10,7 +10,7 @@ import io.anemos.metastore.provider.RegistryInfo; import io.anemos.metastore.provider.StorageProvider; import io.anemos.metastore.putils.ProtoDomain; -import io.anemos.metastore.v1alpha1.RegistryP; +import io.anemos.metastore.v1alpha1.BindP; import io.anemos.metastore.v1alpha1.RegistryP.SubmitSchemaRequest.Comment; import io.anemos.metastore.v1alpha1.Report; import io.grpc.Status; @@ -84,7 +84,7 @@ void initGitRepo() { metaGit.init(); } - public void updateResourceBinding(RegistryP.ResourceBinding resourceBinding, boolean create) + public void updateResourceBinding(BindP.ResourceBinding resourceBinding, boolean create) throws StatusException { if (resourceBinding == null) { throw Status.INVALID_ARGUMENT.withDescription("binding should be set.").asException(); @@ -93,7 +93,7 @@ public void updateResourceBinding(RegistryP.ResourceBinding resourceBinding, boo String linkedResource = validateLinkedResource(resourceBinding.getLinkedResource()); if (resourceBinding.getTypeCase().getNumber() - == RegistryP.ResourceBinding.MESSAGE_NAME_FIELD_NUMBER) { + == BindP.ResourceBinding.MESSAGE_NAME_FIELD_NUMBER) { Descriptors.Descriptor descriptor = protoContainer.getDescriptorByName(resourceBinding.getMessageName()); if (descriptor == null) { @@ -136,8 +136,7 @@ public void deleteResourceBinding(String linkedResource) { this.bindProviders.forEach(provider -> provider.deleteResourceBinding(linkedResource)); } - public RegistryP.ResourceBinding getResourceBinding(String linkedResource) - throws StatusException { + public BindP.ResourceBinding getResourceBinding(String linkedResource) throws StatusException { BindResult bindResult = this.bindProviders.get(0).getResourceBinding(linkedResource); if (bindResult == null) { throw Status.NOT_FOUND @@ -147,9 +146,9 @@ public RegistryP.ResourceBinding getResourceBinding(String linkedResource) return toResourceBinding(bindResult); } - public Collection listResourceBindings(String nextPagetoken) { + public Collection listResourceBindings(String nextPagetoken) { List bindResults = this.bindProviders.get(0).listResourceBindings(nextPagetoken); - List bindings = new ArrayList<>(bindResults.size()); + List bindings = new ArrayList<>(bindResults.size()); bindResults.forEach( result -> { bindings.add(toResourceBinding(result)); @@ -157,8 +156,8 @@ public Collection listResourceBindings(String nextPag return bindings; } - private RegistryP.ResourceBinding toResourceBinding(BindResult result) { - RegistryP.ResourceBinding.Builder resourceBinding = RegistryP.ResourceBinding.newBuilder(); + private BindP.ResourceBinding toResourceBinding(BindResult result) { + BindP.ResourceBinding.Builder resourceBinding = BindP.ResourceBinding.newBuilder(); resourceBinding.setLinkedResource(result.getLinkedResource()); if (result.getMessageName() != null) { resourceBinding.setMessageName(result.getMessageName()); diff --git a/proto/src/main/proto/grpc/registry/v1alpha1/bind.proto b/proto/src/main/proto/grpc/registry/v1alpha1/bind.proto new file mode 100644 index 0000000..12700e4 --- /dev/null +++ b/proto/src/main/proto/grpc/registry/v1alpha1/bind.proto @@ -0,0 +1,145 @@ +syntax = "proto3"; + +import "google/protobuf/timestamp.proto"; + +option java_package = "io.anemos.metastore.v1alpha1"; +option java_outer_classname = "BindP"; + +package grpc.registry.v1alpha1; + +service Bind { + rpc CreateResourceBinding (CreateResourceBindingRequest) returns (CreateResourceBindingResponse); + rpc UpdateResourceBinding (UpdateResourceBindingRequest) returns (UpdateResourceBindingResponse); + rpc DeleteResourceBinding (DeleteResourceBindingRequest) returns (DeleteResourceBindingResponse); + rpc GetResourceBinding (GetResourceBindingeRequest) returns (GetResourceBindingResponse); + rpc ListResourceBindings (ListResourceBindingsRequest) returns (ListResourceBindingsResponse); + rpc UseResource (UseResourceRequest) returns (UseResourceResponse); +} + +message ResourceBinding { + // + // * googlecloud://bigquery.googleapis.com/projects/projectId/datasets/datasetId/tables/tableId + // * googlecloud://pubsub.googleapis.com/projects/projectId/datasets/datasetId/tables/tableId + // * (http/https)://hostname// + string linked_resource = 1; + oneof type { + string message_name = 2; + string service_name = 3; + } +} +message CreateResourceBindingRequest { + string registry_name = 1; + ResourceBinding binding = 2; +} + +message CreateResourceBindingResponse { +} + +message UpdateResourceBindingRequest { + string registry_name = 1; + ResourceBinding binding = 2; +} + +message UpdateResourceBindingResponse { +} + +message DeleteResourceBindingRequest { + string registry_name = 1; + // + // * googlecloud://bigquery.googleapis.com/projects/projectId/datasets/datasetId/tables/tableId + // * googlecloud://pubsub.googleapis.com/projects/projectId/datasets/datasetId/tables/tableId + // * (http/https)://hostname/ + string linked_resource = 2; +} + +message DeleteResourceBindingResponse { +} + + +message GetResourceBindingeRequest { + enum SchemaContext { + SCHEMA_CONTEXT_NONE = 0; + SCHEMA_CONTEXT_IN_FILE = 1; + SCHEMA_CONTEXT_IN_SCOPE = 2; + SCHEMA_CONTEXT_FULL_DOMAIN = 3; + } + + string registry_name = 1; + string linked_resource = 2; + SchemaContext schema_context = 3; +} + +message GetResourceBindingResponse { + string file_name = 1; + string package_name = 2; + ResourceBinding binding = 3; + // These are proto2 type google.protobuf.FileDescriptorProto, but + // we avoid taking a dependency on descriptor.proto, which uses + // proto2 only features, by making them opaque + // bytes instead + repeated bytes file_descriptor_proto = 4; +} + +message ListResourceBindingsRequest { + string registry_name = 1; + // Maximum number of subscription names to return. + int32 page_size = 2; + + // The value returned by the last `ListResourceBindingsRequest`; indicates + // that this is a continuation of a prior `ListResourceBindingsRequest` call, and + // that the system should return the next page of data. + string page_token = 3; +} + +message ListResourceBindingsResponse { + repeated ResourceBinding bindings = 1; + string next_page_token = 2; +} + +message UseResourceRequest { + enum Purpose { + PURPOSE_UNSET = 0; + PURPOSE_PRODUCER = 1; + PURPOSE_CONSUMER = 2; + PURPOSE_API_SERVER = 3; + PURPOSE_API_CLIENT = 4; + } + + message Metrics { + int64 data_bytes = 1; + int64 data_messages = 2; + int64 data_errors = 3; + } + + message Usage { + string usage_name = 1; + oneof entity_scope { + string linked_resource = 2; + string package_name = 3; + string package_prefix = 4; + string message_name = 5; + string service_name = 6; + string enum_name = 7; + string file_name = 8; + } + Purpose purpose = 9; + google.protobuf.Timestamp since = 10; + Metrics metrics = 11; + } + + string registry_name = 2; + string name = 3; + string instance = 4; + map labels = 5; + + // These are proto2 type google.protobuf.FileDescriptorProto, but + // we avoid taking a dependency on descriptor.proto, which uses + // proto2 only features, by making them opaque + // bytes instead + repeated bytes file_descriptor_proto = 6; + + repeated Usage usage = 7; +} + +message UseResourceResponse { +} diff --git a/proto/src/main/proto/grpc/registry/v1alpha1/report.proto b/proto/src/main/proto/grpc/registry/v1alpha1/patch.proto similarity index 100% rename from proto/src/main/proto/grpc/registry/v1alpha1/report.proto rename to proto/src/main/proto/grpc/registry/v1alpha1/patch.proto diff --git a/proto/src/main/proto/grpc/registry/v1alpha1/registry.proto b/proto/src/main/proto/grpc/registry/v1alpha1/registry.proto index a9a9d6f..6edf24a 100644 --- a/proto/src/main/proto/grpc/registry/v1alpha1/registry.proto +++ b/proto/src/main/proto/grpc/registry/v1alpha1/registry.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -import "grpc/registry/v1alpha1/report.proto"; +import "grpc/registry/v1alpha1/patch.proto"; import "google/protobuf/timestamp.proto"; option java_package = "io.anemos.metastore.v1alpha1"; @@ -9,26 +9,31 @@ option java_outer_classname = "RegistryP"; package grpc.registry.v1alpha1; service Registry { - rpc SubmitSchema (SubmitSchemaRequest) returns (SubmitSchemaResponse); - rpc VerifySchema (SubmitSchemaRequest) returns (SubmitSchemaResponse); rpc GetSchema (GetSchemaRequest) returns (GetSchemaResponse); - - rpc CreateResourceBinding (CreateResourceBindingRequest) returns (CreateResourceBindingResponse); - rpc UpdateResourceBinding (UpdateResourceBindingRequest) returns (UpdateResourceBindingResponse); - rpc DeleteResourceBinding (DeleteResourceBindingRequest) returns (DeleteResourceBindingResponse); - rpc GetResourceBinding (GetResourceBindingeRequest) returns (GetResourceBindingResponse); - rpc ListResourceBindings (ListResourceBindingsRequest) returns (ListResourceBindingsResponse); - rpc UseResource (UseResourceRequest) returns (UseResourceResponse); + rpc VerifySchema (SubmitSchemaRequest) returns (SubmitSchemaResponse); + rpc SubmitSchema (SubmitSchemaRequest) returns (SubmitSchemaResponse); } message SubmitSchemaRequest { + // Information of this schema changes. message Comment { string name = 1; string email = 2; string description = 3; } + message FileGroup { + repeated string file_name = 1; + } + + // How a scoped submit will be merged into the existing registry. + enum MergeStrategy { + MERGE = 0; + REPLACE = 1; + CLEAR = 2; + } + // Represents the schema registry names. If a schema registry doesn't support multiple // registries this field is ignored. The default value represents the default registry. string registry_name = 1; @@ -39,10 +44,13 @@ message SubmitSchemaRequest { // bytes instead repeated bytes file_descriptor_proto = 2; + MergeStrategy merge_strategy = 9; + oneof entity_scope { string package_name = 3; string package_prefix = 4; string file_name = 5; + FileGroup file_group = 8; } string validation_profile = 6; @@ -80,131 +88,3 @@ message GetSchemaResponse { repeated bytes file_descriptor_proto = 1; int32 error_code = 2; } - -message ResourceBinding { - // - // * googlecloud://bigquery.googleapis.com/projects/projectId/datasets/datasetId/tables/tableId - // * googlecloud://pubsub.googleapis.com/projects/projectId/datasets/datasetId/tables/tableId - // * (http/https)://hostname// - string linked_resource = 1; - oneof type { - string message_name = 2; - string service_name = 3; - } -} -message CreateResourceBindingRequest { - string registry_name = 1; - ResourceBinding binding = 2; -} - -message CreateResourceBindingResponse { -} - -message UpdateResourceBindingRequest { - string registry_name = 1; - ResourceBinding binding = 2; -} - -message UpdateResourceBindingResponse { -} - -message DeleteResourceBindingRequest { - string registry_name = 1; - // - // * googlecloud://bigquery.googleapis.com/projects/projectId/datasets/datasetId/tables/tableId - // * googlecloud://pubsub.googleapis.com/projects/projectId/datasets/datasetId/tables/tableId - // * (http/https)://hostname/ - string linked_resource = 2; -} - -message DeleteResourceBindingResponse { -} - - -message GetResourceBindingeRequest { - enum SchemaContext { - SCHEMA_CONTEXT_NONE = 0; - SCHEMA_CONTEXT_IN_FILE = 1; - SCHEMA_CONTEXT_IN_SCOPE = 2; - SCHEMA_CONTEXT_FULL_DOMAIN = 3; - } - - string registry_name = 1; - string linked_resource = 2; - SchemaContext schema_context = 3; -} - -message GetResourceBindingResponse { - string file_name = 1; - string package_name = 2; - ResourceBinding binding = 3; - // These are proto2 type google.protobuf.FileDescriptorProto, but - // we avoid taking a dependency on descriptor.proto, which uses - // proto2 only features, by making them opaque - // bytes instead - repeated bytes file_descriptor_proto = 4; -} - -message ListResourceBindingsRequest { - string registry_name = 1; - // Maximum number of subscription names to return. - int32 page_size = 2; - - // The value returned by the last `ListResourceBindingsRequest`; indicates - // that this is a continuation of a prior `ListResourceBindingsRequest` call, and - // that the system should return the next page of data. - string page_token = 3; -} - -message ListResourceBindingsResponse { - repeated ResourceBinding bindings = 1; - string next_page_token = 2; -} - -message UseResourceRequest { - enum Purpose { - PURPOSE_UNSET = 0; - PURPOSE_PRODUCER = 1; - PURPOSE_CONSUMER = 2; - PURPOSE_API_SERVER = 3; - PURPOSE_API_CLIENT = 4; - } - - message Metrics { - int64 data_bytes = 1; - int64 data_messages = 2; - int64 data_errors = 3; - } - - message Usage { - string usage_name = 1; - oneof entity_scope { - string linked_resource = 2; - string package_name = 3; - string package_prefix = 4; - string message_name = 5; - string service_name = 6; - string enum_name = 7; - string file_name = 8; - } - Purpose purpose = 9; - google.protobuf.Timestamp since = 10; - Metrics metrics = 11; - } - - string registry_name = 2; - string name = 3; - string instance = 4; - map labels = 5; - - // These are proto2 type google.protobuf.FileDescriptorProto, but - // we avoid taking a dependency on descriptor.proto, which uses - // proto2 only features, by making them opaque - // bytes instead - repeated bytes file_descriptor_proto = 6; - - repeated Usage usage = 7; -} - -message UseResourceResponse { -} diff --git a/server/src/main/java/io/anemos/metastore/BindService.java b/server/src/main/java/io/anemos/metastore/BindService.java new file mode 100644 index 0000000..0862f56 --- /dev/null +++ b/server/src/main/java/io/anemos/metastore/BindService.java @@ -0,0 +1,164 @@ +package io.anemos.metastore; + +import static io.anemos.metastore.v1alpha1.BindP.GetResourceBindingeRequest.SchemaContext; + +import com.google.protobuf.Descriptors; +import io.anemos.metastore.core.registry.AbstractRegistry; +import io.anemos.metastore.putils.ProtoDomain; +import io.anemos.metastore.v1alpha1.BindGrpc; +import io.anemos.metastore.v1alpha1.BindP; +import io.grpc.Status; +import io.grpc.StatusException; +import io.grpc.stub.StreamObserver; +import io.opencensus.stats.Measure; +import io.opencensus.stats.Stats; +import io.opencensus.stats.StatsRecorder; +import java.util.ArrayList; +import java.util.Collection; +import java.util.stream.Collectors; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class BindService extends BindGrpc.BindImplBase { + private static final Logger LOG = LoggerFactory.getLogger(BindService.class); + + private static final Measure.MeasureLong GET_FDS = + Measure.MeasureLong.create( + "get_schema_file_descriptors_count", "The number of file descriptors returned", "1"); + private static final StatsRecorder STATS_RECORDER = Stats.getStatsRecorder(); + + private MetaStore metaStore; + + public BindService(MetaStore metaStore) { + + this.metaStore = metaStore; + } + + @Override + public void createResourceBinding( + BindP.CreateResourceBindingRequest request, + StreamObserver responseObserver) { + try { + AbstractRegistry registry = metaStore.registries.get(request.getRegistryName()); + BindP.ResourceBinding resourceBinding = request.getBinding(); + registry.updateResourceBinding(resourceBinding, true); + responseObserver.onNext(BindP.CreateResourceBindingResponse.newBuilder().build()); + responseObserver.onCompleted(); + } catch (StatusException e) { + responseObserver.onError(e); + } + } + + @Override + public void updateResourceBinding( + BindP.UpdateResourceBindingRequest request, + StreamObserver responseObserver) { + try { + AbstractRegistry registry = metaStore.registries.get(request.getRegistryName()); + BindP.ResourceBinding resourceBinding = request.getBinding(); + registry.updateResourceBinding(resourceBinding, false); + responseObserver.onNext(BindP.UpdateResourceBindingResponse.newBuilder().build()); + responseObserver.onCompleted(); + } catch (StatusException e) { + responseObserver.onError(e); + } + } + + @Override + public void getResourceBinding( + BindP.GetResourceBindingeRequest request, + StreamObserver responseObserver) { + try { + AbstractRegistry registry = metaStore.registries.get(request.getRegistryName()); + BindP.ResourceBinding resourceBinding = + registry.getResourceBinding(request.getLinkedResource()); + + BindP.GetResourceBindingResponse.Builder response = + BindP.GetResourceBindingResponse.newBuilder().setBinding(resourceBinding); + + ProtoDomain pContainer = registry.get(); + if (request.getSchemaContext() == SchemaContext.SCHEMA_CONTEXT_FULL_DOMAIN) { + response.addAllFileDescriptorProto( + pContainer.getFileDescriptors().stream() + .map(fd -> fd.toProto().toByteString()) + .collect(Collectors.toList())); + } else if (request.getSchemaContext() == SchemaContext.SCHEMA_CONTEXT_IN_SCOPE) { + Collection fds = new ArrayList<>(); + switch (resourceBinding.getTypeCase().getNumber()) { + case BindP.ResourceBinding.MESSAGE_NAME_FIELD_NUMBER: + Descriptors.Descriptor descriptor = + pContainer.getDescriptorByName(resourceBinding.getMessageName()); + fds = pContainer.getDependantFileDescriptors(descriptor.getFile()); + break; + case BindP.ResourceBinding.SERVICE_NAME_FIELD_NUMBER: + Descriptors.ServiceDescriptor service = + pContainer.getServiceDescriptorByName(resourceBinding.getServiceName()); + fds = pContainer.getDependantFileDescriptors(service.getFile()); + break; + default: + throw Status.fromCode(Status.Code.INTERNAL) + .withDescription("Linked resource isn't linked to a descriptor") + .asRuntimeException(); + } + response.addAllFileDescriptorProto( + fds.stream().map(fd -> fd.toProto().toByteString()).collect(Collectors.toList())); + } else if (request.getSchemaContext() == SchemaContext.SCHEMA_CONTEXT_IN_FILE) { + switch (resourceBinding.getTypeCase().getNumber()) { + case BindP.ResourceBinding.MESSAGE_NAME_FIELD_NUMBER: + Descriptors.Descriptor descriptor = + pContainer.getDescriptorByName(resourceBinding.getMessageName()); + response.addFileDescriptorProto(descriptor.getFile().toProto().toByteString()); + break; + case BindP.ResourceBinding.SERVICE_NAME_FIELD_NUMBER: + Descriptors.ServiceDescriptor service = + pContainer.getServiceDescriptorByName(resourceBinding.getServiceName()); + response.addFileDescriptorProto(service.getFile().toProto().toByteString()); + break; + default: + throw Status.fromCode(Status.Code.INTERNAL) + .withDescription("Linked resource isn't linked to a descriptor") + .asRuntimeException(); + } + } + responseObserver.onNext(response.build()); + responseObserver.onCompleted(); + } catch (StatusException e) { + responseObserver.onError(e); + } + } + + @Override + public void deleteResourceBinding( + BindP.DeleteResourceBindingRequest request, + StreamObserver responseObserver) { + try { + AbstractRegistry registry = metaStore.registries.get(request.getRegistryName()); + registry.deleteResourceBinding(request.getLinkedResource()); + responseObserver.onNext(BindP.DeleteResourceBindingResponse.newBuilder().build()); + responseObserver.onCompleted(); + } catch (StatusException e) { + responseObserver.onError(e); + } + } + + @Override + public void listResourceBindings( + BindP.ListResourceBindingsRequest request, + StreamObserver responseObserver) { + try { + AbstractRegistry registry = metaStore.registries.get(request.getRegistryName()); + BindP.ListResourceBindingsResponse.Builder builder = + BindP.ListResourceBindingsResponse.newBuilder(); + registry + .listResourceBindings(request.getPageToken()) + .forEach( + binding -> { + builder.addBindings(binding); + }); + responseObserver.onNext(builder.build()); + responseObserver.onCompleted(); + } catch (StatusException e) { + responseObserver.onError(e); + } + } +} diff --git a/server/src/main/java/io/anemos/metastore/MetaStoreServer.java b/server/src/main/java/io/anemos/metastore/MetaStoreServer.java index c428638..3a95bb0 100644 --- a/server/src/main/java/io/anemos/metastore/MetaStoreServer.java +++ b/server/src/main/java/io/anemos/metastore/MetaStoreServer.java @@ -37,6 +37,7 @@ private MetaStoreServer(String configPath, ServerBuilder serverBuilder, int p serverBuilder .addService(new MetaStoreService(metaStore)) .addService(new RegistryService(metaStore)) + .addService(new BindService(metaStore)) .addService(ProtoReflectionService.newInstance()) .build(); } diff --git a/server/src/main/java/io/anemos/metastore/RegistryService.java b/server/src/main/java/io/anemos/metastore/RegistryService.java index 842668e..a9339d9 100644 --- a/server/src/main/java/io/anemos/metastore/RegistryService.java +++ b/server/src/main/java/io/anemos/metastore/RegistryService.java @@ -1,7 +1,5 @@ package io.anemos.metastore; -import static io.anemos.metastore.v1alpha1.RegistryP.GetResourceBindingeRequest.SchemaContext; - import com.google.protobuf.Descriptors; import io.anemos.metastore.core.proto.profile.*; import io.anemos.metastore.core.proto.validate.ProtoDiff; @@ -9,6 +7,7 @@ import io.anemos.metastore.core.proto.validate.ValidationResults; import io.anemos.metastore.core.registry.AbstractRegistry; import io.anemos.metastore.putils.ProtoDomain; +import io.anemos.metastore.v1alpha1.BindP; import io.anemos.metastore.v1alpha1.RegistryGrpc; import io.anemos.metastore.v1alpha1.RegistryP; import io.anemos.metastore.v1alpha1.Report; @@ -21,7 +20,6 @@ import io.opencensus.stats.StatsRecorder; import java.io.IOException; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.stream.Collectors; import org.slf4j.Logger; @@ -265,7 +263,7 @@ public void getSchema( } break; case LINKED_RESOURCE: - RegistryP.ResourceBinding resourceBinding = + BindP.ResourceBinding resourceBinding = registry.getResourceBinding(request.getLinkedResource()); switch (resourceBinding.getTypeCase()) { case MESSAGE_NAME: @@ -323,132 +321,4 @@ public void getSchema( responseObserver.onError(e); } } - - @Override - public void createResourceBinding( - RegistryP.CreateResourceBindingRequest request, - StreamObserver responseObserver) { - try { - AbstractRegistry registry = metaStore.registries.get(request.getRegistryName()); - RegistryP.ResourceBinding resourceBinding = request.getBinding(); - registry.updateResourceBinding(resourceBinding, true); - responseObserver.onNext(RegistryP.CreateResourceBindingResponse.newBuilder().build()); - responseObserver.onCompleted(); - } catch (StatusException e) { - responseObserver.onError(e); - } - } - - @Override - public void updateResourceBinding( - RegistryP.UpdateResourceBindingRequest request, - StreamObserver responseObserver) { - try { - AbstractRegistry registry = metaStore.registries.get(request.getRegistryName()); - RegistryP.ResourceBinding resourceBinding = request.getBinding(); - registry.updateResourceBinding(resourceBinding, false); - responseObserver.onNext(RegistryP.UpdateResourceBindingResponse.newBuilder().build()); - responseObserver.onCompleted(); - } catch (StatusException e) { - responseObserver.onError(e); - } - } - - @Override - public void getResourceBinding( - RegistryP.GetResourceBindingeRequest request, - StreamObserver responseObserver) { - try { - AbstractRegistry registry = metaStore.registries.get(request.getRegistryName()); - RegistryP.ResourceBinding resourceBinding = - registry.getResourceBinding(request.getLinkedResource()); - - RegistryP.GetResourceBindingResponse.Builder response = - RegistryP.GetResourceBindingResponse.newBuilder().setBinding(resourceBinding); - - ProtoDomain pContainer = registry.get(); - if (request.getSchemaContext() == SchemaContext.SCHEMA_CONTEXT_FULL_DOMAIN) { - response.addAllFileDescriptorProto( - pContainer.getFileDescriptors().stream() - .map(fd -> fd.toProto().toByteString()) - .collect(Collectors.toList())); - } else if (request.getSchemaContext() == SchemaContext.SCHEMA_CONTEXT_IN_SCOPE) { - Collection fds = new ArrayList<>(); - switch (resourceBinding.getTypeCase().getNumber()) { - case RegistryP.ResourceBinding.MESSAGE_NAME_FIELD_NUMBER: - Descriptors.Descriptor descriptor = - pContainer.getDescriptorByName(resourceBinding.getMessageName()); - fds = pContainer.getDependantFileDescriptors(descriptor.getFile()); - break; - case RegistryP.ResourceBinding.SERVICE_NAME_FIELD_NUMBER: - Descriptors.ServiceDescriptor service = - pContainer.getServiceDescriptorByName(resourceBinding.getServiceName()); - fds = pContainer.getDependantFileDescriptors(service.getFile()); - break; - default: - throw Status.fromCode(Status.Code.INTERNAL) - .withDescription("Linked resource isn't linked to a descriptor") - .asRuntimeException(); - } - response.addAllFileDescriptorProto( - fds.stream().map(fd -> fd.toProto().toByteString()).collect(Collectors.toList())); - } else if (request.getSchemaContext() == SchemaContext.SCHEMA_CONTEXT_IN_FILE) { - switch (resourceBinding.getTypeCase().getNumber()) { - case RegistryP.ResourceBinding.MESSAGE_NAME_FIELD_NUMBER: - Descriptors.Descriptor descriptor = - pContainer.getDescriptorByName(resourceBinding.getMessageName()); - response.addFileDescriptorProto(descriptor.getFile().toProto().toByteString()); - break; - case RegistryP.ResourceBinding.SERVICE_NAME_FIELD_NUMBER: - Descriptors.ServiceDescriptor service = - pContainer.getServiceDescriptorByName(resourceBinding.getServiceName()); - response.addFileDescriptorProto(service.getFile().toProto().toByteString()); - break; - default: - throw Status.fromCode(Status.Code.INTERNAL) - .withDescription("Linked resource isn't linked to a descriptor") - .asRuntimeException(); - } - } - responseObserver.onNext(response.build()); - responseObserver.onCompleted(); - } catch (StatusException e) { - responseObserver.onError(e); - } - } - - @Override - public void deleteResourceBinding( - RegistryP.DeleteResourceBindingRequest request, - StreamObserver responseObserver) { - try { - AbstractRegistry registry = metaStore.registries.get(request.getRegistryName()); - registry.deleteResourceBinding(request.getLinkedResource()); - responseObserver.onNext(RegistryP.DeleteResourceBindingResponse.newBuilder().build()); - responseObserver.onCompleted(); - } catch (StatusException e) { - responseObserver.onError(e); - } - } - - @Override - public void listResourceBindings( - RegistryP.ListResourceBindingsRequest request, - StreamObserver responseObserver) { - try { - AbstractRegistry registry = metaStore.registries.get(request.getRegistryName()); - RegistryP.ListResourceBindingsResponse.Builder builder = - RegistryP.ListResourceBindingsResponse.newBuilder(); - registry - .listResourceBindings(request.getPageToken()) - .forEach( - binding -> { - builder.addBindings(binding); - }); - responseObserver.onNext(builder.build()); - responseObserver.onCompleted(); - } catch (StatusException e) { - responseObserver.onError(e); - } - } } From 8c468c94f4c9823da2e206d94a1655bb26d4cac7 Mon Sep 17 00:00:00 2001 From: Alex Van Boxel Date: Fri, 10 Apr 2020 15:05:47 +0200 Subject: [PATCH 03/11] Split Report into Report and Patch --- .../proto/profile/ProfileAllowAddBase.java | 9 ++- .../core/proto/profile/ProfileAllowAll.java | 5 +- .../core/proto/profile/ProfileAllowNone.java | 5 +- .../proto/profile/ProfileProtoEvolve.java | 3 +- .../core/proto/profile/ValidationProfile.java | 3 +- .../proto/validate/ValidationResults.java | 4 +- .../metastore/core/registry/ShadowApply.java | 18 ++--- .../core/registry/ShadowRegistry.java | 13 ++-- .../core/proto/profile/ProfileTest.java | 27 +++---- .../core/proto/validation/DiffTest.java | 24 +++--- .../core/proto/validation/LintTest.java | 38 +++++----- .../core/proto/validation/OptionDiffTest.java | 6 +- .../core/proto/validation/ProtoDiffTest.java | 76 +++++++++---------- .../metastore/core/registry/ShadowTest.java | 10 +-- .../proto/grpc/registry/v1alpha1/patch.proto | 7 +- .../metastore/server/ShadowE2ETest.java | 7 +- 16 files changed, 133 insertions(+), 122 deletions(-) diff --git a/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowAddBase.java b/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowAddBase.java index b491637..57d7eaa 100644 --- a/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowAddBase.java +++ b/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowAddBase.java @@ -24,12 +24,13 @@ private boolean skipValidationForAlpha(String packageName) { } @Override - public Report validate(Report report) { + public Report validate(Patch patch) { ResultCount.Builder resultCountBuilder = ResultCount.newBuilder(); - Report.Builder builder = Report.newBuilder(report); + Report.Builder builder = Report.newBuilder(); + builder.setPatch(patch); int error = 0; - for (MessageResult messageResult : builder.getMessageResultsMap().values()) { + for (MessageResult messageResult : patch.getMessageResultsMap().values()) { if (skipValidationForAlpha(messageResult.getPackage())) { continue; } @@ -103,7 +104,7 @@ public Report validate(Report report) { } } } - for (EnumResult enumResult : builder.getEnumResultsMap().values()) { + for (EnumResult enumResult : patch.getEnumResultsMap().values()) { if (skipValidationForAlpha(enumResult.getPackage())) { continue; } diff --git a/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowAll.java b/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowAll.java index 4ea9956..8cbcda0 100644 --- a/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowAll.java +++ b/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowAll.java @@ -1,5 +1,6 @@ package io.anemos.metastore.core.proto.profile; +import io.anemos.metastore.v1alpha1.Patch; import io.anemos.metastore.v1alpha1.Report; public class ProfileAllowAll implements ValidationProfile { @@ -7,7 +8,7 @@ public class ProfileAllowAll implements ValidationProfile { public String profileName = "proto:allow"; @Override - public Report validate(Report report) { - return report; + public Report validate(Patch patch) { + return Report.newBuilder().setPatch(patch).build(); } } diff --git a/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowNone.java b/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowNone.java index 9335f0b..940c909 100644 --- a/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowNone.java +++ b/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowNone.java @@ -1,5 +1,6 @@ package io.anemos.metastore.core.proto.profile; +import io.anemos.metastore.v1alpha1.Patch; import io.anemos.metastore.v1alpha1.Report; public class ProfileAllowNone implements ValidationProfile { @@ -8,7 +9,7 @@ public class ProfileAllowNone implements ValidationProfile { // TODO implement @Override - public Report validate(Report report) { - return report; + public Report validate(Patch patch) { + return Report.newBuilder().setPatch(patch).build(); } } diff --git a/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileProtoEvolve.java b/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileProtoEvolve.java index 99a4244..2dbc936 100644 --- a/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileProtoEvolve.java +++ b/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileProtoEvolve.java @@ -1,5 +1,6 @@ package io.anemos.metastore.core.proto.profile; +import io.anemos.metastore.v1alpha1.Patch; import io.anemos.metastore.v1alpha1.Report; public class ProfileProtoEvolve implements ValidationProfile { @@ -7,7 +8,7 @@ public class ProfileProtoEvolve implements ValidationProfile { public String profileName = "proto:default"; @Override - public Report validate(Report report) { + public Report validate(Patch patch) { return null; } } diff --git a/core/src/main/java/io/anemos/metastore/core/proto/profile/ValidationProfile.java b/core/src/main/java/io/anemos/metastore/core/proto/profile/ValidationProfile.java index 00fbeeb..0230488 100644 --- a/core/src/main/java/io/anemos/metastore/core/proto/profile/ValidationProfile.java +++ b/core/src/main/java/io/anemos/metastore/core/proto/profile/ValidationProfile.java @@ -1,8 +1,9 @@ package io.anemos.metastore.core.proto.profile; +import io.anemos.metastore.v1alpha1.Patch; import io.anemos.metastore.v1alpha1.Report; public interface ValidationProfile { - Report validate(Report report); + Report validate(Patch patch); } diff --git a/core/src/main/java/io/anemos/metastore/core/proto/validate/ValidationResults.java b/core/src/main/java/io/anemos/metastore/core/proto/validate/ValidationResults.java index d7b7110..127bece 100644 --- a/core/src/main/java/io/anemos/metastore/core/proto/validate/ValidationResults.java +++ b/core/src/main/java/io/anemos/metastore/core/proto/validate/ValidationResults.java @@ -156,8 +156,8 @@ void addImportChange(String fullName, ImportChangeInfo info) { fileResultContainer.addImportChange(info); } - public Report createProto() { - Report.Builder builder = Report.newBuilder(); + public Patch createProto() { + Patch.Builder builder = Patch.newBuilder(); fileMap.values().forEach(file -> builder.putFileResults(file.fullName, file.createProto())); messageMap .values() diff --git a/core/src/main/java/io/anemos/metastore/core/registry/ShadowApply.java b/core/src/main/java/io/anemos/metastore/core/registry/ShadowApply.java index 6196209..a496def 100644 --- a/core/src/main/java/io/anemos/metastore/core/registry/ShadowApply.java +++ b/core/src/main/java/io/anemos/metastore/core/registry/ShadowApply.java @@ -10,7 +10,7 @@ import io.anemos.metastore.v1alpha1.ImportChangeInfo; import io.anemos.metastore.v1alpha1.MessageResult; import io.anemos.metastore.v1alpha1.OptionChangeInfo; -import io.anemos.metastore.v1alpha1.Report; +import io.anemos.metastore.v1alpha1.Patch; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -22,14 +22,14 @@ class ShadowApply { private ProtoDomain shadow; - public ProtoDomain applyDelta(ProtoDomain defaultDescriptor, Report delta) { + public ProtoDomain applyDelta(ProtoDomain defaultDescriptor, Patch patch) { try { shadow = defaultDescriptor; HashMap fileDescriptorProtoBuilders = new HashMap<>(); - applyMessageResults(delta, fileDescriptorProtoBuilders); - applyFileResults(delta, fileDescriptorProtoBuilders); + applyMessageResults(patch, fileDescriptorProtoBuilders); + applyFileResults(patch, fileDescriptorProtoBuilders); List fileDescriptorProtos = new ArrayList<>(); fileDescriptorProtoBuilders.forEach( (name, fd) -> { @@ -37,14 +37,14 @@ public ProtoDomain applyDelta(ProtoDomain defaultDescriptor, Report delta) { }); return shadow.toBuilder().merge(fileDescriptorProtos).build(); } catch (Exception e) { - throw new RuntimeException("Failed to apply delta", e); + throw new RuntimeException("Failed to apply patch", e); } } private void applyFileResults( - Report delta, + Patch patch, HashMap fileDescriptorProtoBuilders) { - for (Map.Entry fileResultEntry : delta.getFileResultsMap().entrySet()) { + for (Map.Entry fileResultEntry : patch.getFileResultsMap().entrySet()) { Descriptors.FileDescriptor fileDescriptor = shadow.getFileDescriptorByFileName(fileResultEntry.getKey()); @@ -61,10 +61,10 @@ private void applyFileResults( } private void applyMessageResults( - Report delta, + Patch patch, HashMap fileDescriptorProtoBuilders) { for (Map.Entry messageResultEntry : - delta.getMessageResultsMap().entrySet()) { + patch.getMessageResultsMap().entrySet()) { Descriptors.Descriptor descriptor = shadow.getDescriptorByName(messageResultEntry.getKey()); HashMap messageNameToIndexMap = getMessageNameToIndexMap(descriptor.getFile()); diff --git a/core/src/main/java/io/anemos/metastore/core/registry/ShadowRegistry.java b/core/src/main/java/io/anemos/metastore/core/registry/ShadowRegistry.java index b74a2e0..114d0da 100644 --- a/core/src/main/java/io/anemos/metastore/core/registry/ShadowRegistry.java +++ b/core/src/main/java/io/anemos/metastore/core/registry/ShadowRegistry.java @@ -6,13 +6,14 @@ import io.anemos.metastore.core.proto.validate.ValidationResults; import io.anemos.metastore.provider.StorageProvider; import io.anemos.metastore.putils.ProtoDomain; +import io.anemos.metastore.v1alpha1.Patch; import io.anemos.metastore.v1alpha1.RegistryP.SubmitSchemaRequest.Comment; import io.anemos.metastore.v1alpha1.Report; import io.grpc.StatusException; import java.io.IOException; class ShadowRegistry extends AbstractRegistry { - private Report delta; + private Patch patch; private String shadowOf; public ShadowRegistry(Registries registries, RegistryConfig registryConfig) { @@ -39,13 +40,13 @@ private void updateShadowCache() { } catch (StatusException e) { throw new RuntimeException("Unable to find registry with name " + shadowOf); } - protoContainer = new ShadowApply().applyDelta(original, this.delta); + protoContainer = new ShadowApply().applyDelta(original, this.patch); protoContainer.registerOptions(); } @Override public ByteString raw() { - return delta.toByteString(); + return patch.toByteString(); } @Override @@ -73,7 +74,7 @@ public void update(ProtoDomain ref, ProtoDomain in, Report report, Comment comme } else { throw new RuntimeException("Shadow registry should have package prefix scopes defined."); } - delta = results.createProto(); + patch = results.createProto(); update(comment); notifyEventListeners(report); } @@ -101,10 +102,10 @@ private boolean read() { try { ByteString buffer = storageProviders.get(0).read(); if (buffer == null) { - delta = Report.parseFrom(ByteString.EMPTY); + patch = Patch.parseFrom(ByteString.EMPTY); return true; } else { - delta = Report.parseFrom(buffer); + patch = Patch.parseFrom(buffer); return false; } } catch (IOException e) { diff --git a/core/src/test/java/io/anemos/metastore/core/proto/profile/ProfileTest.java b/core/src/test/java/io/anemos/metastore/core/proto/profile/ProfileTest.java index 082d603..cea9b75 100644 --- a/core/src/test/java/io/anemos/metastore/core/proto/profile/ProfileTest.java +++ b/core/src/test/java/io/anemos/metastore/core/proto/profile/ProfileTest.java @@ -8,6 +8,7 @@ import io.anemos.metastore.core.proto.validate.ProtoDiff; import io.anemos.metastore.core.proto.validate.ValidationResults; import io.anemos.metastore.putils.ProtoDomain; +import io.anemos.metastore.v1alpha1.Patch; import io.anemos.metastore.v1alpha1.Report; import java.io.IOException; import org.junit.Test; @@ -24,9 +25,9 @@ public void profileAllowAdd_RemoveFieldV1() throws Exception { .build(); ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); - Report report = diff(dRef, dNew); - report = new ProfileAllowAdd().validate(report); - assertEquals(1, report.getMessageResultsCount()); + Patch patch = diff(dRef, dNew); + Report report = new ProfileAllowAdd().validate(patch); + assertEquals(1, report.getPatch().getMessageResultsCount()); assertEquals(1, report.getResultCount().getDiffErrors()); } @@ -40,9 +41,9 @@ public void profileAllowAdd_RemoveFieldV1Alpha() throws Exception { .build(); ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); - Report report = diff(dRef, dNew); - report = new ProfileAllowAdd().validate(report); - assertEquals(1, report.getMessageResultsCount()); + Patch patch = diff(dRef, dNew); + Report report = new ProfileAllowAdd().validate(patch); + assertEquals(1, report.getPatch().getMessageResultsCount()); assertEquals(1, report.getResultCount().getDiffErrors()); } @@ -56,9 +57,9 @@ public void profileAllowStableAddAddAlpha_RemoveFieldV1() throws Exception { .build(); ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); - Report report = diff(dRef, dNew); - report = new ProfileAllowStableAddAlphaAll().validate(report); - assertEquals(1, report.getMessageResultsCount()); + Patch patch = diff(dRef, dNew); + Report report = new ProfileAllowStableAddAlphaAll().validate(patch); + assertEquals(1, report.getPatch().getMessageResultsCount()); assertEquals(1, report.getResultCount().getDiffErrors()); } @@ -72,13 +73,13 @@ public void profileAllowStableAddAddAlpha_RemoveFieldV1Alpha() throws Exception .build(); ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); - Report report = diff(dRef, dNew); - report = new ProfileAllowStableAddAlphaAll().validate(report); - assertEquals(1, report.getMessageResultsCount()); + Patch patch = diff(dRef, dNew); + Report report = new ProfileAllowStableAddAlphaAll().validate(patch); + assertEquals(1, report.getPatch().getMessageResultsCount()); assertEquals(0, report.getResultCount().getDiffErrors()); } - private Report diff(ProtoDomain dRef, ProtoDomain dNew) throws IOException { + private Patch diff(ProtoDomain dRef, ProtoDomain dNew) throws IOException { ValidationResults results = new ValidationResults(); ProtoDiff diff = new ProtoDiff(dRef, dNew, results); diff.diffOnPackagePrefix("package.v1"); diff --git a/core/src/test/java/io/anemos/metastore/core/proto/validation/DiffTest.java b/core/src/test/java/io/anemos/metastore/core/proto/validation/DiffTest.java index 8bab511..86a1228 100644 --- a/core/src/test/java/io/anemos/metastore/core/proto/validation/DiffTest.java +++ b/core/src/test/java/io/anemos/metastore/core/proto/validation/DiffTest.java @@ -160,32 +160,32 @@ public void toBaseUnreserveStringOnlyNumber() throws IOException { @Test public void toBaseExtraFileAdded() throws IOException { - Report report = diffOnPackage(TestSets.base(), TestSets.baseExtraFile()); + Patch patch = diffOnPackage(TestSets.base(), TestSets.baseExtraFile()); - Assert.assertEquals(1, report.getFileResultsCount()); + Assert.assertEquals(1, patch.getFileResultsCount()); Assert.assertEquals( ChangeType.ADDITION, - report.getFileResultsOrThrow("test/v1/extra.proto").getChange().getChangeType()); + patch.getFileResultsOrThrow("test/v1/extra.proto").getChange().getChangeType()); - Assert.assertEquals(1, report.getMessageResultsCount()); + Assert.assertEquals(1, patch.getMessageResultsCount()); Assert.assertEquals( ChangeType.ADDITION, - report.getMessageResultsOrThrow("test.v1.ProtoExtraMessage").getChange().getChangeType()); + patch.getMessageResultsOrThrow("test.v1.ProtoExtraMessage").getChange().getChangeType()); } @Test public void toBaseExtraFileRemoved() throws IOException { - Report report = diffOnPackage(TestSets.baseExtraFile(), TestSets.base()); + Patch patch = diffOnPackage(TestSets.baseExtraFile(), TestSets.base()); - Assert.assertEquals(1, report.getFileResultsCount()); + Assert.assertEquals(1, patch.getFileResultsCount()); Assert.assertEquals( ChangeType.REMOVAL, - report.getFileResultsOrThrow("test/v1/extra.proto").getChange().getChangeType()); + patch.getFileResultsOrThrow("test/v1/extra.proto").getChange().getChangeType()); - Assert.assertEquals(1, report.getMessageResultsCount()); + Assert.assertEquals(1, patch.getMessageResultsCount()); Assert.assertEquals( ChangeType.REMOVAL, - report.getMessageResultsOrThrow("test.v1.ProtoExtraMessage").getChange().getChangeType()); + patch.getMessageResultsOrThrow("test.v1.ProtoExtraMessage").getChange().getChangeType()); } private FieldResult diff(ProtoDomain dRef, ProtoDomain dNew) throws IOException { @@ -193,12 +193,12 @@ private FieldResult diff(ProtoDomain dRef, ProtoDomain dNew) throws IOException ProtoDiff diff = new ProtoDiff(dRef, dNew, results); diff.diffOnMessage("test.v1.ProtoBeamBasicMessage"); - Report result = results.createProto(); + Patch result = results.createProto(); System.out.println(result); return result.getMessageResultsMap().get("test.v1.ProtoBeamBasicMessage").getFieldResults(0); } - private Report diffOnPackage(ProtoDomain dRef, ProtoDomain dNew) throws IOException { + private Patch diffOnPackage(ProtoDomain dRef, ProtoDomain dNew) throws IOException { ValidationResults results = new ValidationResults(); ProtoDiff diff = new ProtoDiff(dRef, dNew, results); diff.diffOnPackagePrefix("test.v1"); diff --git a/core/src/test/java/io/anemos/metastore/core/proto/validation/LintTest.java b/core/src/test/java/io/anemos/metastore/core/proto/validation/LintTest.java index 1360221..baf8b9a 100644 --- a/core/src/test/java/io/anemos/metastore/core/proto/validation/LintTest.java +++ b/core/src/test/java/io/anemos/metastore/core/proto/validation/LintTest.java @@ -20,13 +20,13 @@ public class LintTest { @Test public void fieldOkSnakeCase() throws IOException { - Report result = lintMessage(Lint.LintFieldNamesGood.getDescriptor()); + Patch result = lintMessage(Lint.LintFieldNamesGood.getDescriptor()); Assert.assertEquals(0, result.getMessageResultsCount()); } @Test public void fieldNokCamel() throws IOException { - Report result = lintMessage(Lint.LintFieldNamesBad.getDescriptor()); + Patch result = lintMessage(Lint.LintFieldNamesBad.getDescriptor()); Assert.assertEquals(1, result.getMessageResultsCount()); MessageResult mr = result.getMessageResultsOrThrow("anemos.metastore.core.LintFieldNamesBad"); @@ -37,7 +37,7 @@ public void fieldNokCamel() throws IOException { @Test public void messageLowerCase() throws IOException { - Report result = lintMessage(Lint.lintmessagelowercase.getDescriptor()); + Patch result = lintMessage(Lint.lintmessagelowercase.getDescriptor()); Assert.assertEquals(1, result.getMessageResultsCount()); MessageResult mr = @@ -47,7 +47,7 @@ public void messageLowerCase() throws IOException { @Test public void messageCamelCase() throws IOException { - Report result = lintMessage(Lint.lint_message_camelcase.getDescriptor()); + Patch result = lintMessage(Lint.lint_message_camelcase.getDescriptor()); Assert.assertEquals(1, result.getMessageResultsCount()); MessageResult mr = @@ -57,7 +57,7 @@ public void messageCamelCase() throws IOException { @Test public void methodInputAndReturnTypeNoRR() throws IOException { - Report result = + Patch result = lintService(Lint.LintFieldNamesGood.getDescriptor(), "anemos.metastore.core.MethodService"); ServiceResult mr = result.getServiceResultsOrThrow("anemos.metastore.core.MethodService"); @@ -68,7 +68,7 @@ public void methodInputAndReturnTypeNoRR() throws IOException { @Test public void methodInputTypeNoR() throws IOException { - Report result = + Patch result = lintService(Lint.LintFieldNamesGood.getDescriptor(), "anemos.metastore.core.MethodService"); ServiceResult mr = result.getServiceResultsOrThrow("anemos.metastore.core.MethodService"); @@ -78,7 +78,7 @@ public void methodInputTypeNoR() throws IOException { @Test public void methodReturnTypeNoR() throws IOException { - Report result = + Patch result = lintService(Lint.LintFieldNamesGood.getDescriptor(), "anemos.metastore.core.MethodService"); ServiceResult mr = result.getServiceResultsOrThrow("anemos.metastore.core.MethodService"); @@ -88,14 +88,14 @@ public void methodReturnTypeNoR() throws IOException { @Test public void methodOk() throws IOException { - Report result = + Patch result = lintService(Lint.LintFieldNamesGood.getDescriptor(), "anemos.metastore.core.MethodService"); ServiceResult mr = result.getServiceResultsOrThrow("anemos.metastore.core.MethodService"); Assert.assertNull(getInfoForMethod(mr, "MethodOk")); } - private Report lintMessage(Descriptors.Descriptor d) throws IOException { + private Patch lintMessage(Descriptors.Descriptor d) throws IOException { ProtoDomain pd = ProtoDomain.buildFrom(d); String message = d.getFullName(); @@ -105,7 +105,7 @@ private Report lintMessage(Descriptors.Descriptor d) throws IOException { return results.createProto(); } - private Report lintService(Descriptors.Descriptor ref, String name) throws IOException { + private Patch lintService(Descriptors.Descriptor ref, String name) throws IOException { ProtoDomain pd = ProtoDomain.buildFrom(ref); ValidationResults results = new ValidationResults(); @@ -183,14 +183,14 @@ private void assertOnMessage(MessageResult mr, LintRule expectedRule, String exp @Test public void packageScopeVersionValid() throws IOException { Descriptors.Descriptor descriptor = Lint.LintFieldNamesBad.getDescriptor(); - Report result = lintPackage(descriptor); + Patch result = lintPackage(descriptor); Assert.assertEquals(0, result.getFileResultsCount()); } @Test public void packageScopeVersionInvalid() throws IOException { Descriptors.Descriptor descriptor = Invalid.InvalidMessage.getDescriptor(); - Report result = lintPackage(descriptor); + Patch result = lintPackage(descriptor); FileResult fr = result.getFileResultsOrThrow("anemos/metastore/invalid/invalid.proto"); Assert.assertEquals(1, result.getFileResultsCount()); @@ -211,7 +211,7 @@ private void assertOnFile(FileResult fr, LintRule expectedRule, String expectedC Assert.assertEquals(expectedRule, rule); } - private Report lintPackage(Descriptors.Descriptor ref) throws IOException { + private Patch lintPackage(Descriptors.Descriptor ref) throws IOException { ProtoDomain pd = ProtoDomain.buildFrom(ref); ValidationResults results = new ValidationResults(); @@ -223,14 +223,14 @@ private Report lintPackage(Descriptors.Descriptor ref) throws IOException { @Test public void versionScopeValid() throws IOException { Descriptors.Descriptor descriptor = VersionScopeValid.VersionValid.getDescriptor(); - Report result = lintVersion(descriptor); + Patch result = lintVersion(descriptor); Assert.assertEquals(0, result.getFileResultsCount()); } @Test public void versionScopeInvalid() throws IOException { Descriptors.Descriptor descriptor = VersionScopeInvalid.VersionInValid.getDescriptor(); - Report result = lintVersion(descriptor); + Patch result = lintVersion(descriptor); FileResult fr = result.getFileResultsOrThrow("anemos/metastore/core/test/v1/version_scope_invalid.proto"); @@ -238,7 +238,7 @@ public void versionScopeInvalid() throws IOException { assertOnFile(fr, LintRule.LINT_PACKAGE_NO_VERSION_ALIGNMENT, "L70002/00"); } - private Report lintVersion(Descriptors.Descriptor ref) throws IOException { + private Patch lintVersion(Descriptors.Descriptor ref) throws IOException { ProtoDomain pd = ProtoDomain.buildFrom(ref); ValidationResults results = new ValidationResults(); @@ -250,21 +250,21 @@ private Report lintVersion(Descriptors.Descriptor ref) throws IOException { @Test public void unusedImportValid() throws IOException { Descriptors.Descriptor descriptor = UsedValidImport.Valid.getDescriptor(); - Report result = lintImport(descriptor); + Patch result = lintImport(descriptor); Assert.assertEquals(0, result.getFileResultsCount()); } @Test public void unusedImportInvalid() throws IOException { Descriptors.Descriptor descriptor = UnusedInvalidImport.Invalid.getDescriptor(); - Report result = lintImport(descriptor); + Patch result = lintImport(descriptor); FileResult fr = result.getFileResultsOrThrow("anemos/metastore/unused/invalid/unused_invalid_import.proto"); Assert.assertEquals(1, result.getFileResultsCount()); assertOnFile(fr, LintRule.LINT_IMPORT_NO_ALIGNMENT, "L80001/00"); } - private Report lintImport(Descriptors.Descriptor ref) throws IOException { + private Patch lintImport(Descriptors.Descriptor ref) throws IOException { ProtoDomain pd = ProtoDomain.buildFrom(ref); ValidationResults results = new ValidationResults(); diff --git a/core/src/test/java/io/anemos/metastore/core/proto/validation/OptionDiffTest.java b/core/src/test/java/io/anemos/metastore/core/proto/validation/OptionDiffTest.java index 719862d..6fe1f9c 100644 --- a/core/src/test/java/io/anemos/metastore/core/proto/validation/OptionDiffTest.java +++ b/core/src/test/java/io/anemos/metastore/core/proto/validation/OptionDiffTest.java @@ -9,7 +9,7 @@ import io.anemos.metastore.v1alpha1.FileResult; import io.anemos.metastore.v1alpha1.MessageResult; import io.anemos.metastore.v1alpha1.OptionChangeInfo; -import io.anemos.metastore.v1alpha1.Report; +import io.anemos.metastore.v1alpha1.Patch; import java.io.IOException; import org.junit.Assert; import org.junit.Test; @@ -166,7 +166,7 @@ private MessageResult diffMessage(ProtoDomain dRef, ProtoDomain dNew) throws IOE ProtoDiff diff = new ProtoDiff(dRef, dNew, results); diff.diffOnMessage("test.v1.ProtoBeamBasicMessage"); - Report result = results.createProto(); + Patch result = results.createProto(); System.out.println(result); return result.getMessageResultsMap().get("test.v1.ProtoBeamBasicMessage"); } @@ -176,7 +176,7 @@ private FileResult diffFile(ProtoDomain dRef, ProtoDomain dNew) throws IOExcepti ProtoDiff diff = new ProtoDiff(dRef, dNew, results); diff.diffOnFileName("test/v1/simple.proto"); - Report result = results.createProto(); + Patch result = results.createProto(); System.out.println(result); return result.getFileResultsMap().get("test/v1/simple.proto"); } diff --git a/core/src/test/java/io/anemos/metastore/core/proto/validation/ProtoDiffTest.java b/core/src/test/java/io/anemos/metastore/core/proto/validation/ProtoDiffTest.java index a8e6302..2714fa9 100644 --- a/core/src/test/java/io/anemos/metastore/core/proto/validation/ProtoDiffTest.java +++ b/core/src/test/java/io/anemos/metastore/core/proto/validation/ProtoDiffTest.java @@ -131,7 +131,7 @@ public class ProtoDiffTest { public void noDiff() throws Exception { ProtoDomain dRef = ProtoDomain.builder().add(FILE_V1).build(); ProtoDomain dNew = ProtoDomain.builder().add(FILE_V1).build(); - Report report = diff(dRef, dNew); + Patch patch = diff(dRef, dNew); } @Test @@ -152,8 +152,8 @@ public void addEnum() throws Exception { .build(); ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); - Report report = diff(dRef, dNew); - EnumResult result = report.getEnumResultsMap().get("package.v1.Enum2"); + Patch patch = diff(dRef, dNew); + EnumResult result = patch.getEnumResultsMap().get("package.v1.Enum2"); Assert.assertEquals("package.v1.Enum2", result.getChange().getToName()); Assert.assertEquals(ChangeType.ADDITION, result.getChange().getChangeType()); } @@ -164,8 +164,8 @@ public void removeEnum() throws Exception { DescriptorProtos.FileDescriptorProto fd = FILE_V1.toBuilder().clearEnumType().build(); ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); - Report report = diff(dRef, dNew); - EnumResult result = report.getEnumResultsMap().get("package.v1.Enum1"); + Patch patch = diff(dRef, dNew); + EnumResult result = patch.getEnumResultsMap().get("package.v1.Enum1"); Assert.assertEquals("package.v1.Enum1", result.getChange().getFromName()); Assert.assertEquals(ChangeType.REMOVAL, result.getChange().getChangeType()); } @@ -188,8 +188,8 @@ public void addEnumValue() throws Exception { .build(); ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); - Report report = diff(dRef, dNew); - EnumResult result = report.getEnumResultsMap().get("package.v1.Enum1"); + Patch patch = diff(dRef, dNew); + EnumResult result = patch.getEnumResultsMap().get("package.v1.Enum1"); Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); Assert.assertEquals(ChangeType.ADDITION, result.getValueResults(0).getChange().getChangeType()); Assert.assertEquals(2, result.getValueResults(0).getNumber()); @@ -208,8 +208,8 @@ public void removeEnumValue() throws Exception { .build(); ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); - Report report = diff(dRef, dNew); - EnumResult result = report.getEnumResultsMap().get("package.v1.Enum1"); + Patch patch = diff(dRef, dNew); + EnumResult result = patch.getEnumResultsMap().get("package.v1.Enum1"); Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); Assert.assertEquals(ChangeType.REMOVAL, result.getValueResults(0).getChange().getChangeType()); Assert.assertEquals(1, result.getValueResults(0).getNumber()); @@ -233,8 +233,8 @@ public void renameEnumValue() throws Exception { .build(); ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); - Report report = diff(dRef, dNew); - EnumResult result = report.getEnumResultsMap().get("package.v1.Enum1"); + Patch patch = diff(dRef, dNew); + EnumResult result = patch.getEnumResultsMap().get("package.v1.Enum1"); Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); Assert.assertEquals(ChangeType.CHANGED, result.getValueResults(0).getChange().getChangeType()); Assert.assertEquals(1, result.getValueResults(0).getNumber()); @@ -254,8 +254,8 @@ public void addMessage() throws Exception { .build(); ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); - Report report = diff(dRef, dNew); - MessageResult result = report.getMessageResultsMap().get("package.v1.Message2"); + Patch patch = diff(dRef, dNew); + MessageResult result = patch.getMessageResultsMap().get("package.v1.Message2"); Assert.assertEquals("package.v1.Message2", result.getChange().getToName()); Assert.assertEquals(ChangeType.ADDITION, result.getChange().getChangeType()); } @@ -266,8 +266,8 @@ public void removeMessage() throws Exception { DescriptorProtos.FileDescriptorProto fd = FILE_V1.toBuilder().removeMessageType(0).build(); ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); - Report report = diff(dRef, dNew); - MessageResult result = report.getMessageResultsMap().get("package.v1.Message1"); + Patch patch = diff(dRef, dNew); + MessageResult result = patch.getMessageResultsMap().get("package.v1.Message1"); Assert.assertEquals("package.v1.Message1", result.getChange().getFromName()); Assert.assertEquals(ChangeType.REMOVAL, result.getChange().getChangeType()); } @@ -291,8 +291,8 @@ public void addField() throws Exception { .build(); ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); - Report report = diff(dRef, dNew); - MessageResult result = report.getMessageResultsMap().get("package.v1.Message1"); + Patch patch = diff(dRef, dNew); + MessageResult result = patch.getMessageResultsMap().get("package.v1.Message1"); Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); Assert.assertEquals(ChangeType.ADDITION, result.getFieldResults(0).getChange().getChangeType()); Assert.assertEquals(4, result.getFieldResults(0).getNumber()); @@ -311,8 +311,8 @@ public void removeField() throws Exception { .build(); ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); - Report report = diff(dRef, dNew); - MessageResult result = report.getMessageResultsMap().get("package.v1.Message1"); + Patch patch = diff(dRef, dNew); + MessageResult result = patch.getMessageResultsMap().get("package.v1.Message1"); Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); Assert.assertEquals(ChangeType.REMOVAL, result.getFieldResults(0).getChange().getChangeType()); Assert.assertEquals(1, result.getFieldResults(0).getNumber()); @@ -338,8 +338,8 @@ public void renameField() throws Exception { .build(); ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); - Report report = diff(dRef, dNew); - MessageResult result = report.getMessageResultsMap().get("package.v1.Message1"); + Patch patch = diff(dRef, dNew); + MessageResult result = patch.getMessageResultsMap().get("package.v1.Message1"); Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); Assert.assertEquals(ChangeType.CHANGED, result.getFieldResults(0).getChange().getChangeType()); Assert.assertEquals(1, result.getFieldResults(0).getNumber()); @@ -371,8 +371,8 @@ public void changeFieldType() throws Exception { .build(); ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); - Report report = diff(dRef, dNew); - MessageResult result = report.getMessageResultsMap().get("package.v1.Message1"); + Patch patch = diff(dRef, dNew); + MessageResult result = patch.getMessageResultsMap().get("package.v1.Message1"); Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); Assert.assertEquals(ChangeType.CHANGED, result.getFieldResults(0).getChange().getChangeType()); Assert.assertEquals( @@ -403,8 +403,8 @@ public void changeComplexFieldType() throws Exception { .build(); ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); - Report report = diff(dRef, dNew); - MessageResult result = report.getMessageResultsMap().get("package.v1.Message1"); + Patch patch = diff(dRef, dNew); + MessageResult result = patch.getMessageResultsMap().get("package.v1.Message1"); Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); Assert.assertEquals(ChangeType.CHANGED, result.getFieldResults(0).getChange().getChangeType()); Assert.assertEquals( @@ -437,8 +437,8 @@ public void changeMessageFieldType() throws Exception { .build(); ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); - Report report = diff(dRef, dNew); - MessageResult result = report.getMessageResultsMap().get("package.v1.TestSubMessage"); + Patch patch = diff(dRef, dNew); + MessageResult result = patch.getMessageResultsMap().get("package.v1.TestSubMessage"); Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); Assert.assertEquals(ChangeType.CHANGED, result.getFieldResults(0).getChange().getChangeType()); Assert.assertEquals( @@ -458,8 +458,8 @@ public void addService() throws Exception { .build(); ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); - Report report = diff(dRef, dNew); - ServiceResult serviceResult = report.getServiceResultsMap().get("package.v1.Service2"); + Patch patch = diff(dRef, dNew); + ServiceResult serviceResult = patch.getServiceResultsMap().get("package.v1.Service2"); Assert.assertEquals("package.v1.Service2", serviceResult.getChange().getToName()); Assert.assertEquals(ChangeType.ADDITION, serviceResult.getChange().getChangeType()); } @@ -470,8 +470,8 @@ public void removeService() throws Exception { DescriptorProtos.FileDescriptorProto fd = FILE_V1.toBuilder().clearService().build(); ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); - Report report = diff(dRef, dNew); - ServiceResult serviceResult = report.getServiceResultsMap().get("package.v1.Service1"); + Patch patch = diff(dRef, dNew); + ServiceResult serviceResult = patch.getServiceResultsMap().get("package.v1.Service1"); Assert.assertEquals("package.v1.Service1", serviceResult.getChange().getFromName()); Assert.assertEquals(ChangeType.REMOVAL, serviceResult.getChange().getChangeType()); } @@ -495,8 +495,8 @@ public void addMethod() throws Exception { .build(); ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); - Report report = diff(dRef, dNew); - ServiceResult result = report.getServiceResultsMap().get("package.v1.Service1"); + Patch patch = diff(dRef, dNew); + ServiceResult result = patch.getServiceResultsMap().get("package.v1.Service1"); Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); Assert.assertEquals( ChangeType.ADDITION, result.getMethodResults(0).getChange().getChangeType()); @@ -515,8 +515,8 @@ public void removeMethod() throws Exception { .build(); ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); - Report report = diff(dRef, dNew); - ServiceResult result = report.getServiceResultsMap().get("package.v1.Service1"); + Patch patch = diff(dRef, dNew); + ServiceResult result = patch.getServiceResultsMap().get("package.v1.Service1"); Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); Assert.assertEquals(ChangeType.REMOVAL, result.getMethodResults(0).getChange().getChangeType()); Assert.assertEquals("Method1", result.getMethodResults(0).getName()); @@ -540,8 +540,8 @@ public void renameMethod() throws Exception { .build(); ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); - Report report = diff(dRef, dNew); - ServiceResult result = report.getServiceResultsMap().get("package.v1.Service1"); + Patch patch = diff(dRef, dNew); + ServiceResult result = patch.getServiceResultsMap().get("package.v1.Service1"); Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); Assert.assertEquals( @@ -556,7 +556,7 @@ public void renameMethod() throws Exception { Assert.assertEquals("", result.getMethodResults(1).getChange().getToName()); } - private Report diff(ProtoDomain dRef, ProtoDomain dNew) throws IOException { + private Patch diff(ProtoDomain dRef, ProtoDomain dNew) throws IOException { ValidationResults results = new ValidationResults(); ProtoDiff diff = new ProtoDiff(dRef, dNew, results); diff.diffOnFileName("package/v1/file1.proto"); diff --git a/core/src/test/java/io/anemos/metastore/core/registry/ShadowTest.java b/core/src/test/java/io/anemos/metastore/core/registry/ShadowTest.java index 6da315b..9634944 100644 --- a/core/src/test/java/io/anemos/metastore/core/registry/ShadowTest.java +++ b/core/src/test/java/io/anemos/metastore/core/registry/ShadowTest.java @@ -5,7 +5,7 @@ import io.anemos.metastore.core.proto.validate.ProtoDiff; import io.anemos.metastore.core.proto.validate.ValidationResults; import io.anemos.metastore.putils.ProtoDomain; -import io.anemos.metastore.v1alpha1.Report; +import io.anemos.metastore.v1alpha1.Patch; import org.junit.Assert; import org.junit.Before; import org.junit.Rule; @@ -33,7 +33,7 @@ public void addMessageOptionDeltaTest() throws Exception { ProtoDiff diff = new ProtoDiff(base, baseAddMessageOption, results); diff.diffOnMessage("test.v1.ProtoBeamBasicMessage"); - Report result = results.createProto(); + Patch result = results.createProto(); System.out.println(result); // ShadowRegistry shadowRegistry = new ShadowRegistry(base, result); @@ -57,7 +57,7 @@ public void addFieldOptionDeltaTest() throws Exception { ProtoDiff diff = new ProtoDiff(base, baseAddFieldOption, results); diff.diffOnMessage("test.v1.ProtoBeamBasicMessage"); - Report result = results.createProto(); + Patch result = results.createProto(); System.out.println(result); ProtoDomain shadow = new ShadowApply().applyDelta(base, result); @@ -80,7 +80,7 @@ public void addFileOptionDeltaTest() throws Exception { ProtoDiff diff = new ProtoDiff(base, baseAddFileOption, results); diff.diffOnFileName(fileName); - Report result = results.createProto(); + Patch result = results.createProto(); System.out.println(result); ProtoDomain shadow = new ShadowApply().applyDelta(base, result); @@ -103,7 +103,7 @@ public void multipleOptionsTest() throws Exception { ProtoDiff diff = new ProtoDiff(base, baseMultipleOptions, results); diff.diffOnFileName(fileName); - Report result = results.createProto(); + Patch result = results.createProto(); System.out.println(result); ProtoDomain shadow = new ShadowApply().applyDelta(base, result); diff --git a/proto/src/main/proto/grpc/registry/v1alpha1/patch.proto b/proto/src/main/proto/grpc/registry/v1alpha1/patch.proto index 26ddeda..e7dc4b0 100644 --- a/proto/src/main/proto/grpc/registry/v1alpha1/patch.proto +++ b/proto/src/main/proto/grpc/registry/v1alpha1/patch.proto @@ -8,12 +8,15 @@ option java_multiple_files = true; package grpc.registry.v1alpha1; message Report { + Patch patch = 1; + ResultCount result_count = 5; +} + +message Patch { map file_results = 1; map message_results = 2; map enum_results = 3; map service_results = 4; - - ResultCount result_count = 5; } message ResultCount { diff --git a/server/src/test/java/io/anemos/metastore/server/ShadowE2ETest.java b/server/src/test/java/io/anemos/metastore/server/ShadowE2ETest.java index 83c0730..c215447 100644 --- a/server/src/test/java/io/anemos/metastore/server/ShadowE2ETest.java +++ b/server/src/test/java/io/anemos/metastore/server/ShadowE2ETest.java @@ -135,7 +135,7 @@ public void shadowE2ELocalFileProvider() throws Exception { fileDescriptor.toProto().toByteString())); schemaRegistyStub.submitSchema(submitSchemaRequest2.build()); - // check shadow delta insides + // check shadow patch insides ValidationResults expectedResults = new ValidationResults(); ProtoDiff protoDiff = new ProtoDiff(baseKnownOption(), baseAddMessageOption(), expectedResults); protoDiff.diffOnFileName("test/v1/simple.proto"); @@ -144,7 +144,7 @@ public void shadowE2ELocalFileProvider() throws Exception { new FileInputStream(metastorePath.toAbsolutePath().toString() + "/shadow.pb")); Assert.assertEquals( expectedResults.createProto().getMessageResultsMap(), - actualShadowReport.getMessageResultsMap()); + actualShadowReport.getPatch().getMessageResultsMap()); // add field to default RegistryP.SubmitSchemaRequest.Builder submitDefaultAddField = @@ -163,6 +163,7 @@ public void shadowE2ELocalFileProvider() throws Exception { ChangeType.ADDITION, verifyDefaultResponse2 .getReport() + .getPatch() .getMessageResultsMap() .get("test.v1.ProtoBeamBasicMessage") .getFieldResults(0) @@ -176,7 +177,7 @@ public void shadowE2ELocalFileProvider() throws Exception { new FileInputStream(metastorePath.toAbsolutePath().toString() + "/shadow.pb")); Assert.assertEquals( expectedResults.createProto().getMessageResultsMap(), - actualShadowReport.getMessageResultsMap()); + actualShadowReport.getPatch().getMessageResultsMap()); actualShadowRepo = ProtocUtil.createDescriptorSet(shadowrepoPath.toAbsolutePath().toString()); Assert.assertEquals( From 362d4aab3e27b418b79a7141dcac3dea8141ea4a Mon Sep 17 00:00:00 2001 From: Alex Van Boxel Date: Fri, 10 Apr 2020 15:33:34 +0200 Subject: [PATCH 04/11] Rename Result to Patch --- .../proto/profile/ProfileAllowAddBase.java | 8 +- .../proto/validate/ValidationResults.java | 172 +++++++++--------- .../metastore/core/registry/ShadowApply.java | 28 +-- .../core/proto/AvroToProtoSchemaTest.java | 20 +- .../core/proto/profile/ProfileTest.java | 8 +- .../core/proto/validation/DiffTest.java | 36 ++-- .../core/proto/validation/LintTest.java | 63 ++++--- .../core/proto/validation/OptionDiffTest.java | 36 ++-- .../core/proto/validation/ProtoDiffTest.java | 148 +++++++-------- .../proto/grpc/registry/v1alpha1/patch.proto | 28 +-- .../metastore/server/ShadowE2ETest.java | 12 +- 11 files changed, 278 insertions(+), 281 deletions(-) diff --git a/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowAddBase.java b/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowAddBase.java index 57d7eaa..914bad4 100644 --- a/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowAddBase.java +++ b/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowAddBase.java @@ -30,7 +30,7 @@ public Report validate(Patch patch) { Report.Builder builder = Report.newBuilder(); builder.setPatch(patch); int error = 0; - for (MessageResult messageResult : patch.getMessageResultsMap().values()) { + for (MessagePatch messageResult : patch.getMessagePatchesMap().values()) { if (skipValidationForAlpha(messageResult.getPackage())) { continue; } @@ -57,7 +57,7 @@ public Report validate(Patch patch) { case UNRECOGNIZED: break; } - for (FieldResult fieldResult : messageResult.getFieldResultsList()) { + for (FieldPatch fieldResult : messageResult.getFieldPatchesList()) { switch (fieldResult.getChange().getChangeType()) { case REMOVAL: error++; @@ -104,7 +104,7 @@ public Report validate(Patch patch) { } } } - for (EnumResult enumResult : patch.getEnumResultsMap().values()) { + for (EnumPatch enumResult : patch.getEnumPatchesMap().values()) { if (skipValidationForAlpha(enumResult.getPackage())) { continue; } @@ -131,7 +131,7 @@ public Report validate(Patch patch) { case UNRECOGNIZED: break; } - for (EnumValueResult valueResult : enumResult.getValueResultsList()) { + for (EnumValuePatch valueResult : enumResult.getValuePatchesList()) { switch (valueResult.getChange().getChangeType()) { case REMOVAL: error++; diff --git a/core/src/main/java/io/anemos/metastore/core/proto/validate/ValidationResults.java b/core/src/main/java/io/anemos/metastore/core/proto/validate/ValidationResults.java index 127bece..7db2e69 100644 --- a/core/src/main/java/io/anemos/metastore/core/proto/validate/ValidationResults.java +++ b/core/src/main/java/io/anemos/metastore/core/proto/validate/ValidationResults.java @@ -8,16 +8,16 @@ import java.util.Map; public class ValidationResults { - private Map fileMap = new HashMap<>(); - private Map messageMap = new HashMap<>(); - private Map enumMap = new HashMap<>(); - private Map serviceMap = new HashMap<>(); + private Map fileMap = new HashMap<>(); + private Map messageMap = new HashMap<>(); + private Map enumMap = new HashMap<>(); + private Map serviceMap = new HashMap<>(); public List getInfo(String messageName, String fieldName) { List rules = new ArrayList<>(); - MessageResultContainer messageResult = messageMap.get(messageName); + MessagePatchContainer messageResult = messageMap.get(messageName); if (messageResult != null) { - FieldResultContainer fieldResultContainer = messageResult.fieldMap.get(fieldName); + FieldPatchContainer fieldResultContainer = messageResult.fieldMap.get(fieldName); if (fieldResultContainer != null) { rules.addAll(fieldResultContainer.info); } @@ -25,11 +25,11 @@ public List getInfo(String messageName, String fieldName) { return rules; } - private MessageResultContainer getOrCreateMessage(Descriptors.Descriptor descriptor) { + private MessagePatchContainer getOrCreateMessage(Descriptors.Descriptor descriptor) { String messageName = descriptor.getFullName(); - MessageResultContainer messageResult = messageMap.get(messageName); + MessagePatchContainer messageResult = messageMap.get(messageName); if (messageResult == null) { - messageResult = new MessageResultContainer(); + messageResult = new MessagePatchContainer(); messageResult.packageName = descriptor.getFile().getPackage(); messageResult.fullName = messageName; messageMap.put(messageName, messageResult); @@ -37,12 +37,12 @@ private MessageResultContainer getOrCreateMessage(Descriptors.Descriptor descrip return messageResult; } - private ServiceResultContainer getOrCreateService( + private ServicePatchContainer getOrCreateService( Descriptors.ServiceDescriptor serviceDescriptor) { String serviceName = serviceDescriptor.getFullName(); - ServiceResultContainer serviceResult = serviceMap.get(serviceName); + ServicePatchContainer serviceResult = serviceMap.get(serviceName); if (serviceResult == null) { - serviceResult = new ServiceResultContainer(); + serviceResult = new ServicePatchContainer(); serviceResult.packageName = serviceDescriptor.getFile().getPackage(); serviceResult.fullName = serviceName; serviceMap.put(serviceName, serviceResult); @@ -50,21 +50,21 @@ private ServiceResultContainer getOrCreateService( return serviceResult; } - private FileResultContainer getOrCreateFile(String fileName) { - FileResultContainer fileResult = fileMap.get(fileName); + private FilePatchContainer getOrCreateFile(String fileName) { + FilePatchContainer fileResult = fileMap.get(fileName); if (fileResult == null) { - fileResult = new FileResultContainer(); + fileResult = new FilePatchContainer(); fileResult.fullName = fileName; fileMap.put(fileName, fileResult); } return fileResult; } - private EnumResultContainer getOrCreateEnum(Descriptors.EnumDescriptor enumDescriptor) { + private EnumPatchContainer getOrCreateEnum(Descriptors.EnumDescriptor enumDescriptor) { String fileName = enumDescriptor.getFullName(); - EnumResultContainer enumResult = enumMap.get(fileName); + EnumPatchContainer enumResult = enumMap.get(fileName); if (enumResult == null) { - enumResult = new EnumResultContainer(); + enumResult = new EnumPatchContainer(); enumResult.packageName = enumDescriptor.getFile().getPackage(); enumResult.fullName = fileName; enumMap.put(fileName, enumResult); @@ -73,77 +73,75 @@ private EnumResultContainer getOrCreateEnum(Descriptors.EnumDescriptor enumDescr } void addResult(Descriptors.FieldDescriptor fd, RuleInfo ruleInfo) { - MessageResultContainer messageResult = getOrCreateMessage(fd.getContainingType()); + MessagePatchContainer messageResult = getOrCreateMessage(fd.getContainingType()); messageResult.add(fd, ruleInfo); } void addResult(Descriptors.MethodDescriptor md, RuleInfo ruleInfo) { - ServiceResultContainer messageResult = getOrCreateService(md.getService()); + ServicePatchContainer messageResult = getOrCreateService(md.getService()); messageResult.add(md, ruleInfo); } void addResult(Descriptors.Descriptor descriptor, RuleInfo ruleInfo) { - MessageResultContainer messageResult = getOrCreateMessage(descriptor); + MessagePatchContainer messageResult = getOrCreateMessage(descriptor); messageResult.addResult(ruleInfo); } void addResult(Descriptors.ServiceDescriptor descriptor, RuleInfo ruleInfo) { - ServiceResultContainer serviceResult = getOrCreateService(descriptor); + ServicePatchContainer serviceResult = getOrCreateService(descriptor); serviceResult.addResult(ruleInfo); } void addResult(Descriptors.FileDescriptor descriptor, RuleInfo ruleInfo) { - FileResultContainer fileResult = getOrCreateFile(descriptor.getFullName()); + FilePatchContainer fileResult = getOrCreateFile(descriptor.getFullName()); fileResult.addResult(ruleInfo); } void setPatch(Descriptors.FieldDescriptor fd, FieldChangeInfo patch) { - MessageResultContainer resultContainer = getOrCreateMessage(fd.getContainingType()); + MessagePatchContainer resultContainer = getOrCreateMessage(fd.getContainingType()); resultContainer.addPatch(fd, patch); } void setPatch(Descriptors.MethodDescriptor fd, MethodChangeInfo patch) { - ServiceResultContainer resultContainer = getOrCreateService(fd.getService()); + ServicePatchContainer resultContainer = getOrCreateService(fd.getService()); resultContainer.addPatch(fd, patch); } void setPatch(Descriptors.EnumValueDescriptor fd, EnumValueChangeInfo patch) { - EnumResultContainer resultContainer = getOrCreateEnum(fd.getType()); + EnumPatchContainer resultContainer = getOrCreateEnum(fd.getType()); resultContainer.addPatch(fd, patch); } void setPatch(Descriptors.Descriptor fd, ChangeInfo patch) { - MessageResultContainer resultContainer = getOrCreateMessage(fd); + MessagePatchContainer resultContainer = getOrCreateMessage(fd); resultContainer.setPatch(patch); } void setPatch(Descriptors.FileDescriptor fd, ChangeInfo patch) { - FileResultContainer resultContainer = getOrCreateFile(fd.getFullName()); + FilePatchContainer resultContainer = getOrCreateFile(fd.getFullName()); resultContainer.setPatch(patch); } void setPatch(Descriptors.EnumDescriptor fd, ChangeInfo patch) { - EnumResultContainer resultContainer = getOrCreateEnum(fd); + EnumPatchContainer resultContainer = getOrCreateEnum(fd); resultContainer.setPatch(patch); } void setPatch(Descriptors.ServiceDescriptor fd, ChangeInfo patch) { - ServiceResultContainer serviceResult = getOrCreateService(fd); + ServicePatchContainer serviceResult = getOrCreateService(fd); serviceResult.setPatch(patch); } void addOptionChange(Descriptors.GenericDescriptor descriptor, OptionChangeInfo info) { if (descriptor instanceof Descriptors.FileDescriptor) { - FileResultContainer fileResultContainer = getOrCreateFile(descriptor.getFullName()); + FilePatchContainer fileResultContainer = getOrCreateFile(descriptor.getFullName()); fileResultContainer.addOptionChange(info); } else if (descriptor instanceof Descriptors.Descriptor) { - MessageResultContainer messageResult = - getOrCreateMessage((Descriptors.Descriptor) descriptor); + MessagePatchContainer messageResult = getOrCreateMessage((Descriptors.Descriptor) descriptor); messageResult.addOptionChange(info); } else if (descriptor instanceof Descriptors.FieldDescriptor) { Descriptors.FieldDescriptor fieldDescriptor = (Descriptors.FieldDescriptor) descriptor; - MessageResultContainer messageResult = - getOrCreateMessage(fieldDescriptor.getContainingType()); + MessagePatchContainer messageResult = getOrCreateMessage(fieldDescriptor.getContainingType()); messageResult.addOptionChange(fieldDescriptor, info); } else { // TODO @@ -152,25 +150,25 @@ void addOptionChange(Descriptors.GenericDescriptor descriptor, OptionChangeInfo } void addImportChange(String fullName, ImportChangeInfo info) { - FileResultContainer fileResultContainer = getOrCreateFile(fullName); + FilePatchContainer fileResultContainer = getOrCreateFile(fullName); fileResultContainer.addImportChange(info); } public Patch createProto() { Patch.Builder builder = Patch.newBuilder(); - fileMap.values().forEach(file -> builder.putFileResults(file.fullName, file.createProto())); + fileMap.values().forEach(file -> builder.putFilePatches(file.fullName, file.createProto())); messageMap .values() - .forEach(message -> builder.putMessageResults(message.fullName, message.createProto())); + .forEach(message -> builder.putMessagePatches(message.fullName, message.createProto())); serviceMap .values() - .forEach(service -> builder.putServiceResults(service.fullName, service.createProto())); - enumMap.values().forEach(e -> builder.putEnumResults(e.fullName, e.createProto())); + .forEach(service -> builder.putServicePatches(service.fullName, service.createProto())); + enumMap.values().forEach(e -> builder.putEnumPatches(e.fullName, e.createProto())); return builder.build(); } - static class FieldResultContainer { + static class FieldPatchContainer { List info = new ArrayList<>(); List optionChangeInfos = new ArrayList<>(); FieldChangeInfo patch; @@ -181,9 +179,9 @@ public void add(RuleInfo ruleInfo) { info.add(ruleInfo); } - public FieldResult createProto() { - FieldResult.Builder builder = - FieldResult.newBuilder() + public FieldPatch createProto() { + FieldPatch.Builder builder = + FieldPatch.newBuilder() .setName(name) .setNumber(number) .addAllInfo(info) @@ -203,29 +201,29 @@ void addOptionChange(OptionChangeInfo optionChangeInfo) { } } - static class MessageResultContainer { + static class MessagePatchContainer { String packageName; String fullName; List info = new ArrayList<>(); - Map fieldMap = new HashMap<>(); + Map fieldMap = new HashMap<>(); ChangeInfo patch; List optionChangeInfos = new ArrayList<>(); public void add(Descriptors.FieldDescriptor field, RuleInfo ruleInfo) { - FieldResultContainer fieldResultContainer = getOrCreateFieldContainer(field); + FieldPatchContainer fieldResultContainer = getOrCreateFieldContainer(field); fieldResultContainer.add(ruleInfo); } void addPatch(Descriptors.FieldDescriptor field, FieldChangeInfo patch) { - FieldResultContainer fieldResultContainer = getOrCreateFieldContainer(field); + FieldPatchContainer fieldResultContainer = getOrCreateFieldContainer(field); fieldResultContainer.addPatch(patch); } - private FieldResultContainer getOrCreateFieldContainer(Descriptors.FieldDescriptor field) { - FieldResultContainer fieldResultContainer = fieldMap.get(field.getName()); + private FieldPatchContainer getOrCreateFieldContainer(Descriptors.FieldDescriptor field) { + FieldPatchContainer fieldResultContainer = fieldMap.get(field.getName()); if (fieldResultContainer == null) { - fieldResultContainer = new FieldResultContainer(); + fieldResultContainer = new FieldPatchContainer(); fieldResultContainer.name = field.getName(); fieldResultContainer.number = field.getNumber(); fieldMap.put(field.getName(), fieldResultContainer); @@ -233,14 +231,14 @@ private FieldResultContainer getOrCreateFieldContainer(Descriptors.FieldDescript return fieldResultContainer; } - MessageResult createProto() { - MessageResult.Builder messageInfo = MessageResult.newBuilder(); + MessagePatch createProto() { + MessagePatch.Builder messageInfo = MessagePatch.newBuilder(); messageInfo.setName(fullName); messageInfo.setPackage(packageName); if (patch != null) { messageInfo.setChange(patch); } - fieldMap.values().forEach(field -> messageInfo.addFieldResults(field.createProto())); + fieldMap.values().forEach(field -> messageInfo.addFieldPatches(field.createProto())); messageInfo.addAllInfo(info); messageInfo.addAllOptionChange(optionChangeInfos); return messageInfo.build(); @@ -259,16 +257,16 @@ void addOptionChange(OptionChangeInfo info) { } void addOptionChange(Descriptors.FieldDescriptor field, OptionChangeInfo optionChangeInfo) { - FieldResultContainer fieldResultContainer = getOrCreateFieldContainer(field); + FieldPatchContainer fieldResultContainer = getOrCreateFieldContainer(field); fieldResultContainer.addOptionChange(optionChangeInfo); } } - class FileResultContainer { + class FilePatchContainer { String fullName; List info = new ArrayList<>(); - // Map fieldMap = new HashMap<>(); + // Map fieldMap = new HashMap<>(); ChangeInfo patch; List optionChangeInfos = new ArrayList<>(); List importChangeInfo = new ArrayList<>(); @@ -277,10 +275,10 @@ void setPatch(ChangeInfo patch) { this.patch = patch; } - public FileResult createProto() { + public FilePatch createProto() { - FileResult.Builder builder = - FileResult.newBuilder() + FilePatch.Builder builder = + FilePatch.newBuilder() .setFileName(fullName) .addAllInfo(info) .addAllOptionChange(optionChangeInfos) @@ -304,42 +302,42 @@ void addImportChange(ImportChangeInfo changeInfo) { } } - class ServiceResultContainer { + class ServicePatchContainer { String packageName; String fullName; List info = new ArrayList<>(); - Map methodMap = new HashMap<>(); + Map methodMap = new HashMap<>(); ChangeInfo patch; public void add(Descriptors.MethodDescriptor method, RuleInfo ruleInfo) { - MethodResultContainer methoddResultContainer = getOrCreateMethodContainer(method); + MethodPatchContainer methoddResultContainer = getOrCreateMethodContainer(method); methoddResultContainer.add(ruleInfo); } public void addPatch(Descriptors.MethodDescriptor method, MethodChangeInfo patch) { - MethodResultContainer methodResultContainer = getOrCreateMethodContainer(method); + MethodPatchContainer methodResultContainer = getOrCreateMethodContainer(method); methodResultContainer.addPatch(patch); } - private MethodResultContainer getOrCreateMethodContainer(Descriptors.MethodDescriptor method) { - MethodResultContainer methodResultContainer = methodMap.get(method.getName()); + private MethodPatchContainer getOrCreateMethodContainer(Descriptors.MethodDescriptor method) { + MethodPatchContainer methodResultContainer = methodMap.get(method.getName()); if (methodResultContainer == null) { - methodResultContainer = new MethodResultContainer(); + methodResultContainer = new MethodPatchContainer(); methodResultContainer.fullName = method.getName(); methodMap.put(method.getName(), methodResultContainer); } return methodResultContainer; } - ServiceResult createProto() { - ServiceResult.Builder serviceInfo = ServiceResult.newBuilder(); + ServicePatch createProto() { + ServicePatch.Builder serviceInfo = ServicePatch.newBuilder(); serviceInfo.setPackage(packageName); serviceInfo.setName(fullName); if (patch != null) { serviceInfo.setChange(patch); } - methodMap.values().forEach(method -> serviceInfo.addMethodResults(method.createProto())); + methodMap.values().forEach(method -> serviceInfo.addMethodPatches(method.createProto())); serviceInfo.addAllInfo(info); return serviceInfo.build(); } @@ -353,7 +351,7 @@ void setPatch(ChangeInfo patch) { } } - static class MethodResultContainer { + static class MethodPatchContainer { List info = new ArrayList<>(); MethodChangeInfo patch; String fullName; @@ -362,8 +360,8 @@ public void add(RuleInfo ruleInfo) { info.add(ruleInfo); } - public MethodResult createProto() { - MethodResult.Builder builder = MethodResult.newBuilder().setName(fullName).addAllInfo(info); + public MethodPatch createProto() { + MethodPatch.Builder builder = MethodPatch.newBuilder().setName(fullName).addAllInfo(info); if (patch != null) { builder.setChange(patch); } @@ -375,29 +373,29 @@ void addPatch(MethodChangeInfo patch) { } } - class EnumResultContainer { + class EnumPatchContainer { String packageName; String fullName; List info = new ArrayList<>(); - Map valueMap = new HashMap<>(); + Map valueMap = new HashMap<>(); ChangeInfo patch; public void add(Descriptors.EnumValueDescriptor value, RuleInfo ruleInfo) { - EnumValueResultContainer methodResultContainer = getOrCreateValueContainer(value); + EnumValuePatchContainer methodResultContainer = getOrCreateValueContainer(value); methodResultContainer.add(ruleInfo); } public void addPatch(Descriptors.EnumValueDescriptor value, EnumValueChangeInfo patch) { - EnumValueResultContainer valueResultContainer = getOrCreateValueContainer(value); + EnumValuePatchContainer valueResultContainer = getOrCreateValueContainer(value); valueResultContainer.addPatch(patch); } - private EnumValueResultContainer getOrCreateValueContainer( + private EnumValuePatchContainer getOrCreateValueContainer( Descriptors.EnumValueDescriptor value) { - EnumValueResultContainer valueResultContainer = valueMap.get(value.getName()); + EnumValuePatchContainer valueResultContainer = valueMap.get(value.getName()); if (valueResultContainer == null) { - valueResultContainer = new EnumValueResultContainer(); + valueResultContainer = new EnumValuePatchContainer(); valueResultContainer.fullName = value.getName(); valueResultContainer.number = value.getNumber(); valueMap.put(value.getName(), valueResultContainer); @@ -405,14 +403,14 @@ private EnumValueResultContainer getOrCreateValueContainer( return valueResultContainer; } - EnumResult createProto() { - EnumResult.Builder messageInfo = EnumResult.newBuilder(); + EnumPatch createProto() { + EnumPatch.Builder messageInfo = EnumPatch.newBuilder(); messageInfo.setPackage(packageName); messageInfo.setName(fullName); if (patch != null) { messageInfo.setChange(patch); } - valueMap.values().forEach(method -> messageInfo.addValueResults(method.createProto())); + valueMap.values().forEach(method -> messageInfo.addValuePatches(method.createProto())); messageInfo.addAllInfo(info); return messageInfo.build(); } @@ -426,7 +424,7 @@ void setPatch(ChangeInfo patch) { } } - static class EnumValueResultContainer { + static class EnumValuePatchContainer { List info = new ArrayList<>(); EnumValueChangeInfo patch; String fullName; @@ -436,9 +434,9 @@ public void add(RuleInfo ruleInfo) { info.add(ruleInfo); } - public EnumValueResult createProto() { - EnumValueResult.Builder builder = - EnumValueResult.newBuilder().setName(fullName).setNumber(number).addAllInfo(info); + public EnumValuePatch createProto() { + EnumValuePatch.Builder builder = + EnumValuePatch.newBuilder().setName(fullName).setNumber(number).addAllInfo(info); if (patch != null) { builder.setChange(patch); } diff --git a/core/src/main/java/io/anemos/metastore/core/registry/ShadowApply.java b/core/src/main/java/io/anemos/metastore/core/registry/ShadowApply.java index a496def..af83b5e 100644 --- a/core/src/main/java/io/anemos/metastore/core/registry/ShadowApply.java +++ b/core/src/main/java/io/anemos/metastore/core/registry/ShadowApply.java @@ -5,10 +5,10 @@ import com.google.protobuf.Descriptors; import com.google.protobuf.UnknownFieldSet; import io.anemos.metastore.putils.ProtoDomain; -import io.anemos.metastore.v1alpha1.FieldResult; -import io.anemos.metastore.v1alpha1.FileResult; +import io.anemos.metastore.v1alpha1.FieldPatch; +import io.anemos.metastore.v1alpha1.FilePatch; import io.anemos.metastore.v1alpha1.ImportChangeInfo; -import io.anemos.metastore.v1alpha1.MessageResult; +import io.anemos.metastore.v1alpha1.MessagePatch; import io.anemos.metastore.v1alpha1.OptionChangeInfo; import io.anemos.metastore.v1alpha1.Patch; import java.util.ArrayList; @@ -28,8 +28,8 @@ public ProtoDomain applyDelta(ProtoDomain defaultDescriptor, Patch patch) { HashMap fileDescriptorProtoBuilders = new HashMap<>(); - applyMessageResults(patch, fileDescriptorProtoBuilders); - applyFileResults(patch, fileDescriptorProtoBuilders); + applyMessagePatches(patch, fileDescriptorProtoBuilders); + applyFilePatches(patch, fileDescriptorProtoBuilders); List fileDescriptorProtos = new ArrayList<>(); fileDescriptorProtoBuilders.forEach( (name, fd) -> { @@ -41,10 +41,10 @@ public ProtoDomain applyDelta(ProtoDomain defaultDescriptor, Patch patch) { } } - private void applyFileResults( + private void applyFilePatches( Patch patch, HashMap fileDescriptorProtoBuilders) { - for (Map.Entry fileResultEntry : patch.getFileResultsMap().entrySet()) { + for (Map.Entry fileResultEntry : patch.getFilePatchesMap().entrySet()) { Descriptors.FileDescriptor fileDescriptor = shadow.getFileDescriptorByFileName(fileResultEntry.getKey()); @@ -60,17 +60,17 @@ private void applyFileResults( } } - private void applyMessageResults( + private void applyMessagePatches( Patch patch, HashMap fileDescriptorProtoBuilders) { - for (Map.Entry messageResultEntry : - patch.getMessageResultsMap().entrySet()) { + for (Map.Entry messageResultEntry : + patch.getMessagePatchesMap().entrySet()) { Descriptors.Descriptor descriptor = shadow.getDescriptorByName(messageResultEntry.getKey()); HashMap messageNameToIndexMap = getMessageNameToIndexMap(descriptor.getFile()); DescriptorProtos.DescriptorProto.Builder newDescriptorProtoBuilder = DescriptorProtos.DescriptorProto.newBuilder(descriptor.toProto()); - applyFieldResults(messageResultEntry.getValue(), descriptor, newDescriptorProtoBuilder); + applyFieldPatches(messageResultEntry.getValue(), descriptor, newDescriptorProtoBuilder); if (messageResultEntry.getValue().getOptionChangeCount() > 0) { applyMessageOptionChanges( @@ -104,12 +104,12 @@ private DescriptorProtos.FileDescriptorProto.Builder getOrCreateFileDescriptorPr return fileDescriptorProtoBuilder; } - private void applyFieldResults( - MessageResult messageResult, + private void applyFieldPatches( + MessagePatch messageResult, Descriptors.Descriptor messageDescriptor, DescriptorProtos.DescriptorProto.Builder newDescriptorProtoBuilder) { HashMap fieldNumberToIndexMap = getFieldNumberToIndexMap(messageDescriptor); - for (FieldResult fieldResult : messageResult.getFieldResultsList()) { + for (FieldPatch fieldResult : messageResult.getFieldPatchesList()) { if (fieldResult.getOptionChangeCount() > 0) { Descriptors.FieldDescriptor fieldDescriptor = messageDescriptor.findFieldByNumber(fieldResult.getNumber()); diff --git a/core/src/test/java/io/anemos/metastore/core/proto/AvroToProtoSchemaTest.java b/core/src/test/java/io/anemos/metastore/core/proto/AvroToProtoSchemaTest.java index 1a75184..74f1803 100644 --- a/core/src/test/java/io/anemos/metastore/core/proto/AvroToProtoSchemaTest.java +++ b/core/src/test/java/io/anemos/metastore/core/proto/AvroToProtoSchemaTest.java @@ -26,7 +26,7 @@ public void testSingleInt() throws IOException { new AvroToProtoSchema(node).get(), result) .diffOnMessage("io.anemos.metastore.core.proto.TestSingleInt"); - Assert.assertEquals(0, result.createProto().getMessageResultsCount()); + Assert.assertEquals(0, result.createProto().getMessagePatchesCount()); } @Test @@ -38,7 +38,7 @@ public void testSingleBoolean() throws IOException { new AvroToProtoSchema(node).get(), result) .diffOnMessage("io.anemos.metastore.core.proto.TestSingleBoolean"); - Assert.assertEquals(0, result.createProto().getMessageResultsCount()); + Assert.assertEquals(0, result.createProto().getMessagePatchesCount()); } @Test @@ -50,7 +50,7 @@ public void testSingleLong() throws IOException { new AvroToProtoSchema(node).get(), result) .diffOnMessage("io.anemos.metastore.core.proto.TestSingleLong"); - Assert.assertEquals(0, result.createProto().getMessageResultsCount()); + Assert.assertEquals(0, result.createProto().getMessagePatchesCount()); } @Test @@ -62,7 +62,7 @@ public void testSingleFloat() throws IOException { new AvroToProtoSchema(node).get(), result) .diffOnMessage("io.anemos.metastore.core.proto.TestSingleFloat"); - Assert.assertEquals(0, result.createProto().getMessageResultsCount()); + Assert.assertEquals(0, result.createProto().getMessagePatchesCount()); } @Test @@ -74,7 +74,7 @@ public void testSingleDouble() throws IOException { new AvroToProtoSchema(node).get(), result) .diffOnMessage("io.anemos.metastore.core.proto.TestSingleDouble"); - Assert.assertEquals(0, result.createProto().getMessageResultsCount()); + Assert.assertEquals(0, result.createProto().getMessagePatchesCount()); } @Test @@ -86,7 +86,7 @@ public void testSingleBytes() throws IOException { new AvroToProtoSchema(node).get(), result) .diffOnMessage("io.anemos.metastore.core.proto.TestSingleBytes"); - Assert.assertEquals(0, result.createProto().getMessageResultsCount()); + Assert.assertEquals(0, result.createProto().getMessagePatchesCount()); } @Test @@ -98,7 +98,7 @@ public void testSingleString() throws IOException { new AvroToProtoSchema(node).get(), result) .diffOnMessage("io.anemos.metastore.core.proto.TestSingleString"); - Assert.assertEquals(0, result.createProto().getMessageResultsCount()); + Assert.assertEquals(0, result.createProto().getMessagePatchesCount()); } @Test @@ -110,7 +110,7 @@ public void testComplexArray() throws IOException { new AvroToProtoSchema(node).get(), result) .diffOnMessage("io.anemos.metastore.core.proto.TestComplexArrayInt"); - Assert.assertEquals(0, result.createProto().getMessageResultsCount()); + Assert.assertEquals(0, result.createProto().getMessagePatchesCount()); } @Test @@ -122,7 +122,7 @@ public void testComplexEnum() throws IOException { new AvroToProtoSchema(node).get(), result) .diffOnMessage("io.anemos.metastore.core.proto.TestComplexEnum"); - Assert.assertEquals(0, result.createProto().getMessageResultsCount()); + Assert.assertEquals(0, result.createProto().getMessagePatchesCount()); } @Test @@ -142,7 +142,7 @@ public void testComplexMap() throws IOException { new AvroToProtoSchema(node).get(), result) .diffOnMessage("io.anemos.metastore.core.proto.TestComplexMap"); - Assert.assertEquals(0, result.createProto().getMessageResultsCount()); + Assert.assertEquals(0, result.createProto().getMessagePatchesCount()); } private JsonNode getJsonNode(String jsonName) { diff --git a/core/src/test/java/io/anemos/metastore/core/proto/profile/ProfileTest.java b/core/src/test/java/io/anemos/metastore/core/proto/profile/ProfileTest.java index cea9b75..ddfde57 100644 --- a/core/src/test/java/io/anemos/metastore/core/proto/profile/ProfileTest.java +++ b/core/src/test/java/io/anemos/metastore/core/proto/profile/ProfileTest.java @@ -27,7 +27,7 @@ public void profileAllowAdd_RemoveFieldV1() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); Report report = new ProfileAllowAdd().validate(patch); - assertEquals(1, report.getPatch().getMessageResultsCount()); + assertEquals(1, report.getPatch().getMessagePatchesCount()); assertEquals(1, report.getResultCount().getDiffErrors()); } @@ -43,7 +43,7 @@ public void profileAllowAdd_RemoveFieldV1Alpha() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); Report report = new ProfileAllowAdd().validate(patch); - assertEquals(1, report.getPatch().getMessageResultsCount()); + assertEquals(1, report.getPatch().getMessagePatchesCount()); assertEquals(1, report.getResultCount().getDiffErrors()); } @@ -59,7 +59,7 @@ public void profileAllowStableAddAddAlpha_RemoveFieldV1() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); Report report = new ProfileAllowStableAddAlphaAll().validate(patch); - assertEquals(1, report.getPatch().getMessageResultsCount()); + assertEquals(1, report.getPatch().getMessagePatchesCount()); assertEquals(1, report.getResultCount().getDiffErrors()); } @@ -75,7 +75,7 @@ public void profileAllowStableAddAddAlpha_RemoveFieldV1Alpha() throws Exception ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); Report report = new ProfileAllowStableAddAlphaAll().validate(patch); - assertEquals(1, report.getPatch().getMessageResultsCount()); + assertEquals(1, report.getPatch().getMessagePatchesCount()); assertEquals(0, report.getResultCount().getDiffErrors()); } diff --git a/core/src/test/java/io/anemos/metastore/core/proto/validation/DiffTest.java b/core/src/test/java/io/anemos/metastore/core/proto/validation/DiffTest.java index 86a1228..51d282d 100644 --- a/core/src/test/java/io/anemos/metastore/core/proto/validation/DiffTest.java +++ b/core/src/test/java/io/anemos/metastore/core/proto/validation/DiffTest.java @@ -16,7 +16,7 @@ public class DiffTest { @Test public void onBaseDeprecatedString() throws IOException { - FieldResult fieldResults = diff(TestSets.base(), TestSets.baseDeprecateString()); + FieldPatch fieldResults = diff(TestSets.base(), TestSets.baseDeprecateString()); Assert.assertEquals(16, fieldResults.getNumber()); Assert.assertEquals("primitive_string", fieldResults.getName()); @@ -34,7 +34,7 @@ public void onBaseDeprecatedString() throws IOException { @Test public void onBaseRemoveString() throws IOException { - FieldResult fieldResults = diff(TestSets.base(), TestSets.baseRemoveString()); + FieldPatch fieldResults = diff(TestSets.base(), TestSets.baseRemoveString()); Assert.assertEquals(16, fieldResults.getNumber()); Assert.assertEquals("primitive_string", fieldResults.getName()); @@ -52,7 +52,7 @@ public void onBaseRemoveString() throws IOException { @Test public void onBaseReserveString() throws IOException { - FieldResult fieldResults = diff(TestSets.base(), TestSets.baseReserveString()); + FieldPatch fieldResults = diff(TestSets.base(), TestSets.baseReserveString()); Assert.assertEquals(16, fieldResults.getNumber()); Assert.assertEquals("primitive_string", fieldResults.getName()); @@ -70,7 +70,7 @@ public void onBaseReserveString() throws IOException { @Test public void onBaseReserveStringOnlyNumber() throws IOException { - FieldResult fieldResults = diff(TestSets.base(), TestSets.baseReserveStringOnlyNumber()); + FieldPatch fieldResults = diff(TestSets.base(), TestSets.baseReserveStringOnlyNumber()); Assert.assertEquals(16, fieldResults.getNumber()); Assert.assertEquals("primitive_string", fieldResults.getName()); @@ -88,7 +88,7 @@ public void onBaseReserveStringOnlyNumber() throws IOException { @Test public void toBaseUndeprecatedString() throws IOException { - FieldResult fieldResults = diff(TestSets.baseDeprecateString(), TestSets.base()); + FieldPatch fieldResults = diff(TestSets.baseDeprecateString(), TestSets.base()); Assert.assertEquals(16, fieldResults.getNumber()); Assert.assertEquals("primitive_string", fieldResults.getName()); @@ -106,7 +106,7 @@ public void toBaseUndeprecatedString() throws IOException { @Test public void toBaseUnremoveString() throws IOException { - FieldResult fieldResults = diff(TestSets.baseRemoveString(), TestSets.base()); + FieldPatch fieldResults = diff(TestSets.baseRemoveString(), TestSets.base()); Assert.assertEquals(16, fieldResults.getNumber()); Assert.assertEquals("primitive_string", fieldResults.getName()); @@ -124,7 +124,7 @@ public void toBaseUnremoveString() throws IOException { @Test public void tnBaseUnreserveString() throws IOException { - FieldResult fieldResults = diff(TestSets.baseReserveString(), TestSets.base()); + FieldPatch fieldResults = diff(TestSets.baseReserveString(), TestSets.base()); Assert.assertEquals(16, fieldResults.getNumber()); Assert.assertEquals("primitive_string", fieldResults.getName()); @@ -142,7 +142,7 @@ public void tnBaseUnreserveString() throws IOException { @Test public void toBaseUnreserveStringOnlyNumber() throws IOException { - FieldResult fieldResults = diff(TestSets.baseReserveStringOnlyNumber(), TestSets.base()); + FieldPatch fieldResults = diff(TestSets.baseReserveStringOnlyNumber(), TestSets.base()); Assert.assertEquals(16, fieldResults.getNumber()); Assert.assertEquals("primitive_string", fieldResults.getName()); @@ -162,40 +162,40 @@ public void toBaseUnreserveStringOnlyNumber() throws IOException { public void toBaseExtraFileAdded() throws IOException { Patch patch = diffOnPackage(TestSets.base(), TestSets.baseExtraFile()); - Assert.assertEquals(1, patch.getFileResultsCount()); + Assert.assertEquals(1, patch.getFilePatchesCount()); Assert.assertEquals( ChangeType.ADDITION, - patch.getFileResultsOrThrow("test/v1/extra.proto").getChange().getChangeType()); + patch.getFilePatchesOrThrow("test/v1/extra.proto").getChange().getChangeType()); - Assert.assertEquals(1, patch.getMessageResultsCount()); + Assert.assertEquals(1, patch.getMessagePatchesCount()); Assert.assertEquals( ChangeType.ADDITION, - patch.getMessageResultsOrThrow("test.v1.ProtoExtraMessage").getChange().getChangeType()); + patch.getMessagePatchesOrThrow("test.v1.ProtoExtraMessage").getChange().getChangeType()); } @Test public void toBaseExtraFileRemoved() throws IOException { Patch patch = diffOnPackage(TestSets.baseExtraFile(), TestSets.base()); - Assert.assertEquals(1, patch.getFileResultsCount()); + Assert.assertEquals(1, patch.getFilePatchesCount()); Assert.assertEquals( ChangeType.REMOVAL, - patch.getFileResultsOrThrow("test/v1/extra.proto").getChange().getChangeType()); + patch.getFilePatchesOrThrow("test/v1/extra.proto").getChange().getChangeType()); - Assert.assertEquals(1, patch.getMessageResultsCount()); + Assert.assertEquals(1, patch.getMessagePatchesCount()); Assert.assertEquals( ChangeType.REMOVAL, - patch.getMessageResultsOrThrow("test.v1.ProtoExtraMessage").getChange().getChangeType()); + patch.getMessagePatchesOrThrow("test.v1.ProtoExtraMessage").getChange().getChangeType()); } - private FieldResult diff(ProtoDomain dRef, ProtoDomain dNew) throws IOException { + private FieldPatch diff(ProtoDomain dRef, ProtoDomain dNew) throws IOException { ValidationResults results = new ValidationResults(); ProtoDiff diff = new ProtoDiff(dRef, dNew, results); diff.diffOnMessage("test.v1.ProtoBeamBasicMessage"); Patch result = results.createProto(); System.out.println(result); - return result.getMessageResultsMap().get("test.v1.ProtoBeamBasicMessage").getFieldResults(0); + return result.getMessagePatchesMap().get("test.v1.ProtoBeamBasicMessage").getFieldPatches(0); } private Patch diffOnPackage(ProtoDomain dRef, ProtoDomain dNew) throws IOException { diff --git a/core/src/test/java/io/anemos/metastore/core/proto/validation/LintTest.java b/core/src/test/java/io/anemos/metastore/core/proto/validation/LintTest.java index baf8b9a..c73f793 100644 --- a/core/src/test/java/io/anemos/metastore/core/proto/validation/LintTest.java +++ b/core/src/test/java/io/anemos/metastore/core/proto/validation/LintTest.java @@ -21,15 +21,15 @@ public class LintTest { @Test public void fieldOkSnakeCase() throws IOException { Patch result = lintMessage(Lint.LintFieldNamesGood.getDescriptor()); - Assert.assertEquals(0, result.getMessageResultsCount()); + Assert.assertEquals(0, result.getMessagePatchesCount()); } @Test public void fieldNokCamel() throws IOException { Patch result = lintMessage(Lint.LintFieldNamesBad.getDescriptor()); - Assert.assertEquals(1, result.getMessageResultsCount()); + Assert.assertEquals(1, result.getMessagePatchesCount()); - MessageResult mr = result.getMessageResultsOrThrow("anemos.metastore.core.LintFieldNamesBad"); + MessagePatch mr = result.getMessagePatchesOrThrow("anemos.metastore.core.LintFieldNamesBad"); assertOnField(mr, 1, LintRule.LINT_FIELD_NAME_SHOULD_BE_SNAKE, "L20001/02"); assertOnField(mr, 2, LintRule.LINT_FIELD_NAME_SHOULD_BE_SNAKE, "L20001/01"); assertOnField(mr, 3, LintRule.LINT_FIELD_NAME_SHOULD_BE_SNAKE, "L20001/05"); @@ -38,20 +38,19 @@ public void fieldNokCamel() throws IOException { @Test public void messageLowerCase() throws IOException { Patch result = lintMessage(Lint.lintmessagelowercase.getDescriptor()); - Assert.assertEquals(1, result.getMessageResultsCount()); + Assert.assertEquals(1, result.getMessagePatchesCount()); - MessageResult mr = - result.getMessageResultsOrThrow("anemos.metastore.core.lintmessagelowercase"); + MessagePatch mr = result.getMessagePatchesOrThrow("anemos.metastore.core.lintmessagelowercase"); assertOnMessage(mr, LintRule.LINT_MESSAGE_NAME_SHOULD_BE_PASCAL, "L10001/00"); } @Test public void messageCamelCase() throws IOException { Patch result = lintMessage(Lint.lint_message_camelcase.getDescriptor()); - Assert.assertEquals(1, result.getMessageResultsCount()); + Assert.assertEquals(1, result.getMessagePatchesCount()); - MessageResult mr = - result.getMessageResultsOrThrow("anemos.metastore.core.lint_message_camelcase"); + MessagePatch mr = + result.getMessagePatchesOrThrow("anemos.metastore.core.lint_message_camelcase"); assertOnMessage(mr, LintRule.LINT_MESSAGE_NAME_SHOULD_BE_PASCAL, "L10001/00"); } @@ -60,7 +59,7 @@ public void methodInputAndReturnTypeNoRR() throws IOException { Patch result = lintService(Lint.LintFieldNamesGood.getDescriptor(), "anemos.metastore.core.MethodService"); - ServiceResult mr = result.getServiceResultsOrThrow("anemos.metastore.core.MethodService"); + ServicePatch mr = result.getServicePatchesOrThrow("anemos.metastore.core.MethodService"); Assert.assertEquals(2, getInfoForMethod(mr, "MethodEmpty").size()); assertOnMethod(mr, "MethodEmpty", LintRule.LINT_METHOD_RTYPE_END_WITH_RESPONSE, "L50003/00"); assertOnMethod(mr, "MethodEmpty", LintRule.LINT_METHOD_ITYPE_END_WITH_REQUEST, "L50002/00"); @@ -71,7 +70,7 @@ public void methodInputTypeNoR() throws IOException { Patch result = lintService(Lint.LintFieldNamesGood.getDescriptor(), "anemos.metastore.core.MethodService"); - ServiceResult mr = result.getServiceResultsOrThrow("anemos.metastore.core.MethodService"); + ServicePatch mr = result.getServicePatchesOrThrow("anemos.metastore.core.MethodService"); Assert.assertEquals(1, getInfoForMethod(mr, "MethodEmptyI").size()); assertOnMethod(mr, "MethodEmptyI", LintRule.LINT_METHOD_ITYPE_END_WITH_REQUEST, "L50002/00"); } @@ -81,7 +80,7 @@ public void methodReturnTypeNoR() throws IOException { Patch result = lintService(Lint.LintFieldNamesGood.getDescriptor(), "anemos.metastore.core.MethodService"); - ServiceResult mr = result.getServiceResultsOrThrow("anemos.metastore.core.MethodService"); + ServicePatch mr = result.getServicePatchesOrThrow("anemos.metastore.core.MethodService"); Assert.assertEquals(1, getInfoForMethod(mr, "MethodEmptyR").size()); assertOnMethod(mr, "MethodEmptyR", LintRule.LINT_METHOD_RTYPE_END_WITH_RESPONSE, "L50003/00"); } @@ -91,7 +90,7 @@ public void methodOk() throws IOException { Patch result = lintService(Lint.LintFieldNamesGood.getDescriptor(), "anemos.metastore.core.MethodService"); - ServiceResult mr = result.getServiceResultsOrThrow("anemos.metastore.core.MethodService"); + ServicePatch mr = result.getServicePatchesOrThrow("anemos.metastore.core.MethodService"); Assert.assertNull(getInfoForMethod(mr, "MethodOk")); } @@ -115,8 +114,8 @@ private Patch lintService(Descriptors.Descriptor ref, String name) throws IOExce return results.createProto(); } - private List getInfoForField(MessageResult mr, int fieldNumber) { - for (FieldResult fieldResult : mr.getFieldResultsList()) { + private List getInfoForField(MessagePatch mr, int fieldNumber) { + for (FieldPatch fieldResult : mr.getFieldPatchesList()) { if (fieldResult.getNumber() == fieldNumber) { return fieldResult.getInfoList(); } @@ -125,8 +124,8 @@ private List getInfoForField(MessageResult mr, int fieldNumber) { return null; } - private List getInfoForMethod(ServiceResult mr, String methodName) { - for (MethodResult methodResult : mr.getMethodResultsList()) { + private List getInfoForMethod(ServicePatch mr, String methodName) { + for (MethodPatch methodResult : mr.getMethodPatchesList()) { if (methodResult.getName().equals(methodName)) { return methodResult.getInfoList(); } @@ -135,7 +134,7 @@ private List getInfoForMethod(ServiceResult mr, String methodName) { } private void assertOnMethod( - ServiceResult mr, String methodName, LintRule expecredRule, String expectedCode) { + ServicePatch mr, String methodName, LintRule expecredRule, String expectedCode) { List infoForField = getInfoForMethod(mr, methodName); String code = null; LintRule rule = null; @@ -151,7 +150,7 @@ private void assertOnMethod( } private void assertOnField( - MessageResult mr, int fieldNumber, LintRule expecredRule, String expectedCode) { + MessagePatch mr, int fieldNumber, LintRule expecredRule, String expectedCode) { List infoForField = getInfoForField(mr, fieldNumber); String code = null; LintRule rule = null; @@ -166,7 +165,7 @@ private void assertOnField( Assert.assertEquals(expecredRule, rule); } - private void assertOnMessage(MessageResult mr, LintRule expectedRule, String expectedCode) { + private void assertOnMessage(MessagePatch mr, LintRule expectedRule, String expectedCode) { String code = null; LintRule rule = null; for (RuleInfo ruleInfo : mr.getInfoList()) { @@ -184,20 +183,20 @@ private void assertOnMessage(MessageResult mr, LintRule expectedRule, String exp public void packageScopeVersionValid() throws IOException { Descriptors.Descriptor descriptor = Lint.LintFieldNamesBad.getDescriptor(); Patch result = lintPackage(descriptor); - Assert.assertEquals(0, result.getFileResultsCount()); + Assert.assertEquals(0, result.getFilePatchesCount()); } @Test public void packageScopeVersionInvalid() throws IOException { Descriptors.Descriptor descriptor = Invalid.InvalidMessage.getDescriptor(); Patch result = lintPackage(descriptor); - FileResult fr = result.getFileResultsOrThrow("anemos/metastore/invalid/invalid.proto"); + FilePatch fr = result.getFilePatchesOrThrow("anemos/metastore/invalid/invalid.proto"); - Assert.assertEquals(1, result.getFileResultsCount()); + Assert.assertEquals(1, result.getFilePatchesCount()); assertOnFile(fr, LintRule.LINT_PACKAGE_NO_DIR_ALIGNMENT, "L70001/00"); } - private void assertOnFile(FileResult fr, LintRule expectedRule, String expectedCode) { + private void assertOnFile(FilePatch fr, LintRule expectedRule, String expectedCode) { String code = null; LintRule rule = null; for (RuleInfo ruleInfo : fr.getInfoList()) { @@ -224,17 +223,17 @@ private Patch lintPackage(Descriptors.Descriptor ref) throws IOException { public void versionScopeValid() throws IOException { Descriptors.Descriptor descriptor = VersionScopeValid.VersionValid.getDescriptor(); Patch result = lintVersion(descriptor); - Assert.assertEquals(0, result.getFileResultsCount()); + Assert.assertEquals(0, result.getFilePatchesCount()); } @Test public void versionScopeInvalid() throws IOException { Descriptors.Descriptor descriptor = VersionScopeInvalid.VersionInValid.getDescriptor(); Patch result = lintVersion(descriptor); - FileResult fr = - result.getFileResultsOrThrow("anemos/metastore/core/test/v1/version_scope_invalid.proto"); + FilePatch fr = + result.getFilePatchesOrThrow("anemos/metastore/core/test/v1/version_scope_invalid.proto"); - Assert.assertEquals(1, result.getFileResultsCount()); + Assert.assertEquals(1, result.getFilePatchesCount()); assertOnFile(fr, LintRule.LINT_PACKAGE_NO_VERSION_ALIGNMENT, "L70002/00"); } @@ -251,16 +250,16 @@ private Patch lintVersion(Descriptors.Descriptor ref) throws IOException { public void unusedImportValid() throws IOException { Descriptors.Descriptor descriptor = UsedValidImport.Valid.getDescriptor(); Patch result = lintImport(descriptor); - Assert.assertEquals(0, result.getFileResultsCount()); + Assert.assertEquals(0, result.getFilePatchesCount()); } @Test public void unusedImportInvalid() throws IOException { Descriptors.Descriptor descriptor = UnusedInvalidImport.Invalid.getDescriptor(); Patch result = lintImport(descriptor); - FileResult fr = - result.getFileResultsOrThrow("anemos/metastore/unused/invalid/unused_invalid_import.proto"); - Assert.assertEquals(1, result.getFileResultsCount()); + FilePatch fr = + result.getFilePatchesOrThrow("anemos/metastore/unused/invalid/unused_invalid_import.proto"); + Assert.assertEquals(1, result.getFilePatchesCount()); assertOnFile(fr, LintRule.LINT_IMPORT_NO_ALIGNMENT, "L80001/00"); } diff --git a/core/src/test/java/io/anemos/metastore/core/proto/validation/OptionDiffTest.java b/core/src/test/java/io/anemos/metastore/core/proto/validation/OptionDiffTest.java index 6fe1f9c..1319c96 100644 --- a/core/src/test/java/io/anemos/metastore/core/proto/validation/OptionDiffTest.java +++ b/core/src/test/java/io/anemos/metastore/core/proto/validation/OptionDiffTest.java @@ -6,8 +6,8 @@ import io.anemos.metastore.core.proto.validate.ValidationResults; import io.anemos.metastore.putils.ProtoDomain; import io.anemos.metastore.v1alpha1.ChangeType; -import io.anemos.metastore.v1alpha1.FileResult; -import io.anemos.metastore.v1alpha1.MessageResult; +import io.anemos.metastore.v1alpha1.FilePatch; +import io.anemos.metastore.v1alpha1.MessagePatch; import io.anemos.metastore.v1alpha1.OptionChangeInfo; import io.anemos.metastore.v1alpha1.Patch; import java.io.IOException; @@ -22,7 +22,7 @@ public void addMessageOptionTest() throws IOException { ProtoDomain baseAddMessageOption = TestSets.baseAddMessageOption(); ProtoDomain base = TestSets.baseKnownOption(); - MessageResult messageResult = diffMessage(base, baseAddMessageOption); + MessagePatch messageResult = diffMessage(base, baseAddMessageOption); OptionChangeInfo optionChangeInfo = messageResult.getOptionChangeList().get(0); Assert.assertEquals(ChangeType.ADDITION, optionChangeInfo.getChangeType()); @@ -37,7 +37,7 @@ public void removeMessageOptionTest() throws IOException { ProtoDomain base = TestSets.baseAddMessageOption(); ProtoDomain baseRemoveFieldOption = TestSets.baseKnownOption(); - MessageResult messageResult = diffMessage(base, baseRemoveFieldOption); + MessagePatch messageResult = diffMessage(base, baseRemoveFieldOption); OptionChangeInfo optionChangeInfo = messageResult.getOptionChangeList().get(0); Assert.assertEquals(ChangeType.REMOVAL, optionChangeInfo.getChangeType()); @@ -52,7 +52,7 @@ public void changeMessageOptionTest() throws IOException { ProtoDomain baseAddMessageOption = TestSets.baseAddMessageOption(); ProtoDomain baseChangeMessageOption = TestSets.baseChangeMessageOption(); - MessageResult messageResult = diffMessage(baseAddMessageOption, baseChangeMessageOption); + MessagePatch messageResult = diffMessage(baseAddMessageOption, baseChangeMessageOption); OptionChangeInfo optionChangeInfo = messageResult.getOptionChangeList().get(0); Assert.assertEquals(ChangeType.PAYLOAD_CHANGED, optionChangeInfo.getChangeType()); @@ -70,9 +70,9 @@ public void addFieldOptionTest() throws IOException { ProtoDomain baseAddFieldOption = TestSets.baseAddFieldOption(); ProtoDomain base = TestSets.baseKnownOption(); - MessageResult messageResult = diffMessage(base, baseAddFieldOption); + MessagePatch messageResult = diffMessage(base, baseAddFieldOption); OptionChangeInfo optionChangeInfo = - messageResult.getFieldResults(0).getOptionChangeList().get(0); + messageResult.getFieldPatches(0).getOptionChangeList().get(0); Assert.assertEquals(ChangeType.ADDITION, optionChangeInfo.getChangeType()); Assert.assertEquals(OptionChangeInfo.OptionType.FIELD_OPTION, optionChangeInfo.getType()); @@ -86,9 +86,9 @@ public void removeFieldOptionTest() throws IOException { ProtoDomain base = TestSets.baseAddFieldOption(); ProtoDomain baseRemoveFieldOption = TestSets.baseKnownOption(); - MessageResult messageResult = diffMessage(base, baseRemoveFieldOption); + MessagePatch messageResult = diffMessage(base, baseRemoveFieldOption); OptionChangeInfo optionChangeInfo = - messageResult.getFieldResults(0).getOptionChangeList().get(0); + messageResult.getFieldPatches(0).getOptionChangeList().get(0); Assert.assertEquals(ChangeType.REMOVAL, optionChangeInfo.getChangeType()); Assert.assertEquals(OptionChangeInfo.OptionType.FIELD_OPTION, optionChangeInfo.getType()); @@ -102,9 +102,9 @@ public void changeFieldOptionTest() throws IOException { ProtoDomain base = TestSets.baseAddFieldOption(); ProtoDomain baseChangeFieldOption = TestSets.baseChangeFieldOption(); - MessageResult messageResult = diffMessage(base, baseChangeFieldOption); + MessagePatch messageResult = diffMessage(base, baseChangeFieldOption); OptionChangeInfo optionChangeInfo = - messageResult.getFieldResults(0).getOptionChangeList().get(0); + messageResult.getFieldPatches(0).getOptionChangeList().get(0); Assert.assertEquals(ChangeType.PAYLOAD_CHANGED, optionChangeInfo.getChangeType()); Assert.assertEquals(OptionChangeInfo.OptionType.FIELD_OPTION, optionChangeInfo.getType()); @@ -121,7 +121,7 @@ public void addFileOptionTest() throws IOException { ProtoDomain baseAddFileOption = TestSets.baseAddFileOption(); ProtoDomain base = TestSets.baseKnownOption(); - FileResult fileResult = diffFile(base, baseAddFileOption); + FilePatch fileResult = diffFile(base, baseAddFileOption); OptionChangeInfo optionChangeInfo = fileResult.getOptionChangeList().get(0); Assert.assertEquals(ChangeType.ADDITION, optionChangeInfo.getChangeType()); @@ -136,7 +136,7 @@ public void removeFileOptionTest() throws IOException { ProtoDomain baseRemoveFileOption = TestSets.baseKnownOption(); ProtoDomain base = TestSets.baseAddFileOption(); - FileResult fileResult = diffFile(base, baseRemoveFileOption); + FilePatch fileResult = diffFile(base, baseRemoveFileOption); OptionChangeInfo optionChangeInfo = fileResult.getOptionChangeList().get(0); Assert.assertEquals(ChangeType.REMOVAL, optionChangeInfo.getChangeType()); @@ -151,7 +151,7 @@ public void changeFileOptionTest() throws IOException { ProtoDomain baseChangeFileOption = TestSets.baseChangeFileOption(); ProtoDomain base = TestSets.baseAddFileOption(); - FileResult fileResult = diffFile(base, baseChangeFileOption); + FilePatch fileResult = diffFile(base, baseChangeFileOption); OptionChangeInfo optionChangeInfo = fileResult.getOptionChangeList().get(0); Assert.assertEquals(ChangeType.PAYLOAD_CHANGED, optionChangeInfo.getChangeType()); @@ -161,23 +161,23 @@ public void changeFileOptionTest() throws IOException { Option.TestOption option = Option.TestOption.parseFrom(payload); } - private MessageResult diffMessage(ProtoDomain dRef, ProtoDomain dNew) throws IOException { + private MessagePatch diffMessage(ProtoDomain dRef, ProtoDomain dNew) throws IOException { ValidationResults results = new ValidationResults(); ProtoDiff diff = new ProtoDiff(dRef, dNew, results); diff.diffOnMessage("test.v1.ProtoBeamBasicMessage"); Patch result = results.createProto(); System.out.println(result); - return result.getMessageResultsMap().get("test.v1.ProtoBeamBasicMessage"); + return result.getMessagePatchesMap().get("test.v1.ProtoBeamBasicMessage"); } - private FileResult diffFile(ProtoDomain dRef, ProtoDomain dNew) throws IOException { + private FilePatch diffFile(ProtoDomain dRef, ProtoDomain dNew) throws IOException { ValidationResults results = new ValidationResults(); ProtoDiff diff = new ProtoDiff(dRef, dNew, results); diff.diffOnFileName("test/v1/simple.proto"); Patch result = results.createProto(); System.out.println(result); - return result.getFileResultsMap().get("test/v1/simple.proto"); + return result.getFilePatchesMap().get("test/v1/simple.proto"); } } diff --git a/core/src/test/java/io/anemos/metastore/core/proto/validation/ProtoDiffTest.java b/core/src/test/java/io/anemos/metastore/core/proto/validation/ProtoDiffTest.java index 2714fa9..bb586e5 100644 --- a/core/src/test/java/io/anemos/metastore/core/proto/validation/ProtoDiffTest.java +++ b/core/src/test/java/io/anemos/metastore/core/proto/validation/ProtoDiffTest.java @@ -153,7 +153,7 @@ public void addEnum() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); - EnumResult result = patch.getEnumResultsMap().get("package.v1.Enum2"); + EnumPatch result = patch.getEnumPatchesMap().get("package.v1.Enum2"); Assert.assertEquals("package.v1.Enum2", result.getChange().getToName()); Assert.assertEquals(ChangeType.ADDITION, result.getChange().getChangeType()); } @@ -165,7 +165,7 @@ public void removeEnum() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); - EnumResult result = patch.getEnumResultsMap().get("package.v1.Enum1"); + EnumPatch result = patch.getEnumPatchesMap().get("package.v1.Enum1"); Assert.assertEquals("package.v1.Enum1", result.getChange().getFromName()); Assert.assertEquals(ChangeType.REMOVAL, result.getChange().getChangeType()); } @@ -189,13 +189,13 @@ public void addEnumValue() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); - EnumResult result = patch.getEnumResultsMap().get("package.v1.Enum1"); + EnumPatch result = patch.getEnumPatchesMap().get("package.v1.Enum1"); Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); - Assert.assertEquals(ChangeType.ADDITION, result.getValueResults(0).getChange().getChangeType()); - Assert.assertEquals(2, result.getValueResults(0).getNumber()); - Assert.assertEquals("ENUM_VALUE1_VALUE2", result.getValueResults(0).getName()); - Assert.assertEquals("", result.getValueResults(0).getChange().getFromName()); - Assert.assertEquals("ENUM_VALUE1_VALUE2", result.getValueResults(0).getChange().getToName()); + Assert.assertEquals(ChangeType.ADDITION, result.getValuePatches(0).getChange().getChangeType()); + Assert.assertEquals(2, result.getValuePatches(0).getNumber()); + Assert.assertEquals("ENUM_VALUE1_VALUE2", result.getValuePatches(0).getName()); + Assert.assertEquals("", result.getValuePatches(0).getChange().getFromName()); + Assert.assertEquals("ENUM_VALUE1_VALUE2", result.getValuePatches(0).getChange().getToName()); } @Test @@ -209,13 +209,13 @@ public void removeEnumValue() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); - EnumResult result = patch.getEnumResultsMap().get("package.v1.Enum1"); + EnumPatch result = patch.getEnumPatchesMap().get("package.v1.Enum1"); Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); - Assert.assertEquals(ChangeType.REMOVAL, result.getValueResults(0).getChange().getChangeType()); - Assert.assertEquals(1, result.getValueResults(0).getNumber()); - Assert.assertEquals("ENUM_VALUE1_VALUE1", result.getValueResults(0).getName()); - Assert.assertEquals("ENUM_VALUE1_VALUE1", result.getValueResults(0).getChange().getFromName()); - Assert.assertEquals("", result.getValueResults(0).getChange().getToName()); + Assert.assertEquals(ChangeType.REMOVAL, result.getValuePatches(0).getChange().getChangeType()); + Assert.assertEquals(1, result.getValuePatches(0).getNumber()); + Assert.assertEquals("ENUM_VALUE1_VALUE1", result.getValuePatches(0).getName()); + Assert.assertEquals("ENUM_VALUE1_VALUE1", result.getValuePatches(0).getChange().getFromName()); + Assert.assertEquals("", result.getValuePatches(0).getChange().getToName()); } @Test @@ -234,13 +234,13 @@ public void renameEnumValue() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); - EnumResult result = patch.getEnumResultsMap().get("package.v1.Enum1"); + EnumPatch result = patch.getEnumPatchesMap().get("package.v1.Enum1"); Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); - Assert.assertEquals(ChangeType.CHANGED, result.getValueResults(0).getChange().getChangeType()); - Assert.assertEquals(1, result.getValueResults(0).getNumber()); - Assert.assertEquals("FOO", result.getValueResults(0).getName()); - Assert.assertEquals("ENUM_VALUE1_VALUE1", result.getValueResults(0).getChange().getFromName()); - Assert.assertEquals("FOO", result.getValueResults(0).getChange().getToName()); + Assert.assertEquals(ChangeType.CHANGED, result.getValuePatches(0).getChange().getChangeType()); + Assert.assertEquals(1, result.getValuePatches(0).getNumber()); + Assert.assertEquals("FOO", result.getValuePatches(0).getName()); + Assert.assertEquals("ENUM_VALUE1_VALUE1", result.getValuePatches(0).getChange().getFromName()); + Assert.assertEquals("FOO", result.getValuePatches(0).getChange().getToName()); } @Test @@ -255,7 +255,7 @@ public void addMessage() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); - MessageResult result = patch.getMessageResultsMap().get("package.v1.Message2"); + MessagePatch result = patch.getMessagePatchesMap().get("package.v1.Message2"); Assert.assertEquals("package.v1.Message2", result.getChange().getToName()); Assert.assertEquals(ChangeType.ADDITION, result.getChange().getChangeType()); } @@ -267,7 +267,7 @@ public void removeMessage() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); - MessageResult result = patch.getMessageResultsMap().get("package.v1.Message1"); + MessagePatch result = patch.getMessagePatchesMap().get("package.v1.Message1"); Assert.assertEquals("package.v1.Message1", result.getChange().getFromName()); Assert.assertEquals(ChangeType.REMOVAL, result.getChange().getChangeType()); } @@ -292,13 +292,13 @@ public void addField() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); - MessageResult result = patch.getMessageResultsMap().get("package.v1.Message1"); + MessagePatch result = patch.getMessagePatchesMap().get("package.v1.Message1"); Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); - Assert.assertEquals(ChangeType.ADDITION, result.getFieldResults(0).getChange().getChangeType()); - Assert.assertEquals(4, result.getFieldResults(0).getNumber()); - Assert.assertEquals("fourth_field", result.getFieldResults(0).getName()); - Assert.assertEquals("", result.getFieldResults(0).getChange().getFromName()); - Assert.assertEquals("fourth_field", result.getFieldResults(0).getChange().getToName()); + Assert.assertEquals(ChangeType.ADDITION, result.getFieldPatches(0).getChange().getChangeType()); + Assert.assertEquals(4, result.getFieldPatches(0).getNumber()); + Assert.assertEquals("fourth_field", result.getFieldPatches(0).getName()); + Assert.assertEquals("", result.getFieldPatches(0).getChange().getFromName()); + Assert.assertEquals("fourth_field", result.getFieldPatches(0).getChange().getToName()); } @Test @@ -312,13 +312,13 @@ public void removeField() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); - MessageResult result = patch.getMessageResultsMap().get("package.v1.Message1"); + MessagePatch result = patch.getMessagePatchesMap().get("package.v1.Message1"); Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); - Assert.assertEquals(ChangeType.REMOVAL, result.getFieldResults(0).getChange().getChangeType()); - Assert.assertEquals(1, result.getFieldResults(0).getNumber()); - Assert.assertEquals("first_field", result.getFieldResults(0).getName()); - Assert.assertEquals("first_field", result.getFieldResults(0).getChange().getFromName()); - Assert.assertEquals("", result.getFieldResults(0).getChange().getToName()); + Assert.assertEquals(ChangeType.REMOVAL, result.getFieldPatches(0).getChange().getChangeType()); + Assert.assertEquals(1, result.getFieldPatches(0).getNumber()); + Assert.assertEquals("first_field", result.getFieldPatches(0).getName()); + Assert.assertEquals("first_field", result.getFieldPatches(0).getChange().getFromName()); + Assert.assertEquals("", result.getFieldPatches(0).getChange().getToName()); } @Test @@ -339,13 +339,13 @@ public void renameField() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); - MessageResult result = patch.getMessageResultsMap().get("package.v1.Message1"); + MessagePatch result = patch.getMessagePatchesMap().get("package.v1.Message1"); Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); - Assert.assertEquals(ChangeType.CHANGED, result.getFieldResults(0).getChange().getChangeType()); - Assert.assertEquals(1, result.getFieldResults(0).getNumber()); - Assert.assertEquals("changed_field", result.getFieldResults(0).getName()); - Assert.assertEquals("first_field", result.getFieldResults(0).getChange().getFromName()); - Assert.assertEquals("changed_field", result.getFieldResults(0).getChange().getToName()); + Assert.assertEquals(ChangeType.CHANGED, result.getFieldPatches(0).getChange().getChangeType()); + Assert.assertEquals(1, result.getFieldPatches(0).getNumber()); + Assert.assertEquals("changed_field", result.getFieldPatches(0).getName()); + Assert.assertEquals("first_field", result.getFieldPatches(0).getChange().getFromName()); + Assert.assertEquals("changed_field", result.getFieldPatches(0).getChange().getToName()); } @Test @@ -372,13 +372,13 @@ public void changeFieldType() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); - MessageResult result = patch.getMessageResultsMap().get("package.v1.Message1"); + MessagePatch result = patch.getMessagePatchesMap().get("package.v1.Message1"); Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); - Assert.assertEquals(ChangeType.CHANGED, result.getFieldResults(0).getChange().getChangeType()); + Assert.assertEquals(ChangeType.CHANGED, result.getFieldPatches(0).getChange().getChangeType()); Assert.assertEquals( - "google.protobuf.StringValue", result.getFieldResults(0).getChange().getFromTypeName()); + "google.protobuf.StringValue", result.getFieldPatches(0).getChange().getFromTypeName()); Assert.assertEquals( - "google.protobuf.Int64Value", result.getFieldResults(0).getChange().getToTypeName()); + "google.protobuf.Int64Value", result.getFieldPatches(0).getChange().getToTypeName()); } @Test @@ -404,14 +404,14 @@ public void changeComplexFieldType() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); - MessageResult result = patch.getMessageResultsMap().get("package.v1.Message1"); + MessagePatch result = patch.getMessagePatchesMap().get("package.v1.Message1"); Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); - Assert.assertEquals(ChangeType.CHANGED, result.getFieldResults(0).getChange().getChangeType()); + Assert.assertEquals(ChangeType.CHANGED, result.getFieldPatches(0).getChange().getChangeType()); Assert.assertEquals( - "google.protobuf.StringValue", result.getFieldResults(0).getChange().getFromTypeName()); + "google.protobuf.StringValue", result.getFieldPatches(0).getChange().getFromTypeName()); Assert.assertEquals( FieldChangeInfo.FieldType.FIELD_TYPE_STRING, - result.getFieldResults(0).getChange().getToType()); + result.getFieldPatches(0).getChange().getToType()); } @Test @@ -438,13 +438,13 @@ public void changeMessageFieldType() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); - MessageResult result = patch.getMessageResultsMap().get("package.v1.TestSubMessage"); + MessagePatch result = patch.getMessagePatchesMap().get("package.v1.TestSubMessage"); Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); - Assert.assertEquals(ChangeType.CHANGED, result.getFieldResults(0).getChange().getChangeType()); + Assert.assertEquals(ChangeType.CHANGED, result.getFieldPatches(0).getChange().getChangeType()); Assert.assertEquals( - "google.protobuf.StringValue", result.getFieldResults(0).getChange().getFromTypeName()); + "google.protobuf.StringValue", result.getFieldPatches(0).getChange().getFromTypeName()); Assert.assertEquals( - "google.protobuf.Int64Value", result.getFieldResults(0).getChange().getToTypeName()); + "google.protobuf.Int64Value", result.getFieldPatches(0).getChange().getToTypeName()); } @Test @@ -459,7 +459,7 @@ public void addService() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); - ServiceResult serviceResult = patch.getServiceResultsMap().get("package.v1.Service2"); + ServicePatch serviceResult = patch.getServicePatchesMap().get("package.v1.Service2"); Assert.assertEquals("package.v1.Service2", serviceResult.getChange().getToName()); Assert.assertEquals(ChangeType.ADDITION, serviceResult.getChange().getChangeType()); } @@ -471,7 +471,7 @@ public void removeService() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); - ServiceResult serviceResult = patch.getServiceResultsMap().get("package.v1.Service1"); + ServicePatch serviceResult = patch.getServicePatchesMap().get("package.v1.Service1"); Assert.assertEquals("package.v1.Service1", serviceResult.getChange().getFromName()); Assert.assertEquals(ChangeType.REMOVAL, serviceResult.getChange().getChangeType()); } @@ -496,13 +496,13 @@ public void addMethod() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); - ServiceResult result = patch.getServiceResultsMap().get("package.v1.Service1"); + ServicePatch result = patch.getServicePatchesMap().get("package.v1.Service1"); Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); Assert.assertEquals( - ChangeType.ADDITION, result.getMethodResults(0).getChange().getChangeType()); - Assert.assertEquals("Method2", result.getMethodResults(0).getName()); - Assert.assertEquals("", result.getMethodResults(0).getChange().getFromName()); - Assert.assertEquals("Method2", result.getMethodResults(0).getChange().getToName()); + ChangeType.ADDITION, result.getMethodPatches(0).getChange().getChangeType()); + Assert.assertEquals("Method2", result.getMethodPatches(0).getName()); + Assert.assertEquals("", result.getMethodPatches(0).getChange().getFromName()); + Assert.assertEquals("Method2", result.getMethodPatches(0).getChange().getToName()); } @Test @@ -516,12 +516,12 @@ public void removeMethod() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); - ServiceResult result = patch.getServiceResultsMap().get("package.v1.Service1"); + ServicePatch result = patch.getServicePatchesMap().get("package.v1.Service1"); Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); - Assert.assertEquals(ChangeType.REMOVAL, result.getMethodResults(0).getChange().getChangeType()); - Assert.assertEquals("Method1", result.getMethodResults(0).getName()); - Assert.assertEquals("Method1", result.getMethodResults(0).getChange().getFromName()); - Assert.assertEquals("", result.getMethodResults(0).getChange().getToName()); + Assert.assertEquals(ChangeType.REMOVAL, result.getMethodPatches(0).getChange().getChangeType()); + Assert.assertEquals("Method1", result.getMethodPatches(0).getName()); + Assert.assertEquals("Method1", result.getMethodPatches(0).getChange().getFromName()); + Assert.assertEquals("", result.getMethodPatches(0).getChange().getToName()); } @Test @@ -541,19 +541,19 @@ public void renameMethod() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); - ServiceResult result = patch.getServiceResultsMap().get("package.v1.Service1"); + ServicePatch result = patch.getServicePatchesMap().get("package.v1.Service1"); Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); Assert.assertEquals( - ChangeType.ADDITION, result.getMethodResults(0).getChange().getChangeType()); - Assert.assertEquals("MethodX", result.getMethodResults(0).getName()); - Assert.assertEquals("", result.getMethodResults(0).getChange().getFromName()); - Assert.assertEquals("MethodX", result.getMethodResults(0).getChange().getToName()); - - Assert.assertEquals(ChangeType.REMOVAL, result.getMethodResults(1).getChange().getChangeType()); - Assert.assertEquals("Method1", result.getMethodResults(1).getName()); - Assert.assertEquals("Method1", result.getMethodResults(1).getChange().getFromName()); - Assert.assertEquals("", result.getMethodResults(1).getChange().getToName()); + ChangeType.ADDITION, result.getMethodPatches(0).getChange().getChangeType()); + Assert.assertEquals("MethodX", result.getMethodPatches(0).getName()); + Assert.assertEquals("", result.getMethodPatches(0).getChange().getFromName()); + Assert.assertEquals("MethodX", result.getMethodPatches(0).getChange().getToName()); + + Assert.assertEquals(ChangeType.REMOVAL, result.getMethodPatches(1).getChange().getChangeType()); + Assert.assertEquals("Method1", result.getMethodPatches(1).getName()); + Assert.assertEquals("Method1", result.getMethodPatches(1).getChange().getFromName()); + Assert.assertEquals("", result.getMethodPatches(1).getChange().getToName()); } private Patch diff(ProtoDomain dRef, ProtoDomain dNew) throws IOException { diff --git a/proto/src/main/proto/grpc/registry/v1alpha1/patch.proto b/proto/src/main/proto/grpc/registry/v1alpha1/patch.proto index e7dc4b0..e8d2921 100644 --- a/proto/src/main/proto/grpc/registry/v1alpha1/patch.proto +++ b/proto/src/main/proto/grpc/registry/v1alpha1/patch.proto @@ -13,10 +13,10 @@ message Report { } message Patch { - map file_results = 1; - map message_results = 2; - map enum_results = 3; - map service_results = 4; + map file_patches = 1; + map message_patches = 2; + map enum_patches = 3; + map service_patches = 4; } message ResultCount { @@ -86,7 +86,7 @@ message ImportChangeInfo { string name = 2; } -message FileResult { +message FilePatch { string file_name = 1; repeated string message_result_ref = 2; @@ -98,7 +98,7 @@ message FileResult { repeated OptionChangeInfo option_change = 10; } -message MessageResult { +message MessagePatch { string package = 1; string name = 2; @@ -107,12 +107,12 @@ message MessageResult { ChangeInfo change = 4; - repeated FieldResult field_results = 5; + repeated FieldPatch field_patches = 5; repeated OptionChangeInfo option_change = 10; } -message FieldResult { +message FieldPatch { int32 number = 1; string name = 2; @@ -205,7 +205,7 @@ message MethodChangeInfo { } -message ServiceResult { +message ServicePatch { string package = 1; string name = 2; @@ -213,10 +213,10 @@ message ServiceResult { ChangeInfo change = 4; - repeated MethodResult method_results = 5; + repeated MethodPatch method_patches = 5; } -message MethodResult { +message MethodPatch { string name = 2; repeated RuleInfo info = 3; @@ -224,7 +224,7 @@ message MethodResult { MethodChangeInfo change = 4; } -message EnumResult { +message EnumPatch { string package = 1; string name = 2; @@ -232,10 +232,10 @@ message EnumResult { ChangeInfo change = 4; - repeated EnumValueResult value_results = 5; + repeated EnumValuePatch value_patches = 5; } -message EnumValueResult { +message EnumValuePatch { int32 number = 1; string name = 2; diff --git a/server/src/test/java/io/anemos/metastore/server/ShadowE2ETest.java b/server/src/test/java/io/anemos/metastore/server/ShadowE2ETest.java index c215447..048766e 100644 --- a/server/src/test/java/io/anemos/metastore/server/ShadowE2ETest.java +++ b/server/src/test/java/io/anemos/metastore/server/ShadowE2ETest.java @@ -143,8 +143,8 @@ public void shadowE2ELocalFileProvider() throws Exception { Report.parseFrom( new FileInputStream(metastorePath.toAbsolutePath().toString() + "/shadow.pb")); Assert.assertEquals( - expectedResults.createProto().getMessageResultsMap(), - actualShadowReport.getPatch().getMessageResultsMap()); + expectedResults.createProto().getMessagePatchesMap(), + actualShadowReport.getPatch().getMessagePatchesMap()); // add field to default RegistryP.SubmitSchemaRequest.Builder submitDefaultAddField = @@ -164,9 +164,9 @@ public void shadowE2ELocalFileProvider() throws Exception { verifyDefaultResponse2 .getReport() .getPatch() - .getMessageResultsMap() + .getMessagePatchesMap() .get("test.v1.ProtoBeamBasicMessage") - .getFieldResults(0) + .getFieldPatches(0) .getChange() .getChangeType()); @@ -176,8 +176,8 @@ public void shadowE2ELocalFileProvider() throws Exception { Report.parseFrom( new FileInputStream(metastorePath.toAbsolutePath().toString() + "/shadow.pb")); Assert.assertEquals( - expectedResults.createProto().getMessageResultsMap(), - actualShadowReport.getPatch().getMessageResultsMap()); + expectedResults.createProto().getMessagePatchesMap(), + actualShadowReport.getPatch().getMessagePatchesMap()); actualShadowRepo = ProtocUtil.createDescriptorSet(shadowrepoPath.toAbsolutePath().toString()); Assert.assertEquals( From 61a456d0b24574f5c6724079aca7a1a528d3f065 Mon Sep 17 00:00:00 2001 From: Alex Van Boxel Date: Fri, 10 Apr 2020 15:49:20 +0200 Subject: [PATCH 05/11] Changed ChangeInfo to Change --- .../core/proto/validate/ProtoDiff.java | 145 +++++++++--------- .../proto/validate/ValidationResults.java | 88 +++++------ .../metastore/core/registry/ShadowApply.java | 16 +- .../core/proto/validation/DiffTest.java | 20 +-- .../core/proto/validation/OptionDiffTest.java | 81 +++++----- .../core/proto/validation/ProtoDiffTest.java | 3 +- .../proto/grpc/registry/v1alpha1/patch.proto | 38 ++--- 7 files changed, 192 insertions(+), 199 deletions(-) diff --git a/core/src/main/java/io/anemos/metastore/core/proto/validate/ProtoDiff.java b/core/src/main/java/io/anemos/metastore/core/proto/validate/ProtoDiff.java index f3130bd..8a5f157 100644 --- a/core/src/main/java/io/anemos/metastore/core/proto/validate/ProtoDiff.java +++ b/core/src/main/java/io/anemos/metastore/core/proto/validate/ProtoDiff.java @@ -8,13 +8,13 @@ import com.google.protobuf.Message; import com.google.protobuf.UnknownFieldSet; import io.anemos.metastore.putils.ProtoDomain; -import io.anemos.metastore.v1alpha1.ChangeInfo; +import io.anemos.metastore.v1alpha1.Change; import io.anemos.metastore.v1alpha1.ChangeType; -import io.anemos.metastore.v1alpha1.EnumValueChangeInfo; -import io.anemos.metastore.v1alpha1.FieldChangeInfo; -import io.anemos.metastore.v1alpha1.ImportChangeInfo; -import io.anemos.metastore.v1alpha1.MethodChangeInfo; -import io.anemos.metastore.v1alpha1.OptionChangeInfo; +import io.anemos.metastore.v1alpha1.EnumValueChange; +import io.anemos.metastore.v1alpha1.FieldChange; +import io.anemos.metastore.v1alpha1.ImportChange; +import io.anemos.metastore.v1alpha1.MethodChange; +import io.anemos.metastore.v1alpha1.OptionChange; import java.io.IOException; import java.nio.ByteBuffer; import java.util.ArrayList; @@ -116,7 +116,7 @@ private void diffFileDescriptor( .map(Descriptors.FileDescriptor::getFullName) .collect(Collectors.toList()); } else { - results.setPatch(fdNew, ChangeInfo.newBuilder().setChangeType(ChangeType.ADDITION).build()); + results.setPatch(fdNew, Change.newBuilder().setChangeType(ChangeType.ADDITION).build()); refDescriptors = new ArrayList<>(0); refEnumDescriptors = new ArrayList<>(0); refServiceDescriptors = new ArrayList<>(0); @@ -133,7 +133,7 @@ private void diffFileDescriptor( .map(Descriptors.FileDescriptor::getFullName) .collect(Collectors.toList()); } else { - results.setPatch(fdRef, ChangeInfo.newBuilder().setChangeType(ChangeType.REMOVAL).build()); + results.setPatch(fdRef, Change.newBuilder().setChangeType(ChangeType.REMOVAL).build()); newDescriptors = new ArrayList<>(0); newEnumDescriptors = new ArrayList<>(0); newServiceDescriptors = new ArrayList<>(0); @@ -201,10 +201,7 @@ private void diffImports(String fullFileName, List c_ref, List c v -> { results.addImportChange( fullFileName, - ImportChangeInfo.newBuilder() - .setChangeType(ChangeType.REMOVAL) - .setName(v) - .build()); + ImportChange.newBuilder().setChangeType(ChangeType.REMOVAL).setName(v).build()); }); onlyInLeft(m_new, m_ref) @@ -212,7 +209,7 @@ private void diffImports(String fullFileName, List c_ref, List c v -> results.addImportChange( fullFileName, - ImportChangeInfo.newBuilder() + ImportChange.newBuilder() .setChangeType(ChangeType.ADDITION) .setName(v) .build())); @@ -245,14 +242,14 @@ private void diffMessageTypes( d -> results.setPatch( d, - ChangeInfo.newBuilder() + Change.newBuilder() .setChangeType(ChangeType.REMOVAL) .setFromName(d.getFullName()) .build()), d -> results.setPatch( d, - ChangeInfo.newBuilder() + Change.newBuilder() .setChangeType(ChangeType.ADDITION) .setToName(d.getFullName()) .build()), @@ -270,7 +267,7 @@ private void diffFiles( Descriptors.FileDescriptor fd = m_ref.get(k); results.setPatch( fd, - ChangeInfo.newBuilder() + Change.newBuilder() .setChangeType(ChangeType.REMOVAL) .setFromName(fd.getName()) .build()); @@ -283,7 +280,7 @@ private void diffFiles( Descriptors.FileDescriptor fd = m_new.get(k); results.setPatch( fd, - ChangeInfo.newBuilder() + Change.newBuilder() .setChangeType(ChangeType.ADDITION) .setToName(fd.getName()) .build()); @@ -299,13 +296,13 @@ private void diffMessageType( DescriptorProtos.MessageOptions optionsRef = descriptorRef.getOptions(); DescriptorProtos.MessageOptions optionsNew = descriptorNew.getOptions(); diffExtensionOptions( - OptionChangeInfo.OptionType.MESSAGE_OPTION, + OptionChange.OptionType.MESSAGE_OPTION, descriptorRef, optionsRef.getAllFields(), descriptorNew, optionsNew.getAllFields()); diffUnknownOptions( - OptionChangeInfo.OptionType.MESSAGE_OPTION, + OptionChange.OptionType.MESSAGE_OPTION, descriptorRef, optionsRef.getUnknownFields(), descriptorNew, @@ -321,8 +318,8 @@ private void diffFields(Descriptors.Descriptor d_ref, Descriptors.Descriptor d_n onlyRef.forEach( k -> { Descriptors.FieldDescriptor fd = m_ref.get(k); - FieldChangeInfo.Builder builder = - FieldChangeInfo.newBuilder() + FieldChange.Builder builder = + FieldChange.newBuilder() .setChangeType(ChangeType.REMOVAL) .setFromName(fd.getName()) .setFromTypeValue(fd.getType().toProto().getNumber()) @@ -340,8 +337,8 @@ private void diffFields(Descriptors.Descriptor d_ref, Descriptors.Descriptor d_n onlyNew.forEach( k -> { Descriptors.FieldDescriptor fd = m_new.get(k); - FieldChangeInfo.Builder builder = - FieldChangeInfo.newBuilder() + FieldChange.Builder builder = + FieldChange.newBuilder() .setChangeType(ChangeType.ADDITION) .setToName(fd.getName()) .setToTypeValue(fd.getType().toProto().getNumber()) @@ -358,17 +355,17 @@ private void diffFields(Descriptors.Descriptor d_ref, Descriptors.Descriptor d_n Set common = onlyInCommon(m_new, m_ref); common.forEach( k -> { - FieldChangeInfo fieldDiff = diffField(m_ref.get(k), m_new.get(k)); + FieldChange fieldDiff = diffField(m_ref.get(k), m_new.get(k)); if (fieldDiff != null) { results.setPatch(m_new.get(k), fieldDiff); } }); } - private FieldChangeInfo diffField( + private FieldChange diffField( Descriptors.FieldDescriptor f_ref, Descriptors.FieldDescriptor f_new) { diffOptionsFromField(f_ref, f_new); - FieldChangeInfo.Builder builder = FieldChangeInfo.newBuilder(); + FieldChange.Builder builder = FieldChange.newBuilder(); if (!f_ref.getName().equals(f_new.getName())) { builder.setChangeType(ChangeType.CHANGED); @@ -412,14 +409,14 @@ private void diffServices( d -> results.setPatch( d, - ChangeInfo.newBuilder() + Change.newBuilder() .setChangeType(ChangeType.REMOVAL) .setFromName(d.getFullName()) .build()), d -> results.setPatch( d, - ChangeInfo.newBuilder() + Change.newBuilder() .setChangeType(ChangeType.ADDITION) .setToName(d.getFullName()) .build()), @@ -431,13 +428,13 @@ private void diffServiceDescriptor( DescriptorProtos.ServiceOptions optionsRef = descriptorRef.getOptions(); DescriptorProtos.ServiceOptions optionsNew = descriptorNew.getOptions(); diffExtensionOptions( - OptionChangeInfo.OptionType.SERVICE_OPTION, + OptionChange.OptionType.SERVICE_OPTION, descriptorRef, optionsRef.getAllFields(), descriptorNew, optionsNew.getAllFields()); diffUnknownOptions( - OptionChangeInfo.OptionType.SERVICE_OPTION, + OptionChange.OptionType.SERVICE_OPTION, descriptorRef, optionsRef.getUnknownFields(), descriptorNew, @@ -455,14 +452,14 @@ private void diffMethods( k -> { Descriptors.MethodDescriptor fd = m_ref.get(k); - MethodChangeInfo.Builder builder = - MethodChangeInfo.newBuilder() + MethodChange.Builder builder = + MethodChange.newBuilder() .setChangeType(ChangeType.REMOVAL) .setFromName(fd.getName()) .setFromDeprecated(isDeprecated(fd)); // if (d_new.isReservedNumber(fd.getNumber())) { // - // builder.setChangeType(EnumValueChangeInfo.ValueChangeType.VALUE_RESERVED); + // builder.setChangeType(EnumValueChange.ValueChangeType.VALUE_RESERVED); // if (d_new.isReservedName(fd.getName())) { // builder.setToName(fd.getName()); // } @@ -474,14 +471,14 @@ private void diffMethods( onlyNew.forEach( k -> { Descriptors.MethodDescriptor fd = m_new.get(k); - MethodChangeInfo.Builder builder = - MethodChangeInfo.newBuilder() + MethodChange.Builder builder = + MethodChange.newBuilder() .setChangeType(ChangeType.ADDITION) .setToName(fd.getName()) .setToDeprecated(isDeprecated(fd)); // if (d_ref.isReservedNumber(fd.getNumber())) { // - // builder.setChangeType(EnumValueChangeInfo.ValueChangeType.VALUE_UNRESERVED); + // builder.setChangeType(EnumValueChange.ValueChangeType.VALUE_UNRESERVED); // if (d_ref.isReservedName(fd.getName())) { // builder.setFromName(fd.getName()); // } @@ -492,17 +489,17 @@ private void diffMethods( Set common = onlyInCommon(m_new, m_ref); common.forEach( k -> { - MethodChangeInfo fieldDiff = diffMethod(m_ref.get(k), m_new.get(k)); + MethodChange fieldDiff = diffMethod(m_ref.get(k), m_new.get(k)); if (fieldDiff != null) { results.setPatch(m_new.get(k), fieldDiff); } }); } - private MethodChangeInfo diffMethod( + private MethodChange diffMethod( Descriptors.MethodDescriptor f_ref, Descriptors.MethodDescriptor f_new) { diffOptionsFromMethod(f_ref, f_new); - MethodChangeInfo.Builder builder = MethodChangeInfo.newBuilder(); + MethodChange.Builder builder = MethodChange.newBuilder(); if (!f_ref.getName().equals(f_new.getName())) { builder.setChangeType(ChangeType.CHANGED); @@ -529,14 +526,14 @@ private void diffEnumTypes( d -> results.setPatch( d, - ChangeInfo.newBuilder() + Change.newBuilder() .setChangeType(ChangeType.REMOVAL) .setFromName(d.getFullName()) .build()), d -> results.setPatch( d, - ChangeInfo.newBuilder() + Change.newBuilder() .setChangeType(ChangeType.ADDITION) .setToName(d.getFullName()) .build()), @@ -548,13 +545,13 @@ private void diffEnumDescriptor( DescriptorProtos.EnumOptions optionsRef = descriptorRef.getOptions(); DescriptorProtos.EnumOptions optionsNew = descriptorNew.getOptions(); diffExtensionOptions( - OptionChangeInfo.OptionType.ENUM_OPTION, + OptionChange.OptionType.ENUM_OPTION, descriptorRef, optionsRef.getAllFields(), descriptorNew, optionsNew.getAllFields()); diffUnknownOptions( - OptionChangeInfo.OptionType.ENUM_OPTION, + OptionChange.OptionType.ENUM_OPTION, descriptorRef, optionsRef.getUnknownFields(), descriptorNew, @@ -573,14 +570,14 @@ private void diffEnumValues(Descriptors.EnumDescriptor d_ref, Descriptors.EnumDe k -> { Descriptors.EnumValueDescriptor fd = m_ref.get(k); - EnumValueChangeInfo.Builder builder = - EnumValueChangeInfo.newBuilder() + EnumValueChange.Builder builder = + EnumValueChange.newBuilder() .setChangeType(ChangeType.REMOVAL) .setFromName(fd.getName()) .setFromDeprecated(isDeprecated(fd)); // if (d_new.isReservedNumber(fd.getNumber())) { // - // builder.setChangeType(EnumValueChangeInfo.ValueChangeType.VALUE_RESERVED); + // builder.setChangeType(EnumValueChange.ValueChangeType.VALUE_RESERVED); // if (d_new.isReservedName(fd.getName())) { // builder.setToName(fd.getName()); // } @@ -592,14 +589,14 @@ private void diffEnumValues(Descriptors.EnumDescriptor d_ref, Descriptors.EnumDe onlyNew.forEach( k -> { Descriptors.EnumValueDescriptor fd = m_new.get(k); - EnumValueChangeInfo.Builder builder = - EnumValueChangeInfo.newBuilder() + EnumValueChange.Builder builder = + EnumValueChange.newBuilder() .setChangeType(ChangeType.ADDITION) .setToName(fd.getName()) .setToDeprecated(isDeprecated(fd)); // if (d_ref.isReservedNumber(fd.getNumber())) { // - // builder.setChangeType(EnumValueChangeInfo.ValueChangeType.VALUE_UNRESERVED); + // builder.setChangeType(EnumValueChange.ValueChangeType.VALUE_UNRESERVED); // if (d_ref.isReservedName(fd.getName())) { // builder.setFromName(fd.getName()); // } @@ -610,17 +607,17 @@ private void diffEnumValues(Descriptors.EnumDescriptor d_ref, Descriptors.EnumDe Set common = onlyInCommon(m_new, m_ref); common.forEach( k -> { - EnumValueChangeInfo fieldDiff = diffEnumValue(m_ref.get(k), m_new.get(k)); + EnumValueChange fieldDiff = diffEnumValue(m_ref.get(k), m_new.get(k)); if (fieldDiff != null) { results.setPatch(m_new.get(k), fieldDiff); } }); } - private EnumValueChangeInfo diffEnumValue( + private EnumValueChange diffEnumValue( Descriptors.EnumValueDescriptor f_ref, Descriptors.EnumValueDescriptor f_new) { diffOptionsFromEnumValue(f_ref, f_new); - EnumValueChangeInfo.Builder builder = EnumValueChangeInfo.newBuilder(); + EnumValueChange.Builder builder = EnumValueChange.newBuilder(); if (!f_ref.getName().equals(f_new.getName())) { builder.setChangeType(ChangeType.CHANGED); @@ -685,7 +682,7 @@ private boolean isDeprecated(Descriptors.MethodDescriptor fieldDescriptor) { } private void diffUnknownOptions( - OptionChangeInfo.OptionType changeType, + OptionChange.OptionType changeType, Descriptors.GenericDescriptor descriptorRef, UnknownFieldSet unknownFieldSetRef, Descriptors.GenericDescriptor descriptorNew, @@ -699,8 +696,8 @@ private void diffUnknownOptions( optionNumber -> { UnknownFieldSet.Field field = fieldsRef.get(optionNumber); ByteString payload = serializeUnknownField(optionNumber, field); - OptionChangeInfo.Builder builder = - OptionChangeInfo.newBuilder() + OptionChange.Builder builder = + OptionChange.newBuilder() .setChangeType(ChangeType.REMOVAL) .setType(changeType) .setOptionNumber(optionNumber) @@ -713,8 +710,8 @@ private void diffUnknownOptions( optionNumber -> { UnknownFieldSet.Field field = fieldsNew.get(optionNumber); ByteString payload = serializeUnknownField(optionNumber, field); - OptionChangeInfo.Builder builder = - OptionChangeInfo.newBuilder() + OptionChange.Builder builder = + OptionChange.newBuilder() .setChangeType(ChangeType.ADDITION) .setType(changeType) .setOptionNumber(optionNumber) @@ -731,8 +728,8 @@ private void diffUnknownOptions( ByteString payloadOld = serializeUnknownField(optionNumber, fieldOld); ByteString payloadNew = serializeUnknownField(optionNumber, fieldNew); if (!payloadOld.equals(payloadNew)) { - OptionChangeInfo.Builder builder = - OptionChangeInfo.newBuilder() + OptionChange.Builder builder = + OptionChange.newBuilder() .setChangeType(ChangeType.PAYLOAD_CHANGED) .setType(changeType) .setPayloadOld(payloadOld) @@ -744,7 +741,7 @@ private void diffUnknownOptions( } private void diffExtensionOptions( - OptionChangeInfo.OptionType changeType, + OptionChange.OptionType changeType, Descriptors.GenericDescriptor descriptorRef, Map optionFieldMapRef, Descriptors.GenericDescriptor descriptorNew, @@ -774,8 +771,8 @@ private void diffExtensionOptions( optionNumber -> { Message field = fieldsRef.get(optionNumber); ByteString payload = serializePayload(field); - OptionChangeInfo.Builder builder = - OptionChangeInfo.newBuilder() + OptionChange.Builder builder = + OptionChange.newBuilder() .setChangeType(ChangeType.REMOVAL) .setType(changeType) .setOptionNumber(optionNumber) @@ -788,8 +785,8 @@ private void diffExtensionOptions( optionNumber -> { Message field = fieldsNew.get(optionNumber); ByteString payload = serializePayload(field); - OptionChangeInfo.Builder builder = - OptionChangeInfo.newBuilder() + OptionChange.Builder builder = + OptionChange.newBuilder() .setChangeType(ChangeType.ADDITION) .setType(changeType) .setOptionNumber(optionNumber) @@ -805,8 +802,8 @@ private void diffExtensionOptions( ByteString payloadRef = serializePayload(fieldRef); ByteString payloadNew = serializePayload(fieldNew); if (!payloadRef.equals(payloadNew)) { - OptionChangeInfo.Builder builder = - OptionChangeInfo.newBuilder() + OptionChange.Builder builder = + OptionChange.newBuilder() .setChangeType(ChangeType.PAYLOAD_CHANGED) .setType(changeType) .setOptionNumber(optionNumber) @@ -822,13 +819,13 @@ private void diffOptionsFromFile( DescriptorProtos.FileOptions optionsRef = descriptorRef.getOptions(); DescriptorProtos.FileOptions optionsNew = descriptorNew.getOptions(); diffExtensionOptions( - OptionChangeInfo.OptionType.FILE_OPTION, + OptionChange.OptionType.FILE_OPTION, descriptorRef, optionsRef.getAllFields(), descriptorNew, optionsNew.getAllFields()); diffUnknownOptions( - OptionChangeInfo.OptionType.FILE_OPTION, + OptionChange.OptionType.FILE_OPTION, descriptorRef, optionsRef.getUnknownFields(), descriptorNew, @@ -840,13 +837,13 @@ private void diffOptionsFromField( DescriptorProtos.FieldOptions optionsRef = descriptorRef.getOptions(); DescriptorProtos.FieldOptions optionsNew = descriptorNew.getOptions(); diffExtensionOptions( - OptionChangeInfo.OptionType.FIELD_OPTION, + OptionChange.OptionType.FIELD_OPTION, descriptorRef, optionsRef.getAllFields(), descriptorNew, optionsNew.getAllFields()); diffUnknownOptions( - OptionChangeInfo.OptionType.FIELD_OPTION, + OptionChange.OptionType.FIELD_OPTION, descriptorRef, optionsRef.getUnknownFields(), descriptorNew, @@ -859,13 +856,13 @@ private void diffOptionsFromEnumValue( DescriptorProtos.EnumValueOptions optionsRef = descriptorRef.getOptions(); DescriptorProtos.EnumValueOptions optionsNew = descriptorNew.getOptions(); diffExtensionOptions( - OptionChangeInfo.OptionType.ENUM_VALUE_OPTION, + OptionChange.OptionType.ENUM_VALUE_OPTION, descriptorRef, optionsRef.getAllFields(), descriptorNew, optionsNew.getAllFields()); diffUnknownOptions( - OptionChangeInfo.OptionType.ENUM_VALUE_OPTION, + OptionChange.OptionType.ENUM_VALUE_OPTION, descriptorRef, optionsRef.getUnknownFields(), descriptorNew, @@ -877,13 +874,13 @@ private void diffOptionsFromMethod( DescriptorProtos.MethodOptions optionsRef = descriptorRef.getOptions(); DescriptorProtos.MethodOptions optionsNew = descriptorNew.getOptions(); diffExtensionOptions( - OptionChangeInfo.OptionType.METHOD_OPTION, + OptionChange.OptionType.METHOD_OPTION, descriptorRef, optionsRef.getAllFields(), descriptorNew, optionsNew.getAllFields()); diffUnknownOptions( - OptionChangeInfo.OptionType.METHOD_OPTION, + OptionChange.OptionType.METHOD_OPTION, descriptorRef, optionsRef.getUnknownFields(), descriptorNew, diff --git a/core/src/main/java/io/anemos/metastore/core/proto/validate/ValidationResults.java b/core/src/main/java/io/anemos/metastore/core/proto/validate/ValidationResults.java index 7db2e69..cd75451 100644 --- a/core/src/main/java/io/anemos/metastore/core/proto/validate/ValidationResults.java +++ b/core/src/main/java/io/anemos/metastore/core/proto/validate/ValidationResults.java @@ -97,42 +97,42 @@ void addResult(Descriptors.FileDescriptor descriptor, RuleInfo ruleInfo) { fileResult.addResult(ruleInfo); } - void setPatch(Descriptors.FieldDescriptor fd, FieldChangeInfo patch) { + void setPatch(Descriptors.FieldDescriptor fd, FieldChange patch) { MessagePatchContainer resultContainer = getOrCreateMessage(fd.getContainingType()); resultContainer.addPatch(fd, patch); } - void setPatch(Descriptors.MethodDescriptor fd, MethodChangeInfo patch) { + void setPatch(Descriptors.MethodDescriptor fd, MethodChange patch) { ServicePatchContainer resultContainer = getOrCreateService(fd.getService()); resultContainer.addPatch(fd, patch); } - void setPatch(Descriptors.EnumValueDescriptor fd, EnumValueChangeInfo patch) { + void setPatch(Descriptors.EnumValueDescriptor fd, EnumValueChange patch) { EnumPatchContainer resultContainer = getOrCreateEnum(fd.getType()); resultContainer.addPatch(fd, patch); } - void setPatch(Descriptors.Descriptor fd, ChangeInfo patch) { + void setPatch(Descriptors.Descriptor fd, Change patch) { MessagePatchContainer resultContainer = getOrCreateMessage(fd); resultContainer.setPatch(patch); } - void setPatch(Descriptors.FileDescriptor fd, ChangeInfo patch) { + void setPatch(Descriptors.FileDescriptor fd, Change patch) { FilePatchContainer resultContainer = getOrCreateFile(fd.getFullName()); resultContainer.setPatch(patch); } - void setPatch(Descriptors.EnumDescriptor fd, ChangeInfo patch) { + void setPatch(Descriptors.EnumDescriptor fd, Change patch) { EnumPatchContainer resultContainer = getOrCreateEnum(fd); resultContainer.setPatch(patch); } - void setPatch(Descriptors.ServiceDescriptor fd, ChangeInfo patch) { + void setPatch(Descriptors.ServiceDescriptor fd, Change patch) { ServicePatchContainer serviceResult = getOrCreateService(fd); serviceResult.setPatch(patch); } - void addOptionChange(Descriptors.GenericDescriptor descriptor, OptionChangeInfo info) { + void addOptionChange(Descriptors.GenericDescriptor descriptor, OptionChange info) { if (descriptor instanceof Descriptors.FileDescriptor) { FilePatchContainer fileResultContainer = getOrCreateFile(descriptor.getFullName()); fileResultContainer.addOptionChange(info); @@ -149,7 +149,7 @@ void addOptionChange(Descriptors.GenericDescriptor descriptor, OptionChangeInfo } } - void addImportChange(String fullName, ImportChangeInfo info) { + void addImportChange(String fullName, ImportChange info) { FilePatchContainer fileResultContainer = getOrCreateFile(fullName); fileResultContainer.addImportChange(info); } @@ -170,8 +170,8 @@ public Patch createProto() { static class FieldPatchContainer { List info = new ArrayList<>(); - List optionChangeInfos = new ArrayList<>(); - FieldChangeInfo patch; + List optionChanges = new ArrayList<>(); + FieldChange patch; String name; int number; @@ -185,19 +185,19 @@ public FieldPatch createProto() { .setName(name) .setNumber(number) .addAllInfo(info) - .addAllOptionChange(optionChangeInfos); + .addAllOptionChange(optionChanges); if (patch != null) { builder.setChange(patch); } return builder.build(); } - void addPatch(FieldChangeInfo patch) { + void addPatch(FieldChange patch) { this.patch = patch; } - void addOptionChange(OptionChangeInfo optionChangeInfo) { - this.optionChangeInfos.add(optionChangeInfo); + void addOptionChange(OptionChange optionChange) { + this.optionChanges.add(optionChange); } } @@ -207,15 +207,15 @@ static class MessagePatchContainer { List info = new ArrayList<>(); Map fieldMap = new HashMap<>(); - ChangeInfo patch; - List optionChangeInfos = new ArrayList<>(); + Change patch; + List optionChanges = new ArrayList<>(); public void add(Descriptors.FieldDescriptor field, RuleInfo ruleInfo) { FieldPatchContainer fieldResultContainer = getOrCreateFieldContainer(field); fieldResultContainer.add(ruleInfo); } - void addPatch(Descriptors.FieldDescriptor field, FieldChangeInfo patch) { + void addPatch(Descriptors.FieldDescriptor field, FieldChange patch) { FieldPatchContainer fieldResultContainer = getOrCreateFieldContainer(field); fieldResultContainer.addPatch(patch); } @@ -240,7 +240,7 @@ MessagePatch createProto() { } fieldMap.values().forEach(field -> messageInfo.addFieldPatches(field.createProto())); messageInfo.addAllInfo(info); - messageInfo.addAllOptionChange(optionChangeInfos); + messageInfo.addAllOptionChange(optionChanges); return messageInfo.build(); } @@ -248,17 +248,17 @@ void addResult(RuleInfo ruleInfo) { info.add(ruleInfo); } - void setPatch(ChangeInfo patch) { + void setPatch(Change patch) { this.patch = patch; } - void addOptionChange(OptionChangeInfo info) { - optionChangeInfos.add(info); + void addOptionChange(OptionChange info) { + optionChanges.add(info); } - void addOptionChange(Descriptors.FieldDescriptor field, OptionChangeInfo optionChangeInfo) { + void addOptionChange(Descriptors.FieldDescriptor field, OptionChange optionChange) { FieldPatchContainer fieldResultContainer = getOrCreateFieldContainer(field); - fieldResultContainer.addOptionChange(optionChangeInfo); + fieldResultContainer.addOptionChange(optionChange); } } @@ -267,11 +267,11 @@ class FilePatchContainer { List info = new ArrayList<>(); // Map fieldMap = new HashMap<>(); - ChangeInfo patch; - List optionChangeInfos = new ArrayList<>(); - List importChangeInfo = new ArrayList<>(); + Change patch; + List optionChanges = new ArrayList<>(); + List importChange = new ArrayList<>(); - void setPatch(ChangeInfo patch) { + void setPatch(Change patch) { this.patch = patch; } @@ -281,8 +281,8 @@ public FilePatch createProto() { FilePatch.newBuilder() .setFileName(fullName) .addAllInfo(info) - .addAllOptionChange(optionChangeInfos) - .addAllImportChange(importChangeInfo); + .addAllOptionChange(optionChanges) + .addAllImportChange(importChange); if (patch != null) { builder.setChange(patch); } @@ -293,12 +293,12 @@ void addResult(RuleInfo ruleInfo) { info.add(ruleInfo); } - void addOptionChange(OptionChangeInfo optionChangeInfo) { - this.optionChangeInfos.add(optionChangeInfo); + void addOptionChange(OptionChange optionChange) { + this.optionChanges.add(optionChange); } - void addImportChange(ImportChangeInfo changeInfo) { - this.importChangeInfo.add(changeInfo); + void addImportChange(ImportChange changeInfo) { + this.importChange.add(changeInfo); } } @@ -308,14 +308,14 @@ class ServicePatchContainer { List info = new ArrayList<>(); Map methodMap = new HashMap<>(); - ChangeInfo patch; + Change patch; public void add(Descriptors.MethodDescriptor method, RuleInfo ruleInfo) { MethodPatchContainer methoddResultContainer = getOrCreateMethodContainer(method); methoddResultContainer.add(ruleInfo); } - public void addPatch(Descriptors.MethodDescriptor method, MethodChangeInfo patch) { + public void addPatch(Descriptors.MethodDescriptor method, MethodChange patch) { MethodPatchContainer methodResultContainer = getOrCreateMethodContainer(method); methodResultContainer.addPatch(patch); } @@ -346,14 +346,14 @@ void addResult(RuleInfo ruleInfo) { info.add(ruleInfo); } - void setPatch(ChangeInfo patch) { + void setPatch(Change patch) { this.patch = patch; } } static class MethodPatchContainer { List info = new ArrayList<>(); - MethodChangeInfo patch; + MethodChange patch; String fullName; public void add(RuleInfo ruleInfo) { @@ -368,7 +368,7 @@ public MethodPatch createProto() { return builder.build(); } - void addPatch(MethodChangeInfo patch) { + void addPatch(MethodChange patch) { this.patch = patch; } } @@ -379,14 +379,14 @@ class EnumPatchContainer { List info = new ArrayList<>(); Map valueMap = new HashMap<>(); - ChangeInfo patch; + Change patch; public void add(Descriptors.EnumValueDescriptor value, RuleInfo ruleInfo) { EnumValuePatchContainer methodResultContainer = getOrCreateValueContainer(value); methodResultContainer.add(ruleInfo); } - public void addPatch(Descriptors.EnumValueDescriptor value, EnumValueChangeInfo patch) { + public void addPatch(Descriptors.EnumValueDescriptor value, EnumValueChange patch) { EnumValuePatchContainer valueResultContainer = getOrCreateValueContainer(value); valueResultContainer.addPatch(patch); } @@ -419,14 +419,14 @@ void addResult(RuleInfo ruleInfo) { info.add(ruleInfo); } - void setPatch(ChangeInfo patch) { + void setPatch(Change patch) { this.patch = patch; } } static class EnumValuePatchContainer { List info = new ArrayList<>(); - EnumValueChangeInfo patch; + EnumValueChange patch; String fullName; int number; @@ -443,7 +443,7 @@ public EnumValuePatch createProto() { return builder.build(); } - void addPatch(EnumValueChangeInfo patch) { + void addPatch(EnumValueChange patch) { this.patch = patch; } } diff --git a/core/src/main/java/io/anemos/metastore/core/registry/ShadowApply.java b/core/src/main/java/io/anemos/metastore/core/registry/ShadowApply.java index af83b5e..03d9d9c 100644 --- a/core/src/main/java/io/anemos/metastore/core/registry/ShadowApply.java +++ b/core/src/main/java/io/anemos/metastore/core/registry/ShadowApply.java @@ -7,9 +7,9 @@ import io.anemos.metastore.putils.ProtoDomain; import io.anemos.metastore.v1alpha1.FieldPatch; import io.anemos.metastore.v1alpha1.FilePatch; -import io.anemos.metastore.v1alpha1.ImportChangeInfo; +import io.anemos.metastore.v1alpha1.ImportChange; import io.anemos.metastore.v1alpha1.MessagePatch; -import io.anemos.metastore.v1alpha1.OptionChangeInfo; +import io.anemos.metastore.v1alpha1.OptionChange; import io.anemos.metastore.v1alpha1.Patch; import java.util.ArrayList; import java.util.HashMap; @@ -141,7 +141,7 @@ private HashMap getMessageNameToIndexMap( } private DescriptorProtos.FileDescriptorProto.Builder applyFileOptionChanges( - Descriptors.FileDescriptor fileDescriptor, List optionChanges) { + Descriptors.FileDescriptor fileDescriptor, List optionChanges) { DescriptorProtos.FileDescriptorProto.Builder newDescriptorBuilder = fileDescriptor.toProto().toBuilder(); UnknownFieldSet unknownFieldSet = buildUnknownFieldSet(optionChanges); @@ -151,7 +151,7 @@ private DescriptorProtos.FileDescriptorProto.Builder applyFileOptionChanges( } private DescriptorProtos.FileDescriptorProto.Builder applyImportChanges( - DescriptorProtos.FileDescriptorProto.Builder builder, List importChanges) { + DescriptorProtos.FileDescriptorProto.Builder builder, List importChanges) { Set dependencyList = new HashSet<>(builder.getDependencyList()); importChanges.forEach( @@ -175,7 +175,7 @@ private DescriptorProtos.FileDescriptorProto.Builder applyImportChanges( private DescriptorProtos.DescriptorProto applyMessageOptionChanges( DescriptorProtos.DescriptorProto.Builder newDescriptorBuilder, Descriptors.Descriptor descriptor, - List optionChanges) { + List optionChanges) { UnknownFieldSet unknownFieldSet = buildUnknownFieldSet(optionChanges); DescriptorProtos.MessageOptions messageOptions = DescriptorProtos.MessageOptions.newBuilder().setUnknownFields(unknownFieldSet).build(); @@ -183,7 +183,7 @@ private DescriptorProtos.DescriptorProto applyMessageOptionChanges( } private DescriptorProtos.FieldDescriptorProto applyFieldOptionChanges( - Descriptors.FieldDescriptor fieldDescriptor, List optionChanges) { + Descriptors.FieldDescriptor fieldDescriptor, List optionChanges) { DescriptorProtos.FieldDescriptorProto.Builder newFieldDescriptorProtoBuilder = fieldDescriptor.toProto().toBuilder(); UnknownFieldSet unknownFieldSet = buildUnknownFieldSet(optionChanges); @@ -194,9 +194,9 @@ private DescriptorProtos.FieldDescriptorProto applyFieldOptionChanges( return newFieldDescriptorProtoBuilder.setOptions(fieldOptions).build(); } - private UnknownFieldSet buildUnknownFieldSet(List optionChanges) { + private UnknownFieldSet buildUnknownFieldSet(List optionChanges) { UnknownFieldSet.Builder unknownFieldSetBuilder = UnknownFieldSet.newBuilder(); - for (OptionChangeInfo optionChange : optionChanges) { + for (OptionChange optionChange : optionChanges) { switch (optionChange.getChangeType()) { case ADDITION: unknownFieldSetBuilder = diff --git a/core/src/test/java/io/anemos/metastore/core/proto/validation/DiffTest.java b/core/src/test/java/io/anemos/metastore/core/proto/validation/DiffTest.java index 51d282d..a02d16f 100644 --- a/core/src/test/java/io/anemos/metastore/core/proto/validation/DiffTest.java +++ b/core/src/test/java/io/anemos/metastore/core/proto/validation/DiffTest.java @@ -1,7 +1,7 @@ package io.anemos.metastore.core.proto.validation; -import static io.anemos.metastore.v1alpha1.FieldChangeInfo.FieldType.FIELD_TYPE_STRING; -import static io.anemos.metastore.v1alpha1.FieldChangeInfo.FieldType.FIELD_TYPE_UNSET; +import static io.anemos.metastore.v1alpha1.FieldChange.FieldType.FIELD_TYPE_STRING; +import static io.anemos.metastore.v1alpha1.FieldChange.FieldType.FIELD_TYPE_UNSET; import io.anemos.metastore.core.proto.TestSets; import io.anemos.metastore.core.proto.validate.ProtoDiff; @@ -21,7 +21,7 @@ public void onBaseDeprecatedString() throws IOException { Assert.assertEquals(16, fieldResults.getNumber()); Assert.assertEquals("primitive_string", fieldResults.getName()); - FieldChangeInfo change = fieldResults.getChange(); + FieldChange change = fieldResults.getChange(); Assert.assertEquals(ChangeType.CHANGED, change.getChangeType()); Assert.assertEquals("", change.getFromName()); @@ -39,7 +39,7 @@ public void onBaseRemoveString() throws IOException { Assert.assertEquals(16, fieldResults.getNumber()); Assert.assertEquals("primitive_string", fieldResults.getName()); - FieldChangeInfo change = fieldResults.getChange(); + FieldChange change = fieldResults.getChange(); Assert.assertEquals(ChangeType.REMOVAL, change.getChangeType()); Assert.assertEquals("primitive_string", change.getFromName()); @@ -57,7 +57,7 @@ public void onBaseReserveString() throws IOException { Assert.assertEquals(16, fieldResults.getNumber()); Assert.assertEquals("primitive_string", fieldResults.getName()); - FieldChangeInfo change = fieldResults.getChange(); + FieldChange change = fieldResults.getChange(); Assert.assertEquals(ChangeType.RESERVED, change.getChangeType()); Assert.assertEquals("primitive_string", change.getFromName()); @@ -75,7 +75,7 @@ public void onBaseReserveStringOnlyNumber() throws IOException { Assert.assertEquals(16, fieldResults.getNumber()); Assert.assertEquals("primitive_string", fieldResults.getName()); - FieldChangeInfo change = fieldResults.getChange(); + FieldChange change = fieldResults.getChange(); Assert.assertEquals(ChangeType.RESERVED, change.getChangeType()); Assert.assertEquals("primitive_string", change.getFromName()); @@ -93,7 +93,7 @@ public void toBaseUndeprecatedString() throws IOException { Assert.assertEquals(16, fieldResults.getNumber()); Assert.assertEquals("primitive_string", fieldResults.getName()); - FieldChangeInfo change = fieldResults.getChange(); + FieldChange change = fieldResults.getChange(); Assert.assertEquals(ChangeType.CHANGED, change.getChangeType()); Assert.assertEquals("", change.getFromName()); @@ -111,7 +111,7 @@ public void toBaseUnremoveString() throws IOException { Assert.assertEquals(16, fieldResults.getNumber()); Assert.assertEquals("primitive_string", fieldResults.getName()); - FieldChangeInfo change = fieldResults.getChange(); + FieldChange change = fieldResults.getChange(); Assert.assertEquals(ChangeType.ADDITION, change.getChangeType()); Assert.assertEquals("", change.getFromName()); @@ -129,7 +129,7 @@ public void tnBaseUnreserveString() throws IOException { Assert.assertEquals(16, fieldResults.getNumber()); Assert.assertEquals("primitive_string", fieldResults.getName()); - FieldChangeInfo change = fieldResults.getChange(); + FieldChange change = fieldResults.getChange(); Assert.assertEquals(ChangeType.UNRESERVED, change.getChangeType()); Assert.assertEquals("primitive_string", change.getFromName()); @@ -147,7 +147,7 @@ public void toBaseUnreserveStringOnlyNumber() throws IOException { Assert.assertEquals(16, fieldResults.getNumber()); Assert.assertEquals("primitive_string", fieldResults.getName()); - FieldChangeInfo change = fieldResults.getChange(); + FieldChange change = fieldResults.getChange(); Assert.assertEquals(ChangeType.UNRESERVED, change.getChangeType()); Assert.assertEquals("", change.getFromName()); diff --git a/core/src/test/java/io/anemos/metastore/core/proto/validation/OptionDiffTest.java b/core/src/test/java/io/anemos/metastore/core/proto/validation/OptionDiffTest.java index 1319c96..66a3346 100644 --- a/core/src/test/java/io/anemos/metastore/core/proto/validation/OptionDiffTest.java +++ b/core/src/test/java/io/anemos/metastore/core/proto/validation/OptionDiffTest.java @@ -8,7 +8,7 @@ import io.anemos.metastore.v1alpha1.ChangeType; import io.anemos.metastore.v1alpha1.FilePatch; import io.anemos.metastore.v1alpha1.MessagePatch; -import io.anemos.metastore.v1alpha1.OptionChangeInfo; +import io.anemos.metastore.v1alpha1.OptionChange; import io.anemos.metastore.v1alpha1.Patch; import java.io.IOException; import org.junit.Assert; @@ -23,12 +23,12 @@ public void addMessageOptionTest() throws IOException { ProtoDomain base = TestSets.baseKnownOption(); MessagePatch messageResult = diffMessage(base, baseAddMessageOption); - OptionChangeInfo optionChangeInfo = messageResult.getOptionChangeList().get(0); + OptionChange optionChange = messageResult.getOptionChangeList().get(0); - Assert.assertEquals(ChangeType.ADDITION, optionChangeInfo.getChangeType()); - Assert.assertEquals(OptionChangeInfo.OptionType.MESSAGE_OPTION, optionChangeInfo.getType()); + Assert.assertEquals(ChangeType.ADDITION, optionChange.getChangeType()); + Assert.assertEquals(OptionChange.OptionType.MESSAGE_OPTION, optionChange.getType()); - ByteString payload = optionChangeInfo.getPayloadNew(); + ByteString payload = optionChange.getPayloadNew(); Option.TestOption option = Option.TestOption.parseFrom(payload); } @@ -38,12 +38,12 @@ public void removeMessageOptionTest() throws IOException { ProtoDomain baseRemoveFieldOption = TestSets.baseKnownOption(); MessagePatch messageResult = diffMessage(base, baseRemoveFieldOption); - OptionChangeInfo optionChangeInfo = messageResult.getOptionChangeList().get(0); + OptionChange optionChange = messageResult.getOptionChangeList().get(0); - Assert.assertEquals(ChangeType.REMOVAL, optionChangeInfo.getChangeType()); - Assert.assertEquals(OptionChangeInfo.OptionType.MESSAGE_OPTION, optionChangeInfo.getType()); + Assert.assertEquals(ChangeType.REMOVAL, optionChange.getChangeType()); + Assert.assertEquals(OptionChange.OptionType.MESSAGE_OPTION, optionChange.getType()); - ByteString payload = optionChangeInfo.getPayloadOld(); + ByteString payload = optionChange.getPayloadOld(); Option.TestOption option = Option.TestOption.parseFrom(payload); } @@ -53,14 +53,14 @@ public void changeMessageOptionTest() throws IOException { ProtoDomain baseChangeMessageOption = TestSets.baseChangeMessageOption(); MessagePatch messageResult = diffMessage(baseAddMessageOption, baseChangeMessageOption); - OptionChangeInfo optionChangeInfo = messageResult.getOptionChangeList().get(0); + OptionChange optionChange = messageResult.getOptionChangeList().get(0); - Assert.assertEquals(ChangeType.PAYLOAD_CHANGED, optionChangeInfo.getChangeType()); - Assert.assertEquals(OptionChangeInfo.OptionType.MESSAGE_OPTION, optionChangeInfo.getType()); + Assert.assertEquals(ChangeType.PAYLOAD_CHANGED, optionChange.getChangeType()); + Assert.assertEquals(OptionChange.OptionType.MESSAGE_OPTION, optionChange.getType()); - ByteString payloadOld = optionChangeInfo.getPayloadOld(); + ByteString payloadOld = optionChange.getPayloadOld(); Option.TestOption optionOld = Option.TestOption.parseFrom(payloadOld); - ByteString payloadNew = optionChangeInfo.getPayloadNew(); + ByteString payloadNew = optionChange.getPayloadNew(); Option.TestOption optionNew = Option.TestOption.parseFrom(payloadNew); Assert.assertNotEquals(optionOld, optionNew); } @@ -71,13 +71,12 @@ public void addFieldOptionTest() throws IOException { ProtoDomain base = TestSets.baseKnownOption(); MessagePatch messageResult = diffMessage(base, baseAddFieldOption); - OptionChangeInfo optionChangeInfo = - messageResult.getFieldPatches(0).getOptionChangeList().get(0); + OptionChange optionChange = messageResult.getFieldPatches(0).getOptionChangeList().get(0); - Assert.assertEquals(ChangeType.ADDITION, optionChangeInfo.getChangeType()); - Assert.assertEquals(OptionChangeInfo.OptionType.FIELD_OPTION, optionChangeInfo.getType()); + Assert.assertEquals(ChangeType.ADDITION, optionChange.getChangeType()); + Assert.assertEquals(OptionChange.OptionType.FIELD_OPTION, optionChange.getType()); - ByteString payload = optionChangeInfo.getPayloadNew(); + ByteString payload = optionChange.getPayloadNew(); Option.TestOption option = Option.TestOption.parseFrom(payload); } @@ -87,13 +86,12 @@ public void removeFieldOptionTest() throws IOException { ProtoDomain baseRemoveFieldOption = TestSets.baseKnownOption(); MessagePatch messageResult = diffMessage(base, baseRemoveFieldOption); - OptionChangeInfo optionChangeInfo = - messageResult.getFieldPatches(0).getOptionChangeList().get(0); + OptionChange optionChange = messageResult.getFieldPatches(0).getOptionChangeList().get(0); - Assert.assertEquals(ChangeType.REMOVAL, optionChangeInfo.getChangeType()); - Assert.assertEquals(OptionChangeInfo.OptionType.FIELD_OPTION, optionChangeInfo.getType()); + Assert.assertEquals(ChangeType.REMOVAL, optionChange.getChangeType()); + Assert.assertEquals(OptionChange.OptionType.FIELD_OPTION, optionChange.getType()); - ByteString payload = optionChangeInfo.getPayloadNew(); + ByteString payload = optionChange.getPayloadNew(); Option.TestOption option = Option.TestOption.parseFrom(payload); } @@ -103,15 +101,14 @@ public void changeFieldOptionTest() throws IOException { ProtoDomain baseChangeFieldOption = TestSets.baseChangeFieldOption(); MessagePatch messageResult = diffMessage(base, baseChangeFieldOption); - OptionChangeInfo optionChangeInfo = - messageResult.getFieldPatches(0).getOptionChangeList().get(0); + OptionChange optionChange = messageResult.getFieldPatches(0).getOptionChangeList().get(0); - Assert.assertEquals(ChangeType.PAYLOAD_CHANGED, optionChangeInfo.getChangeType()); - Assert.assertEquals(OptionChangeInfo.OptionType.FIELD_OPTION, optionChangeInfo.getType()); + Assert.assertEquals(ChangeType.PAYLOAD_CHANGED, optionChange.getChangeType()); + Assert.assertEquals(OptionChange.OptionType.FIELD_OPTION, optionChange.getType()); - ByteString payloadOld = optionChangeInfo.getPayloadOld(); + ByteString payloadOld = optionChange.getPayloadOld(); Option.TestOption optionOld = Option.TestOption.parseFrom(payloadOld); - ByteString payloadNew = optionChangeInfo.getPayloadNew(); + ByteString payloadNew = optionChange.getPayloadNew(); Option.TestOption optionNew = Option.TestOption.parseFrom(payloadNew); Assert.assertNotEquals(optionOld, optionNew); } @@ -122,12 +119,12 @@ public void addFileOptionTest() throws IOException { ProtoDomain base = TestSets.baseKnownOption(); FilePatch fileResult = diffFile(base, baseAddFileOption); - OptionChangeInfo optionChangeInfo = fileResult.getOptionChangeList().get(0); + OptionChange optionChange = fileResult.getOptionChangeList().get(0); - Assert.assertEquals(ChangeType.ADDITION, optionChangeInfo.getChangeType()); - Assert.assertEquals(OptionChangeInfo.OptionType.FILE_OPTION, optionChangeInfo.getType()); + Assert.assertEquals(ChangeType.ADDITION, optionChange.getChangeType()); + Assert.assertEquals(OptionChange.OptionType.FILE_OPTION, optionChange.getType()); - ByteString payload = optionChangeInfo.getPayloadNew(); + ByteString payload = optionChange.getPayloadNew(); Option.TestOption option = Option.TestOption.parseFrom(payload); } @@ -137,12 +134,12 @@ public void removeFileOptionTest() throws IOException { ProtoDomain base = TestSets.baseAddFileOption(); FilePatch fileResult = diffFile(base, baseRemoveFileOption); - OptionChangeInfo optionChangeInfo = fileResult.getOptionChangeList().get(0); + OptionChange optionChange = fileResult.getOptionChangeList().get(0); - Assert.assertEquals(ChangeType.REMOVAL, optionChangeInfo.getChangeType()); - Assert.assertEquals(OptionChangeInfo.OptionType.FILE_OPTION, optionChangeInfo.getType()); + Assert.assertEquals(ChangeType.REMOVAL, optionChange.getChangeType()); + Assert.assertEquals(OptionChange.OptionType.FILE_OPTION, optionChange.getType()); - ByteString payload = optionChangeInfo.getPayloadNew(); + ByteString payload = optionChange.getPayloadNew(); Option.TestOption option = Option.TestOption.parseFrom(payload); } @@ -152,12 +149,12 @@ public void changeFileOptionTest() throws IOException { ProtoDomain base = TestSets.baseAddFileOption(); FilePatch fileResult = diffFile(base, baseChangeFileOption); - OptionChangeInfo optionChangeInfo = fileResult.getOptionChangeList().get(0); + OptionChange optionChange = fileResult.getOptionChangeList().get(0); - Assert.assertEquals(ChangeType.PAYLOAD_CHANGED, optionChangeInfo.getChangeType()); - Assert.assertEquals(OptionChangeInfo.OptionType.FILE_OPTION, optionChangeInfo.getType()); + Assert.assertEquals(ChangeType.PAYLOAD_CHANGED, optionChange.getChangeType()); + Assert.assertEquals(OptionChange.OptionType.FILE_OPTION, optionChange.getType()); - ByteString payload = optionChangeInfo.getPayloadNew(); + ByteString payload = optionChange.getPayloadNew(); Option.TestOption option = Option.TestOption.parseFrom(payload); } diff --git a/core/src/test/java/io/anemos/metastore/core/proto/validation/ProtoDiffTest.java b/core/src/test/java/io/anemos/metastore/core/proto/validation/ProtoDiffTest.java index bb586e5..377df6c 100644 --- a/core/src/test/java/io/anemos/metastore/core/proto/validation/ProtoDiffTest.java +++ b/core/src/test/java/io/anemos/metastore/core/proto/validation/ProtoDiffTest.java @@ -410,8 +410,7 @@ public void changeComplexFieldType() throws Exception { Assert.assertEquals( "google.protobuf.StringValue", result.getFieldPatches(0).getChange().getFromTypeName()); Assert.assertEquals( - FieldChangeInfo.FieldType.FIELD_TYPE_STRING, - result.getFieldPatches(0).getChange().getToType()); + FieldChange.FieldType.FIELD_TYPE_STRING, result.getFieldPatches(0).getChange().getToType()); } @Test diff --git a/proto/src/main/proto/grpc/registry/v1alpha1/patch.proto b/proto/src/main/proto/grpc/registry/v1alpha1/patch.proto index e8d2921..3e8ee52 100644 --- a/proto/src/main/proto/grpc/registry/v1alpha1/patch.proto +++ b/proto/src/main/proto/grpc/registry/v1alpha1/patch.proto @@ -72,30 +72,30 @@ message RuleInfo { string code = 2; } -// Generic ChangeInfo message menth for top level objects like File, Message, +// Generic Change message menth for top level objects like File, Message, // Enum and Service. As the don't contain any time information and are // actually containers they only support addition, renames and removals. -message ChangeInfo { +message Change { string from_name = 1; string to_name = 2; ChangeType change_type = 3; } -message ImportChangeInfo { +message ImportChange { ChangeType change_type = 1; string name = 2; } message FilePatch { string file_name = 1; - repeated string message_result_ref = 2; + repeated string message_patch_ref = 2; repeated RuleInfo info = 3; - ChangeInfo change = 4; + Change change = 4; - repeated ImportChangeInfo import_change = 9; - repeated OptionChangeInfo option_change = 10; + repeated ImportChange import_change = 9; + repeated OptionChange option_change = 10; } message MessagePatch { @@ -104,12 +104,12 @@ message MessagePatch { repeated RuleInfo info = 3; - ChangeInfo change = 4; + Change change = 4; repeated FieldPatch field_patches = 5; - repeated OptionChangeInfo option_change = 10; + repeated OptionChange option_change = 10; } message FieldPatch { @@ -118,12 +118,12 @@ message FieldPatch { repeated RuleInfo info = 3; - FieldChangeInfo change = 4; + FieldChange change = 4; - repeated OptionChangeInfo option_change = 10; + repeated OptionChange option_change = 10; } -message OptionChangeInfo { +message OptionChange { enum OptionType { OPTION_TYPE_UNSET = 0; FILE_OPTION = 1; @@ -145,7 +145,7 @@ message OptionChangeInfo { string option_name = 8; } -message FieldChangeInfo { +message FieldChange { enum FieldType { FIELD_TYPE_UNSET = 0; FIELD_TYPE_DOUBLE = 1; @@ -182,7 +182,7 @@ message FieldChangeInfo { string to_type_name = 11; } -message EnumValueChangeInfo { +message EnumValueChange { ChangeType change_type = 1; string from_name = 2; @@ -194,7 +194,7 @@ message EnumValueChangeInfo { bool to_reserved = 9; } -message MethodChangeInfo { +message MethodChange { ChangeType change_type = 1; string from_name = 2; @@ -211,7 +211,7 @@ message ServicePatch { repeated RuleInfo info = 3; - ChangeInfo change = 4; + Change change = 4; repeated MethodPatch method_patches = 5; } @@ -221,7 +221,7 @@ message MethodPatch { repeated RuleInfo info = 3; - MethodChangeInfo change = 4; + MethodChange change = 4; } message EnumPatch { @@ -230,7 +230,7 @@ message EnumPatch { repeated RuleInfo info = 3; - ChangeInfo change = 4; + Change change = 4; repeated EnumValuePatch value_patches = 5; } @@ -241,5 +241,5 @@ message EnumValuePatch { repeated RuleInfo info = 3; - EnumValueChangeInfo change = 4; + EnumValueChange change = 4; } From 3fe283b99cfdf7275061fbaa5070306ca4934028 Mon Sep 17 00:00:00 2001 From: Alex Van Boxel Date: Fri, 10 Apr 2020 16:35:44 +0200 Subject: [PATCH 06/11] Simplified LintRule --- .../core/proto/validate/ProtoLint.java | 48 ++---------- .../proto/validate/ValidationResults.java | 48 ++++++------ .../core/proto/validation/LintTest.java | 74 ++++++++----------- .../v1alpha1/{rules.proto => README.md} | 10 --- .../proto/grpc/registry/v1alpha1/patch.proto | 26 ++++--- 5 files changed, 78 insertions(+), 128 deletions(-) rename proto/src/main/proto/grpc/registry/v1alpha1/{rules.proto => README.md} (82%) diff --git a/core/src/main/java/io/anemos/metastore/core/proto/validate/ProtoLint.java b/core/src/main/java/io/anemos/metastore/core/proto/validate/ProtoLint.java index e5b4881..d31f90e 100644 --- a/core/src/main/java/io/anemos/metastore/core/proto/validate/ProtoLint.java +++ b/core/src/main/java/io/anemos/metastore/core/proto/validate/ProtoLint.java @@ -3,7 +3,6 @@ import com.google.protobuf.Descriptors; import io.anemos.metastore.putils.ProtoDomain; import io.anemos.metastore.v1alpha1.LintRule; -import io.anemos.metastore.v1alpha1.RuleInfo; import java.util.ArrayList; import java.util.List; @@ -38,11 +37,7 @@ public void lintOnService(Descriptors.ServiceDescriptor service) { String name = service.getName(); if (!isPascalCase(name)) { results.addResult( - service, - RuleInfo.newBuilder() - .setLintRule(LintRule.LINT_SERVICE_NAME_SHOULD_BE_PASCAL) - .setCode(String.format("L%d/00", LintRule.LINT_SERVICE_NAME_SHOULD_BE_PASCAL_VALUE)) - .build()); + service, LintRule.newBuilder().setLintRule("LINT_SERVICE_NAME_SHOULD_BE_PASCAL").build()); } service.getMethods().forEach(m -> lintMethod(m)); @@ -76,11 +71,7 @@ private void lintMessage(Descriptors.Descriptor dp) { String name = dp.getName(); if (!isPascalCase(name)) { results.addResult( - dp, - RuleInfo.newBuilder() - .setLintRule(LintRule.LINT_MESSAGE_NAME_SHOULD_BE_PASCAL) - .setCode(String.format("L%d/00", LintRule.LINT_MESSAGE_NAME_SHOULD_BE_PASCAL_VALUE)) - .build()); + dp, LintRule.newBuilder().setLintRule("LINT_MESSAGE_NAME_SHOULD_BE_PASCAL").build()); } dp.getFields().forEach(fd -> lintField(fd)); @@ -89,19 +80,11 @@ private void lintMessage(Descriptors.Descriptor dp) { private void lintMethod(Descriptors.MethodDescriptor md) { if (!md.getInputType().getFullName().endsWith("Request")) { results.addResult( - md, - RuleInfo.newBuilder() - .setLintRule(LintRule.LINT_METHOD_ITYPE_END_WITH_REQUEST) - .setCode(String.format("L%d/00", LintRule.LINT_METHOD_ITYPE_END_WITH_REQUEST_VALUE)) - .build()); + md, LintRule.newBuilder().setLintRule("LINT_METHOD_ITYPE_END_WITH_REQUEST").build()); } if (!md.getOutputType().getFullName().endsWith("Response")) { results.addResult( - md, - RuleInfo.newBuilder() - .setLintRule(LintRule.LINT_METHOD_RTYPE_END_WITH_RESPONSE) - .setCode(String.format("L%d/00", LintRule.LINT_METHOD_RTYPE_END_WITH_RESPONSE_VALUE)) - .build()); + md, LintRule.newBuilder().setLintRule("LINT_METHOD_RTYPE_END_WITH_RESPONSE").build()); } } @@ -110,12 +93,7 @@ private void lintField(Descriptors.FieldDescriptor fd) { String suffix = isSnakeCase(name); if (suffix != null) { results.addResult( - fd, - RuleInfo.newBuilder() - .setLintRule(LintRule.LINT_FIELD_NAME_SHOULD_BE_SNAKE) - .setCode( - String.format("L%d/%s", LintRule.LINT_FIELD_NAME_SHOULD_BE_SNAKE_VALUE, suffix)) - .build()); + fd, LintRule.newBuilder().setLintRule("LINT_FIELD_NAME_SHOULD_BE_SNAKE").build()); } } @@ -186,10 +164,7 @@ public void lintOnPackage(Descriptors.FileDescriptor fileDescriptor) { if (!dirName.equals(protoPackageName)) { results.addResult( fileDescriptor, - RuleInfo.newBuilder() - .setLintRule(LintRule.LINT_PACKAGE_NO_DIR_ALIGNMENT) - .setCode(String.format("L%d/00", LintRule.LINT_PACKAGE_NO_DIR_ALIGNMENT_VALUE)) - .build()); + LintRule.newBuilder().setLintRule("LINT_PACKAGE_NO_DIR_ALIGNMENT").build()); } } @@ -209,10 +184,7 @@ public void lintOnVersion(Descriptors.Descriptor ref) { if (!dependencyVersion.equals(protoVersion)) { results.addResult( fileDescriptor, - RuleInfo.newBuilder() - .setLintRule(LintRule.LINT_PACKAGE_NO_VERSION_ALIGNMENT) - .setCode(String.format("L%d/00", LintRule.LINT_PACKAGE_NO_VERSION_ALIGNMENT_VALUE)) - .build()); + LintRule.newBuilder().setLintRule("LINT_PACKAGE_NO_VERSION_ALIGNMENT").build()); } } } @@ -247,11 +219,7 @@ public void lintOnImport(Descriptors.Descriptor ref) { } if (!dependencyUsed) { results.addResult( - fileDescriptor, - RuleInfo.newBuilder() - .setLintRule(LintRule.LINT_IMPORT_NO_ALIGNMENT) - .setCode(String.format("L%d/00", LintRule.LINT_IMPORT_NO_ALIGNMENT_VALUE)) - .build()); + fileDescriptor, LintRule.newBuilder().setLintRule("LINT_IMPORT_NO_ALIGNMENT").build()); } } } diff --git a/core/src/main/java/io/anemos/metastore/core/proto/validate/ValidationResults.java b/core/src/main/java/io/anemos/metastore/core/proto/validate/ValidationResults.java index cd75451..7fe2174 100644 --- a/core/src/main/java/io/anemos/metastore/core/proto/validate/ValidationResults.java +++ b/core/src/main/java/io/anemos/metastore/core/proto/validate/ValidationResults.java @@ -13,8 +13,8 @@ public class ValidationResults { private Map enumMap = new HashMap<>(); private Map serviceMap = new HashMap<>(); - public List getInfo(String messageName, String fieldName) { - List rules = new ArrayList<>(); + public List getInfo(String messageName, String fieldName) { + List rules = new ArrayList<>(); MessagePatchContainer messageResult = messageMap.get(messageName); if (messageResult != null) { FieldPatchContainer fieldResultContainer = messageResult.fieldMap.get(fieldName); @@ -72,27 +72,27 @@ private EnumPatchContainer getOrCreateEnum(Descriptors.EnumDescriptor enumDescri return enumResult; } - void addResult(Descriptors.FieldDescriptor fd, RuleInfo ruleInfo) { + void addResult(Descriptors.FieldDescriptor fd, LintRule ruleInfo) { MessagePatchContainer messageResult = getOrCreateMessage(fd.getContainingType()); messageResult.add(fd, ruleInfo); } - void addResult(Descriptors.MethodDescriptor md, RuleInfo ruleInfo) { + void addResult(Descriptors.MethodDescriptor md, LintRule ruleInfo) { ServicePatchContainer messageResult = getOrCreateService(md.getService()); messageResult.add(md, ruleInfo); } - void addResult(Descriptors.Descriptor descriptor, RuleInfo ruleInfo) { + void addResult(Descriptors.Descriptor descriptor, LintRule ruleInfo) { MessagePatchContainer messageResult = getOrCreateMessage(descriptor); messageResult.addResult(ruleInfo); } - void addResult(Descriptors.ServiceDescriptor descriptor, RuleInfo ruleInfo) { + void addResult(Descriptors.ServiceDescriptor descriptor, LintRule ruleInfo) { ServicePatchContainer serviceResult = getOrCreateService(descriptor); serviceResult.addResult(ruleInfo); } - void addResult(Descriptors.FileDescriptor descriptor, RuleInfo ruleInfo) { + void addResult(Descriptors.FileDescriptor descriptor, LintRule ruleInfo) { FilePatchContainer fileResult = getOrCreateFile(descriptor.getFullName()); fileResult.addResult(ruleInfo); } @@ -169,13 +169,13 @@ public Patch createProto() { } static class FieldPatchContainer { - List info = new ArrayList<>(); + List info = new ArrayList<>(); List optionChanges = new ArrayList<>(); FieldChange patch; String name; int number; - public void add(RuleInfo ruleInfo) { + public void add(LintRule ruleInfo) { info.add(ruleInfo); } @@ -205,12 +205,12 @@ static class MessagePatchContainer { String packageName; String fullName; - List info = new ArrayList<>(); + List info = new ArrayList<>(); Map fieldMap = new HashMap<>(); Change patch; List optionChanges = new ArrayList<>(); - public void add(Descriptors.FieldDescriptor field, RuleInfo ruleInfo) { + public void add(Descriptors.FieldDescriptor field, LintRule ruleInfo) { FieldPatchContainer fieldResultContainer = getOrCreateFieldContainer(field); fieldResultContainer.add(ruleInfo); } @@ -244,7 +244,7 @@ MessagePatch createProto() { return messageInfo.build(); } - void addResult(RuleInfo ruleInfo) { + void addResult(LintRule ruleInfo) { info.add(ruleInfo); } @@ -265,7 +265,7 @@ void addOptionChange(Descriptors.FieldDescriptor field, OptionChange optionChang class FilePatchContainer { String fullName; - List info = new ArrayList<>(); + List info = new ArrayList<>(); // Map fieldMap = new HashMap<>(); Change patch; List optionChanges = new ArrayList<>(); @@ -289,7 +289,7 @@ public FilePatch createProto() { return builder.build(); } - void addResult(RuleInfo ruleInfo) { + void addResult(LintRule ruleInfo) { info.add(ruleInfo); } @@ -306,11 +306,11 @@ class ServicePatchContainer { String packageName; String fullName; - List info = new ArrayList<>(); + List info = new ArrayList<>(); Map methodMap = new HashMap<>(); Change patch; - public void add(Descriptors.MethodDescriptor method, RuleInfo ruleInfo) { + public void add(Descriptors.MethodDescriptor method, LintRule ruleInfo) { MethodPatchContainer methoddResultContainer = getOrCreateMethodContainer(method); methoddResultContainer.add(ruleInfo); } @@ -342,7 +342,7 @@ ServicePatch createProto() { return serviceInfo.build(); } - void addResult(RuleInfo ruleInfo) { + void addResult(LintRule ruleInfo) { info.add(ruleInfo); } @@ -352,11 +352,11 @@ void setPatch(Change patch) { } static class MethodPatchContainer { - List info = new ArrayList<>(); + List info = new ArrayList<>(); MethodChange patch; String fullName; - public void add(RuleInfo ruleInfo) { + public void add(LintRule ruleInfo) { info.add(ruleInfo); } @@ -377,11 +377,11 @@ class EnumPatchContainer { String packageName; String fullName; - List info = new ArrayList<>(); + List info = new ArrayList<>(); Map valueMap = new HashMap<>(); Change patch; - public void add(Descriptors.EnumValueDescriptor value, RuleInfo ruleInfo) { + public void add(Descriptors.EnumValueDescriptor value, LintRule ruleInfo) { EnumValuePatchContainer methodResultContainer = getOrCreateValueContainer(value); methodResultContainer.add(ruleInfo); } @@ -415,7 +415,7 @@ EnumPatch createProto() { return messageInfo.build(); } - void addResult(RuleInfo ruleInfo) { + void addResult(LintRule ruleInfo) { info.add(ruleInfo); } @@ -425,12 +425,12 @@ void setPatch(Change patch) { } static class EnumValuePatchContainer { - List info = new ArrayList<>(); + List info = new ArrayList<>(); EnumValueChange patch; String fullName; int number; - public void add(RuleInfo ruleInfo) { + public void add(LintRule ruleInfo) { info.add(ruleInfo); } diff --git a/core/src/test/java/io/anemos/metastore/core/proto/validation/LintTest.java b/core/src/test/java/io/anemos/metastore/core/proto/validation/LintTest.java index c73f793..1c0a0bc 100644 --- a/core/src/test/java/io/anemos/metastore/core/proto/validation/LintTest.java +++ b/core/src/test/java/io/anemos/metastore/core/proto/validation/LintTest.java @@ -30,9 +30,9 @@ public void fieldNokCamel() throws IOException { Assert.assertEquals(1, result.getMessagePatchesCount()); MessagePatch mr = result.getMessagePatchesOrThrow("anemos.metastore.core.LintFieldNamesBad"); - assertOnField(mr, 1, LintRule.LINT_FIELD_NAME_SHOULD_BE_SNAKE, "L20001/02"); - assertOnField(mr, 2, LintRule.LINT_FIELD_NAME_SHOULD_BE_SNAKE, "L20001/01"); - assertOnField(mr, 3, LintRule.LINT_FIELD_NAME_SHOULD_BE_SNAKE, "L20001/05"); + assertOnField(mr, 1, "LINT_FIELD_NAME_SHOULD_BE_SNAKE"); + assertOnField(mr, 2, "LINT_FIELD_NAME_SHOULD_BE_SNAKE"); + assertOnField(mr, 3, "LINT_FIELD_NAME_SHOULD_BE_SNAKE"); } @Test @@ -41,7 +41,7 @@ public void messageLowerCase() throws IOException { Assert.assertEquals(1, result.getMessagePatchesCount()); MessagePatch mr = result.getMessagePatchesOrThrow("anemos.metastore.core.lintmessagelowercase"); - assertOnMessage(mr, LintRule.LINT_MESSAGE_NAME_SHOULD_BE_PASCAL, "L10001/00"); + assertOnMessage(mr, "LINT_MESSAGE_NAME_SHOULD_BE_PASCAL"); } @Test @@ -51,7 +51,7 @@ public void messageCamelCase() throws IOException { MessagePatch mr = result.getMessagePatchesOrThrow("anemos.metastore.core.lint_message_camelcase"); - assertOnMessage(mr, LintRule.LINT_MESSAGE_NAME_SHOULD_BE_PASCAL, "L10001/00"); + assertOnMessage(mr, "LINT_MESSAGE_NAME_SHOULD_BE_PASCAL"); } @Test @@ -61,8 +61,8 @@ public void methodInputAndReturnTypeNoRR() throws IOException { ServicePatch mr = result.getServicePatchesOrThrow("anemos.metastore.core.MethodService"); Assert.assertEquals(2, getInfoForMethod(mr, "MethodEmpty").size()); - assertOnMethod(mr, "MethodEmpty", LintRule.LINT_METHOD_RTYPE_END_WITH_RESPONSE, "L50003/00"); - assertOnMethod(mr, "MethodEmpty", LintRule.LINT_METHOD_ITYPE_END_WITH_REQUEST, "L50002/00"); + assertOnMethod(mr, "MethodEmpty", "LINT_METHOD_RTYPE_END_WITH_RESPONSE"); + assertOnMethod(mr, "MethodEmpty", "LINT_METHOD_ITYPE_END_WITH_REQUEST"); } @Test @@ -72,7 +72,7 @@ public void methodInputTypeNoR() throws IOException { ServicePatch mr = result.getServicePatchesOrThrow("anemos.metastore.core.MethodService"); Assert.assertEquals(1, getInfoForMethod(mr, "MethodEmptyI").size()); - assertOnMethod(mr, "MethodEmptyI", LintRule.LINT_METHOD_ITYPE_END_WITH_REQUEST, "L50002/00"); + assertOnMethod(mr, "MethodEmptyI", "LINT_METHOD_ITYPE_END_WITH_REQUEST"); } @Test @@ -82,7 +82,7 @@ public void methodReturnTypeNoR() throws IOException { ServicePatch mr = result.getServicePatchesOrThrow("anemos.metastore.core.MethodService"); Assert.assertEquals(1, getInfoForMethod(mr, "MethodEmptyR").size()); - assertOnMethod(mr, "MethodEmptyR", LintRule.LINT_METHOD_RTYPE_END_WITH_RESPONSE, "L50003/00"); + assertOnMethod(mr, "MethodEmptyR", "LINT_METHOD_RTYPE_END_WITH_RESPONSE"); } @Test @@ -114,7 +114,7 @@ private Patch lintService(Descriptors.Descriptor ref, String name) throws IOExce return results.createProto(); } - private List getInfoForField(MessagePatch mr, int fieldNumber) { + private List getInfoForField(MessagePatch mr, int fieldNumber) { for (FieldPatch fieldResult : mr.getFieldPatchesList()) { if (fieldResult.getNumber() == fieldNumber) { return fieldResult.getInfoList(); @@ -124,7 +124,7 @@ private List getInfoForField(MessagePatch mr, int fieldNumber) { return null; } - private List getInfoForMethod(ServicePatch mr, String methodName) { + private List getInfoForMethod(ServicePatch mr, String methodName) { for (MethodPatch methodResult : mr.getMethodPatchesList()) { if (methodResult.getName().equals(methodName)) { return methodResult.getInfoList(); @@ -133,49 +133,41 @@ private List getInfoForMethod(ServicePatch mr, String methodName) { return null; } - private void assertOnMethod( - ServicePatch mr, String methodName, LintRule expecredRule, String expectedCode) { - List infoForField = getInfoForMethod(mr, methodName); + private void assertOnMethod(ServicePatch mr, String methodName, String expecredRule) { + List infoForField = getInfoForMethod(mr, methodName); String code = null; - LintRule rule = null; - for (RuleInfo ruleInfo : infoForField) { - if (ruleInfo.getCode().equals(expectedCode) && ruleInfo.getLintRule().equals(expecredRule)) { + String rule = null; + for (LintRule ruleInfo : infoForField) { + if (ruleInfo.getLintRule().equals(expecredRule)) { return; } - code = ruleInfo.getCode(); rule = ruleInfo.getLintRule(); } - Assert.assertEquals(expectedCode, code); Assert.assertEquals(expecredRule, rule); } - private void assertOnField( - MessagePatch mr, int fieldNumber, LintRule expecredRule, String expectedCode) { - List infoForField = getInfoForField(mr, fieldNumber); + private void assertOnField(MessagePatch mr, int fieldNumber, String expecredRule) { + List infoForField = getInfoForField(mr, fieldNumber); String code = null; - LintRule rule = null; - for (RuleInfo ruleInfo : infoForField) { - if (ruleInfo.getCode().equals(expectedCode) && ruleInfo.getLintRule().equals(expecredRule)) { + String rule = null; + for (LintRule ruleInfo : infoForField) { + if (ruleInfo.getLintRule().equals(expecredRule)) { return; } - code = ruleInfo.getCode(); rule = ruleInfo.getLintRule(); } - Assert.assertEquals(expectedCode, code); Assert.assertEquals(expecredRule, rule); } - private void assertOnMessage(MessagePatch mr, LintRule expectedRule, String expectedCode) { + private void assertOnMessage(MessagePatch mr, String expectedRule) { String code = null; - LintRule rule = null; - for (RuleInfo ruleInfo : mr.getInfoList()) { - if (ruleInfo.getCode().equals(expectedCode) && ruleInfo.getLintRule().equals(expectedRule)) { + String rule = null; + for (LintRule ruleInfo : mr.getInfoList()) { + if (ruleInfo.getLintRule().equals(expectedRule)) { return; } - code = ruleInfo.getCode(); rule = ruleInfo.getLintRule(); } - Assert.assertEquals(expectedCode, code); Assert.assertEquals(expectedRule, rule); } @@ -193,20 +185,18 @@ public void packageScopeVersionInvalid() throws IOException { FilePatch fr = result.getFilePatchesOrThrow("anemos/metastore/invalid/invalid.proto"); Assert.assertEquals(1, result.getFilePatchesCount()); - assertOnFile(fr, LintRule.LINT_PACKAGE_NO_DIR_ALIGNMENT, "L70001/00"); + assertOnFile(fr, "LINT_PACKAGE_NO_DIR_ALIGNMENT"); } - private void assertOnFile(FilePatch fr, LintRule expectedRule, String expectedCode) { + private void assertOnFile(FilePatch fr, String expectedRule) { String code = null; - LintRule rule = null; - for (RuleInfo ruleInfo : fr.getInfoList()) { - if (ruleInfo.getCode().equals(expectedCode) && ruleInfo.getLintRule().equals(expectedRule)) { + String rule = null; + for (LintRule ruleInfo : fr.getInfoList()) { + if (ruleInfo.getLintRule().equals(expectedRule)) { return; } - code = ruleInfo.getCode(); rule = ruleInfo.getLintRule(); } - Assert.assertEquals(expectedCode, code); Assert.assertEquals(expectedRule, rule); } @@ -234,7 +224,7 @@ public void versionScopeInvalid() throws IOException { result.getFilePatchesOrThrow("anemos/metastore/core/test/v1/version_scope_invalid.proto"); Assert.assertEquals(1, result.getFilePatchesCount()); - assertOnFile(fr, LintRule.LINT_PACKAGE_NO_VERSION_ALIGNMENT, "L70002/00"); + assertOnFile(fr, "LINT_PACKAGE_NO_VERSION_ALIGNMENT"); } private Patch lintVersion(Descriptors.Descriptor ref) throws IOException { @@ -260,7 +250,7 @@ public void unusedImportInvalid() throws IOException { FilePatch fr = result.getFilePatchesOrThrow("anemos/metastore/unused/invalid/unused_invalid_import.proto"); Assert.assertEquals(1, result.getFilePatchesCount()); - assertOnFile(fr, LintRule.LINT_IMPORT_NO_ALIGNMENT, "L80001/00"); + assertOnFile(fr, "LINT_IMPORT_NO_ALIGNMENT"); } private Patch lintImport(Descriptors.Descriptor ref) throws IOException { diff --git a/proto/src/main/proto/grpc/registry/v1alpha1/rules.proto b/proto/src/main/proto/grpc/registry/v1alpha1/README.md similarity index 82% rename from proto/src/main/proto/grpc/registry/v1alpha1/rules.proto rename to proto/src/main/proto/grpc/registry/v1alpha1/README.md index eac96d7..048c560 100644 --- a/proto/src/main/proto/grpc/registry/v1alpha1/rules.proto +++ b/proto/src/main/proto/grpc/registry/v1alpha1/README.md @@ -1,11 +1,3 @@ -syntax = "proto3"; - -option java_package = "io.anemos.metastore.v1alpha1"; -option java_multiple_files = true; - -package grpc.registry.v1alpha1; - -enum LintRule { LINT_OK = 0; LINT_MESSAGE_CUSTOM = 10000; @@ -34,5 +26,3 @@ enum LintRule { LINT_IMPORT_CUSTOM = 80000; LINT_IMPORT_NO_ALIGNMENT = 80001; - -} diff --git a/proto/src/main/proto/grpc/registry/v1alpha1/patch.proto b/proto/src/main/proto/grpc/registry/v1alpha1/patch.proto index 3e8ee52..9048eed 100644 --- a/proto/src/main/proto/grpc/registry/v1alpha1/patch.proto +++ b/proto/src/main/proto/grpc/registry/v1alpha1/patch.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -import "grpc/registry/v1alpha1/rules.proto"; +import "google/protobuf/wrappers.proto"; option java_package = "io.anemos.metastore.v1alpha1"; option java_multiple_files = true; @@ -67,12 +67,14 @@ enum TypeChange { TYPE_LOOSE_INFO = 2; } -message RuleInfo { - LintRule lint_rule = 1; - string code = 2; +message LintRule { + string lint_rule = 1; + bool suppressed = 3; + google.protobuf.StringValue suppressed_comment = 4; + } -// Generic Change message menth for top level objects like File, Message, +// Generic Change message meant for top level objects like File, Message, // Enum and Service. As the don't contain any time information and are // actually containers they only support addition, renames and removals. message Change { @@ -90,7 +92,7 @@ message FilePatch { string file_name = 1; repeated string message_patch_ref = 2; - repeated RuleInfo info = 3; + repeated LintRule info = 3; Change change = 4; @@ -102,7 +104,7 @@ message MessagePatch { string package = 1; string name = 2; - repeated RuleInfo info = 3; + repeated LintRule info = 3; Change change = 4; @@ -116,7 +118,7 @@ message FieldPatch { int32 number = 1; string name = 2; - repeated RuleInfo info = 3; + repeated LintRule info = 3; FieldChange change = 4; @@ -209,7 +211,7 @@ message ServicePatch { string package = 1; string name = 2; - repeated RuleInfo info = 3; + repeated LintRule info = 3; Change change = 4; @@ -219,7 +221,7 @@ message ServicePatch { message MethodPatch { string name = 2; - repeated RuleInfo info = 3; + repeated LintRule info = 3; MethodChange change = 4; } @@ -228,7 +230,7 @@ message EnumPatch { string package = 1; string name = 2; - repeated RuleInfo info = 3; + repeated LintRule info = 3; Change change = 4; @@ -239,7 +241,7 @@ message EnumValuePatch { int32 number = 1; string name = 2; - repeated RuleInfo info = 3; + repeated LintRule info = 3; EnumValueChange change = 4; } From 403b36788dbf69a7b7ff7143105c042246442362 Mon Sep 17 00:00:00 2001 From: Alex Van Boxel Date: Sun, 12 Apr 2020 22:34:14 +0200 Subject: [PATCH 07/11] MergeStrategy is seperate message --- .../io/anemos/metastore/core/git/GitBase.java | 13 +- .../core/registry/AbstractRegistry.java | 10 +- .../metastore/core/registry/MetaGit.java | 6 +- .../metastore/core/registry/Registries.java | 6 +- .../core/registry/SchemaRegistry.java | 14 +-- .../core/registry/ShadowRegistry.java | 12 +- .../metastore/provider/buildin/AvroGit.java | 12 +- .../anemos/metastore/metastep/MetaStep.java | 31 +++-- .../proto/grpc/registry/v1alpha1/patch.proto | 1 - .../grpc/registry/v1alpha1/registry.proto | 114 ++++++++++++------ .../anemos/metastore/putils/ProtoDomain.java | 49 +++++--- .../io/anemos/metastore/RegistryService.java | 112 +++++++++++------ .../metastore/server/ShadowE2ETest.java | 14 ++- 13 files changed, 246 insertions(+), 148 deletions(-) diff --git a/core/src/main/java/io/anemos/metastore/core/git/GitBase.java b/core/src/main/java/io/anemos/metastore/core/git/GitBase.java index 7a7ab14..d23c61c 100644 --- a/core/src/main/java/io/anemos/metastore/core/git/GitBase.java +++ b/core/src/main/java/io/anemos/metastore/core/git/GitBase.java @@ -139,15 +139,15 @@ protected void pull() throws GitAPIException { gitRepo.pull().setTransportConfigCallback(transportConfigCallback).call(); } - protected void commit(RegistryP.SubmitSchemaRequest.Comment comment) throws GitAPIException { + protected void commit(RegistryP.Note note) throws GitAPIException { CommitCommand commit = gitRepo.commit(); - if (comment.getDescription().length() > 0) { - commit.setMessage(comment.getDescription()); + if (note.getNote().length() > 0) { + commit.setMessage(note.getNote()); } else { commit.setMessage("No message provider"); } - if (comment.getEmail().length() > 0 || comment.getName().length() > 0) { - commit.setAuthor(comment.getName(), comment.getEmail()); + if (note.getEmail().length() > 0 || note.getName().length() > 0) { + commit.setAuthor(note.getName(), note.getEmail()); } commit.call(); } @@ -164,8 +164,7 @@ protected File sshPrivateKey() throws IOException { return null; } - protected abstract void sync( - ProtoDomain protoContainer, RegistryP.SubmitSchemaRequest.Comment comment) throws IOException; + protected abstract void sync(ProtoDomain protoContainer, RegistryP.Note note) throws IOException; protected abstract void clean(ProtoDomain domain) throws GitAPIException; diff --git a/core/src/main/java/io/anemos/metastore/core/registry/AbstractRegistry.java b/core/src/main/java/io/anemos/metastore/core/registry/AbstractRegistry.java index a74f370..0d12e13 100644 --- a/core/src/main/java/io/anemos/metastore/core/registry/AbstractRegistry.java +++ b/core/src/main/java/io/anemos/metastore/core/registry/AbstractRegistry.java @@ -11,7 +11,7 @@ import io.anemos.metastore.provider.StorageProvider; import io.anemos.metastore.putils.ProtoDomain; import io.anemos.metastore.v1alpha1.BindP; -import io.anemos.metastore.v1alpha1.RegistryP.SubmitSchemaRequest.Comment; +import io.anemos.metastore.v1alpha1.RegistryP; import io.anemos.metastore.v1alpha1.Report; import io.grpc.Status; import io.grpc.StatusException; @@ -66,7 +66,7 @@ public abstract class AbstractRegistry implements RegistryInfo { public abstract void init(); - public abstract void update(Comment comment); + public abstract void update(RegistryP.Note note); public abstract ByteString raw(); @@ -74,10 +74,10 @@ public abstract class AbstractRegistry implements RegistryInfo { public abstract ProtoDomain ref(); - public abstract void update(ProtoDomain ref, ProtoDomain in, Report report, Comment comment); + public abstract void update(ProtoDomain ref, ProtoDomain in, Report report, RegistryP.Note note); - void syncGitRepo(Comment comment) { - metaGit.sync(protoContainer, comment); + void syncGitRepo(RegistryP.Note note) { + metaGit.sync(protoContainer, note); } void initGitRepo() { diff --git a/core/src/main/java/io/anemos/metastore/core/registry/MetaGit.java b/core/src/main/java/io/anemos/metastore/core/registry/MetaGit.java index 9acdddd..a9adec8 100644 --- a/core/src/main/java/io/anemos/metastore/core/registry/MetaGit.java +++ b/core/src/main/java/io/anemos/metastore/core/registry/MetaGit.java @@ -3,7 +3,7 @@ import io.anemos.metastore.core.git.GitBase; import io.anemos.metastore.core.git.GitConfig; import io.anemos.metastore.putils.ProtoDomain; -import io.anemos.metastore.v1alpha1.RegistryP.SubmitSchemaRequest.Comment; +import io.anemos.metastore.v1alpha1.RegistryP; import io.opencensus.common.Scope; import java.io.File; import java.util.List; @@ -25,7 +25,7 @@ protected void clean(ProtoDomain domain) throws GitAPIException { } @Override - protected void sync(ProtoDomain protoContainer, Comment comment) { + protected void sync(ProtoDomain protoContainer, RegistryP.Note note) { if (!config.isGitEnabled()) { return; } @@ -42,7 +42,7 @@ protected void sync(ProtoDomain protoContainer, Comment comment) { clean(protoContainer); Status status = gitRepo.status().call(); if (status.hasUncommittedChanges()) { - this.commit(comment); + this.commit(note); this.push(); LOG.info("Git changes pushed"); } else { diff --git a/core/src/main/java/io/anemos/metastore/core/registry/Registries.java b/core/src/main/java/io/anemos/metastore/core/registry/Registries.java index 63f1c26..622b949 100644 --- a/core/src/main/java/io/anemos/metastore/core/registry/Registries.java +++ b/core/src/main/java/io/anemos/metastore/core/registry/Registries.java @@ -2,7 +2,7 @@ import io.anemos.metastore.config.MetaStoreConfig; import io.anemos.metastore.config.RegistryConfig; -import io.anemos.metastore.v1alpha1.RegistryP.SubmitSchemaRequest.Comment; +import io.anemos.metastore.v1alpha1.RegistryP.Note; import io.grpc.Status; import io.grpc.StatusException; import java.util.ArrayList; @@ -49,10 +49,10 @@ public Registries(MetaStoreConfig config) { }); } - void notifyShadows(String name, Comment comment) { + void notifyShadows(String name, Note note) { List registries = shadowSubscribers.get(name); if (registries != null) { - registries.forEach(registry -> registry.update(comment)); + registries.forEach(registry -> registry.update(note)); } } diff --git a/core/src/main/java/io/anemos/metastore/core/registry/SchemaRegistry.java b/core/src/main/java/io/anemos/metastore/core/registry/SchemaRegistry.java index 4c902d4..b43bf88 100644 --- a/core/src/main/java/io/anemos/metastore/core/registry/SchemaRegistry.java +++ b/core/src/main/java/io/anemos/metastore/core/registry/SchemaRegistry.java @@ -4,7 +4,7 @@ import io.anemos.metastore.config.RegistryConfig; import io.anemos.metastore.provider.StorageProvider; import io.anemos.metastore.putils.ProtoDomain; -import io.anemos.metastore.v1alpha1.RegistryP.SubmitSchemaRequest.Comment; +import io.anemos.metastore.v1alpha1.RegistryP; import io.anemos.metastore.v1alpha1.Report; import java.io.IOException; @@ -22,7 +22,7 @@ public void init() { writeWriteOnly(); } initGitRepo(); - syncGitRepo(Comment.newBuilder().setDescription("(Re)Sync repo").build()); + syncGitRepo(RegistryP.Note.newBuilder().setNote("(Re)Sync repo").build()); } @Override @@ -41,17 +41,17 @@ public ProtoDomain ref() { } @Override - public void update(ProtoDomain ref, ProtoDomain in, Report report, Comment comment) { + public void update(ProtoDomain ref, ProtoDomain in, Report report, RegistryP.Note note) { protoContainer = in; - update(comment); - syncGitRepo(comment); + update(note); + syncGitRepo(note); notifyEventListeners(report); } @Override - public void update(Comment comment) { + public void update(RegistryP.Note note) { write(); - registries.notifyShadows(getName(), comment); + registries.notifyShadows(getName(), note); } private void write() { diff --git a/core/src/main/java/io/anemos/metastore/core/registry/ShadowRegistry.java b/core/src/main/java/io/anemos/metastore/core/registry/ShadowRegistry.java index 114d0da..3a9f00d 100644 --- a/core/src/main/java/io/anemos/metastore/core/registry/ShadowRegistry.java +++ b/core/src/main/java/io/anemos/metastore/core/registry/ShadowRegistry.java @@ -7,7 +7,7 @@ import io.anemos.metastore.provider.StorageProvider; import io.anemos.metastore.putils.ProtoDomain; import io.anemos.metastore.v1alpha1.Patch; -import io.anemos.metastore.v1alpha1.RegistryP.SubmitSchemaRequest.Comment; +import io.anemos.metastore.v1alpha1.RegistryP; import io.anemos.metastore.v1alpha1.Report; import io.grpc.StatusException; import java.io.IOException; @@ -30,7 +30,7 @@ public void init() { } updateShadowCache(); initGitRepo(); - syncGitRepo(Comment.newBuilder().setDescription("(Re)Sync repo").build()); + syncGitRepo(RegistryP.Note.newBuilder().setNote("(Re)Sync repo").build()); } private void updateShadowCache() { @@ -64,7 +64,7 @@ public ProtoDomain ref() { } @Override - public void update(ProtoDomain ref, ProtoDomain in, Report report, Comment comment) { + public void update(ProtoDomain ref, ProtoDomain in, Report report, RegistryP.Note note) { ValidationResults results = new ValidationResults(); ProtoDiff diff = new ProtoDiff(ref, in, results); if (registryConfig.getScope() != null) { @@ -75,15 +75,15 @@ public void update(ProtoDomain ref, ProtoDomain in, Report report, Comment comme throw new RuntimeException("Shadow registry should have package prefix scopes defined."); } patch = results.createProto(); - update(comment); + update(note); notifyEventListeners(report); } @Override - public void update(Comment comment) { + public void update(RegistryP.Note note) { write(); updateShadowCache(); - syncGitRepo(comment); + syncGitRepo(note); } private void write() { diff --git a/core/src/main/java/io/anemos/metastore/provider/buildin/AvroGit.java b/core/src/main/java/io/anemos/metastore/provider/buildin/AvroGit.java index 0b0f6ff..c9167d0 100644 --- a/core/src/main/java/io/anemos/metastore/provider/buildin/AvroGit.java +++ b/core/src/main/java/io/anemos/metastore/provider/buildin/AvroGit.java @@ -27,18 +27,14 @@ public static void write( String name, GitConfig config, ProtoDomain protoDomain, String rootOptionName) throws IOException { - RegistryP.SubmitSchemaRequest.Comment comment = - RegistryP.SubmitSchemaRequest.Comment.newBuilder() - .setDescription("Sync avro schema files.") - .build(); + RegistryP.Note note = RegistryP.Note.newBuilder().setNote("Sync avro schema files.").build(); AvroGit gitWriteOnly = new AvroGit(name, config, rootOptionName); gitWriteOnly.init(); - gitWriteOnly.sync(protoDomain, comment); + gitWriteOnly.sync(protoDomain, note); } @Override - protected void sync(ProtoDomain protoContainer, RegistryP.SubmitSchemaRequest.Comment comment) - throws IOException { + protected void sync(ProtoDomain protoContainer, RegistryP.Note note) throws IOException { if (!config.isGitEnabled()) { return; } @@ -65,7 +61,7 @@ protected void sync(ProtoDomain protoContainer, RegistryP.SubmitSchemaRequest.Co Status status = gitRepo.status().call(); if (status.hasUncommittedChanges()) { - this.commit(comment); + this.commit(note); this.push(); LOG.info("Git changes pushed"); } else { diff --git a/metastep/src/main/java/io/anemos/metastore/metastep/MetaStep.java b/metastep/src/main/java/io/anemos/metastore/metastep/MetaStep.java index f5631a6..3f0fc16 100644 --- a/metastep/src/main/java/io/anemos/metastore/metastep/MetaStep.java +++ b/metastep/src/main/java/io/anemos/metastore/metastep/MetaStep.java @@ -277,13 +277,27 @@ private RegistryP.SubmitSchemaRequest createSchemaRequest() throws IOException { Map attributes = res.getAttrs(); if (attributes.get("package_prefix") != null) { - schemaRequestBuilder.setPackagePrefix((String) attributes.get("package_prefix")); + schemaRequestBuilder.setMergeStrategy( + RegistryP.Merge.newBuilder() + .setPackagePrefixes( + RegistryP.Merge.PackagePrefix.newBuilder() + .addPackagePrefix((String) attributes.get("package_prefix"))) + .setStrategy(RegistryP.Merge.Strategy.REPLACE)); } if (attributes.get("package_name") != null) { - schemaRequestBuilder.setPackageName((String) attributes.get("package_name")); + schemaRequestBuilder.setMergeStrategy( + RegistryP.Merge.newBuilder() + .setPackageNames( + RegistryP.Merge.PackageName.newBuilder() + .addPackageName((String) attributes.get("package_name"))) + .setStrategy(RegistryP.Merge.Strategy.REPLACE)); } if (attributes.get("file_name") != null) { - schemaRequestBuilder.setFileName((String) attributes.get("file_name")); + schemaRequestBuilder.setMergeStrategy( + RegistryP.Merge.newBuilder() + .setFiles( + RegistryP.Merge.Files.newBuilder() + .addFileName((String) attributes.get("file_name")))); } if (attributes.get("registry") != null) { schemaRequestBuilder.setRegistryName((String) attributes.get("registry")); @@ -292,16 +306,15 @@ private RegistryP.SubmitSchemaRequest createSchemaRequest() throws IOException { schemaRequestBuilder.setValidationProfile((String) attributes.get("profile")); } if (attributes.get("comment") != null) { - RegistryP.SubmitSchemaRequest.Comment.Builder comment = - RegistryP.SubmitSchemaRequest.Comment.newBuilder() - .setDescription((String) attributes.get("comment")); + RegistryP.Note.Builder note = + RegistryP.Note.newBuilder().setNote((String) attributes.get("comment")); if (attributes.get("email") != null) { - comment.setEmail((String) attributes.get("email")); + note.setEmail((String) attributes.get("email")); } if (attributes.get("user") != null) { - comment.setName((String) attributes.get("user")); + note.setName((String) attributes.get("user")); } - schemaRequestBuilder.setComment(comment.build()); + schemaRequestBuilder.setNote(note); } return schemaRequestBuilder.build(); } diff --git a/proto/src/main/proto/grpc/registry/v1alpha1/patch.proto b/proto/src/main/proto/grpc/registry/v1alpha1/patch.proto index 9048eed..de18765 100644 --- a/proto/src/main/proto/grpc/registry/v1alpha1/patch.proto +++ b/proto/src/main/proto/grpc/registry/v1alpha1/patch.proto @@ -71,7 +71,6 @@ message LintRule { string lint_rule = 1; bool suppressed = 3; google.protobuf.StringValue suppressed_comment = 4; - } // Generic Change message meant for top level objects like File, Message, diff --git a/proto/src/main/proto/grpc/registry/v1alpha1/registry.proto b/proto/src/main/proto/grpc/registry/v1alpha1/registry.proto index 6edf24a..d2f12cd 100644 --- a/proto/src/main/proto/grpc/registry/v1alpha1/registry.proto +++ b/proto/src/main/proto/grpc/registry/v1alpha1/registry.proto @@ -12,49 +12,35 @@ service Registry { rpc GetSchema (GetSchemaRequest) returns (GetSchemaResponse); rpc VerifySchema (SubmitSchemaRequest) returns (SubmitSchemaResponse); rpc SubmitSchema (SubmitSchemaRequest) returns (SubmitSchemaResponse); + rpc VerifyPatch (PatchSchemaRequest) returns (PatchSchemaResponse); + rpc PatchSchema (PatchSchemaRequest) returns (PatchSchemaResponse); } message SubmitSchemaRequest { - - // Information of this schema changes. - message Comment { - string name = 1; - string email = 2; - string description = 3; - } - - message FileGroup { - repeated string file_name = 1; - } - - // How a scoped submit will be merged into the existing registry. - enum MergeStrategy { - MERGE = 0; - REPLACE = 1; - CLEAR = 2; - } - // Represents the schema registry names. If a schema registry doesn't support multiple // registries this field is ignored. The default value represents the default registry. string registry_name = 1; - // These are proto2 type google.protobuf.FileDescriptorProto, but - // we avoid taking a dependency on descriptor.proto, which uses - // proto2 only features, by making them opaque - // bytes instead + // The google.protobuf.FileDescriptorProto to be submitted or verified. As these + // messages are proto2 we avoid taking a dependency on descriptor.proto, which uses + // proto2 only features, by making them opaque bytes instead. repeated bytes file_descriptor_proto = 2; - MergeStrategy merge_strategy = 9; - - oneof entity_scope { - string package_name = 3; - string package_prefix = 4; - string file_name = 5; - FileGroup file_group = 8; - } - - string validation_profile = 6; - Comment comment = 7; + // Describes the intended merge behaviour towards the current domain already present + // in the registry. A lot of use-cases merit partial updates, and even clearing of + // file descriptors present in the registry. + // + // If the no strategy is provided a simple merge strategy is applied that is equivalent + // to setting domain with merge strategy MERGE. + Merge merge_strategy = 3; + + // The validation profile that is applied to this request. If non is provided the service + // default profile is applied. If the service doesn't recognises the profile and error is + // expected to be returned. + string validation_profile = 4; + + // If the service keeps track of the registry the note can provide usefull information. + Note note = 5; } message SubmitSchemaResponse { @@ -81,10 +67,62 @@ message GetSchemaRequest { } message GetSchemaResponse { - // These are proto2 type google.protobuf.FileDescriptorProto, but - // we avoid taking a dependency on descriptor.proto, which uses - // proto2 only features, by making them opaque - // bytes instead + // The requested google.protobuf.FileDescriptorProto binaries. As these messages + // are proto2 we avoid taking a dependency on descriptor.proto, which uses proto2 only + // features, by making them opaque bytes instead. repeated bytes file_descriptor_proto = 1; int32 error_code = 2; } + +message PatchSchemaRequest { + + // Represents the schema registry names. If a schema registry doesn't support multiple + // registries this field is ignored. The default value represents the default registry. + string registry_name = 1; + + Patch patch = 2; + + string validation_profile = 3; + Note note = 4; +} + +message PatchSchemaResponse { + string schema_profile = 1; + Report report = 2; + int32 error_code = 3; +} + +// Information of this schema changes. +message Note { + string name = 1; + string email = 2; + string note = 3; +} + +message Merge { + // How a scoped submit will be merged into the existing registry. + enum Strategy { + MERGE = 0; + REPLACE = 1; + } + + message Files { + repeated string file_name = 1; + } + + message PackageName { + repeated string package_name = 1; + } + + message PackagePrefix { + repeated string package_prefix = 1; + } + + oneof merge_strategy { + Files files = 1; + PackageName package_names = 2; + PackagePrefix package_prefixes = 3; + } + Strategy strategy = 4; +} + diff --git a/putils/src/main/java/io/anemos/metastore/putils/ProtoDomain.java b/putils/src/main/java/io/anemos/metastore/putils/ProtoDomain.java index d16f51d..61986df 100644 --- a/putils/src/main/java/io/anemos/metastore/putils/ProtoDomain.java +++ b/putils/src/main/java/io/anemos/metastore/putils/ProtoDomain.java @@ -571,20 +571,34 @@ public Builder mergeBinary(Collection updateBytes) return merge(updateProtos); } - public Builder replaceFileBinary(String file, Collection updateBytes) + public Builder clearFile(String file) { + fileDescriptorMap.remove(file); + return this; + } + + public Builder mergeFileBinary(String file, Collection updateBytes) throws InvalidProtocolBufferException { Map map = toMap(updateBytes); if (map.containsKey(file)) { add(map.get(file)); - } else { - fileDescriptorMap.remove(file); } return this; } - public Builder replacePackageBinary(String packageName, Collection updateBytes) + public Builder mergeInPackageBinary(String packageName, Collection updateBytes) throws InvalidProtocolBufferException { Map updated = toMap(updateBytes); + // only add with package prefix + updated.forEach( + (fileName, fdp) -> { + if (fdp.getPackage().equals(packageName)) { + fileDescriptorMap.put(fileName, fdp); + } + }); + return this; + } + + public Builder clearPackage(String packageName) { List removing = new ArrayList<>(); // clear the package fileDescriptorMap.forEach( @@ -594,13 +608,6 @@ public Builder replacePackageBinary(String packageName, Collection u } }); removing.forEach(f -> fileDescriptorMap.remove(f)); - // only add with package prefix - updated.forEach( - (fileName, fdp) -> { - if (fdp.getPackage().equals(packageName)) { - fileDescriptorMap.put(fileName, fdp); - } - }); return this; } @@ -614,10 +621,21 @@ private boolean isInPackagePrefix( return false; } - public Builder replacePackagePrefixBinary( + public Builder mergeInPackagePrefixBinary( String packagePrefix, Collection updateBytes) throws InvalidProtocolBufferException { Map updated = toMap(updateBytes); + // only add in package + updated.forEach( + (fileName, fdp) -> { + if (isInPackagePrefix(fdp, packagePrefix)) { + fileDescriptorMap.put(fileName, fdp); + } + }); + return this; + } + + public Builder clearPackagePrefix(String packagePrefix) { List removing = new ArrayList<>(); // clear the package prefix fileDescriptorMap.forEach( @@ -627,13 +645,6 @@ public Builder replacePackagePrefixBinary( } }); removing.forEach(f -> fileDescriptorMap.remove(f)); - // only add in package - updated.forEach( - (fileName, fdp) -> { - if (isInPackagePrefix(fdp, packagePrefix)) { - fileDescriptorMap.put(fileName, fdp); - } - }); return this; } diff --git a/server/src/main/java/io/anemos/metastore/RegistryService.java b/server/src/main/java/io/anemos/metastore/RegistryService.java index a9339d9..f317136 100644 --- a/server/src/main/java/io/anemos/metastore/RegistryService.java +++ b/server/src/main/java/io/anemos/metastore/RegistryService.java @@ -1,5 +1,10 @@ package io.anemos.metastore; +import static io.anemos.metastore.v1alpha1.RegistryP.Merge.MergeStrategyCase.MERGESTRATEGY_NOT_SET; +import static io.anemos.metastore.v1alpha1.RegistryP.Merge.MergeStrategyCase.PACKAGE_NAMES; +import static io.anemos.metastore.v1alpha1.RegistryP.Merge.MergeStrategyCase.PACKAGE_PREFIXES; +import static io.anemos.metastore.v1alpha1.RegistryP.Merge.Strategy.REPLACE; + import com.google.protobuf.Descriptors; import io.anemos.metastore.core.proto.profile.*; import io.anemos.metastore.core.proto.validate.ProtoDiff; @@ -88,37 +93,44 @@ public void schema( ProtoDomain in; try { ProtoDomain.Builder builder = registry.get().toBuilder(); - switch (request.getEntityScopeCase()) { - case PACKAGE_NAME: - in = - builder - .replacePackageBinary( - validatePackage(request.getPackageName()), - request.getFileDescriptorProtoList()) - .build(); + RegistryP.Merge mergeStrategy = request.getMergeStrategy(); + switch (mergeStrategy.getMergeStrategyCase()) { + case PACKAGE_NAMES: + if (mergeStrategy.getStrategy().equals(REPLACE)) { + mergeStrategy.getPackageNames().getPackageNameList().forEach(builder::clearPackage); + } + for (String name1 : mergeStrategy.getPackageNames().getPackageNameList()) { + builder.mergeInPackageBinary(name1, request.getFileDescriptorProtoList()); + } break; - case PACKAGE_PREFIX: - in = - builder - .replacePackagePrefixBinary( - validatePackage(request.getPackagePrefix()), - request.getFileDescriptorProtoList()) - .build(); + case PACKAGE_PREFIXES: + if (mergeStrategy.getStrategy().equals(REPLACE)) { + mergeStrategy + .getPackagePrefixes() + .getPackagePrefixList() + .forEach(builder::clearPackagePrefix); + } + for (String s : mergeStrategy.getPackagePrefixes().getPackagePrefixList()) { + builder.mergeInPackagePrefixBinary(s, request.getFileDescriptorProtoList()); + } break; - case FILE_NAME: - in = - builder - .replaceFileBinary( - validateFileName(request.getFileName()), request.getFileDescriptorProtoList()) - .build(); + case FILES: + if (mergeStrategy.getStrategy().equals(REPLACE)) { + mergeStrategy.getFiles().getFileNameList().forEach(builder::clearFile); + } + for (String name : mergeStrategy.getFiles().getFileNameList()) { + builder.mergeFileBinary(name, request.getFileDescriptorProtoList()); + } break; - case ENTITYSCOPE_NOT_SET: + case MERGESTRATEGY_NOT_SET: default: - in = builder.mergeBinary(request.getFileDescriptorProtoList()).build(); + if (mergeStrategy.getStrategy().equals(REPLACE)) { + builder.clearPackagePrefix(""); + } + builder.mergeBinary(request.getFileDescriptorProtoList()).build(); + break; } - } catch (StatusException e) { - responseObserver.onError(e); - return; + in = builder.build(); } catch (IOException | RuntimeException e) { LOG.error("Invalid FileDescriptor Set", e); responseObserver.onError( @@ -140,7 +152,7 @@ public void schema( .asRuntimeException()); return; } - registry.update(registry.ref(), in, report, request.getComment()); + registry.update(registry.ref(), in, report, request.getNote()); } responseObserver.onNext( @@ -169,22 +181,41 @@ private Report validate( ProtoDiff diff = new ProtoDiff(ref, in, results); ProtoLint lint = new ProtoLint(in, results); - switch (request.getEntityScopeCase()) { - case ENTITYSCOPE_NOT_SET: + RegistryP.Merge mergeStrategy = request.getMergeStrategy(); + switch (mergeStrategy.getMergeStrategyCase()) { + case MERGESTRATEGY_NOT_SET: diff.diffOnPackagePrefix(""); lint.lintOnPackagePrefix(""); break; - case PACKAGE_PREFIX: - diff.diffOnPackagePrefix(request.getPackagePrefix()); - lint.lintOnPackagePrefix(request.getPackagePrefix()); + case PACKAGE_PREFIXES: + mergeStrategy + .getPackagePrefixes() + .getPackagePrefixList() + .forEach( + name -> { + diff.diffOnPackagePrefix(name); + lint.lintOnPackagePrefix(name); + }); break; - case PACKAGE_NAME: - diff.diffOnPackage(request.getPackageName()); - lint.lintOnPackage(request.getPackageName()); + case PACKAGE_NAMES: + mergeStrategy + .getPackageNames() + .getPackageNameList() + .forEach( + name -> { + diff.diffOnPackage(name); + lint.lintOnPackage(name); + }); break; - case FILE_NAME: - diff.diffOnFileName(request.getFileName()); - lint.lintOnFileName(request.getFileName()); + case FILES: + mergeStrategy + .getFiles() + .getFileNameList() + .forEach( + name -> { + diff.diffOnFileName(name); + lint.lintOnFileName(name); + }); break; default: throw Status.fromCode(Status.Code.INTERNAL).asRuntimeException(); @@ -207,8 +238,11 @@ private Report validate( case "avro:forward": case "avro:backward": case "allow:add": - default: + case "": profile = new ProfileAllowAdd(); + break; + default: + throw Status.fromCode(Status.Code.INTERNAL).asRuntimeException(); } return profile.validate(results.createProto()); diff --git a/server/src/test/java/io/anemos/metastore/server/ShadowE2ETest.java b/server/src/test/java/io/anemos/metastore/server/ShadowE2ETest.java index 048766e..88cfd7f 100644 --- a/server/src/test/java/io/anemos/metastore/server/ShadowE2ETest.java +++ b/server/src/test/java/io/anemos/metastore/server/ShadowE2ETest.java @@ -101,8 +101,11 @@ public void shadowE2ELocalFileProvider() throws Exception { RegistryP.SubmitSchemaRequest.Builder submitSchemaRequest = RegistryP.SubmitSchemaRequest.newBuilder() - .setPackagePrefix("test") - .setRegistryName("default"); + .setRegistryName("default") + .setMergeStrategy( + RegistryP.Merge.newBuilder() + .setPackagePrefixes( + RegistryP.Merge.PackagePrefix.newBuilder().addPackagePrefix("test"))); baseKnownOption() .iterator() .forEach( @@ -148,7 +151,12 @@ public void shadowE2ELocalFileProvider() throws Exception { // add field to default RegistryP.SubmitSchemaRequest.Builder submitDefaultAddField = - RegistryP.SubmitSchemaRequest.newBuilder().setPackagePrefix("test"); + RegistryP.SubmitSchemaRequest.newBuilder() + .setMergeStrategy( + RegistryP.Merge.newBuilder() + .setPackagePrefixes( + RegistryP.Merge.PackagePrefix.newBuilder().addPackagePrefix("test").build()) + .build()); baseKnownOptionAddField() .iterator() .forEach( From 905742be0811144f3c51d15584377e17b55ffb07 Mon Sep 17 00:00:00 2001 From: Alex Van Boxel Date: Mon, 13 Apr 2020 10:09:40 +0200 Subject: [PATCH 08/11] Implemented Patch methods --- .../{ShadowApply.java => ProtoPatch.java} | 23 +++-- .../core/registry/ShadowRegistry.java | 2 +- .../metastore/core/registry/ShadowTest.java | 8 +- .../io/anemos/metastore/RegistryService.java | 87 +++++++++++++------ 4 files changed, 83 insertions(+), 37 deletions(-) rename core/src/main/java/io/anemos/metastore/core/registry/{ShadowApply.java => ProtoPatch.java} (94%) diff --git a/core/src/main/java/io/anemos/metastore/core/registry/ShadowApply.java b/core/src/main/java/io/anemos/metastore/core/registry/ProtoPatch.java similarity index 94% rename from core/src/main/java/io/anemos/metastore/core/registry/ShadowApply.java rename to core/src/main/java/io/anemos/metastore/core/registry/ProtoPatch.java index 03d9d9c..3cf0db9 100644 --- a/core/src/main/java/io/anemos/metastore/core/registry/ShadowApply.java +++ b/core/src/main/java/io/anemos/metastore/core/registry/ProtoPatch.java @@ -18,13 +18,22 @@ import java.util.Map; import java.util.Set; -class ShadowApply { +public class ProtoPatch { - private ProtoDomain shadow; + private ProtoDomain base; - public ProtoDomain applyDelta(ProtoDomain defaultDescriptor, Patch patch) { + public static ProtoDomain apply(ProtoDomain base, Patch patch) { + return new ProtoPatch(base).applyPatch(patch); + } + + private ProtoPatch() {} + + private ProtoPatch(ProtoDomain base) { + this.base = base; + } + + private ProtoDomain applyPatch(Patch patch) { try { - shadow = defaultDescriptor; HashMap fileDescriptorProtoBuilders = new HashMap<>(); @@ -35,7 +44,7 @@ public ProtoDomain applyDelta(ProtoDomain defaultDescriptor, Patch patch) { (name, fd) -> { fileDescriptorProtos.add(fd.build()); }); - return shadow.toBuilder().merge(fileDescriptorProtos).build(); + return base.toBuilder().merge(fileDescriptorProtos).build(); } catch (Exception e) { throw new RuntimeException("Failed to apply patch", e); } @@ -46,7 +55,7 @@ private void applyFilePatches( HashMap fileDescriptorProtoBuilders) { for (Map.Entry fileResultEntry : patch.getFilePatchesMap().entrySet()) { Descriptors.FileDescriptor fileDescriptor = - shadow.getFileDescriptorByFileName(fileResultEntry.getKey()); + base.getFileDescriptorByFileName(fileResultEntry.getKey()); DescriptorProtos.FileDescriptorProto.Builder fileDescriptorProtoBuilder = getOrCreateFileDescriptorProtoBuilder( @@ -65,7 +74,7 @@ private void applyMessagePatches( HashMap fileDescriptorProtoBuilders) { for (Map.Entry messageResultEntry : patch.getMessagePatchesMap().entrySet()) { - Descriptors.Descriptor descriptor = shadow.getDescriptorByName(messageResultEntry.getKey()); + Descriptors.Descriptor descriptor = base.getDescriptorByName(messageResultEntry.getKey()); HashMap messageNameToIndexMap = getMessageNameToIndexMap(descriptor.getFile()); DescriptorProtos.DescriptorProto.Builder newDescriptorProtoBuilder = diff --git a/core/src/main/java/io/anemos/metastore/core/registry/ShadowRegistry.java b/core/src/main/java/io/anemos/metastore/core/registry/ShadowRegistry.java index 3a9f00d..0a06535 100644 --- a/core/src/main/java/io/anemos/metastore/core/registry/ShadowRegistry.java +++ b/core/src/main/java/io/anemos/metastore/core/registry/ShadowRegistry.java @@ -40,7 +40,7 @@ private void updateShadowCache() { } catch (StatusException e) { throw new RuntimeException("Unable to find registry with name " + shadowOf); } - protoContainer = new ShadowApply().applyDelta(original, this.patch); + protoContainer = ProtoPatch.apply(original, this.patch); protoContainer.registerOptions(); } diff --git a/core/src/test/java/io/anemos/metastore/core/registry/ShadowTest.java b/core/src/test/java/io/anemos/metastore/core/registry/ShadowTest.java index 9634944..76b3c5b 100644 --- a/core/src/test/java/io/anemos/metastore/core/registry/ShadowTest.java +++ b/core/src/test/java/io/anemos/metastore/core/registry/ShadowTest.java @@ -38,7 +38,7 @@ public void addMessageOptionDeltaTest() throws Exception { // ShadowRegistry shadowRegistry = new ShadowRegistry(base, result); // shadowRegistry.setDelta(result); - ProtoDomain shadow = new ShadowApply().applyDelta(base, result); + ProtoDomain shadow = ProtoPatch.apply(base, result); Descriptors.Descriptor expectedDescriptor = baseAddMessageOption.getDescriptorByName("test.v1.ProtoBeamBasicMessage"); @@ -60,7 +60,7 @@ public void addFieldOptionDeltaTest() throws Exception { Patch result = results.createProto(); System.out.println(result); - ProtoDomain shadow = new ShadowApply().applyDelta(base, result); + ProtoDomain shadow = ProtoPatch.apply(base, result); Descriptors.Descriptor expectedDescriptor = baseAddFieldOption.getDescriptorByName("test.v1.ProtoBeamBasicMessage"); @@ -83,7 +83,7 @@ public void addFileOptionDeltaTest() throws Exception { Patch result = results.createProto(); System.out.println(result); - ProtoDomain shadow = new ShadowApply().applyDelta(base, result); + ProtoDomain shadow = ProtoPatch.apply(base, result); Descriptors.FileDescriptor expectedDescriptor = baseAddFileOption.getFileDescriptorByFileName(fileName); @@ -106,7 +106,7 @@ public void multipleOptionsTest() throws Exception { Patch result = results.createProto(); System.out.println(result); - ProtoDomain shadow = new ShadowApply().applyDelta(base, result); + ProtoDomain shadow = ProtoPatch.apply(base, result); Descriptors.FileDescriptor expectedDescriptor = baseMultipleOptions.getFileDescriptorByFileName(fileName); diff --git a/server/src/main/java/io/anemos/metastore/RegistryService.java b/server/src/main/java/io/anemos/metastore/RegistryService.java index f317136..870082e 100644 --- a/server/src/main/java/io/anemos/metastore/RegistryService.java +++ b/server/src/main/java/io/anemos/metastore/RegistryService.java @@ -1,8 +1,5 @@ package io.anemos.metastore; -import static io.anemos.metastore.v1alpha1.RegistryP.Merge.MergeStrategyCase.MERGESTRATEGY_NOT_SET; -import static io.anemos.metastore.v1alpha1.RegistryP.Merge.MergeStrategyCase.PACKAGE_NAMES; -import static io.anemos.metastore.v1alpha1.RegistryP.Merge.MergeStrategyCase.PACKAGE_PREFIXES; import static io.anemos.metastore.v1alpha1.RegistryP.Merge.Strategy.REPLACE; import com.google.protobuf.Descriptors; @@ -11,6 +8,7 @@ import io.anemos.metastore.core.proto.validate.ProtoLint; import io.anemos.metastore.core.proto.validate.ValidationResults; import io.anemos.metastore.core.registry.AbstractRegistry; +import io.anemos.metastore.core.registry.ProtoPatch; import io.anemos.metastore.putils.ProtoDomain; import io.anemos.metastore.v1alpha1.BindP; import io.anemos.metastore.v1alpha1.RegistryGrpc; @@ -141,26 +139,52 @@ public void schema( return; } - try { - Report report = validate(registry, request, registry.get(), in); - - if (submit) { - if (hasErrors(report)) { - responseObserver.onError( - Status.fromCode(Status.Code.FAILED_PRECONDITION) - .withDescription("Incompatible schema, us verify to get errors.") - .asRuntimeException()); - return; - } - registry.update(registry.ref(), in, report, request.getNote()); + Report report = + validate(request.getValidationProfile(), request.getMergeStrategy(), registry.get(), in); + if (submit) { + if (hasErrors(report)) { + responseObserver.onError( + Status.fromCode(Status.Code.FAILED_PRECONDITION) + .withDescription("Incompatible schema, us verify to get errors.") + .asRuntimeException()); + return; } + registry.update(registry.ref(), in, report, request.getNote()); + } - responseObserver.onNext( - RegistryP.SubmitSchemaResponse.newBuilder().setReport(report).build()); - responseObserver.onCompleted(); + responseObserver.onNext(RegistryP.SubmitSchemaResponse.newBuilder().setReport(report).build()); + responseObserver.onCompleted(); + } + + public void patch( + RegistryP.PatchSchemaRequest request, + StreamObserver responseObserver, + boolean submit) { + + AbstractRegistry registry; + try { + registry = metaStore.registries.get(request.getRegistryName()); } catch (StatusException e) { responseObserver.onError(e); + return; } + + ProtoDomain in = ProtoPatch.apply(registry.get(), request.getPatch()); + + Report report = validate(request.getValidationProfile(), registry.get(), in); + if (submit) { + if (hasErrors(report)) { + responseObserver.onError( + Status.fromCode(Status.Code.FAILED_PRECONDITION) + .withDescription("Incompatible schema, us verify to get errors.") + .asRuntimeException()); + return; + } + registry.update(registry.ref(), in, report, request.getNote()); + } + + responseObserver.onNext(RegistryP.PatchSchemaResponse.newBuilder().setReport(report).build()); + responseObserver.onCompleted(); } private boolean hasErrors(Report report) { @@ -171,17 +195,16 @@ private boolean hasErrors(Report report) { return false; } + private Report validate(String validationProfile, ProtoDomain ref, ProtoDomain in) { + return validate(validationProfile, RegistryP.Merge.getDefaultInstance(), ref, in); + } + private Report validate( - AbstractRegistry registry, - RegistryP.SubmitSchemaRequest request, - ProtoDomain ref, - ProtoDomain in) - throws StatusException { + String validationProfile, RegistryP.Merge mergeStrategy, ProtoDomain ref, ProtoDomain in) { ValidationResults results = new ValidationResults(); ProtoDiff diff = new ProtoDiff(ref, in, results); ProtoLint lint = new ProtoLint(in, results); - RegistryP.Merge mergeStrategy = request.getMergeStrategy(); switch (mergeStrategy.getMergeStrategyCase()) { case MERGESTRATEGY_NOT_SET: diff.diffOnPackagePrefix(""); @@ -222,7 +245,7 @@ private Report validate( } ValidationProfile profile; - switch (request.getValidationProfile()) { + switch (validationProfile) { case "allow:all": profile = new ProfileAllowAll(); break; @@ -355,4 +378,18 @@ public void getSchema( responseObserver.onError(e); } } + + @Override + public void verifyPatch( + RegistryP.PatchSchemaRequest request, + StreamObserver responseObserver) { + patch(request, responseObserver, false); + } + + @Override + public void patchSchema( + RegistryP.PatchSchemaRequest request, + StreamObserver responseObserver) { + patch(request, responseObserver, true); + } } From 9cb8e766a9839b19e85c9b33f62d7c6f4c43ce28 Mon Sep 17 00:00:00 2001 From: Alex Van Boxel Date: Tue, 14 Apr 2020 12:43:40 +0200 Subject: [PATCH 09/11] Report split in Patch and Summary --- .../proto/profile/ProfileAllowAddBase.java | 46 +++-- .../core/proto/profile/ProfileAllowAll.java | 6 +- .../core/proto/profile/ProfileAllowNone.java | 6 +- .../proto/profile/ProfileProtoEvolve.java | 4 +- .../core/proto/profile/ValidationProfile.java | 4 +- .../core/proto/validate/ProtoLint.java | 19 +- .../proto/validate/ValidationResults.java | 72 ++++---- .../core/registry/AbstractRegistry.java | 8 +- .../core/registry/SchemaRegistry.java | 6 +- .../core/registry/ShadowRegistry.java | 5 +- .../metastore/provider/EventingProvider.java | 4 +- .../core/proto/profile/ProfileTest.java | 26 +-- .../core/proto/validation/DiffTest.java | 10 +- .../core/proto/validation/LintTest.java | 36 ++-- .../core/proto/validation/ProtoDiffTest.java | 98 ++++++----- .../anemos/metastore/metastep/MetaStep.java | 21 +-- .../proto/grpc/registry/v1alpha1/patch.proto | 163 +++++++----------- .../grpc/registry/v1alpha1/registry.proto | 13 +- .../grpc/registry/v1alpha1/summary.proto | 42 +++++ .../io/anemos/metastore/RegistryService.java | 51 +++--- .../metastore/provider/GooglePubsub.java | 4 +- .../metastore/server/ShadowE2ETest.java | 17 +- 22 files changed, 342 insertions(+), 319 deletions(-) create mode 100644 proto/src/main/proto/grpc/registry/v1alpha1/summary.proto diff --git a/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowAddBase.java b/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowAddBase.java index 914bad4..02e937d 100644 --- a/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowAddBase.java +++ b/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowAddBase.java @@ -24,22 +24,20 @@ private boolean skipValidationForAlpha(String packageName) { } @Override - public Report validate(Patch patch) { - ResultCount.Builder resultCountBuilder = ResultCount.newBuilder(); + public ValidationSummary validate(Patch patch) { + ValidationSummary.Builder builder = ValidationSummary.newBuilder(); - Report.Builder builder = Report.newBuilder(); - builder.setPatch(patch); int error = 0; for (MessagePatch messageResult : patch.getMessagePatchesMap().values()) { if (skipValidationForAlpha(messageResult.getPackage())) { continue; } - switch (messageResult.getChange().getChangeType()) { + switch (messageResult.getNameChange().getChangeType()) { case REMOVAL: error++; - resultCountBuilder.addErrorInfo( + builder.addErrorInfo( ErrorInfo.newBuilder() - .setType(ErrorInfo.ErrorType.ERROR) + .setType(ErrorType.ERROR) .setMessage(messageResult.getName()) .setCode("CAVR-0001") .setDescription( @@ -61,9 +59,9 @@ public Report validate(Patch patch) { switch (fieldResult.getChange().getChangeType()) { case REMOVAL: error++; - resultCountBuilder.addErrorInfo( + builder.addErrorInfo( ErrorInfo.newBuilder() - .setType(ErrorInfo.ErrorType.ERROR) + .setType(ErrorType.ERROR) .setField(messageResult.getName() + "#" + fieldResult.getName()) .setCode("CAVR-0001") .setDescription( @@ -72,9 +70,9 @@ public Report validate(Patch patch) { break; case RESERVED: error++; - resultCountBuilder.addErrorInfo( + builder.addErrorInfo( ErrorInfo.newBuilder() - .setType(ErrorInfo.ErrorType.ERROR) + .setType(ErrorType.ERROR) .setField(messageResult.getName() + "#" + fieldResult.getName()) .setCode("CAVR-0002") .setDescription( @@ -84,9 +82,9 @@ public Report validate(Patch patch) { break; case CHANGED: error++; - resultCountBuilder.addErrorInfo( + builder.addErrorInfo( ErrorInfo.newBuilder() - .setType(ErrorInfo.ErrorType.ERROR) + .setType(ErrorType.ERROR) .setField(messageResult.getName() + "#" + fieldResult.getName()) .setCode("CAVR-0003") .setDescription( @@ -108,12 +106,12 @@ public Report validate(Patch patch) { if (skipValidationForAlpha(enumResult.getPackage())) { continue; } - switch (enumResult.getChange().getChangeType()) { + switch (enumResult.getNameChange().getChangeType()) { case REMOVAL: error++; - resultCountBuilder.addErrorInfo( + builder.addErrorInfo( ErrorInfo.newBuilder() - .setType(ErrorInfo.ErrorType.ERROR) + .setType(ErrorType.ERROR) .setEnum(enumResult.getName()) .setCode("CAVR-0001") .setDescription( @@ -132,12 +130,12 @@ public Report validate(Patch patch) { break; } for (EnumValuePatch valueResult : enumResult.getValuePatchesList()) { - switch (valueResult.getChange().getChangeType()) { + switch (valueResult.getValueChange().getChangeType()) { case REMOVAL: error++; - resultCountBuilder.addErrorInfo( + builder.addErrorInfo( ErrorInfo.newBuilder() - .setType(ErrorInfo.ErrorType.ERROR) + .setType(ErrorType.ERROR) .setField(enumResult.getName() + "#" + valueResult.getName()) .setCode("CAVR-0001") .setDescription( @@ -147,9 +145,9 @@ public Report validate(Patch patch) { break; case RESERVED: error++; - resultCountBuilder.addErrorInfo( + builder.addErrorInfo( ErrorInfo.newBuilder() - .setType(ErrorInfo.ErrorType.ERROR) + .setType(ErrorType.ERROR) .setField(enumResult.getName() + "#" + valueResult.getName()) .setCode("CAVR-0002") .setDescription( @@ -159,9 +157,9 @@ public Report validate(Patch patch) { break; case CHANGED: error++; - resultCountBuilder.addErrorInfo( + builder.addErrorInfo( ErrorInfo.newBuilder() - .setType(ErrorInfo.ErrorType.ERROR) + .setType(ErrorType.ERROR) .setField(enumResult.getName() + "#" + valueResult.getName()) .setCode("CAVR-0003") .setDescription( @@ -179,7 +177,7 @@ public Report validate(Patch patch) { } } } - builder.setResultCount(resultCountBuilder.setDiffErrors(error).build()); + builder.setDiffErrors(error); return builder.build(); } } diff --git a/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowAll.java b/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowAll.java index 8cbcda0..770403b 100644 --- a/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowAll.java +++ b/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowAll.java @@ -1,14 +1,14 @@ package io.anemos.metastore.core.proto.profile; import io.anemos.metastore.v1alpha1.Patch; -import io.anemos.metastore.v1alpha1.Report; +import io.anemos.metastore.v1alpha1.ValidationSummary; public class ProfileAllowAll implements ValidationProfile { public String profileName = "proto:allow"; @Override - public Report validate(Patch patch) { - return Report.newBuilder().setPatch(patch).build(); + public ValidationSummary validate(Patch patch) { + return ValidationSummary.getDefaultInstance(); } } diff --git a/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowNone.java b/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowNone.java index 940c909..2cb916f 100644 --- a/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowNone.java +++ b/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowNone.java @@ -1,7 +1,7 @@ package io.anemos.metastore.core.proto.profile; import io.anemos.metastore.v1alpha1.Patch; -import io.anemos.metastore.v1alpha1.Report; +import io.anemos.metastore.v1alpha1.ValidationSummary; public class ProfileAllowNone implements ValidationProfile { @@ -9,7 +9,7 @@ public class ProfileAllowNone implements ValidationProfile { // TODO implement @Override - public Report validate(Patch patch) { - return Report.newBuilder().setPatch(patch).build(); + public ValidationSummary validate(Patch patch) { + return ValidationSummary.getDefaultInstance(); } } diff --git a/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileProtoEvolve.java b/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileProtoEvolve.java index 2dbc936..a0370c5 100644 --- a/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileProtoEvolve.java +++ b/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileProtoEvolve.java @@ -1,14 +1,14 @@ package io.anemos.metastore.core.proto.profile; import io.anemos.metastore.v1alpha1.Patch; -import io.anemos.metastore.v1alpha1.Report; +import io.anemos.metastore.v1alpha1.ValidationSummary; public class ProfileProtoEvolve implements ValidationProfile { public String profileName = "proto:default"; @Override - public Report validate(Patch patch) { + public ValidationSummary validate(Patch patch) { return null; } } diff --git a/core/src/main/java/io/anemos/metastore/core/proto/profile/ValidationProfile.java b/core/src/main/java/io/anemos/metastore/core/proto/profile/ValidationProfile.java index 0230488..cc7a942 100644 --- a/core/src/main/java/io/anemos/metastore/core/proto/profile/ValidationProfile.java +++ b/core/src/main/java/io/anemos/metastore/core/proto/profile/ValidationProfile.java @@ -1,9 +1,9 @@ package io.anemos.metastore.core.proto.profile; import io.anemos.metastore.v1alpha1.Patch; -import io.anemos.metastore.v1alpha1.Report; +import io.anemos.metastore.v1alpha1.ValidationSummary; public interface ValidationProfile { - Report validate(Patch patch); + ValidationSummary validate(Patch patch); } diff --git a/core/src/main/java/io/anemos/metastore/core/proto/validate/ProtoLint.java b/core/src/main/java/io/anemos/metastore/core/proto/validate/ProtoLint.java index d31f90e..87d8dbf 100644 --- a/core/src/main/java/io/anemos/metastore/core/proto/validate/ProtoLint.java +++ b/core/src/main/java/io/anemos/metastore/core/proto/validate/ProtoLint.java @@ -2,7 +2,7 @@ import com.google.protobuf.Descriptors; import io.anemos.metastore.putils.ProtoDomain; -import io.anemos.metastore.v1alpha1.LintRule; +import io.anemos.metastore.v1alpha1.Rule; import java.util.ArrayList; import java.util.List; @@ -37,7 +37,7 @@ public void lintOnService(Descriptors.ServiceDescriptor service) { String name = service.getName(); if (!isPascalCase(name)) { results.addResult( - service, LintRule.newBuilder().setLintRule("LINT_SERVICE_NAME_SHOULD_BE_PASCAL").build()); + service, Rule.newBuilder().setRuleName("LINT_SERVICE_NAME_SHOULD_BE_PASCAL").build()); } service.getMethods().forEach(m -> lintMethod(m)); @@ -71,7 +71,7 @@ private void lintMessage(Descriptors.Descriptor dp) { String name = dp.getName(); if (!isPascalCase(name)) { results.addResult( - dp, LintRule.newBuilder().setLintRule("LINT_MESSAGE_NAME_SHOULD_BE_PASCAL").build()); + dp, Rule.newBuilder().setRuleName("LINT_MESSAGE_NAME_SHOULD_BE_PASCAL").build()); } dp.getFields().forEach(fd -> lintField(fd)); @@ -80,11 +80,11 @@ private void lintMessage(Descriptors.Descriptor dp) { private void lintMethod(Descriptors.MethodDescriptor md) { if (!md.getInputType().getFullName().endsWith("Request")) { results.addResult( - md, LintRule.newBuilder().setLintRule("LINT_METHOD_ITYPE_END_WITH_REQUEST").build()); + md, Rule.newBuilder().setRuleName("LINT_METHOD_ITYPE_END_WITH_REQUEST").build()); } if (!md.getOutputType().getFullName().endsWith("Response")) { results.addResult( - md, LintRule.newBuilder().setLintRule("LINT_METHOD_RTYPE_END_WITH_RESPONSE").build()); + md, Rule.newBuilder().setRuleName("LINT_METHOD_RTYPE_END_WITH_RESPONSE").build()); } } @@ -93,7 +93,7 @@ private void lintField(Descriptors.FieldDescriptor fd) { String suffix = isSnakeCase(name); if (suffix != null) { results.addResult( - fd, LintRule.newBuilder().setLintRule("LINT_FIELD_NAME_SHOULD_BE_SNAKE").build()); + fd, Rule.newBuilder().setRuleName("LINT_FIELD_NAME_SHOULD_BE_SNAKE").build()); } } @@ -163,8 +163,7 @@ public void lintOnPackage(Descriptors.FileDescriptor fileDescriptor) { String dirName = fileName.substring(0, fileName.lastIndexOf("/")).replace("/", "."); if (!dirName.equals(protoPackageName)) { results.addResult( - fileDescriptor, - LintRule.newBuilder().setLintRule("LINT_PACKAGE_NO_DIR_ALIGNMENT").build()); + fileDescriptor, Rule.newBuilder().setRuleName("LINT_PACKAGE_NO_DIR_ALIGNMENT").build()); } } @@ -184,7 +183,7 @@ public void lintOnVersion(Descriptors.Descriptor ref) { if (!dependencyVersion.equals(protoVersion)) { results.addResult( fileDescriptor, - LintRule.newBuilder().setLintRule("LINT_PACKAGE_NO_VERSION_ALIGNMENT").build()); + Rule.newBuilder().setRuleName("LINT_PACKAGE_NO_VERSION_ALIGNMENT").build()); } } } @@ -219,7 +218,7 @@ public void lintOnImport(Descriptors.Descriptor ref) { } if (!dependencyUsed) { results.addResult( - fileDescriptor, LintRule.newBuilder().setLintRule("LINT_IMPORT_NO_ALIGNMENT").build()); + fileDescriptor, Rule.newBuilder().setRuleName("LINT_IMPORT_NO_ALIGNMENT").build()); } } } diff --git a/core/src/main/java/io/anemos/metastore/core/proto/validate/ValidationResults.java b/core/src/main/java/io/anemos/metastore/core/proto/validate/ValidationResults.java index 7fe2174..7d409ff 100644 --- a/core/src/main/java/io/anemos/metastore/core/proto/validate/ValidationResults.java +++ b/core/src/main/java/io/anemos/metastore/core/proto/validate/ValidationResults.java @@ -13,8 +13,8 @@ public class ValidationResults { private Map enumMap = new HashMap<>(); private Map serviceMap = new HashMap<>(); - public List getInfo(String messageName, String fieldName) { - List rules = new ArrayList<>(); + public List getInfo(String messageName, String fieldName) { + List rules = new ArrayList<>(); MessagePatchContainer messageResult = messageMap.get(messageName); if (messageResult != null) { FieldPatchContainer fieldResultContainer = messageResult.fieldMap.get(fieldName); @@ -72,27 +72,27 @@ private EnumPatchContainer getOrCreateEnum(Descriptors.EnumDescriptor enumDescri return enumResult; } - void addResult(Descriptors.FieldDescriptor fd, LintRule ruleInfo) { + void addResult(Descriptors.FieldDescriptor fd, Rule ruleInfo) { MessagePatchContainer messageResult = getOrCreateMessage(fd.getContainingType()); messageResult.add(fd, ruleInfo); } - void addResult(Descriptors.MethodDescriptor md, LintRule ruleInfo) { + void addResult(Descriptors.MethodDescriptor md, Rule ruleInfo) { ServicePatchContainer messageResult = getOrCreateService(md.getService()); messageResult.add(md, ruleInfo); } - void addResult(Descriptors.Descriptor descriptor, LintRule ruleInfo) { + void addResult(Descriptors.Descriptor descriptor, Rule ruleInfo) { MessagePatchContainer messageResult = getOrCreateMessage(descriptor); messageResult.addResult(ruleInfo); } - void addResult(Descriptors.ServiceDescriptor descriptor, LintRule ruleInfo) { + void addResult(Descriptors.ServiceDescriptor descriptor, Rule ruleInfo) { ServicePatchContainer serviceResult = getOrCreateService(descriptor); serviceResult.addResult(ruleInfo); } - void addResult(Descriptors.FileDescriptor descriptor, LintRule ruleInfo) { + void addResult(Descriptors.FileDescriptor descriptor, Rule ruleInfo) { FilePatchContainer fileResult = getOrCreateFile(descriptor.getFullName()); fileResult.addResult(ruleInfo); } @@ -169,13 +169,13 @@ public Patch createProto() { } static class FieldPatchContainer { - List info = new ArrayList<>(); + List info = new ArrayList<>(); List optionChanges = new ArrayList<>(); FieldChange patch; String name; int number; - public void add(LintRule ruleInfo) { + public void add(Rule ruleInfo) { info.add(ruleInfo); } @@ -184,7 +184,7 @@ public FieldPatch createProto() { FieldPatch.newBuilder() .setName(name) .setNumber(number) - .addAllInfo(info) + .addAllRule(info) .addAllOptionChange(optionChanges); if (patch != null) { builder.setChange(patch); @@ -205,12 +205,12 @@ static class MessagePatchContainer { String packageName; String fullName; - List info = new ArrayList<>(); + List info = new ArrayList<>(); Map fieldMap = new HashMap<>(); Change patch; List optionChanges = new ArrayList<>(); - public void add(Descriptors.FieldDescriptor field, LintRule ruleInfo) { + public void add(Descriptors.FieldDescriptor field, Rule ruleInfo) { FieldPatchContainer fieldResultContainer = getOrCreateFieldContainer(field); fieldResultContainer.add(ruleInfo); } @@ -236,15 +236,15 @@ MessagePatch createProto() { messageInfo.setName(fullName); messageInfo.setPackage(packageName); if (patch != null) { - messageInfo.setChange(patch); + messageInfo.setNameChange(patch); } fieldMap.values().forEach(field -> messageInfo.addFieldPatches(field.createProto())); - messageInfo.addAllInfo(info); + messageInfo.addAllRule(info); messageInfo.addAllOptionChange(optionChanges); return messageInfo.build(); } - void addResult(LintRule ruleInfo) { + void addResult(Rule ruleInfo) { info.add(ruleInfo); } @@ -265,7 +265,7 @@ void addOptionChange(Descriptors.FieldDescriptor field, OptionChange optionChang class FilePatchContainer { String fullName; - List info = new ArrayList<>(); + List info = new ArrayList<>(); // Map fieldMap = new HashMap<>(); Change patch; List optionChanges = new ArrayList<>(); @@ -280,7 +280,7 @@ public FilePatch createProto() { FilePatch.Builder builder = FilePatch.newBuilder() .setFileName(fullName) - .addAllInfo(info) + .addAllRule(info) .addAllOptionChange(optionChanges) .addAllImportChange(importChange); if (patch != null) { @@ -289,7 +289,7 @@ public FilePatch createProto() { return builder.build(); } - void addResult(LintRule ruleInfo) { + void addResult(Rule ruleInfo) { info.add(ruleInfo); } @@ -306,11 +306,11 @@ class ServicePatchContainer { String packageName; String fullName; - List info = new ArrayList<>(); + List info = new ArrayList<>(); Map methodMap = new HashMap<>(); Change patch; - public void add(Descriptors.MethodDescriptor method, LintRule ruleInfo) { + public void add(Descriptors.MethodDescriptor method, Rule ruleInfo) { MethodPatchContainer methoddResultContainer = getOrCreateMethodContainer(method); methoddResultContainer.add(ruleInfo); } @@ -335,14 +335,14 @@ ServicePatch createProto() { serviceInfo.setPackage(packageName); serviceInfo.setName(fullName); if (patch != null) { - serviceInfo.setChange(patch); + serviceInfo.setNameChange(patch); } methodMap.values().forEach(method -> serviceInfo.addMethodPatches(method.createProto())); - serviceInfo.addAllInfo(info); + serviceInfo.addAllRule(info); return serviceInfo.build(); } - void addResult(LintRule ruleInfo) { + void addResult(Rule ruleInfo) { info.add(ruleInfo); } @@ -352,18 +352,18 @@ void setPatch(Change patch) { } static class MethodPatchContainer { - List info = new ArrayList<>(); + List info = new ArrayList<>(); MethodChange patch; String fullName; - public void add(LintRule ruleInfo) { + public void add(Rule ruleInfo) { info.add(ruleInfo); } public MethodPatch createProto() { - MethodPatch.Builder builder = MethodPatch.newBuilder().setName(fullName).addAllInfo(info); + MethodPatch.Builder builder = MethodPatch.newBuilder().setName(fullName).addAllRule(info); if (patch != null) { - builder.setChange(patch); + builder.setMethodChange(patch); } return builder.build(); } @@ -377,11 +377,11 @@ class EnumPatchContainer { String packageName; String fullName; - List info = new ArrayList<>(); + List info = new ArrayList<>(); Map valueMap = new HashMap<>(); Change patch; - public void add(Descriptors.EnumValueDescriptor value, LintRule ruleInfo) { + public void add(Descriptors.EnumValueDescriptor value, Rule ruleInfo) { EnumValuePatchContainer methodResultContainer = getOrCreateValueContainer(value); methodResultContainer.add(ruleInfo); } @@ -408,14 +408,14 @@ EnumPatch createProto() { messageInfo.setPackage(packageName); messageInfo.setName(fullName); if (patch != null) { - messageInfo.setChange(patch); + messageInfo.setNameChange(patch); } valueMap.values().forEach(method -> messageInfo.addValuePatches(method.createProto())); - messageInfo.addAllInfo(info); + messageInfo.addAllRule(info); return messageInfo.build(); } - void addResult(LintRule ruleInfo) { + void addResult(Rule ruleInfo) { info.add(ruleInfo); } @@ -425,20 +425,20 @@ void setPatch(Change patch) { } static class EnumValuePatchContainer { - List info = new ArrayList<>(); + List info = new ArrayList<>(); EnumValueChange patch; String fullName; int number; - public void add(LintRule ruleInfo) { + public void add(Rule ruleInfo) { info.add(ruleInfo); } public EnumValuePatch createProto() { EnumValuePatch.Builder builder = - EnumValuePatch.newBuilder().setName(fullName).setNumber(number).addAllInfo(info); + EnumValuePatch.newBuilder().setName(fullName).setNumber(number).addAllRule(info); if (patch != null) { - builder.setChange(patch); + builder.setValueChange(patch); } return builder.build(); } diff --git a/core/src/main/java/io/anemos/metastore/core/registry/AbstractRegistry.java b/core/src/main/java/io/anemos/metastore/core/registry/AbstractRegistry.java index 0d12e13..17b29fc 100644 --- a/core/src/main/java/io/anemos/metastore/core/registry/AbstractRegistry.java +++ b/core/src/main/java/io/anemos/metastore/core/registry/AbstractRegistry.java @@ -11,8 +11,8 @@ import io.anemos.metastore.provider.StorageProvider; import io.anemos.metastore.putils.ProtoDomain; import io.anemos.metastore.v1alpha1.BindP; +import io.anemos.metastore.v1alpha1.Patch; import io.anemos.metastore.v1alpha1.RegistryP; -import io.anemos.metastore.v1alpha1.Report; import io.grpc.Status; import io.grpc.StatusException; import java.net.URI; @@ -74,7 +74,7 @@ public abstract class AbstractRegistry implements RegistryInfo { public abstract ProtoDomain ref(); - public abstract void update(ProtoDomain ref, ProtoDomain in, Report report, RegistryP.Note note); + public abstract void update(ProtoDomain ref, ProtoDomain in, Patch patch, RegistryP.Note note); void syncGitRepo(RegistryP.Note note) { metaGit.sync(protoContainer, note); @@ -188,10 +188,10 @@ private T loadProvider(Class clazz, String className) { } } - void notifyEventListeners(Report report) { + void notifyEventListeners(Patch patch) { eventingProviders.forEach( provider -> { - provider.descriptorsChanged(report); + provider.descriptorsChanged(patch); }); } diff --git a/core/src/main/java/io/anemos/metastore/core/registry/SchemaRegistry.java b/core/src/main/java/io/anemos/metastore/core/registry/SchemaRegistry.java index b43bf88..312f499 100644 --- a/core/src/main/java/io/anemos/metastore/core/registry/SchemaRegistry.java +++ b/core/src/main/java/io/anemos/metastore/core/registry/SchemaRegistry.java @@ -4,8 +4,8 @@ import io.anemos.metastore.config.RegistryConfig; import io.anemos.metastore.provider.StorageProvider; import io.anemos.metastore.putils.ProtoDomain; +import io.anemos.metastore.v1alpha1.Patch; import io.anemos.metastore.v1alpha1.RegistryP; -import io.anemos.metastore.v1alpha1.Report; import java.io.IOException; class SchemaRegistry extends AbstractRegistry { @@ -41,11 +41,11 @@ public ProtoDomain ref() { } @Override - public void update(ProtoDomain ref, ProtoDomain in, Report report, RegistryP.Note note) { + public void update(ProtoDomain ref, ProtoDomain in, Patch patch, RegistryP.Note note) { protoContainer = in; update(note); syncGitRepo(note); - notifyEventListeners(report); + notifyEventListeners(patch); } @Override diff --git a/core/src/main/java/io/anemos/metastore/core/registry/ShadowRegistry.java b/core/src/main/java/io/anemos/metastore/core/registry/ShadowRegistry.java index 0a06535..3607f27 100644 --- a/core/src/main/java/io/anemos/metastore/core/registry/ShadowRegistry.java +++ b/core/src/main/java/io/anemos/metastore/core/registry/ShadowRegistry.java @@ -8,7 +8,6 @@ import io.anemos.metastore.putils.ProtoDomain; import io.anemos.metastore.v1alpha1.Patch; import io.anemos.metastore.v1alpha1.RegistryP; -import io.anemos.metastore.v1alpha1.Report; import io.grpc.StatusException; import java.io.IOException; @@ -64,7 +63,7 @@ public ProtoDomain ref() { } @Override - public void update(ProtoDomain ref, ProtoDomain in, Report report, RegistryP.Note note) { + public void update(ProtoDomain ref, ProtoDomain in, Patch patch, RegistryP.Note note) { ValidationResults results = new ValidationResults(); ProtoDiff diff = new ProtoDiff(ref, in, results); if (registryConfig.getScope() != null) { @@ -76,7 +75,7 @@ public void update(ProtoDomain ref, ProtoDomain in, Report report, RegistryP.Not } patch = results.createProto(); update(note); - notifyEventListeners(report); + notifyEventListeners(patch); } @Override diff --git a/core/src/main/java/io/anemos/metastore/provider/EventingProvider.java b/core/src/main/java/io/anemos/metastore/provider/EventingProvider.java index f205e54..d31a783 100644 --- a/core/src/main/java/io/anemos/metastore/provider/EventingProvider.java +++ b/core/src/main/java/io/anemos/metastore/provider/EventingProvider.java @@ -1,6 +1,6 @@ package io.anemos.metastore.provider; -import io.anemos.metastore.v1alpha1.Report; +import io.anemos.metastore.v1alpha1.Patch; import java.util.Map; /** @@ -12,5 +12,5 @@ public interface EventingProvider { void initForChangeEvent(RegistryInfo registryInfo, Map config); /** Send event for descriptor changes. */ - void descriptorsChanged(Report report); + void descriptorsChanged(Patch patch); } diff --git a/core/src/test/java/io/anemos/metastore/core/proto/profile/ProfileTest.java b/core/src/test/java/io/anemos/metastore/core/proto/profile/ProfileTest.java index ddfde57..e03d5f9 100644 --- a/core/src/test/java/io/anemos/metastore/core/proto/profile/ProfileTest.java +++ b/core/src/test/java/io/anemos/metastore/core/proto/profile/ProfileTest.java @@ -9,7 +9,7 @@ import io.anemos.metastore.core.proto.validate.ValidationResults; import io.anemos.metastore.putils.ProtoDomain; import io.anemos.metastore.v1alpha1.Patch; -import io.anemos.metastore.v1alpha1.Report; +import io.anemos.metastore.v1alpha1.ValidationSummary; import java.io.IOException; import org.junit.Test; @@ -26,9 +26,9 @@ public void profileAllowAdd_RemoveFieldV1() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); - Report report = new ProfileAllowAdd().validate(patch); - assertEquals(1, report.getPatch().getMessagePatchesCount()); - assertEquals(1, report.getResultCount().getDiffErrors()); + ValidationSummary report = new ProfileAllowAdd().validate(patch); + assertEquals(1, patch.getMessagePatchesCount()); + assertEquals(1, report.getDiffErrors()); } @Test @@ -42,9 +42,9 @@ public void profileAllowAdd_RemoveFieldV1Alpha() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); - Report report = new ProfileAllowAdd().validate(patch); - assertEquals(1, report.getPatch().getMessagePatchesCount()); - assertEquals(1, report.getResultCount().getDiffErrors()); + ValidationSummary report = new ProfileAllowAdd().validate(patch); + assertEquals(1, patch.getMessagePatchesCount()); + assertEquals(1, report.getDiffErrors()); } @Test @@ -58,9 +58,9 @@ public void profileAllowStableAddAddAlpha_RemoveFieldV1() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); - Report report = new ProfileAllowStableAddAlphaAll().validate(patch); - assertEquals(1, report.getPatch().getMessagePatchesCount()); - assertEquals(1, report.getResultCount().getDiffErrors()); + ValidationSummary report = new ProfileAllowStableAddAlphaAll().validate(patch); + assertEquals(1, patch.getMessagePatchesCount()); + assertEquals(1, report.getDiffErrors()); } @Test @@ -74,9 +74,9 @@ public void profileAllowStableAddAddAlpha_RemoveFieldV1Alpha() throws Exception ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); - Report report = new ProfileAllowStableAddAlphaAll().validate(patch); - assertEquals(1, report.getPatch().getMessagePatchesCount()); - assertEquals(0, report.getResultCount().getDiffErrors()); + ValidationSummary report = new ProfileAllowStableAddAlphaAll().validate(patch); + assertEquals(1, patch.getMessagePatchesCount()); + assertEquals(0, report.getDiffErrors()); } private Patch diff(ProtoDomain dRef, ProtoDomain dNew) throws IOException { diff --git a/core/src/test/java/io/anemos/metastore/core/proto/validation/DiffTest.java b/core/src/test/java/io/anemos/metastore/core/proto/validation/DiffTest.java index a02d16f..d45b707 100644 --- a/core/src/test/java/io/anemos/metastore/core/proto/validation/DiffTest.java +++ b/core/src/test/java/io/anemos/metastore/core/proto/validation/DiffTest.java @@ -170,7 +170,10 @@ public void toBaseExtraFileAdded() throws IOException { Assert.assertEquals(1, patch.getMessagePatchesCount()); Assert.assertEquals( ChangeType.ADDITION, - patch.getMessagePatchesOrThrow("test.v1.ProtoExtraMessage").getChange().getChangeType()); + patch + .getMessagePatchesOrThrow("test.v1.ProtoExtraMessage") + .getNameChange() + .getChangeType()); } @Test @@ -185,7 +188,10 @@ public void toBaseExtraFileRemoved() throws IOException { Assert.assertEquals(1, patch.getMessagePatchesCount()); Assert.assertEquals( ChangeType.REMOVAL, - patch.getMessagePatchesOrThrow("test.v1.ProtoExtraMessage").getChange().getChangeType()); + patch + .getMessagePatchesOrThrow("test.v1.ProtoExtraMessage") + .getNameChange() + .getChangeType()); } private FieldPatch diff(ProtoDomain dRef, ProtoDomain dNew) throws IOException { diff --git a/core/src/test/java/io/anemos/metastore/core/proto/validation/LintTest.java b/core/src/test/java/io/anemos/metastore/core/proto/validation/LintTest.java index 1c0a0bc..46f3cef 100644 --- a/core/src/test/java/io/anemos/metastore/core/proto/validation/LintTest.java +++ b/core/src/test/java/io/anemos/metastore/core/proto/validation/LintTest.java @@ -114,47 +114,47 @@ private Patch lintService(Descriptors.Descriptor ref, String name) throws IOExce return results.createProto(); } - private List getInfoForField(MessagePatch mr, int fieldNumber) { + private List getInfoForField(MessagePatch mr, int fieldNumber) { for (FieldPatch fieldResult : mr.getFieldPatchesList()) { if (fieldResult.getNumber() == fieldNumber) { - return fieldResult.getInfoList(); + return fieldResult.getRuleList(); } } Assert.assertNotNull(null); return null; } - private List getInfoForMethod(ServicePatch mr, String methodName) { + private List getInfoForMethod(ServicePatch mr, String methodName) { for (MethodPatch methodResult : mr.getMethodPatchesList()) { if (methodResult.getName().equals(methodName)) { - return methodResult.getInfoList(); + return methodResult.getRuleList(); } } return null; } private void assertOnMethod(ServicePatch mr, String methodName, String expecredRule) { - List infoForField = getInfoForMethod(mr, methodName); + List infoForField = getInfoForMethod(mr, methodName); String code = null; String rule = null; - for (LintRule ruleInfo : infoForField) { - if (ruleInfo.getLintRule().equals(expecredRule)) { + for (Rule ruleInfo : infoForField) { + if (ruleInfo.getRuleName().equals(expecredRule)) { return; } - rule = ruleInfo.getLintRule(); + rule = ruleInfo.getRuleName(); } Assert.assertEquals(expecredRule, rule); } private void assertOnField(MessagePatch mr, int fieldNumber, String expecredRule) { - List infoForField = getInfoForField(mr, fieldNumber); + List infoForField = getInfoForField(mr, fieldNumber); String code = null; String rule = null; - for (LintRule ruleInfo : infoForField) { - if (ruleInfo.getLintRule().equals(expecredRule)) { + for (Rule ruleInfo : infoForField) { + if (ruleInfo.getRuleName().equals(expecredRule)) { return; } - rule = ruleInfo.getLintRule(); + rule = ruleInfo.getRuleName(); } Assert.assertEquals(expecredRule, rule); } @@ -162,11 +162,11 @@ private void assertOnField(MessagePatch mr, int fieldNumber, String expecredRule private void assertOnMessage(MessagePatch mr, String expectedRule) { String code = null; String rule = null; - for (LintRule ruleInfo : mr.getInfoList()) { - if (ruleInfo.getLintRule().equals(expectedRule)) { + for (Rule ruleInfo : mr.getRuleList()) { + if (ruleInfo.getRuleName().equals(expectedRule)) { return; } - rule = ruleInfo.getLintRule(); + rule = ruleInfo.getRuleName(); } Assert.assertEquals(expectedRule, rule); } @@ -191,11 +191,11 @@ public void packageScopeVersionInvalid() throws IOException { private void assertOnFile(FilePatch fr, String expectedRule) { String code = null; String rule = null; - for (LintRule ruleInfo : fr.getInfoList()) { - if (ruleInfo.getLintRule().equals(expectedRule)) { + for (Rule ruleInfo : fr.getRuleList()) { + if (ruleInfo.getRuleName().equals(expectedRule)) { return; } - rule = ruleInfo.getLintRule(); + rule = ruleInfo.getRuleName(); } Assert.assertEquals(expectedRule, rule); } diff --git a/core/src/test/java/io/anemos/metastore/core/proto/validation/ProtoDiffTest.java b/core/src/test/java/io/anemos/metastore/core/proto/validation/ProtoDiffTest.java index 377df6c..3f0409b 100644 --- a/core/src/test/java/io/anemos/metastore/core/proto/validation/ProtoDiffTest.java +++ b/core/src/test/java/io/anemos/metastore/core/proto/validation/ProtoDiffTest.java @@ -154,8 +154,8 @@ public void addEnum() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); EnumPatch result = patch.getEnumPatchesMap().get("package.v1.Enum2"); - Assert.assertEquals("package.v1.Enum2", result.getChange().getToName()); - Assert.assertEquals(ChangeType.ADDITION, result.getChange().getChangeType()); + Assert.assertEquals("package.v1.Enum2", result.getNameChange().getToName()); + Assert.assertEquals(ChangeType.ADDITION, result.getNameChange().getChangeType()); } @Test @@ -166,8 +166,8 @@ public void removeEnum() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); EnumPatch result = patch.getEnumPatchesMap().get("package.v1.Enum1"); - Assert.assertEquals("package.v1.Enum1", result.getChange().getFromName()); - Assert.assertEquals(ChangeType.REMOVAL, result.getChange().getChangeType()); + Assert.assertEquals("package.v1.Enum1", result.getNameChange().getFromName()); + Assert.assertEquals(ChangeType.REMOVAL, result.getNameChange().getChangeType()); } @Test @@ -190,12 +190,14 @@ public void addEnumValue() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); EnumPatch result = patch.getEnumPatchesMap().get("package.v1.Enum1"); - Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); - Assert.assertEquals(ChangeType.ADDITION, result.getValuePatches(0).getChange().getChangeType()); + Assert.assertEquals(ChangeType.UNCHANGED, result.getNameChange().getChangeType()); + Assert.assertEquals( + ChangeType.ADDITION, result.getValuePatches(0).getValueChange().getChangeType()); Assert.assertEquals(2, result.getValuePatches(0).getNumber()); Assert.assertEquals("ENUM_VALUE1_VALUE2", result.getValuePatches(0).getName()); - Assert.assertEquals("", result.getValuePatches(0).getChange().getFromName()); - Assert.assertEquals("ENUM_VALUE1_VALUE2", result.getValuePatches(0).getChange().getToName()); + Assert.assertEquals("", result.getValuePatches(0).getValueChange().getFromName()); + Assert.assertEquals( + "ENUM_VALUE1_VALUE2", result.getValuePatches(0).getValueChange().getToName()); } @Test @@ -210,12 +212,14 @@ public void removeEnumValue() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); EnumPatch result = patch.getEnumPatchesMap().get("package.v1.Enum1"); - Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); - Assert.assertEquals(ChangeType.REMOVAL, result.getValuePatches(0).getChange().getChangeType()); + Assert.assertEquals(ChangeType.UNCHANGED, result.getNameChange().getChangeType()); + Assert.assertEquals( + ChangeType.REMOVAL, result.getValuePatches(0).getValueChange().getChangeType()); Assert.assertEquals(1, result.getValuePatches(0).getNumber()); Assert.assertEquals("ENUM_VALUE1_VALUE1", result.getValuePatches(0).getName()); - Assert.assertEquals("ENUM_VALUE1_VALUE1", result.getValuePatches(0).getChange().getFromName()); - Assert.assertEquals("", result.getValuePatches(0).getChange().getToName()); + Assert.assertEquals( + "ENUM_VALUE1_VALUE1", result.getValuePatches(0).getValueChange().getFromName()); + Assert.assertEquals("", result.getValuePatches(0).getValueChange().getToName()); } @Test @@ -235,12 +239,14 @@ public void renameEnumValue() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); EnumPatch result = patch.getEnumPatchesMap().get("package.v1.Enum1"); - Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); - Assert.assertEquals(ChangeType.CHANGED, result.getValuePatches(0).getChange().getChangeType()); + Assert.assertEquals(ChangeType.UNCHANGED, result.getNameChange().getChangeType()); + Assert.assertEquals( + ChangeType.CHANGED, result.getValuePatches(0).getValueChange().getChangeType()); Assert.assertEquals(1, result.getValuePatches(0).getNumber()); Assert.assertEquals("FOO", result.getValuePatches(0).getName()); - Assert.assertEquals("ENUM_VALUE1_VALUE1", result.getValuePatches(0).getChange().getFromName()); - Assert.assertEquals("FOO", result.getValuePatches(0).getChange().getToName()); + Assert.assertEquals( + "ENUM_VALUE1_VALUE1", result.getValuePatches(0).getValueChange().getFromName()); + Assert.assertEquals("FOO", result.getValuePatches(0).getValueChange().getToName()); } @Test @@ -256,8 +262,8 @@ public void addMessage() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); MessagePatch result = patch.getMessagePatchesMap().get("package.v1.Message2"); - Assert.assertEquals("package.v1.Message2", result.getChange().getToName()); - Assert.assertEquals(ChangeType.ADDITION, result.getChange().getChangeType()); + Assert.assertEquals("package.v1.Message2", result.getNameChange().getToName()); + Assert.assertEquals(ChangeType.ADDITION, result.getNameChange().getChangeType()); } @Test @@ -268,8 +274,8 @@ public void removeMessage() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); MessagePatch result = patch.getMessagePatchesMap().get("package.v1.Message1"); - Assert.assertEquals("package.v1.Message1", result.getChange().getFromName()); - Assert.assertEquals(ChangeType.REMOVAL, result.getChange().getChangeType()); + Assert.assertEquals("package.v1.Message1", result.getNameChange().getFromName()); + Assert.assertEquals(ChangeType.REMOVAL, result.getNameChange().getChangeType()); } @Test @@ -293,7 +299,7 @@ public void addField() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); MessagePatch result = patch.getMessagePatchesMap().get("package.v1.Message1"); - Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); + Assert.assertEquals(ChangeType.UNCHANGED, result.getNameChange().getChangeType()); Assert.assertEquals(ChangeType.ADDITION, result.getFieldPatches(0).getChange().getChangeType()); Assert.assertEquals(4, result.getFieldPatches(0).getNumber()); Assert.assertEquals("fourth_field", result.getFieldPatches(0).getName()); @@ -313,7 +319,7 @@ public void removeField() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); MessagePatch result = patch.getMessagePatchesMap().get("package.v1.Message1"); - Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); + Assert.assertEquals(ChangeType.UNCHANGED, result.getNameChange().getChangeType()); Assert.assertEquals(ChangeType.REMOVAL, result.getFieldPatches(0).getChange().getChangeType()); Assert.assertEquals(1, result.getFieldPatches(0).getNumber()); Assert.assertEquals("first_field", result.getFieldPatches(0).getName()); @@ -340,7 +346,7 @@ public void renameField() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); MessagePatch result = patch.getMessagePatchesMap().get("package.v1.Message1"); - Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); + Assert.assertEquals(ChangeType.UNCHANGED, result.getNameChange().getChangeType()); Assert.assertEquals(ChangeType.CHANGED, result.getFieldPatches(0).getChange().getChangeType()); Assert.assertEquals(1, result.getFieldPatches(0).getNumber()); Assert.assertEquals("changed_field", result.getFieldPatches(0).getName()); @@ -373,7 +379,7 @@ public void changeFieldType() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); MessagePatch result = patch.getMessagePatchesMap().get("package.v1.Message1"); - Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); + Assert.assertEquals(ChangeType.UNCHANGED, result.getNameChange().getChangeType()); Assert.assertEquals(ChangeType.CHANGED, result.getFieldPatches(0).getChange().getChangeType()); Assert.assertEquals( "google.protobuf.StringValue", result.getFieldPatches(0).getChange().getFromTypeName()); @@ -405,7 +411,7 @@ public void changeComplexFieldType() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); MessagePatch result = patch.getMessagePatchesMap().get("package.v1.Message1"); - Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); + Assert.assertEquals(ChangeType.UNCHANGED, result.getNameChange().getChangeType()); Assert.assertEquals(ChangeType.CHANGED, result.getFieldPatches(0).getChange().getChangeType()); Assert.assertEquals( "google.protobuf.StringValue", result.getFieldPatches(0).getChange().getFromTypeName()); @@ -438,7 +444,7 @@ public void changeMessageFieldType() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); MessagePatch result = patch.getMessagePatchesMap().get("package.v1.TestSubMessage"); - Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); + Assert.assertEquals(ChangeType.UNCHANGED, result.getNameChange().getChangeType()); Assert.assertEquals(ChangeType.CHANGED, result.getFieldPatches(0).getChange().getChangeType()); Assert.assertEquals( "google.protobuf.StringValue", result.getFieldPatches(0).getChange().getFromTypeName()); @@ -459,8 +465,8 @@ public void addService() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); ServicePatch serviceResult = patch.getServicePatchesMap().get("package.v1.Service2"); - Assert.assertEquals("package.v1.Service2", serviceResult.getChange().getToName()); - Assert.assertEquals(ChangeType.ADDITION, serviceResult.getChange().getChangeType()); + Assert.assertEquals("package.v1.Service2", serviceResult.getNameChange().getToName()); + Assert.assertEquals(ChangeType.ADDITION, serviceResult.getNameChange().getChangeType()); } @Test @@ -471,8 +477,8 @@ public void removeService() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); ServicePatch serviceResult = patch.getServicePatchesMap().get("package.v1.Service1"); - Assert.assertEquals("package.v1.Service1", serviceResult.getChange().getFromName()); - Assert.assertEquals(ChangeType.REMOVAL, serviceResult.getChange().getChangeType()); + Assert.assertEquals("package.v1.Service1", serviceResult.getNameChange().getFromName()); + Assert.assertEquals(ChangeType.REMOVAL, serviceResult.getNameChange().getChangeType()); } @Test @@ -496,12 +502,12 @@ public void addMethod() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); ServicePatch result = patch.getServicePatchesMap().get("package.v1.Service1"); - Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); + Assert.assertEquals(ChangeType.UNCHANGED, result.getNameChange().getChangeType()); Assert.assertEquals( - ChangeType.ADDITION, result.getMethodPatches(0).getChange().getChangeType()); + ChangeType.ADDITION, result.getMethodPatches(0).getMethodChange().getChangeType()); Assert.assertEquals("Method2", result.getMethodPatches(0).getName()); - Assert.assertEquals("", result.getMethodPatches(0).getChange().getFromName()); - Assert.assertEquals("Method2", result.getMethodPatches(0).getChange().getToName()); + Assert.assertEquals("", result.getMethodPatches(0).getMethodChange().getFromName()); + Assert.assertEquals("Method2", result.getMethodPatches(0).getMethodChange().getToName()); } @Test @@ -516,11 +522,12 @@ public void removeMethod() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); ServicePatch result = patch.getServicePatchesMap().get("package.v1.Service1"); - Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); - Assert.assertEquals(ChangeType.REMOVAL, result.getMethodPatches(0).getChange().getChangeType()); + Assert.assertEquals(ChangeType.UNCHANGED, result.getNameChange().getChangeType()); + Assert.assertEquals( + ChangeType.REMOVAL, result.getMethodPatches(0).getMethodChange().getChangeType()); Assert.assertEquals("Method1", result.getMethodPatches(0).getName()); - Assert.assertEquals("Method1", result.getMethodPatches(0).getChange().getFromName()); - Assert.assertEquals("", result.getMethodPatches(0).getChange().getToName()); + Assert.assertEquals("Method1", result.getMethodPatches(0).getMethodChange().getFromName()); + Assert.assertEquals("", result.getMethodPatches(0).getMethodChange().getToName()); } @Test @@ -541,18 +548,19 @@ public void renameMethod() throws Exception { ProtoDomain dNew = ProtoDomain.builder().add(fd).build(); Patch patch = diff(dRef, dNew); ServicePatch result = patch.getServicePatchesMap().get("package.v1.Service1"); - Assert.assertEquals(ChangeType.UNCHANGED, result.getChange().getChangeType()); + Assert.assertEquals(ChangeType.UNCHANGED, result.getNameChange().getChangeType()); Assert.assertEquals( - ChangeType.ADDITION, result.getMethodPatches(0).getChange().getChangeType()); + ChangeType.ADDITION, result.getMethodPatches(0).getMethodChange().getChangeType()); Assert.assertEquals("MethodX", result.getMethodPatches(0).getName()); - Assert.assertEquals("", result.getMethodPatches(0).getChange().getFromName()); - Assert.assertEquals("MethodX", result.getMethodPatches(0).getChange().getToName()); + Assert.assertEquals("", result.getMethodPatches(0).getMethodChange().getFromName()); + Assert.assertEquals("MethodX", result.getMethodPatches(0).getMethodChange().getToName()); - Assert.assertEquals(ChangeType.REMOVAL, result.getMethodPatches(1).getChange().getChangeType()); + Assert.assertEquals( + ChangeType.REMOVAL, result.getMethodPatches(1).getMethodChange().getChangeType()); Assert.assertEquals("Method1", result.getMethodPatches(1).getName()); - Assert.assertEquals("Method1", result.getMethodPatches(1).getChange().getFromName()); - Assert.assertEquals("", result.getMethodPatches(1).getChange().getToName()); + Assert.assertEquals("Method1", result.getMethodPatches(1).getMethodChange().getFromName()); + Assert.assertEquals("", result.getMethodPatches(1).getMethodChange().getToName()); } private Patch diff(ProtoDomain dRef, ProtoDomain dNew) throws IOException { diff --git a/metastep/src/main/java/io/anemos/metastore/metastep/MetaStep.java b/metastep/src/main/java/io/anemos/metastore/metastep/MetaStep.java index 3f0fc16..12356d9 100644 --- a/metastep/src/main/java/io/anemos/metastore/metastep/MetaStep.java +++ b/metastep/src/main/java/io/anemos/metastore/metastep/MetaStep.java @@ -4,8 +4,7 @@ import io.anemos.metastore.putils.ProtoDomain; import io.anemos.metastore.v1alpha1.RegistryGrpc; import io.anemos.metastore.v1alpha1.RegistryP; -import io.anemos.metastore.v1alpha1.Report; -import io.anemos.metastore.v1alpha1.ResultCount; +import io.anemos.metastore.v1alpha1.ValidationSummary; import io.grpc.netty.shaded.io.grpc.netty.GrpcSslContexts; import io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder; import io.grpc.netty.shaded.io.netty.handler.ssl.SslContext; @@ -233,20 +232,22 @@ private void validate() throws IOException { RegistryP.SubmitSchemaResponse verifySchemaResponse = schemaRegistry.verifySchema(createSchemaRequest()); - Report report = verifySchemaResponse.getReport(); + ValidationSummary validationSummary = verifySchemaResponse.getValidationSummary(); - ResultCount resultCount = report.getResultCount(); int errors = 0, warnings = 0, infos = 0; - errors += resultCount.getDiffErrors(); - errors += resultCount.getLintErrors(); - warnings += resultCount.getLintWarnings(); - warnings += resultCount.getDiffWarnings(); - System.out.print(report); + errors += validationSummary.getDiffErrors(); + errors += validationSummary.getLintErrors(); + warnings += validationSummary.getLintWarnings(); + warnings += validationSummary.getDiffWarnings(); + System.out.print(verifySchemaResponse.getAppliedPatch()); + + System.out.print(validationSummary); System.out.println( String.format("%d errors, %d warnings and %d infos", errors, warnings, infos)); if (errors > 0) { - resultCount + verifySchemaResponse + .getValidationSummary() .getErrorInfoList() .forEach( e -> { diff --git a/proto/src/main/proto/grpc/registry/v1alpha1/patch.proto b/proto/src/main/proto/grpc/registry/v1alpha1/patch.proto index de18765..c74e566 100644 --- a/proto/src/main/proto/grpc/registry/v1alpha1/patch.proto +++ b/proto/src/main/proto/grpc/registry/v1alpha1/patch.proto @@ -7,11 +7,6 @@ option java_multiple_files = true; package grpc.registry.v1alpha1; -message Report { - Patch patch = 1; - ResultCount result_count = 5; -} - message Patch { map file_patches = 1; map message_patches = 2; @@ -19,36 +14,6 @@ message Patch { map service_patches = 4; } -message ResultCount { - int32 lint_errors = 1; - int32 lint_warnings = 2; - int32 lint_infos = 3; - int32 diff_errors = 4; - int32 diff_warnings = 5; - int32 diff_infos = 6; - - repeated ErrorInfo error_info = 7; -} - -message ErrorInfo { - enum ErrorType { - ERROR = 0; - WARNING = 1; - INFO = 2; - } - ErrorType type = 1; - oneof path { - string message = 3; - string field = 4; - string enum = 5; - string enum_value = 6; - string service = 7; - string method = 8; - } - string code = 9; - string description = 10; -} - enum ChangeType { UNCHANGED = 0; CHANGED = 1; @@ -61,69 +26,53 @@ enum ChangeType { PAYLOAD_CHANGED = 8; } -enum TypeChange { - TYPE_UNCHANGED = 0; - TYPE_SAFE = 1; - TYPE_LOOSE_INFO = 2; -} - -message LintRule { - string lint_rule = 1; - bool suppressed = 3; - google.protobuf.StringValue suppressed_comment = 4; +message Rule { + enum RuleType { + RULE_TYPE_UNKNOWN = 0; + RULE_TYPE_LINT = 1; + RULE_TYPE_CUSTOM = 15; + } + string rule_name = 1; + RuleType rule_type = 2; } // Generic Change message meant for top level objects like File, Message, // Enum and Service. As the don't contain any time information and are // actually containers they only support addition, renames and removals. message Change { - string from_name = 1; - string to_name = 2; - ChangeType change_type = 3; + ChangeType change_type = 1; + + string from_name = 2; + string to_name = 3; } message ImportChange { ChangeType change_type = 1; - string name = 2; -} - -message FilePatch { - string file_name = 1; - repeated string message_patch_ref = 2; - - repeated LintRule info = 3; - Change change = 4; - - repeated ImportChange import_change = 9; - repeated OptionChange option_change = 10; -} - -message MessagePatch { - string package = 1; string name = 2; +} - repeated LintRule info = 3; - - Change change = 4; - +message EnumValueChange { + ChangeType change_type = 1; - repeated FieldPatch field_patches = 5; + string from_name = 2; + bool from_deprecated = 4; + bool from_reserved = 5; - repeated OptionChange option_change = 10; + string to_name = 6; + bool to_deprecated = 8; + bool to_reserved = 9; } -message FieldPatch { - int32 number = 1; - string name = 2; - - repeated LintRule info = 3; +message MethodChange { + ChangeType change_type = 1; - FieldChange change = 4; + string from_name = 2; + bool from_deprecated = 4; - repeated OptionChange option_change = 10; + string to_name = 6; + bool to_deprecated = 8; } - message OptionChange { enum OptionType { OPTION_TYPE_UNSET = 0; @@ -183,36 +132,50 @@ message FieldChange { string to_type_name = 11; } -message EnumValueChange { - ChangeType change_type = 1; +message FilePatch { + string file_name = 1; + repeated string message_patch_ref = 2; - string from_name = 2; - bool from_deprecated = 4; - bool from_reserved = 5; + repeated Rule rule = 3; - string to_name = 6; - bool to_deprecated = 8; - bool to_reserved = 9; + Change change = 4; + + repeated ImportChange import_change = 9; + repeated OptionChange option_change = 10; } -message MethodChange { - ChangeType change_type = 1; +message MessagePatch { + string package = 1; + string name = 2; - string from_name = 2; - bool from_deprecated = 4; + repeated Rule rule = 3; - string to_name = 6; - bool to_deprecated = 8; + Change name_change = 4; + + + repeated FieldPatch field_patches = 5; + + repeated OptionChange option_change = 10; } +message FieldPatch { + int32 number = 1; + string name = 2; + + repeated Rule rule = 3; + + FieldChange change = 4; + + repeated OptionChange option_change = 10; +} message ServicePatch { string package = 1; string name = 2; - repeated LintRule info = 3; + repeated Rule rule = 3; - Change change = 4; + Change name_change = 4; repeated MethodPatch method_patches = 5; } @@ -220,18 +183,18 @@ message ServicePatch { message MethodPatch { string name = 2; - repeated LintRule info = 3; + repeated Rule rule = 3; - MethodChange change = 4; + MethodChange method_change = 4; } message EnumPatch { string package = 1; string name = 2; - repeated LintRule info = 3; + repeated Rule rule = 3; - Change change = 4; + Change name_change = 4; repeated EnumValuePatch value_patches = 5; } @@ -240,7 +203,7 @@ message EnumValuePatch { int32 number = 1; string name = 2; - repeated LintRule info = 3; + repeated Rule rule = 3; - EnumValueChange change = 4; + EnumValueChange value_change = 4; } diff --git a/proto/src/main/proto/grpc/registry/v1alpha1/registry.proto b/proto/src/main/proto/grpc/registry/v1alpha1/registry.proto index d2f12cd..7c4937e 100644 --- a/proto/src/main/proto/grpc/registry/v1alpha1/registry.proto +++ b/proto/src/main/proto/grpc/registry/v1alpha1/registry.proto @@ -1,6 +1,7 @@ syntax = "proto3"; import "grpc/registry/v1alpha1/patch.proto"; +import "grpc/registry/v1alpha1/summary.proto"; import "google/protobuf/timestamp.proto"; option java_package = "io.anemos.metastore.v1alpha1"; @@ -44,9 +45,9 @@ message SubmitSchemaRequest { } message SubmitSchemaResponse { - string schema_profile = 1; - Report report = 2; - int32 error_code = 3; + Patch applied_patch = 2; + ValidationSummary validation_summary = 3; + int32 error_code = 4; } message GetSchemaRequest { @@ -87,9 +88,9 @@ message PatchSchemaRequest { } message PatchSchemaResponse { - string schema_profile = 1; - Report report = 2; - int32 error_code = 3; + Patch applied_patch = 2; + ValidationSummary validation_summary = 3; + int32 error_code = 4; } // Information of this schema changes. diff --git a/proto/src/main/proto/grpc/registry/v1alpha1/summary.proto b/proto/src/main/proto/grpc/registry/v1alpha1/summary.proto new file mode 100644 index 0000000..61072ec --- /dev/null +++ b/proto/src/main/proto/grpc/registry/v1alpha1/summary.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; + +import "google/protobuf/wrappers.proto"; + +option java_package = "io.anemos.metastore.v1alpha1"; +option java_multiple_files = true; + +package grpc.registry.v1alpha1; + +message ValidationSummary { + string validation_profile = 1; + + int32 lint_errors = 2; + int32 lint_warnings = 3; + int32 lint_infos = 4; + int32 diff_errors = 5; + int32 diff_warnings = 6; + int32 diff_infos = 7; + + repeated ErrorInfo error_info = 8; + } + + enum ErrorType { + ERROR = 0; + WARNING = 1; + INFO = 2; +} + +message ErrorInfo { + ErrorType type = 1; + oneof path { + string message = 3; + string field = 4; + string enum = 5; + string enum_value = 6; + string service = 7; + string method = 8; + } + string code = 9; + string description = 10; +} + diff --git a/server/src/main/java/io/anemos/metastore/RegistryService.java b/server/src/main/java/io/anemos/metastore/RegistryService.java index 870082e..5f02161 100644 --- a/server/src/main/java/io/anemos/metastore/RegistryService.java +++ b/server/src/main/java/io/anemos/metastore/RegistryService.java @@ -11,10 +11,10 @@ import io.anemos.metastore.core.registry.ProtoPatch; import io.anemos.metastore.putils.ProtoDomain; import io.anemos.metastore.v1alpha1.BindP; +import io.anemos.metastore.v1alpha1.Patch; import io.anemos.metastore.v1alpha1.RegistryGrpc; import io.anemos.metastore.v1alpha1.RegistryP; -import io.anemos.metastore.v1alpha1.Report; -import io.anemos.metastore.v1alpha1.ResultCount; +import io.anemos.metastore.v1alpha1.ValidationSummary; import io.grpc.Status; import io.grpc.StatusException; import io.grpc.stub.StreamObserver; @@ -139,20 +139,24 @@ public void schema( return; } - Report report = - validate(request.getValidationProfile(), request.getMergeStrategy(), registry.get(), in); + Patch appliedPatch = createPatch(request.getMergeStrategy(), registry.get(), in); + ValidationSummary summary = validate(request.getValidationProfile(), appliedPatch); if (submit) { - if (hasErrors(report)) { + if (hasErrors(summary)) { responseObserver.onError( Status.fromCode(Status.Code.FAILED_PRECONDITION) .withDescription("Incompatible schema, us verify to get errors.") .asRuntimeException()); return; } - registry.update(registry.ref(), in, report, request.getNote()); + registry.update(registry.ref(), in, appliedPatch, request.getNote()); } - responseObserver.onNext(RegistryP.SubmitSchemaResponse.newBuilder().setReport(report).build()); + responseObserver.onNext( + RegistryP.SubmitSchemaResponse.newBuilder() + .setAppliedPatch(appliedPatch) + .setValidationSummary(summary) + .build()); responseObserver.onCompleted(); } @@ -171,36 +175,36 @@ public void patch( ProtoDomain in = ProtoPatch.apply(registry.get(), request.getPatch()); - Report report = validate(request.getValidationProfile(), registry.get(), in); + Patch appliedPatch = createPatch(registry.get(), in); + ValidationSummary summary = validate(request.getValidationProfile(), appliedPatch); if (submit) { - if (hasErrors(report)) { + if (hasErrors(summary)) { responseObserver.onError( Status.fromCode(Status.Code.FAILED_PRECONDITION) .withDescription("Incompatible schema, us verify to get errors.") .asRuntimeException()); return; } - registry.update(registry.ref(), in, report, request.getNote()); + registry.update(registry.ref(), in, appliedPatch, request.getNote()); } - responseObserver.onNext(RegistryP.PatchSchemaResponse.newBuilder().setReport(report).build()); + responseObserver.onNext( + RegistryP.PatchSchemaResponse.newBuilder() + .setAppliedPatch(appliedPatch) + .setValidationSummary(summary) + .build()); responseObserver.onCompleted(); } - private boolean hasErrors(Report report) { - if (report.hasResultCount()) { - ResultCount resultCount = report.getResultCount(); - return resultCount.getDiffErrors() > 0 || resultCount.getLintErrors() > 0; - } - return false; + private boolean hasErrors(ValidationSummary report) { + return report.getDiffErrors() > 0 || report.getLintErrors() > 0; } - private Report validate(String validationProfile, ProtoDomain ref, ProtoDomain in) { - return validate(validationProfile, RegistryP.Merge.getDefaultInstance(), ref, in); + private Patch createPatch(ProtoDomain ref, ProtoDomain in) { + return createPatch(RegistryP.Merge.getDefaultInstance(), ref, in); } - private Report validate( - String validationProfile, RegistryP.Merge mergeStrategy, ProtoDomain ref, ProtoDomain in) { + private Patch createPatch(RegistryP.Merge mergeStrategy, ProtoDomain ref, ProtoDomain in) { ValidationResults results = new ValidationResults(); ProtoDiff diff = new ProtoDiff(ref, in, results); ProtoLint lint = new ProtoLint(in, results); @@ -243,7 +247,10 @@ private Report validate( default: throw Status.fromCode(Status.Code.INTERNAL).asRuntimeException(); } + return results.createProto(); + } + private ValidationSummary validate(String validationProfile, Patch patch) { ValidationProfile profile; switch (validationProfile) { case "allow:all": @@ -268,7 +275,7 @@ private Report validate( throw Status.fromCode(Status.Code.INTERNAL).asRuntimeException(); } - return profile.validate(results.createProto()); + return profile.validate(patch); } @Override diff --git a/server/src/main/java/io/anemos/metastore/provider/GooglePubsub.java b/server/src/main/java/io/anemos/metastore/provider/GooglePubsub.java index 0cccf39..66ce7dd 100644 --- a/server/src/main/java/io/anemos/metastore/provider/GooglePubsub.java +++ b/server/src/main/java/io/anemos/metastore/provider/GooglePubsub.java @@ -4,7 +4,7 @@ import com.google.cloud.pubsub.v1.Publisher; import com.google.pubsub.v1.ProjectTopicName; import com.google.pubsub.v1.PubsubMessage; -import io.anemos.metastore.v1alpha1.Report; +import io.anemos.metastore.v1alpha1.Patch; import java.io.IOException; import java.util.Map; @@ -50,7 +50,7 @@ public void initForChangeEvent(RegistryInfo registryInfo, Map co } @Override - public void descriptorsChanged(Report report) { + public void descriptorsChanged(Patch report) { PubsubMessage message = PubsubMessage.newBuilder().setData(report.toByteString()).build(); publisherDescriptorChange.publish(message); } diff --git a/server/src/test/java/io/anemos/metastore/server/ShadowE2ETest.java b/server/src/test/java/io/anemos/metastore/server/ShadowE2ETest.java index 88cfd7f..c28f43b 100644 --- a/server/src/test/java/io/anemos/metastore/server/ShadowE2ETest.java +++ b/server/src/test/java/io/anemos/metastore/server/ShadowE2ETest.java @@ -11,9 +11,9 @@ import io.anemos.metastore.core.proto.validate.ValidationResults; import io.anemos.metastore.putils.ProtoDomain; import io.anemos.metastore.v1alpha1.ChangeType; +import io.anemos.metastore.v1alpha1.Patch; import io.anemos.metastore.v1alpha1.RegistryGrpc; import io.anemos.metastore.v1alpha1.RegistryP; -import io.anemos.metastore.v1alpha1.Report; import io.grpc.inprocess.InProcessChannelBuilder; import io.grpc.inprocess.InProcessServerBuilder; import io.grpc.testing.GrpcCleanupRule; @@ -142,12 +142,12 @@ public void shadowE2ELocalFileProvider() throws Exception { ValidationResults expectedResults = new ValidationResults(); ProtoDiff protoDiff = new ProtoDiff(baseKnownOption(), baseAddMessageOption(), expectedResults); protoDiff.diffOnFileName("test/v1/simple.proto"); - Report actualShadowReport = - Report.parseFrom( + Patch actualShadowReport = + Patch.parseFrom( new FileInputStream(metastorePath.toAbsolutePath().toString() + "/shadow.pb")); Assert.assertEquals( expectedResults.createProto().getMessagePatchesMap(), - actualShadowReport.getPatch().getMessagePatchesMap()); + actualShadowReport.getMessagePatchesMap()); // add field to default RegistryP.SubmitSchemaRequest.Builder submitDefaultAddField = @@ -166,12 +166,11 @@ public void shadowE2ELocalFileProvider() throws Exception { RegistryP.SubmitSchemaResponse verifyDefaultResponse2 = schemaRegistyStub.verifySchema(submitDefaultAddField.build()); - Assert.assertFalse(verifyDefaultResponse2.getReport().getResultCount().getDiffErrors() > 0); + Assert.assertFalse(verifyDefaultResponse2.getValidationSummary().getDiffErrors() > 0); Assert.assertEquals( ChangeType.ADDITION, verifyDefaultResponse2 - .getReport() - .getPatch() + .getAppliedPatch() .getMessagePatchesMap() .get("test.v1.ProtoBeamBasicMessage") .getFieldPatches(0) @@ -181,11 +180,11 @@ public void shadowE2ELocalFileProvider() throws Exception { schemaRegistyStub.submitSchema(submitDefaultAddField.build()); // check shadow insides actualShadowReport = - Report.parseFrom( + Patch.parseFrom( new FileInputStream(metastorePath.toAbsolutePath().toString() + "/shadow.pb")); Assert.assertEquals( expectedResults.createProto().getMessagePatchesMap(), - actualShadowReport.getPatch().getMessagePatchesMap()); + actualShadowReport.getMessagePatchesMap()); actualShadowRepo = ProtocUtil.createDescriptorSet(shadowrepoPath.toAbsolutePath().toString()); Assert.assertEquals( From 60228c84bc7514876eeda628fc0e171edf6587c6 Mon Sep 17 00:00:00 2001 From: Alex Van Boxel Date: Tue, 14 Apr 2020 12:52:03 +0200 Subject: [PATCH 10/11] Add validation profile to summary --- .../metastore/core/proto/profile/ProfileAllowAddBase.java | 1 + .../io/anemos/metastore/core/proto/profile/ProfileAllowAll.java | 2 +- .../anemos/metastore/core/proto/profile/ProfileAllowNone.java | 2 +- .../anemos/metastore/core/proto/profile/ProfileProtoEvolve.java | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowAddBase.java b/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowAddBase.java index 02e937d..ead7509 100644 --- a/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowAddBase.java +++ b/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowAddBase.java @@ -26,6 +26,7 @@ private boolean skipValidationForAlpha(String packageName) { @Override public ValidationSummary validate(Patch patch) { ValidationSummary.Builder builder = ValidationSummary.newBuilder(); + builder.setValidationProfile(profileName); int error = 0; for (MessagePatch messageResult : patch.getMessagePatchesMap().values()) { diff --git a/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowAll.java b/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowAll.java index 770403b..c5c4218 100644 --- a/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowAll.java +++ b/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowAll.java @@ -9,6 +9,6 @@ public class ProfileAllowAll implements ValidationProfile { @Override public ValidationSummary validate(Patch patch) { - return ValidationSummary.getDefaultInstance(); + return ValidationSummary.newBuilder().setValidationProfile(profileName).build(); } } diff --git a/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowNone.java b/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowNone.java index 2cb916f..126afbe 100644 --- a/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowNone.java +++ b/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileAllowNone.java @@ -10,6 +10,6 @@ public class ProfileAllowNone implements ValidationProfile { // TODO implement @Override public ValidationSummary validate(Patch patch) { - return ValidationSummary.getDefaultInstance(); + return ValidationSummary.newBuilder().setValidationProfile(profileName).build(); } } diff --git a/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileProtoEvolve.java b/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileProtoEvolve.java index a0370c5..673909e 100644 --- a/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileProtoEvolve.java +++ b/core/src/main/java/io/anemos/metastore/core/proto/profile/ProfileProtoEvolve.java @@ -9,6 +9,6 @@ public class ProfileProtoEvolve implements ValidationProfile { @Override public ValidationSummary validate(Patch patch) { - return null; + return ValidationSummary.newBuilder().setValidationProfile(profileName).build(); } } From c368fedd13a97f0f688adf4fbf1b00af062c058a Mon Sep 17 00:00:00 2001 From: Alex Van Boxel Date: Thu, 16 Apr 2020 10:53:12 +0200 Subject: [PATCH 11/11] Renamme Schema to Descriptors, joing Submit and Verify --- .../anemos/metastore/metastep/MetaStep.java | 13 ++-- .../grpc/registry/v1alpha1/registry.proto | 71 ++++++++++--------- .../io/anemos/metastore/RegistryService.java | 62 +++++----------- .../metastore/server/ShadowE2ETest.java | 30 ++++---- 4 files changed, 76 insertions(+), 100 deletions(-) diff --git a/metastep/src/main/java/io/anemos/metastore/metastep/MetaStep.java b/metastep/src/main/java/io/anemos/metastore/metastep/MetaStep.java index 12356d9..ac95cf7 100644 --- a/metastep/src/main/java/io/anemos/metastore/metastep/MetaStep.java +++ b/metastep/src/main/java/io/anemos/metastore/metastep/MetaStep.java @@ -229,8 +229,8 @@ private ProtoDomain createDescriptorSet() throws IOException { private void validate() throws IOException { System.out.println("Contract Validation started"); - RegistryP.SubmitSchemaResponse verifySchemaResponse = - schemaRegistry.verifySchema(createSchemaRequest()); + RegistryP.PutDescriptorsResponse verifySchemaResponse = + schemaRegistry.putDescriptors(createSchemaRequest(true)); ValidationSummary validationSummary = verifySchemaResponse.getValidationSummary(); @@ -260,14 +260,14 @@ private void validate() throws IOException { private void publish() throws IOException { System.out.println("Contract Push started"); - schemaRegistry.submitSchema(createSchemaRequest()); + schemaRegistry.putDescriptors(createSchemaRequest(false)); } - private RegistryP.SubmitSchemaRequest createSchemaRequest() throws IOException { + private RegistryP.PutDescriptorsRequest createSchemaRequest(boolean dryRun) throws IOException { ProtoDomain protoContainer = createDescriptorSet(); - RegistryP.SubmitSchemaRequest.Builder schemaRequestBuilder = - RegistryP.SubmitSchemaRequest.newBuilder(); + RegistryP.PutDescriptorsRequest.Builder schemaRequestBuilder = + RegistryP.PutDescriptorsRequest.newBuilder(); protoContainer .iterator() .forEach( @@ -317,6 +317,7 @@ private RegistryP.SubmitSchemaRequest createSchemaRequest() throws IOException { } schemaRequestBuilder.setNote(note); } + schemaRequestBuilder.setDryRun(dryRun); return schemaRequestBuilder.build(); } } diff --git a/proto/src/main/proto/grpc/registry/v1alpha1/registry.proto b/proto/src/main/proto/grpc/registry/v1alpha1/registry.proto index 7c4937e..34e2e15 100644 --- a/proto/src/main/proto/grpc/registry/v1alpha1/registry.proto +++ b/proto/src/main/proto/grpc/registry/v1alpha1/registry.proto @@ -10,14 +10,37 @@ option java_outer_classname = "RegistryP"; package grpc.registry.v1alpha1; service Registry { - rpc GetSchema (GetSchemaRequest) returns (GetSchemaResponse); - rpc VerifySchema (SubmitSchemaRequest) returns (SubmitSchemaResponse); - rpc SubmitSchema (SubmitSchemaRequest) returns (SubmitSchemaResponse); - rpc VerifyPatch (PatchSchemaRequest) returns (PatchSchemaResponse); - rpc PatchSchema (PatchSchemaRequest) returns (PatchSchemaResponse); + rpc GetDescriptors (GetDescriptorsRequest) returns (GetDescriptorsResponse); + rpc PutDescriptors (PutDescriptorsRequest) returns (PutDescriptorsResponse); + rpc PatchDescriptors (PatchDescriptorsRequest) returns (PatchDescriptorsResponse); } -message SubmitSchemaRequest { +message GetDescriptorsRequest { + // Represents the schema registry names. If a schema registry doesn't support multiple + // registries this field is ignored. The default value represents the default registry. + string registry_name = 1; + + oneof entity_scope { + string linked_resource = 2; + string package_name = 3; + string package_prefix = 4; + string file_name = 5; + string message_name = 6; + string service_name = 7; + string enum_name = 8; + } + bool transitive = 9; +} + +message GetDescriptorsResponse { + // The requested google.protobuf.FileDescriptorProto binaries. As these messages + // are proto2 we avoid taking a dependency on descriptor.proto, which uses proto2 only + // features, by making them opaque bytes instead. + repeated bytes file_descriptor_proto = 1; + int32 error_code = 2; +} + +message PutDescriptorsRequest { // Represents the schema registry names. If a schema registry doesn't support multiple // registries this field is ignored. The default value represents the default registry. string registry_name = 1; @@ -42,40 +65,17 @@ message SubmitSchemaRequest { // If the service keeps track of the registry the note can provide usefull information. Note note = 5; + + bool dry_run = 15; } -message SubmitSchemaResponse { +message PutDescriptorsResponse { Patch applied_patch = 2; ValidationSummary validation_summary = 3; int32 error_code = 4; } -message GetSchemaRequest { - // Represents the schema registry names. If a schema registry doesn't support multiple - // registries this field is ignored. The default value represents the default registry. - string registry_name = 1; - - oneof entity_scope { - string linked_resource = 2; - string package_name = 3; - string package_prefix = 4; - string file_name = 5; - string message_name = 6; - string service_name = 7; - string enum_name = 8; - } - bool transitive = 9; -} - -message GetSchemaResponse { - // The requested google.protobuf.FileDescriptorProto binaries. As these messages - // are proto2 we avoid taking a dependency on descriptor.proto, which uses proto2 only - // features, by making them opaque bytes instead. - repeated bytes file_descriptor_proto = 1; - int32 error_code = 2; -} - -message PatchSchemaRequest { +message PatchDescriptorsRequest { // Represents the schema registry names. If a schema registry doesn't support multiple // registries this field is ignored. The default value represents the default registry. @@ -84,10 +84,13 @@ message PatchSchemaRequest { Patch patch = 2; string validation_profile = 3; + Note note = 4; + + bool dry_run = 15; } -message PatchSchemaResponse { +message PatchDescriptorsResponse { Patch applied_patch = 2; ValidationSummary validation_summary = 3; int32 error_code = 4; diff --git a/server/src/main/java/io/anemos/metastore/RegistryService.java b/server/src/main/java/io/anemos/metastore/RegistryService.java index 5f02161..40bf28c 100644 --- a/server/src/main/java/io/anemos/metastore/RegistryService.java +++ b/server/src/main/java/io/anemos/metastore/RegistryService.java @@ -43,20 +43,6 @@ public RegistryService(MetaStore metaStore) { this.metaStore = metaStore; } - @Override - public void submitSchema( - RegistryP.SubmitSchemaRequest request, - StreamObserver responseObserver) { - schema(request, responseObserver, true); - } - - @Override - public void verifySchema( - RegistryP.SubmitSchemaRequest request, - StreamObserver responseObserver) { - schema(request, responseObserver, false); - } - private String validatePackage(String packageName) throws StatusException { if (packageName.contains("/")) { throw new StatusException( @@ -75,10 +61,10 @@ private String validateFileName(String fileName) throws StatusException { return fileName; } - public void schema( - RegistryP.SubmitSchemaRequest request, - StreamObserver responseObserver, - boolean submit) { + @Override + public void putDescriptors( + RegistryP.PutDescriptorsRequest request, + StreamObserver responseObserver) { AbstractRegistry registry; try { @@ -141,7 +127,7 @@ public void schema( Patch appliedPatch = createPatch(request.getMergeStrategy(), registry.get(), in); ValidationSummary summary = validate(request.getValidationProfile(), appliedPatch); - if (submit) { + if (!request.getDryRun()) { if (hasErrors(summary)) { responseObserver.onError( Status.fromCode(Status.Code.FAILED_PRECONDITION) @@ -153,17 +139,17 @@ public void schema( } responseObserver.onNext( - RegistryP.SubmitSchemaResponse.newBuilder() + RegistryP.PutDescriptorsResponse.newBuilder() .setAppliedPatch(appliedPatch) .setValidationSummary(summary) .build()); responseObserver.onCompleted(); } - public void patch( - RegistryP.PatchSchemaRequest request, - StreamObserver responseObserver, - boolean submit) { + @Override + public void patchDescriptors( + RegistryP.PatchDescriptorsRequest request, + StreamObserver responseObserver) { AbstractRegistry registry; try { @@ -177,7 +163,7 @@ public void patch( Patch appliedPatch = createPatch(registry.get(), in); ValidationSummary summary = validate(request.getValidationProfile(), appliedPatch); - if (submit) { + if (!request.getDryRun()) { if (hasErrors(summary)) { responseObserver.onError( Status.fromCode(Status.Code.FAILED_PRECONDITION) @@ -189,7 +175,7 @@ public void patch( } responseObserver.onNext( - RegistryP.PatchSchemaResponse.newBuilder() + RegistryP.PatchDescriptorsResponse.newBuilder() .setAppliedPatch(appliedPatch) .setValidationSummary(summary) .build()); @@ -279,12 +265,12 @@ private ValidationSummary validate(String validationProfile, Patch patch) { } @Override - public void getSchema( - RegistryP.GetSchemaRequest request, - StreamObserver responseObserver) { + public void getDescriptors( + RegistryP.GetDescriptorsRequest request, + StreamObserver responseObserver) { try { - RegistryP.GetSchemaResponse.Builder schemaResponseBuilder = - RegistryP.GetSchemaResponse.newBuilder(); + RegistryP.GetDescriptorsResponse.Builder schemaResponseBuilder = + RegistryP.GetDescriptorsResponse.newBuilder(); AbstractRegistry registry = metaStore.registries.get(request.getRegistryName()); ProtoDomain pContainer = registry.get(); @@ -385,18 +371,4 @@ public void getSchema( responseObserver.onError(e); } } - - @Override - public void verifyPatch( - RegistryP.PatchSchemaRequest request, - StreamObserver responseObserver) { - patch(request, responseObserver, false); - } - - @Override - public void patchSchema( - RegistryP.PatchSchemaRequest request, - StreamObserver responseObserver) { - patch(request, responseObserver, true); - } } diff --git a/server/src/test/java/io/anemos/metastore/server/ShadowE2ETest.java b/server/src/test/java/io/anemos/metastore/server/ShadowE2ETest.java index c28f43b..b32f5e0 100644 --- a/server/src/test/java/io/anemos/metastore/server/ShadowE2ETest.java +++ b/server/src/test/java/io/anemos/metastore/server/ShadowE2ETest.java @@ -97,10 +97,10 @@ public void shadowE2ELocalFileProvider() throws Exception { MetaStore metaStore = new MetaStore(config); - RegistryGrpc.RegistryBlockingStub schemaRegistyStub = getSchemaRegistryStub(metaStore); + RegistryGrpc.RegistryBlockingStub schemaRegistyStub = GetDescriptorsRegistryStub(metaStore); - RegistryP.SubmitSchemaRequest.Builder submitSchemaRequest = - RegistryP.SubmitSchemaRequest.newBuilder() + RegistryP.PutDescriptorsRequest.Builder PutDescriptorsRequest = + RegistryP.PutDescriptorsRequest.newBuilder() .setRegistryName("default") .setMergeStrategy( RegistryP.Merge.newBuilder() @@ -110,9 +110,9 @@ public void shadowE2ELocalFileProvider() throws Exception { .iterator() .forEach( fileDescriptor -> - submitSchemaRequest.addFileDescriptorProto( + PutDescriptorsRequest.addFileDescriptorProto( fileDescriptor.toProto().toByteString())); - schemaRegistyStub.submitSchema(submitSchemaRequest.build()); + schemaRegistyStub.putDescriptors(PutDescriptorsRequest.build()); // check default registry insides ProtoDomain actualDefaultRegistry = @@ -128,15 +128,15 @@ public void shadowE2ELocalFileProvider() throws Exception { baseKnownOption().toFileDescriptorSet(), actualShadowRepo.toFileDescriptorSet()); // add option to shadow - RegistryP.SubmitSchemaRequest.Builder submitSchemaRequest2 = - RegistryP.SubmitSchemaRequest.newBuilder().setRegistryName("shadow"); + RegistryP.PutDescriptorsRequest.Builder PutDescriptorsRequest2 = + RegistryP.PutDescriptorsRequest.newBuilder().setRegistryName("shadow"); baseAddMessageOption() .iterator() .forEach( fileDescriptor -> - submitSchemaRequest2.addFileDescriptorProto( + PutDescriptorsRequest2.addFileDescriptorProto( fileDescriptor.toProto().toByteString())); - schemaRegistyStub.submitSchema(submitSchemaRequest2.build()); + schemaRegistyStub.putDescriptors(PutDescriptorsRequest2.build()); // check shadow patch insides ValidationResults expectedResults = new ValidationResults(); @@ -150,8 +150,8 @@ public void shadowE2ELocalFileProvider() throws Exception { actualShadowReport.getMessagePatchesMap()); // add field to default - RegistryP.SubmitSchemaRequest.Builder submitDefaultAddField = - RegistryP.SubmitSchemaRequest.newBuilder() + RegistryP.PutDescriptorsRequest.Builder submitDefaultAddField = + RegistryP.PutDescriptorsRequest.newBuilder() .setMergeStrategy( RegistryP.Merge.newBuilder() .setPackagePrefixes( @@ -164,8 +164,8 @@ public void shadowE2ELocalFileProvider() throws Exception { submitDefaultAddField.addFileDescriptorProto(fileDescriptor.toProto().toByteString()); }); - RegistryP.SubmitSchemaResponse verifyDefaultResponse2 = - schemaRegistyStub.verifySchema(submitDefaultAddField.build()); + RegistryP.PutDescriptorsResponse verifyDefaultResponse2 = + schemaRegistyStub.putDescriptors(submitDefaultAddField.setDryRun(true).build()); Assert.assertFalse(verifyDefaultResponse2.getValidationSummary().getDiffErrors() > 0); Assert.assertEquals( ChangeType.ADDITION, @@ -177,7 +177,7 @@ public void shadowE2ELocalFileProvider() throws Exception { .getChange() .getChangeType()); - schemaRegistyStub.submitSchema(submitDefaultAddField.build()); + schemaRegistyStub.putDescriptors(submitDefaultAddField.setDryRun(false).build()); // check shadow insides actualShadowReport = Patch.parseFrom( @@ -191,7 +191,7 @@ public void shadowE2ELocalFileProvider() throws Exception { shadowDefaultFieldAdded().toFileDescriptorSet(), actualShadowRepo.toFileDescriptorSet()); } - private RegistryGrpc.RegistryBlockingStub getSchemaRegistryStub(MetaStore metaStore) + private RegistryGrpc.RegistryBlockingStub GetDescriptorsRegistryStub(MetaStore metaStore) throws IOException { String serverName = InProcessServerBuilder.generateName(); grpcCleanup.register(