use of org.opensearch.persistent.PersistentTasksCustomMetadata in project OpenSearch by opensearch-project.
the class ClusterModule method getNamedWriteables.
public static List<Entry> getNamedWriteables() {
List<Entry> entries = new ArrayList<>();
// Cluster State
registerClusterCustom(entries, SnapshotsInProgress.TYPE, SnapshotsInProgress::new, SnapshotsInProgress::readDiffFrom);
registerClusterCustom(entries, RestoreInProgress.TYPE, RestoreInProgress::new, RestoreInProgress::readDiffFrom);
registerClusterCustom(entries, SnapshotDeletionsInProgress.TYPE, SnapshotDeletionsInProgress::new, SnapshotDeletionsInProgress::readDiffFrom);
registerClusterCustom(entries, RepositoryCleanupInProgress.TYPE, RepositoryCleanupInProgress::new, RepositoryCleanupInProgress::readDiffFrom);
// Metadata
registerMetadataCustom(entries, RepositoriesMetadata.TYPE, RepositoriesMetadata::new, RepositoriesMetadata::readDiffFrom);
registerMetadataCustom(entries, IngestMetadata.TYPE, IngestMetadata::new, IngestMetadata::readDiffFrom);
registerMetadataCustom(entries, ScriptMetadata.TYPE, ScriptMetadata::new, ScriptMetadata::readDiffFrom);
registerMetadataCustom(entries, IndexGraveyard.TYPE, IndexGraveyard::new, IndexGraveyard::readDiffFrom);
registerMetadataCustom(entries, PersistentTasksCustomMetadata.TYPE, PersistentTasksCustomMetadata::new, PersistentTasksCustomMetadata::readDiffFrom);
registerMetadataCustom(entries, ComponentTemplateMetadata.TYPE, ComponentTemplateMetadata::new, ComponentTemplateMetadata::readDiffFrom);
registerMetadataCustom(entries, ComposableIndexTemplateMetadata.TYPE, ComposableIndexTemplateMetadata::new, ComposableIndexTemplateMetadata::readDiffFrom);
registerMetadataCustom(entries, DataStreamMetadata.TYPE, DataStreamMetadata::new, DataStreamMetadata::readDiffFrom);
// Task Status (not Diffable)
entries.add(new Entry(Task.Status.class, PersistentTasksNodeService.Status.NAME, PersistentTasksNodeService.Status::new));
return entries;
}
use of org.opensearch.persistent.PersistentTasksCustomMetadata in project OpenSearch by opensearch-project.
the class EnableAssignmentDeciderIT method testEnableAssignmentAfterRestart.
/**
* Test that the {@link EnableAssignmentDecider#CLUSTER_TASKS_ALLOCATION_ENABLE_SETTING} setting correctly
* prevents persistent tasks to be assigned after a cluster restart.
*/
public void testEnableAssignmentAfterRestart() throws Exception {
final int numberOfTasks = randomIntBetween(1, 10);
logger.trace("creating {} persistent tasks", numberOfTasks);
final CountDownLatch latch = new CountDownLatch(numberOfTasks);
for (int i = 0; i < numberOfTasks; i++) {
PersistentTasksService service = internalCluster().getInstance(PersistentTasksService.class);
service.sendStartRequest("task_" + i, TestPersistentTasksExecutor.NAME, new TestParams(randomAlphaOfLength(10)), ActionListener.wrap(latch::countDown));
}
latch.await();
ClusterService clusterService = internalCluster().clusterService(internalCluster().getMasterName());
PersistentTasksCustomMetadata tasks = clusterService.state().getMetadata().custom(PersistentTasksCustomMetadata.TYPE);
assertEquals(numberOfTasks, tasks.tasks().stream().filter(t -> TestPersistentTasksExecutor.NAME.equals(t.getTaskName())).count());
logger.trace("waiting for the tasks to be running");
assertBusy(() -> {
ListTasksResponse listTasks = client().admin().cluster().prepareListTasks().setActions(TestPersistentTasksExecutor.NAME + "[c]").get();
assertThat(listTasks.getTasks().size(), equalTo(numberOfTasks));
});
try {
logger.trace("disable persistent tasks assignment");
disablePersistentTasksAssignment();
logger.trace("restart the cluster");
internalCluster().fullRestart();
ensureYellow();
logger.trace("persistent tasks assignment is still disabled");
assertEnableAssignmentSetting(Allocation.NONE);
logger.trace("persistent tasks are not assigned");
tasks = internalCluster().clusterService().state().getMetadata().custom(PersistentTasksCustomMetadata.TYPE);
assertEquals(numberOfTasks, tasks.tasks().stream().filter(t -> TestPersistentTasksExecutor.NAME.equals(t.getTaskName())).filter(t -> t.isAssigned() == false).count());
ListTasksResponse runningTasks = client().admin().cluster().prepareListTasks().setActions(TestPersistentTasksExecutor.NAME + "[c]").get();
assertThat(runningTasks.getTasks().size(), equalTo(0));
logger.trace("enable persistent tasks assignment");
if (randomBoolean()) {
enablePersistentTasksAssignment();
} else {
resetPersistentTasksAssignment();
}
assertBusy(() -> {
ListTasksResponse listTasks = client().admin().cluster().prepareListTasks().setActions(TestPersistentTasksExecutor.NAME + "[c]").get();
assertThat(listTasks.getTasks().size(), equalTo(numberOfTasks));
});
} finally {
resetPersistentTasksAssignment();
}
}
Aggregations