All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.axual.connect.plugins.adls.gen2.authentication.ServiceClientProvider Maven / Gradle / Ivy

There is a newer version: 1.2.2
Show newest version
package io.axual.connect.plugins.adls.gen2.authentication;

/*-
 * ========================LICENSE_START=================================
 * Azure Data Lake Storage Gen2 Sink Connector for Kafka Connect
 * %%
 * Copyright (C) 2021 Axual B.V.
 * %%
 * Licensed 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.
 * =========================LICENSE_END==================================
 */

import com.azure.core.http.policy.HttpLogDetailLevel;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.storage.common.policy.RequestRetryOptions;
import com.azure.storage.common.policy.RetryPolicyType;
import com.azure.storage.file.datalake.DataLakeServiceClient;
import com.azure.storage.file.datalake.DataLakeServiceClientBuilder;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.axual.connect.plugins.adls.gen2.AdlsGen2SinkConfig;

public abstract class ServiceClientProvider {
    private static final Logger LOG = LoggerFactory.getLogger(ServiceClientProvider.class);
    protected final AdlsGen2SinkConfig config;
    protected final DataLakeServiceClientBuilder serviceClientBuilder;

    protected ServiceClientProvider(AdlsGen2SinkConfig config) {
        this.config = config;
        this.serviceClientBuilder = new DataLakeServiceClientBuilder();
    }

    // used for injecting mocks
    protected ServiceClientProvider(AdlsGen2SinkConfig config, DataLakeServiceClientBuilder serviceClientBuilder) {
        this.config = config;
        this.serviceClientBuilder = serviceClientBuilder;
    }

    public final DataLakeServiceClient create(){
        LOG.debug("Creating Azure DataLake Service Client");
        HttpLogOptions logOptions = new HttpLogOptions();
        logOptions.setLogLevel(HttpLogDetailLevel.NONE);
        logOptions.setPrettyPrintBody(true);
        
        return addCredentials(serviceClientBuilder)
                .httpLogOptions(logOptions)
                .retryOptions(getRequestRetryOptions())
                .endpoint(config.getEndpoint())
                .buildClient();
    }
    
    public abstract DataLakeServiceClientBuilder addCredentials(DataLakeServiceClientBuilder builder);

    protected RequestRetryOptions getRequestRetryOptions() {
        return new RequestRetryOptions(
                config.getAdlsClientUseExponential() ? RetryPolicyType.EXPONENTIAL : RetryPolicyType.FIXED,
                config.getAdlsClientRetryCount(),
                config.getAdlsClientTimeout(),
                config.getAdlsClientRetryInterval(),
                config.getAdlsClientMaximumRetryInterval(), null);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy