Search in sources :

Example 1 with SpringBootConfigurationHelper

use of io.fabric8.maven.core.util.SpringBootConfigurationHelper in project fabric8-maven-plugin by fabric8io.

the class SpringBootGenerator method extractPorts.

@Override
protected List<String> extractPorts() {
    List<String> answer = new ArrayList<>();
    Properties properties = SpringBootUtil.getSpringBootApplicationProperties(this.getProject());
    SpringBootConfigurationHelper propertyHelper = new SpringBootConfigurationHelper(SpringBootUtil.getSpringBootVersion(getProject()));
    String port = properties.getProperty(propertyHelper.getServerPortPropertyKey(), DEFAULT_SERVER_PORT);
    addPortIfValid(answer, getConfig(JavaExecGenerator.Config.webPort, port));
    addPortIfValid(answer, getConfig(JavaExecGenerator.Config.jolokiaPort));
    addPortIfValid(answer, getConfig(JavaExecGenerator.Config.prometheusPort));
    return answer;
}
Also used : SpringBootConfigurationHelper(io.fabric8.maven.core.util.SpringBootConfigurationHelper) ArrayList(java.util.ArrayList) Properties(java.util.Properties)

Example 2 with SpringBootConfigurationHelper

use of io.fabric8.maven.core.util.SpringBootConfigurationHelper in project fabric8-maven-plugin by fabric8io.

the class SpringBootWatcher method getPortForwardUrl.

private String getPortForwardUrl(final Set<HasMetadata> resources) throws Exception {
    LabelSelector selector = KubernetesResourceUtil.getPodLabelSelector(resources);
    if (selector == null) {
        log.warn("Unable to determine a selector for application pods");
        return null;
    }
    Properties properties = SpringBootUtil.getSpringBootApplicationProperties(getContext().getProject());
    SpringBootConfigurationHelper propertyHelper = new SpringBootConfigurationHelper(SpringBootUtil.getSpringBootVersion(getContext().getProject()));
    PortForwardService portForwardService = getContext().getFabric8ServiceHub().getPortForwardService();
    int port = IoUtil.getFreeRandomPort();
    int containerPort = findSpringBootWebPort(propertyHelper, properties);
    portForwardService.forwardPortAsync(getContext().getLogger(), selector, containerPort, port);
    return createForwardUrl(propertyHelper, properties, port);
}
Also used : SpringBootConfigurationHelper(io.fabric8.maven.core.util.SpringBootConfigurationHelper) LabelSelector(io.fabric8.kubernetes.api.model.LabelSelector) Properties(java.util.Properties) PortForwardService(io.fabric8.maven.core.service.PortForwardService)

Example 3 with SpringBootConfigurationHelper

use of io.fabric8.maven.core.util.SpringBootConfigurationHelper in project fabric8-maven-plugin by fabric8io.

the class AbstractSpringBootHealthCheckEnricherSupport method init.

@Before
public void init() {
    String version = getSpringBootVersion();
    this.propertyHelper = new SpringBootConfigurationHelper(version);
    final MavenProject project = new MavenProject();
    Set<Artifact> artifacts = new HashSet<>();
    Artifact a = new DefaultArtifact("org.springframework.boot", "spring-boot", version, "compile", "jar", "", null);
    a.setResolved(true);
    artifacts.add(a);
    project.setArtifacts(artifacts);
    new Expectations() {

        {
            context.getProject();
            result = project;
        }
    };
}
Also used : Expectations(mockit.Expectations) SpringBootConfigurationHelper(io.fabric8.maven.core.util.SpringBootConfigurationHelper) MavenProject(org.apache.maven.project.MavenProject) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) Before(org.junit.Before)

Example 4 with SpringBootConfigurationHelper

use of io.fabric8.maven.core.util.SpringBootConfigurationHelper in project fabric8-maven-plugin by fabric8io.

the class SpringBootHealthCheckEnricher method buildProbe.

protected Probe buildProbe(Properties springBootProperties, Integer initialDelay, Integer period) {
    SpringBootConfigurationHelper propertyHelper = new SpringBootConfigurationHelper(SpringBootUtil.getSpringBootVersion(getContext().getProject()));
    Integer managementPort = PropertiesHelper.getInteger(springBootProperties, propertyHelper.getManagementPortPropertyKey());
    boolean usingManagementPort = managementPort != null;
    Integer port = managementPort;
    if (port == null) {
        port = PropertiesHelper.getInteger(springBootProperties, propertyHelper.getServerPortPropertyKey(), DEFAULT_SERVER_PORT);
    }
    String scheme;
    String prefix;
    if (usingManagementPort) {
        scheme = Strings.isNotBlank(springBootProperties.getProperty(propertyHelper.getManagementKeystorePropertyKey())) ? SCHEME_HTTPS : SCHEME_HTTP;
        prefix = springBootProperties.getProperty(propertyHelper.getManagementContextPathPropertyKey(), "");
    } else {
        scheme = Strings.isNotBlank(springBootProperties.getProperty(propertyHelper.getServerKeystorePropertyKey())) ? SCHEME_HTTPS : SCHEME_HTTP;
        prefix = springBootProperties.getProperty(propertyHelper.getServerContextPathPropertyKey(), "");
        prefix += springBootProperties.getProperty(propertyHelper.getServletPathPropertyKey(), "");
        prefix += springBootProperties.getProperty(propertyHelper.getManagementContextPathPropertyKey(), "");
    }
    String actuatorBasePathKey = propertyHelper.getActuatorBasePathPropertyKey();
    String actuatorBasePath = propertyHelper.getActuatorDefaultBasePath();
    if (actuatorBasePathKey != null) {
        actuatorBasePath = springBootProperties.getProperty(actuatorBasePathKey, actuatorBasePath);
    }
    // lets default to adding a spring boot actuator health check
    ProbeBuilder probeBuilder = new ProbeBuilder().withNewHttpGet().withNewPort(port).withPath(prefix + actuatorBasePath + "/health").withScheme(scheme).endHttpGet();
    if (initialDelay != null) {
        probeBuilder = probeBuilder.withInitialDelaySeconds(initialDelay);
    }
    if (period != null) {
        probeBuilder = probeBuilder.withPeriodSeconds(period);
    }
    return probeBuilder.build();
}
Also used : ProbeBuilder(io.fabric8.kubernetes.api.model.ProbeBuilder) SpringBootConfigurationHelper(io.fabric8.maven.core.util.SpringBootConfigurationHelper)

Aggregations

SpringBootConfigurationHelper (io.fabric8.maven.core.util.SpringBootConfigurationHelper)4 Properties (java.util.Properties)2 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)1 ProbeBuilder (io.fabric8.kubernetes.api.model.ProbeBuilder)1 PortForwardService (io.fabric8.maven.core.service.PortForwardService)1 ArrayList (java.util.ArrayList)1 Expectations (mockit.Expectations)1 Artifact (org.apache.maven.artifact.Artifact)1 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)1 MavenProject (org.apache.maven.project.MavenProject)1 Before (org.junit.Before)1