From 330a112e03d562683a56b7a219b974ae7c9b5750 Mon Sep 17 00:00:00 2001 From: yanghua Date: Mon, 13 Jun 2022 15:01:07 +0800 Subject: [PATCH] fix: Refactor some minor issues /assign @felixwang9817 Signed-off-by: yanghua --- .../logging/entry/MessageAuditLogEntry.java | 28 ++++++++----------- .../interceptors/GrpcMessageInterceptor.java | 6 ++-- .../src/main/java/dev/feast/RequestUtil.java | 4 +-- .../serving/registry/LocalRegistryFile.java | 2 +- .../java/feast/serving/registry/Registry.java | 13 +++++---- .../service/OnlineTransformationService.java | 11 +++----- .../storage/api/retriever/AvroFeature.java | 3 +- 7 files changed, 30 insertions(+), 37 deletions(-) diff --git a/java/common/src/main/java/feast/common/logging/entry/MessageAuditLogEntry.java b/java/common/src/main/java/feast/common/logging/entry/MessageAuditLogEntry.java index 6e5072f66ef..8ad428a3a3d 100644 --- a/java/common/src/main/java/feast/common/logging/entry/MessageAuditLogEntry.java +++ b/java/common/src/main/java/feast/common/logging/entry/MessageAuditLogEntry.java @@ -19,16 +19,13 @@ import com.google.auto.value.AutoValue; import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import com.google.gson.JsonElement; import com.google.gson.JsonParser; -import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; import com.google.protobuf.Empty; import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.Message; import com.google.protobuf.util.JsonFormat; import io.grpc.Status.Code; -import java.lang.reflect.Type; import java.util.UUID; /** MessageAuditLogEntry records the handling of a Protobuf message by a service call. */ @@ -103,20 +100,17 @@ public String toJSON() { new GsonBuilder() .registerTypeAdapter( Message.class, - new JsonSerializer() { - @Override - public JsonElement serialize( - Message message, Type type, JsonSerializationContext context) { - try { - String messageJSON = JsonFormat.printer().print(message); - return new JsonParser().parse(messageJSON); - } catch (InvalidProtocolBufferException e) { - - throw new RuntimeException( - "Unexpected exception converting Protobuf to JSON", e); - } - } - }) + (JsonSerializer) + (message, type, context) -> { + try { + String messageJSON = JsonFormat.printer().print(message); + return new JsonParser().parse(messageJSON); + } catch (InvalidProtocolBufferException e) { + + throw new RuntimeException( + "Unexpected exception converting Protobuf to JSON", e); + } + }) .create(); return gson.toJson(this); } diff --git a/java/common/src/main/java/feast/common/logging/interceptors/GrpcMessageInterceptor.java b/java/common/src/main/java/feast/common/logging/interceptors/GrpcMessageInterceptor.java index 661642a89ad..e34fefd115c 100644 --- a/java/common/src/main/java/feast/common/logging/interceptors/GrpcMessageInterceptor.java +++ b/java/common/src/main/java/feast/common/logging/interceptors/GrpcMessageInterceptor.java @@ -38,7 +38,7 @@ * GrpcMessageInterceptor assumes that all service calls are unary (ie single request/response). */ public class GrpcMessageInterceptor implements ServerInterceptor { - private LoggingProperties loggingProperties; + private final LoggingProperties loggingProperties; /** * Construct GrpcMessageIntercetor. @@ -78,7 +78,7 @@ public Listener interceptCall( // Register forwarding call to intercept outgoing response and log to audit log call = - new SimpleForwardingServerCall(call) { + new SimpleForwardingServerCall<>(call) { @Override public void sendMessage(RespT message) { // 2. Track the response & Log entry to audit logger @@ -97,7 +97,7 @@ public void close(Status status, Metadata trailers) { }; ServerCall.Listener listener = next.startCall(call, headers); - return new SimpleForwardingServerCallListener(listener) { + return new SimpleForwardingServerCallListener<>(listener) { @Override // Register listener to intercept incoming request messages and log to audit log public void onMessage(ReqT message) { diff --git a/java/sdk/src/main/java/dev/feast/RequestUtil.java b/java/sdk/src/main/java/dev/feast/RequestUtil.java index fc13c453119..da2c0dc42e1 100644 --- a/java/sdk/src/main/java/dev/feast/RequestUtil.java +++ b/java/sdk/src/main/java/dev/feast/RequestUtil.java @@ -35,9 +35,7 @@ public static List createFeatureRefs(List featureRef } List featureRefs = - featureRefStrings.stream() - .map(refStr -> parseFeatureRef(refStr)) - .collect(Collectors.toList()); + featureRefStrings.stream().map(RequestUtil::parseFeatureRef).collect(Collectors.toList()); return featureRefs; } diff --git a/java/serving/src/main/java/feast/serving/registry/LocalRegistryFile.java b/java/serving/src/main/java/feast/serving/registry/LocalRegistryFile.java index b0d6b10bfc0..1da45813eea 100644 --- a/java/serving/src/main/java/feast/serving/registry/LocalRegistryFile.java +++ b/java/serving/src/main/java/feast/serving/registry/LocalRegistryFile.java @@ -24,7 +24,7 @@ import java.util.Optional; public class LocalRegistryFile implements RegistryFile { - private RegistryProto.Registry cachedRegistry; + private final RegistryProto.Registry cachedRegistry; public LocalRegistryFile(String path) { try { diff --git a/java/serving/src/main/java/feast/serving/registry/Registry.java b/java/serving/src/main/java/feast/serving/registry/Registry.java index 37fae3d8dcb..bc953174ea4 100644 --- a/java/serving/src/main/java/feast/serving/registry/Registry.java +++ b/java/serving/src/main/java/feast/serving/registry/Registry.java @@ -17,6 +17,9 @@ package feast.serving.registry; import feast.proto.core.*; +import feast.proto.core.FeatureServiceProto.FeatureService; +import feast.proto.core.FeatureViewProto.FeatureView; +import feast.proto.core.OnDemandFeatureViewProto.OnDemandFeatureView; import feast.proto.serving.ServingAPIProto; import feast.serving.exception.SpecRetrievalException; import java.util.List; @@ -26,16 +29,16 @@ public class Registry { private final RegistryProto.Registry registry; - private Map featureViewNameToSpec; + private final Map featureViewNameToSpec; private Map onDemandFeatureViewNameToSpec; - private Map featureServiceNameToSpec; + private final Map featureServiceNameToSpec; Registry(RegistryProto.Registry registry) { this.registry = registry; List featureViewSpecs = registry.getFeatureViewsList().stream() - .map(fv -> fv.getSpec()) + .map(FeatureView::getSpec) .collect(Collectors.toList()); this.featureViewNameToSpec = featureViewSpecs.stream() @@ -43,7 +46,7 @@ public class Registry { Collectors.toMap(FeatureViewProto.FeatureViewSpec::getName, Function.identity())); List onDemandFeatureViewSpecs = registry.getOnDemandFeatureViewsList().stream() - .map(odfv -> odfv.getSpec()) + .map(OnDemandFeatureView::getSpec) .collect(Collectors.toList()); this.onDemandFeatureViewNameToSpec = onDemandFeatureViewSpecs.stream() @@ -53,7 +56,7 @@ public class Registry { Function.identity())); this.featureServiceNameToSpec = registry.getFeatureServicesList().stream() - .map(fs -> fs.getSpec()) + .map(FeatureService::getSpec) .collect( Collectors.toMap( FeatureServiceProto.FeatureServiceSpec::getName, Function.identity())); diff --git a/java/serving/src/main/java/feast/serving/service/OnlineTransformationService.java b/java/serving/src/main/java/feast/serving/service/OnlineTransformationService.java index 365432b84e1..ae83635b861 100644 --- a/java/serving/src/main/java/feast/serving/service/OnlineTransformationService.java +++ b/java/serving/src/main/java/feast/serving/service/OnlineTransformationService.java @@ -239,8 +239,7 @@ public void processTransformFeaturesResponse( } catch (IOException e) { log.info(e.toString()); throw Status.INTERNAL - .withDescription( - "Unable to correctly process transform features response: " + e.toString()) + .withDescription("Unable to correctly process transform features response: " + e) .asRuntimeException(); } } @@ -249,11 +248,10 @@ public void processTransformFeaturesResponse( public ValueType serializeValuesIntoArrowIPC(List>> values) { // In order to be serialized correctly, the data must be packaged in a VectorSchemaRoot. // We first construct all the columns. - Map columnNameToColumn = new HashMap(); BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE); - List columnFields = new ArrayList(); - List columns = new ArrayList(); + List columnFields = new ArrayList<>(); + List columns = new ArrayList<>(); for (Pair> columnEntry : values) { // The Python FTS does not expect full feature names, so we extract the feature name. @@ -316,8 +314,7 @@ public ValueType serializeValuesIntoArrowIPC(List