deployment.go 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. package models
  2. import (
  3. "time"
  4. "gorm.io/gorm"
  5. )
  6. // Deployment represents a deployed instance of an application
  7. type Deployment struct {
  8. ID string `json:"id" gorm:"primaryKey"` // Unique identifier
  9. Name string `json:"name" gorm:"not null"` // Deployment name
  10. Description string `json:"description"` // Deployment description
  11. // Core relationships
  12. BlueprintID string `json:"blueprintId" gorm:"index"` // Reference to the blueprint being deployed
  13. ClientID string `json:"clientId" gorm:"index"` // Client this deployment belongs to
  14. // Infrastructure details
  15. Provider string `json:"provider"` // Cloud provider (aws, gcp, azure, etc.)
  16. InstanceID string `json:"instanceId"` // ID of the provisioned instance
  17. InstanceType string `json:"instanceType"` // Type/size of instance
  18. ImageID string `json:"imageId"` // Image ID used for the instance
  19. IPAddress string `json:"ipAddress"` // IP address of the instance
  20. IsFromPool bool `json:"isFromPool" gorm:"default:false"` // Whether this instance came from the pool
  21. // Status and environment
  22. Status string `json:"status" gorm:"default:'pending'"` // Current deployment status
  23. Environment string `json:"environment" gorm:"default:'development'"` // dev, staging, production
  24. Region string `json:"region"` // Geographic region
  25. // Deployment configuration
  26. Hostname string `json:"hostname"` // External hostname for the deployment
  27. CustomDomain string `json:"customDomain"` // Custom domain if configured
  28. // Operational data
  29. LogsConfig string `json:"logsConfig" gorm:"type:text"` // Logging configuration as JSON
  30. MetricsConfig string `json:"metricsConfig" gorm:"type:text"` // Metrics configuration as JSON
  31. AlertsConfig string `json:"alertsConfig" gorm:"type:text"` // Alert configurations as JSON
  32. CreatedAt time.Time `json:"createdAt" gorm:"autoCreateTime"` // Creation timestamp
  33. UpdatedAt time.Time `json:"updatedAt" gorm:"autoUpdateTime"` // Last update timestamp
  34. LastDeployedAt time.Time `json:"lastDeployedAt"` // When the deployment was last deployed
  35. CreatedBy string `json:"createdBy" gorm:"index"` // User ID who created the deployment
  36. DeletedAt gorm.DeletedAt `json:"-" gorm:"index"` // Soft delete support
  37. // GORM relationships
  38. DeployedComponents []DeployedComponent `json:"deployedComponents" gorm:"foreignKey:DeploymentID"` // Array of deployed components
  39. }
  40. // DeployedComponent represents a specific component within a deployment
  41. type DeployedComponent struct {
  42. ID string `json:"id" gorm:"primaryKey"` // Unique identifier
  43. DeploymentID string `json:"deploymentId" gorm:"index"` // Reference to the parent deployment
  44. ComponentID string `json:"componentId" gorm:"index"` // Reference to the component being deployed
  45. Status string `json:"status" gorm:"default:'pending'"` // Status of this specific app's deployment
  46. Version string `json:"version"` // Deployed version
  47. URL string `json:"url"` // URL to access this app
  48. PodCount int `json:"podCount" gorm:"default:1"` // Number of running instances/pods
  49. HealthStatus string `json:"healthStatus" gorm:"default:'pending'"` // Current health status
  50. ConfigSnapshot string `json:"configSnapshot" gorm:"type:text"` // Snapshot of configuration at deployment time
  51. CreatedAt time.Time `json:"createdAt" gorm:"autoCreateTime"` // Creation timestamp
  52. UpdatedAt time.Time `json:"updatedAt" gorm:"autoUpdateTime"` // Last update timestamp
  53. DeletedAt gorm.DeletedAt `json:"-" gorm:"index"` // Soft delete support
  54. // GORM relationships - these will be serialized/deserialized as JSON
  55. Resources ResourceAllocation `json:"resources" gorm:"-"` // Actual resources allocated
  56. }
  57. // Component resource allocation (will be stored in DeployedComponentResource table)
  58. type DeployedComponentResource struct {
  59. ID string `json:"id" gorm:"primaryKey"` // Unique identifier
  60. DeployedComponentID string `json:"deployedComponentId" gorm:"uniqueIndex"` // Reference to deployed component
  61. CPU string `json:"cpu"` // Allocated CPU
  62. CPUUsage float64 `json:"cpuUsage"` // Current CPU usage percentage
  63. Memory string `json:"memory"` // Allocated memory
  64. MemoryUsage float64 `json:"memoryUsage"` // Current memory usage percentage
  65. Storage string `json:"storage"` // Allocated storage
  66. StorageUsage float64 `json:"storageUsage"` // Current storage usage percentage
  67. LastUpdated time.Time `json:"lastUpdated" gorm:"autoUpdateTime"` // When metrics were last updated
  68. }
  69. // For backward compatibility
  70. type ResourceAllocation struct {
  71. CPU string `json:"cpu"` // Allocated CPU
  72. CPUUsage float64 `json:"cpuUsage"` // Current CPU usage percentage
  73. Memory string `json:"memory"` // Allocated memory
  74. MemoryUsage float64 `json:"memoryUsage"` // Current memory usage percentage
  75. Storage string `json:"storage"` // Allocated storage
  76. StorageUsage float64 `json:"storageUsage"` // Current storage usage percentage
  77. }
  78. // LogConfiguration, MetricsConfiguration, and AlertConfiguration remain the same
  79. // These will be serialized/deserialized as JSON
  80. type LogConfiguration struct {
  81. Enabled bool `json:"enabled"` // Whether logging is enabled
  82. RetentionDays int `json:"retentionDays"` // Number of days to retain logs
  83. ExternalSink string `json:"externalSink"` // External logging system URL if any
  84. }
  85. type MetricsConfiguration struct {
  86. Enabled bool `json:"enabled"` // Whether metrics collection is enabled
  87. RetentionDays int `json:"retentionDays"` // Number of days to retain metrics
  88. CustomMetrics []string `json:"customMetrics"` // Any custom metrics to collect
  89. }
  90. type AlertConfiguration struct {
  91. Type string `json:"type"` // Type of alert
  92. Threshold float64 `json:"threshold"` // Threshold value
  93. Operator string `json:"operator"` // ">", "<", ">=", "<=", "=="
  94. Duration string `json:"duration"` // How long condition must be true before alerting
  95. NotificationChannels []string `json:"notificationChannels"` // Channels to notify (email, slack, etc.)
  96. }
  97. // DeploymentStatus type definitions
  98. type DeploymentStatus string
  99. type Environment string
  100. type ComponentDeploymentStatus string
  101. type HealthStatus string
  102. type AlertType string
  103. const (
  104. // DeploymentStatus values
  105. PENDING_DEPLOYMENT DeploymentStatus = "pending"
  106. DEPLOYING DeploymentStatus = "deploying"
  107. DEPLOYED DeploymentStatus = "deployed"
  108. FAILED_DEPLOYMENT DeploymentStatus = "failed"
  109. UPDATING_DEPLOYMENT DeploymentStatus = "updating"
  110. DELETING DeploymentStatus = "deleting"
  111. // Environment values
  112. DEVELOPMENT Environment = "development"
  113. STAGING Environment = "staging"
  114. PRODUCTION Environment = "production"
  115. // ComponentDeploymentStatus values
  116. PENDING_APP ComponentDeploymentStatus = "pending"
  117. RUNNING ComponentDeploymentStatus = "running"
  118. FAILED_APP ComponentDeploymentStatus = "failed"
  119. SCALING ComponentDeploymentStatus = "scaling"
  120. UPDATING_APP ComponentDeploymentStatus = "updating"
  121. // HealthStatus values
  122. HEALTHY HealthStatus = "healthy"
  123. DEGRADED HealthStatus = "degraded"
  124. UNHEALTHY HealthStatus = "unhealthy"
  125. // AlertType values
  126. CPU_USAGE AlertType = "cpu_usage"
  127. MEMORY_USAGE AlertType = "memory_usage"
  128. DISK_USAGE AlertType = "disk_usage"
  129. ERROR_RATE AlertType = "error_rate"
  130. LATENCY AlertType = "latency"
  131. )