Search in sources :

Example 21 with JetException

use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.

the class HadoopFileSourceFactory method configureFn.

private static <T> ConsumerEx<Configuration> configureFn(FileSourceConfiguration<T> fsc, JobConfigurer configurer, FileFormat<T> fileFormat) {
    return new ConsumerEx<Configuration>() {

        @Override
        public void acceptEx(Configuration configuration) throws Exception {
            try {
                configuration.setBoolean(FileInputFormat.INPUT_DIR_NONRECURSIVE_IGNORE_SUBDIRS, true);
                configuration.setBoolean(FileInputFormat.INPUT_DIR_RECURSIVE, false);
                configuration.setBoolean(HadoopSources.SHARED_LOCAL_FS, fsc.isSharedFileSystem());
                configuration.setBoolean(HadoopSources.IGNORE_FILE_NOT_FOUND, fsc.isIgnoreFileNotFound());
                for (Entry<String, String> option : fsc.getOptions().entrySet()) {
                    configuration.set(option.getKey(), option.getValue());
                }
                // Some methods we use to configure actually take a Job
                Job job = Job.getInstance(configuration);
                Path inputPath = getInputPath(fsc, configuration);
                FileInputFormat.addInputPath(job, inputPath);
                configurer.configure(job, fileFormat);
                // original configuration instance
                for (Entry<String, String> entry : job.getConfiguration()) {
                    configuration.set(entry.getKey(), entry.getValue());
                }
            } catch (IOException e) {
                throw new JetException("Could not create a source", e);
            }
        }

        @Override
        public List<Permission> permissions() {
            String keyFile = fsc.getOptions().get("google.cloud.auth.service.account.json.keyfile");
            if (keyFile != null) {
                return asList(ConnectorPermission.file(keyFile, ACTION_READ), ConnectorPermission.file(fsc.getPath(), ACTION_READ));
            }
            return singletonList(ConnectorPermission.file(fsc.getPath(), ACTION_READ));
        }
    };
}
Also used : ConsumerEx(com.hazelcast.function.ConsumerEx) Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) FileSourceConfiguration(com.hazelcast.jet.pipeline.file.impl.FileSourceConfiguration) ConnectorPermission(com.hazelcast.security.permission.ConnectorPermission) Permission(java.security.Permission) IOException(java.io.IOException) JetException(com.hazelcast.jet.JetException) Job(org.apache.hadoop.mapreduce.Job) AvroJob(org.apache.avro.mapreduce.AvroJob)

Example 22 with JetException

use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.

the class HazelcastCommandLine method deleteSnapshot.

@Command(name = "delete-snapshot", description = "Deletes a named snapshot")
public void deleteSnapshot(@Mixin(name = "verbosity") Verbosity verbosity, @Mixin(name = "targets") TargetsMixin targets, @Parameters(index = "0", paramLabel = "<snapshot name>", description = "Name of the snapshot") String snapshotName) {
    runWithHazelcast(targets, verbosity, false, hz -> {
        JobStateSnapshot jobStateSnapshot = hz.getJet().getJobStateSnapshot(snapshotName);
        if (jobStateSnapshot == null) {
            throw new JetException(String.format("Didn't find a snapshot named '%s'", snapshotName));
        }
        jobStateSnapshot.destroy();
        printf("Deleted snapshot '%s'.", snapshotName);
    });
}
Also used : JobStateSnapshot(com.hazelcast.jet.JobStateSnapshot) JetException(com.hazelcast.jet.JetException) HelpCommand(picocli.CommandLine.HelpCommand) Command(picocli.CommandLine.Command)

Example 23 with JetException

use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.

the class CsvReadFileFnProvider method createReadFileFn.

@SuppressWarnings("unchecked")
@Nonnull
@Override
public <T> FunctionEx<Path, Stream<T>> createReadFileFn(@Nonnull FileFormat<T> format) {
    CsvFileFormat<T> csvFileFormat = (CsvFileFormat<T>) format;
    // Format is not Serializable
    Class<?> formatClazz = csvFileFormat.clazz();
    return path -> {
        FileInputStream fis = new FileInputStream(path.toFile());
        MappingIterator<T> iterator;
        Function<T, T> projection = identity();
        if (formatClazz == String[].class) {
            ObjectReader reader = new CsvMapper().enable(Feature.WRAP_AS_ARRAY).readerFor(String[].class).with(CsvSchema.emptySchema().withSkipFirstDataRow(false));
            iterator = reader.readValues(fis);
            if (!iterator.hasNext()) {
                throw new JetException("Header row missing in " + path);
            }
            String[] header = (String[]) iterator.next();
            List<String> fieldNames = csvFileFormat.fieldNames();
            if (fieldNames != null) {
                projection = (Function<T, T>) createFieldProjection(header, fieldNames);
            }
        } else {
            iterator = new CsvMapper().readerFor(formatClazz).withoutFeatures(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).with(CsvSchema.emptySchema().withHeader()).readValues(fis);
        }
        return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, ORDERED), false).map(projection).onClose(() -> uncheckRun(fis::close));
    };
}
Also used : FunctionEx(com.hazelcast.function.FunctionEx) Util.uncheckRun(com.hazelcast.jet.impl.util.Util.uncheckRun) Spliterators(java.util.Spliterators) MappingIterator(com.fasterxml.jackson.databind.MappingIterator) CsvMapper(com.fasterxml.jackson.dataformat.csv.CsvMapper) CsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema) ORDERED(java.util.Spliterator.ORDERED) FileInputStream(java.io.FileInputStream) Function(java.util.function.Function) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) JetException(com.hazelcast.jet.JetException) CsvFileFormat(com.hazelcast.jet.pipeline.file.CsvFileFormat) Feature(com.fasterxml.jackson.dataformat.csv.CsvParser.Feature) FileFormat(com.hazelcast.jet.pipeline.file.FileFormat) List(java.util.List) Stream(java.util.stream.Stream) Util.createFieldProjection(com.hazelcast.jet.impl.util.Util.createFieldProjection) ReadFileFnProvider(com.hazelcast.jet.pipeline.file.impl.ReadFileFnProvider) Function.identity(java.util.function.Function.identity) StreamSupport(java.util.stream.StreamSupport) Nonnull(javax.annotation.Nonnull) Path(java.nio.file.Path) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) CsvMapper(com.fasterxml.jackson.dataformat.csv.CsvMapper) JetException(com.hazelcast.jet.JetException) FileInputStream(java.io.FileInputStream) Function(java.util.function.Function) MappingIterator(com.fasterxml.jackson.databind.MappingIterator) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) List(java.util.List) CsvFileFormat(com.hazelcast.jet.pipeline.file.CsvFileFormat) Nonnull(javax.annotation.Nonnull)

Example 24 with JetException

use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.

the class CdcSourceP method reconnect.

private void reconnect(RuntimeException re) {
    if (reconnectTracker.shouldTryAgain()) {
        logger.warning("Connection to database lost, will attempt to reconnect and retry operations from " + "scratch" + getCause(re), re);
        killConnection();
        reconnectTracker.reset();
        if (clearStateOnReconnect) {
            state = new State();
        }
    } else {
        throw shutDownAndThrow(new JetException("Failed to connect to database" + getCause(re)));
    }
}
Also used : JetException(com.hazelcast.jet.JetException)

Example 25 with JetException

use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.

the class PythonServiceContext method performCleanup.

private void performCleanup() {
    try {
        List<String> filesNotMarked = editPermissionsRecursively(runtimeBaseDir, perms -> perms.add(OWNER_WRITE));
        if (!filesNotMarked.isEmpty()) {
            logger.info("Couldn't 'chmod u+w' these files: " + filesNotMarked);
        }
        Path cleanupScriptPath = runtimeBaseDir.resolve(USER_CLEANUP_SHELL_SCRIPT);
        if (Files.exists(cleanupScriptPath)) {
            Process cleanupProcess = new ProcessBuilder("/bin/sh", "-c", "./" + CLEANUP_SHELL_SCRIPT).directory(runtimeBaseDir.toFile()).redirectErrorStream(true).start();
            logStdOut(logger, cleanupProcess, "python-cleanup-" + cleanupProcess);
            cleanupProcess.waitFor();
            if (cleanupProcess.exitValue() != 0) {
                logger.warning("Cleanup script finished with non-zero exit code: " + cleanupProcess.exitValue());
            }
        }
    } catch (Exception e) {
        throw new JetException("PythonService cleanup failed: " + e, e);
    }
}
Also used : Path(java.nio.file.Path) JetException(com.hazelcast.jet.JetException) JetException(com.hazelcast.jet.JetException) IOException(java.io.IOException)

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