diff --git a/build.gradle b/build.gradle index 73ebd4304..2f6d80aa9 100644 --- a/build.gradle +++ b/build.gradle @@ -107,7 +107,6 @@ dependencies { implementation "org.opensearch:opensearch:${opensearch_version}" implementation 'org.junit.jupiter:junit-jupiter:5.10.0' implementation "com.google.guava:guava:32.1.2-jre" - implementation 'javax.ws.rs:javax.ws.rs-api:2.1.1' api group: 'org.opensearch', name:'opensearch-ml-client', version: "${opensearch_build}" configurations.all { diff --git a/src/main/java/org/opensearch/flowframework/exception/FlowFrameworkException.java b/src/main/java/org/opensearch/flowframework/exception/FlowFrameworkException.java index 4b45292e3..0e05f476d 100644 --- a/src/main/java/org/opensearch/flowframework/exception/FlowFrameworkException.java +++ b/src/main/java/org/opensearch/flowframework/exception/FlowFrameworkException.java @@ -8,14 +8,14 @@ */ package org.opensearch.flowframework.exception; -import javax.ws.rs.core.Response; +import org.opensearch.core.rest.RestStatus; /** * Representation of Flow Framework Exceptions */ public class FlowFrameworkException extends RuntimeException { - private final Response.Status restStatus; + private final RestStatus restStatus; /** * Constructor with error message. @@ -23,7 +23,7 @@ public class FlowFrameworkException extends RuntimeException { * @param message message of the exception * @param restStatus HTTP status code of the response */ - public FlowFrameworkException(String message, Response.Status restStatus) { + public FlowFrameworkException(String message, RestStatus restStatus) { super(message); this.restStatus = restStatus; } @@ -33,7 +33,7 @@ public FlowFrameworkException(String message, Response.Status restStatus) { * @param cause exception cause * @param restStatus HTTP status code of the response */ - public FlowFrameworkException(Throwable cause, Response.Status restStatus) { + public FlowFrameworkException(Throwable cause, RestStatus restStatus) { super(cause); this.restStatus = restStatus; } @@ -44,7 +44,7 @@ public FlowFrameworkException(Throwable cause, Response.Status restStatus) { * @param cause exception cause * @param restStatus HTTP status code of the response */ - public FlowFrameworkException(String message, Throwable cause, Response.Status restStatus) { + public FlowFrameworkException(String message, Throwable cause, RestStatus restStatus) { super(message, cause); this.restStatus = restStatus; } diff --git a/src/main/java/org/opensearch/flowframework/indices/GlobalContextHandler.java b/src/main/java/org/opensearch/flowframework/indices/GlobalContextHandler.java index 30c27954e..fe3cc653b 100644 --- a/src/main/java/org/opensearch/flowframework/indices/GlobalContextHandler.java +++ b/src/main/java/org/opensearch/flowframework/indices/GlobalContextHandler.java @@ -25,12 +25,11 @@ import org.opensearch.flowframework.model.Template; import org.opensearch.flowframework.workflow.CreateIndexStep; -import javax.ws.rs.core.Response; - import java.io.IOException; import java.util.HashMap; import java.util.Map; +import static org.opensearch.core.rest.RestStatus.INTERNAL_SERVER_ERROR; import static org.opensearch.flowframework.common.CommonValue.GLOBAL_CONTEXT_INDEX; import static org.opensearch.flowframework.common.CommonValue.GLOBAL_CONTEXT_INDEX_MAPPING; import static org.opensearch.flowframework.workflow.CreateIndexStep.getIndexMappings; @@ -74,9 +73,7 @@ private void initGlobalContextIndexIfAbsent(ActionListener listener) { public void putTemplateToGlobalContext(Template template, ActionListener listener) { initGlobalContextIndexIfAbsent(ActionListener.wrap(indexCreated -> { if (!indexCreated) { - listener.onFailure( - new FlowFrameworkException("No response to create global_context index", Response.Status.INTERNAL_SERVER_ERROR) - ); + listener.onFailure(new FlowFrameworkException("No response to create global_context index", INTERNAL_SERVER_ERROR)); return; } IndexRequest request = new IndexRequest(GLOBAL_CONTEXT_INDEX); diff --git a/src/main/java/org/opensearch/flowframework/workflow/CreateIndexStep.java b/src/main/java/org/opensearch/flowframework/workflow/CreateIndexStep.java index 97c389c41..6b3ff8590 100644 --- a/src/main/java/org/opensearch/flowframework/workflow/CreateIndexStep.java +++ b/src/main/java/org/opensearch/flowframework/workflow/CreateIndexStep.java @@ -8,7 +8,6 @@ */ package org.opensearch.flowframework.workflow; -import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Charsets; import com.google.common.io.Resources; import org.apache.logging.log4j.LogManager; @@ -28,8 +27,6 @@ import org.opensearch.flowframework.exception.FlowFrameworkException; import org.opensearch.flowframework.indices.FlowFrameworkIndex; -import javax.ws.rs.core.Response; - import java.io.IOException; import java.net.URL; import java.util.HashMap; @@ -38,6 +35,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicBoolean; +import static org.opensearch.core.rest.RestStatus.INTERNAL_SERVER_ERROR; import static org.opensearch.flowframework.common.CommonValue.META; import static org.opensearch.flowframework.common.CommonValue.NO_SCHEMA_VERSION; import static org.opensearch.flowframework.common.CommonValue.SCHEMA_VERSION_FIELD; @@ -168,7 +166,7 @@ public void initIndexIfAbsent(FlowFrameworkIndex index, ActionListener internalListener.onFailure( new FlowFrameworkException( "Failed to update index setting for: " + indexName, - Response.Status.INTERNAL_SERVER_ERROR + INTERNAL_SERVER_ERROR ) ); } @@ -178,10 +176,7 @@ public void initIndexIfAbsent(FlowFrameworkIndex index, ActionListener })); } else { internalListener.onFailure( - new FlowFrameworkException( - "Failed to update index: " + indexName, - Response.Status.INTERNAL_SERVER_ERROR - ) + new FlowFrameworkException("Failed to update index: " + indexName, INTERNAL_SERVER_ERROR) ); } }, exception -> { @@ -227,8 +222,7 @@ public static String getIndexMappings(String mapping) throws IOException { * @param newVersion new index mapping version * @param listener action listener, if update index is needed, will pass true to its onResponse method */ - @VisibleForTesting - protected void shouldUpdateIndex(String indexName, Integer newVersion, ActionListener listener) { + private void shouldUpdateIndex(String indexName, Integer newVersion, ActionListener listener) { IndexMetadata indexMetaData = clusterService.state().getMetadata().indices().get(indexName); if (indexMetaData == null) { listener.onResponse(Boolean.FALSE);