Contoh Migration Hub menggunakan SDK untuk Java 2.x - AWS SDKContoh Kode

Ada lebih banyak AWS SDK contoh yang tersedia di GitHub repo SDKContoh AWS Dokumen.

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Contoh Migration Hub menggunakan SDK untuk Java 2.x

Contoh kode berikut menunjukkan cara melakukan tindakan dan mengimplementasikan skenario umum menggunakan AWS SDK for Java 2.x with Migration Hub.

Tindakan adalah kutipan kode dari program yang lebih besar dan harus dijalankan dalam konteks. Sementara tindakan menunjukkan cara memanggil fungsi layanan individual, Anda dapat melihat tindakan dalam konteks dalam skenario terkait.

Setiap contoh menyertakan tautan ke kode sumber lengkap, di mana Anda dapat menemukan instruksi tentang cara mengatur dan menjalankan kode dalam konteks.

Tindakan

Contoh kode berikut menunjukkan cara menggunakanDeleteProgressUpdateStream.

SDKuntuk Java 2.x
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode 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); } } }

Contoh kode berikut menunjukkan cara menggunakanDescribeApplicationState.

SDKuntuk Java 2.x
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode 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); } } }

Contoh kode berikut menunjukkan cara menggunakanDescribeMigrationTask.

SDKuntuk Java 2.x
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode 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); } } }

Contoh kode berikut menunjukkan cara menggunakanImportMigrationTask.

SDKuntuk Java 2.x
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode 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); } } }

Contoh kode berikut menunjukkan cara menggunakanListApplications.

SDKuntuk Java 2.x
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode 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); } } }
  • Untuk API detailnya, lihat ListApplicationsdi AWS SDK for Java 2.x APIReferensi.

Contoh kode berikut menunjukkan cara menggunakanListCreatedArtifacts.

SDKuntuk Java 2.x
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode 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); } } }

Contoh kode berikut menunjukkan cara menggunakanListMigrationTasks.

SDKuntuk Java 2.x
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode 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); } } }