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

Add Integration Tests for Workload Management CRUD APIs #15955

Merged
merged 4 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Added
- Add support for async deletion in S3BlobContainer ([#15621](https://github.com/opensearch-project/OpenSearch/pull/15621))
- MultiTermQueries in keyword fields now default to `indexed` approach and gated behind cluster setting ([#15637](https://github.com/opensearch-project/OpenSearch/pull/15637))
- [Workload Management] Add Integration Tests for Workload Management CRUD APIs ([#15955](https://github.com/opensearch-project/OpenSearch/pull/15955))
- [Workload Management] QueryGroup resource cancellation framework changes ([#15651](https://github.com/opensearch-project/OpenSearch/pull/15651))
- [Workload Management] Add orchestrator for wlm resiliency (QueryGroupService) ([#15925](https://github.com/opensearch-project/OpenSearch/pull/15925))
- Fallback to Remote cluster-state on Term-Version check mismatch - ([#15424](https://github.com/opensearch-project/OpenSearch/pull/15424))
Expand Down
1 change: 1 addition & 0 deletions plugins/workload-management/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/

apply plugin: 'opensearch.yaml-rest-test'
apply plugin: 'opensearch.java-rest-test'
apply plugin: 'opensearch.internal-cluster-test'

opensearchplugin {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
/*
* 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;

import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.opensearch.client.Request;
import org.opensearch.client.Response;
import org.opensearch.client.ResponseException;
import org.opensearch.test.rest.OpenSearchRestTestCase;

import java.io.IOException;

public class WorkloadManagementRestIT extends OpenSearchRestTestCase {

public void testCreate() throws Exception {
Response response = performOperation("PUT", "_wlm/query_group", getCreateJson("analytics", "enforced", 0.4, 0.2));
assertEquals(response.getStatusLine().getStatusCode(), 200);
performOperation("DELETE", "_wlm/query_group/analytics", null);
}

public void testMultipleCreate() throws Exception {
Response response = performOperation("PUT", "_wlm/query_group", getCreateJson("analytics2", "enforced", 0.4, 0.2));
assertEquals(response.getStatusLine().getStatusCode(), 200);

Response response2 = performOperation("PUT", "_wlm/query_group", getCreateJson("users", "soft", 0.2, 0.1));
assertEquals(response2.getStatusLine().getStatusCode(), 200);

assertThrows(
ResponseException.class,
() -> performOperation("PUT", "_wlm/query_group", getCreateJson("users2", "soft", 0.41, 0.71))
);
performOperation("DELETE", "_wlm/query_group/analytics2", null);
performOperation("DELETE", "_wlm/query_group/users", null);
}

public void testGet() throws Exception {
Response response = performOperation("PUT", "_wlm/query_group", getCreateJson("analytics3", "enforced", 0.4, 0.2));
assertEquals(response.getStatusLine().getStatusCode(), 200);

Response response2 = performOperation("GET", "_wlm/query_group/analytics3", null);
assertEquals(response2.getStatusLine().getStatusCode(), 200);
String responseBody2 = EntityUtils.toString(response2.getEntity());
assertTrue(responseBody2.contains("\"name\":\"analytics3\""));
assertTrue(responseBody2.contains("\"resiliency_mode\":\"enforced\""));
assertTrue(responseBody2.contains("\"cpu\":0.4"));
assertTrue(responseBody2.contains("\"memory\":0.2"));

assertThrows(ResponseException.class, () -> performOperation("GET", "_wlm/query_group/analytics97", null));
performOperation("DELETE", "_wlm/query_group/analytics3", null);
}

public void testDelete() throws Exception {
Response response = performOperation("PUT", "_wlm/query_group", getCreateJson("analytics4", "enforced", 0.4, 0.2));
assertEquals(response.getStatusLine().getStatusCode(), 200);

Response response2 = performOperation("DELETE", "_wlm/query_group/analytics4", null);
assertEquals(response2.getStatusLine().getStatusCode(), 200);
assertTrue(EntityUtils.toString(response2.getEntity()).contains("\"acknowledged\":true"));

assertThrows(ResponseException.class, () -> performOperation("DELETE", "_wlm/query_group/analytics99", null));
}

public void testUpdate() throws Exception {
Response response = performOperation("PUT", "_wlm/query_group", getCreateJson("analytics5", "enforced", 0.4, 0.2));
assertEquals(response.getStatusLine().getStatusCode(), 200);

Response response2 = performOperation("PUT", "_wlm/query_group/analytics5", getUpdateJson("monitor", 0.41, 0.21));
assertEquals(response2.getStatusLine().getStatusCode(), 200);
String responseBody2 = EntityUtils.toString(response2.getEntity());
assertTrue(responseBody2.contains("\"name\":\"analytics5\""));
assertTrue(responseBody2.contains("\"resiliency_mode\":\"monitor\""));
assertTrue(responseBody2.contains("\"cpu\":0.41"));
assertTrue(responseBody2.contains("\"memory\":0.21"));

String json = "{\n"
+ " \"resource_limits\": {\n"
+ " \"cpu\" : 1.1,\n"
+ " \"memory\" : -0.1\n"
+ " }\n"
+ "}'";
assertThrows(ResponseException.class, () -> performOperation("PUT", "_wlm/query_group/analytics5", json));
assertThrows(
ResponseException.class,
() -> performOperation("PUT", "_wlm/query_group/analytics98", getUpdateJson("monitor", 0.43, 0.23))
);
performOperation("DELETE", "_wlm/query_group/analytics5", null);
}

public void testCRUD() throws Exception {
Response response = performOperation("PUT", "_wlm/query_group", getCreateJson("analytics6", "enforced", 0.4, 0.2));
assertEquals(response.getStatusLine().getStatusCode(), 200);

Response response1 = performOperation("PUT", "_wlm/query_group/analytics6", getUpdateJson("monitor", 0.41, 0.21));
assertEquals(response1.getStatusLine().getStatusCode(), 200);

Response response2 = performOperation("GET", "_wlm/query_group/analytics6", null);
assertEquals(response2.getStatusLine().getStatusCode(), 200);
String responseBody2 = EntityUtils.toString(response2.getEntity());
assertTrue(responseBody2.contains("\"name\":\"analytics6\""));
assertTrue(responseBody2.contains("\"resiliency_mode\":\"monitor\""));
assertTrue(responseBody2.contains("\"cpu\":0.41"));
assertTrue(responseBody2.contains("\"memory\":0.21"));

assertThrows(
ResponseException.class,
() -> performOperation("PUT", "_wlm/query_group", getCreateJson("users3", "monitor", 0.6, 0.8))
);

Response response4 = performOperation("PUT", "_wlm/query_group", getCreateJson("users3", "monitor", 0.59, 0.79));
assertEquals(response4.getStatusLine().getStatusCode(), 200);

Response response5 = performOperation("DELETE", "_wlm/query_group/analytics6", null);
assertEquals(response5.getStatusLine().getStatusCode(), 200);
String responseBody5 = EntityUtils.toString(response5.getEntity());
assertTrue(responseBody5.contains("\"acknowledged\":true"));

Response response6 = performOperation("GET", "_wlm/query_group", null);
assertEquals(response6.getStatusLine().getStatusCode(), 200);
String responseBody6 = EntityUtils.toString(response6.getEntity());
assertTrue(responseBody6.contains("\"query_groups\""));
assertTrue(responseBody6.contains("\"users3\""));
assertFalse(responseBody6.contains("\"analytics6\""));
performOperation("DELETE", "_wlm/query_group/users3", null);
}

static String getCreateJson(String name, String resiliencyMode, double cpu, double memory) {
return "{\n"
+ " \"name\": \""
+ name
+ "\",\n"
+ " \"resiliency_mode\": \""
+ resiliencyMode
+ "\",\n"
+ " \"resource_limits\": {\n"
+ " \"cpu\" : "
+ cpu
+ ",\n"
+ " \"memory\" : "
+ memory
+ "\n"
+ " }\n"
+ "}";
}

static String getUpdateJson(String resiliencyMode, double cpu, double memory) {
return "{\n"
+ " \"resiliency_mode\": \""
+ resiliencyMode
+ "\",\n"
+ " \"resource_limits\": {\n"
+ " \"cpu\" : "
+ cpu
+ ",\n"
+ " \"memory\" : "
+ memory
+ "\n"
+ " }\n"
+ "}";
}

Response performOperation(String method, String uriPath, String json) throws IOException {
Request request = new Request(method, uriPath);
if (json != null) {
request.setJsonEntity(json);
}
return client().performRequest(request);
}
}
Loading