Skip to content

Commit

Permalink
Merge pull request #1196 from atlanhq/FT-898
Browse files Browse the repository at this point in the history
Bump dependencies
  • Loading branch information
cmgrote authored Jan 7, 2025
2 parents 90f5529 + 9ebb8ca commit c0fb5b9
Show file tree
Hide file tree
Showing 149 changed files with 1,174 additions and 812 deletions.
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repositories {

dependencies {
implementation("org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:2.1.0")
implementation("com.diffplug.spotless:spotless-plugin-gradle:6.25.0")
implementation("com.diffplug.spotless:spotless-plugin-gradle:7.0.0")
implementation("io.freefair.gradle:lombok-plugin:8.11")
implementation("net.ltgt.gradle:gradle-errorprone-plugin:4.0.1")
implementation("com.adarshr:gradle-test-logger-plugin:4.0.0")
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ testng = "7.10.2"
log4j = "2.24.3"
wiremock = "3.10.0"
jnanoid = "2.0.0"
awssdk = "2.29.45"
awssdk = "2.29.46"
gcs = "26.51.0"
system-stubs = "2.1.7"
fastcsv = "3.4.0"
Expand Down
8 changes: 2 additions & 6 deletions package-toolkit/runtime/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,7 @@ open class Log4j2PluginsCustomTransformer : com.github.jengelman.gradle.plugins.
private val temporaryFiles = mutableListOf<File>()
private var stats: ShadowStats? = null

override fun canTransformResource(element: FileTreeElement): Boolean {
return PluginProcessor.PLUGIN_CACHE_FILE == element.name
}
override fun canTransformResource(element: FileTreeElement): Boolean = PluginProcessor.PLUGIN_CACHE_FILE == element.name

override fun transform(context: TransformerContext) {
val temporaryFile = File.createTempFile("Log4j2Plugins", ".dat")
Expand All @@ -364,9 +362,7 @@ open class Log4j2PluginsCustomTransformer : com.github.jengelman.gradle.plugins.
}
}

override fun hasTransformedResource(): Boolean {
return temporaryFiles.isNotEmpty()
}
override fun hasTransformedResource(): Boolean = temporaryFiles.isNotEmpty()

override fun modifyOutputStream(
os: ZipOutputStream,
Expand Down
84 changes: 40 additions & 44 deletions package-toolkit/runtime/src/main/kotlin/com/atlan/pkg/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ object Utils {
if (envValue != "") {
val tempResource =
Resource.create(
Attributes.builder().put(
entry.key,
envValue,
).build(),
Attributes
.builder()
.put(
entry.key,
envValue,
).build(),
)
outputResource = outputResource.merge(tempResource)
}
Expand All @@ -128,11 +130,14 @@ object Utils {
)
val resource = appendCustomEnvResource(defaultResource, customResourceEnvNames)
val logExporter: OtlpGrpcLogRecordExporter =
OtlpGrpcLogRecordExporter.builder()
OtlpGrpcLogRecordExporter
.builder()
.setEndpoint(endpoint)
.build()
val logEmitterProvider: SdkLoggerProvider =
SdkLoggerProvider.builder().setResource(resource)
SdkLoggerProvider
.builder()
.setResource(resource)
.addLogRecordProcessor(BatchLogRecordProcessor.builder(logExporter).build())
.build()
val openTelemetry =
Expand Down Expand Up @@ -404,9 +409,7 @@ object Utils {
fun getOrDefault(
configValue: List<String>?,
default: List<String>,
): List<String> {
return if (configValue.isNullOrEmpty()) default else configValue
}
): List<String> = if (configValue.isNullOrEmpty()) default else configValue

/**
* Return the provided configuration value only if it is non-null and not empty,
Expand All @@ -419,13 +422,12 @@ object Utils {
fun getOrDefault(
configValue: Number?,
default: Number,
): Number {
return if (configValue == null || configValue == -1) {
): Number =
if (configValue == null || configValue == -1) {
default
} else {
configValue
}
}

/**
* Return the provided configuration value only if it is non-null and not empty,
Expand All @@ -438,9 +440,7 @@ object Utils {
fun getOrDefault(
configValue: Boolean?,
default: Boolean,
): Boolean {
return configValue ?: default
}
): Boolean = configValue ?: default

/**
* Returns the provided comma-separated configuration value as a list of strings.
Expand All @@ -452,7 +452,8 @@ object Utils {
if (configValue == null) {
return listOf()
}
return configValue.split(",")
return configValue
.split(",")
.map { it.trim() }
.filter { it.isNotBlank() }
.toList()
Expand Down Expand Up @@ -497,13 +498,12 @@ object Utils {
action: String?,
connectionQN: String?,
connection: Connection?,
): String {
return if (getOrDefault(action, "REUSE") == "REUSE") {
): String =
if (getOrDefault(action, "REUSE") == "REUSE") {
reuseConnection(client, connectionQN)
} else {
createConnection(client, connection)
}
}

/**
* Create a connection using the details provided.
Expand All @@ -515,8 +515,8 @@ object Utils {
fun createConnection(
client: AtlanClient,
connection: Connection?,
): String {
return if (connection != null) {
): String =
if (connection != null) {
logger.info { "Attempting to create new connection..." }
try {
val toCreate =
Expand All @@ -533,7 +533,6 @@ object Utils {
} else {
""
}
}

/**
* Calculate the creation handling semantic from a string semantic.
Expand All @@ -545,13 +544,12 @@ object Utils {
fun getCreationHandling(
semantic: String?,
default: AssetCreationHandling,
): AssetCreationHandling {
return if (semantic == null) {
): AssetCreationHandling =
if (semantic == null) {
default
} else {
AssetCreationHandling.fromValue(semantic)
}
}

/**
* Validate the provided connection exists, and if so return its qualifiedName.
Expand All @@ -563,8 +561,8 @@ object Utils {
fun reuseConnection(
client: AtlanClient,
providedConnectionQN: String?,
): String {
return providedConnectionQN?.let {
): String =
providedConnectionQN?.let {
try {
logger.info { "Attempting to reuse connection: $providedConnectionQN" }
Connection.get(client, providedConnectionQN, false)
Expand All @@ -574,7 +572,6 @@ object Utils {
""
}
} ?: ""
}

/**
* Send an email using the tenant's internal SMTP server.
Expand All @@ -593,7 +590,8 @@ object Utils {
html: String? = null,
) {
val builder =
EmailBuilder.startingBlank()
EmailBuilder
.startingBlank()
.from("[email protected]")
.withRecipients(null, false, recipients, Message.RecipientType.TO)
.withSubject(subject)
Expand All @@ -605,12 +603,15 @@ object Utils {
builder.withAttachment(it.name, FileDataSource(it))
}
val email = builder.buildEmail()
MailerBuilder.withSMTPServer(
getEnvVar("SMTP_HOST", "smtp.sendgrid.net"),
getEnvVar("SMTP_PORT", "587").toInt(),
getEnvVar("SMTP_USER"),
getEnvVar("SMTP_PASS"),
).buildMailer().sendMail(email).get()
MailerBuilder
.withSMTPServer(
getEnvVar("SMTP_HOST", "smtp.sendgrid.net"),
getEnvVar("SMTP_PORT", "587").toInt(),
getEnvVar("SMTP_USER"),
getEnvVar("SMTP_PASS"),
).buildMailer()
.sendMail(email)
.get()
}

/**
Expand All @@ -623,9 +624,7 @@ object Utils {
fun getAssetLink(
client: AtlanClient,
guid: String,
): String {
return getLink(client, guid, "assets")
}
): String = getLink(client, guid, "assets")

/**
* Return a URL that will link directly to a data product or data domain in Atlan.
Expand All @@ -637,9 +636,7 @@ object Utils {
fun getProductLink(
client: AtlanClient,
guid: String,
): String {
return getLink(client, guid, "products")
}
): String = getLink(client, guid, "products")

private fun getLink(
client: AtlanClient,
Expand Down Expand Up @@ -980,8 +977,8 @@ object Utils {
* @param directory (optional) fallback directory to use on local filesystem if no object store is detected
* @return object storage syncer for Atlan's backing store
*/
fun getBackingStore(directory: String = Paths.get(separator, "tmp").toString()): ObjectStorageSyncer {
return when (val cloud = getEnvVar("CLOUD_PROVIDER", "local")) {
fun getBackingStore(directory: String = Paths.get(separator, "tmp").toString()): ObjectStorageSyncer =
when (val cloud = getEnvVar("CLOUD_PROVIDER", "local")) {
"aws" -> S3Sync(getEnvVar("AWS_S3_BUCKET_NAME"), getEnvVar("AWS_S3_REGION"), logger)
"gcp" -> GCSSync(getEnvVar("GCP_PROJECT_ID"), getEnvVar("GCP_STORAGE_BUCKET"), logger, "")
"azure" -> ADLSSync(getEnvVar("AZURE_STORAGE_ACCOUNT"), getEnvVar("AZURE_STORAGE_CONTAINER_NAME"), logger, "", "", getEnvVar("AZURE_STORAGE_ACCESS_KEY"))
Expand All @@ -994,7 +991,6 @@ object Utils {
}
else -> throw IllegalStateException("Unable to determine cloud provider: $cloud")
}
}

/**
* Update the connection cache for the provided assets.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ abstract class AssetCache<T : Asset>(
fun getIdentity(
guid: String,
bypassReadLock: Boolean = false,
): String? {
return getNameFromId(guid, bypassReadLock)
}
): String? = getNameFromId(guid, bypassReadLock)

/**
* Mark the provided asset identity as one to ignore.
Expand Down Expand Up @@ -105,9 +103,7 @@ abstract class AssetCache<T : Asset>(
*
* @return the set of all assets in the cache
*/
protected fun listAll(): Stream<Map.Entry<String, T>> {
return entrySet()
}
protected fun listAll(): Stream<Map.Entry<String, T>> = entrySet()

/**
* Check whether the asset is archived, and if so mark it to be ignored.
Expand All @@ -119,15 +115,14 @@ abstract class AssetCache<T : Asset>(
private fun isArchived(
id: String,
asset: T,
): Boolean {
return if (asset.status != AtlanStatus.ACTIVE) {
): Boolean =
if (asset.status != AtlanStatus.ACTIVE) {
logger.warn { "Unable to cache archived asset: $id" }
addToIgnore(id)
true
} else {
false
}
}

/**
* Create a unique, reconstructable identity for the provided asset.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import com.atlan.pkg.Utils
import com.atlan.pkg.serde.cell.GlossaryCategoryXformer
import com.atlan.pkg.serde.cell.GlossaryXformer.GLOSSARY_DELIMITER

class CategoryCache(val ctx: PackageContext<*>) : AssetCache<GlossaryCategory>(ctx, "category") {
class CategoryCache(
val ctx: PackageContext<*>,
) : AssetCache<GlossaryCategory>(ctx, "category") {
private val logger = Utils.getLogger(this.javaClass.name)

private val includesOnResults: List<AtlanField> = listOf(GlossaryCategory.NAME, GlossaryCategory.ANCHOR, GlossaryCategory.PARENT_CATEGORY)
Expand All @@ -39,7 +41,8 @@ class CategoryCache(val ctx: PackageContext<*>) : AssetCache<GlossaryCategory>(c
): GlossaryCategory? {
try {
val category =
GlossaryCategory.select(client)
GlossaryCategory
.select(client)
.where(GlossaryCategory.GUID.eq(guid))
.includesOnResults(includesOnResults)
.includeOnResults(GlossaryTerm.STATUS)
Expand Down Expand Up @@ -73,9 +76,7 @@ class CategoryCache(val ctx: PackageContext<*>) : AssetCache<GlossaryCategory>(c
*
* @param glossaryName name of the glossary for which to bulk-cache categories
*/
private fun traverseAndCacheHierarchy(glossaryName: String): List<GlossaryCategory> {
return this.traverseAndCacheHierarchy(glossaryName, emptyList())
}
private fun traverseAndCacheHierarchy(glossaryName: String): List<GlossaryCategory> = this.traverseAndCacheHierarchy(glossaryName, emptyList())

/**
* It is likely to be more efficient (for any sizeable import) to retrieve and traverse
Expand Down Expand Up @@ -154,7 +155,8 @@ class CategoryCache(val ctx: PackageContext<*>) : AssetCache<GlossaryCategory>(c
override fun refreshCache() {
val count = GlossaryCategory.select(client).count()
logger.info { "Caching all $count categories, up-front..." }
Glossary.select(client)
Glossary
.select(client)
.includeOnResults(Glossary.NAME)
.stream(true)
.forEach { glossary ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,14 @@ class ChecksumCache(
name: String?,
) : AbstractOffHeapCache<AssetIdentity, String>(name) {
/** {@inheritDoc} */
override fun serializeKey(key: AssetIdentity): ByteArray {
return key.toString().toByteArray(StandardCharsets.UTF_8)
}
override fun serializeKey(key: AssetIdentity): ByteArray = key.toString().toByteArray(StandardCharsets.UTF_8)

/** {@inheritDoc} */
override fun deserializeKey(bytes: ByteArray): AssetIdentity {
return AssetIdentity.fromString(String(bytes, StandardCharsets.UTF_8))
}
override fun deserializeKey(bytes: ByteArray): AssetIdentity = AssetIdentity.fromString(String(bytes, StandardCharsets.UTF_8))

/** {@inheritDoc} */
override fun serializeValue(value: String): ByteArray {
return value.toByteArray(StandardCharsets.UTF_8)
}
override fun serializeValue(value: String): ByteArray = value.toByteArray(StandardCharsets.UTF_8)

/** {@inheritDoc} */
override fun deserializeValue(bytes: ByteArray): String {
return String(bytes, StandardCharsets.UTF_8)
}
override fun deserializeValue(bytes: ByteArray): String = String(bytes, StandardCharsets.UTF_8)
}
Loading

0 comments on commit c0fb5b9

Please sign in to comment.