Search in sources :

Example 1 with JetException

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);
    }
}
Also used : Path(java.nio.file.Path) WatchKey(java.nio.file.WatchKey) ILogger(com.hazelcast.logging.ILogger) WatchEvent(java.nio.file.WatchEvent) JetException(com.hazelcast.jet.JetException)

Example 2 with JetException

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);
}
Also used : BroadcastKey(com.hazelcast.jet.core.BroadcastKey) JetException(com.hazelcast.jet.JetException)

Example 3 with JetException

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;
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BufferedInputStream(java.io.BufferedInputStream) JarInputStream(java.util.jar.JarInputStream) InputStream(java.io.InputStream) Util.idToString(com.hazelcast.jet.impl.util.Util.idToString) ResourceConfig(com.hazelcast.jet.config.ResourceConfig) IOException(java.io.IOException) JetException(com.hazelcast.jet.JetException)

Example 4 with JetException

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;
    }
}
Also used : JobStatus(com.hazelcast.jet.core.JobStatus) JobNotFoundException(com.hazelcast.jet.core.JobNotFoundException) JetException(com.hazelcast.jet.JetException)

Example 5 with JetException

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);
    }
}
Also used : JetException(com.hazelcast.jet.JetException) File(java.io.File)

Aggregations

JetException (com.hazelcast.jet.JetException)52 IOException (java.io.IOException)8 Nonnull (javax.annotation.Nonnull)8 ILogger (com.hazelcast.logging.ILogger)7 List (java.util.List)7 Map (java.util.Map)6 Util.idToString (com.hazelcast.jet.Util.idToString)5 JobConfig (com.hazelcast.jet.config.JobConfig)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 BroadcastKey (com.hazelcast.jet.core.BroadcastKey)4 JobStatus (com.hazelcast.jet.core.JobStatus)4 Path (java.nio.file.Path)4 HashMap (java.util.HashMap)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 FunctionEx (com.hazelcast.function.FunctionEx)3 Job (com.hazelcast.jet.Job)3 DAG (com.hazelcast.jet.core.DAG)3 Watermark (com.hazelcast.jet.core.Watermark)3 Tuple2 (com.hazelcast.jet.datamodel.Tuple2)3 Pipeline (com.hazelcast.jet.pipeline.Pipeline)3