Repository: incubator-ignite Updated Branches: refs/heads/ignite-sprint-4 18b4c3941 -> ac399d916
ignite-734: start implementing google ip finder Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/4268e473 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/4268e473 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/4268e473 Branch: refs/heads/ignite-sprint-4 Commit: 4268e473f93c0b46b0bad5ad7b66bc86fcb47b0c Parents: dc455be Author: Denis Magda <dma...@gridgain.com> Authored: Tue Apr 21 19:27:46 2015 +0300 Committer: Denis Magda <dma...@gridgain.com> Committed: Tue Apr 21 19:27:46 2015 +0300 ---------------------------------------------------------------------- modules/gce/pom.xml | 52 ++++++ .../google/TcpDiscoveryGoogleCloudIpFinder.java | 161 +++++++++++++++++++ .../tcp/ipfinder/google/package-info.java | 22 +++ pom.xml | 1 + 4 files changed, 236 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4268e473/modules/gce/pom.xml ---------------------------------------------------------------------- diff --git a/modules/gce/pom.xml b/modules/gce/pom.xml new file mode 100644 index 0000000..1a11614 --- /dev/null +++ b/modules/gce/pom.xml @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + 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. +--> + +<!-- + POM file. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.ignite</groupId> + <artifactId>ignite-parent</artifactId> + <version>1</version> + <relativePath>../../parent</relativePath> + </parent> + + <artifactId>ignite-gce</artifactId> + <version>1.0.3-SNAPSHOT</version> + + <dependencies> + <dependency> + <groupId>org.apache.ignite</groupId> + <artifactId>ignite-core</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>com.google.api-client</groupId> + <artifactId>google-api-client</artifactId> + <version>1.19.1</version> + </dependency> + </dependencies> + +</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4268e473/modules/gce/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/google/TcpDiscoveryGoogleCloudIpFinder.java ---------------------------------------------------------------------- diff --git a/modules/gce/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/google/TcpDiscoveryGoogleCloudIpFinder.java b/modules/gce/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/google/TcpDiscoveryGoogleCloudIpFinder.java new file mode 100644 index 0000000..2d6f9d7 --- /dev/null +++ b/modules/gce/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/google/TcpDiscoveryGoogleCloudIpFinder.java @@ -0,0 +1,161 @@ +/* + * 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.google; + +import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; +import com.google.api.client.http.javanet.NetHttpTransport; +import org.apache.ignite.*; +import org.apache.ignite.resources.*; +import org.apache.ignite.spi.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.*; + +import com.google.api.client.auth.oauth2.*; +import com.google.api.client.googleapis.auth.oauth2.*; +import com.google.api.client.json.jackson2.*; + +import java.io.*; +import java.net.*; +import java.security.GeneralSecurityException; +import java.util.*; + +/** + * Google Cloud Storage based IP finder. + * + * TODO: complete + */ +public class TcpDiscoveryGoogleCloudIpFinder extends TcpDiscoveryIpFinderAdapter { + /** Grid logger. */ + @LoggerResource + private IgniteLogger log; + + /* Google Cloud Platform's project name.*/ + private String projectName; + + /* Google Cloud Platform's bucket name. */ + private String bucketName; + + /* Google Cloud Platform's secret file name. */ + private String secretsFileName; + + /* Google HTTP transport. */ + private NetHttpTransport httpTransport; + + public TcpDiscoveryGoogleCloudIpFinder() { + setShared(true); + } + + /** {@inheritDoc} */ + @Override public Collection<InetSocketAddress> getRegisteredAddresses() throws IgniteSpiException { + return null; + } + + /** {@inheritDoc} */ + @Override public void registerAddresses(Collection<InetSocketAddress> addrs) throws IgniteSpiException { + + } + + /** {@inheritDoc} */ + @Override public void unregisterAddresses(Collection<InetSocketAddress> addrs) throws IgniteSpiException { + + } + + /** + * Sets Google Cloud Platforms project name. + * The project name is the one which your Google VM instances, Cloud Storage, etc. belong to. + * <p> + * For details refer to Google Cloud Platform API reference. + * + * @param projectName Project name. + */ + @IgniteSpiConfiguration(optional = false) + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + /** + * Sets Google Cloud Platforms bucket name. + * + * @param bucketName Bucket name. + */ + @IgniteSpiConfiguration(optional = false) + public void setBucketName(String bucketName) { + this.bucketName = bucketName; + } + + /** + * File name of a client secrets file that is used to authenticate with Google Cloud Platform. + * Client secrets (JSON) file can be created and downloaded from the Google Developers Console. + * Note that the file must correspond to a Service Account. + * <p> + * For details refer to Google Cloud Platform Documentation. + * + * @param secretsFileName Client secrets file name. + */ + @IgniteSpiConfiguration(optional = false) + public void setSecretsFileName(String secretsFileName) { + this.secretsFileName = secretsFileName; + } + + /** + * + */ + private AuthorizationCodeInstalledApp Credential authorize() throws IgniteSpiException { + GoogleClientSecrets clientSecrets = null; + + try { + clientSecrets = GoogleClientSecrets.load(JacksonFactory.getDefaultInstance(), + new InputStreamReader(new FileInputStream(new File(secretsFileName)))); + + if (clientSecrets.getDetails().getClientId() == null || + clientSecrets.getDetails().getClientSecret() == null) + throw new IgniteSpiException("Client secrets file is not well formed."); + + } catch (Exception e) { + throw new IgniteSpiException("Failed to load client secrets JSON file.", e); + } + + try { + httpTransport = GoogleNetHttpTransport.newTrustedTransport(); + } catch (GeneralSecurityException | IOException e ) { + throw new IgniteSpiException(e); + } + + // Set up authorization code flow. + // Ask for only the permissions you need. Asking for more permissions will + // reduce the number of users who finish the process for giving you access + // to their accounts. It will also increase the amount of effort you will + // have to spend explaining to users what you are doing with their data. + // Here we are listing all of the available scopes. You should remove scopes + // that you are not actually using. + Set<String> scopes = new HashSet<String>(); + scopes.add(StorageScopes.DEVSTORAGE_FULL_CONTROL); + scopes.add(StorageScopes.DEVSTORAGE_READ_ONLY); + scopes.add(StorageScopes.DEVSTORAGE_READ_WRITE); + + GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder( + httpTransport, JSON_FACTORY, clientSecrets, scopes) + .setDataStoreFactory(dataStoreFactory) + .build(); + + GooglePromtReceiver + // Authorize. + VerificationCodeReceiver receiver = + AUTH_LOCAL_WEBSERVER ? new LocalServerReceiver() : new GooglePromptReceiver(); + return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user"); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4268e473/modules/gce/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/google/package-info.java ---------------------------------------------------------------------- diff --git a/modules/gce/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/google/package-info.java b/modules/gce/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/google/package-info.java new file mode 100644 index 0000000..fcf00b4 --- /dev/null +++ b/modules/gce/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/google/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 Google Cloud Storage IP finder. + */ +package org.apache.ignite.spi.discovery.tcp.ipfinder.google; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4268e473/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index c6394fd..de667ed 100644 --- a/pom.xml +++ b/pom.xml @@ -75,6 +75,7 @@ <module>modules/jcl</module> <module>modules/schema-import</module> <module>modules/codegen</module> + <module>modules/gce</module> </modules> <profiles>