merge from ignite-1000
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/f8a87769 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/f8a87769 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/f8a87769 Branch: refs/heads/ignite-gg-10249 Commit: f8a877691181063199a5d476a036dfb428118ea5 Parents: 57957d9 Author: Denis Magda <dma...@gridgain.com> Authored: Tue Jun 9 09:02:00 2015 +0300 Committer: Denis Magda <dma...@gridgain.com> Committed: Tue Jun 9 09:02:00 2015 +0300 ---------------------------------------------------------------------- .../cloud/TcpDiscoveryCloudIpFinder.java | 25 +++++++++++++------- .../TcpDiscoveryCloudIpFinderSelfTest.java | 3 +-- 2 files changed, 18 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f8a87769/modules/cloud/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinder.java ---------------------------------------------------------------------- diff --git a/modules/cloud/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinder.java b/modules/cloud/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinder.java index 2637742..7555b16 100644 --- a/modules/cloud/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinder.java +++ b/modules/cloud/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinder.java @@ -30,6 +30,7 @@ import org.jclouds.*; import org.jclouds.compute.*; import org.jclouds.compute.domain.*; import org.jclouds.domain.*; +import org.jclouds.googlecloud.*; import org.jclouds.location.reference.*; import java.io.*; @@ -97,7 +98,7 @@ import java.util.concurrent.atomic.*; * <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.cloud.TcpDiscoveryCloudIpFinder"/> * <property name="provider" value="google-compute-engine"/> * <property name="identity" value="your_service_account_email"/> - * <property name="credentialPath" value="path_to_pem_file"/> + * <property name="credentialPath" value="path_to_json_key"/> * <property name="zones"> * <list> * <value>us-central1-a</value> @@ -253,8 +254,7 @@ public class TcpDiscoveryCloudIpFinder 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. + * This method should be used when an access key or private key is stored in a file. * Content of the file, referred by @{code credentialPath}, is fully read and used as a access key or private key * during authentication. * @@ -322,7 +322,7 @@ public class TcpDiscoveryCloudIpFinder extends TcpDiscoveryIpFinderAdapter { throw new IgniteSpiException("Both credential and credentialPath are set. Use only one method."); if (credentialPath != null) - credential = getPrivateKeyFromFile(); + credential = getCredentialFromFile(); try { ContextBuilder ctxBuilder = ContextBuilder.newBuilder(provider); @@ -398,13 +398,22 @@ public class TcpDiscoveryCloudIpFinder extends TcpDiscoveryIpFinderAdapter { } /** - * Retrieves a private key from the secrets file. + * Reads credential info from {@link #credentialPath} and returns in a string format. * - * @return Private key + * @return Credential in {@code String} representation. + * @throws IgniteSpiException In case of error. */ - private String getPrivateKeyFromFile() throws IgniteSpiException { + private String getCredentialFromFile() throws IgniteSpiException { try { - return Files.toString(new File(credentialPath), Charsets.UTF_8); + String fileContents = Files.toString(new File(credentialPath), Charsets.UTF_8); + + if (provider.equals("google-compute-engine")) { + Supplier<Credentials> credentialSupplier = new GoogleCredentialsFromJson(fileContents); + + return credentialSupplier.get().credential; + } + + return fileContents; } catch (IOException 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/f8a87769/modules/cloud/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinderSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/cloud/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinderSelfTest.java b/modules/cloud/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinderSelfTest.java index aba0760..d1d945f 100644 --- a/modules/cloud/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinderSelfTest.java +++ b/modules/cloud/src/test/java/org/apache/ignite/spi/discovery/tcp/ipfinder/cloud/TcpDiscoveryCloudIpFinderSelfTest.java @@ -101,9 +101,8 @@ public class TcpDiscoveryCloudIpFinderSelfTest extends if (provider.equals("google-compute-engine")) ipFinder.setCredentialPath(IgniteCloudTestSuite.getSecretKey(provider)); - else { + else ipFinder.setCredential(IgniteCloudTestSuite.getSecretKey(provider)); - } Collection<InetSocketAddress> addresses = ipFinder.getRegisteredAddresses();