diff --git a/NOTICE b/NOTICE index dbce76d33304db4d86d4dbc2aca5f51ac884fdd6..397587f820723c1e6ba00fab488463fd59aa85e1 100644 --- a/NOTICE +++ b/NOTICE @@ -16,7 +16,8 @@ The following software have components provided under the terms of this license: - Apache HttpCore (from http://hc.apache.org/httpcomponents-core-ga) - Apache HttpCore NIO (from http://hc.apache.org/httpcomponents-core-ga) - Apache Log4j API (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-api) -- Apache Log4j to SLF4J Adapter (from ) +- Apache Log4j to SLF4J Adapter (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-to-slf4j) +- Bean Validation API (from http://beanvalidation.org) - Bean Validation API (from http://beanvalidation.org) - Byte Buddy (without dependencies) (from https://repo1.maven.org/maven2/net/bytebuddy/byte-buddy) - Byte Buddy Java agent (from https://repo1.maven.org/maven2/net/bytebuddy/byte-buddy-agent) @@ -29,10 +30,10 @@ The following software have components provided under the terms of this license: - Guava InternalFutureFailureAccess and InternalFutures (from https://repo1.maven.org/maven2/com/google/guava/failureaccess) - Guava: Google Core Libraries for Java (from https://repo1.maven.org/maven2/com/google/guava/guava) - HPPC Collections (from https://repo1.maven.org/maven2/com/carrotsearch/hppc) -- Hibernate Validator Engine (from ) +- Hibernate Validator Engine (from https://repo1.maven.org/maven2/org/hibernate/validator/hibernate-validator) - J2ObjC Annotations (from https://github.com/google/j2objc/) - JBoss Logging 3 (from http://www.jboss.org) -- JSON Web Token support for the JVM (from https://github.com/jwtk/jjwt.git) +- JSON Web Token support for the JVM (from https://github.com/jwtk/jjwt) - Jackson dataformat: CBOR (from http://github.com/FasterXML/jackson-dataformats-binary) - 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) @@ -41,7 +42,6 @@ The following software have components provided under the terms of this license: - Jackson-core (from https://github.com/FasterXML/jackson-core) - 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) -- Jakarta Bean Validation API (from https://beanvalidation.org) - Java Servlet API (from http://servlet-spec.java.net) - Javassist (from http://www.javassist.org/) - Joda-Time (from https://www.joda.org/joda-time/) @@ -70,15 +70,23 @@ 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 AOP (from https://github.com/spring-projects/spring-framework) +- Spring Beans (from https://github.com/spring-projects/spring-framework) +- Spring Boot (from https://projects.spring.io/spring-boot/#/spring-boot-parent/spring-boot) +- Spring Boot AutoConfigure (from https://projects.spring.io/spring-boot/#/spring-boot-parent/spring-boot-autoconfigure) +- 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 https://projects.spring.io/spring-boot/#/spring-boot-parent/spring-boot-starters/spring-boot-starter-logging) +- Spring Boot Starter (from https://projects.spring.io/spring-boot/#/spring-boot-parent/spring-boot-starters/spring-boot-starter) +- Spring Boot Tomcat Starter (from https://projects.spring.io/spring-boot/#/spring-boot-parent/spring-boot-starters/spring-boot-starter-tomcat) +- Spring Boot Validation Starter (from https://projects.spring.io/spring-boot/#/spring-boot-parent/spring-boot-starters/spring-boot-starter-validation) +- Spring Boot Web Starter (from https://projects.spring.io/spring-boot/#/spring-boot-parent/spring-boot-starters/spring-boot-starter-web) - Spring Commons Logging Bridge (from https://github.com/spring-projects/spring-framework) +- Spring Context (from https://github.com/spring-projects/spring-framework) +- Spring Core (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) -- Spring Framework: Context (from http://www.springframework.org) -- Spring Framework: WebMVC (from http://www.springframework.org) - Spring TestContext Framework (from https://github.com/spring-projects/spring-framework) -- Spring beans (from https://repo1.maven.org/maven2/org/springframework/spring-beans) -- Spring core (from https://repo1.maven.org/maven2/org/springframework/spring-core) -- Spring web (from https://repo1.maven.org/maven2/org/springframework/spring-web) +- Spring Web (from https://github.com/spring-projects/spring-framework) +- Spring Web MVC (from https://github.com/spring-projects/spring-framework) - T-Digest (from https://github.com/tdunning/t-digest) - aggs-matrix-stats (from https://github.com/elastic/elasticsearch) - compiler (from http://github.com/spullara/mustache.java) @@ -104,14 +112,6 @@ 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/) @@ -142,7 +142,7 @@ The following software have components provided under the terms of this license: - Mockito (from http://www.mockito.org) - Reflections (from http://github.com/ronmamo/reflections) - SnakeYAML (from http://code.google.com/p/snakeyaml/) -- Spring core (from https://repo1.maven.org/maven2/org/springframework/spring-core) +- Spring Core (from https://github.com/spring-projects/spring-framework) ======================================================================== CC-BY-2.5 @@ -318,7 +318,7 @@ The following software have components provided under the terms of this license: - HdrHistogram (from http://hdrhistogram.github.io/HdrHistogram/) - Joda-Time (from https://www.joda.org/joda-time/) - Project Lombok (from https://projectlombok.org) -- Spring web (from https://repo1.maven.org/maven2/org/springframework/spring-web) +- Spring Web (from https://github.com/spring-projects/spring-framework) ======================================================================== unknown 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..f9da47f273af395c68d8a6d1b62de9eb8ad375da --- /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.stereotype.Component; + +@Slf4j +@Component +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 = + this.getClass().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 = + this.getClass().getResourceAsStream(versionInfoProperties.getGitPropertiesPath()); + if (gitStream != null) { + gitProperties.load(gitStream); + } else { + log.error( + "Git properties file not found by path: {}", + versionInfoProperties.getGitPropertiesPath()); + } + } + + /** + * The method collects service-specific values for all outer services connected to OSDU service. + * To define outer services info for OSDU service need to override this method. + */ + 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..501073971aa915bfb5677aa77c9e98a6c121930a --- /dev/null +++ b/src/main/java/org/opengroup/osdu/core/common/info/VersionInfoAutoconfiguration.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 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..419bd12ff108461f7d00c2fea73256e709c9682e --- /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..62c4f487bbdeba6864eaf62b7f41c179e5a728a0 --- /dev/null +++ b/src/main/java/org/opengroup/osdu/core/common/model/info/ConnectedOuterService.java @@ -0,0 +1,33 @@ +/* + * 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 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..aa454b9f36be5e79344215a219a664aeaf61e6af --- /dev/null +++ b/src/main/java/org/opengroup/osdu/core/common/model/info/VersionInfo.java @@ -0,0 +1,35 @@ +/* + * 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.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..56749dc98afd6b639ac0c946bc4f4b7fdd7c1bfc --- /dev/null +++ b/src/test/java/org/opengroup/osdu/core/common/info/CloudVersionInfoBuilderTest.java @@ -0,0 +1,61 @@ +/* + * 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 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