Search in sources :

Example 71 with URL

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

the class BaseTemplate method includeEscaped.

/**
     * Includes contents of another file, not as a template but as escaped text.
     *
     * @param templatePath the path to the other file
     * @throws IOException
     */
public void includeEscaped(String templatePath) throws IOException {
    URL resource = engine.resolveTemplate(templatePath);
    yield(ResourceGroovyMethods.getText(resource, engine.getCompilerConfiguration().getSourceEncoding()));
}
Also used : URL(java.net.URL)

Example 72 with URL

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

the class CompilerPerformanceTest method main.

public static void main(String[] args) throws Exception {
    List<File> sources = new ArrayList<>();
    List<URL> classpath = new ArrayList<>();
    boolean isCp = false;
    for (String arg : args) {
        if ("-cp".equals(arg)) {
            isCp = true;
        } else if (isCp) {
            classpath.add(new File(arg).toURI().toURL());
        } else {
            sources.add(new File(arg));
        }
    }
    ScriptCompilationExecuter executer = new ScriptCompilationExecuter(sources.toArray(new File[sources.size()]), classpath);
    System.out.println("Using Groovy " + GROOVY_VERSION);
    DescriptiveStatistics stats = new DescriptiveStatistics();
    for (int i = 0; i < WARMUP + REPEAT; i++) {
        if (i < WARMUP) {
            System.out.println("Warmup #" + (i + 1));
        } else {
            System.out.println("Round #" + (i - WARMUP));
        }
        long dur = executer.execute();
        System.gc();
        System.out.printf("Compile time = %dms%n", dur);
        if (i >= WARMUP) {
            stats.addValue((double) dur);
        }
    }
    System.out.println("Compilation took " + stats.getMean() + "ms ± " + stats.getStandardDeviation() + "ms");
    FileWriter wrt = new FileWriter(new File("target/compilation-stats.csv"), true);
    wrt.append(String.format("%s;%s;%s\n", GROOVY_VERSION, stats.getMean(), stats.getStandardDeviation()));
    wrt.close();
}
Also used : DescriptiveStatistics(org.apache.commons.math3.stat.descriptive.DescriptiveStatistics) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) File(java.io.File) URL(java.net.URL)

Example 73 with URL

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

the class DelegationTokenAuthenticatedURL method augmentURL.

private URL augmentURL(URL url, Map<String, String> params) throws IOException {
    if (params != null && params.size() > 0) {
        String urlStr = url.toExternalForm();
        StringBuilder sb = new StringBuilder(urlStr);
        String separator = (urlStr.contains("?")) ? "&" : "?";
        for (Map.Entry<String, String> param : params.entrySet()) {
            sb.append(separator).append(param.getKey()).append("=").append(param.getValue());
            separator = "&";
        }
        url = new URL(sb.toString());
    }
    return url;
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) URL(java.net.URL) AuthenticatedURL(org.apache.hadoop.security.authentication.client.AuthenticatedURL)

Example 74 with URL

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

the class JobClient method retrieveClassLoader.

/**
	 * Reconstructs the class loader by first requesting information about it at the JobManager
	 * and then downloading missing jar files.
	 * @param jobID id of job
	 * @param jobManager gateway to the JobManager
	 * @param config the flink configuration
	 * @return A classloader that should behave like the original classloader
	 * @throws JobRetrievalException if anything goes wrong
	 */
public static ClassLoader retrieveClassLoader(JobID jobID, ActorGateway jobManager, Configuration config) throws JobRetrievalException {
    final Object jmAnswer;
    try {
        jmAnswer = Await.result(jobManager.ask(new JobManagerMessages.RequestClassloadingProps(jobID), AkkaUtils.getDefaultTimeoutAsFiniteDuration()), AkkaUtils.getDefaultTimeoutAsFiniteDuration());
    } catch (Exception e) {
        throw new JobRetrievalException(jobID, "Couldn't retrieve class loading properties from JobManager.", e);
    }
    if (jmAnswer instanceof JobManagerMessages.ClassloadingProps) {
        JobManagerMessages.ClassloadingProps props = ((JobManagerMessages.ClassloadingProps) jmAnswer);
        Option<String> jmHost = jobManager.actor().path().address().host();
        String jmHostname = jmHost.isDefined() ? jmHost.get() : "localhost";
        InetSocketAddress serverAddress = new InetSocketAddress(jmHostname, props.blobManagerPort());
        final BlobCache blobClient;
        try {
            blobClient = new BlobCache(serverAddress, config);
        } catch (IOException e) {
            throw new JobRetrievalException(jobID, "Failed to setup blob cache", e);
        }
        final Collection<BlobKey> requiredJarFiles = props.requiredJarFiles();
        final Collection<URL> requiredClasspaths = props.requiredClasspaths();
        final URL[] allURLs = new URL[requiredJarFiles.size() + requiredClasspaths.size()];
        int pos = 0;
        for (BlobKey blobKey : props.requiredJarFiles()) {
            try {
                allURLs[pos++] = blobClient.getURL(blobKey);
            } catch (Exception e) {
                blobClient.shutdown();
                throw new JobRetrievalException(jobID, "Failed to download BlobKey " + blobKey, e);
            }
        }
        for (URL url : requiredClasspaths) {
            allURLs[pos++] = url;
        }
        return new FlinkUserCodeClassLoader(allURLs, JobClient.class.getClassLoader());
    } else if (jmAnswer instanceof JobManagerMessages.JobNotFound) {
        throw new JobRetrievalException(jobID, "Couldn't retrieve class loader. Job " + jobID + " not found");
    } else {
        throw new JobRetrievalException(jobID, "Unknown response from JobManager: " + jmAnswer);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) FlinkUserCodeClassLoader(org.apache.flink.runtime.execution.librarycache.FlinkUserCodeClassLoader) JobManagerMessages(org.apache.flink.runtime.messages.JobManagerMessages) BlobCache(org.apache.flink.runtime.blob.BlobCache) IOException(java.io.IOException) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) URL(java.net.URL) BlobKey(org.apache.flink.runtime.blob.BlobKey)

Example 75 with URL

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

the class BlobLibraryCacheManager method registerTask.

@Override
public void registerTask(JobID jobId, ExecutionAttemptID task, Collection<BlobKey> requiredJarFiles, Collection<URL> requiredClasspaths) throws IOException {
    checkNotNull(jobId, "The JobId must not be null.");
    checkNotNull(task, "The task execution id must not be null.");
    if (requiredJarFiles == null) {
        requiredJarFiles = Collections.emptySet();
    }
    if (requiredClasspaths == null) {
        requiredClasspaths = Collections.emptySet();
    }
    synchronized (lockObject) {
        LibraryCacheEntry entry = cacheEntries.get(jobId);
        if (entry == null) {
            // create a new entry in the library cache
            BlobKey[] keys = requiredJarFiles.toArray(new BlobKey[requiredJarFiles.size()]);
            URL[] urls = new URL[keys.length + requiredClasspaths.size()];
            int count = 0;
            try {
                for (; count < keys.length; count++) {
                    BlobKey blobKey = keys[count];
                    urls[count] = registerReferenceToBlobKeyAndGetURL(blobKey);
                }
            } catch (Throwable t) {
                // undo the reference count increases
                try {
                    for (int i = 0; i < count; i++) {
                        unregisterReferenceToBlobKey(keys[i]);
                    }
                } catch (Throwable tt) {
                    LOG.error("Error while updating library reference counters.", tt);
                }
                // rethrow or wrap
                ExceptionUtils.tryRethrowIOException(t);
                throw new IOException("Library cache could not register the user code libraries.", t);
            }
            // add classpaths
            for (URL url : requiredClasspaths) {
                urls[count] = url;
                count++;
            }
            cacheEntries.put(jobId, new LibraryCacheEntry(requiredJarFiles, urls, task));
        } else {
            entry.register(task, requiredJarFiles);
        }
    }
}
Also used : BlobKey(org.apache.flink.runtime.blob.BlobKey) IOException(java.io.IOException) URL(java.net.URL)

Aggregations

URL (java.net.URL)8112 IOException (java.io.IOException)2006 Test (org.junit.Test)1653 File (java.io.File)1638 MalformedURLException (java.net.MalformedURLException)1165 HttpURLConnection (java.net.HttpURLConnection)1030 InputStream (java.io.InputStream)1028 ArrayList (java.util.ArrayList)633 URLConnection (java.net.URLConnection)515 InputStreamReader (java.io.InputStreamReader)473 URLClassLoader (java.net.URLClassLoader)451 BufferedReader (java.io.BufferedReader)390 HashMap (java.util.HashMap)361 URISyntaxException (java.net.URISyntaxException)286 URI (java.net.URI)269 Map (java.util.Map)259 FileInputStream (java.io.FileInputStream)227 List (java.util.List)205 FileOutputStream (java.io.FileOutputStream)194 OutputStream (java.io.OutputStream)194