Skip to content

Commit c4bc6f5

Browse files
committed
add IT
Signed-off-by: Ruirui Zhang <[email protected]>
1 parent 494a025 commit c4bc6f5

File tree

5 files changed

+177
-2
lines changed

5 files changed

+177
-2
lines changed

plugins/workload-management/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
* GitHub history for details.
1010
*/
1111

12+
apply plugin: 'opensearch.yaml-rest-test'
13+
apply plugin: 'opensearch.internal-cluster-test'
14+
1215
opensearchplugin {
1316
description 'OpenSearch Workload Management Plugin.'
1417
classname 'org.opensearch.plugin.wlm.WorkloadManagementPlugin'
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
/*
10+
* Licensed to Elasticsearch under one or more contributor
11+
* license agreements. See the NOTICE file distributed with
12+
* this work for additional information regarding copyright
13+
* ownership. Elasticsearch licenses this file to you under
14+
* the Apache License, Version 2.0 (the "License"); you may
15+
* not use this file except in compliance with the License.
16+
* You may obtain a copy of the License at
17+
*
18+
* http://www.apache.org/licenses/LICENSE-2.0
19+
*
20+
* Unless required by applicable law or agreed to in writing,
21+
* software distributed under the License is distributed on an
22+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23+
* KIND, either express or implied. See the License for the
24+
* specific language governing permissions and limitations
25+
* under the License.
26+
*/
27+
28+
/*
29+
* Modifications Copyright OpenSearch Contributors. See
30+
* GitHub history for details.
31+
*/
32+
33+
package org.opensearch.plugin.wlm;
34+
35+
import com.carrotsearch.randomizedtesting.annotations.Name;
36+
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
37+
38+
import org.opensearch.test.rest.yaml.ClientYamlTestCandidate;
39+
import org.opensearch.test.rest.yaml.OpenSearchClientYamlSuiteTestCase;
40+
41+
/** Runs yaml rest tests */
42+
public class WorkloadManagementClientYamlTestSuiteIT extends OpenSearchClientYamlSuiteTestCase {
43+
44+
public WorkloadManagementClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) {
45+
super(testCandidate);
46+
}
47+
48+
@ParametersFactory
49+
public static Iterable<Object[]> parameters() throws Exception {
50+
return OpenSearchClientYamlSuiteTestCase.createParameters();
51+
}
52+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"create_query_group_context": {
3+
"stability": "experimental",
4+
"url": {
5+
"paths": [
6+
{
7+
"path": "/_wlm/query_group",
8+
"methods": ["PUT", "POST"],
9+
"parts": {}
10+
}
11+
]
12+
},
13+
"params":{},
14+
"body":{
15+
"description":"The QueryGroup schema"
16+
}
17+
}
18+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
"test create a QueryGroup API successfully":
2+
- skip:
3+
version: " - 2.16.99"
4+
reason: "QueryGroup WorkloadManagement feature was added in 2.17"
5+
6+
- do:
7+
create_query_group_context:
8+
body:
9+
{
10+
"name": "analytics",
11+
"resiliency_mode": "monitor",
12+
"resource_limits": {
13+
"cpu": 0.4,
14+
"memory": 0.2
15+
}
16+
}
17+
18+
- match: { name: "analytics" }
19+
- match: { resiliency_mode: "monitor" }
20+
- match: { resource_limits.cpu: 0.4 }
21+
- match: { resource_limits.memory: 0.2 }
22+
23+
---
24+
"test bad QueryGroup API arguments":
25+
- skip:
26+
version: " - 2.16.99"
27+
reason: "QueryGroup WorkloadManagement feature was added in 2.17"
28+
29+
- do:
30+
catch: /illegal_argument_exception/
31+
create_query_group_context:
32+
body:
33+
{
34+
"name": "analytics",
35+
"resiliency_mode": "monitor",
36+
"resource_limits": {
37+
"cpu": 0.4,
38+
"memory": 0.2
39+
}
40+
}
41+
42+
- do:
43+
catch: /illegal_argument_exception/
44+
create_query_group_context:
45+
body:
46+
{
47+
"name": "analytics2",
48+
"resiliency_mode": "monitor",
49+
"resource_limits": {
50+
"cpu": 0.61,
51+
"memory": 0.2
52+
}
53+
}
54+
55+
- do:
56+
catch: /illegal_argument_exception/
57+
create_query_group_context:
58+
body:
59+
{
60+
"name": "analytics2",
61+
"resiliency_mode": "monitor",
62+
"resource_limits": {
63+
"cpu": -0.1,
64+
"memory": 0.2
65+
}
66+
}
67+
68+
- do:
69+
catch: /illegal_argument_exception/
70+
create_query_group_context:
71+
body:
72+
{
73+
"name": "",
74+
"resiliency_mode": "monitor",
75+
"resource_limits": {
76+
"cpu": 0.1,
77+
"memory": 0.2
78+
}
79+
}
80+
81+
---
82+
"test create another QueryGroup API successfully":
83+
- skip:
84+
version: " - 2.16.99"
85+
reason: "QueryGroup WorkloadManagement feature was added in 2.17"
86+
87+
- do:
88+
create_query_group_context:
89+
body:
90+
{
91+
"name": "analytics2",
92+
"resiliency_mode": "monitor",
93+
"resource_limits": {
94+
"cpu": 0.35,
95+
"memory": 0.25
96+
}
97+
}
98+
99+
- match: { name: "analytics2" }
100+
- match: { resiliency_mode: "monitor" }
101+
- match: { resource_limits.cpu: 0.35 }
102+
- match: { resource_limits.memory: 0.25 }

server/src/main/java/org/opensearch/cluster/metadata/QueryGroup.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public QueryGroup(String name, String _id, ResiliencyMode resiliencyMode, Map<Re
6363
Objects.requireNonNull(resiliencyMode, "QueryGroup.resiliencyMode can't be null");
6464
Objects.requireNonNull(_id, "QueryGroup._id can't be null");
6565

66-
if (name.length() > MAX_CHARS_ALLOWED_IN_NAME) {
67-
throw new IllegalArgumentException("QueryGroup.name shouldn't be more than 50 chars long");
66+
if (name.length() > MAX_CHARS_ALLOWED_IN_NAME || name.isEmpty()) {
67+
throw new IllegalArgumentException("QueryGroup.name shouldn't be empty or more than 50 chars long");
6868
}
6969

7070
if (resourceLimits.isEmpty()) {

0 commit comments

Comments
 (0)