Skip to content

Commit 15e0c3c

Browse files
author
David Hasani
committed
short circuit lang upgrades
1 parent 79ce144 commit 15e0c3c

File tree

4 files changed

+78
-35
lines changed

4 files changed

+78
-35
lines changed

packages/core/src/amazonqGumby/chat/controller/controller.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,28 @@ export class GumbyController {
194194
try {
195195
embeddedSQLProjects = await getValidSQLConversionCandidateProjects()
196196
} catch (err) {
197-
getLogger().error(`Error validating SQL conversion projects: ${err}`)
197+
getLogger().error(`CodeTransformation: error validating SQL conversion projects: ${err}`)
198198
}
199199

200200
if (embeddedSQLProjects.length === 0) {
201201
await this.handleLanguageUpgrade(message)
202202
return
203203
}
204204

205+
let javaUpgradeProjects: TransformationCandidateProject[] = []
206+
try {
207+
javaUpgradeProjects = await getValidLanguageUpgradeCandidateProjects()
208+
} catch (err) {
209+
getLogger().error(`CodeTransformation: error validating Java upgrade projects: ${err}`)
210+
}
211+
212+
// TO-DO: in this case, should we say "I can't do a language upgrade, but I found embedded SQL I can convert..."
213+
// and vice-versa for the case above with handleLanguageUpgrade
214+
if (javaUpgradeProjects.length === 0) {
215+
await this.handleSQLConversion(message)
216+
return
217+
}
218+
205219
// if previous transformation was already running, show correct message to user
206220
switch (this.sessionStorage.getSession().conversationState) {
207221
case ConversationState.JOB_SUBMITTED:
@@ -230,7 +244,10 @@ export class GumbyController {
230244
this.sessionStorage.getSession().conversationState = ConversationState.WAITING_FOR_TRANSFORMATION_OBJECTIVE
231245
this.messenger.sendStaticTextResponse('choose-transformation-objective', message.tabID)
232246
this.messenger.sendChatInputEnabled(message.tabID, true)
233-
this.messenger.sendUpdatePlaceholder(message.tabID, CodeWhispererConstants.chooseTransformationObjective)
247+
this.messenger.sendUpdatePlaceholder(
248+
message.tabID,
249+
CodeWhispererConstants.chooseTransformationObjectivePlaceholder
250+
)
234251
}
235252

236253
private async beginTransformation(message: any) {
@@ -316,13 +333,7 @@ export class GumbyController {
316333

317334
private async validateSQLConversionProjects(message: any) {
318335
try {
319-
const validProjects = await telemetry.codeTransform_validateProject.run(async () => {
320-
telemetry.record({
321-
codeTransformSessionId: CodeTransformTelemetryState.instance.getSessionId(),
322-
})
323-
const validProjects = await getValidSQLConversionCandidateProjects()
324-
return validProjects
325-
})
336+
const validProjects = await getValidSQLConversionCandidateProjects()
326337
return validProjects
327338
} catch (e: any) {
328339
if (e instanceof NoJavaProjectsFoundError) {

packages/core/src/amazonqGumby/chat/controller/messenger/messenger.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ export class Messenger {
426426
message = CodeWhispererConstants.noJavaProjectsFoundChatMessage
427427
break
428428
case 'no-maven-java-project-found':
429+
// shown when user has no pom.xml, but at this point also means they have no eligible SQL conversion projects
429430
message = CodeWhispererConstants.noPomXmlFoundChatMessage
430431
break
431432
case 'could-not-compile-project':
@@ -710,6 +711,13 @@ ${codeSnippet}
710711
}
711712

712713
public async sendSelectSQLMetadataFileMessage(tabID: string) {
714+
this.dispatcher.sendAsyncEventProgress(
715+
new AsyncEventProgressMessage(tabID, {
716+
inProgress: true,
717+
message: 'I can convert the embedded Oracle SQL in your project to PostgreSQL.',
718+
})
719+
)
720+
713721
const message = CodeWhispererConstants.selectSQLMetadataFileHelpMessage
714722
const buttons: ChatItemButton[] = []
715723

packages/core/src/codewhisperer/commands/startTransformByQ.ts

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -732,37 +732,59 @@ export async function finalizeTransformationJob(status: string) {
732732
export async function getValidLanguageUpgradeCandidateProjects() {
733733
const openProjects = await getOpenProjects()
734734
const javaMavenProjects = await validateOpenProjects(openProjects)
735+
getLogger().info(`CodeTransformation: found ${javaMavenProjects.length} projects eligible for language upgrade`)
735736
return javaMavenProjects
736737
}
737738

738739
export async function getValidSQLConversionCandidateProjects() {
739-
const openProjects = await getOpenProjects()
740-
const javaProjects = await getJavaProjects(openProjects)
741740
const embeddedSQLProjects: TransformationCandidateProject[] = []
742-
for (const project of javaProjects) {
743-
// as long as at least one of these strings is found, project contains embedded SQL statements
744-
const searchStrings = ['oracle.jdbc.OracleDriver', 'jdbc:oracle:thin:@//', 'jdbc:oracle:oci:@//']
745-
for (const str of searchStrings) {
746-
const command = process.platform === 'win32' ? 'findstr' : 'grep'
747-
// case-insensitive, recursive search
748-
const args = command === 'findstr' ? ['/i', '/s', str] : ['-i', '-r', str]
749-
const spawnResult = spawnSync(command, args, {
750-
cwd: project.path,
751-
shell: false,
752-
encoding: 'utf-8',
753-
})
754-
/*
755-
in case the search unexpectedly fails, still allow user to transform that project.
756-
error is set when command fails to spawn; stderr is set when command itself fails.
757-
status of 0 plus anything in stdout means search string was detected.
758-
status will be non-zero and stdout / stderr / error will be empty when search string is not detected.
759-
*/
760-
if (spawnResult.error || spawnResult.stderr || (spawnResult.status === 0 && spawnResult.stdout.trim())) {
761-
embeddedSQLProjects.push(project)
762-
break
741+
await telemetry.codeTransform_validateProject.run(async () => {
742+
telemetry.record({
743+
codeTransformSessionId: CodeTransformTelemetryState.instance.getSessionId(),
744+
})
745+
const openProjects = await getOpenProjects()
746+
const javaProjects = await getJavaProjects(openProjects)
747+
let errorLog = ''
748+
for (const project of javaProjects) {
749+
// as long as at least one of these strings is found, project contains embedded SQL statements
750+
const searchStrings = ['oracle.jdbc.OracleDriver', 'jdbc:oracle:thin:@//', 'jdbc:oracle:oci:@//']
751+
for (const str of searchStrings) {
752+
const command = process.platform === 'win32' ? 'findstr' : 'grep'
753+
// case-insensitive, recursive search
754+
const args = command === 'findstr' ? ['/i', '/s', str] : ['-i', '-r', str]
755+
const spawnResult = spawnSync(command, args, {
756+
cwd: project.path,
757+
shell: false,
758+
encoding: 'utf-8',
759+
})
760+
// just for telemetry purposes
761+
if (spawnResult.error || spawnResult.stderr) {
762+
errorLog += `${JSON.stringify(spawnResult)}---`
763+
} else {
764+
errorLog += `${command} succeeded: ${spawnResult.status}`
765+
}
766+
/*
767+
note:
768+
error is set when command fails to spawn; stderr is set when command itself fails.
769+
status of 0 means search string was detected (will be printed to stdout).
770+
status will be non-zero and stdout / stderr / error will be empty when search string is not detected.
771+
*/
772+
getLogger().info(
773+
`CodeTransformation: searching for ${str} in ${project.path}, result = ${JSON.stringify(spawnResult)}`
774+
)
775+
if (spawnResult.status === 0) {
776+
embeddedSQLProjects.push(project)
777+
break
778+
}
763779
}
764780
}
765-
}
781+
getLogger().info(
782+
`CodeTransformation: found ${embeddedSQLProjects.length} projects with embedded SQL statements`
783+
)
784+
telemetry.record({
785+
codeTransformMetadata: errorLog,
786+
})
787+
})
766788
return embeddedSQLProjects
767789
}
768790

packages/core/src/codewhisperer/models/constants.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,9 @@ export const codeTransformLocThreshold = 100000
452452
export const jobStartedChatMessage =
453453
'I am starting to transform your code. It can take 10 to 30 minutes to upgrade your code, depending on the size of your project. To monitor progress, go to the Transformation Hub. If I run into any issues, I might pause the transformation to get input from you on how to proceed.'
454454

455-
export const chooseTransformationObjective = 'Enter "language upgrade" or "sql conversion"'
455+
export const chooseTransformationObjective = `I can help you with the following tasks:\n- Upgrade your Java 8 and Java 11 codebases to Java 17, or upgrade Java 17 code with up to date libraries and other dependencies.\n- Convert embedded SQL code for Oracle to PostgreSQL database migrations in AWS DMS.\n\nWhat would you like to do? You can enter "language upgrade" or "sql conversion".`
456+
457+
export const chooseTransformationObjectivePlaceholder = 'Enter "language upgrade" or "sql conversion"'
456458

457459
export const uploadingCodeStepMessage = 'Upload your code'
458460

@@ -591,7 +593,7 @@ export const jobPartiallyCompletedChatMessage = `I ${getTransformationActionStri
591593

592594
export const jobPartiallyCompletedNotification = `Amazon Q ${getTransformationActionString()} part of your code. You can review the diff to see my proposed changes and accept or reject them. The transformation summary has details about the files I updated and the errors that prevented a complete transformation.`
593595

594-
export const noPomXmlFoundChatMessage = `I couldn\'t find a project that I can upgrade. Your Java project must be built on Maven and contain a pom.xml file. For more information, see the [Amazon Q documentation](${codeTransformPrereqDoc}).`
596+
export const noPomXmlFoundChatMessage = `I couldn\'t find a project that I can upgrade. I couldn\'t find a pom.xml file in any of your open projects, nor could I find any embedded SQL statements. Currently, I can upgrade Java 8 or Java 11 projects built on Maven, or Oracle SQL to PostgreSQL statements in Java projects. For more information, see the [Amazon Q documentation](${codeTransformPrereqDoc}).`
595597

596598
export const noPomXmlFoundNotification = `None of your open modules are supported for code transformation with Amazon Q. A pom.xml is required for transformation.`
597599

0 commit comments

Comments
 (0)