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));
}
};
}
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);
});
}
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));
};
}
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)));
}
}
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);
}
}
Aggregations