Skip to content
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

Adds waiter support to smithy-go #237

Merged
merged 23 commits into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
152e733
draft for waiter support
skotambkar Dec 1, 2020
5a80be1
fix dep import, codegen and code styling issues
skotambkar Dec 1, 2020
30a4e83
additional waiter changes and fixes to support mutliple acceptors
skotambkar Dec 1, 2020
1ba08af
update waiter util to export utils and remove hand-written waiter mid…
skotambkar Dec 2, 2020
81faf82
update codegen to generate waiter specific middleware
skotambkar Dec 2, 2020
e18ca4f
simplify waiter state mutator and fix issue with multi acceptor waiters
skotambkar Dec 2, 2020
53751d0
more model driven testing, and fine-tuning waiters for different comp…
skotambkar Dec 2, 2020
ecdac4f
make comparators case sensitive, update unmodeled error handling and …
skotambkar Dec 2, 2020
96d63bb
move sleep with context method to smithy time package
skotambkar Dec 3, 2020
3adc0fc
feedback and change of design
skotambkar Dec 3, 2020
cc1c95c
update compute delay waiter util
skotambkar Dec 3, 2020
06ecf6c
minor fix
skotambkar Dec 3, 2020
48917fb
update waiter util, naming and add tests
skotambkar Dec 3, 2020
865d004
feedback around naming of java class and go package
skotambkar Dec 4, 2020
6f95047
updates jitter and delay computation for waiter
skotambkar Dec 5, 2020
0ff9d3f
update to use change delay computation function
skotambkar Dec 5, 2020
c4c9a5d
fix operation interface generator for incorrect exceptions
skotambkar Dec 5, 2020
b8cdbaa
update waiter compute delay util and adds waiter logger middleware
skotambkar Dec 8, 2020
3806a96
update java code as per feedback
skotambkar Dec 8, 2020
23a9719
use paginationIndex for paginator interface generation
skotambkar Dec 9, 2020
6cc9c96
doc update
skotambkar Dec 9, 2020
2bbbd84
feedback around remainingTime computation
skotambkar Dec 9, 2020
1d741e4
update waiter call workflow
skotambkar Dec 9, 2020
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
73 changes: 73 additions & 0 deletions codegen/smithy-go-codegen-test/model/main.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace example.weather

use smithy.test#httpRequestTests
use smithy.test#httpResponseTests
use smithy.waiters#waitable

/// Provides weather forecasts.
@fakeProtocol
Expand Down Expand Up @@ -36,6 +37,49 @@ resource CityImage {
string CityId

@readonly
@waitable(
CityExists: {
description: "Waits until a city has been created",
acceptors: [
// Fail-fast if the thing transitions to a "failed" state.
{
state: "failure",
matcher: {
errorType: "NoSuchResource"
}
},
// Succeed when the city image value is not empty i.e. enters into a "success" state.
{
state: "success",
matcher: {
success: true
}
},
// Retry if city id input is of same length as city name in output
{
state: "retry",
matcher: {
inputOutput: {
path: "length(input.cityId) == length(output.name)",
comparator: "booleanEquals",
expected: "true",
}
}
},
// Success if city name in output is seattle
{
state: "success",
matcher: {
output: {
path: "name",
comparator: "stringEquals",
expected: "seattle",
}
}
}
]
}
)
@http(method: "GET", uri: "/cities/{cityId}")
operation GetCity {
input: GetCityInput,
Expand Down Expand Up @@ -178,6 +222,35 @@ apply NoSuchResource @httpResponseTests([
// return truncated results.
@readonly
@paginated(items: "items")
@waitable(
"ListContainsCity": {
skotambkar marked this conversation as resolved.
Show resolved Hide resolved
description: "Wait until ListCities operation response matches a given state",
acceptors: [
// failure in case all items returned match to seattle
{
state: "failure",
matcher: {
output: {
path: "items",
comparator: "allStringEquals",
expected: "seattle",
}
}
},
// success in case any items returned match to NewYork
{
state: "success",
matcher: {
output: {
path: "items",
comparator: "anyStringEquals",
expected: "NewYork",
}
}
}
]
}
)
@http(method: "GET", uri: "/cities")
operation ListCities {
input: ListCitiesInput,
Expand Down
1 change: 1 addition & 0 deletions codegen/smithy-go-codegen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ extra["moduleName"] = "software.amazon.smithy.go.codegen"

dependencies {
api("software.amazon.smithy:smithy-codegen-core:[1.3.0,2.0.0[")
implementation("software.amazon.smithy:smithy-waiters:[1.4.0,2.0.0[")
compile("com.atlassian.commonmark:commonmark:0.15.2")
api("org.jsoup:jsoup:1.13.1")
implementation("software.amazon.smithy:smithy-protocol-test-traits:[1.3.0,2.0.0[")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,23 @@ public static GoStackStepMiddlewareGenerator createDeserializeStepMiddleware(Str
.build());
}

/**
* Create a new Finalize step middleware generator with the provided type name.
*
* @param name is the type name to identify the middleware.
* @param id the unique ID for the middleware.
* @return the middleware generator.
*/
public static GoStackStepMiddlewareGenerator createFinalizeStepMiddleware(String name, MiddlewareIdentifier id) {
return createMiddleware(name,
id,
"HandleFinalize",
SymbolUtils.createValueSymbolBuilder("FinalizeInput", SmithyGoDependency.SMITHY_MIDDLEWARE).build(),
SymbolUtils.createValueSymbolBuilder("FinalizeOutput", SmithyGoDependency.SMITHY_MIDDLEWARE).build(),
SymbolUtils.createValueSymbolBuilder("FinalizeHandler", SmithyGoDependency.SMITHY_MIDDLEWARE)
.build());
}

/**
* Generates a new step middleware generator.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,16 @@ public final class SmithyGoDependency {
public static final GoDependency SMITHY_RAND = smithy("rand", "smithyrand");
public static final GoDependency SMITHY_TESTING = smithy("testing", "smithytesting");
public static final GoDependency SMITHY_XML = smithy("xml", "smithyxml");
public static final GoDependency SMITHY_WAITERS = smithy("waiters", "smithywaiters");

public static final GoDependency GO_CMP = goCmp("cmp");
public static final GoDependency GO_CMP_OPTIONS = goCmp("cmp/cmpopts");

public static final GoDependency GO_JMESPATH = goJmespath(null);
skotambkar marked this conversation as resolved.
Show resolved Hide resolved

private static final String SMITHY_SOURCE_PATH = "github.com/awslabs/smithy-go";
private static final String GO_CMP_SOURCE_PATH = "github.com/google/go-cmp";
private static final String GO_JMESPATH_SOURCE_PATH = "github.com/jmespath/go-jmespath";

private SmithyGoDependency() {
}
Expand Down Expand Up @@ -94,6 +98,10 @@ private static GoDependency goCmp(String relativePath) {
return relativePackage(GO_CMP_SOURCE_PATH, relativePath, Versions.GO_CMP, null);
}

private static GoDependency goJmespath(String relativePath) {
return relativePackage(GO_JMESPATH_SOURCE_PATH, relativePath, Versions.GO_JMESPATH, null);
}

private static GoDependency relativePackage(
String moduleImportPath,
String relativePath,
Expand All @@ -110,6 +118,7 @@ private static GoDependency relativePackage(
private static final class Versions {
private static final String GO_STDLIB = "1.15";
private static final String GO_CMP = "v0.5.4";
private static final String SMITHY_GO = "v0.4.0";
private static final String SMITHY_GO = "v0.4.1-0.20201202055352-1ba08af0096d";
private static final String GO_JMESPATH = "v0.4.0";
}
}
Loading