Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #47 from o19s/create-new-store
Browse files Browse the repository at this point in the history
Fixing response when creating a store.
  • Loading branch information
RasonJ authored Feb 20, 2024
2 parents b4946d3 + 51590dd commit c7b8b4a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
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

0 comments on commit c7b8b4a

Please sign in to comment.