use of com.hazelcast.jet.JetException in project hazelcast-jet by hazelcast.
the class StreamFilesP method drainWatcherEvents.
private void drainWatcherEvents() throws InterruptedException {
final ILogger logger = getLogger();
// poll with blocking only when there is no other work to do
final WatchKey key = (currentFile == null && eventQueue.isEmpty()) ? watcher.poll(1, SECONDS) : watcher.poll();
if (key == null) {
if (!Files.exists(watchedDirectory)) {
logger.info("Directory " + watchedDirectory + " does not exist, stopped watching");
close(null);
}
return;
}
for (WatchEvent<?> event : key.pollEvents()) {
final WatchEvent.Kind<?> kind = event.kind();
final Path fileName = ((WatchEvent<Path>) event).context();
final Path filePath = watchedDirectory.resolve(fileName);
if (kind == ENTRY_CREATE || kind == ENTRY_MODIFY) {
if (glob.matches(fileName) && belongsToThisProcessor(fileName) && !Files.isDirectory(filePath)) {
logFine(logger, "Will open file to read new content: %s", filePath);
eventQueue.add(filePath);
}
} else if (kind == ENTRY_DELETE) {
logFinest(logger, "File was deleted: %s", filePath);
fileOffsets.remove(filePath);
} else if (kind == OVERFLOW) {
logger.warning("Detected OVERFLOW in " + watchedDirectory);
} else {
throw new JetException("Unknown kind of WatchEvent: " + kind);
}
}
if (!key.reset()) {
logger.info("Watch key is invalid. Stopping watcher.");
close(null);
}
}
use of com.hazelcast.jet.JetException in project hazelcast-jet by hazelcast.
the class SlidingWindowP method restoreFromSnapshot.
@Override
@SuppressWarnings("unchecked")
protected void restoreFromSnapshot(@Nonnull Object key, @Nonnull Object value) {
if (key instanceof BroadcastKey) {
BroadcastKey bcastKey = (BroadcastKey) key;
if (!Keys.NEXT_WIN_TO_EMIT.equals(bcastKey.key())) {
throw new JetException("Unexpected broadcast key: " + bcastKey.key());
}
long newNextWinToEmit = (long) value;
assert processingGuarantee != EXACTLY_ONCE || minRestoredNextWinToEmit == Long.MAX_VALUE || minRestoredNextWinToEmit == newNextWinToEmit : "different values for nextWinToEmit restored, before=" + minRestoredNextWinToEmit + ", new=" + newNextWinToEmit;
minRestoredNextWinToEmit = Math.min(newNextWinToEmit, minRestoredNextWinToEmit);
return;
}
SnapshotKey k = (SnapshotKey) key;
if (tsToKeyToAcc.computeIfAbsent(k.timestamp, x -> new HashMap<>()).put((K) k.key, (A) value) != null) {
throw new JetException("Duplicate key in snapshot: " + k);
}
topTs = max(topTs, k.timestamp);
}
use of com.hazelcast.jet.JetException in project hazelcast-jet by hazelcast.
the class JobRepository method uploadJobResources.
/**
* Uploads job resources and returns a unique job id generated for the job.
* If the upload process fails for any reason, such as being unable to access a resource,
* uploaded resources are cleaned up.
*/
public long uploadJobResources(JobConfig jobConfig) {
long jobId = newJobId();
IMap<String, Object> jobResourcesMap = getJobResources(jobId);
for (ResourceConfig rc : jobConfig.getResourceConfigs()) {
Map<String, byte[]> tmpMap = new HashMap<>();
if (rc.isArchive()) {
try {
loadJar(tmpMap, rc.getUrl());
} catch (IOException e) {
cleanupJobResourcesAndSnapshots(jobId, jobResourcesMap);
randomIds.remove(jobId);
throw new JetException("Job resource upload failed", e);
}
} else {
try {
InputStream in = rc.getUrl().openStream();
readStreamAndPutCompressedToMap(rc.getId(), tmpMap, in);
} catch (IOException e) {
cleanupJobResourcesAndSnapshots(jobId, jobResourcesMap);
randomIds.remove(jobId);
throw new JetException("Job resource upload failed", e);
}
}
// now upload it all
jobResourcesMap.putAll(tmpMap);
}
// the marker object will be used to decide when to clean up job resources
jobResourcesMap.put(RESOURCE_MARKER, System.currentTimeMillis());
return jobId;
}
use of com.hazelcast.jet.JetException in project hazelcast-jet by hazelcast.
the class JobCoordinationService method getJobStatus.
/**
* Returns the job status or fails with {@link JobNotFoundException}
* if the requested job is not found
*/
public JobStatus getJobStatus(long jobId) {
if (!isMaster()) {
throw new JetException("Cannot query status of Job " + idToString(jobId) + ". Master address: " + nodeEngine.getClusterService().getMasterAddress());
}
// first check if there is a job result present.
// this map is updated first during completion.
JobResult jobResult = jobRepository.getJobResult(jobId);
if (jobResult != null) {
return jobResult.getJobStatus();
}
// check if there a master context for running job
MasterContext currentMasterContext = masterContexts.get(jobId);
if (currentMasterContext != null) {
JobStatus jobStatus = currentMasterContext.jobStatus();
if (jobStatus == JobStatus.RUNNING) {
return currentMasterContext.isCancelled() ? JobStatus.COMPLETING : JobStatus.RUNNING;
}
return jobStatus;
}
// no master context found, job might be just submitted
JobRecord jobRecord = jobRepository.getJobRecord(jobId);
if (jobRecord == null) {
// no job record found, but check job results again
// since job might have been completed meanwhile.
jobResult = jobRepository.getJobResult(jobId);
if (jobResult != null) {
return jobResult.getJobStatus();
}
throw new JobNotFoundException(jobId);
} else {
return NOT_STARTED;
}
}
use of com.hazelcast.jet.JetException in project hazelcast-jet-reference-manual by hazelcast.
the class WriteFilePSupplier method init.
@Override
public void init(@Nonnull Context context) {
File homeDir = new File(path);
boolean success = homeDir.isDirectory() || homeDir.mkdirs();
if (!success) {
throw new JetException("Failed to create " + homeDir);
}
}
Aggregations