Skip to content

Commit

Permalink
Update build number handling to prevent runtime failures and provide …
Browse files Browse the repository at this point in the history
…a default value
  • Loading branch information
dmitrys committed May 26, 2022
1 parent ab7ecbf commit 0a3b35c
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 47 deletions.
49 changes: 40 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<artifactId>datanode</artifactId>
<groupId>com.odysseusinc.arachne</groupId>
<version>1.19.0</version>
<version>1.19.1</version>
<packaging>jar</packaging>


Expand All @@ -29,8 +29,8 @@
<postgresql.version>42.2.25</postgresql.version>
<javaDockerVersion>3.2.11</javaDockerVersion>
<springRetryVersion>1.2.4.RELEASE</springRetryVersion>
<build.number>${BUILD_NUMBER}</build.number>
<build.id>${BUILD_TIMESTAMP}</build.id>
<commons.version>1.19.0</commons.version>
<build.number>dev</build.number>
<dockerImagePrefix>hub.odysseusinc.com</dockerImagePrefix>
<jackson.version>2.10.5.20201202</jackson.version>
<!-- Overrides SpringBoot defaults to conform Hydra -->
Expand All @@ -47,34 +47,34 @@
<dependency>
<groupId>com.odysseusinc.arachne</groupId>
<artifactId>arachne-commons</artifactId>
<version>${project.version}</version>
<version>${commons.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.odysseusinc.arachne</groupId>
<artifactId>arachne-common-types</artifactId>
<version>${project.version}</version>
<version>${commons.version}</version>
</dependency>
<dependency>
<groupId>com.odysseusinc.arachne</groupId>
<artifactId>arachne-common-utils</artifactId>
<version>${project.version}</version>
<version>${commons.version}</version>
</dependency>
<dependency>
<groupId>com.odysseusinc.arachne</groupId>
<artifactId>arachne-no-handler-found-exception-util</artifactId>
<version>${project.version}</version>
<version>${commons.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.odysseusinc.arachne</groupId>
<artifactId>execution-engine-commons</artifactId>
<version>${project.version}</version>
<version>${commons.version}</version>
</dependency>
<dependency>
<artifactId>arachne-sys-settings</artifactId>
<groupId>com.odysseusinc.arachne</groupId>
<version>${project.version}</version>
<version>${commons.version}</version>
</dependency>
<dependency>
<groupId>javax.jms</groupId>
Expand Down Expand Up @@ -355,6 +355,10 @@
<include>application-${env}.yml</include>
</includes>
</resource>
<resource>
<directory>target/meta</directory>
<targetPath>META-INF</targetPath>
</resource>
</resources>
<plugins>
<plugin>
Expand All @@ -380,6 +384,33 @@
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>ru.yaal.maven</groupId>
<artifactId>write-text-files-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>write-text-files</id>
<phase>generate-resources</phase>
<goals>
<goal>write-text-files</goal>
</goals>
<configuration>
<charset>UTF-8</charset>
<files>
<file>
<path>target/meta/version.properties</path>
<lines>
<line>buildNumber: ${build.number}</line>
<line>buildId: ${maven.build.timestamp}</line>
<line>version: ${project.version}</line>
</lines>
</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package com.odysseusinc.arachne.datanode.config;

import com.odysseusinc.arachne.commons.config.DocketWrapper;
import com.odysseusinc.arachne.datanode.controller.BuildNumberController;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
Expand All @@ -36,12 +37,15 @@
@ConditionalOnProperty(prefix = "swagger", name = "enable")
public class SwaggerConfig {

@Value("${project.version}")
private String projectVersion;
private final String projectVersion;

@Value("${arachne.token.header}")
private String arachneTokenHeader;

public SwaggerConfig(BuildNumberController buildNumberController) {
projectVersion = buildNumberController.getProjectVersion();
}

@Bean
public Docket docket(DocketWrapper docketWrapper) {
return docketWrapper.getDocket();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,54 +25,58 @@
import com.odysseusinc.arachne.datanode.BuildNumberDTO;
import com.odysseusinc.arachne.datanode.util.CentralUtil;
import io.swagger.annotations.ApiOperation;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BuildNumberController {

@Value("${build.number}")
private String buildNumber;
@Value("${build.id}")
private String buildId;
@Value("${project.version}")
private String projectVersion;
private static final String SOURCE = "META-INF/version.properties";
private final Logger log = LoggerFactory.getLogger(BuildNumberController.class);

private CentralUtil centralUtil;
private final String buildNumber;
private final String buildId;
private final String projectVersion;
private final String centralUrl;

@Autowired
public BuildNumberController(CentralUtil centralUtil) {

this.centralUtil = centralUtil;
InputStream is = getClass().getClassLoader().getResourceAsStream(SOURCE);
Properties properties = new Properties();
try {
properties.load(is);
} catch (IOException e) {
log.warn("Unable to read [{}], version info unavailable. Error details: {}.", SOURCE, e.getMessage());
}
projectVersion = properties.getProperty("version", "dev");;
buildNumber = properties.getProperty("buildNumber", "dev");
buildId = properties.getProperty("buildId", "dev");;
centralUrl = centralUtil.getCentralUrl();
log.info("Version [{}], build [{}] @ [{}]", projectVersion, buildNumber, buildId);
log.info("Central url [{}]", centralUrl);
}

@ApiOperation(value = "Get build number")
@RequestMapping(value = "/api/v1/build-number", method = RequestMethod.GET)
public BuildNumberDTO buildNumber() {

BuildNumberDTO buildNumberDTO = new BuildNumberDTO();
buildNumberDTO.setBuildNumber(getBuildNumber());
buildNumberDTO.setBuildId(getBuildId());
buildNumberDTO.setProjectVersion(getProjectVersion());
buildNumberDTO.setCentralUrl(centralUtil.getCentralUrl());
buildNumberDTO.setBuildNumber(buildNumber);
buildNumberDTO.setBuildId(buildId);
buildNumberDTO.setProjectVersion(projectVersion);
buildNumberDTO.setCentralUrl(centralUrl);
return buildNumberDTO;
}

protected String getBuildNumber() {

return buildNumber;
}

protected String getBuildId() {

return buildId;
}

protected String getProjectVersion() {

public String getProjectVersion() {
return projectVersion;
}
}
5 changes: 0 additions & 5 deletions src/main/resources/application-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ spring:
activemq:
packages:
trust-all: true
build:
number: @build.number@
id: @build.id@
project:
version: @project.version@
#ms
files:
store:
Expand Down
3 changes: 0 additions & 3 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
spring:
datasource:
url: jdbc:postgresql://localhost:5432/datanode
build:
number: no_build_number
id: no_build_id
datanode:
arachneCentral:
host: https://localhost
Expand Down
3 changes: 0 additions & 3 deletions src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ datanode.arachneCentral.nodeAuthHeader=Arachne-System-Token

spring.mvc.view.prefix=/
spring.mvc.view.suffix=.html
build.number=@build.number@
build.id=no_build_id
project.version=@project.version@
#ms
files.store.path=/tmp
spring.http.multipart.max-file-size=128MB
Expand Down

0 comments on commit 0a3b35c

Please sign in to comment.