public InputStream getFileFromJarStorage(String fileName) throws IOException { return this.fileStorage.download(fileName); }
public String uploadFileToStorage(InputStream inputStream, String jarFileName) throws IOException { return fileStorage.upload(inputStream, jarFileName); }
public boolean deleteFileFromStorage(String jarName) throws IOException { return fileStorage.delete(jarName); }
@Test public void testJarStorage() throws IOException { FileStorage fileStorage = getFileStorage(); File file = File.createTempFile("test", ".tmp"); file.deleteOnExit(); List<String> lines = Lists.newArrayList("test-line-1", "test-line-2"); Files.write(file.toPath(), lines, Charset.forName("UTF-8")); String name = "file.name"; // delete the file if it already exists fileStorage.delete(name); fileStorage.upload(new FileInputStream(file), name); InputStream inputStream = fileStorage.download(name); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); String nextLine; List<String> actual = Lists.newArrayList(); while((nextLine = bufferedReader.readLine()) != null) { actual.add(nextLine); } Assert.assertEquals(lines, actual); } }
private FileStorage getJarStorage(FileStorageConfiguration fileStorageConfiguration) { FileStorage fileStorage = null; if (fileStorageConfiguration.getClassName() != null) try { fileStorage = (FileStorage) Class.forName(fileStorageConfiguration.getClassName(), true, Thread.currentThread().getContextClassLoader()).newInstance(); fileStorage.init(fileStorageConfiguration.getProperties()); } catch (Exception e) { throw new RuntimeException(e); } return fileStorage; }
udf.setDigest(digest); String jarPath = getExistingJarPath(digest).orElseGet(() -> uploadJar(tmpFile, udf.getName())); if (!fileStorage.exists(jarPath)) { String msg = String.format("The jar path '%s' does not exist. " + "You may have to reset the db and run bootstrap again.", jarPath);
private FileStorage getJarStorage(FileStorageConfiguration fileStorageConfiguration) { FileStorage fileStorage = null; if (fileStorageConfiguration.getClassName() != null) try { fileStorage = (FileStorage) Class.forName(fileStorageConfiguration.getClassName(), true, Thread.currentThread().getContextClassLoader()).newInstance(); fileStorage.init(fileStorageConfiguration.getProperties()); } catch (Exception e) { throw new RuntimeException(e); } return fileStorage; }
public String uploadFileToStorage(InputStream inputStream, String jarFileName) throws IOException { return fileStorage.upload(inputStream, jarFileName); }
@Override public InputStream downloadFile(String fileId) throws IOException { return fileStorage.download(fileId); }
private FileStorage getJarStorage (StreamlineConfiguration configuration, StorageManager storageManager) { FileStorage fileStorage = null; try { fileStorage = ReflectionHelper.newInstance(configuration.getFileStorageConfiguration().getClassName()); fileStorage.init(configuration.getFileStorageConfiguration().getProperties()); if (fileStorage instanceof StorageManagerAware) { ((StorageManagerAware) fileStorage).setStorageManager(storageManager); } } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) { throw new RuntimeException(e); } return fileStorage; }
public boolean deleteFileFromStorage(String jarName) throws IOException { return fileStorage.delete(jarName); }
@Override public String uploadFile(InputStream inputStream) { String fileName = UUID.randomUUID().toString(); try { String uploadedFilePath = fileStorage.upload(inputStream, fileName); } catch (IOException e) { throw new RuntimeException(e); } return fileName; }
public InputStream downloadFileFromStorage(String jarName) throws IOException { return fileStorage.download(jarName); }
private String uploadJar(File inputFile, String udfName) { String jarFileName; try (InputStream is = new FileInputStream(inputFile)) { jarFileName = String.format("streamline-functions-%s.jar", UUID.randomUUID().toString()); String uploadedPath = this.fileStorage.upload(is, jarFileName); LOG.debug("Jar uploaded to {}", uploadedPath); } catch (IOException ex) { LOG.error("Got exception when uploading jar", ex); throw new RuntimeException(ex); } return jarFileName; }
public InputStream downloadFileFromStorage(String jarName) throws IOException { return fileStorage.download(jarName); }
private String uploadJar(InputStream is, String notifierName) throws IOException { String jarFileName; if (is != null) { jarFileName = String.format("notifiers-%s.jar", UUID.randomUUID().toString()); String uploadedPath = this.fileStorage.upload(is, jarFileName); LOG.debug("Jar uploaded to {}", uploadedPath); } else { String message = String.format("Notifier %s jar content is missing.", notifierName); LOG.error(message); throw new IllegalArgumentException(message); } return jarFileName; } }
private void downloadAndCopyJars (Set<String> jarsToDownload, Path destinationPath) throws IOException { Set<String> copiedJars = new HashSet<>(); for (String jar: jarsToDownload) { if (!copiedJars.contains(jar)) { Path jarPath = Paths.get(jar); if (destinationPath == null || jarPath == null) { throw new IllegalArgumentException("null destinationPath or jarPath"); } Path jarFileName = jarPath.getFileName(); if (jarFileName == null) { throw new IllegalArgumentException("null farFileName"); } File destPath = Paths.get(destinationPath.toString(), jarFileName.toString()).toFile(); try (InputStream src = fileStorage.download(jar); FileOutputStream dest = new FileOutputStream(destPath) ) { IOUtils.copy(src, dest); copiedJars.add(jar); LOG.debug("Jar {} copied to {}", jar, destPath); } } } }