You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by nt...@apache.org on 2016/01/26 17:16:13 UTC

ignite git commit: IGNITE-2435 Fixed.

Repository: ignite
Updated Branches:
  refs/heads/ignite-2435 [created] acae0a5f6


IGNITE-2435 Fixed.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/acae0a5f
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/acae0a5f
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/acae0a5f

Branch: refs/heads/ignite-2435
Commit: acae0a5f6bae8e17d1eb5cca1faf3998d258999d
Parents: c55cc97
Author: Tikhonov Nikolay <ti...@gmail.com>
Authored: Tue Jan 26 19:02:04 2016 +0300
Committer: Tikhonov Nikolay <ti...@gmail.com>
Committed: Tue Jan 26 19:13:23 2016 +0300

----------------------------------------------------------------------
 .../apache/ignite/mesos/ClusterProperties.java  |  16 +-
 .../ignite/mesos/resource/IgniteProvider.java   | 182 +++++--------------
 .../ignite/mesos/resource/ResourceProvider.java |  42 +++--
 3 files changed, 96 insertions(+), 144 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/acae0a5f/modules/mesos/src/main/java/org/apache/ignite/mesos/ClusterProperties.java
----------------------------------------------------------------------
diff --git a/modules/mesos/src/main/java/org/apache/ignite/mesos/ClusterProperties.java b/modules/mesos/src/main/java/org/apache/ignite/mesos/ClusterProperties.java
index e249a25..53eac83 100644
--- a/modules/mesos/src/main/java/org/apache/ignite/mesos/ClusterProperties.java
+++ b/modules/mesos/src/main/java/org/apache/ignite/mesos/ClusterProperties.java
@@ -155,6 +155,12 @@ public class ClusterProperties {
     private String ignitePackageUrl = null;
 
     /** */
+    public static final String IGNITE_PACKAGE_PATH = "IGNITE_PACKAGE_PATH";
+
+    /** Ignite package path. */
+    private String ignitePackagePath = null;
+
+    /** */
     public static final String IGNITE_WORK_DIR = "IGNITE_WORK_DIR";
 
     /** */
@@ -397,6 +403,13 @@ public class ClusterProperties {
     }
 
     /**
+     * @return Url to ignite package.
+     */
+    public String ignitePackagePath() {
+        return ignitePackagePath;
+    }
+
+    /**
      * @return Url to ignite configuration.
      */
     public String igniteConfigUrl() {
@@ -456,6 +469,7 @@ public class ClusterProperties {
 
             prop.userLibsUrl = getStringProperty(IGNITE_USERS_LIBS_URL, props, null);
             prop.ignitePackageUrl = getStringProperty(IGNITE_PACKAGE_URL, props, null);
+            prop.ignitePackagePath = getStringProperty(IGNITE_PACKAGE_PATH, props, null);
             prop.licenceUrl = getStringProperty(LICENCE_URL, props, null);
             prop.igniteCfgUrl = getStringProperty(IGNITE_CONFIG_XML_URL, props, null);
 
@@ -550,6 +564,6 @@ public class ClusterProperties {
             }
         }
 
-        throw new RuntimeException("Failed. Couldn't find non-loopback address");
+        throw new RuntimeException("Failed. Could not find non-loopback address");
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/acae0a5f/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/IgniteProvider.java
----------------------------------------------------------------------
diff --git a/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/IgniteProvider.java b/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/IgniteProvider.java
index 7510110..f35a426 100644
--- a/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/IgniteProvider.java
+++ b/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/IgniteProvider.java
@@ -23,27 +23,22 @@ import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.URL;
 import java.nio.channels.Channels;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
+import org.apache.ignite.mesos.ClusterProperties;
 
 /**
  * Class downloads and stores Ignite.
  */
 public class IgniteProvider {
     /** */
-    public static final String DOWNLOAD_LINK = "http://tiny.cc/updater/download_community.php";
+    public static final String DOWNLOAD_LINK = "http://www.ignite.run/download_ignite.php";
 
     /** */
-    public static final String DIRECT_DOWNLOAD_LINK = "http://www.gridgain.com/media/gridgain-community-fabric-";
+    public static final String DOWNLOAD_URL_PATTERN =
+        "http://www.us.apache.org/dist/ignite/%s/apache-ignite-fabric-%s-bin.zip";
 
     /** */
     private String downloadFolder;
 
-    /** */
-    private String latestVersion = null;
-
     /**
      * @param downloadFolder Folder with ignite.
      */
@@ -52,135 +47,50 @@ public class IgniteProvider {
     }
 
     /**
-     * @return Latest ignite version.
-     */
-    public String getIgnite() {
-        File folder = checkDownloadFolder();
-
-        if (latestVersion == null) {
-            List<String> files = findIgnites(folder);
-
-            if (!files.isEmpty()) {
-                if (files.size() == 1)
-                    latestVersion = parseVersion(files.get(0));
-                else
-                    latestVersion = parseVersion(Collections.max(files, new Comparator<String>() {
-                        @Override public int compare(String f1, String f2) {
-                            if (f1.equals(f2))
-                                return 0;
-
-                            String[] ver1 = parseVersion(f1).split("\\.");
-                            String[] ver2 = parseVersion(f2).split("\\.");
-
-                            if (Integer.valueOf(ver1[0]) >= Integer.valueOf(ver2[0])
-                                && Integer.valueOf(ver1[1]) >= Integer.valueOf(ver2[1])
-                                && Integer.valueOf(ver1[2]) >= Integer.valueOf(ver2[2]))
-
-                                return 1;
-                            else
-                                return -1;
-                        }
-                    }));
-            }
-        }
-
-        latestVersion = updateIgnite(latestVersion);
-
-        return "gridgain-community-fabric-" + latestVersion + ".zip";
-    }
-
-    /**
-     * @param folder Folder.
-     * @return Ignite archives.
+     * @param ver Ignite version.
+     * @throws IOException If downloading failed.
+     * @return Path to latest ignite.
      */
-    private List<String> findIgnites(File folder) {
-        String[] files = folder.list();
-
-        List<String> ignites = new ArrayList<>();
-
-        if (files != null) {
-            for (String fileName : files) {
-                if (fileName.contains("gridgain-community-fabric-") && fileName.endsWith(".zip"))
-                    ignites.add(fileName);
-            }
-        }
-
-        return ignites;
+    public String getIgnite(String ver) throws IOException {
+        return downloadIgnite(ver);
     }
 
     /**
-     * @param version Ignite version.
-     * @return Ignite.
-     */
-    public String getIgnite(String version) {
-        File folder = checkDownloadFolder();
-
-        String[] ignites = folder.list();
-
-        String ignite = null;
-
-        if (ignites != null) {
-            for (String fileName : ignites) {
-                if (fileName.equals("gridgain-community-fabric-" + version + ".zip"))
-                    ignite = fileName;
-            }
-        }
-
-        if (ignite != null)
-            return ignite;
-
-        return downloadIgnite(version);
-    }
-
-    /**
-     * @param currentVersion The current latest version.
-     * @return Current version if the current version is latest; new ignite version otherwise.
+     * @param ver Ignite version which will be downloaded. If {@code null} will download the latest ignite version.
+     * @throws IOException If downloading failed.
+     * @return Ignite archive.
      */
-    private String updateIgnite(String currentVersion) {
-        try {
-            URL url;
+    public String downloadIgnite(String ver) throws IOException {
+        URL url;
 
-            if (currentVersion == null)
-                url = new URL(DOWNLOAD_LINK);
-            else
-                url = new URL(DOWNLOAD_LINK + "?version=" + currentVersion);
+        if (ver.equals(ClusterProperties.DEFAULT_IGNITE_VERSION)) {
+            URL updateUrl = new URL(DOWNLOAD_LINK);
 
-            HttpURLConnection conn = (HttpURLConnection)url.openConnection();
+            HttpURLConnection conn = (HttpURLConnection)updateUrl.openConnection();
 
             int code = conn.getResponseCode();
 
-            if (code == 200) {
-                String redirectUrl = conn.getURL().toString();
-
-                checkDownloadFolder();
-
-                FileOutputStream outFile = new FileOutputStream(downloadFolder + "/" + fileName(redirectUrl));
-
-                outFile.getChannel().transferFrom(Channels.newChannel(conn.getInputStream()), 0, Long.MAX_VALUE);
-
-                outFile.close();
-
-                return parseVersion(redirectUrl);
-            }
-            else if (code == 304)
-                // This version is latest.
-                return currentVersion;
+            if (code == 200)
+                url = conn.getURL();
             else
-                throw new RuntimeException("Got unexpected response code. Response code: " + code);
-        }
-        catch (IOException e) {
-            throw new RuntimeException("Failed update ignite.", e);
+                throw new RuntimeException("Failed. Got unexpected response code. Response code: " + code);
         }
+        else
+            url = new URL(String.format(DOWNLOAD_URL_PATTERN, ver.replace("-incubating", ""), ver));
+
+        return downloadIgnite(url);
     }
 
     /**
-     * @param version The current latest version.
-     * @return Ignite archive.
+     * Downloads ignite by URL if this version wasn't downloaded before.
+     *
+     * @param url URL to Ignite.
+     * @return File name in
      */
-    public String downloadIgnite(String version) {
-        try {
-            URL url = new URL(DIRECT_DOWNLOAD_LINK + version + ".zip");
+    private String downloadIgnite(URL url) {
+        assert url != null;
 
+        try {
             HttpURLConnection conn = (HttpURLConnection)url.openConnection();
 
             int code = conn.getResponseCode();
@@ -190,6 +100,9 @@ public class IgniteProvider {
 
                 String fileName = fileName(url.toString());
 
+                if (fileExist(fileName))
+                    return fileName;
+
                 FileOutputStream outFile = new FileOutputStream(downloadFolder + fileName);
 
                 outFile.getChannel().transferFrom(Channels.newChannel(conn.getInputStream()), 0, Long.MAX_VALUE);
@@ -202,11 +115,23 @@ public class IgniteProvider {
                 throw new RuntimeException("Got unexpected response code. Response code: " + code);
         }
         catch (IOException e) {
-            throw new RuntimeException("Failed update ignite.", e);
+            throw new RuntimeException("Failed to download Ignite.", e);
         }
     }
 
     /**
+     * Checks that file exists.
+     *
+     * @param fileName File name.
+     * @return {@code True} if file exist otherwise {@code false}.
+     */
+    public boolean fileExist(String fileName) {
+        String pathToIgnite = downloadFolder + (downloadFolder.endsWith("/") ? "" : '/') + fileName;
+
+        return new File(pathToIgnite).exists();
+    }
+
+    /**
      * @return Download folder.
      */
     private File checkDownloadFolder() {
@@ -215,17 +140,10 @@ public class IgniteProvider {
         if (!file.exists())
             file.mkdirs();
 
-        return file;
-    }
-
-    /**
-     * @param url URL.
-     * @return Ignite version.
-     */
-    public static String parseVersion(String url) {
-        String[] split = url.split("-");
+        if (!file.exists())
+            throw new IllegalArgumentException("Failed to create working directory: " + downloadFolder);
 
-        return split[split.length - 1].replaceAll(".zip", "");
+        return file;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/acae0a5f/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/ResourceProvider.java
----------------------------------------------------------------------
diff --git a/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/ResourceProvider.java b/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/ResourceProvider.java
index 23945e1..965e9ad 100644
--- a/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/ResourceProvider.java
+++ b/modules/mesos/src/main/java/org/apache/ignite/mesos/resource/ResourceProvider.java
@@ -21,6 +21,8 @@ import java.io.File;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 import org.apache.ignite.mesos.ClusterProperties;
 
 import static org.apache.ignite.mesos.resource.ResourceHandler.CONFIG_PREFIX;
@@ -32,6 +34,9 @@ import static org.apache.ignite.mesos.resource.ResourceHandler.LIBS_PREFIX;
  * Provides path to user's libs and config file.
  */
 public class ResourceProvider {
+    /** */
+    private static final Logger log = Logger.getLogger(ResourceProvider.class.getSimpleName());
+
     /** Ignite url. */
     private String igniteUrl;
 
@@ -45,20 +50,35 @@ public class ResourceProvider {
     private String configName;
 
     /**
-     * @param properties Cluster properties.
+     * @param props Cluster properties.
      * @param provider Ignite provider.
      * @param baseUrl Base url.
      */
-    public void init(ClusterProperties properties, IgniteProvider provider, String baseUrl) {
-        // Downloading ignite.
-        if (properties.igniteVer().equals(ClusterProperties.DEFAULT_IGNITE_VERSION))
-            igniteUrl = baseUrl + IGNITE_PREFIX + provider.getIgnite();
-        else
-            igniteUrl = baseUrl + IGNITE_PREFIX + provider.getIgnite(properties.igniteVer());
+    public void init(ClusterProperties props, IgniteProvider provider, String baseUrl) {
+        if (props.ignitePackageUrl() == null && props.ignitePackagePath() == null) {
+            // Downloading ignite.
+            try {
+                igniteUrl = baseUrl + IGNITE_PREFIX + provider.getIgnite(props.igniteVer());
+            }
+            catch (Exception e) {
+                log.log(Level.SEVERE, "Failed to download Ignite [err={0}, ver={1}].\n" +
+                    "If application working behind NAT or Intranet and does not have access to external resources, " +
+                    "see IGNITE_PACKAGE_URL and IGNITE_PACKAGE_PATH properties.",
+                    new Object[]{e, props.igniteVer()});
+            }
+        }
+
+        if (props.ignitePackagePath() != null) {
+            if (provider.fileExist(props.ignitePackagePath()))
+                igniteUrl = baseUrl + IGNITE_PREFIX + props.ignitePackagePath();
+            else
+                throw new IllegalArgumentException("Failed. Could not find Ignite by path: "
+                    + props.ignitePackagePath());
+        }
 
         // Find all jar files into user folder.
-        if (properties.userLibs() != null && !properties.userLibs().isEmpty()) {
-            File libsDir = new File(properties.userLibs());
+        if (props.userLibs() != null && !props.userLibs().isEmpty()) {
+            File libsDir = new File(props.userLibs());
 
             List<String> libs = new ArrayList<>();
 
@@ -78,8 +98,8 @@ public class ResourceProvider {
         }
 
         // Set configuration url.
-        if (properties.igniteCfg() != null) {
-            File cfg = new File(properties.igniteCfg());
+        if (props.igniteCfg() != null) {
+            File cfg = new File(props.igniteCfg());
 
             if (cfg.isFile() && cfg.canRead()) {
                 configUrl = baseUrl + CONFIG_PREFIX + cfg.getName();