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

FT-770 Added logic to prevent updating of connection name. #1049

Merged
merged 5 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
import co.elastic.clients.elasticsearch._types.SortOrder
import com.atlan.exception.ErrorCode
import com.atlan.exception.InvalidRequestException
import com.atlan.exception.NotFoundException
import com.atlan.model.assets.Asset
import com.atlan.model.assets.Connection
import com.atlan.model.assets.Database
import com.atlan.model.fields.CustomMetadataField
import com.atlan.pkg.Utils
import com.atlan.pkg.aim.Importer
import com.atlan.pkg.serde.RowSerde
import mu.KotlinLogging
import java.io.File
import kotlin.jvm.optionals.getOrElse

/**
* Actually run the migrator, taking all settings from environment variables.
Expand Down Expand Up @@ -103,6 +106,7 @@ object EnrichmentMigrator {
MigratorContext(
sourceConnectionQN = sourceConnectionQN,
targetConnectionQN = targetConnectionQN,
targetConnectionName = getConnectionName(targetConnectionQN),
includeArchived = includeArchived,
sourceDatabaseName = sourceDatabaseName,
targetDatabaseName = targetDatabaseName,
Expand Down Expand Up @@ -157,6 +161,19 @@ object EnrichmentMigrator {
return databaseNames
}

@JvmStatic
fun getConnectionName(connectionQN: String): String {
val connection =
Connection.select()
.where(Asset.QUALIFIED_NAME.eq(connectionQN))
.stream()
.findFirst()
.getOrElse {
throw NotFoundException(ErrorCode.ASSET_NOT_FOUND_BY_QN, connectionQN, "Connection")
}
return connection.name
ErnestoLoma marked this conversation as resolved.
Show resolved Hide resolved
}

@JvmStatic
fun getTargetDatabaseName(
targetConnectionQN: String,
Expand All @@ -166,7 +183,7 @@ object EnrichmentMigrator {
return listOf("")
}
val databaseNames = getDatabaseNames(targetConnectionQN, targetDatabasePattern)
if (databaseNames.size < 1) {
if (databaseNames.isEmpty()) {
throw InvalidRequestException(
ErrorCode.UNEXPECTED_NUMBER_OF_DATABASES_FOUND,
"at least one",
Expand Down Expand Up @@ -201,6 +218,7 @@ object EnrichmentMigrator {
data class MigratorContext(
val sourceConnectionQN: String,
val targetConnectionQN: String,
val targetConnectionName: String,
val includeArchived: Boolean,
val sourceDatabaseName: String,
val targetDatabaseName: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ class Transformer(
override fun mapRow(inputRow: Map<String, String>): List<List<String>> {
// Pick the fields to include in the output based on the header,
// and replace the source connection with the target connection
val rowIsConnection = (inputRow[Asset.TYPE_NAME.atlanFieldName] == "Connection")
val values =
header.map {
val raw =
if (it == Asset.STATUS.atlanFieldName) {
// Add the status column as explicitly ACTIVE (to convert any included archived assets)
AtlanStatus.ACTIVE.value
} else if (rowIsConnection && it == Asset.NAME.atlanFieldName) {
// Don't change the name of the connection
ctx.targetConnectionName
} else {
inputRow[it] ?: ""
}
Expand Down