Search in sources :

Example 1 with ConfigurationSupplier

use of io.dekorate.config.ConfigurationSupplier in project dekorate by dekorateio.

the class GeneratorConfigGenerator method configurePaths.

default void configurePaths(String defaultInputPath, String defaultOutputPath) {
    final String inputPath = System.getProperty(INPUT_DIR, defaultInputPath);
    final String outputPath = Optional.ofNullable(System.getProperty(OUTPUT_DIR)).map(path -> {
        resolve(path).mkdirs();
        return path;
    }).orElse(defaultOutputPath);
    if (isInputPathValid(inputPath)) {
        applyToProject(p -> p.withDekorateInputDir(inputPath));
        getSession().getConfigurationRegistry().add(new ConfigurationSupplier<>(new GeneratorConfigBuilder()));
    }
    if (isOutputPathValid(outputPath)) {
        applyToProject(p -> p.withDekorateOutputDir(outputPath));
        getSession().setWriter(new SimpleFileWriter(getProject().getBuildInfo().getClassOutputDir().resolve(getProject().getDekorateMetaDir()), resolve(outputPath).toPath()));
    }
}
Also used : WithProject(io.dekorate.WithProject) Strings(io.dekorate.utils.Strings) PropertyConfiguration(io.dekorate.config.PropertyConfiguration) Configuration(io.dekorate.kubernetes.config.Configuration) SimpleFileWriter(io.dekorate.processor.SimpleFileWriter) AnnotationConfiguration(io.dekorate.config.AnnotationConfiguration) Map(java.util.Map) Optional(java.util.Optional) ConfigurationSupplier(io.dekorate.config.ConfigurationSupplier) ConfigurationGenerator(io.dekorate.ConfigurationGenerator) File(java.io.File) GeneratorConfigAdapter(io.dekorate.option.adapter.GeneratorConfigAdapter) SimpleFileWriter(io.dekorate.processor.SimpleFileWriter)

Example 2 with ConfigurationSupplier

use of io.dekorate.config.ConfigurationSupplier in project dekorate by dekorateio.

the class SpringBootApplicationGenerator method addConfiguration.

default void addConfiguration(Map map) {
    Session session = getSession();
    session.getConfigurationRegistry().add(new ConfigurationSupplier(new SpringApplicationConfigBuilder()));
    session.getConfigurationRegistry().add(new SetSpringBootRuntime());
    session.getConfigurationRegistry().add(new SetSpringBootVersion());
    session.getManifestGenerators().add(new ManifestGenerator() {

        @Override
        public int order() {
            return 410;
        }

        @Override
        public String getKey() {
            return "spring";
        }

        @Override
        public void generate(Configuration config) {
            LOGGER.info("Processing service monitor config.");
            session.getResourceRegistry().decorate(new EndpointPathDecorator("http", "/actuator/prometheus"));
        }

        @Override
        public boolean accepts(Class config) {
            return SpringApplicationConfig.class.equals(config) || EditableServiceMonitorConfig.class.equals(config);
        }
    });
    if (isActuatorAvailable()) {
        // Users configuration should take priority, so add but don't overwrite.
        session.getConfigurationRegistry().add(new AddLivenessProbeConfigurator(new ProbeBuilder().withHttpActionPath("/actuator/info").build(), false));
        session.getConfigurationRegistry().add(new AddReadinessProbeConfigurator(new ProbeBuilder().withHttpActionPath("/actuator/health").build(), false));
    }
    if (isSpringCloudKubernetesAvailable()) {
        session.getManifestGenerators().add(new ManifestGenerator() {

            @Override
            public int order() {
                // We just want to run right after KubernetesManifestGenerator or OpenshiftManifestGenerator.
                return 310;
            }

            @Override
            public String getKey() {
                return "spring";
            }

            @Override
            public void generate(Configuration config) {
                LOGGER.info("Detected spring cloud kubernetes.");
                session.getResourceRegistry().decorate(new ApplyServiceAccountNamedDecorator());
                session.getResourceRegistry().decorate(new AddServiceAccountResourceDecorator());
                session.getResourceRegistry().decorate(new AddRoleBindingResourceDecorator("view"));
            }

            @Override
            public boolean accepts(Class config) {
                return SpringApplicationConfig.class.isAssignableFrom(config);
            }
        });
    }
}
Also used : SpringApplicationConfig(io.dekorate.spring.config.SpringApplicationConfig) AddRoleBindingResourceDecorator(io.dekorate.kubernetes.decorator.AddRoleBindingResourceDecorator) AddServiceAccountResourceDecorator(io.dekorate.kubernetes.decorator.AddServiceAccountResourceDecorator) SetSpringBootVersion(io.dekorate.spring.configurator.SetSpringBootVersion) Configuration(io.dekorate.kubernetes.config.Configuration) AddReadinessProbeConfigurator(io.dekorate.kubernetes.configurator.AddReadinessProbeConfigurator) SpringApplicationConfigBuilder(io.dekorate.spring.config.SpringApplicationConfigBuilder) EndpointPathDecorator(io.dekorate.prometheus.decorator.EndpointPathDecorator) ProbeBuilder(io.dekorate.kubernetes.config.ProbeBuilder) ManifestGenerator(io.dekorate.ManifestGenerator) SetSpringBootRuntime(io.dekorate.spring.configurator.SetSpringBootRuntime) ConfigurationSupplier(io.dekorate.config.ConfigurationSupplier) AddLivenessProbeConfigurator(io.dekorate.kubernetes.configurator.AddLivenessProbeConfigurator) ApplyServiceAccountNamedDecorator(io.dekorate.kubernetes.decorator.ApplyServiceAccountNamedDecorator) Session(io.dekorate.Session) WithSession(io.dekorate.WithSession)

Aggregations

ConfigurationSupplier (io.dekorate.config.ConfigurationSupplier)2 Configuration (io.dekorate.kubernetes.config.Configuration)2 ConfigurationGenerator (io.dekorate.ConfigurationGenerator)1 ManifestGenerator (io.dekorate.ManifestGenerator)1 Session (io.dekorate.Session)1 WithProject (io.dekorate.WithProject)1 WithSession (io.dekorate.WithSession)1 AnnotationConfiguration (io.dekorate.config.AnnotationConfiguration)1 PropertyConfiguration (io.dekorate.config.PropertyConfiguration)1 ProbeBuilder (io.dekorate.kubernetes.config.ProbeBuilder)1 AddLivenessProbeConfigurator (io.dekorate.kubernetes.configurator.AddLivenessProbeConfigurator)1 AddReadinessProbeConfigurator (io.dekorate.kubernetes.configurator.AddReadinessProbeConfigurator)1 AddRoleBindingResourceDecorator (io.dekorate.kubernetes.decorator.AddRoleBindingResourceDecorator)1 AddServiceAccountResourceDecorator (io.dekorate.kubernetes.decorator.AddServiceAccountResourceDecorator)1 ApplyServiceAccountNamedDecorator (io.dekorate.kubernetes.decorator.ApplyServiceAccountNamedDecorator)1 GeneratorConfigAdapter (io.dekorate.option.adapter.GeneratorConfigAdapter)1 SimpleFileWriter (io.dekorate.processor.SimpleFileWriter)1 EndpointPathDecorator (io.dekorate.prometheus.decorator.EndpointPathDecorator)1 SpringApplicationConfig (io.dekorate.spring.config.SpringApplicationConfig)1 SpringApplicationConfigBuilder (io.dekorate.spring.config.SpringApplicationConfigBuilder)1