use of org.opensearch.persistent.TestPersistentTasksPlugin.TestParams in project OpenSearch by opensearch-project.
the class PersistentTasksClusterServiceTests method assignOnlyOneTaskAtATime.
private Assignment assignOnlyOneTaskAtATime(ClusterState clusterState) {
DiscoveryNodes nodes = clusterState.nodes();
PersistentTasksCustomMetadata tasksInProgress = clusterState.getMetadata().custom(PersistentTasksCustomMetadata.TYPE);
if (tasksInProgress.findTasks(TestPersistentTasksExecutor.NAME, task -> "assign_one".equals(((TestParams) task.getParams()).getTestParam()) && nodes.nodeExists(task.getExecutorNode())).isEmpty()) {
return randomNodeAssignment(clusterState.nodes());
} else {
return new Assignment(null, "only one task can be assigned at a time");
}
}
use of org.opensearch.persistent.TestPersistentTasksPlugin.TestParams in project OpenSearch by opensearch-project.
the class PersistentTasksClusterServiceTests method insignificantChange.
private ClusterState insignificantChange(ClusterState clusterState) {
ClusterState.Builder builder = ClusterState.builder(clusterState);
PersistentTasksCustomMetadata tasks = clusterState.getMetadata().custom(PersistentTasksCustomMetadata.TYPE);
tasks = removeTasksWithChangingAssignment(tasks);
PersistentTasksCustomMetadata.Builder tasksBuilder = PersistentTasksCustomMetadata.builder(tasks);
if (randomBoolean()) {
if (hasAssignableTasks(tasks, clusterState.nodes()) == false) {
// we don't have any unassigned tasks - adding a node or changing a routing table shouldn't affect anything
if (randomBoolean()) {
logger.info("added random node");
builder.nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode(randomAlphaOfLength(10))));
}
if (randomBoolean()) {
logger.info("added random unassignable task");
addRandomTask(builder, Metadata.builder(clusterState.metadata()), tasksBuilder, NO_NODE_FOUND, "never_assign");
return builder.build();
}
logger.info("changed routing table");
Metadata.Builder metadata = Metadata.builder(clusterState.metadata());
metadata.putCustom(PersistentTasksCustomMetadata.TYPE, tasksBuilder.build());
RoutingTable.Builder routingTable = RoutingTable.builder(clusterState.routingTable());
changeRoutingTable(metadata, routingTable);
builder.metadata(metadata).routingTable(routingTable.build());
return builder.build();
}
}
if (randomBoolean()) {
// remove a node that doesn't have any tasks assigned to it and it's not the master node
for (DiscoveryNode node : clusterState.nodes()) {
if (hasTasksAssignedTo(tasks, node.getId()) == false && "this_node".equals(node.getId()) == false) {
logger.info("removed unassigned node {}", node.getId());
return builder.nodes(DiscoveryNodes.builder(clusterState.nodes()).remove(node.getId())).build();
}
}
}
if (randomBoolean()) {
// clear the task
if (randomBoolean()) {
logger.info("removed all tasks");
Metadata.Builder metadata = Metadata.builder(clusterState.metadata()).putCustom(PersistentTasksCustomMetadata.TYPE, PersistentTasksCustomMetadata.builder().build());
return builder.metadata(metadata).build();
} else {
logger.info("set task custom to null");
Metadata.Builder metadata = Metadata.builder(clusterState.metadata()).removeCustom(PersistentTasksCustomMetadata.TYPE);
return builder.metadata(metadata).build();
}
}
logger.info("removed all unassigned tasks and changed routing table");
if (tasks != null) {
for (PersistentTask<?> task : tasks.tasks()) {
if (task.getExecutorNode() == null || "never_assign".equals(((TestParams) task.getParams()).getTestParam())) {
tasksBuilder.removeTask(task.getId());
}
}
}
// Just add a random index - that shouldn't change anything
IndexMetadata indexMetadata = IndexMetadata.builder(randomAlphaOfLength(10)).settings(Settings.builder().put("index.version.created", VersionUtils.randomVersion(random()))).numberOfShards(1).numberOfReplicas(1).build();
Metadata.Builder metadata = Metadata.builder(clusterState.metadata()).put(indexMetadata, false).putCustom(PersistentTasksCustomMetadata.TYPE, tasksBuilder.build());
return builder.metadata(metadata).build();
}
use of org.opensearch.persistent.TestPersistentTasksPlugin.TestParams in project OpenSearch by opensearch-project.
the class PersistentTasksClusterServiceTests method addTask.
private String addTask(PersistentTasksCustomMetadata.Builder tasks, String param, String node) {
String id = UUIDs.base64UUID();
tasks.addTask(id, TestPersistentTasksExecutor.NAME, new TestParams(param), new Assignment(node, "explanation: " + param));
return id;
}
use of org.opensearch.persistent.TestPersistentTasksPlugin.TestParams in project OpenSearch by opensearch-project.
the class PersistentTasksCustomMetadataTests method createTestInstance.
@Override
protected PersistentTasksCustomMetadata createTestInstance() {
int numberOfTasks = randomInt(10);
PersistentTasksCustomMetadata.Builder tasks = PersistentTasksCustomMetadata.builder();
for (int i = 0; i < numberOfTasks; i++) {
String taskId = UUIDs.base64UUID();
tasks.addTask(taskId, TestPersistentTasksExecutor.NAME, new TestParams(randomAlphaOfLength(10)), randomAssignment());
if (randomBoolean()) {
// From time to time update status
tasks.updateTaskState(taskId, new State(randomAlphaOfLength(10)));
}
}
return tasks.build();
}
use of org.opensearch.persistent.TestPersistentTasksPlugin.TestParams in project OpenSearch by opensearch-project.
the class PersistentTasksCustomMetadataTests method addRandomTask.
private String addRandomTask(Builder builder) {
String taskId = UUIDs.base64UUID();
builder.addTask(taskId, TestPersistentTasksExecutor.NAME, new TestParams(randomAlphaOfLength(10)), randomAssignment());
return taskId;
}
Aggregations