ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject [07/27] incubator-ignite git commit: ignite-790: fixes, improvements, tests
Date Wed, 29 Apr 2015 12:57:49 GMT
ignite-790: fixes, improvements, tests


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

Branch: refs/heads/ignite-757
Commit: 79861b59bc5d025e56a55097be731422af1d6e35
Parents: cc08687
Author: Denis Magda <dmagda@gridgain.com>
Authored: Fri Apr 24 14:12:18 2015 +0300
Committer: Denis Magda <dmagda@gridgain.com>
Committed: Fri Apr 24 14:12:18 2015 +0300

----------------------------------------------------------------------
 modules/cloud/pom.xml                           | 53 +++++++++++
 .../cloud/TcpDiscoveryCloudNodesIpFinder.java   | 90 +++++++++++--------
 .../TcpDiscoveryCloudNodesIpFinderSelfTest.java | 92 ++++++++++++++++++++
 .../tcp/ipfinder/cloud/package-info.java        | 22 +++++
 .../ignite/testsuites/IgniteCloudTestSuite.java | 69 +++++++++++++++
 5 files changed, 289 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/79861b59/modules/cloud/pom.xml
----------------------------------------------------------------------
diff --git a/modules/cloud/pom.xml b/modules/cloud/pom.xml
index 61bdf22..a555dce 100644
--- a/modules/cloud/pom.xml
+++ b/modules/cloud/pom.xml
@@ -51,6 +51,24 @@
         </dependency>
 
         <dependency>
+            <groupId>org.apache.jclouds.labs</groupId>
+            <artifactId>google-compute-engine</artifactId>
+            <version>${jcloud.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.jclouds.labs</groupId>
+            <artifactId>docker</artifactId>
+            <version>${jcloud.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.jclouds.provider</groupId>
+            <artifactId>cloudsigma-zrh</artifactId>
+            <version>1.8.0</version>
+        </dependency>
+
+        <dependency>
             <groupId>org.apache.jclouds.driver</groupId>
             <artifactId>jclouds-sshj</artifactId>
             <version>${jcloud.version}</version>
@@ -62,6 +80,41 @@
             <version>${jcloud.version}</version>
         </dependency>
 
+        <dependency>
+            <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-core</artifactId>
+            <version>${project.version}</version>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-beans</artifactId>
+            <version>${spring.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-context</artifactId>
+            <version>${spring.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-core</artifactId>
+            <version>${spring.version}</version>
+            <scope>test</scope>
+        </dependency>
+
     </dependencies>
 
 </project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/79861b59/modules/cloud/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudNodesIpFinder.java
----------------------------------------------------------------------
diff --git a/modules/cloud/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudNodesIpFinder.java
b/modules/cloud/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudNodesIpFinder.java
index d542b6d..72b23d0 100644
--- a/modules/cloud/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudNodesIpFinder.java
+++ b/modules/cloud/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudNodesIpFinder.java
@@ -17,33 +17,29 @@
 
 package org.apache.ignite.spi.discovery.tcp.ipfinder.cloud;
 
-import com.google.common.base.Charsets;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.io.Files;
-import com.google.inject.Module;
-import org.apache.ignite.internal.IgniteInterruptedCheckedException;
-import org.apache.ignite.internal.util.tostring.GridToStringExclude;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.spi.IgniteSpiConfiguration;
-import org.apache.ignite.spi.IgniteSpiException;
-import org.apache.ignite.spi.discovery.tcp.TcpClientDiscoverySpi;
-import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
-import org.jclouds.ContextBuilder;
-import org.jclouds.compute.ComputeService;
-import org.jclouds.compute.ComputeServiceContext;
-import org.jclouds.compute.domain.ComputeMetadata;
-import org.jclouds.compute.domain.NodeMetadata;
-import org.jclouds.sshj.config.SshjSshClientModule;
+import com.google.common.base.*;
+import com.google.common.collect.*;
+import com.google.common.io.*;
+import com.google.inject.*;
+
+import org.jclouds.*;
+import org.jclouds.compute.*;
+import org.jclouds.compute.domain.*;
+import org.jclouds.sshj.config.*;
 import org.jclouds.logging.log4j.config.*;
 
-import java.io.File;
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.util.tostring.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.spi.*;
+import org.apache.ignite.spi.discovery.tcp.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
+
+import java.io.*;
+import java.net.*;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.*;
 
 /**
  * IP finder for automatic lookup of nodes running in a cloud.
@@ -80,10 +76,14 @@ public class TcpDiscoveryCloudNodesIpFinder extends TcpDiscoveryIpFinderAdapter
     /* Cloud specific identity (user name, email address, etc.). */
     private String identity;
 
-    /* Cloud specific credential (password, secrets key, etc.). */
+    /* Cloud specific credential (password, access key, etc.). */
     @GridToStringExclude
     private String credential;
 
+    /* Path to a cloud specific credential. */
+    @GridToStringExclude
+    private String credentialPath;
+
     /* Port to use to connect to nodes across a cluster. */
     private Integer discoveryPort;
 
@@ -168,7 +168,7 @@ public class TcpDiscoveryCloudNodesIpFinder extends TcpDiscoveryIpFinderAdapter
 
     /**
      * Sets credential that is used during authentication on the cloud.
-     * Depending on a cloud platform it can be a password, path to a secrets file, etc.
+     * Depending on a cloud platform it can be a password or access key.
      *
      * Refer to <a href="http://jclouds.apache.org/guides/">Apache jclouds guide</a>
to get concrete information on
      * what is used as an credential for a particular cloud platform.
@@ -181,6 +181,24 @@ public class TcpDiscoveryCloudNodesIpFinder extends TcpDiscoveryIpFinderAdapter
     }
 
     /**
+     * Sets the path to a credential that is used during authentication on the cloud.
+     *
+     * This method should be used when an access key or private key is stored in a plain
or PEM file without
+     * a passphrase.
+     * Content of the file, referred by @{code credentialPath}, is fully read and used as
a access key or private key
+     * during authentication.
+     *
+     * Refer to <a href="http://jclouds.apache.org/guides/">Apache jclouds guide</a>
to get concrete information on
+     * what is used as an credential for a particular cloud platform.
+     *
+     * @param credentialPath Path to the credential to use during authentication on the cloud.
+     */
+    @IgniteSpiConfiguration(optional = true)
+    public void setCredentialPath(String credentialPath) {
+        this.credentialPath = credentialPath;
+    }
+
+    /**
      * Sets the port that is used to discover other nodes running Apache Ignite in the cloud.
      * If doesn't set, a default port number is used.
      *
@@ -205,12 +223,11 @@ public class TcpDiscoveryCloudNodesIpFinder extends TcpDiscoveryIpFinderAdapter
                 if (identity == null)
                     throw new IgniteSpiException("Cloud identity is not set.");
 
-                if (provider.equals("google-compute-engine")) {
-                    if (credential == null)
-                        throw new IgniteSpiException("Cloud credential is not set.");
-                    else 
-                        credential = getPrivateKeyFromFile(credential);
-                }
+                if (credential != null && credentialPath != null)
+                    throw new IgniteSpiException("Both credential and credentialPath are
set. Use only one method.");
+
+                if (credentialPath != null)
+                    credential = getPrivateKeyFromFile();
 
                 try {
                     ContextBuilder ctxBuilder = ContextBuilder.newBuilder(provider);
@@ -246,15 +263,14 @@ public class TcpDiscoveryCloudNodesIpFinder extends TcpDiscoveryIpFinderAdapter
     /**
      * Retrieves a private key from the secrets file.
      *
-     * @param filePath Full path to the file.
      * @return Private key
      */
-    private String getPrivateKeyFromFile(String filePath) throws IgniteSpiException {
+    private String getPrivateKeyFromFile() throws IgniteSpiException {
         try {
-            return Files.toString(new File(filePath), Charsets.UTF_8);
+            return Files.toString(new File(credentialPath), Charsets.UTF_8);
         }
         catch (IOException e) {
-            throw new IgniteSpiException("Failed to retrieve a private key from the file:
" + filePath, e);
+            throw new IgniteSpiException("Failed to retrieve the private key from the file:
" + credentialPath, e);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/79861b59/modules/cloud/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudNodesIpFinderSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/cloud/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudNodesIpFinderSelfTest.java
b/modules/cloud/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudNodesIpFinderSelfTest.java
new file mode 100644
index 0000000..e63d73e
--- /dev/null
+++ b/modules/cloud/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudNodesIpFinderSelfTest.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.spi.discovery.tcp.ipfinder.cloud;
+
+import com.google.common.collect.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.spi.discovery.tcp.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
+import org.apache.ignite.testsuites.*;
+
+import java.net.*;
+import java.util.*;
+
+/**
+ * TcpDiscoveryCloudNodesIpFinder test.
+ */
+public class TcpDiscoveryCloudNodesIpFinderSelfTest extends
+    TcpDiscoveryIpFinderAbstractSelfTest<TcpDiscoveryCloudNodesIpFinder> {
+    /**
+     * Constructor.
+     *
+     * @throws Exception If any error occurs.
+     */
+    public TcpDiscoveryCloudNodesIpFinderSelfTest() throws Exception {
+        // No-op.
+    }
+
+    @Override protected void beforeTest() throws Exception {
+        // No-op.
+    }
+
+    /* {@inheritDoc} */
+    @Override protected TcpDiscoveryCloudNodesIpFinder ipFinder() throws Exception {
+        // No-op.
+        return null;
+    }
+
+    /* {@inheritDoc} */
+    @Override public void testIpFinder() throws Exception {
+        TcpDiscoveryCloudNodesIpFinder ipFinder;
+        String[] providers = {"google-compute-engine", "aws-ec2", "rackspace-cloudservers-us"};
+
+        for (String provider : providers) {
+            U.log(log, "Testing provider: " + provider);
+
+            ipFinder = new TcpDiscoveryCloudNodesIpFinder();
+            injectLogger(ipFinder);
+
+            ipFinder.setProvider(provider);
+            ipFinder.setIdentity(IgniteCloudTestSuite.getAccessKey(provider));
+
+            if (provider.equals("google-compute-engine"))
+                ipFinder.setCredentialPath(IgniteCloudTestSuite.getSecretKey(provider));
+            else {
+                ipFinder.setCredential(IgniteCloudTestSuite.getSecretKey(provider));
+            }
+
+            ipFinder.setDiscoveryPort(TcpDiscoverySpi.DFLT_PORT);
+
+            Collection<InetSocketAddress> addresses = ipFinder.getRegisteredAddresses();
+
+            assert addresses.size() > 0;
+
+            for (InetSocketAddress addr: addresses)
+                U.log(log, "Registered instance: " + addr.getAddress().getHostAddress() +
":" + addr.getPort());
+
+            ipFinder.unregisterAddresses(addresses);
+
+            assert addresses.size() == ipFinder.getRegisteredAddresses().size();
+
+            ipFinder.registerAddresses(ImmutableList.<InetSocketAddress>of(
+                new InetSocketAddress("192.168.0.1", TcpDiscoverySpi.DFLT_PORT)));
+
+            assert addresses.size() == ipFinder.getRegisteredAddresses().size();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/79861b59/modules/cloud/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/package-info.java
----------------------------------------------------------------------
diff --git a/modules/cloud/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/package-info.java
b/modules/cloud/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/package-info.java
new file mode 100644
index 0000000..05aeb1c
--- /dev/null
+++ b/modules/cloud/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * <!-- Package description. -->
+ * Contains internal tests or test related classes and interfaces.
+ */
+package org.apache.ignite.spi.discovery.tcp.ipfinder.cloud;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/79861b59/modules/cloud/src/test/java/org/apache/ignite/testsuites/IgniteCloudTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/cloud/src/test/java/org/apache/ignite/testsuites/IgniteCloudTestSuite.java
b/modules/cloud/src/test/java/org/apache/ignite/testsuites/IgniteCloudTestSuite.java
new file mode 100644
index 0000000..576e4f9
--- /dev/null
+++ b/modules/cloud/src/test/java/org/apache/ignite/testsuites/IgniteCloudTestSuite.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.testsuites;
+
+import junit.framework.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.cloud.TcpDiscoveryCloudNodesIpFinderSelfTest;
+
+/**
+ * Ignite Cloud integration test.
+ */
+public class IgniteCloudTestSuite extends TestSuite {
+    /**
+     * @return Test suite.
+     * @throws Exception Thrown in case of the failure.
+     */
+    public static TestSuite suite() throws Exception {
+        TestSuite suite = new TestSuite("Cloud Integration Test Suite");
+
+        // Cloud Nodes IP finder.
+        suite.addTest(new TestSuite(TcpDiscoveryCloudNodesIpFinderSelfTest.class));
+
+        return suite;
+    }
+
+    /**
+     * <a href="http://jclouds.apache.org/guides/google/">Service Account email<a/>
for GCE.
+     * <a href="http://jclouds.apache.org/guides/aws/">Access Key ID</a> for
Amazon.
+     * <a href="http://jclouds.apache.org/guides/rackspace/">Username</a> for
Rackspace.
+     *
+     * @return Access key.
+     */
+    public static String getAccessKey(String provider) {
+        String key = System.getenv("test." + provider + ".access.key");
+
+        assert key != null : "Environment variable 'test." + provider + ".access.key' is
not set";
+        
+        return key;
+    }
+
+    /**
+     * <a href="http://jclouds.apache.org/guides/google/">Path to pkcs12 file<a/>
for GCE.
+     * <a href="http://jclouds.apache.org/guides/aws/">Access Key</a> for Amazon.
+     * <a href="http://jclouds.apache.org/guides/rackspace/">API key</a> for
Rackspace.
+     *
+     * @return Secret key.
+     */
+    public static String getSecretKey(String provider) {
+        String key = System.getenv("test." + provider + ".secret.key");
+
+        assert key != null : "Environment variable 'test." + provider + ".secret.key' is
not set";
+
+        return key;
+    }
+}


Mime
View raw message