Skip to content

Commit

Permalink
refactor: Remove storage properties from ScannerConfiguration
Browse files Browse the repository at this point in the history
The ORT Server uses its own storage implementations and does not offer
a way to configure other storages. Therefore the storage related
properties can be removed from `ScannerConfiguration`, as they have
never been used. Related configuration classes and database tables will
be removed in subsequent commits.

If required, support for other storages might be added later on, this
might make sense to integrate external scan result storages like
ClearlyDefined. But this should be done after scan storages have become
plugins in ORT [1], because then they would share one configuration
model and would not require dedicated database tables anymore.

[1]: oss-review-toolkit/ort#6603

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
  • Loading branch information
mnonnenmacher committed May 2, 2024
1 parent f0dada5 commit 152d6ee
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 267 deletions.
125 changes: 0 additions & 125 deletions dao/src/main/kotlin/repositories/DaoScannerRunRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,45 +27,25 @@ import org.eclipse.apoapsis.ortserver.dao.entityQuery
import org.eclipse.apoapsis.ortserver.dao.mapAndDeduplicate
import org.eclipse.apoapsis.ortserver.dao.tables.ScannerJobDao
import org.eclipse.apoapsis.ortserver.dao.tables.provenance.PackageProvenanceDao
import org.eclipse.apoapsis.ortserver.dao.tables.runs.scanner.ClearlyDefinedStorageConfigurationDao
import org.eclipse.apoapsis.ortserver.dao.tables.runs.scanner.DetectedLicenseMappingDao
import org.eclipse.apoapsis.ortserver.dao.tables.runs.scanner.FileArchiverConfigurationDao
import org.eclipse.apoapsis.ortserver.dao.tables.runs.scanner.FileBasedStorageConfigurationDao
import org.eclipse.apoapsis.ortserver.dao.tables.runs.scanner.FileStorageConfigurationDao
import org.eclipse.apoapsis.ortserver.dao.tables.runs.scanner.HttpFileStorageConfigurationDao
import org.eclipse.apoapsis.ortserver.dao.tables.runs.scanner.LocalFileStorageConfigurationDao
import org.eclipse.apoapsis.ortserver.dao.tables.runs.scanner.PostgresConnectionDao
import org.eclipse.apoapsis.ortserver.dao.tables.runs.scanner.PostgresStorageConfigurationDao
import org.eclipse.apoapsis.ortserver.dao.tables.runs.scanner.ProvenanceStorageConfigurationDao
import org.eclipse.apoapsis.ortserver.dao.tables.runs.scanner.ScannerConfigurationDao
import org.eclipse.apoapsis.ortserver.dao.tables.runs.scanner.ScannerConfigurationOptionDao
import org.eclipse.apoapsis.ortserver.dao.tables.runs.scanner.ScannerConfigurationSecretDao
import org.eclipse.apoapsis.ortserver.dao.tables.runs.scanner.ScannerConfigurationStorageDao
import org.eclipse.apoapsis.ortserver.dao.tables.runs.scanner.ScannerConfigurationsOptionsTable
import org.eclipse.apoapsis.ortserver.dao.tables.runs.scanner.ScannerConfigurationsSecretsTable
import org.eclipse.apoapsis.ortserver.dao.tables.runs.scanner.ScannerRunDao
import org.eclipse.apoapsis.ortserver.dao.tables.runs.scanner.ScannerRunsScannersDao
import org.eclipse.apoapsis.ortserver.dao.tables.runs.scanner.ScannerRunsScannersTable
import org.eclipse.apoapsis.ortserver.dao.tables.runs.scanner.ScannerRunsTable
import org.eclipse.apoapsis.ortserver.dao.tables.runs.scanner.StorageConfigurationDao
import org.eclipse.apoapsis.ortserver.dao.tables.runs.scanner.Sw360StorageConfigurationDao
import org.eclipse.apoapsis.ortserver.dao.tables.runs.shared.EnvironmentDao
import org.eclipse.apoapsis.ortserver.model.repositories.ScannerRunRepository
import org.eclipse.apoapsis.ortserver.model.runs.Environment
import org.eclipse.apoapsis.ortserver.model.runs.Identifier
import org.eclipse.apoapsis.ortserver.model.runs.OrtIssue
import org.eclipse.apoapsis.ortserver.model.runs.scanner.ClearlyDefinedStorageConfiguration
import org.eclipse.apoapsis.ortserver.model.runs.scanner.FileArchiveConfiguration
import org.eclipse.apoapsis.ortserver.model.runs.scanner.FileBasedStorageConfiguration
import org.eclipse.apoapsis.ortserver.model.runs.scanner.FileStorageConfiguration
import org.eclipse.apoapsis.ortserver.model.runs.scanner.KnownProvenance
import org.eclipse.apoapsis.ortserver.model.runs.scanner.PostgresStorageConfiguration
import org.eclipse.apoapsis.ortserver.model.runs.scanner.ProvenanceResolutionResult
import org.eclipse.apoapsis.ortserver.model.runs.scanner.ProvenanceStorageConfiguration
import org.eclipse.apoapsis.ortserver.model.runs.scanner.ScanStorageConfiguration
import org.eclipse.apoapsis.ortserver.model.runs.scanner.ScannerConfiguration
import org.eclipse.apoapsis.ortserver.model.runs.scanner.ScannerRun
import org.eclipse.apoapsis.ortserver.model.runs.scanner.Sw360StorageConfiguration

import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.insert
Expand Down Expand Up @@ -195,8 +175,6 @@ private fun createScannerConfiguration(
this.skipConcluded = scannerConfiguration.skipConcluded
this.createMissingArchives = scannerConfiguration.createMissingArchives
this.ignorePatterns = scannerConfiguration.ignorePatterns
this.storageReaders = scannerConfiguration.storageReaders
this.storageWriters = scannerConfiguration.storageWriters
this.detectedLicenseMappings = detectedLicenseMappings
}

Expand All @@ -220,112 +198,9 @@ private fun createScannerConfiguration(
}
}

createFileArchiverConfiguration(scannerConfigurationDao, scannerConfiguration.archive)
createProvenanceStorageConfiguration(scannerConfigurationDao, scannerConfiguration.provenanceStorage)
createStorages(scannerConfigurationDao, scannerConfiguration.storages)

return scannerConfigurationDao
}

fun createStorages(
scannerConfigurationDao: ScannerConfigurationDao,
storages: Map<String, ScanStorageConfiguration?>?
): List<StorageConfigurationDao?>? =
storages?.map { (storage, storageConfiguration) ->
val scannerStorageConfigurationDao = ScannerConfigurationStorageDao.new {
this.scannerConfiguration = scannerConfigurationDao
this.storage = storage
}

when (storageConfiguration) {
is ClearlyDefinedStorageConfiguration -> {
StorageConfigurationDao.new {
this.scannerConfigurationStorage = scannerStorageConfigurationDao
this.clearlyDefinedStorageConfiguration = ClearlyDefinedStorageConfigurationDao
.getOrPut(storageConfiguration)
}
}

is PostgresStorageConfiguration -> {
StorageConfigurationDao.new {
this.scannerConfigurationStorage = scannerStorageConfigurationDao
this.postgresStorageConfiguration = createPostgresStorageConfiguration(storageConfiguration)
}
}

is FileBasedStorageConfiguration -> {
StorageConfigurationDao.new {
this.scannerConfigurationStorage = scannerStorageConfigurationDao
this.fileBasedStorageConfiguration = createFileBasedStorageConfiguration(storageConfiguration)
}
}

is Sw360StorageConfiguration -> {
StorageConfigurationDao.new {
this.scannerConfigurationStorage = scannerStorageConfigurationDao
this.sw360StorageConfiguration = Sw360StorageConfigurationDao.getOrPut(storageConfiguration)
}
}

else -> null
}
}

private fun createProvenanceStorageConfiguration(
scannerConfigurationDao: ScannerConfigurationDao,
provenanceStorageConfiguration: ProvenanceStorageConfiguration?
): ProvenanceStorageConfigurationDao? =
provenanceStorageConfiguration?.let {
ProvenanceStorageConfigurationDao.new {
this.scannerConfiguration = scannerConfigurationDao
this.fileStorageConfiguration = it.fileStorage?.let { createFileStorageConfiguration(it) }
this.postgresStorageConfiguration = it.postgresStorageConfiguration?.let {
createPostgresStorageConfiguration(it)
}
}
}

private fun createFileArchiverConfiguration(
scannerConfigurationDao: ScannerConfigurationDao,
archive: FileArchiveConfiguration?
): FileArchiverConfigurationDao? =
archive?.let {
FileArchiverConfigurationDao.new {
this.scannerConfiguration = scannerConfigurationDao
this.fileStorageConfiguration = it.fileStorage?.let { createFileStorageConfiguration(it) }
this.postgresStorageConfiguration = it.postgresStorage?.let { createPostgresStorageConfiguration(it) }
}
}

private fun createFileStorageConfiguration(
fileStorageConfiguration: FileStorageConfiguration
): FileStorageConfigurationDao =
FileStorageConfigurationDao.new {
this.localFileStorageConfiguration = fileStorageConfiguration.localFileStorage?.let {
LocalFileStorageConfigurationDao.getOrPut(it)
}

this.httpFileStorageConfiguration = fileStorageConfiguration.httpFileStorage?.let {
HttpFileStorageConfigurationDao.getOrPut(it)
}
}

private fun createPostgresStorageConfiguration(
postgresStorageConfiguration: PostgresStorageConfiguration
): PostgresStorageConfigurationDao =
PostgresStorageConfigurationDao.new {
this.postgresConnection = PostgresConnectionDao.getOrPut(postgresStorageConfiguration.connection)
this.type = postgresStorageConfiguration.type
}

private fun createFileBasedStorageConfiguration(
fileBasedStorageConfiguration: FileBasedStorageConfiguration
): FileBasedStorageConfigurationDao =
FileBasedStorageConfigurationDao.new {
this.fileStorageConfiguration = createFileStorageConfiguration(fileBasedStorageConfiguration.backend)
this.type = fileBasedStorageConfiguration.type
}

private fun createScanners(run: ScannerRunDao, scanners: Map<Identifier, Set<String>>) {
scanners.entries.forEach { (id, scannerNames) ->
scannerNames.forEach { scanner ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,10 @@ class ScannerConfigurationDao(id: EntityID<Long>) : LongEntity(id) {

return ScannerConfiguration(
skipConcluded = skipConcluded,
archive = fileArchiveConfiguration?.mapToModel(),
createMissingArchives = createMissingArchives,
detectedLicenseMappings = detectedLicenseMappings.associate { it.license to it.spdxLicense },
config = config,
storages = storages.associate { it.storage to it.storages.mapToModel() },
storageReaders = storageReaders,
storageWriters = storageWriters,
ignorePatterns = ignorePatterns.orEmpty(),
provenanceStorage = provenanceStorageConfiguration?.mapToModel()
ignorePatterns = ignorePatterns.orEmpty()
)
}
}
47 changes: 1 addition & 46 deletions dao/src/test/kotlin/repositories/DaoScannerRunRepositoryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,7 @@ import org.eclipse.apoapsis.ortserver.model.runs.Identifier
import org.eclipse.apoapsis.ortserver.model.runs.RemoteArtifact
import org.eclipse.apoapsis.ortserver.model.runs.VcsInfo
import org.eclipse.apoapsis.ortserver.model.runs.scanner.ArtifactProvenance
import org.eclipse.apoapsis.ortserver.model.runs.scanner.ClearlyDefinedStorageConfiguration
import org.eclipse.apoapsis.ortserver.model.runs.scanner.FileArchiveConfiguration
import org.eclipse.apoapsis.ortserver.model.runs.scanner.FileBasedStorageConfiguration
import org.eclipse.apoapsis.ortserver.model.runs.scanner.FileStorageConfiguration
import org.eclipse.apoapsis.ortserver.model.runs.scanner.LocalFileStorageConfiguration
import org.eclipse.apoapsis.ortserver.model.runs.scanner.PostgresConnection
import org.eclipse.apoapsis.ortserver.model.runs.scanner.PostgresStorageConfiguration
import org.eclipse.apoapsis.ortserver.model.runs.scanner.ProvenanceResolutionResult
import org.eclipse.apoapsis.ortserver.model.runs.scanner.ProvenanceStorageConfiguration
import org.eclipse.apoapsis.ortserver.model.runs.scanner.RepositoryProvenance
import org.eclipse.apoapsis.ortserver.model.runs.scanner.ScannerConfiguration
import org.eclipse.apoapsis.ortserver.model.runs.scanner.ScannerRun
Expand Down Expand Up @@ -306,19 +298,8 @@ private fun createScanResult(
}
}

internal val fileStorageConfiguration = FileStorageConfiguration(
localFileStorage = LocalFileStorageConfiguration(
directory = "/path/to/storage",
compression = true
)
)

internal val scannerConfiguration = ScannerConfiguration(
skipConcluded = false,
archive = FileArchiveConfiguration(
enabled = true,
fileStorage = fileStorageConfiguration
),
createMissingArchives = true,
detectedLicenseMappings = mapOf(
"license-1" to "spdx-license-1",
Expand All @@ -334,33 +315,7 @@ internal val scannerConfiguration = ScannerConfiguration(
secrets = mapOf("secret-key-1" to "secret-value-1", "secret-key-2" to "secret-value-2")
)
),
storages = mapOf(
"local" to FileBasedStorageConfiguration(
backend = fileStorageConfiguration,
type = "PROVENANCE_BASED"
),
"clearlyDefined" to ClearlyDefinedStorageConfiguration(
serverUrl = "https://api.clearlydefined.io"
)
),
storageReaders = listOf("reader-1", "reader-2"),
storageWriters = listOf("writer-1", "writer-2"),
ignorePatterns = listOf("pattern-1", "pattern-2"),
provenanceStorage = ProvenanceStorageConfiguration(
postgresStorageConfiguration = PostgresStorageConfiguration(
connection = PostgresConnection(
url = "jdbc:postgresql://postgresql-server:5432/database",
schema = "public",
username = "username",
sslMode = "required",
sslCert = "/defaultdir/postgresql.crt",
sslKey = "/defaultdir/postgresql.pk8",
sslRootCert = "/defaultdir/root.crt",
parallelTransactions = 5
),
type = "PROVENANCE_BASED"
)
)
ignorePatterns = listOf("pattern-1", "pattern-2")
)

private fun associateScannerRunWithPackageProvenance(scannerRun: ScannerRun, packageProvenance: PackageProvenanceDao) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,8 @@ import org.eclipse.apoapsis.ortserver.model.PluginConfiguration

data class ScannerConfiguration(
val skipConcluded: Boolean,
val archive: FileArchiveConfiguration? = null,
val createMissingArchives: Boolean,
val detectedLicenseMappings: Map<String, String>,
val config: Map<String, PluginConfiguration>,
val storages: Map<String, ScanStorageConfiguration?>?,
val storageReaders: List<String>?,
val storageWriters: List<String>?,
val ignorePatterns: List<String>,
val provenanceStorage: ProvenanceStorageConfiguration?
val ignorePatterns: List<String>
)
14 changes: 1 addition & 13 deletions workers/common/src/main/kotlin/common/OrtMappings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -448,22 +448,10 @@ fun OrtScannerRun.mapToModel(scannerJobId: Long) =
fun OrtScannerConfiguration.mapToModel() =
ScannerConfiguration(
skipConcluded = skipConcluded,
archive = archive?.mapToModel(),
createMissingArchives = createMissingArchives,
detectedLicenseMappings = detectedLicenseMapping,
config = config?.mapValues { it.value.mapToModel() }.orEmpty(),
storages = storages?.map { (name, storage) ->
name to when (storage) {
is OrtClearlyDefinedStorageConfiguration -> storage.mapToModel()
is OrtFileBasedStorageConfiguration -> storage.mapToModel()
is OrtPostgresStorageConfiguration -> storage.mapToModel()
is OrtSw360StorageConfiguration -> storage.mapToModel()
}
}?.toMap().orEmpty(),
storageReaders = storageReaders,
storageWriters = storageWriters,
ignorePatterns = ignorePatterns,
provenanceStorage = provenanceStorage?.mapToModel()
ignorePatterns = ignorePatterns
)

fun OrtScanResult.mapToModel() =
Expand Down
16 changes: 1 addition & 15 deletions workers/common/src/main/kotlin/common/OrtServerMappings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -378,24 +378,10 @@ fun RepositoryProvenance.mapToOrt() = OrtRepositoryProvenance(vcsInfo.mapToOrt()
fun ScannerConfiguration.mapToOrt() =
OrtScannerConfiguration(
skipConcluded = skipConcluded,
archive = archive?.mapToOrt(),
createMissingArchives = createMissingArchives,
detectedLicenseMapping = detectedLicenseMappings,
config = config.mapValues { it.value.mapToOrt() },
storages = storages?.mapNotNull { (name, storage) ->
storage?.let {
name to when (it) {
is PostgresStorageConfiguration -> it.mapToOrt()
is ClearlyDefinedStorageConfiguration -> it.mapToOrt()
is FileBasedStorageConfiguration -> it.mapToOrt()
is Sw360StorageConfiguration -> it.mapToOrt()
}
}
}?.toMap(),
storageReaders = storageReaders,
storageWriters = storageWriters,
ignorePatterns = ignorePatterns,
provenanceStorage = provenanceStorage?.mapToOrt()
ignorePatterns = ignorePatterns
)

fun ClearlyDefinedStorageConfiguration.mapToOrt() = OrtClearlyDefinedStorageConfiguration(serverUrl)
Expand Down
26 changes: 1 addition & 25 deletions workers/common/src/test/kotlin/OrtServerMappingsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,8 @@ import org.eclipse.apoapsis.ortserver.model.runs.repository.snippet.Provenance
import org.eclipse.apoapsis.ortserver.model.runs.repository.snippet.SnippetChoice
import org.eclipse.apoapsis.ortserver.model.runs.repository.snippet.SnippetChoiceReason
import org.eclipse.apoapsis.ortserver.model.runs.scanner.ArtifactProvenance
import org.eclipse.apoapsis.ortserver.model.runs.scanner.FileArchiveConfiguration
import org.eclipse.apoapsis.ortserver.model.runs.scanner.FileBasedStorageConfiguration
import org.eclipse.apoapsis.ortserver.model.runs.scanner.FileStorageConfiguration
import org.eclipse.apoapsis.ortserver.model.runs.scanner.LicenseFinding
import org.eclipse.apoapsis.ortserver.model.runs.scanner.LocalFileStorageConfiguration
import org.eclipse.apoapsis.ortserver.model.runs.scanner.ProvenanceResolutionResult
import org.eclipse.apoapsis.ortserver.model.runs.scanner.ProvenanceStorageConfiguration
import org.eclipse.apoapsis.ortserver.model.runs.scanner.ScanResult
import org.eclipse.apoapsis.ortserver.model.runs.scanner.ScanSummary
import org.eclipse.apoapsis.ortserver.model.runs.scanner.ScannerConfiguration
Expand Down Expand Up @@ -361,19 +356,8 @@ class OrtServerMappingsTest : WordSpec({
advisorRecords = mapOf(pkgIdentifier to listOf(advisorResult))
)

val fileStorageConfiguration = FileStorageConfiguration(
localFileStorage = LocalFileStorageConfiguration(
directory = "/path/to/storage",
compression = true
)
)

val scannerConfiguration = ScannerConfiguration(
skipConcluded = true,
archive = FileArchiveConfiguration(
enabled = true,
fileStorage = fileStorageConfiguration
),
createMissingArchives = true,
detectedLicenseMappings = mapOf("license-1" to "spdx-license-1", "license-2" to "spdx-license-2"),
config = mapOf(
Expand All @@ -386,15 +370,7 @@ class OrtServerMappingsTest : WordSpec({
secrets = mapOf("secret-key-1" to "secret-value-1", "secret-key-2" to "secret-value-2")
)
),
storages = mapOf(
"local" to FileBasedStorageConfiguration(fileStorageConfiguration, "PROVENANCE_BASED")
),
storageReaders = listOf("reader-1", "reader-2"),
storageWriters = listOf("writer-1", "writer-2"),
ignorePatterns = listOf("pattern-1", "pattern-2"),
provenanceStorage = ProvenanceStorageConfiguration(
fileStorage = fileStorageConfiguration
)
ignorePatterns = listOf("pattern-1", "pattern-2")
)

val packageCuration = PackageCuration(
Expand Down
Loading

0 comments on commit 152d6ee

Please sign in to comment.