Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import software.amazon.awssdk.codegen.model.config.customization.CustomizationConfig;
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
import software.amazon.awssdk.codegen.model.rules.endpoints.EndpointTestSuiteModel;
import software.amazon.awssdk.codegen.model.service.EndpointBddModel;
import software.amazon.awssdk.codegen.model.service.EndpointRuleSetModel;
import software.amazon.awssdk.codegen.model.service.Paginators;
import software.amazon.awssdk.codegen.model.service.ServiceModel;
Expand All @@ -62,6 +63,7 @@ public class GenerationMojo extends AbstractMojo {
private static final String PAGINATORS_FILE = "paginators-1.json";
private static final String ENDPOINT_RULE_SET_FILE = "endpoint-rule-set.json";
private static final String ENDPOINT_TESTS_FILE = "endpoint-tests.json";
private static final String ENDPOINT_BDD_FILE = "endpoint-bdd-1.json";


@Parameter(property = "codeGenResources", defaultValue = "${basedir}/src/main/resources/codegen-resources/")
Expand Down Expand Up @@ -144,6 +146,7 @@ private List<GenerationParams> initGenerationParams() throws MojoExecutionExcept
.waitersModel(loadWaiterModel(modelRootPath))
.paginatorsModel(loadPaginatorModel(modelRootPath))
.endpointRuleSetModel(loadEndpointRuleSetModel(modelRootPath))
.endpointBddModel(loadEndpointBddModel(modelRootPath))
.endpointTestSuiteModel(loadEndpointTestSuiteModel(modelRootPath))
.build();
String intermediateModelFileNamePrefix = intermediateModelFileNamePrefix(c2jModels);
Expand Down Expand Up @@ -218,6 +221,10 @@ private EndpointTestSuiteModel loadEndpointTestSuiteModel(Path root) {
return loadOptionalModel(EndpointTestSuiteModel.class, root.resolve(ENDPOINT_TESTS_FILE)).orElse(null);
}

private EndpointBddModel loadEndpointBddModel(Path root) {
return loadOptionalModel(EndpointBddModel.class, root.resolve(ENDPOINT_BDD_FILE)).orElse(null);
}

/**
* Load required model from the project resources.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import software.amazon.awssdk.codegen.model.config.customization.CustomizationConfig;
import software.amazon.awssdk.codegen.model.rules.endpoints.EndpointTestSuiteModel;
import software.amazon.awssdk.codegen.model.service.EndpointBddModel;
import software.amazon.awssdk.codegen.model.service.EndpointRuleSetModel;
import software.amazon.awssdk.codegen.model.service.Paginators;
import software.amazon.awssdk.codegen.model.service.ServiceModel;
Expand All @@ -32,19 +33,22 @@ public class C2jModels {
private final Waiters waitersModel;
private final EndpointRuleSetModel endpointRuleSetModel;
private final EndpointTestSuiteModel endpointTestSuiteModel;
private final EndpointBddModel endpointBddModel;
private final CustomizationConfig customizationConfig;
private final Paginators paginatorsModel;

private C2jModels(ServiceModel serviceModel,
Waiters waitersModel,
EndpointRuleSetModel endpointRuleSetModel,
EndpointTestSuiteModel endpointTestSuiteModel,
EndpointBddModel endpointBddModel,
CustomizationConfig customizationConfig,
Paginators paginatorsModel) {
this.serviceModel = serviceModel;
this.waitersModel = waitersModel;
this.endpointRuleSetModel = endpointRuleSetModel;
this.endpointTestSuiteModel = endpointTestSuiteModel;
this.endpointBddModel = endpointBddModel;
this.customizationConfig = customizationConfig;
this.paginatorsModel = paginatorsModel;
}
Expand Down Expand Up @@ -77,12 +81,17 @@ public EndpointTestSuiteModel endpointTestSuiteModel() {
return endpointTestSuiteModel;
}

public EndpointBddModel endpointBddModel() {
return endpointBddModel;
}

public static class Builder implements SdkBuilder<Builder, C2jModels> {

private ServiceModel serviceModel;
private Waiters waitersModel;
private EndpointRuleSetModel endpointRuleSetModel;
private EndpointTestSuiteModel endpointTestSuiteModel;
private EndpointBddModel endpointBddModel;
private CustomizationConfig customizationConfig;
private Paginators paginatorsModel;

Expand Down Expand Up @@ -119,12 +128,17 @@ public Builder endpointTestSuiteModel(EndpointTestSuiteModel endpointTestSuiteMo
return this;
}

public Builder endpointBddModel(EndpointBddModel endpointBddModel) {
this.endpointBddModel = endpointBddModel;
return this;
}

@Override
public C2jModels build() {
Waiters waiters = waitersModel != null ? waitersModel : Waiters.none();
Paginators paginators = paginatorsModel != null ? paginatorsModel : Paginators.none();
return new C2jModels(serviceModel, waiters, endpointRuleSetModel, endpointTestSuiteModel, customizationConfig,
paginators);
return new C2jModels(serviceModel, waiters, endpointRuleSetModel, endpointTestSuiteModel, endpointBddModel,
customizationConfig, paginators);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import software.amazon.awssdk.codegen.model.rules.endpoints.EndpointTestSuiteModel;
import software.amazon.awssdk.codegen.model.service.AuthType;
import software.amazon.awssdk.codegen.model.service.CustomOperationContextParam;
import software.amazon.awssdk.codegen.model.service.EndpointBddModel;
import software.amazon.awssdk.codegen.model.service.EndpointRuleSetModel;
import software.amazon.awssdk.codegen.model.service.Operation;
import software.amazon.awssdk.codegen.model.service.Paginators;
Expand All @@ -65,6 +66,7 @@ public class IntermediateModelBuilder {
private final Waiters waiters;
private final EndpointRuleSetModel endpointRuleSet;
private final EndpointTestSuiteModel endpointTestSuiteModel;
private final EndpointBddModel endpointBddModel;

public IntermediateModelBuilder(C2jModels models) {
this.customConfig = models.customizationConfig();
Expand All @@ -76,6 +78,7 @@ public IntermediateModelBuilder(C2jModels models) {
this.waiters = models.waitersModel();
this.endpointRuleSet = models.endpointRuleSetModel();
this.endpointTestSuiteModel = models.endpointTestSuiteModel();
this.endpointBddModel = models.endpointBddModel();
}


Expand Down Expand Up @@ -138,7 +141,8 @@ public IntermediateModel build() {
IntermediateModel fullModel = new IntermediateModel(
constructMetadata(service, customConfig), operations, shapes,
customConfig, endpointOperation, paginators.getPagination(), namingStrategy,
waiters.getWaiters(), endpointRuleSet, endpointTestSuiteModel, service.getClientContextParams());
waiters.getWaiters(), endpointRuleSet, endpointTestSuiteModel, endpointBddModel,
service.getClientContextParams());

customization.postprocess(fullModel);

Expand All @@ -160,6 +164,7 @@ public IntermediateModel build() {
fullModel.getWaiters(),
fullModel.getEndpointRuleSetModel(),
endpointTestSuiteModel,
fullModel.getEndpointBddModel(),
service.getClientContextParams());

linkMembersToShapes(trimmedModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import software.amazon.awssdk.codegen.poet.rules.EndpointProviderTestSpec;
import software.amazon.awssdk.codegen.poet.rules.EndpointResolverUtilsSpec;
import software.amazon.awssdk.codegen.poet.rules.EndpointRulesClientTestSpec;
import software.amazon.awssdk.codegen.poet.rules.bdd.BddEndpointProviderSpec;

public final class EndpointProviderTasks extends BaseGeneratorTasks {
private final GeneratorTaskParams generatorTaskParams;
Expand All @@ -48,7 +49,11 @@ protected List<GeneratorTask> createTasks() throws Exception {
List<GeneratorTask> tasks = new ArrayList<>();
tasks.add(generateInterface());
tasks.add(generateParams());
tasks.add(generateDefaultProvider2());
if (generatorTaskParams.getModel().getEndpointBddModel() != null) {
tasks.add(generateDefaultProviderBdd());
} else {
tasks.add(generateDefaultProvider2());
}
tasks.add(new RulesEngineRuntimeGeneratorTask(generatorTaskParams));
if (shouldGenerateJmesPathRuntime()) {
tasks.add(new JmesPathRuntimeGeneratorTask(generatorTaskParams));
Expand Down Expand Up @@ -79,6 +84,14 @@ private GeneratorTask generateDefaultProvider2() {
return new PoetGeneratorTask(endpointRulesInternalDir(), model.getFileHeader(), new EndpointProviderSpec(model));
}

private GeneratorTask generateDefaultProviderBdd() {
return new PoetGeneratorTask(
endpointRulesInternalDir(),
model.getFileHeader(),
new BddEndpointProviderSpec(model)
);
}

private GeneratorTask generateDefaultPartitionsProvider() {
return new PoetGeneratorTask(endpointRulesInternalDir(), model.getFileHeader(),
new DefaultPartitionDataProviderSpec(model));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import software.amazon.awssdk.codegen.model.config.customization.CustomizationConfig;
import software.amazon.awssdk.codegen.model.rules.endpoints.EndpointTestSuiteModel;
import software.amazon.awssdk.codegen.model.service.ClientContextParam;
import software.amazon.awssdk.codegen.model.service.EndpointBddModel;
import software.amazon.awssdk.codegen.model.service.EndpointRuleSetModel;
import software.amazon.awssdk.codegen.model.service.PaginatorDefinition;
import software.amazon.awssdk.codegen.model.service.WaiterDefinition;
Expand Down Expand Up @@ -60,6 +61,9 @@ public final class IntermediateModel {
@JsonIgnore
private NamingStrategy namingStrategy;

@JsonIgnore
private EndpointBddModel endpointBddModel;

private Map<String, ClientContextParam> clientContextParams;

static {
Expand All @@ -80,7 +84,7 @@ public IntermediateModel(Metadata metadata,
Map<String, ShapeModel> shapes,
CustomizationConfig customizationConfig) {
this(metadata, operations, shapes, customizationConfig, null,
Collections.emptyMap(), null, Collections.emptyMap(), null, null, null);
Collections.emptyMap(), null, Collections.emptyMap(), null, null, null, null);
}

public IntermediateModel(
Expand All @@ -94,6 +98,7 @@ public IntermediateModel(
Map<String, WaiterDefinition> waiters,
EndpointRuleSetModel endpointRuleSetModel,
EndpointTestSuiteModel endpointTestSuiteModel,
EndpointBddModel endpointBddModel,
Map<String, ClientContextParam> clientContextParams) {
this.metadata = metadata;
this.operations = operations;
Expand All @@ -105,6 +110,7 @@ public IntermediateModel(
this.waiters = waiters;
this.endpointRuleSetModel = endpointRuleSetModel;
this.endpointTestSuiteModel = endpointTestSuiteModel;
this.endpointBddModel = endpointBddModel;
this.clientContextParams = clientContextParams;
}

Expand Down Expand Up @@ -183,6 +189,10 @@ public EndpointTestSuiteModel getEndpointTestSuiteModel() {
return endpointTestSuiteModel;
}

public EndpointBddModel getEndpointBddModel() {
return endpointBddModel;
}

public Map<String, ClientContextParam> getClientContextParams() {
return clientContextParams;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.awssdk.codegen.model.service;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.Map;
import software.amazon.awssdk.codegen.model.rules.endpoints.ConditionModel;
import software.amazon.awssdk.codegen.model.rules.endpoints.ParameterModel;
import software.amazon.awssdk.codegen.model.rules.endpoints.RuleModel;

public class EndpointBddModel {
private String serviceId;
private String version;
private Map<String, ParameterModel> parameters;
private List<ConditionModel> conditions;
private List<RuleModel> results;
private int root;
private int nodeCount;
private String nodes; // Base64-encoded binary representation of BDD nodes.

public String getServiceId() {
return serviceId;
}

public void setServiceId(String serviceId) {
this.serviceId = serviceId;
}

public String getVersion() {
return version;
}

public void setVersion(String version) {
this.version = version;
}

public Map<String, ParameterModel> getParameters() {
return parameters;
}

public void setParameters(Map<String, ParameterModel> parameters) {
this.parameters = parameters;
}

public List<ConditionModel> getConditions() {
return conditions;
}

public void setConditions(List<ConditionModel> conditions) {
this.conditions = conditions;
}

public List<RuleModel> getResults() {
return results;
}

public void setResults(List<RuleModel> results) {
this.results = results;
}

public String getNodes() {
return nodes;
}

public int getRoot() {
return root;
}

public void setRoot(int root) {
this.root = root;
}

public int getNodeCount() {
return nodeCount;
}

public void setNodeCount(int nodeCount) {
this.nodeCount = nodeCount;
}

public void setNodes(String nodes) {
this.nodes = nodes;
}

public List<BddNode> getDecodedNodes() {
List<BddNode> out = new ArrayList<>(nodeCount);
byte[] data = Base64.getDecoder().decode(nodes);
ByteBuffer buf = ByteBuffer.wrap(data); // big-endian by default
while (buf.remaining() >= 12) {
int conditionIndex = buf.getInt();
int highRef = buf.getInt();
int lowRef = buf.getInt();
out.add(new BddNode(conditionIndex, highRef, lowRef));
}
return out;
}

public static class BddNode {
int conditionIndex;
int highRef;
int lowRef;

public BddNode(int conditionIndex, int highRef, int lowRef) {
this.conditionIndex = conditionIndex;
this.highRef = highRef;
this.lowRef = lowRef;
}

public int getConditionIndex() {
return conditionIndex;
}

public int getHighRef() {
return highRef;
}

public int getLowRef() {
return lowRef;
}

@Override
public String toString() {
return "[C" + conditionIndex + ", " + highRef + ", " + lowRef + "]";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,11 @@ public MethodSpec recordAccountIdEndpointModeMethod() {
+ ".ifPresent(m -> executionAttributes.getAttribute($T.BUSINESS_METRICS).addMetric(m))",
BusinessMetricsUtils.class, SdkInternalExecutionAttribute.class);

builder.addStatement("return mode.name().toLowerCase()");
// Use value() rather than name().toLowerCase() so that the returned String is an interned compile-time
// literal. That keeps the reference stable across calls and removes a per-request allocation. It also
// avoids name().toLowerCase()'s dependence on the default locale, which mangles the value under a
// Turkish locale.
builder.addStatement("return mode.value()");

return builder.build();
}
Expand Down
Loading
Loading