Skip to content

Commit

Permalink
Merge pull request #1049 from atlanhq/ft-770
Browse files Browse the repository at this point in the history
FT-770 Added logic to prevent updating of connection name.
  • Loading branch information
cmgrote authored Nov 26, 2024
2 parents 9c73b8d + 59177fe commit 8102e87
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ log4j = "2.24.2"
wiremock = "3.9.2"
jnanoid = "2.0.0"
numaflow = "0.9.0"
awssdk = "2.29.20"
awssdk = "2.29.21"
gcs = "26.50.0"
system-stubs = "2.1.7"
fastcsv = "3.4.0"
poi = "5.3.0"
parsson = "1.1.7"
simplejavamail = "8.12.2"
simplejavamail = "8.12.3"
swagger = "2.1.24"
jsonpath = "2.9.0"
commons-compress = "1.27.1"
commons-io = "2.18.0"
sqlite = "3.47.0.0"
sqlite = "3.47.1.0"
jakarta-mail = "2.1.3"
angus-mail = "2.0.3"
pkl = "0.27.0"
Expand Down
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
}

@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

0 comments on commit 8102e87

Please sign in to comment.