Search in sources :

Example 21 with JetServiceBackend

use of com.hazelcast.jet.impl.JetServiceBackend in project hazelcast by hazelcast.

the class ExecutionContext method initialize.

public ExecutionContext initialize(@Nonnull Address coordinator, @Nonnull Set<Address> participants, @Nonnull ExecutionPlan plan) {
    this.coordinator = coordinator;
    this.participants = participants;
    jobConfig = plan.getJobConfig();
    jobName = jobConfig.getName() == null ? jobName : jobConfig.getName();
    // Must be populated early, so all processor suppliers are
    // available to be completed in the case of init failure
    vertices = plan.getVertices();
    snapshotContext = new SnapshotContext(nodeEngine.getLogger(SnapshotContext.class), jobNameAndExecutionId(), plan.lastSnapshotId(), jobConfig.getProcessingGuarantee());
    JetServiceBackend jetServiceBackend = nodeEngine.getService(JetServiceBackend.SERVICE_NAME);
    serializationService = jetServiceBackend.createSerializationService(jobConfig.getSerializerConfigs());
    metricsEnabled = jobConfig.isMetricsEnabled() && nodeEngine.getConfig().getMetricsConfig().isEnabled();
    plan.initialize(nodeEngine, jobId, executionId, snapshotContext, tempDirectories, serializationService);
    int numPrioritySsTasklets = plan.getStoreSnapshotTaskletCount() != 0 ? plan.getHigherPriorityVertexCount() : 0;
    snapshotContext.initTaskletCount(plan.getProcessorTaskletCount(), plan.getStoreSnapshotTaskletCount(), numPrioritySsTasklets);
    Map<SenderReceiverKey, ReceiverTasklet> receiverMapTmp = new HashMap<>();
    for (Entry<Integer, Map<Integer, Map<Address, ReceiverTasklet>>> vertexIdEntry : plan.getReceiverMap().entrySet()) {
        for (Entry<Integer, Map<Address, ReceiverTasklet>> ordinalEntry : vertexIdEntry.getValue().entrySet()) {
            for (Entry<Address, ReceiverTasklet> addressEntry : ordinalEntry.getValue().entrySet()) {
                SenderReceiverKey key = new SenderReceiverKey(vertexIdEntry.getKey(), ordinalEntry.getKey(), addressEntry.getKey());
                // the queue might already exist, if some data were received for it, or it will be created now
                Queue<byte[]> queue = receiverQueuesMap.computeIfAbsent(key, CREATE_RECEIVER_QUEUE_FN);
                ReceiverTasklet receiverTasklet = addressEntry.getValue();
                receiverTasklet.initIncomingQueue(queue);
                receiverMapTmp.put(new SenderReceiverKey(vertexIdEntry.getKey(), ordinalEntry.getKey(), addressEntry.getKey()), receiverTasklet);
            }
        }
    }
    this.receiverMap = unmodifiableMap(receiverMapTmp);
    Map<SenderReceiverKey, SenderTasklet> senderMapTmp = new HashMap<>();
    for (Entry<Integer, Map<Integer, Map<Address, SenderTasklet>>> e1 : plan.getSenderMap().entrySet()) {
        for (Entry<Integer, Map<Address, SenderTasklet>> e2 : e1.getValue().entrySet()) {
            for (Entry<Address, SenderTasklet> e3 : e2.getValue().entrySet()) {
                senderMapTmp.put(new SenderReceiverKey(e1.getKey(), e2.getKey(), e3.getKey()), e3.getValue());
            }
        }
    }
    this.senderMap = unmodifiableMap(senderMapTmp);
    tasklets = plan.getTasklets();
    return this;
}
Also used : Address(com.hazelcast.cluster.Address) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Collections.unmodifiableMap(java.util.Collections.unmodifiableMap) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend)

Example 22 with JetServiceBackend

use of com.hazelcast.jet.impl.JetServiceBackend in project hazelcast by hazelcast.

the class GetJobConfigOperation method run.

@Override
public void run() {
    JetServiceBackend service = getJetServiceBackend();
    response = service.getJobConfig(jobId(), isLightJob);
}
Also used : JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend)

Example 23 with JetServiceBackend

use of com.hazelcast.jet.impl.JetServiceBackend in project hazelcast by hazelcast.

the class InitExecutionOperation method doRun.

@Override
protected CompletableFuture<?> doRun() {
    ILogger logger = getLogger();
    if (!getNodeEngine().getLocalMember().getVersion().asVersion().equals(coordinatorVersion)) {
        // the same address.
        throw new JetException("Mismatch between coordinator and participant version");
    }
    JetServiceBackend service = getJetServiceBackend();
    Address caller = getCallerAddress();
    LoggingUtil.logFine(logger, "Initializing execution plan for %s from %s", jobIdAndExecutionId(jobId(), executionId), caller);
    ExecutionPlan plan = deserializePlan(serializedPlan);
    if (isLightJob) {
        return service.getJobExecutionService().runLightJob(jobId(), executionId, caller, coordinatorMemberListVersion, participants, plan);
    } else {
        service.getJobExecutionService().initExecution(jobId(), executionId, caller, coordinatorMemberListVersion, participants, plan);
        return CompletableFuture.completedFuture(null);
    }
}
Also used : ExecutionPlan(com.hazelcast.jet.impl.execution.init.ExecutionPlan) Address(com.hazelcast.cluster.Address) ILogger(com.hazelcast.logging.ILogger) JetException(com.hazelcast.jet.JetException) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend)

Example 24 with JetServiceBackend

use of com.hazelcast.jet.impl.JetServiceBackend in project hazelcast by hazelcast.

the class InitExecutionOperation method deserializePlan.

private ExecutionPlan deserializePlan(Data planBlob) {
    if (isLightJob) {
        return getNodeEngine().getSerializationService().toObject(planBlob);
    } else {
        JetServiceBackend service = getJetServiceBackend();
        JobConfig jobConfig = service.getJobConfig(jobId(), isLightJob);
        JobClassLoaderService jobClassloaderService = service.getJobClassLoaderService();
        ClassLoader cl = jobClassloaderService.getOrCreateClassLoader(jobConfig, jobId(), EXECUTION);
        try {
            jobClassloaderService.prepareProcessorClassLoaders(jobId());
            return deserializeWithCustomClassLoader(getNodeEngine().getSerializationService(), cl, planBlob);
        } finally {
            jobClassloaderService.clearProcessorClassLoaders();
        }
    }
}
Also used : JobClassLoaderService(com.hazelcast.jet.impl.JobClassLoaderService) CustomClassLoadedObject.deserializeWithCustomClassLoader(com.hazelcast.jet.impl.execution.init.CustomClassLoadedObject.deserializeWithCustomClassLoader) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend) JobConfig(com.hazelcast.jet.config.JobConfig)

Example 25 with JetServiceBackend

use of com.hazelcast.jet.impl.JetServiceBackend in project hazelcast by hazelcast.

the class TopologyChangeTest method when_jobParticipantReceivesStaleInitOperation_then_jobRestarts.

@Test
public void when_jobParticipantReceivesStaleInitOperation_then_jobRestarts() {
    // Given
    HazelcastInstance newInstance = createHazelcastInstance(config);
    for (HazelcastInstance instance : instances) {
        assertClusterSizeEventually(NODE_COUNT + 1, instance);
    }
    rejectOperationsBetween(instances[0], instances[2], JetInitDataSerializerHook.FACTORY_ID, singletonList(INIT_EXECUTION_OP));
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(TestProcessors.Identity::new, nodeCount + 1)));
    Job job = instances[0].getJet().newJob(dag);
    JetServiceBackend jetServiceBackend = getJetServiceBackend(instances[0]);
    assertTrueEventually(() -> assertFalse(jetServiceBackend.getJobCoordinationService().getMasterContexts().isEmpty()));
    MasterContext masterContext = jetServiceBackend.getJobCoordinationService().getMasterContext(job.getId());
    assertTrueEventually(() -> {
        assertEquals(STARTING, masterContext.jobStatus());
        assertNotEquals(0, masterContext.executionId());
    });
    // When
    long executionId = masterContext.executionId();
    assertTrueEventually(() -> {
        Arrays.stream(instances).filter(instance -> !instance.getCluster().getLocalMember().isLiteMember()).filter(instance -> instance != instances[2]).map(JetTestSupport::getJetServiceBackend).map(service -> service.getJobExecutionService().getExecutionContext(executionId)).forEach(Assert::assertNotNull);
    });
    newInstance.getLifecycleService().terminate();
    for (HazelcastInstance instance : instances) {
        assertClusterSizeEventually(NODE_COUNT, instance);
    }
    resetPacketFiltersFrom(instances[0]);
    // Then
    job.join();
    assertNotEquals(executionId, masterContext.executionId());
}
Also used : HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Arrays(java.util.Arrays) INIT_EXECUTION_OP(com.hazelcast.jet.impl.execution.init.JetInitDataSerializerHook.INIT_EXECUTION_OP) Collections.singletonList(java.util.Collections.singletonList) Assert.assertThat(org.junit.Assert.assertThat) PacketFiltersUtil.dropOperationsBetween(com.hazelcast.test.PacketFiltersUtil.dropOperationsBetween) PacketFiltersUtil.rejectOperationsBetween(com.hazelcast.test.PacketFiltersUtil.rejectOperationsBetween) Future(java.util.concurrent.Future) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) STARTING(com.hazelcast.jet.core.JobStatus.STARTING) SUSPENDED(com.hazelcast.jet.core.JobStatus.SUSPENDED) Assert.fail(org.junit.Assert.fail) ClusterDataSerializerHook(com.hazelcast.internal.cluster.impl.ClusterDataSerializerHook) Parameterized(org.junit.runners.Parameterized) MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) HazelcastParametrizedRunner(com.hazelcast.test.HazelcastParametrizedRunner) CancellationException(java.util.concurrent.CancellationException) MEMBER_INFO_UPDATE(com.hazelcast.internal.cluster.impl.ClusterDataSerializerHook.MEMBER_INFO_UPDATE) Collection(java.util.Collection) START_EXECUTION_OP(com.hazelcast.jet.impl.execution.init.JetInitDataSerializerHook.START_EXECUTION_OP) JobConfig(com.hazelcast.jet.config.JobConfig) Set(java.util.Set) PartitionDataSerializerHook(com.hazelcast.internal.partition.impl.PartitionDataSerializerHook) JobResult(com.hazelcast.jet.impl.JobResult) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) Category(org.junit.experimental.categories.Category) NoOutputSourceP(com.hazelcast.jet.core.TestProcessors.NoOutputSourceP) Assert.assertFalse(org.junit.Assert.assertFalse) MasterContext(com.hazelcast.jet.impl.MasterContext) RunWith(org.junit.runner.RunWith) HazelcastSerialParametersRunnerFactory(com.hazelcast.test.HazelcastSerialParametersRunnerFactory) JetInitDataSerializerHook(com.hazelcast.jet.impl.execution.init.JetInitDataSerializerHook) Accessors(com.hazelcast.test.Accessors) HashSet(java.util.HashSet) InitExecutionOperation(com.hazelcast.jet.impl.operation.InitExecutionOperation) Version(com.hazelcast.version.Version) ExpectedException(org.junit.rules.ExpectedException) Job(com.hazelcast.jet.Job) Before(org.junit.Before) UseParametersRunnerFactory(org.junit.runners.Parameterized.UseParametersRunnerFactory) JobRepository(com.hazelcast.jet.impl.JobRepository) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Matchers.empty(org.hamcrest.Matchers.empty) Assert.assertNotNull(org.junit.Assert.assertNotNull) EXACTLY_ONCE(com.hazelcast.jet.config.ProcessingGuarantee.EXACTLY_ONCE) MemberLeftException(com.hazelcast.core.MemberLeftException) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest) NONE(com.hazelcast.jet.config.ProcessingGuarantee.NONE) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) ExecutionException(java.util.concurrent.ExecutionException) Rule(org.junit.Rule) FAILED(com.hazelcast.jet.core.JobStatus.FAILED) JOB_RECORDS_MAP_NAME(com.hazelcast.jet.impl.JobRepository.JOB_RECORDS_MAP_NAME) RUNNING(com.hazelcast.jet.core.JobStatus.RUNNING) Assert(org.junit.Assert) PacketFiltersUtil.resetPacketFiltersFrom(com.hazelcast.test.PacketFiltersUtil.resetPacketFiltersFrom) Collections(java.util.Collections) JobRecord(com.hazelcast.jet.impl.JobRecord) Assert.assertEquals(org.junit.Assert.assertEquals) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend) SHUTDOWN_REQUEST(com.hazelcast.internal.partition.impl.PartitionDataSerializerHook.SHUTDOWN_REQUEST) MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Assert(org.junit.Assert) Job(com.hazelcast.jet.Job) MasterContext(com.hazelcast.jet.impl.MasterContext) JetServiceBackend(com.hazelcast.jet.impl.JetServiceBackend) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Aggregations

JetServiceBackend (com.hazelcast.jet.impl.JetServiceBackend)32 JobConfig (com.hazelcast.jet.config.JobConfig)14 Test (org.junit.Test)14 Job (com.hazelcast.jet.Job)13 HazelcastInstance (com.hazelcast.core.HazelcastInstance)11 MockPS (com.hazelcast.jet.core.TestProcessors.MockPS)9 NoOutputSourceP (com.hazelcast.jet.core.TestProcessors.NoOutputSourceP)9 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)9 JobRepository (com.hazelcast.jet.impl.JobRepository)8 Map (java.util.Map)8 Assert.assertEquals (org.junit.Assert.assertEquals)8 Config (com.hazelcast.config.Config)7 Category (org.junit.experimental.categories.Category)7 RunWith (org.junit.runner.RunWith)7 Address (com.hazelcast.cluster.Address)6 RUNNING (com.hazelcast.jet.core.JobStatus.RUNNING)6 HazelcastSerialClassRunner (com.hazelcast.test.HazelcastSerialClassRunner)6 CancellationException (java.util.concurrent.CancellationException)6 Collectors (java.util.stream.Collectors)6 Assert.assertTrue (org.junit.Assert.assertTrue)6