-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
feat(appmesh): change VirtualRouter's Listener to a union-like class #11277
Changes from 3 commits
c0aed38
53d5122
0ee787c
ed0474e
6ac1fe9
526035f
c50357c
507f625
060a86d
c170649
b299390
cc00cb4
4aede95
ddbdc9d
41a525e
1121c44
004e4bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import * as cdk from '@aws-cdk/core'; | ||
import { CfnVirtualRouter } from './appmesh.generated'; | ||
import { Protocol } from './shared-interfaces'; | ||
|
||
/** | ||
* Represents the properties needed to define Listeners for a VirtualRouter | ||
*/ | ||
export interface RouterListenerProps { | ||
/** | ||
* Port to listen for connections on | ||
* | ||
* @default - 8080 | ||
*/ | ||
readonly port?: number | ||
} | ||
|
||
/** | ||
* Properties for a VirtualRouter listener | ||
*/ | ||
export interface VirtualRouterListenerConfig { | ||
/** | ||
* Single listener config for a VirtualRouter | ||
*/ | ||
readonly listener: CfnVirtualRouter.VirtualRouterListenerProperty; | ||
} | ||
|
||
/** | ||
* Represents the properties needed to define listeners for a VirtualRouter | ||
*/ | ||
export abstract class VirtualRouterListener { | ||
/** | ||
* Returns an HTTP Listener for a VirtualRouter | ||
*/ | ||
public static httpVirtualRouterListener(props: RouterListenerProps = {}): VirtualRouterListener { | ||
dfezzie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return new HttpVirtualRouterListener(props); | ||
} | ||
|
||
/** | ||
* Returns an HTTP2 Listener for a VirtualRouter | ||
*/ | ||
public static http2GatewayListener(props: RouterListenerProps = {}): VirtualRouterListener { | ||
return new Http2VirtualRouterListener(props); | ||
} | ||
|
||
/** | ||
* Returns a GRPC Listener for a VirtualRouter | ||
*/ | ||
public static grpcGatewayListener(props: RouterListenerProps = {}): VirtualRouterListener { | ||
return new GrpcVirtualRouterListener(props); | ||
} | ||
|
||
/** | ||
* Returns a TCP Listener for a VirtualRouter | ||
*/ | ||
public static tcpGatewayListener(props: RouterListenerProps = {}): VirtualRouterListener { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any chance any of these will have protocol-specific properties later? Because frankly, in its current form, I don't think this abstraction is buying us anything... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Virtual Routers specifically do not currently have any protocol specific properties. The main reason I think we should do this change is for consistency. If we have listeners on Virtual Nodes and Virtual Gateways, having listeners for your virtual routers that are defined in a different way seems like poor UX. If you don't think it is worth the change, we can scrap this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consistency is not a bad argument. How about this. Let's make Thoughts on this idea? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good to me. Simpler for sure. Made the update |
||
return new TcpVirtualRouterListener(props); | ||
} | ||
|
||
/** | ||
* Protocol the listener implements | ||
*/ | ||
protected abstract protocol: Protocol; | ||
|
||
/** | ||
* Port to listen for connections on | ||
*/ | ||
protected abstract port: number; | ||
|
||
/** | ||
* Called when the VirtualRouterListener type is initialized. Can be used to enforce | ||
* mutual exclusivity | ||
*/ | ||
public abstract bind(scope: cdk.Construct): VirtualRouterListenerConfig; | ||
} | ||
|
||
class HttpVirtualRouterListener extends VirtualRouterListener { | ||
/** | ||
* Protocol the listener implements | ||
*/ | ||
protected protocol: Protocol = Protocol.HTTP; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you instead make the base class abstract with a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, we can further simplify this by only having one subclass for all 4 protocols. |
||
/** | ||
* Port to listen for connections on | ||
*/ | ||
protected port: number; | ||
dfezzie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
constructor(props: RouterListenerProps = {}) { | ||
super(); | ||
this.port = props.port ? props.port : 8080; | ||
} | ||
|
||
bind(_scope: cdk.Construct): VirtualRouterListenerConfig { | ||
return { | ||
listener: { | ||
portMapping: { | ||
port: this.port, | ||
protocol: this.protocol, | ||
}, | ||
}, | ||
}; | ||
} | ||
} | ||
|
||
class Http2VirtualRouterListener extends HttpVirtualRouterListener { | ||
constructor(props: RouterListenerProps = {}) { | ||
super(props); | ||
this.protocol = Protocol.HTTP2; | ||
} | ||
} | ||
|
||
class GrpcVirtualRouterListener extends HttpVirtualRouterListener { | ||
constructor(props: RouterListenerProps = {}) { | ||
super(props); | ||
this.protocol = Protocol.GRPC; | ||
} | ||
} | ||
|
||
class TcpVirtualRouterListener extends HttpVirtualRouterListener { | ||
constructor(props: RouterListenerProps = {}) { | ||
super(props); | ||
this.protocol = Protocol.TCP; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be
*Options
, soRouterListenerOptions
.*Props
are reserved for construction properties of Constructs. Apologies I did not notice this before (we'll probably have to go back and change a few of these in other places in the AppMesh module).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem. Should updating other places be done in this in this PR or separate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep it separate.