forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor code, rebase with pagination PR merge and add relevant changes
Signed-off-by: Sumit Bansal <sumitsb@amazon.com>
- Loading branch information
Showing
15 changed files
with
199 additions
and
155 deletions.
There are no files selected for viewing
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
66 changes: 66 additions & 0 deletions
66
server/src/main/java/org/opensearch/common/breaker/ResponseLimitBreachedException.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,66 @@ | ||
/* | ||
* 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.common.breaker; | ||
|
||
import org.opensearch.OpenSearchException; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.core.rest.RestStatus; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Thrown when api response breaches threshold limit. | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class ResponseLimitBreachedException extends OpenSearchException { | ||
|
||
private final int responseLimit; | ||
private final ResponseLimitSettings.LimitEntity limitEntity; | ||
|
||
public ResponseLimitBreachedException(StreamInput in) throws IOException { | ||
super(in); | ||
responseLimit = in.readVInt(); | ||
limitEntity = in.readEnum(ResponseLimitSettings.LimitEntity.class); | ||
} | ||
|
||
public ResponseLimitBreachedException(String msg, int responseLimit, ResponseLimitSettings.LimitEntity limitEntity) { | ||
super(msg); | ||
this.responseLimit = responseLimit; | ||
this.limitEntity = limitEntity; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeVInt(responseLimit); | ||
out.writeEnum(limitEntity); | ||
} | ||
|
||
public int getResponseLimit() { | ||
return responseLimit; | ||
} | ||
|
||
public ResponseLimitSettings.LimitEntity getLimitEntity() { | ||
return limitEntity; | ||
} | ||
|
||
@Override | ||
public RestStatus status() { | ||
return RestStatus.TOO_MANY_REQUESTS; | ||
} | ||
|
||
@Override | ||
protected void metadataToXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.field("response_limit", responseLimit); | ||
builder.field("limit_entity", limitEntity); | ||
} | ||
} |
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
36 changes: 0 additions & 36 deletions
36
server/src/main/java/org/opensearch/rest/ResponseLimitBreachedException.java
This file was deleted.
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
Oops, something went wrong.