<commit_before>/*
 * Copyright 2015 Netflix, Inc.
 *
 * 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.
 */

package com.netflix.spinnaker.orca.clouddriver.config;

import static retrofit.Endpoints.newFixedEndpoint;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.jakewharton.retrofit.Ok3Client;
import com.netflix.spinnaker.config.DefaultServiceEndpoint;
import com.netflix.spinnaker.config.okhttp3.OkHttpClientProvider;
import com.netflix.spinnaker.kork.core.RetrySupport;
import com.netflix.spinnaker.kork.web.selector.DefaultServiceSelector;
import com.netflix.spinnaker.kork.web.selector.SelectableService;
import com.netflix.spinnaker.kork.web.selector.ServiceSelector;
import com.netflix.spinnaker.orca.api.operations.OperationsRunner;
import com.netflix.spinnaker.orca.clouddriver.*;
import com.netflix.spinnaker.orca.jackson.OrcaObjectMapper;
import com.netflix.spinnaker.orca.retrofit.RetrofitConfiguration;
import com.netflix.spinnaker.orca.retrofit.logging.RetrofitSlf4jLog;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import retrofit.RequestInterceptor;
import retrofit.RestAdapter;
import retrofit.converter.JacksonConverter;

@Configuration
@Import(RetrofitConfiguration.class)
@ComponentScan({
  "com.netflix.spinnaker.orca.clouddriver",
  "com.netflix.spinnaker.orca.kato.pipeline",
  "com.netflix.spinnaker.orca.kato.tasks"
})
@EnableConfigurationProperties({
  CloudDriverConfigurationProperties.class,
  PollerConfigurationProperties.class
})
@Slf4j
public class CloudDriverConfiguration {

  @ConditionalOnMissingBean(ObjectMapper.class)
  @Bean
  ObjectMapper mapper() {
    return OrcaObjectMapper.newInstance();
  }

  @Bean
  ClouddriverRetrofitBuilder clouddriverRetrofitBuilder(
      ObjectMapper objectMapper,
      OkHttpClientProvider clientProvider,
      RestAdapter.LogLevel retrofitLogLevel,
      RequestInterceptor spinnakerRequestInterceptor,
      CloudDriverConfigurationProperties cloudDriverConfigurationProperties) {
    return new ClouddriverRetrofitBuilder(
        objectMapper,
        clientProvider,
        retrofitLogLevel,
        spinnakerRequestInterceptor,
        cloudDriverConfigurationProperties);
  }

  static class ClouddriverRetrofitBuilder {
    ObjectMapper objectMapper;
    OkHttpClientProvider clientProvider;
    RestAdapter.LogLevel retrofitLogLevel;
    RequestInterceptor spinnakerRequestInterceptor;
    CloudDriverConfigurationProperties cloudDriverConfigurationProperties;

    ClouddriverRetrofitBuilder(
        ObjectMapper objectMapper,
        OkHttpClientProvider clientProvider,
        RestAdapter.LogLevel retrofitLogLevel,
        RequestInterceptor spinnakerRequestInterceptor,
        CloudDriverConfigurationProperties cloudDriverConfigurationProperties) {
      this.objectMapper = objectMapper;
      this.clientProvider = clientProvider;
      this.retrofitLogLevel = retrofitLogLevel;
      this.spinnakerRequestInterceptor = spinnakerRequestInterceptor;
      this.cloudDriverConfigurationProperties = cloudDriverConfigurationProperties;
    }

    <T> T buildWriteableService(Class<T> type) {
      return buildService(type, cloudDriverConfigurationProperties.getCloudDriverBaseUrl());
    }

    private <T> T buildService(Class<T> type, String url) {
      return new RestAdapter.Builder()
          .setRequestInterceptor(spinnakerRequestInterceptor)
          .setEndpoint(newFixedEndpoint(url))
          .setClient(
              new Ok3Client(
                  clientProvider.getClient(new DefaultServiceEndpoint("clouddriver", url))))
          .setLogLevel(retrofitLogLevel)
          .setLog(new RetrofitSlf4jLog(type))
          .setConverter(new JacksonConverter(objectMapper))
          .build()
          .create(type);
    }
<commit_msg>fix(config): add back public visibility for ClouddriverRetrofitBuilder class (#4331)<commit_after>/*
 * Copyright 2015 Netflix, Inc.
 *
 * 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.
 */

package com.netflix.spinnaker.orca.clouddriver.config;

import static retrofit.Endpoints.newFixedEndpoint;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.jakewharton.retrofit.Ok3Client;
import com.netflix.spinnaker.config.DefaultServiceEndpoint;
import com.netflix.spinnaker.config.okhttp3.OkHttpClientProvider;
import com.netflix.spinnaker.kork.core.RetrySupport;
import com.netflix.spinnaker.kork.web.selector.DefaultServiceSelector;
import com.netflix.spinnaker.kork.web.selector.SelectableService;
import com.netflix.spinnaker.kork.web.selector.ServiceSelector;
import com.netflix.spinnaker.orca.api.operations.OperationsRunner;
import com.netflix.spinnaker.orca.clouddriver.*;
import com.netflix.spinnaker.orca.jackson.OrcaObjectMapper;
import com.netflix.spinnaker.orca.retrofit.RetrofitConfiguration;
import com.netflix.spinnaker.orca.retrofit.logging.RetrofitSlf4jLog;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import retrofit.RequestInterceptor;
import retrofit.RestAdapter;
import retrofit.converter.JacksonConverter;

@Configuration
@Import(RetrofitConfiguration.class)
@ComponentScan({
  "com.netflix.spinnaker.orca.clouddriver",
  "com.netflix.spinnaker.orca.kato.pipeline",
  "com.netflix.spinnaker.orca.kato.tasks"
})
@EnableConfigurationProperties({
  CloudDriverConfigurationProperties.class,
  PollerConfigurationProperties.class
})
@Slf4j
public class CloudDriverConfiguration {

  @ConditionalOnMissingBean(ObjectMapper.class)
  @Bean
  ObjectMapper mapper() {
    return OrcaObjectMapper.newInstance();
  }

  @Bean
  ClouddriverRetrofitBuilder clouddriverRetrofitBuilder(
      ObjectMapper objectMapper,
      OkHttpClientProvider clientProvider,
      RestAdapter.LogLevel retrofitLogLevel,
      RequestInterceptor spinnakerRequestInterceptor,
      CloudDriverConfigurationProperties cloudDriverConfigurationProperties) {
    return new ClouddriverRetrofitBuilder(
        objectMapper,
        clientProvider,
        retrofitLogLevel,
        spinnakerRequestInterceptor,
        cloudDriverConfigurationProperties);
  }

  public static class ClouddriverRetrofitBuilder {
    ObjectMapper objectMapper;
    OkHttpClientProvider clientProvider;
    RestAdapter.LogLevel retrofitLogLevel;
    RequestInterceptor spinnakerRequestInterceptor;
    CloudDriverConfigurationProperties cloudDriverConfigurationProperties;

    ClouddriverRetrofitBuilder(
        ObjectMapper objectMapper,
        OkHttpClientProvider clientProvider,
        RestAdapter.LogLevel retrofitLogLevel,
        RequestInterceptor spinnakerRequestInterceptor,
        CloudDriverConfigurationProperties cloudDriverConfigurationProperties) {
      this.objectMapper = objectMapper;
      this.clientProvider = clientProvider;
      this.retrofitLogLevel = retrofitLogLevel;
      this.spinnakerRequestInterceptor = spinnakerRequestInterceptor;
      this.cloudDriverConfigurationProperties = cloudDriverConfigurationProperties;
    }

    public <T> T buildWriteableService(Class<T> type) {
      return buildService(type, cloudDriverConfigurationProperties.getCloudDriverBaseUrl());
    }

    private <T> T buildService(Class<T> type, String url) {
      return new RestAdapter.Builder()
          .setRequestInterceptor(spinnakerRequestInterceptor)
          .setEndpoint(newFixedEndpoint(url))
          .setClient(
              new Ok3Client(
                  clientProvider.getClient(new DefaultServiceEndpoint("clouddriver", url))))
          .setLogLevel(retrofitLogLevel)
          .setLog(new RetrofitSlf4jLog(type))
          .setConverter(new JacksonConverter(objectMapper))
          .build()
          .create(type);
    }

{'fraction_non_alphanumeric': 0.07577184720041863, 'fraction_numerical': 0.0037676609105180532, 'mean_word_length': 4.830384380719951, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1379620', 'n_tokens_mistral': 2633, 'n_tokens_neox': 2594, 'n_words': 502}