Commit 4482e5ea authored by Anastasiia Gelmut's avatar Anastasiia Gelmut Committed by Riabokon Stanislav(EPAM)[GCP]
Browse files

Added Service Version Endpoint (GONRG-2886)

parent 75c54643
This diff is collapsed.
......@@ -25,4 +25,4 @@ 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.
\ No newline at end of file
limitations under the License.
......@@ -15,6 +15,8 @@ tags:
description: Partition Api
- name: health-check
description: Health Check
- name: info
description: "Version info endpoint"
paths:
/actuator/health:
get:
......@@ -214,6 +216,21 @@ paths:
security:
- JWT:
- global
/info:
get:
tags:
- info
summary: "Version info"
description: "For deployment available public `/info` endpoint, \
\ which provides build and git related information."
operationId: "Version info"
produces:
- "application/json"
responses:
200:
description: "Version info."
schema:
$ref: "#/definitions/VersionInfo"
securityDefinitions:
JWT:
type: apiKey
......@@ -241,6 +258,46 @@ definitions:
cosmos-connection:
sensitive: true
value: 'cosmos-connection'
VersionInfo:
type: "object"
properties:
groupId:
type: "string"
description: "Maven artifact group ID."
actifactId:
type: "string"
description: "Maven artifact ID."
version:
type: "string"
description: "Maven artifact version"
buildTime:
type: "string"
description: "Maven artifact build time"
branch:
type: "string"
description: "Current git branch"
commitId:
type: "string"
description: "Latest commit hash"
commitMessage:
type: "string"
description: "Latest commit message"
connectedOuterServices:
type: "array"
description: "Connected outer services information"
items:
$ref: "#/definitions/ConnectedOuterService"
description: "Version info."
ConnectedOuterService:
type: "object"
properties:
name:
type: "string"
description: "Connected outer service name."
version:
type: "string"
description: "Connected outer service version."
description: "Connected outer service information."
Property:
type: object
properties:
......
......@@ -10,7 +10,7 @@
* [Update an existing partition](#update-partition)
* [Delete an existing partition](#delete-partition)
* [List of partitions](#list-partition)
* [Version info endpoint](#version-info-endpoint)
## Introduction <a name="introduction"></a>
Partition service is responsible for creating and retrieving the partition specific properties (secret and non-secret) on behalf of other services.
......@@ -200,4 +200,40 @@ A sample output is shown below.
</details>
[Back to Table of Contents](#TOC)
\ No newline at end of file
[Back to Table of Contents](#TOC)
## Version info endpoint
For deployment available public `/info` endpoint, which provides build and git related information.
#### Example response:
```json
{
"groupId": "org.opengroup.osdu",
"artifactId": "storage-gcp",
"version": "0.10.0-SNAPSHOT",
"buildTime": "2021-07-09T14:29:51.584Z",
"branch": "feature/GONRG-2681_Build_info",
"commitId": "7777",
"commitMessage": "Added copyright to version info properties file",
"connectedOuterServices": [
{
"name": "elasticSearch",
"version":"..."
},
{
"name": "postgresSql",
"version":"..."
},
{
"name": "redis",
"version":"..."
}
]
}
```
This endpoint takes information from files, generated by `spring-boot-maven-plugin`,
`git-commit-id-plugin` plugins. Need to specify paths for generated files to matching
properties:
- `version.info.buildPropertiesPath`
- `version.info.gitPropertiesPath`
[Back to table of contents](#TOC)
/*
* 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.partition.api;
import java.io.IOException;
import org.opengroup.osdu.core.common.info.VersionInfoBuilder;
import org.opengroup.osdu.core.common.model.info.VersionInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping
public class InfoApi {
@Autowired
private VersionInfoBuilder versionInfoBuilder;
@GetMapping(value = "/info", produces = MediaType.APPLICATION_JSON_VALUE)
public VersionInfo info() throws IOException {
return versionInfoBuilder.buildVersionInfo();
}
}
......@@ -26,7 +26,7 @@
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<os-core-common.version>0.10.0</os-core-common.version>
<os-core-common.version>0.11.0-SNAPSHOT</os-core-common.version>
<org.springframework.boot.version>2.4.5</org.springframework.boot.version>
</properties>
......@@ -86,9 +86,40 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${org.springframework.boot.version}</version>
<executions>
<execution>
<id>build-info</id>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>4.0.5</version>
<executions>
<execution>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<verbose>true</verbose>
<dateFormat>yyyy-MM-dd'T'HH:mm:ssZ</dateFormat>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>
${project.build.outputDirectory}/git.properties
</generateGitPropertiesFilename>
</configuration>
</plugin>
</plugins>
</build>
<modules>
......
......@@ -47,6 +47,7 @@ public class AADSecurityConfig extends WebSecurityConfigurerAdapter {
"/configuration/security",
"/swagger",
"/swagger-ui.html",
"/info",
"/webjars/**").permitAll()
.anyRequest().authenticated()
.and()
......
package org.opengroup.osdu.partition.api;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.partition.util.AwsTestUtils;
public class TestGetVersionInfo extends GetVersionInfoApiTest {
@Before
@Override
public void setup() throws Exception {
this.testUtils = new AwsTestUtils();
}
@After
@Override
public void tearDown() throws Exception {
this.testUtils = null;
}
}
package org.opengroup.osdu.partition.api;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.partition.util.AzureTestUtils;
public class TestGetVersionInfo extends GetVersionInfoApiTest {
@Before
@Override
public void setup() throws Exception {
this.testUtils = new AzureTestUtils();
}
@After
@Override
public void tearDown() throws Exception {
this.testUtils = null;
}
}
/*
* 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.partition.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import com.sun.jersey.api.client.ClientResponse;
import org.junit.Test;
import org.opengroup.osdu.partition.util.TestBase;
import org.opengroup.osdu.partition.util.TestUtils;
import org.opengroup.osdu.partition.util.VersionInfoUtils;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
public abstract class GetVersionInfoApiTest extends TestBase {
protected static final VersionInfoUtils VERSION_INFO_UTILS = new VersionInfoUtils();
@Test
public void should_returnInfo() throws Exception {
ClientResponse response = TestUtils
.send("api/partition/v1/info", HttpMethod.GET.name(), this.testUtils.getAccessToken(), "",
"", false);
assertEquals(HttpStatus.OK.value(), response.getStatus());
VersionInfoUtils.VersionInfo responseObject = VERSION_INFO_UTILS
.getVersionInfoFromResponse(response);
assertNotNull(responseObject.groupId);
assertNotNull(responseObject.artifactId);
assertNotNull(responseObject.version);
assertNotNull(responseObject.buildTime);
assertNotNull(responseObject.branch);
assertNotNull(responseObject.commitId);
assertNotNull(responseObject.commitMessage);
}
}
/*
* 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.partition.util;
import static org.junit.Assert.assertTrue;
import com.google.gson.Gson;
import com.sun.jersey.api.client.ClientResponse;
public class VersionInfoUtils {
public VersionInfo getVersionInfoFromResponse(ClientResponse response) {
assertTrue(response.getType().toString().contains("application/json"));
String json = response.getEntity(String.class);
Gson gson = new Gson();
return gson.fromJson(json, VersionInfo.class);
}
public class VersionInfo {
public String groupId;
public String artifactId;
public String version;
public String buildTime;
public String branch;
public String commitId;
public String commitMessage;
}
}
/*
* 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.partition.api;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.partition.util.GCPTestUtils;
public class TestGetVersionInfo extends GetVersionInfoApiTest {
@Before
@Override
public void setup() throws Exception {
this.testUtils = new GCPTestUtils();
}
@After
@Override
public void tearDown() throws Exception {
this.testUtils = null;
}
}
package org.opengroup.osdu.partition.api;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.partition.util.IBMTestUtils;
public class TestGetVersionInfo extends GetVersionInfoApiTest {
@Before
@Override
public void setup() throws Exception {
this.testUtils = new IBMTestUtils();
}
@After
@Override
public void tearDown() throws Exception {
this.testUtils = null;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment