Skip to content

Commit

Permalink
Fix v2 migration package mapping (aws#5524)
Browse files Browse the repository at this point in the history
* Fix v2 migration package mapping

* Add client mapping
  • Loading branch information
zoewangg authored Aug 22, 2024
1 parent c320377 commit 94e6580
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

package software.amazon.awssdk.v2migration.internal.utils;

import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.utils.internal.CodegenNamingUtils;
Expand All @@ -24,6 +26,106 @@ public final class NamingConversionUtils {

private static final String V1_PACKAGE_PREFIX = "com.amazonaws.services";
private static final String V2_PACKAGE_PREFIX = "software.amazon.awssdk.services";
private static final Map<String, String> PACKAGE_MAPPING = new HashMap<>();
private static final Map<String, String> CLIENT_MAPPING = new HashMap<>();

static {
PACKAGE_MAPPING.put("appregistry", "servicecatalogappregistry");
PACKAGE_MAPPING.put("certificatemanager", "acm");
PACKAGE_MAPPING.put("cloudcontrolapi", "cloudcontrol");
PACKAGE_MAPPING.put("cloudsearchv2", "cloudsearch");
PACKAGE_MAPPING.put("cloudwatchevidently", "evidently");
PACKAGE_MAPPING.put("logs", "cloudwatchlogs");
PACKAGE_MAPPING.put("cloudwatchrum", "rum");
PACKAGE_MAPPING.put("cognitoidp", "cognitoidentityprovider");
PACKAGE_MAPPING.put("connectcampaign", "connectcampaigns");
PACKAGE_MAPPING.put("connectwisdom", "wisdom");
PACKAGE_MAPPING.put("databasemigrationservice", "databasemigration");
PACKAGE_MAPPING.put("dynamodbv2", "dynamodb");
PACKAGE_MAPPING.put("elasticfilesystem", "efs");
PACKAGE_MAPPING.put("elasticmapreduce", "emr");
PACKAGE_MAPPING.put("gluedatabrew", "databrew");
PACKAGE_MAPPING.put("iamrolesanywhere", "rolesanywhere");
PACKAGE_MAPPING.put("identitymanagement", "iam");
PACKAGE_MAPPING.put("iotdata", "iotdataplane");
PACKAGE_MAPPING.put("mainframemodernization", "m2");
PACKAGE_MAPPING.put("managedgrafana", "grafana");
PACKAGE_MAPPING.put("migrationhubstrategyrecommendations", "migrationhubstrategy");
PACKAGE_MAPPING.put("nimblestudio", "nimble");
PACKAGE_MAPPING.put("private5g", "privatenetworks");
PACKAGE_MAPPING.put("prometheus", "amp");
PACKAGE_MAPPING.put("recyclebin", "rbin");
PACKAGE_MAPPING.put("redshiftdataapi", "redshiftdata");
PACKAGE_MAPPING.put("sagemakeredgemanager", "sagemakeredge");
PACKAGE_MAPPING.put("securitytoken", "sts");
PACKAGE_MAPPING.put("servermigration", "sms");
PACKAGE_MAPPING.put("simpleemail", "ses");
PACKAGE_MAPPING.put("simpleemailv2", "sesv2");
PACKAGE_MAPPING.put("simplesystemsmanagement", "ssm");
PACKAGE_MAPPING.put("simpleworkflow", "swf");
PACKAGE_MAPPING.put("stepfunctions", "sfn");
}

static {
CLIENT_MAPPING.put("ACMPCA", "AcmPca");
CLIENT_MAPPING.put("AppRegistry", "ServiceCatalogAppRegistry");
CLIENT_MAPPING.put("AugmentedAIRuntime", "SageMakerA2IRuntime");
CLIENT_MAPPING.put("BillingConductor", "Billingconductor");
CLIENT_MAPPING.put("CertificateManager", "Acm");
CLIENT_MAPPING.put("CloudControlApi", "CloudControl");
CLIENT_MAPPING.put("CloudHSMV2", "CloudHsmV2");
CLIENT_MAPPING.put("CloudWatchEvidently", "Evidently");
CLIENT_MAPPING.put("CloudWatchRUM", "Rum");
CLIENT_MAPPING.put("CodeArtifact", "Codeartifact");
CLIENT_MAPPING.put("CodeStarNotifications", "CodestarNotifications");
CLIENT_MAPPING.put("CodeStarconnections", "CodeStarConnections");
CLIENT_MAPPING.put("ConnectCampaign", "ConnectCampaigns");
CLIENT_MAPPING.put("ConnectWisdom", "Wisdom");
CLIENT_MAPPING.put("DatabaseMigrationService", "DatabaseMigration");
CLIENT_MAPPING.put("DirectoryService", "Directory");
CLIENT_MAPPING.put("DynamoDB", "DynamoDb");
CLIENT_MAPPING.put("DynamoDBStreams", "DynamoDbStreams");
CLIENT_MAPPING.put("ElasticFileSystem", "Efs");
CLIENT_MAPPING.put("ElasticMapReduce", "Emr");
CLIENT_MAPPING.put("FinSpaceData", "FinspaceData");
CLIENT_MAPPING.put("ForecastQuery", "Forecastquery");
CLIENT_MAPPING.put("GlueDataBrew", "DataBrew");
CLIENT_MAPPING.put("IAMRolesAnywhere", "RolesAnywhere");
CLIENT_MAPPING.put("IdentityManagement", "Iam");
CLIENT_MAPPING.put("IdentityStore", "Identitystore");
CLIENT_MAPPING.put("IoT1ClickDevices", "Iot1ClickDevices");
CLIENT_MAPPING.put("IoT1ClickProjects", "Iot1ClickProjects");
CLIENT_MAPPING.put("IoTDeviceAdvisor", "IotDeviceAdvisor");
CLIENT_MAPPING.put("IoTEvents", "IotEvents");
CLIENT_MAPPING.put("IoTEventsData", "IotEventsData");
CLIENT_MAPPING.put("IoTJobsDataPlane", "IotJobsDataPlane");
CLIENT_MAPPING.put("IoTWireless", "IotWireless");
CLIENT_MAPPING.put("IotData", "IotDataPlane");
CLIENT_MAPPING.put("KinesisVideoSignalingChannels", "KinesisVideoSignaling");
CLIENT_MAPPING.put("Logs", "CloudWatchLogs");
CLIENT_MAPPING.put("LookoutforVision", "LookoutVision");
CLIENT_MAPPING.put("MainframeModernization", "M2");
CLIENT_MAPPING.put("ManagedGrafana", "Grafana");
CLIENT_MAPPING.put("MigrationHubStrategyRecommendations", "MigrationHubStrategy");
CLIENT_MAPPING.put("NimbleStudio", "Nimble");
CLIENT_MAPPING.put("Private5G", "PrivateNetworks");
CLIENT_MAPPING.put("RecycleBin", "Rbin");
CLIENT_MAPPING.put("RedshiftDataAPI", "RedshiftData");
CLIENT_MAPPING.put("ResilienceHub", "Resiliencehub");
CLIENT_MAPPING.put("SSOOIDC", "SsoOidc");
CLIENT_MAPPING.put("SagemakerEdgeManager", "SagemakerEdge");
CLIENT_MAPPING.put("SavingsPlans", "Savingsplans");
CLIENT_MAPPING.put("SecurityTokenService", "Sts");
CLIENT_MAPPING.put("ServerMigration", "Sms");
CLIENT_MAPPING.put("SimpleEmailService", "Ses");
CLIENT_MAPPING.put("SimpleEmailServiceV2", "SesV2");
CLIENT_MAPPING.put("SimpleSystemsManagement", "Ssm");
CLIENT_MAPPING.put("SimpleWorkflow", "Swf");
CLIENT_MAPPING.put("StepFunctions", "Sfn");
CLIENT_MAPPING.put("WAF", "Waf");
CLIENT_MAPPING.put("WAFRegional", "WafRegional");
CLIENT_MAPPING.put("Workspaces", "WorkSpaces");
}

private NamingConversionUtils() {
}
Expand Down Expand Up @@ -51,11 +153,12 @@ public static String getV2Equivalent(String currentFqcn) {
* Edge cases in v1 package names
*/
private static String checkPackageServiceNameForV2Suffix(String v2PackagePrefix) {
if (v2PackagePrefix.contains("dynamodbv2")) {
return v2PackagePrefix.replace("dynamodbv2", "dynamodb");
}
if (v2PackagePrefix.contains("cloudsearchv2")) {
return v2PackagePrefix.replace("cloudsearchv2", "cloudsearch");
for (Map.Entry<String, String> entry : PACKAGE_MAPPING.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (v2PackagePrefix.contains(key)) {
return v2PackagePrefix.replace(key, value);
}
}
return v2PackagePrefix;
}
Expand All @@ -64,10 +167,12 @@ public static String getV2ModelPackageWildCardEquivalent(String currentFqcn) {
int lastIndexOfDot = currentFqcn.lastIndexOf(".");
String packagePrefix = currentFqcn.substring(0, lastIndexOfDot);
String v2PackagePrefix = packagePrefix.replace(V1_PACKAGE_PREFIX, V2_PACKAGE_PREFIX);
v2PackagePrefix = checkPackageServiceNameForV2Suffix(v2PackagePrefix);
return v2PackagePrefix + ".*";
}

private static String getV2ClientOrExceptionEquivalent(String className) {

if (className.startsWith("Abstract")) {
className = className.substring(8);
}
Expand All @@ -77,6 +182,15 @@ private static String getV2ClientOrExceptionEquivalent(String className) {
className = className.substring(3);
}

for (Map.Entry<String, String> entry : CLIENT_MAPPING.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (className.contains(key)) {
className = className.replace(key, value);
break;
}
}

String v2Style = CodegenNamingUtils.pascalCase(className);

if (className.endsWith("Exception")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@ void v1Pojos_shouldConvertToV2() {
.isEqualTo("software.amazon.awssdk.services.iot.ListCaCertificatesRequest");
}

@Test
void v1PojoSpecialCase_shouldConvertToV2() {
assertThat(NamingConversionUtils.getV2Equivalent("com.amazonaws.services.stepfunctions.model.DeleteActivityRequest"))
.isEqualTo("software.amazon.awssdk.services.sfn.model.DeleteActivityRequest");
assertThat(NamingConversionUtils.getV2Equivalent("com.amazonaws.services.stepfunctions.model.AWSStepFunctionsException"))
.isEqualTo("software.amazon.awssdk.services.sfn.model.SfnException");
}

@Test
void v1ClientSpecialCase_shouldConvertToV2() {
assertThat(NamingConversionUtils.getV2Equivalent("com.amazonaws.services.dynamodbv2.AmazonDynamoDB"))
.isEqualTo("software.amazon.awssdk.services.dynamodb.DynamoDbClient");
assertThat(NamingConversionUtils.getV2Equivalent("com.amazonaws.services.simpleworkflow.AmazonSimpleWorkflowClient"))
.isEqualTo("software.amazon.awssdk.services.swf.SwfClient");
assertThat(NamingConversionUtils.getV2Equivalent("com.amazonaws.services.cloudsearchv2.AmazonCloudSearch"))
.isEqualTo("software.amazon.awssdk.services.cloudsearch.CloudSearchClient");
}


@Test
void v1SyncClients_shouldConvertToV2() {
assertThat(NamingConversionUtils.getV2Equivalent("com.amazonaws.services.iot.AWSIot"))
Expand Down Expand Up @@ -84,6 +103,8 @@ void v2WildCardImport_shouldConvertToV2() {
.isEqualTo("software.amazon.awssdk.services.iot.model.*");
assertThat(NamingConversionUtils.getV2ModelPackageWildCardEquivalent("com.amazonaws.services.iot.*"))
.isEqualTo("software.amazon.awssdk.services.iot.*");
assertThat(NamingConversionUtils.getV2ModelPackageWildCardEquivalent("com.amazonaws.services.cloudsearchv2.*"))
.isEqualTo("software.amazon.awssdk.services.cloudsearch.*");
}

@Test
Expand Down

0 comments on commit 94e6580

Please sign in to comment.