Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing response when creating a store. #47

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,27 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient nod
final String storeName = request.param("store");

LOGGER.info("Creating search relevance index {}", storeName);
return (channel) -> backend.initialize(storeName, channel);
backend.initialize(storeName);
return (channel) -> channel.sendResponse(new BytesRestResponse(RestStatus.OK, "created"));

} else if (request.method() == DELETE) {

final String storeName = request.param("store");

// TODO: Make sure the store actually exists first.

LOGGER.info("Deleting search relevance index {}", storeName);
return (channel) -> backend.delete(storeName, channel);
backend.delete(storeName);
return (channel) -> channel.sendResponse(new BytesRestResponse(RestStatus.OK, "deleted"));

} else if (request.method() == POST) {

if (request.hasContent()) {

final String storeName = request.param("store");

// TODO: Make sure the store actually exists first.

LOGGER.info("Persisting event into {}", storeName);
final String eventJson = request.content().utf8ToString();
backend.persistEvent(storeName, eventJson);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/opensearch/ubl/backends/Backend.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

public interface Backend {

void initialize(final String storeName, RestChannel channel);
void initialize(final String storeName);

void delete(final String storeName, RestChannel channel);
void delete(final String storeName);

void persistEvent(final String storeName, String eventJson);

Expand Down
12 changes: 5 additions & 7 deletions src/main/java/org/opensearch/ubl/backends/OpenSearchBackend.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import org.opensearch.common.settings.Settings;
import org.opensearch.common.util.io.Streams;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.rest.RestChannel;
import org.opensearch.rest.action.RestToXContentListener;
import org.opensearch.ubl.SettingsConstants;
import org.opensearch.ubl.events.Event;
import org.opensearch.ubl.events.OpenSearchEventManager;
Expand Down Expand Up @@ -51,7 +49,7 @@ public OpenSearchBackend(final Client client) {
}

@Override
public void initialize(final String storeName, final RestChannel channel) {
public void initialize(final String storeName) {

// TODO: Determine if already initialized with this index name first.
// TODO: Also need some error handling around this in case one or both of these index creations fail.
Expand All @@ -65,7 +63,7 @@ public void initialize(final String storeName, final RestChannel channel) {
.mapping(getResourceFile(EVENTS_MAPPING_FILE))
.settings(getIndexSettings());

client.admin().indices().create(createEventsIndexRequest, new RestToXContentListener<>(channel));
client.admin().indices().create(createEventsIndexRequest);

// Create the queries index.
final String queriesIndexName = getQueriesIndexName(storeName);
Expand All @@ -74,19 +72,19 @@ public void initialize(final String storeName, final RestChannel channel) {
.mapping(getResourceFile(QUERIES_MAPPING_FILE))
.settings(getIndexSettings());

client.admin().indices().create(createQueryIndexRequest, new RestToXContentListener<>(channel));
client.admin().indices().create(createQueryIndexRequest);

}

@Override
public void delete(String storeName, RestChannel channel) {
public void delete(String storeName) {

LOGGER.info("Deleting search relevance store {}", storeName);

final String eventsIndexName = getEventsIndexName(storeName);
final String queriesIndexName = getQueriesIndexName(storeName);
final DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(eventsIndexName, queriesIndexName);
client.admin().indices().delete(deleteIndexRequest, new RestToXContentListener<>(channel));
client.admin().indices().delete(deleteIndexRequest);

}

Expand Down
Loading