本指南將說明如何使用 Cloud Code for VS Code 擴充功能,將舊版大型主機應用程式現代化。
大型主機現代化程式碼重寫功能可讓客戶和合作夥伴採用疊代方式重寫程式碼。通常是在使用 Mainframe Assessment Tool (MAT) 完成評估後使用。這項擴充功能整合了 Mainframe GenAI 功能,可進行程式碼分析、規格、程式碼生成和測試生成,提供互動式開發體驗。
事前準備
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI API.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI API.
- 如果尚未安裝,請安裝 Cloud Code 擴充功能。
- 如果尚未安裝 Google Cloud CLI,請先安裝。
按下 Ctrl/Cmd+Shift+P 開啟「Command Palette」(指令面板)。
選取「Preferences: Open User Settings (JSON)」指令。
如要啟用大型主機現代化程式碼重寫功能,請在
settings.json
檔案中新增"cloudcode.beta.enableMainframeModernization": true
設定:{ "cloudcode.updateChannel": "Insiders", "cloudcode.beta.enableMainframeModernization": true }
再次開啟「Command Palette」(按下 Ctrl/Cmd+Shift+P),然後選取「Developer: Reload Window」指令。
在終端機視窗中執行下列指令:
gcloud auth application-default login
按照新開啟的網路瀏覽器視窗中的畫面指示操作。
按照提示登入 Google Cloud。
選取要使用的專案。
執行「Developer: Reload Window」(開發人員:重新載入視窗) 指令。
在編輯器中選取要使用的來源檔案,將其設為有效檔案。
按下 Ctrl/Cmd+Shift+P 開啟「Command Palette」(指令面板)。
搜尋並選取「Cloud Code: Generate Specification Summary for Active File」(Cloud Code:為現用檔案產生規格摘要) 指令。
在活動列中,按一下「Explorer」或按下 Ctrl/Cmd+Shift+E。
在偏好的來源檔案上按一下滑鼠右鍵,然後選取「Generate Specification Summary」(產生規格摘要)。
如要開啟內嵌 CMS 檢視畫面,以便為工作/節目加上註解,請按一下「新增」。新增附註後,按一下「建立附註」即可儲存。
儲存註解後,請使用「Generate Specification Summary」(產生規格摘要) 指令,根據註解產生工作/程式的規格。
然後編輯註解,修正提供的指引,或刪除註解,讓模型不再將其納入考量。
在編輯器中選取要使用的來源檔案,將其設為有效檔案。
按下 Ctrl/Cmd+Shift+P 開啟「Command Palette」(指令面板)。
搜尋並選取「Cloud Code: Generate Modernized Code for Active File」(Cloud Code:為現用檔案產生現代化程式碼) 指令。
選取要產生新版程式碼的目標語言。
編輯器中會顯示產生的新式程式碼,並以未命名的新檔案形式呈現。
在活動列中,按一下「Explorer」或按下 Ctrl/Cmd+Shift+E。
在要產生新式程式碼的來源檔案上按一下滑鼠右鍵,然後選取「產生新式程式碼」。
選取要產生新版程式碼的目標語言。
編輯器中會顯示產生的新式程式碼,並以未命名的新檔案形式呈現。
設定屬性名稱:
cloudcode.beta.mainframeModernization.enableGoogleAnalytics
。設定值範例:
false
。預設值:
true
(已啟用 Analytics)。設定屬性名稱:
cloudcode.beta.mainframeModernization.enableCloudLogging
。設定值範例:
true
。預設值:
false
(停用 Cloud Logging)。設定屬性名稱:
cloudcode.beta.mainframeModernization.model
設定值範例:
"gemini-1.5-flash"
、"gemini-1.5-pro"
、"gemini-2.0-flash"
、"gemini-2.0-flash-lite"
或"gemini-2.5-pro"
。預設值:
"(default)"
(每次都詢問)。設定屬性名稱:
cloudcode.beta.mainframeModernization.codeGenerationSettings.targetLanguage
設定值範例:
"java"
、"csharp"
、"python"
或"pgsql"
。預設值:
null
(每次都詢問)。設定屬性名稱:
cloudcode.beta.mainframeModernization.codeGenerationSettings.techStackHints
範例設定值:
[ "Do not print messages directly to the console; use a logging framework instead.", "when generating java code - use Spring Boot version 3 as the framework" ]
預設值:
[]
(空白清單;沒有技術堆疊提示)。從選單列中依序選取「View」>「Terminal」,或按下
⌃
鍵盤快速鍵,開啟終端機。在終端機中輸入下列指令:
確認專案已啟用 Vertex AI API。 Google Cloud
切換至已啟用 Vertex AI API 的其他 Google Cloud 專案。
- Linux:
~/.cache/cloud-code/mainframe/bin/codegen
- Windows:
%LOCALAPPDATA%\cloud-code\mainframe\bin\codegen.exe
- macOS:
$HOME/Library/Application Support/cloud-code/mainframe/bin/codegen_macos
- 按下 Ctrl/Cmd+Shift+P 開啟「Command Palette」(指令面板)。
- 選取「Cloud Code: Install or Update Mainframe Modernization Tools」指令。
- 確認可執行檔不再遺失。
- 再次按下 Ctrl/Cmd+Shift+P 開啟「Command Palette」(指令面板)。
- 選取「開發人員:重新載入視窗」指令。
- 按下 Ctrl/Cmd+Shift+P 開啟「Command Palette」(指令面板)。
- 選取「輸出:顯示輸出通道」指令。
- 選取 Cloud Code Mainframe Modernization 輸出管道。
設定大型主機現代化程式碼重寫
下列各節說明如何設定 Mainframe Modernization Code Rewrite。您必須先在 IDE 中啟用 Mainframe Modernization Code Rewrite,然後連線至 Vertex AI。
啟用大型主機現代化程式碼重寫功能
如要啟用 Mainframe Modernization Code Rewrite,請按照下列步驟操作:
將 Mainframe Modernization Code Rewrite 連線至 Vertex AI
如要將 Mainframe Modernization Code Rewrite 連線至 Vertex AI,請按照下列步驟操作:
設定完成後,您可以開啟任何包含大型主機程式碼的工作區或資料夾,並在 COBOL、JCL、Easytrieve 和 HLASM 上執行「Generate Specification Summary」(產生規格摘要) 和「Generate Modernized Code」(產生現代化程式碼) 指令。
生成規格摘要
Cloud Code:為現用檔案產生規格摘要指令可讓您為舊版大型主機程式碼建立中性語言規格。支援 COBOL、JCL、Easytrieve 和 HLASM。
您可以透過「指令面板」或「檔案總管」檢視畫面存取規格摘要:
指令區塊面板
程式碼旁會顯示規格摘要。
Explorer
程式碼旁會顯示規格摘要。
為大型主機舊版程式碼加上註解
如要引導規格摘要的生成過程,可以新增註解來註解舊版程式碼。如要註解 JCL 工作或 COBOL 程式,請在工作/程式定義行旁邊尋找「add」「Add」按鈕:
JCL 工作
COBOL 程式
產生現代化程式碼
Cloud Code:為現用檔案生成現代化程式碼指令可讓您從大型主機舊版程式碼建立現代化程式碼。
支援的來源語言:COBOL、JCL、Easytrieve 和 HLASM。
支援的目標語言:Java、C#、Python、SQL。
您可以透過指令面板或「Explorer」檢視畫面存取這項指令:
指令區塊面板
Explorer
修改設定
您可以透過工作區範圍或 (全域) 使用者設定範圍,設定 Mainframe Modernization Code Rewrite 的下列設定。
如要在工作區層級修改設定,請按下 Ctrl/Cmd+Shift+P 開啟指令面板,然後選取「Preferences: Open Workspace Settings (JSON)」指令。
如要修改全域使用者設定層級的設定,請按下 Ctrl/Cmd+Shift+P 開啟指令區塊,然後選取「Preferences: Open User Settings (JSON)」指令。
以下是 settings.json
檔案的範例,其中包含擴充功能的全部設定屬性:
{
"cloudcode.beta.enableMainframeModernization": true,
"cloudcode.beta.mainframeModernization.enableGoogleAnalytics": true,
"cloudcode.beta.mainframeModernization.enableCloudLogging": false,
"cloudcode.beta.mainframeModernization.model": "gemini-2.5-pro",
"cloudcode.beta.mainframeModernization.codeGenerationSettings.targetLanguage": "csharp",
"cloudcode.beta.mainframeModernization.codeGenerationSettings.techStackHints": [
"Do not print messages directly to the console; use a logging framework instead."
],
}
啟用及停用 Google Analytics
這項設定屬性會啟用或停用擴充功能的用量分析資料收集功能。
啟用及停用 Cloud Logging
這項設定屬性可控制是否啟用記錄功能。
模型
設定這項設定屬性後,Mainframe Modernization Code Rewrite 會使用設定中指定的 Gemini 模型。
譯文語言
設定這個設定屬性後,產生現代化程式碼指令就不會再要求您選取產生程式碼的目標語言,而是使用屬性中設定的語言。
程式碼生成技術堆疊提示
設定這項設定屬性後,Generate Modernized Code 指令會在生成程式碼時,將指定的技術堆疊提示清單做為額外指令傳遞至 LLM。這項設定可做為調整目標架構、架構和程式碼樣式的指引。
刪除大型主機現代化程式碼重寫資料
如要移除 Mainframe Modernization Code Rewrite 為目前工作區儲存在本機的所有資料,請按照下列步驟操作:
Linux (Bash 或 Zsh)
workspace_id=$(printf %s "$PWD$(stat -c '%i' .)" | md5sum | head -c 32)
workspace_storage_dir="$HOME/.config/Code/User/workspaceStorage/$workspace_id"
rm -r "$workspace_storage_dir/googlecloudtools.cloudcode/mainframe/"
Windows (PowerShell)
$workspacePath = (Get-Location).ToString()
$tempFile = (New-TemporaryFile).FullName
($workspacePath.Substring(0, 1).ToLower() + $workspacePath.Substring(1) +
(([decimal](Get-Date (Get-ItemProperty . |
Select-Object -ExpandProperty CreationTimeUtc) -UFormat %s) * 1000) -split '\.')[0]
) | Out-File -FilePath $tempFile -Encoding ascii -NoNewline
$workspaceId = (Get-FileHash -Algorithm MD5 -Path $tempFile).Hash.ToLower()
Remove-Item $tempFile
$workspaceStorageDir = "$env:APPDATA\Code\User\workspaceStorage\$workspaceId"
Remove-Item -Recurse "$workspaceStorageDir\googlecloudtools.cloudcode\mainframe"
疑難排解
本節將說明 Mainframe Modernization Code Rewrite 的已知問題,並提供疑難排解步驟:
專案不支援 Vertex AI Google Cloud
如果「Generate Specification Summary」(產生規格摘要) 或「Generate Modernized Code」(產生現代化程式碼) 指令執行時間過長,然後失敗,可能是因為 Vertex AI API 未啟用,或已超出所選專案的配額。如要確認是否為這個問題,請按一下「前往輸出」按鈕。
如果無法使用「前往輸出」按鈕,請按照「檢查輸出管道」一節中的步驟操作。在輸出管道中,尋找含有「Vertex.GenerateContent failed」的錯誤訊息。舉例來說,如果所選 Google Cloud 專案未啟用 Vertex AI API,就會顯示以下錯誤訊息:
"generic::unknown: retry budget exhausted (30 attempts): Vertex.GenerateContent
failed: 403 Forbidden (403)"
如要解決這個問題,請採取下列其中一種做法:
無法使用大型主機現代化程式碼重寫指令
如果「命令調色盤」中沒有「Generate Specification Summary」(產生規格摘要) 或「Generate Modernized Code」(產生現代化程式碼) 等指令,可能表示 Mainframe Modernization CLI 工具安裝失敗。如要確認是否為這種情況,請檢查下列可執行檔是否遺失:
如果是這種情況,請嘗試執行下列工作來解決問題:
檢查輸出頻道
如要排解本指南其他部分未列出的錯誤,請嘗試檢查擴充功能的輸出通道。如要開啟輸出管道,請執行下列工作: