Skip to content

Commit

Permalink
Add StreamingClassOperatorResponse (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
s-vitaliy authored Apr 5, 2024
1 parent 59c7171 commit d5485c5
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 29 deletions.
22 changes: 22 additions & 0 deletions src/Models/Common/ResourceStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace Arcane.Operator.Models.Common;

/// <summary>
/// Represents stream status badge for Lens app.
/// </summary>
public enum ResourceStatus
{
/// <summary>
/// The stream is in a ready state.
/// </summary>
READY,

/// <summary>
/// The stream is in an error state.
/// </summary>
ERROR,

/// <summary>
/// The stream is in a warning state.
/// </summary>
WARNING
}
38 changes: 9 additions & 29 deletions src/Models/StreamOperatorResponse.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,11 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Arcane.Operator.Models.Common;
using Arcane.Operator.Models.StreamStatuses.StreamStatus.V1Beta1;

namespace Arcane.Operator.Models;

/// <summary>
/// Represents stream status badge for Lens app.
/// </summary>
public enum StreamStatusType
{
/// <summary>
/// The stream is in a ready state.
/// </summary>
READY,

/// <summary>
/// The stream is in an error state.
/// </summary>
ERROR,

/// <summary>
/// The stream is in a warning state.
/// </summary>
WARNING
}

/// <summary>
/// Possible stream states.
/// </summary>
Expand Down Expand Up @@ -114,7 +94,7 @@ public static StreamOperatorResponse Restarting(string nameSpace, string kind, s
Kind = kind,
Conditions = new[]
{
new V1Beta1StreamCondition { Type = StreamStatusType.WARNING.ToString(), Status = "True" }
new V1Beta1StreamCondition { Type = ResourceStatus.WARNING.ToString(), Status = "True" }
},
Phase = StreamPhase.RESTARTING
};
Expand All @@ -135,7 +115,7 @@ public static StreamOperatorResponse Running(string nameSpace, string kind, stri
Namespace = nameSpace,
Conditions = new[]
{
new V1Beta1StreamCondition { Type = StreamStatusType.READY.ToString(), Status = "True" }
new V1Beta1StreamCondition { Type = ResourceStatus.READY.ToString(), Status = "True" }
},
Phase = StreamPhase.RUNNING
};
Expand All @@ -156,7 +136,7 @@ public static StreamOperatorResponse Reloading(string nameSpace, string kind, st
Namespace = nameSpace,
Conditions = new[]
{
new V1Beta1StreamCondition { Type = StreamStatusType.READY.ToString(), Status = "True" }
new V1Beta1StreamCondition { Type = ResourceStatus.READY.ToString(), Status = "True" }
},
Phase = StreamPhase.RELOADING
};
Expand All @@ -177,7 +157,7 @@ public static StreamOperatorResponse Terminating(string nameSpace, string kind,
Kind = kind,
Conditions = new[]
{
new V1Beta1StreamCondition { Type = StreamStatusType.WARNING.ToString(), Status = "True" }
new V1Beta1StreamCondition { Type = ResourceStatus.WARNING.ToString(), Status = "True" }
},
Phase = StreamPhase.TERMINATING
};
Expand All @@ -198,7 +178,7 @@ public static StreamOperatorResponse Stopped(string nameSpace, string kind, stri
Namespace = nameSpace,
Conditions = new[]
{
new V1Beta1StreamCondition { Type = StreamStatusType.WARNING.ToString(), Status = "True" }
new V1Beta1StreamCondition { Type = ResourceStatus.WARNING.ToString(), Status = "True" }
},
Phase = StreamPhase.STOPPED
};
Expand All @@ -222,7 +202,7 @@ public static StreamOperatorResponse OperationFailed(string nameSpace, string ki
Conditions = new[]
{
new V1Beta1StreamCondition
{ Type = StreamStatusType.ERROR.ToString(), Status = "True", Message = message }
{ Type = ResourceStatus.ERROR.ToString(), Status = "True", Message = message }
},
Phase = StreamPhase.FAILED
};
Expand All @@ -244,7 +224,7 @@ public static StreamOperatorResponse Suspended(string nameSpace, string kind, st
Namespace = nameSpace,
Conditions = new[]
{
new V1Beta1StreamCondition { Type = StreamStatusType.WARNING.ToString(), Status = "True" }
new V1Beta1StreamCondition { Type = ResourceStatus.WARNING.ToString(), Status = "True" }
},
Phase = StreamPhase.SUSPENDED
};
Expand All @@ -266,7 +246,7 @@ public static StreamOperatorResponse CrashLoopDetected(string nameSpace, string
Namespace = nameSpace,
Conditions = new[]
{
new V1Beta1StreamCondition { Type = StreamStatusType.ERROR.ToString(), Status = "True" }
new V1Beta1StreamCondition { Type = ResourceStatus.ERROR.ToString(), Status = "True" }
},
Phase = StreamPhase.FAILED
};
Expand Down
128 changes: 128 additions & 0 deletions src/Models/StreamingClassOperatorResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Arcane.Operator.Models.Common;
using Arcane.Operator.Models.StreamStatuses.StreamStatus.V1Beta1;

namespace Arcane.Operator.Models;

/// <summary>
/// Possible stream states.
/// </summary>
public enum StreamClassPhase
{
/// <summary>
/// An initial state of the StreamClass object.
/// </summary>
INITIALIZING,

/// <summary>
/// A ready streaming class is ready to be used and new Streams of this class can be created.
/// </summary>
READY,

/// <summary>
/// An error occured in stream class controller and new Streams of this class can not be created.
/// </summary>
FAILED,

/// <summary>
/// The stream class is stopped and new Streams of this class can not be created.
/// </summary>
STOPPED
}

/// <summary>
/// Contains response from stream operator that can be used by other services inside the application
/// </summary>
[ExcludeFromCodeCoverage(Justification = "Model")]
public record StreamClassOperatorResponse
{
/// <summary>
/// Affected StreamClass identifier
/// </summary>
public string Id { get; private init; }

/// <summary>
/// Affected StreamClass kind
/// </summary>
public string Kind { get; set; }

/// <summary>
/// Affected StreamClass namespace
/// </summary>
public string Namespace { get; set; }

/// <summary>
/// Latest observed state of the StreamClass object
/// </summary>
public IEnumerable<V1Beta1StreamCondition> Conditions { get; private init; }

/// <summary>
/// StreamClass livecycle phase
/// </summary>
public StreamClassPhase Phase { get; private set; }


/// <summary>
/// Creates a StreamOperatorResponse object for stream with specified identifier, setting it state to RUNNING
/// </summary>
/// <param name="nameSpace">Kubernetes namespace</param>
/// <param name="kind">Affected stream class kind</param>
/// <param name="streamClassId">Affected stream class identifier</param>
public static StreamClassOperatorResponse Ready(string nameSpace, string kind, string streamClassId)
{
return new StreamClassOperatorResponse
{
Id = streamClassId,
Kind = kind,
Namespace = nameSpace,
Conditions = new[]
{
new V1Beta1StreamCondition { Type = ResourceStatus.READY.ToString(), Status = "True" }
},
Phase = StreamClassPhase.READY
};
}

/// <summary>
/// Creates a StreamOperatorResponse object for stream with specified identifier, setting it state to RUNNING
/// </summary>
/// <param name="nameSpace">Kubernetes namespace</param>
/// <param name="kind">Affected stream class kind</param>
/// <param name="streamClassId">Affected stream class identifier</param>
public static StreamClassOperatorResponse Failed(string nameSpace, string kind, string streamClassId)
{
return new StreamClassOperatorResponse
{
Id = streamClassId,
Kind = kind,
Namespace = nameSpace,
Conditions = new[]
{
new V1Beta1StreamCondition { Type = ResourceStatus.READY.ToString(), Status = "True" }
},
Phase = StreamClassPhase.FAILED
};
}

/// <summary>
/// Creates a StreamOperatorResponse object for stream with specified identifier, setting it state to RUNNING
/// </summary>
/// <param name="nameSpace">Kubernetes namespace</param>
/// <param name="kind">Affected stream class kind</param>
/// <param name="streamClassId">Affected stream class identifier</param>
public static StreamClassOperatorResponse Stopped(string nameSpace, string kind, string streamClassId)
{
return new StreamClassOperatorResponse
{
Id = streamClassId,
Kind = kind,
Namespace = nameSpace,
Conditions = new[]
{
new V1Beta1StreamCondition { Type = ResourceStatus.READY.ToString(), Status = "True" }
},
Phase = StreamClassPhase.STOPPED
};
}
}

0 comments on commit d5485c5

Please sign in to comment.