Skip to content

Endpoint Discovery for DynamoDb #853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 17, 2019
Merged
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 @@ -79,6 +79,7 @@ private ShapeModel generateInputShapeModel(Operation operation,
shapeModel.setType(ShapeType.Request.getValue());
shapeModel.setMarshaller(
createInputShapeMarshaller(getServiceModel().getMetadata(), operation));
shapeModel.setEndpointDiscovery(operation.getEndpointDiscovery());

return shapeModel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ public Map<String, OperationModel> constructOperations() {
operationModel.setDocumentation(op.getDocumentation());
operationModel.setIsAuthenticated(isAuthenticated(op));
operationModel.setPaginated(isPaginated(op));
operationModel.setEndpointOperation(op.isEndpointOperation());
operationModel.setEndpointDiscovery(op.getEndpointDiscovery());
operationModel.setEndpointTrait(op.getEndpoint());

Input input = op.getInput();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ private MemberModel generateMemberModel(String c2jMemberName, Member c2jMemberDe
memberModel.setIdempotencyToken(c2jMemberDefinition.isIdempotencyToken());
memberModel.setEventPayload(c2jMemberDefinition.isEventPayload());
memberModel.setEventHeader(c2jMemberDefinition.isEventHeader());
memberModel.setEndpointDiscoveryId(c2jMemberDefinition.isEndpointDiscoveryId());

// Pass the xmlNameSpace from the member reference
if (c2jMemberDefinition.getXmlNamespace() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ public IntermediateModel build() {
operations.putAll(new AddOperations(this).constructOperations());
authorizers.putAll(new AddCustomAuthorizers(this.service, getNamingStrategy()).constructAuthorizers());

OperationModel endpointOperation = null;

for (OperationModel o : operations.values()) {
if (o.isEndpointOperation()) {
endpointOperation = o;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: we can break after finding the operation.

break;
}
}

for (IntermediateModelShapeProcessor processor : shapeProcessors) {
shapes.putAll(processor.process(Collections.unmodifiableMap(operations),
Collections.unmodifiableMap(shapes)));
Expand All @@ -119,7 +128,7 @@ public IntermediateModel build() {

IntermediateModel fullModel = new IntermediateModel(
constructMetadata(service, customConfig), operations, shapes,
customConfig, examples, authorizers, paginators.getPaginators(), namingStrategy);
customConfig, examples, endpointOperation, authorizers, paginators.getPaginators(), namingStrategy);

customization.postprocess(fullModel);

Expand All @@ -136,6 +145,7 @@ public IntermediateModel build() {
trimmedShapes,
fullModel.getCustomizationConfig(),
fullModel.getExamples(),
endpointOperation,
fullModel.getCustomAuthorizers(),
fullModel.getPaginators(),
namingStrategy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
package software.amazon.awssdk.codegen.emitters.tasks;

import java.io.IOException;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import software.amazon.awssdk.codegen.emitters.GeneratorTask;
import software.amazon.awssdk.codegen.emitters.GeneratorTaskParams;
import software.amazon.awssdk.codegen.poet.builder.AsyncClientBuilderClass;
import software.amazon.awssdk.codegen.poet.builder.AsyncClientBuilderInterface;
import software.amazon.awssdk.codegen.poet.client.AsyncClientClass;
import software.amazon.awssdk.codegen.poet.client.AsyncClientInterface;
import software.amazon.awssdk.codegen.poet.endpointdiscovery.EndpointDiscoveryAsyncCacheLoaderGenerator;

public class AsyncClientGeneratorTasks extends BaseGeneratorTasks {

Expand All @@ -37,10 +38,16 @@ public AsyncClientGeneratorTasks(GeneratorTaskParams dependencies) {
@Override
protected List<GeneratorTask> createTasks() throws Exception {
info("Emitting Async client classes");
return Arrays.asList(createClientClassTask(),
createClientBuilderTask(),
createClientBuilderInterfaceTask(),
createClientInterfaceTask());
List<GeneratorTask> generatorTasks = new ArrayList<>();
generatorTasks.add(createClientClassTask());
generatorTasks.add(createClientBuilderTask());
generatorTasks.add(createClientBuilderInterfaceTask());
generatorTasks.add(createClientInterfaceTask());
if (model.getEndpointOperation().isPresent()) {
generatorTasks.add(createEndpointDiscoveryCacheLoaderTask());
}

return generatorTasks;
}

private GeneratorTask createClientClassTask() throws IOException {
Expand All @@ -58,4 +65,8 @@ private GeneratorTask createClientBuilderInterfaceTask() throws IOException {
private GeneratorTask createClientInterfaceTask() throws IOException {
return createPoetGeneratorTask(new AsyncClientInterface(model));
}

private GeneratorTask createEndpointDiscoveryCacheLoaderTask() throws IOException {
return createPoetGeneratorTask(new EndpointDiscoveryAsyncCacheLoaderGenerator(generatorTaskParams));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import software.amazon.awssdk.codegen.poet.client.ClientSimpleMethodsIntegrationTests;
import software.amazon.awssdk.codegen.poet.client.SyncClientClass;
import software.amazon.awssdk.codegen.poet.client.SyncClientInterface;
import software.amazon.awssdk.codegen.poet.endpointdiscovery.EndpointDiscoveryCacheLoaderGenerator;

public class SyncClientGeneratorTasks extends BaseGeneratorTasks {
private final GeneratorTaskParams generatorTaskParams;
Expand All @@ -50,6 +51,9 @@ protected List<GeneratorTask> createTasks() throws Exception {
if (!model.simpleMethodsRequiringTesting().isEmpty()) {
tasks.add(createClientSimpleMethodsTest());
}
if (model.getEndpointOperation().isPresent()) {
tasks.add(createEndpointDiscoveryCacheLoaderTask());
}
return tasks;
}

Expand All @@ -72,4 +76,8 @@ private GeneratorTask createClientBuilderInterfaceTask() throws IOException {
private GeneratorTask createClientSimpleMethodsTest() throws IOException {
return createPoetGeneratorTestTask(new ClientSimpleMethodsIntegrationTests(model));
}

private GeneratorTask createEndpointDiscoveryCacheLoaderTask() throws IOException {
return createPoetGeneratorTask(new EndpointDiscoveryCacheLoaderGenerator(generatorTaskParams));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2010-2018 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.intermediate;

public class EndpointDiscovery {

private boolean required;

public boolean isRequired() {
return required;
}

public void setRequired(boolean required) {
this.required = required;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import software.amazon.awssdk.awscore.AwsResponse;
import software.amazon.awssdk.awscore.AwsResponseMetadata;
Expand Down Expand Up @@ -54,6 +55,9 @@ public final class IntermediateModel {

private final Map<String, AuthorizerModel> customAuthorizers;

@JsonIgnore
private final Optional<OperationModel> endpointOperation;

@JsonIgnore
private final Map<String, PaginatorDefinition> paginators;

Expand All @@ -68,7 +72,8 @@ public IntermediateModel(
@JsonProperty("customizationConfig") CustomizationConfig customizationConfig,
@JsonProperty("serviceExamples") ServiceExamples examples) {

this(metadata, operations, shapes, customizationConfig, examples, Collections.emptyMap(), Collections.emptyMap(), null);
this(metadata, operations, shapes, customizationConfig, examples, null,
Collections.emptyMap(), Collections.emptyMap(), null);
}

public IntermediateModel(
Expand All @@ -77,6 +82,7 @@ public IntermediateModel(
Map<String, ShapeModel> shapes,
CustomizationConfig customizationConfig,
ServiceExamples examples,
OperationModel endpointOperation,
Map<String, AuthorizerModel> customAuthorizers,
Map<String, PaginatorDefinition> paginators,
NamingStrategy namingStrategy) {
Expand All @@ -85,6 +91,7 @@ public IntermediateModel(
this.shapes = shapes;
this.customizationConfig = customizationConfig;
this.examples = examples;
this.endpointOperation = Optional.ofNullable(endpointOperation);
this.customAuthorizers = customAuthorizers;
this.paginators = paginators;
this.namingStrategy = namingStrategy;
Expand Down Expand Up @@ -205,6 +212,10 @@ public Map<String, AuthorizerModel> getCustomAuthorizers() {
return customAuthorizers;
}

public Optional<OperationModel> getEndpointOperation() {
return endpointOperation;
}

public boolean hasPaginators() {
return paginators.size() > 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public class MemberModel extends DocumentationModel {

private boolean eventHeader;

private boolean endpointDiscoveryId;

public String getName() {
return name;
}
Expand Down Expand Up @@ -297,6 +299,15 @@ public void setEventHeader(boolean eventHeader) {
this.eventHeader = eventHeader;
}


public boolean isEndpointDiscoveryId() {
return endpointDiscoveryId;
}

public void setEndpointDiscoveryId(boolean endpointDiscoveryId) {
this.endpointDiscoveryId = endpointDiscoveryId;
}

public ListModel getListModel() {
return listModel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public class OperationModel extends DocumentationModel {

private boolean isPaginated;

private boolean endpointOperation;

private EndpointDiscovery endpointDiscovery;

@JsonIgnore
private ShapeModel inputShape;

Expand Down Expand Up @@ -184,6 +188,14 @@ public boolean isStreaming() {
return hasStreamingInput() || hasStreamingOutput();
}

public boolean isEndpointOperation() {
return endpointOperation;
}

public void setEndpointOperation(boolean endpointOperation) {
this.endpointOperation = endpointOperation;
}

public boolean isPaginated() {
return isPaginated;
}
Expand All @@ -192,6 +204,14 @@ public void setPaginated(boolean paginated) {
isPaginated = paginated;
}

public EndpointDiscovery getEndpointDiscovery() {
return endpointDiscovery;
}

public void setEndpointDiscovery(EndpointDiscovery endpointDiscovery) {
this.endpointDiscovery = endpointDiscovery;
}

/**
* Returns the endpoint trait that will be used to resolve the endpoint of an API.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class ShapeModel extends DocumentationModel implements HasDeprecation {
private boolean wrapper;
private boolean simpleMethod;
private String requestSignerClassFqcn;
private EndpointDiscovery endpointDiscovery;

private List<MemberModel> members;
private List<EnumModel> enums;
Expand Down Expand Up @@ -510,6 +511,14 @@ public void setRequestSignerClassFqcn(String authorizerClass) {
this.requestSignerClassFqcn = authorizerClass;
}

public EndpointDiscovery getEndpointDiscovery() {
return endpointDiscovery;
}

public void setEndpointDiscovery(EndpointDiscovery endpointDiscovery) {
this.endpointDiscovery = endpointDiscovery;
}

/**
* @return True if the shape is an 'eventstream' shape. The eventstream shape is the tagged union like
* container that holds individual 'events'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public class Member {
@JsonProperty(value = "eventheader")
private boolean eventHeader;

@JsonProperty(value = "endpointdiscoveryid")
private boolean endpointDiscoveryId;

public String getShape() {
return shape;
}
Expand Down Expand Up @@ -171,4 +174,12 @@ public boolean isEventHeader() {
public void setEventHeader(boolean eventHeader) {
this.eventHeader = eventHeader;
}

public boolean isEndpointDiscoveryId() {
return endpointDiscoveryId;
}

public void setEndpointDiscoveryId(boolean endpointDiscoveryId) {
this.endpointDiscoveryId = endpointDiscoveryId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
import software.amazon.awssdk.codegen.model.intermediate.EndpointDiscovery;

public class Operation {

Expand All @@ -38,6 +39,12 @@ public class Operation {

private boolean requiresApiKey;

@JsonProperty("endpointdiscovery")
private EndpointDiscovery endpointDiscovery;

@JsonProperty("endpointoperation")
private boolean endpointOperation;

private EndpointTrait endpoint;

@JsonProperty("authtype")
Expand Down Expand Up @@ -138,6 +145,22 @@ public void setRequiresApiKey(boolean requiresApiKey) {
this.requiresApiKey = requiresApiKey;
}

public EndpointDiscovery getEndpointDiscovery() {
return endpointDiscovery;
}

public void setEndpointDiscovery(EndpointDiscovery endpointDiscovery) {
this.endpointDiscovery = endpointDiscovery;
}

public boolean isEndpointOperation() {
return endpointOperation;
}

public void setEndpointOperation(boolean endpointOperation) {
this.endpointOperation = endpointOperation;
}

public EndpointTrait getEndpoint() {
return endpoint;
}
Expand Down
Loading