Google Cloud Platform

GCP Source Configuration

The Google Cloud Platform Source allows you to load files from within a Google Cloud Platform (GCP) Container. The GCP Source can be configured as a Fetching or Listening source.

Application properties

# General Cloud Source Properties
cloud.fetch.thread=

# Google Cloud Platform Source Properties
google.container=
google.root_directory=
local.root_directory=

If using a Listening Source, the pollingDelay property is required. This property defines how frequently we should check if a file has been modified.

pollingDelay=Miliseconds

Maven Dependency

We first must ensure we are importing the correct dependency. Your pom should have:

    <!-- For Google-Cloud-Platform CSV Source -->
    <dependency>
        <groupId>com.activeviam.io</groupId>
        <artifactId>data-connectors-gcp</artifactId>
        <version>${dataconnectors.version}</version>
    </dependency>

Channel Configuration

For details on channel configuration, see the Channel Configuration section in the Local CSV topic.

Source Configuration

To load from Azure Blob storage, an GcpCsvScopedFetchSource or GcpCsvScopedListenSource source needs to be constructed. This source contains cloud specific topics of type CsvCloudScopedFetchTopic or CsvCloudScopedFetchTopic. One Topic needs to be created for each fileMatcher and target datastore. A few additional beans are also created to establish connectivity with remote storage. The connectivity details for GCP Container are provided via application properties.

Below is an example for a Fetching Source:

@Value("${google.container}")
protected String gcpContainer;

@Value("${google.root_directory}")
protected String gcpRootDirectory;

@Value("${cloud.fetch.thread:4}")
protected String gcpFetchThreads;

public ICSVSource<ICloudEntityPath<Blob>> createGcpSource() {
    //
    // Configure Gcp Source Props
    //
    final Properties sourceProps = new Properties();
    // add source properties ...
    sourceProps.put(ACsvScopedSource.PROP__SOURCE_NAME, "Gcp-CSV-Source");
    ICSVSource<ICloudEntityPath<Blob>> gcpSource = new GcpCsvScopedFetchSource(sourceProps);

    //
    // Add topics
    //
    gcpSource.addTopic(
            createDirectoryTopic(
                    "Trade_Topic",
                    "/data",
                    "glob:**/*trades*.csv",
                    gcpSource.createParserConfiguration(generateTradeCsvFileds(), NB_HEADER_LINES_TO_SKIP)
            )
    );

    return gcpSource;
}

protected ICSVTopic<ICloudEntityPath<Blob>> createDirectoryTopic(String topic, String subdirectory, String pathMatcherSyntaxAndPattern, ICSVParserConfiguration parserConfig) {
    // Default directory to the root GCP directory
    ICloudDirectory<Blob> cloudDirectory = rootDirectory();

    // Check if subdirectory contains a file separator, remove if so.
    if (!subdirectory.isEmpty()) {
        if ((subdirectory.toCharArray()[0] == '\\') || (subdirectory.toCharArray()[0] == '/')) {
            subdirectory = subdirectory.substring(1);
        }
        cloudDirectory = cloudDirectory.getSubDirectory(subdirectory);
    }

    // Modify pathMatcher into a Regular Expression.
    pathMatcherSyntaxAndPattern = pathMatcherSyntaxAndPattern.replace("**", "*");
    pathMatcherSyntaxAndPattern = pathMatcherSyntaxAndPattern.replace("*", ".*");
    pathMatcherSyntaxAndPattern = pathMatcherSyntaxAndPattern.replace("glob:", "");
    pathMatcherSyntaxAndPattern = pathMatcherSyntaxAndPattern.replace("{", "(");
    pathMatcherSyntaxAndPattern = pathMatcherSyntaxAndPattern.replace("}", ")");
    pathMatcherSyntaxAndPattern = pathMatcherSyntaxAndPattern.replace(",", "|");

    // File is named after the CobDate.
    FilesScopedFetchTopic.FetchScopeToFileScanParametersConverter converter = new FilesScopedFetchTopic.FetchScopeToFileScanParametersConverter(DataLoadControllerRestService.SCOPE_KEY__COB_DATE);

    return new CsvCloudScopedFetchTopic<>(
            topic,
            cloudDirectory,
            dataProviderFactory(),
            pathMatcherSyntaxAndPattern,
            converter,
            parserConfig,
            "",
            null);
}

@Bean
public ICloudDirectory<Blob> rootDirectory() {
    return new GoogleCloudDirectory(client(), env.getRequiredProperty(gcpContainer),
            env.getRequiredProperty(gcpRootDirectory));
}

@Bean
public Storage client() {
    return StorageOptions.getDefaultInstance().getService();
}

@Bean
public ICloudCsvDataProviderFactory<Blob> dataProviderFactory() {
    //the maximum number of threads that will download in parallel parts of an entity
    //the maximum number of threads that will download in parallel parts of an entity
    String cloudFetchThread = env.getProperty(gcpFetchThreads, "10");
    return new GoogleCsvDataProviderFactory(new CloudFetchingConfig(Integer.parseInt(cloudFetchThread) ));
}

Topic Configuration

The GCP Source consists of one or many Topics of type CsvCloudScopedFetchTopic or CsvCloudScopedListenTopic for Fetch or Listen Sources respectively. Fetch and Listen Topics cannot be mixed with opposite Fetch or Listen sources. The Topic name must be globally unique (to all other Topics). The CSV Cloud Topic’s consist of the following parameters:

Topic Parameter Description
name Name of this topic. Must be globally unique among all Topics
rootDirectoryPath Base directory to apply pathMatcher to within the GCP Container
GoogleCsvDataProviderFactory An instance of GoogleCsvDataProviderFactory
regex Regex pattern to be used to match files. Similar to a PathMatcher.
fetchScopeToFileScanParametersConverter Function to use Scope keys to an IFileScanParameters to scan files to load. Can use provided CsvFilesScopedFetchTopic.ScopeToFileScanParametersConverter
csvParserConfiguration ICSVParserConfiguration for CSV file Column Names, number of lines to skip, etc. Can use GcpCsvScopedFetchSource.createParserConfiguration(...)
fileTaskPluginKey Optional Plugin Key of IFileTask to handle processing of CSV file.
extraProperties Can be null, no required additional Properties
Topic Parameter Description
topic Name of this topic. Must be globally unique among all Topics
pathMatcher String regex to match file paths for this topic
GoogleCsvDataProviderFactory An instance of GoogleCsvDataProviderFactory
rootDirectoryPath Base directory to apply pathMatcher to within the GCP Container
scopeToFileScanParametersConverter Function to use Scope keys to an IFileScanParameters to scan files to load. Can use provided CsvFilesScopedListenTopic.ScopeToFileScanParametersConverter
csvParserConfiguration ICSVParserConfiguration for CSV file Column Names, number of lines to skip, etc. Can use GcpCsvScopedListenSource.createParserConfiguration(...)
extraProperties Can contain optional property “pollingDelay” describing millisecond pause between checks for CSV file changes. Default is 500

Java Topic properties:

public CsvCloudScopedFetchTopic(
    String name,
    ICloudDirectory<E> rootDirectoryPath,
    ICloudCsvDataProviderFactory<E> providerFactory,
    String regex,
    IFilesScopedFetchTopic.IScopeToFileScanParametersConverter fetchScopeToFileScanParametersConverter,
    ICSVParserConfiguration csvParserConfiguration,
    String fileTaskPluginKey,
    Properties extraProperties)
public CsvCloudScopedListenTopic(
    String topic,
    String pathMatcher,
    ICloudCsvDataProviderFactory<E> providerFactory,
    ICloudDirectory<E> rootDirectoryPath,
    IFilesScopedTopic.IScopeToFileScanParametersConverter scopeToFileScanParametersConverter,
    ICSVParserConfiguration csvParserConfiguration,
    Properties extraProperties)
search.js