List of usage examples for org.apache.commons.vfs2 VFS getManager
public static synchronized FileSystemManager getManager() throws FileSystemException
From source file:org.pentaho.hadoop.shim.HadoopRunningOnClusterTest.java
@BeforeClass public static void setup() throws Exception { // Create a test hadoop configuration FileObject ramRoot = VFS.getManager().resolveFile(CONFIG_PROPERTY_CLASSPATH); if (ramRoot.exists()) { ramRoot.delete(new AllFileSelector()); }/* w w w .j av a 2 s . c o m*/ ramRoot.createFolder(); // Create the implementation jars ramRoot.resolveFile("hadoop-mapreduce-client-app-2.7.0-mapr-1602.jar").createFile(); ramRoot.resolveFile("hadoop-mapreduce-client-common-2.7.0-mapr-1602.jar").createFile(); ramRoot.resolveFile("hadoop-mapreduce-client-contrib-2.7.0-mapr-1602.jar").createFile(); ramRoot.resolveFile("hadoop-mapreduce-client-core-2.7.0-mapr-1602.jar").createFile(); ramRoot.resolveFile("hadoop-mapreduce-client-hs-2.7.0-mapr-1602.jar").createFile(); pmrFolder = tempFolder.newFolder("pmr"); urlTestResources = Thread.currentThread().getContextClassLoader().getResource(PMR_PROPERTIES); Files.copy(Paths.get(urlTestResources.toURI()), Paths.get(pmrFolder.getAbsolutePath(), PMR_PROPERTIES)); }
From source file:org.pentaho.hadoop.shim.HadoopRunningOnClusterTest.java
@Test public void runningLocally_withLinuxClassPathProperty() throws Exception { HadoopConfigurationLocator locator = new HadoopConfigurationLocator(); FileObject folder = VFS.getManager().resolveFile(CONFIG_PROPERTY_CLASSPATH); try {/*from w ww .ja v a 2 s . co m*/ disablePmrFile(); List<URL> classpathElements = null; if (!locator.isRunningOnCluster()) { classpathElements = locator.parseURLs(folder, folder.toString()); count = classpathElements.size(); } Assert.assertNotNull(classpathElements); Assert.assertEquals(6, count); } finally { activatePmrFile(); } }
From source file:org.pentaho.hadoop.shim.HadoopRunningOnClusterTest.java
@Test public void runningOnCluster_ignoreLinuxClassPathProperty() throws Exception { HadoopConfigurationLocator locator = new HadoopConfigurationLocator(); FileObject folder = VFS.getManager().resolveFile(CONFIG_PROPERTY_CLASSPATH); activatePmrFile();//w w w. j a va 2 s. c o m List<URL> classpathElements = null; if (!locator.isRunningOnCluster()) { classpathElements = locator.parseURLs(folder, folder.toString()); count = classpathElements.size(); } Assert.assertEquals(null, classpathElements); Assert.assertEquals(0, count); }
From source file:org.pentaho.hadoop.shim.mapr.HadoopShimTest.java
@Test public void onLoad() throws Exception { HadoopConfigurationProvider configProvider = new HadoopConfigurationProvider() { @Override/* www. j av a 2s.c om*/ public boolean hasConfiguration(String id) { throw new UnsupportedOperationException(); } @Override public List<? extends HadoopConfiguration> getConfigurations() { throw new UnsupportedOperationException(); } @Override public HadoopConfiguration getConfiguration(String id) throws ConfigurationException { throw new UnsupportedOperationException(); } @Override public HadoopConfiguration getActiveConfiguration() throws ConfigurationException { throw new UnsupportedOperationException(); } }; DefaultFileSystemManager delegate = new DefaultFileSystemManager(); HadoopConfigurationFileSystemManager fsm = new HadoopConfigurationFileSystemManager(configProvider, delegate); assertFalse(fsm.hasProvider("hdfs")); HadoopShim shim = new HadoopShim(); HadoopConfiguration config = new HadoopConfiguration(VFS.getManager().resolveFile("ram:///"), "id", "name", shim, null, null, null); shim.onLoad(config, fsm); assertNotNull(shim.getDistributedCacheUtil()); }
From source file:org.pentaho.metaverse.impl.VfsLineageWriterTest.java
/** * @throws FileSystemException/* ww w . ja v a2s . co m*/ * @throws java.lang.Exception */ @After public void tearDown() throws FileSystemException { FileSystemManager fsManager = VFS.getManager(); fsManager.resolveFile(BAD_OUTPUT_FOLDER).deleteAll(); fsManager.resolveFile(GOOD_OUTPUT_FOLDER).deleteAll(); }
From source file:org.pentaho.platform.pdi.PdiPlatformActivator.java
@Override public void start(BundleContext bundleContext) throws Exception { if (PentahoSystem.get(IAuthorizationPolicy.class) == null) { PentahoSystem.registerObject(new AgileBiAuthorizationPolicy()); }// w w w .jav a2s .c o m if (PentahoSystem.get(IPluginResourceLoader.class) == null) { PentahoSystem.registerObject(RESOURCE_LOADER); } if (PentahoSystem.get(IPluginManager.class) == null) { PentahoSystem.registerObject(new PentahoSystemPluginManager() { @Override public Object getPluginSetting(String pluginId, String key, String defaultValue) { return null; } }); } // We're the one who boots PentahoSystem when running outside of the server if (PentahoSystem.getInitializedStatus() != PentahoSystem.SYSTEM_INITIALIZED_OK) { PentahoSystem.init(); } // We need to prime Mondrian. String solutionPath = PentahoSystem.getApplicationContext() .getSolutionPath("system/mondrian/mondrian.properties"); try { MondrianProperties.instance().load(new FileInputStream(new File(solutionPath))); } catch (IOException e) { logger.error("Error loading mondrian properties", e); } try { ((DefaultFileSystemManager) VFS.getManager()).addProvider("mtm", new MetadataToMondrianVfs()); } catch (FileSystemException e) { if (e.getCode().equals("vfs.impl/multiple-providers-for-scheme.error")) { // it's already registered. just log it as info logger.error("There is already a vfs provider registered for scheme mtm", e); } else { logger.error("There is already a vfs provider registered for scheme mtm", e); } } }
From source file:org.pentaho.platform.pdi.vfs.MetadataToMondrianVfsTest.java
@Test public void testVfs() throws Exception { ((DefaultFileSystemManager) VFS.getManager()).addProvider("mtm", new MetadataToMondrianVfs()); FileSystemManager fsManager = VFS.getManager(); FileObject fobj = fsManager.resolveFile("mtm:src/test/resources/example_olap.xmi"); StringBuilder buf = new StringBuilder(1000); InputStream in = fobj.getContent().getInputStream(); int n;//from www . jav a 2s . c o m while ((n = in.read()) != -1) { buf.append((char) n); } in.close(); String results = buf.toString(); Assert.assertTrue(results.indexOf("<Cube name=\"customer2 Table\">") >= 0); }
From source file:org.pentaho.reporting.designer.extensions.pentaho.drilldown.PentahoParameterRefreshHandler.java
private static String getParameterServicePath(final AuthenticationData loginData, final PentahoPathModel pathModel) { try {//from w w w . j av a 2 s. c om final FileObject fileSystemRoot = PublishUtil.createVFSConnection(VFS.getManager(), loginData); final FileSystem fileSystem = fileSystemRoot.getFileSystem(); // as of version 3.7 we do not need to check anything other than that the version information is there // later we may have to add additional checks in here to filter out known broken versions. final String localPath = pathModel.getLocalPath(); final FileObject object = fileSystemRoot.resolveFile(localPath); final FileContent content = object.getContent(); final String majorVersionText = (String) fileSystem.getAttribute(WebSolutionFileSystem.MAJOR_VERSION); if (StringUtils.isEmpty(majorVersionText) == false) { final String paramService = (String) content.getAttribute("param-service-url"); if (StringUtils.isEmpty(paramService)) { return null; } if (paramService.startsWith("http://") || paramService.startsWith("https://")) { return paramService; } try { // Encode the URL (must use URI as URL encoding doesn't work on spaces correctly) final URL target = new URL(loginData.getUrl()); final String host; if (target.getPort() != -1) { host = target.getHost() + ":" + target.getPort(); } else { host = target.getHost(); } return target.getProtocol() + "://" + host + paramService; } catch (MalformedURLException e) { UncaughtExceptionsModel.getInstance().addException(e); return null; } } final String extension = IOUtils.getInstance().getFileExtension(localPath); if (".prpt".equals(extension)) { logger.debug( "Ancient pentaho system detected: parameter service does not deliver valid parameter values"); final String name = pathModel.getName(); final String path = pathModel.getPath(); final String solution = pathModel.getSolution(); final FastMessageFormat messageFormat = new FastMessageFormat( "/content/reporting/?renderMode=XML&solution={0}&path={1}&name={2}"); messageFormat.setNullString(""); return loginData.getUrl() + messageFormat.format(new Object[] { solution, path, name }); } logger.debug("Ancient pentaho system detected: We will not have access to a working parameter service"); return null; } catch (FileSystemException e) { UncaughtExceptionsModel.getInstance().addException(e); return null; } }
From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.actions.ValidateLoginTask.java
public boolean validateLoginData() throws FileSystemException { if (loginData == null) { return true; }//from www.j a va2 s.c o m final FileObject vfsConnection = PublishUtil.createVFSConnection(VFS.getManager(), loginData); try { final FileSystem fileSystem = vfsConnection.getFileSystem(); if (fileSystem instanceof WebSolutionFileSystem) { final WebSolutionFileSystem webSolutionFileSystem = (WebSolutionFileSystem) fileSystem; final Long l = (Long) webSolutionFileSystem .getAttribute(WebSolutionFileSystem.LAST_REFRESH_TIME_ATTRIBUTE); if (l != null) { if ((System.currentTimeMillis() - l) > 500) { webSolutionFileSystem.getLocalFileModel().refresh(); } } return true; } } catch (FileSystemException fse) { // not all file systems support attributes .. } catch (IOException e) { return false; } final FileType type = vfsConnection.getType(); if (type != FileType.FOLDER) { return false; } return true; }
From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.dialogs.RepositoryOpenDialog.java
public String performOpen(final AuthenticationData loginData, final String previousSelection) throws FileSystemException, UnsupportedEncodingException { fileSystemRoot = PublishUtil.createVFSConnection(VFS.getManager(), loginData); if (previousSelection == null) { setSelectedView(fileSystemRoot); } else {/*from w ww. jav a2 s .c o m*/ final FileObject view = fileSystemRoot.resolveFile(previousSelection); if (view == null) { setSelectedView(fileSystemRoot); } else { if (view.exists() == false) { setSelectedView(fileSystemRoot); } else if (view.getType() == FileType.FOLDER) { setSelectedView(view); } else { setSelectedView(view.getParent()); } } } if (StringUtils.isEmpty(fileNameTextField.getText(), true) && previousSelection != null) { final String fileName = IOUtils.getInstance().getFileName(previousSelection); DebugLog.log("Setting filename to " + fileName); fileNameTextField.setText(fileName); } getConfirmAction().setEnabled(validateInputs(false)); if (super.performEdit() == false || selectedView == null) { return null; } return getSelectedFile(); }