Skip to content

Commit ae1150f

Browse files
Merge pull request #463 from Drill4J/feature/etl-optimization
Feature: test definition & test launches dedicated API endpoints
2 parents 401283a + 427e68a commit ae1150f

6 files changed

Lines changed: 349 additions & 7 deletions

File tree

admin-app/src/main/resources/openapi.yml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,54 @@ paths:
189189
application/json:
190190
schema:
191191
$ref: '#/components/schemas/MessageResponse'
192+
/api/data-ingest/test-definitions:
193+
post:
194+
summary: Save test definitions
195+
operationId: postTestDefinitions
196+
tags:
197+
- data-ingest
198+
security:
199+
- apiKeyAuth: [ ]
200+
requestBody:
201+
required: true
202+
content:
203+
application/json:
204+
schema:
205+
$ref: '#/components/schemas/AddTestDefinitionsPayload'
206+
application/protobuf:
207+
schema:
208+
$ref: '#/components/schemas/AddTestDefinitionsPayload'
209+
responses:
210+
'200':
211+
description: Test definitions saved
212+
content:
213+
application/json:
214+
schema:
215+
$ref: '#/components/schemas/MessageResponse'
216+
/api/data-ingest/test-launches:
217+
post:
218+
summary: Save test launches
219+
operationId: postTestLaunches
220+
tags:
221+
- data-ingest
222+
security:
223+
- apiKeyAuth: [ ]
224+
requestBody:
225+
required: true
226+
content:
227+
application/json:
228+
schema:
229+
$ref: '#/components/schemas/AddTestLaunchesPayload'
230+
application/protobuf:
231+
schema:
232+
$ref: '#/components/schemas/AddTestLaunchesPayload'
233+
responses:
234+
'200':
235+
description: Test launches saved
236+
content:
237+
application/json:
238+
schema:
239+
$ref: '#/components/schemas/MessageResponse'
192240
/api/data-ingest/sessions:
193241
put:
194242
summary: Save test sessions
@@ -1644,6 +1692,78 @@ components:
16441692
- SKIPPED
16451693
- SMART_SKIPPED
16461694
- UNKNOWN
1695+
AddTestDefinitionsPayload:
1696+
type: object
1697+
required:
1698+
- groupId
1699+
- definitions
1700+
properties:
1701+
groupId:
1702+
type: string
1703+
definitions:
1704+
type: array
1705+
items:
1706+
$ref: '#/components/schemas/TestDefinitionPayload'
1707+
TestDefinitionPayload:
1708+
type: object
1709+
required:
1710+
- id
1711+
- runner
1712+
- name
1713+
properties:
1714+
id:
1715+
type: string
1716+
runner:
1717+
type: string
1718+
name:
1719+
type: string
1720+
type:
1721+
type: string
1722+
nullable: true
1723+
path:
1724+
type: string
1725+
nullable: true
1726+
tags:
1727+
type: array
1728+
items:
1729+
type: string
1730+
default: [ ]
1731+
metadata:
1732+
type: object
1733+
nullable: true
1734+
additionalProperties: true
1735+
AddTestLaunchesPayload:
1736+
type: object
1737+
required:
1738+
- groupId
1739+
- testSessionId
1740+
- launches
1741+
properties:
1742+
groupId:
1743+
type: string
1744+
testSessionId:
1745+
type: string
1746+
launches:
1747+
type: array
1748+
items:
1749+
$ref: '#/components/schemas/TestLaunchPayload'
1750+
TestLaunchPayload:
1751+
type: object
1752+
required:
1753+
- id
1754+
- testDefinitionId
1755+
properties:
1756+
id:
1757+
type: string
1758+
testDefinitionId:
1759+
type: string
1760+
result:
1761+
type: string
1762+
nullable: true
1763+
duration:
1764+
type: integer
1765+
format: int32
1766+
nullable: true
16471767
SessionPayload:
16481768
type: object
16491769
properties:

admin-writer/src/main/kotlin/com/epam/drill/admin/writer/rawdata/route/RawDataWriterRoutes.kt

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,22 @@
1616
package com.epam.drill.admin.writer.rawdata.route
1717

1818
import com.epam.drill.admin.common.principal.User
19+
import com.epam.drill.admin.common.route.ok
1920
import com.epam.drill.admin.writer.rawdata.service.RawDataWriter
2021
import io.ktor.client.*
2122
import io.ktor.client.engine.apache.*
2223
import io.ktor.client.plugins.contentnegotiation.*
2324
import io.ktor.client.request.*
2425
import io.ktor.http.*
2526
import io.ktor.resources.*
26-
import io.ktor.server.resources.put
27-
import io.ktor.server.resources.post
28-
import io.ktor.server.resources.get
29-
import io.ktor.server.resources.delete
3027
import io.ktor.serialization.kotlinx.json.*
3128
import io.ktor.server.application.*
29+
import io.ktor.server.auth.*
3230
import io.ktor.server.plugins.*
3331
import io.ktor.server.request.*
32+
import io.ktor.server.resources.*
33+
import io.ktor.server.resources.post
34+
import io.ktor.server.resources.put
3435
import io.ktor.server.routing.*
3536
import kotlinx.coroutines.Dispatchers
3637
import kotlinx.coroutines.withContext
@@ -42,8 +43,6 @@ import org.kodein.di.instance
4243
import org.kodein.di.ktor.closestDI
4344
import java.io.InputStream
4445
import java.util.zip.GZIPInputStream
45-
import com.epam.drill.admin.common.route.ok
46-
import io.ktor.server.auth.principal
4746

4847
private val logger = KotlinLogging.logger {}
4948

@@ -65,6 +64,12 @@ class TestMetadataRoute()
6564
@Resource("sessions")
6665
class TestSessionRoute()
6766

67+
@Resource("test-definitions")
68+
class TestDefinitionsRoute()
69+
70+
@Resource("test-launches")
71+
class TestLaunchesRoute()
72+
6873
@Resource("method-ignore-rules")
6974
class MethodIgnoreRulesRoute() {
7075
@Resource("/{id}")
@@ -81,6 +86,8 @@ fun Route.dataIngestRoutes() {
8186
putMethods()
8287
postTestMetadata()
8388
putTestSessions()
89+
postTestDefinitions()
90+
postTestLaunches()
8491
postMethodIgnoreRules()
8592
getMethodIgnoreRules()
8693
deleteMethodIgnoreRule()
@@ -142,6 +149,24 @@ fun Route.putTestSessions() {
142149
}
143150
}
144151

152+
fun Route.postTestDefinitions() {
153+
val rawDataWriter by closestDI().instance<RawDataWriter>()
154+
155+
post<TestDefinitionsRoute> {
156+
rawDataWriter.saveTestDefinitions(call.decompressAndReceive())
157+
call.ok("Test definitions saved")
158+
}
159+
}
160+
161+
fun Route.postTestLaunches() {
162+
val rawDataWriter by closestDI().instance<RawDataWriter>()
163+
164+
post<TestLaunchesRoute> {
165+
rawDataWriter.saveTestLaunches(call.decompressAndReceive())
166+
call.ok("Test launches saved")
167+
}
168+
}
169+
145170
fun Route.postMethodIgnoreRules() {
146171
val rawDataWriter by closestDI().instance<RawDataWriter>()
147172

admin-writer/src/main/kotlin/com/epam/drill/admin/writer/rawdata/route/payload/TestMetadataPayload.kt

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import kotlinx.datetime.Instant
1919
import kotlinx.serialization.Serializable
2020
import kotlinx.serialization.json.JsonElement
2121

22-
// TODO rework alongside with Java Autotest Agent
22+
// TODO update test agent
2323
@Serializable
2424
class AddTestsPayload(
2525
val groupId: String,
@@ -70,4 +70,41 @@ class SessionPayload(
7070
val testTaskId: String,
7171
val startedAt: Instant,
7272
val builds: List<SingleSessionBuildPayload> = emptyList(),
73+
)
74+
75+
@Serializable
76+
class AddTestLaunchesPayload(
77+
val groupId: String,
78+
val testSessionId: String,
79+
val launches: List<TestLaunchPayload>,
80+
)
81+
82+
@Serializable
83+
class TestLaunchPayload (
84+
val id: String,
85+
val testDefinitionId: String,
86+
val result: String?,
87+
val duration: Int? = null,
88+
)
89+
90+
91+
@Serializable
92+
class AddTestDefinitionsPayload(
93+
val groupId: String,
94+
val definitions: List<TestDefinitionPayload>
95+
)
96+
97+
// TODO: update test agent
98+
// Order of fields, and field definitions changed compared to original TestDefinition class:
99+
// - name and runner are no longer nullable
100+
// - type field is moved and became nullable
101+
@Serializable
102+
class TestDefinitionPayload(
103+
val id: String,
104+
val runner: String,
105+
val name: String,
106+
val type: String?,
107+
val path: String?,
108+
val tags: List<String> = emptyList(),
109+
val metadata: JsonElement? = null,
73110
)

admin-writer/src/main/kotlin/com/epam/drill/admin/writer/rawdata/service/RawDataWriter.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ interface RawDataWriter {
2525
suspend fun saveMethods(methodsPayload: MethodsPayload)
2626
suspend fun saveCoverage(coveragePayload: CoveragePayload)
2727
suspend fun saveTestMetadata(testsPayload: AddTestsPayload)
28+
suspend fun saveTestDefinitions(testDefinitionsPayload: AddTestDefinitionsPayload)
29+
suspend fun saveTestLaunches(testLaunchesPayload: AddTestLaunchesPayload)
2830
suspend fun saveTestSession(sessionPayload: SessionPayload, user: User?)
2931
suspend fun saveMethodIgnoreRule(rulePayload: MethodIgnoreRulePayload)
3032
suspend fun getAllMethodIgnoreRules(): List<MethodIgnoreRuleView>

admin-writer/src/main/kotlin/com/epam/drill/admin/writer/rawdata/service/impl/RawDataServiceImpl.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ class RawDataServiceImpl(
177177
}
178178
}
179179

180+
// WARNING: keep this method for backward compatibility with existing adoptions
180181
override suspend fun saveTestMetadata(testsPayload: AddTestsPayload) = transaction {
181182
testsPayload.tests.map { test ->
182183
TestLaunch(
@@ -203,6 +204,34 @@ class RawDataServiceImpl(
203204
}.let { testDefinitionRepository.createMany(it) }
204205
}
205206

207+
override suspend fun saveTestDefinitions(testDefinitionsPayload: AddTestDefinitionsPayload) = transaction {
208+
testDefinitionsPayload.definitions.map { definition ->
209+
TestDefinition(
210+
groupId = testDefinitionsPayload.groupId,
211+
id = definition.id,
212+
type = definition.type,
213+
runner = definition.runner,
214+
name = definition.name,
215+
path = definition.path,
216+
tags = definition.tags,
217+
metadata = definition.metadata
218+
)
219+
}.let { testDefinitionRepository.createMany(it) }
220+
}
221+
222+
override suspend fun saveTestLaunches(testLaunchesPayload: AddTestLaunchesPayload) = transaction {
223+
testLaunchesPayload.launches.map { launch ->
224+
TestLaunch(
225+
groupId = testLaunchesPayload.groupId,
226+
id = launch.id,
227+
testDefinitionId = launch.testDefinitionId,
228+
testSessionId = testLaunchesPayload.testSessionId,
229+
result = launch.result.toString(),
230+
duration = launch.duration
231+
)
232+
}.let { testLaunchRepository.createMany(it) }
233+
}
234+
206235
override suspend fun saveTestSession(sessionPayload: SessionPayload, user: User?) {
207236
val testSession = TestSession(
208237
id = sessionPayload.id,

0 commit comments

Comments
 (0)