使用SDK适用于 Java 2.x 的 Migration Hub 示例 - AWS SDK for Java 2.x

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用SDK适用于 Java 2.x 的 Migration Hub 示例

以下代码示例向您展示了如何使用 with Migration Hub 来执行操作和实现常见场景。 AWS SDK for Java 2.x

操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景的上下文查看操作。

每个示例都包含一个指向完整源代码的链接,您可以在其中找到有关如何在上下文中设置和运行代码的说明。

主题

操作

以下代码示例显示了如何使用DeleteProgressUpdateStream

SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库中进行设置和运行。

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.migrationhub.MigrationHubClient; import software.amazon.awssdk.services.migrationhub.model.DeleteProgressUpdateStreamRequest; import software.amazon.awssdk.services.migrationhub.model.MigrationHubException; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class DeleteProgressStream { public static void main(String[] args) { final String usage = """ Usage: <progressStream>\s Where: progressStream - the name of a progress stream to delete.\s """; if (args.length != 1) { System.out.println(usage); System.exit(1); } String progressStream = args[0]; Region region = Region.US_WEST_2; MigrationHubClient migrationClient = MigrationHubClient.builder() .region(region) .build(); deleteStream(migrationClient, progressStream); migrationClient.close(); } public static void deleteStream(MigrationHubClient migrationClient, String streamName) { try { DeleteProgressUpdateStreamRequest deleteProgressUpdateStreamRequest = DeleteProgressUpdateStreamRequest .builder() .progressUpdateStreamName(streamName) .build(); migrationClient.deleteProgressUpdateStream(deleteProgressUpdateStreamRequest); System.out.println(streamName + " is deleted"); } catch (MigrationHubException e) { System.out.println(e.getMessage()); System.exit(1); } } }

以下代码示例显示了如何使用DescribeApplicationState

SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库中进行设置和运行。

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.migrationhub.MigrationHubClient; import software.amazon.awssdk.services.migrationhub.model.DescribeApplicationStateRequest; import software.amazon.awssdk.services.migrationhub.model.DescribeApplicationStateResponse; import software.amazon.awssdk.services.migrationhub.model.MigrationHubException; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class DescribeAppState { public static void main(String[] args) { final String usage = """ Usage: DescribeAppState <appId>\s Where: appId - the application id value.\s """; if (args.length != 1) { System.out.println(usage); System.exit(1); } String appId = args[0]; Region region = Region.US_WEST_2; MigrationHubClient migrationClient = MigrationHubClient.builder() .region(region) .build(); describeApplicationState(migrationClient, appId); migrationClient.close(); } public static void describeApplicationState(MigrationHubClient migrationClient, String appId) { try { DescribeApplicationStateRequest applicationStateRequest = DescribeApplicationStateRequest.builder() .applicationId(appId) .build(); DescribeApplicationStateResponse applicationStateResponse = migrationClient .describeApplicationState(applicationStateRequest); System.out.println("The application status is " + applicationStateResponse.applicationStatusAsString()); } catch (MigrationHubException e) { System.out.println(e.getMessage()); System.exit(1); } } }

以下代码示例显示了如何使用DescribeMigrationTask

SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库中进行设置和运行。

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.migrationhub.MigrationHubClient; import software.amazon.awssdk.services.migrationhub.model.DescribeMigrationTaskRequest; import software.amazon.awssdk.services.migrationhub.model.DescribeMigrationTaskResponse; import software.amazon.awssdk.services.migrationhub.model.MigrationHubException; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class DescribeMigrationTask { public static void main(String[] args) { final String usage = """ Usage: DescribeMigrationTask <migrationTask> <progressStream>\s Where: migrationTask - the name of a migration task.\s progressStream - the name of a progress stream.\s """; if (args.length < 2) { System.out.println(usage); System.exit(1); } String migrationTask = args[0]; String progressStream = args[1]; Region region = Region.US_WEST_2; MigrationHubClient migrationClient = MigrationHubClient.builder() .region(region) .build(); describeMigTask(migrationClient, migrationTask, progressStream); migrationClient.close(); } public static void describeMigTask(MigrationHubClient migrationClient, String migrationTask, String progressStream) { try { DescribeMigrationTaskRequest migrationTaskRequestRequest = DescribeMigrationTaskRequest.builder() .progressUpdateStream(progressStream) .migrationTaskName(migrationTask) .build(); DescribeMigrationTaskResponse migrationTaskResponse = migrationClient .describeMigrationTask(migrationTaskRequestRequest); System.out.println("The name is " + migrationTaskResponse.migrationTask().migrationTaskName()); } catch (MigrationHubException e) { System.out.println(e.getMessage()); System.exit(1); } } }

以下代码示例显示了如何使用ImportMigrationTask

SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库中进行设置和运行。

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.migrationhub.MigrationHubClient; import software.amazon.awssdk.services.migrationhub.model.CreateProgressUpdateStreamRequest; import software.amazon.awssdk.services.migrationhub.model.ImportMigrationTaskRequest; import software.amazon.awssdk.services.migrationhub.model.MigrationHubException; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class ImportMigrationTask { public static void main(String[] args) { final String usage = """ Usage: <migrationTask> <progressStream>\s Where: migrationTask - the name of a migration task.\s progressStream - the name of a progress stream.\s """; if (args.length != 2) { System.out.println(usage); System.exit(1); } String migrationTask = args[0]; String progressStream = args[1]; Region region = Region.US_WEST_2; MigrationHubClient migrationClient = MigrationHubClient.builder() .region(region) .build(); importMigrTask(migrationClient, migrationTask, progressStream); migrationClient.close(); } public static void importMigrTask(MigrationHubClient migrationClient, String migrationTask, String progressStream) { try { CreateProgressUpdateStreamRequest progressUpdateStreamRequest = CreateProgressUpdateStreamRequest.builder() .progressUpdateStreamName(progressStream) .dryRun(false) .build(); migrationClient.createProgressUpdateStream(progressUpdateStreamRequest); ImportMigrationTaskRequest migrationTaskRequest = ImportMigrationTaskRequest.builder() .migrationTaskName(migrationTask) .progressUpdateStream(progressStream) .dryRun(false) .build(); migrationClient.importMigrationTask(migrationTaskRequest); } catch (MigrationHubException e) { System.out.println(e.getMessage()); System.exit(1); } } }
  • 有关API详细信息,请参阅 “AWS SDK for Java 2.x API参考 ImportMigrationTask” 中的。

以下代码示例显示了如何使用ListApplications

SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库中进行设置和运行。

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.migrationhub.MigrationHubClient; import software.amazon.awssdk.services.migrationhub.model.ApplicationState; import software.amazon.awssdk.services.migrationhub.model.ListApplicationStatesRequest; import software.amazon.awssdk.services.migrationhub.model.ListApplicationStatesResponse; import software.amazon.awssdk.services.migrationhub.model.MigrationHubException; import java.util.List; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class ListApplications { public static void main(String[] args) { Region region = Region.US_WEST_2; MigrationHubClient migrationClient = MigrationHubClient.builder() .region(region) .build(); listApps(migrationClient); migrationClient.close(); } public static void listApps(MigrationHubClient migrationClient) { try { ListApplicationStatesRequest applicationStatesRequest = ListApplicationStatesRequest.builder() .maxResults(10) .build(); ListApplicationStatesResponse response = migrationClient.listApplicationStates(applicationStatesRequest); List<ApplicationState> apps = response.applicationStateList(); for (ApplicationState appState : apps) { System.out.println("App Id is " + appState.applicationId()); System.out.println("The status is " + appState.applicationStatus().toString()); } } catch (MigrationHubException e) { System.out.println(e.getMessage()); System.exit(1); } } }
  • 有关API详细信息,请参阅 “AWS SDK for Java 2.x API参考 ListApplications” 中的。

以下代码示例显示了如何使用ListCreatedArtifacts

SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库中进行设置和运行。

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.migrationhub.MigrationHubClient; import software.amazon.awssdk.services.migrationhub.model.CreatedArtifact; import software.amazon.awssdk.services.migrationhub.model.ListCreatedArtifactsRequest; import software.amazon.awssdk.services.migrationhub.model.ListCreatedArtifactsResponse; import software.amazon.awssdk.services.migrationhub.model.MigrationHubException; import java.util.List; /** * To run this Java V2 code example, ensure that you have setup your development * environment, including your credentials. * * For information, see this documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class ListCreatedArtifacts { public static void main(String[] args) { Region region = Region.US_WEST_2; MigrationHubClient migrationClient = MigrationHubClient.builder() .region(region) .build(); listArtifacts(migrationClient); migrationClient.close(); } public static void listArtifacts(MigrationHubClient migrationClient) { try { ListCreatedArtifactsRequest listCreatedArtifactsRequest = ListCreatedArtifactsRequest.builder() .maxResults(10) .migrationTaskName("SampleApp5") .progressUpdateStream("ProgressSteamB") .build(); ListCreatedArtifactsResponse response = migrationClient.listCreatedArtifacts(listCreatedArtifactsRequest); List<CreatedArtifact> apps = response.createdArtifactList(); for (CreatedArtifact artifact : apps) { System.out.println("APp Id is " + artifact.description()); System.out.println("The name is " + artifact.name()); } } catch (MigrationHubException e) { System.out.println(e.getMessage()); System.exit(1); } } }
  • 有关API详细信息,请参阅 “AWS SDK for Java 2.x API参考 ListCreatedArtifacts” 中的。

以下代码示例显示了如何使用ListMigrationTasks

SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库中进行设置和运行。

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.migrationhub.MigrationHubClient; import software.amazon.awssdk.services.migrationhub.model.ListMigrationTasksRequest; import software.amazon.awssdk.services.migrationhub.model.ListMigrationTasksResponse; import software.amazon.awssdk.services.migrationhub.model.MigrationTaskSummary; import software.amazon.awssdk.services.migrationhub.model.MigrationHubException; import java.util.List; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class ListMigrationTasks { public static void main(String[] args) { Region region = Region.US_WEST_2; MigrationHubClient migrationClient = MigrationHubClient.builder() .region(region) .build(); listMigrTasks(migrationClient); migrationClient.close(); } public static void listMigrTasks(MigrationHubClient migrationClient) { try { ListMigrationTasksRequest listMigrationTasksRequest = ListMigrationTasksRequest.builder() .maxResults(10) .build(); ListMigrationTasksResponse response = migrationClient.listMigrationTasks(listMigrationTasksRequest); List<MigrationTaskSummary> migrationList = response.migrationTaskSummaryList(); for (MigrationTaskSummary migration : migrationList) { System.out.println("Migration task name is " + migration.migrationTaskName()); System.out.println("The Progress update stream is " + migration.progressUpdateStream()); } } catch (MigrationHubException e) { System.out.println(e.getMessage()); System.exit(1); } } }
  • 有关API详细信息,请参阅 “AWS SDK for Java 2.x API参考 ListMigrationTasks” 中的。