Skip to content

Commit

Permalink
refactor package and file names
Browse files Browse the repository at this point in the history
Signed-off-by: Jackie Han <[email protected]>
  • Loading branch information
jackiehanyang committed Oct 2, 2023
1 parent 098a0e4 commit 2ee84c8
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
package org.opensearch.flowframework.constant;
package org.opensearch.flowframework.common;

/**
* Representation of common values that are used across project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
package org.opensearch.flowframework.function;
package org.opensearch.flowframework.common;

/**
* A supplier that can throw checked exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
package org.opensearch.flowframework.function;
package org.opensearch.flowframework.common;

import java.util.function.Supplier;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,43 @@
*/
package org.opensearch.flowframework.exception;

import javax.ws.rs.core.Response;

/**
* Representation of Flow Framework Exceptions
*/
public class FlowFrameworkException extends RuntimeException {

private final Response.Status restStatus;
/**
* Constructor with error message.
*
* @param message message of the exception
* @param restStatus HTTP status code of the response
*/
public FlowFrameworkException(String message) {
public FlowFrameworkException(String message, Response.Status restStatus) {
super(message);
this.restStatus = restStatus;
}

/**
* Constructor with specified cause.
* @param cause exception cause
* @param restStatus HTTP status code of the response
*/
public FlowFrameworkException(Throwable cause) {
public FlowFrameworkException(Throwable cause, Response.Status restStatus) {
super(cause);
this.restStatus = restStatus;
}

/**
* Constructor with specified error message adn cause.
* @param message error message
* @param cause exception cause
* @param restStatus HTTP status code of the response
*/
public FlowFrameworkException(String message, Throwable cause) {
public FlowFrameworkException(String message, Throwable cause, Response.Status restStatus) {
super(message, cause);
this.restStatus = restStatus;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@
*/
package org.opensearch.flowframework.indices;

import org.opensearch.flowframework.function.ThrowingSupplierWrapper;
import org.opensearch.flowframework.common.ThrowingSupplierWrapper;

import java.util.function.Supplier;

import static org.opensearch.flowframework.constant.CommonValue.GLOBAL_CONTEXT_INDEX;
import static org.opensearch.flowframework.constant.CommonValue.GLOBAL_CONTEXT_INDEX_VERSION;
import static org.opensearch.flowframework.common.CommonValue.GLOBAL_CONTEXT_INDEX;
import static org.opensearch.flowframework.common.CommonValue.GLOBAL_CONTEXT_INDEX_VERSION;

/**
* An enumeration of Flow Framework indices
*/
public enum FlowFrameworkIndex {
GLOBAL_CONTEXT(
GLOBAL_CONTEXT_INDEX,
ThrowingSupplierWrapper.throwingSupplierWrapper(GlobalContextHandler::getGlobalContextMappings),
GLOBAL_CONTEXT_INDEX_VERSION
GLOBAL_CONTEXT_INDEX,
ThrowingSupplierWrapper.throwingSupplierWrapper(GlobalContextHandler::getGlobalContextMappings),
GLOBAL_CONTEXT_INDEX_VERSION
);

private final String indexName;
Expand All @@ -46,4 +46,4 @@ public String getMapping() {
public Integer getVersion() {
return version;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@
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.flowframework.constant.CommonValue.GLOBAL_CONTEXT_INDEX;
import static org.opensearch.flowframework.constant.CommonValue.GLOBAL_CONTEXT_INDEX_MAPPING;
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;

/**
Expand Down Expand Up @@ -72,7 +73,7 @@ private void initGlobalContextIndexIfAbsent(ActionListener<Boolean> listener) {
public void putTemplateToGlobalContext(Template template, ActionListener<IndexResponse> listener) {
initGlobalContextIndexIfAbsent(ActionListener.wrap(indexCreated -> {
if (!indexCreated) {
listener.onFailure(new FlowFrameworkException("No response to create global_context index"));
listener.onFailure(new FlowFrameworkException("No response to create global_context index", Response.Status.INTERNAL_SERVER_ERROR));
return;
}
IndexRequest request = new IndexRequest(GLOBAL_CONTEXT_INDEX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;
Expand All @@ -36,9 +37,9 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean;

import static org.opensearch.flowframework.constant.CommonValue.META;
import static org.opensearch.flowframework.constant.CommonValue.NO_SCHEMA_VERSION;
import static org.opensearch.flowframework.constant.CommonValue.SCHEMA_VERSION_FIELD;
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;

/**
* Step to create an index
Expand Down Expand Up @@ -164,15 +165,15 @@ public void initIndexIfAbsent(FlowFrameworkIndex index, ActionListener<Boolean>
internalListener.onResponse(true);
} else {
internalListener.onFailure(
new FlowFrameworkException("Failed to update index setting for: " + indexName)
new FlowFrameworkException("Failed to update index setting for: " + indexName, Response.Status.INTERNAL_SERVER_ERROR)
);
}
}, exception -> {
logger.error("Failed to update index setting for: " + indexName, exception);
internalListener.onFailure(exception);
}));
} else {
internalListener.onFailure(new FlowFrameworkException("Failed to update index: " + indexName));
internalListener.onFailure(new FlowFrameworkException("Failed to update index: " + indexName, Response.Status.INTERNAL_SERVER_ERROR));
}
}, exception -> {
logger.error("Failed to update index " + indexName, exception);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import static org.opensearch.flowframework.constant.CommonValue.GLOBAL_CONTEXT_INDEX;
import static org.opensearch.flowframework.common.CommonValue.GLOBAL_CONTEXT_INDEX;
import static org.mockito.Mockito.*;

public class GlobalContextHandlerTests extends OpenSearchTestCase {
Expand Down Expand Up @@ -66,7 +66,6 @@ public void setUp() throws Exception {
when(client.admin()).thenReturn(adminClient);
}

@Test
public void testPutTemplateToGlobalContext() throws IOException {
Template template = mock(Template.class);
when(template.toXContent(any(XContentBuilder.class), eq(ToXContent.EMPTY_PARAMS))).thenAnswer(invocation -> {
Expand All @@ -89,7 +88,6 @@ public void testPutTemplateToGlobalContext() throws IOException {
assertEquals(GLOBAL_CONTEXT_INDEX, requestCaptor.getValue().index());
}

@Test
public void testStoreResponseToGlobalContext() {
String documentId = "docId";
Map<String, Object> updatedFields = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import static org.opensearch.flowframework.constant.CommonValue.*;
import static org.opensearch.flowframework.common.CommonValue.*;
import static org.mockito.Mockito.*;

public class CreateIndexStepTests extends OpenSearchTestCase {
Expand Down

0 comments on commit 2ee84c8

Please sign in to comment.