功能修改
This commit is contained in:
@@ -0,0 +1,282 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"browser.local/platform/domain"
|
||||
)
|
||||
|
||||
type CapacityAdmissionRequest struct {
|
||||
ServerInstanceID string `json:"serverInstanceId,omitempty"`
|
||||
RunEndpointID string `json:"runEndpointId,omitempty"`
|
||||
Capability string `json:"capability"`
|
||||
TargetKey string `json:"targetKey,omitempty"`
|
||||
IdempotencyKey string `json:"idempotencyKey,omitempty"`
|
||||
}
|
||||
|
||||
type CapacityAdmissionDecisionResponse struct {
|
||||
Accepted bool `json:"accepted"`
|
||||
State string `json:"state"`
|
||||
Reason string `json:"reason"`
|
||||
RetryAfterSeconds int `json:"retryAfterSeconds,omitempty"`
|
||||
ServerInstanceID string `json:"serverInstanceId,omitempty"`
|
||||
RunEndpointID string `json:"runEndpointId,omitempty"`
|
||||
Capability string `json:"capability"`
|
||||
TargetKey string `json:"targetKey,omitempty"`
|
||||
MaxJobs int `json:"maxJobs"`
|
||||
RunningJobs int `json:"runningJobs"`
|
||||
QueuedJobs int `json:"queuedJobs"`
|
||||
PressureCodes []string `json:"pressureCodes,omitempty"`
|
||||
CheckedAt time.Time `json:"checkedAt"`
|
||||
AlertID string `json:"alertId,omitempty"`
|
||||
AuditEventID string `json:"auditEventId,omitempty"`
|
||||
}
|
||||
|
||||
type EndpointCapacityProjectionResponse struct {
|
||||
RunEndpointID string `json:"runEndpointId"`
|
||||
DisplayName string `json:"displayName"`
|
||||
Status string `json:"status"`
|
||||
Capabilities []string `json:"capabilities"`
|
||||
MaxJobs int `json:"maxJobs"`
|
||||
RunningJobs int `json:"runningJobs"`
|
||||
QueuedJobs int `json:"queuedJobs"`
|
||||
LogBacklogBatches int `json:"logBacklogBatches,omitempty"`
|
||||
ArtifactBacklogChunks int `json:"artifactBacklogChunks,omitempty"`
|
||||
PressureCodes []string `json:"pressureCodes,omitempty"`
|
||||
Summary string `json:"summary,omitempty"`
|
||||
LastHeartbeatAt time.Time `json:"lastHeartbeatAt"`
|
||||
LastAdmissionDecision string `json:"lastAdmissionDecision,omitempty"`
|
||||
LastAdmissionReason string `json:"lastAdmissionReason,omitempty"`
|
||||
LastAdmissionCheckedAt time.Time `json:"lastAdmissionCheckedAt,omitempty"`
|
||||
}
|
||||
|
||||
type ProductionCapacitySummaryResponse struct {
|
||||
Endpoints []EndpointCapacityProjectionResponse `json:"endpoints"`
|
||||
TotalMaxJobs int `json:"totalMaxJobs"`
|
||||
TotalRunningJobs int `json:"totalRunningJobs"`
|
||||
TotalQueuedJobs int `json:"totalQueuedJobs"`
|
||||
ActiveAlerts int `json:"activeAlerts"`
|
||||
GeneratedAt time.Time `json:"generatedAt"`
|
||||
}
|
||||
|
||||
type AlertResponse struct {
|
||||
ID string `json:"id"`
|
||||
SourceKind string `json:"sourceKind"`
|
||||
SourceID string `json:"sourceId"`
|
||||
RuleKey string `json:"ruleKey"`
|
||||
Severity string `json:"severity"`
|
||||
State string `json:"state"`
|
||||
Title string `json:"title"`
|
||||
Message string `json:"message"`
|
||||
OccurrenceCount int `json:"occurrenceCount"`
|
||||
Retryable bool `json:"retryable"`
|
||||
RetryAfterSeconds int `json:"retryAfterSeconds,omitempty"`
|
||||
LastJobID string `json:"lastJobId,omitempty"`
|
||||
LastAuditEventID string `json:"lastAuditEventId,omitempty"`
|
||||
LastSeenAt time.Time `json:"lastSeenAt"`
|
||||
AcknowledgedBy string `json:"acknowledgedBy,omitempty"`
|
||||
AcknowledgedAt time.Time `json:"acknowledgedAt,omitempty"`
|
||||
ResolvedBy string `json:"resolvedBy,omitempty"`
|
||||
ResolvedAt time.Time `json:"resolvedAt,omitempty"`
|
||||
ResolutionNote string `json:"resolutionNote,omitempty"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
type AlertListResponse struct {
|
||||
Items []AlertResponse `json:"items"`
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
type AlertAcknowledgeRequest struct {
|
||||
Note string `json:"note,omitempty"`
|
||||
}
|
||||
|
||||
type AlertResolveRequest struct {
|
||||
Note string `json:"note,omitempty"`
|
||||
}
|
||||
|
||||
type AlertRetryRequest struct {
|
||||
IdempotencyKey string `json:"idempotencyKey"`
|
||||
}
|
||||
|
||||
type AlertRetryResponse struct {
|
||||
Status string `json:"status"`
|
||||
Alert AlertResponse `json:"alert"`
|
||||
Decision CapacityAdmissionDecisionResponse `json:"decision"`
|
||||
}
|
||||
|
||||
type PluginLifecycleActionRequest struct {
|
||||
ServerInstanceID string `json:"serverInstanceId"`
|
||||
Operation string `json:"operation"`
|
||||
TargetVersion string `json:"targetVersion,omitempty"`
|
||||
IdempotencyKey string `json:"idempotencyKey"`
|
||||
Confirmed bool `json:"confirmed"`
|
||||
}
|
||||
|
||||
type PluginLifecycleInstallationResponse struct {
|
||||
ID string `json:"id"`
|
||||
PluginID string `json:"pluginId"`
|
||||
ServerInstanceID string `json:"serverInstanceId"`
|
||||
CurrentVersion string `json:"currentVersion,omitempty"`
|
||||
TargetVersion string `json:"targetVersion,omitempty"`
|
||||
PreviousVersion string `json:"previousVersion,omitempty"`
|
||||
DesiredState string `json:"desiredState"`
|
||||
CurrentState string `json:"currentState"`
|
||||
LastOperation string `json:"lastOperation,omitempty"`
|
||||
Compatibility string `json:"compatibility,omitempty"`
|
||||
DependencyState string `json:"dependencyState,omitempty"`
|
||||
JobID string `json:"jobId,omitempty"`
|
||||
AlertID string `json:"alertId,omitempty"`
|
||||
AuditEventID string `json:"auditEventId,omitempty"`
|
||||
FailureReason string `json:"failureReason,omitempty"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
type PluginLifecycleListResponse struct {
|
||||
Items []PluginLifecycleInstallationResponse `json:"items"`
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
type PluginLifecycleActionResponse struct {
|
||||
Status string `json:"status"`
|
||||
Installation PluginLifecycleInstallationResponse `json:"installation"`
|
||||
Job JobResponse `json:"job"`
|
||||
Decision CapacityAdmissionDecisionResponse `json:"decision"`
|
||||
Alert *AlertResponse `json:"alert,omitempty"`
|
||||
}
|
||||
|
||||
type AIConfigDiffPreviewResponse struct {
|
||||
ID string `json:"id"`
|
||||
RequestID string `json:"requestId"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
ServerInstanceID string `json:"serverInstanceId"`
|
||||
PluginID string `json:"pluginId,omitempty"`
|
||||
ProviderID string `json:"providerId,omitempty"`
|
||||
Model string `json:"model,omitempty"`
|
||||
Key string `json:"key"`
|
||||
ConfigVersion int `json:"configVersion"`
|
||||
CurrentConfigChecksum string `json:"currentConfigChecksum,omitempty"`
|
||||
ProposedConfig string `json:"proposedConfig,omitempty"`
|
||||
DiffSummary string `json:"diffSummary"`
|
||||
State string `json:"state"`
|
||||
ExpiresAt time.Time `json:"expiresAt"`
|
||||
ApprovedBy string `json:"approvedBy,omitempty"`
|
||||
ApprovedAt time.Time `json:"approvedAt,omitempty"`
|
||||
CancelledBy string `json:"cancelledBy,omitempty"`
|
||||
CancelledAt time.Time `json:"cancelledAt,omitempty"`
|
||||
JobID string `json:"jobId,omitempty"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
type AIConfigDiffListResponse struct {
|
||||
Items []AIConfigDiffPreviewResponse `json:"items"`
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
type AIConfigDiffApprovalRequest struct {
|
||||
IdempotencyKey string `json:"idempotencyKey"`
|
||||
}
|
||||
|
||||
type AIConfigDiffApprovalResponse struct {
|
||||
Preview AIConfigDiffPreviewResponse `json:"preview"`
|
||||
Dispatch ServerConfigWriteDispatchResponse `json:"dispatch"`
|
||||
}
|
||||
|
||||
func (request CapacityAdmissionRequest) ToDomain() domain.CapacityAdmissionRequest {
|
||||
return domain.CapacityAdmissionRequest{ServerInstanceID: request.ServerInstanceID, RunEndpointID: request.RunEndpointID, Capability: request.Capability, TargetKey: request.TargetKey, IdempotencyKey: request.IdempotencyKey}
|
||||
}
|
||||
|
||||
func CapacityDecisionFromDomain(decision domain.CapacityAdmissionDecision) CapacityAdmissionDecisionResponse {
|
||||
decision = domain.CopyCapacityAdmissionDecision(decision)
|
||||
return CapacityAdmissionDecisionResponse{Accepted: decision.Accepted, State: string(decision.State), Reason: decision.Reason, RetryAfterSeconds: decision.RetryAfterSeconds, ServerInstanceID: decision.ServerInstanceID, RunEndpointID: decision.RunEndpointID, Capability: decision.Capability, TargetKey: decision.TargetKey, MaxJobs: decision.MaxJobs, RunningJobs: decision.RunningJobs, QueuedJobs: decision.QueuedJobs, PressureCodes: pressureCodesFromDomain(decision.PressureCodes), CheckedAt: decision.CheckedAt, AlertID: decision.AlertID, AuditEventID: decision.AuditEventID}
|
||||
}
|
||||
|
||||
func ProductionCapacityFromDomain(summary domain.ProductionCapacitySummary) ProductionCapacitySummaryResponse {
|
||||
summary = domain.CopyProductionCapacitySummary(summary)
|
||||
items := make([]EndpointCapacityProjectionResponse, len(summary.Endpoints))
|
||||
for i, endpoint := range summary.Endpoints {
|
||||
items[i] = EndpointCapacityProjectionResponse{RunEndpointID: endpoint.RunEndpointID, DisplayName: endpoint.DisplayName, Status: string(endpoint.Status), Capabilities: endpoint.Capabilities, MaxJobs: endpoint.MaxJobs, RunningJobs: endpoint.RunningJobs, QueuedJobs: endpoint.QueuedJobs, LogBacklogBatches: endpoint.LogBacklogBatches, ArtifactBacklogChunks: endpoint.ArtifactBacklogChunks, PressureCodes: pressureCodesFromDomain(endpoint.PressureCodes), Summary: endpoint.Summary, LastHeartbeatAt: endpoint.LastHeartbeatAt, LastAdmissionDecision: string(endpoint.LastAdmissionDecision), LastAdmissionReason: endpoint.LastAdmissionReason, LastAdmissionCheckedAt: endpoint.LastAdmissionCheckedAt}
|
||||
}
|
||||
return ProductionCapacitySummaryResponse{Endpoints: items, TotalMaxJobs: summary.TotalMaxJobs, TotalRunningJobs: summary.TotalRunningJobs, TotalQueuedJobs: summary.TotalQueuedJobs, ActiveAlerts: summary.ActiveAlerts, GeneratedAt: summary.GeneratedAt}
|
||||
}
|
||||
|
||||
func AlertFromDomain(alert domain.AlertRecord) AlertResponse {
|
||||
alert = domain.CopyAlertRecord(alert)
|
||||
return AlertResponse{ID: alert.ID, SourceKind: alert.SourceKind, SourceID: alert.SourceID, RuleKey: alert.RuleKey, Severity: string(alert.Severity), State: string(alert.State), Title: alert.Title, Message: alert.Message, OccurrenceCount: alert.OccurrenceCount, Retryable: alert.Retryable, RetryAfterSeconds: alert.RetryAfterSeconds, LastJobID: alert.LastJobID, LastAuditEventID: alert.LastAuditEventID, LastSeenAt: alert.LastSeenAt, AcknowledgedBy: alert.AcknowledgedBy, AcknowledgedAt: alert.AcknowledgedAt, ResolvedBy: alert.ResolvedBy, ResolvedAt: alert.ResolvedAt, ResolutionNote: alert.ResolutionNote, CreatedAt: alert.CreatedAt, UpdatedAt: alert.UpdatedAt}
|
||||
}
|
||||
|
||||
func AlertListFromDomain(alerts []domain.AlertRecord) AlertListResponse {
|
||||
items := make([]AlertResponse, len(alerts))
|
||||
for i, alert := range alerts {
|
||||
items[i] = AlertFromDomain(alert)
|
||||
}
|
||||
return AlertListResponse{Items: items, Count: len(items)}
|
||||
}
|
||||
|
||||
func AlertRetryFromDomain(result domain.AlertRetryResult) AlertRetryResponse {
|
||||
result = domain.CopyAlertRetryResult(result)
|
||||
return AlertRetryResponse{Status: result.Status, Alert: AlertFromDomain(result.Alert), Decision: CapacityDecisionFromDomain(result.Decision)}
|
||||
}
|
||||
|
||||
func (request PluginLifecycleActionRequest) ToDomain(pluginID string) domain.PluginLifecycleRequest {
|
||||
return domain.PluginLifecycleRequest{PluginID: pluginID, ServerInstanceID: request.ServerInstanceID, Operation: domain.PluginLifecycleOperation(request.Operation), TargetVersion: request.TargetVersion, IdempotencyKey: request.IdempotencyKey, Confirmed: request.Confirmed}
|
||||
}
|
||||
|
||||
func PluginLifecycleFromDomain(installation domain.PluginLifecycleInstallation) PluginLifecycleInstallationResponse {
|
||||
installation = domain.CopyPluginLifecycleInstallation(installation)
|
||||
return PluginLifecycleInstallationResponse{ID: installation.ID, PluginID: installation.PluginID, ServerInstanceID: installation.ServerInstanceID, CurrentVersion: installation.CurrentVersion, TargetVersion: installation.TargetVersion, PreviousVersion: installation.PreviousVersion, DesiredState: string(installation.DesiredState), CurrentState: string(installation.CurrentState), LastOperation: string(installation.LastOperation), Compatibility: installation.Compatibility, DependencyState: string(installation.DependencyState), JobID: installation.JobID, AlertID: installation.AlertID, AuditEventID: installation.AuditEventID, FailureReason: installation.FailureReason, CreatedAt: installation.CreatedAt, UpdatedAt: installation.UpdatedAt}
|
||||
}
|
||||
|
||||
func PluginLifecycleListFromDomain(installations []domain.PluginLifecycleInstallation) PluginLifecycleListResponse {
|
||||
items := make([]PluginLifecycleInstallationResponse, len(installations))
|
||||
for i, installation := range installations {
|
||||
items[i] = PluginLifecycleFromDomain(installation)
|
||||
}
|
||||
return PluginLifecycleListResponse{Items: items, Count: len(items)}
|
||||
}
|
||||
|
||||
func PluginLifecycleResultFromDomain(result domain.PluginLifecycleResult) PluginLifecycleActionResponse {
|
||||
result = domain.CopyPluginLifecycleResult(result)
|
||||
var alert *AlertResponse
|
||||
if result.Alert != nil {
|
||||
item := AlertFromDomain(*result.Alert)
|
||||
alert = &item
|
||||
}
|
||||
return PluginLifecycleActionResponse{Status: result.Status, Installation: PluginLifecycleFromDomain(result.Installation), Job: JobFromDomain(result.Job), Decision: CapacityDecisionFromDomain(result.Decision), Alert: alert}
|
||||
}
|
||||
|
||||
func AIConfigDiffFromDomain(preview domain.AIConfigDiffPreview) AIConfigDiffPreviewResponse {
|
||||
preview = domain.CopyAIConfigDiffPreview(preview)
|
||||
return AIConfigDiffPreviewResponse{ID: preview.ID, RequestID: preview.RequestID, CreatedBy: preview.CreatedBy, ServerInstanceID: preview.ServerInstanceID, PluginID: preview.PluginID, ProviderID: preview.ProviderID, Model: preview.Model, Key: preview.Key, ConfigVersion: preview.ConfigVersion, CurrentConfigChecksum: preview.CurrentConfigChecksum, ProposedConfig: preview.ProposedConfig, DiffSummary: preview.DiffSummary, State: string(preview.State), ExpiresAt: preview.ExpiresAt, ApprovedBy: preview.ApprovedBy, ApprovedAt: preview.ApprovedAt, CancelledBy: preview.CancelledBy, CancelledAt: preview.CancelledAt, JobID: preview.JobID, CreatedAt: preview.CreatedAt, UpdatedAt: preview.UpdatedAt}
|
||||
}
|
||||
|
||||
func AIConfigDiffListFromDomain(previews []domain.AIConfigDiffPreview) AIConfigDiffListResponse {
|
||||
items := make([]AIConfigDiffPreviewResponse, len(previews))
|
||||
for i, preview := range previews {
|
||||
items[i] = AIConfigDiffFromDomain(preview)
|
||||
}
|
||||
return AIConfigDiffListResponse{Items: items, Count: len(items)}
|
||||
}
|
||||
|
||||
func (request AIConfigDiffApprovalRequest) ToDomain(diffID string) domain.AIConfigDiffApprovalRequest {
|
||||
return domain.AIConfigDiffApprovalRequest{DiffID: diffID, IdempotencyKey: request.IdempotencyKey}
|
||||
}
|
||||
|
||||
func AIConfigDiffApprovalFromDomain(result domain.AIConfigDiffApprovalResult) AIConfigDiffApprovalResponse {
|
||||
result = domain.CopyAIConfigDiffApprovalResult(result)
|
||||
return AIConfigDiffApprovalResponse{Preview: AIConfigDiffFromDomain(result.Preview), Dispatch: ServerConfigWriteDispatchFromDomain(result.Dispatch)}
|
||||
}
|
||||
|
||||
func pressureCodesFromDomain(codes []domain.CapacityPressureCode) []string {
|
||||
if codes == nil {
|
||||
return nil
|
||||
}
|
||||
out := make([]string, len(codes))
|
||||
for i, code := range codes {
|
||||
out[i] = string(code)
|
||||
}
|
||||
return out
|
||||
}
|
||||
Reference in New Issue
Block a user