From f4e90e4c0e763cf4e5db223c092461d16745046e Mon Sep 17 00:00:00 2001 From: Sean Kao Date: Wed, 12 Jun 2024 18:46:41 -0700 Subject: [PATCH] undo reflection Signed-off-by: Sean Kao --- .../flint/core/FlintClientBuilder.java | 19 ++---------- .../opensearch/flint/core/FlintOptions.java | 8 ----- .../flint/core/FlintClientBuilderSuite.scala | 30 ------------------- 3 files changed, 2 insertions(+), 55 deletions(-) delete mode 100644 integ-test/src/test/scala/org/opensearch/flint/core/FlintClientBuilderSuite.scala diff --git a/flint-core/src/main/scala/org/opensearch/flint/core/FlintClientBuilder.java b/flint-core/src/main/scala/org/opensearch/flint/core/FlintClientBuilder.java index 36d14ae49..006770581 100644 --- a/flint-core/src/main/scala/org/opensearch/flint/core/FlintClientBuilder.java +++ b/flint-core/src/main/scala/org/opensearch/flint/core/FlintClientBuilder.java @@ -5,9 +5,8 @@ package org.opensearch.flint.core; -import java.lang.reflect.Constructor; import org.opensearch.flint.core.storage.FlintOpenSearchClient; -import org.opensearch.flint.core.metadata.log.FlintMetadataLogService; +import org.opensearch.flint.core.storage.FlintOpenSearchMetadataLogService; /** * {@link FlintClient} builder. @@ -15,20 +14,6 @@ public class FlintClientBuilder { public static FlintClient build(FlintOptions options) { - return new FlintOpenSearchClient(options, - instantiateFlintMetadataLogService(options.getCustomFlintMetadataLogServiceClass(), options)); - } - - /** - * Attempts to instantiate Flint metadata log service using reflection. - */ - private static FlintMetadataLogService instantiateFlintMetadataLogService(String className, FlintOptions options) { - try { - Class flintMetadataLogServiceClass = Class.forName(className); - Constructor constructor = flintMetadataLogServiceClass.getConstructor(FlintOptions.class); - return (FlintMetadataLogService) constructor.newInstance(options); - } catch (Exception e) { - throw new RuntimeException("Failed to instantiate FlintMetadataLogService: " + className, e); - } + return new FlintOpenSearchClient(options, new FlintOpenSearchMetadataLogService(options)); } } diff --git a/flint-core/src/main/scala/org/opensearch/flint/core/FlintOptions.java b/flint-core/src/main/scala/org/opensearch/flint/core/FlintOptions.java index 904f78a73..0cf643791 100644 --- a/flint-core/src/main/scala/org/opensearch/flint/core/FlintOptions.java +++ b/flint-core/src/main/scala/org/opensearch/flint/core/FlintOptions.java @@ -90,10 +90,6 @@ public class FlintOptions implements Serializable { public static final String DEFAULT_BATCH_BYTES = "1mb"; - public static final String CUSTOM_FLINT_METADATA_LOG_SERVICE_CLASS = "customFlintMetadataLogServiceClass"; - - public static final String DEFAULT_FLINT_METADATA_LOG_SERVICE_CLASS = "org.opensearch.flint.core.storage.FlintOpenSearchMetadataLogService"; - public FlintOptions(Map options) { this.options = options; this.retryOptions = new FlintRetryOptions(options); @@ -166,8 +162,4 @@ public int getBatchBytes() { return (int) org.apache.spark.network.util.JavaUtils .byteStringAs(options.getOrDefault(BATCH_BYTES, DEFAULT_BATCH_BYTES), ByteUnit.BYTE); } - - public String getCustomFlintMetadataLogServiceClass() { - return options.getOrDefault(CUSTOM_FLINT_METADATA_LOG_SERVICE_CLASS, DEFAULT_FLINT_METADATA_LOG_SERVICE_CLASS); - } } diff --git a/integ-test/src/test/scala/org/opensearch/flint/core/FlintClientBuilderSuite.scala b/integ-test/src/test/scala/org/opensearch/flint/core/FlintClientBuilderSuite.scala deleted file mode 100644 index f5f1a06df..000000000 --- a/integ-test/src/test/scala/org/opensearch/flint/core/FlintClientBuilderSuite.scala +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.flint.core - -import scala.collection.JavaConverters._ - -import org.opensearch.flint.OpenSearchSuite -import org.scalatest.flatspec.AnyFlatSpec -import org.scalatest.matchers.should.Matchers - -class FlintClientBuilderSuite extends AnyFlatSpec with OpenSearchSuite with Matchers { - - behavior of "Flint client builder" - - it should "build flint client" in { - val flintClient = FlintClientBuilder.build(new FlintOptions(openSearchOptions.asJava)) - flintClient shouldBe a[FlintClient] - } - - it should "fail if cannot instantiate metadata log service" in { - val options = - openSearchOptions + (FlintOptions.CUSTOM_FLINT_METADATA_LOG_SERVICE_CLASS -> "org.dummy.Class") - the[RuntimeException] thrownBy { - FlintClientBuilder.build(new FlintOptions(options.asJava)) - } - } -}