You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2021/03/15 09:53:53 UTC

[GitHub] [camel] omarsmak commented on a change in pull request #5205: CAMEL-15963 Create a Google Cloud Functions component

omarsmak commented on a change in pull request #5205:
URL: https://github.com/apache/camel/pull/5205#discussion_r594168321



##########
File path: components/camel-google/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsComponent.java
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.camel.component.google.functions;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.annotations.Component;
+import org.apache.camel.support.DefaultComponent;
+
+@Component("google-functions")
+public class GoogleCloudFunctionsComponent extends DefaultComponent {
+
+    @Metadata
+    private GoogleCloudFunctionsConfiguration configuration = new GoogleCloudFunctionsConfiguration();
+
+    public GoogleCloudFunctionsComponent() {
+        super(null);

Review comment:
       is not needed, you can just remove `super(null)`

##########
File path: components/camel-google/camel-google-functions/pom.xml
##########
@@ -0,0 +1,144 @@
+<?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.
+
+-->
+<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/maven-v4_0_0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.camel</groupId>
+    <artifactId>camel-google-parent</artifactId>
+    <version>3.9.0-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>camel-google-functions</artifactId>
+  <packaging>jar</packaging>
+  <name>Camel :: Google Functions</name>
+  <description>Camel Component for Google Cloud Platform Functions</description>
+
+  <properties>
+    <firstVersion>3.9.0</firstVersion>
+    <google-cloud-functions-version>1.0.8</google-cloud-functions-version>
+  </properties>
+
+  <dependencyManagement>
+    <dependencies>
+      <!-- Override the android JDK 7 guava in libraries-bom -->
+      <dependency>
+        <groupId>com.google.guava</groupId>
+        <artifactId>guava</artifactId>
+        <version>${google-cloud-guava-version}</version>
+      </dependency>
+      <dependency>
+        <groupId>com.google.cloud</groupId>
+        <artifactId>google-cloud-functions-bom</artifactId>
+        <version>${google-cloud-functions-version}</version>
+        <type>pom</type>
+        <scope>import</scope>
+      </dependency>
+    </dependencies>
+  
+  </dependencyManagement>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-support</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>com.google.guava</groupId>
+      <artifactId>guava</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.google.cloud</groupId>
+      <artifactId>google-cloud-functions</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.google.api.grpc</groupId>
+      <artifactId>grpc-google-cloud-functions-v1</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>com.google.api</groupId>
+      <artifactId>gax-grpc</artifactId>
+      <classifier>testlib</classifier>
+      <version>1.62.0</version>

Review comment:
       this version as well should move to the parent pom

##########
File path: components/camel-google/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsEndpoint.java
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.camel.component.google.functions;
+
+import java.io.FileInputStream;
+
+import com.google.api.client.util.Strings;
+import com.google.api.gax.core.FixedCredentialsProvider;
+import com.google.auth.Credentials;
+import com.google.auth.oauth2.ServiceAccountCredentials;
+import com.google.cloud.functions.v1.CloudFunctionsServiceClient;
+import com.google.cloud.functions.v1.CloudFunctionsServiceSettings;
+import org.apache.camel.Category;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.support.DefaultEndpoint;
+
+/**
+ * Store and retrieve objects from Google Cloud Functions Service using the google-cloud-storage library.
+ * 
+ * Google Functions Endpoint definition represents a function within the GCP and contains configuration to customize the
+ * behavior of Producer.
+ */
+@UriEndpoint(firstVersion = "3.9.0", scheme = "google-functions", title = "GoogleCloudFunctions",
+             syntax = "google-functions:functionName", category = {
+                     Category.CLOUD },
+             producerOnly = true)
+public class GoogleCloudFunctionsEndpoint extends DefaultEndpoint {
+
+    @UriParam
+    private GoogleCloudFunctionsConfiguration configuration;
+
+    private CloudFunctionsServiceClient cloudFunctionsClient;
+
+    public GoogleCloudFunctionsEndpoint(String uri, GoogleCloudFunctionsComponent component,
+                                        GoogleCloudFunctionsConfiguration configuration) {
+        super(uri, component);
+        this.configuration = configuration;
+    }
+
+    public Producer createProducer() throws Exception {
+        return new GoogleCloudFunctionsProducer(this);
+    }
+
+    public Consumer createConsumer(Processor processor) throws Exception {
+        throw new UnsupportedOperationException(
+                "Cannot consume from the google-functions endpoint: " + getEndpointUri());
+    }
+
+    public GoogleCloudFunctionsConfiguration getConfiguration() {
+        return configuration;
+    }
+
+    /**
+     * Setup configuration
+     */
+    public void setConfiguration(GoogleCloudFunctionsConfiguration configuration) {
+        this.configuration = configuration;
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+        if (configuration.getClient() != null) {
+            cloudFunctionsClient = configuration.getClient();
+        } else {
+            if (!Strings.isNullOrEmpty(configuration.getServiceAccountKey())) {

Review comment:
       Can we move the chunk that creates the client into a factory or function?

##########
File path: components/camel-google/camel-google-functions/pom.xml
##########
@@ -0,0 +1,144 @@
+<?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.
+
+-->
+<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/maven-v4_0_0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.camel</groupId>
+    <artifactId>camel-google-parent</artifactId>
+    <version>3.9.0-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>camel-google-functions</artifactId>
+  <packaging>jar</packaging>
+  <name>Camel :: Google Functions</name>
+  <description>Camel Component for Google Cloud Platform Functions</description>
+
+  <properties>
+    <firstVersion>3.9.0</firstVersion>
+    <google-cloud-functions-version>1.0.8</google-cloud-functions-version>

Review comment:
       This should move to the parent pom

##########
File path: components/camel-google/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsProducer.java
##########
@@ -0,0 +1,330 @@
+/*
+ * 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.camel.component.google.functions;
+
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+
+import com.google.api.client.util.Lists;
+import com.google.api.gax.rpc.ApiException;
+import com.google.cloud.functions.v1.CallFunctionRequest;
+import com.google.cloud.functions.v1.CallFunctionResponse;
+import com.google.cloud.functions.v1.CloudFunction;
+import com.google.cloud.functions.v1.CloudFunctionName;
+import com.google.cloud.functions.v1.CloudFunctionsServiceClient;
+import com.google.cloud.functions.v1.CloudFunctionsServiceClient.ListFunctionsPagedResponse;
+import com.google.cloud.functions.v1.CreateFunctionRequest;
+import com.google.cloud.functions.v1.DeleteFunctionRequest;
+import com.google.cloud.functions.v1.GenerateDownloadUrlRequest;
+import com.google.cloud.functions.v1.GenerateDownloadUrlResponse;
+import com.google.cloud.functions.v1.GenerateUploadUrlRequest;
+import com.google.cloud.functions.v1.GenerateUploadUrlResponse;
+import com.google.cloud.functions.v1.HttpsTrigger;
+import com.google.cloud.functions.v1.ListFunctionsRequest;
+import com.google.cloud.functions.v1.LocationName;
+import com.google.cloud.functions.v1.UpdateFunctionRequest;
+import com.google.protobuf.Empty;
+import org.apache.camel.Exchange;
+import org.apache.camel.InvalidPayloadException;
+import org.apache.camel.Message;
+import org.apache.camel.support.DefaultProducer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The GoogleCloudFunctions producer.
+ */
+public class GoogleCloudFunctionsProducer extends DefaultProducer {
+    private static final Logger LOG = LoggerFactory.getLogger(GoogleCloudFunctionsProducer.class);
+
+    private GoogleCloudFunctionsEndpoint endpoint;
+
+    public GoogleCloudFunctionsProducer(GoogleCloudFunctionsEndpoint endpoint) {
+        super(endpoint);
+        this.endpoint = endpoint;
+    }
+
+    @Override
+    public void process(final Exchange exchange) throws Exception {
+        switch (determineOperation(exchange)) {
+            case listFunctions:
+                listFunctions(endpoint.getClient(), exchange);
+                break;
+            case getFunction:
+                getFunction(endpoint.getClient(), exchange);
+                break;
+            case callFunction:
+                callFunction(endpoint.getClient(), exchange);
+                break;
+            case generateDownloadUrl:
+                generateDownloadUrl(endpoint.getClient(), exchange);
+                break;
+            case generateUploadUrl:
+                generateUploadUrl(endpoint.getClient(), exchange);
+                break;
+            case createFunction:
+                createFunction(endpoint.getClient(), exchange);
+                break;
+            case updateFunction:
+                updateFunction(endpoint.getClient(), exchange);
+                break;
+            case deleteFunction:
+                deleteFunction(endpoint.getClient(), exchange);
+                break;
+
+            default:
+                throw new IllegalArgumentException("Unsupported operation");
+        }
+    }
+
+    private void listFunctions(CloudFunctionsServiceClient client, Exchange exchange) throws InvalidPayloadException {
+        if (getConfiguration().isPojoRequest()) {
+            Object payload = exchange.getIn().getMandatoryBody();
+            if (payload instanceof ListFunctionsRequest) {
+                ListFunctionsPagedResponse pagedListResponse;
+                try {
+                    pagedListResponse = client.listFunctions((ListFunctionsRequest) payload);
+                    List<CloudFunction> response = Lists.newArrayList(pagedListResponse.iterateAll());
+                    Message message = getMessageForResponse(exchange);
+                    message.setBody(response);
+                } catch (ApiException ae) {
+                    LOG.trace("listFunctions command returned the error code {}", ae.getStatusCode());
+                    throw ae;
+                }
+            }
+        } else {
+            ListFunctionsRequest request = ListFunctionsRequest.newBuilder()
+                    .setParent(LocationName.of(getConfiguration().getProject(), getConfiguration().getLocation())
+                            .toString())
+                    .setPageSize(883849137) // TODO check it
+                    .setPageToken("pageToken873572522").build();

Review comment:
       is this page token fixed?

##########
File path: components/camel-google/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsProducer.java
##########
@@ -0,0 +1,330 @@
+/*
+ * 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.camel.component.google.functions;
+
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+
+import com.google.api.client.util.Lists;
+import com.google.api.gax.rpc.ApiException;
+import com.google.cloud.functions.v1.CallFunctionRequest;
+import com.google.cloud.functions.v1.CallFunctionResponse;
+import com.google.cloud.functions.v1.CloudFunction;
+import com.google.cloud.functions.v1.CloudFunctionName;
+import com.google.cloud.functions.v1.CloudFunctionsServiceClient;
+import com.google.cloud.functions.v1.CloudFunctionsServiceClient.ListFunctionsPagedResponse;
+import com.google.cloud.functions.v1.CreateFunctionRequest;
+import com.google.cloud.functions.v1.DeleteFunctionRequest;
+import com.google.cloud.functions.v1.GenerateDownloadUrlRequest;
+import com.google.cloud.functions.v1.GenerateDownloadUrlResponse;
+import com.google.cloud.functions.v1.GenerateUploadUrlRequest;
+import com.google.cloud.functions.v1.GenerateUploadUrlResponse;
+import com.google.cloud.functions.v1.HttpsTrigger;
+import com.google.cloud.functions.v1.ListFunctionsRequest;
+import com.google.cloud.functions.v1.LocationName;
+import com.google.cloud.functions.v1.UpdateFunctionRequest;
+import com.google.protobuf.Empty;
+import org.apache.camel.Exchange;
+import org.apache.camel.InvalidPayloadException;
+import org.apache.camel.Message;
+import org.apache.camel.support.DefaultProducer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The GoogleCloudFunctions producer.
+ */
+public class GoogleCloudFunctionsProducer extends DefaultProducer {
+    private static final Logger LOG = LoggerFactory.getLogger(GoogleCloudFunctionsProducer.class);
+
+    private GoogleCloudFunctionsEndpoint endpoint;
+
+    public GoogleCloudFunctionsProducer(GoogleCloudFunctionsEndpoint endpoint) {
+        super(endpoint);
+        this.endpoint = endpoint;
+    }
+
+    @Override
+    public void process(final Exchange exchange) throws Exception {
+        switch (determineOperation(exchange)) {
+            case listFunctions:
+                listFunctions(endpoint.getClient(), exchange);
+                break;
+            case getFunction:
+                getFunction(endpoint.getClient(), exchange);
+                break;
+            case callFunction:
+                callFunction(endpoint.getClient(), exchange);
+                break;
+            case generateDownloadUrl:
+                generateDownloadUrl(endpoint.getClient(), exchange);
+                break;
+            case generateUploadUrl:
+                generateUploadUrl(endpoint.getClient(), exchange);
+                break;
+            case createFunction:
+                createFunction(endpoint.getClient(), exchange);
+                break;
+            case updateFunction:
+                updateFunction(endpoint.getClient(), exchange);
+                break;
+            case deleteFunction:
+                deleteFunction(endpoint.getClient(), exchange);
+                break;
+
+            default:
+                throw new IllegalArgumentException("Unsupported operation");
+        }
+    }
+
+    private void listFunctions(CloudFunctionsServiceClient client, Exchange exchange) throws InvalidPayloadException {
+        if (getConfiguration().isPojoRequest()) {
+            Object payload = exchange.getIn().getMandatoryBody();
+            if (payload instanceof ListFunctionsRequest) {
+                ListFunctionsPagedResponse pagedListResponse;
+                try {
+                    pagedListResponse = client.listFunctions((ListFunctionsRequest) payload);
+                    List<CloudFunction> response = Lists.newArrayList(pagedListResponse.iterateAll());
+                    Message message = getMessageForResponse(exchange);
+                    message.setBody(response);
+                } catch (ApiException ae) {
+                    LOG.trace("listFunctions command returned the error code {}", ae.getStatusCode());
+                    throw ae;
+                }
+            }
+        } else {
+            ListFunctionsRequest request = ListFunctionsRequest.newBuilder()
+                    .setParent(LocationName.of(getConfiguration().getProject(), getConfiguration().getLocation())
+                            .toString())
+                    .setPageSize(883849137) // TODO check it

Review comment:
       Can we move put this number into a constant?

##########
File path: components/camel-google/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsProducer.java
##########
@@ -0,0 +1,330 @@
+/*
+ * 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.camel.component.google.functions;
+
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+
+import com.google.api.client.util.Lists;
+import com.google.api.gax.rpc.ApiException;
+import com.google.cloud.functions.v1.CallFunctionRequest;
+import com.google.cloud.functions.v1.CallFunctionResponse;
+import com.google.cloud.functions.v1.CloudFunction;
+import com.google.cloud.functions.v1.CloudFunctionName;
+import com.google.cloud.functions.v1.CloudFunctionsServiceClient;
+import com.google.cloud.functions.v1.CloudFunctionsServiceClient.ListFunctionsPagedResponse;
+import com.google.cloud.functions.v1.CreateFunctionRequest;
+import com.google.cloud.functions.v1.DeleteFunctionRequest;
+import com.google.cloud.functions.v1.GenerateDownloadUrlRequest;
+import com.google.cloud.functions.v1.GenerateDownloadUrlResponse;
+import com.google.cloud.functions.v1.GenerateUploadUrlRequest;
+import com.google.cloud.functions.v1.GenerateUploadUrlResponse;
+import com.google.cloud.functions.v1.HttpsTrigger;
+import com.google.cloud.functions.v1.ListFunctionsRequest;
+import com.google.cloud.functions.v1.LocationName;
+import com.google.cloud.functions.v1.UpdateFunctionRequest;
+import com.google.protobuf.Empty;
+import org.apache.camel.Exchange;
+import org.apache.camel.InvalidPayloadException;
+import org.apache.camel.Message;
+import org.apache.camel.support.DefaultProducer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The GoogleCloudFunctions producer.
+ */
+public class GoogleCloudFunctionsProducer extends DefaultProducer {
+    private static final Logger LOG = LoggerFactory.getLogger(GoogleCloudFunctionsProducer.class);
+
+    private GoogleCloudFunctionsEndpoint endpoint;
+
+    public GoogleCloudFunctionsProducer(GoogleCloudFunctionsEndpoint endpoint) {
+        super(endpoint);
+        this.endpoint = endpoint;
+    }
+
+    @Override
+    public void process(final Exchange exchange) throws Exception {
+        switch (determineOperation(exchange)) {
+            case listFunctions:
+                listFunctions(endpoint.getClient(), exchange);
+                break;
+            case getFunction:
+                getFunction(endpoint.getClient(), exchange);
+                break;
+            case callFunction:
+                callFunction(endpoint.getClient(), exchange);
+                break;
+            case generateDownloadUrl:
+                generateDownloadUrl(endpoint.getClient(), exchange);
+                break;
+            case generateUploadUrl:
+                generateUploadUrl(endpoint.getClient(), exchange);
+                break;
+            case createFunction:
+                createFunction(endpoint.getClient(), exchange);
+                break;
+            case updateFunction:
+                updateFunction(endpoint.getClient(), exchange);
+                break;
+            case deleteFunction:
+                deleteFunction(endpoint.getClient(), exchange);
+                break;
+
+            default:
+                throw new IllegalArgumentException("Unsupported operation");
+        }
+    }
+
+    private void listFunctions(CloudFunctionsServiceClient client, Exchange exchange) throws InvalidPayloadException {
+        if (getConfiguration().isPojoRequest()) {
+            Object payload = exchange.getIn().getMandatoryBody();
+            if (payload instanceof ListFunctionsRequest) {
+                ListFunctionsPagedResponse pagedListResponse;
+                try {
+                    pagedListResponse = client.listFunctions((ListFunctionsRequest) payload);
+                    List<CloudFunction> response = Lists.newArrayList(pagedListResponse.iterateAll());
+                    Message message = getMessageForResponse(exchange);
+                    message.setBody(response);
+                } catch (ApiException ae) {
+                    LOG.trace("listFunctions command returned the error code {}", ae.getStatusCode());
+                    throw ae;
+                }
+            }
+        } else {
+            ListFunctionsRequest request = ListFunctionsRequest.newBuilder()
+                    .setParent(LocationName.of(getConfiguration().getProject(), getConfiguration().getLocation())
+                            .toString())
+                    .setPageSize(883849137) // TODO check it
+                    .setPageToken("pageToken873572522").build();
+            ListFunctionsPagedResponse pagedListResponse = client.listFunctions(request);
+            List<CloudFunction> response = Lists.newArrayList(pagedListResponse.iterateAll());
+            Message message = getMessageForResponse(exchange);
+            message.setBody(response);
+        }
+    }
+
+    private void getFunction(CloudFunctionsServiceClient client, Exchange exchange) throws InvalidPayloadException {
+        if (getConfiguration().isPojoRequest()) {

Review comment:
       I see in almost every function, duplicated code to get the response from the client, one with POJO and one from the configurations, since both are the same, can you please refactor these functions to remove the duplication code in order to reduce the maintenance overhead?

##########
File path: components/camel-google/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsProducer.java
##########
@@ -0,0 +1,330 @@
+/*
+ * 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.camel.component.google.functions;
+
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+
+import com.google.api.client.util.Lists;
+import com.google.api.gax.rpc.ApiException;
+import com.google.cloud.functions.v1.CallFunctionRequest;
+import com.google.cloud.functions.v1.CallFunctionResponse;
+import com.google.cloud.functions.v1.CloudFunction;
+import com.google.cloud.functions.v1.CloudFunctionName;
+import com.google.cloud.functions.v1.CloudFunctionsServiceClient;
+import com.google.cloud.functions.v1.CloudFunctionsServiceClient.ListFunctionsPagedResponse;
+import com.google.cloud.functions.v1.CreateFunctionRequest;
+import com.google.cloud.functions.v1.DeleteFunctionRequest;
+import com.google.cloud.functions.v1.GenerateDownloadUrlRequest;
+import com.google.cloud.functions.v1.GenerateDownloadUrlResponse;
+import com.google.cloud.functions.v1.GenerateUploadUrlRequest;
+import com.google.cloud.functions.v1.GenerateUploadUrlResponse;
+import com.google.cloud.functions.v1.HttpsTrigger;
+import com.google.cloud.functions.v1.ListFunctionsRequest;
+import com.google.cloud.functions.v1.LocationName;
+import com.google.cloud.functions.v1.UpdateFunctionRequest;
+import com.google.protobuf.Empty;
+import org.apache.camel.Exchange;
+import org.apache.camel.InvalidPayloadException;
+import org.apache.camel.Message;
+import org.apache.camel.support.DefaultProducer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The GoogleCloudFunctions producer.
+ */
+public class GoogleCloudFunctionsProducer extends DefaultProducer {
+    private static final Logger LOG = LoggerFactory.getLogger(GoogleCloudFunctionsProducer.class);
+
+    private GoogleCloudFunctionsEndpoint endpoint;
+
+    public GoogleCloudFunctionsProducer(GoogleCloudFunctionsEndpoint endpoint) {
+        super(endpoint);
+        this.endpoint = endpoint;
+    }
+
+    @Override
+    public void process(final Exchange exchange) throws Exception {
+        switch (determineOperation(exchange)) {
+            case listFunctions:
+                listFunctions(endpoint.getClient(), exchange);
+                break;
+            case getFunction:
+                getFunction(endpoint.getClient(), exchange);
+                break;
+            case callFunction:
+                callFunction(endpoint.getClient(), exchange);
+                break;
+            case generateDownloadUrl:
+                generateDownloadUrl(endpoint.getClient(), exchange);
+                break;
+            case generateUploadUrl:
+                generateUploadUrl(endpoint.getClient(), exchange);
+                break;
+            case createFunction:
+                createFunction(endpoint.getClient(), exchange);
+                break;
+            case updateFunction:
+                updateFunction(endpoint.getClient(), exchange);
+                break;
+            case deleteFunction:
+                deleteFunction(endpoint.getClient(), exchange);
+                break;
+
+            default:
+                throw new IllegalArgumentException("Unsupported operation");
+        }
+    }
+
+    private void listFunctions(CloudFunctionsServiceClient client, Exchange exchange) throws InvalidPayloadException {
+        if (getConfiguration().isPojoRequest()) {
+            Object payload = exchange.getIn().getMandatoryBody();
+            if (payload instanceof ListFunctionsRequest) {
+                ListFunctionsPagedResponse pagedListResponse;
+                try {
+                    pagedListResponse = client.listFunctions((ListFunctionsRequest) payload);
+                    List<CloudFunction> response = Lists.newArrayList(pagedListResponse.iterateAll());
+                    Message message = getMessageForResponse(exchange);
+                    message.setBody(response);
+                } catch (ApiException ae) {
+                    LOG.trace("listFunctions command returned the error code {}", ae.getStatusCode());
+                    throw ae;
+                }
+            }
+        } else {
+            ListFunctionsRequest request = ListFunctionsRequest.newBuilder()
+                    .setParent(LocationName.of(getConfiguration().getProject(), getConfiguration().getLocation())
+                            .toString())
+                    .setPageSize(883849137) // TODO check it
+                    .setPageToken("pageToken873572522").build();
+            ListFunctionsPagedResponse pagedListResponse = client.listFunctions(request);
+            List<CloudFunction> response = Lists.newArrayList(pagedListResponse.iterateAll());
+            Message message = getMessageForResponse(exchange);
+            message.setBody(response);
+        }
+    }
+
+    private void getFunction(CloudFunctionsServiceClient client, Exchange exchange) throws InvalidPayloadException {
+        if (getConfiguration().isPojoRequest()) {
+            Object payload = exchange.getIn().getMandatoryBody();

Review comment:
       You can do something like this `CloudFunctionName payload = exchange.getIn().getBody(CloudFunctionName.class);`

##########
File path: components/camel-google/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsEndpoint.java
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.camel.component.google.functions;
+
+import java.io.FileInputStream;
+
+import com.google.api.client.util.Strings;
+import com.google.api.gax.core.FixedCredentialsProvider;
+import com.google.auth.Credentials;
+import com.google.auth.oauth2.ServiceAccountCredentials;
+import com.google.cloud.functions.v1.CloudFunctionsServiceClient;
+import com.google.cloud.functions.v1.CloudFunctionsServiceSettings;
+import org.apache.camel.Category;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.support.DefaultEndpoint;
+
+/**
+ * Store and retrieve objects from Google Cloud Functions Service using the google-cloud-storage library.
+ * 
+ * Google Functions Endpoint definition represents a function within the GCP and contains configuration to customize the
+ * behavior of Producer.
+ */
+@UriEndpoint(firstVersion = "3.9.0", scheme = "google-functions", title = "GoogleCloudFunctions",
+             syntax = "google-functions:functionName", category = {
+                     Category.CLOUD },
+             producerOnly = true)
+public class GoogleCloudFunctionsEndpoint extends DefaultEndpoint {
+
+    @UriParam
+    private GoogleCloudFunctionsConfiguration configuration;
+
+    private CloudFunctionsServiceClient cloudFunctionsClient;
+
+    public GoogleCloudFunctionsEndpoint(String uri, GoogleCloudFunctionsComponent component,
+                                        GoogleCloudFunctionsConfiguration configuration) {
+        super(uri, component);
+        this.configuration = configuration;
+    }
+
+    public Producer createProducer() throws Exception {
+        return new GoogleCloudFunctionsProducer(this);
+    }
+
+    public Consumer createConsumer(Processor processor) throws Exception {
+        throw new UnsupportedOperationException(
+                "Cannot consume from the google-functions endpoint: " + getEndpointUri());
+    }
+
+    public GoogleCloudFunctionsConfiguration getConfiguration() {
+        return configuration;
+    }
+
+    /**
+     * Setup configuration
+     */
+    public void setConfiguration(GoogleCloudFunctionsConfiguration configuration) {
+        this.configuration = configuration;
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+        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 {
+                //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);
+            }
+        }
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        super.doStop();
+        if (configuration.getClient() == null) {

Review comment:
       ```suggestion
           if (configuration.getClient() == null && cloudFunctionsClient != null) {
   ```

##########
File path: components/camel-google/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsProducer.java
##########
@@ -0,0 +1,330 @@
+/*
+ * 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.camel.component.google.functions;
+
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+
+import com.google.api.client.util.Lists;
+import com.google.api.gax.rpc.ApiException;
+import com.google.cloud.functions.v1.CallFunctionRequest;
+import com.google.cloud.functions.v1.CallFunctionResponse;
+import com.google.cloud.functions.v1.CloudFunction;
+import com.google.cloud.functions.v1.CloudFunctionName;
+import com.google.cloud.functions.v1.CloudFunctionsServiceClient;
+import com.google.cloud.functions.v1.CloudFunctionsServiceClient.ListFunctionsPagedResponse;
+import com.google.cloud.functions.v1.CreateFunctionRequest;
+import com.google.cloud.functions.v1.DeleteFunctionRequest;
+import com.google.cloud.functions.v1.GenerateDownloadUrlRequest;
+import com.google.cloud.functions.v1.GenerateDownloadUrlResponse;
+import com.google.cloud.functions.v1.GenerateUploadUrlRequest;
+import com.google.cloud.functions.v1.GenerateUploadUrlResponse;
+import com.google.cloud.functions.v1.HttpsTrigger;
+import com.google.cloud.functions.v1.ListFunctionsRequest;
+import com.google.cloud.functions.v1.LocationName;
+import com.google.cloud.functions.v1.UpdateFunctionRequest;
+import com.google.protobuf.Empty;
+import org.apache.camel.Exchange;
+import org.apache.camel.InvalidPayloadException;
+import org.apache.camel.Message;
+import org.apache.camel.support.DefaultProducer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The GoogleCloudFunctions producer.
+ */
+public class GoogleCloudFunctionsProducer extends DefaultProducer {
+    private static final Logger LOG = LoggerFactory.getLogger(GoogleCloudFunctionsProducer.class);
+
+    private GoogleCloudFunctionsEndpoint endpoint;
+
+    public GoogleCloudFunctionsProducer(GoogleCloudFunctionsEndpoint endpoint) {
+        super(endpoint);
+        this.endpoint = endpoint;
+    }
+
+    @Override
+    public void process(final Exchange exchange) throws Exception {
+        switch (determineOperation(exchange)) {
+            case listFunctions:
+                listFunctions(endpoint.getClient(), exchange);
+                break;
+            case getFunction:
+                getFunction(endpoint.getClient(), exchange);
+                break;
+            case callFunction:
+                callFunction(endpoint.getClient(), exchange);
+                break;
+            case generateDownloadUrl:
+                generateDownloadUrl(endpoint.getClient(), exchange);
+                break;
+            case generateUploadUrl:
+                generateUploadUrl(endpoint.getClient(), exchange);
+                break;
+            case createFunction:
+                createFunction(endpoint.getClient(), exchange);
+                break;
+            case updateFunction:
+                updateFunction(endpoint.getClient(), exchange);
+                break;
+            case deleteFunction:
+                deleteFunction(endpoint.getClient(), exchange);
+                break;
+
+            default:
+                throw new IllegalArgumentException("Unsupported operation");
+        }
+    }
+
+    private void listFunctions(CloudFunctionsServiceClient client, Exchange exchange) throws InvalidPayloadException {
+        if (getConfiguration().isPojoRequest()) {
+            Object payload = exchange.getIn().getMandatoryBody();
+            if (payload instanceof ListFunctionsRequest) {
+                ListFunctionsPagedResponse pagedListResponse;
+                try {
+                    pagedListResponse = client.listFunctions((ListFunctionsRequest) payload);
+                    List<CloudFunction> response = Lists.newArrayList(pagedListResponse.iterateAll());
+                    Message message = getMessageForResponse(exchange);
+                    message.setBody(response);
+                } catch (ApiException ae) {
+                    LOG.trace("listFunctions command returned the error code {}", ae.getStatusCode());
+                    throw ae;
+                }
+            }
+        } else {
+            ListFunctionsRequest request = ListFunctionsRequest.newBuilder()
+                    .setParent(LocationName.of(getConfiguration().getProject(), getConfiguration().getLocation())
+                            .toString())
+                    .setPageSize(883849137) // TODO check it
+                    .setPageToken("pageToken873572522").build();
+            ListFunctionsPagedResponse pagedListResponse = client.listFunctions(request);
+            List<CloudFunction> response = Lists.newArrayList(pagedListResponse.iterateAll());
+            Message message = getMessageForResponse(exchange);
+            message.setBody(response);
+        }
+    }
+
+    private void getFunction(CloudFunctionsServiceClient client, Exchange exchange) throws InvalidPayloadException {
+        if (getConfiguration().isPojoRequest()) {
+            Object payload = exchange.getIn().getMandatoryBody();
+            if (payload instanceof CloudFunctionName) {
+                CloudFunction response;
+                try {
+                    response = client.getFunction((CloudFunctionName) payload);
+                } catch (ApiException ae) {
+                    LOG.trace("getFunction command returned the error code {}", ae.getStatusCode());
+                    throw ae;
+                }
+                Message message = getMessageForResponse(exchange);
+                message.setBody(response);
+            }
+        } else {
+            CloudFunctionName cfName = CloudFunctionName.of(getConfiguration().getProject(),
+                    getConfiguration().getLocation(), getConfiguration().getFunctionName());
+            CloudFunction response = client.getFunction(cfName);
+            Message message = getMessageForResponse(exchange);
+            message.setBody(response);
+        }
+    }
+
+    private void callFunction(CloudFunctionsServiceClient client, Exchange exchange) throws InvalidPayloadException {
+        if (getConfiguration().isPojoRequest()) {
+            Object payload = exchange.getIn().getMandatoryBody();
+            if (payload instanceof CallFunctionRequest) {
+                CallFunctionResponse response;
+                try {
+                    response = client.callFunction((CallFunctionRequest) payload);
+                    Message message = getMessageForResponse(exchange);
+                    message.setHeader(GoogleCloudFunctionsConstants.RESPONSE_OBJECT, response);
+                    message.setBody(response.getResult());
+                } catch (ApiException ae) {

Review comment:
       These exceptions that you log in every function, also the same function will be thrown in other duplicated code (e.g: https://github.com/apache/camel/pull/5205/files#diff-0cab0789896e74525b9f46a8445b841a9a8b2f108b6300c7a5edd970d9c47550R166), you don't need to log that? 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org