-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Prudhvi Godithi <[email protected]>
- Loading branch information
1 parent
6e2bb1d
commit 285fc87
Showing
23 changed files
with
2,326 additions
and
181 deletions.
There are no files selected for viewing
200 changes: 152 additions & 48 deletions
200
...s/scale/searchonly/SearchOnlyScaleIT.java → ...ndices/scale/searchonly/SearchOnlyIT.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
server/src/main/java/org/opensearch/rest/action/admin/indices/RestScaleSearchOnlyAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.rest.action.admin.indices; | ||
|
||
import org.opensearch.rest.BaseRestHandler; | ||
import org.opensearch.rest.RestRequest; | ||
import org.opensearch.rest.action.RestToXContentListener; | ||
import org.opensearch.transport.client.node.NodeClient; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static java.util.Arrays.asList; | ||
import static java.util.Collections.unmodifiableList; | ||
import static org.opensearch.rest.RestRequest.Method.POST; | ||
|
||
/** | ||
* Rest action for scaling index operations | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class RestScaleSearchOnlyAction extends BaseRestHandler { | ||
|
||
private static final String SEARCH_ONLY_FIELD = "search_only"; | ||
|
||
@Override | ||
public List<Route> routes() { | ||
return unmodifiableList(asList(new Route(POST, "/{index}/_scale"))); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "search_only_index_action"; | ||
} | ||
|
||
@Override | ||
protected RestChannelConsumer prepareRequest(final RestRequest request, NodeClient client) throws IOException { | ||
String index = request.param("index"); | ||
if (index == null || index.trim().isEmpty()) { | ||
throw new IllegalArgumentException("index is required"); | ||
} | ||
|
||
// Parse the request body first to get the scale down value | ||
final boolean searchOnly = parseSearchOnlyValue(request); | ||
|
||
// Then use the final value in the lambda | ||
return channel -> client.admin() | ||
.indices() | ||
.prepareSearchOnly(index) | ||
.setSearchOnly(searchOnly) | ||
.execute(new RestToXContentListener<>(channel)); | ||
} | ||
|
||
/** | ||
* Parses and validates the search_only parameter from the request body. | ||
*/ | ||
private boolean parseSearchOnlyValue(RestRequest request) { | ||
try { | ||
Map<String, Object> source; | ||
try { | ||
source = request.contentParser().map(); | ||
} catch (Exception e) { | ||
throw new IllegalArgumentException("Request body must be valid JSON", e); | ||
} | ||
for (String key : source.keySet()) { | ||
if (!SEARCH_ONLY_FIELD.equals(key)) { | ||
throw new IllegalArgumentException("Unknown parameter [" + key + "]. Only [" + SEARCH_ONLY_FIELD + "] is allowed."); | ||
} | ||
} | ||
if (!source.containsKey(SEARCH_ONLY_FIELD)) { | ||
throw new IllegalArgumentException("Parameter [" + SEARCH_ONLY_FIELD + "] is required"); | ||
} | ||
Object value = source.get(SEARCH_ONLY_FIELD); | ||
if (!(value instanceof Boolean)) { | ||
throw new IllegalArgumentException("Parameter [" + SEARCH_ONLY_FIELD + "] must be a boolean (true or false)"); | ||
} | ||
return (Boolean) value; | ||
} catch (Exception e) { | ||
if (e instanceof IllegalArgumentException) { | ||
throw e; | ||
} | ||
throw new IllegalArgumentException("Request body must be valid JSON", e); | ||
} | ||
} | ||
} |
Oops, something went wrong.