Skip to content

Commit 044a4f8

Browse files
author
David Hasani
committed
copy over entire ZIP metadata file
1 parent a3e30b2 commit 044a4f8

File tree

5 files changed

+49
-29
lines changed

5 files changed

+49
-29
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import { getAuthType } from '../../../codewhisperer/service/transformByQ/transfo
6161
import DependencyVersions from '../../models/dependencies'
6262
import { getStringHash } from '../../../shared/utilities/textUtilities'
6363
import { getVersionData } from '../../../codewhisperer/service/transformByQ/transformMavenHandler'
64+
import AdmZip from 'adm-zip'
6465

6566
// These events can be interactions within the chat,
6667
// or elsewhere in the IDE
@@ -532,7 +533,7 @@ export class GumbyController {
532533
canSelectMany: false,
533534
openLabel: 'Select',
534535
filters: {
535-
'SCT metadata': ['sct'], // Restrict user to only pick a .sct file
536+
'SCT metadata': ['zip'], // Restrict user to only pick a .zip file
536537
},
537538
})
538539

@@ -545,7 +546,15 @@ export class GumbyController {
545546
return
546547
}
547548

548-
const fileContents = nodefs.readFileSync(fileUri[0].fsPath, 'utf-8')
549+
const metadataZip = new AdmZip(fileUri[0].fsPath)
550+
const fileEntries = metadataZip.getEntries()
551+
const metadataFile = fileEntries.find((entry) => entry.name.endsWith('.sct'))
552+
if (!metadataFile) {
553+
this.messenger.sendUnrecoverableErrorResponse('invalid-zip-no-sct-file', message.tabID)
554+
return
555+
}
556+
557+
const fileContents = metadataFile.getData().toString('utf-8')
549558

550559
const isValidMetadata = await validateSQLMetadataFile(fileContents, message)
551560
if (!isValidMetadata) {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export type UnrecoverableErrorType =
5151
| 'unsupported-source-db'
5252
| 'unsupported-target-db'
5353
| 'error-parsing-sct-file'
54+
| 'invalid-zip-no-sct-file'
5455

5556
export enum GumbyNamedMessages {
5657
COMPILATION_PROGRESS_MESSAGE = 'gumbyProjectCompilationMessage',
@@ -440,6 +441,8 @@ export class Messenger {
440441
break
441442
case 'error-parsing-sct-file':
442443
message = CodeWhispererConstants.invalidMetadataFileErrorParsing
444+
case 'invalid-zip-no-sct-file':
445+
message = CodeWhispererConstants.invalidMetadataFileNoSctFile
443446
}
444447

445448
const buttons: ChatItemButton[] = []
@@ -558,7 +561,7 @@ export class Messenger {
558561
`
559562
this.dispatcher.sendChatMessage(
560563
new ChatMessage(
561-
{ message: 'I detected the following in your .sct metadata file.', messageType: 'ai-prompt' },
564+
{ message: CodeWhispererConstants.sqlMetadataFileReceived, messageType: 'ai-prompt' },
562565
tabID
563566
)
564567
)

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -503,13 +503,18 @@ export const absolutePathDetectedMessage = (numPaths: number, buildFile: string,
503503
export const unsupportedJavaVersionChatMessage = `Sorry, currently I can only upgrade Java 8 or Java 11 projects. For more information, see the [Amazon Q documentation](${codeTransformPrereqDoc}).`
504504

505505
export const selectSQLMetadataFileHelpMessage =
506-
'Next, I need the .sct metadata file of your project. You can download the .sct file by going to AWS Console -> AWS DMS -> Migration Projects. Open the schema conversion project and navigate to the S3 bucket linked to it. You will find the ZIP containing the .sct file under the {schema-conversion-project}/ directory.'
506+
'Next, I need the metadata ZIP file of your project. You can download the metadata ZIP file by going to AWS Console -> AWS DMS -> Migration Projects. Open the schema conversion project and navigate to the S3 bucket linked to it. You will find the ZIP file under the {schema-conversion-project}/ directory.'
507507

508-
export const invalidMetadataFileUnsupportedSourceDB = `Sorry, your .sct metadata file appears to be invalid; the source DB must be Oracle.`
508+
export const invalidMetadataFileUnsupportedSourceDB = `Sorry, the .sct file in the provided ZIP appears to be invalid; the source DB must be Oracle.`
509509

510-
export const invalidMetadataFileUnsupportedTargetDB = `Sorry, your .sct metadata file appears to be invalid; the target DB must be Aurora PostgreSQL or Amazon RDS for PostgreSQL.`
510+
export const invalidMetadataFileUnsupportedTargetDB = `Sorry, the .sct file in the provided ZIP appears to be invalid; the target DB must be Aurora PostgreSQL or Amazon RDS for PostgreSQL.`
511511

512-
export const invalidMetadataFileErrorParsing = 'Sorry, the .sct metadata file you provided appears to be invalid.'
512+
export const invalidMetadataFileErrorParsing = 'Sorry, the .sct file in the provided ZIP appears to be invalid.'
513+
514+
export const invalidMetadataFileNoSctFile =
515+
'Sorry, the provided ZIP does not contain a .sct file, which is needed to do the transformation.'
516+
517+
export const sqlMetadataFileReceived = 'I detected the following in the .sct file from the provided ZIP.'
513518

514519
export const failedToStartJobChatMessage =
515520
"Sorry, I couldn't begin the transformation. Please try starting the transformation again."

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -319,19 +319,22 @@ export enum BuildSystem {
319319

320320
export class ZipManifest {
321321
sourcesRoot: string = 'sources/'
322-
dependenciesRoot: string | undefined = 'dependencies/'
322+
dependenciesRoot: string = 'dependencies/'
323323
buildLogs: string = 'build-logs.txt'
324324
version: string = '1.0'
325325
hilCapabilities: string[] = ['HIL_1pDependency_VersionUpgrade']
326-
transformCapabilities: string[] = ['EXPLAINABILITY_V1']
326+
transformCapabilities: string[] = ['EXPLAINABILITY_V1'] // TO-DO: for SQL conversions, maybe make this = []
327327
customBuildCommand: string = 'clean test'
328-
customConversions: {
329-
type: string | undefined
330-
source: string | undefined
331-
target: string | undefined
332-
schema: string | undefined
333-
host: string | undefined
334-
} = { type: undefined, source: undefined, target: undefined, schema: undefined, host: undefined }
328+
requestedConversions: {
329+
sqlConversion:
330+
| {
331+
source: string | undefined
332+
target: string | undefined
333+
schema: string | undefined
334+
host: string | undefined
335+
}
336+
| undefined
337+
} = { sqlConversion: undefined }
335338
}
336339

337340
export interface IHilZipManifestParams {

packages/core/src/codewhisperer/service/transformByQ/transformApiHandler.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -322,15 +322,19 @@ export async function zipCode(
322322
if (transformByQState.getMetadataPathSQL() && zipManifest instanceof ZipManifest) {
323323
// user is doing a SQL conversion since metadataPath is defined
324324
// also, it must be a ZipManifest since only other option is HilZipManifest which is not used for SQL conversions
325-
zip.addLocalFile(
326-
transformByQState.getMetadataPathSQL(),
327-
path.join(zipManifest.sourcesRoot, 'qct-sct-metadata')
328-
)
329-
zipManifest.customConversions['source'] = transformByQState.getSourceDB()
330-
zipManifest.customConversions['target'] = transformByQState.getTargetDB()
331-
zipManifest.customConversions['type'] = 'SQL'
332-
zipManifest.customConversions['schema'] = transformByQState.getSchema()
333-
zipManifest.customConversions['host'] = transformByQState.getSourceServerName()
325+
zipManifest.requestedConversions.sqlConversion = {
326+
source: transformByQState.getSourceDB(),
327+
target: transformByQState.getTargetDB(),
328+
schema: transformByQState.getSchema(),
329+
host: transformByQState.getSourceServerName(),
330+
}
331+
const metadataZip = new AdmZip(transformByQState.getMetadataPathSQL())
332+
// TO-DO: later make this add to path.join(zipManifest.dependenciesRoot, 'qct-sct-metadata', entry.entryName) so that it's more organized
333+
metadataZip
334+
.getEntries()
335+
.forEach((entry) =>
336+
zip.addFile(path.join(zipManifest.dependenciesRoot, entry.entryName), entry.getData())
337+
)
334338
const sqlMetadataSize = (await nodefs.promises.stat(transformByQState.getMetadataPathSQL())).size
335339
getLogger().info(`CodeTransformation: SQL metadata file size = ${sqlMetadataSize}`)
336340
}
@@ -356,10 +360,6 @@ export async function zipCode(
356360
}
357361
getLogger().info(`CodeTransformation: dependency files size = ${dependencyFilesSize}`)
358362
dependenciesCopied = true
359-
} else {
360-
if (zipManifest instanceof ZipManifest) {
361-
zipManifest.dependenciesRoot = undefined
362-
}
363363
}
364364

365365
zip.addFile('manifest.json', Buffer.from(JSON.stringify(zipManifest)), 'utf-8')

0 commit comments

Comments
 (0)