com.netflix.spinnaker.echo.config.DryRunConfig Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2017 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.echo.config;
import static retrofit.Endpoints.newFixedEndpoint;
import com.jakewharton.retrofit.Ok3Client;
import com.netflix.spinnaker.config.DefaultServiceEndpoint;
import com.netflix.spinnaker.config.okhttp3.OkHttpClientProvider;
import com.netflix.spinnaker.echo.notification.DryRunNotificationAgent;
import com.netflix.spinnaker.echo.pipelinetriggers.orca.OrcaService;
import com.netflix.spinnaker.echo.services.Front50Service;
import com.netflix.spinnaker.retrofit.Slf4jRetrofitLogger;
import java.util.List;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import retrofit.Endpoint;
import retrofit.RestAdapter;
import retrofit.converter.JacksonConverter;
@Configuration
@EnableConfigurationProperties(DryRunConfig.DryRunProperties.class)
@ConditionalOnProperty("dryrun.enabled")
@Slf4j
public class DryRunConfig {
@Bean
Endpoint dryRunEndpoint(DryRunProperties properties) {
return newFixedEndpoint(properties.getBaseUrl());
}
@Bean
DryRunNotificationAgent dryRunNotificationAgent(
Front50Service front50,
OkHttpClientProvider clientProvider,
RestAdapter.LogLevel retrofitLogLevel,
Endpoint dryRunEndpoint,
DryRunProperties properties) {
log.info("Pipeline dry runs will execute at {}", dryRunEndpoint.getUrl());
OrcaService orca =
new RestAdapter.Builder()
.setEndpoint(dryRunEndpoint)
.setConverter(new JacksonConverter())
.setClient(
new Ok3Client(
clientProvider.getClient(
new DefaultServiceEndpoint("orca", dryRunEndpoint.getUrl()))))
.setLogLevel(retrofitLogLevel)
.setLog(new Slf4jRetrofitLogger(OrcaService.class))
.build()
.create(OrcaService.class);
return new DryRunNotificationAgent(front50, orca, properties);
}
@ConfigurationProperties("dryrun")
@Data
public static class DryRunProperties {
String baseUrl;
List notifications;
}
// seems like I have to do this as Spring can't parse lists of strings from YAML
@Data
public static class Notification {
String type;
String address;
String level;
List when;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy