Package org.elasticsearch.common.http.client

Examples of org.elasticsearch.common.http.client.HttpDownloadHelper


            e.printStackTrace();
        }
    }

    public void downloadAndExtract(String name) throws IOException {
        HttpDownloadHelper downloadHelper = new HttpDownloadHelper();

        File pluginFile = new File(url + "/" + name + "/elasticsearch-" + name + "-" + Version.number() + ".zip");
        boolean downloaded = false;
        String filterZipName = null;
        if (!pluginFile.exists()) {
            pluginFile = new File(url + "/elasticsearch-" + name + "-" + Version.number() + ".zip");
            if (!pluginFile.exists()) {
                pluginFile = new File(environment.pluginsFile(), name + ".zip");
                if (url != null) {
                    URL pluginUrl = new URL(url);
                    System.out.println("Trying " + pluginUrl.toExternalForm() + "...");
                    try {
                        downloadHelper.download(pluginUrl, pluginFile, new HttpDownloadHelper.VerboseProgress(System.out));
                        downloaded = true;
                    } catch (IOException e) {
                        // ignore
                    }
                } else {
                    url = "http://elasticsearch.googlecode.com/svn/plugins";
                }
                if (!downloaded) {
                    if (name.indexOf('/') != -1) {
                        // github repo
                        String[] elements = name.split("/");
                        String userName = elements[0];
                        String repoName = elements[1];
                        String version = null;
                        if (elements.length > 2) {
                            version = elements[2];
                        }
                        filterZipName = userName + "-" + repoName;
                        // the installation file should not include the userName, just the repoName
                        name = repoName;
                        if (name.startsWith("elasticsearch-")) {
                            // remove elasticsearch- prefix
                            name = name.substring("elasticsearch-".length());
                        } else if (name.startsWith("es-")) {
                            // remove es- prefix
                            name = name.substring("es-".length());
                        }
                        pluginFile = new File(environment.pluginsFile(), name + ".zip");
                        if (version == null) {
                            // try with ES version from downloads
                            URL pluginUrl = new URL("https://github.com/downloads/" + userName + "/" + repoName + "/" + repoName + "-" + Version.number() + ".zip");
                            System.out.println("Trying " + pluginUrl.toExternalForm() + "...");
                            try {
                                downloadHelper.download(pluginUrl, pluginFile, new HttpDownloadHelper.VerboseProgress(System.out));
                                downloaded = true;
                            } catch (IOException e) {
                                // try a tag with ES version
                                pluginUrl = new URL("https://github.com/" + userName + "/" + repoName + "/zipball/v" + Version.number());
                                System.out.println("Trying " + pluginUrl.toExternalForm() + "...");
                                try {
                                    downloadHelper.download(pluginUrl, pluginFile, new HttpDownloadHelper.VerboseProgress(System.out));
                                    downloaded = true;
                                } catch (IOException e1) {
                                    // download master
                                    pluginUrl = new URL("https://github.com/" + userName + "/" + repoName + "/zipball/master");
                                    System.out.println("Trying " + pluginUrl.toExternalForm() + "...");
                                    try {
                                        downloadHelper.download(pluginUrl, pluginFile, new HttpDownloadHelper.VerboseProgress(System.out));
                                        downloaded = true;
                                    } catch (IOException e2) {
                                        // ignore
                                    }
                                }
                            }
                        } else {
                            // download explicit version
                            URL pluginUrl = new URL("https://github.com/downloads/" + userName + "/" + repoName + "/" + repoName + "-" + version + ".zip");
                            System.out.println("Trying " + pluginUrl.toExternalForm() + "...");
                            try {
                                downloadHelper.download(pluginUrl, pluginFile, new HttpDownloadHelper.VerboseProgress(System.out));
                                downloaded = true;
                            } catch (IOException e) {
                                // try a tag with ES version
                                pluginUrl = new URL("https://github.com/" + userName + "/" + repoName + "/zipball/v" + version);
                                System.out.println("Trying " + pluginUrl.toExternalForm() + "...");
                                try {
                                    downloadHelper.download(pluginUrl, pluginFile, new HttpDownloadHelper.VerboseProgress(System.out));
                                    downloaded = true;
                                } catch (IOException e1) {
                                    // ignore
                                }
                            }
                        }
                    } else {
                        URL pluginUrl = new URL(url + "/" + name + "/elasticsearch-" + name + "-" + Version.number() + ".zip");
                        System.out.println("Trying " + pluginUrl.toExternalForm() + "...");
                        try {
                            downloadHelper.download(pluginUrl, pluginFile, new HttpDownloadHelper.VerboseProgress(System.out));
                            downloaded = true;
                        } catch (IOException e) {
                            // ignore
                        }
                    }
View Full Code Here


    public void downloadAndExtract(String name) throws IOException {
        if (name == null) {
            throw new ElasticsearchIllegalArgumentException("plugin name must be supplied with --install [name].");
        }
        HttpDownloadHelper downloadHelper = new HttpDownloadHelper();
        boolean downloaded = false;
        HttpDownloadHelper.DownloadProgress progress;
        if (outputMode == OutputMode.SILENT) {
            progress = new HttpDownloadHelper.NullProgress();
        } else {
            progress = new HttpDownloadHelper.VerboseProgress(System.out);
        }

        if (!environment.pluginsFile().canWrite()) {
            System.err.println();
            throw new IOException("plugin directory " + environment.pluginsFile() + " is read only");
        }

        PluginHandle pluginHandle = PluginHandle.parse(name);
        checkForForbiddenName(pluginHandle.name);

        File pluginFile = pluginHandle.distroFile(environment);
        // extract the plugin
        File extractLocation = pluginHandle.extractedDir(environment);
        if (extractLocation.exists()) {
            throw new IOException("plugin directory " + extractLocation.getAbsolutePath() + " already exists. To update the plugin, uninstall it first using --remove " + name + " command");
        }

        // first, try directly from the URL provided
        if (url != null) {
            URL pluginUrl = new URL(url);
            log("Trying " + pluginUrl.toExternalForm() + "...");
            try {
                downloadHelper.download(pluginUrl, pluginFile, progress, this.timeout);
                downloaded = true;
            } catch (ElasticsearchTimeoutException e) {
                throw e;
            } catch (Exception e) {
                // ignore
                log("Failed: " + ExceptionsHelper.detailedMessage(e));
            }
        }

        if (!downloaded) {
            // We try all possible locations
            for (URL url : pluginHandle.urls()) {
                log("Trying " + url.toExternalForm() + "...");
                try {
                    downloadHelper.download(url, pluginFile, progress, this.timeout);
                    downloaded = true;
                    break;
                } catch (ElasticsearchTimeoutException e) {
                    throw e;
                } catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.elasticsearch.common.http.client.HttpDownloadHelper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.