Search in sources :

Example 46 with URI

use of java.net.URI in project flink by apache.

the class PythonPlanBinder method close.

private void close() {
    try {
        //prevent throwing exception so that previous exceptions aren't hidden.
        FileSystem hdfs = FileSystem.get(new URI(FLINK_HDFS_PATH));
        hdfs.delete(new Path(FLINK_HDFS_PATH), true);
        FileSystem local = FileSystem.getLocalFileSystem();
        local.delete(new Path(FLINK_PYTHON_FILE_PATH), true);
        local.delete(new Path(FLINK_TMP_DATA_DIR), true);
        streamer.close();
    } catch (NullPointerException npe) {
    } catch (IOException ioe) {
        LOG.error("PythonAPI file cleanup failed. " + ioe.getMessage());
    } catch (URISyntaxException use) {
    // can't occur
    }
}
Also used : Path(org.apache.flink.core.fs.Path) FileSystem(org.apache.flink.core.fs.FileSystem) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 47 with URI

use of java.net.URI in project groovy by apache.

the class ModuleNode method extractClassFromFileDescription.

protected String extractClassFromFileDescription() {
    String answer = getDescription();
    try {
        URI uri = new URI(answer);
        String path = uri.getPath();
        String schemeSpecific = uri.getSchemeSpecificPart();
        if (path != null) {
            answer = path;
        } else if (schemeSpecific != null) {
            answer = schemeSpecific;
        }
    } catch (URISyntaxException e) {
    }
    // let's strip off everything after the last '.'
    int slashIdx = answer.lastIndexOf('/');
    int separatorIdx = answer.lastIndexOf(File.separatorChar);
    int dotIdx = answer.lastIndexOf('.');
    if (dotIdx > 0 && dotIdx > Math.max(slashIdx, separatorIdx)) {
        answer = answer.substring(0, dotIdx);
    }
    // new let's strip everything up to and including the path separators
    if (slashIdx >= 0) {
        answer = answer.substring(slashIdx + 1);
    }
    // recalculate in case we have already done some stripping
    separatorIdx = answer.lastIndexOf(File.separatorChar);
    if (separatorIdx >= 0) {
        answer = answer.substring(separatorIdx + 1);
    }
    return answer;
}
Also used : URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 48 with URI

use of java.net.URI in project groovy by apache.

the class SourceURIASTTransformation method getSourceURI.

protected URI getSourceURI(AnnotationNode node) {
    URI uri = sourceUnit.getSource().getURI();
    if (uri != null) {
        if (!(uri.isAbsolute() || memberHasValue(node, "allowRelative", true))) {
            // FIXME:  What should we use as the base URI?
            // It is unlikely we get to this point with a relative URI since making a URL
            // from will make it absolute I think.  But lets handle the simple case of
            // using file paths and turning that into an absolute file URI.
            // So we will use the current working directory as the base.
            URI baseURI = new File(".").toURI();
            uri = uri.resolve(baseURI);
        }
    }
    return uri;
}
Also used : SourceURI(groovy.transform.SourceURI) URI(java.net.URI) File(java.io.File)

Example 49 with URI

use of java.net.URI in project flink by apache.

the class ChaosMonkeyITCase method checkCleanRecoveryState.

private void checkCleanRecoveryState(Configuration config) throws Exception {
    LOG.info("Checking " + ZooKeeper.getClientNamespace() + ConfigConstants.DEFAULT_ZOOKEEPER_JOBGRAPHS_PATH);
    List<String> jobGraphs = ZooKeeper.getChildren(ConfigConstants.DEFAULT_ZOOKEEPER_JOBGRAPHS_PATH);
    assertEquals("Unclean job graphs: " + jobGraphs, 0, jobGraphs.size());
    LOG.info("Checking " + ZooKeeper.getClientNamespace() + ConfigConstants.DEFAULT_ZOOKEEPER_CHECKPOINTS_PATH);
    for (int i = 0; i < 10; i++) {
        List<String> checkpoints = ZooKeeper.getChildren(ConfigConstants.DEFAULT_ZOOKEEPER_CHECKPOINTS_PATH);
        assertEquals("Unclean checkpoints: " + checkpoints, 0, checkpoints.size());
        LOG.info("Unclean... retrying in 2s.");
        Thread.sleep(2000);
    }
    LOG.info("Checking " + ZooKeeper.getClientNamespace() + ConfigConstants.DEFAULT_ZOOKEEPER_CHECKPOINT_COUNTER_PATH);
    List<String> checkpointCounter = ZooKeeper.getChildren(ConfigConstants.DEFAULT_ZOOKEEPER_CHECKPOINT_COUNTER_PATH);
    assertEquals("Unclean checkpoint counter: " + checkpointCounter, 0, checkpointCounter.size());
    LOG.info("ZooKeeper state is clean");
    LOG.info("Checking file system backend state...");
    File fsCheckpoints = new File(new URI(config.getString(FsStateBackendFactory.CHECKPOINT_DIRECTORY_URI_CONF_KEY, "")).getPath());
    LOG.info("Checking " + fsCheckpoints);
    File[] files = fsCheckpoints.listFiles();
    if (files == null) {
        fail(fsCheckpoints + " does not exist: " + Arrays.toString(FileStateBackendBasePath.listFiles()));
    }
    File fsRecovery = new File(new URI(config.getString(HighAvailabilityOptions.HA_STORAGE_PATH)).getPath());
    LOG.info("Checking " + fsRecovery);
    files = fsRecovery.listFiles();
    if (files == null) {
        fail(fsRecovery + " does not exist: " + Arrays.toString(FileStateBackendBasePath.listFiles()));
    }
}
Also used : File(java.io.File) URI(java.net.URI)

Example 50 with URI

use of java.net.URI in project hadoop by apache.

the class TestFileUtil method testCopy5.

@Test(timeout = 30000)
public /*
   * Test method copy(FileSystem srcFS, Path src, File dst, boolean deleteSource, Configuration conf)
   */
void testCopy5() throws IOException {
    setupDirs();
    URI uri = tmp.toURI();
    Configuration conf = new Configuration();
    FileSystem fs = FileSystem.newInstance(uri, conf);
    final String content = "some-content";
    File srcFile = createFile(tmp, "src", content);
    Path srcPath = new Path(srcFile.toURI());
    // copy regular file:
    final File dest = new File(del, "dest");
    boolean result = FileUtil.copy(fs, srcPath, dest, false, conf);
    assertTrue(result);
    assertTrue(dest.exists());
    assertEquals(content.getBytes().length + System.getProperty("line.separator").getBytes().length, dest.length());
    // should not be deleted
    assertTrue(srcFile.exists());
    // copy regular file, delete src:
    dest.delete();
    assertTrue(!dest.exists());
    result = FileUtil.copy(fs, srcPath, dest, true, conf);
    assertTrue(result);
    assertTrue(dest.exists());
    assertEquals(content.getBytes().length + System.getProperty("line.separator").getBytes().length, dest.length());
    // should be deleted
    assertTrue(!srcFile.exists());
    // copy a dir:
    dest.delete();
    assertTrue(!dest.exists());
    srcPath = new Path(partitioned.toURI());
    result = FileUtil.copy(fs, srcPath, dest, true, conf);
    assertTrue(result);
    assertTrue(dest.exists() && dest.isDirectory());
    File[] files = dest.listFiles();
    assertTrue(files != null);
    assertEquals(2, files.length);
    for (File f : files) {
        assertEquals(3 + System.getProperty("line.separator").getBytes().length, f.length());
    }
    // should be deleted
    assertTrue(!partitioned.exists());
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) URI(java.net.URI) JarFile(java.util.jar.JarFile) File(java.io.File) Test(org.junit.Test)

Aggregations

URI (java.net.URI)5680 Test (org.junit.Test)1852 URISyntaxException (java.net.URISyntaxException)1016 IOException (java.io.IOException)749 File (java.io.File)531 HashMap (java.util.HashMap)458 ArrayList (java.util.ArrayList)452 Test (org.testng.annotations.Test)394 Configuration (org.apache.hadoop.conf.Configuration)321 Path (org.apache.hadoop.fs.Path)267 URL (java.net.URL)266 Map (java.util.Map)262 Response (javax.ws.rs.core.Response)218 List (java.util.List)184 InputStream (java.io.InputStream)154 HashSet (java.util.HashSet)136 FileSystem (org.apache.hadoop.fs.FileSystem)135 RequestContext (com.linkedin.r2.message.RequestContext)129 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)128 RestRequest (com.linkedin.r2.message.rest.RestRequest)112