このガイドでは、Cloud Code for VS Code 拡張機能を使用して、レガシー メインフレーム アプリケーションをモダナイズする方法について説明します。
Mainframe Modernization Code Rewrite を使用すると、お客様とパートナー様はコードの書き換えを反復的に行うことができます。通常は、評価を完了した後に使用します。 Mainframe Assessment Tool(MAT)この拡張機能は、コード分析、仕様、コード生成、テスト生成のための Mainframe GenAI 機能を統合し、インタラクティブな開発エクスペリエンスを提供します。
始める前に
- アカウントにログインします。 Google Cloud を初めて使用する場合は、 アカウントを作成して、 Google Cloud実際のシナリオでプロダクトがどのように動作するかを評価します。新規のお客様には、ワークロードの実行、テスト、デプロイができる無料クレジット $300 分を差し上げます。
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Vertex AI API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Vertex AI API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.- Cloud Code 拡張機能をインストールします(まだインストールしていない場合)。
- Google Cloud CLI をインストールします(まだインストールしていない場合)。
Mainframe Modernization Code Rewrite を設定する
以降のセクションでは、Mainframe Modernization Code Rewrite を設定する方法について説明します。 まず、IDE で Mainframe Modernization Code Rewrite を有効にしてから、Vertex AI に接続する必要があります。
Mainframe Modernization Code Rewrite を有効にする
Mainframe Modernization Code Rewrite を有効にする手順は次のとおりです。
Ctrl/Cmd+Shift+P を押してコマンド パレットを開きます。
[Preferences: Open User Settings (JSON)] コマンドを選択します。
Mainframe Modernization Code Rewrite を有効にするには、
"cloudcode.beta.enableMainframeModernization": true設定をsettings.jsonファイルに追加します。{ "cloudcode.updateChannel": "Insiders", "cloudcode.beta.enableMainframeModernization": true }コマンド パレットをもう一度開き(`Ctrl/Cmd+Shift+P` を押す)、 [Developer: Reload Window] コマンドを選択します。
Mainframe Modernization Code Rewrite を Vertex AI に接続する
Mainframe Modernization Code Rewrite を Vertex AI に接続する手順は次のとおりです。
ターミナル ウィンドウで次のコマンドを実行します。
gcloud auth application-default login新しく開いたウェブブラウザ ウィンドウの画面上の指示に沿って操作します。
プロンプトに沿って にログインします Google Cloud。
使用するプロジェクトを選択します。
[Developer: Reload Window] コマンドを実行します。
設定が完了したら、メインフレーム コードを含むワークスペースまたはフォルダを開き、COBOL、JCL、Easytrieve、HLASM で [Generate Specification Summary] コマンドと [Generate Modernized Code] コマンドを実行できます。
仕様の概要を生成する
[Cloud Code: Generate Specification Summary for Active File] コマンドを使用すると、レガシー メインフレーム コードの中立的な言語仕様を作成できます。 COBOL、JCL、Easytrieve、HLASM がサポートされています。
仕様の概要には、コマンド パレットまたはエクスプローラ ビューからアクセスできます。
コマンド パレット
エディタで、使用するソースファイルを選択してアクティブ ファイルにします。
Ctrl/Cmd+Shift+P を押してコマンド パレットを開きます。
[Cloud Code: Generate Specification Summary for Active File] コマンドを検索して選択します。
仕様の概要がコードの横に表示されます。
エクスプローラ
アクティビティ バーで [Explorer] をクリックするか、 Ctrl/Cmd+Shift+E を押します。
目的のソースファイルを右クリックして、[Generate Specification Summary] を選択します。
仕様の概要がコードの横に表示されます。
メインフレームのレガシーコードにアノテーションを付ける
仕様の概要生成プロセスをガイドするには、コメントを追加してレガシーコードにアノテーションを付けることができます。JCL ジョブまたは COBOL プログラムにアノテーションを付けるには、ジョブ/プログラム定義行の横にある [add] [Add] ボタンを探します。
JCL ジョブ

COBOL プログラム

[add] [Add] をクリックして、ジョブ/プログラムにアノテーションを付けることができるインライン CMS ビューを開きます。コメントを追加したら、[Create Note] をクリックして保存します。
アノテーションが保存されたら、[Generate Specification Summary] コマンドを使用して、コメントに基づいてジョブ/プログラムの仕様を生成します。
その後、アノテーションを編集して、提供されたガイダンスを絞り込むことができます。また、モデルで考慮する必要がなくなった場合は、アノテーションを削除することもできます。
モダナイズされたコードを生成する
[Cloud Code: Generate Modernized Code for Active File] コマンドを使用すると、メインフレームのレガシーコードから最新のコードを作成できます。
サポートされているソース言語: COBOL、JCL、Easytrieve、HLASM。
サポートされているターゲット言語: Java、C#、Python、SQL。
このコマンドには、コマンド パレットまたはエクスプローラ ビューからアクセスできます。
コマンド パレット
エディタで、使用するソースファイルを選択してアクティブ ファイルにします。
Ctrl/Cmd+Shift+P を押してコマンド パレットを開きます。
[Cloud Code: Generate Modernized Code for Active File] コマンドを検索して選択します。
モダナイズされたコードを生成するターゲット言語を選択します。
生成されたモダナイズされたコードが、新しい無題のファイルとしてエディタに表示されます。
エクスプローラ
アクティビティ バーで [Explorer] をクリックするか、 Ctrl/Cmd+Shift+E を押します。
モダナイズされたコードを生成するソースファイルを右クリックして、[Generate Modernized Code] を選択します。
モダナイズされたコードを生成するターゲット言語を選択します。
生成されたモダナイズされたコードが、新しい無題のファイルとしてエディタに表示されます。
設定の変更
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 アナリティクスを有効または無効にする
この構成プロパティは、拡張機能の使用状況分析情報の収集を有効または無効にします。
構成プロパティ名:
cloudcode.beta.mainframeModernization.enableGoogleAnalytics構成値の例:
false。デフォルト値:
true(アナリティクスが有効)。
Cloud Logging を有効または無効にする
この構成プロパティは、Logging を有効にするかどうかを制御します。
構成プロパティ名:
cloudcode.beta.mainframeModernization.enableCloudLogging。構成値の例:
true。デフォルト値:
false(Cloud Logging は無効)。
モデル
この構成プロパティが設定されている場合、Mainframe Modernization Code Rewrite は構成で指定された Gemini モデルを使用します。
構成プロパティ名:
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)"(毎回確認)。
訳文の言語
この構成プロパティが設定されている場合、[Generate Modernized Code] コマンドはコードの生成時にターゲット言語の選択を求めず、プロパティで設定された言語を使用します。
構成プロパティ名:
cloudcode.beta.mainframeModernization.codeGenerationSettings.targetLanguage構成値の例:
"java"、"csharp"、"python"、または"pgsql"。デフォルト値:
null(毎回確認)。
コード生成の技術スタックのヒント
この構成プロパティが設定されている場合、[Generate Modernized Code] コマンドは、コードの生成時に指定された技術スタックのヒントのリストを追加の指示として LLM に渡します。この構成は、ターゲット アーキテクチャ、フレームワーク、コード スタイルの調整のガイダンスとして使用できます。
構成プロパティ名:
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" ][デフォルト値]:
[](空のリスト。技術スタックのヒントはありません)。
Mainframe Modernization Code Rewrite データを削除する
現在のワークスペースの 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 が有効になっていないか、選択したプロジェクトで割り当てを超えている可能性があります。これが問題であることを確認するには、[Go to output] ボタンをクリックします。
If the [Go to output] button isn't available, follow the steps in Inspect the output channel. 出力チャンネルで、「Vertex.GenerateContent failed」を含むエラー メッセージを探します。 たとえば、選択した Google Cloud プロジェクトで Vertex AI API が有効になっていないことが原因のエラー メッセージは次のようになります。
"generic::unknown: retry budget exhausted (30 attempts): Vertex.GenerateContent
failed: 403 Forbidden (403)"
この問題を解決するには、次のいずれかを行います。
プロジェクトで Vertex AI API が有効になっていることを確認します。 Google Cloud
Vertex AI API が有効になっている別の Google Cloud プロジェクトに切り替えます。
Mainframe Modernization Code Rewrite コマンドを使用できない
コマンド パレットで [Generate Specification Summary] や [Generate Modernized Code] などのコマンドを使用できない場合は、Mainframe Modernization CLI ツールがインストールされていない可能性があります。これを確認するには、次の実行可能ファイルが存在しないかどうかを確認します。
- 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 を押してコマンド パレットを開きます。
- [Cloud Code: Install or Update Mainframe Modernization Tools] コマンドを選択します。
- 実行可能ファイルが存在しないことを確認します。
- Ctrl/Cmd+Shift+P を押してコマンド パレットをもう一度開きます。
- [Developer: Reload Window] コマンドを選択します。
出力チャンネルを検査する
このガイドに記載されていないその他のエラーをトラブルシューティングするには、拡張機能の出力チャンネルを検査してみてください。出力チャンネルを開くには、次の操作を行います。
- Ctrl/Cmd+Shift+P を押してコマンド パレットを開きます。
- [Output: Show Output Channels] コマンドを選択します。
- [Cloud Code Mainframe Modernization] 出力チャンネルを選択します。