Search in sources :

Example 1 with PersistentTasksCustomMetadata

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;
}
Also used : PersistentTasksNodeService(org.opensearch.persistent.PersistentTasksNodeService) ComponentTemplateMetadata(org.opensearch.cluster.metadata.ComponentTemplateMetadata) ArrayList(java.util.ArrayList) PersistentTasksCustomMetadata(org.opensearch.persistent.PersistentTasksCustomMetadata) DataStreamMetadata(org.opensearch.cluster.metadata.DataStreamMetadata) RepositoriesMetadata(org.opensearch.cluster.metadata.RepositoriesMetadata) Entry(org.opensearch.common.io.stream.NamedWriteableRegistry.Entry) ScriptMetadata(org.opensearch.script.ScriptMetadata) IngestMetadata(org.opensearch.ingest.IngestMetadata) ComposableIndexTemplateMetadata(org.opensearch.cluster.metadata.ComposableIndexTemplateMetadata) IndexGraveyard(org.opensearch.cluster.metadata.IndexGraveyard)

Example 2 with PersistentTasksCustomMetadata

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();
    }
}
Also used : OpenSearchAssertions.assertAcked(org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked) TestPersistentTasksPlugin(org.opensearch.persistent.TestPersistentTasksPlugin) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) PersistentTasksService(org.opensearch.persistent.PersistentTasksService) TestParams(org.opensearch.persistent.TestPersistentTasksPlugin.TestParams) Collection(java.util.Collection) PersistentTasksCustomMetadata(org.opensearch.persistent.PersistentTasksCustomMetadata) Settings(org.opensearch.common.settings.Settings) Plugin(org.opensearch.plugins.Plugin) Collections.singletonList(java.util.Collections.singletonList) TestPersistentTasksExecutor(org.opensearch.persistent.TestPersistentTasksPlugin.TestPersistentTasksExecutor) CountDownLatch(java.util.concurrent.CountDownLatch) ListTasksResponse(org.opensearch.action.admin.cluster.node.tasks.list.ListTasksResponse) Matchers.equalTo(org.hamcrest.Matchers.equalTo) ClusterService(org.opensearch.cluster.service.ClusterService) Allocation(org.opensearch.persistent.decider.EnableAssignmentDecider.Allocation) ActionListener(org.opensearch.action.ActionListener) OpenSearchIntegTestCase(org.opensearch.test.OpenSearchIntegTestCase) CLUSTER_TASKS_ALLOCATION_ENABLE_SETTING(org.opensearch.persistent.decider.EnableAssignmentDecider.CLUSTER_TASKS_ALLOCATION_ENABLE_SETTING) ClusterService(org.opensearch.cluster.service.ClusterService) TestParams(org.opensearch.persistent.TestPersistentTasksPlugin.TestParams) PersistentTasksService(org.opensearch.persistent.PersistentTasksService) CountDownLatch(java.util.concurrent.CountDownLatch) PersistentTasksCustomMetadata(org.opensearch.persistent.PersistentTasksCustomMetadata) ListTasksResponse(org.opensearch.action.admin.cluster.node.tasks.list.ListTasksResponse)

Aggregations

PersistentTasksCustomMetadata (org.opensearch.persistent.PersistentTasksCustomMetadata)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections.singletonList (java.util.Collections.singletonList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Matchers.equalTo (org.hamcrest.Matchers.equalTo)1 ActionListener (org.opensearch.action.ActionListener)1 ListTasksResponse (org.opensearch.action.admin.cluster.node.tasks.list.ListTasksResponse)1 ClusterStateResponse (org.opensearch.action.admin.cluster.state.ClusterStateResponse)1 ComponentTemplateMetadata (org.opensearch.cluster.metadata.ComponentTemplateMetadata)1 ComposableIndexTemplateMetadata (org.opensearch.cluster.metadata.ComposableIndexTemplateMetadata)1 DataStreamMetadata (org.opensearch.cluster.metadata.DataStreamMetadata)1 IndexGraveyard (org.opensearch.cluster.metadata.IndexGraveyard)1 RepositoriesMetadata (org.opensearch.cluster.metadata.RepositoriesMetadata)1 ClusterService (org.opensearch.cluster.service.ClusterService)1 Entry (org.opensearch.common.io.stream.NamedWriteableRegistry.Entry)1 Settings (org.opensearch.common.settings.Settings)1 IngestMetadata (org.opensearch.ingest.IngestMetadata)1 PersistentTasksNodeService (org.opensearch.persistent.PersistentTasksNodeService)1 PersistentTasksService (org.opensearch.persistent.PersistentTasksService)1