use of com.hazelcast.jet.core.JobStatus.RUNNING in project hazelcast-jet by hazelcast.
the class SinksTest method mapWithEntryProcessor_when_entryIsLocked_then_entryIsNotUpdated.
@Test
public void mapWithEntryProcessor_when_entryIsLocked_then_entryIsNotUpdated() {
// Given
srcMap.put("key", 1);
srcMap.lock("key");
// When
p.drawFrom(Sources.<String, Integer>map(srcName)).drainTo(Sinks.mapWithEntryProcessor(srcName, Entry::getKey, entry -> new IncrementEntryProcessor<>(10)));
Job job = jet().newJob(p);
// Then
assertTrueEventually(() -> assertEquals(RUNNING, job.getStatus()));
assertEquals(1, srcMap.size());
assertEquals(1, srcMap.get("key").intValue());
srcMap.unlock("key");
assertTrueEventually(() -> assertEquals(11, srcMap.get("key").intValue()), 10);
job.join();
}
use of com.hazelcast.jet.core.JobStatus.RUNNING in project hazelcast-jet by hazelcast.
the class MasterContext method invokeCompleteExecution.
private void invokeCompleteExecution(Throwable error) {
JobStatus status = jobStatus();
Throwable finalError;
if (status == STARTING || status == RESTARTING || status == RUNNING) {
logger.fine("Completing " + jobIdString());
finalError = error;
} else {
if (error != null) {
logger.severe("Cannot properly complete failed " + jobIdString() + ": status is " + status, error);
} else {
logger.severe("Cannot properly complete " + jobIdString() + ": status is " + status);
}
finalError = new IllegalStateException("Job coordination failed.");
}
Function<ExecutionPlan, Operation> operationCtor = plan -> new CompleteExecutionOperation(executionId, finalError);
invoke(operationCtor, responses -> finalizeJob(error), null);
}
use of com.hazelcast.jet.core.JobStatus.RUNNING in project hazelcast-jet by hazelcast.
the class MasterContext method invokeStartExecution.
// If a participant leaves or the execution fails in a participant locally, executions are cancelled
// on the remaining participants and the callback is completed after all invocations return.
private void invokeStartExecution() {
logger.fine("Executing " + jobIdString());
long executionId = this.executionId;
ExecutionInvocationCallback callback = new ExecutionInvocationCallback(executionId);
cancellationToken.whenCompleted(callback::cancelInvocations);
CompletionToken executionRestartToken = new CompletionToken(logger);
executionRestartToken.whenCompleted(callback::cancelInvocations);
Function<ExecutionPlan, Operation> operationCtor = plan -> new StartExecutionOperation(jobId, executionId);
Consumer<Map<MemberInfo, Object>> completionCallback = results -> {
this.executionRestartToken = null;
onExecuteStepCompleted(results, executionRestartToken.isCompleted());
};
// We must set executionRestartToken before we call invoke() method because once all invocations
// are done, executionRestartToken will be reset. Therefore, setting it after the invoke() call is racy.
this.executionRestartToken = executionRestartToken;
jobStatus.set(RUNNING);
invoke(operationCtor, completionCallback, callback);
if (isSnapshottingEnabled()) {
coordinationService.scheduleSnapshot(jobId, executionId);
}
}
use of com.hazelcast.jet.core.JobStatus.RUNNING in project hazelcast by hazelcast.
the class MasterSnapshotContext method tryBeginSnapshot.
void tryBeginSnapshot() {
mc.coordinationService().submitToCoordinatorThread(() -> {
boolean isTerminal;
String snapshotMapName;
CompletableFuture<Void> future;
mc.lock();
long localExecutionId;
try {
if (mc.jobStatus() != RUNNING) {
logger.fine("Not beginning snapshot, " + mc.jobIdString() + " is not RUNNING, but " + mc.jobStatus());
return;
}
if (snapshotInProgress) {
logger.fine("Not beginning snapshot since one is already in progress " + mc.jobIdString());
return;
}
if (terminalSnapshotFuture.isDone()) {
logger.fine("Not beginning snapshot since terminal snapshot is already completed " + mc.jobIdString());
return;
}
Tuple3<String, Boolean, CompletableFuture<Void>> requestedSnapshot = snapshotQueue.poll();
if (requestedSnapshot == null) {
return;
}
snapshotInProgress = true;
snapshotMapName = requestedSnapshot.f0();
assert requestedSnapshot.f1() != null;
isTerminal = requestedSnapshot.f1();
future = requestedSnapshot.f2();
mc.jobExecutionRecord().startNewSnapshot(snapshotMapName);
localExecutionId = mc.executionId();
} finally {
mc.unlock();
}
mc.writeJobExecutionRecord(false);
long newSnapshotId = mc.jobExecutionRecord().ongoingSnapshotId();
boolean isExport = snapshotMapName != null;
int snapshotFlags = SnapshotFlags.create(isTerminal, isExport);
String finalMapName = isExport ? exportedSnapshotMapName(snapshotMapName) : snapshotDataMapName(mc.jobId(), mc.jobExecutionRecord().ongoingDataMapIndex());
mc.nodeEngine().getHazelcastInstance().getMap(finalMapName).clear();
logFine(logger, "Starting snapshot %d for %s, flags: %s, writing to: %s", newSnapshotId, jobNameAndExecutionId(mc.jobName(), localExecutionId), SnapshotFlags.toString(snapshotFlags), snapshotMapName);
Function<ExecutionPlan, Operation> factory = plan -> new SnapshotPhase1Operation(mc.jobId(), localExecutionId, newSnapshotId, finalMapName, snapshotFlags);
// Need to take a copy of executionId: we don't cancel the scheduled task when the execution
// finalizes. If a new execution is started in the meantime, we'll use the execution ID to detect it.
mc.invokeOnParticipants(factory, responses -> onSnapshotPhase1Complete(responses, localExecutionId, newSnapshotId, finalMapName, snapshotFlags, future), null, true);
});
}
use of com.hazelcast.jet.core.JobStatus.RUNNING in project hazelcast by hazelcast.
the class SqlMetadataInJobConfigTest method test_selectMetadata_clientJobSummary.
@Test
public void test_selectMetadata_clientJobSummary() {
String sql = "SELECT * FROM table(generate_stream(1))";
try (SqlResult ignored = client().getSql().execute(new SqlStatement(sql).setCursorBufferSize(1))) {
List<JobSummary> jobSummaries = ((JetClientInstanceImpl) client().getJet()).getJobSummaryList().stream().filter(jobSummary -> jobSummary.getStatus() == RUNNING).collect(Collectors.toList());
assertEquals(1, jobSummaries.size());
JobSummary jobSummary = jobSummaries.get(0);
// TODO uncomment this when doing https://github.com/hazelcast/hazelcast/issues/20372
// assertNotNull(jobSummary.getSqlSummary());
// assertEquals(sql, jobSummary.getSqlSummary().getQuery());
// assertEquals(Boolean.TRUE, jobSummary.getSqlSummary().isUnbounded());
}
}
Aggregations