Skip to content

Commit

Permalink
KAL-44
Browse files Browse the repository at this point in the history
Break out container and task events into their own classes and update tests.
  • Loading branch information
Slushnas committed Sep 21, 2018
1 parent 5b9f819 commit 876a0ef
Show file tree
Hide file tree
Showing 6 changed files with 269 additions and 84 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Collections.Generic;

namespace Amazon.Lambda.CloudWatchEvents.ECSEvents
{
/// <summary>
/// An object representing a container instance or task attachment.
/// https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_Attachment.html
/// </summary>
public class Attachment
{
/// <summary>
/// Details of the attachment. For elastic network interfaces, this includes the
/// network interface ID, the MAC address, the subnet ID, and the private IPv4 address.
/// </summary>
public List<KeyValuePair<string, string>> Details { get; set; }

/// <summary>
/// The unique identifier for the attachment.
/// </summary>
public string Id { get; set; }

/// <summary>
/// The status of the attachment. Valid values are PRECREATED, CREATED, ATTACHING,
/// ATTACHED, DETACHING, DETACHED, and DELETED.
/// </summary>
public string Status { get; set; }

/// <summary>
/// The type of the attachment, such as ElasticNetworkInterface.
/// </summary>
public string Type { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Amazon.Lambda.CloudWatchEvents.ECSEvents
{
using System;
using System.Collections.Generic;

/// <summary>
/// ECS event detail
/// https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs_cwe_events.html#ecs_container_instance_events
/// https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs_cwe_events.html#ecs_task_events
/// An EC2 instance that is running the Amazon ECS agent and has been registered with a cluster.
/// https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerInstance.html
/// https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_Task.html
/// </summary>
public class Detail
public class ContainerInstance
{
/// <summary>
/// This parameter returns true if the agent is connected to Amazon ECS.
Expand All @@ -24,15 +17,20 @@ public class Detail
public bool AgentConnected { get; set; }

/// <summary>
/// The attributes set for the container instance, either by the Amazon ECS container agent at instance
/// registration or manually with the PutAttributes operation.
/// The status of the most recent agent update. If an update has never been requested, this value is NULL.
/// </summary>
public List<Attribute> Attributes { get; set; }
public string AgentUpdateStatus { get; set; }

/// <summary>
/// The Amazon Resource Name (ARN) of the cluster that hosts the service.
/// The elastic network interfaces associated with the container instance.
/// </summary>
public string ClusterArn { get; set; }
public List<Attachment> Attachments { get; set; }

/// <summary>
/// The attributes set for the container instance, either by the Amazon ECS container agent at instance
/// registration or manually with the PutAttributes operation.
/// </summary>
public List<Attribute> Attributes { get; set; }

/// <summary>
/// The Amazon Resource Name (ARN) of the container instance.
Expand All @@ -43,14 +41,19 @@ public class Detail
public string ContainerInstanceArn { get; set; }

/// <summary>
/// List of Docker container that is part of a task.
/// The EC2 instance ID of the container instance.
/// </summary>
public string Ec2InstanceId { get; set; }

/// <summary>
/// The number of tasks on the container instance that are in the PENDING status.
/// </summary>
public List<Container> Containers { get; set; }
public int PendingTasksCount { get; set; }

/// <summary>
/// The EC2 instance ID of the container instance.
/// The Unix time stamp for when the container instance was registered.
/// </summary>
public string Ec2InstanceId { get; set; }
public DateTime RegisteredAt { get; set; }

/// <summary>
/// For CPU and memory resource types, this parameter describes the amount of each resource that was available
Expand All @@ -71,6 +74,11 @@ public class Detail
/// </summary>
public List<Resource> RemainingResources { get; set; }

/// <summary>
/// The number of tasks on the container instance that are in the RUNNING status.
/// </summary>
public int RunningTasksCount { get; set; }

/// <summary>
/// The status of the container instance.
/// The valid values are ACTIVE, INACTIVE, or DRAINING. ACTIVE indicates that the container instance
Expand All @@ -81,73 +89,31 @@ public class Detail
public string Status { get; set; }

/// <summary>
/// The version counter for the container instance or task.
/// Every time a container instance/task experiences a change that triggers a CloudWatch event,
/// the version counter is incremented. If you are replicating your Amazon ECS
/// container instance/task state with CloudWatch Events, you can compare the version of
/// a container instance/task reported by the Amazon ECS APIs with the version reported in
/// CloudWatch Events for the container instance/task (inside the detail object) to
/// verify that the version in your event stream is current.
/// The version counter for the container instance.
/// Every time a container instance experiences a change that triggers a CloudWatch event,
/// the version counter is incremented. If you are replicating your Amazon ECS container instance
/// state with CloudWatch Events, you can compare the version of a container instance reported by
/// the Amazon ECS APIs with the version reported in CloudWatch Events for the container instance
/// (inside the detail object) to verify that the version in your event stream is current.
/// </summary>
public int Version { get; set; }
public long Version { get; set; }

/// <summary>
/// The version information for the Amazon ECS container agent and Docker daemon running on the container instance.
/// </summary>
public VersionInfo VersionInfo { get; set; }

/// <summary>
/// The Unix time stamp for when the service was last updated.
/// </summary>
public DateTime UpdatedAt { get; set; }
// NOTE: The following properties are not present in the ContainerInstance object documentation but have
// been added here for convenience.

/// <summary>
/// The Unix time stamp for when the task was created (the task entered the PENDING state).
/// </summary>
public DateTime CreatedAt { get; set; }

/// <summary>
/// The desired status of the task. For more information,
/// see Task Lifecycle: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_life_cycle.html.
/// </summary>
public string DesiredStatus { get; set; }

/// <summary>
/// The name of the task group associated with the task.
/// </summary>
public string Group { get; set; }

/// <summary>
/// The last known status of the task. For more information,
/// see Task Lifecycle: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_life_cycle.html.
/// </summary>
public string LastStatus { get; set; }

/// <summary>
/// One or more container overrides.
/// </summary>
public TaskOverride Overrides { get; set; }

/// <summary>
/// The Unix time stamp for when the task started (the task
/// transitioned from the PENDING state to the RUNNING state).
/// </summary>
public DateTime StartedAt { get; set; }

/// <summary>
/// The tag specified when a task is started. If the task is started by an Amazon ECS service,
/// then the startedBy parameter contains the deployment ID of the service that starts it.
/// </summary>
public string StartedBy { get; set; }

/// <summary>
/// The Amazon Resource Name (ARN) of the task.
/// The Amazon Resource Name (ARN) of the cluster that hosts the service.
/// </summary>
public string TaskArn { get; set; }
public string ClusterArn { get; set; }

/// <summary>
/// The ARN of the task definition that creates the task.
/// The Unix time stamp for when the service was last updated.
/// </summary>
public string TaskDefinitionArn { get; set; }
public DateTime UpdatedAt { get; set; }
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CloudWatchEvents;
using System;
using CloudWatchEvents;

namespace Amazon.Lambda.CloudWatchEvents.ECSEvents
{
Expand All @@ -9,7 +10,7 @@ namespace Amazon.Lambda.CloudWatchEvents.ECSEvents
/// http://docs.aws.amazon.com/config/latest/developerguide/evaluate-config_develop-rules_example-events.html
/// https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs_cwe_events.html
/// </summary>
public class ECSEvent : CloudWatchEvent<Detail>
public class ECSContainerInstanceStateChangeEvent : CloudWatchEvent<ContainerInstance>
{

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using CloudWatchEvents;

namespace Amazon.Lambda.CloudWatchEvents.ECSEvents
{
/// <summary>
/// /// AWS ECS task state change event
/// http://docs.aws.amazon.com/config/latest/developerguide/evaluate-config_develop-rules.html
/// http://docs.aws.amazon.com/config/latest/developerguide/evaluate-config_develop-rules_example-events.html
/// https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs_cwe_events.html
/// </summary>
public class ECSTaskStateChangeEvent : CloudWatchEvent<Task>
{

}
}
Loading

0 comments on commit 876a0ef

Please sign in to comment.