Skip to content

Commit

Permalink
Merge main into feature/q-mega
Browse files Browse the repository at this point in the history
  • Loading branch information
aws-toolkit-automation authored Nov 18, 2024
2 parents e417c89 + 0e94d02 commit 0722fed
Show file tree
Hide file tree
Showing 37 changed files with 1,024 additions and 204 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type" : "feature",
"description" : "Feature(Amazon Q Code Transformation): support conversions of embedded SQL from Oracle to PostgreSQL"
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.model.CodeModerni
import software.aws.toolkits.jetbrains.services.codemodernizer.model.CodeModernizerSessionContext
import software.aws.toolkits.jetbrains.services.codemodernizer.model.CodeModernizerStartJobResult
import software.aws.toolkits.jetbrains.services.codemodernizer.model.CodeTransformHilDownloadArtifact
import software.aws.toolkits.jetbrains.services.codemodernizer.model.CodeTransformType
import software.aws.toolkits.jetbrains.services.codemodernizer.model.CustomerSelection
import software.aws.toolkits.jetbrains.services.codemodernizer.model.Dependency
import software.aws.toolkits.jetbrains.services.codemodernizer.model.InvalidTelemetryReason
Expand All @@ -59,6 +60,7 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.toolwindow.CodeMo
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.STATES_WHERE_PLAN_EXIST
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.createFileCopy
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.findLineNumberByString
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getJavaModulesWithSQL
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getMavenVersion
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getModuleOrProjectNameForFile
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getPathToHilArtifactPomFile
Expand Down Expand Up @@ -125,53 +127,64 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo
JavaSdkVersion.JDK_11 to setOf(JavaSdkVersion.JDK_17),
JavaSdkVersion.JDK_17 to setOf(JavaSdkVersion.JDK_17),
)

init {
CodeModernizerSessionState.getInstance(project).setDefaults()
}

fun validate(project: Project): ValidationResult {
fun validate(project: Project, transformationType: CodeTransformType): ValidationResult {
fun validateCore(project: Project): ValidationResult {
if (isRunningOnRemoteBackend()) {
return ValidationResult(
false,
message("codemodernizer.notification.warn.invalid_project.description.reason.remote_backend"),
InvalidTelemetryReason(
CodeTransformPreValidationError.RemoteRunProject
CodeTransformPreValidationError.RemoteRunProject,
)
)
}
if (!isCodeTransformAvailable(project)) {
return ValidationResult(
false,
message("codemodernizer.notification.warn.invalid_project.description.reason.not_logged_in"),
InvalidTelemetryReason(
CodeTransformPreValidationError.NonSsoLogin
CodeTransformPreValidationError.NonSsoLogin,
)
)
}

if (ProjectRootManager.getInstance(project).contentRoots.isEmpty()) {
return ValidationResult(
false,
message("codemodernizer.notification.warn.invalid_project.description.reason.missing_content_roots"),
InvalidTelemetryReason(
CodeTransformPreValidationError.NoPom
CodeTransformPreValidationError.EmptyProject,
)
)
}

if (transformationType == CodeTransformType.SQL_CONVERSION) {
val javaModules = project.getJavaModulesWithSQL()
return if (javaModules.isNotEmpty()) {
ValidationResult(
true,
)
} else {
ValidationResult(
false,
InvalidTelemetryReason(
CodeTransformPreValidationError.NoJavaProject,
)
)
}
}

val supportedModules = project.getSupportedModules(supportedJavaMappings).toSet()
val validProjectJdk = project.getSupportedJavaMappings(supportedJavaMappings).isNotEmpty()
val projectJdk = project.tryGetJdk()
if (supportedModules.isEmpty() && !validProjectJdk) {
return ValidationResult(
false,
message(
"codemodernizer.notification.warn.invalid_project.description.reason.invalid_jdk_versions",
supportedJavaMappings.keys.joinToString()
),
InvalidTelemetryReason(
CodeTransformPreValidationError.UnsupportedJavaVersion,
projectJdk?.toString().orEmpty()
projectJdk.toString()
)
)
}
Expand All @@ -180,17 +193,12 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo
ValidationResult(
true,
validatedBuildFiles = validatedBuildFiles,
validatedProjectJdkName = projectJdk?.description.orEmpty(),
buildSystem = CodeTransformBuildSystem.Maven,
buildSystemVersion = getMavenVersion(project)
)
} else {
ValidationResult(
false,
invalidReason = message(
"codemodernizer.notification.warn.invalid_project.description.reason.no_valid_files",
supportedBuildFileNames.joinToString()
),
invalidTelemetryReason = InvalidTelemetryReason(
CodeTransformPreValidationError.UnsupportedBuildSystem,
if (isGradleProject(project)) "Gradle build" else "other build"
Expand Down Expand Up @@ -248,15 +256,17 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo
}
}

fun runModernize(copyResult: MavenCopyCommandsResult) {
fun runModernize(copyResult: MavenCopyCommandsResult? = null) {
initStopParameters()
val session = codeTransformationSession as CodeModernizerSession
initModernizationJobUI(true, project.getModuleOrProjectNameForFile(session.sessionContext.configurationFile))
launchModernizationJob(session, copyResult)
}

suspend fun resumePollingFromHil() {
val result = handleJobResumedFromHil(managerState.getLatestJobId(), codeTransformationSession as CodeModernizerSession)
val transformationType =
if (codeTransformationSession?.sessionContext?.sqlMetadataZip != null) CodeTransformType.SQL_CONVERSION else CodeTransformType.LANGUAGE_UPGRADE
val result = handleJobResumedFromHil(managerState.getLatestJobId(), codeTransformationSession as CodeModernizerSession, transformationType)
postModernizationJob(result)
}

Expand Down Expand Up @@ -312,7 +322,7 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo
)
}

fun launchModernizationJob(session: CodeModernizerSession, copyResult: MavenCopyCommandsResult) = projectCoroutineScope(project).launch {
fun launchModernizationJob(session: CodeModernizerSession, copyResult: MavenCopyCommandsResult?) = projectCoroutineScope(project).launch {
val result = initModernizationJob(session, copyResult)

postModernizationJob(result)
Expand All @@ -339,7 +349,8 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo
CodeModernizerSessionState.getInstance(project).currentJobCreationTime = currentJobResult.creationTime()
codeTransformationSession = session
initModernizationJobUI(false, project.getModuleOrProjectNameForFile(session.sessionContext.configurationFile))
codeModernizerBottomWindowPanelManager.setResumeJobUI(currentJobResult, plan, session.sessionContext.sourceJavaVersion)
val transformationType = if (session.sessionContext.sqlMetadataZip != null) CodeTransformType.SQL_CONVERSION else CodeTransformType.LANGUAGE_UPGRADE
codeModernizerBottomWindowPanelManager.setResumeJobUI(currentJobResult, plan, session.sessionContext.sourceJavaVersion, transformationType)
session.resumeJob(currentJobResult.creationTime(), lastJobId)
val result = handleJobStarted(lastJobId, session)
postModernizationJob(result)
Expand Down Expand Up @@ -395,7 +406,7 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo

fun parseBuildFile(): String? = parseBuildFile(codeTransformationSession?.sessionContext?.configurationFile)

internal suspend fun initModernizationJob(session: CodeModernizerSession, copyResult: MavenCopyCommandsResult): CodeModernizerJobCompletedResult =
private suspend fun initModernizationJob(session: CodeModernizerSession, copyResult: MavenCopyCommandsResult?): CodeModernizerJobCompletedResult =
when (val result = session.createModernizationJob(copyResult)) {
is CodeModernizerStartJobResult.ZipCreationFailed -> {
CodeModernizerJobCompletedResult.UnableToCreateJob(
Expand Down Expand Up @@ -441,10 +452,12 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo
private suspend fun handleJobResumedFromHil(
jobId: JobId,
session: CodeModernizerSession,
transformType: CodeTransformType,
): CodeModernizerJobCompletedResult = session.pollUntilJobCompletion(
transformType,
jobId
) { new, plan ->
codeModernizerBottomWindowPanelManager.handleJobTransition(new, plan, session.sessionContext.sourceJavaVersion)
codeModernizerBottomWindowPanelManager.handleJobTransition(new, plan, session.sessionContext.sourceJavaVersion, transformType)
}

private suspend fun handleJobStarted(jobId: JobId, session: CodeModernizerSession): CodeModernizerJobCompletedResult {
Expand All @@ -455,8 +468,10 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo
codeModernizerBottomWindowPanelManager.setJobRunningUI()
}

return session.pollUntilJobCompletion(jobId) { new, plan ->
codeModernizerBottomWindowPanelManager.handleJobTransition(new, plan, session.sessionContext.sourceJavaVersion)
val transformType = if (session.sessionContext.sqlMetadataZip != null) CodeTransformType.SQL_CONVERSION else CodeTransformType.LANGUAGE_UPGRADE

return session.pollUntilJobCompletion(transformType, jobId) { new, plan ->
codeModernizerBottomWindowPanelManager.handleJobTransition(new, plan, session.sessionContext.sourceJavaVersion, transformType)
}
}

Expand Down Expand Up @@ -667,10 +682,14 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo
fun createCodeModernizerSession(customerSelection: CustomerSelection, project: Project) {
codeTransformationSession = CodeModernizerSession(
CodeModernizerSessionContext(
project,
customerSelection.configurationFile,
customerSelection.sourceJavaVersion,
customerSelection.targetJavaVersion,
project = project,
configurationFile = customerSelection.configurationFile,
sourceJavaVersion = customerSelection.sourceJavaVersion,
targetJavaVersion = customerSelection.targetJavaVersion,
sourceVendor = customerSelection.sourceVendor,
targetVendor = customerSelection.targetVendor,
sourceServerName = customerSelection.sourceServerName,
sqlMetadataZip = customerSelection.sqlMetadataZip,
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.model.CodeModerni
import software.aws.toolkits.jetbrains.services.codemodernizer.model.CodeModernizerSessionContext
import software.aws.toolkits.jetbrains.services.codemodernizer.model.CodeModernizerStartJobResult
import software.aws.toolkits.jetbrains.services.codemodernizer.model.CodeTransformHilDownloadArtifact
import software.aws.toolkits.jetbrains.services.codemodernizer.model.CodeTransformType
import software.aws.toolkits.jetbrains.services.codemodernizer.model.DownloadArtifactResult
import software.aws.toolkits.jetbrains.services.codemodernizer.model.JobId
import software.aws.toolkits.jetbrains.services.codemodernizer.model.MavenCopyCommandsResult
Expand Down Expand Up @@ -61,12 +62,7 @@ import java.util.concurrent.CancellationException
import java.util.concurrent.atomic.AtomicBoolean
import javax.net.ssl.SSLHandshakeException

const val ZIP_SOURCES_PATH = "sources"
const val BUILD_LOG_PATH = "build-logs.txt"
const val UPLOAD_ZIP_MANIFEST_VERSION = 1.0F
const val MAX_ZIP_SIZE = 2000000000 // 2GB
const val HIL_1P_UPGRADE_CAPABILITY = "HIL_1pDependency_VersionUpgrade"
const val EXPLAINABILITY_V1 = "EXPLAINABILITY_V1"

// constants for handling SDKClientException
const val CONNECTION_REFUSED_ERROR: String = "Connection refused"
Expand Down Expand Up @@ -144,7 +140,7 @@ class CodeModernizerSession(
*
* Based on [CodeWhispererCodeScanSession]
*/
fun createModernizationJob(copyResult: MavenCopyCommandsResult): CodeModernizerStartJobResult {
fun createModernizationJob(copyResult: MavenCopyCommandsResult?): CodeModernizerStartJobResult {
LOG.info { "Compressing local project" }
val payload: File?
var payloadSize = 0
Expand All @@ -164,6 +160,7 @@ class CodeModernizerSession(
telemetryErrorMessage = "Disposed when about to create zip"
return CodeModernizerStartJobResult.Disposed
}
// for language upgrades, copyResult should always be Successful here, failure cases already handled
val result = sessionContext.createZipWithModuleFiles(copyResult)

if (result is ZipCreationResult.Missing1P) {
Expand Down Expand Up @@ -324,11 +321,6 @@ class CodeModernizerSession(
return clientAdaptor.getCodeModernizationJob(jobId.id).transformationJob()
}

fun getTransformPlanDetails(jobId: JobId): TransformationPlan {
LOG.info { "Getting transform plan details." }
return clientAdaptor.getCodeModernizationPlan(jobId).transformationPlan()
}

/**
* This will resume the job, i.e. it will resume the main job loop kicked of by [createModernizationJob]
*/
Expand Down Expand Up @@ -418,6 +410,7 @@ class CodeModernizerSession(
}

suspend fun pollUntilJobCompletion(
transformType: CodeTransformType,
jobId: JobId,
jobTransitionHandler: (currentStatus: TransformationStatus, migrationPlan: TransformationPlan?) -> Unit,
): CodeModernizerJobCompletedResult {
Expand All @@ -432,6 +425,7 @@ class CodeModernizerSession(
var passedStart = false

val result = jobId.pollTransformationStatusAndPlan(
transformType,
succeedOn = setOf(
TransformationStatus.COMPLETED,
TransformationStatus.PAUSED,
Expand Down Expand Up @@ -463,8 +457,8 @@ class CodeModernizerSession(
}
}

// Open the transformation plan detail panel once transformation plan is available
if (state.transformationPlan != null && !isTransformationPlanEditorOpened) {
// Open the transformation plan detail panel once transformation plan is available (no plan for SQL conversions)
if (transformType != CodeTransformType.SQL_CONVERSION && state.transformationPlan != null && !isTransformationPlanEditorOpened) {
tryOpenTransformationPlanEditor()
isTransformationPlanEditorOpened = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ private enum class CodeTransformMessageTypes(val type: String) {
TabCreated("new-tab-was-created"),
TabRemoved("tab-was-removed"),
Transform("transform"),
ChatPrompt("chat-prompt"), // for getting the transformation objective
CodeTransformStart("codetransform-start"),
CodeTransformSelectSQLMetadata("codetransform-select-sql-metadata"),
CodeTransformSelectSQLModuleSchema("codetransform-select-sql-module-schema"),
CodeTransformStop("codetransform-stop"),
CodeTransformCancel("codetransform-cancel"),
CodeTransformConfirmSkipTests("codetransform-confirm-skip-tests"),
Expand Down Expand Up @@ -63,8 +66,11 @@ class CodeTransformChatApp : AmazonQApp {
CodeTransformMessageTypes.TabRemoved.type to IncomingCodeTransformMessage.TabRemoved::class,
CodeTransformMessageTypes.Transform.type to IncomingCodeTransformMessage.Transform::class,
CodeTransformMessageTypes.CodeTransformStart.type to IncomingCodeTransformMessage.CodeTransformStart::class,
CodeTransformMessageTypes.CodeTransformSelectSQLMetadata.type to IncomingCodeTransformMessage.CodeTransformSelectSQLMetadata::class,
CodeTransformMessageTypes.CodeTransformSelectSQLModuleSchema.type to IncomingCodeTransformMessage.CodeTransformSelectSQLModuleSchema::class,
CodeTransformMessageTypes.CodeTransformStop.type to IncomingCodeTransformMessage.CodeTransformStop::class,
CodeTransformMessageTypes.CodeTransformCancel.type to IncomingCodeTransformMessage.CodeTransformCancel::class,
CodeTransformMessageTypes.ChatPrompt.type to IncomingCodeTransformMessage.ChatPrompt::class,
CodeTransformMessageTypes.CodeTransformConfirmSkipTests.type to IncomingCodeTransformMessage.CodeTransformConfirmSkipTests::class,
CodeTransformMessageTypes.CodeTransformNew.type to IncomingCodeTransformMessage.CodeTransformNew::class,
CodeTransformMessageTypes.CodeTransformOpenTransformHub.type to IncomingCodeTransformMessage.CodeTransformOpenTransformHub::class,
Expand Down Expand Up @@ -153,8 +159,12 @@ class CodeTransformChatApp : AmazonQApp {
when (message) {
is IncomingCodeTransformMessage.Transform -> inboundAppMessagesHandler.processTransformQuickAction(message)
is IncomingCodeTransformMessage.CodeTransformStart -> inboundAppMessagesHandler.processCodeTransformStartAction(message)
is IncomingCodeTransformMessage.CodeTransformSelectSQLMetadata -> inboundAppMessagesHandler.processCodeTransformSelectSQLMetadataAction(message)
is IncomingCodeTransformMessage.CodeTransformSelectSQLModuleSchema ->
inboundAppMessagesHandler.processCodeTransformSelectSQLModuleSchemaAction(message)
is IncomingCodeTransformMessage.CodeTransformCancel -> inboundAppMessagesHandler.processCodeTransformCancelAction(message)
is IncomingCodeTransformMessage.CodeTransformStop -> inboundAppMessagesHandler.processCodeTransformStopAction(message.tabId)
is IncomingCodeTransformMessage.ChatPrompt -> inboundAppMessagesHandler.processChatPromptMessage(message)
is IncomingCodeTransformMessage.CodeTransformConfirmSkipTests -> inboundAppMessagesHandler.processCodeTransformConfirmSkipTests(message)
is IncomingCodeTransformMessage.CodeTransformNew -> inboundAppMessagesHandler.processCodeTransformNewAction(message)
is IncomingCodeTransformMessage.CodeTransformOpenTransformHub -> inboundAppMessagesHandler.processCodeTransformOpenTransformHub(message)
Expand Down
Loading

0 comments on commit 0722fed

Please sign in to comment.