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

Feature/QueryGroup Add CRUD APIs in plugin #13315

Closed
Show file tree
Hide file tree
Changes from 11 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
1 change: 1 addition & 0 deletions CHANGELOG-3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Add task completion count in search backpressure stats API ([#10028](https://github.com/opensearch-project/OpenSearch/pull/10028/))
- Deprecate CamelCase `PathHierarchy` tokenizer name in favor to lowercase `path_hierarchy` ([#10894](https://github.com/opensearch-project/OpenSearch/pull/10894))
- Breaking change: Do not request "search_pipelines" metrics by default in NodesInfoRequest ([#12497](https://github.com/opensearch-project/OpenSearch/pull/12497))
- [Query Sandbox] Add Resource Limit Group CRUD APIs ([#13315](https://github.com/opensearch-project/OpenSearch/pull/13315))
ruai0511 marked this conversation as resolved.
Show resolved Hide resolved

### Deprecated

Expand Down
18 changes: 18 additions & 0 deletions plugins/query-resource-limit-group/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

opensearchplugin {
description 'OpenSearch ResourceLimitGroup Plugin.'
classname 'org.opensearch.plugin.resource_limit_group.ResourceLimitGroupPlugin'
ruai0511 marked this conversation as resolved.
Show resolved Hide resolved
}

dependencies {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.plugin.resource_limit_group;

import org.opensearch.action.ActionType;

/**
* Rest action to create Resource Limit Group
*
* @opensearch.api
*/
public class CreateResourceLimitGroupAction extends ActionType<CreateResourceLimitGroupResponse> {

/**
* An instance of CreateResourceLimitGroupAction
*/
public static final CreateResourceLimitGroupAction INSTANCE = new CreateResourceLimitGroupAction();

Check warning on line 23 in plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupAction.java

View check run for this annotation

Codecov / codecov/patch

plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupAction.java#L23

Added line #L23 was not covered by tests

/**
* Name for CreateResourceLimitGroupAction
*/
public static final String NAME = "cluster:admin/opensearch/resource_limit_group/_create";

/**
* Default constructor
*/
private CreateResourceLimitGroupAction() {
super(NAME, CreateResourceLimitGroupResponse::new);
}

Check warning on line 35 in plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupAction.java

View check run for this annotation

Codecov / codecov/patch

plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupAction.java#L34-L35

Added lines #L34 - L35 were not covered by tests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/*
* 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.plugin.resource_limit_group;

import org.opensearch.action.ActionRequest;
import org.opensearch.action.ActionRequestValidationException;
import org.opensearch.cluster.metadata.ResourceLimitGroup;
import org.opensearch.cluster.metadata.ResourceLimitGroup.ResourceLimit;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.core.common.io.stream.Writeable;
import org.opensearch.core.xcontent.XContentParser;

import java.io.IOException;
import java.util.List;

/**
* A request for create Resource Limit Group
*
* @opensearch.internal
*/
public class CreateResourceLimitGroupRequest extends ActionRequest implements Writeable.Reader<CreateResourceLimitGroupRequest> {
private String name;
private String uuid;
private List<ResourceLimit> resourceLimits;
ruai0511 marked this conversation as resolved.
Show resolved Hide resolved
private String enforcement;
private String createdAt;
private String updatedAt;
ruai0511 marked this conversation as resolved.
Show resolved Hide resolved

/**
* Default constructor for CreateResourceLimitGroupRequest
*/
public CreateResourceLimitGroupRequest() {}

Check warning on line 39 in plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupRequest.java

View check run for this annotation

Codecov / codecov/patch

plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupRequest.java#L39

Added line #L39 was not covered by tests

/**
* Constructor for CreateResourceLimitGroupRequest
* @param resourceLimitGroup - A {@link ResourceLimitGroup} object
*/
public CreateResourceLimitGroupRequest(ResourceLimitGroup resourceLimitGroup) {
this.name = resourceLimitGroup.getName();
this.uuid = resourceLimitGroup.getUUID();
this.resourceLimits = resourceLimitGroup.getResourceLimits();
this.enforcement = resourceLimitGroup.getEnforcement();
this.createdAt = resourceLimitGroup.getCreatedAt();
this.updatedAt = resourceLimitGroup.getUpdatedAt();
}

/**
* Constructor for CreateResourceLimitGroupRequest
* @param in - A {@link StreamInput} object
*/
public CreateResourceLimitGroupRequest(StreamInput in) throws IOException {
super(in);
name = in.readString();
uuid = in.readString();
resourceLimits = in.readList(ResourceLimit::new);
enforcement = in.readString();
createdAt = in.readString();
updatedAt = in.readString();
}

@Override
public CreateResourceLimitGroupRequest read(StreamInput in) throws IOException {
return new CreateResourceLimitGroupRequest(in);

Check warning on line 70 in plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupRequest.java

View check run for this annotation

Codecov / codecov/patch

plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupRequest.java#L70

Added line #L70 was not covered by tests
}

/**
* Generate a CreateResourceLimitGroupRequest from XContent
* @param parser - A {@link XContentParser} object
*/
public static CreateResourceLimitGroupRequest fromXContent(XContentParser parser) throws IOException {
ResourceLimitGroup resourceLimitGroup = ResourceLimitGroup.fromXContent(parser);
return new CreateResourceLimitGroupRequest(resourceLimitGroup);

Check warning on line 79 in plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupRequest.java

View check run for this annotation

Codecov / codecov/patch

plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupRequest.java#L78-L79

Added lines #L78 - L79 were not covered by tests
}

@Override
public ActionRequestValidationException validate() {
ruai0511 marked this conversation as resolved.
Show resolved Hide resolved
return null;

Check warning on line 84 in plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupRequest.java

View check run for this annotation

Codecov / codecov/patch

plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupRequest.java#L84

Added line #L84 was not covered by tests
}

/**
* name getter
*/
public String getName() {
return name;
}

/**
* name setter
* @param name - name to be set
*/
public void setName(String name) {
this.name = name;
}

Check warning on line 100 in plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupRequest.java

View check run for this annotation

Codecov / codecov/patch

plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupRequest.java#L99-L100

Added lines #L99 - L100 were not covered by tests

/**
* resourceLimits getter
*/
public List<ResourceLimit> getResourceLimits() {
return resourceLimits;
}

/**
* resourceLimits setter
* @param resourceLimits - resourceLimit to be set
*/
public void setResourceLimits(List<ResourceLimit> resourceLimits) {
this.resourceLimits = resourceLimits;
}

Check warning on line 115 in plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupRequest.java

View check run for this annotation

Codecov / codecov/patch

plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupRequest.java#L114-L115

Added lines #L114 - L115 were not covered by tests

/**
* Enforcement getter
*/
public String getEnforcement() {
return enforcement;
}

/**
* Enforcement setter
* @param enforcement - enforcement to be set
*/
public void setEnforcement(String enforcement) {
this.enforcement = enforcement;
}

Check warning on line 130 in plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupRequest.java

View check run for this annotation

Codecov / codecov/patch

plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupRequest.java#L129-L130

Added lines #L129 - L130 were not covered by tests

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
ResourceLimitGroup.writeToOutputStream(out, name, uuid, resourceLimits, enforcement, createdAt, updatedAt);
}

/**
* UUID getter
*/
public String getUUID() {
return uuid;

Check warning on line 142 in plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupRequest.java

View check run for this annotation

Codecov / codecov/patch

plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupRequest.java#L142

Added line #L142 was not covered by tests
}

/**
* UUID setter
* @param uuid - uuid to be set
*/
public void setUUID(String uuid) {
this.uuid = uuid;
}

Check warning on line 151 in plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupRequest.java

View check run for this annotation

Codecov / codecov/patch

plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupRequest.java#L150-L151

Added lines #L150 - L151 were not covered by tests

/**
* createdAt getter
*/
public String getCreatedAt() {
return createdAt;
}

/**
* createdAt setter
* @param createdAt - createdAt to be set
*/
public void setCreatedAt(String createdAt) {
this.createdAt = createdAt;
}

Check warning on line 166 in plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupRequest.java

View check run for this annotation

Codecov / codecov/patch

plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupRequest.java#L165-L166

Added lines #L165 - L166 were not covered by tests

/**
* updatedAt getter
*/
public String getUpdatedAt() {
return updatedAt;
}

/**
* updatedAt setter
* @param updatedAt - updatedAt to be set
*/
public void setUpdatedAt(String updatedAt) {
this.updatedAt = updatedAt;
}

Check warning on line 181 in plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupRequest.java

View check run for this annotation

Codecov / codecov/patch

plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupRequest.java#L180-L181

Added lines #L180 - L181 were not covered by tests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* 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.plugin.resource_limit_group;

import org.opensearch.cluster.metadata.ResourceLimitGroup;
import org.opensearch.core.action.ActionResponse;
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.ToXContent;
import org.opensearch.core.xcontent.ToXContentObject;
import org.opensearch.core.xcontent.XContentBuilder;

import java.io.IOException;

/**
* Response for the create API for resource limit groups
*
* @opensearch.internal
*/
public class CreateResourceLimitGroupResponse extends ActionResponse implements ToXContent, ToXContentObject {
private final ResourceLimitGroup resourceLimitGroup;
private RestStatus restStatus;

/**
* Constructor for CreateResourceLimitGroupResponse
*/
public CreateResourceLimitGroupResponse() {
this.resourceLimitGroup = null;
}

Check warning on line 36 in plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupResponse.java

View check run for this annotation

Codecov / codecov/patch

plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupResponse.java#L34-L36

Added lines #L34 - L36 were not covered by tests

/**
* Constructor for CreateResourceLimitGroupResponse
* @param resourceLimitGroup - The resource limit group to be created
*/
public CreateResourceLimitGroupResponse(final ResourceLimitGroup resourceLimitGroup) {
this.resourceLimitGroup = resourceLimitGroup;
}

/**
* Constructor for CreateResourceLimitGroupResponse
* @param in - A {@link StreamInput} object
*/
public CreateResourceLimitGroupResponse(StreamInput in) throws IOException {
resourceLimitGroup = new ResourceLimitGroup(in);
}

@Override
public void writeTo(StreamOutput out) throws IOException {
resourceLimitGroup.writeTo(out);
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
resourceLimitGroup.toXContent(builder, params);
return builder;

Check warning on line 62 in plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupResponse.java

View check run for this annotation

Codecov / codecov/patch

plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupResponse.java#L61-L62

Added lines #L61 - L62 were not covered by tests
}

/**
* resourceLimitGroup getter
*/
public ResourceLimitGroup getResourceLimitGroup() {
return resourceLimitGroup;
}

/**
* restStatus getter
*/
public RestStatus getRestStatus() {
return restStatus;
}

/**
* restStatus setter
* @param restStatus - A {@link RestStatus} object
*/
public void setRestStatus(RestStatus restStatus) {
this.restStatus = restStatus;
}

Check warning on line 85 in plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupResponse.java

View check run for this annotation

Codecov / codecov/patch

plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/CreateResourceLimitGroupResponse.java#L84-L85

Added lines #L84 - L85 were not covered by tests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.plugin.resource_limit_group;

import org.opensearch.action.ActionType;

/**
* Rest action to delete Resource Limit Group
*
* @opensearch.api
*/
public class DeleteResourceLimitGroupAction extends ActionType<DeleteResourceLimitGroupResponse> {

/**
/**
* An instance of DeleteResourceLimitGroupAction
*/
public static final DeleteResourceLimitGroupAction INSTANCE = new DeleteResourceLimitGroupAction();

Check warning on line 24 in plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/DeleteResourceLimitGroupAction.java

View check run for this annotation

Codecov / codecov/patch

plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/DeleteResourceLimitGroupAction.java#L24

Added line #L24 was not covered by tests

/**
* Name for DeleteResourceLimitGroupAction
*/
public static final String NAME = "cluster:admin/opensearch/resource_limit_group/_delete";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Maybe consider a shortened alternative such as rlg etc.


/**
* Default constructor
*/
private DeleteResourceLimitGroupAction() {
super(NAME, DeleteResourceLimitGroupResponse::new);
}

Check warning on line 36 in plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/DeleteResourceLimitGroupAction.java

View check run for this annotation

Codecov / codecov/patch

plugins/query-resource-limit-group/src/main/java/org/opensearch/plugin/resource_limit_group/DeleteResourceLimitGroupAction.java#L35-L36

Added lines #L35 - L36 were not covered by tests
}
Loading
Loading