/** * Move the files * * @param fileLocation * @param filename * @param filebeforepprocess * @return */ private boolean moveFile( String fileLocation, String filename, String filebeforepprocess, String fileafterprocess, String newFileLocation) throws FileSystemException { boolean resultStatus = false; FileSystemOptions opts = FTPSiteUtils.createDefaultOptions(); FileSystemManager manager = VFS.getManager(); // Create remote object FileObject remoteFile = manager.resolveFile(fileLocation + filename, opts); FileObject newFile = manager.resolveFile(newFileLocation + filename, opts); if (!filebeforepprocess.equals("")) { FileObject fBeforeProcess = manager.resolveFile(filebeforepprocess + filename, opts); fBeforeProcess.copyFrom(remoteFile, Selectors.SELECT_SELF); } if (remoteFile.exists()) { remoteFile.moveTo(newFile); resultStatus = true; if (log.isDebugEnabled()) { log.info("Move remote file success"); } } if (!fileafterprocess.equals("")) { FileObject fAfterProcess = manager.resolveFile(fileafterprocess + filename, opts); fAfterProcess.copyFrom(newFile, Selectors.SELECT_SELF); } return resultStatus; }
public static FileObject resolveFile(String fileUri, UserAuthenticator userAuthenticator) throws FileSystemException { FileSystemOptions opts = null; if (VFS.getManager().getBaseFile() != null) { opts = VFS.getManager().getBaseFile().getFileSystem().getFileSystemOptions(); } if (opts == null) { opts = new FileSystemOptions(); } DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, userAuthenticator); FileObject file = resolveFile(fileUri, opts); return file; }
private void startFileMonitor(long scanInterval) throws FileSystemException { FileSystemManager fsManager = VFS.getManager(); FileObject listenFile = fsManager.resolveFile(propertyFile.getAbsolutePath()); DefaultFileMonitor defaultFileMonitor = new DefaultFileMonitor(new ServiceIdFileMonitor(this)); defaultFileMonitor.setDelay(scanInterval); defaultFileMonitor.addFile(listenFile); defaultFileMonitor.start(); LOGGER.info("Started file monitor on " + propertyFile.getAbsolutePath()); }
/** @param aLauncher Launcher being used in background */ public NuxeoLauncherGUI(NuxeoLauncher aLauncher) { launcher = aLauncher; // Set OS-specific decorations if (PlatformUtils.isMac()) { System.setProperty("apple.laf.useScreenMenuBar", "true"); System.setProperty("com.apple.mrj.application.growbox.intrudes", "false"); System.setProperty("com.apple.mrj.application.live-resize", "true"); System.setProperty("com.apple.macos.smallTabs", "true"); } initFrame(); dumpedConfigMonitor = new DefaultFileMonitor( new FileListener() { @Override public void fileDeleted(FileChangeEvent event) { // Ignore } @Override public void fileCreated(FileChangeEvent event) { updateNuxeoFrame(); } @Override public void fileChanged(FileChangeEvent event) { updateNuxeoFrame(); } private synchronized void updateNuxeoFrame() { waitForFrameLoaded(); log.debug("Configuration changed. Reloading frame..."); launcher.init(); updateServerStatus(); try { Properties props = new Properties(); props.load(new FileReader(getConfigurationGenerator().getDumpedConfig())); nuxeoFrame.updateLogsTab(props.getProperty("log.id")); } catch (IOException e) { log.error(e); } } }); try { dumpedConfigMonitor.setRecursive(false); FileObject dumpedConfig = VFS.getManager().resolveFile(getConfigurationGenerator().getDumpedConfig().getPath()); dumpedConfigMonitor.addFile(dumpedConfig); dumpedConfigMonitor.start(); } catch (FileSystemException e) { throw new RuntimeException("Couldn't find " + getConfigurationGenerator().getNuxeoConf(), e); } }
/** Constructor for testing purposes. Takes a repository as a parameter. */ public OlapServiceImpl(IUnifiedRepository repo, final MondrianServer server) { this.repository = repo; this.filters = new CopyOnWriteArrayList<IOlapConnectionFilter>(); this.server = server; try { DefaultFileSystemManager dfsm = (DefaultFileSystemManager) VFS.getManager(); if (dfsm.hasProvider("mondrian") == false) { dfsm.addProvider("mondrian", new MondrianVfs()); } } catch (FileSystemException e) { throw new RuntimeException(e); } }
public static void deployWebappFiles(ServletContext servletContext) throws IOException { Assert.Arg.notNull(servletContext, "servletContext"); FileSystemManager fsManager = VFS.getManager(); FileObject webappDir = fsManager.resolveFile(servletContext.getRealPath("/")); logger.info("Webapp dir: " + webappDir.getName()); for (Enumeration<URL> dirUrls = getResources(WEBAPP_DIR); dirUrls.hasMoreElements(); ) { FileObject extWebappDir = fsManager.resolveFile(dirUrls.nextElement().toExternalForm()); logger.info("Extension webapp dir: " + extWebappDir.getName()); if (extWebappDir.getType().hasChildren()) { logger.info(" Deploying webapp files ... "); webappDir.copyFrom(extWebappDir, new AllFileSelector()); } } }
public ConfigurationWatcher(ConfigChangeListener<C> configListener, Class<C> confClass) { this.configListener = configListener; this.confClass = confClass; this.confFilePath = ConfigurationManager.getConfFilePath(confClass); try { FileSystemManager fsManager = VFS.getManager(); FileObject file = fsManager.resolveFile(this.confFilePath); fileMonitor = new DefaultFileMonitor(this); fileMonitor.setRecursive(false); fileMonitor.addFile(file); fileMonitor.start(); this.notifyListener(); } catch (Exception e) { e.printStackTrace(); } }
public FileObject connectAndChangeToWorkDir() throws FileSystemException { StaticUserAuthenticator auth = new StaticUserAuthenticator(null, ftpConfig.getUsername(), ftpConfig.getPassword()); FileSystemOptions opts = new FileSystemOptions(); switch (ftpConfig.getType()) { case FTP: FtpFileSystemConfigBuilder.getInstance().setSoTimeout(opts, SOCKET_TIMEOUT); FtpFileSystemConfigBuilder.getInstance().setDataTimeout(opts, DATA_TIMEOUT); FtpFileSystemConfigBuilder.getInstance().setConnectTimeout(opts, CONNET_TIMEOUT); break; case FTPS: FtpsFileSystemConfigBuilder.getInstance().setSoTimeout(opts, SOCKET_TIMEOUT); FtpsFileSystemConfigBuilder.getInstance().setDataTimeout(opts, DATA_TIMEOUT); FtpsFileSystemConfigBuilder.getInstance().setConnectTimeout(opts, CONNET_TIMEOUT); break; case SFTP: SftpFileSystemConfigBuilder.getInstance().setTimeout(opts, SOCKET_TIMEOUT); break; } DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); FileObject fo = VFS.getManager().resolveFile(connectionString, opts); LOG.info("connected at {} #{}", connectionString, ftpConfig.getId()); return fo; }
private void killLogstashAgent(int logAgentNumber, String logstashLogPath) { FileObject listendir; CustomFileListener listener = new CustomFileListener(); long TIMEOUT_BETWEEN_FILE_QUERYING = 1000; long LOOP_TIMEOUT_IN_MILLIS = 10 * 1000; try { FileSystemManager fileSystemManager = VFS.getManager(); listendir = fileSystemManager.resolveFile(logstashLogPath); } catch (FileSystemException e) { e.printStackTrace(); return; } DefaultFileMonitor fm = new DefaultFileMonitor(listener); fm.setRecursive(true); fm.addFile(listendir); fm.setDelay(TIMEOUT_BETWEEN_FILE_QUERYING); fm.start(); LogUtils.log("waiting to destroy logger"); long startTimeMillis = System.currentTimeMillis(); while (true) { if (!listener.isProcessUp()) { break; } listener.setProcessUp(false); try { TimeUnit.MILLISECONDS.sleep(LOOP_TIMEOUT_IN_MILLIS); } catch (InterruptedException e) { e.printStackTrace(); } } long endTimeMillis = System.currentTimeMillis(); LogUtils.log("destroying logstash agent " + logAgentNumber); LogUtils.log("waited " + (endTimeMillis - startTimeMillis) / 1000 + " seconds"); fm.stop(); // File logstashOutputFile = new File(logstashLogPath); if (logAgentNumber == 1) { process.destroy(); process = null; } else { process2.destroy(); process2 = null; } // try { // TimeUnit.SECONDS.sleep(5); // // LogUtils.log("returning logstash config file to initial state"); // if(logAgentNumber == 1){ // IOUtils.replaceFileWithMove(new File(confFilePath), new File(backupFilePath)); // FileUtils.deleteQuietly(new File(backupFilePath)); // } // else{ // IOUtils.replaceFileWithMove(new File(confFilePath2), new // File(backupFilePath2)); // FileUtils.deleteQuietly(new File(backupFilePath2)); // // } // } catch (IOException e) { // e.printStackTrace(); // } catch (InterruptedException e) { // e.printStackTrace(); // } // if(logstashOutputFile.exists()){ // FileUtils.deleteQuietly(logstashOutputFile); // } }
public static FileObject resolveFile(String fileUri, FileSystemOptions opts) throws FileSystemException { FileObject file = VFS.getManager().resolveFile(fileUri, opts); return file; }
public void process() throws Exception { StreamProcessingLogDataCollector logDataCollector = new StreamProcessingLogDataCollector(logDataParsedListener, batchProcessingContext); FileSystemManager manager = null; try { manager = VFS.getManager(); } catch (FileSystemException e1) { return; } int i = 0; ArrayList<FileObject> fileObjects = new ArrayList<>(); for (String file : files) { i++; FileObject resolveFile = null; try { batchProcessingContext.printIfVerbose( "Resolving file %s [%d of %d]", file, i, files.size()); try { resolveFile = manager.resolveFile(file); } catch (Exception e) { file = new File(file).getAbsolutePath(); resolveFile = manager.resolveFile(file); } if (resolveFile != null) { fileObjects.add(resolveFile); } } catch (Exception e) { System.err.printf("Error resolving %s: %s", file, e.getMessage()); } } batchProcessingContext.setAllFiles(fileObjects); if (logDataParsedListener instanceof BatchProcessingListener) { ((BatchProcessingListener) logDataParsedListener).processingStarted(batchProcessingContext); } AutoDetectingImporterProvider importerProvider = new AutoDetectingImporterProvider( AllPluginables.getInstance().getLogImportersContainer().getElements()); i = 0; for (FileObject resolveFile : fileObjects) { i++; String fileName = resolveFile.getName().getBaseName(); try { batchProcessingContext.printIfVerbose( "Opening file %s [%d of %d]", fileName, i, fileObjects.size()); batchProcessingContext.setCurrentFile(resolveFile); if (logDataParsedListener instanceof SingleFileBatchProcessingListener) { ((SingleFileBatchProcessingListener) logDataParsedListener) .processingFileStarted(batchProcessingContext); } LoadingInfo openFileObject = Utils.openFileObject(resolveFile); LogImporter logImporter = importerProvider.getLogImporter(openFileObject); if (logImporter == null) { System.err.println("Can't find suitable log importer for " + fileName); continue; } batchProcessingContext.printIfVerbose( "Will user log importer: %s [%s]", logImporter.getName(), logImporter.getPluginableId()); // TODO for HTTP, Attempted read on closed stream. issue related to checking if file is // gziped // Utils.closeQuietly(resolveFile); // String fileUrl = resolveFile.getURL().toString(); // resolveFile = manager.resolveFile(fileUrl); // openFileObject = Utils.openFileObject(resolveFile); batchProcessingContext.setCurrentFile(resolveFile); ParsingContext context = new ParsingContext(); context.setLogSource(resolveFile.getName().getFriendlyURI()); logImporter.initParsingContext(context); logImporter.importLogs(openFileObject.getContentInputStream(), logDataCollector, context); if (logDataParsedListener instanceof SingleFileBatchProcessingListener) { ((SingleFileBatchProcessingListener) logDataParsedListener) .processingFileFinished(batchProcessingContext); } batchProcessingContext.printIfVerbose( "File %s processed [%d of %d]", fileName, i, files.size()); } catch (Exception e) { batchProcessingContext.printIfVerbose( "Error processing file %s: %s", fileName, e.getMessage()); System.err.println("Can't resolve file " + fileName + ": " + e.getMessage()); continue; } } if (logDataParsedListener instanceof BatchProcessingListener) { ((BatchProcessingListener) logDataParsedListener).processingFinished(batchProcessingContext); } }