use of org.opensearch.ml.common.parameter.KMeansParams in project ml-commons by opensearch-project.
the class SecureMLRestIT method testReadOnlyUser_CanGetTask_CanNotDeleteTask.
public void testReadOnlyUser_CanGetTask_CanNotDeleteTask() throws IOException {
KMeansParams kMeansParams = KMeansParams.builder().build();
// train model with full access client
train(mlFullAccessClient, FunctionName.KMEANS, irisIndex, kMeansParams, searchSourceBuilder, trainResult -> {
assertFalse(trainResult.containsKey("model_id"));
String taskId = (String) trainResult.get("task_id");
assertNotNull(taskId);
String status = (String) trainResult.get("status");
assertEquals(MLTaskState.CREATED.name(), status);
try {
// get task with readonly client
getTask(mlReadOnlyClient, taskId, task -> {
String algorithm = (String) task.get("function_name");
assertEquals(FunctionName.KMEANS.name(), algorithm);
});
} catch (IOException e) {
assertNull(e);
}
try {
// Failed to delete task with read only client
deleteTask(mlReadOnlyClient, taskId, null);
throw new RuntimeException("Delete task for readonly user does not fail");
} catch (Exception e) {
assertEquals(ResponseException.class, e.getClass());
assertTrue(Throwables.getStackTraceAsString(e).contains("no permissions for [cluster:admin/opensearch/ml/tasks/delete]"));
}
}, true);
}
use of org.opensearch.ml.common.parameter.KMeansParams in project ml-commons by opensearch-project.
the class SecureMLRestIT method testReadOnlyUser_CanSearchModels.
public void testReadOnlyUser_CanSearchModels() throws IOException {
KMeansParams kMeansParams = KMeansParams.builder().build();
// train model with full access client
train(mlFullAccessClient, FunctionName.KMEANS, irisIndex, kMeansParams, searchSourceBuilder, trainResult -> {
String modelId = (String) trainResult.get("model_id");
assertNotNull(modelId);
String status = (String) trainResult.get("status");
assertEquals(MLTaskState.COMPLETED.name(), status);
try {
// search model with readonly client
searchModelsWithAlgoName(mlReadOnlyClient, FunctionName.KMEANS.name(), models -> {
ArrayList<Object> hits = (ArrayList) ((Map<String, Object>) models.get("hits")).get("hits");
assertTrue(hits.size() > 0);
});
} catch (IOException e) {
assertNull(e);
}
}, false);
}
use of org.opensearch.ml.common.parameter.KMeansParams in project ml-commons by opensearch-project.
the class SecureMLRestIT method testTrainWithReadOnlyMLAccess.
public void testTrainWithReadOnlyMLAccess() throws IOException {
exceptionRule.expect(ResponseException.class);
exceptionRule.expectMessage("no permissions for [cluster:admin/opensearch/ml/train]");
KMeansParams kMeansParams = KMeansParams.builder().build();
train(mlReadOnlyClient, FunctionName.KMEANS, irisIndex, kMeansParams, searchSourceBuilder, null, false);
}
use of org.opensearch.ml.common.parameter.KMeansParams in project ml-commons by opensearch-project.
the class SecureMLRestIT method testPredictWithReadOnlyMLAccess.
public void testPredictWithReadOnlyMLAccess() throws IOException {
exceptionRule.expect(ResponseException.class);
exceptionRule.expectMessage("no permissions for [cluster:admin/opensearch/ml/predict]");
KMeansParams kMeansParams = KMeansParams.builder().build();
predict(mlReadOnlyClient, FunctionName.KMEANS, "modelId", irisIndex, kMeansParams, searchSourceBuilder, null);
}
Aggregations