-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
…on dynamic limit settings (#15986) * Add changes to block calls in cat shards, indices and segments based on dynamic limit settings Signed-off-by: Sumit Bansal <[email protected]>
- Loading branch information
There are no files selected for viewing
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); | ||
} | ||
Check warning on line 33 in server/src/main/java/org/opensearch/common/breaker/ResponseLimitBreachedException.java Codecov / codecov/patchserver/src/main/java/org/opensearch/common/breaker/ResponseLimitBreachedException.java#L30-L33
|
||
|
||
public ResponseLimitBreachedException(String msg, int responseLimit, ResponseLimitSettings.LimitEntity limitEntity) { | ||
super(msg); | ||
this.responseLimit = responseLimit; | ||
this.limitEntity = limitEntity; | ||
} | ||
Check warning on line 39 in server/src/main/java/org/opensearch/common/breaker/ResponseLimitBreachedException.java Codecov / codecov/patchserver/src/main/java/org/opensearch/common/breaker/ResponseLimitBreachedException.java#L36-L39
|
||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeVInt(responseLimit); | ||
out.writeEnum(limitEntity); | ||
} | ||
Check warning on line 46 in server/src/main/java/org/opensearch/common/breaker/ResponseLimitBreachedException.java Codecov / codecov/patchserver/src/main/java/org/opensearch/common/breaker/ResponseLimitBreachedException.java#L43-L46
|
||
|
||
public int getResponseLimit() { | ||
return responseLimit; | ||
Check warning on line 49 in server/src/main/java/org/opensearch/common/breaker/ResponseLimitBreachedException.java Codecov / codecov/patchserver/src/main/java/org/opensearch/common/breaker/ResponseLimitBreachedException.java#L49
|
||
} | ||
|
||
public ResponseLimitSettings.LimitEntity getLimitEntity() { | ||
return limitEntity; | ||
Check warning on line 53 in server/src/main/java/org/opensearch/common/breaker/ResponseLimitBreachedException.java Codecov / codecov/patchserver/src/main/java/org/opensearch/common/breaker/ResponseLimitBreachedException.java#L53
|
||
} | ||
|
||
@Override | ||
public RestStatus status() { | ||
return RestStatus.TOO_MANY_REQUESTS; | ||
Check warning on line 58 in server/src/main/java/org/opensearch/common/breaker/ResponseLimitBreachedException.java Codecov / codecov/patchserver/src/main/java/org/opensearch/common/breaker/ResponseLimitBreachedException.java#L58
|
||
} | ||
|
||
@Override | ||
protected void metadataToXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.field("response_limit", responseLimit); | ||
builder.field("limit_entity", limitEntity); | ||
} | ||
Check warning on line 65 in server/src/main/java/org/opensearch/common/breaker/ResponseLimitBreachedException.java Codecov / codecov/patchserver/src/main/java/org/opensearch/common/breaker/ResponseLimitBreachedException.java#L63-L65
|
||
} |