io.github.cdklabs.cdkecsserviceextensions.QueueExtension Maven / Gradle / Ivy
Show all versions of cdk-ecs-service-extensions Show documentation
package io.github.cdklabs.cdkecsserviceextensions;
/**
* (experimental) This extension creates a default eventsQueue
for the service (if not provided) and accepts a list of objects of type ISubscribable
that the eventsQueue
subscribes to.
*
* It creates the subscriptions and sets up permissions
* for the service to consume messages from the SQS Queues.
*
* It also configures a target tracking scaling policy for the service to maintain an acceptable queue latency by tracking
* the backlog per task. For more information, please refer: https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-using-sqs-queue.html .
*
* The default queue for this service can be accessed using the getter <extension>.eventsQueue
.
*/
@javax.annotation.Generated(value = "jsii-pacmak/1.103.1 (build bef2dea)", date = "2024-09-27T00:29:46.247Z")
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
@software.amazon.jsii.Jsii(module = io.github.cdklabs.cdkecsserviceextensions.$Module.class, fqn = "@aws-cdk-containers/ecs-service-extensions.QueueExtension")
public class QueueExtension extends io.github.cdklabs.cdkecsserviceextensions.ServiceExtension {
protected QueueExtension(final software.amazon.jsii.JsiiObjectRef objRef) {
super(objRef);
}
protected QueueExtension(final software.amazon.jsii.JsiiObject.InitializationMode initializationMode) {
super(initializationMode);
}
/**
* @param props
*/
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
public QueueExtension(final @org.jetbrains.annotations.Nullable io.github.cdklabs.cdkecsserviceextensions.QueueExtensionProps props) {
super(software.amazon.jsii.JsiiObject.InitializationMode.JSII);
software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this, new Object[] { props });
}
/**
*/
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
public QueueExtension() {
super(software.amazon.jsii.JsiiObject.InitializationMode.JSII);
software.amazon.jsii.JsiiEngine.getInstance().createNewObject(this);
}
/**
* (experimental) Add hooks to the main application extension so that it is modified to add the events queue URL to the container environment.
*/
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
@Override
public void addHooks() {
software.amazon.jsii.Kernel.call(this, "addHooks", software.amazon.jsii.NativeType.VOID);
}
/**
* (experimental) This hook creates (if required) and sets the default queue eventsQueue
.
*
* It also sets up the subscriptions for
* the provided ISubscribable
objects.
*
* @param service The parent service which this extension has been added to. This parameter is required.
* @param scope The scope that this extension should create resources in. This parameter is required.
*/
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
@Override
public void prehook(final @org.jetbrains.annotations.NotNull io.github.cdklabs.cdkecsserviceextensions.Service service, final @org.jetbrains.annotations.NotNull software.constructs.Construct scope) {
software.amazon.jsii.Kernel.call(this, "prehook", software.amazon.jsii.NativeType.VOID, new Object[] { java.util.Objects.requireNonNull(service, "service is required"), java.util.Objects.requireNonNull(scope, "scope is required") });
}
/**
* (experimental) When this hook is implemented by extension, it allows the extension to use the service which has been created.
*
* It is used to add target tracking
* scaling policies for the SQS Queues of the service. It also creates an AWS Lambda
* Function for calculating the backlog per task metric.
*
* @param service
- The generated service.
This parameter is required.
*/
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
@Override
public void useService(final @org.jetbrains.annotations.NotNull java.lang.Object service) {
if (software.amazon.jsii.Configuration.getRuntimeTypeChecking()) {
if (
!(service instanceof software.amazon.awscdk.services.ecs.Ec2Service)
&& !(service instanceof software.amazon.awscdk.services.ecs.FargateService)
) {
throw new IllegalArgumentException(
new java.lang.StringBuilder("Expected ")
.append("service")
.append(" to be one of: software.amazon.awscdk.services.ecs.Ec2Service, software.amazon.awscdk.services.ecs.FargateService; received ")
.append(service.getClass()).toString());
}
}
software.amazon.jsii.Kernel.call(this, "useService", software.amazon.jsii.NativeType.VOID, new Object[] { java.util.Objects.requireNonNull(service, "service is required") });
}
/**
* (experimental) After the task definition has been created, this hook grants SQS permissions to the task role.
*
* @param taskDefinition The created task definition. This parameter is required.
*/
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
@Override
public void useTaskDefinition(final @org.jetbrains.annotations.NotNull software.amazon.awscdk.services.ecs.TaskDefinition taskDefinition) {
software.amazon.jsii.Kernel.call(this, "useTaskDefinition", software.amazon.jsii.NativeType.VOID, new Object[] { java.util.Objects.requireNonNull(taskDefinition, "taskDefinition is required") });
}
/**
*/
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
public @org.jetbrains.annotations.NotNull software.amazon.awscdk.services.sqs.IQueue getEventsQueue() {
return software.amazon.jsii.Kernel.get(this, "eventsQueue", software.amazon.jsii.NativeType.forClass(software.amazon.awscdk.services.sqs.IQueue.class));
}
/**
*/
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
public @org.jetbrains.annotations.Nullable io.github.cdklabs.cdkecsserviceextensions.QueueAutoScalingOptions getAutoscalingOptions() {
return software.amazon.jsii.Kernel.get(this, "autoscalingOptions", software.amazon.jsii.NativeType.forClass(io.github.cdklabs.cdkecsserviceextensions.QueueAutoScalingOptions.class));
}
/**
* (experimental) The log group created by the extension where the AWS Lambda function logs are stored.
*/
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
public @org.jetbrains.annotations.Nullable software.amazon.awscdk.services.logs.ILogGroup getLogGroup() {
return software.amazon.jsii.Kernel.get(this, "logGroup", software.amazon.jsii.NativeType.forClass(software.amazon.awscdk.services.logs.ILogGroup.class));
}
/**
* (experimental) The log group created by the extension where the AWS Lambda function logs are stored.
*/
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
public void setLogGroup(final @org.jetbrains.annotations.Nullable software.amazon.awscdk.services.logs.ILogGroup value) {
software.amazon.jsii.Kernel.set(this, "logGroup", value);
}
/**
* (experimental) A fluent builder for {@link io.github.cdklabs.cdkecsserviceextensions.QueueExtension}.
*/
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
public static final class Builder implements software.amazon.jsii.Builder {
/**
* @return a new instance of {@link Builder}.
*/
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
public static Builder create() {
return new Builder();
}
private io.github.cdklabs.cdkecsserviceextensions.QueueExtensionProps.Builder props;
private Builder() {
}
/**
* (experimental) The user-provided default queue for this service.
*
* If the eventsQueue
is not provided, a default SQS Queue is created for the service.
*
* Default: none
*
* @return {@code this}
* @param eventsQueue The user-provided default queue for this service. This parameter is required.
*/
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
public Builder eventsQueue(final software.amazon.awscdk.services.sqs.IQueue eventsQueue) {
this.props().eventsQueue(eventsQueue);
return this;
}
/**
* (experimental) The user-provided queue delay fields to configure auto scaling for the default queue.
*
* Default: none
*
* @return {@code this}
* @param scaleOnLatency The user-provided queue delay fields to configure auto scaling for the default queue. This parameter is required.
*/
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
public Builder scaleOnLatency(final io.github.cdklabs.cdkecsserviceextensions.QueueAutoScalingOptions scaleOnLatency) {
this.props().scaleOnLatency(scaleOnLatency);
return this;
}
/**
* (experimental) The list of subscriptions for this service.
*
* Default: none
*
* @return {@code this}
* @param subscriptions The list of subscriptions for this service. This parameter is required.
*/
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
public Builder subscriptions(final java.util.List extends io.github.cdklabs.cdkecsserviceextensions.ISubscribable> subscriptions) {
this.props().subscriptions(subscriptions);
return this;
}
/**
* @return a newly built instance of {@link io.github.cdklabs.cdkecsserviceextensions.QueueExtension}.
*/
@software.amazon.jsii.Stability(software.amazon.jsii.Stability.Level.Experimental)
@Override
public io.github.cdklabs.cdkecsserviceextensions.QueueExtension build() {
return new io.github.cdklabs.cdkecsserviceextensions.QueueExtension(
this.props != null ? this.props.build() : null
);
}
private io.github.cdklabs.cdkecsserviceextensions.QueueExtensionProps.Builder props() {
if (this.props == null) {
this.props = new io.github.cdklabs.cdkecsserviceextensions.QueueExtensionProps.Builder();
}
return this.props;
}
}
}