Skip to content

Commit

Permalink
Rating: phase 0.5. TestingType, best_execution in `lnk_contest_pr…
Browse files Browse the repository at this point in the history
…oject` (#1142)

* Change `ExecutionType` to `TestingType`, pass `testingType` from the frontend
* Add columns for best execution and best score in `lnk_contest_project`

Part of #1115

Co-authored-by: Kirill Gevorkyan <[email protected]>
  • Loading branch information
petertrr and kgevorkyan authored Sep 5, 2022
1 parent ec7b29f commit 0cd2e5c
Show file tree
Hide file tree
Showing 24 changed files with 133 additions and 100 deletions.
12 changes: 6 additions & 6 deletions db/test-data/execution-insert.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<column name="test_suite_ids" value="1, 2, 3" />
<column name="resources_root_path" value="resources_root_path" />
<column name="batch_size" value="10" />
<column name="type" value="GIT" />
<column name="type" value="PRIVATE_TESTS" />
<column name="version" value="0.0.1" />
<column name="running_tests" value="3" />
<column name="passed_tests" value="9" />
Expand Down Expand Up @@ -43,7 +43,7 @@
<column name="test_suite_ids" value="1, 2, 3" />
<column name="resources_root_path" value="resources_root_path" />
<column name="batch_size" value="20" />
<column name="type" value="STANDARD" />
<column name="type" value="PUBLIC_TESTS" />
<column name="version" value="0.0.1" />
<column name="running_tests" value="0" />
<column name="passed_tests" value="0" />
Expand Down Expand Up @@ -71,7 +71,7 @@
<column name="test_suite_ids" value="4" />
<column name="resources_root_path" value="resources_root_path" />
<column name="batch_size" value="20" />
<column name="type" value="GIT" />
<column name="type" value="PRIVATE_TESTS" />
<column name="version" value="0.0.1" />
<column name="running_tests" value="2" />
<column name="passed_tests" value="0" />
Expand Down Expand Up @@ -99,7 +99,7 @@
<column name="test_suite_ids" value="1, 2, 3" />
<column name="resources_root_path" value="resources_root_path" />
<column name="batch_size" value="10" />
<column name="type" value="GIT" />
<column name="type" value="PRIVATE_TESTS" />
<column name="version" value="0.0.1" />
<column name="running_tests" value="3" />
<column name="passed_tests" value="9" />
Expand Down Expand Up @@ -127,7 +127,7 @@
<column name="test_suite_ids" value="11" />
<column name="resources_root_path" value="resources_root_path" />
<column name="batch_size" value="20" />
<column name="type" value="STANDARD" />
<column name="type" value="PUBLIC_TESTS" />
<column name="version" value="0.0.1" />
<column name="running_tests" value="0" />
<column name="passed_tests" value="0" />
Expand Down Expand Up @@ -156,7 +156,7 @@
<column name="test_suite_ids" value="11" />
<column name="resources_root_path" value="resources_root_path" />
<column name="batch_size" value="20" />
<column name="type" value="STANDARD" />
<column name="type" value="PUBLIC_TESTS" />
<column name="version" value="0.0.1" />
<column name="running_tests" value="0" />
<column name="passed_tests" value="0" />
Expand Down
9 changes: 9 additions & 0 deletions db/v-2/tables/lnk-contest-project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,13 @@
<dropColumn tableName="lnk_contest_project" columnName="score"/>
</changeSet>

<changeSet id="lnk_contest_project_add_best_execution" author="petertrr">
<addColumn tableName="lnk_contest_project">
<column name="best_execution_id" type="bigint" defaultValue="null">
<constraints foreignKeyName="fk_lnk_contest_project_execution" references="execution(id)" nullable="true"/>
</column>
<column name="best_score" type="bigint"/>
</addColumn>
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
package com.saveourtool.save.apicli

import com.saveourtool.save.api.authorization.Authorization
import com.saveourtool.save.execution.ExecutionType
import com.saveourtool.save.execution.TestingType

import org.slf4j.LoggerFactory

Expand All @@ -22,7 +22,7 @@ private val log = LoggerFactory.getLogger(object {}.javaClass.enclosingClass::cl
*/
data class CliArguments(
val authorization: Authorization,
val mode: ExecutionType,
val mode: TestingType,
)

/**
Expand Down Expand Up @@ -60,7 +60,7 @@ fun parseArguments(args: Array<String>): CliArguments? {
)

val mode by parser.option(
ArgType.Choice<ExecutionType>(),
ArgType.Choice<TestingType>(),
fullName = "mode",
shortName = "m",
description = "Mode of execution: git/standard"
Expand Down
2 changes: 1 addition & 1 deletion save-api-cli/src/main/resources/evaluated-tool.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ organizationName=saveourtool.com

# Required
# Name of project
projectName=Diktat
projectName=save

# Optional
# SDK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import com.saveourtool.save.entities.GitDto
import com.saveourtool.save.entities.Project
import com.saveourtool.save.execution.ExecutionDto
import com.saveourtool.save.execution.ExecutionStatus
import com.saveourtool.save.execution.ExecutionType
import com.saveourtool.save.execution.TestingType

import io.ktor.client.*
import io.ktor.http.*
Expand All @@ -38,7 +38,7 @@ import kotlinx.coroutines.delay
class SaveCloudClient(
webClientProperties: WebClientProperties,
private val evaluatedToolProperties: EvaluatedToolProperties,
private val executionType: ExecutionType,
private val testingType: TestingType,
authorization: Authorization,
) {
private val log = LoggerFactory.getLogger(SaveCloudClient::class.java)
Expand All @@ -65,9 +65,9 @@ class SaveCloudClient(
} ?: {
"without additional files"
}
log.info("Starting submit execution $msg, type: $executionType")
log.info("Starting submit execution $msg, type: $testingType")

val executionRequest = submitExecution(executionType, additionalFileInfoList) ?: return
val executionRequest = submitExecution(testingType, additionalFileInfoList) ?: return

// Sending requests, which checks current state, until results will be received
// TODO: in which form do we actually need results?
Expand All @@ -81,23 +81,23 @@ class SaveCloudClient(
}

/**
* Submit execution according [executionType]
* Submit execution according [testingType]
*
* @param executionType
* @param testingType
* @param additionalFiles
* @return pair of organization and submitted execution request
*/
private suspend fun submitExecution(
executionType: ExecutionType,
testingType: TestingType,
additionalFiles: List<ShortFileInfo>?
): ExecutionRequestBase? {
val executionRequest = if (executionType == ExecutionType.GIT) {
val executionRequest = if (testingType == TestingType.PRIVATE_TESTS) {
buildExecutionRequest()
} else {
val userProvidedTestSuites = verifyTestSuites() ?: return null
buildExecutionRequestForStandardSuites(userProvidedTestSuites)
}
val response = httpClient.submitExecution(executionType, executionRequest, additionalFiles)
val response = httpClient.submitExecution(testingType, executionRequest, additionalFiles)
if (response.status != HttpStatusCode.OK && response.status != HttpStatusCode.Accepted) {
log.error("Can't submit execution=$executionRequest! Response status: ${response.status}")
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.saveourtool.save.entities.ExecutionRequestBase
import com.saveourtool.save.entities.ExecutionRequestForStandardSuites
import com.saveourtool.save.entities.Project
import com.saveourtool.save.execution.ExecutionDto
import com.saveourtool.save.execution.ExecutionType
import com.saveourtool.save.execution.TestingType
import com.saveourtool.save.testsuite.TestSuiteDto
import com.saveourtool.save.utils.LocalDateTimeSerializer
import com.saveourtool.save.utils.extractUserNameAndSource
Expand Down Expand Up @@ -118,8 +118,8 @@ suspend fun HttpClient.getStandardTestSuites(
*/
@OptIn(InternalAPI::class)
@Suppress("TOO_LONG_FUNCTION")
suspend fun HttpClient.submitExecution(executionType: ExecutionType, executionRequest: ExecutionRequestBase, additionalFiles: List<ShortFileInfo>?): HttpResponse {
val endpoint = if (executionType == ExecutionType.GIT) {
suspend fun HttpClient.submitExecution(executionType: TestingType, executionRequest: ExecutionRequestBase, additionalFiles: List<ShortFileInfo>?): HttpResponse {
val endpoint = if (executionType == TestingType.PRIVATE_TESTS) {
"/api/$v1/submitExecutionRequest"
} else {
"/api/$v1/executionRequestStandardTests"
Expand All @@ -131,7 +131,7 @@ suspend fun HttpClient.submitExecution(executionType: ExecutionType, executionRe
append(HttpHeaders.ContentType, ContentType.Application.Json)
}
setBody(MultiPartFormDataContent(formData {
if (executionType == ExecutionType.GIT) {
if (executionType == TestingType.PRIVATE_TESTS) {
append(
"executionRequest",
json.encodeToString(executionRequest as ExecutionRequest),
Expand Down
2 changes: 1 addition & 1 deletion save-backend/Backend-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ The response format will look like:
{
"id": 42, # execution id
"status": "FINISHED", # execution status, i.e. running, finished and so on
"type":"GIT", # execution type
"type":"PRIVATE_TESTS", # testing type
"version": "264e5feb8f4c6410d70536d6fc4bdf090df62287", # commit hash
"startTime": 1651856549, # start time of execution in Unix format
"endTime": 1651856797, # end time of execution in Unix format
Expand Down
39 changes: 28 additions & 11 deletions save-backend/backend-api-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,8 @@
}
}
}
}
},
"deprecated": true
}
},
"/api/v1/run/trigger": {
Expand All @@ -804,6 +805,21 @@
"run-execution-controller"
],
"operationId": "trigger",
"parameters": [
{
"name": "testingType",
"in": "query",
"required": true,
"schema": {
"type": "string",
"enum": [
"CONTEST_MODE",
"PRIVATE_TESTS",
"PUBLIC_TESTS"
]
}
}
],
"requestBody": {
"content": {
"application/json": {
Expand Down Expand Up @@ -2103,7 +2119,8 @@
}
}
}
}
},
"deprecated": true
}
},
"/api/v1/execution/delete": {
Expand Down Expand Up @@ -4861,7 +4878,7 @@
],
"summary": "Get contests that can be participated.",
"description": "Get list of contest names that a given project can participate in.",
"operationId": "getAvaliableContestsForProject",
"operationId": "getAvailableContestsForProject",
"parameters": [
{
"name": "organizationName",
Expand Down Expand Up @@ -5648,7 +5665,7 @@
],
"summary": "Get projects that can participate in contest.",
"description": "Get list of user\u0027s projects that can participate in a given contest.",
"operationId": "getAvaliableProjectsForContest",
"operationId": "getAvailableProjectsForContest",
"parameters": [
{
"name": "contestName",
Expand All @@ -5668,7 +5685,7 @@
],
"responses": {
"200": {
"description": "Successfully fetched projects avaliable for contest.",
"description": "Successfully fetched projects available for contest.",
"content": {
"*/*": {
"schema": {
Expand Down Expand Up @@ -7347,9 +7364,9 @@
"type": {
"type": "string",
"enum": [
"CONTEST",
"GIT",
"STANDARD"
"CONTEST_MODE",
"PRIVATE_TESTS",
"PUBLIC_TESTS"
]
},
"version": {
Expand Down Expand Up @@ -7533,9 +7550,9 @@
"type": {
"type": "string",
"enum": [
"CONTEST",
"GIT",
"STANDARD"
"CONTEST_MODE",
"PRIVATE_TESTS",
"PUBLIC_TESTS"
]
},
"version": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.saveourtool.save.backend.storage.TestSuitesSourceSnapshotStorage
import com.saveourtool.save.backend.utils.blockingToMono
import com.saveourtool.save.domain.*
import com.saveourtool.save.entities.*
import com.saveourtool.save.execution.TestingType
import com.saveourtool.save.testsuite.TestSuitesSourceSnapshotKey
import com.saveourtool.save.utils.getLogger
import com.saveourtool.save.utils.orNotFound
Expand All @@ -27,6 +28,7 @@ import reactor.kotlin.core.util.function.component2
*/
@RestController
@RequestMapping("/api")
@Deprecated("All new logic should use RunExecutionController's endpoints")
class CloneRepositoryController(
private val testSuitesService: TestSuitesService,
private val testSuitesSourceService: TestSuitesSourceService,
Expand All @@ -50,6 +52,7 @@ class CloneRepositoryController(
): Mono<StringResponse> =
sendToTrigger(
executionRequest,
TestingType.PRIVATE_TESTS,
authentication,
files,
{ true }
Expand Down Expand Up @@ -87,16 +90,23 @@ class CloneRepositoryController(
): Mono<StringResponse> =
sendToTrigger(
executionRequestForStandardSuites,
TestingType.PUBLIC_TESTS,
authentication,
files,
{ it.name in executionRequestForStandardSuites.testSuites }
) {
testSuitesSourceService.getStandardTestSuitesSources()
}

@Suppress("TOO_LONG_FUNCTION", "TOO_MANY_LINES_IN_LAMBDA")
@Suppress(
"TOO_LONG_FUNCTION",
"TOO_MANY_LINES_IN_LAMBDA",
"TOO_MANY_PARAMETERS",
"LongParameterList",
)
private fun <T : ExecutionRequestBase> sendToTrigger(
executionRequest: T,
testingType: TestingType,
authentication: Authentication,
shortFiles: Flux<ShortFileInfo>,
testSuitesFilter: (TestSuite) -> Boolean,
Expand Down Expand Up @@ -143,7 +153,7 @@ class CloneRepositoryController(
)
}
.flatMap {
runExecutionController.trigger(it, authentication)
runExecutionController.trigger(it, testingType, authentication)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ class LnkContestProjectController(
@Parameters(
Parameter(name = "contestName", `in` = ParameterIn.PATH, description = "name of a contest", required = true),
)
@ApiResponse(responseCode = "200", description = "Successfully fetched projects avaliable for contest.")
fun getAvaliableProjectsForContest(
@ApiResponse(responseCode = "200", description = "Successfully fetched projects available for contest.")
fun getAvailableProjectsForContest(
@PathVariable contestName: String,
authentication: Authentication,
): Mono<List<String>> = Mono.fromCallable {
Expand All @@ -138,7 +138,7 @@ class LnkContestProjectController(
Parameter(name = "projectName", `in` = ParameterIn.PATH, description = "name of a project", required = true),
)
@ApiResponse(responseCode = "200", description = "Successfully fetched contests avaliable for project.")
fun getAvaliableContestsForProject(
fun getAvailableContestsForProject(
@PathVariable organizationName: String,
@PathVariable projectName: String,
authentication: Authentication,
Expand Down
Loading

0 comments on commit 0cd2e5c

Please sign in to comment.