Github user joewitt commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1482#discussion_r100466820
  
    --- Diff: 
nifi-nar-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/AbstractGCPProcessor.java
 ---
    @@ -0,0 +1,118 @@
    +/*
    + * 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.nifi.processors.gcp;
    +
    +import com.google.auth.oauth2.GoogleCredentials;
    +import com.google.cloud.HttpServiceOptions;
    +import com.google.cloud.Service;
    +import com.google.common.collect.ImmutableList;
    +import org.apache.nifi.annotation.lifecycle.OnScheduled;
    +import org.apache.nifi.components.PropertyDescriptor;
    +import org.apache.nifi.processor.AbstractProcessor;
    +import org.apache.nifi.processor.ProcessContext;
    +import org.apache.nifi.processor.util.StandardValidators;
    +import 
org.apache.nifi.processors.gcp.credentials.service.GCPCredentialsService;
    +
    +import java.util.List;
    +
    +/**
    + * Abstract base class for gcp processors.
    + *
    + */
    +public abstract class AbstractGCPProcessor<
    +        CloudService extends Service<CloudServiceOptions>,
    +        CloudServiceRpc,
    +        CloudServiceOptions extends HttpServiceOptions<CloudService, 
CloudServiceRpc, CloudServiceOptions>> extends AbstractProcessor {
    +
    +    public static final PropertyDescriptor PROJECT_ID = new 
PropertyDescriptor
    +            .Builder().name("gcp-project-id")
    +            .displayName("Project ID")
    +            .description("Google Cloud Project ID")
    +            .expressionLanguageSupported(true)
    +            .required(true)
    +            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
    +            .build();
    +
    +    public static final PropertyDescriptor RETRY_COUNT = new 
PropertyDescriptor
    +            .Builder().name("gcp-retry-count")
    +            .displayName("Number of retries")
    +            .description("How many retry attempts should be made before 
routing to the failure relationship.")
    +            .defaultValue("6")
    +            .expressionLanguageSupported(true)
    +            .required(true)
    +            .addValidator(StandardValidators.INTEGER_VALIDATOR)
    +            .build();
    +
    +    /**
    +     * Links to the {@link GCPCredentialsService} which provides 
credentials for this particular processor.
    +     */
    +    public static final PropertyDescriptor 
GCP_CREDENTIALS_PROVIDER_SERVICE = new PropertyDescriptor.Builder()
    +            .name("gcp-credentials-provider-service")
    +            .name("GCP Credentials Provider Service")
    +            .description("The Controller Service used to obtain Google 
Cloud Platform credentials.")
    +            .required(true)
    +            .identifiesControllerService(GCPCredentialsService.class)
    +            .build();
    +
    +
    +    protected volatile CloudService cloudService;
    +
    +    protected CloudService getCloudService() {
    +        return cloudService;
    +    }
    +
    +    @Override
    +    public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
    +        return ImmutableList.of(
    +                GCP_CREDENTIALS_PROVIDER_SERVICE,
    +                PROJECT_ID,
    +                RETRY_COUNT
    +        );
    +    }
    +
    +
    +    /**
    +     * Retrieve credentials from the {@link GCPCredentialsService} 
attached to this processor.
    +     * @param context the process context provided on scheduling the 
processor.
    +     * @return GoogleCredentials for the processor to access.
    +     * @see  <a 
href="https://developers.google.com/api-client-library/java/google-api-java-client/reference/1.20.0/com/google/api/client/googleapis/auth/oauth2/GoogleCredential";>AuthCredentials</a>
    +     */
    +    private GoogleCredentials getGoogleCredentials(final ProcessContext 
context) {
    +        final GCPCredentialsService gcpCredentialsService =
    +                
context.getProperty(GCP_CREDENTIALS_PROVIDER_SERVICE).asControllerService(GCPCredentialsService.class);
    +        return gcpCredentialsService.getGoogleCredentials();
    +    }
    +
    +    /**
    +     * Assigns the cloud service client on scheduling.
    +     * @param context the process context provided on scheduling the 
processor.
    +     */
    +    @OnScheduled
    +    public void onScheduled(ProcessContext context) {
    --- End diff --
    
    It isn't clear to me just yet but as a thing to consider..  This 
'cloudService' instance being set means this cloud service object must be 
thread safe should these processors have more than one thread and if this 
service is like a connection then it may be better to lazily init during 
onTrigger calls so that it can be recovered if the connection drops.  Open 
connections can be killed during onUnscheduled.  
    
    What I'm suggesting here might not  matter if this object isn't what it 
seems in just scanning through the code.  I checked the google api for 
'getService()' to see if I could better understand what it was and it wasnt 
revealing.
    
    In any even this is a really substantive PR with a lot of well thought out 
areas and attention to details like LICENSE/NOTICE so big thanks to you.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to