Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rating: phase 0.5. TestingType, best_execution in lnk_contest_project #1142

Merged
merged 18 commits into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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="PUBLIC_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="PRIVATE_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="PUBLIC_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="PUBLIC_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="PRIVATE_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="PRIVATE_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.PUBLIC_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.PUBLIC_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.PUBLIC_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":"PUBLIC_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
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,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 @@ -141,7 +141,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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.saveourtool.save.utils.switchIfEmptyToResponseException
import com.saveourtool.save.v1

import com.fasterxml.jackson.databind.ObjectMapper
import com.saveourtool.save.execution.TestingType
import io.micrometer.core.instrument.MeterRegistry
import org.slf4j.Logger
import org.springframework.http.HttpStatus
Expand Down Expand Up @@ -68,6 +69,7 @@ class RunExecutionController(
@PostMapping("/trigger")
fun trigger(
@RequestBody request: RunExecutionRequest,
@RequestParam testingType: TestingType,
petertrr marked this conversation as resolved.
Show resolved Hide resolved
authentication: Authentication,
): Mono<StringResponse> = Mono.just(request.projectCoordinates)
.validateAccess(authentication) { it }
Expand All @@ -79,7 +81,8 @@ class RunExecutionController(
username = authentication.username(),
sdk = request.sdk,
execCmd = request.execCmd,
batchSizeForAnalyzer = request.batchSizeForAnalyzer
batchSizeForAnalyzer = request.batchSizeForAnalyzer,
testingType = testingType
)
}
.subscribeOn(Schedulers.boundedElastic())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.saveourtool.save.entities.Execution
import com.saveourtool.save.entities.Organization
import com.saveourtool.save.entities.Project
import com.saveourtool.save.execution.ExecutionStatus
import com.saveourtool.save.execution.ExecutionType
import com.saveourtool.save.execution.TestingType
import com.saveourtool.save.utils.debug
import com.saveourtool.save.utils.orNotFound

Expand Down Expand Up @@ -135,6 +135,7 @@ class ExecutionService(
* @param sdk
* @param execCmd
* @param batchSizeForAnalyzer
* @param testingType
* @return new [Execution] with provided values
*/
@Suppress("LongParameterList", "TOO_MANY_PARAMETERS")
Expand All @@ -147,6 +148,7 @@ class ExecutionService(
sdk: Sdk,
execCmd: String?,
batchSizeForAnalyzer: String?,
testingType: TestingType
): Execution {
val project = with(projectCoordinates) {
projectService.findByNameAndOrganizationName(projectName, organizationName).orNotFound {
Expand All @@ -165,6 +167,7 @@ class ExecutionService(
sdk = sdk.toString(),
execCmd = execCmd,
batchSizeForAnalyzer = batchSizeForAnalyzer,
testingType = testingType
)
}

Expand All @@ -187,6 +190,7 @@ class ExecutionService(
sdk = execution.sdk,
execCmd = execution.execCmd,
batchSizeForAnalyzer = execution.batchSizeForAnalyzer,
testingType = execution.type,
)

@Suppress("LongParameterList", "TOO_MANY_PARAMETERS", "UnsafeCallOnNullableType")
Expand All @@ -200,6 +204,7 @@ class ExecutionService(
sdk: String,
execCmd: String?,
batchSizeForAnalyzer: String?,
testingType: TestingType
): Execution {
val user = userRepository.findByName(username).orNotFound {
"Not found user $username"
Expand All @@ -214,8 +219,7 @@ class ExecutionService(
status = ExecutionStatus.PENDING,
testSuiteIds = formattedTestSuiteIds,
batchSize = configProperties.initialBatchSize,
// FIXME: remove this type
type = ExecutionType.GIT,
type = testingType,
version = version,
allTests = allTests,
runningTests = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class LnkContestProjectService(
fun saveLnkContestProject(project: Project, contest: Contest): Boolean = if (lnkContestProjectRepository.findByContestAndProject(contest, project).isPresent) {
false
} else {
lnkContestProjectRepository.save(LnkContestProject(project, contest))
lnkContestProjectRepository.save(LnkContestProject(project, contest, null, 0))
true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import com.saveourtool.save.domain.Jdk
import com.saveourtool.save.domain.ProjectCoordinates
import com.saveourtool.save.domain.toFileInfo
import com.saveourtool.save.entities.*
import com.saveourtool.save.execution.ExecutionType
import com.saveourtool.save.execution.TestingType
import com.saveourtool.save.testsuite.TestSuitesSourceSnapshotKey
import com.saveourtool.save.testutils.checkQueues
import com.saveourtool.save.testutils.cleanup
Expand Down Expand Up @@ -227,7 +227,7 @@ class CloneRepoTest {
executionRepository.findAll().shouldExist {
it.project.name == project.name &&
it.project.organization == project.organization &&
it.type == ExecutionType.GIT &&
it.type == TestingType.PUBLIC_TESTS &&
it.sdk == sdk.toString()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.saveourtool.save.backend.utils.MySqlExtension
import com.saveourtool.save.backend.utils.mutateMockedUser
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 com.saveourtool.save.execution.ExecutionUpdateDto
import com.saveourtool.save.utils.debug
import com.saveourtool.save.utils.getLogger
Expand Down Expand Up @@ -97,7 +97,7 @@ class ExecutionControllerTest {
.expectBody<ExecutionDto>()
.consumeWith {
requireNotNull(it.responseBody)
assertEquals(ExecutionType.GIT, it.responseBody!!.type)
assertEquals(TestingType.PUBLIC_TESTS, it.responseBody!!.type)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import kotlinx.serialization.Serializable
data class ExecutionDto(
val id: Long,
val status: ExecutionStatus,
val type: ExecutionType,
val type: TestingType,
val version: String?,
val startTime: Long,
val endTime: Long?,
Expand All @@ -44,7 +44,7 @@ data class ExecutionDto(
val empty = ExecutionDto(
id = -1,
status = ExecutionStatus.PENDING,
type = ExecutionType.STANDARD,
type = TestingType.PRIVATE_TESTS,
version = null,
startTime = -1,
endTime = null,
Expand Down

This file was deleted.

Loading