diff --git a/NOTICE b/NOTICE index 47740844bc09faef457da66af708c0e7b670546a..5152ca18e4189037d1ab8b25b509987e3bb68d56 100644 --- a/NOTICE +++ b/NOTICE @@ -37,7 +37,7 @@ The following software have components provided under the terms of this license: - Jackson dataformat: Smile (from http://github.com/FasterXML/jackson-dataformats-binary) - Jackson datatype: JSR310 (from https://repo1.maven.org/maven2/com/fasterxml/jackson/datatype/jackson-datatype-jsr310) - Jackson datatype: jdk8 (from https://repo1.maven.org/maven2/com/fasterxml/jackson/datatype/jackson-datatype-jdk8) -- Jackson-annotations (from http://wiki.fasterxml.com/JacksonHome) +- Jackson-annotations (from http://github.com/FasterXML/jackson) - Jackson-core (from http://wiki.fasterxml.com/JacksonHome) - Jackson-dataformat-YAML (from https://github.com/FasterXML/jackson-dataformats-text) - Jackson-module-parameter-names (from https://repo1.maven.org/maven2/com/fasterxml/jackson/module/jackson-module-parameter-names) @@ -70,14 +70,6 @@ The following software have components provided under the terms of this license: - OpenCensus (from https://github.com/census-instrumentation/opencensus-java) - OpenCensus (from https://github.com/census-instrumentation/opencensus-java) - SnakeYAML (from http://code.google.com/p/snakeyaml/) -- Spring Boot (from http://projects.spring.io/spring-boot/) -- Spring Boot AutoConfigure (from http://projects.spring.io/spring-boot/) -- Spring Boot Json Starter (from https://projects.spring.io/spring-boot/#/spring-boot-parent/spring-boot-starters/spring-boot-starter-json) -- Spring Boot Logging Starter (from http://projects.spring.io/spring-boot/) -- Spring Boot Starter (from http://projects.spring.io/spring-boot/) -- Spring Boot Tomcat Starter (from http://projects.spring.io/spring-boot/) -- Spring Boot Validation Starter (from http://projects.spring.io/spring-boot/) -- Spring Boot Web Starter (from http://projects.spring.io/spring-boot/) - Spring Commons Logging Bridge (from https://github.com/spring-projects/spring-framework) - Spring Expression Language (SpEL) (from https://github.com/spring-projects/spring-framework) - Spring Framework: AOP (from http://www.springframework.org) @@ -112,10 +104,18 @@ The following software have components provided under the terms of this license: - rest-high-level (from https://github.com/elastic/elasticsearch) - rxjava (from https://github.com/ReactiveX/RxJava) - server (from https://github.com/elastic/elasticsearch) +- spring-boot (from https://spring.io/projects/spring-boot) +- spring-boot-autoconfigure (from https://spring.io/projects/spring-boot) +- spring-boot-starter (from https://spring.io/projects/spring-boot) +- spring-boot-starter-json (from https://spring.io/projects/spring-boot) +- spring-boot-starter-logging (from https://spring.io/projects/spring-boot) +- spring-boot-starter-tomcat (from https://spring.io/projects/spring-boot) +- spring-boot-starter-validation (from https://spring.io/projects/spring-boot) +- spring-boot-starter-web (from https://spring.io/projects/spring-boot) - swagger-annotations (from https://repo1.maven.org/maven2/io/swagger/swagger-annotations) - swagger-jaxrs (from ) - tomcat-embed-core (from http://tomcat.apache.org/) -- tomcat-embed-websocket (from http://tomcat.apache.org/) +- tomcat-embed-websocket (from https://tomcat.apache.org/) ======================================================================== BSD-2-Clause diff --git a/src/main/java/org/opengroup/osdu/core/common/info/CloudVersionInfoBuilder.java b/src/main/java/org/opengroup/osdu/core/common/info/CloudVersionInfoBuilder.java new file mode 100644 index 0000000000000000000000000000000000000000..cd6368d6c311c4a45b0a2e12ed9f0d0a5e9bbbdf --- /dev/null +++ b/src/main/java/org/opengroup/osdu/core/common/info/CloudVersionInfoBuilder.java @@ -0,0 +1,89 @@ +/* + * Copyright 2021 Google LLC + * Copyright 2021 EPAM Systems, 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 + * + * https://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 org.opengroup.osdu.core.common.info; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Collections; +import java.util.List; +import java.util.Properties; +import lombok.extern.slf4j.Slf4j; +import org.opengroup.osdu.core.common.model.info.ConnectedOuterService; +import org.opengroup.osdu.core.common.model.info.VersionInfo; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +@ConditionalOnMissingBean(value = VersionInfoBuilder.class) +public class CloudVersionInfoBuilder implements VersionInfoBuilder { + + private final Properties buildInfoProperties = new Properties(); + private final Properties gitProperties = new Properties(); + private final VersionInfoProperties versionInfoProperties; + + public CloudVersionInfoBuilder(VersionInfoProperties versionInfoProperties) { + this.versionInfoProperties = versionInfoProperties; + } + + public VersionInfo buildVersionInfo() throws IOException { + loadBuildInfoProperties(); + loadGitProperties(); + List connectedOuterServices = loadConnectedOuterServices(); + return VersionInfo.builder() + .groupId(buildInfoProperties.getProperty("build.group")) + .artifactId(buildInfoProperties.getProperty("build.artifact")) + .version(buildInfoProperties.getProperty("build.version")) + .buildTime(buildInfoProperties.getProperty("build.time")) + .branch(gitProperties.getProperty("git.branch")) + .commitId(gitProperties.getProperty("git.commit.id")) + .commitMessage(gitProperties.getProperty("git.commit.message.short")) + .connectedOuterServices(connectedOuterServices) + .build(); + } + + private void loadBuildInfoProperties() throws IOException { + InputStream buildInfoStream = + ClassLoader.getSystemClassLoader() + .getResourceAsStream(versionInfoProperties.getBuildPropertiesPath()); + if (buildInfoStream != null) { + buildInfoProperties.load(buildInfoStream); + } else { + log.error( + "Build-info properties file not found by path: {}", + versionInfoProperties.getBuildPropertiesPath()); + } + } + + private void loadGitProperties() throws IOException { + InputStream gitStream = + ClassLoader.getSystemClassLoader() + .getResourceAsStream(versionInfoProperties.getGitPropertiesPath()); + if (gitStream != null) { + gitProperties.load(gitStream); + } else { + log.error( + "Git properties file not found by path: {}", + versionInfoProperties.getGitPropertiesPath()); + } + } + + protected List loadConnectedOuterServices() { + return Collections.emptyList(); + } +} diff --git a/src/main/java/org/opengroup/osdu/core/common/info/VersionInfoAutoconfiguration.java b/src/main/java/org/opengroup/osdu/core/common/info/VersionInfoAutoconfiguration.java new file mode 100644 index 0000000000000000000000000000000000000000..0a32c4398ac37fc3780a7a39762bc9b1320d2e3d --- /dev/null +++ b/src/main/java/org/opengroup/osdu/core/common/info/VersionInfoAutoconfiguration.java @@ -0,0 +1,10 @@ +package org.opengroup.osdu.core.common.info; + +import lombok.extern.java.Log; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@Log +@ComponentScan("org.opengroup.osdu.core.common.info") +public class VersionInfoAutoconfiguration {} diff --git a/src/main/java/org/opengroup/osdu/core/common/info/VersionInfoBuilder.java b/src/main/java/org/opengroup/osdu/core/common/info/VersionInfoBuilder.java new file mode 100644 index 0000000000000000000000000000000000000000..af157a8bf8e68ad2bac3511a6228fef29b5c01c2 --- /dev/null +++ b/src/main/java/org/opengroup/osdu/core/common/info/VersionInfoBuilder.java @@ -0,0 +1,26 @@ +/* + * Copyright 2021 Google LLC + * Copyright 2021 EPAM Systems, 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 + * + * https://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 org.opengroup.osdu.core.common.info; + +import java.io.IOException; +import org.opengroup.osdu.core.common.model.info.VersionInfo; + +public interface VersionInfoBuilder { + + VersionInfo buildVersionInfo() throws IOException; +} diff --git a/src/main/java/org/opengroup/osdu/core/common/info/VersionInfoProperties.java b/src/main/java/org/opengroup/osdu/core/common/info/VersionInfoProperties.java new file mode 100644 index 0000000000000000000000000000000000000000..d201a48845e39243e469bae8e8fc66882e0bb30c --- /dev/null +++ b/src/main/java/org/opengroup/osdu/core/common/info/VersionInfoProperties.java @@ -0,0 +1,32 @@ +/* + * Copyright 2021 Google LLC + * Copyright 2021 EPAM Systems, 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 + * + * https://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 org.opengroup.osdu.core.common.info; + +import lombok.Getter; +import lombok.Setter; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ConfigurationProperties(prefix = "osdu.version.info") +@Getter +@Setter +public class VersionInfoProperties { + + private String buildPropertiesPath = "META-INF/build-info.properties"; + private String gitPropertiesPath = "BOOT-INF/classes/git.properties"; +} diff --git a/src/main/java/org/opengroup/osdu/core/common/model/info/ConnectedOuterService.java b/src/main/java/org/opengroup/osdu/core/common/model/info/ConnectedOuterService.java new file mode 100644 index 0000000000000000000000000000000000000000..cf7d7c0ea8b92721dcf7893082f17e52b9e8cd5e --- /dev/null +++ b/src/main/java/org/opengroup/osdu/core/common/model/info/ConnectedOuterService.java @@ -0,0 +1,17 @@ +package org.opengroup.osdu.core.common.model.info; + +import lombok.Builder; +import lombok.Data; + +/** + * The node contains service-specific values for all outer services connected to OSDU service. + * The value is optional - basic implementation contains an empty list. + * To define outer services info for OSDU service + * need to override loadConnectedOuterServices method. + */ +@Data +@Builder +public class ConnectedOuterService { + private String name; + private String version; +} diff --git a/src/main/java/org/opengroup/osdu/core/common/model/info/VersionInfo.java b/src/main/java/org/opengroup/osdu/core/common/model/info/VersionInfo.java new file mode 100644 index 0000000000000000000000000000000000000000..f0d1d7693d8a3352953383fb1c22ba90b483c68f --- /dev/null +++ b/src/main/java/org/opengroup/osdu/core/common/model/info/VersionInfo.java @@ -0,0 +1,36 @@ +/* + * Copyright 2021 Google LLC + * Copyright 2021 EPAM Systems, 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 + * + * https://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 org.opengroup.osdu.core.common.model.info; + +import java.util.Collections; +import java.util.List; +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class VersionInfo { + private String groupId; + private String artifactId; + private String version; + private String buildTime; + private String branch; + private String commitId; + private String commitMessage; + private List connectedOuterServices; +} \ No newline at end of file diff --git a/src/main/resources/META-INF/spring.factories b/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000000000000000000000000000000000000..4cb5336267e383666521289b81a23ca3a6d52834 --- /dev/null +++ b/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=org/opengroup/osdu/core/common/info/VersionInfoAutoconfiguration \ No newline at end of file diff --git a/src/test/java/org/opengroup/osdu/core/common/info/CloudVersionInfoBuilderTest.java b/src/test/java/org/opengroup/osdu/core/common/info/CloudVersionInfoBuilderTest.java new file mode 100644 index 0000000000000000000000000000000000000000..eb501cff8174b239c02348b09519fbe535266392 --- /dev/null +++ b/src/test/java/org/opengroup/osdu/core/common/info/CloudVersionInfoBuilderTest.java @@ -0,0 +1,45 @@ +package org.opengroup.osdu.core.common.info; + +import static org.mockito.Mockito.when; + +import java.io.IOException; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.opengroup.osdu.core.common.model.info.VersionInfo; + +@RunWith(MockitoJUnitRunner.class) +public class CloudVersionInfoBuilderTest { + + private static final String TEST_BUILD_INFO_PATH = "testdata/build-info.properties"; + private static final String TEST_GIT_INFO_PATH = "testdata/git-info.properties"; + + @InjectMocks + private CloudVersionInfoBuilder versionInfoBuilder; + + @Mock + private VersionInfoProperties versionInfoProperties; + + @Before + public void setUp() { + when(versionInfoProperties.getBuildPropertiesPath()).thenReturn(TEST_BUILD_INFO_PATH); + when(versionInfoProperties.getGitPropertiesPath()).thenReturn(TEST_GIT_INFO_PATH); + } + + @Test + public void buildVersionInfo() throws IOException { + VersionInfo versionInfo = versionInfoBuilder.buildVersionInfo(); + + Assert.assertNotNull(versionInfo.getGroupId()); + Assert.assertNotNull(versionInfo.getArtifactId()); + Assert.assertNotNull(versionInfo.getVersion()); + Assert.assertNotNull(versionInfo.getBuildTime()); + Assert.assertNotNull(versionInfo.getBranch()); + Assert.assertNotNull(versionInfo.getCommitId()); + Assert.assertNotNull(versionInfo.getCommitMessage()); + } +} diff --git a/src/test/resources/testdata/build-info.properties b/src/test/resources/testdata/build-info.properties new file mode 100644 index 0000000000000000000000000000000000000000..ba922d47e7dee96b3b3eb5c85661b08736cfbe62 --- /dev/null +++ b/src/test/resources/testdata/build-info.properties @@ -0,0 +1,5 @@ +build.artifact=storage-core +build.group=org.opengroup.osdu +build.name=storage-core +build.time=2021-07-22T14\:31\:10.717Z +build.version=0.10.0-SNAPSHOT diff --git a/src/test/resources/testdata/git-info.properties b/src/test/resources/testdata/git-info.properties new file mode 100644 index 0000000000000000000000000000000000000000..96fbae6fadb5a73705fc9f457610ccbf0460b975 --- /dev/null +++ b/src/test/resources/testdata/git-info.properties @@ -0,0 +1,25 @@ +#Generated by Git-Commit-Id-Plugin +git.branch=version-endpoint +git.build.host=EPRUSARW000F +git.build.time=2021-07-22T18\:31\:17+0400 +git.build.user.email=7nolikov@gmail.com +git.build.user.name=Dmitriy Novikov +git.build.version=0.10.0-SNAPSHOT +git.closest.tag.commit.count= +git.closest.tag.name= +git.commit.author.time=2021-07-22T16\:39\:53+0400 +git.commit.committer.time=2021-07-22T16\:39\:53+0400 +git.commit.id=7777 +git.commit.id.abbrev=0aff671 +git.commit.id.describe=0aff671-dirty +git.commit.id.describe-short=0aff671-dirty +git.commit.message.full=Merge remote-tracking branch 'community/master' into version-endpoint +git.commit.message.short=Merge remote-tracking branch 'community/master' into version-endpoint +git.commit.time=2021-07-22T16\:39\:53+0400 +git.commit.user.email=7nolikov@gmail.com +git.commit.user.name=Dmitriy Novikov +git.dirty=true +git.local.branch.ahead=0 +git.local.branch.behind=0 +git.tags= +git.total.commit.count=1010