Skip to content

Commit 987d1d0

Browse files
authored
Amazon Q Transform: refactor gumby client (#4098)
1 parent fef7450 commit 987d1d0

File tree

6 files changed

+157
-232
lines changed

6 files changed

+157
-232
lines changed

jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/ArtifactHandler.kt

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import kotlinx.coroutines.launch
1616
import software.aws.toolkits.core.utils.error
1717
import software.aws.toolkits.core.utils.exists
1818
import software.aws.toolkits.core.utils.getLogger
19-
import software.aws.toolkits.core.utils.warn
19+
import software.aws.toolkits.core.utils.info
2020
import software.aws.toolkits.jetbrains.core.coroutines.projectCoroutineScope
2121
import software.aws.toolkits.jetbrains.services.codemodernizer.client.GumbyClient
2222
import software.aws.toolkits.jetbrains.services.codemodernizer.model.CodeModernizerArtifact
@@ -26,7 +26,6 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.summary.CodeModer
2626
import software.aws.toolkits.jetbrains.utils.notifyInfo
2727
import software.aws.toolkits.jetbrains.utils.notifyWarn
2828
import software.aws.toolkits.resources.message
29-
import software.aws.toolkits.telemetry.CodeTransformApiNames
3029
import software.aws.toolkits.telemetry.CodeTransformPatchViewerCancelSrcComponents
3130
import software.aws.toolkits.telemetry.CodeTransformVCSViewerSrcComponents
3231
import software.aws.toolkits.telemetry.CodetransformTelemetry
@@ -61,6 +60,7 @@ class ArtifactHandler(private val project: Project, private val clientAdaptor: G
6160

6261
suspend fun downloadArtifact(job: JobId): DownloadArtifactResult {
6362
isCurrentlyDownloading.set(true)
63+
val downloadStartTime = Instant.now()
6464
try {
6565
// 1. Attempt reusing previously downloaded artifact for job
6666
val previousArtifact = downloadedArtifacts.getOrDefault(job, null)
@@ -78,26 +78,11 @@ class ArtifactHandler(private val project: Project, private val clientAdaptor: G
7878

7979
// 2. Download the data
8080
notifyDownloadStart()
81-
LOG.warn { "About to download the export result archive" }
82-
var apiStartTime: Instant = Instant.now()
83-
lateinit var apiEndTime: Instant
84-
val downloadResultsResponse: MutableList<ByteArray>
85-
try {
86-
downloadResultsResponse = clientAdaptor.downloadExportResultArchive(job)
87-
} catch (e: Exception) {
88-
CodetransformTelemetry.logApiError(
89-
codeTransformApiNames = CodeTransformApiNames.ExportResultArchive,
90-
codeTransformSessionId = CodeTransformTelemetryState.instance.getSessionId(),
91-
codeTransformApiErrorMessage = e.message.toString(),
92-
codeTransformJobId = job.id,
93-
)
94-
throw e // pass along error to callee
95-
} finally {
96-
apiEndTime = Instant.now()
97-
}
81+
LOG.info { "About to download the export result archive" }
82+
val downloadResultsResponse = clientAdaptor.downloadExportResultArchive(job)
9883

9984
// 3. Convert to zip
100-
LOG.warn { "Downloaded the export result archive, about to transform to zip" }
85+
LOG.info { "Downloaded the export result archive, about to transform to zip" }
10186
val path = Files.createTempFile(null, ".zip")
10287
var totalDownloadBytes = 0
10388
Files.newOutputStream(path).use {
@@ -106,33 +91,23 @@ class ArtifactHandler(private val project: Project, private val clientAdaptor: G
10691
totalDownloadBytes += bytes.size
10792
}
10893
}
109-
CodetransformTelemetry.logApiLatency(
110-
codeTransformApiNames = CodeTransformApiNames.ExportResultArchive,
111-
codeTransformSessionId = CodeTransformTelemetryState.instance.getSessionId(),
112-
codeTransformRunTimeLatency = calculateTotalLatency(apiStartTime, apiEndTime),
113-
codeTransformJobId = job.id,
114-
codeTransformTotalByteSize = totalDownloadBytes
115-
)
116-
LOG.warn { "Successfully converted the download to a zip at ${path.toAbsolutePath()}." }
94+
LOG.info { "Successfully converted the download to a zip at ${path.toAbsolutePath()}." }
11795
val zipPath = path.toAbsolutePath().toString()
11896

11997
// 4. Deserialize zip to CodeModernizerArtifact
120-
var telemetryErrorMessage = ""
98+
var telemetryErrorMessage: String? = null
12199
return try {
122-
apiStartTime = Instant.now()
123100
val output = DownloadArtifactResult(CodeModernizerArtifact.create(zipPath), zipPath)
124-
apiEndTime = Instant.now()
125101
downloadedArtifacts[job] = path
126102
output
127103
} catch (e: RuntimeException) {
128104
LOG.error { e.message.toString() }
129-
telemetryErrorMessage = e.message.toString()
130-
apiEndTime = Instant.now()
105+
telemetryErrorMessage = "Unexpected error when downloading result"
131106
DownloadArtifactResult(null, zipPath)
132107
} finally {
133108
CodetransformTelemetry.jobArtifactDownloadAndDeserializeTime(
134109
codeTransformSessionId = CodeTransformTelemetryState.instance.getSessionId(),
135-
codeTransformRunTimeLatency = calculateTotalLatency(apiStartTime, apiEndTime),
110+
codeTransformRunTimeLatency = calculateTotalLatency(downloadStartTime, Instant.now()),
136111
codeTransformJobId = job.id,
137112
codeTransformTotalByteSize = totalDownloadBytes,
138113
codeTransformRuntimeError = telemetryErrorMessage
@@ -185,7 +160,7 @@ class ArtifactHandler(private val project: Project, private val clientAdaptor: G
185160
}
186161

187162
fun notifyUnableToApplyPatch(patchPath: String) {
188-
LOG.warn { "Unable to find patch for file: $patchPath" }
163+
LOG.error { "Unable to find patch for file: $patchPath" }
189164
notifyWarn(
190165
message("codemodernizer.notification.warn.view_diff_failed.title"),
191166
message("codemodernizer.notification.warn.view_diff_failed.content"),
@@ -195,7 +170,7 @@ class ArtifactHandler(private val project: Project, private val clientAdaptor: G
195170
}
196171

197172
fun notifyUnableToShowSummary() {
198-
LOG.warn { "Unable to display summary" }
173+
LOG.error { "Unable to display summary" }
199174
notifyWarn(
200175
message("codemodernizer.notification.warn.view_summary_failed.title"),
201176
message("codemodernizer.notification.warn.view_summary_failed.content"),

jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerManager.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import software.amazon.awssdk.services.codewhispererruntime.model.Transformation
2828
import software.amazon.awssdk.services.codewhispererruntime.model.TransformationStatus
2929
import software.aws.toolkits.core.utils.error
3030
import software.aws.toolkits.core.utils.getLogger
31+
import software.aws.toolkits.core.utils.info
3132
import software.aws.toolkits.core.utils.warn
3233
import software.aws.toolkits.jetbrains.core.coroutines.projectCoroutineScope
3334
import software.aws.toolkits.jetbrains.core.explorer.refreshCwQTree
@@ -357,7 +358,7 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo
357358
postModernizationJob(result)
358359
} catch (e: Exception) {
359360
notifyUnableToResumeJob()
360-
LOG.warn(e) { e.message.toString() }
361+
LOG.error(e) { e.message.toString() }
361362
return@launch
362363
}
363364
}
@@ -443,12 +444,12 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo
443444
val notYetResumed = isResumingJob.compareAndSet(false, true)
444445
if (!notYetResumed) return@launch
445446

446-
LOG.warn { "Attempting to resume job, current state is: $managerState" }
447+
LOG.info { "Attempting to resume job, current state is: $managerState" }
447448
if (!managerState.flags.getOrDefault(StateFlags.IS_ONGOING, false)) return@launch
448449
val context = managerState.toSessionContext(project)
449450
val session = CodeModernizerSession(context)
450451
val lastJobId = managerState.getLatestJobId()
451-
LOG.warn { "Attempting to resume job with id $lastJobId" }
452+
LOG.info { "Attempting to resume job with id $lastJobId" }
452453
val result = session.getJobDetails(lastJobId)
453454
when (result.status()) {
454455
TransformationStatus.COMPLETED -> {
@@ -501,10 +502,10 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo
501502
codeTransformStatus = result.status().toString()
502503
)
503504
} catch (e: AccessDeniedException) {
504-
LOG.warn { "Unable to resume job as credentials are invalid" }
505+
LOG.error { "Unable to resume job as credentials are invalid" }
505506
// User is logged in with old or invalid credentials, nothing to do until they log in with valid credentials
506507
} catch (e: Exception) {
507-
LOG.warn { "Unable to resume job as an unexpected exception occurred ${e.stackTraceToString()}" }
508+
LOG.error { "Unable to resume job as an unexpected exception occurred ${e.stackTraceToString()}" }
508509
} finally {
509510
isResumingJob.set(false)
510511
}

0 commit comments

Comments
 (0)