This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit acf3f80ebb2ddc9f502a778c8fbec36112343ba5
Author: Raffaele Marcello <marcelloraffa...@gmail.com>
AuthorDate: Tue Mar 9 19:49:37 2021 +0100

    CAMEL-15963 Create a Google Cloud Functions component
---
 components/camel-google-functions/ReadMe.txt       | 16 +++++--------
 .../GoogleCloudFunctionsEndpointUriFactory.java    |  2 +-
 .../google/functions/google-functions.json         |  2 +-
 .../src/main/docs/google-functions-component.adoc  | 26 +++++++++++-----------
 .../functions/GoogleCloudFunctionsComponent.java   |  5 -----
 .../functions/GoogleCloudFunctionsEndpoint.java    | 16 +++++--------
 .../functions/GoogleCloudFunctionsProducer.java    | 10 ++-------
 .../unit/GoogleCloudFunctionsComponentTest.java    |  3 ++-
 .../builder/endpoint/StaticEndpointBuilders.java   |  8 +++----
 ...GoogleCloudFunctionsEndpointBuilderFactory.java |  8 +++----
 10 files changed, 38 insertions(+), 58 deletions(-)

diff --git a/components/camel-google-functions/ReadMe.txt 
b/components/camel-google-functions/ReadMe.txt
index c9ad8d9..6aa6aa3 100644
--- a/components/camel-google-functions/ReadMe.txt
+++ b/components/camel-google-functions/ReadMe.txt
@@ -1,25 +1,21 @@
 # Camel Google Functions Component
-This component is based on the [google java functions 
library](https://github.com/googleapis/java-storage) that works as a client for 
the Google Cloud Storage.
+This component is based on the [google java functions 
library](https://github.com/googleapis/java-functions) that works as a client 
for the Google Cloud Functions.
 
 
-## Camel Google Storage Component testing
+## Camel Google Storage Functions testing
 
 The unit tests provided are somewhat limited.
-Due to the nature of the component, it needs to be tested against a google 
Storage instance because although there are some emulators
+Due to the nature of the component, it needs to be tested against a google 
Functions instance because although there are some emulators
 they doesn't cover all the functionalities.
 
 The tests are organized into two packages:
 * **Unit** : Standalone tests that can be conducted on their own
-* **Integration** : Tests against a Google Storage instance
-
-For the Unit tests has been extended the emulator 
[google-cloud-nio](https://github.com/googleapis/java-storage-nio/tree/master/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/testing)
-adding some functionalities (bucket creation and deletion). However there are 
still some unsupported operations.
-
+* **Integration** : Tests against a Google Functions instance
 
 ### Execution of integration tests
 
-To run the Google Storage client library, you must first set up authentication 
by creating a service account key.
-You can find more info at: 
[cloud.google.com/storage/docs/reference/libraries#setting_up_authentication](https://cloud.google.com/storage/docs/reference/libraries#setting_up_authentication).
+To run the Google Functions client library, you must first set up 
authentication by creating a service account key.
+You can find more info at: [Google Cloud 
Authentication](https://github.com/googleapis/google-cloud-java#authentication).
 
 When you have the **service account key** you can provide authentication 
credentials to your application code by setting the environment variable:
 
diff --git 
a/components/camel-google-functions/src/generated/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsEndpointUriFactory.java
 
b/components/camel-google-functions/src/generated/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsEndpointUriFactory.java
index f372af5..6180262 100644
--- 
a/components/camel-google-functions/src/generated/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsEndpointUriFactory.java
+++ 
b/components/camel-google-functions/src/generated/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsEndpointUriFactory.java
@@ -15,7 +15,7 @@ import org.apache.camel.spi.EndpointUriFactory;
  */
 public class GoogleCloudFunctionsEndpointUriFactory extends 
org.apache.camel.support.component.EndpointUriFactorySupport implements 
EndpointUriFactory {
 
-    private static final String BASE = ":name";
+    private static final String BASE = ":functionName";
 
     private static final Set<String> PROPERTY_NAMES;
     private static final Set<String> SECRET_PROPERTY_NAMES;
diff --git 
a/components/camel-google-functions/src/generated/resources/org/apache/camel/component/google/functions/google-functions.json
 
b/components/camel-google-functions/src/generated/resources/org/apache/camel/component/google/functions/google-functions.json
index 812d563..43eaa11 100644
--- 
a/components/camel-google-functions/src/generated/resources/org/apache/camel/component/google/functions/google-functions.json
+++ 
b/components/camel-google-functions/src/generated/resources/org/apache/camel/component/google/functions/google-functions.json
@@ -14,7 +14,7 @@
     "version": "3.9.0-SNAPSHOT",
     "scheme": "google-functions",
     "extendsScheme": "",
-    "syntax": "google-functions:name",
+    "syntax": "google-functions:functionName",
     "async": false,
     "api": false,
     "consumerOnly": false,
diff --git 
a/components/camel-google-functions/src/main/docs/google-functions-component.adoc
 
b/components/camel-google-functions/src/main/docs/google-functions-component.adoc
index 4606cad..530a4cd 100644
--- 
a/components/camel-google-functions/src/main/docs/google-functions-component.adoc
+++ 
b/components/camel-google-functions/src/main/docs/google-functions-component.adoc
@@ -2,7 +2,7 @@
 = GoogleCloudFunctions Component
 :docTitle: GoogleCloudFunctions
 :artifactId: camel-google-functions
-:description: Store and retrieve objects from Google Cloud Functions Service 
using the google-cloud-storage library.
+:description: Store and retrieve objects from Google Cloud Functions Service 
using the google-cloud-functions library.
 :since: 3.9
 :supportLevel: Preview
 :component-header: Only producer is supported
@@ -14,7 +14,7 @@ 
include::{cq-version}@camel-quarkus:ROOT:partial$reference/components/google-fun
 
 *{component-header}*
 
-The Google Storage component provides access to 
https://cloud.google.com/functions/[Google Cloud Functions] via
+The Google Functions component provides access to 
https://cloud.google.com/functions/[Google Cloud Functions] via
 the https://github.com/googleapis/java-functions[google java functions 
library].
 
 Maven users will need to add the following dependency to their pom.xml
@@ -69,8 +69,8 @@ For example in order to call the function `myCamelFunction` 
from the project `my
 
 [source,java]
 
--------------------------------------------------------------------------------
-from("google-functions://myCamelFunction?serviceAccountKey=/home/user/Downloads/my-key.json&project=myProject&location=us-central1&operation=callFunction")
-  .to("file:/var/downloaded");
+from("google-functions://myCamelFunction?project=myProject&location=us-central1&operation=callFunction&serviceAccountKey=/home/user/Downloads/my-key.json")
+  .to("direct:test");
 
--------------------------------------------------------------------------------
 
 
@@ -127,7 +127,7 @@ with the following path and query parameters:
 
 == Usage
 
-=== Message headers evaluated by the Google Storage Producer
+=== Message headers evaluated by the Google Functions Producer
 
 [width="100%",cols="10%,10%,80%",options="header",]
 |=======================================================================
@@ -158,7 +158,7 @@ with the following path and query parameters:
 
 |=======================================================================
 
-=== Message headers set by the Google Storage Producer
+=== Message headers set by the Google Functions Producer
 
 [width="100%",cols="10%,10%,80%",options="header",]
 |=======================================================================
@@ -191,14 +191,14 @@ with the following path and query parameters:
 | `CamelGoogleCloudStorageMediaLink` |`String` | The media link
 | `CamelGoogleCloudStorageMetageneration` | `String` | The metageneration of 
the object
 | `CamelGoogleCloudStorageContentLength` |`Long` |The content length of this 
object.
-| `CamelGoogleCloudStorageStorageClass` | `String` | The storage class of the 
object
+| `CamelGoogleCloudStorageStorageClass` | `String` | The functions class of 
the object
 | `CamelGoogleCloudStorageCreateTime` |`String` | The creation time of the 
object
 | `CamelGoogleCloudStorageLastUpdate` |`String` | The last update of the object
 |=======================================================================
 
-=== Google Storage Producer operations
+=== Google Functions Producer operations
 
-Google Storage component provides the following operation on the producer side:
+Google Functions component provides the following operation on the producer 
side:
 
 - copyObject
 - listObjects
@@ -212,17 +212,17 @@ If you don't specify an operation explicitly the producer 
will a file upload.
 
 === Advanced component configuration
 
-If you need to have more control over the `storageClient` instance 
configuration, you can create your own instance and refer to it in your Camel 
google-storage component configuration:
+If you need to have more control over the `functionsClient` instance 
configuration, you can create your own instance and refer to it in your Camel 
google-functions component configuration:
 
 [source,java]
 
--------------------------------------------------------------------------------
-from("google-functions://myCamelFunction?storageClient=#client")
+from("google-functions://myCamelFunction?functionsClient=#client")
 .to("mock:result");
 
--------------------------------------------------------------------------------
 
-=== Google Storage Producer Operation examples
+=== Google Functions Producer Operation examples
 
-- File Upload: This operation will upload a file to the Google Storage based 
on the body content
+- File Upload: This operation will upload a file to the Google Functions based 
on the body content
 
 [source,java]
 
--------------------------------------------------------------------------------
diff --git 
a/components/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsComponent.java
 
b/components/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsComponent.java
index 4319fc4..5dcdedc 100644
--- 
a/components/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsComponent.java
+++ 
b/components/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsComponent.java
@@ -23,14 +23,10 @@ import org.apache.camel.Endpoint;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.annotations.Component;
 import org.apache.camel.support.DefaultComponent;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 @Component("google-functions")
 public class GoogleCloudFunctionsComponent extends DefaultComponent {
 
-    private static final Logger LOG = 
LoggerFactory.getLogger(GoogleCloudFunctionsComponent.class);
-
     @Metadata
     private GoogleCloudFunctionsConfiguration configuration = new 
GoogleCloudFunctionsConfiguration();
 
@@ -52,7 +48,6 @@ public class GoogleCloudFunctionsComponent extends 
DefaultComponent {
 
         Endpoint endpoint = new GoogleCloudFunctionsEndpoint(uri, this, 
configuration);
         setProperties(endpoint, parameters);
-        LOG.info("configuration={}", configuration);
         return endpoint;
     }
 
diff --git 
a/components/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsEndpoint.java
 
b/components/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsEndpoint.java
index e74c9d7..d3016bd 100644
--- 
a/components/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsEndpoint.java
+++ 
b/components/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsEndpoint.java
@@ -31,8 +31,6 @@ import org.apache.camel.Producer;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.support.DefaultEndpoint;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * Store and retrieve objects from Google Cloud Functions Service using the 
google-cloud-storage library.
@@ -41,13 +39,11 @@ import org.slf4j.LoggerFactory;
  * behavior of Producer.
  */
 @UriEndpoint(firstVersion = "3.9.0", scheme = "google-functions", title = 
"GoogleCloudFunctions",
-             syntax = "google-functions:name", category = {
+             syntax = "google-functions:functionName", category = {
                      Category.CLOUD },
              producerOnly = true)
 public class GoogleCloudFunctionsEndpoint extends DefaultEndpoint {
 
-    private static final Logger LOG = 
LoggerFactory.getLogger(GoogleCloudFunctionsEndpoint.class);
-
     @UriParam
     private GoogleCloudFunctionsConfiguration configuration;
 
@@ -57,7 +53,6 @@ public class GoogleCloudFunctionsEndpoint extends 
DefaultEndpoint {
                                         GoogleCloudFunctionsConfiguration 
configuration) {
         super(uri, component);
         this.configuration = configuration;
-        LOG.info("uris={}, configuration={}", uri, configuration);
     }
 
     public Producer createProducer() throws Exception {
@@ -86,19 +81,18 @@ public class GoogleCloudFunctionsEndpoint extends 
DefaultEndpoint {
         if (configuration.getClient() != null) {
             cloudFunctionsClient = configuration.getClient();
         } else {
-
             if (!Strings.isNullOrEmpty(configuration.getServiceAccountKey())) {
                 Credentials myCredentials = ServiceAccountCredentials
                         .fromStream(new 
FileInputStream(configuration.getServiceAccountKey()));
                 CloudFunctionsServiceSettings settings = 
CloudFunctionsServiceSettings.newBuilder()
                         
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)).build();
                 cloudFunctionsClient = 
CloudFunctionsServiceClient.create(settings);
-
             } else {
-                // TODO remember to implement this
-                throw new RuntimeException("Not yet implmented");
+                //it needs to define the  environment variable 
GOOGLE_APPLICATION_CREDENTIALS with the service account file
+                //more info at 
https://cloud.google.com/docs/authentication/production
+                CloudFunctionsServiceSettings settings = 
CloudFunctionsServiceSettings.newBuilder().build();
+                cloudFunctionsClient = 
CloudFunctionsServiceClient.create(settings);
             }
-
         }
     }
 
diff --git 
a/components/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsProducer.java
 
b/components/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsProducer.java
index 3464705..663eb35 100644
--- 
a/components/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsProducer.java
+++ 
b/components/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsProducer.java
@@ -233,13 +233,7 @@ public class GoogleCloudFunctionsProducer extends 
DefaultProducer {
                 }
             }
         } else {
-            LocationName locationName = 
LocationName.of(getConfiguration().getProject(),
-                    getConfiguration().getLocation());
-            CreateFunctionRequest request = 
CreateFunctionRequest.newBuilder().setLocation(locationName.toString())
-                    .setFunction(CloudFunction.newBuilder().build()).build(); 
// TODO check if add function name
-            CloudFunction result = client.createFunctionAsync(request).get();
-            Message message = getMessageForResponse(exchange);
-            message.setBody(result);
+            throw new IllegalArgumentException("createFunction is supported 
only in pojo mode");
         }
     }
 
@@ -258,7 +252,7 @@ public class GoogleCloudFunctionsProducer extends 
DefaultProducer {
                 }
             }
         } else {
-            throw new IllegalArgumentException("updateFunction supported only 
in pojo mode");   // TODO check
+            throw new IllegalArgumentException("updateFunction is supported 
only in pojo mode");
         }
     }
 
diff --git 
a/components/camel-google-functions/src/test/java/org/apache/camel/component/google/functions/unit/GoogleCloudFunctionsComponentTest.java
 
b/components/camel-google-functions/src/test/java/org/apache/camel/component/google/functions/unit/GoogleCloudFunctionsComponentTest.java
index f478683..d9e94f9 100644
--- 
a/components/camel-google-functions/src/test/java/org/apache/camel/component/google/functions/unit/GoogleCloudFunctionsComponentTest.java
+++ 
b/components/camel-google-functions/src/test/java/org/apache/camel/component/google/functions/unit/GoogleCloudFunctionsComponentTest.java
@@ -64,7 +64,7 @@ public class GoogleCloudFunctionsComponentTest extends 
GoogleCloudFunctionsBaseT
 
     private String project = "project123";
     private String location = "location123";
-    private String functionName = "myCalmelFunction";
+    private String functionName = "myCamelFunction";
 
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
@@ -399,6 +399,7 @@ public class GoogleCloudFunctionsComponentTest extends 
GoogleCloudFunctionsBaseT
         assertEquals(locationName.toString(), actualRequest.getParent());
     }
 
+    @Disabled
     @Test
     public void createFunctionTest() throws Exception {
         CloudFunctionName cfName = CloudFunctionName.of(project, location, 
functionName);
diff --git 
a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/StaticEndpointBuilders.java
 
b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/StaticEndpointBuilders.java
index c86f34e..af7104a 100644
--- 
a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/StaticEndpointBuilders.java
+++ 
b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/StaticEndpointBuilders.java
@@ -5596,12 +5596,12 @@ public class StaticEndpointBuilders {
      * Since: 3.9
      * Maven coordinates: org.apache.camel:camel-google-functions
      * 
-     * Syntax: <code>google-functions:name</code>
+     * Syntax: <code>google-functions:functionName</code>
      * 
      * Path parameter: functionName (required)
      * Function name
      * 
-     * @param path name
+     * @param path functionName
      * @return the dsl builder
      */
     public static 
org.apache.camel.builder.endpoint.dsl.GoogleCloudFunctionsEndpointBuilderFactory.GoogleCloudFunctionsEndpointBuilder
 googleFunctions(
@@ -5617,14 +5617,14 @@ public class StaticEndpointBuilders {
      * Since: 3.9
      * Maven coordinates: org.apache.camel:camel-google-functions
      * 
-     * Syntax: <code>google-functions:name</code>
+     * Syntax: <code>google-functions:functionName</code>
      * 
      * Path parameter: functionName (required)
      * Function name
      * 
      * @param componentName to use a custom component name for the endpoint
      * instead of the default name
-     * @param path name
+     * @param path functionName
      * @return the dsl builder
      */
     public static 
org.apache.camel.builder.endpoint.dsl.GoogleCloudFunctionsEndpointBuilderFactory.GoogleCloudFunctionsEndpointBuilder
 googleFunctions(
diff --git 
a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/GoogleCloudFunctionsEndpointBuilderFactory.java
 
b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/GoogleCloudFunctionsEndpointBuilderFactory.java
index 2ab5f20..3a574ab 100644
--- 
a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/GoogleCloudFunctionsEndpointBuilderFactory.java
+++ 
b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/GoogleCloudFunctionsEndpointBuilderFactory.java
@@ -265,12 +265,12 @@ public interface 
GoogleCloudFunctionsEndpointBuilderFactory {
          * Since: 3.9
          * Maven coordinates: org.apache.camel:camel-google-functions
          * 
-         * Syntax: <code>google-functions:name</code>
+         * Syntax: <code>google-functions:functionName</code>
          * 
          * Path parameter: functionName (required)
          * Function name
          * 
-         * @param path name
+         * @param path functionName
          * @return the dsl builder
          */
         default GoogleCloudFunctionsEndpointBuilder googleFunctions(String 
path) {
@@ -285,14 +285,14 @@ public interface 
GoogleCloudFunctionsEndpointBuilderFactory {
          * Since: 3.9
          * Maven coordinates: org.apache.camel:camel-google-functions
          * 
-         * Syntax: <code>google-functions:name</code>
+         * Syntax: <code>google-functions:functionName</code>
          * 
          * Path parameter: functionName (required)
          * Function name
          * 
          * @param componentName to use a custom component name for the endpoint
          * instead of the default name
-         * @param path name
+         * @param path functionName
          * @return the dsl builder
          */
         default GoogleCloudFunctionsEndpointBuilder googleFunctions(

Reply via email to