Search in sources :

Example 6 with JobContextService

use of io.crate.jobs.JobContextService in project crate by crate.

the class DocLevelCollectTest method collect.

private Bucket collect(RoutedCollectPhase collectNode) throws Throwable {
    ContextPreparer contextPreparer = internalCluster().getDataNodeInstance(ContextPreparer.class);
    JobContextService contextService = internalCluster().getDataNodeInstance(JobContextService.class);
    SharedShardContexts sharedShardContexts = new SharedShardContexts(internalCluster().getDataNodeInstance(IndicesService.class));
    JobExecutionContext.Builder builder = contextService.newBuilder(collectNode.jobId());
    NodeOperation nodeOperation = NodeOperation.withDownstream(collectNode, mock(ExecutionPhase.class), (byte) 0, "remoteNode");
    List<CompletableFuture<Bucket>> results = contextPreparer.prepareOnRemote(ImmutableList.of(nodeOperation), builder, sharedShardContexts);
    JobExecutionContext context = contextService.createContext(builder);
    context.start();
    return results.get(0).get(2, TimeUnit.SECONDS);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) SharedShardContexts(io.crate.action.job.SharedShardContexts) ContextPreparer(io.crate.action.job.ContextPreparer) IndicesService(org.elasticsearch.indices.IndicesService) JobExecutionContext(io.crate.jobs.JobExecutionContext) NodeOperation(io.crate.operation.NodeOperation) ExecutionPhase(io.crate.planner.node.ExecutionPhase) JobContextService(io.crate.jobs.JobContextService)

Example 7 with JobContextService

use of io.crate.jobs.JobContextService in project crate by crate.

the class NodeDisconnectJobMonitorServiceTest method testOnNodeDisconnectedKillsJobOriginatingFromThatNode.

@Test
public void testOnNodeDisconnectedKillsJobOriginatingFromThatNode() throws Exception {
    JobContextService jobContextService = jobContextService();
    JobExecutionContext.Builder builder = jobContextService.newBuilder(UUID.randomUUID());
    builder.addSubContext(new DummySubContext());
    JobExecutionContext context = jobContextService.createContext(builder);
    ThreadPool threadPool = mock(ThreadPool.class);
    when(threadPool.schedule(any(TimeValue.class), anyString(), any(Runnable.class))).thenAnswer((Answer<Object>) invocation -> {
        ((Runnable) invocation.getArguments()[2]).run();
        return null;
    });
    NodeDisconnectJobMonitorService monitorService = new NodeDisconnectJobMonitorService(Settings.EMPTY, threadPool, jobContextService, mock(TransportService.class), mock(TransportKillJobsNodeAction.class));
    monitorService.onNodeDisconnected(new DiscoveryNode("noop_id", DummyTransportAddress.INSTANCE, Version.CURRENT));
    expectedException.expect(ContextMissingException.class);
    jobContextService.getContext(context.jobId());
}
Also used : Arrays(java.util.Arrays) DummySubContext(io.crate.jobs.DummySubContext) Matchers.anyString(org.mockito.Matchers.anyString) TransportKillJobsNodeAction(io.crate.executor.transport.kill.TransportKillJobsNodeAction) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) Answer(org.mockito.stubbing.Answer) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Settings(org.elasticsearch.common.settings.Settings) TimeValue(org.elasticsearch.common.unit.TimeValue) KillJobsRequest(io.crate.executor.transport.kill.KillJobsRequest) DummyTransportAddress(org.elasticsearch.common.transport.DummyTransportAddress) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TransportService(org.elasticsearch.transport.TransportService) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) ContextMissingException(io.crate.exceptions.ContextMissingException) Test(org.junit.Test) UUID(java.util.UUID) JobsLogs(io.crate.operation.collect.stats.JobsLogs) CrateUnitTest(io.crate.test.integration.CrateUnitTest) JobExecutionContext(io.crate.jobs.JobExecutionContext) Matchers.any(org.mockito.Matchers.any) Mockito(org.mockito.Mockito) Version(org.elasticsearch.Version) JobContextService(io.crate.jobs.JobContextService) ActionListener(org.elasticsearch.action.ActionListener) TransportKillJobsNodeAction(io.crate.executor.transport.kill.TransportKillJobsNodeAction) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ThreadPool(org.elasticsearch.threadpool.ThreadPool) DummySubContext(io.crate.jobs.DummySubContext) TransportService(org.elasticsearch.transport.TransportService) JobExecutionContext(io.crate.jobs.JobExecutionContext) TimeValue(org.elasticsearch.common.unit.TimeValue) JobContextService(io.crate.jobs.JobContextService) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 8 with JobContextService

use of io.crate.jobs.JobContextService in project crate by crate.

the class SQLTransportIntegrationTest method assertNoJobExecutionContextAreLeftOpen.

@After
public void assertNoJobExecutionContextAreLeftOpen() throws Exception {
    final Field activeContexts = JobContextService.class.getDeclaredField("activeContexts");
    final Field activeOperationsSb = TransportShardAction.class.getDeclaredField("activeOperations");
    activeContexts.setAccessible(true);
    activeOperationsSb.setAccessible(true);
    try {
        assertBusy(new Runnable() {

            @Override
            public void run() {
                for (JobContextService jobContextService : internalCluster().getInstances(JobContextService.class)) {
                    try {
                        //noinspection unchecked
                        Map<UUID, JobExecutionContext> contexts = (Map<UUID, JobExecutionContext>) activeContexts.get(jobContextService);
                        assertThat(contexts.size(), is(0));
                    } catch (IllegalAccessException e) {
                        throw Throwables.propagate(e);
                    }
                }
                for (TransportShardUpsertAction action : internalCluster().getInstances(TransportShardUpsertAction.class)) {
                    try {
                        Multimap<UUID, KillableCallable> operations = (Multimap<UUID, KillableCallable>) activeOperationsSb.get(action);
                        assertThat(operations.size(), is(0));
                    } catch (IllegalAccessException e) {
                        throw Throwables.propagate(e);
                    }
                }
                for (TransportShardDeleteAction action : internalCluster().getInstances(TransportShardDeleteAction.class)) {
                    try {
                        Multimap<UUID, KillableCallable> operations = (Multimap<UUID, KillableCallable>) activeOperationsSb.get(action);
                        assertThat(operations.size(), is(0));
                    } catch (IllegalAccessException e) {
                        throw Throwables.propagate(e);
                    }
                }
            }
        }, 10L, TimeUnit.SECONDS);
    } catch (AssertionError e) {
        StringBuilder errorMessageBuilder = new StringBuilder();
        String[] nodeNames = internalCluster().getNodeNames();
        for (String nodeName : nodeNames) {
            JobContextService jobContextService = internalCluster().getInstance(JobContextService.class, nodeName);
            try {
                //noinspection unchecked
                Map<UUID, JobExecutionContext> contexts = (Map<UUID, JobExecutionContext>) activeContexts.get(jobContextService);
                String contextsString = contexts.toString();
                if (!"{}".equals(contextsString)) {
                    errorMessageBuilder.append("## node: ");
                    errorMessageBuilder.append(nodeName);
                    errorMessageBuilder.append("\n");
                    errorMessageBuilder.append(contextsString);
                    errorMessageBuilder.append("\n");
                }
                contexts.clear();
            } catch (IllegalAccessException ex) {
                throw Throwables.propagate(e);
            }
        }
        throw new AssertionError(errorMessageBuilder.toString(), e);
    }
}
Also used : TransportShardUpsertAction(io.crate.executor.transport.TransportShardUpsertAction) TransportShardDeleteAction(io.crate.executor.transport.TransportShardDeleteAction) KillableCallable(io.crate.executor.transport.kill.KillableCallable) Field(java.lang.reflect.Field) Multimap(com.google.common.collect.Multimap) JobExecutionContext(io.crate.jobs.JobExecutionContext) JobContextService(io.crate.jobs.JobContextService) After(org.junit.After)

Example 9 with JobContextService

use of io.crate.jobs.JobContextService in project crate by crate.

the class TransportKillJobsNodeActionTest method testKillIsCalledOnJobContextService.

@Test
public void testKillIsCalledOnJobContextService() throws Exception {
    TransportService transportService = mock(TransportService.class);
    JobContextService jobContextService = mock(JobContextService.class, Answers.RETURNS_MOCKS.get());
    TransportKillJobsNodeAction transportKillJobsNodeAction = new TransportKillJobsNodeAction(Settings.EMPTY, jobContextService, new NoopClusterService(), transportService);
    final CountDownLatch latch = new CountDownLatch(1);
    List<UUID> toKill = ImmutableList.of(UUID.randomUUID(), UUID.randomUUID());
    transportKillJobsNodeAction.nodeOperation(new KillJobsRequest(toKill), new ActionListener<KillResponse>() {

        @Override
        public void onResponse(KillResponse killAllResponse) {
            latch.countDown();
        }

        @Override
        public void onFailure(Throwable throwable) {
            latch.countDown();
        }
    });
    latch.await(1, TimeUnit.SECONDS);
    verify(jobContextService, times(1)).killJobs(toKill);
}
Also used : TransportService(org.elasticsearch.transport.TransportService) CountDownLatch(java.util.concurrent.CountDownLatch) UUID(java.util.UUID) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) JobContextService(io.crate.jobs.JobContextService) Test(org.junit.Test)

Aggregations

JobContextService (io.crate.jobs.JobContextService)9 Test (org.junit.Test)5 JobExecutionContext (io.crate.jobs.JobExecutionContext)4 NoopClusterService (org.elasticsearch.test.cluster.NoopClusterService)4 TransportService (org.elasticsearch.transport.TransportService)4 TransportKillJobsNodeAction (io.crate.executor.transport.kill.TransportKillJobsNodeAction)3 UUID (java.util.UUID)3 KillJobsRequest (io.crate.executor.transport.kill.KillJobsRequest)2 DummySubContext (io.crate.jobs.DummySubContext)2 Routing (io.crate.metadata.Routing)2 JobsLogs (io.crate.operation.collect.stats.JobsLogs)2 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)2 CrateUnitTest (io.crate.test.integration.CrateUnitTest)2 Field (java.lang.reflect.Field)2 Map (java.util.Map)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ActionListener (org.elasticsearch.action.ActionListener)2 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)2 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)2 ImmutableMap (com.google.common.collect.ImmutableMap)1