Skip to content

Commit

Permalink
copy over entire ZIP metadata file
Browse files Browse the repository at this point in the history
  • Loading branch information
David Hasani committed Oct 18, 2024
1 parent 7dbe8e0 commit b4c97ad
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 29 deletions.
13 changes: 11 additions & 2 deletions packages/core/src/amazonqGumby/chat/controller/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import { getAuthType } from '../../../codewhisperer/service/transformByQ/transfo
import DependencyVersions from '../../models/dependencies'
import { getStringHash } from '../../../shared/utilities/textUtilities'
import { getVersionData } from '../../../codewhisperer/service/transformByQ/transformMavenHandler'
import AdmZip from 'adm-zip'

// These events can be interactions within the chat,
// or elsewhere in the IDE
Expand Down Expand Up @@ -532,7 +533,7 @@ export class GumbyController {
canSelectMany: false,
openLabel: 'Select',
filters: {
'SCT metadata': ['sct'], // Restrict user to only pick a .sct file
'SCT metadata': ['zip'], // Restrict user to only pick a .zip file
},
})

Expand All @@ -545,7 +546,15 @@ export class GumbyController {
return
}

const fileContents = nodefs.readFileSync(fileUri[0].fsPath, 'utf-8')
const metadataZip = new AdmZip(fileUri[0].fsPath)
const fileEntries = metadataZip.getEntries()
const metadataFile = fileEntries.find((entry) => entry.name.endsWith('.sct'))
if (!metadataFile) {
this.messenger.sendUnrecoverableErrorResponse('invalid-zip-no-sct-file', message.tabID)
return
}

const fileContents = metadataFile.getData().toString('utf-8')

const isValidMetadata = await validateSQLMetadataFile(fileContents, message)
if (!isValidMetadata) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export type UnrecoverableErrorType =
| 'unsupported-source-db'
| 'unsupported-target-db'
| 'error-parsing-sct-file'
| 'invalid-zip-no-sct-file'

export enum GumbyNamedMessages {
COMPILATION_PROGRESS_MESSAGE = 'gumbyProjectCompilationMessage',
Expand Down Expand Up @@ -440,6 +441,8 @@ export class Messenger {
break
case 'error-parsing-sct-file':
message = CodeWhispererConstants.invalidMetadataFileErrorParsing
case 'invalid-zip-no-sct-file':
message = CodeWhispererConstants.invalidMetadataFileNoSctFile
}

const buttons: ChatItemButton[] = []
Expand Down Expand Up @@ -558,7 +561,7 @@ export class Messenger {
`
this.dispatcher.sendChatMessage(
new ChatMessage(
{ message: 'I detected the following in your .sct metadata file.', messageType: 'ai-prompt' },
{ message: CodeWhispererConstants.sqlMetadataFileReceived, messageType: 'ai-prompt' },
tabID
)
)
Expand Down
13 changes: 9 additions & 4 deletions packages/core/src/codewhisperer/models/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,13 +503,18 @@ export const absolutePathDetectedMessage = (numPaths: number, buildFile: string,
export const unsupportedJavaVersionChatMessage = `Sorry, currently I can only upgrade Java 8 or Java 11 projects. For more information, see the [Amazon Q documentation](${codeTransformPrereqDoc}).`

export const selectSQLMetadataFileHelpMessage =
'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.'
'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.'

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

export const invalidMetadataFileUnsupportedTargetDB = `Sorry, your .sct metadata file appears to be invalid; the target DB must be Aurora PostgreSQL or Amazon RDS for PostgreSQL.`
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.`

export const invalidMetadataFileErrorParsing = 'Sorry, the .sct metadata file you provided appears to be invalid.'
export const invalidMetadataFileErrorParsing = 'Sorry, the .sct file in the provided ZIP appears to be invalid.'

export const invalidMetadataFileNoSctFile =
'Sorry, the provided ZIP does not contain a .sct file, which is needed to do the transformation.'

export const sqlMetadataFileReceived = 'I detected the following in the .sct file from the provided ZIP.'

export const failedToStartJobChatMessage =
"Sorry, I couldn't begin the transformation. Please try starting the transformation again."
Expand Down
21 changes: 12 additions & 9 deletions packages/core/src/codewhisperer/models/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,19 +319,22 @@ export enum BuildSystem {

export class ZipManifest {
sourcesRoot: string = 'sources/'
dependenciesRoot: string | undefined = 'dependencies/'
dependenciesRoot: string = 'dependencies/'
buildLogs: string = 'build-logs.txt'
version: string = '1.0'
hilCapabilities: string[] = ['HIL_1pDependency_VersionUpgrade']
transformCapabilities: string[] = ['EXPLAINABILITY_V1']
transformCapabilities: string[] = ['EXPLAINABILITY_V1'] // TO-DO: for SQL conversions, maybe make this = []
customBuildCommand: string = 'clean test'
customConversions: {
type: string | undefined
source: string | undefined
target: string | undefined
schema: string | undefined
host: string | undefined
} = { type: undefined, source: undefined, target: undefined, schema: undefined, host: undefined }
requestedConversions: {
sqlConversion:
| {
source: string | undefined
target: string | undefined
schema: string | undefined
host: string | undefined
}
| undefined
} = { sqlConversion: undefined }
}

export interface IHilZipManifestParams {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,15 +320,19 @@ export async function zipCode({ dependenciesFolder, humanInTheLoopFlag, projectP
if (transformByQState.getMetadataPathSQL() && zipManifest instanceof ZipManifest) {
// user is doing a SQL conversion since metadataPath is defined
// also, it must be a ZipManifest since only other option is HilZipManifest which is not used for SQL conversions
zip.addLocalFile(
transformByQState.getMetadataPathSQL(),
path.join(zipManifest.sourcesRoot, 'qct-sct-metadata')
)
zipManifest.customConversions['source'] = transformByQState.getSourceDB()
zipManifest.customConversions['target'] = transformByQState.getTargetDB()
zipManifest.customConversions['type'] = 'SQL'
zipManifest.customConversions['schema'] = transformByQState.getSchema()
zipManifest.customConversions['host'] = transformByQState.getSourceServerName()
zipManifest.requestedConversions.sqlConversion = {
source: transformByQState.getSourceDB(),
target: transformByQState.getTargetDB(),
schema: transformByQState.getSchema(),
host: transformByQState.getSourceServerName(),
}
const metadataZip = new AdmZip(transformByQState.getMetadataPathSQL())
// TO-DO: later make this add to path.join(zipManifest.dependenciesRoot, 'qct-sct-metadata', entry.entryName) so that it's more organized
metadataZip
.getEntries()
.forEach((entry) =>
zip.addFile(path.join(zipManifest.dependenciesRoot, entry.entryName), entry.getData())
)
const sqlMetadataSize = (await nodefs.promises.stat(transformByQState.getMetadataPathSQL())).size
getLogger().info(`CodeTransformation: SQL metadata file size = ${sqlMetadataSize}`)
}
Expand All @@ -354,10 +358,6 @@ export async function zipCode({ dependenciesFolder, humanInTheLoopFlag, projectP
}
getLogger().info(`CodeTransformation: dependency files size = ${dependencyFilesSize}`)
dependenciesCopied = true
} else {
if (zipManifest instanceof ZipManifest) {
zipManifest.dependenciesRoot = undefined
}
}

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

0 comments on commit b4c97ad

Please sign in to comment.